]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/app.cpp
c1ea01dc9f16af33234f5f075dbfa4e1a184addf
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"
38 extern char *wxBuffer
;
39 extern wxList wxPendingDelete
;
41 wxApp
*wxTheApp
= NULL
;
43 #if !USE_SHARED_LIBRARY
44 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
45 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
46 EVT_IDLE(wxApp::OnIdle
)
52 typedef void * PLEventHandle
;
54 int PLTestMinimalRequirements() ;
55 void PLErrorMessage( int errorCode
) ;
56 int PLStartupPhase1() ;
57 int PLStartupPhase2() ;
61 bool PLHandleOneEvent( PLEventHandle event
) ; // true if really event
62 bool PLCallbackIdle() ;
63 bool PLCallbackRepeat() ;
65 long wxApp::sm_lastMessageTime
= 0;
67 bool wxApp::Initialize()
71 error
= PLStartupPhase1() ;
74 error
= PLTestMinimalRequirements() ;
76 error
= PLStartupPhase2() ;
81 PLErrorMessage( error
) ;
86 wxBuffer
= new char[1500];
88 wxBuffer
= new char[BUFSIZ
+ 512];
92 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
94 streambuf* sBuf = new wxDebugStreamBuf;
95 ostream* oStr = new ostream(sBuf) ;
96 wxDebugContext::SetStream(oStr, sBuf);
100 wxClassInfo::InitializeClasses();
102 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
103 wxTheColourDatabase
->Initialize();
105 wxInitializeStockLists();
106 wxInitializeStockObjects();
108 #if wxUSE_WX_RESOURCES
109 wxInitializeResourceSystem();
112 wxBitmap::InitStandardHandlers();
114 wxModule::RegisterModules();
115 wxASSERT( wxModule::InitializeModules() == TRUE
);
120 void wxApp::CleanUp()
122 wxModule::CleanUpModules();
124 #if wxUSE_WX_RESOURCES
125 wxCleanUpResourceSystem();
128 wxDeleteStockObjects() ;
130 // Destroy all GDI lists, etc.
132 delete wxTheBrushList
;
133 wxTheBrushList
= NULL
;
138 delete wxTheFontList
;
139 wxTheFontList
= NULL
;
141 delete wxTheBitmapList
;
142 wxTheBitmapList
= NULL
;
144 delete wxTheColourDatabase
;
145 wxTheColourDatabase
= NULL
;
147 wxBitmap::CleanUpHandlers();
152 wxClassInfo::CleanUpClasses();
157 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
158 // At this point we want to check if there are any memory
159 // blocks that aren't part of the wxDebugContext itself,
160 // as a special case. Then when dumping we need to ignore
161 // wxDebugContext, too.
162 if (wxDebugContext::CountObjectsLeft() > 0)
164 wxTrace("There were memory leaks.\n");
165 wxDebugContext::Dump();
166 wxDebugContext::PrintStatistics();
168 // wxDebugContext::SetStream(NULL, NULL);
171 // do it as the very last thing because everything else can log messages
172 wxLog::DontCreateOnDemand();
173 // do it as the very last thing because everything else can log messages
174 delete wxLog::SetActiveTarget(NULL
);
179 int wxEntry( int argc
, char *argv
[] )
181 if (!wxApp::Initialize())
185 if (!wxApp::GetInitializerFunction())
187 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
191 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
196 printf( "wxWindows error: wxTheApp == NULL\n" );
200 wxTheApp
->argc
= argc
;
201 wxTheApp
->argv
= argv
;
203 // GUI-specific initialization, such as creating an app context.
204 wxTheApp
->OnInitGui();
206 // Here frames insert themselves automatically
207 // into wxTopLevelWindows by getting created
210 if (!wxTheApp
->OnInit()) return 0;
214 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
216 if (wxTheApp
->GetTopWindow())
218 delete wxTheApp
->GetTopWindow();
219 wxTheApp
->SetTopWindow(NULL
);
222 wxTheApp
->DeletePendingObjects();
231 // Static member initialization
232 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
239 m_wantDebugOutput
= TRUE
;
244 m_printMode
= wxPRINT_WINDOWS
;
246 m_printMode
= wxPRINT_POSTSCRIPT
;
248 m_exitOnFrameDelete
= TRUE
;
252 bool wxApp::Initialized()
255 // if (GetTopWindow())
261 int wxApp::MainLoop()
273 // Returns TRUE if more time is needed.
274 bool wxApp::ProcessIdle()
277 event
.SetEventObject(this);
280 return event
.MoreRequested();
283 void wxApp::ExitMainLoop()
288 // Is a message/event pending?
289 bool wxApp::Pending()
296 // Dispatch a message.
297 void wxApp::Dispatch()
303 void wxApp::OnIdle(wxIdleEvent
& event
)
305 static bool inOnIdle
= FALSE
;
307 // Avoid recursion (via ProcessEvent default case)
313 // 'Garbage' collection of windows deleted with Close().
314 DeletePendingObjects();
316 // flush the logged messages if any
317 wxLog
*pLog
= wxLog::GetActiveTarget();
318 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
321 // Send OnIdle events to all windows
322 bool needMore
= SendIdleEvents();
325 event
.RequestMore(TRUE
);
330 // Send idle event to all top-level windows
331 bool wxApp::SendIdleEvents()
333 bool needMore
= FALSE
;
334 wxNode
* node
= wxTopLevelWindows
.First();
337 wxWindow
* win
= (wxWindow
*) node
->Data();
338 if (SendIdleEvents(win
))
346 // Send idle event to window and all subwindows
347 bool wxApp::SendIdleEvents(wxWindow
* win
)
349 bool needMore
= FALSE
;
352 event
.SetEventObject(win
);
353 win
->ProcessEvent(event
);
355 if (event
.MoreRequested())
358 wxNode
* node
= win
->GetChildren().First();
361 wxWindow
* win
= (wxWindow
*) node
->Data();
362 if (SendIdleEvents(win
))
370 void wxApp::DeletePendingObjects()
372 wxNode
*node
= wxPendingDelete
.First();
375 wxObject
*obj
= (wxObject
*)node
->Data();
379 if (wxPendingDelete
.Member(obj
))
382 // Deleting one object may have deleted other pending
383 // objects, so start from beginning of list again.
384 node
= wxPendingDelete
.First();
388 wxLog
* wxApp::CreateLogTarget()
393 wxWindow
* wxApp::GetTopWindow() const
397 else if (wxTopLevelWindows
.Number() > 0)
398 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
407 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
408 * only for emergencies.
412 // Yield to other processes
421 // -------------------------------------------------------------------
422 // Portability Layer PL
423 // -------------------------------------------------------------------
424 // this is the c-api part, the only part of this file that needs to be
425 // adapted for supporting a new platform
426 // there are two flavours of PL... functions, Callbacks and normal functions
427 // Callbacks are called by other PLxxx functions and allow to trigger idle
428 // processing etc. the callbacks don't have to be adapted for every platform
429 // but only in case of changes to the underlying wx framework
433 bool PLCallbackIdle()
435 return wxTheApp
->ProcessIdle() ;
438 bool PLCallbackRepeat()
440 // wxMacProcessSocketEvents() ;
444 // platform specific static variables
446 bool gMacHasAppearance
= false ;
447 long gMacAppearanceVersion
= 0 ;
448 RgnHandle gMacCursorRgn
= NULL
;
450 #define kMinHeap (29 * 1024)
451 #define kMinSpace (20 * 1024)
452 #define eWrongMachine 1
456 #define eGenericAbout 5
458 // platform specific prototypes
460 void DoMacNullEvent( EventRecord
*ev
) ;
461 void DoMacHighLevelEvent( EventRecord
*ev
) ;
462 void DoMacMouseDownEvent( EventRecord
*ev
) ;
463 void DoMacMouseUpEvent( EventRecord
*ev
) ;
464 void DoMacKeyDownEvent( EventRecord
*ev
) ;
465 void DoMacKeyUpEvent( EventRecord
*ev
) ;
466 void DoMacAutoKeyEvent( EventRecord
*ev
) ;
467 void DoMacActivateEvent( EventRecord
*ev
) ;
468 void DoMacUpdateEvent( EventRecord
*ev
) ;
469 void DoMacDiskEvent( EventRecord
*ev
) ;
470 void DoMacOSEvent( EventRecord
*ev
) ;
472 // platform specific functions
474 // -------------------------------------------------------------------
476 // -------------------------------------------------------------------
477 // Initializes the system so that at least the requirements can be tested
478 // and that error messages will shop up at all ;-)
481 // return value : non zero for a implementation specific error code
483 int PLStartupPhase1()
485 ::InitGraf(&qd
.thePort
);
492 CursHandle aCursHandle
= ::GetCursor(watchCursor
); // Watch should be in system
494 ::SetCursor(*aCursHandle
); // Change cursor to watch
495 ::FlushEvents(everyEvent
, 0);
497 gMacCursorRgn
= ::NewRgn() ;
502 // -------------------------------------------------------------------
504 // -------------------------------------------------------------------
505 // booting the system further until all subsystems are running
508 // return value : non zero for a implementation specific error code
510 int PLStartupPhase2()
515 for (long i
= 1; i
<= 4; i
++)
517 PurgeSpace(&total
, &contig
);
518 ::SetCursor( &qd
.arrow
) ;
523 GUSISetup(GUSIwithInternetSockets
);
529 // -------------------------------------------------------------------
531 // -------------------------------------------------------------------
532 // notifies the user of a implementation specific error
533 // is useful for messages before the wx System is up and running
535 // parameters : int error = error code (implementation specific)
536 // return value : none
538 void PLErrorMessage( int error
)
543 SetCursor(&qd
.arrow
);
544 GetIndString(message
, 128, error
);
545 ParamText(message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
546 itemHit
= Alert(129, nil
);
549 // -------------------------------------------------------------------
551 // -------------------------------------------------------------------
552 // notifies the user of a implementation specific error
553 // is useful for messages before the wx System is up and running
555 // parameters : int error = error code (implementation specific)
556 // return value : none
562 ::DisposeRgn(gMacCursorRgn
);
568 // -------------------------------------------------------------------
569 // PLTestMinimalRequirements
570 // -------------------------------------------------------------------
571 // test whether we are on the correct runnable system and read out any
572 // useful informations from the system
575 // return value : non zero for a implementation specific error code
577 int PLTestMinimalRequirements()
583 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
585 return(eWrongMachine
);
588 if (theMachine
< gestaltMacPlus
)
590 return(eWrongMachine
);
593 if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
595 return( eOldSystem
) ;
598 if ( theSystem
< 0x0700 )
600 return( eOldSystem
) ;
603 if ((long)GetApplLimit() - (long)ApplicationZone() < kMinHeap
)
608 if ( Gestalt( gestaltAppearanceAttr
, &theAppearance
) == noErr
)
610 gMacHasAppearance
= true ;
611 RegisterAppearanceClient();
612 if ( Gestalt( gestaltAppearanceVersion
, &theAppearance
) == noErr
)
614 gMacAppearanceVersion
= theAppearance
;
618 gMacAppearanceVersion
= 0x0100 ;
625 // -------------------------------------------------------------------
627 // -------------------------------------------------------------------
630 // return value : returns true if a real event occured (no null or timeout event)
638 bool gotEvent
= false ;
641 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, gMacCursorRgn
))
643 gotEvent
= PLHandleOneEvent( &event
);
655 // -------------------------------------------------------------------
657 // -------------------------------------------------------------------
659 // parameters : event = event handle of the platform specific event to be handled
660 // return value : returns true if a real event occured (no null or timeout event)
662 bool PLHandleOneEvent( PLEventHandle event
)
664 bool realEvent
= true ;
666 EventRecord
* ev
= (EventRecord
*) event
;
671 DoMacNullEvent( ev
) ;
674 case kHighLevelEvent
:
675 DoMacHighLevelEvent( ev
) ;
678 DoMacMouseDownEvent( ev
) ;
679 wxTheApp
->ExitMainLoop() ;
682 DoMacMouseUpEvent( ev
) ;
685 DoMacKeyDownEvent( ev
) ;
688 DoMacAutoKeyEvent( ev
) ;
691 DoMacKeyUpEvent( ev
) ;
694 DoMacActivateEvent( ev
) ;
697 DoMacUpdateEvent( ev
) ;
700 DoMacDiskEvent( ev
) ;
711 // platform specific functions (non PLxxx functions)
713 void DoMacNullEvent( EventRecord
*ev
)
717 void DoMacHighLevelEvent( EventRecord
*ev
)
721 void DoMacMouseDownEvent( EventRecord
*ev
)
725 void DoMacMouseUpEvent( EventRecord
*ev
)
729 void DoMacKeyDownEvent( EventRecord
*ev
)
733 void DoMacKeyUpEvent( EventRecord
*ev
)
737 void DoMacAutoKeyEvent( EventRecord
*ev
)
741 void DoMacActivateEvent( EventRecord
*ev
)
745 void DoMacUpdateEvent( EventRecord
*ev
)
749 void DoMacDiskEvent( EventRecord
*ev
)
753 void DoMacOSEvent( EventRecord
*ev
)
761 void wxApp::doMacMouseDown(void)
764 short windowPart = ::FindWindow(m_event.where, &window);
765 if ( windowPart != inMenuBar )
767 WindowPtr frontWindow = FrontWindow();
768 if (WindowIsModal(frontWindow) && (window != frontWindow))
777 doMacInContent(window); break;
779 doMacInDrag(window); break;
781 doMacInGrow(window); break;
783 doMacInGoAway(window); break;
786 doMacInZoom(window, windowPart); break;
795 doMacInMenuBar(::MenuSelect(m_event.where));
799 void wxApp::doMacMouseUp(void)
804 int hitX = m_event.where.h; // screen window c.s.
805 int hitY = m_event.where.v; // screen window c.s.
806 m_mouseWindow->ScreenToClient(&hitX, &hitY); // mouseWindow client c.s.
807 m_mouseWindow->ClientToLogical(&hitX, &hitY); // mouseWindow logical c.s.
810 wxMouseEvent event(wxEVT_LEFT_UP);
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_leftDown = FALSE;
816 event.m_middleDown = FALSE;
817 event.m_rightDown = FALSE;
818 event.m_x = m_event.where.h;
819 event.m_y = m_event.where.v;
820 event.m_timeStamp = m_event.when;
821 event.SetEventObject(m_mouseWindow);
823 m_mouseWindow->ProcessEvent(event);
827 //??? Can't we just throw away mouse up events without matching mouse down
828 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
832 int hitX = cCurrentEvent.where.h; // screen window c.s.
833 int hitY = cCurrentEvent.where.v; // screen window c.s.
834 theMacWxFrame->ScreenToWindow(&hitX, &hitY);
837 wxMouseEvent event(wxEVT_LEFT_UP);
838 event.m_shiftDown = m_event.modifiers & shiftKey;
839 event.m_controlDown = m_event.modifiers & controlKey;
840 event.m_altDown = m_event.modifiers & optionKey;
841 event.m_metaDown = m_event.modifiers & cmdKey;
842 event.m_leftDown = FALSE;
843 event.m_middleDown = FALSE;
844 event.m_rightDown = FALSE;
845 event.m_x = m_event.where.h;
846 event.m_y = m_event.where.v;
847 event.m_timeStamp = m_event.when;
848 event.SetEventObject(m_mouseWindow);
850 theMacWxFrame->ProcessEvent(event);
855 void wxApp::doMacMouseMotion(void)
858 wxMouseEvent event(wxEVT_MOTION);
859 event.m_shiftDown = m_event.modifiers & shiftKey;
860 event.m_controlDown = m_event.modifiers & controlKey;
861 event.m_altDown = m_event.modifiers & optionKey;
862 event.m_metaDown = m_event.modifiers & cmdKey;
863 event.m_leftDown = !(m_event.modifiers & btnState);
864 event.m_middleDown = FALSE;
865 event.m_rightDown = FALSE;
866 event.m_x = m_event.where.h;
867 event.m_y = m_event.where.v;
868 event.m_timeStamp = m_event.when;
869 event.SetEventObject(m_mouseWindow);
871 m_mouseWindow->ProcessEvent(event);
875 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
878 wxMouseEvent event(wxEVT_MOTION);
879 event.m_shiftDown = m_event.modifiers & shiftKey;
880 event.m_controlDown = m_event.modifiers & controlKey;
881 event.m_altDown = m_event.modifiers & optionKey;
882 event.m_metaDown = m_event.modifiers & cmdKey;
883 event.m_leftDown = !(m_event.modifiers & btnState);
884 event.m_middleDown = FALSE;
885 event.m_rightDown = FALSE;
886 event.m_x = m_event.where.h;
887 event.m_y = m_event.where.v;
888 event.m_timeStamp = m_event.when;
889 event.SetEventObject(m_mouseWindow);
891 m_mouseWindow->ProcessEvent(event);
895 //??? Need to work with floating windows... isn't there a toolbox call to find the
896 // top window intersecting a point is screen coordinates??
898 else // will only work for one floating window at the moment... ?
900 WindowPtr frontDocPtr = findFrontNonFloatingWindow();
901 WindowPtr frontFloatingPtr = ::FrontWindow();
903 int hitX = cCurrentEvent.where.h;
904 int hitY = cCurrentEvent.where.v;
906 wxFrame* macWxFrame = findMacWxFrame(frontDocPtr);
908 if ((frontFloatingPtr != frontDocPtr) & (frontFloatingPtr != NULL))
910 RgnHandle frontFloatStrRgn = getStructureRegion(frontFloatingPtr);
911 Rect frontFloatRect = (**frontFloatStrRgn).rgnBBox;
913 if ((hitX >= frontFloatRect.left) &
914 (hitX <= frontFloatRect.right) &
915 (hitY >= frontFloatRect.top) &
916 (hitY <= frontFloatRect.bottom))
918 macWxFrame = findMacWxFrame(frontFloatingPtr);
925 void wxApp::doMacKeyDown(void)
927 long menuResult = 0 ;
930 keychar = short(m_event.message & charCodeMask);
931 keycode = short(m_event.message & keyCodeMask) >> 8 ;
933 // Handle menu accelerators
934 if ( gSFMacHasAppearance )
936 menuResult = MenuEvent( &m_event ) ;
937 if ( HiWord( menuResult ) )
939 doMacInMenuBar( menuResult ) ;
943 ControlHandle control ;
945 GetKeyboardFocus( FrontNonFloatingWindow() , &control ) ;
946 if ( control && keychar != 0x07 )
947 HandleControlKey( control , keycode , keychar , m_event.modifiers ) ;
950 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
953 wxKeyEvent event(wxEVT_CHAR);
954 event.m_shiftDown = m_event.modifiers & shiftKey;
955 event.m_controlDown = m_event.modifiers & controlKey;
956 event.m_altDown = m_event.modifiers & optionKey;
957 event.m_metaDown = m_event.modifiers & cmdKey;
958 event.m_keyCode = macTranslateKey(keychar, m_event.modifiers & (shiftKey|optionKey));
959 event.m_x = m_event.where.h;
960 event.m_y = m_event.where.v;
961 event.m_timeStamp = m_event.when;
962 event.SetEventObject(theMacWxFrame);
964 theMacWxFrame->ProcessEvent(event);
971 if (GetMenuHandle( kwxMacAppleMenuId ) )
973 // menuResult = MDEF_MenuKey(m_event.message, m_event.modifiers , GetMenuHandle( kwxMacAppleMenuId ) );
977 if (m_event.modifiers & cmdKey)
979 menuResult = MenuKey( keychar ) ;
983 if ( HiWord( menuResult ) )
985 doMacInMenuBar( menuResult ) ;
989 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
992 wxKeyEvent event(wxEVT_CHAR);
993 event.m_shiftDown = m_event.modifiers & shiftKey;
994 event.m_controlDown = m_event.modifiers & controlKey;
995 event.m_altDown = m_event.modifiers & optionKey;
996 event.m_metaDown = m_event.modifiers & cmdKey;
997 event.m_keyCode = macTranslateKey(keychar, m_event.modifiers & (shiftKey|optionKey));
998 event.m_x = m_event.where.h;
999 event.m_y = m_event.where.v;
1000 event.m_timeStamp = m_event.when;
1001 event.SetEventObject(theMacWxFrame);
1003 theMacWxFrame->ProcessEvent(event);
1009 void wxApp::doMacAutoKey(void)
1014 void wxApp::doMacKeyUp(void)
1018 void wxApp::doMacActivateEvt(void)
1020 HighlightAndActivateWindow( (WindowPtr) m_event.message , m_event.modifiers & activeFlag ) ;
1023 void wxApp::doMacUpdateEvt(void)
1025 WindowPtr theMacWindow = (WindowPtr)(m_event.message);
1026 ::BeginUpdate(theMacWindow);
1028 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(theMacWindow);
1031 // if (!::EmptyRgn(theMacWindow->visRgn)) // this doesn't work with windowshade
1033 if ( theMacWxFrame->MacSetupPort() )
1035 // Erase update region
1036 // we must do this, because controls add their former rect to the inval
1037 // rgn and the background might not have been correct at that moment
1038 ::EraseRect(&theMacWindow->portRect);
1040 // Can't use UpdateControls since each control has it's own coordinate system
1041 // ::UpdateControls(theMacWindow, theMacWindow->visRgn);
1043 ::UpdateControls( theMacWindow , theMacWindow->visRgn ) ;
1045 // Draw the grow box
1046 if (cStyle & wxRESIZE_BORDER)
1051 event.m_timeStamp = m_event.when;
1052 event.SetEventObject(theMacWxFrame);
1054 theMacWxFrame->ProcessEvent(event);
1055 // ::SetThemeWindowBackground( theMacWindow , kThemeActiveDialogBackgroundBrush , false ) ;
1056 ::ClipRect( &theMacWindow->portRect ) ;
1057 ::SetOrigin( 0 , 0 );
1061 wxASSERT_MSG( false , "unabled to setup window mac port") ;
1067 ::EndUpdate(theMacWindow);
1070 void wxApp::doMacDiskEvt(void)
1071 { // based on "Programming for System 7" by Gary Little and Tim Swihart
1072 if ((m_event.message >> 16) != noErr)
1074 const int kDILeft = 0x0050; // top coord for disk init dialog
1075 const int kDITop = 0x0070; // left coord for disk init dialog
1077 mountPoint.h = kDILeft;
1078 mountPoint.v = kDITop;
1079 int myError = DIBadMount(mountPoint, m_event.message);
1083 void wxApp::doMacOsEvt(void)
1084 { // based on "Programming for System 7" by Gary Little and Tim Swihart
1085 switch ((m_event.message >> 24) & 0x0ff)
1087 case suspendResumeMessage:
1088 if (m_event.message & resumeFlag)
1091 doMacSuspendEvent();
1093 case mouseMovedMessage:
1094 doMacMouseMovedMessage();
1099 void wxApp::doMacHighLevelEvent(void)
1101 ::AEProcessAppleEvent(&m_event); // System 7 or higher
1104 void wxApp::doMacResumeEvent(void)
1106 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1109 if (m_event.message & convertClipboardFlag)
1112 wxActivateEvent event(wxEVT_ACTIVATE, TRUE);
1113 event.m_timeStamp = m_event.when;
1114 event.SetEventObject(theMacWxFrame);
1116 theMacWxFrame->ProcessEvent(event);
1120 void wxApp::doMacSuspendEvent(void)
1122 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1128 wxActivateEvent event(wxEVT_ACTIVATE, FALSE);
1129 event.m_timeStamp = m_event.when;
1130 event.SetEventObject(theMacWxFrame);
1132 theMacWxFrame->ProcessEvent(event);
1136 void wxApp::doMacMouseMovedMessage(void)
1137 { // based on "Programming for System 7" by Gary Little and Tim Swihart
1139 ::DisposeRgn(m_cursorRgn);
1140 m_cursorRgn = ::NewRgn();
1141 ::SetRectRgn(m_cursorRgn, -32768, -32768, 32766, 32766);
1144 void wxApp::doMacInMenuBar(long menuResult)
1146 int macMenuId = HiWord(menuResult);
1147 int macMenuItemNum = LoWord(menuResult); // counting from 1
1149 if (macMenuId == 0) // no menu item selected;
1151 if (macMenuId == 128)
1153 if (macMenuItemNum != 1)
1154 { // if not the "About" entry (or the separator)
1156 ::GetMenuItemText(GetMenuHandle(128), macMenuItemNum, daName);
1157 (void)::OpenDeskAcc(daName);
1163 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1166 if ( theMacWxFrame->IsKindOf( CLASSINFO( wxDialog ) ) )
1167 (( wxDialog *) theMacWxFrame)->MacMenuSelect(m_event, macMenuId, macMenuItemNum);
1168 else if ( theMacWxFrame->IsKindOf( CLASSINFO( wxFrame ) ) )
1169 (( wxFrame *) theMacWxFrame)->MacMenuSelect(m_event, macMenuId, macMenuItemNum);
1174 void wxApp::doMacInContent(WindowPtr window)
1176 WindowPtr frontWindow = FrontWindow();
1177 if (window != frontWindow )
1179 // SFSelectWindow( window ) ;
1183 ControlHandle control ;
1184 Point localwhere = m_event.where ;
1186 SInt16 controlpart ;
1188 ::GetPort( &port ) ;
1189 ::SetPort( window ) ;
1190 ::GlobalToLocal( &localwhere ) ;
1194 if ( !gSFMacHasAppearance )
1196 controlpart = FindControl( localwhere , window , &control ) ;
1200 control = FindControlUnderMouse( localwhere , window , &controlpart ) ;
1203 if ( control && IsControlActive( control ) )
1205 wxControl* wxc = (wxControl*) GetControlReference( control ) ;
1207 if ( wxWindow::FindFocus() != wxc && wxc->AcceptsFocus() )
1210 if ( wxWindow::FindFocus() != wxc )
1211 control = NULL ; // we were not able to change focus
1216 if ( !gSFMacHasAppearance)
1218 controlpart = TrackControl( control , localwhere , NULL ) ;
1222 controlpart = HandleControlClick( control , localwhere , m_event.modifiers , (ControlActionUPP) -1 ) ;
1227 wxControl* wx = (wxControl*) GetControlReference( control ) ;
1229 wx->MacHandleControlClick( control , controlpart ) ;
1235 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
1238 doMacContentClick((wxFrame*)theMacWxFrame); // todo : this cast is wrong
1244 wxFrame* theMacWxFrame = findMacWxFrame(window);
1247 WindowPtr MacWindow = findFrontNonFloatingWindow();
1248 if (window != MacWindow)
1250 wxFrame* frontFrame = findMacWxFrame(MacWindow);
1251 if (!frontFrame) wxFatalError("No wxFrame for frontnonfloatingWindow.");
1252 if (!frontFrame->IsModal())
1254 frontFrame->SetFocus();
1255 doMacContentClick(theMacWxFrame); // jonto - to deal with doc windows behind floaters ?
1256 ::newSelectWindow(window); // WCH : should I be calling some wxMethod?
1257 if (!IsFloating(MacWindow))
1261 if (!(keyMap[1] & 0x8000)) theMacWxFrame->ShowAsActive(true); // temporary measure...
1263 } // jonto : not sure yet, but let's try this ...
1268 doMacContentClick(theMacWxFrame);
1274 void wxApp::doMacContentClick(wxWindow* frame)
1276 m_mouseWindow = frame;
1278 wxMouseEvent event(wxEVT_LEFT_DOWN);
1279 event.m_shiftDown = m_event.modifiers & shiftKey;
1280 event.m_controlDown = m_event.modifiers & controlKey;
1281 event.m_altDown = m_event.modifiers & optionKey;
1282 event.m_metaDown = m_event.modifiers & cmdKey;
1283 event.m_leftDown = FALSE;
1284 event.m_middleDown = FALSE;
1285 event.m_rightDown = FALSE;
1286 if ( m_event.modifiers & controlKey )
1288 event.m_rightDown = TRUE;
1292 event.m_leftDown = TRUE;
1295 event.m_leftDown = !(m_event.modifiers & btnState);
1296 event.m_middleDown = FALSE;
1297 event.m_rightDown = FALSE;
1299 event.m_x = m_event.where.h;
1300 event.m_y = m_event.where.v;
1301 event.m_timeStamp = m_event.when;
1302 event.SetEventObject(m_mouseWindow);
1304 // m_mouseWindow->ProcessEvent(event);
1305 m_mouseWindow->MacDispatchMouseEvent(event);
1308 // RightButton is cmdKey click on the mac platform for one-button mouse
1309 Bool rightButton = cCurrentEvent.modifiers & cmdKey;
1310 // altKey is optionKey on the mac platform:
1311 Bool isAltKey = cCurrentEvent.modifiers & optionKey;
1313 WXTYPE mouseEventType = rightButton ? wxEVENT_TYPE_RIGHT_DOWN
1314 : wxEVENT_TYPE_LEFT_DOWN;
1315 wxMouseEvent theMouseEvent(mouseEventType);
1316 theMouseEvent.leftDown = !rightButton;
1317 theMouseEvent.middleDown = FALSE;
1318 theMouseEvent.rightDown = rightButton;
1319 theMouseEvent.shiftDown = cCurrentEvent.modifiers & shiftKey;
1320 theMouseEvent.controlDown = cCurrentEvent.modifiers & controlKey;
1321 theMouseEvent.altDown = isAltKey;
1322 theMouseEvent.metaDown = FALSE; // mflatt
1323 theMouseEvent.timeStamp = cCurrentEvent.when; // mflatt
1325 int hitX = cCurrentEvent.where.h; // screen window c.s.
1326 int hitY = cCurrentEvent.where.v; // screen window c.s.
1328 frame->ScreenToWindow(&hitX, &hitY);
1329 // frameParentArea->ScreenToArea(&hitX, &hitY); // tx coords ?
1330 theMouseEvent.x = hitX; // frame parent area c.s.
1331 theMouseEvent.y = hitY; // frame parent area c.s.
1333 frame->SeekMouseEventArea(theMouseEvent);
1337 void wxApp::doMacInDrag(WindowPtr window)
1339 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
1342 // should be desktop, not screen
1343 Rect dragBoundsRect = qd.screenBits.bounds; // can't move to a different screen
1344 //xxx ::InsetRect(&dragBoundsRect, 4, ::GetMBarHeight() + 4); // This is not really necessary
1345 Rect oldPos = (**(((WindowPeek)window)->strucRgn)).rgnBBox;
1346 ::DragReferencedWindow(window, m_event.where, &dragBoundsRect); // jonto
1348 theMacWxFrame->m_x += (**(((WindowPeek)window)->strucRgn)).rgnBBox.left - oldPos.left;
1349 theMacWxFrame->m_y += (**(((WindowPeek)window)->strucRgn)).rgnBBox.top - oldPos.top;
1351 Move( (**(((WindowPeek)window)->strucRgn)).rgnBBox.left , (**(((WindowPeek)window)->strucRgn)).rgnBBox.top ) ;
1353 theMacWxFrame->wxMacRecalcNewSize(); // Actually, recalc new position only
1358 // if (window != ::FrontWindow())
1359 if (window != findFrontNonFloatingWindow())
1361 // wxFrame* frontFrame = findMacWxFrame(::FrontWindow());
1362 wxFrame* frontFrame = findMacWxFrame(findFrontNonFloatingWindow());
1363 if (!frontFrame) wxFatalError("No wxFrame for frontWindow.");
1364 if (frontFrame->IsModal())
1371 wxFrame* theMacWxFrame = findMacWxFrame(window);
1374 Rect dragBoundsRect = qd.screenBits.bounds; // can't move to a different screen
1375 ::InsetRect(&dragBoundsRect, 4, ::GetMBarHeight() + 4); // This is not really necessary
1376 newDragWindow(window, cCurrentEvent.where, &dragBoundsRect); // jonto
1377 theMacWxFrame->wxMacRecalcNewSize(); // Actually, recalc new position only
1378 if (!IsFloating(window))
1380 theMacWxFrame->ShowAsActive(true); // temporary measure...
1386 void wxApp::doMacInGrow(WindowPtr window)
1388 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
1391 Rect growSizeRect; // WCH: growSizeRect should be a member of wxFrame class
1392 growSizeRect.top = 1; // minimum window height
1393 growSizeRect.left = 1; // minimum window width
1394 growSizeRect.bottom = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
1395 growSizeRect.right = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
1396 long windSize = ::GrowWindow(window, m_event.where, &growSizeRect);
1399 int nWidth = LoWord(windSize);
1400 int nHeight = HiWord(windSize);
1401 int oWidth, oHeight;
1402 theMacWxFrame->GetSize(&oWidth, &oHeight);
1403 if (nWidth == 0) nWidth = oWidth;
1404 if (nHeight == 0) nHeight = oHeight;
1405 theMacWxFrame->SetSize( -1, -1, nWidth, nHeight, wxSIZE_USE_EXISTING);
1410 void wxApp::doMacInGoAway(WindowPtr window)
1412 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
1415 if (TrackGoAway(window, m_event.where))
1417 if (theMacWxFrame->OnClose()) {
1418 #if WXGARBAGE_COLLECTION_ON
1419 theMacWxFrame->Show(FALSE);
1421 delete theMacWxFrame;
1428 void wxApp::doMacInZoom(WindowPtr window, short windowPart)
1430 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
1433 if (TrackBox(window, m_event.where, windowPart))
1436 theMacWxFrame->Maximize(windowPart == inZoomOut);
1442 long wxApp::macTranslateKey(char key, int mods)
1444 static Handle transH = NULL;
1445 static unsigned long transState = 0;
1446 static Handle ScriptH = NULL;
1447 static short region_code = 1;
1449 if (!ScriptH) { // tom: don't guess the regioncode!!!!
1450 struct ItlbRecord * r;
1451 ScriptH = GetResource('itlb',0);
1454 r = (ItlbRecord*)*ScriptH;
1455 region_code = r->itlbKeys;
1504 transH = GetIndResource('KCHR', 1);
1507 #if 0 //Tom replaces
1509 // Only let shift & option modify the key:
1511 key = KeyTranslate(*transH, (key & 0x7F) | mods, &transState) & charCodeMask;
1514 if (0) { // tom fettig@dfki.uni-sb.de
1516 // code is not correct, see inside Macintosh: Text 1-87
1517 // and 'itlk'-resource!!
1518 // and it is not necessary, as the translated char is in
1519 // cCurrrentEvent.message!!
1520 // Only let shift & option modify the key:
1522 key = KeyTranslate(*transH, (key & 0x7F) | mods, &transState) & charCodeMask;
1532 wxApp::macAdjustCursor()
1534 if (m_event.what != kHighLevelEvent)
1536 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1539 if (!theMacWxFrame->MacAdjustCursor(m_event.where))
1540 ::SetCursor(&(qd.arrow));