1
//-----------------------------------------------------------------------------
2
// Copyright 2008 Jonathan Westhues
4
// This file is part of SketchFlat.
6
// SketchFlat is free software: you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation, either version 3 of the License, or
9
// (at your option) any later version.
11
// SketchFlat is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with SketchFlat. If not, see <http://www.gnu.org/licenses/>.
20
// A dialog box with a combination of textboxes, labels for those textboxes,
21
// and listboxes that can be used to choose an existing derived. We use this
22
// when we're creating all sorts of different derived things.
24
// This is partially swiped from the simpldialog stuff in LDmicro.
26
// Jonathan Westhues, May 2007
27
//-----------------------------------------------------------------------------
28
#include "PreCompiled.h"
33
#include "sketchflat.h"
36
void NiceFont(HWND x);
37
HWND CreateWindowClient(DWORD exStyle, char *className, char *windowName,
38
DWORD style, int x, int y, int width, int height, HWND parent,
39
HMENU menu, HINSTANCE instance, void *param);
40
extern HINSTANCE Instance;
41
extern HWND MainWindow;
43
// Our dialog, and controls in our dialog.
44
static HWND SimpleDialog;
46
static HWND CancelButton;
49
static HWND Textboxes[MAX_BOXES];
50
static HWND Lists[MAX_BOXES];
51
static HWND Labels[MAX_BOXES];
52
static LONG_PTR PrevNumOnlyProc[MAX_BOXES];
54
static BOOL DialogDone;
55
static BOOL DialogCancel;
58
//-----------------------------------------------------------------------------
59
// Don't allow any characters other than -0-9. in the box.
60
//-----------------------------------------------------------------------------
62
static LRESULT CALLBACK MyNumOnlyProc(HWND hwnd, UINT msg, WPARAM wParam,
65
//if(msg == WM_CHAR) {
66
// if(!(isdigit(wParam) || wParam == '.' || wParam == '\b'
74
//for(i = 0; i < MAX_BOXES; i++) {
75
// if(hwnd == Textboxes[i]) {
76
// return CallWindowProc((WNDPROC)PrevNumOnlyProc[i], hwnd, msg,
85
static void MakeControls(int boxes, char **labels, DWORD numMask)
88
//for(i = 0; i < boxes; i++) {
89
// Labels[i] = CreateWindowEx(0, WC_STATIC, labels[i],
90
// WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_RIGHT,
91
// 5, 13 + i*30, 80, 21,
92
// SimpleDialog, NULL, Instance, NULL);
93
// NiceFont(Labels[i]);
95
// if(numMask & (1 << i)) {
96
// Textboxes[i] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "",
97
// WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS |
99
// 90, 12 + 30*i, 170, 21,
100
// SimpleDialog, NULL, Instance, NULL);
102
// Lists[i] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_COMBOBOX, "",
103
// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE |
104
// CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL,
105
// 90, 10 + 30*i, 170, 200,
106
// SimpleDialog, NULL, Instance, NULL);
107
// NiceFont(Lists[i]);
109
// for(j = 0; j < DL->polys; j++) {
110
// SendMessage(Lists[i], CB_ADDSTRING, 0,
111
// (LPARAM)DL->poly[j].displayName);
115
// NiceFont(Textboxes[i]);
118
//OkButton = CreateWindowEx(0, WC_BUTTON, "OK",
119
// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON,
120
// 268, 11, 70, 23, SimpleDialog, NULL, Instance, NULL);
121
//NiceFont(OkButton);
123
//CancelButton = CreateWindowEx(0, WC_BUTTON, "Cancel",
124
// WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE,
125
// 268, 41, 70, 23, SimpleDialog, NULL, Instance, NULL);
126
//NiceFont(CancelButton);
129
//-----------------------------------------------------------------------------
130
// Window proc for the dialog boxes. Handles Ok/Cancel stuff.
131
//-----------------------------------------------------------------------------
133
static LRESULT CALLBACK SimpleProc(HWND hwnd, UINT msg, WPARAM wParam,
141
HWND h = (HWND)lParam;
142
if(h == OkButton && wParam == BN_CLICKED) {
144
} else if(h == CancelButton && wParam == BN_CLICKED) {
158
return DefWindowProc(hwnd, msg, wParam, lParam);
164
static void MakeSimpleWindowClass(void)
167
//memset(&wc, 0, sizeof(wc));
168
//wc.cbSize = sizeof(wc);
170
//wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC |
172
//wc.lpfnWndProc = (WNDPROC)SimpleProc;
173
//wc.hInstance = Instance;
174
//wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
175
//wc.lpszClassName = "SketchFlatDialog";
176
//wc.lpszMenuName = NULL;
177
//wc.hCursor = LoadCursor(NULL, IDC_ARROW);
178
//wc.hIcon = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
179
// IMAGE_ICON, 32, 32, 0);
180
//wc.hIconSm = (HICON)LoadImage(Instance, MAKEINTRESOURCE(4000),
181
// IMAGE_ICON, 16, 16, 0);
183
//RegisterClassEx(&wc);
186
BOOL uiShowSimpleDialog(char *title, int boxes, char **labels,
187
DWORD numMask, hDerived *destH, char **destS)
191
//if(boxes > MAX_BOXES) oops();
193
//MakeSimpleWindowClass();
194
//SimpleDialog = CreateWindowClient(0, "SketchFlatDialog", title,
195
// WS_OVERLAPPED | WS_SYSMENU,
196
// 100, 100, 354, 15 + 30*(boxes < 2 ? 2 : boxes), NULL, NULL,
199
//MakeControls(boxes, labels, numMask);
202
//for(i = 0; i < boxes; i++) {
203
// if(numMask & (1 << i)) {
204
// // Initially, the text box shows whatever was in the string.
205
// SendMessage(Textboxes[i], WM_SETTEXT, 0, (LPARAM)destS[i]);
207
// PrevNumOnlyProc[i] = SetWindowLongPtr(Textboxes[i], GWLP_WNDPROC,
208
// (LONG_PTR)MyNumOnlyProc);
210
// // And the lists are set to whichever polygon we were using
213
// for(j = 0; j < DL->polys; j++) {
214
// if(DL->poly[j].id == destH[i]) {
215
// SendMessage(Lists[i], CB_SETCURSEL, j, 0);
222
//EnableWindow(MainWindow, FALSE);
223
//ShowWindow(SimpleDialog, TRUE);
226
// SetFocus(Textboxes[0]);
227
// SendMessage(Textboxes[0], EM_SETSEL, 0, -1);
229
// SetFocus(Lists[0]);
234
//DialogDone = FALSE;
235
//DialogCancel = FALSE;
236
//while((ret = GetMessage(&msg, NULL, 0, 0)) && !DialogDone) {
237
// if(msg.message == WM_KEYDOWN) {
238
// if(msg.wParam == VK_RETURN) {
239
// DialogDone = TRUE;
241
// } else if(msg.wParam == VK_ESCAPE) {
242
// DialogDone = TRUE;
243
// DialogCancel = TRUE;
248
// if(IsDialogMessage(SimpleDialog, &msg)) continue;
249
// TranslateMessage(&msg);
250
// DispatchMessage(&msg);
253
//didCancel = DialogCancel;
256
// for(i = 0; i < boxes; i++) {
257
// if(numMask & (1 << i)) {
258
// SendMessage(Textboxes[i], WM_GETTEXT, 15, (LPARAM)destS[i]);
260
// int p = SendMessage(Lists[i], CB_GETCURSEL, 0, 0);
261
// if(p < 0 || p >= DL->polys) {
262
// // That's like cancelling; shouldn't be possible anyways.
265
// destH[i] = DL->poly[p].id;
270
//EnableWindow(MainWindow, TRUE);
271
//DestroyWindow(SimpleDialog);