Style changes

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9647 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2004-10-29 09:11:53 +00:00
parent 08db68e8ee
commit f900119889
5 changed files with 100 additions and 128 deletions

View File

@ -1,5 +1,5 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2003, OpenBeOS
// Copyright (c) 2001-2004, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@ -24,41 +24,34 @@
// Description: Line storage used by BTextView
//------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include "LineBuffer.h"
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
_BLineBuffer_::_BLineBuffer_()
: _BTextViewSupportBuffer_<STELine>(20, 2)
{
}
//------------------------------------------------------------------------------
_BLineBuffer_::~_BLineBuffer_()
{
}
//------------------------------------------------------------------------------
void
_BLineBuffer_::InsertLine(STELine *inLine, int32 index)
{
InsertItemsAt(1, index, inLine);
}
//------------------------------------------------------------------------------
void
_BLineBuffer_::RemoveLines(int32 index, int32 count)
{
RemoveItemsAt(count, index);
}
//------------------------------------------------------------------------------
void
_BLineBuffer_::RemoveLineRange(int32 fromOffset, int32 toOffset)
{
@ -71,7 +64,8 @@ _BLineBuffer_::RemoveLineRange(int32 fromOffset, int32 toOffset)
BumpOffset(fromOffset - toOffset, fromLine + 1);
}
//------------------------------------------------------------------------------
int32
_BLineBuffer_::OffsetToLine(int32 offset) const
{
@ -86,14 +80,14 @@ _BLineBuffer_::OffsetToLine(int32 offset) const
break;
else
minIndex = index + 1;
}
else
} else
maxIndex = index;
}
return index;
}
//------------------------------------------------------------------------------
int32 _BLineBuffer_::PixelToLine(float pixel) const
{
int32 minIndex = 0;
@ -107,32 +101,25 @@ int32 _BLineBuffer_::PixelToLine(float pixel) const
break;
else
minIndex = index + 1;
}
else
} else
maxIndex = index;
}
return index;
}
//------------------------------------------------------------------------------
void
_BLineBuffer_::BumpOrigin(float delta, long index)
{
for (long i = index; i < fItemCount; i++)
fBuffer[i].origin += delta;
}
//------------------------------------------------------------------------------
void
_BLineBuffer_::BumpOffset(int32 delta, int32 index)
{
for (long i = index; i < fItemCount; i++)
fBuffer[i].offset += delta;
}
//------------------------------------------------------------------------------
/*
* $Log $
*
* $Id $
*
*/

View File

@ -1,5 +1,5 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2003, OpenBeOS
// Copyright (c) 2001-2004, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@ -24,9 +24,6 @@
// Description: Style storage used by BTextView
//------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <Font.h>
#include <InterfaceDefs.h>
#include <SupportDefs.h>
@ -39,16 +36,19 @@ typedef struct STEStyle {
rgb_color color; // pen color
} STEStyle, *STEStylePtr;
typedef struct STEStyleRun {
long offset; // byte offset of first character of run
STEStyle style; // style info
} STEStyleRun, *STEStyleRunPtr;
typedef struct STEStyleRange {
long count; // number of style runs
STEStyleRun runs[1]; // array of count number of runs
} STEStyleRange, *STEStyleRangePtr;
typedef struct STEStyleRecord {
long refs; // reference count for this style
float ascent; // ascent for this style
@ -56,12 +56,12 @@ typedef struct STEStyleRecord {
STEStyle style; // style info
} STEStyleRecord, *STEStyleRecordPtr;
typedef struct STEStyleRunDesc {
long offset; // byte offset of first character of run
long index; // index of corresponding style record
} STEStyleRunDesc, *STEStyleRunDescPtr;
// Globals ---------------------------------------------------------------------
// _BStyleRunDescBuffer_ class -------------------------------------------------
class _BStyleRunDescBuffer_ : public _BTextViewSupportBuffer_<STEStyleRunDesc> {
@ -77,13 +77,14 @@ public:
const STEStyleRunDescPtr operator[](int32 index) const;
};
//------------------------------------------------------------------------------
inline const
STEStyleRunDescPtr _BStyleRunDescBuffer_::operator[](int32 index) const
inline const STEStyleRunDescPtr
_BStyleRunDescBuffer_::operator[](int32 index) const
{
return &fBuffer[index];
}
//------------------------------------------------------------------------------
// _BStyleRecordBuffer_ class --------------------------------------------------
class _BStyleRecordBuffer_ : public _BTextViewSupportBuffer_<STEStyleRecord> {
@ -100,13 +101,14 @@ public:
const STEStyleRecordPtr operator[](int32 index) const;
};
//------------------------------------------------------------------------------
inline const
STEStyleRecordPtr _BStyleRecordBuffer_::operator[](int32 index) const
inline const STEStyleRecordPtr
_BStyleRecordBuffer_::operator[](int32 index) const
{
return &fBuffer[index];
}
//------------------------------------------------------------------------------
class _BInlineInput_;
// _BStyleBuffer_ class --------------------------------------------------------
@ -162,29 +164,24 @@ protected:
bool fValidNullStyle;
STEStyle fNullStyle;
};
//------------------------------------------------------------------------------
inline int32
_BStyleBuffer_::NumRuns() const
{
return fStyleRunDesc.ItemCount();
}
//------------------------------------------------------------------------------
inline const
_BStyleRunDescBuffer_ &_BStyleBuffer_::RunBuffer() const
inline const _BStyleRunDescBuffer_&
_BStyleBuffer_::RunBuffer() const
{
return fStyleRunDesc;
}
//------------------------------------------------------------------------------
inline const
_BStyleRecordBuffer_ &_BStyleBuffer_::RecordBuffer() const
inline const _BStyleRecordBuffer_&
_BStyleBuffer_::RecordBuffer() const
{
return fStyleRecord;
}
//------------------------------------------------------------------------------
/*
* $Log $
*
* $Id $
*
*/

View File

@ -20,27 +20,19 @@
// DEALINGS IN THE SOFTWARE.
//
// File Name: TextGapBuffer.cpp
// Author: Marc Flerackers (mflerackers@androme.be)
// Authors: Marc Flerackers (mflerackers@androme.be)
// Stefano Ceccherini (burton666@libero.it)
// Description: Text storage used by BTextView
//------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
#include <cstdlib>
#include <cstring>
// System Includes -------------------------------------------------------------
#include <File.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
#include "TextGapBuffer.h"
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
_BTextGapBuffer_::_BTextGapBuffer_()
: fExtraCount(2048),
fItemCount(0),
@ -55,13 +47,15 @@ _BTextGapBuffer_::_BTextGapBuffer_()
fBuffer = (char *)malloc(fExtraCount + fItemCount);
fScratchBuffer = NULL;
}
//------------------------------------------------------------------------------
_BTextGapBuffer_::~_BTextGapBuffer_()
{
free(fBuffer);
free(fScratchBuffer);
}
//------------------------------------------------------------------------------
void
_BTextGapBuffer_::InsertText(const char *inText, int32 inNumItems,
int32 inAtIndex)
@ -84,7 +78,8 @@ _BTextGapBuffer_::InsertText(const char *inText, int32 inNumItems,
fGapIndex += inNumItems;
fItemCount += inNumItems;
}
//------------------------------------------------------------------------------
void
_BTextGapBuffer_::InsertText(BFile *file, int32 fileOffset, int32 inNumItems, int32 inAtIndex)
{
@ -119,7 +114,8 @@ _BTextGapBuffer_::InsertText(BFile *file, int32 fileOffset, int32 inNumItems, in
fItemCount += inNumItems;
}
}
//------------------------------------------------------------------------------
void
_BTextGapBuffer_::RemoveRange(int32 start, int32 end)
{
@ -140,7 +136,8 @@ _BTextGapBuffer_::RemoveRange(int32 start, int32 end)
if (fGapCount > fExtraCount)
SizeGapTo(fExtraCount);
}
//------------------------------------------------------------------------------
void
_BTextGapBuffer_::MoveGapTo(int32 toIndex)
{
@ -157,8 +154,7 @@ _BTextGapBuffer_::MoveGapTo(int32 toIndex)
dstIndex = fGapIndex;
count = fGapCount + (toIndex - srcIndex);
count = (count > trailGapCount) ? trailGapCount : count;
}
else {
} else {
srcIndex = toIndex;
dstIndex = toIndex + (gapEndIndex - fGapIndex);
count = gapEndIndex - dstIndex;
@ -169,7 +165,8 @@ _BTextGapBuffer_::MoveGapTo(int32 toIndex)
fGapIndex = toIndex;
}
//------------------------------------------------------------------------------
void
_BTextGapBuffer_::SizeGapTo(long inCount)
{
@ -184,7 +181,8 @@ _BTextGapBuffer_::SizeGapTo(long inCount)
fGapCount = inCount;
fBufferCount = fItemCount + fGapCount;
}
//------------------------------------------------------------------------------
const char *
_BTextGapBuffer_::GetString(int32 fromOffset, int32 numChars)
{
@ -215,7 +213,8 @@ _BTextGapBuffer_::GetString(int32 fromOffset, int32 numChars)
return result;
}
//------------------------------------------------------------------------------
bool
_BTextGapBuffer_::FindChar(char inChar, long fromIndex, long *ioDelta)
{
@ -231,7 +230,8 @@ _BTextGapBuffer_::FindChar(char inChar, long fromIndex, long *ioDelta)
return false;
}
//------------------------------------------------------------------------------
const char *
_BTextGapBuffer_::Text()
{
@ -240,12 +240,15 @@ _BTextGapBuffer_::Text()
return fBuffer;
}
//------------------------------------------------------------------------------
/*char *_BTextGapBuffer_::RealText()
/*char *
_BTextGapBuffer_::RealText()
{
return fText;
}*/
//------------------------------------------------------------------------------
void
_BTextGapBuffer_::GetString(int32 offset, int32 length, char *buffer)
{
@ -285,27 +288,24 @@ _BTextGapBuffer_::GetString(int32 offset, int32 length, char *buffer)
buffer[length] = '\0';
}
//------------------------------------------------------------------------------
char
_BTextGapBuffer_::RealCharAt(int32 offset) const
{
return (offset < fGapIndex) ? fBuffer[offset] : fBuffer[offset + fGapCount];
}
//------------------------------------------------------------------------------
bool
_BTextGapBuffer_::PasswordMode() const
{
return fPasswordMode;
}
//------------------------------------------------------------------------------
void
_BTextGapBuffer_::SetPasswordMode(bool state)
{
fPasswordMode = state;
}
/*
* $Log $
*
* $Id $
*
*/

View File

@ -1,5 +1,5 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2004, Haiku
// Copyright (c) 2001-2004, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@ -26,18 +26,8 @@
#ifndef __TEXTGAPBUFFER_H
#define __TEXTGAPBUFFER_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <SupportDefs.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
class BFile;
// _BTextGapBuffer_ class ------------------------------------------------------
@ -84,13 +74,15 @@ protected:
int32 fScratchSize; // scratch size
bool fPasswordMode;
};
//------------------------------------------------------------------------------
inline int32
_BTextGapBuffer_::Length() const
{
return fItemCount;
}
//------------------------------------------------------------------------------
inline char
_BTextGapBuffer_::operator[](long index) const
{
@ -98,9 +90,3 @@ _BTextGapBuffer_::operator[](long index) const
}
#endif //__TEXTGAPBUFFER_H
/*
* $Log $
*
* $Id $
*
*/

View File

@ -1,5 +1,5 @@
//------------------------------------------------------------------------------
// Copyright (c) 2003, OpenBeOS
// Copyright (c) 2003-2004, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@ -27,13 +27,12 @@
#ifndef __UNDOBUFFER_H
#define __UNDOBUFFER_H
// System Includes -------------------------------------------------------------
#include <TextView.h>
class BClipboard;
class _BUndoBuffer_
{
class _BUndoBuffer_ {
public:
_BUndoBuffer_(BTextView *, undo_state);
virtual ~_BUndoBuffer_();
@ -55,32 +54,33 @@ protected:
int32 fRunArrayLength;
bool fRedo;
private:
undo_state fState;
};
// ******** _BCutUndoBuffer_ *******
class _BCutUndoBuffer_ : public _BUndoBuffer_
{
class _BCutUndoBuffer_ : public _BUndoBuffer_ {
public:
_BCutUndoBuffer_(BTextView *textView);
~_BCutUndoBuffer_();
protected:
virtual void RedoSelf(BClipboard *);
};
// ******** _BPasteUndoBuffer_ *******
class _BPasteUndoBuffer_ : public _BUndoBuffer_
{
class _BPasteUndoBuffer_ : public _BUndoBuffer_ {
public:
_BPasteUndoBuffer_(BTextView *, const char *, int32, text_run_array *, int32);
~_BPasteUndoBuffer_();
protected:
virtual void UndoSelf(BClipboard *);
virtual void RedoSelf(BClipboard *);
private:
char *fPasteText;
int32 fPasteTextLength;
@ -90,25 +90,26 @@ private:
// ******** _BClearUndoBuffer_ *******
class _BClearUndoBuffer_ : public _BUndoBuffer_
{
class _BClearUndoBuffer_ : public _BUndoBuffer_ {
public:
_BClearUndoBuffer_(BTextView *textView);
~_BClearUndoBuffer_();
protected:
virtual void RedoSelf(BClipboard *);
};
// ******** _BDropUndoBuffer_ ********
class _BDropUndoBuffer_ : public _BUndoBuffer_
{
class _BDropUndoBuffer_ : public _BUndoBuffer_ {
public:
_BDropUndoBuffer_(BTextView *, char const *, int32, text_run_array *, int32, int32, bool);
~_BDropUndoBuffer_();
protected:
virtual void UndoSelf(BClipboard *);
virtual void RedoSelf(BClipboard *);
private:
char *fDropText;
int32 fDropTextLength;
@ -121,18 +122,19 @@ private:
// ******** _BTypingUndoBuffer_ ********
class _BTypingUndoBuffer_ : public _BUndoBuffer_
{
class _BTypingUndoBuffer_ : public _BUndoBuffer_ {
public:
_BTypingUndoBuffer_(BTextView *);
~_BTypingUndoBuffer_();
void InputCharacter(int32);
void BackwardErase();
void ForwardErase();
void ForwardErase();
protected:
virtual void RedoSelf(BClipboard *);
virtual void UndoSelf(BClipboard *);
private:
void Reset();