Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 270 lines (214 sloc) 7.707 kB
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
1 /*
2 ** gwstatb.c -- status bar support for elvis.
3 **
4 ** Copyright 1996, Serge Pirotte.
5 */
6
7 #define CHAR Char
8 #include "elvis.h"
9 #undef CHAR
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
10 #undef ELVBOOL
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
11
12 #if defined (GUI_WIN32)
13
14 #include <windows.h>
15 #include <commctrl.h>
16 #include "winelvis.h"
17
18 #define SB_PART_POS 1
19 #define SB_PART_CHANGED 2
20 #define SB_PART_MODE 3
21 #define SB_PART_NUM 4
22 #define SB_PART_CAP 5
23 #define SB_PART_TIME 6
24
25 static int size_pos;
26 static int size_changed;
27 static int size_mode;
28 static int size_num;
29 static int size_cap;
30 static int size_time;
31
32 static int cxborder;
33 static int cyborder;
34
35 /* --------------------------------------------------------------------
36 **
37 ** gw_status_upd_time -- update time on status bar.
38 */
39
40 static void gw_status_upd_time (HWND hwnd)
41
42 {
43 SYSTEMTIME sys_time;
44 char str[10];
45 int hour;
46
47 GetLocalTime (&sys_time);
48 if (sys_time.wHour == 0)
49 hour = 12;
50 else if (sys_time.wHour > 12)
51 hour = sys_time.wHour - 12;
52 else
53 hour = sys_time.wHour;
54 sprintf (str, "%d:%2.2d %s", hour, sys_time.wMinute,
55 sys_time.wHour < 12 ? "AM" : "PM");
56 SendMessage (hwnd, SB_SETTEXT, (WPARAM)SB_PART_TIME, (LPARAM)str);
57 }
58
59 /* --------------------------------------------------------------------
60 **
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
61 ** gw_set_panes -- set the panes' positions.
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
62 */
63
64 static void gw_set_panes (GUI_WINDOW *gwp, int maximized)
65
66 {
67 int *parts;
68 RECT rect;
69 int borders[3];
70
71 /* retrieve status bar size */
72 SendMessage (gwp->statusbarHWnd, SB_GETBORDERS, (WPARAM)0, (LPARAM)&borders);
73 GetClientRect (gwp->statusbarHWnd, &rect);
74 if (!maximized)
75 rect.right -= GetSystemMetrics (SM_CXVSCROLL);
76
77 /* set the parts */
78 parts = (int *)LocalAlloc (LPTR, sizeof (int) * 7);
79 parts[6] = rect.right - borders[2];
80 parts[5] = parts[6] - size_time - borders[2];
81 parts[4] = parts[5] - size_cap - borders[2];
82 parts[3] = parts[4] - size_num - borders[2];
83 parts[2] = parts[3] - size_mode - borders[2];
84 parts[1] = parts[2] - size_changed - borders[2];
85 parts[0] = parts[1] - size_pos - borders[2];
86 SendMessage (gwp->statusbarHWnd, SB_SETPARTS, (WPARAM)7, (LPARAM)parts);
87 LocalFree (parts);
88 SendMessage (gwp->statusbarHWnd, SB_SETTEXT, (WPARAM)SBT_NOBORDERS, (LPARAM)0);
89
90 /* update time */
91 gw_status_upd_time (gwp->statusbarHWnd);
92
93 /* update key indicators */
94 gw_upd_status_bar_ind (gwp, GetKeyState (VK_NUMLOCK) & 1,
95 GetKeyState (VK_CAPITAL) & 1);
96 }
97
98 /* --------------------------------------------------------------------
99 **
100 ** gw_status_timer_proc -- timer processing.
101 */
102
103 static void CALLBACK gw_status_timer_proc (HWND hwnd, UINT uMsg,
104 UINT idEvent, DWORD dwTime)
105
106 {
107 /* update time */
108 gw_status_upd_time (hwnd);
109 }
110
111 /* --------------------------------------------------------------------
112 **
113 ** gw_create_status_bar -- create a new status bar.
114 */
115
116 void gw_create_status_bar (GUI_WINDOW *gwp)
117
118 {
119 HDC dc;
120 SIZE size;
121
122 /* check that we can do it. */
123 if (!o_statusbar (gwp))
124 return;
125 if (gwp->statusbarHWnd != NULL)
126 return;
127
128 /* get borders size */
129 cxborder = GetSystemMetrics (SM_CXBORDER);
130 cyborder = GetSystemMetrics (SM_CYBORDER);
131
132 /* create the status bar */
133 gwp->statusbarHWnd = CreateStatusWindow (WS_CHILD | WS_VISIBLE,
134 NULL,
135 gwp->frameHWnd,
136 1);
137
138 /* get text extents for the various parts */
139 dc = GetDC (gwp->statusbarHWnd);
140 GetTextExtentPoint32 (dc, " 0000000 ", 9, &size);
141 size_pos = size.cx;
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
142 GetTextExtentPoint32 (dc, "MOD", 3, &size);
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
143 size_changed = size.cx;
144 GetTextExtentPoint32 (dc, " Command ", 9, &size);
145 size_mode = size.cx;
146 GetTextExtentPoint32 (dc, " CAPS ", 6, &size);
147 size_cap = size.cx;
148 GetTextExtentPoint32 (dc, " NUM ", 5, &size);
149 size_num = size.cx;
150 GetTextExtentPoint32 (dc, " 00:00PM ", 9, &size);
151 size_time = size.cx;
152 ReleaseDC (gwp->statusbarHWnd, dc);
153
154 /* set the panes positions */
155 gw_set_panes (gwp, 0);
156
157 /* start the timer */
158 SetTimer (gwp->statusbarHWnd, 1, 5000, (TIMERPROC)gw_status_timer_proc);
159 }
160
161 /* --------------------------------------------------------------------
162 **
163 ** gw_destroy_status_bar -- destroy the status bar.
164 */
165
166 extern void gw_destroy_status_bar (GUI_WINDOW *gwp)
167
168 {
169 /* check that we can do it. */
170 if (gwp->statusbarHWnd == NULL)
171 return;
172
173 /* kill the timer */
174 KillTimer (gwp->statusbarHWnd, 1);
175
176 /* destroy the window */
177 DestroyWindow (gwp->statusbarHWnd);
178 gwp->statusbarHWnd = NULL;
179 }
180
181 /* --------------------------------------------------------------------
182 **
183 ** gw_size_status_bar -- resize the status bar.
184 */
185
186 int gw_size_status_bar (GUI_WINDOW *gwp, RECT *parentRect, int maximized)
187
188 {
189 RECT rect;
190
191 /* check that we can do it. */
192 if (gwp->statusbarHWnd == NULL)
193 return 1;
194
195 /* resize the status bar */
196 GetClientRect (gwp->statusbarHWnd, &rect);
197 SetWindowPos (gwp->statusbarHWnd, NULL, parentRect->left + cxborder,
198 parentRect->bottom - rect.bottom - 2 * cyborder,
199 parentRect->right - parentRect->left - 2 * cxborder,
200 rect.bottom, SWP_NOZORDER);
201
202 /* set the panes positions */
203 gw_set_panes (gwp, maximized);
204
205 return rect.bottom + 1;
206 }
207
208 /* --------------------------------------------------------------------
209 **
210 ** gw_upd_status_bar -- update status bar panes.
211 */
212
213 void gw_upd_status_bar (GUI_WINDOW *gwp, Char *cmd, long row, long col, char learn, char *mode)
214
215 {
216 char tmp[20];
217
218 /* check that we can do it. */
219 if (gwp->statusbarHWnd == NULL)
220 return;
221
222 SendMessage (gwp->statusbarHWnd, SB_SETTEXT, (WPARAM)SBT_NOBORDERS, (LPARAM)cmd);
223 sprintf (tmp, "%ld,%ld", row, col);
224 SendMessage (gwp->statusbarHWnd, SB_SETTEXT, (WPARAM)SB_PART_POS, (LPARAM)&tmp);
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
225 switch (learn)
226 {
227 case ',': strcpy(tmp, " "); break;
228 case '*': strcpy(tmp, "MOD"); break;
229 default: sprintf(tmp, " %c ", learn);
230 }
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
231 SendMessage (gwp->statusbarHWnd, SB_SETTEXT, (WPARAM)SB_PART_CHANGED, (LPARAM)&tmp);
232 SendMessage (gwp->statusbarHWnd, SB_SETTEXT, (WPARAM)SB_PART_MODE, (LPARAM)mode);
233 }
234
235 /* --------------------------------------------------------------------
236 **
237 ** gw_upd_status_bar_ind -- update key indicators.
238 */
239
240 void gw_upd_status_bar_ind (GUI_WINDOW *gwp, int num_state, int cap_state)
241
242 {
243 /* check that we can do it. */
244 if (gwp->statusbarHWnd == NULL)
245 return;
246
247 SendMessage (gwp->statusbarHWnd, SB_SETTEXT, (WPARAM)SB_PART_NUM,
248 (LPARAM)(num_state ? "NUM" : NULL));
249 SendMessage (gwp->statusbarHWnd, SB_SETTEXT, (WPARAM)SB_PART_CAP,
250 (LPARAM)(cap_state ? "CAPS" : NULL));
251 }
252
253 /* --------------------------------------------------------------------
254 **
255 ** gw_status_bar_text -- display text on 1st pane.
256 */
257
258 void gw_status_bar_text (GUI_WINDOW *gwp, char *str)
259
260 {
261 /* check that we can do it. */
262 if (gwp->statusbarHWnd == NULL)
263 return;
264
265 SendMessage (gwp->statusbarHWnd, SB_SETTEXT, (WPARAM)SBT_NOBORDERS, (LPARAM)str);
266 }
267
268 #endif
3a9bb55 @mbert Import Elvis 2.1_3 (written by Steve Kirkendall)
authored
269 /* ex:se ts=4 sw=4: */
Something went wrong with that request. Please try again.