X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2646f485163f410baaad5bcf49028c604a352d19..b4446c244775324631b8dd2b588ea35f32e71728:/src/mac/classic/app.cpp diff --git a/src/mac/classic/app.cpp b/src/mac/classic/app.cpp index 613c323b92..6670bde5cc 100644 --- a/src/mac/classic/app.cpp +++ b/src/mac/classic/app.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: app.cpp +// Name: src/mac/classic/app.cpp // Purpose: wxApp // Author: Stefan Csomor // Modified by: @@ -9,33 +9,37 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "app.h" -#endif +#include "wx/wxprec.h" -#include "wx/defs.h" +#ifdef __BORLANDC__ + #pragma hdrstop +#endif -#include "wx/window.h" -#include "wx/frame.h" -#include "wx/button.h" #include "wx/app.h" -#include "wx/utils.h" + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/log.h" + #include "wx/utils.h" + #include "wx/window.h" + #include "wx/frame.h" + #include "wx/dc.h" + #include "wx/button.h" + #include "wx/menu.h" + #include "wx/pen.h" + #include "wx/brush.h" + #include "wx/palette.h" + #include "wx/icon.h" + #include "wx/cursor.h" + #include "wx/dialog.h" + #include "wx/msgdlg.h" +#endif + #include "wx/gdicmn.h" -#include "wx/pen.h" -#include "wx/brush.h" -#include "wx/cursor.h" -#include "wx/intl.h" -#include "wx/icon.h" -#include "wx/palette.h" -#include "wx/dc.h" -#include "wx/dialog.h" -#include "wx/msgdlg.h" -#include "wx/log.h" #include "wx/module.h" #include "wx/memory.h" #include "wx/tooltip.h" #include "wx/textctrl.h" -#include "wx/menu.h" #include "wx/docview.h" #include "wx/filename.h" @@ -76,24 +80,21 @@ extern size_t g_numberOfThreads; // statics for implementation -static bool s_inYield = FALSE; +static bool s_inYield = false; #if TARGET_CARBON -static bool s_inReceiveEvent = FALSE ; +static bool s_inReceiveEvent = false ; static EventTime sleepTime = kEventDurationNoWait ; #else static long sleepTime = 0 ; #endif -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) EVT_IDLE(wxApp::OnIdle) EVT_END_SESSION(wxApp::OnEndSession) EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession) END_EVENT_TABLE() -#endif - const short kMacMinHeap = (29 * 1024) ; // platform specific static variables @@ -236,7 +237,7 @@ short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNU { wxCommandEvent exitEvent(wxEVT_COMMAND_MENU_SELECTED, s_macExitMenuItemId); if (!win->ProcessEvent(exitEvent)) - win->Close(TRUE ) ; + win->Close(true) ; } else { @@ -280,7 +281,7 @@ void wxApp::MacPrintFile(const wxString & fileName ) if (printout) { wxPrinter printer; - printer.Print(view->GetFrame(), printout, TRUE); + printer.Print(view->GetFrame(), printout, true); delete printout; } } @@ -335,17 +336,17 @@ static pascal OSStatus MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar(); - + if ( mbar ) { wxFrame* win = mbar->GetFrame(); if ( win ) { - + // VZ: we could find the menu from its handle here by examining all // the menus in the menu bar recursively but knowing that neither // wxMSW nor wxGTK do it why bother... - #if 0 +#if 0 MenuRef menuRef; GetEventParameter(event, @@ -353,9 +354,9 @@ MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) typeMenuRef, NULL, sizeof(menuRef), NULL, &menuRef); - #endif // 0 +#endif // 0 - wxEventType type=0; + wxEventType type=0; MenuCommand cmd=0; switch (GetEventKind(event)) { @@ -387,9 +388,9 @@ MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) return eventNotHandledErr; } -// due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop +// due to the rather low-level event API of wxWidgets, we cannot use RunApplicationEventLoop // but have to use ReceiveNextEvent dealing with events manually, therefore we also have -// deal with clicks in the menu bar explicitely +// to deal with clicks in the menu bar explicitly pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ; @@ -636,7 +637,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv) UMAShowArrowCursor() ; ParamText("\pFatal Error", message, (ConstStr255Param)"\p", (ConstStr255Param)"\p"); itemHit = Alert(128, nil); - return FALSE ; + return false ; } #ifndef __DARWIN__ @@ -742,7 +743,7 @@ bool wxApp::OnInitGui() #endif } - return TRUE ; + return true ; } void wxApp::CleanUp() @@ -841,15 +842,15 @@ void wxStAppResource::OpenSharedLibraryResource(const void *initBlock) NSModule theModule; const char *theLibPath; - gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows")); + gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWidgets")); if (gSharedLibraryBundle != NULL) { - // wxWindows has been bundled into a framework + // wxWidgets has been bundled into a framework // load the framework resources gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle); } else { - // wxWindows is a simple dynamic shared library + // wxWidgets is a simple dynamic shared library // load the resources from the data fork of a separate resource file wxString theResPath; wxString theName; @@ -1076,18 +1077,18 @@ pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , Even wxApp::wxApp() { - m_printMode = wxPRINT_WINDOWS; - m_auto3D = TRUE; + m_printMode = wxPRINT_WINDOWS; + m_auto3D = true; - m_macCurrentEvent = NULL ; + m_macCurrentEvent = NULL ; #if TARGET_CARBON - m_macCurrentEventHandlerCallRef = NULL ; + m_macCurrentEventHandlerCallRef = NULL ; #endif } int wxApp::MainLoop() { - m_keepGoing = TRUE; + m_keepGoing = true; while (m_keepGoing) { @@ -1099,7 +1100,7 @@ int wxApp::MainLoop() void wxApp::ExitMainLoop() { - m_keepGoing = FALSE; + m_keepGoing = false; } // Is a message/event pending? @@ -1109,7 +1110,7 @@ bool wxApp::Pending() // without the receive event (with pull param = false ) nothing is ever reported EventRef theEvent; ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, &theEvent); - return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ; + return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ; #else EventRecord event ; @@ -1152,7 +1153,7 @@ void wxApp::Exit() void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event)) { if (GetTopWindow()) - GetTopWindow()->Close(TRUE); + GetTopWindow()->Close(true); } // Default behaviour: close the application with prompts. The @@ -1162,7 +1163,7 @@ void wxApp::OnQueryEndSession(wxCloseEvent& event) if (GetTopWindow()) { if (!GetTopWindow()->Close(!event.CanVeto())) - event.Veto(TRUE); + event.Veto(true); } } @@ -1183,10 +1184,10 @@ bool wxApp::Yield(bool onlyIfNeeded) wxFAIL_MSG( wxT("wxYield called recursively" ) ); } - return FALSE; + return false; } - s_inYield = TRUE; + s_inYield = true; #if wxUSE_THREADS YieldToAnyThread() ; @@ -1237,9 +1238,9 @@ bool wxApp::Yield(bool onlyIfNeeded) #endif wxMacProcessNotifierAndPendingEvents() ; - s_inYield = FALSE; + s_inYield = false; - return TRUE; + return true; } // platform specifics @@ -1388,7 +1389,7 @@ void wxApp::MacDoOneEvent() /*virtual*/ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr ) { - // Override to process unhandled events as you please + // Override to process unhandled events as you please } void wxApp::MacHandleOneEvent( WXEVENTREF evr ) @@ -1479,7 +1480,7 @@ void wxApp::MacHandleModifierEvents( WXEVENTREF evr ) event.m_x = ev->where.h; event.m_y = ev->where.v; - event.m_timeStamp = ev->when; + event.SetTimestamp( ev->when ); wxWindow* focus = wxWindow::FindFocus() ; event.SetEventObject(focus); @@ -1515,7 +1516,7 @@ void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr ) { // we must avoid reentrancy problems when processing high level events eg printing bool former = s_inYield ; - s_inYield = TRUE ; + s_inYield = true ; EventRecord* ev = (EventRecord*) evr ; ::AEProcessAppleEvent( ev ) ; s_inYield = former ; @@ -1533,7 +1534,7 @@ void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr ) ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ; short windowPart = ::FindWindow(ev->where, &window); - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) window ) ; if ( wxPendingDelete.Member(win) ) return ; @@ -1707,7 +1708,7 @@ void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr ) break ; default: { - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) window ) ; if ( win ) win->MacMouseUp( ev , windowPart ) ; } @@ -1853,20 +1854,12 @@ int wxKeyCodeToMacModifier(wxKeyCode key) bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below { -//#ifdef __DARWIN__ -// wxHIDKeyboard keyboard; -// return keyboard.IsActive(key); -//#else -// TODO: Have it use HID Manager on OSX... -//if OS X > 10.2 (i.e. 10.2.x) -//a known apple bug prevents the system from determining led -//states with GetKeys... can only determine caps lock led - return !!(GetCurrentKeyModifiers() & wxKeyCodeToMacModifier(key)); -//else -// KeyMapByteArray keymap; -// GetKeys((BigEndianLong*)keymap); -// return !!(BitTst(keymap, (sizeof(KeyMapByteArray)*8) - iKey)); -//#endif + wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key != + WXK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons")); + + KeyMap keymap; + GetKeys(keymap); + return !!(BitTst(keymap, (sizeof(KeyMap)*8) - key)); } #if !TARGET_CARBON @@ -1959,7 +1952,7 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi event.m_x = wherex; event.m_y = wherey; - event.m_timeStamp = when; + event.SetTimestamp(when); event.SetEventObject(focus); handled = focus->GetEventHandler()->ProcessEvent( event ) ; if ( handled && event.GetSkipped() ) @@ -1988,7 +1981,7 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi } if (!handled) { - event.Skip( FALSE ) ; + event.Skip( false ) ; event.SetEventType( wxEVT_CHAR ) ; // raw value again event.m_keyCode = realkeyval ; @@ -2024,7 +2017,7 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi { // if window is not having a focus still testing for default enter or cancel // TODO add the UMA version for ActiveNonFloatingWindow - wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ; + wxWindow* focus = wxFindWinFromMacWindow( (WXWindow) FrontWindow() ) ; if ( focus ) { if ( keyval == WXK_RETURN ) @@ -2086,7 +2079,7 @@ bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifier event.m_x = wherex; event.m_y = wherey; - event.m_timeStamp = when; + event.SetTimestamp(when); event.SetEventObject(focus); handled = focus->GetEventHandler()->ProcessEvent( event ) ; @@ -2108,7 +2101,7 @@ void wxApp::MacHandleActivateEvent( WXEVENTREF evr ) // if it is a floater we activate/deactivate the front non-floating window instead window = ::FrontNonFloatingWindow() ; } - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) window ) ; if ( win ) win->MacActivate( ev->when , activate ) ; } @@ -2118,7 +2111,7 @@ void wxApp::MacHandleUpdateEvent( WXEVENTREF evr ) { EventRecord* ev = (EventRecord*) evr ; WindowRef window = (WindowRef) ev->message ; - wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac * win = wxFindWinFromMacWindow( (WXWindow) window ) ; if ( win ) { if ( !wxPendingDelete.Member(win) ) @@ -2176,13 +2169,13 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) if ( oldFrontWindow ) { - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) oldFrontWindow ) ; if ( win ) win->MacActivate( ev->when , false ) ; } if ( newFrontWindow ) { - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) newFrontWindow ) ; if ( win ) win->MacActivate( ev->when , true ) ; } @@ -2217,7 +2210,7 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse event.m_leftDown = isDown && !controlDown; - event.m_middleDown = FALSE; + event.m_middleDown = false; event.m_rightDown = isDown && controlDown; event.m_shiftDown = ev->modifiers & shiftKey; event.m_controlDown = ev->modifiers & controlKey; @@ -2225,7 +2218,7 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) event.m_metaDown = ev->modifiers & cmdKey; event.m_x = ev->where.h; event.m_y = ev->where.v; - event.m_timeStamp = ev->when; + event.SetTimestamp( ev->when ); event.SetEventObject(this); if ( wxWindow::s_lastMouseWindow ) @@ -2264,7 +2257,7 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) { case inContent : { - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) window ) ; if ( win ) win->MacMouseMoved( ev , windowPart ) ; else @@ -2318,7 +2311,7 @@ void wxApp::MacHandleMouseMovedEvent(wxInt32 x , wxInt32 y ,wxUint32 modifiers , event.m_leftDown = isDown && !controlDown; - event.m_middleDown = FALSE; + event.m_middleDown = false; event.m_rightDown = isDown && controlDown; event.m_shiftDown = modifiers & shiftKey; @@ -2328,7 +2321,7 @@ void wxApp::MacHandleMouseMovedEvent(wxInt32 x , wxInt32 y ,wxUint32 modifiers , event.m_x = x; event.m_y = y; - event.m_timeStamp = timestamp; + event.SetTimestamp(timestamp); if ( wxWindow::s_lastMouseWindow ) {