forked from alexfru/dflat20
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsmallpad.c
168 lines (156 loc) · 4.56 KB
/
smallpad.c
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
/* --------------- smallpad.c ----------- */
#include "dflat.h"
char DFlatApplication[] = "SmallPad";
static char Untitled[] = "Untitled";
static int wndpos;
static int SmallPadProc(WINDOW, MESSAGE, PARAM, PARAM);
static void NewFile(WINDOW);
static void OpenPadWindow(WINDOW, char *);
static int OurEditorProc(WINDOW, MESSAGE, PARAM, PARAM);
void PrepFileMenu(void *w, struct Menu *mnu)
{
}
/* --------------------- the main menu --------------------- */
DEFMENU(MainMenu)
/* --------------- the File popdown menu ----------------*/
POPDOWN( "~File", PrepFileMenu, "Read/write/print files. Go to DOS" )
SELECTION( "~New", ID_NEW, 0, 0 )
SEPARATOR
SELECTION( "E~xit", ID_EXIT, ALT_X, 0 )
ENDPOPDOWN
ENDMENU
/* ------------- the System Menu --------------------- */
DEFMENU(SystemMenu)
POPDOWN("System Menu", NULL, NULL)
SELECTION("~Move", ID_SYSMOVE, 0, 0 )
SELECTION("~Size", ID_SYSSIZE, 0, 0 )
SEPARATOR
SELECTION("~Close", ID_SYSCLOSE, CTRL_F4, 0 )
ENDPOPDOWN
ENDMENU
int main(int argc, char *argv[])
{
WINDOW wnd;
if (!init_messages())
return 1;
Argv = argv;
if (!LoadConfig())
cfg.ScreenLines = SCREENHEIGHT;
wnd = CreateWindow(APPLICATION,
"D-Flat SmallPad",
0, 0, -1, -1,
&MainMenu,
NULL,
SmallPadProc,
MOVEABLE |
SIZEABLE |
HASBORDER |
MINMAXBOX
/* | HASSTATUSBAR */
);
SendMessage(wnd, SETFOCUS, TRUE, 0);
while (argc > 1) {
OpenPadWindow(wnd, argv[1]);
--argc;
argv++;
}
while (dispatch_message())
;
return 0;
}
/* ------- window processing module for the
memopad application window ----- */
static int SmallPadProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
{
int rtn;
switch (msg) {
case COMMAND:
switch ((int)p1) {
case ID_NEW:
NewFile(wnd);
return TRUE;
case ID_EXIT:
break;
default:
break;
}
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
/* --- The New command. Open an empty editor window --- */
static void NewFile(WINDOW wnd)
{
OpenPadWindow(wnd, Untitled);
}
/* --- open a document window and load a file --- */
static void OpenPadWindow(WINDOW wnd, char *FileName)
{
static WINDOW wnd1;
wndpos += 2;
if (wndpos == 20)
wndpos = 2;
wnd1 = CreateWindow(EDITOR,
FileName,
(wndpos-1)*2, wndpos, 10, 40,
NULL, wnd, OurEditorProc,
SHADOW |
MINMAXBOX |
CONTROLBOX |
VSCROLLBAR |
HSCROLLBAR |
MOVEABLE |
HASBORDER |
SIZEABLE |
MULTILINE
);
SendMessage(wnd1, SETFOCUS, TRUE, 0);
}
/* ------ display the row and column in the statusbar ------ */
static void ShowPosition(WINDOW wnd)
{
char status[30];
sprintf(status, "Line:%4d Column: %2d",
wnd->CurrLine, wnd->CurrCol);
SendMessage(GetParent(wnd), ADDSTATUS, (PARAM) status, 0);
}
/* ----- window processing module for the editboxes ----- */
static int OurEditorProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
{
int rtn;
switch (msg) {
case SETFOCUS:
if ((int)p1) {
wnd->InsertMode = 1;
wnd->WordWrapMode = 1;
}
rtn = DefaultWndProc(wnd, msg, p1, p2);
if ((int)p1 == FALSE)
SendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
else
ShowPosition(wnd);
return rtn;
case KEYBOARD_CURSOR:
rtn = DefaultWndProc(wnd, msg, p1, p2);
ShowPosition(wnd);
return rtn;
case COMMAND:
switch ((int) p1) {
default:
break;
}
break;
case CLOSE_WINDOW:
wndpos = 0;
if (wnd->extension != NULL) {
free(wnd->extension);
wnd->extension = NULL;
}
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}