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