diff --git a/libs/librunview/Emoconfig.cpp b/libs/librunview/Emoconfig.cpp index 07760bd..c40ede1 100644 --- a/libs/librunview/Emoconfig.cpp +++ b/libs/librunview/Emoconfig.cpp @@ -10,183 +10,153 @@ #include "SmileTextRender.h" //tmp -BMessage* faces=NULL; -bool valid=false; -bool fname=false; -bool svg=false; -bool size=true; +BMessage* faces = NULL; +bool valid = false; +bool fname = false; +bool svg = false; +bool size = true; BString filename; BString face; BPath path; BString gCharacters; -Emoconfig::Emoconfig(const char* xmlfile):BMessage() +Emoconfig::Emoconfig(const char* xmlfile): BMessage() { fEmoticonSize = 16.0; //default - numfaces=0; - + numfaces = 0; + fParser = XML_ParserCreate(NULL); XML_SetUserData(fParser, this); XML_SetElementHandler(fParser, StartElement, EndElement); XML_SetCharacterDataHandler(fParser, Characters); - + //path! BPath p(xmlfile); p.GetParent(&path); - + // loading the config file.. - BFile* settings=new BFile(xmlfile,B_READ_ONLY); + BFile* settings = new BFile(xmlfile, B_READ_ONLY); off_t size; settings->GetSize(&size); - if(size) - { - void *buffer=malloc(size); - size=settings->Read(buffer,size); + if (size) { + void* buffer = malloc(size); + size = settings->Read(buffer, size); XML_Parse(fParser, (const char*)buffer, size, true); free(buffer); } delete settings; - - if(fParser) + + if (fParser) XML_ParserFree(fParser); - + printf("Emoconfig: loaded %d faces\n", numfaces); } Emoconfig::~Emoconfig() { - + } -void -Emoconfig::StartElement(void * /*pUserData*/, const char * pName, const char ** /*pAttr*/) +void +Emoconfig::StartElement(void * /*pUserData*/, const char* pName, const char** /*pAttr*/) { //printf("StartElement %s\n",pName); BString name(pName); - if(name.ICompare("emoticon")==0) - { - faces=new BMessage(); - svg=false; - } - else - if(name.ICompare("text")==0 && faces) - { - valid=true; - } - else - if(name.ICompare("file")==0 && faces) - { - fname=true; - } else - if(name.ICompare("svg")==0 && faces) - { -// printf("File is SVG\n"); - svg=true; - } else - if(name.ICompare("size")==0) - { - size=true; + if (name.ICompare("emoticon") == 0) { + faces = new BMessage(); + svg = false; + } else if (name.ICompare("text") == 0 && faces) { + valid = true; + } else if (name.ICompare("file") == 0 && faces) { + fname = true; + } else if (name.ICompare("svg") == 0 && faces) { + // printf("File is SVG\n"); + svg = true; + } else if (name.ICompare("size") == 0) { + size = true; gCharacters = ""; } } -void -Emoconfig::EndElement(void * pUserData, const char * pName) +void +Emoconfig::EndElement(void* pUserData, const char* pName) { //printf("EndElement %s\n",pName); BString name(pName); - - if(name.ICompare("emoticon")==0 && faces) - { + + if (name.ICompare("emoticon") == 0 && faces) { //faces->PrintToStream(); //debug delete faces; - faces=NULL; - - } - else - if(name.ICompare("text")==0 && faces) - { - valid=false; - faces->AddString("face",face); + faces = NULL; + + } else if (name.ICompare("text") == 0 && faces) { + valid = false; + faces->AddString("face", face); //printf("to ]%s[\n",face.String()); face.SetTo(""); - - } - else - if(name.ICompare("file")==0 && faces) - { + + } else if (name.ICompare("file") == 0 && faces) { //load file - + //compose the filename BPath p(path); p.Append(filename.String()); - BBitmap *icons = NULL; - - if ( !svg ) - { // - icons=BTranslationUtils::GetBitmap(p.Path()); + BBitmap* icons = NULL; + + if ( !svg ) { + // + icons = BTranslationUtils::GetBitmap(p.Path()); } - + //assign to faces; - fname=false; - -// printf("Filename %s [%s]\n",p.Path(),path.Path()); - if(!icons) return; - - int i=0; + fname = false; + + // printf("Filename %s [%s]\n",p.Path(),path.Path()); + if (!icons) return; + + int i = 0; BString s; - while(faces->FindString("face",i,&s)==B_OK) - { - - if(i==0) - { - ((Emoconfig*)pUserData)->menu.AddPointer(s.String(),(const void*)icons); - ((Emoconfig*)pUserData)->menu.AddString("face",s.String()); + while (faces->FindString("face", i, &s) == B_OK) { + + if (i == 0) { + ((Emoconfig*)pUserData)->menu.AddPointer(s.String(), (const void*)icons); + ((Emoconfig*)pUserData)->menu.AddString("face", s.String()); } - ((BMessage*)pUserData)->AddPointer(s.String(),(const void*)icons); - ((BMessage*)pUserData)->AddString("face",s.String()); + ((BMessage*)pUserData)->AddPointer(s.String(), (const void*)icons); + ((BMessage*)pUserData)->AddString("face", s.String()); ((Emoconfig*)pUserData)->numfaces++; i++; - + } - - - } else - if(name.ICompare("size")==0) - { - if ( size ) - { + + + } else if (name.ICompare("size") == 0) { + if ( size ) { ((Emoconfig*)pUserData)->fEmoticonSize = atoi(gCharacters.String()); } - + size = false; } - + } -void -Emoconfig::Characters(void * /*pUserData*/, const char * pString, int pLen) +void +Emoconfig::Characters(void * /*pUserData*/, const char* pString, int pLen) { - BString f(pString,pLen); + BString f(pString, pLen); //printf("Characters %s\n",f.String()); - if(faces && valid) - { + if (faces && valid) { f.RemoveAll(" "); f.RemoveAll("\""); - if(f.Length()>0) - face.Append(f); - } - else - if(fname) - { + if (f.Length() > 0) + face.Append(f); + } else if (fname) { f.RemoveAll(" "); - filename=f; - - } - else - { + filename = f; + + } else { gCharacters.Append(f); } } diff --git a/libs/librunview/Emoconfig.h b/libs/librunview/Emoconfig.h index 03c324a..67ccc1d 100644 --- a/libs/librunview/Emoconfig.h +++ b/libs/librunview/Emoconfig.h @@ -8,23 +8,25 @@ class Emoconfig : public BMessage { - public: - Emoconfig(const char* xmlfile); - ~Emoconfig(); - int numfaces; - BMessage menu; - - float GetEmoticonSize() { return fEmoticonSize; } - - private: +public: + Emoconfig(const char* xmlfile); + ~Emoconfig(); + int numfaces; + BMessage menu; - float fEmoticonSize; - XML_Parser fParser; + float GetEmoticonSize() { + return fEmoticonSize; + } + +private: + + float fEmoticonSize; + XML_Parser fParser; + + static void StartElement(void* pUserData, const char* pName, const char** pAttr); + static void EndElement(void* pUserData, const char* pName); + static void Characters(void* pUserData, const char* pString, int pLen); - static void StartElement(void * pUserData, const char * pName, const char ** pAttr); - static void EndElement(void * pUserData, const char * pName); - static void Characters(void * pUserData, const char * pString, int pLen); - }; #endif diff --git a/libs/librunview/Emoticor.cpp b/libs/librunview/Emoticor.cpp index 9cc579b..65c8ac0 100644 --- a/libs/librunview/Emoticor.cpp +++ b/libs/librunview/Emoticor.cpp @@ -12,7 +12,7 @@ Emoticor::Get() { if (fInstance == NULL) fInstance = new Emoticor(); - + return fInstance; } @@ -28,7 +28,7 @@ Emoticor::~Emoticor() delete fConfig; } -Emoconfig* +Emoconfig* Emoticor::Config() { return fConfig; @@ -41,76 +41,71 @@ Emoticor::LoadConfig(const char* txt) } void -Emoticor::_findTokens(RunView *fTextView,BString text,int tokenstart, int16 cols ,int16 font ,int16 cols2 ,int16 font2) +Emoticor::_findTokens(RunView* fTextView, BString text, int tokenstart, int16 cols , int16 font , int16 cols2 , int16 font2) { //****************************************** // "Iteration is human, recursion is divine" //****************************************** - - + + int32 newindex = 0; BString cur; int i = tokenstart; - - if (fConfig != NULL) - { - while(fConfig->FindString("face",i,&cur)==B_OK) - //for(int i=tokenstart;inumfaces;i++) + + if (fConfig != NULL) { + while (fConfig->FindString("face", i, &cur) == B_OK) + //for(int i=tokenstart;inumfaces;i++) { - i++; + i++; //if(config->FindString("face",i,&cur)!=B_OK) return; - - newindex=0; - - while(true) - { - newindex=text.IFindFirst(cur.String(),0); - //printf("Try %d %s -- match %d\n",i,cur->original.String(),newindex); - - if(newindex!=B_ERROR) - { - //take a walk on the left side ;) - - //printf("Found at %ld \n",newindex); - - if(newindex-1>=0) - { - BString left; - text.CopyInto(left,0,newindex); - //printf("ready to recourse! [%s]\n",left.String()); - _findTokens(fTextView,left,tokenstart+1,cols,font,cols2,font2); - } - - - text.Remove(0,newindex+cur.Length()); - - //printf("remaning [%s] printed [%s]\n",text.String(),cur->original.String()); - - fTextView->Append(cur.String(),cols2,cols2,font2); - - if(text.Length()==0) return; //useless stack - } - else - break; - + + newindex = 0; + + while (true) { + newindex = text.IFindFirst(cur.String(), 0); + //printf("Try %d %s -- match %d\n",i,cur->original.String(),newindex); + + if (newindex != B_ERROR) { + //take a walk on the left side ;) + + //printf("Found at %ld \n",newindex); + + if (newindex - 1 >= 0) { + BString left; + text.CopyInto(left, 0, newindex); + //printf("ready to recourse! [%s]\n",left.String()); + _findTokens(fTextView, left, tokenstart + 1, cols, font, cols2, font2); + } + + + text.Remove(0, newindex + cur.Length()); + + //printf("remaning [%s] printed [%s]\n",text.String(),cur->original.String()); + + fTextView->Append(cur.String(), cols2, cols2, font2); + + if (text.Length() == 0) return; //useless stack + } else + break; + } } } - - fTextView->Append(text.String(),cols,cols,font); - + + fTextView->Append(text.String(), cols, cols, font); + } void -Emoticor::AddText(RunView *fTextView,const char * txt, int16 cols ,int16 font ,int16 cols2 ,int16 font2 ) +Emoticor::AddText(RunView* fTextView, const char* txt, int16 cols , int16 font , int16 cols2 , int16 font2 ) { - + BString left(txt); - -// if(!fConfig) -// fTextView->Append(txt,cols,cols,font); - - _findTokens(fTextView,left,0,cols,font,cols2,font2); + + // if(!fConfig) + // fTextView->Append(txt,cols,cols,font); + + _findTokens(fTextView, left, 0, cols, font, cols2, font2); return; diff --git a/libs/librunview/Emoticor.h b/libs/librunview/Emoticor.h index 4780b6a..796ebfb 100644 --- a/libs/librunview/Emoticor.h +++ b/libs/librunview/Emoticor.h @@ -8,23 +8,23 @@ class Emoticor { - public: - - static Emoticor* Get(); //singleton +public: + + static Emoticor* Get(); //singleton + + + void AddText(RunView* fTextView, const char* text, int16 cols , int16 font , int16 cols2 , int16 font2 ); + void LoadConfig(const char*); + + Emoconfig* Config(); + + ~Emoticor(); + +private: + Emoticor(); + Emoconfig* fConfig; + void _findTokens(RunView* fTextView, BString text, int tokenstart, int16 cols , int16 font , int16 cols2 , int16 font2); - - void AddText(RunView *fTextView,const char* text, int16 cols ,int16 font ,int16 cols2 ,int16 font2 ); - void LoadConfig(const char*); - - Emoconfig *Config(); - - ~Emoticor(); - - private: - Emoticor(); - Emoconfig* fConfig; - void _findTokens(RunView *fTextView,BString text,int tokenstart, int16 cols ,int16 font ,int16 cols2 ,int16 font2); - }; #endif diff --git a/libs/librunview/NormalTextRender.h b/libs/librunview/NormalTextRender.h index 90e68af..9b63e51 100644 --- a/libs/librunview/NormalTextRender.h +++ b/libs/librunview/NormalTextRender.h @@ -1,43 +1,46 @@ -#ifndef _NormalTextRender_H_ -#define _NormalTextRender_H_ - -#include "TextRender.h" -#include -#include - -#include - -class NormalTextRender : public TextRender -{ - public: - - NormalTextRender(BFont f):TextRender(){ - font=f; - } - virtual ~NormalTextRender() {}; - - virtual void Render(BView *target,const char* txt,int16 num,BPoint pos) { - - target->SetFont(&font); - target->DrawString(txt,num,pos); - - - }; - - - virtual float Size(){ return font.Size();} - - virtual void GetHeight(font_height *height){ font.GetHeight(height); }; - - - virtual void - GetEscapements(const char charArray[], int32 numChars,float escapementArray[]) - { - font.GetEscapements(charArray,numChars,escapementArray); - } - - private: - BFont font; - -}; -#endif +#ifndef _NormalTextRender_H_ +#define _NormalTextRender_H_ + +#include "TextRender.h" +#include +#include + +#include + +class NormalTextRender : public TextRender +{ +public: + + NormalTextRender(BFont f): TextRender() { + font = f; + } + virtual ~NormalTextRender() {}; + + virtual void Render(BView* target, const char* txt, int16 num, BPoint pos) { + + target->SetFont(&font); + target->DrawString(txt, num, pos); + + + }; + + + virtual float Size() { + return font.Size(); + } + + virtual void GetHeight(font_height* height) { + font.GetHeight(height); + }; + + + virtual void + GetEscapements(const char charArray[], int32 numChars, float escapementArray[]) { + font.GetEscapements(charArray, numChars, escapementArray); + } + +private: + BFont font; + +}; +#endif diff --git a/libs/librunview/ObjectList.h b/libs/librunview/ObjectList.h index a4655d0..8841dc7 100644 --- a/libs/librunview/ObjectList.h +++ b/libs/librunview/ObjectList.h @@ -73,52 +73,55 @@ template class BObjectList; template struct UnaryPredicate { - virtual int operator()(const T *) const - // virtual could be avoided here if FindBinaryInsertionIndex, - // etc. were member template functions - { return 0; } + virtual int operator()(const T*) const + // virtual could be avoided here if FindBinaryInsertionIndex, + // etc. were member template functions + { + return 0; + } private: - static int _unary_predicate_glue(const void *item, void *context); + static int _unary_predicate_glue(const void* item, void* context); -friend class BObjectList; + friend class BObjectList; }; template int -UnaryPredicate::_unary_predicate_glue(const void *item, void *context) +UnaryPredicate::_unary_predicate_glue(const void* item, void* context) { - return ((UnaryPredicate *)context)->operator()((const T *)item); + return ((UnaryPredicate *)context)->operator()((const T*)item); } -class _PointerList_ : public BList { +class _PointerList_ : public BList +{ public: _PointerList_(const _PointerList_ &list); _PointerList_(int32 itemsPerBlock = 20, bool owning = false); ~_PointerList_(); - typedef void *(* GenericEachFunction)(void *, void *); - typedef int (* GenericCompareFunction)(const void *, const void *); - typedef int (* GenericCompareFunctionWithState)(const void *, const void *, - void *); - typedef int (* UnaryPredicateGlue)(const void *, void *); + typedef void *(* GenericEachFunction)(void*, void*); + typedef int (* GenericCompareFunction)(const void*, const void*); + typedef int (* GenericCompareFunctionWithState)(const void*, const void*, + void*); + typedef int (* UnaryPredicateGlue)(const void*, void*); - void *EachElement(GenericEachFunction, void *); + void* EachElement(GenericEachFunction, void*); void SortItems(GenericCompareFunction); - void SortItems(GenericCompareFunctionWithState, void *state); + void SortItems(GenericCompareFunctionWithState, void* state); void HSortItems(GenericCompareFunction); - void HSortItems(GenericCompareFunctionWithState, void *state); + void HSortItems(GenericCompareFunctionWithState, void* state); - void *BinarySearch(const void *, GenericCompareFunction) const; - void *BinarySearch(const void *, GenericCompareFunctionWithState, void *state) const; + void* BinarySearch(const void*, GenericCompareFunction) const; + void* BinarySearch(const void*, GenericCompareFunctionWithState, void* state) const; - int32 BinarySearchIndex(const void *, GenericCompareFunction) const; - int32 BinarySearchIndex(const void *, GenericCompareFunctionWithState, void *state) const; - int32 BinarySearchIndexByPredicate(const void *, UnaryPredicateGlue) const; + int32 BinarySearchIndex(const void*, GenericCompareFunction) const; + int32 BinarySearchIndex(const void*, GenericCompareFunctionWithState, void* state) const; + int32 BinarySearchIndexByPredicate(const void*, UnaryPredicateGlue) const; bool Owning() const; - bool ReplaceItem(int32, void *); + bool ReplaceItem(int32, void*); protected: bool owning; @@ -126,124 +129,127 @@ protected: }; template -class BObjectList : private _PointerList_ { +class BObjectList : private _PointerList_ +{ public: // iteration and sorting - typedef T *(* EachFunction)(T *, void *); - typedef const T *(* ConstEachFunction)(const T *, void *); - typedef int (* CompareFunction)(const T *, const T *); - typedef int (* CompareFunctionWithState)(const T *, const T *, void *state); + typedef T *(* EachFunction)(T*, void*); + typedef const T *(* ConstEachFunction)(const T*, void*); + typedef int (* CompareFunction)(const T*, const T*); + typedef int (* CompareFunctionWithState)(const T*, const T*, void* state); BObjectList(int32 itemsPerBlock = 20, bool owning = false); - BObjectList(const BObjectList &list); - // clones list; if list is owning, makes copies of all - // the items + BObjectList(const BObjectList& list); + // clones list; if list is owning, makes copies of all + // the items virtual ~BObjectList(); - BObjectList &operator=(const BObjectList &list); - // clones list; if list is owning, makes copies of all - // the items + BObjectList& operator=(const BObjectList& list); + // clones list; if list is owning, makes copies of all + // the items // adding and removing // ToDo: // change Add calls to return const item - bool AddItem(T *); - bool AddItem(T *, int32); - bool AddList(BObjectList *); - bool AddList(BObjectList *, int32); + bool AddItem(T*); + bool AddItem(T*, int32); + bool AddList(BObjectList*); + bool AddList(BObjectList*, int32); - bool RemoveItem(T *, bool deleteIfOwning = true); - // if owning, deletes the removed item - T *RemoveItemAt(int32); - // returns the removed item + bool RemoveItem(T*, bool deleteIfOwning = true); + // if owning, deletes the removed item + T* RemoveItemAt(int32); + // returns the removed item void MakeEmpty(); // item access - T *ItemAt(int32) const; + T* ItemAt(int32) const; - bool ReplaceItem(int32 index, T *); - // if list is owning, deletes the item at first - T *SwapWithItem(int32 index, T *newItem); - // same as ReplaceItem, except does not delete old item at , - // returns it instead + bool ReplaceItem(int32 index, T*); + // if list is owning, deletes the item at first + T* SwapWithItem(int32 index, T* newItem); + // same as ReplaceItem, except does not delete old item at , + // returns it instead - T *FirstItem() const; - T *LastItem() const; + T* FirstItem() const; + T* LastItem() const; // misc. getters - int32 IndexOf(const T *) const; - bool HasItem(const T *) const; + int32 IndexOf(const T*) const; + bool HasItem(const T*) const; bool IsEmpty() const; int32 CountItems() const; - T *EachElement(EachFunction, void *); - const T *EachElement(ConstEachFunction, void *) const; + T* EachElement(EachFunction, void*); + const T* EachElement(ConstEachFunction, void*) const; void SortItems(CompareFunction); - void SortItems(CompareFunctionWithState, void *state); + void SortItems(CompareFunctionWithState, void* state); void HSortItems(CompareFunction); - void HSortItems(CompareFunctionWithState, void *state); + void HSortItems(CompareFunctionWithState, void* state); // linear search, returns first item that matches predicate - const T *FindIf(const UnaryPredicate &) const; - T *FindIf(const UnaryPredicate &); + const T* FindIf(const UnaryPredicate &) const; + T* FindIf(const UnaryPredicate &); // list must be sorted with CompareFunction for these to work - T *BinarySearch(const T &, CompareFunction) const; - T *BinarySearch(const T &, CompareFunctionWithState, void *state) const; + T* BinarySearch(const T&, CompareFunction) const; + T* BinarySearch(const T&, CompareFunctionWithState, void* state) const; template - T *BinarySearchByKey(const Key &key, int (*compare)(const Key *, const T *)) - const; + T* BinarySearchByKey(const Key& key, int (*compare)(const Key*, const T*)) + const; template - T *BinarySearchByKey(const Key &key, - int (*compare)(const Key *, const T *, void *), void *state) const; + T* BinarySearchByKey(const Key& key, + int (*compare)(const Key*, const T*, void*), void* state) const; - int32 BinarySearchIndex(const T &item, CompareFunction compare) const; - int32 BinarySearchIndex(const T &item, CompareFunctionWithState compare, - void *state) const; + int32 BinarySearchIndex(const T& item, CompareFunction compare) const; + int32 BinarySearchIndex(const T& item, CompareFunctionWithState compare, + void* state) const; template - int32 BinarySearchIndexByKey(const Key &key, - int (*compare)(const Key *, const T *)) const; + int32 BinarySearchIndexByKey(const Key& key, + int (*compare)(const Key*, const T*)) const; // Binary insertion - list must be sorted with CompareFunction for // these to work // simple insert - bool BinaryInsert(T *, CompareFunction); - bool BinaryInsert(T *, CompareFunctionWithState, void *state); - bool BinaryInsert(T *, const UnaryPredicate &); + bool BinaryInsert(T*, CompareFunction); + bool BinaryInsert(T*, CompareFunctionWithState, void* state); + bool BinaryInsert(T*, const UnaryPredicate &); // unique insert, returns false if item already in list - bool BinaryInsertUnique(T *, CompareFunction); - bool BinaryInsertUnique(T *, CompareFunctionWithState, void *state); - bool BinaryInsertUnique(T *, const UnaryPredicate &); + bool BinaryInsertUnique(T*, CompareFunction); + bool BinaryInsertUnique(T*, CompareFunctionWithState, void* state); + bool BinaryInsertUnique(T*, const UnaryPredicate &); // insert a copy of the item, returns new inserted item - T *BinaryInsertCopy(const T ©This, CompareFunction); - T *BinaryInsertCopy(const T ©This, CompareFunctionWithState, void *state); + T* BinaryInsertCopy(const T& copyThis, CompareFunction); + T* BinaryInsertCopy(const T& copyThis, CompareFunctionWithState, void* state); // insert a copy of the item if not in list already // returns new inserted item or existing item in case of a conflict - T *BinaryInsertCopyUnique(const T ©This, CompareFunction); - T *BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState, void *state); + T* BinaryInsertCopyUnique(const T& copyThis, CompareFunction); + T* BinaryInsertCopyUnique(const T& copyThis, CompareFunctionWithState, void* state); - int32 FindBinaryInsertionIndex(const UnaryPredicate &, bool *alreadyInList = 0) const; - // returns either the index into which a new item should be inserted - // or index of an existing item that matches the predicate + int32 FindBinaryInsertionIndex(const UnaryPredicate &, bool* alreadyInList = 0) const; + // returns either the index into which a new item should be inserted + // or index of an existing item that matches the predicate // deprecated API, will go away - BList *AsBList() - { return this; } - const BList *AsBList() const - { return this; } + BList* AsBList() { + return this; + } + const BList* AsBList() const { + return this; + } private: - void SetItem(int32, T *); + void SetItem(int32, T*); }; template @@ -262,7 +268,7 @@ WhileEachListItem(BObjectList *list, Result (Item::*func)(Param1), Param1 template Result -WhileEachListItem(BObjectList *list, Result (*func)(Item *, Param1), Param1 p1) +WhileEachListItem(BObjectList *list, Result (*func)(Item*, Param1), Param1 p1) { Result result = 0; int32 count = list->CountItems(); @@ -277,7 +283,7 @@ WhileEachListItem(BObjectList *list, Result (*func)(Item *, Param1), Param template Result WhileEachListItem(BObjectList *list, Result (Item::*func)(Param1, Param2), - Param1 p1, Param2 p2) + Param1 p1, Param2 p2) { Result result = 0; int32 count = list->CountItems(); @@ -291,8 +297,8 @@ WhileEachListItem(BObjectList *list, Result (Item::*func)(Param1, Param2), template Result -WhileEachListItem(BObjectList *list, Result (*func)(Item *, Param1, Param2), - Param1 p1, Param2 p2) +WhileEachListItem(BObjectList *list, Result (*func)(Item*, Param1, Param2), + Param1 p1, Param2 p2) { Result result = 0; int32 count = list->CountItems(); @@ -306,8 +312,8 @@ WhileEachListItem(BObjectList *list, Result (*func)(Item *, Param1, Param2 template Result -WhileEachListItem(BObjectList *list, Result (*func)(Item *, Param1, Param2, - Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4) +WhileEachListItem(BObjectList *list, Result (*func)(Item*, Param1, Param2, + Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4) { Result result = 0; int32 count = list->CountItems(); @@ -330,7 +336,7 @@ EachListItemIgnoreResult(BObjectList *list, Result (Item::*func)()) template void -EachListItem(BObjectList *list, void (*func)(Item *, Param1), Param1 p1) +EachListItem(BObjectList *list, void (*func)(Item*, Param1), Param1 p1) { int32 count = list->CountItems(); for (int32 index = 0; index < count; index++) @@ -340,7 +346,7 @@ EachListItem(BObjectList *list, void (*func)(Item *, Param1), Param1 p1) template void EachListItem(BObjectList *list, void (Item::*func)(Param1, Param2), - Param1 p1, Param2 p2) + Param1 p1, Param2 p2) { int32 count = list->CountItems(); for (int32 index = 0; index < count; index++) @@ -349,8 +355,8 @@ EachListItem(BObjectList *list, void (Item::*func)(Param1, Param2), template void -EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2), - Param1 p1, Param2 p2) +EachListItem(BObjectList *list, void (*func)(Item*, Param1, Param2), + Param1 p1, Param2 p2) { int32 count = list->CountItems(); for (int32 index = 0; index < count; index++) @@ -359,8 +365,8 @@ EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2), template void -EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2, - Param3), Param1 p1, Param2 p2, Param3 p3) +EachListItem(BObjectList *list, void (*func)(Item*, Param1, Param2, + Param3), Param1 p1, Param2 p2, Param3 p3) { int32 count = list->CountItems(); for (int32 index = 0; index < count; index++) @@ -370,8 +376,8 @@ EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2, template void -EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2, - Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4) +EachListItem(BObjectList *list, void (*func)(Item*, Param1, Param2, + Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4) { int32 count = list->CountItems(); for (int32 index = 0; index < count; index++) @@ -401,7 +407,7 @@ BObjectList::BObjectList(const BObjectList &list) // make our own copies in an owning list int32 count = list.CountItems(); for (int32 index = 0; index < count; index++) { - T *item = list.ItemAt(index); + T* item = list.ItemAt(index); if (item) item = new T(*item); SetItem(index, item); @@ -427,7 +433,7 @@ BObjectList::operator=(const BObjectList &list) // make our own copies in an owning list int32 count = list.CountItems(); for (int32 index = 0; index < count; index++) { - T *item = list.ItemAt(index); + T* item = list.ItemAt(index); if (item) item = new T(*item); SetItem(index, item); @@ -438,17 +444,17 @@ BObjectList::operator=(const BObjectList &list) template bool -BObjectList::AddItem(T *item) +BObjectList::AddItem(T* item) { // need to cast to void * to make T work for const pointers - return _PointerList_::AddItem((void *)item); + return _PointerList_::AddItem((void*)item); } template bool -BObjectList::AddItem(T *item, int32 atIndex) +BObjectList::AddItem(T* item, int32 atIndex) { - return _PointerList_::AddItem((void *)item, atIndex); + return _PointerList_::AddItem((void*)item, atIndex); } template @@ -468,9 +474,9 @@ BObjectList::AddList(BObjectList *newItems, int32 atIndex) template bool -BObjectList::RemoveItem(T *item, bool deleteIfOwning) +BObjectList::RemoveItem(T* item, bool deleteIfOwning) { - bool result = _PointerList_::RemoveItem((void *)item); + bool result = _PointerList_::RemoveItem((void*)item); if (result && Owning() && deleteIfOwning) delete item; @@ -482,67 +488,67 @@ template T * BObjectList::RemoveItemAt(int32 index) { - return (T *)_PointerList_::RemoveItem(index); + return (T*)_PointerList_::RemoveItem(index); } template inline T * BObjectList::ItemAt(int32 index) const { - return (T *)_PointerList_::ItemAt(index); + return (T*)_PointerList_::ItemAt(index); } template bool -BObjectList::ReplaceItem(int32 index, T *item) +BObjectList::ReplaceItem(int32 index, T* item) { if (owning) delete ItemAt(index); - return _PointerList_::ReplaceItem(index, (void *)item); + return _PointerList_::ReplaceItem(index, (void*)item); } template T * -BObjectList::SwapWithItem(int32 index, T *newItem) +BObjectList::SwapWithItem(int32 index, T* newItem) { - T *result = ItemAt(index); - _PointerList_::ReplaceItem(index, (void *)newItem); + T* result = ItemAt(index); + _PointerList_::ReplaceItem(index, (void*)newItem); return result; } template void -BObjectList::SetItem(int32 index, T *newItem) +BObjectList::SetItem(int32 index, T* newItem) { - _PointerList_::ReplaceItem(index, (void *)newItem); + _PointerList_::ReplaceItem(index, (void*)newItem); } template int32 -BObjectList::IndexOf(const T *item) const +BObjectList::IndexOf(const T* item) const { - return _PointerList_::IndexOf((void *)item); + return _PointerList_::IndexOf((void*)item); } template T * BObjectList::FirstItem() const { - return (T *)_PointerList_::FirstItem(); + return (T*)_PointerList_::FirstItem(); } template T * BObjectList::LastItem() const { - return (T *)_PointerList_::LastItem(); + return (T*)_PointerList_::LastItem(); } template bool -BObjectList::HasItem(const T *item) const +BObjectList::HasItem(const T* item) const { - return _PointerList_::HasItem((void *)item); + return _PointerList_::HasItem((void*)item); } template @@ -573,19 +579,19 @@ BObjectList::MakeEmpty() template T * -BObjectList::EachElement(EachFunction func, void *params) +BObjectList::EachElement(EachFunction func, void* params) { - return (T *)_PointerList_::EachElement((GenericEachFunction)func, params); + return (T*)_PointerList_::EachElement((GenericEachFunction)func, params); } template const T * -BObjectList::EachElement(ConstEachFunction func, void *params) const +BObjectList::EachElement(ConstEachFunction func, void* params) const { - return (const T *) - const_cast *>(this)->_PointerList_::EachElement( - (GenericEachFunction)func, params); + return (const T*) + const_cast *>(this)->_PointerList_::EachElement( + (GenericEachFunction)func, params); } template @@ -620,7 +626,7 @@ BObjectList::SortItems(CompareFunction function) template void -BObjectList::SortItems(CompareFunctionWithState function, void *state) +BObjectList::SortItems(CompareFunctionWithState function, void* state) { _PointerList_::SortItems((GenericCompareFunctionWithState)function, state); } @@ -634,86 +640,86 @@ BObjectList::HSortItems(CompareFunction function) template void -BObjectList::HSortItems(CompareFunctionWithState function, void *state) +BObjectList::HSortItems(CompareFunctionWithState function, void* state) { _PointerList_::HSortItems((GenericCompareFunctionWithState)function, state); } template T * -BObjectList::BinarySearch(const T &key, CompareFunction func) const +BObjectList::BinarySearch(const T& key, CompareFunction func) const { return (T*)_PointerList_::BinarySearch(&key, - (GenericCompareFunction)func); + (GenericCompareFunction)func); } template T * -BObjectList::BinarySearch(const T &key, CompareFunctionWithState func, void *state) const +BObjectList::BinarySearch(const T& key, CompareFunctionWithState func, void* state) const { return (T*)_PointerList_::BinarySearch(&key, - (GenericCompareFunctionWithState)func, state); + (GenericCompareFunctionWithState)func, state); } template template T * -BObjectList::BinarySearchByKey(const Key &key, - int (*compare)(const Key *, const T *)) const +BObjectList::BinarySearchByKey(const Key& key, + int (*compare)(const Key*, const T*)) const { return (T*)_PointerList_::BinarySearch(&key, - (GenericCompareFunction)compare); + (GenericCompareFunction)compare); } template template T * -BObjectList::BinarySearchByKey(const Key &key, - int (*compare)(const Key *, const T *, void *), void *state) const +BObjectList::BinarySearchByKey(const Key& key, + int (*compare)(const Key*, const T*, void*), void* state) const { return (T*)_PointerList_::BinarySearch(&key, - (GenericCompareFunctionWithState)compare, state); + (GenericCompareFunctionWithState)compare, state); } template int32 -BObjectList::BinarySearchIndex(const T &item, CompareFunction compare) const +BObjectList::BinarySearchIndex(const T& item, CompareFunction compare) const { return _PointerList_::BinarySearchIndex(&item, - (GenericCompareFunction)compare); + (GenericCompareFunction)compare); } template int32 -BObjectList::BinarySearchIndex(const T &item, - CompareFunctionWithState compare, void *state) const +BObjectList::BinarySearchIndex(const T& item, + CompareFunctionWithState compare, void* state) const { return _PointerList_::BinarySearchIndex(&item, - (GenericCompareFunctionWithState)compare, state); + (GenericCompareFunctionWithState)compare, state); } template template int32 -BObjectList::BinarySearchIndexByKey(const Key &key, - int (*compare)(const Key *, const T *)) const +BObjectList::BinarySearchIndexByKey(const Key& key, + int (*compare)(const Key*, const T*)) const { return _PointerList_::BinarySearchIndex(&key, - (GenericCompareFunction)compare); + (GenericCompareFunction)compare); } template bool -BObjectList::BinaryInsert(T *item, CompareFunction func) +BObjectList::BinaryInsert(T* item, CompareFunction func) { int32 index = _PointerList_::BinarySearchIndex(item, - (GenericCompareFunction)func); + (GenericCompareFunction)func); if (index >= 0) { // already in list, add after existing return AddItem(item, index + 1); @@ -724,10 +730,10 @@ BObjectList::BinaryInsert(T *item, CompareFunction func) template bool -BObjectList::BinaryInsert(T *item, CompareFunctionWithState func, void *state) +BObjectList::BinaryInsert(T* item, CompareFunctionWithState func, void* state) { int32 index = _PointerList_::BinarySearchIndex(item, - (GenericCompareFunctionWithState)func, state); + (GenericCompareFunctionWithState)func, state); if (index >= 0) { // already in list, add after existing return AddItem(item, index + 1); @@ -738,10 +744,10 @@ BObjectList::BinaryInsert(T *item, CompareFunctionWithState func, void *state template bool -BObjectList::BinaryInsertUnique(T *item, CompareFunction func) +BObjectList::BinaryInsertUnique(T* item, CompareFunction func) { int32 index = _PointerList_::BinarySearchIndex(item, - (GenericCompareFunction)func); + (GenericCompareFunction)func); if (index >= 0) return false; @@ -750,10 +756,10 @@ BObjectList::BinaryInsertUnique(T *item, CompareFunction func) template bool -BObjectList::BinaryInsertUnique(T *item, CompareFunctionWithState func, void *state) +BObjectList::BinaryInsertUnique(T* item, CompareFunctionWithState func, void* state) { int32 index = _PointerList_::BinarySearchIndex(item, - (GenericCompareFunctionWithState)func, state); + (GenericCompareFunctionWithState)func, state); if (index >= 0) return false; @@ -763,76 +769,76 @@ BObjectList::BinaryInsertUnique(T *item, CompareFunctionWithState func, void template T * -BObjectList::BinaryInsertCopy(const T ©This, CompareFunction func) +BObjectList::BinaryInsertCopy(const T& copyThis, CompareFunction func) { int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunction)func); + (GenericCompareFunction)func); if (index >= 0) index++; else index = -index - 1; - T *newItem = new T(copyThis); + T* newItem = new T(copyThis); AddItem(newItem, index); return newItem; } template T * -BObjectList::BinaryInsertCopy(const T ©This, CompareFunctionWithState func, void *state) +BObjectList::BinaryInsertCopy(const T& copyThis, CompareFunctionWithState func, void* state) { int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunctionWithState)func, state); + (GenericCompareFunctionWithState)func, state); if (index >= 0) index++; else index = -index - 1; - T *newItem = new T(copyThis); + T* newItem = new T(copyThis); AddItem(newItem, index); return newItem; } template T * -BObjectList::BinaryInsertCopyUnique(const T ©This, CompareFunction func) +BObjectList::BinaryInsertCopyUnique(const T& copyThis, CompareFunction func) { int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunction)func); + (GenericCompareFunction)func); if (index >= 0) return ItemAt(index); index = -index - 1; - T *newItem = new T(copyThis); + T* newItem = new T(copyThis); AddItem(newItem, index); return newItem; } template T * -BObjectList::BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState func, - void *state) +BObjectList::BinaryInsertCopyUnique(const T& copyThis, CompareFunctionWithState func, + void* state) { int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunctionWithState)func, state); + (GenericCompareFunctionWithState)func, state); if (index >= 0) return ItemAt(index); index = -index - 1; - T *newItem = new T(copyThis); + T* newItem = new T(copyThis); AddItem(newItem, index); return newItem; } template int32 -BObjectList::FindBinaryInsertionIndex(const UnaryPredicate &pred, bool *alreadyInList) - const +BObjectList::FindBinaryInsertionIndex(const UnaryPredicate &pred, bool* alreadyInList) +const { int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred, - (UnaryPredicateGlue)&UnaryPredicate::_unary_predicate_glue); + (UnaryPredicateGlue)&UnaryPredicate::_unary_predicate_glue); if (alreadyInList) *alreadyInList = index >= 0; @@ -845,14 +851,14 @@ BObjectList::FindBinaryInsertionIndex(const UnaryPredicate &pred, bool *al template bool -BObjectList::BinaryInsert(T *item, const UnaryPredicate &pred) +BObjectList::BinaryInsert(T* item, const UnaryPredicate &pred) { return AddItem(item, FindBinaryInsertionIndex(pred)); } template bool -BObjectList::BinaryInsertUnique(T *item, const UnaryPredicate &pred) +BObjectList::BinaryInsertUnique(T* item, const UnaryPredicate &pred) { bool alreadyInList; int32 index = FindBinaryInsertionIndex(pred, &alreadyInList); diff --git a/libs/librunview/RunView.cpp b/libs/librunview/RunView.cpp index f93e51c..9d28d20 100644 --- a/libs/librunview/RunView.cpp +++ b/libs/librunview/RunView.cpp @@ -66,154 +66,149 @@ // cursor data for hovering over URLs -static unsigned char URLCursorData[] = {16,1,2,2, - 0,0,0,0,56,0,36,0,36,0,19,224,18,92,9,42, - 8,1,60,33,76,49,66,121,48,125,12,253,2,0,1,0, - 0,0,0,0,56,0,60,0,60,0,31,224,31,252,15,254, - 15,255,63,255,127,255,127,255,63,255,15,255,3,254,1,248 +static unsigned char URLCursorData[] = {16, 1, 2, 2, + 0, 0, 0, 0, 56, 0, 36, 0, 36, 0, 19, 224, 18, 92, 9, 42, + 8, 1, 60, 33, 76, 49, 66, 121, 48, 125, 12, 253, 2, 0, 1, 0, + 0, 0, 0, 0, 56, 0, 60, 0, 60, 0, 31, 224, 31, 252, 15, 254, + 15, 255, 63, 255, 127, 255, 127, 255, 63, 255, 15, 255, 3, 254, 1, 248 + }; + +struct SoftBreak { + int16 fOffset; + float fHeight; + float fAscent; }; -struct SoftBreak -{ - int16 fOffset; - float fHeight; - float fAscent; -}; +struct URL { + int32 fOffset; + int32 fLength; + BString fUrl; -struct URL -{ - int32 fOffset; - int32 fLength; - BString fUrl; - - URL (const char *address, int32 off, int32 len) : - fOffset (off), - fLength (len), - fUrl (address) - { } + URL (const char* address, int32 off, int32 len) : + fOffset (off), + fLength (len), + fUrl (address) + { } }; typedef BObjectList urllist; -struct SoftBreakEnd -{ - int16 fOffset; +struct SoftBreakEnd { + int16 fOffset; - SoftBreakEnd (int16 offset) - : fOffset (offset) - { } + SoftBreakEnd (int16 offset) + : fOffset (offset) + { } }; -struct FontColor -{ - int16 fOffset; - // G++ is stupid. We only need 2 bits - // for fWhich, but the compiler has a bug - // and warns us against fWhich == 2 - int16 fWhich : 3; - int16 fIndex : 13; +struct FontColor { + int16 fOffset; + // G++ is stupid. We only need 2 bits + // for fWhich, but the compiler has a bug + // and warns us against fWhich == 2 + int16 fWhich : 3; + int16 fIndex : 13; }; -struct Line -{ - char *fText; - time_t fStamp; - urllist *fUrls; - int16 *fSpaces; - int16 *fEdges; - FontColor *fFcs; - SoftBreak *fSofties; - float fTop; - float fBottom; +struct Line { + char* fText; + time_t fStamp; + urllist* fUrls; + int16* fSpaces; + int16* fEdges; + FontColor* fFcs; + SoftBreak* fSofties; + float fTop; + float fBottom; - int16 fLength; - int16 fSpace_count; - int16 fEdge_count; - int16 fFc_count; - int16 fSoftie_size; - int16 fSoftie_used; + int16 fLength; + int16 fSpace_count; + int16 fEdge_count; + int16 fFc_count; + int16 fSoftie_size; + int16 fSoftie_used; - Line ( - const char *buffer, - int16 fLength, - float top, - float width, - Theme *fTheme, - const char *fStamp_format, - int16 fore, - int16 back, - int16 font); + Line ( + const char* buffer, + int16 fLength, + float top, + float width, + Theme* fTheme, + const char* fStamp_format, + int16 fore, + int16 back, + int16 font); - ~Line (void); + ~Line (void); - void Append ( - const char *buffer, - int16 len, - float width, - Theme *fTheme, - int16 fore, - int16 back, - int16 font); + void Append ( + const char* buffer, + int16 len, + float width, + Theme* fTheme, + int16 fore, + int16 back, + int16 font); - void FigureSpaces (void); + void FigureSpaces (void); - void FigureFontColors ( - int16 pos, - int16 fore, - int16 back, - int16 font); + void FigureFontColors ( + int16 pos, + int16 fore, + int16 back, + int16 font); - void FigureEdges ( - Theme *fTheme, - float width); + void FigureEdges ( + Theme* fTheme, + float width); - void SoftBreaks ( - Theme * fTheme, - float width); + void SoftBreaks ( + Theme* fTheme, + float width); - void AddSoftBreak (SoftBreakEnd , float &, - uint16 &, int16 &, float &, float &, Theme *); + void AddSoftBreak (SoftBreakEnd , float&, + uint16&, int16&, float&, float&, Theme*); - int16 CountChars (int16 pos, int16 len); - size_t SetStamp (const char *, bool); + int16 CountChars (int16 pos, int16 len); + size_t SetStamp (const char*, bool); - void SelectWord (int16 *, int16 *); + void SelectWord (int16*, int16*); }; inline int32 UTF8_CHAR_LEN (uchar c) { - return (((0xE5000000 >> (((c) >> 3) & 0x1E)) & 3) + 1); + return (((0xE5000000 >> (((c) >> 3) & 0x1E)) & 3) + 1); } RunView::RunView ( - BRect frame, - const char *name, - Theme *theme, - uint32 resizingMode, - uint32 flags) - : BView ( - frame, - name, - resizingMode, - flags | B_WILL_DRAW | B_FRAME_EVENTS), - fScroller (NULL), - fTheme (theme), - fWorking (NULL), - fLine_count (0), - fStamp_format (NULL), - fClipping_name (NULL), - fSp_start (0, 0), - fSp_end (0, 0), - fTracking (0), - fTrack_offset (0, 0), - fOff_view_runner (NULL), - fOff_view_time (0), - fResizedirty (false), - fFontsdirty (false), - fMyPopUp (NULL), - fLastClick (0,0), - fLastClickTime (0) + BRect frame, + const char* name, + Theme* theme, + uint32 resizingMode, + uint32 flags) + : BView ( + frame, + name, + resizingMode, + flags | B_WILL_DRAW | B_FRAME_EVENTS), + fScroller (NULL), + fTheme (theme), + fWorking (NULL), + fLine_count (0), + fStamp_format (NULL), + fClipping_name (NULL), + fSp_start (0, 0), + fSp_end (0, 0), + fTracking (0), + fTrack_offset (0, 0), + fOff_view_runner (NULL), + fOff_view_time (0), + fResizedirty (false), + fFontsdirty (false), + fMyPopUp (NULL), + fLastClick (0, 0), + fLastClickTime (0) { memset (fLines, 0, sizeof (fLines)); @@ -229,2394 +224,2199 @@ RunView::RunView ( RunView::~RunView (void) { - for (int16 i = 0; i < fLine_count; ++i) - delete fLines[i]; + for (int16 i = 0; i < fLine_count; ++i) + delete fLines[i]; - delete fWorking; - delete fURLCursor; - delete [] fStamp_format; - delete [] fClipping_name; + delete fWorking; + delete fURLCursor; + delete [] fStamp_format; + delete [] fClipping_name; } void RunView::AttachedToWindow (void) { - BView::AttachedToWindow(); + BView::AttachedToWindow(); #if B_BEOS_VERSION_DANO - SetDoubleBuffering (B_UPDATE_INVALIDATED | B_UPDATE_SCROLLED | B_UPDATE_EXPOSED | B_UPDATE_RESIZED); + SetDoubleBuffering (B_UPDATE_INVALIDATED | B_UPDATE_SCROLLED | B_UPDATE_EXPOSED | B_UPDATE_RESIZED); #endif - RecalcScrollBar (false); - fTheme->WriteLock(); - fTheme->AddView (this); - fTheme->WriteUnlock(); + RecalcScrollBar (false); + fTheme->WriteLock(); + fTheme->AddView (this); + fTheme->WriteUnlock(); } void RunView::DetachedFromWindow (void) { - fTheme->WriteLock(); - fTheme->RemoveView (this); - fTheme->WriteUnlock(); + fTheme->WriteLock(); + fTheme->RemoveView (this); + fTheme->WriteUnlock(); } void RunView::FrameResized (float start_width, float height) { - BView::FrameResized (start_width, height); + BView::FrameResized (start_width, height); - if (IsHidden()) - { - fResizedirty = true; - return; - } - ResizeRecalc(); + if (IsHidden()) { + fResizedirty = true; + return; + } + ResizeRecalc(); } void -RunView::TargetedByScrollView (BScrollView *s) +RunView::TargetedByScrollView (BScrollView* s) { - fScroller = s; - BView::TargetedByScrollView (fScroller); + fScroller = s; + BView::TargetedByScrollView (fScroller); } void RunView::Show (void) { - if (fFontsdirty) - { - FontChangeRecalc(); - // this effectively does the same thing as resize so if both have changed, only - // do the fonts recalculation - fFontsdirty = false; - fResizedirty = false; - } - else if (fResizedirty) - { - ResizeRecalc(); - fResizedirty = false; - } - BView::Show(); + if (fFontsdirty) { + FontChangeRecalc(); + // this effectively does the same thing as resize so if both have changed, only + // do the fonts recalculation + fFontsdirty = false; + fResizedirty = false; + } else if (fResizedirty) { + ResizeRecalc(); + fResizedirty = false; + } + BView::Show(); } void RunView::Draw (BRect frame) { - TextRender *tr = NULL; - - Window()->DisableUpdates(); - Window()->BeginViewTransaction(); + TextRender* tr = NULL; - rgb_color low_color, hi_color, view_color, sel_color, sel_fText; - float height (frame.bottom); - BRect bounds (Bounds()); - BRegion clipper; - bool drawSelection (false); - bool checkSelection (fSp_start != fSp_end); + Window()->DisableUpdates(); + Window()->BeginViewTransaction(); - clipper.Set (frame); - ConstrainClippingRegion (&clipper); + rgb_color low_color, hi_color, view_color, sel_color, sel_fText; + float height (frame.bottom); + BRect bounds (Bounds()); + BRegion clipper; + bool drawSelection (false); + bool checkSelection (fSp_start != fSp_end); - fTheme->ReadLock(); - view_color = fTheme->BackgroundAt (Theme::NormalBack); + clipper.Set (frame); + ConstrainClippingRegion (&clipper); - sel_color = fTheme->BackgroundAt (Theme::SelectionBack); - if (((sel_color.red + sel_color.blue + sel_color.green) / 3) >= 127) - { - sel_fText.red = sel_fText.green = sel_fText.blue = 0; - sel_fText.alpha = 255; - } - else - { - sel_fText.red = sel_fText.green = sel_fText.blue = sel_fText.alpha = 255; - } - BRect remains; - if (fLine_count == 0) - remains = frame; - else if (frame.bottom >= fLines[fLine_count - 1]->fBottom + 1.0) - remains.Set ( - frame.left, - fLines[fLine_count - 1]->fBottom + 1.0, - frame.right, - frame.bottom); + fTheme->ReadLock(); + view_color = fTheme->BackgroundAt (Theme::NormalBack); - if (remains.IsValid()) - { - SetLowColor (view_color); - FillRect (remains, B_SOLID_LOW); - } + sel_color = fTheme->BackgroundAt (Theme::SelectionBack); + if (((sel_color.red + sel_color.blue + sel_color.green) / 3) >= 127) { + sel_fText.red = sel_fText.green = sel_fText.blue = 0; + sel_fText.alpha = 255; + } else { + sel_fText.red = sel_fText.green = sel_fText.blue = sel_fText.alpha = 255; + } + BRect remains; + if (fLine_count == 0) + remains = frame; + else if (frame.bottom >= fLines[fLine_count - 1]->fBottom + 1.0) + remains.Set ( + frame.left, + fLines[fLine_count - 1]->fBottom + 1.0, + frame.right, + frame.bottom); - for (int16 i = fLine_count - 1; i >= 0; --i) - { - Line *line (fLines[i]); - if (line->fBottom < frame.top) - break; + if (remains.IsValid()) { + SetLowColor (view_color); + FillRect (remains, B_SOLID_LOW); + } - BRect r (bounds.left, line->fTop, bounds.right, line->fBottom); + for (int16 i = fLine_count - 1; i >= 0; --i) { + Line* line (fLines[i]); + if (line->fBottom < frame.top) + break; - if (!frame.Intersects (r)) - continue; + BRect r (bounds.left, line->fTop, bounds.right, line->fBottom); - float indent (fTheme->TextMargin()); - int16 place (0); + if (!frame.Intersects (r)) + continue; - int16 fore (0); - int16 back (0); - int16 font (0); + float indent (fTheme->TextMargin()); + int16 place (0); - height = line->fTop; + int16 fore (0); + int16 back (0); + int16 font (0); - for (int16 sit = 0; sit < line->fSoftie_used; /*++sit*/sit++) - { - int16 last_len (UTF8_CHAR_LEN (line->fText[line->fSofties[sit].fOffset])); - float left (indent); - float start (0.0); + height = line->fTop; - // Fill indentation - SetLowColor (view_color); + for (int16 sit = 0; sit < line->fSoftie_used; /*++sit*/sit++) { + int16 last_len (UTF8_CHAR_LEN (line->fText[line->fSofties[sit].fOffset])); + float left (indent); + float start (0.0); - SetDrawingMode (B_OP_COPY); - r.Set (0.0, height, indent - 1.0, height + line->fSofties[sit].fHeight - 1.0); - FillRect (r, B_SOLID_LOW); + // Fill indentation + SetLowColor (view_color); - if (sit) - { - int16 j (place); + SetDrawingMode (B_OP_COPY); + r.Set (0.0, height, indent - 1.0, height + line->fSofties[sit].fHeight - 1.0); + FillRect (r, B_SOLID_LOW); - while (--j >= 0) - if ((start = line->fEdges[j]) != 0) - break; - } + if (sit) { + int16 j (place); - while (place < line->fSofties[sit].fOffset + last_len) - { - // Get current foreground color and set - while (fore < line->fFc_count) - { - if (line->fFcs[fore].fWhich == FORE_WHICH) - { - if (line->fFcs[fore].fOffset > place) - break; + while (--j >= 0) + if ((start = line->fEdges[j]) != 0) + break; + } - hi_color = fTheme->ForegroundAt (line->fFcs[fore].fIndex); - } + while (place < line->fSofties[sit].fOffset + last_len) { + // Get current foreground color and set + while (fore < line->fFc_count) { + if (line->fFcs[fore].fWhich == FORE_WHICH) { + if (line->fFcs[fore].fOffset > place) + break; - ++fore; - } + hi_color = fTheme->ForegroundAt (line->fFcs[fore].fIndex); + } - // Get current background color and set - while (back < line->fFc_count) - { - if (line->fFcs[back].fWhich == BACK_WHICH) - { - if (line->fFcs[back].fOffset > place) - break; + ++fore; + } + + // Get current background color and set + while (back < line->fFc_count) { + if (line->fFcs[back].fWhich == BACK_WHICH) { + if (line->fFcs[back].fOffset > place) + break; - low_color = fTheme->BackgroundAt (line->fFcs[back].fIndex); - } + low_color = fTheme->BackgroundAt (line->fFcs[back].fIndex); + } - ++back; - } + ++back; + } - // Get current font and set - while (font < line->fFc_count) - { - if (line->fFcs[font].fWhich == FONT_WHICH) - { - if (line->fFcs[font].fOffset > place) - break; + // Get current font and set + while (font < line->fFc_count) { + if (line->fFcs[font].fWhich == FONT_WHICH) { + if (line->fFcs[font].fOffset > place) + break; - //const BFont &f (fTheme->FontAt (line->fFcs[font].fIndex)); - tr = fTheme->TextRenderAt (line->fFcs[font].fIndex); - //SetFont (&f); - } + //const BFont &f (fTheme->FontAt (line->fFcs[font].fIndex)); + tr = fTheme->TextRenderAt (line->fFcs[font].fIndex); + //SetFont (&f); + } - ++font; - } + ++font; + } - int16 fLength (line->fSofties[sit].fOffset - place + last_len); + int16 fLength (line->fSofties[sit].fOffset - place + last_len); - if (fore < line->fFc_count - && line->fFcs[fore].fOffset - place < fLength) - fLength = line->fFcs[fore].fOffset - place; + if (fore < line->fFc_count + && line->fFcs[fore].fOffset - place < fLength) + fLength = line->fFcs[fore].fOffset - place; - if (back < line->fFc_count - && line->fFcs[back].fOffset - place < fLength) - fLength = line->fFcs[back].fOffset - place; + if (back < line->fFc_count + && line->fFcs[back].fOffset - place < fLength) + fLength = line->fFcs[back].fOffset - place; - if (font < line->fFc_count - && line->fFcs[font].fOffset - place < fLength) - fLength = line->fFcs[font].fOffset - place; + if (font < line->fFc_count + && line->fFcs[font].fOffset - place < fLength) + fLength = line->fFcs[font].fOffset - place; - if (checkSelection) - { - // case 1: current line marks beginning of selection - if (i == fSp_start.fLine) - { - // if we're just prior to the selection, clip fLength to only - // draw up to the selection start - if (place + fLength >= fSp_start.fOffset && place < fSp_start.fOffset) - { - fLength = fSp_start.fOffset - place; - drawSelection = false; - } - // we're at the selection, switch drawing color mode - else if (place >= fSp_start.fOffset) - { - if (fSp_end.fLine == fSp_start.fLine) - { - if (place < fSp_end.fOffset) - { - drawSelection = true; - if ((fSp_end.fOffset - place) < fLength) - fLength = fSp_end.fOffset - place; - } - else - drawSelection = false; - } - else - drawSelection = true; - } - else - drawSelection = false; + if (checkSelection) { + // case 1: current line marks beginning of selection + if (i == fSp_start.fLine) { + // if we're just prior to the selection, clip fLength to only + // draw up to the selection start + if (place + fLength >= fSp_start.fOffset && place < fSp_start.fOffset) { + fLength = fSp_start.fOffset - place; + drawSelection = false; + } + // we're at the selection, switch drawing color mode + else if (place >= fSp_start.fOffset) { + if (fSp_end.fLine == fSp_start.fLine) { + if (place < fSp_end.fOffset) { + drawSelection = true; + if ((fSp_end.fOffset - place) < fLength) + fLength = fSp_end.fOffset - place; + } else + drawSelection = false; + } else + drawSelection = true; + } else + drawSelection = false; - } - // case 2: line in between beginning and end of selection, - // highlight entire line - else if (i > fSp_start.fLine && i < fSp_end.fLine) - drawSelection = true; - // case 3: last line of selection, with multiple fLines in between - else if (i == fSp_end.fLine && i != fSp_start.fLine) - { - if (place < (fSp_end.fOffset)) - { - if (fSp_end.fOffset - place < fLength) - fLength = (fSp_end.fOffset - place); - drawSelection = true; - } - else - drawSelection = false; - } - else - drawSelection = false; - } + } + // case 2: line in between beginning and end of selection, + // highlight entire line + else if (i > fSp_start.fLine && i < fSp_end.fLine) + drawSelection = true; + // case 3: last line of selection, with multiple fLines in between + else if (i == fSp_end.fLine && i != fSp_start.fLine) { + if (place < (fSp_end.fOffset)) { + if (fSp_end.fOffset - place < fLength) + fLength = (fSp_end.fOffset - place); + drawSelection = true; + } else + drawSelection = false; + } else + drawSelection = false; + } - if (place + fLength == line->fLength) - --fLength; + if (place + fLength == line->fLength) + --fLength; - int16 k (place + fLength - 1); - while (line->fEdges[k] == 0) - --k; + int16 k (place + fLength - 1); + while (line->fEdges[k] == 0) + --k; - r.Set ( - left, - height, - line->fEdges[k] + indent - start, - height + line->fSofties[sit].fHeight - 1.0); + r.Set ( + left, + height, + line->fEdges[k] + indent - start, + height + line->fSofties[sit].fHeight - 1.0); - SetDrawingMode (B_OP_COPY); - if (drawSelection) - SetLowColor (sel_color); - else - SetLowColor (low_color); - SetHighColor (hi_color); - FillRect (r, B_SOLID_LOW); + SetDrawingMode (B_OP_COPY); + if (drawSelection) + SetLowColor (sel_color); + else + SetLowColor (low_color); + SetHighColor (hi_color); + FillRect (r, B_SOLID_LOW); - if (drawSelection) - SetHighColor (sel_fText); + if (drawSelection) + SetHighColor (sel_fText); - SetDrawingMode (B_OP_OVER); + SetDrawingMode (B_OP_OVER); - if ( sit >= line->fSoftie_used ) - { - printf("bah. sit is %d and fSoftie_used is %d\n", sit, line->fSoftie_used); - } else { + if ( sit >= line->fSoftie_used ) { + printf("bah. sit is %d and fSoftie_used is %d\n", sit, line->fSoftie_used); + } else { - tr->Render(this, - line->fText + place, - min_c (fLength, line->fLength - place - 1), - BPoint (left, height + line->fSofties[sit].fAscent)); + tr->Render(this, + line->fText + place, + min_c (fLength, line->fLength - place - 1), + BPoint (left, height + line->fSofties[sit].fAscent)); + } + + left = line->fEdges[k] + indent - start; + + if ((place += fLength) + 1 >= line->fLength) + ++place; + } + + + // Margin after fText + SetDrawingMode (B_OP_COPY); + SetLowColor (view_color); + FillRect ( + BRect ( + left + 1.0, + height, + bounds.right, + height + line->fSofties[sit].fHeight - 1.0), + B_SOLID_LOW); + + height += line->fSofties[sit].fHeight; + + if (sit == 0) + indent += fTheme->SoftLineIndent();//fSoftLineIndent; } + } - left = line->fEdges[k] + indent - start; - - if ((place += fLength) + 1 >= line->fLength) - ++place; - } - - - // Margin after fText - SetDrawingMode (B_OP_COPY); - SetLowColor (view_color); - FillRect ( - BRect ( - left + 1.0, - height, - bounds.right, - height + line->fSofties[sit].fHeight - 1.0), - B_SOLID_LOW); - - height += line->fSofties[sit].fHeight; - - if (sit == 0) - indent += fTheme->SoftLineIndent();//fSoftLineIndent; - } - } - - fTheme->ReadUnlock(); - Window()->EndViewTransaction(); - Window()->EnableUpdates(); - ConstrainClippingRegion (NULL); + fTheme->ReadUnlock(); + Window()->EndViewTransaction(); + Window()->EnableUpdates(); + ConstrainClippingRegion (NULL); } void RunView::SetViewColor (rgb_color color) { - assert (memcmp (&color, &B_TRANSPARENT_COLOR, sizeof (rgb_color)) != 0); - BView::SetViewColor (color); + assert (memcmp (&color, &B_TRANSPARENT_COLOR, sizeof (rgb_color)) != 0); + BView::SetViewColor (color); } void RunView::BuildPopUp (void) { - // This function checks certain criteria (fText is selected, - // TextView is editable, etc) to determine fWhich MenuItems - // to enable and disable + // This function checks certain criteria (fText is selected, + // TextView is editable, etc) to determine fWhich MenuItems + // to enable and disable - bool enablecopy (true), - enableselectall (true), - enablelookup (false); - BString querystring (""); + bool enablecopy (true), + enableselectall (true), + enablelookup (false); + BString querystring (""); - if (fSp_start == fSp_end) - enablecopy = false; // no selection + if (fSp_start == fSp_end) + enablecopy = false; // no selection - if (!fLine_count) - enableselectall = false; + if (!fLine_count) + enableselectall = false; - if (enablecopy) - { - enablelookup = true; // has a selection less than 32 chars long - GetSelectionText(querystring); - } + if (enablecopy) { + enablelookup = true; // has a selection less than 32 chars long + GetSelectionText(querystring); + } - fMyPopUp = new BPopUpMenu ("IRCView Context Menu", false, false); + fMyPopUp = new BPopUpMenu ("IRCView Context Menu", false, false); - BMenuItem *item; + BMenuItem* item; - BMessage *lookup; - lookup = new BMessage (M_LOOKUP_WEBSTER); - lookup->AddString ("string", querystring); - item = new BMenuItem(_T("Lookup (Dictionary)"), lookup); - item->SetEnabled (enablelookup); - item->SetTarget(this); - fMyPopUp->AddItem (item); + BMessage* lookup; + lookup = new BMessage (M_LOOKUP_WEBSTER); + lookup->AddString ("string", querystring); + item = new BMenuItem(_T("Lookup (Dictionary)"), lookup); + item->SetEnabled (enablelookup); + item->SetTarget(this); + fMyPopUp->AddItem (item); - lookup = new BMessage (M_LOOKUP_GOOGLE); - lookup->AddString ("string", querystring); - item = new BMenuItem(_T("Lookup (Google)"), lookup); - item->SetEnabled (enablelookup); - item->SetTarget(this); - fMyPopUp->AddItem (item); - - lookup = new BMessage (M_LOOKUP_ACRONYM); - lookup->AddString ("string", querystring); - item = new BMenuItem(_T("Lookup (Acronym Finder)"), lookup); - item->SetEnabled (enablelookup); - item->SetTarget(this); - fMyPopUp->AddItem (item); + lookup = new BMessage (M_LOOKUP_GOOGLE); + lookup->AddString ("string", querystring); + item = new BMenuItem(_T("Lookup (Google)"), lookup); + item->SetEnabled (enablelookup); + item->SetTarget(this); + fMyPopUp->AddItem (item); - fMyPopUp->AddSeparatorItem(); - - item = new BMenuItem(_T("Copy"), new BMessage (B_COPY), 'C'); - item->SetEnabled (enablecopy); - item->SetTarget (this); - fMyPopUp->AddItem (item); + lookup = new BMessage (M_LOOKUP_ACRONYM); + lookup->AddString ("string", querystring); + item = new BMenuItem(_T("Lookup (Acronym Finder)"), lookup); + item->SetEnabled (enablelookup); + item->SetTarget(this); + fMyPopUp->AddItem (item); - item = new BMenuItem(_T("Select All"), new BMessage (B_SELECT_ALL), 'A'); - item->SetEnabled (enableselectall); - item->SetTarget (this); - fMyPopUp->AddItem (item); + fMyPopUp->AddSeparatorItem(); - fMyPopUp->AddSeparatorItem(); - - item = new BMenuItem(_T("Clear"), new BMessage(M_CLEAR)); - item->SetTarget(this); - fMyPopUp->AddItem(item); + item = new BMenuItem(_T("Copy"), new BMessage (B_COPY), 'C'); + item->SetEnabled (enablecopy); + item->SetTarget (this); + fMyPopUp->AddItem (item); - fMyPopUp->SetFont (be_plain_font); + item = new BMenuItem(_T("Select All"), new BMessage (B_SELECT_ALL), 'A'); + item->SetEnabled (enableselectall); + item->SetTarget (this); + fMyPopUp->AddItem (item); + + fMyPopUp->AddSeparatorItem(); + + item = new BMenuItem(_T("Clear"), new BMessage(M_CLEAR)); + item->SetTarget(this); + fMyPopUp->AddItem(item); + + fMyPopUp->SetFont (be_plain_font); } bool -RunView::CheckClickBounds (const SelectPos &s, const BPoint &point) const +RunView::CheckClickBounds (const SelectPos& s, const BPoint& point) const { - return ((point.x <= fLines[s.fLine]->fEdges[fLines[s.fLine]->fLength - 1]) - && (point.y <= fLines[s.fLine]->fBottom)); + return ((point.x <= fLines[s.fLine]->fEdges[fLines[s.fLine]->fLength - 1]) + && (point.y <= fLines[s.fLine]->fBottom)); } void RunView::MouseDown (BPoint point) { - if (!fLine_count) - return; - - BMessage *msg (Window()->CurrentMessage()); - uint32 buttons; - uint32 mouseModifiers; - bigtime_t sysTime; - msg->FindInt64 ("when", &sysTime); - uint16 clicks = CheckClickCount (point, fLastClick, sysTime, fLastClickTime, fClickCount) % 3; - msg->FindInt32 ("buttons", reinterpret_cast(&buttons)); - msg->FindInt32 ("modifiers", reinterpret_cast(&mouseModifiers)); + if (!fLine_count) + return; - SelectPos s (PositionAt (point)); - bool inBounds (CheckClickBounds (s, point)); + BMessage* msg (Window()->CurrentMessage()); + uint32 buttons; + uint32 mouseModifiers; + bigtime_t sysTime; + msg->FindInt64 ("when", &sysTime); + uint16 clicks = CheckClickCount (point, fLastClick, sysTime, fLastClickTime, fClickCount) % 3; + msg->FindInt32 ("buttons", reinterpret_cast(&buttons)); + msg->FindInt32 ("modifiers", reinterpret_cast(&mouseModifiers)); - if (buttons == B_SECONDARY_MOUSE_BUTTON - && (mouseModifiers & B_SHIFT_KEY) == 0 - && (mouseModifiers & B_COMMAND_KEY) == 0 - && (mouseModifiers & B_CONTROL_KEY) == 0 - && (mouseModifiers & B_OPTION_KEY) == 0 - && (mouseModifiers & B_MENU_KEY) == 0) - { - SelectPos start (s), - end (s); + SelectPos s (PositionAt (point)); + bool inBounds (CheckClickBounds (s, point)); - // select word - if (inBounds && !IntersectSelection (s,s)) - { - fLines[s.fLine]->SelectWord (&start.fOffset, &end.fOffset); + if (buttons == B_SECONDARY_MOUSE_BUTTON + && (mouseModifiers & B_SHIFT_KEY) == 0 + && (mouseModifiers & B_COMMAND_KEY) == 0 + && (mouseModifiers & B_CONTROL_KEY) == 0 + && (mouseModifiers & B_OPTION_KEY) == 0 + && (mouseModifiers & B_MENU_KEY) == 0) { + SelectPos start (s), + end (s); - Select (start, end); - } + // select word + if (inBounds && !IntersectSelection (s, s)) { + fLines[s.fLine]->SelectWord (&start.fOffset, &end.fOffset); - BuildPopUp(); - fMyPopUp->Go ( - ConvertToScreen (point), - true, - false); + Select (start, end); + } - delete fMyPopUp; - fMyPopUp = 0; - return; - } + BuildPopUp(); + fMyPopUp->Go ( + ConvertToScreen (point), + true, + false); - if (buttons == B_PRIMARY_MOUSE_BUTTON - && (mouseModifiers & B_SHIFT_KEY) == 0 - && (mouseModifiers & B_COMMAND_KEY) == 0 - && (mouseModifiers & B_CONTROL_KEY) == 0 - && (mouseModifiers & B_OPTION_KEY) == 0 - && (mouseModifiers & B_MENU_KEY) == 0) - { - SelectPos start (s), - end (s); + delete fMyPopUp; + fMyPopUp = 0; + return; + } - switch (clicks) - { - case 2: - { - if (inBounds) - { - // select word - fLines[s.fLine]->SelectWord (&start.fOffset, &end.fOffset); + if (buttons == B_PRIMARY_MOUSE_BUTTON + && (mouseModifiers & B_SHIFT_KEY) == 0 + && (mouseModifiers & B_COMMAND_KEY) == 0 + && (mouseModifiers & B_CONTROL_KEY) == 0 + && (mouseModifiers & B_OPTION_KEY) == 0 + && (mouseModifiers & B_MENU_KEY) == 0) { + SelectPos start (s), + end (s); - Select (start, end); - return; - } - } - break; + switch (clicks) { + case 2: { + if (inBounds) { + // select word + fLines[s.fLine]->SelectWord (&start.fOffset, &end.fOffset); - case 0: - { - if (inBounds) - { - start.fOffset = 0; - end.fOffset = fLines[s.fLine]->fLength - 1; - Select (start, end); - return; - } - } - break; + Select (start, end); + return; + } + } + break; - default: - { - if (!inBounds || !IntersectSelection (s, s)) - Select (s,s); - SetMouseEventMask (B_POINTER_EVENTS); - fTracking = 1; - fTrack_offset = s; - return; - } - } - } - else if (buttons == B_PRIMARY_MOUSE_BUTTON - && (mouseModifiers & B_SHIFT_KEY) != 0 - && (mouseModifiers & B_COMMAND_KEY) == 0 - && (mouseModifiers & B_CONTROL_KEY) == 0 - && (mouseModifiers & B_OPTION_KEY) == 0 - && (mouseModifiers & B_MENU_KEY) == 0) - { - if (s.fLine < fSp_start.fLine || s.fOffset < fSp_start.fOffset) - { - Select (s, fSp_end); - fTrack_offset = SelectPos (fSp_end.fLine, (fSp_end.fOffset > 0) ? fSp_end.fOffset - 1 : fSp_end.fOffset); - } - else - { - Select (fSp_start, s); - fTrack_offset = fSp_start; - } + case 0: { + if (inBounds) { + start.fOffset = 0; + end.fOffset = fLines[s.fLine]->fLength - 1; + Select (start, end); + return; + } + } + break; - SetMouseEventMask (B_POINTER_EVENTS); - fTracking = 2; - } + default: { + if (!inBounds || !IntersectSelection (s, s)) + Select (s, s); + SetMouseEventMask (B_POINTER_EVENTS); + fTracking = 1; + fTrack_offset = s; + return; + } + } + } else if (buttons == B_PRIMARY_MOUSE_BUTTON + && (mouseModifiers & B_SHIFT_KEY) != 0 + && (mouseModifiers & B_COMMAND_KEY) == 0 + && (mouseModifiers & B_CONTROL_KEY) == 0 + && (mouseModifiers & B_OPTION_KEY) == 0 + && (mouseModifiers & B_MENU_KEY) == 0) { + if (s.fLine < fSp_start.fLine || s.fOffset < fSp_start.fOffset) { + Select (s, fSp_end); + fTrack_offset = SelectPos (fSp_end.fLine, (fSp_end.fOffset > 0) ? fSp_end.fOffset - 1 : fSp_end.fOffset); + } else { + Select (fSp_start, s); + fTrack_offset = fSp_start; + } + + SetMouseEventMask (B_POINTER_EVENTS); + fTracking = 2; + } } void RunView::CheckURLCursor (BPoint point) { - if (!fLine_count) - return; + if (!fLine_count) + return; - SelectPos s = PositionAt (point); + SelectPos s = PositionAt (point); - if (!fLines[s.fLine]->fUrls) - { - // if there aren't any URLs in the current line, go back to default - SetViewCursor (B_CURSOR_SYSTEM_DEFAULT); - return; - } - Line *curline (fLines[s.fLine]); + if (!fLines[s.fLine]->fUrls) { + // if there aren't any URLs in the current line, go back to default + SetViewCursor (B_CURSOR_SYSTEM_DEFAULT); + return; + } + Line* curline (fLines[s.fLine]); - for (int32 i = 0; i < curline->fUrls->CountItems(); i++) - { - URL *current = curline->fUrls->ItemAt(i); - if ((s.fOffset >= current->fOffset) - && (s.fOffset <= current->fOffset + current->fLength)) - { - SetViewCursor (fURLCursor); - return; - } - } + for (int32 i = 0; i < curline->fUrls->CountItems(); i++) { + URL* current = curline->fUrls->ItemAt(i); + if ((s.fOffset >= current->fOffset) + && (s.fOffset <= current->fOffset + current->fLength)) { + SetViewCursor (fURLCursor); + return; + } + } - // no URLs found, set back to default - SetViewCursor (B_CURSOR_SYSTEM_DEFAULT); + // no URLs found, set back to default + SetViewCursor (B_CURSOR_SYSTEM_DEFAULT); } void -RunView::MouseMoved (BPoint point, uint32 transit, const BMessage *msg) +RunView::MouseMoved (BPoint point, uint32 transit, const BMessage* msg) { - if (fTracking == 0 - && fLine_count - && (transit == B_ENTERED_VIEW - || transit == B_INSIDE_VIEW)) - CheckURLCursor (point); + if (fTracking == 0 + && fLine_count + && (transit == B_ENTERED_VIEW + || transit == B_INSIDE_VIEW)) + CheckURLCursor (point); - if (!fLine_count || fTracking == 0) - { - BView::MouseMoved (point, transit, msg); - return; - } + if (!fLine_count || fTracking == 0) { + BView::MouseMoved (point, transit, msg); + return; + } - switch (transit) - { - case B_ENTERED_VIEW: - if (fOff_view_runner) - { - delete fOff_view_runner; - fOff_view_runner = 0; - } + switch (transit) { + case B_ENTERED_VIEW: + if (fOff_view_runner) { + delete fOff_view_runner; + fOff_view_runner = 0; + } - if (fTracking == 1 || fTracking == 2) - ExtendTrackingSelect (point); + if (fTracking == 1 || fTracking == 2) + ExtendTrackingSelect (point); - break; + break; - case B_EXITED_VIEW: - if (fTracking == 1 || fTracking == 2) - ShiftTrackingSelect (point, true, OFFVIEW_TIMER); - break; + case B_EXITED_VIEW: + if (fTracking == 1 || fTracking == 2) + ShiftTrackingSelect (point, true, OFFVIEW_TIMER); + break; - case B_OUTSIDE_VIEW: + case B_OUTSIDE_VIEW: - if (fTracking == 1 || fTracking == 2) - { - bigtime_t now (system_time()); + if (fTracking == 1 || fTracking == 2) { + bigtime_t now (system_time()); - ShiftTrackingSelect ( - point, - false, - max_c (0LL, min_c (OFFVIEW_TIMER, OFFVIEW_TIMER - (now - fOff_view_time)))); - } - break; + ShiftTrackingSelect ( + point, + false, + max_c (0LL, min_c (OFFVIEW_TIMER, OFFVIEW_TIMER - (now - fOff_view_time)))); + } + break; - case B_INSIDE_VIEW: + case B_INSIDE_VIEW: - if ((fTracking == 1) && (fSp_start != fSp_end)) - { - BMessage msg (B_MIME_DATA); - BString fText; + if ((fTracking == 1) && (fSp_start != fSp_end)) { + BMessage msg (B_MIME_DATA); + BString fText; - GetSelectionText (fText); - msg.AddData ( - "text/plain", - B_MIME_TYPE, - fText.String(), - fText.Length() + 1); + GetSelectionText (fText); + msg.AddData ( + "text/plain", + B_MIME_TYPE, + fText.String(), + fText.Length() + 1); - BString clip_name (" Clipping"); + BString clip_name (" Clipping"); - if (fClipping_name) - clip_name.Prepend (fClipping_name); - else - clip_name.Prepend ("RunView"); + if (fClipping_name) + clip_name.Prepend (fClipping_name); + else + clip_name.Prepend ("RunView"); - msg.AddString ("be:clip_name", clip_name.String()); - msg.AddInt32 ("be:actions", B_COPY_TARGET); + msg.AddString ("be:clip_name", clip_name.String()); + msg.AddInt32 ("be:actions", B_COPY_TARGET); - BRect frame ( - fLines[fSp_start.fLine]->fEdges[fSp_start.fOffset], - fLines[fSp_start.fLine]->fTop, - fLines[fSp_end.fLine]->fEdges[fSp_end.fOffset], - fLines[fSp_end.fLine]->fBottom); + BRect frame ( + fLines[fSp_start.fLine]->fEdges[fSp_start.fOffset], + fLines[fSp_start.fLine]->fTop, + fLines[fSp_end.fLine]->fEdges[fSp_end.fOffset], + fLines[fSp_end.fLine]->fBottom); - if (fSp_start.fLine != fSp_end.fLine) - { - frame.left = 0.0; - frame.right = Bounds().right; - } - // selection lies within the bounds of a line, check - // if it fLines on one of the wrapped subfLines and calculate rectangle - // appropriately - else - { - Line *line (fLines[fSp_start.fLine]); - float left (line->fEdges[fSp_start.fOffset]), - top (line->fTop), - right (line->fEdges[fSp_end.fOffset]), - bottom (line->fBottom); - int top_softie (0), bottom_softie (0); - bool start_found (false); - bool end_found (false); + if (fSp_start.fLine != fSp_end.fLine) { + frame.left = 0.0; + frame.right = Bounds().right; + } + // selection lies within the bounds of a line, check + // if it fLines on one of the wrapped subfLines and calculate rectangle + // appropriately + else { + Line* line (fLines[fSp_start.fLine]); + float left (line->fEdges[fSp_start.fOffset]), + top (line->fTop), + right (line->fEdges[fSp_end.fOffset]), + bottom (line->fBottom); + int top_softie (0), bottom_softie (0); + bool start_found (false); + bool end_found (false); - if (line->fSoftie_used) - { - if (fSp_start.fOffset < line->fSofties[0].fOffset) - start_found = true; + if (line->fSoftie_used) { + if (fSp_start.fOffset < line->fSofties[0].fOffset) + start_found = true; - if (fSp_end.fOffset < line->fSofties[0].fOffset) - end_found = true; - } + if (fSp_end.fOffset < line->fSofties[0].fOffset) + end_found = true; + } - if (!end_found) - for (int16 sit = 1; sit < line->fSoftie_used; ++sit) - { - if (!start_found && fSp_start.fOffset < line->fSofties[sit].fOffset) - { - left = line->fEdges[fSp_start.fOffset] - - line->fEdges[line->fSofties[sit-1].fOffset]; + if (!end_found) + for (int16 sit = 1; sit < line->fSoftie_used; ++sit) { + if (!start_found && fSp_start.fOffset < line->fSofties[sit].fOffset) { + left = line->fEdges[fSp_start.fOffset] - + line->fEdges[line->fSofties[sit-1].fOffset]; - top += (sit) * line->fSofties[sit].fHeight; - top_softie = sit; - start_found = true; - } + top += (sit) * line->fSofties[sit].fHeight; + top_softie = sit; + start_found = true; + } - if (fSp_end.fOffset < line->fSofties[sit].fOffset) - { - right = line->fEdges[fSp_end.fOffset] - - line->fEdges[line->fSofties[sit-1].fOffset]; + if (fSp_end.fOffset < line->fSofties[sit].fOffset) { + right = line->fEdges[fSp_end.fOffset] - + line->fEdges[line->fSofties[sit-1].fOffset]; - bottom = top + (sit - top_softie + 1) * line->fSofties[sit].fHeight; - bottom_softie = sit; - end_found = true; - break; - } - } - if (!end_found) - { - int32 soft_count = (line->fSoftie_used >= 2) ? - line->fSoftie_used - 2 : 0; - right = line->fEdges[line->fLength - 1] - - line->fEdges[line->fSofties[soft_count].fOffset]; - bottom_softie = soft_count - 2; + bottom = top + (sit - top_softie + 1) * line->fSofties[sit].fHeight; + bottom_softie = sit; + end_found = true; + break; + } + } + if (!end_found) { + int32 soft_count = (line->fSoftie_used >= 2) ? + line->fSoftie_used - 2 : 0; + right = line->fEdges[line->fLength - 1] - + line->fEdges[line->fSofties[soft_count].fOffset]; + bottom_softie = soft_count - 2; - } - if (right < left || (bottom_softie - top_softie) > 0) - { - left = 0.0; - right = Bounds().right; - } + } + if (right < left || (bottom_softie - top_softie) > 0) { + left = 0.0; + right = Bounds().right; + } - frame.Set (left, top, right, bottom); - frame.OffsetBy (fTheme->TextMargin(), 0.0); - } + frame.Set (left, top, right, bottom); + frame.OffsetBy (fTheme->TextMargin(), 0.0); + } - if (frame.Height() > Bounds().Height()) - frame = Bounds(); + if (frame.Height() > Bounds().Height()) + frame = Bounds(); - DragMessage (&msg, frame); + DragMessage (&msg, frame); - fTracking = 3; - } - else if (fTracking == 1 || fTracking == 2) - ExtendTrackingSelect (point); - break; - } + fTracking = 3; + } else if (fTracking == 1 || fTracking == 2) + ExtendTrackingSelect (point); + break; + } } void RunView::MouseUp (BPoint point) { - SelectPos s (PositionAt (point)); - bool url_handle (false); + SelectPos s (PositionAt (point)); + bool url_handle (false); - if (!fLine_count) - { - fTracking = 0; - return; - } + if (!fLine_count) { + fTracking = 0; + return; + } - if (fTracking == 1) - { - Line *curline (fLines[s.fLine]); - if (curline->fUrls) - { - for (int32 i = 0; i < curline->fUrls->CountItems(); i++) - { - URL *current = curline->fUrls->ItemAt(i); - if ((s.fOffset >= current->fOffset) - && (s.fOffset <= current->fOffset + current->fLength)) - { + if (fTracking == 1) { + Line* curline (fLines[s.fLine]); + if (curline->fUrls) { + for (int32 i = 0; i < curline->fUrls->CountItems(); i++) { + URL* current = curline->fUrls->ItemAt(i); + if ((s.fOffset >= current->fOffset) + && (s.fOffset <= current->fOffset + current->fLength)) { - LoadURL (current->fUrl.String()); - url_handle = true; - break; - } - } - } - if (!url_handle && s == fTrack_offset) - Select (s, s); - } + LoadURL (current->fUrl.String()); + url_handle = true; + break; + } + } + } + if (!url_handle && s == fTrack_offset) + Select (s, s); + } - if (fOff_view_runner) - { - delete fOff_view_runner; - fOff_view_runner = 0; - } + if (fOff_view_runner) { + delete fOff_view_runner; + fOff_view_runner = 0; + } - fTracking = 0; + fTracking = 0; } void RunView::ExtendTrackingSelect (BPoint point) { - SelectPos s (PositionAt (point)); + SelectPos s (PositionAt (point)); - if (s.fLine < fTrack_offset.fLine || (s.fLine == fTrack_offset.fLine && s.fOffset < fTrack_offset.fOffset)) - { - Select (s, fTrack_offset); - fTracking = 2; - } - else if (s.fLine > fTrack_offset.fLine || (s.fLine == fTrack_offset.fLine && s.fOffset > fTrack_offset.fOffset)) - { - Select (fTrack_offset, s); - fTracking = 2; - } + if (s.fLine < fTrack_offset.fLine || (s.fLine == fTrack_offset.fLine && s.fOffset < fTrack_offset.fOffset)) { + Select (s, fTrack_offset); + fTracking = 2; + } else if (s.fLine > fTrack_offset.fLine || (s.fLine == fTrack_offset.fLine && s.fOffset > fTrack_offset.fOffset)) { + Select (fTrack_offset, s); + fTracking = 2; + } } void RunView::ShiftTrackingSelect (BPoint point, bool move, bigtime_t timer) { - BRect bounds (Bounds()); + BRect bounds (Bounds()); - if (fOff_view_runner) - { - delete fOff_view_runner; - fOff_view_runner = 0; - } + if (fOff_view_runner) { + delete fOff_view_runner; + fOff_view_runner = 0; + } - if (point.y < bounds.top) - { - if (bounds.top > 0.0) - { - float delta (bounds.top - point.y); + if (point.y < bounds.top) { + if (bounds.top > 0.0) { + float delta (bounds.top - point.y); - if (fOff_view_runner == 0) - { - BMessage *msg (new BMessage (M_OFFVIEW_SELECTION)); + if (fOff_view_runner == 0) { + BMessage* msg (new BMessage (M_OFFVIEW_SELECTION)); - msg->AddFloat ("delta", delta); - msg->AddBool ("bottom", false); - msg->AddPoint ("point", point); + msg->AddFloat ("delta", delta); + msg->AddBool ("bottom", false); + msg->AddPoint ("point", point); - fOff_view_runner = new BMessageRunner ( - BMessenger (this), - msg, - timer == 0LL ? OFFVIEW_TIMER : timer); + fOff_view_runner = new BMessageRunner ( + BMessenger (this), + msg, + timer == 0LL ? OFFVIEW_TIMER : timer); - } + } - if (move || timer == 0) - { - delta = max_c (ABS (ceil (delta / 2.0)), 10.0); - delta = min_c (delta, Bounds().Height()); + if (move || timer == 0) { + delta = max_c (ABS (ceil (delta / 2.0)), 10.0); + delta = min_c (delta, Bounds().Height()); - if (bounds.top - delta < 0.0) - delta = bounds.top; + if (bounds.top - delta < 0.0) + delta = bounds.top; - ScrollBy (0.0, -delta); - fOff_view_time = system_time(); - } - } + ScrollBy (0.0, -delta); + fOff_view_time = system_time(); + } + } - point.x = 0.0; - point.y = Bounds().top; - ExtendTrackingSelect (point); - } + point.x = 0.0; + point.y = Bounds().top; + ExtendTrackingSelect (point); + } - if (point.y > bounds.bottom) - { - Line *line (fLines[fLine_count-1]); - if (line - && line->fBottom > bounds.bottom) - { - float delta (point.y - bounds.bottom); + if (point.y > bounds.bottom) { + Line* line (fLines[fLine_count-1]); + if (line + && line->fBottom > bounds.bottom) { + float delta (point.y - bounds.bottom); - if (fOff_view_runner == 0) - { - BMessage *msg (new BMessage (M_OFFVIEW_SELECTION)); + if (fOff_view_runner == 0) { + BMessage* msg (new BMessage (M_OFFVIEW_SELECTION)); - msg->AddFloat ("delta", delta); - msg->AddBool ("bottom", true); - msg->AddPoint ("point", point); + msg->AddFloat ("delta", delta); + msg->AddBool ("bottom", true); + msg->AddPoint ("point", point); - fOff_view_runner = new BMessageRunner ( - BMessenger (this), - msg, - timer == 0LL ? OFFVIEW_TIMER : timer); + fOff_view_runner = new BMessageRunner ( + BMessenger (this), + msg, + timer == 0LL ? OFFVIEW_TIMER : timer); - } + } - if (move || timer == 0) - { - delta = max_c (ABS (ceil (delta / 2.0)), 10.0); - delta = min_c (delta, Bounds().Height()); + if (move || timer == 0) { + delta = max_c (ABS (ceil (delta / 2.0)), 10.0); + delta = min_c (delta, Bounds().Height()); - if (bounds.bottom + delta > line->fBottom) - delta = line->fBottom - bounds.bottom; + if (bounds.bottom + delta > line->fBottom) + delta = line->fBottom - bounds.bottom; - ScrollBy (0.0, delta); - fOff_view_time = system_time(); - } - } + ScrollBy (0.0, delta); + fOff_view_time = system_time(); + } + } - point.x = Bounds().right; - point.y = Bounds().bottom; - ExtendTrackingSelect (point); - } - else - ExtendTrackingSelect (point); + point.x = Bounds().right; + point.y = Bounds().bottom; + ExtendTrackingSelect (point); + } else + ExtendTrackingSelect (point); } void -RunView::MessageReceived (BMessage *msg) +RunView::MessageReceived (BMessage* msg) { - switch (msg->what) - { + switch (msg->what) { - case M_THEME_FOREGROUND_CHANGE: - case M_THEME_BACKGROUND_CHANGE: - if (!IsHidden()) - Invalidate (Bounds()); - break; + case M_THEME_FOREGROUND_CHANGE: + case M_THEME_BACKGROUND_CHANGE: + if (!IsHidden()) + Invalidate (Bounds()); + break; - case M_THEME_FONT_CHANGE: - { - Theme *save (fTheme); + case M_THEME_FONT_CHANGE: { + Theme* save (fTheme); - fTheme = NULL; - SetTheme (save); - break; - } + fTheme = NULL; + SetTheme (save); + break; + } - case B_SELECT_ALL: - SelectAll(); - break; + case B_SELECT_ALL: + SelectAll(); + break; - case B_COPY: - if (fSp_start != fSp_end - && be_clipboard->Lock()) - { - BString fText; - GetSelectionText (fText); + case B_COPY: + if (fSp_start != fSp_end + && be_clipboard->Lock()) { + BString fText; + GetSelectionText (fText); - be_clipboard->Clear(); + be_clipboard->Clear(); - BMessage *msg (be_clipboard->Data()); - msg->AddData ("text/plain", B_MIME_TYPE, fText.String(), fText.Length()); + BMessage* msg (be_clipboard->Data()); + msg->AddData ("text/plain", B_MIME_TYPE, fText.String(), fText.Length()); - be_clipboard->Commit(); - be_clipboard->Unlock(); - } - break; + be_clipboard->Commit(); + be_clipboard->Unlock(); + } + break; - case M_OFFVIEW_SELECTION: - { - BPoint point; - float delta; - bool bottom; + case M_OFFVIEW_SELECTION: { + BPoint point; + float delta; + bool bottom; - msg->FindPoint ("point", &point); - msg->FindBool ("bottom", &bottom); - msg->FindFloat ("delta", &delta); + msg->FindPoint ("point", &point); + msg->FindBool ("bottom", &bottom); + msg->FindFloat ("delta", &delta); - if (bottom) - point.y = Bounds().bottom + delta; - else - point.y = Bounds().top - delta; + if (bottom) + point.y = Bounds().bottom + delta; + else + point.y = Bounds().top - delta; - ShiftTrackingSelect (point, true, OFFVIEW_TIMER); - break; - } + ShiftTrackingSelect (point, true, OFFVIEW_TIMER); + break; + } - case M_LOOKUP_WEBSTER: - { - BString lookup; - msg->FindString ("string", &lookup); - lookup = StringToURI (lookup.String()); - lookup.Prepend ("http://www.m-w.com/cgi-bin/dictionary?va="); - LoadURL (lookup.String()); - } - break; + case M_LOOKUP_WEBSTER: { + BString lookup; + msg->FindString ("string", &lookup); + lookup = StringToURI (lookup.String()); + lookup.Prepend ("http://www.m-w.com/cgi-bin/dictionary?va="); + LoadURL (lookup.String()); + } + break; - case M_LOOKUP_GOOGLE: - { - BString lookup; - msg->FindString ("string", &lookup); - lookup = StringToURI (lookup.String()); - lookup.Prepend ("http://www.google.com/search?q="); - LoadURL (lookup.String()); - } - break; - - case M_LOOKUP_ACRONYM: - { - BString lookup; - msg->FindString ("string", &lookup); - lookup = StringToURI (lookup.String()); - lookup.Prepend ("http://www.acronymfinder.com/af-query.asp?String=exact&Acronym="); - lookup.Append ("&Find=Find"); - LoadURL (lookup.String()); - } - break; - - case M_CLEAR: - { - Clear(); - } - break; + case M_LOOKUP_GOOGLE: { + BString lookup; + msg->FindString ("string", &lookup); + lookup = StringToURI (lookup.String()); + lookup.Prepend ("http://www.google.com/search?q="); + LoadURL (lookup.String()); + } + break; - default: - BView::MessageReceived (msg); - } + case M_LOOKUP_ACRONYM: { + BString lookup; + msg->FindString ("string", &lookup); + lookup = StringToURI (lookup.String()); + lookup.Prepend ("http://www.acronymfinder.com/af-query.asp?String=exact&Acronym="); + lookup.Append ("&Find=Find"); + LoadURL (lookup.String()); + } + break; + + case M_CLEAR: { + Clear(); + } + break; + + default: + BView::MessageReceived (msg); + } } void RunView::ResizeRecalc (void) { - float width (Bounds().Width() - (fTheme->TextMargin()*2)); - int16 fSoftie_size (0), fSoftie_used (0); - SoftBreak *fSofties (NULL); - BRect bounds (Bounds()); - BRegion region; - float top (0.0); + float width (Bounds().Width() - (fTheme->TextMargin() * 2)); + int16 fSoftie_size (0), fSoftie_used (0); + SoftBreak* fSofties (NULL); + BRect bounds (Bounds()); + BRegion region; + float top (0.0); - fTheme->ReadLock(); - for (int16 i = 0; i < fLine_count; ++i) - { - float old_top (fLines[i]->fTop), old_bottom (fLines[i]->fBottom); - if (fSoftie_size < fLines[i]->fSoftie_used) - { - delete [] fSofties; - fSofties = new SoftBreak [fSoftie_size = fLines[i]->fSoftie_size]; - } + fTheme->ReadLock(); + for (int16 i = 0; i < fLine_count; ++i) { + float old_top (fLines[i]->fTop), old_bottom (fLines[i]->fBottom); + if (fSoftie_size < fLines[i]->fSoftie_used) { + delete [] fSofties; + fSofties = new SoftBreak [fSoftie_size = fLines[i]->fSoftie_size]; + } - fSoftie_used = fLines[i]->fSoftie_used; - memcpy (fSofties, fLines[i]->fSofties, (fSoftie_used * sizeof (SoftBreak))); + fSoftie_used = fLines[i]->fSoftie_used; + memcpy (fSofties, fLines[i]->fSofties, (fSoftie_used * sizeof (SoftBreak))); - fLines[i]->fTop = top; - fLines[i]->SoftBreaks (fTheme, width); - top = fLines[i]->fBottom + 1.0; + fLines[i]->fTop = top; + fLines[i]->SoftBreaks (fTheme, width); + top = fLines[i]->fBottom + 1.0; - BRect r (0.0, fLines[i]->fTop, bounds.right, fLines[i]->fBottom); + BRect r (0.0, fLines[i]->fTop, bounds.right, fLines[i]->fBottom); - if (bounds.Intersects (r) - && (old_top != fLines[i]->fTop - || old_bottom != fLines[i]->fBottom - || fSoftie_used != fLines[i]->fSoftie_used - || memcmp (fSofties, fLines[i]->fSofties, fSoftie_used * sizeof (SoftBreak)))) - region.Include (r); - } + if (bounds.Intersects (r) + && (old_top != fLines[i]->fTop + || old_bottom != fLines[i]->fBottom + || fSoftie_used != fLines[i]->fSoftie_used + || memcmp (fSofties, fLines[i]->fSofties, fSoftie_used * sizeof (SoftBreak)))) + region.Include (r); + } - fTheme->ReadUnlock(); + fTheme->ReadUnlock(); - if (Window()) - { - if (RecalcScrollBar (true)) - Invalidate (Bounds()); - else - { - int32 count (region.CountRects()), j; + if (Window()) { + if (RecalcScrollBar (true)) + Invalidate (Bounds()); + else { + int32 count (region.CountRects()), j; - for (j = 0; j < count; ++j) - Invalidate (region.RectAt (j)); + for (j = 0; j < count; ++j) + Invalidate (region.RectAt (j)); - if (top <= bounds.bottom) - { - BRect r (bounds); + if (top <= bounds.bottom) { + BRect r (bounds); - r.top = top; - Invalidate (r); - } - } + r.top = top; + Invalidate (r); + } + } - Window()->Sync(); - } + Window()->Sync(); + } - if (fWorking) fWorking->fTop = top; - delete [] fSofties; + if (fWorking) fWorking->fTop = top; + delete [] fSofties; } void RunView::FontChangeRecalc (void) { - float width (Bounds().Width() - (fTheme->TextMargin()*2)); - float top (0.0); + float width (Bounds().Width() - (fTheme->TextMargin() * 2)); + float top (0.0); - for (int16 i = 0; i < fLine_count; ++i) - { - fLines[i]->fTop = top; + for (int16 i = 0; i < fLine_count; ++i) { + fLines[i]->fTop = top; - fLines[i]->FigureSpaces(); - fLines[i]->FigureEdges (fTheme, width); + fLines[i]->FigureSpaces(); + fLines[i]->FigureEdges (fTheme, width); - top = fLines[i]->fBottom + 1.0; - } + top = fLines[i]->fBottom + 1.0; + } - if (fWorking) - fWorking->fTop = top; + if (fWorking) + fWorking->fTop = top; - RecalcScrollBar (false); - if (!IsHidden()) - Invalidate (Bounds()); - if (Window()) Window()->UpdateIfNeeded(); + RecalcScrollBar (false); + if (!IsHidden()) + Invalidate (Bounds()); + if (Window()) Window()->UpdateIfNeeded(); } bool RunView::RecalcScrollBar (bool constrain) { - BScrollBar *bar; + BScrollBar* bar; - if (fScroller == NULL - || (bar = fScroller->ScrollBar (B_VERTICAL)) == NULL) - return false; + if (fScroller == NULL + || (bar = fScroller->ScrollBar (B_VERTICAL)) == NULL) + return false; - float value (bar->Value()); - BRect bounds (Bounds()); - bool changed (false); - float bottom (0.0); - float scrollMin, scrollMax; + float value (bar->Value()); + BRect bounds (Bounds()); + bool changed (false); + float bottom (0.0); + float scrollMin, scrollMax; - bar->GetRange (&scrollMin, &scrollMax); + bar->GetRange (&scrollMin, &scrollMax); - if (fLine_count - && (bounds.Contains (BPoint (0.0, 0.0)) == false - || bounds.Contains (BPoint (0.0, fLines[fLine_count - 1]->fBottom)) == false)) - { - bottom = fLines[fLine_count - 1]->fBottom + 5.0; - bar->SetProportion (bounds.Height() / bottom); - bar->SetSteps (10.0, bounds.Height()); + if (fLine_count + && (bounds.Contains (BPoint (0.0, 0.0)) == false + || bounds.Contains (BPoint (0.0, fLines[fLine_count - 1]->fBottom)) == false)) { + bottom = fLines[fLine_count - 1]->fBottom + 5.0; + bar->SetProportion (bounds.Height() / bottom); + bar->SetSteps (10.0, bounds.Height()); - bottom -= bounds.Height(); - } + bottom -= bounds.Height(); + } - // We don't want the bar to cause a draw/copybits, so we restrict the - // clipping region to nothing + // We don't want the bar to cause a draw/copybits, so we restrict the + // clipping region to nothing - if (constrain) - { - BRegion region; - ConstrainClippingRegion (®ion); - } + if (constrain) { + BRegion region; + ConstrainClippingRegion (®ion); + } - if (scrollMax != bottom) - { - bar->SetRange (0.0, bottom); + if (scrollMax != bottom) { + bar->SetRange (0.0, bottom); - if (value == scrollMax || scrollMin == scrollMax) - { - bar->SetValue (bottom); - changed = true; - } - } + if (value == scrollMax || scrollMin == scrollMax) { + bar->SetValue (bottom); + changed = true; + } + } - if (constrain) - ConstrainClippingRegion (NULL); + if (constrain) + ConstrainClippingRegion (NULL); - return changed; + return changed; } void RunView::Append ( - const char *buffer, - int16 fore, - int16 back, - int16 font) + const char* buffer, + int16 fore, + int16 back, + int16 font) { - Append (buffer, strlen (buffer), fore, back, font); + Append (buffer, strlen (buffer), fore, back, font); } void RunView::Append ( - const char *buffer, - int32 len, - int16 fore, - int16 back, - int16 font) + const char* buffer, + int32 len, + int16 fore, + int16 back, + int16 font) { - if (buffer == NULL) - return; - float width (Bounds().Width() - 10); - int32 place (0); + if (buffer == NULL) + return; + float width (Bounds().Width() - 10); + int32 place (0); - assert (fore != Theme::TimestampFore); - assert (back != Theme::TimestampBack); - assert (font != Theme::TimestampFont); - assert (fore != Theme::TimespaceFore); - assert (back != Theme::TimespaceBack); - assert (font != Theme::TimespaceFont); - assert (back != Theme::SelectionBack); + assert (fore != Theme::TimestampFore); + assert (back != Theme::TimestampBack); + assert (font != Theme::TimestampFont); + assert (fore != Theme::TimespaceFore); + assert (back != Theme::TimespaceBack); + assert (font != Theme::TimespaceFont); + assert (back != Theme::SelectionBack); - fTheme->ReadLock(); + fTheme->ReadLock(); - while (place < len) - { - int32 end (place); + while (place < len) { + int32 end (place); - while (end < len && buffer[end] != '\n') - ++end; - - if (end < len) ++end; + while (end < len && buffer[end] != '\n') + ++end; - if (fWorking) - { - - URLCrunch crunch (buffer + place, end - place); - BString temp; - int32 url_offset (0), - last_offset (0); + if (end < len) ++end; + + if (fWorking) { + + URLCrunch crunch (buffer + place, end - place); + BString temp; + int32 url_offset (0), + last_offset (0); - while ((url_offset = crunch.Crunch (&temp)) != B_ERROR) - { - fWorking->Append (buffer + place, - (url_offset - last_offset), - width, - fTheme, - fore, - back, - font); + while ((url_offset = crunch.Crunch (&temp)) != B_ERROR) { + fWorking->Append (buffer + place, + (url_offset - last_offset), + width, + fTheme, + fore, + back, + font); - fWorking->Append (temp.String(), - temp.Length(), - width, - fTheme, - C_URL, - back, - F_URL); + fWorking->Append (temp.String(), + temp.Length(), + width, + fTheme, + C_URL, + back, + F_URL); - place += (url_offset - last_offset) + temp.Length(); - last_offset = url_offset + temp.Length(); - } + place += (url_offset - last_offset) + temp.Length(); + last_offset = url_offset + temp.Length(); + } - if (place < end) - fWorking->Append ( - buffer + place, - end - place, - width, - fTheme, - fore, - back, - font); - } - else - { - float top (0.0); + if (place < end) + fWorking->Append ( + buffer + place, + end - place, + width, + fTheme, + fore, + back, + font); + } else { + float top (0.0); - if (fLine_count > 0) - top = fLines[fLine_count - 1]->fBottom + 1.0; + if (fLine_count > 0) + top = fLines[fLine_count - 1]->fBottom + 1.0; -//HERE - fWorking = new Line ( - buffer + place, - 0, - top, - width, - fTheme, - fStamp_format, - fore, - back, - font); + //HERE + fWorking = new Line ( + buffer + place, + 0, + top, + width, + fTheme, + fStamp_format, + fore, + back, + font); - URLCrunch crunch (buffer + place, end - place); - BString temp; - int32 url_offset (0), - last_offset (0); + URLCrunch crunch (buffer + place, end - place); + BString temp; + int32 url_offset (0), + last_offset (0); - while ((url_offset = crunch.Crunch (&temp)) != B_ERROR) - { - fWorking->Append (buffer + place, - (url_offset - last_offset), - width, - fTheme, - fore, - back, - font); - fWorking->Append (temp.String(), - temp.Length(), - width, - fTheme, - C_URL, - back, - F_URL); + while ((url_offset = crunch.Crunch (&temp)) != B_ERROR) { + fWorking->Append (buffer + place, + (url_offset - last_offset), + width, + fTheme, + fore, + back, + font); + fWorking->Append (temp.String(), + temp.Length(), + width, + fTheme, + C_URL, + back, + F_URL); - place += (url_offset - last_offset) + temp.Length(); - last_offset = url_offset + temp.Length(); - } + place += (url_offset - last_offset) + temp.Length(); + last_offset = url_offset + temp.Length(); + } - if (place < end) - fWorking->Append (buffer + place, - end - place, - width, - fTheme, - fore, - back, - font); - } + if (place < end) + fWorking->Append (buffer + place, + end - place, + width, + fTheme, + fore, + back, + font); + } - if (fWorking->fLength - && fWorking->fText[fWorking->fLength - 1] == '\n') - { - bool chopped; + if (fWorking->fLength + && fWorking->fText[fWorking->fLength - 1] == '\n') { + bool chopped; - if (Window()) Window()->DisableUpdates(); + if (Window()) Window()->DisableUpdates(); - if ((chopped = (fLine_count == LINE_COUNT))) - { - Line *first (fLines[0]); - float shift (first->fBottom + 1); + if ((chopped = (fLine_count == LINE_COUNT))) { + Line* first (fLines[0]); + float shift (first->fBottom + 1); - for (int16 i = 1; i < LINE_COUNT; ++i) - { - fLines[i]->fTop -= shift; - fLines[i]->fBottom -= shift; + for (int16 i = 1; i < LINE_COUNT; ++i) { + fLines[i]->fTop -= shift; + fLines[i]->fBottom -= shift; - fLines[i - 1] = fLines[i]; - } + fLines[i - 1] = fLines[i]; + } - fWorking->fTop -= shift; - fWorking->fBottom -= shift; + fWorking->fTop -= shift; + fWorking->fBottom -= shift; - delete first; - - if (fSp_start.fLine > 0) - fSp_start.fLine--; - else - fSp_start.fOffset = 0; - - if (fSp_end.fLine > 0) - fSp_end.fLine--; - else - fSp_end.fOffset = 0; + delete first; - // Recalc the scrollbar so that we have clean drawing - // after the line has been removed - --fLine_count; - RecalcScrollBar (true); - } + if (fSp_start.fLine > 0) + fSp_start.fLine--; + else + fSp_start.fOffset = 0; - fLines[fLine_count++] = fWorking; - RecalcScrollBar (true); + if (fSp_end.fLine > 0) + fSp_end.fLine--; + else + fSp_end.fOffset = 0; - Invalidate (Bounds()); + // Recalc the scrollbar so that we have clean drawing + // after the line has been removed + --fLine_count; + RecalcScrollBar (true); + } - if (Window()) - { - Window()->EnableUpdates(); - Window()->UpdateIfNeeded(); - } + fLines[fLine_count++] = fWorking; + RecalcScrollBar (true); - fWorking = NULL; - } + Invalidate (Bounds()); - place = end; - } + if (Window()) { + Window()->EnableUpdates(); + Window()->UpdateIfNeeded(); + } - fTheme->ReadUnlock(); + fWorking = NULL; + } + + place = end; + } + + fTheme->ReadUnlock(); } void RunView::Clear (void) { - for (int16 i = 0; i < fLine_count; ++i) - delete fLines[i]; + for (int16 i = 0; i < fLine_count; ++i) + delete fLines[i]; - fLine_count = 0; - RecalcScrollBar (true); - Invalidate(); + fLine_count = 0; + RecalcScrollBar (true); + Invalidate(); - fSp_start.fLine = 0; - fSp_start.fOffset = 0; - fSp_end = fSp_start; + fSp_start.fLine = 0; + fSp_start.fOffset = 0; + fSp_end = fSp_start; - if (fWorking) - fWorking->fTop = 0.0; + if (fWorking) + fWorking->fTop = 0.0; } int16 RunView::LineCount (void) const { - return fLine_count; + return fLine_count; } const char * RunView::LineAt (int16 which) const { - if (which < 0 || which >= fLine_count) - return NULL; + if (which < 0 || which >= fLine_count) + return NULL; - return fLines[which]->fText; + return fLines[which]->fText; } void -RunView::SetTimeStampFormat (const char *format) +RunView::SetTimeStampFormat (const char* format) { - if ((format == NULL - && fStamp_format == NULL) - || (format != NULL - && fStamp_format != NULL - && strcmp (format, fStamp_format) == 0)) - return; + if ((format == NULL + && fStamp_format == NULL) + || (format != NULL + && fStamp_format != NULL + && strcmp (format, fStamp_format) == 0)) + return; - bool was_on (false); + bool was_on (false); - if (fStamp_format) - { - delete [] fStamp_format; - fStamp_format = NULL; - was_on = true; - } + if (fStamp_format) { + delete [] fStamp_format; + fStamp_format = NULL; + was_on = true; + } - if (format) - fStamp_format = strcpy (new char [strlen (format) + 1], format); + if (format) + fStamp_format = strcpy (new char [strlen (format) + 1], format); - float width (Bounds().Width() - (fTheme->TextMargin()*2)); - float top (0.0); + float width (Bounds().Width() - (fTheme->TextMargin() * 2)); + float top (0.0); - fTheme->ReadLock(); - for (int16 i = 0; i < fLine_count; ++i) - { - fLines[i]->fTop = top; + fTheme->ReadLock(); + for (int16 i = 0; i < fLine_count; ++i) { + fLines[i]->fTop = top; - fLines[i]->SetStamp (fStamp_format, was_on); - fLines[i]->FigureSpaces(); - fLines[i]->FigureEdges(fTheme, width); + fLines[i]->SetStamp (fStamp_format, was_on); + fLines[i]->FigureSpaces(); + fLines[i]->FigureEdges(fTheme, width); - top = fLines[i]->fBottom + 1.0; - } - fTheme->ReadUnlock(); + top = fLines[i]->fBottom + 1.0; + } + fTheme->ReadUnlock(); - if (fWorking) - { - fWorking->fTop = top; - fWorking->SetStamp (fStamp_format, was_on); - } + if (fWorking) { + fWorking->fTop = top; + fWorking->SetStamp (fStamp_format, was_on); + } - RecalcScrollBar (false); - Invalidate (Bounds()); - if (Window()) Window()->UpdateIfNeeded(); + RecalcScrollBar (false); + Invalidate (Bounds()); + if (Window()) Window()->UpdateIfNeeded(); } void -RunView::SetTheme (Theme *t) +RunView::SetTheme (Theme* t) { - if (t == NULL || fTheme == t) - return; + if (t == NULL || fTheme == t) + return; - fTheme = t; + fTheme = t; - if (IsHidden()) - { - fFontsdirty = true; - return; - } - FontChangeRecalc(); + if (IsHidden()) { + fFontsdirty = true; + return; + } + FontChangeRecalc(); } SelectPos RunView::PositionAt (BPoint point) const { - int16 i, lfIndex (0); - SelectPos pos (-1, 0); + int16 i, lfIndex (0); + SelectPos pos (-1, 0); - if (fLine_count == 0) - return pos; + if (fLine_count == 0) + return pos; - // find the line - for (i = 0; i < fLine_count; ++i) - { - if (fLines[i]->fTop > point.y) - break; - lfIndex = i; - } + // find the line + for (i = 0; i < fLine_count; ++i) { + if (fLines[i]->fTop > point.y) + break; + lfIndex = i; + } - // check to make sure we actually did find a line and not just run into fLine_count - if (fLines[lfIndex]->fBottom < point.y) - { - pos.fLine = fLine_count - 1; - pos.fOffset = fLines[fLine_count - 1]->fLength; - return pos; - } + // check to make sure we actually did find a line and not just run into fLine_count + if (fLines[lfIndex]->fBottom < point.y) { + pos.fLine = fLine_count - 1; + pos.fOffset = fLines[fLine_count - 1]->fLength; + return pos; + } - float height (fLines[lfIndex]->fTop); - int16 sfIndex (0); + float height (fLines[lfIndex]->fTop); + int16 sfIndex (0); - for (i = 0; i < fLines[lfIndex]->fSoftie_used; ++i) - { - if (height > point.y) - break; + for (i = 0; i < fLines[lfIndex]->fSoftie_used; ++i) { + if (height > point.y) + break; - sfIndex = i; - height += fLines[lfIndex]->fSofties[i].fHeight; - } + sfIndex = i; + height += fLines[lfIndex]->fSofties[i].fHeight; + } - float margin (fTheme->TextMargin()); - float width (0); - int16 start (0); + float margin (fTheme->TextMargin()); + float width (0); + int16 start (0); - if (sfIndex) - { - int16 offset (fLines[lfIndex]->fSofties[sfIndex - 1].fOffset); + if (sfIndex) { + int16 offset (fLines[lfIndex]->fSofties[sfIndex - 1].fOffset); - width = fLines[lfIndex]->fEdges[offset]; - start = offset + UTF8_CHAR_LEN (fLines[lfIndex]->fText[offset]); - } + width = fLines[lfIndex]->fEdges[offset]; + start = offset + UTF8_CHAR_LEN (fLines[lfIndex]->fText[offset]); + } - for (i = start; i <= fLines[lfIndex]->fSofties[sfIndex].fOffset; ++i) - if (fLines[lfIndex]->fEdges[i] + margin - width >= point.x) - break; + for (i = start; i <= fLines[lfIndex]->fSofties[sfIndex].fOffset; ++i) + if (fLines[lfIndex]->fEdges[i] + margin - width >= point.x) + break; - pos.fLine = lfIndex; - pos.fOffset = min_c (i, fLines[lfIndex]->fSofties[sfIndex].fOffset); - if (pos.fOffset > 0) pos.fOffset += UTF8_CHAR_LEN (fLines[pos.fLine]->fText[pos.fOffset]); + pos.fLine = lfIndex; + pos.fOffset = min_c (i, fLines[lfIndex]->fSofties[sfIndex].fOffset); + if (pos.fOffset > 0) pos.fOffset += UTF8_CHAR_LEN (fLines[pos.fLine]->fText[pos.fOffset]); - return pos; + return pos; } BPoint RunView::PointAt (SelectPos s) const { - return BPoint(fLines[s.fLine]->fTop + fLines[s.fLine]->fBottom / 2.0, fLines[s.fLine]->fEdges[s.fOffset]); + return BPoint(fLines[s.fLine]->fTop + fLines[s.fLine]->fBottom / 2.0, fLines[s.fLine]->fEdges[s.fOffset]); } void -RunView::GetSelectionText (BString &string) const +RunView::GetSelectionText (BString& string) const { - if (fSp_start == fSp_end) - return; + if (fSp_start == fSp_end) + return; - if (fSp_start.fLine == fSp_end.fLine) - { - const char *line (LineAt (fSp_start.fLine)); - string.Append (line + fSp_start.fOffset, fSp_end.fOffset - fSp_start.fOffset); - return; - } + if (fSp_start.fLine == fSp_end.fLine) { + const char* line (LineAt (fSp_start.fLine)); + string.Append (line + fSp_start.fOffset, fSp_end.fOffset - fSp_start.fOffset); + return; + } - for (int32 i = fSp_start.fLine; i <= fSp_end.fLine; i++) - { - const char *line (LineAt (i)); - if (i == fSp_start.fLine) - { - line += fSp_start.fOffset; - string.Append (line); - } - else if (i == fSp_end.fLine) - { - string.Append (line, fSp_end.fOffset); - break; - } - else - string.Append (line); - } + for (int32 i = fSp_start.fLine; i <= fSp_end.fLine; i++) { + const char* line (LineAt (i)); + if (i == fSp_start.fLine) { + line += fSp_start.fOffset; + string.Append (line); + } else if (i == fSp_end.fLine) { + string.Append (line, fSp_end.fOffset); + break; + } else + string.Append (line); + } } bool -RunView::IntersectSelection (const SelectPos &start, const SelectPos &end) const +RunView::IntersectSelection (const SelectPos& start, const SelectPos& end) const { - if (fSp_start.fLine == fSp_end.fLine) - { - if (start.fLine == fSp_start.fLine && start.fOffset >= fSp_start.fOffset && start.fOffset < fSp_end.fOffset) - return true; - if (end.fLine == fSp_start.fLine && end.fOffset >= fSp_start.fOffset && end.fOffset < fSp_end.fOffset) - return true; - } - else - { - if (start.fLine > fSp_start.fLine && start.fLine < fSp_end.fLine) - return true; - if (end.fLine > fSp_start.fLine && end.fLine < fSp_end.fLine) - return true; - if (start.fLine == fSp_start.fLine && start.fOffset >= fSp_start.fOffset) - return true; - if (end.fLine == fSp_start.fLine && end.fOffset >= fSp_start.fOffset) - return true; - if (start.fLine == fSp_end.fLine && start.fOffset < fSp_end.fOffset) - return true; - if (end.fLine == fSp_end.fLine && end.fOffset < fSp_end.fOffset) - return true; - } + if (fSp_start.fLine == fSp_end.fLine) { + if (start.fLine == fSp_start.fLine && start.fOffset >= fSp_start.fOffset && start.fOffset < fSp_end.fOffset) + return true; + if (end.fLine == fSp_start.fLine && end.fOffset >= fSp_start.fOffset && end.fOffset < fSp_end.fOffset) + return true; + } else { + if (start.fLine > fSp_start.fLine && start.fLine < fSp_end.fLine) + return true; + if (end.fLine > fSp_start.fLine && end.fLine < fSp_end.fLine) + return true; + if (start.fLine == fSp_start.fLine && start.fOffset >= fSp_start.fOffset) + return true; + if (end.fLine == fSp_start.fLine && end.fOffset >= fSp_start.fOffset) + return true; + if (start.fLine == fSp_end.fLine && start.fOffset < fSp_end.fOffset) + return true; + if (end.fLine == fSp_end.fLine && end.fOffset < fSp_end.fOffset) + return true; + } - return false; + return false; } BRect -RunView::GetTextFrame(const SelectPos &start, const SelectPos &end) const +RunView::GetTextFrame(const SelectPos& start, const SelectPos& end) const { - return BRect (0.0, fLines[(start.fLine > 0) ? (start.fLine - 1) : 0]->fTop, - Bounds().Width(), fLines[end.fLine]->fBottom); + return BRect (0.0, fLines[(start.fLine > 0) ? (start.fLine - 1) : 0]->fTop, + Bounds().Width(), fLines[end.fLine]->fBottom); } void -RunView::Select (const SelectPos &start, const SelectPos &end) +RunView::Select (const SelectPos& start, const SelectPos& end) { - if (fSp_start != fSp_end) - { - if (start == end || !IntersectSelection (start, end)) - { - BRect frame (GetTextFrame (fSp_start, fSp_end)); + if (fSp_start != fSp_end) { + if (start == end || !IntersectSelection (start, end)) { + BRect frame (GetTextFrame (fSp_start, fSp_end)); - fSp_start = start; - fSp_end = start; - Invalidate (frame); - } - else - { - if (fSp_start.fLine < start.fLine || (fSp_start.fLine == start.fLine && fSp_start.fOffset < start.fOffset)) - { - BRect frame (GetTextFrame (fSp_start, start)); + fSp_start = start; + fSp_end = start; + Invalidate (frame); + } else { + if (fSp_start.fLine < start.fLine || (fSp_start.fLine == start.fLine && fSp_start.fOffset < start.fOffset)) { + BRect frame (GetTextFrame (fSp_start, start)); - fSp_start = start; - Invalidate (frame); - } + fSp_start = start; + Invalidate (frame); + } - if (end.fLine < fSp_end.fLine || (fSp_end.fLine == end.fLine && end.fOffset < fSp_end.fOffset)) - { - BRect frame (GetTextFrame (end, fSp_end)); + if (end.fLine < fSp_end.fLine || (fSp_end.fLine == end.fLine && end.fOffset < fSp_end.fOffset)) { + BRect frame (GetTextFrame (end, fSp_end)); - fSp_end = end; - Invalidate (frame); - } - } - } + fSp_end = end; + Invalidate (frame); + } + } + } - if (fSp_start == fSp_end) - { - fSp_start = start; - fSp_end = end; + if (fSp_start == fSp_end) { + fSp_start = start; + fSp_end = end; - if (fSp_start != fSp_end) - { - BRect frame (GetTextFrame (start, end)); + if (fSp_start != fSp_end) { + BRect frame (GetTextFrame (start, end)); - Invalidate (frame); - } - } - else // extension - { - if (start.fLine < fSp_start.fLine || (start.fLine == fSp_start.fLine && start.fOffset < fSp_start.fOffset)) - { - BRect frame (GetTextFrame (start, fSp_start)); + Invalidate (frame); + } + } else { // extension + if (start.fLine < fSp_start.fLine || (start.fLine == fSp_start.fLine && start.fOffset < fSp_start.fOffset)) { + BRect frame (GetTextFrame (start, fSp_start)); - fSp_start = start; - Invalidate (frame); - } + fSp_start = start; + Invalidate (frame); + } - if (end.fLine > fSp_end.fLine || (end.fLine == fSp_end.fLine && end.fOffset > fSp_end.fOffset)) - { - BRect frame (GetTextFrame (fSp_end, end)); + if (end.fLine > fSp_end.fLine || (end.fLine == fSp_end.fLine && end.fOffset > fSp_end.fOffset)) { + BRect frame (GetTextFrame (fSp_end, end)); - fSp_end = end; - Invalidate (frame); - } - } + fSp_end = end; + Invalidate (frame); + } + } } void RunView::SelectAll (void) { - if (fLine_count) - { - fSp_start = SelectPos (0, 0); - fSp_end = SelectPos (fLine_count-1, fLines[fLine_count-1]->fLength); - Invalidate(Bounds()); - } + if (fLine_count) { + fSp_start = SelectPos (0, 0); + fSp_end = SelectPos (fLine_count - 1, fLines[fLine_count-1]->fLength); + Invalidate(Bounds()); + } } void -RunView::SetClippingName (const char *name) +RunView::SetClippingName (const char* name) { - delete [] fClipping_name; - fClipping_name = new char[strlen(name) + 1]; - memcpy (fClipping_name, name, strlen(name)); - fClipping_name[strlen(name)] = '\0'; + delete [] fClipping_name; + fClipping_name = new char[strlen(name) + 1]; + memcpy (fClipping_name, name, strlen(name)); + fClipping_name[strlen(name)] = '\0'; } Line::Line ( - const char *buffer, - int16 len, - float top, - float width, - Theme *theme, - const char *stamp_format, - int16 fore, - int16 back, - int16 font) - : fText (NULL), - fStamp (time(NULL)), - fUrls (NULL), - fSpaces (NULL), - fEdges (NULL), - fFcs (NULL), - fSofties (NULL), - fTop (top), - fBottom (0.0), - fLength (len), - fSpace_count (0), - fEdge_count (0), - fFc_count (0), - fSoftie_size (0), - fSoftie_used (0) + const char* buffer, + int16 len, + float top, + float width, + Theme* theme, + const char* stamp_format, + int16 fore, + int16 back, + int16 font) + : fText (NULL), + fStamp (time(NULL)), + fUrls (NULL), + fSpaces (NULL), + fEdges (NULL), + fFcs (NULL), + fSofties (NULL), + fTop (top), + fBottom (0.0), + fLength (len), + fSpace_count (0), + fEdge_count (0), + fFc_count (0), + fSoftie_size (0), + fSoftie_used (0) { - // Very important to call SetStamp before Append, It would look real funny otherwise! - SetStamp( stamp_format, false ); + // Very important to call SetStamp before Append, It would look real funny otherwise! + SetStamp( stamp_format, false ); - Append( buffer, len, width, theme, fore, back, font ); + Append( buffer, len, width, theme, fore, back, font ); } Line::~Line (void) { - delete [] fSpaces; - delete [] fEdges; - delete [] fFcs; - delete [] fText; - delete [] fSofties; - - if (fUrls) - { - while (fUrls->CountItems() > 0) - delete fUrls->RemoveItemAt(0L); - delete fUrls; - } + delete [] fSpaces; + delete [] fEdges; + delete [] fFcs; + delete [] fText; + delete [] fSofties; + + if (fUrls) { + while (fUrls->CountItems() > 0) + delete fUrls->RemoveItemAt(0L); + delete fUrls; + } } void Line::Append ( - const char *buffer, - int16 len, - float width, - Theme *theme, - int16 fore, - int16 back, - int16 font) + const char* buffer, + int16 len, + float width, + Theme* theme, + int16 fore, + int16 back, + int16 font) { - int16 save (fLength); - char *new_fText; + int16 save (fLength); + char* new_fText; - new_fText = new char [fLength + len + 1]; + new_fText = new char [fLength + len + 1]; - if (fText != NULL) - { - memcpy (new_fText, fText, fLength); - delete [] fText; - } + if (fText != NULL) { + memcpy (new_fText, fText, fLength); + delete [] fText; + } - memcpy (new_fText + fLength, buffer, len); - fLength += len; - new_fText[fLength] = '\0'; + memcpy (new_fText + fLength, buffer, len); + fLength += len; + new_fText[fLength] = '\0'; - // replace Tab chars with spaces. - // todo: This should be temp until RunView can properly - // display tabs. - for( char* pos = new_fText + save; *pos; ++pos ) - { - if( '\t' == *pos ) - { - *pos = ' '; - } - } - - fText = new_fText; + // replace Tab chars with spaces. + // todo: This should be temp until RunView can properly + // display tabs. + for ( char* pos = new_fText + save; *pos; ++pos ) { + if ( '\t' == *pos ) { + *pos = ' '; + } + } - FigureFontColors (save, fore, back, font); + fText = new_fText; - if (fore == C_URL) - { - if (!fUrls) - fUrls = new urllist; - fUrls->AddItem (new URL (buffer, save, len)); - } + FigureFontColors (save, fore, back, font); - if (fText[fLength - 1] == '\n') - { - FigureSpaces(); - FigureEdges (theme, width); - } + if (fore == C_URL) { + if (!fUrls) + fUrls = new urllist; + fUrls->AddItem (new URL (buffer, save, len)); + } + + if (fText[fLength - 1] == '\n') { + FigureSpaces(); + FigureEdges (theme, width); + } } void Line::FigureSpaces (void) { - const char spacers[] = " \t\n-\\/"; - const char *buffer (fText); - size_t offset (0), n; - int16 count (0); + const char spacers[] = " \t\n-\\/"; + const char* buffer (fText); + size_t offset (0), n; + int16 count (0); - delete [] fSpaces; - fSpace_count = 0; - while ((n = strcspn (buffer + offset, spacers)) < fLength - offset) - { - ++count; - offset += n + 1; - } + delete [] fSpaces; + fSpace_count = 0; + while ((n = strcspn (buffer + offset, spacers)) < fLength - offset) { + ++count; + offset += n + 1; + } - fSpaces = new int16 [count]; + fSpaces = new int16 [count]; - offset = 0; - while ((n = strcspn (buffer + offset, spacers)) < fLength - offset) - { - fSpaces[fSpace_count++] = n + offset; - offset += n + 1; - } + offset = 0; + while ((n = strcspn (buffer + offset, spacers)) < fLength - offset) { + fSpaces[fSpace_count++] = n + offset; + offset += n + 1; + } } void Line::FigureFontColors ( - int16 pos, - int16 fore, - int16 back, - int16 font) + int16 pos, + int16 fore, + int16 back, + int16 font) { - if (fFc_count) - { - int16 last_fore = -1; - int16 last_back = -1; - int16 last_font = -1; - int16 i; + if (fFc_count) { + int16 last_fore = -1; + int16 last_back = -1; + int16 last_font = -1; + int16 i; - // we have fFcs, so we backtrack for last of each fWhich - for (i = fFc_count - 1; i >= 0; --i) - { - if (last_fore < 0 - && fFcs[i].fWhich == FORE_WHICH) - last_fore = i; - else if (last_back < 0 - && fFcs[i].fWhich == BACK_WHICH) - last_back = i; - else if (last_font < 0 - && fFcs[i].fWhich == FONT_WHICH) - last_font = i; + // we have fFcs, so we backtrack for last of each fWhich + for (i = fFc_count - 1; i >= 0; --i) { + if (last_fore < 0 + && fFcs[i].fWhich == FORE_WHICH) + last_fore = i; + else if (last_back < 0 + && fFcs[i].fWhich == BACK_WHICH) + last_back = i; + else if (last_font < 0 + && fFcs[i].fWhich == FONT_WHICH) + last_font = i; - if (last_fore >= 0 - && last_back >= 0 - && last_font >= 0) - break; - } + if (last_fore >= 0 + && last_back >= 0 + && last_font >= 0) + break; + } - // now figure out how many more we need - int16 count = 0; - if (fFcs[last_fore].fIndex != fore) - ++count; - if (fFcs[last_back].fIndex != back) - ++count; - if (fFcs[last_font].fIndex != font) - ++count; + // now figure out how many more we need + int16 count = 0; + if (fFcs[last_fore].fIndex != fore) + ++count; + if (fFcs[last_back].fIndex != back) + ++count; + if (fFcs[last_font].fIndex != font) + ++count; - if (count) - { - FontColor *new_fFcs; - new_fFcs = new FontColor [fFc_count + count]; - memcpy (new_fFcs, fFcs, fFc_count * sizeof (FontColor)); - delete [] fFcs; - fFcs = new_fFcs; + if (count) { + FontColor* new_fFcs; + new_fFcs = new FontColor [fFc_count + count]; + memcpy (new_fFcs, fFcs, fFc_count * sizeof (FontColor)); + delete [] fFcs; + fFcs = new_fFcs; - if (fFcs[last_fore].fIndex != fore) - { - fFcs[fFc_count].fWhich = FORE_WHICH; - fFcs[fFc_count].fOffset = pos; - fFcs[fFc_count].fIndex = fore; - ++fFc_count; - } + if (fFcs[last_fore].fIndex != fore) { + fFcs[fFc_count].fWhich = FORE_WHICH; + fFcs[fFc_count].fOffset = pos; + fFcs[fFc_count].fIndex = fore; + ++fFc_count; + } - if (fFcs[last_back].fIndex != back) - { - fFcs[fFc_count].fWhich = BACK_WHICH; - fFcs[fFc_count].fOffset = pos; - fFcs[fFc_count].fIndex = back; - ++fFc_count; - } + if (fFcs[last_back].fIndex != back) { + fFcs[fFc_count].fWhich = BACK_WHICH; + fFcs[fFc_count].fOffset = pos; + fFcs[fFc_count].fIndex = back; + ++fFc_count; + } - if (fFcs[last_font].fIndex != font) - { - fFcs[fFc_count].fWhich = FONT_WHICH; - fFcs[fFc_count].fOffset = pos; - fFcs[fFc_count].fIndex = font; - ++fFc_count; - } - } - } - else - { - fFcs = new FontColor [fFc_count = 3]; - fFcs[0].fWhich = FORE_WHICH; - fFcs[0].fOffset = 0; - fFcs[0].fIndex = fore; - fFcs[1].fWhich = BACK_WHICH; - fFcs[1].fOffset = 0; - fFcs[1].fIndex = back; - fFcs[2].fWhich = FONT_WHICH; - fFcs[2].fOffset = 0; - fFcs[2].fIndex = font; - } + if (fFcs[last_font].fIndex != font) { + fFcs[fFc_count].fWhich = FONT_WHICH; + fFcs[fFc_count].fOffset = pos; + fFcs[fFc_count].fIndex = font; + ++fFc_count; + } + } + } else { + fFcs = new FontColor [fFc_count = 3]; + fFcs[0].fWhich = FORE_WHICH; + fFcs[0].fOffset = 0; + fFcs[0].fIndex = fore; + fFcs[1].fWhich = BACK_WHICH; + fFcs[1].fOffset = 0; + fFcs[1].fIndex = back; + fFcs[2].fWhich = FONT_WHICH; + fFcs[2].fOffset = 0; + fFcs[2].fIndex = font; + } } void Line::FigureEdges ( - Theme *theme, - float width) + Theme* theme, + float width) { - delete [] fEdges; - fEdges = new int16 [fLength]; + delete [] fEdges; + fEdges = new int16 [fLength]; - int16 cur_fFcs (0), next_fFcs (0), cur_font (0); + int16 cur_fFcs (0), next_fFcs (0), cur_font (0); - fEdge_count = 0; - while (cur_fFcs < fFc_count) - { - if (fFcs[cur_fFcs].fWhich == FONT_WHICH) - { - cur_font = cur_fFcs; - break; - } + fEdge_count = 0; + while (cur_fFcs < fFc_count) { + if (fFcs[cur_fFcs].fWhich == FONT_WHICH) { + cur_font = cur_fFcs; + break; + } - ++cur_fFcs; - } + ++cur_fFcs; + } - while (cur_fFcs < fFc_count) - { - int16 last_offset (fFcs[cur_fFcs].fOffset); - next_fFcs = cur_fFcs + 1; + while (cur_fFcs < fFc_count) { + int16 last_offset (fFcs[cur_fFcs].fOffset); + next_fFcs = cur_fFcs + 1; - while (next_fFcs < fFc_count) - { - // We want to break at every difference - // but, we want to break on a font if available - if (fFcs[next_fFcs].fOffset > last_offset) - { - while (next_fFcs < fFc_count - && fFcs[next_fFcs].fWhich != FONT_WHICH - && next_fFcs + 1 < fFc_count - && fFcs[next_fFcs + 1].fOffset == fFcs[next_fFcs].fOffset) - ++next_fFcs; + while (next_fFcs < fFc_count) { + // We want to break at every difference + // but, we want to break on a font if available + if (fFcs[next_fFcs].fOffset > last_offset) { + while (next_fFcs < fFc_count + && fFcs[next_fFcs].fWhich != FONT_WHICH + && next_fFcs + 1 < fFc_count + && fFcs[next_fFcs + 1].fOffset == fFcs[next_fFcs].fOffset) + ++next_fFcs; - break; - } - ++next_fFcs; - } + break; + } + ++next_fFcs; + } - if (fFcs[cur_fFcs].fWhich == FONT_WHICH) - cur_font = cur_fFcs; + if (fFcs[cur_fFcs].fWhich == FONT_WHICH) + cur_font = cur_fFcs; - int16 ccount; - int16 seglen; + int16 ccount; + int16 seglen; - if (next_fFcs == fFc_count) - { - ccount = CountChars (fFcs[cur_fFcs].fOffset, fLength - fFcs[cur_fFcs].fOffset); - seglen = fLength - fFcs[cur_fFcs].fOffset; - } - else - { - ccount = CountChars ( - fFcs[cur_fFcs].fOffset, - fFcs[next_fFcs].fOffset - fFcs[cur_fFcs].fOffset); - seglen = fFcs[next_fFcs].fOffset - fFcs[cur_fFcs].fOffset; - } + if (next_fFcs == fFc_count) { + ccount = CountChars (fFcs[cur_fFcs].fOffset, fLength - fFcs[cur_fFcs].fOffset); + seglen = fLength - fFcs[cur_fFcs].fOffset; + } else { + ccount = CountChars ( + fFcs[cur_fFcs].fOffset, + fFcs[next_fFcs].fOffset - fFcs[cur_fFcs].fOffset); + seglen = fFcs[next_fFcs].fOffset - fFcs[cur_fFcs].fOffset; + } - // const BFont &f (theme->FontAt (fFcs[cur_font].fIndex)); - TextRender *tr=theme->TextRenderAt (fFcs[cur_font].fIndex); + // const BFont &f (theme->FontAt (fFcs[cur_font].fIndex)); + TextRender* tr = theme->TextRenderAt (fFcs[cur_font].fIndex); #ifdef __INTEL__ - float eshift[ccount]; + float eshift[ccount]; #else - float *eshift = new float[ccount]; + float* eshift = new float[ccount]; #endif - - /* f.GetEscapements ( - fText + fFcs[cur_fFcs].fOffset, - ccount, - eshift);*/ -// if(tr) - tr->GetEscapements ( - fText + fFcs[cur_fFcs].fOffset, - ccount, - eshift); - - // This is not perfect, because we are including the left edge, - // but BFont::GetEdges doesn't seem to work as we'd like + /* f.GetEscapements ( + fText + fFcs[cur_fFcs].fOffset, + ccount, + eshift);*/ - int16 i; - float size=0; - -// if(tr) - size=tr->Size(); - - - float incrementor = (fEdge_count > 0) ? fEdges[fEdge_count - 1] : 0; - - for (i = 0; i < ccount; ++i) - { - incrementor += eshift[i] * size; + // if(tr) + tr->GetEscapements ( + fText + fFcs[cur_fFcs].fOffset, + ccount, + eshift); - fEdges[fEdge_count+i] = (int16) incrementor; - - // this little backfTracking routine is necessary in the case where an fFcs change - // comes immediately after a UTF8-char, since all but the first edge will be 0 - // and thus the new edge's starting position will be thrown off if we don't - // backtrack to the beginning of the char - if ((fEdge_count + i > 0) && fEdges[fEdge_count + i - 1] == 0) - { - int32 temp = fEdge_count + i - 1; - while (fEdges[--temp] == 0); - fEdges[fEdge_count + i] += fEdges[temp]; - } - } + // This is not perfect, because we are including the left edge, + // but BFont::GetEdges doesn't seem to work as we'd like - for (i = fFcs[cur_fFcs].fOffset; i < fFcs[cur_fFcs].fOffset + seglen;) - { - int32 len (UTF8_CHAR_LEN (fText[i]) - 1); + int16 i; + float size = 0; - if (len) - { - int16 k; - for (k = fEdge_count + ccount - 1; k > i; --k) - fEdges[k + len] = fEdges[k]; + // if(tr) + size = tr->Size(); - for (k = 1; k <= len; ++k) - fEdges[i + k] = 0; - ccount += len; - } + float incrementor = (fEdge_count > 0) ? fEdges[fEdge_count - 1] : 0; - i += len + 1; - } + for (i = 0; i < ccount; ++i) { + incrementor += eshift[i] * size; - cur_fFcs = next_fFcs; - fEdge_count += ccount; + fEdges[fEdge_count+i] = (int16) incrementor; + + // this little backfTracking routine is necessary in the case where an fFcs change + // comes immediately after a UTF8-char, since all but the first edge will be 0 + // and thus the new edge's starting position will be thrown off if we don't + // backtrack to the beginning of the char + if ((fEdge_count + i > 0) && fEdges[fEdge_count + i - 1] == 0) { + int32 temp = fEdge_count + i - 1; + while (fEdges[--temp] == 0); + fEdges[fEdge_count + i] += fEdges[temp]; + } + } + + for (i = fFcs[cur_fFcs].fOffset; i < fFcs[cur_fFcs].fOffset + seglen;) { + int32 len (UTF8_CHAR_LEN (fText[i]) - 1); + + if (len) { + int16 k; + for (k = fEdge_count + ccount - 1; k > i; --k) + fEdges[k + len] = fEdges[k]; + + for (k = 1; k <= len; ++k) + fEdges[i + k] = 0; + + ccount += len; + } + + i += len + 1; + } + + cur_fFcs = next_fFcs; + fEdge_count += ccount; #ifndef __INTEL__ - delete [] eshift; + delete [] eshift; #endif - } + } - SoftBreaks (theme, width); + SoftBreaks (theme, width); } void -Line::AddSoftBreak (SoftBreakEnd sbe, float &start, uint16 &fText_place, - int16 &font, float &width, float &start_width, Theme *theme) +Line::AddSoftBreak (SoftBreakEnd sbe, float& start, uint16& fText_place, + int16& font, float& width, float& start_width, Theme* theme) { - fText_place = sbe.fOffset; + fText_place = sbe.fOffset; - if (fSoftie_size < fSoftie_used + 1) - { - SoftBreak *new_softies; + if (fSoftie_size < fSoftie_used + 1) { + SoftBreak* new_softies; - new_softies = new SoftBreak [fSoftie_size += SOFTBREAK_STEP]; + new_softies = new SoftBreak [fSoftie_size += SOFTBREAK_STEP]; - if (fSofties) - { - memcpy (new_softies, fSofties, sizeof (SoftBreak) * fSoftie_used); - delete [] fSofties; - } + if (fSofties) { + memcpy (new_softies, fSofties, sizeof (SoftBreak) * fSoftie_used); + delete [] fSofties; + } - fSofties = new_softies; - } + fSofties = new_softies; + } - // consume whitespace - while (fText_place + 1 < fLength - && isspace (fText[fText_place + 1])) - ++fText_place; + // consume whitespace + while (fText_place + 1 < fLength + && isspace (fText[fText_place + 1])) + ++fText_place; - fSofties[fSoftie_used].fOffset = fText_place; - fSofties[fSoftie_used].fHeight = 0.0; - fSofties[fSoftie_used].fAscent = 0.0; + fSofties[fSoftie_used].fOffset = fText_place; + fSofties[fSoftie_used].fHeight = 0.0; + fSofties[fSoftie_used].fAscent = 0.0; - int16 last (font); - while (font < fFc_count) - { - TextRender *tr = theme->TextRenderAt (fFcs[font].fIndex); - - font_height fh; - float height; + int16 last (font); + while (font < fFc_count) { + TextRender* tr = theme->TextRenderAt (fFcs[font].fIndex); - tr->GetHeight (&fh); + font_height fh; + float height; - height = ceil (fh.ascent + fh.descent + fh.leading); - if (fSofties[fSoftie_used].fHeight < height) - fSofties[fSoftie_used].fHeight = height; - if (fSofties[fSoftie_used].fAscent < fh.ascent) - fSofties[fSoftie_used].fAscent = fh.ascent; + tr->GetHeight (&fh); - // now try and find next - while (++font < fFc_count) - if (fFcs[font].fWhich == FONT_WHICH) - break; + height = ceil (fh.ascent + fh.descent + fh.leading); + if (fSofties[fSoftie_used].fHeight < height) + fSofties[fSoftie_used].fHeight = height; + if (fSofties[fSoftie_used].fAscent < fh.ascent) + fSofties[fSoftie_used].fAscent = fh.ascent; - if (font == fFc_count - || fFcs[font].fOffset > fText_place) - { - font = last; - break; - } + // now try and find next + while (++font < fFc_count) + if (fFcs[font].fWhich == FONT_WHICH) + break; - last = font; - } + if (font == fFc_count + || fFcs[font].fOffset > fText_place) { + font = last; + break; + } - if (fText_place < fLength) - start = fEdges[fText_place]; + last = font; + } - fBottom += fSofties[fSoftie_used++].fHeight; - fText_place += UTF8_CHAR_LEN (fText[fText_place]); - width = start_width - (theme->SoftLineIndent()); + if (fText_place < fLength) + start = fEdges[fText_place]; + + fBottom += fSofties[fSoftie_used++].fHeight; + fText_place += UTF8_CHAR_LEN (fText[fText_place]); + width = start_width - (theme->SoftLineIndent()); } void -Line::SoftBreaks (Theme *theme, float start_width) +Line::SoftBreaks (Theme* theme, float start_width) { - float margin (theme->TextMargin()); - float width (start_width); - float start (0.0); - uint16 fText_place (0); - int16 space_place (0); - int16 font (0); + float margin (theme->TextMargin()); + float width (start_width); + float start (0.0); + uint16 fText_place (0); + int16 space_place (0); + int16 font (0); - fSoftie_used = 0; - fBottom = fTop; + fSoftie_used = 0; + fBottom = fTop; - // find first font - while (font < fFc_count && fFcs[font].fWhich != FONT_WHICH) - ++font; + // find first font + while (font < fFc_count && fFcs[font].fWhich != FONT_WHICH) + ++font; - while (fText_place < fLength) - { - while (space_place < fSpace_count) - { - if (fEdges[fSpaces[space_place]] - start > width) - break; + while (fText_place < fLength) { + while (space_place < fSpace_count) { + if (fEdges[fSpaces[space_place]] - start > width) + break; - ++space_place; - } + ++space_place; + } - // we've reached the end of the line (but it might not all fit) - // or we only have one space, so we check if we need to split the word - if (space_place == fSpace_count - || space_place == 0 - || fSpaces[space_place - 1] < fText_place) - { - // everything fits.. how wonderful (but we want at least one softbreak) - if (fEdge_count == 0) - { - AddSoftBreak (SoftBreakEnd(fLength - 1), start, fText_place, font, width, start_width, theme); - break; - } + // we've reached the end of the line (but it might not all fit) + // or we only have one space, so we check if we need to split the word + if (space_place == fSpace_count + || space_place == 0 + || fSpaces[space_place - 1] < fText_place) { + // everything fits.. how wonderful (but we want at least one softbreak) + if (fEdge_count == 0) { + AddSoftBreak (SoftBreakEnd(fLength - 1), start, fText_place, font, width, start_width, theme); + break; + } - int16 i (fEdge_count - 1); + int16 i (fEdge_count - 1); - while (fEdges[i] == 0) - --i; - - if (fEdges[i] - start <= width) - { - AddSoftBreak (SoftBreakEnd(fLength - 1), start, fText_place, font, width, start_width, theme); - continue; - } + while (fEdges[i] == 0) + --i; - // we force at least one character - // your font may be a little too large for your window! - fText_place += UTF8_CHAR_LEN (fText[fText_place]); - while (fText_place < fLength) - { - if (fEdges[fText_place] - start > width - margin) - break; + if (fEdges[i] - start <= width) { + AddSoftBreak (SoftBreakEnd(fLength - 1), start, fText_place, font, width, start_width, theme); + continue; + } - fText_place += UTF8_CHAR_LEN (fText[fText_place]); - } - AddSoftBreak (SoftBreakEnd(fText_place), start, fText_place, font, width, start_width, theme); - continue; - } + // we force at least one character + // your font may be a little too large for your window! + fText_place += UTF8_CHAR_LEN (fText[fText_place]); + while (fText_place < fLength) { + if (fEdges[fText_place] - start > width - margin) + break; - // we encountered more than one space, so we rule out having to - // split the word, if the current word will fit within the bounds - int16 ccount1, ccount2; - --space_place; + fText_place += UTF8_CHAR_LEN (fText[fText_place]); + } + AddSoftBreak (SoftBreakEnd(fText_place), start, fText_place, font, width, start_width, theme); + continue; + } - ccount1 = fSpaces[space_place]; - ccount2 = fSpaces[space_place+1] - ccount1; + // we encountered more than one space, so we rule out having to + // split the word, if the current word will fit within the bounds + int16 ccount1, ccount2; + --space_place; - int16 i (ccount1 - 1); - while (fEdges[i] == 0) - --i; - - if (fEdges[ccount1 + ccount2] - fEdges[i] < width - margin) - { - AddSoftBreak (SoftBreakEnd(fSpaces[space_place]), start, fText_place, font, width, start_width, theme); - continue; - } + ccount1 = fSpaces[space_place]; + ccount2 = fSpaces[space_place+1] - ccount1; - // We need to break up the really long word - fText_place = fSpaces[space_place]; - while (fText_place < fEdge_count) - { - if ((fEdges[fText_place] - start) > width) - break; + int16 i (ccount1 - 1); + while (fEdges[i] == 0) + --i; - fText_place += UTF8_CHAR_LEN (fText[fText_place]); - } - } + if (fEdges[ccount1 + ccount2] - fEdges[i] < width - margin) { + AddSoftBreak (SoftBreakEnd(fSpaces[space_place]), start, fText_place, font, width, start_width, theme); + continue; + } - fBottom -= 1.0; + // We need to break up the really long word + fText_place = fSpaces[space_place]; + while (fText_place < fEdge_count) { + if ((fEdges[fText_place] - start) > width) + break; + + fText_place += UTF8_CHAR_LEN (fText[fText_place]); + } + } + + fBottom -= 1.0; } int16 Line::CountChars (int16 pos, int16 len) { - int16 ccount (0); + int16 ccount (0); - if (pos >= fLength) - return ccount; + if (pos >= fLength) + return ccount; - if (pos + len > fLength) - len = fLength - pos; + if (pos + len > fLength) + len = fLength - pos; - register int16 i = pos; - while (i < pos + len) - { - i += UTF8_CHAR_LEN(fText[i]); - ++ccount; - } + register int16 i = pos; + while (i < pos + len) { + i += UTF8_CHAR_LEN(fText[i]); + ++ccount; + } - return ccount; + return ccount; } size_t -Line::SetStamp (const char *format, bool was_on) +Line::SetStamp (const char* format, bool was_on) { - size_t size (0); - int32 i (0); - - if (was_on) - { - int16 offset (fFcs[4].fOffset + 1); + size_t size (0); + int32 i (0); - if (fUrls) - { - for (i = 0; i < fUrls->CountItems(); i++) - fUrls->ItemAt(i)->fOffset -= offset; - } - memmove (fText, fText + offset, fLength - offset); - fText[fLength -= offset] = '\0'; + if (was_on) { + int16 offset (fFcs[4].fOffset + 1); - for (i = 6; i < fFc_count; ++i) - { - fFcs[i].fOffset -= offset; - fFcs[i - 6] = fFcs[i]; - } + if (fUrls) { + for (i = 0; i < fUrls->CountItems(); i++) + fUrls->ItemAt(i)->fOffset -= offset; + } + memmove (fText, fText + offset, fLength - offset); + fText[fLength -= offset] = '\0'; - fFc_count -= 6; - } + for (i = 6; i < fFc_count; ++i) { + fFcs[i].fOffset -= offset; + fFcs[i - 6] = fFcs[i]; + } - if (format) - { - char buffer[1024]; - struct tm curTime; + fFc_count -= 6; + } - localtime_r (&fStamp, &curTime); - size = strftime (buffer, 1023, format, &curTime); - if (fUrls) - { - for (i = 0; i < fUrls->CountItems(); i++) - fUrls->ItemAt(i)->fOffset += size; - } + if (format) { + char buffer[1024]; + struct tm curTime; - char *new_fText; + localtime_r (&fStamp, &curTime); + size = strftime (buffer, 1023, format, &curTime); + if (fUrls) { + for (i = 0; i < fUrls->CountItems(); i++) + fUrls->ItemAt(i)->fOffset += size; + } - new_fText = new char [fLength + size + 2]; - memcpy (new_fText, buffer, size); - new_fText[size++] = ' '; - new_fText[size] = '\0'; + char* new_fText; - if (fText) - { - memcpy (new_fText + size, fText, fLength); - delete [] fText; - } + new_fText = new char [fLength + size + 2]; + memcpy (new_fText, buffer, size); + new_fText[size++] = ' '; + new_fText[size] = '\0'; - fText = new_fText; - fText[fLength += size] = '\0'; + if (fText) { + memcpy (new_fText + size, fText, fLength); + delete [] fText; + } - FontColor *new_fFcs; - new_fFcs = new FontColor [fFc_count + 6]; + fText = new_fText; + fText[fLength += size] = '\0'; - if (fFcs) - { - memcpy ( - new_fFcs + 6, - fFcs, - fFc_count * sizeof (FontColor)); - delete [] fFcs; - } - fFcs = new_fFcs; - fFc_count += 6; + FontColor* new_fFcs; + new_fFcs = new FontColor [fFc_count + 6]; - fFcs[0].fWhich = FORE_WHICH; - fFcs[0].fIndex = Theme::TimestampFore; - fFcs[0].fOffset = 0; - fFcs[1].fWhich = BACK_WHICH; - fFcs[1].fIndex = Theme::TimestampBack; - fFcs[1].fOffset = 0; - fFcs[2].fWhich = FONT_WHICH; - fFcs[2].fIndex = Theme::TimestampFont; - fFcs[2].fOffset = 0; + if (fFcs) { + memcpy ( + new_fFcs + 6, + fFcs, + fFc_count * sizeof (FontColor)); + delete [] fFcs; + } + fFcs = new_fFcs; + fFc_count += 6; - fFcs[3].fWhich = FORE_WHICH; - fFcs[3].fIndex = Theme::TimespaceFore; - fFcs[3].fOffset = size - 1; - fFcs[4].fWhich = BACK_WHICH; - fFcs[4].fIndex = Theme::TimespaceBack; - fFcs[4].fOffset = size - 1; - fFcs[5].fWhich = FONT_WHICH; - fFcs[5].fIndex = Theme::TimespaceFont; - fFcs[5].fOffset = size - 1; + fFcs[0].fWhich = FORE_WHICH; + fFcs[0].fIndex = Theme::TimestampFore; + fFcs[0].fOffset = 0; + fFcs[1].fWhich = BACK_WHICH; + fFcs[1].fIndex = Theme::TimestampBack; + fFcs[1].fOffset = 0; + fFcs[2].fWhich = FONT_WHICH; + fFcs[2].fIndex = Theme::TimestampFont; + fFcs[2].fOffset = 0; - for (i = 6; i < fFc_count; ++i) - fFcs[i].fOffset += size; - } + fFcs[3].fWhich = FORE_WHICH; + fFcs[3].fIndex = Theme::TimespaceFore; + fFcs[3].fOffset = size - 1; + fFcs[4].fWhich = BACK_WHICH; + fFcs[4].fIndex = Theme::TimespaceBack; + fFcs[4].fOffset = size - 1; + fFcs[5].fWhich = FONT_WHICH; + fFcs[5].fIndex = Theme::TimespaceFont; + fFcs[5].fOffset = size - 1; - return size; + for (i = 6; i < fFc_count; ++i) + fFcs[i].fOffset += size; + } + + return size; } void -Line::SelectWord (int16 *start, int16 *end) +Line::SelectWord (int16* start, int16* end) { - int16 start_tmp (*start), end_tmp (*end); + int16 start_tmp (*start), end_tmp (*end); - while(start_tmp > 0 && fText[start_tmp-1] != ' ') - start_tmp--; + while (start_tmp > 0 && fText[start_tmp-1] != ' ') + start_tmp--; - while ((end_tmp - 1) < fLength && fText[end_tmp] != ' ') - end_tmp++; + while ((end_tmp - 1) < fLength && fText[end_tmp] != ' ') + end_tmp++; - while (end_tmp >= fLength) - --end_tmp; + while (end_tmp >= fLength) + --end_tmp; - *start = start_tmp; - *end = end_tmp; + *start = start_tmp; + *end = end_tmp; } bool -RunView::FindText(const char *text) +RunView::FindText(const char* text) { - bool result (false); - if (text != NULL) - { - for (int32 i = 0; i < fLine_count; i++) - { - char *offset (NULL); - if ((offset = strstr((const char *)fLines[i], text)) != NULL) - { - SelectPos start (i, offset - text), - end (i, (offset - text) + strlen(text)); - Select(start, end); - ScrollTo(0.0, fLines[i]->fTop); - result = true; - break; - } - } - } - return result; + bool result (false); + if (text != NULL) { + for (int32 i = 0; i < fLine_count; i++) { + char* offset (NULL); + if ((offset = strstr((const char*)fLines[i], text)) != NULL) { + SelectPos start (i, offset - text), + end (i, (offset - text) + strlen(text)); + Select(start, end); + ScrollTo(0.0, fLines[i]->fTop); + result = true; + break; + } + } + } + return result; } -void RunView::LoadURL(const char *url) { - BString argument (url); - if (argument.FindFirst ("://") == B_ERROR) - { +void RunView::LoadURL(const char* url) +{ + BString argument (url); + if (argument.FindFirst ("://") == B_ERROR) { - if (argument.IFindFirst ("www") == 0) - argument.Prepend ("http://"); - - else if (argument.IFindFirst ("ftp") == 0) - argument.Prepend ("ftp://"); - } + if (argument.IFindFirst ("www") == 0) + argument.Prepend ("http://"); - const char *args[] = { argument.String(), 0 }; - - if (argument.IFindFirst ("file:") == 0) - { - // The URL is guaranteed to be at least "file:/" - BString file(argument.String() + 5); + else if (argument.IFindFirst ("ftp") == 0) + argument.Prepend ("ftp://"); + } - // todo: Should probably see if the file exists before going through - // all this, but, oh well... ;) - file.Prepend("/boot/beos/system/Tracker "); - file += " &"; // just in case + const char* args[] = { argument.String(), 0 }; - system(file.String()); - } - else if (argument.IFindFirst ("mailto:") == 0) - { - be_roster->Launch ("text/x-email", 1, const_cast(args)); - } - else - { - be_roster->Launch ("text/html", 1, const_cast(args)); - } + if (argument.IFindFirst ("file:") == 0) { + // The URL is guaranteed to be at least "file:/" + BString file(argument.String() + 5); + + // todo: Should probably see if the file exists before going through + // all this, but, oh well... ;) + file.Prepend("/boot/beos/system/Tracker "); + file += " &"; // just in case + + system(file.String()); + } else if (argument.IFindFirst ("mailto:") == 0) { + be_roster->Launch ("text/x-email", 1, const_cast(args)); + } else { + be_roster->Launch ("text/html", 1, const_cast(args)); + } } -void RunView::ScrollToBottom(void) { +void RunView::ScrollToBottom(void) +{ if (fLine_count != 0) { - BScrollBar *scroll = fScroller->ScrollBar(B_VERTICAL); + BScrollBar* scroll = fScroller->ScrollBar(B_VERTICAL); if (scroll != NULL) scroll->SetValue(fLines[fLine_count - 1]->fBottom); ScrollTo(0.0, fLines[fLine_count - 1]->fBottom); }; }; -void RunView::ScrollToSelection(void) { +void RunView::ScrollToSelection(void) +{ if (fLine_count == 0) return; if (fSp_start != fSp_end) ScrollTo(0.0, fLines[fSp_start.fLine]->fTop); - + }; diff --git a/libs/librunview/RunView.h b/libs/librunview/RunView.h index 01aa3d8..c6154ac 100644 --- a/libs/librunview/RunView.h +++ b/libs/librunview/RunView.h @@ -1,25 +1,25 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * * The Original Code is Vision. - * + * * The Initial Developer of the Original Code is The Vision Team. * Portions created by The Vision Team are * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights * Reserved. - * + * * Contributor(s): Rene Gollent * Todd Lair */ - + #ifndef RUNVIEW_H_ #define RUNVIEW_H_ @@ -50,71 +50,68 @@ class BPopUpMenu; class SelectPos { - public: +public: int16 fLine; int16 fOffset; - SelectPos ( - int16 selLine = 0, - int16 selOffset = 0) - : fLine (selLine), - fOffset (selOffset) - { } + SelectPos ( + int16 selLine = 0, + int16 selOffset = 0) + : fLine (selLine), + fOffset (selOffset) + { } - SelectPos (const SelectPos &pos) - : fLine (pos.fLine), - fOffset (pos.fOffset) - { } + SelectPos (const SelectPos& pos) + : fLine (pos.fLine), + fOffset (pos.fOffset) + { } - ~SelectPos (void) - { } + ~SelectPos (void) + { } - SelectPos &operator = (const SelectPos &pos) - { - fLine = pos.fLine; - fOffset = pos.fOffset; + SelectPos& operator = (const SelectPos& pos) { + fLine = pos.fLine; + fOffset = pos.fOffset; + + return *this; + } + + inline int operator == (const SelectPos& rhs) const { + return ((fLine == rhs.fLine) && (fOffset == rhs.fOffset)); + } + + inline int operator != (const SelectPos& rhs) const { + return (!(*this == rhs)); + } - return *this; - } - - inline int operator == (const SelectPos &rhs) const - { - return ((fLine == rhs.fLine) && (fOffset == rhs.fOffset)); - } - - inline int operator != (const SelectPos &rhs) const - { - return (!(*this == rhs)); - } - }; class RunView : public BView { - BScrollView *fScroller; - BCursor *fURLCursor; - Theme *fTheme; + BScrollView* fScroller; + BCursor* fURLCursor; + Theme* fTheme; - Line *fWorking; - Line *fLines[LINE_COUNT]; + Line* fWorking; + Line* fLines[LINE_COUNT]; int16 fLine_count, - fClickCount; + fClickCount; + + char* fStamp_format; + char* fClipping_name; - char *fStamp_format; - char *fClipping_name; - SelectPos fSp_start, fSp_end; - + int32 fTracking; SelectPos fTrack_offset; - BMessageRunner *fOff_view_runner; + BMessageRunner* fOff_view_runner; bigtime_t fOff_view_time; bool fResizedirty; bool fFontsdirty; - BPopUpMenu *fMyPopUp; + BPopUpMenu* fMyPopUp; BPoint fLastClick; bigtime_t fLastClickTime; @@ -127,62 +124,64 @@ class RunView : public BView void CheckURLCursor (BPoint); void BuildPopUp (void); - bool CheckClickBounds (const SelectPos &, const BPoint &) const; - void LoadURL(const char *url); - - public: + bool CheckClickBounds (const SelectPos&, const BPoint&) const; + void LoadURL(const char* url); - RunView ( - BRect, - const char *, - Theme *, - uint32 = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 = 0UL); +public: + + RunView ( + BRect, + const char*, + Theme*, + uint32 = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 = 0UL); virtual ~RunView (void); virtual void AttachedToWindow (void); virtual void DetachedFromWindow (void); virtual void FrameResized (float, float); - virtual void TargetedByScrollView (BScrollView *); + virtual void TargetedByScrollView (BScrollView*); virtual void Show (); virtual void Draw (BRect); - virtual void MessageReceived (BMessage *); + virtual void MessageReceived (BMessage*); virtual void SetViewColor (rgb_color); - void SetViewColor (uchar red, uchar green, uchar blue, uchar alpha = 255) - { rgb_color color = {red, green, blue, alpha}; SetViewColor (color); } + void SetViewColor (uchar red, uchar green, uchar blue, uchar alpha = 255) { + rgb_color color = {red, green, blue, alpha}; + SetViewColor (color); + } + - virtual void MouseDown (BPoint); - virtual void MouseMoved (BPoint, uint32, const BMessage *); + virtual void MouseMoved (BPoint, uint32, const BMessage*); virtual void MouseUp (BPoint); - - void Append (const char *, int32, int16, int16, int16); - void Append (const char *, int16, int16, int16); - + + void Append (const char*, int32, int16, int16, int16); + void Append (const char*, int16, int16, int16); + void Clear (void); int16 LineCount (void) const; - const char *LineAt (int16) const; + const char* LineAt (int16) const; - void SetTimeStampFormat (const char *); - void SetTheme (Theme *); + void SetTimeStampFormat (const char*); + void SetTheme (Theme*); SelectPos PositionAt (BPoint) const; BPoint PointAt (SelectPos) const; - - BRect GetTextFrame (const SelectPos &, const SelectPos &) const; - bool IntersectSelection (const SelectPos &, const SelectPos &) const; - void GetSelectionText (BString &) const; - void Select (const SelectPos &, const SelectPos &); + + BRect GetTextFrame (const SelectPos&, const SelectPos&) const; + bool IntersectSelection (const SelectPos&, const SelectPos&) const; + void GetSelectionText (BString&) const; + void Select (const SelectPos&, const SelectPos&); void SelectAll (void); - void SetClippingName (const char *); - bool FindText(const char *); + void SetClippingName (const char*); + bool FindText(const char*); void ScrollToBottom(void); void ScrollToSelection(void); - + }; diff --git a/libs/librunview/SmileTextRender.h b/libs/librunview/SmileTextRender.h index 3eebd03..8a58444 100644 --- a/libs/librunview/SmileTextRender.h +++ b/libs/librunview/SmileTextRender.h @@ -1,53 +1,52 @@ -#ifndef _SmileTextRender_H_ -#define _SmileTextRender_H_ - -#include "TextRender.h" -#include -#include - -#include -#include -#include -#include - -#include "Emoticor.h" - -class SmileTextRender : public TextRender -{ - public: - - SmileTextRender():TextRender(){}; - - virtual ~SmileTextRender() {}; - - virtual void Render(BView *target,const char* txt,int16 num,BPoint pos) { - - BBitmap *pointer=NULL; - BString f(txt,num); - - if(Emoticor::Get()->Config()->FindPointer(f.String(),(void**)&pointer)==B_OK) - { - target->SetDrawingMode( B_OP_ALPHA ); - target->DrawBitmapAsync( pointer,BPoint(pos.x, pos.y- (Emoticor::Get()->Config()->GetEmoticonSize()/2)) ); - target->SetDrawingMode( B_OP_OVER ); - } - }; - - - virtual float Size(){ return Emoticor::Get()->Config()->GetEmoticonSize();} - - virtual void GetHeight(font_height *h) - { - h->descent = h->ascent = Emoticor::Get()->Config()->GetEmoticonSize()/2; - h->leading=0; - }; - - virtual void - GetEscapements(const char * /*charArray*/, int32 numChars,float escapementArray[]) - { - //font.GetEscapements(charArray,numChars,escapementArray); - escapementArray[0]=1; - for(int i=1;i +#include + +#include +#include +#include +#include + +#include "Emoticor.h" + +class SmileTextRender : public TextRender +{ +public: + + SmileTextRender(): TextRender() {}; + + virtual ~SmileTextRender() {}; + + virtual void Render(BView* target, const char* txt, int16 num, BPoint pos) { + + BBitmap* pointer = NULL; + BString f(txt, num); + + if (Emoticor::Get()->Config()->FindPointer(f.String(), (void**)&pointer) == B_OK) { + target->SetDrawingMode( B_OP_ALPHA ); + target->DrawBitmapAsync( pointer, BPoint(pos.x, pos.y - (Emoticor::Get()->Config()->GetEmoticonSize() / 2)) ); + target->SetDrawingMode( B_OP_OVER ); + } + }; + + + virtual float Size() { + return Emoticor::Get()->Config()->GetEmoticonSize(); + } + + virtual void GetHeight(font_height* h) { + h->descent = h->ascent = Emoticor::Get()->Config()->GetEmoticonSize() / 2; + h->leading = 0; + }; + + virtual void + GetEscapements(const char * /*charArray*/, int32 numChars, float escapementArray[]) { + //font.GetEscapements(charArray,numChars,escapementArray); + escapementArray[0] = 1; + for (int i = 1; i < numChars; i++) escapementArray[i] = 0; + } +}; +#endif diff --git a/libs/librunview/TextRender.h b/libs/librunview/TextRender.h index 366da92..84807f6 100644 --- a/libs/librunview/TextRender.h +++ b/libs/librunview/TextRender.h @@ -5,15 +5,15 @@ class TextRender { - public: - TextRender(){}; - virtual ~TextRender() {}; - - virtual void Render(BView *target,const char*,int16 num,BPoint pos) = 0; - virtual void GetHeight(font_height *height) = 0; - virtual void GetEscapements(const char charArray[], int32 numChars,float escapementArray[])=0; - virtual float Size() = 0; - // - +public: + TextRender() {}; + virtual ~TextRender() {}; + + virtual void Render(BView* target, const char*, int16 num, BPoint pos) = 0; + virtual void GetHeight(font_height* height) = 0; + virtual void GetEscapements(const char charArray[], int32 numChars, float escapementArray[]) = 0; + virtual float Size() = 0; + // + }; #endif diff --git a/libs/librunview/Theme.cpp b/libs/librunview/Theme.cpp index 0eab2b7..a8007d9 100644 --- a/libs/librunview/Theme.cpp +++ b/libs/librunview/Theme.cpp @@ -1,26 +1,26 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Vision. - * +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Vision. + * * The Initial Developer of the Original Code is The Vision Team. * Portions created by The Vision Team are * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights * Reserved. - * + * * Contributor(s): Rene Gollent * Todd Lair * Andrea Anzani, andrea.anzani@gmail.com */ - + #define NUMBER_THEME_READERS 1000 #include @@ -48,79 +48,79 @@ int16 Theme::SelectionBack = 3; Theme::Theme ( - const char *n, - int16 foreCount, - int16 backCount, - int16 renderCount) - : name (NULL), - fores (NULL), - backs (NULL), - text_renders (NULL), - fore_count (max_c (foreCount, 4)), - back_count (max_c (backCount, 4)), - render_count (max_c (renderCount, 4)) + const char* n, + int16 foreCount, + int16 backCount, + int16 renderCount) + : name (NULL), + fores (NULL), + backs (NULL), + text_renders (NULL), + fore_count (max_c (foreCount, 4)), + back_count (max_c (backCount, 4)), + render_count (max_c (renderCount, 4)) { - + fSoftLineIndent = (float)(MARGIN_WIDTH / 2.0); fTextMargin = (float)(MARGIN_WIDTH / 2.0); - - name = strcpy (new char [strlen (n) + 1], n); - fores = new rgb_color [fore_count]; - backs = new rgb_color [back_count]; - - normal_textrender = new NormalTextRender(be_plain_font); - - text_renders = (TextRender**)malloc(render_count*sizeof(TextRender*)); - for ( int i=0; i= fore_count || which < 0) - return color; + if (which >= fore_count || which < 0) + return color; - return fores[which]; + return fores[which]; } const rgb_color Theme::BackgroundAt (int16 which) const { - rgb_color color = {255, 255, 255, 255}; + rgb_color color = {255, 255, 255, 255}; - if (which >= back_count || which < 0) - return color; + if (which >= back_count || which < 0) + return color; - return backs[which]; + return backs[which]; } /* const BFont & @@ -193,63 +193,63 @@ Theme::FontAt (int16 which) const */ TextRender* -Theme::TextRenderAt (int16 which) +Theme::TextRenderAt (int16 which) { - if ( which < 0 ){ - //printf("Theme::TextRenderAt(): which < 0 (%d)\n", which); - return normal_textrender; - } - if ( which >= render_count ){ - //printf("Theme::TextRenderAt(): which >= render_count (%d, %d)\n", which, render_count); - return normal_textrender; - } - - return text_renders[which]; + if ( which < 0 ) { + //printf("Theme::TextRenderAt(): which < 0 (%d)\n", which); + return normal_textrender; + } + if ( which >= render_count ) { + //printf("Theme::TextRenderAt(): which >= render_count (%d, %d)\n", which, render_count); + return normal_textrender; + } + + return text_renders[which]; } bool Theme::SetForeground (int16 which, const rgb_color color) { - if (which >= fore_count || which < 0) - return false; + if (which >= fore_count || which < 0) + return false; - fores[which] = color; - return true; + fores[which] = color; + return true; } bool Theme::SetBackground (int16 which, const rgb_color color) { - if (which >= back_count || which < 0) - return false; + if (which >= back_count || which < 0) + return false; - backs[which] = color; - return true; + backs[which] = color; + return true; } bool -Theme::SetTextRender(int16 which,TextRender *trender) +Theme::SetTextRender(int16 which, TextRender* trender) { - - - if (which >= render_count || which < 0 || !trender) - return false; - - text_renders[which] = trender; - return true; + + + if (which >= render_count || which < 0 || !trender) + return false; + + text_renders[which] = trender; + return true; } void -Theme::AddView (BView *view) +Theme::AddView (BView* view) { - list.AddItem (view); + list.AddItem (view); } void -Theme::RemoveView (BView *view) +Theme::RemoveView (BView* view) { - list.RemoveItem (view); + list.RemoveItem (view); } void diff --git a/libs/librunview/Theme.h b/libs/librunview/Theme.h index fb53413..73d22bf 100644 --- a/libs/librunview/Theme.h +++ b/libs/librunview/Theme.h @@ -1,25 +1,25 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Vision. - * +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Vision. + * * The Initial Developer of the Original Code is The Vision Team. * Portions created by The Vision Team are * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights * Reserved. - * + * * Contributor(s): Rene Gollent * Todd Lair */ - + #ifndef THEME_H_ #define THEME_H_ @@ -37,23 +37,23 @@ class NormalTextRender; class Theme { - char *name; - rgb_color *fores; - rgb_color *backs; - TextRender **text_renders; //FIX!! - + char* name; + rgb_color* fores; + rgb_color* backs; + TextRender** text_renders; //FIX!! + int16 fore_count; int16 back_count; int16 render_count; BList list; sem_id sid; - + float fSoftLineIndent; float fTextMargin; NormalTextRender* normal_textrender; - public: +public: static int16 TimestampFore; static int16 TimestampBack; @@ -66,15 +66,16 @@ class Theme static int16 NormalFont; static int16 SelectionBack; - Theme ( - const char *, - int16, - int16, - int16); + Theme ( + const char*, + int16, + int16, + int16); virtual ~Theme (void); - const char *Name (void) const - { return name; } + const char* Name (void) const { + return name; + } void ReadLock (void); void ReadUnlock (void); @@ -83,36 +84,44 @@ class Theme int16 CountForegrounds (void) const; int16 CountBackgrounds (void) const; -// int16 CountFonts (void) const; + // int16 CountFonts (void) const; int16 CountTextRenders (void) const; - + const rgb_color ForegroundAt (int16) const; const rgb_color BackgroundAt (int16) const; - + //const BFont &FontAt (int16) const; TextRender* TextRenderAt(int16); bool SetForeground (int16, const rgb_color); - bool SetForeground (int16 w, uchar r, uchar g, uchar b, uchar a = 255) - { rgb_color color = {r, g, b, a}; return SetForeground (w, color); } + bool SetForeground (int16 w, uchar r, uchar g, uchar b, uchar a = 255) { + rgb_color color = {r, g, b, a}; + return SetForeground (w, color); + } bool SetBackground (int16, const rgb_color); - bool SetBackground (int16 w, uchar r, uchar g, uchar b, uchar a = 255) - { rgb_color color = {r, g, b, a}; return SetBackground (w, color); } - + bool SetBackground (int16 w, uchar r, uchar g, uchar b, uchar a = 255) { + rgb_color color = {r, g, b, a}; + return SetBackground (w, color); + } + //bool SetFont (int16, const BFont &); - bool SetTextRender(int16, TextRender *); - + bool SetTextRender(int16, TextRender*); + void SetSoftLineIndent(float indent); void SetTextMargin(float margin); - - float TextMargin() const { return fTextMargin; } - float SoftLineIndent() const { return fSoftLineIndent; } - - - - void AddView (BView *); - void RemoveView (BView *); + + float TextMargin() const { + return fTextMargin; + } + float SoftLineIndent() const { + return fSoftLineIndent; + } + + + + void AddView (BView*); + void RemoveView (BView*); }; diff --git a/libs/librunview/URLCrunch.cpp b/libs/librunview/URLCrunch.cpp index c8aaf7e..40199b4 100644 --- a/libs/librunview/URLCrunch.cpp +++ b/libs/librunview/URLCrunch.cpp @@ -1,30 +1,30 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * * The Original Code is Vision. - * + * * The Initial Developer of the Original Code is The Vision Team. * Portions created by The Vision Team are * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights * Reserved. - * + * * Contributor(s): Rene Gollent * Todd Lair */ - + #include #include "URLCrunch.h" -URLCrunch::URLCrunch (const char *data, int32 len) +URLCrunch::URLCrunch (const char* data, int32 len) : buffer (""), current_pos (0) { @@ -36,14 +36,13 @@ URLCrunch::~URLCrunch (void) } int32 -URLCrunch::Crunch (BString *url) +URLCrunch::Crunch (BString* url) { if (current_pos >= buffer.Length()) return B_ERROR; const int32 tagNum = 7; - const char *tags[tagNum] = - { + const char* tags[tagNum] = { "http://", "https://", "www.", @@ -63,37 +62,33 @@ URLCrunch::Crunch (BString *url) markers[i] = buffer.IFindFirst (tags[i], pos); for (i = 0; i < tagNum; ++i) - + if (markers[i] != B_ERROR - && markers[i] < marker) - { + && markers[i] < marker) { url_length = markers[i] + strlen(tags[i]); - + url_length += strcspn (buffer.String() + url_length, " \t\n|\\<>\")(][}{;'*^"); int len (strlen (tags[i])); if (url_length - markers[i] > len - && (isdigit (buffer[markers[i] + len]) - || isalpha (buffer[markers[i] + len]))) - { + && (isdigit (buffer[markers[i] + len]) + || isalpha (buffer[markers[i] + len]))) { marker = markers[i]; pos = url_length + 1; url_length -= marker; - } - else + } else pos = markers[i] + 1; } - - if (marker < buffer.Length()) - { - *url = ""; - url->Append (buffer.String() + marker, url_length); - } + if (marker < buffer.Length()) { + *url = ""; - current_pos = pos; + url->Append (buffer.String() + marker, url_length); + } + + current_pos = pos; return marker < buffer.Length() ? marker : B_ERROR; } diff --git a/libs/librunview/URLCrunch.h b/libs/librunview/URLCrunch.h index e410e16..7129137 100644 --- a/libs/librunview/URLCrunch.h +++ b/libs/librunview/URLCrunch.h @@ -1,25 +1,25 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * * The Original Code is Vision. - * + * * The Initial Developer of the Original Code is The Vision Team. * Portions created by The Vision Team are * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights * Reserved. - * + * * Contributor(s): Todd Lair - * + * */ - + #ifndef URLCRUNCH_H_ #define URLCRUNCH_H_ @@ -30,11 +30,11 @@ class URLCrunch BString buffer; int32 current_pos; - public: +public: - URLCrunch (const char *, int32); - ~URLCrunch (void); - int32 Crunch (BString *); + URLCrunch (const char*, int32); + ~URLCrunch (void); + int32 Crunch (BString*); }; #endif diff --git a/libs/librunview/Utilities.cpp b/libs/librunview/Utilities.cpp index 18e6394..c38eebf 100644 --- a/libs/librunview/Utilities.cpp +++ b/libs/librunview/Utilities.cpp @@ -1,26 +1,26 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Vision. - * +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Vision. + * * The Initial Developer of the Original Code is The Vision Team. * Portions created by The Vision Team are * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights * Reserved. - * + * * Contributor(s): Wade Majors * Todd Lair * Andrew Bazan */ - + #include #include @@ -33,287 +33,277 @@ const float doubleClickThresh = 6; BString -GetWord (const char *cData, int32 wordNeeded) +GetWord (const char* cData, int32 wordNeeded) { - /* - * Function purpose: Get word number {wordNeeded} from {cData} - * (space delimited) - */ - - BString data (cData); - BString buffer ("-9z99"); - int32 wordAt (1), place (0); + /* + * Function purpose: Get word number {wordNeeded} from {cData} + * (space delimited) + */ - while (wordAt != wordNeeded && place != B_ERROR) - { - if ((place = data.FindFirst ('\x20', place)) != B_ERROR) - if (++place < data.Length() - && data[place] != '\x20') - ++wordAt; - } + BString data (cData); + BString buffer ("-9z99"); + int32 wordAt (1), place (0); - if (wordAt == wordNeeded - && place != B_ERROR - && place < data.Length()) - { - int32 end (data.FindFirst ('\x20', place)); + while (wordAt != wordNeeded && place != B_ERROR) { + if ((place = data.FindFirst ('\x20', place)) != B_ERROR) + if (++place < data.Length() + && data[place] != '\x20') + ++wordAt; + } - if (end == B_ERROR) - end = data.Length(); + if (wordAt == wordNeeded + && place != B_ERROR + && place < data.Length()) { + int32 end (data.FindFirst ('\x20', place)); - data.CopyInto (buffer, place, end - place); - } + if (end == B_ERROR) + end = data.Length(); - return buffer; + data.CopyInto (buffer, place, end - place); + } + + return buffer; } BString -GetWordColon (const char *cData, int32 wordNeeded) +GetWordColon (const char* cData, int32 wordNeeded) { - /* - * Function purpose: Get word number {wordNeeded} from {cData} - * (colon delimited) - */ - - BString data (cData); - BString buffer ("-9z99"); - int32 wordAt (1), place (0); + /* + * Function purpose: Get word number {wordNeeded} from {cData} + * (colon delimited) + */ - while (wordAt != wordNeeded && place != B_ERROR) - { - if ((place = data.FindFirst (':', place)) != B_ERROR) - if (++place < data.Length() - && data[place] != ':') - ++wordAt; - } + BString data (cData); + BString buffer ("-9z99"); + int32 wordAt (1), place (0); - if (wordAt == wordNeeded - && place != B_ERROR - && place < data.Length()) - { - int32 end (data.FindFirst (':', place)); + while (wordAt != wordNeeded && place != B_ERROR) { + if ((place = data.FindFirst (':', place)) != B_ERROR) + if (++place < data.Length() + && data[place] != ':') + ++wordAt; + } - if (end == B_ERROR) - end = data.Length(); + if (wordAt == wordNeeded + && place != B_ERROR + && place < data.Length()) { + int32 end (data.FindFirst (':', place)); - data.CopyInto (buffer, place, end - place); - } + if (end == B_ERROR) + end = data.Length(); - return buffer; + data.CopyInto (buffer, place, end - place); + } + + return buffer; } BString -RestOfString (const char *cData, int32 wordStart) +RestOfString (const char* cData, int32 wordStart) { - /* - * Function purpose: Get word number {wordStart} from {cData} - * append the rest of the string after {wordStart} - * (space delimited) - */ + /* + * Function purpose: Get word number {wordStart} from {cData} + * append the rest of the string after {wordStart} + * (space delimited) + */ - BString data (cData); - int32 wordAt (1), place (0); - BString buffer ("-9z99"); - - while (wordAt != wordStart && place != B_ERROR) - { - if ((place = data.FindFirst ('\x20', place)) != B_ERROR) - if (++place < data.Length() - && data[place] != '\x20') - ++wordAt; - } + BString data (cData); + int32 wordAt (1), place (0); + BString buffer ("-9z99"); - if (wordAt == wordStart - && place != B_ERROR - && place < data.Length()) - data.CopyInto (buffer, place, data.Length() - place); + while (wordAt != wordStart && place != B_ERROR) { + if ((place = data.FindFirst ('\x20', place)) != B_ERROR) + if (++place < data.Length() + && data[place] != '\x20') + ++wordAt; + } - return buffer; + if (wordAt == wordStart + && place != B_ERROR + && place < data.Length()) + data.CopyInto (buffer, place, data.Length() - place); + + return buffer; } BString -GetNick (const char *cData) +GetNick (const char* cData) { - /* - * Function purpose: Get nickname from {cData} - * - * Expected format: nickname!user@host.name - */ - - BString data (cData); - BString theNick; + /* + * Function purpose: Get nickname from {cData} + * + * Expected format: nickname!user@host.name + */ - for (int32 i = 1; i < data.Length() && data[i] != '!' && data[i] != '\x20'; ++i) - theNick += data[i]; + BString data (cData); + BString theNick; - return theNick; + for (int32 i = 1; i < data.Length() && data[i] != '!' && data[i] != '\x20'; ++i) + theNick += data[i]; + + return theNick; } BString -GetIdent (const char *cData) +GetIdent (const char* cData) { - /* - * Function purpose: Get identname/username from {cData} - * - * Expected format: nickname!user@host.name - */ - - BString data (GetWord(cData, 1)); - BString theIdent; - int32 place[2]; + /* + * Function purpose: Get identname/username from {cData} + * + * Expected format: nickname!user@host.name + */ - if ((place[0] = data.FindFirst ('!')) != B_ERROR - && (place[1] = data.FindFirst ('@')) != B_ERROR) - { - ++(place[0]); - data.CopyInto (theIdent, place[0], place[1] - place[0]); - } - - return theIdent; + BString data (GetWord(cData, 1)); + BString theIdent; + int32 place[2]; + + if ((place[0] = data.FindFirst ('!')) != B_ERROR + && (place[1] = data.FindFirst ('@')) != B_ERROR) { + ++(place[0]); + data.CopyInto (theIdent, place[0], place[1] - place[0]); + } + + return theIdent; } BString -GetAddress (const char *cData) +GetAddress (const char* cData) { - /* - * Function purpose: Get address/hostname from {cData} - * - * Expected format: nickname!user@host.name - */ + /* + * Function purpose: Get address/hostname from {cData} + * + * Expected format: nickname!user@host.name + */ - BString data (GetWord(cData, 1)); - BString address; - int32 place; + BString data (GetWord(cData, 1)); + BString address; + int32 place; - if ((place = data.FindFirst ('@')) != B_ERROR) - { - int32 length (data.FindFirst ('\x20', place)); + if ((place = data.FindFirst ('@')) != B_ERROR) { + int32 length (data.FindFirst ('\x20', place)); - if (length == B_ERROR) - length = data.Length(); + if (length == B_ERROR) + length = data.Length(); - ++place; - data.CopyInto (address, place, length - place); - } + ++place; + data.CopyInto (address, place, length - place); + } - return address; + return address; } BString TimeStamp() { - /* - * Function purpose: Return the timestamp string - * - */ - -// if(!vision_app->GetBool ("timestamp")) -// return ""; - -// const char *ts_format (vision_app->GetString ("timestamp_format")); - const char *ts_format = "[%H:%M]"; + /* + * Function purpose: Return the timestamp string + * + */ - time_t myTime (time (0)); - tm curTime; - localtime_r (&myTime, &curTime); - - char tempTime[32]; - tempTime[strftime (tempTime, 31, ts_format, &curTime)] = '\0'; - - return BString (tempTime).Append('\x20', 1); + // if(!vision_app->GetBool ("timestamp")) + // return ""; + + // const char *ts_format (vision_app->GetString ("timestamp_format")); + const char* ts_format = "[%H:%M]"; + + time_t myTime (time (0)); + tm curTime; + localtime_r (&myTime, &curTime); + + char tempTime[32]; + tempTime[strftime (tempTime, 31, ts_format, &curTime)] = '\0'; + + return BString (tempTime).Append('\x20', 1); } BString ExpandKeyed ( - const char *incoming, - const char *keys, - const char **expansions) + const char* incoming, + const char* keys, + const char** expansions) { - BString buffer; + BString buffer; - while (incoming && *incoming) - { - if (*incoming == '$') - { - const char *place; + while (incoming && *incoming) { + if (*incoming == '$') { + const char* place; - ++incoming; + ++incoming; - if ((place = strchr (keys, *incoming)) != 0) - buffer += expansions[place - keys]; - else - buffer += *incoming; - } - else - buffer += *incoming; + if ((place = strchr (keys, *incoming)) != 0) + buffer += expansions[place - keys]; + else + buffer += *incoming; + } else + buffer += *incoming; - ++incoming; - } + ++incoming; + } - buffer += "\n"; + buffer += "\n"; - return buffer; + return buffer; } BString -StringToURI (const char *string) +StringToURI (const char* string) { - /* - * Function purpose: Converts {string} to a URI safe format - * - */ + /* + * Function purpose: Converts {string} to a URI safe format + * + */ - BString buffer (string); - buffer.ToLower(); - buffer.ReplaceAll ("%", "%25"); // do this first! - buffer.ReplaceAll ("\n", "%20"); - buffer.ReplaceAll (" ", "%20"); - buffer.ReplaceAll ("\"", "%22"); - buffer.ReplaceAll ("#", "%23"); - buffer.ReplaceAll ("@", "%40"); - buffer.ReplaceAll ("`", "%60"); - buffer.ReplaceAll (":", "%3A"); - buffer.ReplaceAll ("<", "%3C"); - buffer.ReplaceAll (">", "%3E"); - buffer.ReplaceAll ("[", "%5B"); - buffer.ReplaceAll ("\\", "%5C"); - buffer.ReplaceAll ("]", "%5D"); - buffer.ReplaceAll ("^", "%5E"); - buffer.ReplaceAll ("{", "%7B"); - buffer.ReplaceAll ("|", "%7C"); - buffer.ReplaceAll ("}", "%7D"); - buffer.ReplaceAll ("~", "%7E"); - return buffer; + BString buffer (string); + buffer.ToLower(); + buffer.ReplaceAll ("%", "%25"); // do this first! + buffer.ReplaceAll ("\n", "%20"); + buffer.ReplaceAll (" ", "%20"); + buffer.ReplaceAll ("\"", "%22"); + buffer.ReplaceAll ("#", "%23"); + buffer.ReplaceAll ("@", "%40"); + buffer.ReplaceAll ("`", "%60"); + buffer.ReplaceAll (":", "%3A"); + buffer.ReplaceAll ("<", "%3C"); + buffer.ReplaceAll (">", "%3E"); + buffer.ReplaceAll ("[", "%5B"); + buffer.ReplaceAll ("\\", "%5C"); + buffer.ReplaceAll ("]", "%5D"); + buffer.ReplaceAll ("^", "%5E"); + buffer.ReplaceAll ("{", "%7B"); + buffer.ReplaceAll ("|", "%7C"); + buffer.ReplaceAll ("}", "%7D"); + buffer.ReplaceAll ("~", "%7E"); + return buffer; } BString DurationString (int64 value) { - /* - * Function purpose: Return a duration string based on {value} - * - */ - + /* + * Function purpose: Return a duration string based on {value} + * + */ + BString duration; bigtime_t micro = value; - bigtime_t milli = micro/1000; - bigtime_t sec = milli/1000; - bigtime_t min = sec/60; - bigtime_t hours = min/60; - bigtime_t days = hours/24; + bigtime_t milli = micro / 1000; + bigtime_t sec = milli / 1000; + bigtime_t min = sec / 60; + bigtime_t hours = min / 60; + bigtime_t days = hours / 24; char message[512] = ""; if (days) - sprintf(message, "%Ld day%s ",days,days!=1?"s":""); - - if (hours%24) - sprintf(message, "%s%Ld hr%s ",message, hours%24,(hours%24)!=1?"s":""); - - if (min%60) - sprintf(message, "%s%Ld min%s ",message, min%60, (min%60)!=1?"s":""); + sprintf(message, "%Ld day%s ", days, days != 1 ? "s" : ""); - sprintf(message, "%s%Ld.%Ld sec%s",message, sec%60, (milli%1000), (sec%60)!=1?"s":""); + if (hours % 24) + sprintf(message, "%s%Ld hr%s ", message, hours % 24, (hours % 24) != 1 ? "s" : ""); + + if (min % 60) + sprintf(message, "%s%Ld min%s ", message, min % 60, (min % 60) != 1 ? "s" : ""); + + sprintf(message, "%s%Ld.%Ld sec%s", message, sec % 60, (milli % 1000), (sec % 60) != 1 ? "s" : ""); duration += message; @@ -322,57 +312,56 @@ DurationString (int64 value) const char * -RelToAbsPath (const char *append_) +RelToAbsPath (const char* append_) { - app_info ai; - be_app->GetAppInfo (&ai); - - BEntry entry (&ai.ref); - BPath path; - entry.GetPath (&path); - path.GetParent (&path); - path.Append (append_); - - return path.Path(); + app_info ai; + be_app->GetAppInfo (&ai); + + BEntry entry (&ai.ref); + BPath path; + entry.GetPath (&path); + path.GetParent (&path); + path.Append (append_); + + return path.Path(); } int32 -Get440Len (const char *cData) +Get440Len (const char* cData) { - BString data (cData); + BString data (cData); - if (data.Length() < 440) - return data.Length(); - else - { - int32 place (data.FindLast ('\x20', 440)); - if (place == B_ERROR) - return 440; - return place; - } + if (data.Length() < 440) + return data.Length(); + else { + int32 place (data.FindLast ('\x20', 440)); + if (place == B_ERROR) + return 440; + return place; + } } uint16 -CheckClickCount(BPoint point, BPoint &lastClick, bigtime_t sysTime, bigtime_t &lastClickTime, int16 &clickCount) +CheckClickCount(BPoint point, BPoint& lastClick, bigtime_t sysTime, bigtime_t& lastClickTime, int16& clickCount) { - // check time and proximity - BPoint delta = point - lastClick; + // check time and proximity + BPoint delta = point - lastClick; - bigtime_t timeDelta = sysTime - lastClickTime; + bigtime_t timeDelta = sysTime - lastClickTime; - bigtime_t doubleClickSpeed; - get_click_speed(&doubleClickSpeed); + bigtime_t doubleClickSpeed; + get_click_speed(&doubleClickSpeed); - lastClickTime = sysTime; + lastClickTime = sysTime; - if (timeDelta < doubleClickSpeed - && fabs(delta.x) < doubleClickThresh - && fabs(delta.y) < doubleClickThresh) - return (++clickCount); + if (timeDelta < doubleClickSpeed + && fabs(delta.x) < doubleClickThresh + && fabs(delta.y) < doubleClickThresh) + return (++clickCount); - lastClick = point; - clickCount = 1; - return clickCount; + lastClick = point; + clickCount = 1; + return clickCount; } diff --git a/libs/librunview/Utilities.h b/libs/librunview/Utilities.h index 80af0ca..0695d27 100644 --- a/libs/librunview/Utilities.h +++ b/libs/librunview/Utilities.h @@ -1,70 +1,68 @@ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Vision. - * +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Vision. + * * The Initial Developer of the Original Code is The Vision Team. * Portions created by The Vision Team are * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights * Reserved. - * + * * Contributor(s): Wade Majors * Todd Lair * Andrew Bazan */ - + #ifndef _UTILITIES_H #define _UTILITIES_H_ #include -template class AutoDestructor { - public: - AutoDestructor(T *t) - { - fObject = t; - } - - virtual ~AutoDestructor(void) - { - delete fObject; - } - - void SetTo(T *t) - { - delete fObject; - fObject = t; - } - - private: - T *fObject; +template class AutoDestructor +{ +public: + AutoDestructor(T* t) { + fObject = t; + } + + virtual ~AutoDestructor(void) { + delete fObject; + } + + void SetTo(T* t) { + delete fObject; + fObject = t; + } + +private: + T* fObject; }; class BMessage; class BPoint; -BString GetWord (const char *, int32); -BString RestOfString (const char *, int32); -BString GetNick (const char *); -BString GetIdent (const char *); -BString GetAddress (const char *); +BString GetWord (const char*, int32); +BString RestOfString (const char*, int32); +BString GetNick (const char*); +BString GetIdent (const char*); +BString GetAddress (const char*); BString TimeStamp (void); -BString ExpandKeyed (const char *, const char *, const char **); +BString ExpandKeyed (const char*, const char*, const char**); BString DurationString (int64); -BString StringToURI (const char *); -const char *RelToAbsPath (const char *); -BString GetWordColon (const char *, int32); -int32 Get440Len (const char *); -uint16 CheckClickCount(BPoint, BPoint &, bigtime_t, bigtime_t &, int16 &); +BString StringToURI (const char*); +const char* RelToAbsPath (const char*); +BString GetWordColon (const char*, int32); +int32 Get440Len (const char*); +uint16 CheckClickCount(BPoint, BPoint&, bigtime_t, bigtime_t&, int16&); #endif