-
Notifications
You must be signed in to change notification settings - Fork 2
/
help.c
235 lines (202 loc) · 6.68 KB
/
help.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
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
#include "htmlbrowser.h"
#include "stdafx.h"
#include "LoftyCAD.h"
#include <CommCtrl.h>
#include <CommDlg.h>
#include <stdio.h>
// Directory containing help pages
char help_dir[256];
// These are indexed by the app state (LoftyCAD.h) and must agree.
char *state_key[STATE_MAX] =
{
"Exploring",
"Moving",
"Dragging_Selection",
"Drawing_Edge",
"Drawing_Face",
"Drawing_Face",
"Drawing_Face",
"Drawing_Edge",
"Drawing_Edge",
"Drawing_Face",
"Drawing_Face",
"Drawing_Extrude",
"Drawing_Text",
"Drawing_Extrude",
"Drawing_Scale",
"Drawing_Rotate",
"Drawing_Edge",
"Drawing_Face",
"Drawing_Face",
"Drawing_Face",
"Drawing_Edge",
"Drawing_Edge",
"Drawing_Face",
"Drawing_Face",
"Drawing_Extrude",
"Drawing_Text",
"Drawing_Extrude",
"Drawing_Scale",
"Drawing_Rotate"
};
// These are indexed by the app state (LoftyCAD.h) and must agree.
struct
{
HINSTANCE instance;
LPSTR idc;
HCURSOR cursor;
} cursors[STATE_MAX] =
{
{ NULL, IDC_ARROW, NULL },
{ NULL, IDC_ARROW, NULL },
{ NULL, IDC_ARROW, NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_EDGE1), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE1), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE6), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE2), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_EDGE3), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_EDGE2), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE1), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE2), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE3), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE4), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE5), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_RESIZE1), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_RESIZE2), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_EDGE1), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE1), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE6), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE2), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_EDGE3), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_EDGE2), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE1), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE2), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE3), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE4), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_FACE5), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_RESIZE1), NULL },
{ (HINSTANCE)1, MAKEINTRESOURCE(IDC_RESIZE2), NULL },
};
HWND init_help_window(void)
{
HWND hWnd;
int i;
char *slosh;
// Initialise OLE and help dialog.
OleInitialize(NULL);
hWnd = CreateDialog
(
hInst,
MAKEINTRESOURCE(IDD_HELP),
auxGetHWND(),
help_dialog
);
SetWindowPos(hWnd, HWND_NOTOPMOST, wWidth, toolbar_bottom, 0, 0, SWP_NOSIZE);
if (view_help)
ShowWindow(hWnd, SW_SHOW);
// Some checks that really should be done at compile time, but C doesn't let us.
// Do after the help window comes up.
ASSERT(sizeof(state_key) / sizeof(state_key[0]) == STATE_MAX, "Key array doesn't line up with states");
ASSERT(sizeof(cursors) / sizeof(cursors[0]) == STATE_MAX, "Cursor array doesn't line up with states");
ASSERT(STATE_DRAWING_OFFSET == STATE_DRAWING_OFFSET2, "Drawing states don't match starting states");
// Load the cursors (both homemade and system-supplied ones)
for (i = 0; i < STATE_MAX; i++)
{
if (cursors[i].instance != NULL)
cursors[i].instance = hInst;
cursors[i].cursor = LoadCursor(cursors[i].instance, (LPCTSTR)cursors[i].idc);
}
// Find the directory containing the help files
GetModuleFileName(NULL, help_dir, 256);
slosh = strrchr(help_dir, '\\');
if (slosh != NULL)
*slosh = '\0';
// If we're running from a Debug directory, go up one level
if (_stricmp(slosh - 6, "\\Debug") == 0)
*(slosh - 6) = '\0';
strcat_s(help_dir, 256, "\\html\\");
return hWnd;
}
// Show the help window if it currently isn't shown.
void
display_help_window()
{
HMENU hMenu;
if (!view_help)
{
ShowWindow(hWndHelp, SW_SHOW);
view_help = TRUE;
hMenu = GetSubMenu(GetMenu(auxGetHWND()), 2);
CheckMenuItem(hMenu, ID_VIEW_HELP, MF_CHECKED);
}
}
// Display text or an HTML page in the help window relevant to the current action.
void
display_help(char *key)
{
char fname[256];
strcpy_s(fname, 256, help_dir);
strcat_s(fname, 256, key);
strcat_s(fname, 256, ".htm");
DisplayHTMLPage(hWndHelp, fname);
}
void
display_help_state(STATE state)
{
display_help(state_key[app_state]);
}
// Change app state, displaying any help for the new state. Clear any error messages.
void
change_state(STATE new_state)
{
app_state = new_state;
display_help_state(app_state);
clear_status_and_progress();
}
// Display the cursor for the new state
void
display_cursor(STATE new_state)
{
SetCursor(cursors[new_state].cursor);
}
// Wndproc for help dialog. Comments from the original code (see htmlbrowser.[ch])
int WINAPI
help_dialog(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu;
switch (msg)
{
case WM_INITDIALOG:
// Embed the browser object into our host window. We need do this only
// once. Note that the browser object will start calling some of our
// IOleInPlaceFrame and IOleClientSite functions as soon as we start
// calling browser object functions in EmbedBrowserObject().
if (EmbedBrowserObject(hWnd))
return(-1);
// Another window created with an embedded browser object
++WindowCount;
break;
case WM_DESTROY:
// Detach the browser object from this window, and free resources.
UnEmbedBrowserObject(hWnd);
// One less window
if (--WindowCount == 0)
OleUninitialize();
break;
case WM_CLOSE:
// Closing just hides the window, it can be brought back (like the other toolbars)
view_help = FALSE;
ShowWindow(hWnd, SW_HIDE);
hMenu = GetSubMenu(GetMenu(auxGetHWND()), 2);
CheckMenuItem(hMenu, ID_VIEW_HELP, view_help ? MF_CHECKED : MF_UNCHECKED);
break;
// NOTE: If you want to resize the area that the browser object occupies when you
// resize the window, then handle WM_SIZE and use the IWebBrowser2's put_Width()
// and put_Height() to give it the new dimensions.
// TODO: This doesn't seem to work at all. Why?
case WM_SIZE:
SetBrowserSize(hWnd, LOWORD(lParam), HIWORD(lParam));
break;
}
return 0;
}