~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Sketcher/App/sketchflat/FCsimple.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//-----------------------------------------------------------------------------
 
2
// Copyright 2008 Jonathan Westhues
 
3
//
 
4
// This file is part of SketchFlat.
 
5
// 
 
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.
 
10
// 
 
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.
 
15
// 
 
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/>.
 
18
//------
 
19
//
 
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.
 
23
//
 
24
// This is partially swiped from the simpldialog stuff in LDmicro.
 
25
//
 
26
// Jonathan Westhues, May 2007
 
27
//-----------------------------------------------------------------------------
 
28
#include "PreCompiled.h"
 
29
#ifndef _PreComp_
 
30
#endif
 
31
 
 
32
 
 
33
#include "sketchflat.h"
 
34
 
 
35
/*
 
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;
 
42
 
 
43
// Our dialog, and controls in our dialog.
 
44
static HWND SimpleDialog;
 
45
static HWND OkButton;
 
46
static HWND CancelButton;
 
47
 
 
48
#define MAX_BOXES 10
 
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];
 
53
 
 
54
static BOOL DialogDone;
 
55
static BOOL DialogCancel;
 
56
*/
 
57
 
 
58
//-----------------------------------------------------------------------------
 
59
// Don't allow any characters other than -0-9. in the box.
 
60
//-----------------------------------------------------------------------------
 
61
/*
 
62
static LRESULT CALLBACK MyNumOnlyProc(HWND hwnd, UINT msg, WPARAM wParam,
 
63
    LPARAM lParam)
 
64
{
 
65
    //if(msg == WM_CHAR) {
 
66
    //    if(!(isdigit(wParam) || wParam == '.' || wParam == '\b' 
 
67
    //        || wParam == '-'))
 
68
    //    {
 
69
    //        return 0;
 
70
    //    }
 
71
    //}
 
72
 
 
73
    //int i;
 
74
    //for(i = 0; i < MAX_BOXES; i++) {
 
75
    //    if(hwnd == Textboxes[i]) {
 
76
    //        return CallWindowProc((WNDPROC)PrevNumOnlyProc[i], hwnd, msg, 
 
77
    //            wParam, lParam);
 
78
    //    }
 
79
    //}
 
80
    //oops();
 
81
        return 0;
 
82
}
 
83
*/
 
84
/*
 
85
static void MakeControls(int boxes, char **labels, DWORD numMask)
 
86
{
 
87
    //int i, j;
 
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]);
 
94
 
 
95
    //    if(numMask & (1 << i)) {
 
96
    //        Textboxes[i] = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "",
 
97
    //            WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS |
 
98
    //            WS_VISIBLE,
 
99
    //            90, 12 + 30*i, 170, 21,
 
100
    //            SimpleDialog, NULL, Instance, NULL);
 
101
    //    } else {
 
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]);
 
108
 
 
109
    //        for(j = 0; j < DL->polys; j++) {
 
110
    //            SendMessage(Lists[i], CB_ADDSTRING, 0, 
 
111
    //                            (LPARAM)DL->poly[j].displayName);
 
112
    //        }
 
113
    //    }
 
114
 
 
115
    //    NiceFont(Textboxes[i]);
 
116
    //}
 
117
 
 
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);
 
122
 
 
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);
 
127
}
 
128
*/
 
129
//-----------------------------------------------------------------------------
 
130
// Window proc for the dialog boxes. Handles Ok/Cancel stuff.
 
131
//-----------------------------------------------------------------------------
 
132
/*
 
133
static LRESULT CALLBACK SimpleProc(HWND hwnd, UINT msg, WPARAM wParam,
 
134
    LPARAM lParam)
 
135
{
 
136
   switch (msg) {
 
137
        case WM_NOTIFY:
 
138
            break;
 
139
 
 
140
        case WM_COMMAND: {
 
141
            HWND h = (HWND)lParam;
 
142
            if(h == OkButton && wParam == BN_CLICKED) {
 
143
                DialogDone = TRUE;
 
144
            } else if(h == CancelButton && wParam == BN_CLICKED) {
 
145
                DialogDone = TRUE;
 
146
                DialogCancel = TRUE;
 
147
            }
 
148
            break;
 
149
        }
 
150
 
 
151
        case WM_CLOSE:
 
152
        case WM_DESTROY:
 
153
            DialogDone = TRUE;
 
154
            DialogCancel = TRUE;
 
155
            break;
 
156
 
 
157
        default:
 
158
            return DefWindowProc(hwnd, msg, wParam, lParam);
 
159
    }
 
160
 
 
161
    return 1;
 
162
}
 
163
*/
 
164
static void MakeSimpleWindowClass(void)
 
165
{
 
166
    //WNDCLASSEX wc;
 
167
    //memset(&wc, 0, sizeof(wc));
 
168
    //wc.cbSize = sizeof(wc);
 
169
 
 
170
    //wc.style            = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC |
 
171
    //                      CS_DBLCLKS;
 
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);
 
182
 
 
183
    //RegisterClassEx(&wc);
 
184
}
 
185
 
 
186
BOOL uiShowSimpleDialog(char *title, int boxes, char **labels,
 
187
    DWORD numMask, hDerived *destH, char **destS)
 
188
{
 
189
    //BOOL didCancel;
 
190
 
 
191
    //if(boxes > MAX_BOXES) oops();
 
192
 
 
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,
 
197
    //    Instance, NULL);
 
198
 
 
199
    //MakeControls(boxes, labels, numMask);
 
200
  
 
201
    //int i;
 
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]);
 
206
 
 
207
    //        PrevNumOnlyProc[i] = SetWindowLongPtr(Textboxes[i], GWLP_WNDPROC, 
 
208
    //            (LONG_PTR)MyNumOnlyProc);
 
209
    //    } else {
 
210
    //        // And the lists are set to whichever polygon we were using 
 
211
    //        // previously.
 
212
    //        int j;
 
213
    //        for(j = 0; j < DL->polys; j++) {
 
214
    //            if(DL->poly[j].id == destH[i]) {
 
215
    //                SendMessage(Lists[i], CB_SETCURSEL, j, 0);
 
216
    //                break;
 
217
    //            }
 
218
    //        }
 
219
    //    }
 
220
    //}
 
221
 
 
222
    //EnableWindow(MainWindow, FALSE);
 
223
    //ShowWindow(SimpleDialog, TRUE);
 
224
 
 
225
    //if(numMask & 1) {
 
226
    //    SetFocus(Textboxes[0]);
 
227
    //    SendMessage(Textboxes[0], EM_SETSEL, 0, -1);
 
228
    //} else {
 
229
    //    SetFocus(Lists[0]);
 
230
    //}
 
231
 
 
232
    //MSG msg;
 
233
    //DWORD ret;
 
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;
 
240
    //            break;
 
241
    //        } else if(msg.wParam == VK_ESCAPE) {
 
242
    //            DialogDone = TRUE;
 
243
    //            DialogCancel = TRUE;
 
244
    //            break;
 
245
    //        }
 
246
    //    }
 
247
 
 
248
    //    if(IsDialogMessage(SimpleDialog, &msg)) continue;
 
249
    //    TranslateMessage(&msg);
 
250
    //    DispatchMessage(&msg);
 
251
    //}
 
252
 
 
253
    //didCancel = DialogCancel;
 
254
 
 
255
    //if(!didCancel) {
 
256
    //    for(i = 0; i < boxes; i++) {
 
257
    //        if(numMask & (1 << i)) {
 
258
    //            SendMessage(Textboxes[i], WM_GETTEXT, 15, (LPARAM)destS[i]);
 
259
    //        } else {
 
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.
 
263
    //                return FALSE;
 
264
    //            }
 
265
    //            destH[i] = DL->poly[p].id;
 
266
    //        }
 
267
    //    }
 
268
    //}
 
269
 
 
270
    //EnableWindow(MainWindow, TRUE);
 
271
    //DestroyWindow(SimpleDialog);
 
272
 
 
273
    //return !didCancel;
 
274
        return false;
 
275
}