]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/app.cpp
1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
19 #include "wx/gdicmn.h"
22 #include "wx/cursor.h"
24 #include "wx/palette.h"
26 #include "wx/dialog.h"
27 #include "wx/msgdlg.h"
29 #include "wx/module.h"
30 #include "wx/memory.h"
32 #if wxUSE_WX_RESOURCES
33 #include "wx/resource.h"
42 extern char *wxBuffer
;
43 extern wxList wxPendingDelete
;
45 wxApp
*wxTheApp
= NULL
;
47 #if !USE_SHARED_LIBRARY
48 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
49 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
50 EVT_IDLE(wxApp::OnIdle
)
54 long wxApp::sm_lastMessageTime
= 0;
56 const short kMacMinHeap
= (29 * 1024) ;
57 // platform specific static variables
59 bool gMacHasAppearance
= false ;
60 long gMacAppearanceVersion
= 0 ;
61 RgnHandle gMacCursorRgn
= NULL
;
64 bool wxApp::Initialize()
73 ::InitGraf(&qd
.thePort
);
80 CursHandle aCursHandle
= ::GetCursor(watchCursor
); // Watch should be in system
82 ::SetCursor(*aCursHandle
);
83 ::FlushEvents(everyEvent
, 0);
85 // setup memory of application
88 for (long i
= 1; i
<= 4; i
++)
90 PurgeSpace(&total
, &contig
);
91 ::SetCursor( &qd
.arrow
) ;
96 GUSISetup(GUSIwithInternetSockets
);
99 // test the minimal configuration necessary
105 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
107 error
= kMacSTRWrongMachine
;
109 else if (theMachine
< gestaltMacPlus
)
111 error
= kMacSTRWrongMachine
;
113 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
115 error
= kMacSTROldSystem
;
117 else if ( theSystem
< 0x0700 )
119 error
= kMacSTROldSystem
;
121 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
123 error
= kMacSTRSmallSize
;
127 if ( Gestalt( gestaltAppearanceAttr
, &theAppearance
) == noErr
)
129 gMacHasAppearance
= true ;
130 RegisterAppearanceClient();
131 if ( Gestalt( gestaltAppearanceVersion
, &theAppearance
) == noErr
)
133 gMacAppearanceVersion
= theAppearance
;
137 gMacAppearanceVersion
= 0x0100 ;
141 error
= kMacSTRNoPre8Yet
;
144 // if we encountered any problems so far, give the error code and exit immediately
151 SetCursor(&qd
.arrow
);
152 GetIndString(message
, 128, error
);
153 ParamText(message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
154 itemHit
= Alert(129, nil
);
158 // now avoid exceptions thrown for new (bad_alloc)
160 std::__throws_bad_alloc
= FALSE
;
162 gMacCursorRgn
= ::NewRgn() ;
165 wxBuffer
= new char[1500];
167 wxBuffer
= new char[BUFSIZ
+ 512];
171 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
173 streambuf* sBuf = new wxDebugStreamBuf;
174 ostream* oStr = new ostream(sBuf) ;
175 wxDebugContext::SetStream(oStr, sBuf);
179 wxClassInfo::InitializeClasses();
181 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
182 wxTheColourDatabase
->Initialize();
184 wxInitializeStockLists();
185 wxInitializeStockObjects();
187 #if wxUSE_WX_RESOURCES
188 wxInitializeResourceSystem();
191 wxBitmap::InitStandardHandlers();
193 wxModule::RegisterModules();
194 wxASSERT( wxModule::InitializeModules() == TRUE
);
199 void wxApp::CleanUp()
201 wxModule::CleanUpModules();
203 #if wxUSE_WX_RESOURCES
204 wxCleanUpResourceSystem();
207 wxDeleteStockObjects() ;
209 // Destroy all GDI lists, etc.
211 delete wxTheBrushList
;
212 wxTheBrushList
= NULL
;
217 delete wxTheFontList
;
218 wxTheFontList
= NULL
;
220 delete wxTheBitmapList
;
221 wxTheBitmapList
= NULL
;
223 delete wxTheColourDatabase
;
224 wxTheColourDatabase
= NULL
;
226 wxBitmap::CleanUpHandlers();
231 wxClassInfo::CleanUpClasses();
236 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
237 // At this point we want to check if there are any memory
238 // blocks that aren't part of the wxDebugContext itself,
239 // as a special case. Then when dumping we need to ignore
240 // wxDebugContext, too.
241 if (wxDebugContext::CountObjectsLeft() > 0)
243 wxTrace("There were memory leaks.\n");
244 wxDebugContext::Dump();
245 wxDebugContext::PrintStatistics();
247 // wxDebugContext::SetStream(NULL, NULL);
250 // do it as the very last thing because everything else can log messages
251 wxLog::DontCreateOnDemand();
252 // do it as the very last thing because everything else can log messages
253 delete wxLog::SetActiveTarget(NULL
);
257 ::DisposeRgn(gMacCursorRgn
);
263 int wxEntry( int argc
, char *argv
[] )
265 if (!wxApp::Initialize())
269 if (!wxApp::GetInitializerFunction())
271 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
275 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
280 printf( "wxWindows error: wxTheApp == NULL\n" );
284 wxTheApp
->argc
= argc
;
285 wxTheApp
->argv
= argv
;
287 // GUI-specific initialization, such as creating an app context.
288 wxTheApp
->OnInitGui();
290 // Here frames insert themselves automatically
291 // into wxTopLevelWindows by getting created
294 if (!wxTheApp
->OnInit()) return 0;
298 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
300 if (wxTheApp
->GetTopWindow())
302 delete wxTheApp
->GetTopWindow();
303 wxTheApp
->SetTopWindow(NULL
);
306 wxTheApp
->DeletePendingObjects();
315 // Static member initialization
316 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
323 m_wantDebugOutput
= TRUE
;
328 m_printMode
= wxPRINT_WINDOWS
;
330 m_printMode
= wxPRINT_POSTSCRIPT
;
332 m_exitOnFrameDelete
= TRUE
;
336 bool wxApp::Initialized()
339 // if (GetTopWindow())
345 int wxApp::MainLoop()
357 // Returns TRUE if more time is needed.
358 bool wxApp::ProcessIdle()
361 event
.SetEventObject(this);
364 return event
.MoreRequested();
367 void wxApp::ExitMainLoop()
372 // Is a message/event pending?
373 bool wxApp::Pending()
380 // Dispatch a message.
381 void wxApp::Dispatch()
387 void wxApp::OnIdle(wxIdleEvent
& event
)
389 static bool inOnIdle
= FALSE
;
391 // Avoid recursion (via ProcessEvent default case)
397 // 'Garbage' collection of windows deleted with Close().
398 DeletePendingObjects();
400 // flush the logged messages if any
401 wxLog
*pLog
= wxLog::GetActiveTarget();
402 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
405 // Send OnIdle events to all windows
406 bool needMore
= SendIdleEvents();
409 event
.RequestMore(TRUE
);
414 // Send idle event to all top-level windows
415 bool wxApp::SendIdleEvents()
417 bool needMore
= FALSE
;
418 wxNode
* node
= wxTopLevelWindows
.First();
421 wxWindow
* win
= (wxWindow
*) node
->Data();
422 if (SendIdleEvents(win
))
430 // Send idle event to window and all subwindows
431 bool wxApp::SendIdleEvents(wxWindow
* win
)
433 bool needMore
= FALSE
;
436 event
.SetEventObject(win
);
437 win
->ProcessEvent(event
);
439 if (event
.MoreRequested())
442 wxNode
* node
= win
->GetChildren().First();
445 wxWindow
* win
= (wxWindow
*) node
->Data();
446 if (SendIdleEvents(win
))
454 void wxApp::DeletePendingObjects()
456 wxNode
*node
= wxPendingDelete
.First();
459 wxObject
*obj
= (wxObject
*)node
->Data();
463 if (wxPendingDelete
.Member(obj
))
466 // Deleting one object may have deleted other pending
467 // objects, so start from beginning of list again.
468 node
= wxPendingDelete
.First();
472 wxLog
* wxApp::CreateLogTarget()
477 wxWindow
* wxApp::GetTopWindow() const
481 else if (wxTopLevelWindows
.Number() > 0)
482 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
493 // Yield to other processes
497 ::YieldToOtherThreads() ;
503 // platform specifics
505 void wxApp::MacDoOneEvent()
511 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, gMacCursorRgn
))
513 MacHandleOneEvent( &event
);
518 wxTheApp
->ProcessIdle() ;
523 wxMacProcessSocketEvents() ;
527 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
532 MacHandleNullEvent( ev
) ;
534 case kHighLevelEvent
:
535 MacHandleHighLevelEvent( ev
) ;
538 MacHandleMouseDownEvent( ev
) ;
539 wxTheApp
->ExitMainLoop() ;
542 MacHandleMouseUpEvent( ev
) ;
545 MacHandleKeyDownEvent( ev
) ;
548 MacHandleAutoKeyEvent( ev
) ;
551 MacHandleKeyUpEvent( ev
) ;
554 MacHandleActivateEvent( ev
) ;
557 MacHandleUpdateEvent( ev
) ;
560 MacHandleDiskEvent( ev
) ;
563 MacHandleOSEvent( ev
) ;
570 void wxApp::MacHandleNullEvent( EventRecord
*ev
)
574 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
578 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
582 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
586 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
590 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
594 void wxApp::MacHandleAutoKeyEvent( EventRecord
*ev
)
598 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
602 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
606 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
610 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
618 void wxApp::doMacMouseDown(void)
621 short windowPart = ::FindWindow(m_event.where, &window);
622 if ( windowPart != inMenuBar )
624 WindowPtr frontWindow = FrontWindow();
625 if (WindowIsModal(frontWindow) && (window != frontWindow))
634 doMacInContent(window); break;
636 doMacInDrag(window); break;
638 doMacInGrow(window); break;
640 doMacInGoAway(window); break;
643 doMacInZoom(window, windowPart); break;
652 doMacInMenuBar(::MenuSelect(m_event.where));
656 void wxApp::doMacMouseUp(void)
661 int hitX = m_event.where.h; // screen window c.s.
662 int hitY = m_event.where.v; // screen window c.s.
663 m_mouseWindow->ScreenToClient(&hitX, &hitY); // mouseWindow client c.s.
664 m_mouseWindow->ClientToLogical(&hitX, &hitY); // mouseWindow logical c.s.
667 wxMouseEvent event(wxEVT_LEFT_UP);
668 event.m_shiftDown = m_event.modifiers & shiftKey;
669 event.m_controlDown = m_event.modifiers & controlKey;
670 event.m_altDown = m_event.modifiers & optionKey;
671 event.m_metaDown = m_event.modifiers & cmdKey;
672 event.m_leftDown = FALSE;
673 event.m_middleDown = FALSE;
674 event.m_rightDown = FALSE;
675 event.m_x = m_event.where.h;
676 event.m_y = m_event.where.v;
677 event.m_timeStamp = m_event.when;
678 event.SetEventObject(m_mouseWindow);
680 m_mouseWindow->ProcessEvent(event);
684 //??? Can't we just throw away mouse up events without matching mouse down
685 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
689 int hitX = cCurrentEvent.where.h; // screen window c.s.
690 int hitY = cCurrentEvent.where.v; // screen window c.s.
691 theMacWxFrame->ScreenToWindow(&hitX, &hitY);
694 wxMouseEvent event(wxEVT_LEFT_UP);
695 event.m_shiftDown = m_event.modifiers & shiftKey;
696 event.m_controlDown = m_event.modifiers & controlKey;
697 event.m_altDown = m_event.modifiers & optionKey;
698 event.m_metaDown = m_event.modifiers & cmdKey;
699 event.m_leftDown = FALSE;
700 event.m_middleDown = FALSE;
701 event.m_rightDown = FALSE;
702 event.m_x = m_event.where.h;
703 event.m_y = m_event.where.v;
704 event.m_timeStamp = m_event.when;
705 event.SetEventObject(m_mouseWindow);
707 theMacWxFrame->ProcessEvent(event);
712 void wxApp::doMacMouseMotion(void)
715 wxMouseEvent event(wxEVT_MOTION);
716 event.m_shiftDown = m_event.modifiers & shiftKey;
717 event.m_controlDown = m_event.modifiers & controlKey;
718 event.m_altDown = m_event.modifiers & optionKey;
719 event.m_metaDown = m_event.modifiers & cmdKey;
720 event.m_leftDown = !(m_event.modifiers & btnState);
721 event.m_middleDown = FALSE;
722 event.m_rightDown = FALSE;
723 event.m_x = m_event.where.h;
724 event.m_y = m_event.where.v;
725 event.m_timeStamp = m_event.when;
726 event.SetEventObject(m_mouseWindow);
728 m_mouseWindow->ProcessEvent(event);
732 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
735 wxMouseEvent event(wxEVT_MOTION);
736 event.m_shiftDown = m_event.modifiers & shiftKey;
737 event.m_controlDown = m_event.modifiers & controlKey;
738 event.m_altDown = m_event.modifiers & optionKey;
739 event.m_metaDown = m_event.modifiers & cmdKey;
740 event.m_leftDown = !(m_event.modifiers & btnState);
741 event.m_middleDown = FALSE;
742 event.m_rightDown = FALSE;
743 event.m_x = m_event.where.h;
744 event.m_y = m_event.where.v;
745 event.m_timeStamp = m_event.when;
746 event.SetEventObject(m_mouseWindow);
748 m_mouseWindow->ProcessEvent(event);
752 //??? Need to work with floating windows... isn't there a toolbox call to find the
753 // top window intersecting a point is screen coordinates??
755 else // will only work for one floating window at the moment... ?
757 WindowPtr frontDocPtr = findFrontNonFloatingWindow();
758 WindowPtr frontFloatingPtr = ::FrontWindow();
760 int hitX = cCurrentEvent.where.h;
761 int hitY = cCurrentEvent.where.v;
763 wxFrame* macWxFrame = findMacWxFrame(frontDocPtr);
765 if ((frontFloatingPtr != frontDocPtr) & (frontFloatingPtr != NULL))
767 RgnHandle frontFloatStrRgn = getStructureRegion(frontFloatingPtr);
768 Rect frontFloatRect = (**frontFloatStrRgn).rgnBBox;
770 if ((hitX >= frontFloatRect.left) &
771 (hitX <= frontFloatRect.right) &
772 (hitY >= frontFloatRect.top) &
773 (hitY <= frontFloatRect.bottom))
775 macWxFrame = findMacWxFrame(frontFloatingPtr);
782 void wxApp::doMacKeyDown(void)
784 long menuResult = 0 ;
787 keychar = short(m_event.message & charCodeMask);
788 keycode = short(m_event.message & keyCodeMask) >> 8 ;
790 // Handle menu accelerators
791 if ( gSFMacHasAppearance )
793 menuResult = MenuEvent( &m_event ) ;
794 if ( HiWord( menuResult ) )
796 doMacInMenuBar( menuResult ) ;
800 ControlHandle control ;
802 GetKeyboardFocus( FrontNonFloatingWindow() , &control ) ;
803 if ( control && keychar != 0x07 )
804 HandleControlKey( control , keycode , keychar , m_event.modifiers ) ;
807 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
810 wxKeyEvent event(wxEVT_CHAR);
811 event.m_shiftDown = m_event.modifiers & shiftKey;
812 event.m_controlDown = m_event.modifiers & controlKey;
813 event.m_altDown = m_event.modifiers & optionKey;
814 event.m_metaDown = m_event.modifiers & cmdKey;
815 event.m_keyCode = macTranslateKey(keychar, m_event.modifiers & (shiftKey|optionKey));
816 event.m_x = m_event.where.h;
817 event.m_y = m_event.where.v;
818 event.m_timeStamp = m_event.when;
819 event.SetEventObject(theMacWxFrame);
821 theMacWxFrame->ProcessEvent(event);
828 if (GetMenuHandle( kwxMacAppleMenuId ) )
830 // menuResult = MDEF_MenuKey(m_event.message, m_event.modifiers , GetMenuHandle( kwxMacAppleMenuId ) );
834 if (m_event.modifiers & cmdKey)
836 menuResult = MenuKey( keychar ) ;
840 if ( HiWord( menuResult ) )
842 doMacInMenuBar( menuResult ) ;
846 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
849 wxKeyEvent event(wxEVT_CHAR);
850 event.m_shiftDown = m_event.modifiers & shiftKey;
851 event.m_controlDown = m_event.modifiers & controlKey;
852 event.m_altDown = m_event.modifiers & optionKey;
853 event.m_metaDown = m_event.modifiers & cmdKey;
854 event.m_keyCode = macTranslateKey(keychar, m_event.modifiers & (shiftKey|optionKey));
855 event.m_x = m_event.where.h;
856 event.m_y = m_event.where.v;
857 event.m_timeStamp = m_event.when;
858 event.SetEventObject(theMacWxFrame);
860 theMacWxFrame->ProcessEvent(event);
866 void wxApp::doMacAutoKey(void)
871 void wxApp::doMacKeyUp(void)
875 void wxApp::doMacActivateEvt(void)
877 HighlightAndActivateWindow( (WindowPtr) m_event.message , m_event.modifiers & activeFlag ) ;
880 void wxApp::doMacUpdateEvt(void)
882 WindowPtr theMacWindow = (WindowPtr)(m_event.message);
883 ::BeginUpdate(theMacWindow);
885 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(theMacWindow);
888 // if (!::EmptyRgn(theMacWindow->visRgn)) // this doesn't work with windowshade
890 if ( theMacWxFrame->MacSetupPort() )
892 // Erase update region
893 // we must do this, because controls add their former rect to the inval
894 // rgn and the background might not have been correct at that moment
895 ::EraseRect(&theMacWindow->portRect);
897 // Can't use UpdateControls since each control has it's own coordinate system
898 // ::UpdateControls(theMacWindow, theMacWindow->visRgn);
900 ::UpdateControls( theMacWindow , theMacWindow->visRgn ) ;
903 if (cStyle & wxRESIZE_BORDER)
908 event.m_timeStamp = m_event.when;
909 event.SetEventObject(theMacWxFrame);
911 theMacWxFrame->ProcessEvent(event);
912 // ::SetThemeWindowBackground( theMacWindow , kThemeActiveDialogBackgroundBrush , false ) ;
913 ::ClipRect( &theMacWindow->portRect ) ;
914 ::SetOrigin( 0 , 0 );
918 wxASSERT_MSG( false , "unabled to setup window mac port") ;
924 ::EndUpdate(theMacWindow);
927 void wxApp::doMacDiskEvt(void)
928 { // based on "Programming for System 7" by Gary Little and Tim Swihart
929 if ((m_event.message >> 16) != noErr)
931 const int kDILeft = 0x0050; // top coord for disk init dialog
932 const int kDITop = 0x0070; // left coord for disk init dialog
934 mountPoint.h = kDILeft;
935 mountPoint.v = kDITop;
936 int myError = DIBadMount(mountPoint, m_event.message);
940 void wxApp::doMacOsEvt(void)
941 { // based on "Programming for System 7" by Gary Little and Tim Swihart
942 switch ((m_event.message >> 24) & 0x0ff)
944 case suspendResumeMessage:
945 if (m_event.message & resumeFlag)
950 case mouseMovedMessage:
951 doMacMouseMovedMessage();
956 void wxApp::doMacHighLevelEvent(void)
958 ::AEProcessAppleEvent(&m_event); // System 7 or higher
961 void wxApp::doMacResumeEvent(void)
963 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
966 if (m_event.message & convertClipboardFlag)
969 wxActivateEvent event(wxEVT_ACTIVATE, TRUE);
970 event.m_timeStamp = m_event.when;
971 event.SetEventObject(theMacWxFrame);
973 theMacWxFrame->ProcessEvent(event);
977 void wxApp::doMacSuspendEvent(void)
979 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
985 wxActivateEvent event(wxEVT_ACTIVATE, FALSE);
986 event.m_timeStamp = m_event.when;
987 event.SetEventObject(theMacWxFrame);
989 theMacWxFrame->ProcessEvent(event);
993 void wxApp::doMacMouseMovedMessage(void)
994 { // based on "Programming for System 7" by Gary Little and Tim Swihart
996 ::DisposeRgn(m_cursorRgn);
997 m_cursorRgn = ::NewRgn();
998 ::SetRectRgn(m_cursorRgn, -32768, -32768, 32766, 32766);
1001 void wxApp::doMacInMenuBar(long menuResult)
1003 int macMenuId = HiWord(menuResult);
1004 int macMenuItemNum = LoWord(menuResult); // counting from 1
1006 if (macMenuId == 0) // no menu item selected;
1008 if (macMenuId == 128)
1010 if (macMenuItemNum != 1)
1011 { // if not the "About" entry (or the separator)
1013 ::GetMenuItemText(GetMenuHandle(128), macMenuItemNum, daName);
1014 (void)::OpenDeskAcc(daName);
1020 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1023 if ( theMacWxFrame->IsKindOf( CLASSINFO( wxDialog ) ) )
1024 (( wxDialog *) theMacWxFrame)->MacMenuSelect(m_event, macMenuId, macMenuItemNum);
1025 else if ( theMacWxFrame->IsKindOf( CLASSINFO( wxFrame ) ) )
1026 (( wxFrame *) theMacWxFrame)->MacMenuSelect(m_event, macMenuId, macMenuItemNum);
1031 void wxApp::doMacInContent(WindowPtr window)
1033 WindowPtr frontWindow = FrontWindow();
1034 if (window != frontWindow )
1036 // SFSelectWindow( window ) ;
1040 ControlHandle control ;
1041 Point localwhere = m_event.where ;
1043 SInt16 controlpart ;
1045 ::GetPort( &port ) ;
1046 ::SetPort( window ) ;
1047 ::GlobalToLocal( &localwhere ) ;
1051 if ( !gSFMacHasAppearance )
1053 controlpart = FindControl( localwhere , window , &control ) ;
1057 control = FindControlUnderMouse( localwhere , window , &controlpart ) ;
1060 if ( control && IsControlActive( control ) )
1062 wxControl* wxc = (wxControl*) GetControlReference( control ) ;
1064 if ( wxWindow::FindFocus() != wxc && wxc->AcceptsFocus() )
1067 if ( wxWindow::FindFocus() != wxc )
1068 control = NULL ; // we were not able to change focus
1073 if ( !gSFMacHasAppearance)
1075 controlpart = TrackControl( control , localwhere , NULL ) ;
1079 controlpart = HandleControlClick( control , localwhere , m_event.modifiers , (ControlActionUPP) -1 ) ;
1084 wxControl* wx = (wxControl*) GetControlReference( control ) ;
1086 wx->MacHandleControlClick( control , controlpart ) ;
1092 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
1095 doMacContentClick((wxFrame*)theMacWxFrame); // todo : this cast is wrong
1101 wxFrame* theMacWxFrame = findMacWxFrame(window);
1104 WindowPtr MacWindow = findFrontNonFloatingWindow();
1105 if (window != MacWindow)
1107 wxFrame* frontFrame = findMacWxFrame(MacWindow);
1108 if (!frontFrame) wxFatalError("No wxFrame for frontnonfloatingWindow.");
1109 if (!frontFrame->IsModal())
1111 frontFrame->SetFocus();
1112 doMacContentClick(theMacWxFrame); // jonto - to deal with doc windows behind floaters ?
1113 ::newSelectWindow(window); // WCH : should I be calling some wxMethod?
1114 if (!IsFloating(MacWindow))
1118 if (!(keyMap[1] & 0x8000)) theMacWxFrame->ShowAsActive(true); // temporary measure...
1120 } // jonto : not sure yet, but let's try this ...
1125 doMacContentClick(theMacWxFrame);
1131 void wxApp::doMacContentClick(wxWindow* frame)
1133 m_mouseWindow = frame;
1135 wxMouseEvent event(wxEVT_LEFT_DOWN);
1136 event.m_shiftDown = m_event.modifiers & shiftKey;
1137 event.m_controlDown = m_event.modifiers & controlKey;
1138 event.m_altDown = m_event.modifiers & optionKey;
1139 event.m_metaDown = m_event.modifiers & cmdKey;
1140 event.m_leftDown = FALSE;
1141 event.m_middleDown = FALSE;
1142 event.m_rightDown = FALSE;
1143 if ( m_event.modifiers & controlKey )
1145 event.m_rightDown = TRUE;
1149 event.m_leftDown = TRUE;
1152 event.m_leftDown = !(m_event.modifiers & btnState);
1153 event.m_middleDown = FALSE;
1154 event.m_rightDown = FALSE;
1156 event.m_x = m_event.where.h;
1157 event.m_y = m_event.where.v;
1158 event.m_timeStamp = m_event.when;
1159 event.SetEventObject(m_mouseWindow);
1161 // m_mouseWindow->ProcessEvent(event);
1162 m_mouseWindow->MacDispatchMouseEvent(event);
1165 // RightButton is cmdKey click on the mac platform for one-button mouse
1166 Bool rightButton = cCurrentEvent.modifiers & cmdKey;
1167 // altKey is optionKey on the mac platform:
1168 Bool isAltKey = cCurrentEvent.modifiers & optionKey;
1170 WXTYPE mouseEventType = rightButton ? wxEVENT_TYPE_RIGHT_DOWN
1171 : wxEVENT_TYPE_LEFT_DOWN;
1172 wxMouseEvent theMouseEvent(mouseEventType);
1173 theMouseEvent.leftDown = !rightButton;
1174 theMouseEvent.middleDown = FALSE;
1175 theMouseEvent.rightDown = rightButton;
1176 theMouseEvent.shiftDown = cCurrentEvent.modifiers & shiftKey;
1177 theMouseEvent.controlDown = cCurrentEvent.modifiers & controlKey;
1178 theMouseEvent.altDown = isAltKey;
1179 theMouseEvent.metaDown = FALSE; // mflatt
1180 theMouseEvent.timeStamp = cCurrentEvent.when; // mflatt
1182 int hitX = cCurrentEvent.where.h; // screen window c.s.
1183 int hitY = cCurrentEvent.where.v; // screen window c.s.
1185 frame->ScreenToWindow(&hitX, &hitY);
1186 // frameParentArea->ScreenToArea(&hitX, &hitY); // tx coords ?
1187 theMouseEvent.x = hitX; // frame parent area c.s.
1188 theMouseEvent.y = hitY; // frame parent area c.s.
1190 frame->SeekMouseEventArea(theMouseEvent);
1194 void wxApp::doMacInDrag(WindowPtr window)
1196 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
1199 // should be desktop, not screen
1200 Rect dragBoundsRect = qd.screenBits.bounds; // can't move to a different screen
1201 //xxx ::InsetRect(&dragBoundsRect, 4, ::GetMBarHeight() + 4); // This is not really necessary
1202 Rect oldPos = (**(((WindowPeek)window)->strucRgn)).rgnBBox;
1203 ::DragReferencedWindow(window, m_event.where, &dragBoundsRect); // jonto
1205 theMacWxFrame->m_x += (**(((WindowPeek)window)->strucRgn)).rgnBBox.left - oldPos.left;
1206 theMacWxFrame->m_y += (**(((WindowPeek)window)->strucRgn)).rgnBBox.top - oldPos.top;
1208 Move( (**(((WindowPeek)window)->strucRgn)).rgnBBox.left , (**(((WindowPeek)window)->strucRgn)).rgnBBox.top ) ;
1210 theMacWxFrame->wxMacRecalcNewSize(); // Actually, recalc new position only
1215 // if (window != ::FrontWindow())
1216 if (window != findFrontNonFloatingWindow())
1218 // wxFrame* frontFrame = findMacWxFrame(::FrontWindow());
1219 wxFrame* frontFrame = findMacWxFrame(findFrontNonFloatingWindow());
1220 if (!frontFrame) wxFatalError("No wxFrame for frontWindow.");
1221 if (frontFrame->IsModal())
1228 wxFrame* theMacWxFrame = findMacWxFrame(window);
1231 Rect dragBoundsRect = qd.screenBits.bounds; // can't move to a different screen
1232 ::InsetRect(&dragBoundsRect, 4, ::GetMBarHeight() + 4); // This is not really necessary
1233 newDragWindow(window, cCurrentEvent.where, &dragBoundsRect); // jonto
1234 theMacWxFrame->wxMacRecalcNewSize(); // Actually, recalc new position only
1235 if (!IsFloating(window))
1237 theMacWxFrame->ShowAsActive(true); // temporary measure...
1243 void wxApp::doMacInGrow(WindowPtr window)
1245 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
1248 Rect growSizeRect; // WCH: growSizeRect should be a member of wxFrame class
1249 growSizeRect.top = 1; // minimum window height
1250 growSizeRect.left = 1; // minimum window width
1251 growSizeRect.bottom = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
1252 growSizeRect.right = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
1253 long windSize = ::GrowWindow(window, m_event.where, &growSizeRect);
1256 int nWidth = LoWord(windSize);
1257 int nHeight = HiWord(windSize);
1258 int oWidth, oHeight;
1259 theMacWxFrame->GetSize(&oWidth, &oHeight);
1260 if (nWidth == 0) nWidth = oWidth;
1261 if (nHeight == 0) nHeight = oHeight;
1262 theMacWxFrame->SetSize( -1, -1, nWidth, nHeight, wxSIZE_USE_EXISTING);
1267 void wxApp::doMacInGoAway(WindowPtr window)
1269 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
1272 if (TrackGoAway(window, m_event.where))
1274 // TODO: Stefan, I think you need to send a wxCloseEvent to the window
1275 // here. The OnCloseWindow handler will take care of delete the frame
1276 // if it wishes to (there should be a default wxFrame::OnCloseWindow
1277 // that destroys the frame).
1278 if (theMacWxFrame->OnClose()) {
1279 #if WXGARBAGE_COLLECTION_ON
1280 theMacWxFrame->Show(FALSE);
1282 delete theMacWxFrame;
1289 void wxApp::doMacInZoom(WindowPtr window, short windowPart)
1291 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
1294 if (TrackBox(window, m_event.where, windowPart))
1297 theMacWxFrame->Maximize(windowPart == inZoomOut);
1303 long wxApp::macTranslateKey(char key, int mods)
1305 static Handle transH = NULL;
1306 static unsigned long transState = 0;
1307 static Handle ScriptH = NULL;
1308 static short region_code = 1;
1310 if (!ScriptH) { // tom: don't guess the regioncode!!!!
1311 struct ItlbRecord * r;
1312 ScriptH = GetResource('itlb',0);
1315 r = (ItlbRecord*)*ScriptH;
1316 region_code = r->itlbKeys;
1365 transH = GetIndResource('KCHR', 1);
1368 #if 0 //Tom replaces
1370 // Only let shift & option modify the key:
1372 key = KeyTranslate(*transH, (key & 0x7F) | mods, &transState) & charCodeMask;
1375 if (0) { // tom fettig@dfki.uni-sb.de
1377 // code is not correct, see inside Macintosh: Text 1-87
1378 // and 'itlk'-resource!!
1379 // and it is not necessary, as the translated char is in
1380 // cCurrrentEvent.message!!
1381 // Only let shift & option modify the key:
1383 key = KeyTranslate(*transH, (key & 0x7F) | mods, &transState) & charCodeMask;
1393 wxApp::macAdjustCursor()
1395 if (m_event.what != kHighLevelEvent)
1397 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1400 if (!theMacWxFrame->MacAdjustCursor(m_event.where))
1401 ::SetCursor(&(qd.arrow));