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
+19 -32
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 // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@@ -24,41 +24,34 @@
// Description: Line storage used by BTextView // Description: Line storage used by BTextView
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include "LineBuffer.h" #include "LineBuffer.h"
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
_BLineBuffer_::_BLineBuffer_() _BLineBuffer_::_BLineBuffer_()
: _BTextViewSupportBuffer_<STELine>(20, 2) : _BTextViewSupportBuffer_<STELine>(20, 2)
{ {
} }
//------------------------------------------------------------------------------
_BLineBuffer_::~_BLineBuffer_() _BLineBuffer_::~_BLineBuffer_()
{ {
} }
//------------------------------------------------------------------------------
void void
_BLineBuffer_::InsertLine(STELine *inLine, int32 index) _BLineBuffer_::InsertLine(STELine *inLine, int32 index)
{ {
InsertItemsAt(1, index, inLine); InsertItemsAt(1, index, inLine);
} }
//------------------------------------------------------------------------------
void void
_BLineBuffer_::RemoveLines(int32 index, int32 count) _BLineBuffer_::RemoveLines(int32 index, int32 count)
{ {
RemoveItemsAt(count, index); RemoveItemsAt(count, index);
} }
//------------------------------------------------------------------------------
void void
_BLineBuffer_::RemoveLineRange(int32 fromOffset, int32 toOffset) _BLineBuffer_::RemoveLineRange(int32 fromOffset, int32 toOffset)
{ {
@@ -71,7 +64,8 @@ _BLineBuffer_::RemoveLineRange(int32 fromOffset, int32 toOffset)
BumpOffset(fromOffset - toOffset, fromLine + 1); BumpOffset(fromOffset - toOffset, fromLine + 1);
} }
//------------------------------------------------------------------------------
int32 int32
_BLineBuffer_::OffsetToLine(int32 offset) const _BLineBuffer_::OffsetToLine(int32 offset) const
{ {
@@ -86,14 +80,14 @@ _BLineBuffer_::OffsetToLine(int32 offset) const
break; break;
else else
minIndex = index + 1; minIndex = index + 1;
} } else
else
maxIndex = index; maxIndex = index;
} }
return index; return index;
} }
//------------------------------------------------------------------------------
int32 _BLineBuffer_::PixelToLine(float pixel) const int32 _BLineBuffer_::PixelToLine(float pixel) const
{ {
int32 minIndex = 0; int32 minIndex = 0;
@@ -107,32 +101,25 @@ int32 _BLineBuffer_::PixelToLine(float pixel) const
break; break;
else else
minIndex = index + 1; minIndex = index + 1;
} } else
else
maxIndex = index; maxIndex = index;
} }
return index; return index;
} }
//------------------------------------------------------------------------------
void void
_BLineBuffer_::BumpOrigin(float delta, long index) _BLineBuffer_::BumpOrigin(float delta, long index)
{ {
for (long i = index; i < fItemCount; i++) for (long i = index; i < fItemCount; i++)
fBuffer[i].origin += delta; fBuffer[i].origin += delta;
} }
//------------------------------------------------------------------------------
void void
_BLineBuffer_::BumpOffset(int32 delta, int32 index) _BLineBuffer_::BumpOffset(int32 delta, int32 index)
{ {
for (long i = index; i < fItemCount; i++) for (long i = index; i < fItemCount; i++)
fBuffer[i].offset += delta; fBuffer[i].offset += delta;
} }
//------------------------------------------------------------------------------
/*
* $Log $
*
* $Id $
*
*/
+25 -28
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 // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@@ -24,9 +24,6 @@
// Description: Style storage used by BTextView // Description: Style storage used by BTextView
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <Font.h> #include <Font.h>
#include <InterfaceDefs.h> #include <InterfaceDefs.h>
#include <SupportDefs.h> #include <SupportDefs.h>
@@ -39,16 +36,19 @@ typedef struct STEStyle {
rgb_color color; // pen color rgb_color color; // pen color
} STEStyle, *STEStylePtr; } STEStyle, *STEStylePtr;
typedef struct STEStyleRun { typedef struct STEStyleRun {
long offset; // byte offset of first character of run long offset; // byte offset of first character of run
STEStyle style; // style info STEStyle style; // style info
} STEStyleRun, *STEStyleRunPtr; } STEStyleRun, *STEStyleRunPtr;
typedef struct STEStyleRange { typedef struct STEStyleRange {
long count; // number of style runs long count; // number of style runs
STEStyleRun runs[1]; // array of count number of runs STEStyleRun runs[1]; // array of count number of runs
} STEStyleRange, *STEStyleRangePtr; } STEStyleRange, *STEStyleRangePtr;
typedef struct STEStyleRecord { typedef struct STEStyleRecord {
long refs; // reference count for this style long refs; // reference count for this style
float ascent; // ascent for this style float ascent; // ascent for this style
@@ -56,12 +56,12 @@ typedef struct STEStyleRecord {
STEStyle style; // style info STEStyle style; // style info
} STEStyleRecord, *STEStyleRecordPtr; } STEStyleRecord, *STEStyleRecordPtr;
typedef struct STEStyleRunDesc { typedef struct STEStyleRunDesc {
long offset; // byte offset of first character of run long offset; // byte offset of first character of run
long index; // index of corresponding style record long index; // index of corresponding style record
} STEStyleRunDesc, *STEStyleRunDescPtr; } STEStyleRunDesc, *STEStyleRunDescPtr;
// Globals ---------------------------------------------------------------------
// _BStyleRunDescBuffer_ class ------------------------------------------------- // _BStyleRunDescBuffer_ class -------------------------------------------------
class _BStyleRunDescBuffer_ : public _BTextViewSupportBuffer_<STEStyleRunDesc> { class _BStyleRunDescBuffer_ : public _BTextViewSupportBuffer_<STEStyleRunDesc> {
@@ -77,13 +77,14 @@ public:
const STEStyleRunDescPtr operator[](int32 index) const; 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]; return &fBuffer[index];
} }
//------------------------------------------------------------------------------
// _BStyleRecordBuffer_ class -------------------------------------------------- // _BStyleRecordBuffer_ class --------------------------------------------------
class _BStyleRecordBuffer_ : public _BTextViewSupportBuffer_<STEStyleRecord> { class _BStyleRecordBuffer_ : public _BTextViewSupportBuffer_<STEStyleRecord> {
@@ -100,13 +101,14 @@ public:
const STEStyleRecordPtr operator[](int32 index) const; 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]; return &fBuffer[index];
} }
//------------------------------------------------------------------------------
class _BInlineInput_; class _BInlineInput_;
// _BStyleBuffer_ class -------------------------------------------------------- // _BStyleBuffer_ class --------------------------------------------------------
@@ -162,29 +164,24 @@ protected:
bool fValidNullStyle; bool fValidNullStyle;
STEStyle fNullStyle; STEStyle fNullStyle;
}; };
//------------------------------------------------------------------------------
inline int32 inline int32
_BStyleBuffer_::NumRuns() const _BStyleBuffer_::NumRuns() const
{ {
return fStyleRunDesc.ItemCount(); return fStyleRunDesc.ItemCount();
} }
//------------------------------------------------------------------------------
inline const
_BStyleRunDescBuffer_ &_BStyleBuffer_::RunBuffer() const inline const _BStyleRunDescBuffer_&
_BStyleBuffer_::RunBuffer() const
{ {
return fStyleRunDesc; return fStyleRunDesc;
} }
//------------------------------------------------------------------------------
inline const
_BStyleRecordBuffer_ &_BStyleBuffer_::RecordBuffer() const inline const _BStyleRecordBuffer_&
_BStyleBuffer_::RecordBuffer() const
{ {
return fStyleRecord; return fStyleRecord;
} }
//------------------------------------------------------------------------------
/*
* $Log $
*
* $Id $
*
*/
+33 -33
View File
@@ -20,27 +20,19 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
// File Name: TextGapBuffer.cpp // File Name: TextGapBuffer.cpp
// Author: Marc Flerackers ([email protected]) // Authors: Marc Flerackers ([email protected])
// Stefano Ceccherini ([email protected])
// Description: Text storage used by BTextView // Description: Text storage used by BTextView
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
// System Includes -------------------------------------------------------------
#include <File.h> #include <File.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
#include "TextGapBuffer.h" #include "TextGapBuffer.h"
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
_BTextGapBuffer_::_BTextGapBuffer_() _BTextGapBuffer_::_BTextGapBuffer_()
: fExtraCount(2048), : fExtraCount(2048),
fItemCount(0), fItemCount(0),
@@ -55,13 +47,15 @@ _BTextGapBuffer_::_BTextGapBuffer_()
fBuffer = (char *)malloc(fExtraCount + fItemCount); fBuffer = (char *)malloc(fExtraCount + fItemCount);
fScratchBuffer = NULL; fScratchBuffer = NULL;
} }
//------------------------------------------------------------------------------
_BTextGapBuffer_::~_BTextGapBuffer_() _BTextGapBuffer_::~_BTextGapBuffer_()
{ {
free(fBuffer); free(fBuffer);
free(fScratchBuffer); free(fScratchBuffer);
} }
//------------------------------------------------------------------------------
void void
_BTextGapBuffer_::InsertText(const char *inText, int32 inNumItems, _BTextGapBuffer_::InsertText(const char *inText, int32 inNumItems,
int32 inAtIndex) int32 inAtIndex)
@@ -84,7 +78,8 @@ _BTextGapBuffer_::InsertText(const char *inText, int32 inNumItems,
fGapIndex += inNumItems; fGapIndex += inNumItems;
fItemCount += inNumItems; fItemCount += inNumItems;
} }
//------------------------------------------------------------------------------
void void
_BTextGapBuffer_::InsertText(BFile *file, int32 fileOffset, int32 inNumItems, int32 inAtIndex) _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; fItemCount += inNumItems;
} }
} }
//------------------------------------------------------------------------------
void void
_BTextGapBuffer_::RemoveRange(int32 start, int32 end) _BTextGapBuffer_::RemoveRange(int32 start, int32 end)
{ {
@@ -140,7 +136,8 @@ _BTextGapBuffer_::RemoveRange(int32 start, int32 end)
if (fGapCount > fExtraCount) if (fGapCount > fExtraCount)
SizeGapTo(fExtraCount); SizeGapTo(fExtraCount);
} }
//------------------------------------------------------------------------------
void void
_BTextGapBuffer_::MoveGapTo(int32 toIndex) _BTextGapBuffer_::MoveGapTo(int32 toIndex)
{ {
@@ -157,8 +154,7 @@ _BTextGapBuffer_::MoveGapTo(int32 toIndex)
dstIndex = fGapIndex; dstIndex = fGapIndex;
count = fGapCount + (toIndex - srcIndex); count = fGapCount + (toIndex - srcIndex);
count = (count > trailGapCount) ? trailGapCount : count; count = (count > trailGapCount) ? trailGapCount : count;
} } else {
else {
srcIndex = toIndex; srcIndex = toIndex;
dstIndex = toIndex + (gapEndIndex - fGapIndex); dstIndex = toIndex + (gapEndIndex - fGapIndex);
count = gapEndIndex - dstIndex; count = gapEndIndex - dstIndex;
@@ -169,7 +165,8 @@ _BTextGapBuffer_::MoveGapTo(int32 toIndex)
fGapIndex = toIndex; fGapIndex = toIndex;
} }
//------------------------------------------------------------------------------
void void
_BTextGapBuffer_::SizeGapTo(long inCount) _BTextGapBuffer_::SizeGapTo(long inCount)
{ {
@@ -184,7 +181,8 @@ _BTextGapBuffer_::SizeGapTo(long inCount)
fGapCount = inCount; fGapCount = inCount;
fBufferCount = fItemCount + fGapCount; fBufferCount = fItemCount + fGapCount;
} }
//------------------------------------------------------------------------------
const char * const char *
_BTextGapBuffer_::GetString(int32 fromOffset, int32 numChars) _BTextGapBuffer_::GetString(int32 fromOffset, int32 numChars)
{ {
@@ -215,7 +213,8 @@ _BTextGapBuffer_::GetString(int32 fromOffset, int32 numChars)
return result; return result;
} }
//------------------------------------------------------------------------------
bool bool
_BTextGapBuffer_::FindChar(char inChar, long fromIndex, long *ioDelta) _BTextGapBuffer_::FindChar(char inChar, long fromIndex, long *ioDelta)
{ {
@@ -231,7 +230,8 @@ _BTextGapBuffer_::FindChar(char inChar, long fromIndex, long *ioDelta)
return false; return false;
} }
//------------------------------------------------------------------------------
const char * const char *
_BTextGapBuffer_::Text() _BTextGapBuffer_::Text()
{ {
@@ -240,12 +240,15 @@ _BTextGapBuffer_::Text()
return fBuffer; return fBuffer;
} }
//------------------------------------------------------------------------------
/*char *_BTextGapBuffer_::RealText()
/*char *
_BTextGapBuffer_::RealText()
{ {
return fText; return fText;
}*/ }*/
//------------------------------------------------------------------------------
void void
_BTextGapBuffer_::GetString(int32 offset, int32 length, char *buffer) _BTextGapBuffer_::GetString(int32 offset, int32 length, char *buffer)
{ {
@@ -285,27 +288,24 @@ _BTextGapBuffer_::GetString(int32 offset, int32 length, char *buffer)
buffer[length] = '\0'; buffer[length] = '\0';
} }
//------------------------------------------------------------------------------
char char
_BTextGapBuffer_::RealCharAt(int32 offset) const _BTextGapBuffer_::RealCharAt(int32 offset) const
{ {
return (offset < fGapIndex) ? fBuffer[offset] : fBuffer[offset + fGapCount]; return (offset < fGapIndex) ? fBuffer[offset] : fBuffer[offset + fGapCount];
} }
//------------------------------------------------------------------------------
bool bool
_BTextGapBuffer_::PasswordMode() const _BTextGapBuffer_::PasswordMode() const
{ {
return fPasswordMode; return fPasswordMode;
} }
//------------------------------------------------------------------------------
void void
_BTextGapBuffer_::SetPasswordMode(bool state) _BTextGapBuffer_::SetPasswordMode(bool state)
{ {
fPasswordMode = state; fPasswordMode = state;
} }
/*
* $Log $
*
* $Id $
*
*/
+5 -19
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 // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@@ -26,18 +26,8 @@
#ifndef __TEXTGAPBUFFER_H #ifndef __TEXTGAPBUFFER_H
#define __TEXTGAPBUFFER_H #define __TEXTGAPBUFFER_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <SupportDefs.h> #include <SupportDefs.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
class BFile; class BFile;
// _BTextGapBuffer_ class ------------------------------------------------------ // _BTextGapBuffer_ class ------------------------------------------------------
@@ -84,13 +74,15 @@ protected:
int32 fScratchSize; // scratch size int32 fScratchSize; // scratch size
bool fPasswordMode; bool fPasswordMode;
}; };
//------------------------------------------------------------------------------
inline int32 inline int32
_BTextGapBuffer_::Length() const _BTextGapBuffer_::Length() const
{ {
return fItemCount; return fItemCount;
} }
//------------------------------------------------------------------------------
inline char inline char
_BTextGapBuffer_::operator[](long index) const _BTextGapBuffer_::operator[](long index) const
{ {
@@ -98,9 +90,3 @@ _BTextGapBuffer_::operator[](long index) const
} }
#endif //__TEXTGAPBUFFER_H #endif //__TEXTGAPBUFFER_H
/*
* $Log $
*
* $Id $
*
*/
+18 -16
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 // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@@ -27,13 +27,12 @@
#ifndef __UNDOBUFFER_H #ifndef __UNDOBUFFER_H
#define __UNDOBUFFER_H #define __UNDOBUFFER_H
// System Includes -------------------------------------------------------------
#include <TextView.h> #include <TextView.h>
class BClipboard; class BClipboard;
class _BUndoBuffer_ class _BUndoBuffer_ {
{
public: public:
_BUndoBuffer_(BTextView *, undo_state); _BUndoBuffer_(BTextView *, undo_state);
virtual ~_BUndoBuffer_(); virtual ~_BUndoBuffer_();
@@ -55,32 +54,33 @@ protected:
int32 fRunArrayLength; int32 fRunArrayLength;
bool fRedo; bool fRedo;
private: private:
undo_state fState; undo_state fState;
}; };
// ******** _BCutUndoBuffer_ ******* // ******** _BCutUndoBuffer_ *******
class _BCutUndoBuffer_ : public _BUndoBuffer_ class _BCutUndoBuffer_ : public _BUndoBuffer_ {
{
public: public:
_BCutUndoBuffer_(BTextView *textView); _BCutUndoBuffer_(BTextView *textView);
~_BCutUndoBuffer_(); ~_BCutUndoBuffer_();
protected: protected:
virtual void RedoSelf(BClipboard *); virtual void RedoSelf(BClipboard *);
}; };
// ******** _BPasteUndoBuffer_ ******* // ******** _BPasteUndoBuffer_ *******
class _BPasteUndoBuffer_ : public _BUndoBuffer_ class _BPasteUndoBuffer_ : public _BUndoBuffer_ {
{
public: public:
_BPasteUndoBuffer_(BTextView *, const char *, int32, text_run_array *, int32); _BPasteUndoBuffer_(BTextView *, const char *, int32, text_run_array *, int32);
~_BPasteUndoBuffer_(); ~_BPasteUndoBuffer_();
protected: protected:
virtual void UndoSelf(BClipboard *); virtual void UndoSelf(BClipboard *);
virtual void RedoSelf(BClipboard *); virtual void RedoSelf(BClipboard *);
private: private:
char *fPasteText; char *fPasteText;
int32 fPasteTextLength; int32 fPasteTextLength;
@@ -90,25 +90,26 @@ private:
// ******** _BClearUndoBuffer_ ******* // ******** _BClearUndoBuffer_ *******
class _BClearUndoBuffer_ : public _BUndoBuffer_ class _BClearUndoBuffer_ : public _BUndoBuffer_ {
{
public: public:
_BClearUndoBuffer_(BTextView *textView); _BClearUndoBuffer_(BTextView *textView);
~_BClearUndoBuffer_(); ~_BClearUndoBuffer_();
protected: protected:
virtual void RedoSelf(BClipboard *); virtual void RedoSelf(BClipboard *);
}; };
// ******** _BDropUndoBuffer_ ******** // ******** _BDropUndoBuffer_ ********
class _BDropUndoBuffer_ : public _BUndoBuffer_ class _BDropUndoBuffer_ : public _BUndoBuffer_ {
{
public: public:
_BDropUndoBuffer_(BTextView *, char const *, int32, text_run_array *, int32, int32, bool); _BDropUndoBuffer_(BTextView *, char const *, int32, text_run_array *, int32, int32, bool);
~_BDropUndoBuffer_(); ~_BDropUndoBuffer_();
protected: protected:
virtual void UndoSelf(BClipboard *); virtual void UndoSelf(BClipboard *);
virtual void RedoSelf(BClipboard *); virtual void RedoSelf(BClipboard *);
private: private:
char *fDropText; char *fDropText;
int32 fDropTextLength; int32 fDropTextLength;
@@ -121,18 +122,19 @@ private:
// ******** _BTypingUndoBuffer_ ******** // ******** _BTypingUndoBuffer_ ********
class _BTypingUndoBuffer_ : public _BUndoBuffer_ class _BTypingUndoBuffer_ : public _BUndoBuffer_ {
{
public: public:
_BTypingUndoBuffer_(BTextView *); _BTypingUndoBuffer_(BTextView *);
~_BTypingUndoBuffer_(); ~_BTypingUndoBuffer_();
void InputCharacter(int32); void InputCharacter(int32);
void BackwardErase(); void BackwardErase();
void ForwardErase(); void ForwardErase();
protected: protected:
virtual void RedoSelf(BClipboard *); virtual void RedoSelf(BClipboard *);
virtual void UndoSelf(BClipboard *); virtual void UndoSelf(BClipboard *);
private: private:
void Reset(); void Reset();