1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | /*---------------------------------------
|
---|
39 | POPPAD.C -- Popup Editor
|
---|
40 | (c) Charles Petzold, 1992
|
---|
41 | ---------------------------------------*/
|
---|
42 |
|
---|
43 | #include "nspr.h"
|
---|
44 | #include "plevent.h"
|
---|
45 | #include <windows.h>
|
---|
46 | #include <commdlg.h>
|
---|
47 | #include <stdlib.h>
|
---|
48 | #include "poppad.h"
|
---|
49 | #include <time.h>
|
---|
50 |
|
---|
51 | #define EDITID 1
|
---|
52 | #define UNTITLED "(untitled)"
|
---|
53 |
|
---|
54 | long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG) ;
|
---|
55 | BOOL FAR PASCAL _export AboutDlgProc (HWND, UINT, UINT, LONG) ;
|
---|
56 |
|
---|
57 | /* Declarations for NSPR customization
|
---|
58 | **
|
---|
59 | */
|
---|
60 | typedef struct PadEvent
|
---|
61 | {
|
---|
62 | PLEvent plEvent;
|
---|
63 | int unused;
|
---|
64 | } PadEvent;
|
---|
65 |
|
---|
66 | static void PR_CALLBACK TimerThread( void *arg);
|
---|
67 | static void PR_CALLBACK HandlePadEvent( PadEvent *padEvent );
|
---|
68 | static void PR_CALLBACK DestroyPadEvent( PadEvent *padevent );
|
---|
69 | static PRThread *tThread;
|
---|
70 | static PLEventQueue *padQueue;
|
---|
71 | static int quitSwitch = 0;
|
---|
72 | static long ThreadSleepTime = 1000;
|
---|
73 | static long timerCount = 0;
|
---|
74 | static char *startMessage = "Poppad: NSPR GUI and event test program.\n"
|
---|
75 | "You should see lines of 50 characters\n"
|
---|
76 | "with a new character appearing at 1 second intervals.\n"
|
---|
77 | "Every 10 seconds gets a '+'; every 5 seconds gets a '_';\n"
|
---|
78 | "every 1 second gets a '.'.\n\n"
|
---|
79 | "You should be able to type in the window.\n\n\n";
|
---|
80 |
|
---|
81 |
|
---|
82 | // Functions in POPFILE.C
|
---|
83 |
|
---|
84 | void PopFileInitialize (HWND) ;
|
---|
85 | BOOL PopFileOpenDlg (HWND, LPSTR, LPSTR) ;
|
---|
86 | BOOL PopFileSaveDlg (HWND, LPSTR, LPSTR) ;
|
---|
87 | BOOL PopFileRead (HWND, LPSTR) ;
|
---|
88 | BOOL PopFileWrite (HWND, LPSTR) ;
|
---|
89 |
|
---|
90 | // Functions in POPFIND.C
|
---|
91 |
|
---|
92 | HWND PopFindFindDlg (HWND) ;
|
---|
93 | HWND PopFindReplaceDlg (HWND) ;
|
---|
94 | BOOL PopFindFindText (HWND, int *, LPFINDREPLACE) ;
|
---|
95 | BOOL PopFindReplaceText (HWND, int *, LPFINDREPLACE) ;
|
---|
96 | BOOL PopFindNextText (HWND, int *) ;
|
---|
97 | BOOL PopFindValidFind (void) ;
|
---|
98 |
|
---|
99 | // Functions in POPFONT.C
|
---|
100 |
|
---|
101 | void PopFontInitialize (HWND) ;
|
---|
102 | BOOL PopFontChooseFont (HWND) ;
|
---|
103 | void PopFontSetFont (HWND) ;
|
---|
104 | void PopFontDeinitialize (void) ;
|
---|
105 |
|
---|
106 | // Functions in POPPRNT.C
|
---|
107 |
|
---|
108 | BOOL PopPrntPrintFile (HANDLE, HWND, HWND, LPSTR) ;
|
---|
109 |
|
---|
110 | // Global variables
|
---|
111 |
|
---|
112 | static char szAppName [] = "PopPad" ;
|
---|
113 | static HWND hDlgModeless ;
|
---|
114 | static HWND hwndEdit ;
|
---|
115 |
|
---|
116 | int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
|
---|
117 | LPSTR lpszCmdLine, int nCmdShow)
|
---|
118 | {
|
---|
119 | MSG msg;
|
---|
120 | HWND hwnd ;
|
---|
121 | HANDLE hAccel ;
|
---|
122 | WNDCLASS wndclass ;
|
---|
123 |
|
---|
124 | PR_STDIO_INIT();
|
---|
125 | PR_Init(0, 0, 0);
|
---|
126 |
|
---|
127 | if (!hPrevInstance)
|
---|
128 | {
|
---|
129 | wndclass.style = CS_HREDRAW | CS_VREDRAW ;
|
---|
130 | wndclass.lpfnWndProc = WndProc ;
|
---|
131 | wndclass.cbClsExtra = 0 ;
|
---|
132 | wndclass.cbWndExtra = 0 ;
|
---|
133 | wndclass.hInstance = hInstance ;
|
---|
134 | wndclass.hIcon = LoadIcon (hInstance, szAppName) ;
|
---|
135 | wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
|
---|
136 | wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
|
---|
137 | wndclass.lpszMenuName = szAppName ;
|
---|
138 | wndclass.lpszClassName = szAppName ;
|
---|
139 |
|
---|
140 | RegisterClass (&wndclass) ;
|
---|
141 | }
|
---|
142 |
|
---|
143 | hwnd = CreateWindow (szAppName, NULL,
|
---|
144 | WS_OVERLAPPEDWINDOW,
|
---|
145 | CW_USEDEFAULT, CW_USEDEFAULT,
|
---|
146 | CW_USEDEFAULT, CW_USEDEFAULT,
|
---|
147 | NULL, NULL, hInstance, lpszCmdLine) ;
|
---|
148 |
|
---|
149 | ShowWindow (hwnd, nCmdShow) ;
|
---|
150 | UpdateWindow (hwnd);
|
---|
151 |
|
---|
152 | hAccel = LoadAccelerators (hInstance, szAppName) ;
|
---|
153 |
|
---|
154 | for(;;)
|
---|
155 | {
|
---|
156 | if ( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ))
|
---|
157 | {
|
---|
158 | if (GetMessage(&msg, NULL, 0, 0))
|
---|
159 | {
|
---|
160 | if (hDlgModeless == NULL || !IsDialogMessage (hDlgModeless, &msg))
|
---|
161 | {
|
---|
162 | if (!TranslateAccelerator (hwnd, hAccel, &msg))
|
---|
163 | {
|
---|
164 | TranslateMessage (&msg) ;
|
---|
165 | DispatchMessage (&msg) ;
|
---|
166 | } /* end if !TranslateAccelerator */
|
---|
167 | }
|
---|
168 | }
|
---|
169 | else
|
---|
170 | {
|
---|
171 | break;
|
---|
172 | } /* end if GetMessage() */
|
---|
173 | }
|
---|
174 | else /* !PeekMessage */
|
---|
175 | {
|
---|
176 | PR_Sleep(50);
|
---|
177 | }/* end if PeekMessage() */
|
---|
178 | } /* end for() */
|
---|
179 |
|
---|
180 | PR_JoinThread( tThread );
|
---|
181 | PL_DestroyEventQueue( padQueue );
|
---|
182 | PR_Cleanup();
|
---|
183 | return msg.wParam ;
|
---|
184 | }
|
---|
185 |
|
---|
186 | void DoCaption (HWND hwnd, char *szTitleName)
|
---|
187 | {
|
---|
188 | char szCaption [64 + _MAX_FNAME + _MAX_EXT] ;
|
---|
189 |
|
---|
190 | wsprintf (szCaption, "%s - %s", (LPSTR) szAppName,
|
---|
191 | (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ;
|
---|
192 |
|
---|
193 | SetWindowText (hwnd, szCaption) ;
|
---|
194 | }
|
---|
195 |
|
---|
196 | void OkMessage (HWND hwnd, char *szMessage, char *szTitleName)
|
---|
197 | {
|
---|
198 | char szBuffer [64 + _MAX_FNAME + _MAX_EXT] ;
|
---|
199 |
|
---|
200 | wsprintf (szBuffer, szMessage,
|
---|
201 | (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ;
|
---|
202 |
|
---|
203 | MessageBox (hwnd, szBuffer, szAppName, MB_OK | MB_ICONEXCLAMATION) ;
|
---|
204 | }
|
---|
205 |
|
---|
206 | short AskAboutSave (HWND hwnd, char *szTitleName)
|
---|
207 | {
|
---|
208 | char szBuffer [64 + _MAX_FNAME + _MAX_EXT] ;
|
---|
209 | short nReturn ;
|
---|
210 |
|
---|
211 | wsprintf (szBuffer, "Save current changes in %s?",
|
---|
212 | (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ;
|
---|
213 |
|
---|
214 | nReturn = MessageBox (hwnd, szBuffer, szAppName,
|
---|
215 | MB_YESNOCANCEL | MB_ICONQUESTION) ;
|
---|
216 |
|
---|
217 | if (nReturn == IDYES)
|
---|
218 | if (!SendMessage (hwnd, WM_COMMAND, IDM_SAVE, 0L))
|
---|
219 | nReturn = IDCANCEL ;
|
---|
220 |
|
---|
221 | return nReturn ;
|
---|
222 | }
|
---|
223 |
|
---|
224 | long FAR PASCAL _export WndProc (HWND hwnd, UINT message, UINT wParam,
|
---|
225 | LONG lParam)
|
---|
226 | {
|
---|
227 | static BOOL bNeedSave = FALSE ;
|
---|
228 | static char szFileName [_MAX_PATH] ;
|
---|
229 | static char szTitleName [_MAX_FNAME + _MAX_EXT] ;
|
---|
230 | static FARPROC lpfnAboutDlgProc ;
|
---|
231 | static HANDLE hInst ;
|
---|
232 | static int iOffset ;
|
---|
233 | static UINT messageFindReplace ;
|
---|
234 | LONG lSelect ;
|
---|
235 | LPFINDREPLACE lpfr ;
|
---|
236 | WORD wEnable ;
|
---|
237 |
|
---|
238 | switch (message)
|
---|
239 | {
|
---|
240 | case WM_CREATE:
|
---|
241 | // Get About dialog instance address
|
---|
242 |
|
---|
243 | hInst = ((LPCREATESTRUCT) lParam)->hInstance ;
|
---|
244 | lpfnAboutDlgProc = MakeProcInstance ((FARPROC) AboutDlgProc,
|
---|
245 | hInst) ;
|
---|
246 |
|
---|
247 | // Create the edit control child window
|
---|
248 |
|
---|
249 | hwndEdit = CreateWindow ("edit", NULL,
|
---|
250 | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
|
---|
251 | WS_BORDER | ES_LEFT | ES_MULTILINE |
|
---|
252 | ES_NOHIDESEL | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
|
---|
253 | 0, 0, 0, 0,
|
---|
254 | hwnd, EDITID, hInst, NULL) ;
|
---|
255 |
|
---|
256 | SendMessage (hwndEdit, EM_LIMITTEXT, 32000, 0L) ;
|
---|
257 |
|
---|
258 | // Initialize common dialog box stuff
|
---|
259 |
|
---|
260 | PopFileInitialize (hwnd) ;
|
---|
261 | PopFontInitialize (hwndEdit) ;
|
---|
262 |
|
---|
263 | messageFindReplace = RegisterWindowMessage (FINDMSGSTRING) ;
|
---|
264 |
|
---|
265 | // Process command line
|
---|
266 |
|
---|
267 | lstrcpy (szFileName, (LPSTR)
|
---|
268 | (((LPCREATESTRUCT) lParam)->lpCreateParams)) ;
|
---|
269 |
|
---|
270 | if (lstrlen (szFileName) > 0)
|
---|
271 | {
|
---|
272 | GetFileTitle (szFileName, szTitleName,
|
---|
273 | sizeof (szTitleName)) ;
|
---|
274 |
|
---|
275 | if (!PopFileRead (hwndEdit, szFileName))
|
---|
276 | OkMessage (hwnd, "File %s cannot be read!",
|
---|
277 | szTitleName) ;
|
---|
278 | }
|
---|
279 |
|
---|
280 | DoCaption (hwnd, szTitleName) ;
|
---|
281 |
|
---|
282 | /* Initialize Event Processing for NSPR
|
---|
283 | ** Retrieve the event queue just created
|
---|
284 | ** Create the TimerThread
|
---|
285 | */
|
---|
286 | PL_InitializeEventsLib("someName");
|
---|
287 | padQueue = PL_GetMainEventQueue();
|
---|
288 | tThread = PR_CreateThread(PR_USER_THREAD,
|
---|
289 | TimerThread,
|
---|
290 | NULL,
|
---|
291 | PR_PRIORITY_NORMAL,
|
---|
292 | PR_LOCAL_THREAD,
|
---|
293 | PR_JOINABLE_THREAD,
|
---|
294 | 0 );
|
---|
295 | return 0 ;
|
---|
296 |
|
---|
297 | case WM_SETFOCUS:
|
---|
298 | SetFocus (hwndEdit) ;
|
---|
299 | return 0 ;
|
---|
300 |
|
---|
301 | case WM_SIZE:
|
---|
302 | MoveWindow (hwndEdit, 0, 0, LOWORD (lParam),
|
---|
303 | HIWORD (lParam), TRUE) ;
|
---|
304 | return 0 ;
|
---|
305 |
|
---|
306 | case WM_INITMENUPOPUP:
|
---|
307 | switch (lParam)
|
---|
308 | {
|
---|
309 | case 1: // Edit menu
|
---|
310 |
|
---|
311 | // Enable Undo if edit control can do it
|
---|
312 |
|
---|
313 | EnableMenuItem (wParam, IDM_UNDO,
|
---|
314 | SendMessage (hwndEdit, EM_CANUNDO, 0, 0L) ?
|
---|
315 | MF_ENABLED : MF_GRAYED) ;
|
---|
316 |
|
---|
317 | // Enable Paste if text is in the clipboard
|
---|
318 |
|
---|
319 | EnableMenuItem (wParam, IDM_PASTE,
|
---|
320 | IsClipboardFormatAvailable (CF_TEXT) ?
|
---|
321 | MF_ENABLED : MF_GRAYED) ;
|
---|
322 |
|
---|
323 | // Enable Cut, Copy, and Del if text is selected
|
---|
324 |
|
---|
325 | lSelect = SendMessage (hwndEdit, EM_GETSEL, 0, 0L) ;
|
---|
326 | wEnable = HIWORD (lSelect) != LOWORD (lSelect) ?
|
---|
327 | MF_ENABLED : MF_GRAYED ;
|
---|
328 |
|
---|
329 | EnableMenuItem (wParam, IDM_CUT, wEnable) ;
|
---|
330 | EnableMenuItem (wParam, IDM_COPY, wEnable) ;
|
---|
331 | EnableMenuItem (wParam, IDM_DEL, wEnable) ;
|
---|
332 | break ;
|
---|
333 |
|
---|
334 | case 2: // Search menu
|
---|
335 |
|
---|
336 | // Enable Find, Next, and Replace if modeless
|
---|
337 | // dialogs are not already active
|
---|
338 |
|
---|
339 | wEnable = hDlgModeless == NULL ?
|
---|
340 | MF_ENABLED : MF_GRAYED ;
|
---|
341 |
|
---|
342 | EnableMenuItem (wParam, IDM_FIND, wEnable) ;
|
---|
343 | EnableMenuItem (wParam, IDM_NEXT, wEnable) ;
|
---|
344 | EnableMenuItem (wParam, IDM_REPLACE, wEnable) ;
|
---|
345 | break ;
|
---|
346 | }
|
---|
347 | return 0 ;
|
---|
348 |
|
---|
349 | case WM_COMMAND :
|
---|
350 | // Messages from edit control
|
---|
351 |
|
---|
352 | if (LOWORD (lParam) && wParam == EDITID)
|
---|
353 | {
|
---|
354 | switch (HIWORD (lParam))
|
---|
355 | {
|
---|
356 | case EN_UPDATE:
|
---|
357 | bNeedSave = TRUE ;
|
---|
358 | return 0 ;
|
---|
359 |
|
---|
360 | case EN_ERRSPACE:
|
---|
361 | case EN_MAXTEXT:
|
---|
362 | MessageBox (hwnd, "Edit control out of space.",
|
---|
363 | szAppName, MB_OK | MB_ICONSTOP) ;
|
---|
364 | return 0 ;
|
---|
365 | }
|
---|
366 | break ;
|
---|
367 | }
|
---|
368 |
|
---|
369 | switch (wParam)
|
---|
370 | {
|
---|
371 | // Messages from File menu
|
---|
372 |
|
---|
373 | case IDM_NEW:
|
---|
374 | if (bNeedSave && IDCANCEL ==
|
---|
375 | AskAboutSave (hwnd, szTitleName))
|
---|
376 | return 0 ;
|
---|
377 |
|
---|
378 | SetWindowText (hwndEdit, "\0") ;
|
---|
379 | szFileName [0] = '\0' ;
|
---|
380 | szTitleName [0] = '\0' ;
|
---|
381 | DoCaption (hwnd, szTitleName) ;
|
---|
382 | bNeedSave = FALSE ;
|
---|
383 | return 0 ;
|
---|
384 |
|
---|
385 | case IDM_OPEN:
|
---|
386 | if (bNeedSave && IDCANCEL ==
|
---|
387 | AskAboutSave (hwnd, szTitleName))
|
---|
388 | return 0 ;
|
---|
389 |
|
---|
390 | if (PopFileOpenDlg (hwnd, szFileName, szTitleName))
|
---|
391 | {
|
---|
392 | if (!PopFileRead (hwndEdit, szFileName))
|
---|
393 | {
|
---|
394 | OkMessage (hwnd, "Could not read file %s!",
|
---|
395 | szTitleName) ;
|
---|
396 | szFileName [0] = '\0' ;
|
---|
397 | szTitleName [0] = '\0' ;
|
---|
398 | }
|
---|
399 | }
|
---|
400 |
|
---|
401 | DoCaption (hwnd, szTitleName) ;
|
---|
402 | bNeedSave = FALSE ;
|
---|
403 | return 0 ;
|
---|
404 |
|
---|
405 | case IDM_SAVE:
|
---|
406 | if (szFileName [0])
|
---|
407 | {
|
---|
408 | if (PopFileWrite (hwndEdit, szFileName))
|
---|
409 | {
|
---|
410 | bNeedSave = FALSE ;
|
---|
411 | return 1 ;
|
---|
412 | }
|
---|
413 | else
|
---|
414 | OkMessage (hwnd, "Could not write file %s",
|
---|
415 | szTitleName) ;
|
---|
416 | return 0 ;
|
---|
417 | }
|
---|
418 | // fall through
|
---|
419 | case IDM_SAVEAS:
|
---|
420 | if (PopFileSaveDlg (hwnd, szFileName, szTitleName))
|
---|
421 | {
|
---|
422 | DoCaption (hwnd, szTitleName) ;
|
---|
423 |
|
---|
424 | if (PopFileWrite (hwndEdit, szFileName))
|
---|
425 | {
|
---|
426 | bNeedSave = FALSE ;
|
---|
427 | return 1 ;
|
---|
428 | }
|
---|
429 | else
|
---|
430 | OkMessage (hwnd, "Could not write file %s",
|
---|
431 | szTitleName) ;
|
---|
432 | }
|
---|
433 | return 0 ;
|
---|
434 |
|
---|
435 | case IDM_PRINT:
|
---|
436 | if (!PopPrntPrintFile (hInst, hwnd, hwndEdit,
|
---|
437 | szTitleName))
|
---|
438 | OkMessage (hwnd, "Could not print file %s",
|
---|
439 | szTitleName) ;
|
---|
440 | return 0 ;
|
---|
441 |
|
---|
442 | case IDM_EXIT:
|
---|
443 | SendMessage (hwnd, WM_CLOSE, 0, 0L) ;
|
---|
444 | return 0 ;
|
---|
445 |
|
---|
446 | // Messages from Edit menu
|
---|
447 |
|
---|
448 | case IDM_UNDO:
|
---|
449 | SendMessage (hwndEdit, WM_UNDO, 0, 0L) ;
|
---|
450 | return 0 ;
|
---|
451 |
|
---|
452 | case IDM_CUT:
|
---|
453 | SendMessage (hwndEdit, WM_CUT, 0, 0L) ;
|
---|
454 | return 0 ;
|
---|
455 |
|
---|
456 | case IDM_COPY:
|
---|
457 | SendMessage (hwndEdit, WM_COPY, 0, 0L) ;
|
---|
458 | return 0 ;
|
---|
459 |
|
---|
460 | case IDM_PASTE:
|
---|
461 | SendMessage (hwndEdit, WM_PASTE, 0, 0L) ;
|
---|
462 | return 0 ;
|
---|
463 |
|
---|
464 | case IDM_DEL:
|
---|
465 | SendMessage (hwndEdit, WM_CLEAR, 0, 0L) ;
|
---|
466 | return 0 ;
|
---|
467 |
|
---|
468 | case IDM_SELALL:
|
---|
469 | SendMessage (hwndEdit, EM_SETSEL, 0,
|
---|
470 | MAKELONG (0, 32767)) ;
|
---|
471 | return 0 ;
|
---|
472 |
|
---|
473 | // Messages from Search menu
|
---|
474 |
|
---|
475 | case IDM_FIND:
|
---|
476 | iOffset = HIWORD (
|
---|
477 | SendMessage (hwndEdit, EM_GETSEL, 0, 0L)) ;
|
---|
478 | hDlgModeless = PopFindFindDlg (hwnd) ;
|
---|
479 | return 0 ;
|
---|
480 |
|
---|
481 | case IDM_NEXT:
|
---|
482 | iOffset = HIWORD (
|
---|
483 | SendMessage (hwndEdit, EM_GETSEL, 0, 0L)) ;
|
---|
484 |
|
---|
485 | if (PopFindValidFind ())
|
---|
486 | PopFindNextText (hwndEdit, &iOffset) ;
|
---|
487 | else
|
---|
488 | hDlgModeless = PopFindFindDlg (hwnd) ;
|
---|
489 |
|
---|
490 | return 0 ;
|
---|
491 |
|
---|
492 | case IDM_REPLACE:
|
---|
493 | iOffset = HIWORD (
|
---|
494 | SendMessage (hwndEdit, EM_GETSEL, 0, 0L)) ;
|
---|
495 |
|
---|
496 | hDlgModeless = PopFindReplaceDlg (hwnd) ;
|
---|
497 | return 0 ;
|
---|
498 |
|
---|
499 | case IDM_FONT:
|
---|
500 | if (PopFontChooseFont (hwnd))
|
---|
501 | PopFontSetFont (hwndEdit) ;
|
---|
502 |
|
---|
503 | return 0 ;
|
---|
504 |
|
---|
505 | // Messages from Help menu
|
---|
506 |
|
---|
507 | case IDM_HELP:
|
---|
508 | OkMessage (hwnd, "Help not yet implemented!", NULL) ;
|
---|
509 | return 0 ;
|
---|
510 |
|
---|
511 | case IDM_ABOUT:
|
---|
512 | DialogBox (hInst, "AboutBox", hwnd, lpfnAboutDlgProc);
|
---|
513 | return 0 ;
|
---|
514 | }
|
---|
515 | break ;
|
---|
516 |
|
---|
517 | case WM_CLOSE:
|
---|
518 | if (!bNeedSave || IDCANCEL != AskAboutSave (hwnd, szTitleName))
|
---|
519 | DestroyWindow (hwnd) ;
|
---|
520 |
|
---|
521 | return 0 ;
|
---|
522 |
|
---|
523 | case WM_QUERYENDSESSION:
|
---|
524 | if (!bNeedSave || IDCANCEL != AskAboutSave (hwnd, szTitleName))
|
---|
525 | return 1L ;
|
---|
526 |
|
---|
527 | return 0 ;
|
---|
528 |
|
---|
529 | case WM_DESTROY:
|
---|
530 | PopFontDeinitialize () ;
|
---|
531 | PostQuitMessage (0) ;
|
---|
532 | quitSwitch = 1;
|
---|
533 | return 0 ;
|
---|
534 |
|
---|
535 | default:
|
---|
536 | // Process "Find-Replace" messages
|
---|
537 |
|
---|
538 | if (message == messageFindReplace)
|
---|
539 | {
|
---|
540 | lpfr = (LPFINDREPLACE) lParam ;
|
---|
541 |
|
---|
542 | if (lpfr->Flags & FR_DIALOGTERM)
|
---|
543 | hDlgModeless = NULL ;
|
---|
544 |
|
---|
545 | if (lpfr->Flags & FR_FINDNEXT)
|
---|
546 | if (!PopFindFindText (hwndEdit, &iOffset, lpfr))
|
---|
547 | OkMessage (hwnd, "Text not found!", NULL) ;
|
---|
548 |
|
---|
549 | if (lpfr->Flags & FR_REPLACE ||
|
---|
550 | lpfr->Flags & FR_REPLACEALL)
|
---|
551 | if (!PopFindReplaceText (hwndEdit, &iOffset, lpfr))
|
---|
552 | OkMessage (hwnd, "Text not found!", NULL) ;
|
---|
553 |
|
---|
554 | if (lpfr->Flags & FR_REPLACEALL)
|
---|
555 | while (PopFindReplaceText (hwndEdit, &iOffset, lpfr));
|
---|
556 |
|
---|
557 | return 0 ;
|
---|
558 | }
|
---|
559 | break ;
|
---|
560 | }
|
---|
561 | return DefWindowProc (hwnd, message, wParam, lParam) ;
|
---|
562 | }
|
---|
563 |
|
---|
564 | BOOL FAR PASCAL _export AboutDlgProc (HWND hDlg, UINT message, UINT wParam,
|
---|
565 | LONG lParam)
|
---|
566 | {
|
---|
567 | switch (message)
|
---|
568 | {
|
---|
569 | case WM_INITDIALOG:
|
---|
570 | return TRUE ;
|
---|
571 |
|
---|
572 | case WM_COMMAND:
|
---|
573 | switch (wParam)
|
---|
574 | {
|
---|
575 | case IDOK:
|
---|
576 | EndDialog (hDlg, 0) ;
|
---|
577 | return TRUE ;
|
---|
578 | }
|
---|
579 | break ;
|
---|
580 | }
|
---|
581 | return FALSE ;
|
---|
582 | }
|
---|
583 | /*
|
---|
584 | ** TimerThread() -- The Main function of the timer pop thread
|
---|
585 | **
|
---|
586 | */
|
---|
587 | static void PR_CALLBACK TimerThread( void *arg)
|
---|
588 | {
|
---|
589 | do {
|
---|
590 | PadEvent *ev;
|
---|
591 |
|
---|
592 | /*
|
---|
593 | ** Should we quit now?
|
---|
594 | */
|
---|
595 | if ( quitSwitch )
|
---|
596 | break;
|
---|
597 | /*
|
---|
598 | ** Create and Post the event the event
|
---|
599 | */
|
---|
600 | PL_ENTER_EVENT_QUEUE_MONITOR( padQueue );
|
---|
601 | ev = (PadEvent *) PR_NEW( PadEvent );
|
---|
602 | PL_InitEvent( &ev->plEvent, NULL,
|
---|
603 | (PLHandleEventProc)HandlePadEvent,
|
---|
604 | (PLDestroyEventProc)DestroyPadEvent );
|
---|
605 | PL_PostEvent( padQueue, &ev->plEvent );
|
---|
606 | PL_EXIT_EVENT_QUEUE_MONITOR( padQueue );
|
---|
607 |
|
---|
608 | PR_Sleep( ThreadSleepTime );
|
---|
609 | } while(1);
|
---|
610 | return;
|
---|
611 | }
|
---|
612 |
|
---|
613 | /*
|
---|
614 | ** HandlePadEvent() -- gets called because of PostEvent
|
---|
615 | */
|
---|
616 | static void PR_CALLBACK HandlePadEvent( PadEvent *padEvent )
|
---|
617 | {
|
---|
618 | if ( timerCount++ == 0 )
|
---|
619 | {
|
---|
620 | char *cp;
|
---|
621 |
|
---|
622 | for ( cp = startMessage; *cp != 0 ; cp++ )
|
---|
623 | {
|
---|
624 | SendMessage( hwndEdit, WM_CHAR, *cp, MAKELONG( *cp, 1 ));
|
---|
625 | }
|
---|
626 | }
|
---|
627 | /*
|
---|
628 | ** Send a WM_CHAR event the edit Window
|
---|
629 | */
|
---|
630 | if ((timerCount % 10) == 0)
|
---|
631 | {
|
---|
632 | SendMessage( hwndEdit, WM_CHAR, '+', MAKELONG( '+', 1 ));
|
---|
633 | }
|
---|
634 | else if ((timerCount % 5) == 0)
|
---|
635 | {
|
---|
636 | SendMessage( hwndEdit, WM_CHAR, '_', MAKELONG( '_', 1 ));
|
---|
637 | }
|
---|
638 | else
|
---|
639 | {
|
---|
640 | SendMessage( hwndEdit, WM_CHAR, '.', MAKELONG( '.', 1 ));
|
---|
641 | }
|
---|
642 |
|
---|
643 | if ( (timerCount % 50) == 0)
|
---|
644 | {
|
---|
645 | SendMessage( hwndEdit, WM_CHAR, '\n', MAKELONG( '\n', 1 ));
|
---|
646 | }
|
---|
647 |
|
---|
648 | /*
|
---|
649 | ** PL_RevokeEvents() is broken. Test to fix it.
|
---|
650 | */
|
---|
651 | {
|
---|
652 | static long revokeCounter = 0;
|
---|
653 |
|
---|
654 | if (revokeCounter++ > 10 )
|
---|
655 | {
|
---|
656 | PR_Sleep( ThreadSleepTime * 10 );
|
---|
657 | SendMessage( hwndEdit, WM_CHAR, '*', MAKELONG( '\n', 1 ));
|
---|
658 | PL_RevokeEvents( padQueue, NULL );
|
---|
659 | revokeCounter = 0;
|
---|
660 | }
|
---|
661 | }
|
---|
662 | return;
|
---|
663 | }
|
---|
664 |
|
---|
665 | /*
|
---|
666 | ** DestroyPadEvent() -- Called after HandlePadEvent()
|
---|
667 | */
|
---|
668 | static void PR_CALLBACK DestroyPadEvent( PadEvent *padevent )
|
---|
669 | {
|
---|
670 | PR_Free( padevent );
|
---|
671 | return;
|
---|
672 | }
|
---|