00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 #ifndef _WIDGETS_H_
00094 #define _WIDGETS_H_
00095
00096 #include <sys/stat.h>
00097 #include <string.h>
00098
00099 #ifdef __WATCOMC__
00100 #ifdef __DOS__
00101 #include <direct.h>
00102 #else
00103 #include <dirent.h>
00104 #endif // dos
00105 #elif !defined(_MSC_VER)
00106 #include <dirent.h>
00107 #endif // watcom
00108
00109 #ifdef __BORLANDC__
00110 #include <dir.h>
00111 #endif
00112
00113 #ifdef _MSC_VER
00114 #include <direct.h>
00115 #include "mydirent.h"
00116 #endif
00117
00118 #ifdef __BORLANDC__
00119 #pragma option push -b
00120 #pragma option push -a4
00121 #endif
00122
00123 #ifdef FG_NAMESPACE
00124 namespace fgl {
00125 #endif
00126
00127 const unsigned FDIALOG_OPEN = 1;
00128 const unsigned FDIALOG_SAVE = 2;
00129 const unsigned FDIALOG_MODAL = 4;
00130 const unsigned FDIALOG_SAVEDIR = 8;
00131 const unsigned FDIALOG_MULTISELECT = 16;
00132
00137 struct mydirent
00138 {
00139 struct dirent item;
00140 bool type;
00141 bool selected;
00142 mydirent() { memset(this, 0, sizeof(*this)); }
00143 };
00144
00154 class FGFileDialog : public FGConnector
00155 {
00156 public:
00157 enum { name_width=200, max_pathlen=512 };
00158 private:
00159 char path[max_pathlen];
00160 char tmppath[max_pathlen];
00161 char filename[max_pathlen];
00162 char *filter;
00163 int mode;
00164 int files,fls,dirs;
00165 int maxfiles;
00166 FileDialogCallBack fileselect2;
00167 void reload(void);
00168 FGWindow *wnd;
00169 FGEditBox *nameEBox;
00170 struct mydirent *filebuffer, *unused;
00171 int param;
00172 FGListBox *list;
00173 FGListBox *list2;
00174 FGPushButton *ok, *cancel, *mkdir, *home, *updir;
00175 int mdir;
00176
00177
00178 int Selected();
00179 void Refresh(char *);
00180 bool SelectFile(void);
00181 void _init(char *dir, char *flt, char *namewnd, int m, int ink, int paper);
00182
00183 static void InputName(CallBack);
00184 static void Mkdir(CallBack);
00185 static void Ok(CallBack);
00186 static void Updir(CallBack);
00187 static void Home(CallBack);
00188 static void myproc(FGEvent *p);
00189 static void drawone(int flag, FGWindow *wnd,int x,int y,void *str,int index);
00190 static void drawone2(int flag, FGWindow *wnd,int x,int y,void *str,int index);
00191 static char delimiter[2];
00192 protected:
00193 public:
00204 FGFileDialog(FileDialogCallBack filesel, char *dir=0, char *flt=0, char *namewnd="File Dialog", int m=FDIALOG_OPEN, int ink=0, int paper=PM);
00205 virtual ~FGFileDialog()
00206 {
00207 delete [] filebuffer;
00208 if (wnd) delete wnd;
00209 }
00213 char* FGAPI GetDir(void) { return path; }
00215 char* FGAPI GetName(void) { return filename; }
00219 void FGAPI BuildFullPathname(char *buffer);
00223 void FGAPI BuildRelativePathname(char *buffer);
00227 void FGAPI SetDir(char *d) { strcpy(path, d); reload(); }
00231 void FGAPI SetFilter(char *f) { filter=f; reload(); }
00239 void FGAPI SetMode(int m) { mode=m; }
00245 bool TestForOverwrite(void);
00246 };
00247
00255 class FGTextEditor : public FGConnector
00256 {
00257 public:
00258 enum { FGMAX_LINE=32768, FGMAX_LINESIZE=512 };
00259 private:
00260 class FGLINE
00261 {
00262 public:
00263 unsigned size;
00264 unsigned char *text;
00265 };
00266
00267 class FGBUFFER
00268 {
00269 public:
00270 char name[256];
00271 char buffer[FGMAX_LINESIZE];
00272 int posx, posy;
00273 int line;
00274 int lines;
00275 int flags;
00276 int top;
00277 int ovr;
00278 int hscroll;
00279 int sel_line1;
00280 int sel_pos1;
00281 int sel_line2;
00282 int sel_pos2;
00283 FGBUFFER()
00284 {
00285 memset(this,0,sizeof(*this));
00286 }
00287 };
00288
00289 protected:
00290 FGWindow *Text_EditorPtr;
00291 FGWindow *OptionsPtr;
00292 FGWindow *String_SearchPtr;
00293 int lfonly, font_save;
00294 FGBUFFER buf;
00295 FGLINE text[FGMAX_LINE];
00296 char s[1028];
00297 int WX, WY;
00298 char srch_str[33];
00299 int last_found;
00300 int _font;
00301 int TABSIZE;
00302 int nodraw,inblock,ronly;
00303 int X, Y, W, H;
00304 FGTextEditor **self;
00305
00306 void FGAPI file(void);
00307 int FGAPI _memcmp(unsigned char *from, unsigned char *co, unsigned kolko, unsigned l);
00308 int FGAPI Find(int from, int count, int size);
00309 void FGAPI Clear(void);
00310 void FGAPI _goto(void);
00311 static void SearchProc(FGEvent *p);
00312 void FGAPI search(void);
00313 static void SetFont(CallBack);
00314 static void OptionsProc(FGEvent *p);
00315 static void file_proc(CallBack);
00316 void FGAPI options(void);
00317 static char* FGAPI terminate(char *s);
00318 FGLINE* FGAPI create_line(char *s, int at);
00319 void FGAPI Init(void);
00320 void FGAPI SaveAsBuffer2(void);
00321 void FGAPI OpenBuffer2(void);
00322 static void OpenBuffer1(char *s, FGFileDialog *);
00323 static void SaveAsBuffer1(char *s, FGFileDialog *);
00324 void FGAPI ShowCursor(int trigger);
00325 void FGAPI ShowLine(int scr, char *s);
00326 int FGAPI isempty(char *s);
00327 void FGAPI CKey(int k);
00328 void FGAPI Key(int k);
00329 void FGAPI SaveChanges(void);
00330 static void Text_EditorProc(FGEvent *p);
00331 void FGAPI Open(char *s);
00332 void FGAPI Destruct(void);
00333 public:
00334 FGTextEditor(FGTextEditor **e=0, char *arg="Untitled", int font=FONT0816, int ink=CGRAY3, int paper=CBLACK, int flags = WSTANDARD|WMENU|WSTATUSBAR|WSIZEABLE|WNOTIFY|WMINIMIZE|WUSELAST|WNOPICTO);
00335 virtual ~FGTextEditor();
00336 void FGAPI ShowBuffer(int top=0);
00337 void FGAPI NewBuffer(void);
00338 void FGAPI OpenBuffer(char *s);
00339 void FGAPI ReopenBuffer(void);
00340 void FGAPI SaveBuffer(void);
00341 void FGAPI SaveAsBuffer(char *s);
00342 void FGAPI Close(void);
00343 void FGAPI Goto(int);
00347 void FGAPI ReadOnlyMode(void) { ronly = 1; Text_EditorPtr->ResetChange(); };
00351 void FGAPI SetFocus(void) { Text_EditorPtr->WindowFocus(); }
00355 int FGAPI AppendLine(char *str);
00356 };
00357
00364 class FGColorDialog : public FGConnector
00365 {
00366 FGWindow *wnd;
00367 ColorDialogCallBack fnc;
00368 int curr;
00369 unsigned color;
00370 FGSlideBarV *sl1, *sl2, *sl3;
00371 int cd_r, cd_g, cd_b;
00372
00373 static unsigned int custom_colors[256];
00374 void FGAPI FocusTo(int a);
00375 static void CSliderFnc(CallBack cb);
00376 static void SetColorsProc(FGEvent *p);
00377 void UpdatePalette(void);
00378 protected:
00379 public:
00380 virtual ~FGColorDialog()
00381 {
00382 if (wnd) delete wnd;
00383 }
00390 FGColorDialog(char *capture, ColorDialogCallBack f, FGPixel bgc=PM);
00396 static int FGAPI Import(char *name);
00402 static int FGAPI Export(char *name);
00406 unsigned int* FGAPI GetColors(void)
00407 {
00408 return custom_colors;
00409 }
00410 };
00411
00412 const unsigned FONT_DIALOG_FIXED = 1;
00413 const unsigned FONT_DIALOG_VARIABLE = 2;
00414 const unsigned FONT_DIALOG_ALL = (FONT_DIALOG_FIXED | FONT_DIALOG_VARIABLE);
00415
00422 class FGFontDialog : public FGConnector
00423 {
00424 FGWindow *wnd;
00425 FontDialogCallBack userfnc;
00426 int curr;
00427 FGListBox *lb;
00428 static void SetFontProc(FGEvent *p);
00429 void ShowFont(void);
00430 public:
00439 FGFontDialog(FontDialogCallBack f, int which=FONT_DIALOG_ALL, char *capture="Font selection dialog", FGPixel bgc=PM);
00440 virtual ~FGFontDialog()
00441 {
00442 }
00443 };
00444
00451 class FGUpDown
00452 {
00453 FGPushButton *up, *down;
00454 FGEditBox *eb;
00455 float step;
00456 static void handler1(CallBack);
00457 static void handler2(CallBack);
00458
00459 public:
00460 FGUpDown(FGEditBox *eb, float _step);
00462 void Disable(void)
00463 {
00464 up->Disable();
00465 down->Disable();
00466 eb->Disable();
00467 }
00469 void Enable(void)
00470 {
00471 up->Enable();
00472 down->Enable();
00473 eb->Enable();
00474 }
00475 };
00476
00482 class FGWidgetContainer
00483 {
00484 protected:
00485 void *ptr;
00486
00487 public:
00488 FGWidgetContainer();
00489 ~FGWidgetContainer();
00491 void DisableContainer(void);
00493 void EnableContainer(void);
00495 void AddToContainer(FGControl *);
00497 void SetUserData(void* val);
00498
00499 };
00500
00504 class FGRadioGroup : public FGWidgetContainer
00505 {
00506 protected:
00507 FGButtonGroup* grp;
00508 unsigned id;
00509 int* value;
00510 int current;
00511 int count;
00512 void (*userfnc)(FGControl* ,int);
00513
00514 static void callback(CallBack cb)
00515 {
00516 FGRadioGroup* _THIS = (FGRadioGroup *)cb->GetPrivateData();
00517 _THIS->current = cb->GetId() - _THIS->id;
00518 if (_THIS->value) *_THIS->value = _THIS->current;
00519 if (_THIS->userfnc)
00520 _THIS->userfnc(cb, _THIS->current);
00521 }
00522 public:
00523 FGRadioGroup(int x, int y, char *names[], int *init_value, void (*cb)(FGControl* ,int), FGWindow* w, int step=20);
00527 virtual ~FGRadioGroup()
00528 {
00529 if (grp) delete grp;
00530 grp = 0;
00531 }
00532 void ChangeItem(int* new_value);
00533 };
00534
00539 class FGRadioGroupVertical : public FGRadioGroup
00540 {
00541 FGControl* DrawOne(int x, int y, int offset, char* name, int key, FGWindow* w, ControlCall cb)
00542 {
00543 return w->AddRadioButton(x, y+offset, name, key, 0, cb);
00544 }
00545 public:
00558 FGRadioGroupVertical(int x, int y, char *names[], int keys[], int *init_value, void (*cb)(FGControl* ,int), FGWindow* w, int step=20)
00559 : FGRadioGroup(x,y,names,init_value,cb,w,step)
00560 {
00561 FGControl *c;
00562 for(int i=0; i<count; i++)
00563 {
00564 c = DrawOne(x, y, i*step, names[i], keys[i], w, callback);
00565 if (i==0) id = c->GetId();
00566 c->SetPrivateData((void *)this);
00567 grp->AddToGroup(c, init_value ? i == *init_value : 0);
00568 AddToContainer(c);
00569 }
00570 }
00571 };
00572
00577 class FGRadioGroupHorizontal : public FGRadioGroup
00578 {
00579 FGControl* DrawOne(int x, int y, int offset, char* name, int key, FGWindow* w, ControlCall cb)
00580 {
00581 return w->AddRadioButton(x+offset, y, name, key, 0, cb);
00582 }
00583 public:
00596 FGRadioGroupHorizontal(int x, int y, char *names[], int keys[], int *init_value, void (*cb)(FGControl* ,int), FGWindow* w, int step)
00597 : FGRadioGroup(x,y,names,init_value,cb,w,step)
00598 {
00599 FGControl *c;
00600 for(int i=0; i<count; i++)
00601 {
00602 c = DrawOne(x, y, i*step, names[i], keys[i], w, callback);
00603 if (i==0) id = c->GetId();
00604 c->SetPrivateData((void *)this);
00605 grp->AddToGroup(c, init_value ? i == *init_value : 0);
00606 AddToContainer(c);
00607 }
00608 }
00609 };
00610
00683 class FGColorPicker
00684 {
00685 FGWindow* wnd;
00686 FGColor* base_color;
00687 FGColor the_color;
00688
00689 FGControl* ctrl_sat;
00690 FGControl* ctrl_lum;
00691 FGControl* ctrl_hue;
00692 FGControl* ctrl_r;
00693 FGControl* ctrl_g;
00694 FGControl* ctrl_b;
00695
00696 int m_saturation;
00697 int m_luminance;
00698 int m_hue;
00699
00700 int m_r;
00701 int m_g;
00702 int m_b;
00703
00704 static void PickerProc(FGEvent* e);
00705 void DrawColorCircle(void);
00706 static void Ok(CallBack cb)
00707 {
00708 FGColorPicker *_THIS = (FGColorPicker *)cb->GetOwner()->GetUserData();
00709 * (_THIS->base_color) = _THIS->the_color;
00710 cb->Close(cb);
00711 }
00712 static void DrawColorHSV(CallBack cb)
00713 {
00714 FGColorPicker *_THIS = (FGColorPicker *)cb->GetOwner()->GetUserData();
00715 _THIS->the_color.SetHLS(_THIS->m_hue, _THIS->m_luminance/100., _THIS->m_saturation/100.);
00716 _THIS->DrawColor();
00717 }
00718 static void DrawColorRGB(CallBack cb)
00719 {
00720 FGColorPicker *_THIS = (FGColorPicker *)cb->GetOwner()->GetUserData();
00721 _THIS->the_color.SetRGB(_THIS->m_r, _THIS->m_g, _THIS->m_b);
00722 _THIS->DrawColor();
00723 }
00724 void SetState(FGColor& c)
00725 {
00726 the_color = c;
00727 m_saturation = int(the_color.GetSaturation()*100.);
00728 m_luminance = int(the_color.GetLuminance()*100.);
00729 m_hue = int(the_color.GetHue());
00730 m_r = the_color.GetRed();
00731 m_g = the_color.GetGreen();
00732 m_b = the_color.GetBlue();
00733 DrawColor();
00734 }
00735 void DrawColor(void);
00736 void Box(int x, int y, FGColor paper);
00737 public:
00747 FGColorPicker(FGColor* _base_color);
00748 ~FGColorPicker()
00749 {
00750 delete wnd;
00751 wnd = 0;
00752 }
00753 };
00754
00755 #ifdef __BORLANDC__
00756 #pragma option pop
00757 #pragma option pop
00758 #endif
00759
00760 #ifdef FG_NAMESPACE
00761 }
00762 #endif
00763
00764 #endif