#include <string.h>
#include <ctype.h>
-#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__))
+#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__) || defined(__WXMICROWIN__)) && !defined(__CYGWIN10__))
#include <commctrl.h>
#endif
+#ifndef __WXMICROWIN__
#include "wx/msw/msvcrt.h"
+#endif
// ----------------------------------------------------------------------------
// conditional compilation
#define _WIN32_IE 0x0200
#endif
-#if _WIN32_IE >= 0x0300
+#if _WIN32_IE >= 0x0300 && !defined(__MINGW32__)
#include <shlwapi.h>
#endif
extern wxChar *wxBuffer;
extern wxList *wxWinHandleList;
extern wxList WXDLLEXPORT wxPendingDelete;
+#ifndef __WXMICROWIN__
extern void wxSetKeyboardHook(bool doIt);
+#endif
MSG s_currentMsg;
wxApp *wxTheApp = NULL;
wxBitmap::InitStandardHandlers();
-#if defined(__WIN95__)
+#if defined(__WIN95__) && !defined(__WXMICROWIN__)
InitCommonControls();
-
#endif // __WIN95__
-#if wxUSE_OLE
+#if wxUSE_OLE || wxUSE_DRAG_AND_DROP
#ifdef __WIN16__
// for OLE, enlarge message queue to be as large as possible
while (!SetMessageQueue(iMsg) && (iMsg -= 8))
;
#endif // Win16
+
// we need to initialize OLE library
if ( FAILED(::OleInitialize(NULL)) )
wxLogError(_("Cannot initialize OLE"));
+
#endif // wxUSE_OLE
#if wxUSE_CTL3D
wxLogError(wxT("Cannot register CTL3D"));
Ctl3dAutoSubclass(wxhInstance);
-#endif
+#endif // wxUSE_CTL3D
// VZ: these icons are not in wx.rc anyhow (but should they?)!
#if 0
RegisterWindowClasses();
+#ifndef __WXMICROWIN__
// Create the brush for disabling bitmap buttons
LOGBRUSH lb;
::DeleteObject( (HGDIOBJ)lb.lbHatch );
}
//else: wxWindows resources are probably not linked in
+#endif
#if wxUSE_PENWINDOWS
wxRegisterPenWin();
if (wxDummyChar) wxDummyChar++;
#endif
+#ifndef __WXMICROWIN__
wxSetKeyboardHook(TRUE);
+#endif
wxModule::RegisterModules();
if (!wxModule::InitializeModules())
return TRUE;
}
+// ---------------------------------------------------------------------------
+// UnregisterWindowClasses
+// ---------------------------------------------------------------------------
+
+bool wxApp::UnregisterWindowClasses()
+{
+ bool retval = TRUE;
+
+ // frame window class.
+ if ( !UnregisterClass(wxFrameClassName, wxhInstance) )
+ {
+ wxLogLastError(wxT("UnregisterClass(frame)"));
+
+ retval = FALSE;
+ }
+
+ // "no redraw" frame
+ if ( !UnregisterClass(wxFrameClassNameNoRedraw, wxhInstance) )
+ {
+ wxLogLastError(wxT("UnregisterClass(no redraw frame)"));
+
+ return FALSE;
+ }
+
+ // MDI frame window class.
+ if ( !UnregisterClass(wxMDIFrameClassName, wxhInstance) )
+ {
+ wxLogLastError(wxT("UnregisterClass(MDI parent)"));
+
+ retval = FALSE;
+ }
+
+ // "no redraw" MDI frame
+ if ( !UnregisterClass(wxMDIFrameClassNameNoRedraw, wxhInstance) )
+ {
+ wxLogLastError(wxT("UnregisterClass(no redraw MDI parent frame)"));
+
+ retval = FALSE;
+ }
+
+ // MDI child frame window class.
+ if ( !UnregisterClass(wxMDIChildFrameClassName, wxhInstance) )
+ {
+ wxLogLastError(wxT("UnregisterClass(MDI child)"));
+
+ retval = FALSE;
+ }
+
+ // "no redraw" MDI child frame
+ if ( !UnregisterClass(wxMDIChildFrameClassNameNoRedraw, wxhInstance) )
+ {
+ wxLogLastError(wxT("UnregisterClass(no redraw MDI child)"));
+
+ retval = FALSE;
+ }
+
+ // panel window class.
+ if ( !UnregisterClass(wxPanelClassName, wxhInstance) )
+ {
+ wxLogLastError(wxT("UnregisterClass(panel)"));
+
+ retval = FALSE;
+ }
+
+ // no redraw panel window class.
+ if ( !UnregisterClass(wxPanelClassNameNR, wxhInstance) )
+ {
+ wxLogLastError(wxT("UnregisterClass(no redraw panel)"));
+
+ retval = FALSE;
+ }
+
+ // canvas and textsubwindow class name
+ if ( !UnregisterClass(wxCanvasClassName, wxhInstance) )
+ {
+ wxLogLastError(wxT("UnregisterClass(canvas)"));
+
+ retval = FALSE;
+ }
+
+ if ( !UnregisterClass(wxCanvasClassNameNR, wxhInstance) )
+ {
+ wxLogLastError(wxT("UnregisterClass(no redraw canvas)"));
+
+ retval = FALSE;
+ }
+
+ return retval;
+}
+
// ---------------------------------------------------------------------------
// Convert Windows to argc, argv style
// ---------------------------------------------------------------------------
//// WINDOWS-SPECIFIC CLEANUP
+#ifndef __WXMICROWIN__
wxSetKeyboardHook(FALSE);
+#endif
#if wxUSE_PENWINDOWS
wxCleanUpPenWin();
::OleUninitialize();
#endif
+#ifdef WXMAKINGDLL
+ // for an EXE the classes are unregistered when it terminates but DLL may
+ // be loaded several times (load/unload/load) into the same process in
+ // which case the registration will fail after the first time if we don't
+ // unregister the classes now
+ UnregisterWindowClasses();
+#endif // WXMAKINGDLL
+
#if wxUSE_CTL3D
Ctl3dUnregister(wxhInstance);
#endif
// GL: I'm annoyed ... I don't know where to put this and I don't want to
// create a module for that as it's part of the core.
delete wxPendingEvents;
+
#if wxUSE_THREADS
delete wxPendingEventsLocker;
- // If we don't do the following, we get an apparent memory leak.
+ // If we don't do the following, we get an apparent memory leak
+#if wxUSE_VALIDATORS
((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
-#endif
+#endif // wxUSE_VALIDATORS
+#endif // wxUSE_THREADS
wxClassInfo::CleanUpClasses();
int WXDLLEXPORT wxEntryInitGui()
{
- wxTheApp->OnInitGui();
- return 0;
+ return wxTheApp->OnInitGui();
}
void WXDLLEXPORT wxEntryCleanup()
// do check for memory leaks on program exit
// (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
// deallocated memory which may be used to simulate low-memory condition)
+#ifndef __WXMICROWIN__
wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
+#endif
+
#ifdef __MWERKS__
#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
// This seems to be necessary since there are 'rogue'
wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
wxT("No initializer - use IMPLEMENT_APP macro.") );
- wxTheApp = (*wxApp::GetInitializerFunction()) ();
+ wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) ();
}
wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
wxTheApp->ConvertToStandardCommandArgs(lpCmdLine);
wxTheApp->m_nCmdShow = nCmdShow;
- // GUI-specific initialisation. In fact on Windows we don't have any,
- // but this call is provided for compatibility across platforms.
- wxEntryInitGui();
-
// We really don't want timestamps by default, because it means
// we can't simply double-click on the error message and get to that
// line in the source. So VC++ at least, let's have a sensible default.
int retValue = 0;
- if ( wxTheApp->OnInit() )
+ // it is common to create a modal dialog in OnInit() (to ask/notify the
+ // user about something) but it wouldn't work if we don't change the
+ // "exit on delete last frame" flag here as when this dialog is
+ // deleted, the app would terminate (it was the last top level window
+ // as the main frame wasn't created yet!), so disable this behaviour
+ // temproarily
+ bool exitOnLastFrameDelete = wxTheApp->GetExitOnFrameDelete();
+ wxTheApp->SetExitOnFrameDelete(FALSE);
+
+ // init the app
+ retValue = wxEntryInitGui() && wxTheApp->OnInit() ? 0 : -1;
+
+ // restore the old flag value
+ wxTheApp->SetExitOnFrameDelete(exitOnLastFrameDelete);
+
+ if ( retValue == 0 )
{
if ( enterLoop )
{
+ // run the main loop
retValue = wxTheApp->OnRun();
}
else
- // We want to initialize, but not run or exit immediately.
+ {
+ // we want to initialize, but not run or exit immediately.
return 1;
+ }
}
//else: app initialization failed, so we skipped OnRun()
wxApp::wxApp()
{
- m_topWindow = NULL;
- wxTheApp = this;
- m_wantDebugOutput = TRUE;
-
argc = 0;
argv = NULL;
m_printMode = wxPRINT_WINDOWS;
- m_exitOnFrameDelete = TRUE;
m_auto3D = TRUE;
}
#endif // wxUSE_THREADS
// Process the message
- if ( !ProcessMessage((WXMSG *)&s_currentMsg) )
- {
- ::TranslateMessage(&s_currentMsg);
- ::DispatchMessage(&s_currentMsg);
- }
+ DoMessage((WXMSG *)&s_currentMsg);
}
return TRUE;
}
+void wxApp::DoMessage(WXMSG *pMsg)
+{
+ if ( !ProcessMessage(pMsg) )
+ {
+ ::TranslateMessage((MSG *)pMsg);
+ ::DispatchMessage((MSG *)pMsg);
+ }
+}
+
/*
* Keep trying to process messages until WM_QUIT
* received.
bool wxApp::ProcessMessage(WXMSG *wxmsg)
{
MSG *msg = (MSG *)wxmsg;
- HWND hWnd = msg->hwnd;
- wxWindow *wndThis = wxGetWindowFromHWND((WXHWND)hWnd);
+ HWND hwnd = msg->hwnd;
+ wxWindow *wndThis = wxGetWindowFromHWND((WXHWND)hwnd);
+
+ // this may happen if the event occured in a standard modeless dialog (the
+ // only example of which I know of is the find/replace dialog) - then call
+ // IsDialogMessage() to make TAB navigation in it work
+ if ( !wndThis )
+ {
+ // we need to find the dialog containing this control as
+ // IsDialogMessage() just eats all the messages (i.e. returns TRUE for
+ // them) if we call it for the control itself
+ while ( hwnd && ::GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD )
+ {
+ hwnd = ::GetParent(hwnd);
+ }
+
+ return hwnd && ::IsDialogMessage(hwnd, msg) != 0;
+ }
#if wxUSE_TOOLTIPS
// we must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
// popup the tooltip bubbles
- if ( wndThis && (msg->message == WM_MOUSEMOVE) )
+ if ( (msg->message == WM_MOUSEMOVE) )
{
wxToolTip *tt = wndThis->GetToolTip();
if ( tt )
}
#endif // wxUSE_TOOLTIPS
- // Try translations first; find the youngest window with
- // a translation table.
+ // allow the window to prevent certain messages from being
+ // translated/processed (this is currently used by wxTextCtrl to always
+ // grab Ctrl-C/V/X, even if they are also accelerators in some parent)
+ if ( !wndThis->MSWShouldPreProcessMessage(wxmsg) )
+ {
+ return FALSE;
+ }
+
+ // try translations first: the accelerators override everything
wxWindow *wnd;
for ( wnd = wndThis; wnd; wnd = wnd->GetParent() )
{
- if ( wnd->MSWTranslateMessage(wxmsg) )
+ if ( wnd->MSWTranslateMessage(wxmsg))
return TRUE;
+
+ // stop at first top level window, i.e. don't try to process the key
+ // strokes originating in a dialog using the accelerators of the parent
+ // frame - this doesn't make much sense
+ if ( wnd->IsTopLevel() )
+ break;
}
- // Anyone for a non-translation message? Try youngest descendants first.
- for ( wnd = wndThis; wnd; wnd = wnd->GetParent() )
+ // now try the other hooks (kbd navigation is handled here): we start from
+ // wndThis->GetParent() because wndThis->MSWProcessMessage() was already
+ // called above
+ for ( wnd = wndThis->GetParent(); wnd; wnd = wnd->GetParent() )
{
if ( wnd->MSWProcessMessage(wxmsg) )
return TRUE;
}
+ // no special preprocessing for this message, dispatch it normally
return FALSE;
}
wxLog::FlushActive();
#endif // wxUSE_LOG
+#if wxUSE_DC_CACHEING
+ // automated DC cache management: clear the cached DCs and bitmap
+ // if it's likely that the app has finished with them, that is, we
+ // get an idle event and we're not dragging anything.
+ if (!::GetKeyState(MK_LBUTTON) && !::GetKeyState(MK_MBUTTON) && !::GetKeyState(MK_RBUTTON))
+ wxDC::ClearCache();
+#endif // wxUSE_DC_CACHEING
+
// Send OnIdle events to all windows
if ( SendIdleEvents() )
{
/* static */
int wxApp::GetComCtl32Version()
{
+#ifdef __WXMICROWIN__
+ return 0;
+#else
// cache the result
static int s_verComCtl32 = -1;
}
return s_verComCtl32;
+#endif
}
void wxExit()
}
// Yield to incoming messages
+
+static bool gs_inYield = FALSE;
+
bool wxYield()
{
// disable log flushing from here because a call to wxYield() shouldn't
// normally result in message boxes popping up &c
wxLog::Suspend();
+#ifdef __WXDEBUG__
+ if (gs_inYield)
+ wxFAIL_MSG( wxT("wxYield called recursively" ) );
+#endif
+
+ gs_inYield = TRUE;
+
// we don't want to process WM_QUIT from here - it should be processed in
// the main event loop in order to stop it
MSG msg;
// let the logs be flashed again
wxLog::Resume();
+ gs_inYield = FALSE;
+
return TRUE;
}
+// Yield to incoming messages; but fail silently if recursion is detected.
+bool wxYieldIfNeeded()
+{
+ if (gs_inYield)
+ return FALSE;
+
+ return wxYield();
+}
+
bool wxHandleFatalExceptions(bool doit)
{
#if wxUSE_ON_FATAL_EXCEPTION
return TRUE;
#else
wxFAIL_MSG(_T("set wxUSE_ON_FATAL_EXCEPTION to 1 to sue this function"));
-
+
+ (void)doit;
return FALSE;
#endif
}