File: gui.h

package info (click to toggle)
efte 1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,800 kB
  • sloc: cpp: 43,587; ansic: 1,228; makefile: 271; objc: 92; sh: 40
file content (221 lines) | stat: -rw-r--r-- 6,209 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*    gui.h
 *
 *    Copyright (c) 2008, eFTE SF Group (see AUTHORS file)
 *    Copyright (c) 1994-1996, Marko Macek
 *
 *    You may distribute under the terms of either the GNU General Public
 *    License or the Artistic License, as specified in the README file.
 *
 */

#ifndef __GUI_H
#define __GUI_H

#include "console.h"
#include <stdarg.h>

#define RUN_WAIT 0
#define RUN_ASYNC 1

class GFramePeer;
class GViewPeer;

class GUI;
class GFrame;

class GView {
public:
    GFrame *Parent;
    GView *Next, *Prev;
    GViewPeer *Peer;
    int Result;

    GView(GFrame *parent, int XSize, int YSize);
    virtual ~GView();

    int ConClear();
    int ConPutBox(int X, int Y, int W, int H, PCell Cell);
    int ConGetBox(int X, int Y, int W, int H, PCell Cell);
    int ConPutLine(int X, int Y, int W, int H, PCell Cell);
    int ConSetBox(int X, int Y, int W, int H, TCell Cell);
    int ConScroll(int Way, int X, int Y, int W, int H, TAttr Fill, int Count);

    int ConSetSize(int X, int Y);
    int ConQuerySize(int *X, int *Y);

    int ConSetCursorPos(int X, int Y);
    int ConQueryCursorPos(int *X, int *Y);
    int ConShowCursor();
    int ConHideCursor();
    int ConCursorVisible();
    void ConSetInsertState(bool insert);

    int CaptureMouse(int grab);
    int CaptureFocus(int grab);

    virtual int Execute();
    void EndExec(int NewResult);

    int QuerySbVPos();
    int SetSbVPos(int Start, int Amount, int Total);
    int SetSbHPos(int Start, int Amount, int Total);
    int ExpandHeight(int DeltaY);

    int IsActive();

    virtual void Update();
    virtual void Repaint();
    virtual void Activate(int gotfocus);
    virtual void Resize(int width, int height);
    virtual void HandleEvent(TEvent &Event);
};

class GFrame {
public:
    GFrame *Prev, *Next;
    GView *Top, *Active;
    GFramePeer *Peer;
    char *Menu;

    GFrame(int XSize, int YSize);
    virtual ~GFrame();

    int ConSetTitle(char *Title, char *STitle);
    int ConGetTitle(char *Title, int MaxLen, char *STitle, int SMaxLen);

    int ConSetSize(int X, int Y);
    int ConQuerySize(int *X, int *Y);

    int AddView(GView *view);
    int ConSplitView(GView *view, GView *newview);
    int ConCloseView(GView *view);
    int ConResizeView(GView *view, int DeltaY);
    int SelectView(GView *view);

    virtual void Update();
    virtual void Repaint();
    virtual void UpdateMenu();

    void InsertView(GView *Prev, GView *view);
    void RemoveView(GView *view);
    void SelectNext(int back);

    void Resize(int width, int height);
    void DrawMenuBar();

    int ExecMainMenu(char Sub);
    int SetMenu(const char *Name);
    char *QueryMenu();
    int PopupMenu(const char *Name);

    void Show();
    void Activate();

    int isLastFrame();
};

class GUI {
public:
    GUI(int &argc, char **argv, int XSize, int YSize);
    virtual ~GUI();

    int ConSuspend();
    int ConContinue();
    int ShowEntryScreen();

    void ProcessEvent();
    virtual void DispatchEvent(GFrame *frame, GView *view, TEvent &Event);
    int ConGetEvent(TEventMask EventMask, TEvent *Event, int WaitTime, int Delete, GView **view);
    int ConPutEvent(TEvent Event);
    int ConFlush(void);
    int ConGrabEvents(TEventMask EventMask);

    virtual int Start(int &argc, char **argv);
    virtual void Stop();

    int Run();
    void StopLoop();

    int RunProgram(int mode, char *Command);

    int OpenPipe(char *Command, EModel *notify);
    int SetPipeView(int id, EModel *notify);
    int ReadPipe(int id, void *buffer, int len);
    int ClosePipe(int id);

    int multiFrame();
    void deleteFrame(GFrame *frame);

    int fArgc;
    char **fArgv;
    int doLoop;
};

extern GFrame *frames;
extern GUI *gui;

#define GUIDLG_CHOICE      0x00000001
#define GUIDLG_PROMPT      0x00000002
#define GUIDLG_PROMPT2     0x00000004
#define GUIDLG_FILE        0x00000008
#define GUIDLG_FIND        0x00000010
#define GUIDLG_FINDREPLACE 0x00000020

extern unsigned long HaveGUIDialogs;

void DieError(int rc, const char *msg, ...);

#define GF_OPEN    0x0001
#define GF_SAVEAS  0x0002

int DLGGetStr(GView *View, const char *Prompt, unsigned int BufLen, char *Str, int HistId, int Flags);
int DLGGetFile(GView *View, const char *Prompt, unsigned int BufLen, char *FileName, int Flags);

#define GPC_NOTE    0x0000
#define GPC_CONFIRM 0x0001
#define GPC_WARNING 0x0002
#define GPC_ERROR   0x0004
#define GPC_FATAL   0x0008
#define GPC_ABOUT   0x00016
int DLGPickChoice(GView *View, const char *ATitle, int NSel, va_list ap, int Flags);

#define SEARCH_BACK    0x00000001   // reverse (TODO for regexps)
#define SEARCH_RE      0x00000002   // use regexp
#define SEARCH_NCASE   0x00000004   // case
#define SEARCH_GLOBAL  0x00000008   // start from beggining (or end if BACK)
#define SEARCH_BLOCK   0x00000010   // search in block
#define SEARCH_NEXT    0x00000020   // next match
#define SEARCH_NASK    0x00000040   // ask before replacing
#define SEARCH_ALL     0x00000080   // search all
#define SEARCH_REPLACE 0x00000100   // do a replace operation
#define SEARCH_JOIN    0x00000200   // join line
#define SEARCH_SPLIT   0x00000800   // split the line
#define SEARCH_DELETE  0x00000400   // delete line
#define SEARCH_CENTER  0x00001000   // center finds
#define SEARCH_NOPOS   0x00002000   // don't move the cursor
#define SEARCH_WORDBEG 0x00004000   // match at beginning of words only
#define SEARCH_WORDEND 0x00008000   // match at end of words only
#define SEARCH_WORD    (SEARCH_WORDBEG | SEARCH_WORDEND)
//0x00000800   // search words
//#define SEARCH_LINE    0x00002000   // search on current line only TODO
//#define SEARCH_WRAP    0x00004000   // similiar to GLOBAL, but goes to start
// only when match from current position fails TODO
//#define SEARCH_BOL     0x00008000   // search at line start
//#define SEARCH_EOL     0x00010000   // search at line end

#define MAXSEARCH 512

typedef struct {
    int ok;
    char strSearch[MAXSEARCH];
    char strReplace[MAXSEARCH];
    unsigned long Options;
    //
    int resCount;
    int lastInsertLen;
} SearchReplaceOptions;

int DLGGetFind(GView *View, SearchReplaceOptions &sr);
int DLGGetFindReplace(GView *View, SearchReplaceOptions &sr);

#endif