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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
/****************************************************************************/
/* */
/* Microsoft Confidential */
/* */
/* Copyright (c) Microsoft Corp. 1987, 1990 */
/* All Rights Reserved */
/* */
/****************************************************************************/
/****************************** Module Header *******************************
* Module Name: toolbox.c
*
* Contains routines that handle the toolbox.
*
* History:
*
* 04/30/91 - Byron Dazey: Copied from DlgEdit.
*
****************************************************************************/
#include "imagedit.h"
#include "dialogs.h"
#define TOOLBOXCOLUMNS 2 // Columns in the Toolbox.
/*
* Style of the toolbox window.
*/
#define TOOLBOXSTYLE (WS_POPUP | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU)
STATICFN VOID NEAR ToolboxDrawBitmap(HDC hDC, INT tool);
/*
* Dimensions of a tool button bitmap.
*/
static INT cxToolBtn;
static INT cyToolBtn;
/*
* Index to the last available tool. If tools at the end of the
* toolbox are disabled, this number gets lowered.
*/
static INT iToolLast = CTOOLS - 1;
/****************************************************************************
* ToolboxCreate
*
* This function creates the toolbox window.
*
* History:
*
****************************************************************************/
VOID ToolboxCreate(VOID)
{
BITMAP bmp;
INT i;
INT x;
INT y;
INT cx;
INT cy;
INT cxDummy;
INT cyDummy;
RECT rc;
RECT rcClient;
POINT pt;
BOOL fMaximized;
/*
* Load the bitmaps.
*/
for (i = 0; i < CTOOLS; i++) {
if (!(gaTools[i].hbmToolBtnUp = LoadBitmap(ghInst,
MAKEINTRESOURCE(gaTools[i].idbmToolBtnUp))))
return;
if (!(gaTools[i].hbmToolBtnDown = LoadBitmap(ghInst,
MAKEINTRESOURCE(gaTools[i].idbmToolBtnDown))))
return;
}
/*
* Get the dimensions of the tool button bitmaps.
*/
GetObject(gaTools[0].hbmToolBtnUp, sizeof(BITMAP), (PSTR)&bmp);
cxToolBtn = bmp.bmWidth;
cyToolBtn = bmp.bmHeight;
/*
* Calculate the required window size for the client area
* size we want. The size leaves room for a margin, and
* assumes that adjacent buttons overlap their borders by
* one pixel.
*/
rc.left = 0;
rc.top = 0;
rc.right = PALETTEMARGIN + ((cxToolBtn - 1) * 2) + 1 + PALETTEMARGIN;
rc.bottom = PALETTEMARGIN + ((cyToolBtn - 1) *
(CTOOLS / 2)) + 1 + PALETTEMARGIN;
AdjustWindowRect(&rc, TOOLBOXSTYLE, FALSE);
cx = rc.right - rc.left;
cy = rc.bottom - rc.top;
/*
* Get the saved position of the Toolbox. Note that we throw away
* the size fields, because we just calculated the required size.
*/
if (!ReadWindowPos(szTBPos, &x, &y, &cxDummy, &cyDummy, &fMaximized)) {
/*
* The previous position of the Toolbox couldn't be found.
* Position the toolbox to the upper right corner of the
* client area of the editor, but make sure it is completely
* visible.
*/
GetClientRect(ghwndMain, &rcClient);
pt.x = rcClient.right - cx - (2 * PALETTEMARGIN);
pt.y = rcClient.top + gcyPropBar + (2 * PALETTEMARGIN);
ClientToScreen(ghwndMain, &pt);
SetRect(&rc, pt.x, pt.y, pt.x + cx, pt.y + cy);
FitRectToScreen(&rc);
x = rc.left;
y = rc.top;
}
if (!(ghwndToolbox = CreateWindow(szToolboxClass, NULL, TOOLBOXSTYLE,
x, y, cx, cy, ghwndMain, NULL, ghInst, NULL)))
return;
/*
* Create the buttons.
*/
x = PALETTEMARGIN;
y = PALETTEMARGIN;
for (i = 0; i < CTOOLS; i++) {
CreateWindow(szToolBtnClass, NULL,
WS_CHILD | WS_VISIBLE,
x, y, cxToolBtn, cyToolBtn,
ghwndToolbox, (HMENU)i, ghInst, NULL);
if (x == PALETTEMARGIN) {
x += cxToolBtn - 1;
}
else {
x = PALETTEMARGIN;
y += cyToolBtn - 1;
}
}
ToolboxUpdate();
}
/****************************************************************************
* ToolboxShow
*
* This function shows or hides the toolbox window.
*
* History:
*
****************************************************************************/
VOID ToolboxShow(
BOOL fShow)
{
if (fShow)
ShowWindow(ghwndToolbox, SW_SHOWNA);
else
ShowWindow(ghwndToolbox, SW_HIDE);
}
/****************************************************************************
* ToolboxUpdate
*
* This function updates the toolbox. It should be called any time that
* a new file is opened/created for editing.
*
* History:
*
****************************************************************************/
VOID ToolboxUpdate(VOID)
{
if (!ghwndToolbox)
return;
if (giType == FT_CURSOR) {
ShowWindow(GetDlgItem(ghwndToolbox, TOOL_HOTSPOT), SW_SHOWNA);
iToolLast = CTOOLS - 1;
}
else {
ShowWindow(GetDlgItem(ghwndToolbox, TOOL_HOTSPOT), SW_HIDE);
iToolLast = TOOL_HOTSPOT - 1;
if (gCurTool == TOOL_HOTSPOT)
ToolboxSelectTool(TOOL_FIRST);
}
}
/****************************************************************************
* ToolboxWndProc
*
* This is the window procedure for the toolbox window.
*
* History:
*
****************************************************************************/
WINDOWPROC ToolboxWndProc(
HWND hwnd,
UINT msg,
WPARAM wParam,
LONG lParam)
{
switch (msg) {
case WM_CREATE:
{
HMENU hmenu = GetSystemMenu(hwnd, FALSE);
RemoveMenu(hmenu, 7, MF_BYPOSITION); // Second separator.
RemoveMenu(hmenu, 5, MF_BYPOSITION); // First separator.
RemoveMenu(hmenu, SC_RESTORE, MF_BYCOMMAND);
RemoveMenu(hmenu, SC_SIZE, MF_BYCOMMAND);
RemoveMenu(hmenu, SC_MINIMIZE, MF_BYCOMMAND);
RemoveMenu(hmenu, SC_MAXIMIZE, MF_BYCOMMAND);
RemoveMenu(hmenu, SC_TASKLIST, MF_BYCOMMAND);
}
return 0;
case WM_KEYDOWN:
{
INT iToolNext;
switch (wParam) {
case VK_UP:
if ((GetKeyState(VK_SHIFT) & 0x8000) ||
(GetKeyState(VK_CONTROL) & 0x8000))
break;
/*
* Go up a row, but don't go beyond the top.
*/
iToolNext = gCurTool - TOOLBOXCOLUMNS;
if (iToolNext < 0)
break;
ToolboxSelectTool(iToolNext);
break;
case VK_DOWN:
if ((GetKeyState(VK_SHIFT) & 0x8000) ||
(GetKeyState(VK_CONTROL) & 0x8000))
break;
/*
* Go down a row, but don't go beyond the bottom.
*/
iToolNext = gCurTool + TOOLBOXCOLUMNS;
if (iToolNext > iToolLast)
break;
ToolboxSelectTool(iToolNext);
break;
case VK_LEFT:
if ((GetKeyState(VK_SHIFT) & 0x8000) ||
(GetKeyState(VK_CONTROL) & 0x8000))
break;
/*
* Already at left edge.
*/
if (!(gCurTool % TOOLBOXCOLUMNS))
break;
/*
* Go left a column.
*/
ToolboxSelectTool(gCurTool - 1);
break;
case VK_RIGHT:
if ((GetKeyState(VK_SHIFT) & 0x8000) ||
(GetKeyState(VK_CONTROL) & 0x8000))
break;
/*
* Already at right edge.
*/
if ((gCurTool % TOOLBOXCOLUMNS) == TOOLBOXCOLUMNS - 1)
break;
/*
* Don't go off the end of the available tools.
*/
if (gCurTool + 1 > iToolLast)
break;
/*
* Go right a column.
*/
ToolboxSelectTool(gCurTool + 1);
break;
case VK_TAB:
if (GetKeyState(VK_CONTROL) & 0x8000)
break;
/*
* Is the shift key pressed also?
*/
if (GetKeyState(VK_SHIFT) & 0x8000) {
if (gCurTool == TOOL_FIRST)
iToolNext = iToolLast;
else
iToolNext = gCurTool - 1;
}
else {
if (gCurTool == iToolLast)
iToolNext = TOOL_FIRST;
else
iToolNext = gCurTool + 1;
}
ToolboxSelectTool(iToolNext);
break;
case VK_END:
if ((GetKeyState(VK_SHIFT) & 0x8000) ||
(GetKeyState(VK_CONTROL) & 0x8000))
break;
ToolboxSelectTool(iToolLast);
break;
case VK_HOME:
case VK_ESCAPE:
if ((GetKeyState(VK_SHIFT) & 0x8000) ||
(GetKeyState(VK_CONTROL) & 0x8000))
break;
ToolboxSelectTool(TOOL_FIRST);
break;
}
}
break;
case WM_ACTIVATE:
if (GET_WM_ACTIVATE_STATE(wParam, lParam))
gidCurrentDlg = DID_TOOLBOX;
break;
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd, &ps);
DrawMarginBorder(hwnd, hdc);
EndPaint(hwnd, &ps);
}
break;
case WM_CLOSE:
/*
* The user closed the toolbox from the system menu.
* Hide the toolbox (we don't actually destroy it so
* that it will appear in the same spot when they show
* it again).
*/
ToolboxShow(FALSE);
gfShowToolbox = FALSE;
break;
case WM_DESTROY:
{
INT i;
RECT rc;
for (i = 0; i < CTOOLS; i++) {
DeleteObject(gaTools[i].hbmToolBtnUp);
gaTools[i].hbmToolBtnUp = NULL;
DeleteObject(gaTools[i].hbmToolBtnDown);
gaTools[i].hbmToolBtnDown = NULL;
}
/*
* Save the position of the toolbox.
*/
GetWindowRect(hwnd, &rc);
WriteWindowPos(&rc, FALSE, szTBPos);
/*
* Null out the global window handle for the toolbox
* for safety's sake.
*/
ghwndToolbox = NULL;
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
/****************************************************************************
* ToolBtnWndProc
*
* This is the window procedure for the buttons in the toolbox window.
*
* History:
*
****************************************************************************/
WINDOWPROC ToolBtnWndProc(
HWND hwnd,
UINT msg,
WPARAM wParam,
LONG lParam)
{
switch (msg) {
case WM_LBUTTONDOWN:
/*
* Select the tool that was clicked on.
*/
ToolboxSelectTool(GETWINDOWID(hwnd));
break;
case WM_PAINT:
{
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hwnd, &ps);
ToolboxDrawBitmap(hDC, GETWINDOWID(hwnd));
EndPaint(hwnd, &ps);
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
/****************************************************************************
* ToolboxDrawBitmap
*
*
* History:
*
****************************************************************************/
STATICFN VOID NEAR ToolboxDrawBitmap(
HDC hDC,
INT tool)
{
HDC hMemDC;
HBITMAP hbmOld;
/*
* Draw the image.
*/
hMemDC = CreateCompatibleDC(hDC);
hbmOld = SelectObject(hMemDC, (tool == gCurTool) ?
gaTools[tool].hbmToolBtnDown : gaTools[tool].hbmToolBtnUp);
BitBlt(hDC, 0, 0, cxToolBtn, cyToolBtn, hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hbmOld);
DeleteDC(hMemDC);
}
/****************************************************************************
* ToolboxSelectTool
*
*
* History:
*
****************************************************************************/
VOID ToolboxSelectTool(
INT tool)
{
if (gCurTool != tool) {
if (ghwndToolbox) {
InvalidateRect(GetDlgItem(ghwndToolbox, gCurTool), NULL, FALSE);
InvalidateRect(GetDlgItem(ghwndToolbox, tool), NULL, FALSE);
}
gCurTool = tool;
gpfnDrawProc = gaTools[gCurTool].pfnDrawProc;
}
}
|