Automatic style cleanup with the astyle program.

This commit is contained in:
plfiorini 2010-07-10 13:58:15 +00:00
parent 082f2ad34e
commit a651de0f53
16 changed files with 2779 additions and 3014 deletions

View File

@ -10,20 +10,20 @@
#include "SmileTextRender.h" #include "SmileTextRender.h"
//tmp //tmp
BMessage* faces=NULL; BMessage* faces = NULL;
bool valid=false; bool valid = false;
bool fname=false; bool fname = false;
bool svg=false; bool svg = false;
bool size=true; bool size = true;
BString filename; BString filename;
BString face; BString face;
BPath path; BPath path;
BString gCharacters; BString gCharacters;
Emoconfig::Emoconfig(const char* xmlfile):BMessage() Emoconfig::Emoconfig(const char* xmlfile): BMessage()
{ {
fEmoticonSize = 16.0; //default fEmoticonSize = 16.0; //default
numfaces=0; numfaces = 0;
fParser = XML_ParserCreate(NULL); fParser = XML_ParserCreate(NULL);
@ -36,19 +36,18 @@ Emoconfig::Emoconfig(const char* xmlfile):BMessage()
p.GetParent(&path); p.GetParent(&path);
// loading the config file.. // loading the config file..
BFile* settings=new BFile(xmlfile,B_READ_ONLY); BFile* settings = new BFile(xmlfile, B_READ_ONLY);
off_t size; off_t size;
settings->GetSize(&size); settings->GetSize(&size);
if(size) if (size) {
{ void* buffer = malloc(size);
void *buffer=malloc(size); size = settings->Read(buffer, size);
size=settings->Read(buffer,size);
XML_Parse(fParser, (const char*)buffer, size, true); XML_Parse(fParser, (const char*)buffer, size, true);
free(buffer); free(buffer);
} }
delete settings; delete settings;
if(fParser) if (fParser)
XML_ParserFree(fParser); XML_ParserFree(fParser);
printf("Emoconfig: loaded %d faces\n", numfaces); printf("Emoconfig: loaded %d faces\n", numfaces);
@ -61,103 +60,80 @@ Emoconfig::~Emoconfig()
} }
void void
Emoconfig::StartElement(void * /*pUserData*/, const char * pName, const char ** /*pAttr*/) Emoconfig::StartElement(void * /*pUserData*/, const char* pName, const char** /*pAttr*/)
{ {
//printf("StartElement %s\n",pName); //printf("StartElement %s\n",pName);
BString name(pName); BString name(pName);
if(name.ICompare("emoticon")==0) if (name.ICompare("emoticon") == 0) {
{ faces = new BMessage();
faces=new BMessage(); svg = false;
svg=false; } else if (name.ICompare("text") == 0 && faces) {
} valid = true;
else } else if (name.ICompare("file") == 0 && faces) {
if(name.ICompare("text")==0 && faces) fname = true;
{ } else if (name.ICompare("svg") == 0 && faces) {
valid=true; // printf("File is SVG\n");
} svg = true;
else } else if (name.ICompare("size") == 0) {
if(name.ICompare("file")==0 && faces) size = true;
{
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 = ""; gCharacters = "";
} }
} }
void void
Emoconfig::EndElement(void * pUserData, const char * pName) Emoconfig::EndElement(void* pUserData, const char* pName)
{ {
//printf("EndElement %s\n",pName); //printf("EndElement %s\n",pName);
BString name(pName); BString name(pName);
if(name.ICompare("emoticon")==0 && faces) if (name.ICompare("emoticon") == 0 && faces) {
{
//faces->PrintToStream(); //debug //faces->PrintToStream(); //debug
delete faces; delete faces;
faces=NULL; faces = NULL;
} } else if (name.ICompare("text") == 0 && faces) {
else valid = false;
if(name.ICompare("text")==0 && faces) faces->AddString("face", face);
{
valid=false;
faces->AddString("face",face);
//printf("to ]%s[\n",face.String()); //printf("to ]%s[\n",face.String());
face.SetTo(""); face.SetTo("");
} } else if (name.ICompare("file") == 0 && faces) {
else
if(name.ICompare("file")==0 && faces)
{
//load file //load file
//compose the filename //compose the filename
BPath p(path); BPath p(path);
p.Append(filename.String()); p.Append(filename.String());
BBitmap *icons = NULL; BBitmap* icons = NULL;
if ( !svg ) if ( !svg ) {
{ // //
icons=BTranslationUtils::GetBitmap(p.Path()); icons = BTranslationUtils::GetBitmap(p.Path());
} }
//assign to faces; //assign to faces;
fname=false; fname = false;
// printf("Filename %s [%s]\n",p.Path(),path.Path()); // printf("Filename %s [%s]\n",p.Path(),path.Path());
if(!icons) return; if (!icons) return;
int i=0; int i = 0;
BString s; BString s;
while(faces->FindString("face",i,&s)==B_OK) while (faces->FindString("face", i, &s) == B_OK) {
{
if(i==0) if (i == 0) {
{ ((Emoconfig*)pUserData)->menu.AddPointer(s.String(), (const void*)icons);
((Emoconfig*)pUserData)->menu.AddPointer(s.String(),(const void*)icons); ((Emoconfig*)pUserData)->menu.AddString("face", s.String());
((Emoconfig*)pUserData)->menu.AddString("face",s.String());
} }
((BMessage*)pUserData)->AddPointer(s.String(),(const void*)icons); ((BMessage*)pUserData)->AddPointer(s.String(), (const void*)icons);
((BMessage*)pUserData)->AddString("face",s.String()); ((BMessage*)pUserData)->AddString("face", s.String());
((Emoconfig*)pUserData)->numfaces++; ((Emoconfig*)pUserData)->numfaces++;
i++; i++;
} }
} else } else if (name.ICompare("size") == 0) {
if(name.ICompare("size")==0) if ( size ) {
{
if ( size )
{
((Emoconfig*)pUserData)->fEmoticonSize = atoi(gCharacters.String()); ((Emoconfig*)pUserData)->fEmoticonSize = atoi(gCharacters.String());
} }
@ -167,26 +143,20 @@ Emoconfig::EndElement(void * pUserData, const char * pName)
} }
void void
Emoconfig::Characters(void * /*pUserData*/, const char * pString, int pLen) Emoconfig::Characters(void * /*pUserData*/, const char* pString, int pLen)
{ {
BString f(pString,pLen); BString f(pString, pLen);
//printf("Characters %s\n",f.String()); //printf("Characters %s\n",f.String());
if(faces && valid) if (faces && valid) {
{
f.RemoveAll(" "); f.RemoveAll(" ");
f.RemoveAll("\""); f.RemoveAll("\"");
if(f.Length()>0) if (f.Length() > 0)
face.Append(f); face.Append(f);
} } else if (fname) {
else
if(fname)
{
f.RemoveAll(" "); f.RemoveAll(" ");
filename=f; filename = f;
} } else {
else
{
gCharacters.Append(f); gCharacters.Append(f);
} }
} }

View File

@ -8,22 +8,24 @@
class Emoconfig : public BMessage class Emoconfig : public BMessage
{ {
public: public:
Emoconfig(const char* xmlfile); Emoconfig(const char* xmlfile);
~Emoconfig(); ~Emoconfig();
int numfaces; int numfaces;
BMessage menu; BMessage menu;
float GetEmoticonSize() { return fEmoticonSize; } float GetEmoticonSize() {
return fEmoticonSize;
}
private: private:
float fEmoticonSize; float fEmoticonSize;
XML_Parser fParser; XML_Parser fParser;
static void StartElement(void * pUserData, const char * pName, const char ** pAttr); static void StartElement(void* pUserData, const char* pName, const char** pAttr);
static void EndElement(void * pUserData, const char * pName); static void EndElement(void* pUserData, const char* pName);
static void Characters(void * pUserData, const char * pString, int pLen); static void Characters(void* pUserData, const char* pString, int pLen);
}; };

View File

@ -41,7 +41,7 @@ Emoticor::LoadConfig(const char* txt)
} }
void 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" // "Iteration is human, recursion is divine"
@ -52,65 +52,60 @@ Emoticor::_findTokens(RunView *fTextView,BString text,int tokenstart, int16 cols
BString cur; BString cur;
int i = tokenstart; int i = tokenstart;
if (fConfig != NULL) if (fConfig != NULL) {
{ while (fConfig->FindString("face", i, &cur) == B_OK)
while(fConfig->FindString("face",i,&cur)==B_OK) //for(int i=tokenstart;i<config->numfaces;i++)
//for(int i=tokenstart;i<config->numfaces;i++)
{ {
i++; i++;
//if(config->FindString("face",i,&cur)!=B_OK) return; //if(config->FindString("face",i,&cur)!=B_OK) return;
newindex=0; newindex = 0;
while(true) while (true) {
{ newindex = text.IFindFirst(cur.String(), 0);
newindex=text.IFindFirst(cur.String(),0); //printf("Try %d %s -- match %d\n",i,cur->original.String(),newindex);
//printf("Try %d %s -- match %d\n",i,cur->original.String(),newindex);
if(newindex!=B_ERROR) if (newindex != B_ERROR) {
{ //take a walk on the left side ;)
//take a walk on the left side ;)
//printf("Found at %ld \n",newindex); //printf("Found at %ld \n",newindex);
if(newindex-1>=0) if (newindex - 1 >= 0) {
{ BString left;
BString left; text.CopyInto(left, 0, newindex);
text.CopyInto(left,0,newindex); //printf("ready to recourse! [%s]\n",left.String());
//printf("ready to recourse! [%s]\n",left.String()); _findTokens(fTextView, left, tokenstart + 1, cols, font, cols2, font2);
_findTokens(fTextView,left,tokenstart+1,cols,font,cols2,font2); }
}
text.Remove(0,newindex+cur.Length()); text.Remove(0, newindex + cur.Length());
//printf("remaning [%s] printed [%s]\n",text.String(),cur->original.String()); //printf("remaning [%s] printed [%s]\n",text.String(),cur->original.String());
fTextView->Append(cur.String(),cols2,cols2,font2); fTextView->Append(cur.String(), cols2, cols2, font2);
if(text.Length()==0) return; //useless stack if (text.Length() == 0) return; //useless stack
} } else
else break;
break;
} }
} }
} }
fTextView->Append(text.String(),cols,cols,font); fTextView->Append(text.String(), cols, cols, font);
} }
void 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); BString left(txt);
// if(!fConfig) // if(!fConfig)
// fTextView->Append(txt,cols,cols,font); // fTextView->Append(txt,cols,cols,font);
_findTokens(fTextView,left,0,cols,font,cols2,font2); _findTokens(fTextView, left, 0, cols, font, cols2, font2);
return; return;

View File

@ -8,22 +8,22 @@
class Emoticor class Emoticor
{ {
public: public:
static Emoticor* Get(); //singleton static Emoticor* Get(); //singleton
void AddText(RunView *fTextView,const char* text, 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*); void LoadConfig(const char*);
Emoconfig *Config(); Emoconfig* Config();
~Emoticor(); ~Emoticor();
private: private:
Emoticor(); Emoticor();
Emoconfig* fConfig; Emoconfig* fConfig;
void _findTokens(RunView *fTextView,BString text,int tokenstart, int16 cols ,int16 font ,int16 cols2 ,int16 font2); void _findTokens(RunView* fTextView, BString text, int tokenstart, int16 cols , int16 font , int16 cols2 , int16 font2);
}; };

View File

@ -9,35 +9,38 @@
class NormalTextRender : public TextRender class NormalTextRender : public TextRender
{ {
public: public:
NormalTextRender(BFont f):TextRender(){ NormalTextRender(BFont f): TextRender() {
font=f; font = f;
} }
virtual ~NormalTextRender() {}; virtual ~NormalTextRender() {};
virtual void Render(BView *target,const char* txt,int16 num,BPoint pos) { virtual void Render(BView* target, const char* txt, int16 num, BPoint pos) {
target->SetFont(&font); target->SetFont(&font);
target->DrawString(txt,num,pos); target->DrawString(txt, num, pos);
}; };
virtual float Size(){ return font.Size();} virtual float Size() {
return font.Size();
}
virtual void GetHeight(font_height *height){ font.GetHeight(height); }; virtual void GetHeight(font_height* height) {
font.GetHeight(height);
};
virtual void virtual void
GetEscapements(const char charArray[], int32 numChars,float escapementArray[]) GetEscapements(const char charArray[], int32 numChars, float escapementArray[]) {
{ font.GetEscapements(charArray, numChars, escapementArray);
font.GetEscapements(charArray,numChars,escapementArray); }
}
private: private:
BFont font; BFont font;
}; };
#endif #endif

View File

@ -73,52 +73,55 @@ template<class T> class BObjectList;
template<class T> template<class T>
struct UnaryPredicate { struct UnaryPredicate {
virtual int operator()(const T *) const virtual int operator()(const T*) const
// virtual could be avoided here if FindBinaryInsertionIndex, // virtual could be avoided here if FindBinaryInsertionIndex,
// etc. were member template functions // etc. were member template functions
{ return 0; } {
return 0;
}
private: private:
static int _unary_predicate_glue(const void *item, void *context); static int _unary_predicate_glue(const void* item, void* context);
friend class BObjectList<T>; friend class BObjectList<T>;
}; };
template<class T> template<class T>
int int
UnaryPredicate<T>::_unary_predicate_glue(const void *item, void *context) UnaryPredicate<T>::_unary_predicate_glue(const void* item, void* context)
{ {
return ((UnaryPredicate<T> *)context)->operator()((const T *)item); return ((UnaryPredicate<T> *)context)->operator()((const T*)item);
} }
class _PointerList_ : public BList { class _PointerList_ : public BList
{
public: public:
_PointerList_(const _PointerList_ &list); _PointerList_(const _PointerList_ &list);
_PointerList_(int32 itemsPerBlock = 20, bool owning = false); _PointerList_(int32 itemsPerBlock = 20, bool owning = false);
~_PointerList_(); ~_PointerList_();
typedef void *(* GenericEachFunction)(void *, void *); typedef void *(* GenericEachFunction)(void*, void*);
typedef int (* GenericCompareFunction)(const void *, const void *); typedef int (* GenericCompareFunction)(const void*, const void*);
typedef int (* GenericCompareFunctionWithState)(const void *, const void *, typedef int (* GenericCompareFunctionWithState)(const void*, const void*,
void *); void*);
typedef int (* UnaryPredicateGlue)(const void *, void *); typedef int (* UnaryPredicateGlue)(const void*, void*);
void *EachElement(GenericEachFunction, void *); void* EachElement(GenericEachFunction, void*);
void SortItems(GenericCompareFunction); void SortItems(GenericCompareFunction);
void SortItems(GenericCompareFunctionWithState, void *state); void SortItems(GenericCompareFunctionWithState, void* state);
void HSortItems(GenericCompareFunction); void HSortItems(GenericCompareFunction);
void HSortItems(GenericCompareFunctionWithState, void *state); void HSortItems(GenericCompareFunctionWithState, void* state);
void *BinarySearch(const void *, GenericCompareFunction) const; void* BinarySearch(const void*, GenericCompareFunction) const;
void *BinarySearch(const void *, GenericCompareFunctionWithState, void *state) const; void* BinarySearch(const void*, GenericCompareFunctionWithState, void* state) const;
int32 BinarySearchIndex(const void *, GenericCompareFunction) const; int32 BinarySearchIndex(const void*, GenericCompareFunction) const;
int32 BinarySearchIndex(const void *, GenericCompareFunctionWithState, void *state) const; int32 BinarySearchIndex(const void*, GenericCompareFunctionWithState, void* state) const;
int32 BinarySearchIndexByPredicate(const void *, UnaryPredicateGlue) const; int32 BinarySearchIndexByPredicate(const void*, UnaryPredicateGlue) const;
bool Owning() const; bool Owning() const;
bool ReplaceItem(int32, void *); bool ReplaceItem(int32, void*);
protected: protected:
bool owning; bool owning;
@ -126,124 +129,127 @@ protected:
}; };
template<class T> template<class T>
class BObjectList : private _PointerList_ { class BObjectList : private _PointerList_
{
public: public:
// iteration and sorting // iteration and sorting
typedef T *(* EachFunction)(T *, void *); typedef T *(* EachFunction)(T*, void*);
typedef const T *(* ConstEachFunction)(const T *, void *); typedef const T *(* ConstEachFunction)(const T*, void*);
typedef int (* CompareFunction)(const T *, const T *); typedef int (* CompareFunction)(const T*, const T*);
typedef int (* CompareFunctionWithState)(const T *, const T *, void *state); typedef int (* CompareFunctionWithState)(const T*, const T*, void* state);
BObjectList(int32 itemsPerBlock = 20, bool owning = false); BObjectList(int32 itemsPerBlock = 20, bool owning = false);
BObjectList(const BObjectList &list); BObjectList(const BObjectList& list);
// clones list; if list is owning, makes copies of all // clones list; if list is owning, makes copies of all
// the items // the items
virtual ~BObjectList(); virtual ~BObjectList();
BObjectList &operator=(const BObjectList &list); BObjectList& operator=(const BObjectList& list);
// clones list; if list is owning, makes copies of all // clones list; if list is owning, makes copies of all
// the items // the items
// adding and removing // adding and removing
// ToDo: // ToDo:
// change Add calls to return const item // change Add calls to return const item
bool AddItem(T *); bool AddItem(T*);
bool AddItem(T *, int32); bool AddItem(T*, int32);
bool AddList(BObjectList *); bool AddList(BObjectList*);
bool AddList(BObjectList *, int32); bool AddList(BObjectList*, int32);
bool RemoveItem(T *, bool deleteIfOwning = true); bool RemoveItem(T*, bool deleteIfOwning = true);
// if owning, deletes the removed item // if owning, deletes the removed item
T *RemoveItemAt(int32); T* RemoveItemAt(int32);
// returns the removed item // returns the removed item
void MakeEmpty(); void MakeEmpty();
// item access // item access
T *ItemAt(int32) const; T* ItemAt(int32) const;
bool ReplaceItem(int32 index, T *); bool ReplaceItem(int32 index, T*);
// if list is owning, deletes the item at <index> first // if list is owning, deletes the item at <index> first
T *SwapWithItem(int32 index, T *newItem); T* SwapWithItem(int32 index, T* newItem);
// same as ReplaceItem, except does not delete old item at <index>, // same as ReplaceItem, except does not delete old item at <index>,
// returns it instead // returns it instead
T *FirstItem() const; T* FirstItem() const;
T *LastItem() const; T* LastItem() const;
// misc. getters // misc. getters
int32 IndexOf(const T *) const; int32 IndexOf(const T*) const;
bool HasItem(const T *) const; bool HasItem(const T*) const;
bool IsEmpty() const; bool IsEmpty() const;
int32 CountItems() const; int32 CountItems() const;
T *EachElement(EachFunction, void *); T* EachElement(EachFunction, void*);
const T *EachElement(ConstEachFunction, void *) const; const T* EachElement(ConstEachFunction, void*) const;
void SortItems(CompareFunction); void SortItems(CompareFunction);
void SortItems(CompareFunctionWithState, void *state); void SortItems(CompareFunctionWithState, void* state);
void HSortItems(CompareFunction); void HSortItems(CompareFunction);
void HSortItems(CompareFunctionWithState, void *state); void HSortItems(CompareFunctionWithState, void* state);
// linear search, returns first item that matches predicate // linear search, returns first item that matches predicate
const T *FindIf(const UnaryPredicate<T> &) const; const T* FindIf(const UnaryPredicate<T> &) const;
T *FindIf(const UnaryPredicate<T> &); T* FindIf(const UnaryPredicate<T> &);
// list must be sorted with CompareFunction for these to work // list must be sorted with CompareFunction for these to work
T *BinarySearch(const T &, CompareFunction) const; T* BinarySearch(const T&, CompareFunction) const;
T *BinarySearch(const T &, CompareFunctionWithState, void *state) const; T* BinarySearch(const T&, CompareFunctionWithState, void* state) const;
template<typename Key> template<typename Key>
T *BinarySearchByKey(const Key &key, int (*compare)(const Key *, const T *)) T* BinarySearchByKey(const Key& key, int (*compare)(const Key*, const T*))
const; const;
template<typename Key> template<typename Key>
T *BinarySearchByKey(const Key &key, T* BinarySearchByKey(const Key& key,
int (*compare)(const Key *, const T *, void *), void *state) const; int (*compare)(const Key*, const T*, void*), void* state) const;
int32 BinarySearchIndex(const T &item, CompareFunction compare) const; int32 BinarySearchIndex(const T& item, CompareFunction compare) const;
int32 BinarySearchIndex(const T &item, CompareFunctionWithState compare, int32 BinarySearchIndex(const T& item, CompareFunctionWithState compare,
void *state) const; void* state) const;
template<typename Key> template<typename Key>
int32 BinarySearchIndexByKey(const Key &key, int32 BinarySearchIndexByKey(const Key& key,
int (*compare)(const Key *, const T *)) const; int (*compare)(const Key*, const T*)) const;
// Binary insertion - list must be sorted with CompareFunction for // Binary insertion - list must be sorted with CompareFunction for
// these to work // these to work
// simple insert // simple insert
bool BinaryInsert(T *, CompareFunction); bool BinaryInsert(T*, CompareFunction);
bool BinaryInsert(T *, CompareFunctionWithState, void *state); bool BinaryInsert(T*, CompareFunctionWithState, void* state);
bool BinaryInsert(T *, const UnaryPredicate<T> &); bool BinaryInsert(T*, const UnaryPredicate<T> &);
// unique insert, returns false if item already in list // unique insert, returns false if item already in list
bool BinaryInsertUnique(T *, CompareFunction); bool BinaryInsertUnique(T*, CompareFunction);
bool BinaryInsertUnique(T *, CompareFunctionWithState, void *state); bool BinaryInsertUnique(T*, CompareFunctionWithState, void* state);
bool BinaryInsertUnique(T *, const UnaryPredicate<T> &); bool BinaryInsertUnique(T*, const UnaryPredicate<T> &);
// insert a copy of the item, returns new inserted item // insert a copy of the item, returns new inserted item
T *BinaryInsertCopy(const T &copyThis, CompareFunction); T* BinaryInsertCopy(const T& copyThis, CompareFunction);
T *BinaryInsertCopy(const T &copyThis, CompareFunctionWithState, void *state); T* BinaryInsertCopy(const T& copyThis, CompareFunctionWithState, void* state);
// insert a copy of the item if not in list already // insert a copy of the item if not in list already
// returns new inserted item or existing item in case of a conflict // returns new inserted item or existing item in case of a conflict
T *BinaryInsertCopyUnique(const T &copyThis, CompareFunction); T* BinaryInsertCopyUnique(const T& copyThis, CompareFunction);
T *BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState, void *state); T* BinaryInsertCopyUnique(const T& copyThis, CompareFunctionWithState, void* state);
int32 FindBinaryInsertionIndex(const UnaryPredicate<T> &, bool *alreadyInList = 0) const; int32 FindBinaryInsertionIndex(const UnaryPredicate<T> &, bool* alreadyInList = 0) const;
// returns either the index into which a new item should be inserted // returns either the index into which a new item should be inserted
// or index of an existing item that matches the predicate // or index of an existing item that matches the predicate
// deprecated API, will go away // deprecated API, will go away
BList *AsBList() BList* AsBList() {
{ return this; } return this;
const BList *AsBList() const }
{ return this; } const BList* AsBList() const {
return this;
}
private: private:
void SetItem(int32, T *); void SetItem(int32, T*);
}; };
template<class Item, class Result, class Param1> template<class Item, class Result, class Param1>
@ -262,7 +268,7 @@ WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1), Param1
template<class Item, class Result, class Param1> template<class Item, class Result, class Param1>
Result Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1), Param1 p1) WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item*, Param1), Param1 p1)
{ {
Result result = 0; Result result = 0;
int32 count = list->CountItems(); int32 count = list->CountItems();
@ -277,7 +283,7 @@ WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1), Param
template<class Item, class Result, class Param1, class Param2> template<class Item, class Result, class Param1, class Param2>
Result Result
WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1, Param2), WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1, Param2),
Param1 p1, Param2 p2) Param1 p1, Param2 p2)
{ {
Result result = 0; Result result = 0;
int32 count = list->CountItems(); int32 count = list->CountItems();
@ -291,8 +297,8 @@ WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1, Param2),
template<class Item, class Result, class Param1, class Param2> template<class Item, class Result, class Param1, class Param2>
Result Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2), WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item*, Param1, Param2),
Param1 p1, Param2 p2) Param1 p1, Param2 p2)
{ {
Result result = 0; Result result = 0;
int32 count = list->CountItems(); int32 count = list->CountItems();
@ -306,8 +312,8 @@ WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2
template<class Item, class Result, class Param1, class Param2, class Param3, class Param4> template<class Item, class Result, class Param1, class Param2, class Param3, class Param4>
Result Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2, WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item*, Param1, Param2,
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4) Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
{ {
Result result = 0; Result result = 0;
int32 count = list->CountItems(); int32 count = list->CountItems();
@ -330,7 +336,7 @@ EachListItemIgnoreResult(BObjectList<Item> *list, Result (Item::*func)())
template<class Item, class Param1> template<class Item, class Param1>
void void
EachListItem(BObjectList<Item> *list, void (*func)(Item *, Param1), Param1 p1) EachListItem(BObjectList<Item> *list, void (*func)(Item*, Param1), Param1 p1)
{ {
int32 count = list->CountItems(); int32 count = list->CountItems();
for (int32 index = 0; index < count; index++) for (int32 index = 0; index < count; index++)
@ -340,7 +346,7 @@ EachListItem(BObjectList<Item> *list, void (*func)(Item *, Param1), Param1 p1)
template<class Item, class Param1, class Param2> template<class Item, class Param1, class Param2>
void void
EachListItem(BObjectList<Item> *list, void (Item::*func)(Param1, Param2), EachListItem(BObjectList<Item> *list, void (Item::*func)(Param1, Param2),
Param1 p1, Param2 p2) Param1 p1, Param2 p2)
{ {
int32 count = list->CountItems(); int32 count = list->CountItems();
for (int32 index = 0; index < count; index++) for (int32 index = 0; index < count; index++)
@ -349,8 +355,8 @@ EachListItem(BObjectList<Item> *list, void (Item::*func)(Param1, Param2),
template<class Item, class Param1, class Param2> template<class Item, class Param1, class Param2>
void void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2), EachListItem(BObjectList<Item> *list, void (*func)(Item*, Param1, Param2),
Param1 p1, Param2 p2) Param1 p1, Param2 p2)
{ {
int32 count = list->CountItems(); int32 count = list->CountItems();
for (int32 index = 0; index < count; index++) for (int32 index = 0; index < count; index++)
@ -359,8 +365,8 @@ EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2),
template<class Item, class Param1, class Param2, class Param3> template<class Item, class Param1, class Param2, class Param3>
void void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2, EachListItem(BObjectList<Item> *list, void (*func)(Item*, Param1, Param2,
Param3), Param1 p1, Param2 p2, Param3 p3) Param3), Param1 p1, Param2 p2, Param3 p3)
{ {
int32 count = list->CountItems(); int32 count = list->CountItems();
for (int32 index = 0; index < count; index++) for (int32 index = 0; index < count; index++)
@ -370,8 +376,8 @@ EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
template<class Item, class Param1, class Param2, class Param3, class Param4> template<class Item, class Param1, class Param2, class Param3, class Param4>
void void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2, EachListItem(BObjectList<Item> *list, void (*func)(Item*, Param1, Param2,
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4) Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
{ {
int32 count = list->CountItems(); int32 count = list->CountItems();
for (int32 index = 0; index < count; index++) for (int32 index = 0; index < count; index++)
@ -401,7 +407,7 @@ BObjectList<T>::BObjectList(const BObjectList<T> &list)
// make our own copies in an owning list // make our own copies in an owning list
int32 count = list.CountItems(); int32 count = list.CountItems();
for (int32 index = 0; index < count; index++) { for (int32 index = 0; index < count; index++) {
T *item = list.ItemAt(index); T* item = list.ItemAt(index);
if (item) if (item)
item = new T(*item); item = new T(*item);
SetItem(index, item); SetItem(index, item);
@ -427,7 +433,7 @@ BObjectList<T>::operator=(const BObjectList<T> &list)
// make our own copies in an owning list // make our own copies in an owning list
int32 count = list.CountItems(); int32 count = list.CountItems();
for (int32 index = 0; index < count; index++) { for (int32 index = 0; index < count; index++) {
T *item = list.ItemAt(index); T* item = list.ItemAt(index);
if (item) if (item)
item = new T(*item); item = new T(*item);
SetItem(index, item); SetItem(index, item);
@ -438,17 +444,17 @@ BObjectList<T>::operator=(const BObjectList<T> &list)
template<class T> template<class T>
bool bool
BObjectList<T>::AddItem(T *item) BObjectList<T>::AddItem(T* item)
{ {
// need to cast to void * to make T work for const pointers // need to cast to void * to make T work for const pointers
return _PointerList_::AddItem((void *)item); return _PointerList_::AddItem((void*)item);
} }
template<class T> template<class T>
bool bool
BObjectList<T>::AddItem(T *item, int32 atIndex) BObjectList<T>::AddItem(T* item, int32 atIndex)
{ {
return _PointerList_::AddItem((void *)item, atIndex); return _PointerList_::AddItem((void*)item, atIndex);
} }
template<class T> template<class T>
@ -468,9 +474,9 @@ BObjectList<T>::AddList(BObjectList<T> *newItems, int32 atIndex)
template<class T> template<class T>
bool bool
BObjectList<T>::RemoveItem(T *item, bool deleteIfOwning) BObjectList<T>::RemoveItem(T* item, bool deleteIfOwning)
{ {
bool result = _PointerList_::RemoveItem((void *)item); bool result = _PointerList_::RemoveItem((void*)item);
if (result && Owning() && deleteIfOwning) if (result && Owning() && deleteIfOwning)
delete item; delete item;
@ -482,67 +488,67 @@ template<class T>
T * T *
BObjectList<T>::RemoveItemAt(int32 index) BObjectList<T>::RemoveItemAt(int32 index)
{ {
return (T *)_PointerList_::RemoveItem(index); return (T*)_PointerList_::RemoveItem(index);
} }
template<class T> template<class T>
inline T * inline T *
BObjectList<T>::ItemAt(int32 index) const BObjectList<T>::ItemAt(int32 index) const
{ {
return (T *)_PointerList_::ItemAt(index); return (T*)_PointerList_::ItemAt(index);
} }
template<class T> template<class T>
bool bool
BObjectList<T>::ReplaceItem(int32 index, T *item) BObjectList<T>::ReplaceItem(int32 index, T* item)
{ {
if (owning) if (owning)
delete ItemAt(index); delete ItemAt(index);
return _PointerList_::ReplaceItem(index, (void *)item); return _PointerList_::ReplaceItem(index, (void*)item);
} }
template<class T> template<class T>
T * T *
BObjectList<T>::SwapWithItem(int32 index, T *newItem) BObjectList<T>::SwapWithItem(int32 index, T* newItem)
{ {
T *result = ItemAt(index); T* result = ItemAt(index);
_PointerList_::ReplaceItem(index, (void *)newItem); _PointerList_::ReplaceItem(index, (void*)newItem);
return result; return result;
} }
template<class T> template<class T>
void void
BObjectList<T>::SetItem(int32 index, T *newItem) BObjectList<T>::SetItem(int32 index, T* newItem)
{ {
_PointerList_::ReplaceItem(index, (void *)newItem); _PointerList_::ReplaceItem(index, (void*)newItem);
} }
template<class T> template<class T>
int32 int32
BObjectList<T>::IndexOf(const T *item) const BObjectList<T>::IndexOf(const T* item) const
{ {
return _PointerList_::IndexOf((void *)item); return _PointerList_::IndexOf((void*)item);
} }
template<class T> template<class T>
T * T *
BObjectList<T>::FirstItem() const BObjectList<T>::FirstItem() const
{ {
return (T *)_PointerList_::FirstItem(); return (T*)_PointerList_::FirstItem();
} }
template<class T> template<class T>
T * T *
BObjectList<T>::LastItem() const BObjectList<T>::LastItem() const
{ {
return (T *)_PointerList_::LastItem(); return (T*)_PointerList_::LastItem();
} }
template<class T> template<class T>
bool bool
BObjectList<T>::HasItem(const T *item) const BObjectList<T>::HasItem(const T* item) const
{ {
return _PointerList_::HasItem((void *)item); return _PointerList_::HasItem((void*)item);
} }
template<class T> template<class T>
@ -573,19 +579,19 @@ BObjectList<T>::MakeEmpty()
template<class T> template<class T>
T * T *
BObjectList<T>::EachElement(EachFunction func, void *params) BObjectList<T>::EachElement(EachFunction func, void* params)
{ {
return (T *)_PointerList_::EachElement((GenericEachFunction)func, params); return (T*)_PointerList_::EachElement((GenericEachFunction)func, params);
} }
template<class T> template<class T>
const T * const T *
BObjectList<T>::EachElement(ConstEachFunction func, void *params) const BObjectList<T>::EachElement(ConstEachFunction func, void* params) const
{ {
return (const T *) return (const T*)
const_cast<BObjectList<T> *>(this)->_PointerList_::EachElement( const_cast<BObjectList<T> *>(this)->_PointerList_::EachElement(
(GenericEachFunction)func, params); (GenericEachFunction)func, params);
} }
template<class T> template<class T>
@ -620,7 +626,7 @@ BObjectList<T>::SortItems(CompareFunction function)
template<class T> template<class T>
void void
BObjectList<T>::SortItems(CompareFunctionWithState function, void *state) BObjectList<T>::SortItems(CompareFunctionWithState function, void* state)
{ {
_PointerList_::SortItems((GenericCompareFunctionWithState)function, state); _PointerList_::SortItems((GenericCompareFunctionWithState)function, state);
} }
@ -634,86 +640,86 @@ BObjectList<T>::HSortItems(CompareFunction function)
template<class T> template<class T>
void void
BObjectList<T>::HSortItems(CompareFunctionWithState function, void *state) BObjectList<T>::HSortItems(CompareFunctionWithState function, void* state)
{ {
_PointerList_::HSortItems((GenericCompareFunctionWithState)function, state); _PointerList_::HSortItems((GenericCompareFunctionWithState)function, state);
} }
template<class T> template<class T>
T * T *
BObjectList<T>::BinarySearch(const T &key, CompareFunction func) const BObjectList<T>::BinarySearch(const T& key, CompareFunction func) const
{ {
return (T*)_PointerList_::BinarySearch(&key, return (T*)_PointerList_::BinarySearch(&key,
(GenericCompareFunction)func); (GenericCompareFunction)func);
} }
template<class T> template<class T>
T * T *
BObjectList<T>::BinarySearch(const T &key, CompareFunctionWithState func, void *state) const BObjectList<T>::BinarySearch(const T& key, CompareFunctionWithState func, void* state) const
{ {
return (T*)_PointerList_::BinarySearch(&key, return (T*)_PointerList_::BinarySearch(&key,
(GenericCompareFunctionWithState)func, state); (GenericCompareFunctionWithState)func, state);
} }
template<class T> template<class T>
template<typename Key> template<typename Key>
T * T *
BObjectList<T>::BinarySearchByKey(const Key &key, BObjectList<T>::BinarySearchByKey(const Key& key,
int (*compare)(const Key *, const T *)) const int (*compare)(const Key*, const T*)) const
{ {
return (T*)_PointerList_::BinarySearch(&key, return (T*)_PointerList_::BinarySearch(&key,
(GenericCompareFunction)compare); (GenericCompareFunction)compare);
} }
template<class T> template<class T>
template<typename Key> template<typename Key>
T * T *
BObjectList<T>::BinarySearchByKey(const Key &key, BObjectList<T>::BinarySearchByKey(const Key& key,
int (*compare)(const Key *, const T *, void *), void *state) const int (*compare)(const Key*, const T*, void*), void* state) const
{ {
return (T*)_PointerList_::BinarySearch(&key, return (T*)_PointerList_::BinarySearch(&key,
(GenericCompareFunctionWithState)compare, state); (GenericCompareFunctionWithState)compare, state);
} }
template<class T> template<class T>
int32 int32
BObjectList<T>::BinarySearchIndex(const T &item, CompareFunction compare) const BObjectList<T>::BinarySearchIndex(const T& item, CompareFunction compare) const
{ {
return _PointerList_::BinarySearchIndex(&item, return _PointerList_::BinarySearchIndex(&item,
(GenericCompareFunction)compare); (GenericCompareFunction)compare);
} }
template<class T> template<class T>
int32 int32
BObjectList<T>::BinarySearchIndex(const T &item, BObjectList<T>::BinarySearchIndex(const T& item,
CompareFunctionWithState compare, void *state) const CompareFunctionWithState compare, void* state) const
{ {
return _PointerList_::BinarySearchIndex(&item, return _PointerList_::BinarySearchIndex(&item,
(GenericCompareFunctionWithState)compare, state); (GenericCompareFunctionWithState)compare, state);
} }
template<class T> template<class T>
template<typename Key> template<typename Key>
int32 int32
BObjectList<T>::BinarySearchIndexByKey(const Key &key, BObjectList<T>::BinarySearchIndexByKey(const Key& key,
int (*compare)(const Key *, const T *)) const int (*compare)(const Key*, const T*)) const
{ {
return _PointerList_::BinarySearchIndex(&key, return _PointerList_::BinarySearchIndex(&key,
(GenericCompareFunction)compare); (GenericCompareFunction)compare);
} }
template<class T> template<class T>
bool bool
BObjectList<T>::BinaryInsert(T *item, CompareFunction func) BObjectList<T>::BinaryInsert(T* item, CompareFunction func)
{ {
int32 index = _PointerList_::BinarySearchIndex(item, int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunction)func); (GenericCompareFunction)func);
if (index >= 0) { if (index >= 0) {
// already in list, add after existing // already in list, add after existing
return AddItem(item, index + 1); return AddItem(item, index + 1);
@ -724,10 +730,10 @@ BObjectList<T>::BinaryInsert(T *item, CompareFunction func)
template<class T> template<class T>
bool bool
BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state) BObjectList<T>::BinaryInsert(T* item, CompareFunctionWithState func, void* state)
{ {
int32 index = _PointerList_::BinarySearchIndex(item, int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunctionWithState)func, state); (GenericCompareFunctionWithState)func, state);
if (index >= 0) { if (index >= 0) {
// already in list, add after existing // already in list, add after existing
return AddItem(item, index + 1); return AddItem(item, index + 1);
@ -738,10 +744,10 @@ BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state
template<class T> template<class T>
bool bool
BObjectList<T>::BinaryInsertUnique(T *item, CompareFunction func) BObjectList<T>::BinaryInsertUnique(T* item, CompareFunction func)
{ {
int32 index = _PointerList_::BinarySearchIndex(item, int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunction)func); (GenericCompareFunction)func);
if (index >= 0) if (index >= 0)
return false; return false;
@ -750,10 +756,10 @@ BObjectList<T>::BinaryInsertUnique(T *item, CompareFunction func)
template<class T> template<class T>
bool bool
BObjectList<T>::BinaryInsertUnique(T *item, CompareFunctionWithState func, void *state) BObjectList<T>::BinaryInsertUnique(T* item, CompareFunctionWithState func, void* state)
{ {
int32 index = _PointerList_::BinarySearchIndex(item, int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunctionWithState)func, state); (GenericCompareFunctionWithState)func, state);
if (index >= 0) if (index >= 0)
return false; return false;
@ -763,76 +769,76 @@ BObjectList<T>::BinaryInsertUnique(T *item, CompareFunctionWithState func, void
template<class T> template<class T>
T * T *
BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunction func) BObjectList<T>::BinaryInsertCopy(const T& copyThis, CompareFunction func)
{ {
int32 index = _PointerList_::BinarySearchIndex(&copyThis, int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunction)func); (GenericCompareFunction)func);
if (index >= 0) if (index >= 0)
index++; index++;
else else
index = -index - 1; index = -index - 1;
T *newItem = new T(copyThis); T* newItem = new T(copyThis);
AddItem(newItem, index); AddItem(newItem, index);
return newItem; return newItem;
} }
template<class T> template<class T>
T * T *
BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunctionWithState func, void *state) BObjectList<T>::BinaryInsertCopy(const T& copyThis, CompareFunctionWithState func, void* state)
{ {
int32 index = _PointerList_::BinarySearchIndex(&copyThis, int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state); (GenericCompareFunctionWithState)func, state);
if (index >= 0) if (index >= 0)
index++; index++;
else else
index = -index - 1; index = -index - 1;
T *newItem = new T(copyThis); T* newItem = new T(copyThis);
AddItem(newItem, index); AddItem(newItem, index);
return newItem; return newItem;
} }
template<class T> template<class T>
T * T *
BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunction func) BObjectList<T>::BinaryInsertCopyUnique(const T& copyThis, CompareFunction func)
{ {
int32 index = _PointerList_::BinarySearchIndex(&copyThis, int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunction)func); (GenericCompareFunction)func);
if (index >= 0) if (index >= 0)
return ItemAt(index); return ItemAt(index);
index = -index - 1; index = -index - 1;
T *newItem = new T(copyThis); T* newItem = new T(copyThis);
AddItem(newItem, index); AddItem(newItem, index);
return newItem; return newItem;
} }
template<class T> template<class T>
T * T *
BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState func, BObjectList<T>::BinaryInsertCopyUnique(const T& copyThis, CompareFunctionWithState func,
void *state) void* state)
{ {
int32 index = _PointerList_::BinarySearchIndex(&copyThis, int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state); (GenericCompareFunctionWithState)func, state);
if (index >= 0) if (index >= 0)
return ItemAt(index); return ItemAt(index);
index = -index - 1; index = -index - 1;
T *newItem = new T(copyThis); T* newItem = new T(copyThis);
AddItem(newItem, index); AddItem(newItem, index);
return newItem; return newItem;
} }
template<class T> template<class T>
int32 int32
BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *alreadyInList) BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool* alreadyInList)
const const
{ {
int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred, int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred,
(UnaryPredicateGlue)&UnaryPredicate<T>::_unary_predicate_glue); (UnaryPredicateGlue)&UnaryPredicate<T>::_unary_predicate_glue);
if (alreadyInList) if (alreadyInList)
*alreadyInList = index >= 0; *alreadyInList = index >= 0;
@ -845,14 +851,14 @@ BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *al
template<class T> template<class T>
bool bool
BObjectList<T>::BinaryInsert(T *item, const UnaryPredicate<T> &pred) BObjectList<T>::BinaryInsert(T* item, const UnaryPredicate<T> &pred)
{ {
return AddItem(item, FindBinaryInsertionIndex(pred)); return AddItem(item, FindBinaryInsertionIndex(pred));
} }
template<class T> template<class T>
bool bool
BObjectList<T>::BinaryInsertUnique(T *item, const UnaryPredicate<T> &pred) BObjectList<T>::BinaryInsertUnique(T* item, const UnaryPredicate<T> &pred)
{ {
bool alreadyInList; bool alreadyInList;
int32 index = FindBinaryInsertionIndex(pred, &alreadyInList); int32 index = FindBinaryInsertionIndex(pred, &alreadyInList);

File diff suppressed because it is too large Load Diff

View File

@ -50,71 +50,68 @@ class BPopUpMenu;
class SelectPos class SelectPos
{ {
public: public:
int16 fLine; int16 fLine;
int16 fOffset; int16 fOffset;
SelectPos ( SelectPos (
int16 selLine = 0, int16 selLine = 0,
int16 selOffset = 0) int16 selOffset = 0)
: fLine (selLine), : fLine (selLine),
fOffset (selOffset) fOffset (selOffset)
{ } { }
SelectPos (const SelectPos &pos) SelectPos (const SelectPos& pos)
: fLine (pos.fLine), : fLine (pos.fLine),
fOffset (pos.fOffset) fOffset (pos.fOffset)
{ } { }
~SelectPos (void) ~SelectPos (void)
{ } { }
SelectPos &operator = (const SelectPos &pos) SelectPos& operator = (const SelectPos& pos) {
{ fLine = pos.fLine;
fLine = pos.fLine; fOffset = pos.fOffset;
fOffset = pos.fOffset;
return *this; return *this;
} }
inline int operator == (const SelectPos &rhs) const inline int operator == (const SelectPos& rhs) const {
{ return ((fLine == rhs.fLine) && (fOffset == rhs.fOffset));
return ((fLine == rhs.fLine) && (fOffset == rhs.fOffset)); }
}
inline int operator != (const SelectPos &rhs) const inline int operator != (const SelectPos& rhs) const {
{ return (!(*this == rhs));
return (!(*this == rhs)); }
}
}; };
class RunView : public BView class RunView : public BView
{ {
BScrollView *fScroller; BScrollView* fScroller;
BCursor *fURLCursor; BCursor* fURLCursor;
Theme *fTheme; Theme* fTheme;
Line *fWorking; Line* fWorking;
Line *fLines[LINE_COUNT]; Line* fLines[LINE_COUNT];
int16 fLine_count, int16 fLine_count,
fClickCount; fClickCount;
char *fStamp_format; char* fStamp_format;
char *fClipping_name; char* fClipping_name;
SelectPos fSp_start, fSp_end; SelectPos fSp_start, fSp_end;
int32 fTracking; int32 fTracking;
SelectPos fTrack_offset; SelectPos fTrack_offset;
BMessageRunner *fOff_view_runner; BMessageRunner* fOff_view_runner;
bigtime_t fOff_view_time; bigtime_t fOff_view_time;
bool fResizedirty; bool fResizedirty;
bool fFontsdirty; bool fFontsdirty;
BPopUpMenu *fMyPopUp; BPopUpMenu* fMyPopUp;
BPoint fLastClick; BPoint fLastClick;
bigtime_t fLastClickTime; bigtime_t fLastClickTime;
@ -127,58 +124,60 @@ class RunView : public BView
void CheckURLCursor (BPoint); void CheckURLCursor (BPoint);
void BuildPopUp (void); void BuildPopUp (void);
bool CheckClickBounds (const SelectPos &, const BPoint &) const; bool CheckClickBounds (const SelectPos&, const BPoint&) const;
void LoadURL(const char *url); void LoadURL(const char* url);
public: public:
RunView ( RunView (
BRect, BRect,
const char *, const char*,
Theme *, Theme*,
uint32 = B_FOLLOW_LEFT | B_FOLLOW_TOP, uint32 = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 = 0UL); uint32 = 0UL);
virtual ~RunView (void); virtual ~RunView (void);
virtual void AttachedToWindow (void); virtual void AttachedToWindow (void);
virtual void DetachedFromWindow (void); virtual void DetachedFromWindow (void);
virtual void FrameResized (float, float); virtual void FrameResized (float, float);
virtual void TargetedByScrollView (BScrollView *); virtual void TargetedByScrollView (BScrollView*);
virtual void Show (); virtual void Show ();
virtual void Draw (BRect); virtual void Draw (BRect);
virtual void MessageReceived (BMessage *); virtual void MessageReceived (BMessage*);
virtual void SetViewColor (rgb_color); virtual void SetViewColor (rgb_color);
void SetViewColor (uchar red, uchar green, uchar blue, uchar alpha = 255) void SetViewColor (uchar red, uchar green, uchar blue, uchar alpha = 255) {
{ rgb_color color = {red, green, blue, alpha}; SetViewColor (color); } rgb_color color = {red, green, blue, alpha};
SetViewColor (color);
}
virtual void MouseDown (BPoint); virtual void MouseDown (BPoint);
virtual void MouseMoved (BPoint, uint32, const BMessage *); virtual void MouseMoved (BPoint, uint32, const BMessage*);
virtual void MouseUp (BPoint); virtual void MouseUp (BPoint);
void Append (const char *, int32, int16, int16, int16); void Append (const char*, int32, int16, int16, int16);
void Append (const char *, int16, int16, int16); void Append (const char*, int16, int16, int16);
void Clear (void); void Clear (void);
int16 LineCount (void) const; int16 LineCount (void) const;
const char *LineAt (int16) const; const char* LineAt (int16) const;
void SetTimeStampFormat (const char *); void SetTimeStampFormat (const char*);
void SetTheme (Theme *); void SetTheme (Theme*);
SelectPos PositionAt (BPoint) const; SelectPos PositionAt (BPoint) const;
BPoint PointAt (SelectPos) const; BPoint PointAt (SelectPos) const;
BRect GetTextFrame (const SelectPos &, const SelectPos &) const; BRect GetTextFrame (const SelectPos&, const SelectPos&) const;
bool IntersectSelection (const SelectPos &, const SelectPos &) const; bool IntersectSelection (const SelectPos&, const SelectPos&) const;
void GetSelectionText (BString &) const; void GetSelectionText (BString&) const;
void Select (const SelectPos &, const SelectPos &); void Select (const SelectPos&, const SelectPos&);
void SelectAll (void); void SelectAll (void);
void SetClippingName (const char *); void SetClippingName (const char*);
bool FindText(const char *); bool FindText(const char*);
void ScrollToBottom(void); void ScrollToBottom(void);
void ScrollToSelection(void); void ScrollToSelection(void);

View File

@ -14,40 +14,39 @@
class SmileTextRender : public TextRender class SmileTextRender : public TextRender
{ {
public: public:
SmileTextRender():TextRender(){}; SmileTextRender(): TextRender() {};
virtual ~SmileTextRender() {}; virtual ~SmileTextRender() {};
virtual void Render(BView *target,const char* txt,int16 num,BPoint pos) { virtual void Render(BView* target, const char* txt, int16 num, BPoint pos) {
BBitmap *pointer=NULL; BBitmap* pointer = NULL;
BString f(txt,num); BString f(txt, num);
if(Emoticor::Get()->Config()->FindPointer(f.String(),(void**)&pointer)==B_OK) if (Emoticor::Get()->Config()->FindPointer(f.String(), (void**)&pointer) == B_OK) {
{ target->SetDrawingMode( B_OP_ALPHA );
target->SetDrawingMode( B_OP_ALPHA ); target->DrawBitmapAsync( pointer, BPoint(pos.x, pos.y - (Emoticor::Get()->Config()->GetEmoticonSize() / 2)) );
target->DrawBitmapAsync( pointer,BPoint(pos.x, pos.y- (Emoticor::Get()->Config()->GetEmoticonSize()/2)) ); target->SetDrawingMode( B_OP_OVER );
target->SetDrawingMode( B_OP_OVER ); }
} };
};
virtual float Size(){ return Emoticor::Get()->Config()->GetEmoticonSize();} virtual float Size() {
return Emoticor::Get()->Config()->GetEmoticonSize();
}
virtual void GetHeight(font_height *h) virtual void GetHeight(font_height* h) {
{ h->descent = h->ascent = Emoticor::Get()->Config()->GetEmoticonSize() / 2;
h->descent = h->ascent = Emoticor::Get()->Config()->GetEmoticonSize()/2; h->leading = 0;
h->leading=0; };
};
virtual void virtual void
GetEscapements(const char * /*charArray*/, int32 numChars,float escapementArray[]) GetEscapements(const char * /*charArray*/, int32 numChars, float escapementArray[]) {
{ //font.GetEscapements(charArray,numChars,escapementArray);
//font.GetEscapements(charArray,numChars,escapementArray); escapementArray[0] = 1;
escapementArray[0]=1; for (int i = 1; i < numChars; i++) escapementArray[i] = 0;
for(int i=1;i<numChars;i++) escapementArray[i]=0; }
}
}; };
#endif #endif

View File

@ -5,15 +5,15 @@
class TextRender class TextRender
{ {
public: public:
TextRender(){}; TextRender() {};
virtual ~TextRender() {}; virtual ~TextRender() {};
virtual void Render(BView *target,const char*,int16 num,BPoint pos) = 0; virtual void Render(BView* target, const char*, int16 num, BPoint pos) = 0;
virtual void GetHeight(font_height *height) = 0; virtual void GetHeight(font_height* height) = 0;
virtual void GetEscapements(const char charArray[], int32 numChars,float escapementArray[])=0; virtual void GetEscapements(const char charArray[], int32 numChars, float escapementArray[]) = 0;
virtual float Size() = 0; virtual float Size() = 0;
// //
}; };
#endif #endif

View File

@ -48,79 +48,79 @@ int16 Theme::SelectionBack = 3;
Theme::Theme ( Theme::Theme (
const char *n, const char* n,
int16 foreCount, int16 foreCount,
int16 backCount, int16 backCount,
int16 renderCount) int16 renderCount)
: name (NULL), : name (NULL),
fores (NULL), fores (NULL),
backs (NULL), backs (NULL),
text_renders (NULL), text_renders (NULL),
fore_count (max_c (foreCount, 4)), fore_count (max_c (foreCount, 4)),
back_count (max_c (backCount, 4)), back_count (max_c (backCount, 4)),
render_count (max_c (renderCount, 4)) render_count (max_c (renderCount, 4))
{ {
fSoftLineIndent = (float)(MARGIN_WIDTH / 2.0); fSoftLineIndent = (float)(MARGIN_WIDTH / 2.0);
fTextMargin = (float)(MARGIN_WIDTH / 2.0); fTextMargin = (float)(MARGIN_WIDTH / 2.0);
name = strcpy (new char [strlen (n) + 1], n); name = strcpy (new char [strlen (n) + 1], n);
fores = new rgb_color [fore_count]; fores = new rgb_color [fore_count];
backs = new rgb_color [back_count]; backs = new rgb_color [back_count];
normal_textrender = new NormalTextRender(be_plain_font); normal_textrender = new NormalTextRender(be_plain_font);
text_renders = (TextRender**)malloc(render_count*sizeof(TextRender*)); text_renders = (TextRender**)malloc(render_count * sizeof(TextRender*));
for ( int i=0; i<render_count; i++ ) for ( int i = 0; i < render_count; i++ )
text_renders[i] = normal_textrender; text_renders[i] = normal_textrender;
sid = create_sem (NUMBER_THEME_READERS, name); sid = create_sem (NUMBER_THEME_READERS, name);
rgb_color def_timestamp_fore = {200, 150, 150, 255}; rgb_color def_timestamp_fore = {200, 150, 150, 255};
rgb_color def_timestamp_back = {255, 255, 255, 255}; rgb_color def_timestamp_back = {255, 255, 255, 255};
rgb_color def_fore = {0, 0, 0, 255}; rgb_color def_fore = {0, 0, 0, 255};
rgb_color def_back = {255, 255, 255, 255}; rgb_color def_back = {255, 255, 255, 255};
fores[0] = def_timestamp_fore; fores[0] = def_timestamp_fore;
int16 i; int16 i;
for (i = 1; i < fore_count; ++i) for (i = 1; i < fore_count; ++i)
fores[i] = def_fore; fores[i] = def_fore;
backs[0] = def_timestamp_back; backs[0] = def_timestamp_back;
for (i = 1; i < back_count; ++i) for (i = 1; i < back_count; ++i)
backs[i] = def_back; backs[i] = def_back;
} }
Theme::~Theme (void) Theme::~Theme (void)
{ {
delete_sem (sid); delete_sem (sid);
//delete [] fonts; //delete [] fonts;
for ( int i=0; i<render_count; i++ ) for ( int i = 0; i < render_count; i++ )
if ( text_renders[i] ) if ( text_renders[i] )
text_renders[i]=NULL; text_renders[i] = NULL;
delete normal_textrender; delete normal_textrender;
delete [] backs; delete [] backs;
delete [] fores; delete [] fores;
delete [] name; delete [] name;
} }
int16 int16
Theme::CountForegrounds (void) const Theme::CountForegrounds (void) const
{ {
return fore_count; return fore_count;
} }
int16 int16
Theme::CountBackgrounds (void) const Theme::CountBackgrounds (void) const
{ {
return back_count; return back_count;
} }
/* /*
int16 int16
@ -133,53 +133,53 @@ Theme::CountFonts (void) const
int16 int16
Theme::CountTextRenders (void) const Theme::CountTextRenders (void) const
{ {
return render_count; return render_count;
} }
void void
Theme::ReadLock (void) Theme::ReadLock (void)
{ {
acquire_sem (sid); acquire_sem (sid);
} }
void void
Theme::ReadUnlock (void) Theme::ReadUnlock (void)
{ {
release_sem (sid); release_sem (sid);
} }
void void
Theme::WriteLock (void) Theme::WriteLock (void)
{ {
acquire_sem_etc (sid, NUMBER_THEME_READERS, 0, 0); acquire_sem_etc (sid, NUMBER_THEME_READERS, 0, 0);
} }
void void
Theme::WriteUnlock (void) Theme::WriteUnlock (void)
{ {
release_sem_etc (sid, NUMBER_THEME_READERS, 0); release_sem_etc (sid, NUMBER_THEME_READERS, 0);
} }
const rgb_color const rgb_color
Theme::ForegroundAt (int16 which) const Theme::ForegroundAt (int16 which) const
{ {
rgb_color color = {0, 0, 0, 255}; rgb_color color = {0, 0, 0, 255};
if (which >= fore_count || which < 0) if (which >= fore_count || which < 0)
return color; return color;
return fores[which]; return fores[which];
} }
const rgb_color const rgb_color
Theme::BackgroundAt (int16 which) const 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) if (which >= back_count || which < 0)
return color; return color;
return backs[which]; return backs[which];
} }
/* /*
const BFont & const BFont &
@ -195,61 +195,61 @@ Theme::FontAt (int16 which) const
TextRender* TextRender*
Theme::TextRenderAt (int16 which) Theme::TextRenderAt (int16 which)
{ {
if ( which < 0 ){ if ( which < 0 ) {
//printf("Theme::TextRenderAt(): which < 0 (%d)\n", which); //printf("Theme::TextRenderAt(): which < 0 (%d)\n", which);
return normal_textrender; return normal_textrender;
} }
if ( which >= render_count ){ if ( which >= render_count ) {
//printf("Theme::TextRenderAt(): which >= render_count (%d, %d)\n", which, render_count); //printf("Theme::TextRenderAt(): which >= render_count (%d, %d)\n", which, render_count);
return normal_textrender; return normal_textrender;
} }
return text_renders[which]; return text_renders[which];
} }
bool bool
Theme::SetForeground (int16 which, const rgb_color color) Theme::SetForeground (int16 which, const rgb_color color)
{ {
if (which >= fore_count || which < 0) if (which >= fore_count || which < 0)
return false; return false;
fores[which] = color; fores[which] = color;
return true; return true;
} }
bool bool
Theme::SetBackground (int16 which, const rgb_color color) Theme::SetBackground (int16 which, const rgb_color color)
{ {
if (which >= back_count || which < 0) if (which >= back_count || which < 0)
return false; return false;
backs[which] = color; backs[which] = color;
return true; return true;
} }
bool bool
Theme::SetTextRender(int16 which,TextRender *trender) Theme::SetTextRender(int16 which, TextRender* trender)
{ {
if (which >= render_count || which < 0 || !trender) if (which >= render_count || which < 0 || !trender)
return false; return false;
text_renders[which] = trender; text_renders[which] = trender;
return true; return true;
} }
void void
Theme::AddView (BView *view) Theme::AddView (BView* view)
{ {
list.AddItem (view); list.AddItem (view);
} }
void void
Theme::RemoveView (BView *view) Theme::RemoveView (BView* view)
{ {
list.RemoveItem (view); list.RemoveItem (view);
} }
void void

View File

@ -37,10 +37,10 @@ class NormalTextRender;
class Theme class Theme
{ {
char *name; char* name;
rgb_color *fores; rgb_color* fores;
rgb_color *backs; rgb_color* backs;
TextRender **text_renders; //FIX!! TextRender** text_renders; //FIX!!
int16 fore_count; int16 fore_count;
int16 back_count; int16 back_count;
@ -53,7 +53,7 @@ class Theme
float fTextMargin; float fTextMargin;
NormalTextRender* normal_textrender; NormalTextRender* normal_textrender;
public: public:
static int16 TimestampFore; static int16 TimestampFore;
static int16 TimestampBack; static int16 TimestampBack;
@ -66,15 +66,16 @@ class Theme
static int16 NormalFont; static int16 NormalFont;
static int16 SelectionBack; static int16 SelectionBack;
Theme ( Theme (
const char *, const char*,
int16, int16,
int16, int16,
int16); int16);
virtual ~Theme (void); virtual ~Theme (void);
const char *Name (void) const const char* Name (void) const {
{ return name; } return name;
}
void ReadLock (void); void ReadLock (void);
void ReadUnlock (void); void ReadUnlock (void);
@ -83,7 +84,7 @@ class Theme
int16 CountForegrounds (void) const; int16 CountForegrounds (void) const;
int16 CountBackgrounds (void) const; int16 CountBackgrounds (void) const;
// int16 CountFonts (void) const; // int16 CountFonts (void) const;
int16 CountTextRenders (void) const; int16 CountTextRenders (void) const;
const rgb_color ForegroundAt (int16) const; const rgb_color ForegroundAt (int16) const;
@ -94,25 +95,33 @@ class Theme
TextRender* TextRenderAt(int16); TextRender* TextRenderAt(int16);
bool SetForeground (int16, const rgb_color); bool SetForeground (int16, const rgb_color);
bool SetForeground (int16 w, uchar r, uchar g, uchar b, uchar a = 255) bool SetForeground (int16 w, uchar r, uchar g, uchar b, uchar a = 255) {
{ rgb_color color = {r, g, b, a}; return SetForeground (w, color); } rgb_color color = {r, g, b, a};
return SetForeground (w, color);
}
bool SetBackground (int16, const rgb_color); bool SetBackground (int16, const rgb_color);
bool SetBackground (int16 w, uchar r, uchar g, uchar b, uchar a = 255) bool SetBackground (int16 w, uchar r, uchar g, uchar b, uchar a = 255) {
{ rgb_color color = {r, g, b, a}; return SetBackground (w, color); } rgb_color color = {r, g, b, a};
return SetBackground (w, color);
}
//bool SetFont (int16, const BFont &); //bool SetFont (int16, const BFont &);
bool SetTextRender(int16, TextRender *); bool SetTextRender(int16, TextRender*);
void SetSoftLineIndent(float indent); void SetSoftLineIndent(float indent);
void SetTextMargin(float margin); void SetTextMargin(float margin);
float TextMargin() const { return fTextMargin; } float TextMargin() const {
float SoftLineIndent() const { return fSoftLineIndent; } return fTextMargin;
}
float SoftLineIndent() const {
return fSoftLineIndent;
}
void AddView (BView *); void AddView (BView*);
void RemoveView (BView *); void RemoveView (BView*);
}; };

View File

@ -24,7 +24,7 @@
#include "URLCrunch.h" #include "URLCrunch.h"
URLCrunch::URLCrunch (const char *data, int32 len) URLCrunch::URLCrunch (const char* data, int32 len)
: buffer (""), : buffer (""),
current_pos (0) current_pos (0)
{ {
@ -36,14 +36,13 @@ URLCrunch::~URLCrunch (void)
} }
int32 int32
URLCrunch::Crunch (BString *url) URLCrunch::Crunch (BString* url)
{ {
if (current_pos >= buffer.Length()) if (current_pos >= buffer.Length())
return B_ERROR; return B_ERROR;
const int32 tagNum = 7; const int32 tagNum = 7;
const char *tags[tagNum] = const char* tags[tagNum] = {
{
"http://", "http://",
"https://", "https://",
"www.", "www.",
@ -65,8 +64,7 @@ URLCrunch::Crunch (BString *url)
for (i = 0; i < tagNum; ++i) for (i = 0; i < tagNum; ++i)
if (markers[i] != B_ERROR if (markers[i] != B_ERROR
&& markers[i] < marker) && markers[i] < marker) {
{
url_length = markers[i] + strlen(tags[i]); url_length = markers[i] + strlen(tags[i]);
url_length += strcspn (buffer.String() + url_length, " \t\n|\\<>\")(][}{;'*^"); url_length += strcspn (buffer.String() + url_length, " \t\n|\\<>\")(][}{;'*^");
@ -75,25 +73,22 @@ URLCrunch::Crunch (BString *url)
int len (strlen (tags[i])); int len (strlen (tags[i]));
if (url_length - markers[i] > len if (url_length - markers[i] > len
&& (isdigit (buffer[markers[i] + len]) && (isdigit (buffer[markers[i] + len])
|| isalpha (buffer[markers[i] + len]))) || isalpha (buffer[markers[i] + len]))) {
{
marker = markers[i]; marker = markers[i];
pos = url_length + 1; pos = url_length + 1;
url_length -= marker; url_length -= marker;
} } else
else
pos = markers[i] + 1; pos = markers[i] + 1;
} }
if (marker < buffer.Length()) if (marker < buffer.Length()) {
{ *url = "";
*url = "";
url->Append (buffer.String() + marker, url_length); url->Append (buffer.String() + marker, url_length);
} }
current_pos = pos; current_pos = pos;
return marker < buffer.Length() ? marker : B_ERROR; return marker < buffer.Length() ? marker : B_ERROR;
} }

View File

@ -30,11 +30,11 @@ class URLCrunch
BString buffer; BString buffer;
int32 current_pos; int32 current_pos;
public: public:
URLCrunch (const char *, int32); URLCrunch (const char*, int32);
~URLCrunch (void); ~URLCrunch (void);
int32 Crunch (BString *); int32 Crunch (BString*);
}; };
#endif #endif

View File

@ -33,287 +33,277 @@
const float doubleClickThresh = 6; const float doubleClickThresh = 6;
BString BString
GetWord (const char *cData, int32 wordNeeded) GetWord (const char* cData, int32 wordNeeded)
{ {
/* /*
* Function purpose: Get word number {wordNeeded} from {cData} * Function purpose: Get word number {wordNeeded} from {cData}
* (space delimited) * (space delimited)
*/ */
BString data (cData); BString data (cData);
BString buffer ("-9z99"); BString buffer ("-9z99");
int32 wordAt (1), place (0); int32 wordAt (1), place (0);
while (wordAt != wordNeeded && place != B_ERROR) while (wordAt != wordNeeded && place != B_ERROR) {
{ if ((place = data.FindFirst ('\x20', place)) != B_ERROR)
if ((place = data.FindFirst ('\x20', place)) != B_ERROR) if (++place < data.Length()
if (++place < data.Length() && data[place] != '\x20')
&& data[place] != '\x20') ++wordAt;
++wordAt; }
}
if (wordAt == wordNeeded if (wordAt == wordNeeded
&& place != B_ERROR && place != B_ERROR
&& place < data.Length()) && place < data.Length()) {
{ int32 end (data.FindFirst ('\x20', place));
int32 end (data.FindFirst ('\x20', place));
if (end == B_ERROR) if (end == B_ERROR)
end = data.Length(); end = data.Length();
data.CopyInto (buffer, place, end - place); data.CopyInto (buffer, place, end - place);
} }
return buffer; return buffer;
} }
BString BString
GetWordColon (const char *cData, int32 wordNeeded) GetWordColon (const char* cData, int32 wordNeeded)
{ {
/* /*
* Function purpose: Get word number {wordNeeded} from {cData} * Function purpose: Get word number {wordNeeded} from {cData}
* (colon delimited) * (colon delimited)
*/ */
BString data (cData); BString data (cData);
BString buffer ("-9z99"); BString buffer ("-9z99");
int32 wordAt (1), place (0); int32 wordAt (1), place (0);
while (wordAt != wordNeeded && place != B_ERROR) while (wordAt != wordNeeded && place != B_ERROR) {
{ if ((place = data.FindFirst (':', place)) != B_ERROR)
if ((place = data.FindFirst (':', place)) != B_ERROR) if (++place < data.Length()
if (++place < data.Length() && data[place] != ':')
&& data[place] != ':') ++wordAt;
++wordAt; }
}
if (wordAt == wordNeeded if (wordAt == wordNeeded
&& place != B_ERROR && place != B_ERROR
&& place < data.Length()) && place < data.Length()) {
{ int32 end (data.FindFirst (':', place));
int32 end (data.FindFirst (':', place));
if (end == B_ERROR) if (end == B_ERROR)
end = data.Length(); end = data.Length();
data.CopyInto (buffer, place, end - place); data.CopyInto (buffer, place, end - place);
} }
return buffer; return buffer;
} }
BString BString
RestOfString (const char *cData, int32 wordStart) RestOfString (const char* cData, int32 wordStart)
{ {
/* /*
* Function purpose: Get word number {wordStart} from {cData} * Function purpose: Get word number {wordStart} from {cData}
* append the rest of the string after {wordStart} * append the rest of the string after {wordStart}
* (space delimited) * (space delimited)
*/ */
BString data (cData); BString data (cData);
int32 wordAt (1), place (0); int32 wordAt (1), place (0);
BString buffer ("-9z99"); BString buffer ("-9z99");
while (wordAt != wordStart && place != B_ERROR) while (wordAt != wordStart && place != B_ERROR) {
{ if ((place = data.FindFirst ('\x20', place)) != B_ERROR)
if ((place = data.FindFirst ('\x20', place)) != B_ERROR) if (++place < data.Length()
if (++place < data.Length() && data[place] != '\x20')
&& data[place] != '\x20') ++wordAt;
++wordAt; }
}
if (wordAt == wordStart if (wordAt == wordStart
&& place != B_ERROR && place != B_ERROR
&& place < data.Length()) && place < data.Length())
data.CopyInto (buffer, place, data.Length() - place); data.CopyInto (buffer, place, data.Length() - place);
return buffer; return buffer;
} }
BString BString
GetNick (const char *cData) GetNick (const char* cData)
{ {
/* /*
* Function purpose: Get nickname from {cData} * Function purpose: Get nickname from {cData}
* *
* Expected format: nickname!user@host.name * Expected format: nickname!user@host.name
*/ */
BString data (cData); BString data (cData);
BString theNick; BString theNick;
for (int32 i = 1; i < data.Length() && data[i] != '!' && data[i] != '\x20'; ++i) for (int32 i = 1; i < data.Length() && data[i] != '!' && data[i] != '\x20'; ++i)
theNick += data[i]; theNick += data[i];
return theNick; return theNick;
} }
BString BString
GetIdent (const char *cData) GetIdent (const char* cData)
{ {
/* /*
* Function purpose: Get identname/username from {cData} * Function purpose: Get identname/username from {cData}
* *
* Expected format: nickname!user@host.name * Expected format: nickname!user@host.name
*/ */
BString data (GetWord(cData, 1)); BString data (GetWord(cData, 1));
BString theIdent; BString theIdent;
int32 place[2]; int32 place[2];
if ((place[0] = data.FindFirst ('!')) != B_ERROR if ((place[0] = data.FindFirst ('!')) != B_ERROR
&& (place[1] = data.FindFirst ('@')) != B_ERROR) && (place[1] = data.FindFirst ('@')) != B_ERROR) {
{ ++(place[0]);
++(place[0]); data.CopyInto (theIdent, place[0], place[1] - place[0]);
data.CopyInto (theIdent, place[0], place[1] - place[0]); }
}
return theIdent; return theIdent;
} }
BString BString
GetAddress (const char *cData) GetAddress (const char* cData)
{ {
/* /*
* Function purpose: Get address/hostname from {cData} * Function purpose: Get address/hostname from {cData}
* *
* Expected format: nickname!user@host.name * Expected format: nickname!user@host.name
*/ */
BString data (GetWord(cData, 1)); BString data (GetWord(cData, 1));
BString address; BString address;
int32 place; int32 place;
if ((place = data.FindFirst ('@')) != B_ERROR) if ((place = data.FindFirst ('@')) != B_ERROR) {
{ int32 length (data.FindFirst ('\x20', place));
int32 length (data.FindFirst ('\x20', place));
if (length == B_ERROR) if (length == B_ERROR)
length = data.Length(); length = data.Length();
++place; ++place;
data.CopyInto (address, place, length - place); data.CopyInto (address, place, length - place);
} }
return address; return address;
} }
BString BString
TimeStamp() TimeStamp()
{ {
/* /*
* Function purpose: Return the timestamp string * Function purpose: Return the timestamp string
* *
*/ */
// if(!vision_app->GetBool ("timestamp")) // if(!vision_app->GetBool ("timestamp"))
// return ""; // return "";
// const char *ts_format (vision_app->GetString ("timestamp_format")); // const char *ts_format (vision_app->GetString ("timestamp_format"));
const char *ts_format = "[%H:%M]"; const char* ts_format = "[%H:%M]";
time_t myTime (time (0)); time_t myTime (time (0));
tm curTime; tm curTime;
localtime_r (&myTime, &curTime); localtime_r (&myTime, &curTime);
char tempTime[32]; char tempTime[32];
tempTime[strftime (tempTime, 31, ts_format, &curTime)] = '\0'; tempTime[strftime (tempTime, 31, ts_format, &curTime)] = '\0';
return BString (tempTime).Append('\x20', 1); return BString (tempTime).Append('\x20', 1);
} }
BString BString
ExpandKeyed ( ExpandKeyed (
const char *incoming, const char* incoming,
const char *keys, const char* keys,
const char **expansions) const char** expansions)
{ {
BString buffer; BString buffer;
while (incoming && *incoming) while (incoming && *incoming) {
{ if (*incoming == '$') {
if (*incoming == '$') const char* place;
{
const char *place;
++incoming; ++incoming;
if ((place = strchr (keys, *incoming)) != 0) if ((place = strchr (keys, *incoming)) != 0)
buffer += expansions[place - keys]; buffer += expansions[place - keys];
else else
buffer += *incoming; buffer += *incoming;
} } else
else buffer += *incoming;
buffer += *incoming;
++incoming; ++incoming;
} }
buffer += "\n"; buffer += "\n";
return buffer; return buffer;
} }
BString 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); BString buffer (string);
buffer.ToLower(); buffer.ToLower();
buffer.ReplaceAll ("%", "%25"); // do this first! buffer.ReplaceAll ("%", "%25"); // do this first!
buffer.ReplaceAll ("\n", "%20"); buffer.ReplaceAll ("\n", "%20");
buffer.ReplaceAll (" ", "%20"); buffer.ReplaceAll (" ", "%20");
buffer.ReplaceAll ("\"", "%22"); buffer.ReplaceAll ("\"", "%22");
buffer.ReplaceAll ("#", "%23"); buffer.ReplaceAll ("#", "%23");
buffer.ReplaceAll ("@", "%40"); buffer.ReplaceAll ("@", "%40");
buffer.ReplaceAll ("`", "%60"); buffer.ReplaceAll ("`", "%60");
buffer.ReplaceAll (":", "%3A"); buffer.ReplaceAll (":", "%3A");
buffer.ReplaceAll ("<", "%3C"); buffer.ReplaceAll ("<", "%3C");
buffer.ReplaceAll (">", "%3E"); buffer.ReplaceAll (">", "%3E");
buffer.ReplaceAll ("[", "%5B"); buffer.ReplaceAll ("[", "%5B");
buffer.ReplaceAll ("\\", "%5C"); buffer.ReplaceAll ("\\", "%5C");
buffer.ReplaceAll ("]", "%5D"); buffer.ReplaceAll ("]", "%5D");
buffer.ReplaceAll ("^", "%5E"); buffer.ReplaceAll ("^", "%5E");
buffer.ReplaceAll ("{", "%7B"); buffer.ReplaceAll ("{", "%7B");
buffer.ReplaceAll ("|", "%7C"); buffer.ReplaceAll ("|", "%7C");
buffer.ReplaceAll ("}", "%7D"); buffer.ReplaceAll ("}", "%7D");
buffer.ReplaceAll ("~", "%7E"); buffer.ReplaceAll ("~", "%7E");
return buffer; return buffer;
} }
BString BString
DurationString (int64 value) DurationString (int64 value)
{ {
/* /*
* Function purpose: Return a duration string based on {value} * Function purpose: Return a duration string based on {value}
* *
*/ */
BString duration; BString duration;
bigtime_t micro = value; bigtime_t micro = value;
bigtime_t milli = micro/1000; bigtime_t milli = micro / 1000;
bigtime_t sec = milli/1000; bigtime_t sec = milli / 1000;
bigtime_t min = sec/60; bigtime_t min = sec / 60;
bigtime_t hours = min/60; bigtime_t hours = min / 60;
bigtime_t days = hours/24; bigtime_t days = hours / 24;
char message[512] = ""; char message[512] = "";
if (days) if (days)
sprintf(message, "%Ld day%s ",days,days!=1?"s":""); sprintf(message, "%Ld day%s ", days, days != 1 ? "s" : "");
if (hours%24) if (hours % 24)
sprintf(message, "%s%Ld hr%s ",message, hours%24,(hours%24)!=1?"s":""); sprintf(message, "%s%Ld hr%s ", message, hours % 24, (hours % 24) != 1 ? "s" : "");
if (min%60) if (min % 60)
sprintf(message, "%s%Ld min%s ",message, min%60, (min%60)!=1?"s":""); 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":""); sprintf(message, "%s%Ld.%Ld sec%s", message, sec % 60, (milli % 1000), (sec % 60) != 1 ? "s" : "");
duration += message; duration += message;
@ -322,57 +312,56 @@ DurationString (int64 value)
const char * const char *
RelToAbsPath (const char *append_) RelToAbsPath (const char* append_)
{ {
app_info ai; app_info ai;
be_app->GetAppInfo (&ai); be_app->GetAppInfo (&ai);
BEntry entry (&ai.ref); BEntry entry (&ai.ref);
BPath path; BPath path;
entry.GetPath (&path); entry.GetPath (&path);
path.GetParent (&path); path.GetParent (&path);
path.Append (append_); path.Append (append_);
return path.Path(); return path.Path();
} }
int32 int32
Get440Len (const char *cData) Get440Len (const char* cData)
{ {
BString data (cData); BString data (cData);
if (data.Length() < 440) if (data.Length() < 440)
return data.Length(); return data.Length();
else else {
{ int32 place (data.FindLast ('\x20', 440));
int32 place (data.FindLast ('\x20', 440)); if (place == B_ERROR)
if (place == B_ERROR) return 440;
return 440; return place;
return place; }
}
} }
uint16 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 // check time and proximity
BPoint delta = point - lastClick; BPoint delta = point - lastClick;
bigtime_t timeDelta = sysTime - lastClickTime; bigtime_t timeDelta = sysTime - lastClickTime;
bigtime_t doubleClickSpeed; bigtime_t doubleClickSpeed;
get_click_speed(&doubleClickSpeed); get_click_speed(&doubleClickSpeed);
lastClickTime = sysTime; lastClickTime = sysTime;
if (timeDelta < doubleClickSpeed if (timeDelta < doubleClickSpeed
&& fabs(delta.x) < doubleClickThresh && fabs(delta.x) < doubleClickThresh
&& fabs(delta.y) < doubleClickThresh) && fabs(delta.y) < doubleClickThresh)
return (++clickCount); return (++clickCount);
lastClick = point; lastClick = point;
clickCount = 1; clickCount = 1;
return clickCount; return clickCount;
} }

View File

@ -26,45 +26,43 @@
#include <String.h> #include <String.h>
template<class T> class AutoDestructor { template<class T> class AutoDestructor
public: {
AutoDestructor(T *t) public:
{ AutoDestructor(T* t) {
fObject = t; fObject = t;
} }
virtual ~AutoDestructor(void) virtual ~AutoDestructor(void) {
{ delete fObject;
delete fObject; }
}
void SetTo(T *t) void SetTo(T* t) {
{ delete fObject;
delete fObject; fObject = t;
fObject = t; }
}
private: private:
T *fObject; T* fObject;
}; };
class BMessage; class BMessage;
class BPoint; class BPoint;
BString GetWord (const char *, int32); BString GetWord (const char*, int32);
BString RestOfString (const char *, int32); BString RestOfString (const char*, int32);
BString GetNick (const char *); BString GetNick (const char*);
BString GetIdent (const char *); BString GetIdent (const char*);
BString GetAddress (const char *); BString GetAddress (const char*);
BString TimeStamp (void); BString TimeStamp (void);
BString ExpandKeyed (const char *, const char *, const char **); BString ExpandKeyed (const char*, const char*, const char**);
BString DurationString (int64); BString DurationString (int64);
BString StringToURI (const char *); BString StringToURI (const char*);
const char *RelToAbsPath (const char *); const char* RelToAbsPath (const char*);
BString GetWordColon (const char *, int32); BString GetWordColon (const char*, int32);
int32 Get440Len (const char *); int32 Get440Len (const char*);
uint16 CheckClickCount(BPoint, BPoint &, bigtime_t, bigtime_t &, int16 &); uint16 CheckClickCount(BPoint, BPoint&, bigtime_t, bigtime_t&, int16&);
#endif #endif