]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: app.cpp | |
3 | // Purpose: wxApp | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
a5e0e655 | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
e5c0b16a VZ |
12 | // =========================================================================== |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
e5c0b16a | 21 | #pragma implementation "app.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
2bda0e17 KB |
25 | #include "wx/wxprec.h" |
26 | ||
27 | #if defined(__BORLANDC__) | |
e5c0b16a | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
e5c0b16a VZ |
32 | #include "wx/frame.h" |
33 | #include "wx/app.h" | |
34 | #include "wx/utils.h" | |
35 | #include "wx/gdicmn.h" | |
36 | #include "wx/pen.h" | |
37 | #include "wx/brush.h" | |
38 | #include "wx/cursor.h" | |
39 | #include "wx/icon.h" | |
40 | #include "wx/palette.h" | |
41 | #include "wx/dc.h" | |
42 | #include "wx/dialog.h" | |
43 | #include "wx/msgdlg.h" | |
44 | #include "wx/intl.h" | |
45 | #include "wx/dynarray.h" | |
72cdf4c9 VZ |
46 | #include "wx/wxchar.h" |
47 | #include "wx/icon.h" | |
2bda0e17 KB |
48 | #endif |
49 | ||
2bda0e17 KB |
50 | #include "wx/log.h" |
51 | #include "wx/module.h" | |
4bf78aae | 52 | |
4286a5b5 RR |
53 | #include "wx/msw/private.h" |
54 | ||
4bf78aae | 55 | #if wxUSE_THREADS |
bee503b0 VZ |
56 | #include "wx/thread.h" |
57 | ||
58 | // define the array of MSG strutures | |
59 | WX_DECLARE_OBJARRAY(MSG, wxMsgArray); | |
60 | ||
61 | #include "wx/arrimpl.cpp" | |
62 | ||
63 | WX_DEFINE_OBJARRAY(wxMsgArray); | |
64 | #endif // wxUSE_THREADS | |
2bda0e17 | 65 | |
47d67540 | 66 | #if wxUSE_WX_RESOURCES |
e5c0b16a | 67 | #include "wx/resource.h" |
2bda0e17 KB |
68 | #endif |
69 | ||
8614c467 VZ |
70 | #if wxUSE_TOOLTIPS |
71 | #include "wx/tooltip.h" | |
72 | #endif // wxUSE_TOOLTIPS | |
73 | ||
c42404a5 VZ |
74 | // OLE is used for drag-and-drop, clipboard, OLE Automation..., but some |
75 | // compilers don't support it (missing headers, libs, ...) | |
76 | #if defined(__GNUWIN32_OLD__) || defined(__SC__) || defined(__SALFORDC__) | |
e5c0b16a VZ |
77 | #undef wxUSE_OLE |
78 | ||
79 | #define wxUSE_OLE 0 | |
80 | #endif // broken compilers | |
81 | ||
82 | #if wxUSE_OLE | |
6e0d9d43 | 83 | #include <ole2.h> |
d05237ea | 84 | #endif |
ce3ed50d | 85 | |
2bda0e17 | 86 | #include <string.h> |
a5e0e655 | 87 | #include <ctype.h> |
2bda0e17 | 88 | |
c42404a5 | 89 | #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) |
e5c0b16a | 90 | #include <commctrl.h> |
2bda0e17 KB |
91 | #endif |
92 | ||
6e0d9d43 | 93 | #include "wx/msw/msvcrt.h" |
370382c7 | 94 | |
bdc72a22 VZ |
95 | // ---------------------------------------------------------------------------- |
96 | // conditional compilation | |
97 | // ---------------------------------------------------------------------------- | |
98 | ||
99 | // The macro _WIN32_IE is defined by commctrl.h (unless it had already been | |
100 | // defined before) and shows us what common control features are available | |
101 | // during the compile time (it doesn't mean that they will be available during | |
102 | // the run-time, use GetComCtl32Version() to test for them!). The possible | |
103 | // values are: | |
104 | // | |
105 | // 0x0200 for comctl32.dll 4.00 shipped with Win95/NT 4.0 | |
106 | // 0x0300 4.70 IE 3.x | |
107 | // 0x0400 4.71 IE 4.0 | |
108 | // 0x0401 4.72 IE 4.01 and Win98 | |
109 | // 0x0500 5.00 IE 5.x and NT 5.0 (Win2000) | |
110 | ||
111 | #ifndef _WIN32_IE | |
112 | // minimal set of features by default | |
113 | #define _WIN32_IE 0x0200 | |
114 | #endif | |
115 | ||
036bc7d9 VZ |
116 | #if _WIN32_IE >= 0x0300 |
117 | #include <shlwapi.h> | |
118 | #endif | |
119 | ||
e5c0b16a VZ |
120 | // --------------------------------------------------------------------------- |
121 | // global variables | |
122 | // --------------------------------------------------------------------------- | |
123 | ||
837e5743 OK |
124 | extern wxChar *wxBuffer; |
125 | extern wxChar *wxOsVersion; | |
2bda0e17 | 126 | extern wxList *wxWinHandleList; |
cde9f08e | 127 | extern wxList WXDLLEXPORT wxPendingDelete; |
2bda0e17 KB |
128 | extern void wxSetKeyboardHook(bool doIt); |
129 | extern wxCursor *g_globalCursor; | |
130 | ||
42e69d6b | 131 | MSG s_currentMsg; |
2bda0e17 KB |
132 | wxApp *wxTheApp = NULL; |
133 | ||
193fe989 VZ |
134 | // NB: all "NoRedraw" classes must have the same names as the "normal" classes |
135 | // with NR suffix - wxWindow::MSWCreate() supposes this | |
2ffa221c VZ |
136 | const wxChar *wxFrameClassName = wxT("wxFrameClass"); |
137 | const wxChar *wxFrameClassNameNoRedraw = wxT("wxFrameClassNR"); | |
138 | const wxChar *wxMDIFrameClassName = wxT("wxMDIFrameClass"); | |
139 | const wxChar *wxMDIFrameClassNameNoRedraw = wxT("wxMDIFrameClassNR"); | |
140 | const wxChar *wxMDIChildFrameClassName = wxT("wxMDIChildFrameClass"); | |
141 | const wxChar *wxMDIChildFrameClassNameNoRedraw = wxT("wxMDIChildFrameClassNR"); | |
142 | const wxChar *wxPanelClassName = wxT("wxPanelClass"); | |
143 | const wxChar *wxCanvasClassName = wxT("wxCanvasClass"); | |
2bda0e17 | 144 | |
57c208c5 JS |
145 | HICON wxSTD_FRAME_ICON = (HICON) NULL; |
146 | HICON wxSTD_MDICHILDFRAME_ICON = (HICON) NULL; | |
147 | HICON wxSTD_MDIPARENTFRAME_ICON = (HICON) NULL; | |
2bda0e17 | 148 | |
57c208c5 JS |
149 | HICON wxDEFAULT_FRAME_ICON = (HICON) NULL; |
150 | HICON wxDEFAULT_MDICHILDFRAME_ICON = (HICON) NULL; | |
151 | HICON wxDEFAULT_MDIPARENTFRAME_ICON = (HICON) NULL; | |
2bda0e17 | 152 | |
57c208c5 | 153 | HBRUSH wxDisableButtonBrush = (HBRUSH) 0; |
2bda0e17 | 154 | |
3135f4a7 | 155 | LRESULT WXDLLEXPORT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM); |
2bda0e17 | 156 | |
e5c0b16a VZ |
157 | // =========================================================================== |
158 | // implementation | |
159 | // =========================================================================== | |
589f0e3e | 160 | |
e5c0b16a VZ |
161 | // --------------------------------------------------------------------------- |
162 | // wxApp | |
163 | // --------------------------------------------------------------------------- | |
164 | ||
e5c0b16a VZ |
165 | IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) |
166 | ||
167 | BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) | |
168 | EVT_IDLE(wxApp::OnIdle) | |
169 | EVT_END_SESSION(wxApp::OnEndSession) | |
170 | EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession) | |
171 | END_EVENT_TABLE() | |
e5c0b16a | 172 | |
e5c0b16a | 173 | //// Initialize |
589f0e3e | 174 | bool wxApp::Initialize() |
2bda0e17 | 175 | { |
c030b70f JS |
176 | // Some people may wish to use this, but |
177 | // probably it shouldn't be here by default. | |
178 | #ifdef __WXDEBUG__ | |
e5c0b16a | 179 | // wxRedirectIOToConsole(); |
c030b70f JS |
180 | #endif |
181 | ||
837e5743 | 182 | wxBuffer = new wxChar[1500]; // FIXME |
589f0e3e | 183 | |
aa0b7e1e | 184 | wxClassInfo::InitializeClasses(); |
589f0e3e | 185 | |
aa0b7e1e | 186 | #if wxUSE_RESOURCES |
223d09f6 | 187 | wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion); |
aa0b7e1e | 188 | #endif |
589f0e3e | 189 | |
4d3a259a | 190 | #if wxUSE_THREADS |
8e193f38 | 191 | wxPendingEventsLocker = new wxCriticalSection; |
4d3a259a GL |
192 | #endif |
193 | ||
aa0b7e1e JS |
194 | wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING); |
195 | wxTheColourDatabase->Initialize(); | |
589f0e3e | 196 | |
aa0b7e1e JS |
197 | wxInitializeStockLists(); |
198 | wxInitializeStockObjects(); | |
589f0e3e | 199 | |
aa0b7e1e | 200 | #if wxUSE_WX_RESOURCES |
a5e0e655 | 201 | wxInitializeResourceSystem(); |
aa0b7e1e | 202 | #endif |
2bda0e17 | 203 | |
aa0b7e1e | 204 | wxBitmap::InitStandardHandlers(); |
2bda0e17 | 205 | |
aa0b7e1e | 206 | #if defined(__WIN95__) |
a5e0e655 | 207 | InitCommonControls(); |
57c208c5 | 208 | |
e5c0b16a | 209 | #endif // __WIN95__ |
2bda0e17 | 210 | |
c49245f8 VZ |
211 | #if wxUSE_OLE |
212 | ||
213 | #ifdef __WIN16__ | |
e5c0b16a | 214 | // for OLE, enlarge message queue to be as large as possible |
aa0b7e1e | 215 | int iMsg = 96; |
c49245f8 VZ |
216 | while (!SetMessageQueue(iMsg) && (iMsg -= 8)) |
217 | ; | |
218 | #endif // Win16 | |
a5e0e655 VZ |
219 | // we need to initialize OLE library |
220 | if ( FAILED(::OleInitialize(NULL)) ) | |
e5c0b16a | 221 | wxLogError(_("Cannot initialize OLE")); |
c49245f8 | 222 | #endif // wxUSE_OLE |
2bda0e17 | 223 | |
1f112209 | 224 | #if wxUSE_CTL3D |
a5e0e655 | 225 | if (!Ctl3dRegister(wxhInstance)) |
223d09f6 | 226 | wxLogError(wxT("Cannot register CTL3D")); |
2bda0e17 | 227 | |
a5e0e655 | 228 | Ctl3dAutoSubclass(wxhInstance); |
aa0b7e1e | 229 | #endif |
2bda0e17 | 230 | |
aa0b7e1e | 231 | g_globalCursor = new wxCursor; |
589f0e3e | 232 | |
87a1e308 VZ |
233 | // VZ: these icons are not in wx.rc anyhow (but should they?)! |
234 | #if 0 | |
223d09f6 KB |
235 | wxSTD_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_FRAME")); |
236 | wxSTD_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDIPARENTFRAME")); | |
237 | wxSTD_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDICHILDFRAME")); | |
2bda0e17 | 238 | |
223d09f6 KB |
239 | wxDEFAULT_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_FRAME")); |
240 | wxDEFAULT_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDIPARENTFRAME")); | |
241 | wxDEFAULT_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDICHILDFRAME")); | |
87a1e308 | 242 | #endif // 0 |
2bda0e17 | 243 | |
aa0b7e1e | 244 | RegisterWindowClasses(); |
2bda0e17 | 245 | |
aa0b7e1e | 246 | // Create the brush for disabling bitmap buttons |
2bda0e17 | 247 | |
42e69d6b | 248 | LOGBRUSH lb; |
aa0b7e1e | 249 | lb.lbStyle = BS_PATTERN; |
223d09f6 | 250 | lb.lbHatch = (int)LoadBitmap( wxhInstance, wxT("wxDISABLE_BUTTON_BITMAP") ); |
3a5ffa81 VZ |
251 | if ( lb.lbHatch ) |
252 | { | |
253 | wxDisableButtonBrush = ::CreateBrushIndirect( & lb ); | |
254 | ::DeleteObject( (HGDIOBJ)lb.lbHatch ); | |
255 | } | |
256 | //else: wxWindows resources are probably not linked in | |
2bda0e17 | 257 | |
aa0b7e1e | 258 | #if wxUSE_PENWINDOWS |
a5e0e655 | 259 | wxRegisterPenWin(); |
aa0b7e1e | 260 | #endif |
2bda0e17 | 261 | |
aa0b7e1e | 262 | wxWinHandleList = new wxList(wxKEY_INTEGER); |
2bda0e17 | 263 | |
6e0d9d43 | 264 | // This is to foil optimizations in Visual C++ that throw out dummy.obj. |
8cbd2bde | 265 | // PLEASE DO NOT ALTER THIS. |
3f4a0c5b | 266 | #if defined(__VISUALC__) && !defined(WXMAKINGDLL) |
a5e0e655 VZ |
267 | extern char wxDummyChar; |
268 | if (wxDummyChar) wxDummyChar++; | |
aa0b7e1e | 269 | #endif |
a5e0e655 | 270 | |
aa0b7e1e | 271 | wxSetKeyboardHook(TRUE); |
2bda0e17 | 272 | |
aa0b7e1e JS |
273 | wxModule::RegisterModules(); |
274 | if (!wxModule::InitializeModules()) | |
275 | return FALSE; | |
276 | return TRUE; | |
2bda0e17 KB |
277 | } |
278 | ||
42e69d6b VZ |
279 | // --------------------------------------------------------------------------- |
280 | // RegisterWindowClasses | |
281 | // --------------------------------------------------------------------------- | |
589f0e3e | 282 | |
b782f2e0 VZ |
283 | // TODO we should only register classes really used by the app. For this it |
284 | // would be enough to just delay the class registration until an attempt | |
285 | // to create a window of this class is made. | |
bb6290e3 | 286 | bool wxApp::RegisterWindowClasses() |
2bda0e17 | 287 | { |
42e69d6b | 288 | WNDCLASS wndclass; |
e5c0b16a | 289 | |
193fe989 VZ |
290 | // for each class we register one with CS_(V|H)REDRAW style and one |
291 | // without for windows created with wxNO_FULL_REDRAW_ON_REPAINT flag | |
292 | static const long styleNormal = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; | |
293 | static const long styleNoRedraw = CS_DBLCLKS; | |
294 | ||
42e69d6b | 295 | // the fields which are common to all classes |
e5c0b16a VZ |
296 | wndclass.lpfnWndProc = (WNDPROC)wxWndProc; |
297 | wndclass.cbClsExtra = 0; | |
193fe989 | 298 | wndclass.cbWndExtra = sizeof( DWORD ); // VZ: what is this DWORD used for? |
e5c0b16a | 299 | wndclass.hInstance = wxhInstance; |
42e69d6b VZ |
300 | wndclass.hIcon = (HICON) NULL; |
301 | wndclass.hCursor = ::LoadCursor((HINSTANCE)NULL, IDC_ARROW); | |
e5c0b16a | 302 | wndclass.lpszMenuName = NULL; |
42e69d6b VZ |
303 | |
304 | // Register the frame window class. | |
305 | wndclass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1); | |
e5c0b16a | 306 | wndclass.lpszClassName = wxFrameClassName; |
b782f2e0 | 307 | wndclass.style = styleNormal; |
e5c0b16a | 308 | |
42e69d6b | 309 | if ( !RegisterClass(&wndclass) ) |
e5c0b16a | 310 | { |
42e69d6b VZ |
311 | wxLogLastError("RegisterClass(frame)"); |
312 | ||
313 | return FALSE; | |
e5c0b16a VZ |
314 | } |
315 | ||
193fe989 VZ |
316 | // "no redraw" frame |
317 | wndclass.lpszClassName = wxFrameClassNameNoRedraw; | |
318 | wndclass.style = styleNoRedraw; | |
319 | ||
320 | if ( !RegisterClass(&wndclass) ) | |
321 | { | |
322 | wxLogLastError("RegisterClass(no redraw frame)"); | |
323 | ||
324 | return FALSE; | |
325 | } | |
326 | ||
e5c0b16a | 327 | // Register the MDI frame window class. |
42e69d6b | 328 | wndclass.hbrBackground = (HBRUSH)NULL; // paint MDI frame ourselves |
b782f2e0 VZ |
329 | wndclass.lpszClassName = wxMDIFrameClassName; |
330 | wndclass.style = styleNormal; | |
42e69d6b VZ |
331 | |
332 | if ( !RegisterClass(&wndclass) ) | |
e5c0b16a | 333 | { |
42e69d6b VZ |
334 | wxLogLastError("RegisterClass(MDI parent)"); |
335 | ||
336 | return FALSE; | |
e5c0b16a VZ |
337 | } |
338 | ||
193fe989 | 339 | // "no redraw" MDI frame |
b782f2e0 | 340 | wndclass.lpszClassName = wxMDIFrameClassNameNoRedraw; |
193fe989 VZ |
341 | wndclass.style = styleNoRedraw; |
342 | ||
343 | if ( !RegisterClass(&wndclass) ) | |
344 | { | |
345 | wxLogLastError("RegisterClass(no redraw MDI parent frame)"); | |
346 | ||
347 | return FALSE; | |
348 | } | |
349 | ||
e5c0b16a | 350 | // Register the MDI child frame window class. |
42e69d6b VZ |
351 | wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); |
352 | wndclass.lpszClassName = wxMDIChildFrameClassName; | |
b782f2e0 | 353 | wndclass.style = styleNormal; |
42e69d6b VZ |
354 | |
355 | if ( !RegisterClass(&wndclass) ) | |
e5c0b16a | 356 | { |
42e69d6b VZ |
357 | wxLogLastError("RegisterClass(MDI child)"); |
358 | ||
359 | return FALSE; | |
e5c0b16a VZ |
360 | } |
361 | ||
193fe989 VZ |
362 | // "no redraw" MDI child frame |
363 | wndclass.lpszClassName = wxMDIChildFrameClassNameNoRedraw; | |
364 | wndclass.style = styleNoRedraw; | |
365 | ||
366 | if ( !RegisterClass(&wndclass) ) | |
367 | { | |
368 | wxLogLastError("RegisterClass(no redraw MDI child)"); | |
369 | ||
370 | return FALSE; | |
371 | } | |
372 | ||
e5c0b16a | 373 | // Register the panel window class. |
42e69d6b VZ |
374 | wndclass.hbrBackground = (HBRUSH) GetStockObject( LTGRAY_BRUSH ); |
375 | wndclass.lpszClassName = wxPanelClassName; | |
b782f2e0 | 376 | wndclass.style = styleNormal; |
42e69d6b VZ |
377 | |
378 | if ( !RegisterClass(&wndclass) ) | |
e5c0b16a | 379 | { |
42e69d6b VZ |
380 | wxLogLastError("RegisterClass(panel)"); |
381 | ||
382 | return FALSE; | |
e5c0b16a VZ |
383 | } |
384 | ||
e5c0b16a | 385 | // Register the canvas and textsubwindow class name |
42e69d6b VZ |
386 | wndclass.hbrBackground = (HBRUSH)NULL; |
387 | wndclass.lpszClassName = wxCanvasClassName; | |
388 | ||
389 | if ( !RegisterClass(&wndclass) ) | |
e5c0b16a | 390 | { |
42e69d6b VZ |
391 | wxLogLastError("RegisterClass(canvas)"); |
392 | ||
393 | return FALSE; | |
e5c0b16a VZ |
394 | } |
395 | ||
396 | return TRUE; | |
2bda0e17 KB |
397 | } |
398 | ||
42e69d6b VZ |
399 | // --------------------------------------------------------------------------- |
400 | // Convert Windows to argc, argv style | |
401 | // --------------------------------------------------------------------------- | |
589f0e3e JS |
402 | |
403 | void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine) | |
404 | { | |
da36f544 | 405 | wxStringList args; |
589f0e3e | 406 | |
da36f544 JS |
407 | wxString cmdLine(lpCmdLine); |
408 | int count = 0; | |
589f0e3e | 409 | |
da36f544 | 410 | // Get application name |
837e5743 | 411 | wxChar name[260]; // 260 is MAX_PATH value from windef.h |
da36f544 JS |
412 | ::GetModuleFileName(wxhInstance, name, WXSIZEOF(name)); |
413 | ||
da36f544 | 414 | args.Add(name); |
50ef256e | 415 | count++; |
589f0e3e | 416 | |
837e5743 | 417 | wxStrcpy(name, wxFileNameFromPath(name)); |
da36f544 JS |
418 | wxStripExtension(name); |
419 | wxTheApp->SetAppName(name); | |
589f0e3e | 420 | |
da36f544 JS |
421 | // Break up string |
422 | // Treat strings enclosed in double-quotes as single arguments | |
423 | int i = 0; | |
424 | int len = cmdLine.Length(); | |
425 | while (i < len) | |
a5e0e655 | 426 | { |
da36f544 | 427 | // Skip whitespace |
837e5743 | 428 | while ((i < len) && wxIsspace(cmdLine.GetChar(i))) |
da36f544 JS |
429 | i ++; |
430 | ||
431 | if (i < len) | |
432 | { | |
223d09f6 | 433 | if (cmdLine.GetChar(i) == wxT('"')) // We found the start of a string |
da36f544 JS |
434 | { |
435 | i ++; | |
436 | int first = i; | |
223d09f6 | 437 | while ((i < len) && (cmdLine.GetChar(i) != wxT('"'))) |
da36f544 JS |
438 | i ++; |
439 | ||
440 | wxString arg(cmdLine.Mid(first, (i - first))); | |
441 | ||
442 | args.Add(arg); | |
443 | count ++; | |
444 | ||
445 | if (i < len) | |
446 | i ++; // Skip past 2nd quote | |
447 | } | |
448 | else // Unquoted argument | |
449 | { | |
450 | int first = i; | |
837e5743 | 451 | while ((i < len) && !wxIsspace(cmdLine.GetChar(i))) |
da36f544 JS |
452 | i ++; |
453 | ||
454 | wxString arg(cmdLine.Mid(first, (i - first))); | |
455 | ||
456 | args.Add(arg); | |
457 | count ++; | |
458 | } | |
459 | } | |
a5e0e655 | 460 | } |
a5e0e655 | 461 | |
837e5743 | 462 | wxTheApp->argv = new wxChar*[count + 1]; |
da36f544 | 463 | for (i = 0; i < count; i++) |
a5e0e655 | 464 | { |
da36f544 | 465 | wxString arg(args[i]); |
837e5743 | 466 | wxTheApp->argv[i] = copystring((const wxChar*)arg); |
a5e0e655 | 467 | } |
da36f544 JS |
468 | wxTheApp->argv[count] = NULL; // argv[] is a NULL-terminated list |
469 | wxTheApp->argc = count; | |
589f0e3e JS |
470 | } |
471 | ||
472 | //// Cleans up any wxWindows internal structures left lying around | |
473 | ||
bb6290e3 | 474 | void wxApp::CleanUp() |
2bda0e17 | 475 | { |
e5c0b16a VZ |
476 | //// COMMON CLEANUP |
477 | ||
546db2a8 | 478 | #if wxUSE_LOG |
e5c0b16a VZ |
479 | // flush the logged messages if any and install a 'safer' log target: the |
480 | // default one (wxLogGui) can't be used after the resources are freed just | |
481 | // below and the user suppliedo ne might be even more unsafe (using any | |
482 | // wxWindows GUI function is unsafe starting from now) | |
483 | wxLog::DontCreateOnDemand(); | |
f5e5bd66 | 484 | |
e5c0b16a VZ |
485 | // this will flush the old messages if any |
486 | delete wxLog::SetActiveTarget(new wxLogStderr); | |
546db2a8 | 487 | #endif // wxUSE_LOG |
f5e5bd66 | 488 | |
e5c0b16a VZ |
489 | // One last chance for pending objects to be cleaned up |
490 | wxTheApp->DeletePendingObjects(); | |
f5e5bd66 | 491 | |
e5c0b16a | 492 | wxModule::CleanUpModules(); |
2bda0e17 | 493 | |
47d67540 | 494 | #if wxUSE_WX_RESOURCES |
e5c0b16a | 495 | wxCleanUpResourceSystem(); |
589f0e3e | 496 | |
e5c0b16a | 497 | // wxDefaultResourceTable->ClearTable(); |
589f0e3e JS |
498 | #endif |
499 | ||
e5c0b16a VZ |
500 | // Indicate that the cursor can be freed, so that cursor won't be deleted |
501 | // by deleting the bitmap list before g_globalCursor goes out of scope | |
502 | // (double deletion of the cursor). | |
503 | wxSetCursor(wxNullCursor); | |
504 | delete g_globalCursor; | |
2a47d3c1 | 505 | g_globalCursor = NULL; |
589f0e3e | 506 | |
42e69d6b | 507 | wxDeleteStockObjects(); |
589f0e3e | 508 | |
e5c0b16a VZ |
509 | // Destroy all GDI lists, etc. |
510 | wxDeleteStockLists(); | |
589f0e3e | 511 | |
e5c0b16a VZ |
512 | delete wxTheColourDatabase; |
513 | wxTheColourDatabase = NULL; | |
589f0e3e | 514 | |
e5c0b16a | 515 | wxBitmap::CleanUpHandlers(); |
589f0e3e | 516 | |
e5c0b16a VZ |
517 | delete[] wxBuffer; |
518 | wxBuffer = NULL; | |
589f0e3e | 519 | |
e5c0b16a | 520 | //// WINDOWS-SPECIFIC CLEANUP |
2bda0e17 | 521 | |
e5c0b16a | 522 | wxSetKeyboardHook(FALSE); |
2bda0e17 | 523 | |
47d67540 | 524 | #if wxUSE_PENWINDOWS |
e5c0b16a | 525 | wxCleanUpPenWin(); |
2bda0e17 KB |
526 | #endif |
527 | ||
e5c0b16a VZ |
528 | if (wxSTD_FRAME_ICON) |
529 | DestroyIcon(wxSTD_FRAME_ICON); | |
530 | if (wxSTD_MDICHILDFRAME_ICON) | |
531 | DestroyIcon(wxSTD_MDICHILDFRAME_ICON); | |
532 | if (wxSTD_MDIPARENTFRAME_ICON) | |
533 | DestroyIcon(wxSTD_MDIPARENTFRAME_ICON); | |
534 | ||
535 | if (wxDEFAULT_FRAME_ICON) | |
536 | DestroyIcon(wxDEFAULT_FRAME_ICON); | |
537 | if (wxDEFAULT_MDICHILDFRAME_ICON) | |
538 | DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON); | |
539 | if (wxDEFAULT_MDIPARENTFRAME_ICON) | |
540 | DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON); | |
541 | ||
542 | if ( wxDisableButtonBrush ) | |
42e69d6b | 543 | ::DeleteObject( wxDisableButtonBrush ); |
e5c0b16a VZ |
544 | |
545 | #if wxUSE_OLE | |
546 | ::OleUninitialize(); | |
5de5db0e | 547 | #endif |
2bda0e17 | 548 | |
1f112209 | 549 | #if wxUSE_CTL3D |
e5c0b16a | 550 | Ctl3dUnregister(wxhInstance); |
2bda0e17 KB |
551 | #endif |
552 | ||
e5c0b16a | 553 | if (wxWinHandleList) |
42e69d6b | 554 | delete wxWinHandleList; |
d50b2a58 | 555 | |
3135f4a7 | 556 | // GL: I'm annoyed ... I don't know where to put this and I don't want to |
4d3a259a | 557 | // create a module for that as it's part of the core. |
4d3a259a | 558 | delete wxPendingEvents; |
8e193f38 | 559 | #if wxUSE_THREADS |
4d3a259a | 560 | delete wxPendingEventsLocker; |
63863e09 JS |
561 | // If we don't do the following, we get an apparent memory leak. |
562 | ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker(); | |
4d3a259a GL |
563 | #endif |
564 | ||
e5c0b16a | 565 | wxClassInfo::CleanUpClasses(); |
0c32066b | 566 | |
e5c0b16a VZ |
567 | delete wxTheApp; |
568 | wxTheApp = NULL; | |
184b5d99 JS |
569 | |
570 | #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT | |
e5c0b16a VZ |
571 | // At this point we want to check if there are any memory |
572 | // blocks that aren't part of the wxDebugContext itself, | |
573 | // as a special case. Then when dumping we need to ignore | |
574 | // wxDebugContext, too. | |
d13c32e9 | 575 | if (wxDebugContext::CountObjectsLeft(TRUE) > 0) |
e5c0b16a | 576 | { |
223d09f6 | 577 | wxLogDebug(wxT("There were memory leaks.")); |
e5c0b16a VZ |
578 | wxDebugContext::Dump(); |
579 | wxDebugContext::PrintStatistics(); | |
580 | } | |
581 | // wxDebugContext::SetStream(NULL, NULL); | |
184b5d99 JS |
582 | #endif |
583 | ||
546db2a8 | 584 | #if wxUSE_LOG |
e5c0b16a VZ |
585 | // do it as the very last thing because everything else can log messages |
586 | delete wxLog::SetActiveTarget(NULL); | |
546db2a8 | 587 | #endif // wxUSE_LOG |
2bda0e17 KB |
588 | } |
589 | ||
2bda0e17 KB |
590 | #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL)) |
591 | ||
e5c0b16a VZ |
592 | // temporarily disable this warning which would be generated in release builds |
593 | // because of __try | |
3f4a0c5b | 594 | #ifdef __VISUALC__ |
f8a3e080 VZ |
595 | #pragma warning(disable: 4715) // not all control paths return a value |
596 | #endif // Visual C++ | |
597 | ||
589f0e3e | 598 | //// Main wxWindows entry point |
a5e0e655 VZ |
599 | int wxEntry(WXHINSTANCE hInstance, |
600 | WXHINSTANCE WXUNUSED(hPrevInstance), | |
601 | char *lpCmdLine, | |
602 | int nCmdShow, | |
603 | bool enterLoop) | |
2bda0e17 | 604 | { |
6e0d9d43 VZ |
605 | // do check for memory leaks on program exit |
606 | // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free | |
607 | // deallocated memory which may be used to simulate low-memory condition) | |
608 | wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF); | |
6418cb93 SC |
609 | #ifdef __MWERKS__ |
610 | #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT | |
611 | // This seems to be necessary since there are 'rogue' | |
612 | // objects present at this point (perhaps global objects?) | |
613 | // Setting a checkpoint will ignore them as far as the | |
614 | // memory checking facility is concerned. | |
615 | // Of course you may argue that memory allocated in globals should be | |
616 | // checked, but this is a reasonable compromise. | |
617 | wxDebugContext::SetCheckpoint(); | |
618 | #endif | |
619 | #endif | |
e5c0b16a VZ |
620 | // take everything into a try-except block in release build |
621 | // FIXME other compilers must support Win32 SEH (structured exception | |
622 | // handling) too, just find the appropriate keyword in their docs! | |
623 | // Please note that it's _not_ the same as C++ exceptions! | |
3f4a0c5b | 624 | #if !defined(__WXDEBUG__) && defined(__VISUALC__) |
f8a3e080 VZ |
625 | #define CATCH_PROGRAM_EXCEPTIONS |
626 | ||
3f4a0c5b | 627 | __try { |
f8a3e080 VZ |
628 | #else |
629 | #undef CATCH_PROGRAM_EXCEPTIONS | |
a5e0e655 | 630 | #endif |
e5c0b16a | 631 | wxhInstance = (HINSTANCE) hInstance; |
2bda0e17 | 632 | |
e5c0b16a VZ |
633 | if (!wxApp::Initialize()) |
634 | return 0; | |
2bda0e17 | 635 | |
e5c0b16a VZ |
636 | // create the application object or ensure that one already exists |
637 | if (!wxTheApp) | |
638 | { | |
639 | // The app may have declared a global application object, but we recommend | |
640 | // the IMPLEMENT_APP macro is used instead, which sets an initializer | |
641 | // function for delayed, dynamic app object construction. | |
642 | wxCHECK_MSG( wxApp::GetInitializerFunction(), 0, | |
223d09f6 | 643 | wxT("No initializer - use IMPLEMENT_APP macro.") ); |
f8a3e080 | 644 | |
e5c0b16a VZ |
645 | wxTheApp = (*wxApp::GetInitializerFunction()) (); |
646 | } | |
647 | ||
223d09f6 | 648 | wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") ); |
e5c0b16a VZ |
649 | |
650 | // save the WinMain() parameters | |
651 | wxTheApp->ConvertToStandardCommandArgs(lpCmdLine); | |
652 | wxTheApp->m_nCmdShow = nCmdShow; | |
a5e0e655 | 653 | |
e5c0b16a VZ |
654 | // GUI-specific initialisation. In fact on Windows we don't have any, |
655 | // but this call is provided for compatibility across platforms. | |
42e69d6b | 656 | wxTheApp->OnInitGui(); |
f8a3e080 | 657 | |
36edded9 JS |
658 | // We really don't want timestamps by default, because it means |
659 | // we can't simply double-click on the error message and get to that | |
660 | // line in the source. So VC++ at least, let's have a sensible default. | |
661 | #ifdef __VISUALC__ | |
662 | wxLog::SetTimestamp(NULL); | |
663 | #endif | |
664 | ||
e5c0b16a VZ |
665 | int retValue = 0; |
666 | ||
667 | if ( wxTheApp->OnInit() ) | |
668 | { | |
669 | if ( enterLoop ) | |
670 | { | |
671 | retValue = wxTheApp->OnRun(); | |
672 | } | |
673 | else | |
674 | // We want to initialize, but not run or exit immediately. | |
675 | return 1; | |
676 | } | |
677 | //else: app initialization failed, so we skipped OnRun() | |
678 | ||
679 | wxWindow *topWindow = wxTheApp->GetTopWindow(); | |
680 | if ( topWindow ) | |
681 | { | |
682 | // Forcibly delete the window. | |
683 | if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) || | |
684 | topWindow->IsKindOf(CLASSINFO(wxDialog)) ) | |
685 | { | |
686 | topWindow->Close(TRUE); | |
687 | wxTheApp->DeletePendingObjects(); | |
688 | } | |
689 | else | |
690 | { | |
691 | delete topWindow; | |
692 | wxTheApp->SetTopWindow(NULL); | |
693 | } | |
694 | } | |
695 | ||
696 | wxTheApp->OnExit(); | |
697 | ||
698 | wxApp::CleanUp(); | |
699 | ||
700 | return retValue; | |
701 | ||
702 | #ifdef CATCH_PROGRAM_EXCEPTIONS | |
703 | } | |
704 | __except ( EXCEPTION_EXECUTE_HANDLER ) { | |
705 | /* | |
706 | if ( wxTheApp ) | |
707 | wxTheApp->OnFatalException(); | |
708 | */ | |
709 | ||
710 | // using wxLog would be unsafe here | |
711 | ::MessageBox(NULL, | |
712 | _("Unrecoverable program error detected: " | |
713 | " the application will terminate."), | |
714 | _("Fatal Error"), | |
715 | MB_APPLMODAL | MB_ICONSTOP | MB_OK); | |
716 | ||
717 | ::ExitProcess(3); // the same exit code as abort() | |
718 | ||
719 | // NOTREACHED | |
720 | } | |
f8a3e080 | 721 | #endif // CATCH_PROGRAM_EXCEPTIONS |
2bda0e17 KB |
722 | } |
723 | ||
f8a3e080 | 724 | // restore warning state |
3f4a0c5b | 725 | #ifdef __VISUALC__ |
f8a3e080 VZ |
726 | #pragma warning(default: 4715) // not all control paths return a value |
727 | #endif // Visual C++ | |
728 | ||
2bda0e17 KB |
729 | #else /* _WINDLL */ |
730 | ||
589f0e3e JS |
731 | //// Entry point for DLLs |
732 | ||
2bda0e17 KB |
733 | int wxEntry(WXHINSTANCE hInstance) |
734 | { | |
e5c0b16a VZ |
735 | wxhInstance = (HINSTANCE) hInstance; |
736 | wxApp::Initialize(); | |
2bda0e17 | 737 | |
e5c0b16a VZ |
738 | // The app may have declared a global application object, but we recommend |
739 | // the IMPLEMENT_APP macro is used instead, which sets an initializer function | |
740 | // for delayed, dynamic app object construction. | |
741 | if (!wxTheApp) | |
a5e0e655 | 742 | { |
e5c0b16a VZ |
743 | wxCHECK_MSG( wxApp::GetInitializerFunction(), 0, |
744 | "No initializer - use IMPLEMENT_APP macro." ); | |
2bda0e17 | 745 | |
e5c0b16a VZ |
746 | wxTheApp = (* wxApp::GetInitializerFunction()) (); |
747 | } | |
2bda0e17 | 748 | |
e5c0b16a | 749 | wxCHECK_MSG( wxTheApp, 0, "You have to define an instance of wxApp!" ); |
2bda0e17 | 750 | |
e5c0b16a VZ |
751 | wxTheApp->argc = 0; |
752 | wxTheApp->argv = NULL; | |
2bda0e17 | 753 | |
e5c0b16a | 754 | wxTheApp->OnInitGui(); |
2bda0e17 | 755 | |
e5c0b16a | 756 | wxTheApp->OnInit(); |
2bda0e17 | 757 | |
e5c0b16a VZ |
758 | wxWindow *topWindow = wxTheApp->GetTopWindow(); |
759 | if ( topWindow && topWindow->GetHWND()) | |
760 | { | |
761 | topWindow->Show(TRUE); | |
762 | } | |
2bda0e17 | 763 | |
e5c0b16a | 764 | return 1; |
2bda0e17 KB |
765 | } |
766 | #endif // _WINDLL | |
767 | ||
589f0e3e JS |
768 | //// Static member initialization |
769 | ||
c94ad3c3 | 770 | wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL; |
2bda0e17 | 771 | |
bb6290e3 | 772 | wxApp::wxApp() |
2bda0e17 | 773 | { |
e5c0b16a VZ |
774 | m_topWindow = NULL; |
775 | wxTheApp = this; | |
42e69d6b VZ |
776 | m_wantDebugOutput = TRUE; |
777 | ||
e5c0b16a VZ |
778 | argc = 0; |
779 | argv = NULL; | |
e5c0b16a | 780 | m_printMode = wxPRINT_WINDOWS; |
e5c0b16a VZ |
781 | m_exitOnFrameDelete = TRUE; |
782 | m_auto3D = TRUE; | |
2bda0e17 KB |
783 | } |
784 | ||
589f0e3e JS |
785 | wxApp::~wxApp() |
786 | { | |
e5c0b16a VZ |
787 | // Delete command-line args |
788 | int i; | |
789 | for (i = 0; i < argc; i++) | |
790 | { | |
791 | delete[] argv[i]; | |
792 | } | |
793 | delete[] argv; | |
589f0e3e JS |
794 | } |
795 | ||
bb6290e3 | 796 | bool wxApp::Initialized() |
2bda0e17 KB |
797 | { |
798 | #ifndef _WINDLL | |
e5c0b16a VZ |
799 | if (GetTopWindow()) |
800 | return TRUE; | |
801 | else | |
802 | return FALSE; | |
2bda0e17 KB |
803 | #endif |
804 | #ifdef _WINDLL // Assume initialized if DLL (no way of telling) | |
e5c0b16a | 805 | return TRUE; |
2bda0e17 KB |
806 | #endif |
807 | } | |
808 | ||
809 | /* | |
810 | * Get and process a message, returning FALSE if WM_QUIT | |
bee503b0 | 811 | * received (and also set the flag telling the app to exit the main loop) |
2bda0e17 KB |
812 | * |
813 | */ | |
bb6290e3 | 814 | bool wxApp::DoMessage() |
2bda0e17 | 815 | { |
bee503b0 VZ |
816 | BOOL rc = ::GetMessage(&s_currentMsg, (HWND) NULL, 0, 0); |
817 | if ( rc == 0 ) | |
818 | { | |
819 | // got WM_QUIT | |
820 | m_keepGoing = FALSE; | |
4a9968f9 | 821 | |
bee503b0 VZ |
822 | return FALSE; |
823 | } | |
824 | else if ( rc == -1 ) | |
825 | { | |
826 | // should never happen, but let's test for it nevertheless | |
827 | wxLogLastError("GetMessage"); | |
828 | } | |
829 | else | |
830 | { | |
831 | #if wxUSE_THREADS | |
832 | wxASSERT_MSG( wxThread::IsMain(), | |
223d09f6 | 833 | wxT("only the main thread can process Windows messages") ); |
d50b2a58 | 834 | |
bee503b0 VZ |
835 | static bool s_hadGuiLock = TRUE; |
836 | static wxMsgArray s_aSavedMessages; | |
837 | ||
838 | // if a secondary thread owns is doing GUI calls, save all messages for | |
839 | // later processing - we can't process them right now because it will | |
840 | // lead to recursive library calls (and we're not reentrant) | |
841 | if ( !wxGuiOwnedByMainThread() ) | |
842 | { | |
843 | s_hadGuiLock = FALSE; | |
844 | ||
4a9968f9 VZ |
845 | // leave out WM_COMMAND messages: too dangerous, sometimes |
846 | // the message will be processed twice | |
847 | if ( !wxIsWaitingForThread() || | |
e5c0b16a | 848 | s_currentMsg.message != WM_COMMAND ) |
4a9968f9 VZ |
849 | { |
850 | s_aSavedMessages.Add(s_currentMsg); | |
851 | } | |
bee503b0 VZ |
852 | |
853 | return TRUE; | |
854 | } | |
855 | else | |
856 | { | |
857 | // have we just regained the GUI lock? if so, post all of the saved | |
858 | // messages | |
859 | // | |
860 | // FIXME of course, it's not _exactly_ the same as processing the | |
861 | // messages normally - expect some things to break... | |
862 | if ( !s_hadGuiLock ) | |
863 | { | |
864 | s_hadGuiLock = TRUE; | |
865 | ||
866 | size_t count = s_aSavedMessages.Count(); | |
867 | for ( size_t n = 0; n < count; n++ ) | |
868 | { | |
869 | MSG& msg = s_aSavedMessages[n]; | |
870 | ||
871 | if ( !ProcessMessage((WXMSG *)&msg) ) | |
872 | { | |
873 | ::TranslateMessage(&msg); | |
874 | ::DispatchMessage(&msg); | |
875 | } | |
876 | } | |
877 | ||
878 | s_aSavedMessages.Empty(); | |
879 | } | |
880 | } | |
881 | #endif // wxUSE_THREADS | |
882 | ||
883 | // Process the message | |
884 | if ( !ProcessMessage((WXMSG *)&s_currentMsg) ) | |
885 | { | |
886 | ::TranslateMessage(&s_currentMsg); | |
bee503b0 VZ |
887 | ::DispatchMessage(&s_currentMsg); |
888 | } | |
889 | } | |
890 | ||
891 | return TRUE; | |
2bda0e17 KB |
892 | } |
893 | ||
894 | /* | |
895 | * Keep trying to process messages until WM_QUIT | |
896 | * received. | |
897 | * | |
898 | * If there are messages to be processed, they will all be | |
899 | * processed and OnIdle will not be called. | |
900 | * When there are no more messages, OnIdle is called. | |
901 | * If OnIdle requests more time, | |
902 | * it will be repeatedly called so long as there are no pending messages. | |
903 | * A 'feature' of this is that once OnIdle has decided that no more processing | |
904 | * is required, then it won't get processing time until further messages | |
905 | * are processed (it'll sit in DoMessage). | |
906 | */ | |
907 | ||
bb6290e3 | 908 | int wxApp::MainLoop() |
2bda0e17 | 909 | { |
e5c0b16a | 910 | m_keepGoing = TRUE; |
bee503b0 | 911 | |
e5c0b16a VZ |
912 | while ( m_keepGoing ) |
913 | { | |
914 | #if wxUSE_THREADS | |
bee503b0 | 915 | wxMutexGuiLeaveOrEnter(); |
e5c0b16a | 916 | #endif // wxUSE_THREADS |
bee503b0 | 917 | |
b6c588e1 VZ |
918 | while ( !Pending() && ProcessIdle() ) |
919 | ; | |
7214297d | 920 | |
b6c588e1 | 921 | // a message came or no more idle processing to do |
e5c0b16a VZ |
922 | DoMessage(); |
923 | } | |
2bda0e17 | 924 | |
e5c0b16a | 925 | return s_currentMsg.wParam; |
2bda0e17 KB |
926 | } |
927 | ||
928 | // Returns TRUE if more time is needed. | |
bb6290e3 | 929 | bool wxApp::ProcessIdle() |
2bda0e17 KB |
930 | { |
931 | wxIdleEvent event; | |
932 | event.SetEventObject(this); | |
933 | ProcessEvent(event); | |
934 | ||
935 | return event.MoreRequested(); | |
936 | } | |
937 | ||
bb6290e3 | 938 | void wxApp::ExitMainLoop() |
2bda0e17 | 939 | { |
b6c588e1 | 940 | // VZ: why not ::PostQuitMessage()? |
e5c0b16a | 941 | m_keepGoing = FALSE; |
2bda0e17 KB |
942 | } |
943 | ||
bb6290e3 | 944 | bool wxApp::Pending() |
2bda0e17 | 945 | { |
b6c588e1 | 946 | return ::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) != 0; |
2bda0e17 KB |
947 | } |
948 | ||
bb6290e3 | 949 | void wxApp::Dispatch() |
2bda0e17 | 950 | { |
bee503b0 | 951 | DoMessage(); |
2bda0e17 KB |
952 | } |
953 | ||
954 | /* | |
955 | * Give all windows a chance to preprocess | |
956 | * the message. Some may have accelerator tables, or have | |
957 | * MDI complications. | |
958 | */ | |
2a47d3c1 | 959 | |
d3f0a137 | 960 | bool wxApp::ProcessMessage(WXMSG *wxmsg) |
2bda0e17 | 961 | { |
d3f0a137 VZ |
962 | MSG *msg = (MSG *)wxmsg; |
963 | HWND hWnd = msg->hwnd; | |
8614c467 | 964 | wxWindow *wndThis = wxGetWindowFromHWND((WXHWND)hWnd); |
2bda0e17 | 965 | |
8614c467 VZ |
966 | #if wxUSE_TOOLTIPS |
967 | // we must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to | |
968 | // popup the tooltip bubbles | |
969 | if ( wndThis && (msg->message == WM_MOUSEMOVE) ) | |
834362a2 | 970 | { |
8614c467 VZ |
971 | wxToolTip *tt = wndThis->GetToolTip(); |
972 | if ( tt ) | |
973 | { | |
974 | tt->RelayEvent(wxmsg); | |
975 | } | |
834362a2 | 976 | } |
8614c467 | 977 | #endif // wxUSE_TOOLTIPS |
834362a2 | 978 | |
e5c0b16a VZ |
979 | // Try translations first; find the youngest window with |
980 | // a translation table. | |
8614c467 | 981 | wxWindow *wnd; |
d3f0a137 | 982 | for ( wnd = wndThis; wnd; wnd = wnd->GetParent() ) |
2bda0e17 | 983 | { |
d3f0a137 VZ |
984 | if ( wnd->MSWTranslateMessage(wxmsg) ) |
985 | return TRUE; | |
2bda0e17 | 986 | } |
2bda0e17 | 987 | |
e5c0b16a | 988 | // Anyone for a non-translation message? Try youngest descendants first. |
d3f0a137 | 989 | for ( wnd = wndThis; wnd; wnd = wnd->GetParent() ) |
57a7b7c1 | 990 | { |
d3f0a137 VZ |
991 | if ( wnd->MSWProcessMessage(wxmsg) ) |
992 | return TRUE; | |
57a7b7c1 | 993 | } |
d3f0a137 | 994 | |
e5c0b16a | 995 | return FALSE; |
2bda0e17 KB |
996 | } |
997 | ||
998 | void wxApp::OnIdle(wxIdleEvent& event) | |
999 | { | |
3222fde2 | 1000 | static bool s_inOnIdle = FALSE; |
2bda0e17 | 1001 | |
3222fde2 VZ |
1002 | // Avoid recursion (via ProcessEvent default case) |
1003 | if ( s_inOnIdle ) | |
1004 | return; | |
2bda0e17 | 1005 | |
3222fde2 | 1006 | s_inOnIdle = TRUE; |
2bda0e17 | 1007 | |
52e52bea GRG |
1008 | // If there are pending events, we must process them: pending events |
1009 | // are either events to the threads other than main or events posted | |
1010 | // with wxPostEvent() functions | |
1011 | // GRG: I have moved this here so that all pending events are processed | |
1012 | // before starting to delete any objects. This behaves better (in | |
1013 | // particular, wrt wxPostEvent) and is coherent with wxGTK's current | |
1014 | // behaviour. Changed Feb/2000 before 2.1.14 | |
1015 | ProcessPendingEvents(); | |
1016 | ||
3222fde2 VZ |
1017 | // 'Garbage' collection of windows deleted with Close(). |
1018 | DeletePendingObjects(); | |
2bda0e17 | 1019 | |
546db2a8 | 1020 | #if wxUSE_LOG |
3222fde2 VZ |
1021 | // flush the logged messages if any |
1022 | wxLog *pLog = wxLog::GetActiveTarget(); | |
1023 | if ( pLog != NULL && pLog->HasPendingMessages() ) | |
1024 | pLog->Flush(); | |
546db2a8 | 1025 | #endif // wxUSE_LOG |
c54f78a2 | 1026 | |
3222fde2 VZ |
1027 | // Send OnIdle events to all windows |
1028 | if ( SendIdleEvents() ) | |
1029 | { | |
1030 | // SendIdleEvents() returns TRUE if at least one window requested more | |
1031 | // idle events | |
1032 | event.RequestMore(TRUE); | |
1033 | } | |
2bda0e17 | 1034 | |
3222fde2 | 1035 | s_inOnIdle = FALSE; |
2bda0e17 KB |
1036 | } |
1037 | ||
1038 | // Send idle event to all top-level windows | |
bb6290e3 | 1039 | bool wxApp::SendIdleEvents() |
2bda0e17 KB |
1040 | { |
1041 | bool needMore = FALSE; | |
e146b8c8 | 1042 | |
f1d534df | 1043 | wxWindowList::Node* node = wxTopLevelWindows.GetFirst(); |
3222fde2 VZ |
1044 | while (node) |
1045 | { | |
e146b8c8 | 1046 | wxWindow* win = node->GetData(); |
3222fde2 | 1047 | if (SendIdleEvents(win)) |
2bda0e17 | 1048 | needMore = TRUE; |
e146b8c8 | 1049 | node = node->GetNext(); |
3222fde2 VZ |
1050 | } |
1051 | ||
2bda0e17 KB |
1052 | return needMore; |
1053 | } | |
1054 | ||
1055 | // Send idle event to window and all subwindows | |
1056 | bool wxApp::SendIdleEvents(wxWindow* win) | |
1057 | { | |
e5c0b16a | 1058 | bool needMore = FALSE; |
2bda0e17 | 1059 | |
e5c0b16a VZ |
1060 | wxIdleEvent event; |
1061 | event.SetEventObject(win); | |
1062 | win->GetEventHandler()->ProcessEvent(event); | |
2bda0e17 | 1063 | |
e5c0b16a VZ |
1064 | if (event.MoreRequested()) |
1065 | needMore = TRUE; | |
2bda0e17 | 1066 | |
e5c0b16a VZ |
1067 | wxNode* node = win->GetChildren().First(); |
1068 | while (node) | |
1069 | { | |
1070 | wxWindow* win = (wxWindow*) node->Data(); | |
1071 | if (SendIdleEvents(win)) | |
1072 | needMore = TRUE; | |
2bda0e17 | 1073 | |
e5c0b16a VZ |
1074 | node = node->Next(); |
1075 | } | |
42e69d6b | 1076 | return needMore; |
2bda0e17 KB |
1077 | } |
1078 | ||
bb6290e3 | 1079 | void wxApp::DeletePendingObjects() |
2bda0e17 | 1080 | { |
e5c0b16a VZ |
1081 | wxNode *node = wxPendingDelete.First(); |
1082 | while (node) | |
1083 | { | |
1084 | wxObject *obj = (wxObject *)node->Data(); | |
d50b2a58 | 1085 | |
e5c0b16a | 1086 | delete obj; |
2bda0e17 | 1087 | |
e5c0b16a VZ |
1088 | if (wxPendingDelete.Member(obj)) |
1089 | delete node; | |
2bda0e17 | 1090 | |
e5c0b16a VZ |
1091 | // Deleting one object may have deleted other pending |
1092 | // objects, so start from beginning of list again. | |
1093 | node = wxPendingDelete.First(); | |
1094 | } | |
2bda0e17 KB |
1095 | } |
1096 | ||
57c208c5 | 1097 | void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event)) |
387a3b02 JS |
1098 | { |
1099 | if (GetTopWindow()) | |
1100 | GetTopWindow()->Close(TRUE); | |
1101 | } | |
1102 | ||
1103 | // Default behaviour: close the application with prompts. The | |
1104 | // user can veto the close, and therefore the end session. | |
1105 | void wxApp::OnQueryEndSession(wxCloseEvent& event) | |
1106 | { | |
1107 | if (GetTopWindow()) | |
1108 | { | |
1109 | if (!GetTopWindow()->Close(!event.CanVeto())) | |
1110 | event.Veto(TRUE); | |
1111 | } | |
1112 | } | |
1113 | ||
6d167489 VZ |
1114 | /* static */ |
1115 | int wxApp::GetComCtl32Version() | |
1116 | { | |
6d167489 | 1117 | // cache the result |
bdc72a22 VZ |
1118 | static int s_verComCtl32 = -1; |
1119 | ||
1120 | wxCRIT_SECT_DECLARE(csComCtl32); | |
1121 | wxCRIT_SECT_LOCKER(lock, csComCtl32); | |
6d167489 VZ |
1122 | |
1123 | if ( s_verComCtl32 == -1 ) | |
1124 | { | |
bdc72a22 | 1125 | // initally assume no comctl32.dll at all |
6d167489 VZ |
1126 | s_verComCtl32 = 0; |
1127 | ||
bdc72a22 VZ |
1128 | // do we have it? |
1129 | HMODULE hModuleComCtl32 = ::GetModuleHandle(wxT("COMCTL32")); | |
6d167489 VZ |
1130 | |
1131 | // if so, then we can check for the version | |
bdc72a22 | 1132 | if ( hModuleComCtl32 ) |
bb6290e3 | 1133 | { |
bdc72a22 VZ |
1134 | // try to use DllGetVersion() if available in _headers_ |
1135 | #ifdef DLLVER_PLATFORM_WINDOWS // defined in shlwapi.h | |
1136 | DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC) | |
1137 | ::GetProcAddress(hModuleComCtl32, _T("DllGetVersion")); | |
1138 | if ( pfnDllGetVersion ) | |
6d167489 | 1139 | { |
bdc72a22 VZ |
1140 | DLLVERSIONINFO dvi; |
1141 | dvi.cbSize = sizeof(dvi); | |
1142 | ||
1143 | HRESULT hr = (*pfnDllGetVersion)(&dvi); | |
1144 | if ( FAILED(hr) ) | |
1145 | { | |
1146 | wxLogApiError(_T("DllGetVersion"), hr); | |
1147 | } | |
1148 | else | |
1149 | { | |
1150 | // this is incompatible with _WIN32_IE values, but | |
1151 | // compatible with the other values returned by | |
1152 | // GetComCtl32Version() | |
1153 | s_verComCtl32 = 100*dvi.dwMajorVersion + | |
1154 | dvi.dwMinorVersion; | |
1155 | } | |
6d167489 | 1156 | } |
bdc72a22 VZ |
1157 | #endif |
1158 | // DllGetVersion() unavailable either during compile or | |
1159 | // run-time, try to guess the version otherwise | |
1160 | if ( !s_verComCtl32 ) | |
1161 | { | |
1162 | // InitCommonControlsEx is unique to 4.70 and later | |
1163 | FARPROC theProc = ::GetProcAddress | |
1164 | ( | |
1165 | hModuleComCtl32, | |
a8ee71c7 OK |
1166 | #if defined(__BORLANDC__) && (__BORLANDC__ <= 0x520) |
1167 | "InitCommonControlsEx" | |
1168 | #else | |
bdc72a22 | 1169 | _T("InitCommonControlsEx") |
a8ee71c7 | 1170 | #endif |
bdc72a22 VZ |
1171 | ); |
1172 | ||
1173 | if ( !theProc ) | |
1174 | { | |
1175 | // not found, must be 4.00 | |
1176 | s_verComCtl32 = 400; | |
1177 | } | |
1178 | else | |
1179 | { | |
1180 | // many symbols appeared in comctl32 4.71, could use | |
1181 | // any of them except may be DllInstall | |
1182 | theProc = ::GetProcAddress | |
1183 | ( | |
1184 | hModuleComCtl32, | |
a8ee71c7 OK |
1185 | #if defined(__BORLANDC__) && (__BORLANDC__ <= 0x520) |
1186 | "InitializeFlatSB" | |
1187 | #else | |
bdc72a22 | 1188 | _T("InitializeFlatSB") |
a8ee71c7 | 1189 | #endif |
bdc72a22 VZ |
1190 | ); |
1191 | if ( !theProc ) | |
1192 | { | |
1193 | // not found, must be 4.70 | |
1194 | s_verComCtl32 = 470; | |
1195 | } | |
1196 | else | |
1197 | { | |
1198 | // found, must be 4.71 | |
1199 | s_verComCtl32 = 471; | |
1200 | } | |
1201 | } | |
6d167489 | 1202 | } |
bb6290e3 JS |
1203 | } |
1204 | } | |
6d167489 VZ |
1205 | |
1206 | return s_verComCtl32; | |
bb6290e3 JS |
1207 | } |
1208 | ||
1209 | void wxExit() | |
2bda0e17 | 1210 | { |
e5c0b16a VZ |
1211 | wxLogError(_("Fatal error: exiting")); |
1212 | ||
1213 | wxApp::CleanUp(); | |
2bda0e17 KB |
1214 | } |
1215 | ||
1216 | // Yield to incoming messages | |
bb6290e3 | 1217 | bool wxYield() |
2bda0e17 | 1218 | { |
8e193f38 VZ |
1219 | // we don't want to process WM_QUIT from here - it should be processed in |
1220 | // the main event loop in order to stop it | |
1221 | ||
e5c0b16a | 1222 | MSG msg; |
8e193f38 VZ |
1223 | while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) && |
1224 | msg.message != WM_QUIT ) | |
e5c0b16a | 1225 | { |
5b615ed8 VZ |
1226 | #if wxUSE_THREADS |
1227 | wxMutexGuiLeaveOrEnter(); | |
1228 | #endif // wxUSE_THREADS | |
1229 | ||
e5c0b16a VZ |
1230 | if ( !wxTheApp->DoMessage() ) |
1231 | break; | |
1232 | } | |
8e193f38 | 1233 | |
aadbdf11 | 1234 | // If they are pending events, we must process them. |
6a2f3103 | 1235 | wxTheApp->ProcessPendingEvents(); |
e5c0b16a VZ |
1236 | |
1237 | return TRUE; | |
2bda0e17 | 1238 | } |
094637f6 | 1239 | |
9779893b RD |
1240 | //----------------------------------------------------------------------------- |
1241 | // wxWakeUpIdle | |
1242 | //----------------------------------------------------------------------------- | |
1243 | ||
1244 | void wxWakeUpIdle() | |
1245 | { | |
1246 | // Send the top window a dummy message so idle handler processing will | |
1247 | // start up again. Doing it this way ensures that the idle handler | |
b568d04f VZ |
1248 | // wakes up in the right thread (see also wxWakeUpMainThread() which does |
1249 | // the same for the main app thread only) | |
9779893b | 1250 | wxWindow *topWindow = wxTheApp->GetTopWindow(); |
b568d04f VZ |
1251 | if ( topWindow ) |
1252 | { | |
1253 | if ( !::PostMessage(GetHwndOf(topWindow), WM_NULL, 0, 0) ) | |
1254 | { | |
1255 | // should never happen | |
1256 | wxLogLastError("PostMessage(WM_NULL)"); | |
1257 | } | |
9779893b RD |
1258 | } |
1259 | } | |
1260 | ||
1261 | //----------------------------------------------------------------------------- | |
1262 | ||
ebea0891 KB |
1263 | wxIcon |
1264 | wxApp::GetStdIcon(int which) const | |
1265 | { | |
094637f6 VZ |
1266 | switch(which) |
1267 | { | |
1268 | case wxICON_INFORMATION: | |
1269 | return wxIcon("wxICON_INFO"); | |
1270 | ||
1271 | case wxICON_QUESTION: | |
1272 | return wxIcon("wxICON_QUESTION"); | |
1273 | ||
1274 | case wxICON_EXCLAMATION: | |
1275 | return wxIcon("wxICON_WARNING"); | |
1276 | ||
1277 | default: | |
223d09f6 | 1278 | wxFAIL_MSG(wxT("requested non existent standard icon")); |
094637f6 VZ |
1279 | // still fall through |
1280 | ||
1281 | case wxICON_HAND: | |
1282 | return wxIcon("wxICON_ERROR"); | |
1283 | } | |
ebea0891 KB |
1284 | } |
1285 | ||
2bda0e17 KB |
1286 | // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly |
1287 | // if in a separate file. So include it here to ensure it's linked. | |
31e78e0c | 1288 | #if (defined(__VISUALC__) && !defined(__WIN32__)) || (defined(__GNUWIN32__) && !defined(__TWIN32__) && !defined(WXMAKINGDLL)) |
e5c0b16a | 1289 | #include "main.cpp" |
2bda0e17 | 1290 | #endif |