1 /* gui.h 2 * 3 * Copyright (c) 1994-1996, Marko Macek 4 * 5 * You may distribute under the terms of either the GNU General Public 6 * License or the Artistic License, as specified in the README file. 7 * 8 */ 9 10 #ifndef GUI_H 11 #define GUI_H 12 13 #include "console.h" 14 15 #include <stdarg.h> 16 17 class GFramePeer; 18 class GViewPeer; 19 class GUI; 20 class GFrame; 21 22 class GView { 23 public: 24 GFrame *Parent; 25 GView *Next, *Prev; 26 GViewPeer *Peer; 27 int Result; 28 29 GView(GFrame *parent, int XSize, int YSize); 30 virtual ~GView(); 31 32 int ConClear(); 33 int ConPutBox(int X, int Y, int W, int H, PCell Cell); 34 int ConGetBox(int X, int Y, int W, int H, PCell Cell); 35 int ConPutLine(int X, int Y, int W, int H, PCell Cell); 36 int ConSetBox(int X, int Y, int W, int H, TCell Cell); 37 int ConScroll(int Way, int X, int Y, int W, int H, TAttr Fill, int Count); 38 39 int ConSetSize(int X, int Y); 40 int ConQuerySize(int *X, int *Y); 41 42 int ConSetCursorPos(int X, int Y); 43 int ConQueryCursorPos(int *X, int *Y); 44 int ConShowCursor(); 45 int ConHideCursor(); 46 int ConCursorVisible(); 47 int ConSetCursorSize(int Start, int End); 48 49 int CaptureMouse(int grab); 50 int CaptureFocus(int grab); 51 52 virtual int Execute(); 53 void EndExec(int NewResult); 54 55 int QuerySbVPos(); 56 int SetSbVPos(int Start, int Amount, int Total); 57 int SetSbHPos(int Start, int Amount, int Total); 58 int ExpandHeight(int DeltaY); 59 60 int IsActive(); 61 62 virtual void Update(); 63 virtual void Repaint(); 64 virtual void Activate(int gotfocus); 65 virtual void Resize(int width, int height); 66 virtual void HandleEvent(TEvent &Event); 67 }; 68 69 class GFrame { 70 public: 71 GFrame *Prev, *Next; 72 GView *Top, *Active; 73 GFramePeer *Peer; 74 char *Menu; 75 76 GFrame(int XSize, int YSize); 77 virtual ~GFrame(); 78 79 int ConSetTitle(const char *Title, const char *STitle); 80 int ConGetTitle(char *Title, size_t MaxLen, char *STitle, size_t SMaxLen); 81 82 int ConSetSize(int X, int Y); 83 int ConQuerySize(int *X, int *Y); 84 85 int AddView(GView *view); 86 int ConSplitView(GView *view, GView *newview); 87 int ConCloseView(GView *view); 88 int ConResizeView(GView *view, int DeltaY); 89 int SelectView(GView *view); 90 91 virtual void Update(); 92 virtual void Repaint(); 93 virtual void UpdateMenu(); 94 95 void InsertView(GView *Prev, GView *view); 96 void RemoveView(GView *view); 97 void SelectNext(int back); 98 99 void Resize(int width, int height); 100 void DrawMenuBar(); 101 102 int ExecMainMenu(char Sub); 103 int SetMenu(const char *Name); 104 char *QueryMenu(); 105 int PopupMenu(const char *Name); 106 107 void Show(); 108 void Activate(); 109 110 int isLastFrame(); 111 }; 112 113 class GUI { 114 public: 115 enum { 116 RUN_WAIT, 117 RUN_ASYNC 118 }; 119 120 GUI(int &argc, char **argv, int XSize, int YSize); 121 virtual ~GUI(); 122 123 int ConSuspend(); 124 int ConContinue(); 125 int ShowEntryScreen(); 126 127 void ProcessEvent(); 128 virtual void DispatchEvent(GFrame *frame, GView *view, TEvent &Event); 129 int ConGetEvent(TEventMask EventMask, TEvent* Event, int WaitTime, int Delete, GView **view); 130 int ConPutEvent(const TEvent& Event); 131 int ConFlush(); 132 int ConGrabEvents(TEventMask EventMask); 133 134 virtual int Start(int &argc, char **argv); 135 virtual void Stop(); 136 137 int Run(); 138 void StopLoop(); 139 140 int RunProgram(int mode, char *Command); 141 142 int OpenPipe(const char *Command, EModel *notify); 143 int SetPipeView(int id, EModel *notify); 144 ssize_t ReadPipe(int id, void *buffer, size_t len); 145 int ClosePipe(int id); 146 147 int multiFrame(); 148 149 int fArgc; 150 char **fArgv; 151 int doLoop; 152 }; 153 154 extern GFrame *frames; 155 extern GUI *gui; 156 157 #define GUIDLG_CHOICE 0x00000001 158 #define GUIDLG_PROMPT 0x00000002 159 #define GUIDLG_PROMPT2 0x00000004 160 #define GUIDLG_FILE 0x00000008 161 #define GUIDLG_FIND 0x00000010 162 #define GUIDLG_FINDREPLACE 0x00000020 163 164 extern unsigned long HaveGUIDialogs; 165 166 void DieError(int rc, const char *msg, ...); 167 168 #define GF_OPEN 0x0001 169 #define GF_SAVEAS 0x0002 170 171 int DLGGetStr(GView *View, const char *Prompt, unsigned int BufLen, char *Str, int HistId, int Flags); 172 int DLGGetFile(GView *View, const char *Prompt, unsigned int BufLen, char *FileName, int Flags); 173 174 #define GPC_NOTE 0x0000 175 #define GPC_CONFIRM 0x0001 176 #define GPC_WARNING 0x0002 177 #define GPC_ERROR 0x0004 178 #define GPC_FATAL 0x0008 179 int DLGPickChoice(GView *View, const char *ATitle, int NSel, va_list ap, int Flags); 180 181 #define SEARCH_BACK 0x00000001 // reverse (TODO for regexps) 182 #define SEARCH_RE 0x00000002 // use regexp 183 #define SEARCH_NCASE 0x00000004 // case 184 #define SEARCH_GLOBAL 0x00000008 // start from begining (or end if BACK) 185 #define SEARCH_BLOCK 0x00000010 // search in block 186 #define SEARCH_NEXT 0x00000020 // next match 187 #define SEARCH_NASK 0x00000040 // ask before replacing 188 #define SEARCH_ALL 0x00000080 // search all 189 #define SEARCH_REPLACE 0x00000100 // do a replace operation 190 #define SEARCH_JOIN 0x00000200 // join line 191 #define SEARCH_DELETE 0x00000400 // delete line 192 #define SEARCH_CENTER 0x00001000 // center finds 193 #define SEARCH_NOPOS 0x00002000 // don't move the cursor 194 #define SEARCH_WORDBEG 0x00004000 // match at beginning of words only 195 #define SEARCH_WORDEND 0x00008000 // match at end of words only 196 #define SEARCH_WORD (SEARCH_WORDBEG | SEARCH_WORDEND) 197 //0x00000800 // search words 198 //#define SEARCH_LINE 0x00002000 // search on current line only TODO 199 //#define SEARCH_WRAP 0x00004000 // similiar to GLOBAL, but goes to start 200 // only when match from current position fails TODO 201 //#define SEARCH_BOL 0x00008000 // search at line start 202 //#define SEARCH_EOL 0x00010000 // search at line end 203 204 #define MAXSEARCH 512 205 206 struct SearchReplaceOptions { 207 int ok; 208 int resCount; 209 int lastInsertLen; 210 unsigned long Options; 211 212 //enum { MAXSEARCH = 512 }; 213 char strSearch[MAXSEARCH]; 214 char strReplace[MAXSEARCH]; 215 216 SearchReplaceOptions(); 217 }; 218 219 int DLGGetFind(GView *View, SearchReplaceOptions &sr); 220 int DLGGetFindReplace(GView *View, SearchReplaceOptions &sr); 221 222 enum WaitFdPipe { 223 FD_PIPE_ERROR, 224 FD_PIPE_1, 225 FD_PIPE_2, 226 FD_PIPE_EVENT, 227 FD_PIPE_TIMEOUT 228 }; 229 WaitFdPipe WaitFdPipeEvent(TEvent *Event, int fd, int fd2, int WaitTime); 230 231 #endif // GUI_H 232