00001
00002
00003 #define TEXTBOX_MAXLINELENGTH (32*1024) //32X better than MS-EDIT
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #define GUI_SHOWBORDER 0x0001
00015 #define GUI_SHOWLINES 0x0002
00016 #define GUI_SHOWDETAILS 0x0004
00017 #define GUI_EXPANDING 0x0008
00018 #define GUI_FOLDERSONLY 0x0010
00019
00020
00021 class Transparent : public Element {
00022 public:
00023 Transparent() {inited = TRUE;}
00024 void Draw() {};
00025 };
00026
00027 class Label : public Element {
00028 friend class Radio;
00029 _PROTECTED_:
00030 int lox;
00031 int justify;
00032 BOOL transparent;
00033
00034 BOOL b_underline;
00035 public:
00036 Label() {}
00037 void Init(char *_txt, Font *_fnt, uint32 _clr = 0x000000, int _justify = LEFT);
00038 void Draw();
00039 Font *fnt;
00040
00041 String Text;
00042 void SetLabel(char *);
00043 char *GetLabel();
00044 void SetFont(Font *_fnt);
00045 Font *GetFont() { return fnt;}
00046 void SetUnderline(BOOL state) {b_underline = state;}
00047 void SetJustify(int _justify) {
00048 justify = _justify;
00049 FlagDraw();
00050 }
00051 int GetJustify() { return justify;}
00052 void SetTransparent(BOOL x) {transparent = x;FlagDraw();}
00053 };
00054
00055 class Button : public Label {
00056 friend class CheckBox;
00057 friend class Radio;
00058 _PROTECTED_:
00059 Bitmap Image;
00060 BOOL useImage;
00061 public:
00062 Button();
00063 void Init(Bitmap *_img);
00064 void Init(char *_label, Font *_fnt);
00065
00066 void SetSize(uint32, uint32);
00067 void SetPos(int, int);
00068 void Show();
00069 void Hide();
00070 void Draw();
00071 void KeyDown(int keycode);
00072 void KeyUp(int keycode);
00073 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00074 void Enable();
00075 void Disable();
00076
00077
00078 void SetBitmap(Bitmap *_img);
00079 };
00080
00081
00082 #define CT_LINE 0x00
00083 #define CT_BOX 0x01
00084 #define CT_L 0x02
00085
00086 class Cursor : public Element, public TimerCallback {
00087 _PROTECTED_:
00088
00089 Timer timer;
00090 BOOL shown;
00091 int ct;
00092 int width;
00093 void Draw();
00094 BOOL skip;
00095 public:
00096 void TimerEvent(Timer *);
00097 void Init(int _ct, int _width = 2);
00098 void Show();
00099 void Hide();
00100 void SetPos(int x, int y);
00101 void SetPos(int x);
00102 void PutPixel(int, int, uint32);
00103 void SetType(int new_type,int new_width = 2);
00104 };
00105
00106 class Radio : public Button {
00107 _PROTECTED_:
00108 void CalcOffset();
00109 public:
00110 Radio() : State(FALSE) {}
00111 int __x, __y;
00112 void Init(Bitmap *_img);
00113 void Init(char *_label, Font *_fnt);
00114 void Draw();
00115 void Click(int, int, int);
00116 void DblClick(int, int, int);
00117 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00118 void SetSize(uint32, uint32);
00119 void SetPos(uint32, uint32);
00120
00121 BOOL State;
00122
00123 void SetState(BOOL newstate) {
00124 State = (newstate) ? TRUE : FALSE;
00125 FlagDraw();
00126 };
00127 BOOL GetState() { return State;}
00128 };
00129
00130 class CheckBox : public Radio {
00131 _PROTECTED_:
00132 void CalcOffset();
00133 public:
00134 CheckBox() {}
00135 void Init(Bitmap *_img);
00136 void Init(char *_label, Font *_fnt);
00137 void Draw();
00138 void Click(int, int, int);
00139 void DblClick(int, int, int);
00140 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00141 void SetSize(uint32, uint32);
00142 void SetPos(uint32, uint32);
00143 };
00144
00145 class ScrollArrow : public Element {
00146 _PROTECTED_:
00147 int dir;
00148 public:
00149 ScrollArrow();
00150 void SetDirection(int newdir);
00151 int GetDirection() { return dir;}
00152 void Init(int _dir) {
00153 nofocus = TRUE;
00154 SetDirection(_dir);
00155 }
00156 void Draw();
00157 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent) {
00158 return Element::Create(_xpos, _ypos, 16, 16, _Style, _Parent);
00159 }
00160 void KeyDown(int keycode);
00161 };
00162
00163 class ScrollBar : public Element {
00164 friend class ScrollBarCombo;
00165 _PROTECTED_:
00166
00167 int idx;
00168 int viewsize;
00169 int totalsize;
00170
00171 int type;
00172 int pidx;
00173 int barsize;
00174 float ratio;
00175
00176 int start;
00177 BOOL movebar;
00178
00179 void Recalc();
00180 void RecalcIdx() {
00181 idx = int(float(pidx) * ratio);
00182 if (idx > (totalsize + viewsize)) idx = totalsize + viewsize;
00183 }
00184 void PageUp() {SetPos(idx - viewsize);}
00185 void PageDown() {SetPos(idx + viewsize);}
00186 public:
00187 ScrollBar();
00188 void SetSize(uint32, uint32);
00189 int GetPos() { return idx;}
00190 int SetPos(int newidx);
00191 void SetPos(int _x, int _y) {Element::SetPos(_x, _y);}
00192 void SetTotalSize(int newsize);
00193 void SetViewSize(int newsize);
00194 void Init(int _type);
00195 void Draw();
00196 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00197 void MouseDown(int, int, int);
00198 void MouseUp(int, int, int);
00199 void MouseOver(int, int, int);
00200 };
00201
00202 class ScrollBarCombo : public ScrollBar {
00203 _PROTECTED_:
00204 ScrollArrow *sa1, *sa2;
00205 public:
00206 ScrollBarCombo();
00207 void Init(int _type) {
00208 ScrollBar::Init(_type);
00209 }
00210 void Destroy();
00211 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00212 BOOL DispatchEvent(Element *id, int, int, int, int);
00213 void SetSize(uint32, uint32);
00214 void SetPos(int, int);
00215 int SetPos(int newidx) { return ScrollBar::SetPos(newidx);}
00216 };
00217
00218 struct TabElement {
00219 BOOL useimg;
00220 Element *img;
00221 String label;
00222 Font *fnt;
00223 Element *id;
00224 int width;
00225 };
00226
00227
00228 class Tabs : public Element {
00229 _PROTECTED_:
00230 ScrollArrow sal, sar;
00231 Array<TabElement*> list;
00232 int32 xpos;
00233 BOOL arrows;
00234 public:
00235 uint32 Count;
00236 int Index;
00237 Tabs();
00238 ~Tabs();
00239 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00240 BOOL DispatchEvent(Element *id, int, int, int, int);
00241 void AddTab(Element *id, Element *_img, int width);
00242 void AddTab(Element *id, char *_label, Font *_fnt, int width);
00243 void DeleteTab(uint32 idx);
00244 void Show();
00245 void Hide();
00246 void Draw();
00247 void MouseDown(int, int, int);
00248 void SetLabel(uint32 idx, char *_newlabel);
00249 void Switch(uint32 idx);
00250 void SetWidth(uint32 idx, uint32 width);
00251 void ScrollLeft();
00252 void ScrollRight();
00253 };
00254
00255 class BoxFill : public Element {
00256 public:
00257 void Draw();
00258 };
00259
00260 class Box : public Element {
00261 _PROTECTED_:
00262 BOOL _double;
00263 BOOL _outy;
00264 public:
00265 Box() {};
00266 void Init(BOOL __double, BOOL __outy);
00267 void Draw();
00268 void SetStyle(BOOL __double, BOOL __outy) {
00269 _double = __double;
00270 _outy = __outy;
00271 FlagDraw();
00272 }
00273 };
00274
00275 class HLine : public Element {
00276 public:
00277 HLine();
00278 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00279 void Draw();
00280 };
00281
00282 class VLine : public Element {
00283 public:
00284 VLine();
00285 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00286 void Draw();
00287 };
00288
00289 class TextBox : public Element {
00290 friend class TextBoxCombo;
00291 friend class TextLine;
00292 friend class PasswordTextLine;
00293 _PROTECTED_:
00294 Font *fnt;
00295 uint8 ct;
00296 void Draw();
00297 int32 dx, dy;
00298 int32 cx, cy;
00299
00300 int seldir;
00301 int32 selline1;
00302 int32 seloff1;
00303 int32 selline2;
00304 int32 seloff2;
00305 uint32 numcharx, numchary;
00306 uint32 pnumcharx, pnumchary;
00307 Cursor cursor;
00308 BOOL ProcessKey(int);
00309 void FindCursor(BOOL);
00310 void BreakUpLine(int);
00311 void AdjustSelection();
00312 void StartSelection();
00313 virtual void UpdateCount();
00314 void UpdateNumChars();
00315 void _SetSize(uint32, uint32);
00316 int strlentab(char *, int max);
00317 BOOL singleline;
00318 BOOL showborder;
00319 BOOL dirty;
00320 public:
00321
00322 TextBox();
00323 void Init(Font *_fnt, uint8 cursor_type = CT_LINE, int guiflgs = GUI_SHOWBORDER);
00324 ~TextBox();
00325
00326 void KeyDown(int);
00327 void GetKey(char);
00328 void MouseDown(int, int, int);
00329 void MouseUp(int, int, int);
00330 void MouseOver(int, int, int);
00331
00332
00333 Array<String*> text;
00334 void SetSize(uint32, uint32);
00335 void Show();
00336 void GetFocus();
00337 void LostFocus();
00338 void SetPos(int, int);
00339 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00340
00341 BOOL Editable;
00342 BOOL InsertMode;
00343 int Count;
00344 int MaxLineLength;
00345
00346 BOOL LoadText(File &);
00347 BOOL LoadText(char *);
00348 BOOL SaveText(File &, BOOL _unix = FALSE, BOOL removetrailingspaces = FALSE);
00349 BOOL SaveText(char *, BOOL _unix = FALSE, BOOL removetrailingspaces = FALSE);
00350 void SetText(char *);
00351
00352 char *GetLine(uint32 line);
00353 String &GetString(uint32 line);
00354 BOOL SetLine(uint32 line, char *str);
00355 void DelLine(uint32 line);
00356 void AddText(char *txt);
00357 void SetFont(Font *);
00358 Font *GetFont() {return fnt;}
00359 void SetEditable(BOOL state);
00360 void SetInsertMode(BOOL state);
00361 void SetCursorPos(int x , int y);
00362 void GetCursorPos(int *x, int *y);
00363 void SelectAll();
00364 void SelectNone();
00365 void SelectText(int line1, int off1, int line2, int off2, int dir = DOWN);
00366
00367 BOOL Find(char *fndstr, int flgs);
00368 BOOL SelectReplace(char *repstr);
00369 BOOL IsDirty();
00370 void ClearDirty();
00371
00372 void TrimRight(char *);
00373 void TrimLeft(char *);
00374 BOOL IsSelect();
00375 void GetSelect(String &s);
00376 };
00377
00378 class TextBoxCombo : public TextBox {
00379 _PROTECTED_:
00380 ScrollBarCombo *sv, *sh;
00381 BOOL svp, shp;
00382 void UpdateCount();
00383 public:
00384 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00385 void Destroy();
00386 void SetSize(uint32, uint32);
00387 TextBoxCombo();
00388 void Init(Font *_fnt, uint8 cursor_type = CT_LINE, int guiflgs = GUI_SHOWBORDER) {
00389 TextBox::Init(_fnt, cursor_type, guiflgs);
00390 }
00391 BOOL DispatchEvent(Element *id, int, int, int, int);
00392 void Hide();
00393 void Show();
00394 };
00395
00396 class TextLine : public TextBox {
00397 public:
00398 TextLine() {};
00399 void Init(Font *_fnt, uint8 cursor_type = CT_LINE);
00400 char *GetText() { return GetLine(0);}
00401 String &GetString() { return TextBox::GetString(0);}
00402 void SetCursorPos(int x) {TextBox::SetCursorPos(x, 0);}
00403 void GetCursorPos(int *x) {TextBox::GetCursorPos(x, (int*)NULL);}
00404 };
00405
00406 class PasswordTextLine : public TextLine {
00407 public:
00408 void Draw();
00409 PasswordTextLine();
00410 void Init(Font *_fnt, uint8 cursor_type = CT_LINE);
00411 };
00412
00413 class ProgressBar : public Element {
00414 _PROTECTED_:
00415 uint32 value;
00416 void Draw();
00417 public:
00418 ProgressBar();
00419
00420 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00421 void SetValue(uint32 newvalue) {
00422 if (newvalue > 100) newvalue = 100;
00423 value = newvalue;
00424 FlagDraw();
00425 }
00426 uint32 GetValue() { return value;}
00427 void SetClr(uint32 newclr) {clr = newclr; FlagDraw();}
00428 uint32 GetClr() { return clr;}
00429 };
00430
00431 struct SpreadSheetCell {
00432 friend class SpreadSheet;
00433 _PROTECTED_:
00434 BOOL deleteImage;
00435 Element *Image;
00436
00437 int vo;
00438 int ho;
00439 };
00440
00441 class SpreadSheet : public Element {
00442 friend class SpreadSheetCombo;
00443 _PROTECTED_:
00444 SpreadSheetCell *list;
00445
00446
00447 int posx, posy;
00448
00449 Array<int> Xs;
00450 Array<int> Ys;
00451 BOOL showlines;
00452 BOOL showborder;
00453 BOOL _double;
00454 BOOL _outy;
00455 void HideAll();
00456 void DeleteList();
00457 uint32 GetTotalXSize();
00458 uint32 GetTotalYSize();
00459 public:
00460 SpreadSheet();
00461 ~SpreadSheet();
00462 void Draw();
00463 void Show();
00464 void Hide();
00465 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00466
00467 void CreateSheet(int xc, int yc, int xs, int ys, int guiflgs);
00468
00469 void SetBorderStyle(BOOL __double, BOOL __outy);
00470 void SetCell(int x, int y, char *_text, Font *_fnt, int _clr);
00471 void SetCell(int x, int y, Element *_img);
00472 void SetCellJustify(int x, int y, int horizontal, int vertial);
00473 void DeleteCell(int x, int y);
00474 void DeleteSheet();
00475 void SetSheetPos(int x, int y);
00476 void GetSheetPos(int *x, int *y);
00477 void SetXSize(uint32 x, uint32 size);
00478 void SetYSize(uint32 y, uint32 size);
00479 };
00480
00481 class SpreadSheetCombo : public SpreadSheet {
00482 _PROTECTED_:
00483 ScrollBarCombo *sv, *sh;
00484 void SetTotalSizes();
00485 void DestroyChildren();
00486 public:
00487 SpreadSheetCombo();
00488 BOOL DispatchEvent(Element *id, int, int, int, int);
00489 void KeyDown(int key);
00490 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00491 void CreateSheet(int xc, int yc, int xs, int ys, int guiflgs);
00492 void DeleteSheet();
00493 void SetBorderStyle(BOOL __double, BOOL __outy);
00494 void Destroy() {
00495 DestroyChildren();
00496 SpreadSheet::Destroy();
00497 }
00498 void Show();
00499 void Hide();
00500 void SetXSize(uint32 x, uint32 size);
00501 void SetYSize(uint32 y, uint32 size);
00502 void SetSheetPos(int x, int y);
00503 };
00504
00505 class SelectionList;
00506
00507 class Selection : public Element {
00508 friend class SelectionList;
00509 _PROTECTED_:
00510 SelectionList *Owner;
00511 BOOL highlight;
00512 public:
00513
00514 Selection();
00515 ~Selection();
00516
00517 BOOL State;
00518 void Click(int, int, int);
00519 void Draw();
00520 void SetState(BOOL);
00521 void MouseOver(int,int,int);
00522
00523 void SetHighlight(BOOL state) {highlight = state;}
00524 };
00525
00526 class SelectionList {
00527 friend class Selection;
00528 _PROTECTED_:
00529 List<Selection*> list;
00530 void Click(Selection *, int flgs);
00531 public:
00532 void Add(Selection *);
00533 void Delete(Selection *);
00534 void DeleteAll();
00535
00536 void SelectAll();
00537 void UnselectAll();
00538 };
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550 class ListBox : public Element {
00551 friend class ComboBox;
00552 _PROTECTED_:
00553 Font *fnt;
00554 SpreadSheetCombo *ss;
00555 Array<String*> strlist;
00556 Array<Label*> llist;
00557 Array<Selection*> slist;
00558 BOOL highlight;
00559 public:
00560 ListBox();
00561 ~ListBox();
00562 int32 Index;
00563 uint32 Count;
00564 void Init(Font *_fnt);
00565 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00566 void Destroy();
00567 void Show();
00568 void Hide();
00569 BOOL DispatchEvent(Element *id, int, int, int, int);
00570
00571 BOOL Add(char *, int32 pos = -1);
00572
00573 BOOL Delete(int32 idx);
00574 void SetHighlight(BOOL state) {highlight = state;}
00575 BOOL GetState(int idx);
00576 int GetState();
00577 void SetState(int idx, BOOL state);
00578 char *Get();
00579 char *Get(int idx);
00580 void ClrAll();
00581 void SetTopZOrder();
00582 };
00583
00584
00585 class ComboBox : public Element {
00586 _PROTECTED_:
00587 Font *fnt;
00588 ListBox *lbox;
00589 TextLine *tline;
00590 BOOL lboxvisible;
00591
00592 void HideList();
00593 void ShowList();
00594 public:
00595 ComboBox() : Index( -1) {}
00596 ~ComboBox();
00597 int32 Index;
00598 void Init(Font *_fnt);
00599 BOOL Create(int _xpos, int _ypos, int _x, int _y, int _Style, Element *_Parent);
00600 void Destroy();
00601 void MouseDown(int, int, int);
00602 void MouseUp(int, int, int);
00603 void Draw();
00604
00605 void SetEditable(BOOL state) {tline->SetEditable(state);}
00606 BOOL Add(char *x, int32 pos = -1) { return lbox->Add(x, pos);}
00607 BOOL Delete(int32 idx) { return lbox->Delete(idx);}
00608 void Clear() {
00609 tline->SetText("");
00610 Index = -1;
00611 }
00612 int GetIndex() { return Index;}
00613 char *Get();
00614 char *Get(int idx);
00615 void SetIndex(int idx);
00616 void SetTopZOrder();
00617 BOOL DispatchEvent(Element *id, int, int, int, int);
00618 };
00619
00620 struct ExplorerResource {
00621 String name;
00622 String fullpath;
00623 uint32 type;
00624 Label lbl_1;
00625 Label lbl_2;
00626
00627 Selection sel_2;
00628 Bitmap icon;
00629 Bitmap expandicon;
00630 int indent;
00631 BOOL bExpanded;
00632 };
00633
00634 class Explorer : public SpreadSheetCombo {
00635 private:
00636 Font *fnt;
00637 Array<ExplorerResource*> reslist;
00638 BOOL bAutoStart, bIcons;
00639 void EnumFiles();
00640 BOOL EventExpand;
00641 int EventIndex;
00642 void SetCells();
00643 uint32 col1size, col2size, col3size;
00644 void FreeList();
00645 void Start(ExplorerResource *p);
00646 Bitmap *bmFolder, *bmFile, *bmDrive, *bmPlus, *bmMinus;
00647 String mask;
00648 Enumerator *ff;
00649 char *BuildAttrString(String &s);
00650 int guiflgs;
00651 void Insert(char *, int);
00652 void Sort(int);
00653 void qsort(int,int);
00654 int CalcXC();
00655 void Verify();
00656 public:
00657 String Path;
00658 String Filename;
00659
00660 Explorer();
00661 ~Explorer();
00662 void Init(Font *_fnt, Enumerator *Enum, int guiflgs);
00663 BOOL DispatchEvent(Element *id, int, int, int, int);
00664 void Show();
00665 void Hide();
00666
00667 void Update();
00668
00669 void SetPath(char *path);
00670 void SetAutoStart(BOOL state);
00671 void ShowDetails(BOOL state);
00672 void SetIcons(Bitmap *folder, Bitmap *file, Bitmap *drive, Bitmap *plus, Bitmap *minus);
00673 void GotoParentPath();
00674 void ViewOnlyPaths(BOOL state);
00675 void SetMask(char *msk) {mask = msk;}
00676
00677 void Expand(int idx);
00678 void Colapse(int idx);
00679
00680 BOOL ExpandToPath(char *path);
00681 };
00682