From facd6764872eede45605ba7c9dfa0e1d0c708fa2 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sat, 27 Mar 2004 09:44:31 +0000 Subject: [PATCH] new control based view architecture git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26408 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/app.cpp | 1136 +-------------- src/mac/carbon/bmpbuttn.cpp | 18 +- src/mac/carbon/brush.cpp | 8 +- src/mac/carbon/button.cpp | 64 +- src/mac/carbon/checkbox.cpp | 17 +- src/mac/carbon/checklst.cpp | 32 +- src/mac/carbon/choice.cpp | 39 +- src/mac/carbon/clipbrd.cpp | 5 - src/mac/carbon/combobox.cpp | 4 +- src/mac/carbon/control.cpp | 721 +--------- src/mac/carbon/dc.cpp | 210 +-- src/mac/carbon/dialog.cpp | 9 +- src/mac/carbon/dirmac.cpp | 20 +- src/mac/carbon/dnd.cpp | 2 +- src/mac/carbon/font.cpp | 220 ++- src/mac/carbon/frame.cpp | 75 +- src/mac/carbon/gauge.cpp | 18 +- src/mac/carbon/glcanvas.cpp | 8 +- src/mac/carbon/gsockosx.cpp | 2 +- src/mac/carbon/listbox.cpp | 942 +++++++++++-- src/mac/carbon/mdi.cpp | 5 +- src/mac/carbon/notebmac.cpp | 173 +-- src/mac/carbon/radiobox.cpp | 57 +- src/mac/carbon/radiobut.cpp | 19 +- src/mac/carbon/scrolbar.cpp | 38 +- src/mac/carbon/slider.cpp | 123 +- src/mac/carbon/spinbutt.cpp | 21 +- src/mac/carbon/statbox.cpp | 18 +- src/mac/carbon/statbrma.cpp | 34 +- src/mac/carbon/statlmac.cpp | 12 +- src/mac/carbon/stattext.cpp | 211 +-- src/mac/carbon/tabctrl.cpp | 12 +- src/mac/carbon/textctrl.cpp | 1414 ++++++++----------- src/mac/carbon/tglbtn.cpp | 29 +- src/mac/carbon/timer.cpp | 4 - src/mac/carbon/toolbar.cpp | 157 ++- src/mac/carbon/tooltip.cpp | 2 +- src/mac/carbon/toplevel.cpp | 1065 ++++++-------- src/mac/carbon/uma.cpp | 87 +- src/mac/carbon/utils.cpp | 51 +- src/mac/carbon/window.cpp | 2010 +++++++++++++++++---------- src/mac/corefoundation/gsockosx.cpp | 2 +- 42 files changed, 3977 insertions(+), 5117 deletions(-) diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index f66548a217..dfb23fd941 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -68,8 +68,7 @@ #endif extern wxList wxPendingDelete; -extern wxList *wxWinMacWindowList; -extern wxList *wxWinMacControlList; + #if wxUSE_THREADS extern size_t g_numberOfThreads; #endif // wxUSE_THREADS @@ -78,12 +77,8 @@ extern size_t g_numberOfThreads; static bool s_inYield = FALSE; -#if TARGET_CARBON static bool s_inReceiveEvent = FALSE ; static EventTime sleepTime = kEventDurationNoWait ; -#else -static long sleepTime = 0 ; -#endif #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) @@ -306,33 +301,31 @@ void wxApp::MacReopenApp() // Carbon Event Handler //---------------------------------------------------------------------- -#if TARGET_CARBON - - static const EventTypeSpec eventList[] = - { - { kEventClassCommand, kEventProcessCommand } , - { kEventClassCommand, kEventCommandUpdateStatus } , +static const EventTypeSpec eventList[] = +{ + { kEventClassCommand, kEventProcessCommand } , + { kEventClassCommand, kEventCommandUpdateStatus } , - { kEventClassMenu, kEventMenuOpening }, - { kEventClassMenu, kEventMenuClosed }, - { kEventClassMenu, kEventMenuTargetItem }, + { kEventClassMenu, kEventMenuOpening }, + { kEventClassMenu, kEventMenuClosed }, + { kEventClassMenu, kEventMenuTargetItem }, - { kEventClassApplication , kEventAppActivated } , - { kEventClassApplication , kEventAppDeactivated } , - // handling the quit event is not recommended by apple - // rather using the quit apple event - which we do + { kEventClassApplication , kEventAppActivated } , + { kEventClassApplication , kEventAppDeactivated } , + // handling the quit event is not recommended by apple + // rather using the quit apple event - which we do - { kEventClassAppleEvent , kEventAppleEvent } , + { kEventClassAppleEvent , kEventAppleEvent } , - { kEventClassMouse , kEventMouseDown } , - { kEventClassMouse , kEventMouseMoved } , - { kEventClassMouse , kEventMouseUp } , - { kEventClassMouse , kEventMouseDragged } , - { 'WXMC' , 'WXMC' } - } ; + { kEventClassMouse , kEventMouseDown } , + { kEventClassMouse , kEventMouseMoved } , + { kEventClassMouse , kEventMouseUp } , + { kEventClassMouse , kEventMouseDragged } , + { 'WXMC' , 'WXMC' } +} ; static pascal OSStatus -MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +wxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar(); @@ -387,69 +380,7 @@ MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) return eventNotHandledErr; } -// due to the rather low-level event API of wxWindows, 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 - -pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ; - -static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) -{ - OSStatus result = eventNotHandledErr ; - - Point point ; - UInt32 modifiers = 0; - EventMouseButton button = 0 ; - UInt32 click = 0 ; - - GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, - sizeof( Point ), NULL, &point ); - GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, - sizeof( UInt32 ), NULL, &modifiers ); - GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL, - sizeof( EventMouseButton ), NULL, &button ); - GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL, - sizeof( UInt32 ), NULL, &click ); - - if ( button == 0 || GetEventKind( event ) == kEventMouseUp ) - modifiers += btnState ; - - - switch( GetEventKind(event) ) - { - case kEventMouseDown : - { - WindowRef window ; - - short windowPart = ::FindWindow(point, &window); - - if ( windowPart == inMenuBar ) - { - MenuSelect( point ) ; - result = noErr ; - } - } - break ; - case kEventMouseDragged : - case kEventMouseUp : - { - if ( wxTheApp->s_captureWindow ) - wxMacWindowEventHandler( handler , event , (void*) wxTheApp->s_captureWindow->MacGetTopLevelWindow() ) ; - } - break ; - case kEventMouseMoved : - { - wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; - result = noErr ; - break ; - } - break ; - } - - return result ; -} - -static pascal OSStatus CommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; @@ -504,7 +435,7 @@ static pascal OSStatus CommandEventHandler( EventHandlerCallRef handler , EventR return result ; } -static pascal OSStatus ApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +static pascal OSStatus wxMacAppApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; switch ( GetEventKind( event ) ) @@ -512,14 +443,14 @@ static pascal OSStatus ApplicationEventHandler( EventHandlerCallRef handler , Ev case kEventAppActivated : { if ( wxTheApp ) - wxTheApp->MacResume( true ) ; + wxTheApp->SetActive( true , NULL ) ; result = noErr ; } break ; case kEventAppDeactivated : { if ( wxTheApp ) - wxTheApp->MacSuspend( true ) ; + wxTheApp->SetActive( false , NULL ) ; result = noErr ; } break ; @@ -529,22 +460,22 @@ static pascal OSStatus ApplicationEventHandler( EventHandlerCallRef handler , Ev return result ; } -pascal OSStatus wxAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +pascal OSStatus wxMacAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; switch( GetEventClass( event ) ) { case kEventClassCommand : - result = CommandEventHandler( handler , event , data ) ; + result = wxMacAppCommandEventHandler( handler , event , data ) ; break ; case kEventClassApplication : - result = ApplicationEventHandler( handler , event , data ) ; + result = wxMacAppApplicationEventHandler( handler , event , data ) ; break ; case kEventClassMenu : - result = MenuEventHandler( handler , event , data ) ; + result = wxMacAppMenuEventHandler( handler , event , data ) ; break ; case kEventClassMouse : - result = MouseEventHandler( handler , event , data ) ; + result = wxMacTopLevelMouseEventHandler( handler , event , data ) ; break ; case kEventClassAppleEvent : { @@ -560,21 +491,56 @@ pascal OSStatus wxAppEventHandler( EventHandlerCallRef handler , EventRef event return result ; } -DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler ) - -#endif +DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacAppEventHandler ) #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__) // we know it's there ;-) WXIMPORT char std::__throws_bad_alloc ; #endif -bool wxApp::Initialize(int& argc, wxChar **argv) +pascal static void wxMacAssertOutputHandler(OSType componentSignature, UInt32 options, + const char *assertionString, const char *exceptionLabelString, + const char *errorString, const char *fileName, long lineNumber, void *value, ConstStr255Param outputMsg) { - int error = 0 ; + // flow into assert handling + wxString fileNameStr ; + wxString assertionStr ; + wxString exceptionStr ; + wxString errorStr ; +#if wxUSE_UNICODE + fileNameStr = wxString(fileName, wxConvLocal); + assertionStr = wxString(assertionString, wxConvLocal); + exceptionStr = wxString((exceptionLabelString!=0) ? exceptionLabelString : "", wxConvLocal) ; + errorStr = wxString((errorString!=0) ? errorString : "", wxConvLocal) ; +#else + fileNameStr = fileName; + assertionStr = assertionString; + exceptionStr = (exceptionLabelString!=0) ? exceptionLabelString : "" ; + errorStr = (errorString!=0) ? errorString : "" ; +#endif +#if 1 + // flow into log + wxLogDebug( wxT("AssertMacros: %s %s %s file: %s, line: %d (value %d)\n"), + assertionStr.c_str() , + exceptionStr.c_str() , + errorStr.c_str(), + fileNameStr.c_str(), lineNumber , + value ) ; +#else + + wxOnAssert(fileNameStr, lineNumber , assertionStr , + wxString::Format( wxT("%s %s value (%d)") ,exceptionStr, errorStr , value ) ) ; +#endif +} + +bool wxApp::Initialize(int& argc, wxChar **argv) +{ // Mac-specific +#if __WXDEBUG__ + InstallDebugAssertOutputHandler ( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) ); +#endif UMAInitToolbox( 4, sm_isEmbedded ) ; SetEventMask( everyEvent ) ; UMAShowWatchCursor() ; @@ -585,60 +551,6 @@ bool wxApp::Initialize(int& argc, wxChar **argv) wxStAppResource::OpenSharedLibraryResource(NULL); #endif -#ifndef __DARWIN__ - // test the minimal configuration necessary - -# if !TARGET_CARBON - long theSystem ; - long theMachine; - - if (Gestalt(gestaltMachineType, &theMachine) != noErr) - { - error = kMacSTRWrongMachine; - } - else if (theMachine < gestaltMacPlus) - { - error = kMacSTRWrongMachine; - } - else if (Gestalt(gestaltSystemVersion, &theSystem) != noErr ) - { - error = kMacSTROldSystem ; - } - else if ( theSystem < 0x0860 ) - { - error = kMacSTROldSystem ; - } - else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap) - { - error = kMacSTRSmallSize; - } -# endif - /* - else - { - if ( !UMAHasAppearance() ) - { - error = kMacSTRNoPre8Yet ; - } - } - */ -#endif - - // if we encountered any problems so far, give the error code and exit immediately - - if ( error ) - { - wxStAppResource resload ; - short itemHit; - Str255 message; - - GetIndString(message, 128, error); - UMAShowArrowCursor() ; - ParamText("\pFatal Error", message, (ConstStr255Param)"\p", (ConstStr255Param)"\p"); - itemHit = Alert(128, nil); - return FALSE ; - } - #ifndef __DARWIN__ # if __option(profile) ProfilerInit( collectDetailed, bestTimeBase , 40000 , 50 ) ; @@ -679,9 +591,6 @@ bool wxApp::Initialize(int& argc, wxChar **argv) #endif - wxWinMacWindowList = new wxList(wxKEY_INTEGER); - wxWinMacControlList = new wxList(wxKEY_INTEGER); - wxMacCreateNotifierTable() ; UMAShowArrowCursor() ; @@ -694,20 +603,17 @@ bool wxApp::OnInitGui() if( !wxAppBase::OnInitGui() ) return false ; -#if TARGET_CARBON InstallStandardEventHandler( GetApplicationEventTarget() ) ; if (!sm_isEmbedded) { InstallApplicationEventHandler( - GetwxAppEventHandlerUPP(), + GetwxMacAppEventHandlerUPP(), GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler)); } -#endif if (!sm_isEmbedded) { -#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , NewAEEventHandlerUPP(AEHandleODoc) , 0 , FALSE ) ; @@ -723,23 +629,6 @@ bool wxApp::OnInitGui() AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerUPP(AEHandleQuit) , 0 , FALSE ) ; -#else - AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , - NewAEEventHandlerProc(AEHandleODoc) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , - NewAEEventHandlerProc(AEHandleOApp) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , - NewAEEventHandlerProc(AEHandlePDoc) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEReopenApplication , - NewAEEventHandlerProc(AEHandleRApp) , - 0 , FALSE ) ; - AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , - NewAEEventHandlerProc(AEHandleQuit) , - 0 , FALSE ) ; -#endif } return TRUE ; @@ -754,12 +643,6 @@ void wxApp::CleanUp() wxMacDestroyNotifierTable() ; - delete wxWinMacWindowList ; - wxWinMacWindowList = NULL; - - delete wxWinMacControlList ; - wxWinMacControlList = NULL; - #ifndef __DARWIN__ # if __option(profile) ProfilerDump( (StringPtr)"\papp.prof" ) ; @@ -791,7 +674,7 @@ void wxApp::CleanUp() // extern variable for shared library resource id // need to be able to find it with NSLookupAndBindSymbol -short WXDLLEXPORT gSharedLibraryResource = kResFileNotOpened ; +short gSharedLibraryResource = kResFileNotOpened ; #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__) CFBundleRef gSharedLibraryBundle = NULL; @@ -962,8 +845,6 @@ pascal void __wxterminate(void) #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */ -#if TARGET_CARBON - bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) { bool converted = ConvertEventRefToEventRecord( event,rec) ; @@ -1042,47 +923,12 @@ bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) return converted ; } -/* -pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) -{ - OSStatus result = eventNotHandledErr ; - - EventRecord rec ; - switch ( GetEventClass( event ) ) - { - case kEventClassKeyboard : - if ( wxMacConvertEventToRecord( event , &rec ) ) - { - wxTheApp->MacHandleModifierEvents( &rec ) ; - wxTheApp->MacHandleOneEvent( &rec ) ; - result = noErr ; - } - break ; - case kEventClassTextInput : - if ( wxMacConvertEventToRecord( event , &rec ) ) - { - wxTheApp->MacHandleModifierEvents( &rec ) ; - wxTheApp->MacHandleOneEvent( &rec ) ; - result = noErr ; - } - break ; - default : - break ; - } - return result ; -} -*/ -#endif - wxApp::wxApp() { m_printMode = wxPRINT_WINDOWS; - m_auto3D = TRUE; m_macCurrentEvent = NULL ; -#if TARGET_CARBON m_macCurrentEventHandlerCallRef = NULL ; -#endif } int wxApp::MainLoop() @@ -1105,16 +951,10 @@ void wxApp::ExitMainLoop() // Is a message/event pending? bool wxApp::Pending() { -#if TARGET_CARBON // without the receive event (with pull param = false ) nothing is ever reported EventRef theEvent; ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, &theEvent); return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ; -#else - EventRecord event ; - - return EventAvail( everyEvent , &event ) ; -#endif } // Dispatch a message. @@ -1192,7 +1032,7 @@ bool wxApp::Yield(bool onlyIfNeeded) YieldToAnyThread() ; #endif // by definition yield should handle all non-processed events -#if TARGET_CARBON + EventRef theEvent; OSStatus status = noErr ; @@ -1218,23 +1058,6 @@ bool wxApp::Yield(bool onlyIfNeeded) ReleaseEvent(theEvent); } } while( status == noErr ) ; -#else - EventRecord event ; - - // having a larger value here leads to large performance slowdowns - // so we cannot give background apps more processor time here - // we do so however having a large sleep value in the main event loop - sleepTime = 0 ; - - while ( !IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) - { - MacHandleModifierEvents( &event ) ; - MacHandleOneEvent( &event ); - if ( event.what != kHighLevelEvent ) - SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; - } - MacHandleModifierEvents( &event ) ; -#endif wxMacProcessNotifierAndPendingEvents() ; s_inYield = FALSE; @@ -1242,73 +1065,8 @@ bool wxApp::Yield(bool onlyIfNeeded) return TRUE; } -// platform specifics - -void wxApp::MacSuspend( bool convertClipboard ) -{ -#if !TARGET_CARBON - // we have to deactive the top level windows manually - - wxWindowListNode* node = wxTopLevelWindows.GetFirst(); - while (node) - { - wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data(); -#if TARGET_CARBON -#if 0 // having problems right now with that - if (!win->HasFlag(wxSTAY_ON_TOP)) -#endif -#endif - win->MacActivate( ((EventRecord*) MacGetCurrentEvent())->when , false ) ; - - node = node->GetNext(); - } - - ::HideFloatingWindows() ; -#endif - s_lastMouseDown = 0 ; - - if( convertClipboard ) - { - MacConvertPrivateToPublicScrap() ; - } -} - -extern wxList wxModalDialogs; - -void wxApp::MacResume( bool convertClipboard ) -{ - s_lastMouseDown = 0 ; - if( convertClipboard ) - { - MacConvertPublicToPrivateScrap() ; - } - -#if !TARGET_CARBON - ::ShowFloatingWindows() ; - // raise modal dialogs in case a non modal window was selected to activate the app - - wxNode* node = wxModalDialogs.GetFirst(); - while (node) - { - wxDialog* dialog = (wxDialog *) node->GetData(); - dialog->Raise(); - - node = node->GetNext(); - } -#endif -} - -void wxApp::MacConvertPrivateToPublicScrap() -{ -} - -void wxApp::MacConvertPublicToPrivateScrap() -{ -} - void wxApp::MacDoOneEvent() { -#if TARGET_CARBON EventRef theEvent; s_inReceiveEvent = true ; @@ -1343,43 +1101,6 @@ void wxApp::MacDoOneEvent() ReleaseEvent(theEvent); sleepTime = kEventDurationNoWait ; } -#else - EventRecord event ; - - EventMask eventMask = everyEvent ; - - if (WaitNextEvent(eventMask, &event, sleepTime, (RgnHandle) s_macCursorRgn)) - { - MacHandleModifierEvents( &event ) ; - MacHandleOneEvent( &event ); - } - else - { - MacHandleModifierEvents( &event ) ; - // idlers - WindowPtr window = ::FrontWindow() ; - if ( window ) - ::IdleControls( window ) ; - - if ( wxTheApp->ProcessIdle() ) - sleepTime = kEventDurationNoWait; - else - { -#if wxUSE_THREADS - if (g_numberOfThreads) - { - sleepTime = kEventDurationNoWait; - } - else -#endif // wxUSE_THREADS - { - sleepTime = kEventDurationSecond; - } - } - } - if ( event.what != kHighLevelEvent ) - SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; -#endif // repeaters DeletePendingObjects() ; @@ -1393,7 +1114,6 @@ void wxApp::MacDoOneEvent() void wxApp::MacHandleOneEvent( WXEVENTREF evr ) { -#if TARGET_CARBON EventTargetRef theTarget; theTarget = GetEventDispatcherTarget(); m_macCurrentEvent = evr ; @@ -1402,321 +1122,9 @@ void wxApp::MacHandleOneEvent( WXEVENTREF evr ) { MacHandleUnhandledEvent(evr); } -#else - EventRecord* ev = (EventRecord*) evr ; - m_macCurrentEvent = ev ; - - wxApp::sm_lastMessageTime = ev->when ; - - switch (ev->what) - { - case mouseDown: - MacHandleMouseDownEvent( ev ) ; - if ( ev->modifiers & controlKey ) - s_lastMouseDown = 2; - else - s_lastMouseDown = 1; - break; - case mouseUp: - if ( s_lastMouseDown == 2 ) - { - ev->modifiers |= controlKey ; - } - else - { - ev->modifiers &= ~controlKey ; - } - MacHandleMouseUpEvent( ev ) ; - s_lastMouseDown = 0; - break; - case activateEvt: - MacHandleActivateEvent( ev ) ; - break; - case updateEvt: - // In embedded mode we first let the UnhandledEvent function - // try to handle the update event. If we handle it ourselves - // first and then pass it on, the host's windows won't update. - MacHandleUnhandledEvent(ev); - MacHandleUpdateEvent( ev ) ; - break; - case keyDown: - case autoKey: - MacHandleKeyDownEvent( ev ) ; - break; - case keyUp: - MacHandleKeyUpEvent( ev ) ; - break; - case diskEvt: - MacHandleDiskEvent( ev ) ; - break; - case osEvt: - MacHandleOSEvent( ev ) ; - break; - case kHighLevelEvent: - MacHandleHighLevelEvent( ev ) ; - break; - default: - break; - } -#endif wxMacProcessNotifierAndPendingEvents() ; } -#if !TARGET_CARBON -bool s_macIsInModalLoop = false ; - -void wxApp::MacHandleModifierEvents( WXEVENTREF evr ) -{ - EventRecord* ev = (EventRecord*) evr ; - if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL ) - { - wxKeyEvent event(wxEVT_KEY_DOWN); - - event.m_shiftDown = ev->modifiers & shiftKey; - event.m_controlDown = ev->modifiers & controlKey; - event.m_altDown = ev->modifiers & optionKey; - event.m_metaDown = ev->modifiers & cmdKey; - - event.m_x = ev->where.h; - event.m_y = ev->where.v; - event.m_timeStamp = ev->when; - wxWindow* focus = wxWindow::FindFocus() ; - event.SetEventObject(focus); - - if ( (ev->modifiers ^ s_lastModifiers ) & controlKey ) - { - event.m_keyCode = WXK_CONTROL ; - event.SetEventType( ( ev->modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; - focus->GetEventHandler()->ProcessEvent( event ) ; - } - if ( (ev->modifiers ^ s_lastModifiers ) & shiftKey ) - { - event.m_keyCode = WXK_SHIFT ; - event.SetEventType( ( ev->modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; - focus->GetEventHandler()->ProcessEvent( event ) ; - } - if ( (ev->modifiers ^ s_lastModifiers ) & optionKey ) - { - event.m_keyCode = WXK_ALT ; - event.SetEventType( ( ev->modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; - focus->GetEventHandler()->ProcessEvent( event ) ; - } - if ( ( ev->modifiers ^ s_lastModifiers ) & cmdKey ) - { - event.m_keyCode = WXK_COMMAND ; - event.SetEventType( ( ev->modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; - focus->GetEventHandler()->ProcessEvent( event ) ; - } - s_lastModifiers = ev->modifiers ; - } -} - -void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr ) -{ - // we must avoid reentrancy problems when processing high level events eg printing - bool former = s_inYield ; - s_inYield = TRUE ; - EventRecord* ev = (EventRecord*) evr ; - ::AEProcessAppleEvent( ev ) ; - s_inYield = former ; -} - -void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr ) -{ - EventRecord* ev = (EventRecord*) evr ; - wxToolTip::RemoveToolTips() ; - - WindowRef window; - WindowRef frontWindow = ::FrontNonFloatingWindow() ; - WindowAttributes frontWindowAttributes = NULL ; - if ( frontWindow ) - ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ; - - short windowPart = ::FindWindow(ev->where, &window); - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; - if ( wxPendingDelete.Member(win) ) - return ; - - BitMap screenBits; - GetQDGlobalsScreenBits( &screenBits ); - - switch (windowPart) - { - case inMenuBar : - if ( s_macIsInModalLoop ) - { - SysBeep ( 30 ) ; - } - else - { - UInt32 menuresult = MenuSelect(ev->where) ; - MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ); - s_lastMouseDown = 0; - } - break ; - case inSysWindow : - SystemClick( ev , window ) ; - s_lastMouseDown = 0; - break ; - case inDrag : - if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) ) - { - SysBeep ( 30 ) ; - } - else - { - DragWindow(window, ev->where, &screenBits.bounds); - if (win) - { - GrafPtr port ; - GetPort( &port ) ; - Point pt = { 0, 0 } ; - SetPortWindowPort(window) ; - LocalToGlobal( &pt ) ; - SetPort( port ) ; - win->SetSize( pt.h , pt.v , -1 , - -1 , wxSIZE_USE_EXISTING); - } - s_lastMouseDown = 0; - } - break ; - case inGoAway: - if (TrackGoAway(window, ev->where)) - { - if ( win ) - win->Close() ; - } - s_lastMouseDown = 0; - break; - case inGrow: - { - Rect newContentRect ; - Rect constraintRect ; - constraintRect.top = win->GetMinHeight() ; - if ( constraintRect.top == -1 ) - constraintRect.top = 0 ; - constraintRect.left = win->GetMinWidth() ; - if ( constraintRect.left == -1 ) - constraintRect.left = 0 ; - constraintRect.right = win->GetMaxWidth() ; - if ( constraintRect.right == -1 ) - constraintRect.right = 32000 ; - constraintRect.bottom = win->GetMaxHeight() ; - if ( constraintRect.bottom == -1 ) - constraintRect.bottom = 32000 ; - - Boolean growResult = ResizeWindow( window , ev->where , - &constraintRect , &newContentRect ) ; - if ( growResult ) - { - win->SetSize( newContentRect.left , newContentRect.top , - newContentRect.right - newContentRect.left , - newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); - } - s_lastMouseDown = 0; - } - break; - case inZoomIn: - case inZoomOut: - if (TrackBox(window, ev->where, windowPart)) - { - // TODO setup size event - ZoomWindow( window , windowPart , false ) ; - if (win) - { - Rect tempRect ; - GrafPtr port ; - GetPort( &port ) ; - Point pt = { 0, 0 } ; - SetPortWindowPort(window) ; - LocalToGlobal( &pt ) ; - SetPort( port ) ; - - GetWindowPortBounds(window, &tempRect ) ; - win->SetSize( pt.h , pt.v , tempRect.right-tempRect.left , - tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING); - } - } - s_lastMouseDown = 0; - break; - case inCollapseBox : - // TODO setup size event - s_lastMouseDown = 0; - break ; - - case inContent : - { - GrafPtr port ; - GetPort( &port ) ; - SetPortWindowPort(window) ; - SetPort( port ) ; - } - if ( window != frontWindow && wxTheApp->s_captureWindow == NULL ) - { - if ( s_macIsInModalLoop ) - { - SysBeep ( 30 ) ; - } - else if ( UMAIsWindowFloating( window ) ) - { - if ( win ) - win->MacMouseDown( ev , windowPart ) ; - } - else - { - // Activate window first - ::SelectWindow( window ) ; - - // Send event later - if ( win ) - win->MacMouseDown( ev , windowPart ) ; - } - } - else - { - if ( win ) - win->MacMouseDown( ev , windowPart ) ; - } - break ; - default: - break; - } -} - -void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr ) -{ - EventRecord* ev = (EventRecord*) evr ; - WindowRef window; - - short windowPart = inNoWindow ; - if ( wxTheApp->s_captureWindow ) - { - window = (WindowRef) s_captureWindow->MacGetRootWindow() ; - windowPart = inContent ; - } - else - { - windowPart = ::FindWindow(ev->where, &window) ; - } - - switch (windowPart) - { - case inMenuBar : - break ; - case inSysWindow : - break ; - default: - { - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; - if ( win ) - win->MacMouseUp( ev , windowPart ) ; - } - break; - } -} - -#endif - long wxMacTranslateKey(unsigned char key, unsigned char code) ; long wxMacTranslateKey(unsigned char key, unsigned char code) { @@ -1826,7 +1234,7 @@ long wxMacTranslateKey(unsigned char key, unsigned char code) return retval; } -int wxKeyCodeToMacModifier(wxKeyCode key) +int wxMacKeyCodeToModifier(wxKeyCode key) { switch (key) { @@ -1861,7 +1269,7 @@ bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below //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)); + return !!(GetCurrentKeyModifiers() & wxMacKeyCodeToModifier(key)); //else // KeyMapByteArray keymap; // GetKeys((BigEndianLong*)keymap); @@ -1869,57 +1277,6 @@ bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below //#endif } -#if !TARGET_CARBON -void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) -{ - EventRecord* ev = (EventRecord*) evr ; - wxToolTip::RemoveToolTips() ; - - UInt32 menuresult = UMAMenuEvent(ev) ; - if ( HiWord( menuresult ) ) - { - if ( !s_macIsInModalLoop ) - MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ; - } - else - { - wxWindow* focus = wxWindow::FindFocus() ; - - if ( MacSendKeyDownEvent( focus , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false ) - { -#if 0 - // we must handle control keys the other way round, otherwise text content is updated too late - // has not been handled -> perform default - wxControl* control = wxDynamicCast( focus , wxControl ) ; - if ( control && control->GetMacControl() != NULL ) - { - short keycode ; - short keychar ; - keychar = short(ev->message & charCodeMask); - keycode = short(ev->message & keyCodeMask) >> 8 ; - ::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ; - } -#endif - } - } -} - -void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr ) -{ - EventRecord* ev = (EventRecord*) evr ; - wxToolTip::RemoveToolTips() ; - - UInt32 menuresult = UMAMenuEvent(ev) ; - if ( HiWord( menuresult ) ) - { - } - else - { - MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ; - } -} - -#endif bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) { @@ -2092,348 +1449,3 @@ bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifier return handled ; } - -#if !TARGET_CARBON -void wxApp::MacHandleActivateEvent( WXEVENTREF evr ) -{ - EventRecord* ev = (EventRecord*) evr ; - WindowRef window = (WindowRef) ev->message ; - if ( window ) - { - bool activate = (ev->modifiers & activeFlag ) ; - WindowClass wclass ; - ::GetWindowClass ( window , &wclass ) ; - if ( wclass == kFloatingWindowClass ) - { - // if it is a floater we activate/deactivate the front non-floating window instead - window = ::FrontNonFloatingWindow() ; - } - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; - if ( win ) - win->MacActivate( ev->when , activate ) ; - } -} - -void wxApp::MacHandleUpdateEvent( WXEVENTREF evr ) -{ - EventRecord* ev = (EventRecord*) evr ; - WindowRef window = (WindowRef) ev->message ; - wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ; - if ( win ) - { - if ( !wxPendingDelete.Member(win) ) - win->MacUpdate( ev->when ) ; - } - else - { - // since there is no way of telling this foreign window to update itself - // we have to invalidate the update region otherwise we keep getting the same - // event over and over again - BeginUpdate( window ) ; - EndUpdate( window ) ; - } -} - -void wxApp::MacHandleDiskEvent( WXEVENTREF evr ) -{ - EventRecord* ev = (EventRecord*) evr ; - if ( HiWord( ev->message ) != noErr ) - { - OSErr err ; - Point point ; - SetPt( &point , 100 , 100 ) ; - - err = DIBadMount( point , ev->message ) ; - wxASSERT( err == noErr ) ; - } -} - -void wxApp::MacHandleOSEvent( WXEVENTREF evr ) -{ - EventRecord* ev = (EventRecord*) evr ; - switch( ( ev->message & osEvtMessageMask ) >> 24 ) - { - case suspendResumeMessage : - { - bool isResuming = ev->message & resumeFlag ; - bool convertClipboard = ev->message & convertClipboardFlag ; - - bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ; - if ( isResuming ) - { - WindowRef oldFrontWindow = NULL ; - WindowRef newFrontWindow = NULL ; - - // in case we don't take care of activating ourselves, we have to synchronize - // our idea of the active window with the process manager's - which it already activated - - if ( !doesActivate ) - oldFrontWindow = ::FrontNonFloatingWindow() ; - - MacResume( convertClipboard ) ; - - newFrontWindow = ::FrontNonFloatingWindow() ; - - if ( oldFrontWindow ) - { - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ; - if ( win ) - win->MacActivate( ev->when , false ) ; - } - if ( newFrontWindow ) - { - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ; - if ( win ) - win->MacActivate( ev->when , true ) ; - } - } - else - { - MacSuspend( convertClipboard ) ; - } - } - break ; - case mouseMovedMessage : - { - WindowRef window; - - wxWindow* currentMouseWindow = NULL ; - - if (s_captureWindow ) - { - currentMouseWindow = s_captureWindow ; - } - else - { - wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , - ¤tMouseWindow ) ; - } - - if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) - { - wxMouseEvent event ; - - bool isDown = !(ev->modifiers & btnState) ; // 1 is for up - bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse - - event.m_leftDown = isDown && !controlDown; - event.m_middleDown = FALSE; - event.m_rightDown = isDown && controlDown; - event.m_shiftDown = ev->modifiers & shiftKey; - event.m_controlDown = ev->modifiers & controlKey; - event.m_altDown = ev->modifiers & optionKey; - event.m_metaDown = ev->modifiers & cmdKey; - event.m_x = ev->where.h; - event.m_y = ev->where.v; - event.m_timeStamp = ev->when; - event.SetEventObject(this); - - if ( wxWindow::s_lastMouseWindow ) - { - wxMouseEvent eventleave(event); - eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); - wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); - eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ; - - wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); - } - if ( currentMouseWindow ) - { - wxMouseEvent evententer(event); - evententer.SetEventType( wxEVT_ENTER_WINDOW ); - currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); - evententer.SetEventObject( currentMouseWindow ) ; - currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); - } - wxWindow::s_lastMouseWindow = currentMouseWindow ; - } - - short windowPart = inNoWindow ; - - if ( s_captureWindow ) - { - window = (WindowRef) s_captureWindow->MacGetRootWindow() ; - windowPart = inContent ; - } - else - { - windowPart = ::FindWindow(ev->where, &window); - } - - switch (windowPart) - { - case inContent : - { - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; - if ( win ) - win->MacMouseMoved( ev , windowPart ) ; - else - { - if ( wxIsBusy() ) - { - } - else - UMAShowArrowCursor(); - } - } - break; - default : - { - if ( wxIsBusy() ) - { - } - else - UMAShowArrowCursor(); - } - break ; - } - } - break ; - - } -} -#else - -void wxApp::MacHandleMouseMovedEvent(wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp) -{ - WindowRef window; - - wxWindow* currentMouseWindow = NULL ; - - if (s_captureWindow ) - { - currentMouseWindow = s_captureWindow ; - } - else - { - wxWindow::MacGetWindowFromPoint( wxPoint( x, y ) , ¤tMouseWindow ) ; - } - - if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) - { - wxMouseEvent event ; - - bool isDown = !(modifiers & btnState) ; // 1 is for up - bool controlDown = modifiers & controlKey ; // for simulating right mouse - - event.m_leftDown = isDown && !controlDown; - - event.m_middleDown = FALSE; - event.m_rightDown = isDown && controlDown; - - event.m_shiftDown = modifiers & shiftKey; - event.m_controlDown = modifiers & controlKey; - event.m_altDown = modifiers & optionKey; - event.m_metaDown = modifiers & cmdKey; - - event.m_x = x; - event.m_y = y; - event.m_timeStamp = timestamp; - - if ( wxWindow::s_lastMouseWindow ) - { - wxMouseEvent eventleave(event); - eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); - wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); - eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ; - -#if wxUSE_TOOLTIPS - wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow , eventleave); -#endif // wxUSE_TOOLTIPS - wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); - } - if ( currentMouseWindow ) - { - wxMouseEvent evententer(event); - evententer.SetEventType( wxEVT_ENTER_WINDOW ); - currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); - evententer.SetEventObject( currentMouseWindow ) ; -#if wxUSE_TOOLTIPS - wxToolTip::RelayEvent( currentMouseWindow , evententer); -#endif // wxUSE_TOOLTIPS - currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); - } - wxWindow::s_lastMouseWindow = currentMouseWindow ; - } - - short windowPart = inNoWindow ; - - if ( s_captureWindow ) - { - window = (WindowRef) s_captureWindow->MacGetRootWindow() ; - windowPart = inContent ; - } - else - { - Point pt= { y , x } ; - windowPart = ::FindWindow(pt , &window); - } - - switch (windowPart) - { - case inContent : - { - wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; - if ( win ) - win->MacFireMouseEvent( nullEvent , x , y , modifiers , timestamp ) ; - else - { - if ( wxIsBusy() ) - { - } - else - UMAShowArrowCursor(); - } - } - break; - default : - { - if ( wxIsBusy() ) - { - } - else - UMAShowArrowCursor(); - } - break ; - } -} -#endif - -void wxApp::MacHandleMenuCommand( wxUint32 id ) -{ - wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ; - wxFrame* frame = mbar->GetFrame(); - wxCHECK_RET( mbar != NULL && frame != NULL, wxT("error in menu item callback") ); - if ( frame ) - { - frame->ProcessCommand(id); - } -} - -#if !TARGET_CARBON -void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum ) -{ - if (macMenuId == 0) - return; // no menu item selected - - if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1) - { - #if ! TARGET_CARBON - Str255 deskAccessoryName ; - GrafPtr savedPort ; - - GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName); - GetPort(&savedPort); - OpenDeskAcc(deskAccessoryName); - SetPort(savedPort); - #endif - } - else - { - MenuCommand id ; - GetMenuItemCommandID( GetMenuHandle(macMenuId) , macMenuItemNum , &id ) ; - MacHandleMenuCommand( id ) ; - } - HiliteMenu(0); -} -#endif diff --git a/src/mac/carbon/bmpbuttn.cpp b/src/mac/carbon/bmpbuttn.cpp index f6ce4dd00c..bfb91977f1 100644 --- a/src/mac/carbon/bmpbuttn.cpp +++ b/src/mac/carbon/bmpbuttn.cpp @@ -29,6 +29,8 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit const wxValidator& validator, const wxString& name) { + m_macIsUserPane = FALSE ; + // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create // essentially creates an additional button if ( !wxControl::Create(parent, id, pos, size, @@ -60,30 +62,28 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit height = newSize.y; } - Rect bounds ; - Str255 title ; m_bmpNormal = bitmap; + wxBitmapRefData * bmap = NULL ; if ( m_bmpNormal.Ok() ) bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ; - MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ; - - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , kControlBehaviorOffsetContents + ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ? kControlContentCIconHandle : kControlContentPictHandle ) , 0, (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ; - wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; + wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info , m_bmpNormal ) ; if ( info.contentType != kControlNoContent ) { - ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; + ::SetControlData( (ControlRef) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; } - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; return TRUE; } @@ -96,7 +96,7 @@ void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) wxMacCreateBitmapButton( &info , m_bmpNormal ) ; if ( info.contentType != kControlNoContent ) { - ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; + ::SetControlData( (ControlRef) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; } } diff --git a/src/mac/carbon/brush.cpp b/src/mac/carbon/brush.cpp index d484314a2c..f94401052f 100644 --- a/src/mac/carbon/brush.cpp +++ b/src/mac/carbon/brush.cpp @@ -164,7 +164,7 @@ void wxBrush::SetStipple(const wxBitmap& Stipple) RealizeResource(); } -void wxBrush::SetMacTheme(ThemeBrush macThemeBrush) +void wxBrush::MacSetTheme(ThemeBrush macThemeBrush) { Unshare(); @@ -174,7 +174,7 @@ void wxBrush::SetMacTheme(ThemeBrush macThemeBrush) RealizeResource(); } -void wxBrush::SetMacThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent) +void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent) { Unshare(); @@ -189,7 +189,7 @@ bool wxBrush::RealizeResource() return TRUE; } -unsigned long wxBrush::GetMacThemeBackground( WXRECTPTR extent) const +unsigned long wxBrush::MacGetThemeBackground( WXRECTPTR extent) const { if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground ) { @@ -203,7 +203,7 @@ unsigned long wxBrush::GetMacThemeBackground( WXRECTPTR extent) const } } -short wxBrush::GetMacTheme() const +short wxBrush::MacGetTheme() const { return (M_BRUSHDATA ? ( M_BRUSHDATA->m_macBrushKind == kwxMacBrushTheme ? M_BRUSHDATA->m_macThemeBrush : kThemeBrushBlack) : kThemeBrushBlack); } diff --git a/src/mac/carbon/button.cpp b/src/mac/carbon/button.cpp index 82e4e34c5f..d11c858561 100644 --- a/src/mac/carbon/button.cpp +++ b/src/mac/carbon/button.cpp @@ -25,34 +25,25 @@ IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) #include "wx/mac/uma.h" // Button -static const int kMacOSXHorizontalBorder = 2 ; -static const int kMacOSXVerticalBorder = 4 ; - bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) ) return false; - - Rect bounds ; - Str255 title ; - - if ( UMAHasAquaLayout() ) - { - m_macHorizontalBorder = kMacOSXHorizontalBorder; - m_macVerticalBorder = kMacOSXVerticalBorder; - } - MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; + m_label = label ; - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, kControlPushButtonProc , (long) this ) ; - wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; + wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; return TRUE; } @@ -72,13 +63,13 @@ void wxButton::SetDefault() if ( btnOldDefault && btnOldDefault->m_macControl ) { inData = 0; - ::SetControlData( (ControlHandle) btnOldDefault->m_macControl , kControlButtonPart , + ::SetControlData( (ControlRef) btnOldDefault->m_macControl , kControlButtonPart , kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ; } - if ( (ControlHandle) m_macControl ) + if ( (ControlRef) m_macControl ) { inData = 1; - ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , + ::SetControlData( (ControlRef) m_macControl , kControlButtonPart , kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ; } } @@ -87,8 +78,25 @@ wxSize wxButton::DoGetBestSize() const { wxSize sz = GetDefaultSize() ; - int wBtn = m_label.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder ; - + int charspace = 8 ; + if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE ) + { + sz.y = 20 ; + charspace = 10 ; + } + else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL ) + { + sz.y = 17 ; + charspace = 8 ; + } + else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI ) + { + sz.y = 15 ; + charspace = 8 ; + } + + int wBtn = m_label.Length() * charspace + 12 ; + if (wBtn > sz.x) sz.x = wBtn; return sz ; @@ -98,24 +106,18 @@ wxSize wxButton::GetDefaultSize() { int wBtn = 70 ; int hBtn = 20 ; - - if ( UMAHasAquaLayout() ) - { - wBtn += 2 * kMacOSXHorizontalBorder ; - hBtn += 2 * kMacOSXVerticalBorder ; - } - + return wxSize(wBtn, hBtn); } void wxButton::Command (wxCommandEvent & event) { - if ( (ControlHandle) m_macControl ) + if ( (ControlRef) m_macControl ) { - HiliteControl( (ControlHandle) m_macControl , kControlButtonPart ) ; + HiliteControl( (ControlRef) m_macControl , kControlButtonPart ) ; unsigned long finalTicks ; Delay( 8 , &finalTicks ) ; - HiliteControl( (ControlHandle) m_macControl , 0 ) ; + HiliteControl( (ControlRef) m_macControl , 0 ) ; } ProcessCommand (event); } diff --git a/src/mac/carbon/checkbox.cpp b/src/mac/carbon/checkbox.cpp index 6e6aa299b2..72993d6081 100644 --- a/src/mac/carbon/checkbox.cpp +++ b/src/mac/carbon/checkbox.cpp @@ -31,13 +31,12 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, const wxValidator& validator, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxCheckBoxBase::Create(parent, id, pos, size, style, validator, name) ) return false; - Rect bounds ; - Str255 title ; - - MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; + m_label = label ; SInt16 maxValue = 1 /* kControlCheckboxCheckedValue */; if (style & wxCHK_3STATE) @@ -45,10 +44,12 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, maxValue = 2 /* kControlCheckboxMixedValue */; } - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , maxValue, + + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , maxValue, kControlCheckBoxProc , (long) this ) ; - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; return TRUE; } @@ -85,12 +86,12 @@ void wxCheckBox::Command (wxCommandEvent & event) wxCheckBoxState wxCheckBox::DoGet3StateValue() const { - return (wxCheckBoxState) ::GetControl32BitValue( (ControlHandle) m_macControl ); + return (wxCheckBoxState) ::GetControl32BitValue( (ControlRef) m_macControl ); } void wxCheckBox::DoSet3StateValue(wxCheckBoxState val) { - ::SetControl32BitValue( (ControlHandle) m_macControl , (int) val) ; + ::SetControl32BitValue( (ControlRef) m_macControl , (int) val) ; MacRedrawControl() ; } diff --git a/src/mac/carbon/checklst.cpp b/src/mac/carbon/checklst.cpp index c442bbdfcb..855049cb04 100644 --- a/src/mac/carbon/checklst.cpp +++ b/src/mac/carbon/checklst.cpp @@ -70,7 +70,7 @@ static pascal void wxMacCheckListDefinition( short message, Boolean isSelected, ListHandle listHandle ) { wxCheckListBox* list; - list = (wxCheckListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) ); + list = (wxCheckListBox*) GetControlReference( (ControlRef) GetListRefCon(listHandle) ); if ( list == NULL ) return ; @@ -109,9 +109,9 @@ static pascal void wxMacCheckListDefinition( short message, Boolean isSelected, const wxFont& font = list->GetFont(); if ( font.Ok() ) { - ::TextFont( font.GetMacFontNum() ) ; - ::TextSize( font.GetMacFontSize()) ; - ::TextFace( font.GetMacFontStyle() ) ; + ::TextFont( font.MacGetFontNum() ) ; + ::TextSize( font.MacGetFontSize()) ; + ::TextFace( font.MacGetFontStyle() ) ; } ThemeButtonDrawInfo info ; @@ -201,6 +201,8 @@ bool wxCheckListBox::Create(wxWindow *parent, const wxValidator& validator, const wxString &name) { + m_macIsUserPane = FALSE ; + if ( !wxCheckListBoxBase::Create(parent, id, pos, size, n, choices, style, validator, name) ) return false; @@ -220,7 +222,7 @@ bool wxCheckListBox::Create(wxWindow *parent, const wxFont& font = GetFont(); FontInfo finfo; - FetchFontInfo(font.GetMacFontNum(),font.GetMacFontSize(),font.GetMacFontStyle(),&finfo); + FetchFontInfo(font.MacGetFontNum(),font.MacGetFontSize(),font.MacGetFontStyle(),&finfo); m_TextBaseLineOffset= finfo.leading+finfo.ascent; m_checkBoxHeight= finfo.leading+finfo.ascent+finfo.descent; @@ -231,10 +233,8 @@ bool wxCheckListBox::Create(wxWindow *parent, m_checkBoxHeight= h; } - Rect bounds ; - Str255 title ; - - MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ; + + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; ListDefSpec listDef; listDef.defType = kListDefUserProcType; @@ -248,24 +248,24 @@ bool wxCheckListBox::Create(wxWindow *parent, Size asize; - CreateListBoxControl( MAC_WXHWND(parent->MacGetRootWindow()), &bounds, false, 0, 1, false, true, + CreateListBoxControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, false, 0, 1, false, true, m_checkBoxHeight+2, 14, false, &listDef, (ControlRef *)&m_macControl ); - GetControlData( (ControlHandle) m_macControl, kControlNoPart, kControlListBoxListHandleTag, + GetControlData( (ControlRef) m_macControl, kControlNoPart, kControlListBoxListHandleTag, sizeof(ListHandle), (Ptr) &m_macList, &asize); - SetControlReference( (ControlHandle) m_macControl, (long) this); - SetControlVisibility( (ControlHandle) m_macControl, false, false); + SetControlReference( (ControlRef) m_macControl, (long) this); + SetControlVisibility( (ControlRef) m_macControl, false, false); #else long result ; wxStAppResource resload ; - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , kwxMacListWithVerticalScrollbar , 0 , 0, kControlListBoxProc , (long) this ) ; - ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag , + ::GetControlData( (ControlRef) m_macControl , kControlNoPart , kControlListBoxListHandleTag , sizeof( ListHandle ) , (char*) &m_macList , &result ) ; HLock( (Handle) m_macList ) ; @@ -298,7 +298,7 @@ bool wxCheckListBox::Create(wxWindow *parent, } SetListSelectionFlags((ListHandle)m_macList, options); - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; for ( int i = 0 ; i < n ; i++ ) { diff --git a/src/mac/carbon/choice.cpp b/src/mac/carbon/choice.cpp index 9f8494db9a..1a617ef6a5 100644 --- a/src/mac/carbon/choice.cpp +++ b/src/mac/carbon/choice.cpp @@ -60,23 +60,22 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxChoiceBase::Create(parent, id, pos, size, style, validator, name) ) return false; - Rect bounds ; - Str255 title ; - - MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ; - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , -12345 , 0 , + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , -12345 , 0 , kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ; m_macPopUpMenuHandle = NewUniqueMenu() ; - SetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; - SetControl32BitMinimum( (ControlHandle) m_macControl , 0 ) ; - SetControl32BitMaximum( (ControlHandle) m_macControl , 0) ; + SetControlData( (ControlRef) m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; + SetControl32BitMinimum( (ControlRef) m_macControl , 0 ) ; + SetControl32BitMaximum( (ControlRef) m_macControl , 0) ; if ( n > 0 ) - SetControl32BitValue( (ControlHandle) m_macControl , 1 ) ; - MacPostControlCreate() ; + SetControl32BitValue( (ControlRef) m_macControl , 1 ) ; + MacPostControlCreate(pos,size) ; // TODO wxCB_SORT for ( int i = 0; i < n; i++ ) { @@ -95,7 +94,7 @@ int wxChoice::DoAppend(const wxString& item) m_datas.Add( NULL ) ; int index = m_strings.GetCount() - 1 ; DoSetItemClientData( index , NULL ) ; - SetControl32BitMaximum( (ControlHandle) m_macControl , GetCount()) ; + SetControl32BitMaximum( (ControlRef) m_macControl , GetCount()) ; return index ; } @@ -111,7 +110,7 @@ int wxChoice::DoInsert(const wxString& item, int pos) m_strings.Insert( item, pos ) ; m_datas.Insert( NULL, pos ) ; DoSetItemClientData( pos , NULL ) ; - SetControl32BitMaximum( (ControlHandle) m_macControl , pos) ; + SetControl32BitMaximum( (ControlRef) m_macControl , pos) ; return pos ; } @@ -125,7 +124,7 @@ void wxChoice::Delete(int n) ::DeleteMenuItem( MAC_WXHMENU(m_macPopUpMenuHandle) , n + 1) ; m_strings.RemoveAt( n ) ; m_datas.RemoveAt( n ) ; - SetControl32BitMaximum( (ControlHandle) m_macControl , GetCount()) ; + SetControl32BitMaximum( (ControlRef) m_macControl , GetCount()) ; } void wxChoice::Clear() @@ -137,7 +136,7 @@ void wxChoice::Clear() } m_strings.Empty() ; m_datas.Empty() ; - SetControl32BitMaximum( (ControlHandle) m_macControl , 0 ) ; + SetControl32BitMaximum( (ControlRef) m_macControl , 0 ) ; } void wxChoice::FreeData() @@ -157,12 +156,12 @@ void wxChoice::FreeData() // ---------------------------------------------------------------------------- int wxChoice::GetSelection() const { - return GetControl32BitValue( (ControlHandle) m_macControl ) -1 ; + return GetControl32BitValue( (ControlRef) m_macControl ) -1 ; } void wxChoice::SetSelection(int n) { - SetControl32BitValue( (ControlHandle) m_macControl , n + 1 ) ; + SetControl32BitValue( (ControlRef) m_macControl , n + 1 ) ; } // ---------------------------------------------------------------------------- @@ -258,12 +257,12 @@ wxSize wxChoice::DoGetBestSize() const lbHeight = metric ; #endif { - wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ; + wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetTopLevelWindowRef() ) ) ; if ( m_font.Ok() ) { - ::TextFont( m_font.GetMacFontNum() ) ; - ::TextSize( m_font.GetMacFontSize() ) ; - ::TextFace( m_font.GetMacFontStyle() ) ; + ::TextFont( m_font.MacGetFontNum() ) ; + ::TextSize( m_font.MacGetFontSize() ) ; + ::TextFace( m_font.MacGetFontStyle() ) ; } else { diff --git a/src/mac/carbon/clipbrd.cpp b/src/mac/carbon/clipbrd.cpp index e331d80f8e..7e48c9ec34 100644 --- a/src/mac/carbon/clipbrd.cpp +++ b/src/mac/carbon/clipbrd.cpp @@ -236,11 +236,6 @@ bool wxClipboard::AddData( wxDataObject *data ) wxT("wxClipboard now supports atom %s"), array[i].GetId().c_str() ); -#if !TARGET_CARBON - OSErr err = noErr ; -#else - OSStatus err = noErr ; -#endif size_t sz = data->GetDataSize( array[i] ) ; void* buf = malloc( sz + 1 ) ; if ( buf ) diff --git a/src/mac/carbon/combobox.cpp b/src/mac/carbon/combobox.cpp index 27aa1a58de..795874147e 100644 --- a/src/mac/carbon/combobox.cpp +++ b/src/mac/carbon/combobox.cpp @@ -204,7 +204,9 @@ void wxComboBox::DoMoveWindow(int x, int y, int width, int height) { if ( m_text == NULL ) { - m_choice->SetSize(0, 0 , width, -1); + // we might not be fully constructed yet, therefore watch out... + if ( m_choice ) + m_choice->SetSize(0, 0 , width, -1); } else { diff --git a/src/mac/carbon/control.cpp b/src/mac/carbon/control.cpp index 473bdec9fd..ba7d6a7a3c 100644 --- a/src/mac/carbon/control.cpp +++ b/src/mac/carbon/control.cpp @@ -33,11 +33,6 @@ #if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) - -BEGIN_EVENT_TABLE(wxControl, wxWindow) - EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) - EVT_PAINT( wxControl::OnPaint ) -END_EVENT_TABLE() #endif #include "wx/mac/uma.h" @@ -45,117 +40,8 @@ END_EVENT_TABLE() // Item members - -#if PRAGMA_STRUCT_ALIGN - #pragma options align=mac68k -#elif PRAGMA_STRUCT_PACKPUSH - #pragma pack(push, 2) -#elif PRAGMA_STRUCT_PACK - #pragma pack(2) -#endif - -typedef struct { - unsigned short instruction; - void (*function)(); -} cdefRec, *cdefPtr, **cdefHandle; - -#if PRAGMA_STRUCT_ALIGN - #pragma options align=reset -#elif PRAGMA_STRUCT_PACKPUSH - #pragma pack(pop) -#elif PRAGMA_STRUCT_PACK - #pragma pack() -#endif - -ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; -wxControl *wxFindControlFromMacControl(ControlHandle inControl ) ; - -pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ; -pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) -{ - if ( partCode != 0) - { - wxControl* wx = (wxControl*) GetControlReference( control ) ; - if ( wx ) - { - wx->MacHandleControlClick( control , partCode , true /* stillDown */ ) ; - } - } -} - -ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ; -ControlDefUPP wxMacControlActionUPP = NULL ; - -pascal SInt32 wxMacControlDefinition(SInt16 varCode, ControlRef theControl, ControlDefProcMessage message, SInt32 param) -{ - - wxControl* wx = (wxControl*) wxFindControlFromMacControl( theControl ) ; - if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) ) - { - if( message == drawCntl ) - { - wxMacWindowClipper clip( wx ) ; - return InvokeControlDefUPP( varCode , theControl , message , param , (ControlDefUPP) wx->MacGetControlAction() ) ; - } - else - return InvokeControlDefUPP( varCode , theControl , message , param , (ControlDefUPP) wx->MacGetControlAction() ) ; - } - return NULL ; -} - -pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) -{ - OSStatus status = noErr ; - switch( iMessage ) - { - case kControlMsgSetUpBackground : - { - wxControl* wx = (wxControl*) GetControlReference( iControl ) ; - if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) ) - { - wxDC::MacSetupBackgroundForCurrentPort( wx->MacGetBackgroundBrush() ) ; -#if TARGET_CARBON - // under classic this would lead to partial redraws - RgnHandle clip = NewRgn() ; - int x = 0 , y = 0; - - wx->MacWindowToRootWindow( &x,&y ) ; - CopyRgn( (RgnHandle) wx->MacGetVisibleRegion(false).GetWXHRGN() , clip ) ; - OffsetRgn( clip , x , y ) ; - SetClip( clip ) ; - DisposeRgn( clip ) ; -#endif - } - else - { - status = paramErr ; - } - } - break ; - default : - status = paramErr ; - break ; - } - return status ; -} - wxControl::wxControl() { - m_macControl = NULL ; - m_macControlAction = NULL ; - m_macHorizontalBorder = 0 ; // additional pixels around the real control - m_macVerticalBorder = 0 ; - m_backgroundColour = *wxWHITE; - m_foregroundColour = *wxBLACK; - - if ( wxMacLiveScrollbarActionUPP == NULL ) - { -#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) - wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc ); -#else - wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ; -#endif - } } bool wxControl::Create(wxWindow *parent, wxWindowID id, @@ -164,17 +50,19 @@ bool wxControl::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - m_macControl = NULL ; - m_macHorizontalBorder = 0 ; // additional pixels around the real control - m_macVerticalBorder = 0 ; - bool rval = wxWindow::Create(parent, id, pos, size, style, name); + +#if 0 + // no automatic inheritance as we most often need transparent backgrounds if ( parent ) { m_backgroundColour = parent->GetBackgroundColour() ; m_foregroundColour = parent->GetForegroundColour() ; } - if (rval) { +#endif + + if (rval) + { #if wxUSE_VALIDATORS SetValidator(validator); #endif @@ -185,73 +73,6 @@ bool wxControl::Create(wxWindow *parent, wxWindowID id, wxControl::~wxControl() { m_isBeingDeleted = TRUE; - wxRemoveMacControlAssociation( this ) ; - // If we delete an item, we should initialize the parent panel, - // because it could now be invalid. - wxWindow *parent = GetParent() ; - if ( parent ) - { - if (parent->GetDefaultItem() == (wxButton*) this) - parent->SetDefaultItem(NULL); - } - if ( (ControlHandle) m_macControl ) - { - // in case the callback might be called during destruction - ::SetControlColorProc( (ControlHandle) m_macControl , NULL ) ; - ::DisposeControl( (ControlHandle) m_macControl ) ; - m_macControl = NULL ; - } -} - -void wxControl::SetLabel(const wxString& title) -{ - m_label = wxStripMenuCodes(title) ; - - if ( m_macControl ) - { - UMASetControlTitle( (ControlHandle) m_macControl , m_label , m_font.GetEncoding() ) ; - } - Refresh() ; -} - -wxSize wxControl::DoGetBestSize() const -{ - if ( (ControlHandle) m_macControl == NULL ) - return wxWindow::DoGetBestSize() ; - - Rect bestsize = { 0 , 0 , 0 , 0 } ; - short baselineoffset ; - int bestWidth, bestHeight ; - ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ; - - if ( EmptyRect( &bestsize ) ) - { - baselineoffset = 0; - bestsize.left = bestsize.top = 0 ; - bestsize.right = 16 ; - bestsize.bottom = 16 ; - if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) - { - bestsize.bottom = 16 ; - } - else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) - { - bestsize.bottom = 24 ; - } - } - - bestWidth = bestsize.right - bestsize.left ; - - bestWidth += 2 * m_macHorizontalBorder ; - - bestHeight = bestsize.bottom - bestsize.top ; - if ( bestHeight < 10 ) - bestHeight = 13 ; - - bestHeight += 2 * m_macVerticalBorder; - - - return wxSize(bestWidth, bestHeight); } bool wxControl::ProcessCommand (wxCommandEvent & event) @@ -262,398 +83,9 @@ bool wxControl::ProcessCommand (wxCommandEvent & event) return GetEventHandler()->ProcessEvent(event); } -// ------------------------ -wxList *wxWinMacControlList = NULL; -wxControl *wxFindControlFromMacControl(ControlHandle inControl ) -{ - wxNode *node = wxWinMacControlList->Find((long)inControl); - if (!node) - return NULL; - return (wxControl *)node->GetData(); -} - -void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control) -{ - // adding NULL WindowRef is (first) surely a result of an error and - // (secondly) breaks menu command processing - wxCHECK_RET( inControl != (ControlHandle) NULL, wxT("attempt to add a NULL WindowRef to window list") ); - - if ( !wxWinMacControlList->Find((long)inControl) ) - wxWinMacControlList->Append((long)inControl, control); -} - -void wxRemoveMacControlAssociation(wxControl *control) -{ - if ( wxWinMacControlList ) - wxWinMacControlList->DeleteObject(control); -} - -void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label , - const wxPoint& pos, - const wxSize& size, long style, - const wxValidator& validator, - const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel ) -{ - m_label = label ; - - // These sizes will be adjusted in MacPostControlCreate - m_width = size.x ; - m_height = size.y ; - m_x = pos.x ; - m_y = pos.y ; - - ((Rect*)outBounds)->top = -10; - ((Rect*)outBounds)->left = -10; - ((Rect*)outBounds)->bottom = 0; - ((Rect*)outBounds)->right = 0; - - wxMacStringToPascal( wxStripMenuCodes(label) , maclabel ) ; -} - -void wxControl::MacPostControlCreate() -{ - wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; - DoSetWindowVariant( m_windowVariant ) ; - /* - if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) - { - // no font - } - else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) ) - { - ControlFontStyleRec controlstyle ; - controlstyle.flags = kControlUseFontMask ; - controlstyle.font = kControlFontSmallBoldSystemFont ; - - ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; - } - else - { - ControlFontStyleRec controlstyle ; - controlstyle.flags = kControlUseFontMask ; - - if (IsKindOf( CLASSINFO( wxButton ) ) ) - controlstyle.font = kControlFontBigSystemFont ; // eventually kControlFontBigSystemFont ; - else - controlstyle.font = kControlFontSmallSystemFont ; - - ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ; - } - */ - ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ; - wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; - ::EmbedControl( (ControlHandle) m_macControl , container ) ; - m_macControlIsShown = MacIsReallyShown() ; - - wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ; - if ( wxMacSetupControlBackgroundUPP == NULL ) - { - wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ; - } - if ( wxMacControlActionUPP == NULL ) - { - wxMacControlActionUPP = NewControlDefUPP( wxMacControlDefinition ) ; - } - // The following block of code is responsible for crashes when switching - // back to windows, which can be seen in the dialogs sample. - // It is disabled until a proper solution can be found. -#if 0 -#if TARGET_CARBON -/* - only working under classic carbon - m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ; - (**(ControlHandle)m_macControl).contrlDefProc = (Handle) &wxMacControlActionUPP ; -*/ -#else - m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ; - - cdefHandle cdef ; - cdef = (cdefHandle) NewHandle( sizeof(cdefRec) ) ; - if ( (**(ControlHandle)m_macControl).contrlDefProc != NULL ) - { - (**cdef).instruction = 0x4EF9; /* JMP instruction */ - (**cdef).function = (void(*)()) wxMacControlActionUPP; - (**(ControlHandle)m_macControl).contrlDefProc = (Handle) cdef ; - } -#endif -#endif - SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ; - - // Adjust the controls size and position - wxPoint pos(m_x, m_y); - wxSize best_size( DoGetBestSize() ); - wxSize new_size( m_width, m_height ); - - m_x = m_y = m_width = m_height = -1; // Forces SetSize to move/size the control - - if (new_size.x == -1) { - new_size.x = best_size.x; - } - if (new_size.y == -1) { - new_size.y = best_size.y; - } - - SetSize(pos.x, pos.y, new_size.x, new_size.y); - -#if wxUSE_UNICODE - UMASetControlTitle( (ControlHandle) m_macControl , wxStripMenuCodes(m_label) , m_font.GetEncoding() ) ; -#endif - - if ( m_macControlIsShown ) - UMAShowControl( (ControlHandle) m_macControl ) ; - - SetCursor( *wxSTANDARD_CURSOR ) ; - - Refresh() ; -} - -void wxControl::MacAdjustControlRect() -{ - wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; - if ( m_width == -1 || m_height == -1 ) - { - Rect bestsize = { 0 , 0 , 0 , 0 } ; - short baselineoffset ; - - ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ; - - if ( EmptyRect( &bestsize ) ) - { - baselineoffset = 0; - bestsize.left = bestsize.top = 0 ; - bestsize.right = 16 ; - bestsize.bottom = 16 ; - if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) - { - bestsize.bottom = 16 ; - } - else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) - { - bestsize.bottom = 24 ; - } - } - - if ( m_width == -1 ) - { - if ( IsKindOf( CLASSINFO( wxButton ) ) ) - { - m_width = m_label.Length() * 8 + 12 ; - if ( m_width < 70 ) - m_width = 70 ; - } - else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) - { - m_width = m_label.Length() * 8 ; - } - else - m_width = bestsize.right - bestsize.left ; - - m_width += 2 * m_macHorizontalBorder + MacGetLeftBorderSize() + MacGetRightBorderSize() ; - } - if ( m_height == -1 ) - { - m_height = bestsize.bottom - bestsize.top ; - if ( m_height < 10 ) - m_height = 13 ; - - m_height += 2 * m_macVerticalBorder + MacGetTopBorderSize() + MacGetBottomBorderSize() ; - } - MacUpdateDimensions() ; - } -} - -WXWidget wxControl::MacGetContainerForEmbedding() -{ - if ( m_macControl ) - return m_macControl ; - - return wxWindow::MacGetContainerForEmbedding() ; -} - -void wxControl::MacUpdateDimensions() -{ - // actually in the current systems this should never be possible, but later reparenting - // may become a reality - - if ( (ControlHandle) m_macControl == NULL ) - return ; - - if ( GetParent() == NULL ) - return ; - - WindowRef rootwindow = (WindowRef) MacGetRootWindow() ; - if ( rootwindow == NULL ) - return ; - - Rect oldBounds ; - GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ; - - int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ; - int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ; - int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder ; - int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder ; - - GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ; - bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ; - bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ; - if ( doMove || doResize ) - { - InvalWindowRect( rootwindow, &oldBounds ) ; - if ( doMove ) - { - UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ; - } - if ( doResize ) - { - UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ; - } - } -} - -void wxControl::MacSuperChangedPosition() -{ - MacUpdateDimensions() ; - wxWindow::MacSuperChangedPosition() ; -} - -void wxControl::MacSuperEnabled( bool enabled ) -{ - Refresh(FALSE) ; - wxWindow::MacSuperEnabled( enabled ) ; -} - -void wxControl::MacSuperShown( bool show ) -{ - if ( (ControlHandle) m_macControl ) - { - if ( !show ) - { - if ( m_macControlIsShown ) - { - ::UMAHideControl( (ControlHandle) m_macControl ) ; - m_macControlIsShown = false ; - } - } - else - { - if ( MacIsReallyShown() && !m_macControlIsShown ) - { - ::UMAShowControl( (ControlHandle) m_macControl ) ; - m_macControlIsShown = true ; - } - } - } - - wxWindow::MacSuperShown( show ) ; -} - -void wxControl::DoSetSize(int x, int y, - int width, int height, - int sizeFlags ) -{ - wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ; -#if 0 - { - Rect meta , control ; - GetControlBounds( (ControlHandle) m_macControl , &control ) ; - RgnHandle rgn = NewRgn() ; - GetControlRegion( (ControlHandle) m_macControl , kControlStructureMetaPart , rgn ) ; - GetRegionBounds( rgn , &meta ) ; - if ( !EmptyRect( &meta ) ) - { - wxASSERT( meta.left >= control.left - m_macHorizontalBorder ) ; - wxASSERT( meta.right <= control.right + m_macHorizontalBorder ) ; - wxASSERT( meta.top >= control.top - m_macVerticalBorder ) ; - wxASSERT( meta.bottom <= control.bottom + m_macVerticalBorder ) ; - } - DisposeRgn( rgn ) ; - } -#endif - return ; -} - -bool wxControl::Show(bool show) -{ - if ( !wxWindow::Show( show ) ) - return FALSE ; - - if ( (ControlHandle) m_macControl ) - { - if ( !show ) - { - if ( m_macControlIsShown ) - { - ::UMAHideControl( (ControlHandle) m_macControl ) ; - m_macControlIsShown = false ; - } - } - else - { - if ( MacIsReallyShown() && !m_macControlIsShown ) - { - ::UMAShowControl( (ControlHandle) m_macControl ) ; - m_macControlIsShown = true ; - } - } - } - return TRUE ; -} - -bool wxControl::Enable(bool enable) -{ - if ( !wxWindow::Enable(enable) ) - return FALSE; - - if ( (ControlHandle) m_macControl ) - { - if ( enable ) - UMAActivateControl( (ControlHandle) m_macControl ) ; - else - UMADeactivateControl( (ControlHandle) m_macControl ) ; - } - return TRUE ; -} - -void wxControl::Refresh(bool eraseBack, const wxRect *rect) -{ - wxWindow::Refresh( eraseBack , rect ) ; -} - -void wxControl::MacRedrawControl() -{ - if ( (ControlHandle) m_macControl && MacGetRootWindow() && m_macControlIsShown ) - { - wxClientDC dc(this) ; - wxMacPortSetter helper(&dc) ; - wxMacWindowClipper clipper(this) ; - wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; - UMADrawControl( (ControlHandle) m_macControl ) ; - } -} - -void wxControl::OnPaint(wxPaintEvent& event) -{ - if ( (ControlHandle) m_macControl ) - { - wxPaintDC dc(this) ; - wxMacPortSetter helper(&dc) ; - wxMacWindowClipper clipper(this) ; - wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; - UMADrawControl( (ControlHandle) m_macControl ) ; - } - else - { - event.Skip() ; - } -} -void wxControl::OnEraseBackground(wxEraseEvent& event) -{ - wxWindow::OnEraseBackground( event ) ; -} - void wxControl::OnKeyDown( wxKeyEvent &event ) { - if ( (ControlHandle) m_macControl == NULL ) + if ( (ControlRef) m_macControl == NULL ) return ; #if TARGET_CARBON @@ -666,7 +98,7 @@ void wxControl::OnKeyDown( wxKeyEvent &event ) GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); - ::HandleControlKey( (ControlHandle) m_macControl , keyCode , charCode , modifiers ) ; + ::HandleControlKey( (ControlRef) m_macControl , keyCode , charCode , modifiers ) ; #else EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ; @@ -675,140 +107,7 @@ void wxControl::OnKeyDown( wxKeyEvent &event ) keychar = short(ev->message & charCodeMask); keycode = short(ev->message & keyCodeMask) >> 8 ; - ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ; + ::HandleControlKey( (ControlRef) m_macControl , keycode , keychar , ev->modifiers ) ; #endif } -void wxControl::OnMouseEvent( wxMouseEvent &event ) -{ - if ( (ControlHandle) m_macControl == NULL ) - { - event.Skip() ; - return ; - } - - if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) - { - - int x = event.m_x ; - int y = event.m_y ; - - MacClientToRootWindow( &x , &y ) ; - - ControlHandle control ; - Point localwhere ; - SInt16 controlpart ; - - localwhere.h = x ; - localwhere.v = y ; - - short modifiers = 0; - - if ( !event.m_leftDown && !event.m_rightDown ) - modifiers |= btnState ; - - if ( event.m_shiftDown ) - modifiers |= shiftKey ; - - if ( event.m_controlDown ) - modifiers |= controlKey ; - - if ( event.m_altDown ) - modifiers |= optionKey ; - - if ( event.m_metaDown ) - modifiers |= cmdKey ; - { - control = (ControlHandle) m_macControl ; - if ( control && ::IsControlActive( control ) ) - { - { - controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; - wxTheApp->s_lastMouseDown = 0 ; - if ( control && controlpart != kControlNoPart ) - { - MacHandleControlClick( control , controlpart , false /* mouse not down anymore */ ) ; - } - } - } - } - } - else - { - event.Skip() ; - } -} - -bool wxControl::MacCanFocus() const -{ - if ( (ControlHandle) m_macControl == NULL ) - return true ; - else - return false ; -} - -void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) -{ - wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; -} - -void wxControl::DoSetWindowVariant( wxWindowVariant variant ) -{ - if ( m_macControl == NULL ) - { - wxWindow::SetWindowVariant( variant ) ; - return ; - - } - m_windowVariant = variant ; - - ControlSize size ; - ControlFontStyleRec fontStyle; - fontStyle.flags = kControlUseFontMask ; - - // we will get that from the settings later - // and make this NORMAL later, but first - // we have a few calculations that we must fix - - if ( variant == wxWINDOW_VARIANT_DEFAULT ) - { - if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) - variant = wxWINDOW_VARIANT_NORMAL ; - else - variant = wxWINDOW_VARIANT_SMALL ; - } - - switch ( variant ) - { - case wxWINDOW_VARIANT_NORMAL : - size = kControlSizeNormal; - fontStyle.font = kControlFontBigSystemFont; - break ; - case wxWINDOW_VARIANT_SMALL : - size = kControlSizeSmall; - fontStyle.font = kControlFontSmallSystemFont; - break ; - case wxWINDOW_VARIANT_MINI : - if (UMAGetSystemVersion() >= 0x1030 ) - { - size = 3 ; // not always defined in the header - fontStyle.font = -5 ; // not always defined in the header - } - else - { - size = kControlSizeSmall; - fontStyle.font = kControlFontSmallSystemFont; - } - break; - break ; - case wxWINDOW_VARIANT_LARGE : - size = kControlSizeLarge; - fontStyle.font = kControlFontBigSystemFont; - break ; - default: - wxFAIL_MSG(_T("unexpected window variant")); - break ; - } - ::SetControlData( (ControlHandle) m_macControl , kControlEntireControl, kControlSizeTag, sizeof( ControlSize ), &size ); - ::SetControlFontStyle( (ControlHandle) m_macControl , &fontStyle ); -} diff --git a/src/mac/carbon/dc.cpp b/src/mac/carbon/dc.cpp index d906bac5a4..005e7d54ea 100644 --- a/src/mac/carbon/dc.cpp +++ b/src/mac/carbon/dc.cpp @@ -104,31 +104,8 @@ private : typedef wxMacPortSetter wxMacFastPortSetter ; #endif -#if 0 - -// start moving to a dual implementation for QD and CGContextRef - -class wxMacGraphicsContext -{ -public : - void DrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ) = 0 ; - void SetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) = 0 ; - void SetClippingRegion( const wxRegion ®ion ) = 0 ; - void DestroyClippingRegion() = 0 ; - void SetTextForeground( const wxColour &col ) = 0 ; - void SetTextBackground( const wxColour &col ) = 0 ; - void SetLogicalScale( double x , double y ) = 0 ; - void SetUserScale( double x , double y ) = 0; -} ; - -class wxMacQuickDrawContext : public wxMacGraphicsContext -{ -public : -} ; - -#endif - -wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) +wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) : + wxMacPortSaver( (GrafPtr) GetWindowPort((WindowRef) win->MacGetTopLevelWindowRef()) ) { m_formerClip = NewRgn() ; m_newClip = NewRgn() ; @@ -136,29 +113,14 @@ wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) if ( win ) { -#if 0 - // this clipping area was set to the parent window's drawing area, lead to problems - // with MacOSX controls drawing outside their wx' rectangle - RgnHandle insidergn = NewRgn() ; - int x = 0 , y = 0; - wxWindow *parent = win->GetParent() ; - parent->MacWindowToRootWindow( &x,&y ) ; - wxSize size = parent->GetSize() ; - SetRectRgn( insidergn , parent->MacGetLeftBorderSize() , parent->MacGetTopBorderSize() , - size.x - parent->MacGetRightBorderSize(), - size.y - parent->MacGetBottomBorderSize()) ; - CopyRgn( (RgnHandle) parent->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip ) ; - SectRgn( m_newClip , insidergn , m_newClip ) ; - OffsetRgn( m_newClip , x , y ) ; - SetClip( m_newClip ) ; - DisposeRgn( insidergn ) ; -#else int x = 0 , y = 0; win->MacWindowToRootWindow( &x,&y ) ; - CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion().GetWXHRGN() , m_newClip ) ; - OffsetRgn( m_newClip , x , y ) ; + // get area including focus rect + CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip ) ; + if ( !EmptyRgn( m_newClip ) ) + OffsetRgn( m_newClip , x , y ) ; + SetClip( m_newClip ) ; -#endif } } @@ -617,20 +579,6 @@ void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) ComputeScaleAndOrigin(); } -#if 0 -void wxDC::SetInternalDeviceOrigin( long x, long y ) -{ - m_internalDeviceOriginX = x; - m_internalDeviceOriginY = y; - ComputeScaleAndOrigin(); -} -void wxDC::GetInternalDeviceOrigin( long *x, long *y ) -{ - if (x) *x = m_internalDeviceOriginX; - if (y) *y = m_internalDeviceOriginY; -} -#endif - void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) { m_signX = (xLeftRight ? 1 : -1); @@ -1358,7 +1306,7 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, double angle) { wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") ); - +/* if (angle == 0.0 ) { DrawText(str, x, y); @@ -1367,14 +1315,14 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, if ( str.Length() == 0 ) return ; - +*/ wxMacFastPortSetter helper(this) ; MacInstallFont() ; if ( 0 ) { m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize); - SetAntiAliasedTextEnabled(true, SInt16(m_scaleY * m_font.GetMacFontSize())); + SetAntiAliasedTextEnabled(true, SInt16(m_scaleY * m_font.MacGetFontSize())); m_macAliasWasEnabled = true ; } OSStatus status = noErr ; @@ -1470,76 +1418,8 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) { ::TextMode( srcCopy ) ; } - int length = strtext.Length() ; - - int laststop = 0 ; - int i = 0 ; int line = 0 ; { -#if 0 // we don't have to do all that here - while( i < length ) - { - if( strtext[i] == 13 || strtext[i] == 10) - { - wxString linetext = strtext.Mid( laststop , i - laststop ) ; -#if TARGET_CARBON - if ( useDrawThemeText ) - { - Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ; - wxMacCFStringHolder mString( linetext , m_font.GetEncoding() ) ; - if ( m_backgroundMode != wxTRANSPARENT ) - { - Point bounds={0,0} ; - Rect background = frame ; - SInt16 baseline ; - ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, - kThemeStateActive, - false, - &bounds, - &baseline ); - background.right = background.left + bounds.h ; - background.bottom = background.top + bounds.v ; - ::EraseRect( &background ) ; - } - ::DrawThemeTextBox( mString, - kThemeCurrentPortFont, - kThemeStateActive, - false, - &frame, - teJustLeft, - nil ); - line++ ; - } - else -#endif - { - wxCharBuffer text = linetext.mb_str(wxConvLocal) ; - ::DrawText( text , 0 , strlen(text) ) ; - if ( m_backgroundMode != wxTRANSPARENT ) - { - Point bounds={0,0} ; - Rect background = frame ; - SInt16 baseline ; - ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, - kThemeStateActive, - false, - &bounds, - &baseline ); - background.right = background.left + bounds.h ; - background.bottom = background.top + bounds.v ; - ::EraseRect( &background ) ; - } - line++ ; - ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) ); - } - laststop = i+1 ; - } - i++ ; - } - wxString linetext = strtext.Mid( laststop , i - laststop ) ; -#endif // 0 wxString linetext = strtext ; #if TARGET_CARBON if ( useDrawThemeText ) @@ -1553,7 +1433,7 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) Rect background = frame ; SInt16 baseline ; ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, + m_font.MacGetThemeFontID() , kThemeStateActive, false, &bounds, @@ -1563,7 +1443,7 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) ::EraseRect( &background ) ; } ::DrawThemeTextBox( mString, - kThemeCurrentPortFont, + m_font.MacGetThemeFontID() , kThemeStateActive, false, &frame, @@ -1620,60 +1500,21 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h *descent =YDEV2LOGREL( fi.descent ); if ( externalLeading ) *externalLeading = YDEV2LOGREL( fi.leading ) ; - int length = strtext.Length() ; - int laststop = 0 ; - int i = 0 ; int curwidth = 0 ; if ( width ) { *width = 0 ; -#if 0 // apparently we don't have to do all that - while( i < length ) - { - if( strtext[i] == 13 || strtext[i] == 10) - { - wxString linetext = strtext.Mid( laststop , i - laststop ) ; - if ( height ) - *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ; -#if TARGET_CARBON - if ( useGetThemeText ) - { - Point bounds={0,0} ; - SInt16 baseline ; - wxMacCFStringHolder mString( linetext , m_font.GetEncoding() ) ; - ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, - kThemeStateActive, - false, - &bounds, - &baseline ); - curwidth = bounds.h ; - } - else -#endif - { - wxCharBuffer text = linetext.mb_str(wxConvLocal) ; - curwidth = ::TextWidth( text , 0 , strlen(text) ) ; - } - if ( curwidth > *width ) - *width = XDEV2LOGREL( curwidth ) ; - laststop = i+1 ; - } - i++ ; - } - - wxString linetext = strtext.Mid( laststop , i - laststop ) ; -#endif // 0 wxString linetext = strtext ; -#if TARGET_CARBON + if ( useGetThemeText ) { Point bounds={0,0} ; SInt16 baseline ; wxMacCFStringHolder mString( linetext , m_font.GetEncoding() ) ; + ThemeFontID themeFont = m_font.MacGetThemeFontID() ; ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, + themeFont , kThemeStateActive, false, &bounds, @@ -1681,7 +1522,6 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h curwidth = bounds.h ; } else -#endif { wxCharBuffer text = linetext.mb_str(wxConvLocal) ; curwidth = ::TextWidth( text , 0 , strlen(text) ) ; @@ -1729,7 +1569,7 @@ bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) con SInt16 baseline ; wxMacCFStringHolder mString(str, m_font.GetEncoding()); ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, + m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, @@ -1778,7 +1618,7 @@ wxCoord wxDC::GetCharWidth(void) const SInt16 baseline ; CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text , 1 , CFStringGetSystemEncoding(), false ) ; ::GetThemeTextDimensions( mString, - kThemeCurrentPortFont, + m_font.MacGetThemeFontID(), kThemeStateActive, false, &bounds, @@ -1827,9 +1667,9 @@ void wxDC::MacInstallFont() const MacSetupBackgroundForCurrentPort(m_backgroundBrush) ; if ( m_font.Ok() ) { - ::TextFont( m_font.GetMacFontNum() ) ; - ::TextSize( (short)(m_scaleY * m_font.GetMacFontSize()) ) ; - ::TextFace( m_font.GetMacFontStyle() ) ; + ::TextFont( m_font.MacGetFontNum() ) ; + ::TextSize( (short)(m_scaleY * m_font.MacGetFontSize()) ) ; + ::TextFace( m_font.MacGetFontStyle() ) ; m_macFontInstalled = true ; m_macBrushInstalled = false ; m_macPenInstalled = false ; @@ -1898,9 +1738,9 @@ void wxDC::MacInstallFont() const } ::PenMode( mode ) ; OSStatus status = noErr ; - Fixed atsuSize = IntToFixed( int(m_scaleY * m_font.GetMacFontSize()) ) ; - Style qdStyle = m_font.GetMacFontStyle() ; - ATSUFontID atsuFont = m_font.GetMacATSUFontID() ; + Fixed atsuSize = IntToFixed( int(m_scaleY * m_font.MacGetFontSize()) ) ; + Style qdStyle = m_font.MacGetATSUAdditionalQDStyles() ; + ATSUFontID atsuFont = m_font.MacGetATSUFontID() ; status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUIStyle) ; wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ) ; ATSUAttributeTag atsuTags[] = @@ -2077,13 +1917,13 @@ void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush& background ) { case kwxMacBrushTheme : { - ::SetThemeBackground( background.GetMacTheme() , wxDisplayDepth() , true ) ; + ::SetThemeBackground( background.MacGetTheme() , wxDisplayDepth() , true ) ; break ; } case kwxMacBrushThemeBackground : { Rect extent ; - ThemeBackgroundKind bg = background.GetMacThemeBackground( &extent ) ; + ThemeBackgroundKind bg = background.MacGetThemeBackground( &extent ) ; ::ApplyThemeBackground( bg , &extent ,kThemeStateActive , wxDisplayDepth() , true ) ; break ; } diff --git a/src/mac/carbon/dialog.cpp b/src/mac/carbon/dialog.cpp index f29ed3e59e..16f3a0fb7f 100644 --- a/src/mac/carbon/dialog.cpp +++ b/src/mac/carbon/dialog.cpp @@ -57,16 +57,15 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name) { - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); + SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG); + // All dialogs should really have this style + style |= wxTAB_TRAVERSAL; if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) return FALSE; - MacCreateRealWindow( title , pos , size , MacRemoveBordersFromStyle(style) & ~(wxYES|wxOK|wxNO|wxCANCEL) , name ) ; - - m_macWindowBackgroundTheme = kThemeBrushDialogBackgroundActive ; - SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ; + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); return TRUE; } diff --git a/src/mac/carbon/dirmac.cpp b/src/mac/carbon/dirmac.cpp index 0afc3b5cb3..ff168bafdc 100644 --- a/src/mac/carbon/dirmac.cpp +++ b/src/mac/carbon/dirmac.cpp @@ -81,7 +81,6 @@ public: void Rewind() ; const wxString& GetName() const { return m_dirname; } - bool Ok() const { return m_ok; } private: CInfoPBRec m_CPB ; @@ -94,7 +93,6 @@ private: wxString m_filespec; int m_flags; - bool m_ok; }; // ============================================================================ @@ -108,8 +106,6 @@ private: wxDirData::wxDirData(const wxString& dirname) : m_dirname(dirname) { - m_ok = false; - OSErr err; // throw away the trailing slashes @@ -137,11 +133,7 @@ wxDirData::wxDirData(const wxString& dirname) err = FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ; #endif - //wxASSERT_MSG( (err == noErr) || (err == nsvErr) , wxT("Error accessing directory " + m_dirname)) ; - if ( (err == noErr) || (err == nsvErr)) - m_ok = true; - else - wxLogError(wxString(wxT("Error accessing directory ")) + m_dirname); + wxASSERT_MSG( (err == noErr) || (err == nsvErr) , wxT("Error accessing directory " + m_dirname)) ; m_CPB.hFileInfo.ioNamePtr = m_name ; m_index = 0 ; @@ -255,14 +247,8 @@ bool wxDir::Open(const wxString& dirname) { delete M_DIR; m_data = new wxDirData(dirname); - if (m_data->Ok()) - return TRUE; - else - { - delete m_data; - m_data = NULL; - return FALSE; - } + + return TRUE; } bool wxDir::IsOpened() const diff --git a/src/mac/carbon/dnd.cpp b/src/mac/carbon/dnd.cpp index 22ced39ede..9ffa32aafa 100644 --- a/src/mac/carbon/dnd.cpp +++ b/src/mac/carbon/dnd.cpp @@ -463,7 +463,7 @@ pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, Wind { wxPoint point(localMouse.h , localMouse.v) ; wxWindow *win = NULL ; - toplevel->MacGetWindowFromPointSub( point , &win ) ; + // TODO toplevel->MacGetWindowFromPointSub( point , &win ) ; int localx , localy ; localx = localMouse.h ; localy = localMouse.v ; diff --git a/src/mac/carbon/font.cpp b/src/mac/carbon/font.cpp index ef0ecc73b6..1b9416748d 100644 --- a/src/mac/carbon/font.cpp +++ b/src/mac/carbon/font.cpp @@ -119,11 +119,23 @@ protected: bool m_noAA; // No anti-aliasing public: - short m_macFontNum; - short m_macFontSize; - unsigned char m_macFontStyle; - wxUint32 m_macATSUFontID; - + short m_macFontNum; + short m_macFontSize; + Style m_macFontStyle; + + // ATSU Font Information + + // this is splitted into an ATSU font id that may + // contain some styles (special bold fonts etc) and + // these are the additional qd styles that are not + // included in the ATSU font id + ATSUFontID m_macATSUFontID; + Style m_macATSUAdditionalQDStyles ; + + // for true themeing support we must store the correct font + // information here, as this speeds up and optimizes rendering + ThemeFontID m_macThemeFontID ; + wxNativeFontInfo m_info; public: @@ -157,7 +169,10 @@ void wxFontRefData::Init(int pointSize, m_macFontNum = 0 ; m_macFontSize = 0; m_macFontStyle = 0; - m_fontId = 0; + m_macATSUFontID = 0; + m_macATSUAdditionalQDStyles = 0 ; + + m_macThemeFontID = kThemeCurrentPortFont ; m_noAA = FALSE; } @@ -167,68 +182,106 @@ wxFontRefData::~wxFontRefData() void wxFontRefData::MacFindFont() { - if( m_faceName.Length() == 0 ) + if ( m_macThemeFontID != kThemeCurrentPortFont ) { - switch( m_family ) - { - case wxDEFAULT : - m_macFontNum = ::GetAppFont() ; - break ; - case wxDECORATIVE : - ::GetFNum( "\pTimes" , &m_macFontNum) ; - break ; - case wxROMAN : - ::GetFNum( "\pTimes" , &m_macFontNum) ; - break ; - case wxSCRIPT : - ::GetFNum( "\pTimes" , &m_macFontNum) ; - break ; - case wxSWISS : - ::GetFNum( "\pGeneva" , &m_macFontNum) ; - break ; - case wxMODERN : - ::GetFNum( "\pMonaco" , &m_macFontNum) ; - break ; - } - Str255 name ; - GetFontName( m_macFontNum , name ) ; - m_faceName = wxMacMakeStringFromPascal( name ) ; + Str255 fontName ; + GetThemeFont(m_macThemeFontID , GetApplicationScript() , fontName , &m_macFontSize , &m_macFontStyle ) ; + m_faceName = wxMacMakeStringFromPascal( fontName ) ; + if ( m_macFontStyle & bold ) + m_weight = wxBOLD ; + else + m_weight = wxNORMAL ; + if ( m_macFontStyle & italic ) + m_style = wxITALIC ; + if ( m_macFontStyle & underline ) + m_underlined = true ; + ::GetFNum( fontName, &m_macFontNum); + m_pointSize = m_macFontSize ; } else { - if ( m_faceName == wxT("systemfont") ) - m_macFontNum = ::GetSysFont() ; - else if ( m_faceName == wxT("applicationfont") ) - m_macFontNum = ::GetAppFont() ; + if( m_faceName.Length() == 0 ) + { + switch( m_family ) + { + case wxDEFAULT : + m_macFontNum = ::GetAppFont() ; + break ; + case wxDECORATIVE : + ::GetFNum( "\pTimes" , &m_macFontNum) ; + break ; + case wxROMAN : + ::GetFNum( "\pTimes" , &m_macFontNum) ; + break ; + case wxSCRIPT : + ::GetFNum( "\pTimes" , &m_macFontNum) ; + break ; + case wxSWISS : + ::GetFNum( "\pGeneva" , &m_macFontNum) ; + break ; + case wxMODERN : + ::GetFNum( "\pMonaco" , &m_macFontNum) ; + break ; + } + Str255 name ; + ::GetFontName( m_macFontNum , name ) ; + m_faceName = wxMacMakeStringFromPascal( name ) ; + } else { - Str255 fontname ; - wxMacStringToPascal( m_faceName , fontname ) ; - ::GetFNum( fontname, &m_macFontNum); + if ( m_faceName == wxT("systemfont") ) + m_macFontNum = ::GetSysFont() ; + else if ( m_faceName == wxT("applicationfont") ) + m_macFontNum = ::GetAppFont() ; + else + { + Str255 fontname ; + wxMacStringToPascal( m_faceName , fontname ) ; + ::GetFNum( fontname, &m_macFontNum); + } } + + m_macFontStyle = 0; + if (m_weight == wxBOLD) + m_macFontStyle |= bold; + if (m_style == wxITALIC || m_style == wxSLANT) + m_macFontStyle |= italic; + if (m_underlined) + m_macFontStyle |= underline; + m_macFontSize = m_pointSize ; } - m_macFontStyle = 0; - if (m_weight == wxBOLD) - m_macFontStyle |= bold; - if (m_style == wxITALIC || m_style == wxSLANT) - m_macFontStyle |= italic; - if (m_underlined) - m_macFontStyle |= underline; - m_macFontSize = m_pointSize ; - - //TODO:if we supply the style as an additional parameter we must make a testing - //sequence in order to degrade gracefully while trying to maintain most of the style - //information, meanwhile we just take the normal font and apply the features after -#ifdef __WXDEBUG__ - OSStatus status = -#endif // __WXDEBUG__ - ::ATSUFONDtoFontID(m_macFontNum, normal /*qdStyle*/, (UInt32*)&m_macATSUFontID); - /* - status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) , - kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ; - */ - wxASSERT_MSG( status == noErr , wxT("couldn't retrieve font identifier") ) ; + // we try to get as much styles as possible into ATSU + Style atsuStyle = normal ; + verify_noerr(::ATSUFONDtoFontID(m_macFontNum, atsuStyle , (UInt32*)&m_macATSUFontID) ); + if ( m_macFontStyle & bold ) + { + ATSUFontID test ; + if ( ::ATSUFONDtoFontID(m_macFontNum, atsuStyle | bold , &test) == noErr ) + { + atsuStyle |= bold ; + m_macATSUFontID = test ; + } + } + if ( m_macFontStyle & italic ) + { + ATSUFontID test ; + if ( ::ATSUFONDtoFontID(m_macFontNum, atsuStyle | italic , &test) == noErr ) + { + atsuStyle |= italic ; + m_macATSUFontID = test ; + } + } + if ( m_macFontStyle & underline ) + { + ATSUFontID test ; + if ( ::ATSUFONDtoFontID(m_macFontNum, atsuStyle | underline , &test) == noErr ) + { + atsuStyle |= underline ; + m_macATSUFontID = test ; + } + } + m_macATSUAdditionalQDStyles = m_macFontStyle & (~atsuStyle ) ; } // ---------------------------------------------------------------------------- @@ -269,6 +322,16 @@ bool wxFont::Create(int pointSize, return TRUE; } +bool wxFont::MacCreateThemeFont(wxUint16 themeFontID ) +{ + UnRef(); + m_refData = new wxFontRefData(12, 0, 0, wxNORMAL,false, wxEmptyString, wxFONTENCODING_DEFAULT); + M_FONTDATA->m_macThemeFontID = themeFontID ; + RealizeResource(); + + return TRUE; +} + wxFont::~wxFont() { } @@ -374,69 +437,92 @@ void wxFont::SetNoAntiAliasing( bool no ) int wxFont::GetPointSize() const { + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); return M_FONTDATA->m_pointSize; } int wxFont::GetFamily() const { + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); return M_FONTDATA->m_family; } int wxFont::GetStyle() const { + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); return M_FONTDATA->m_style; } int wxFont::GetWeight() const { + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); return M_FONTDATA->m_weight; } bool wxFont::GetUnderlined() const { + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); return M_FONTDATA->m_underlined; } wxString wxFont::GetFaceName() const { - wxString str; - if ( M_FONTDATA ) - str = M_FONTDATA->m_faceName ; - return str; + wxCHECK_MSG( M_FONTDATA != NULL , wxEmptyString , wxT("invalid font") ); + return M_FONTDATA->m_faceName; } wxFontEncoding wxFont::GetEncoding() const { + wxCHECK_MSG( M_FONTDATA != NULL , wxFONTENCODING_DEFAULT , wxT("invalid font") ); return M_FONTDATA->m_encoding; } bool wxFont::GetNoAntiAliasing() { + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); return M_FONTDATA->m_noAA; } -short wxFont::GetMacFontNum() const +short wxFont::MacGetFontNum() const { + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); return M_FONTDATA->m_macFontNum; } -short wxFont::GetMacFontSize() const +short wxFont::MacGetFontSize() const { + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); return M_FONTDATA->m_macFontSize; } -wxByte wxFont::GetMacFontStyle() const +wxByte wxFont::MacGetFontStyle() const { + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); return M_FONTDATA->m_macFontStyle; } -wxUint32 wxFont::GetMacATSUFontID() const +wxUint32 wxFont::MacGetATSUFontID() const { + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); return M_FONTDATA->m_macATSUFontID; } +wxUint32 wxFont::MacGetATSUAdditionalQDStyles() const +{ + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); + return M_FONTDATA->m_macATSUAdditionalQDStyles; +} + +wxUint16 wxFont::MacGetThemeFontID() const +{ + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); + return M_FONTDATA->m_macThemeFontID; +} + + const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); M_FONTDATA->m_info.InitFromFont(*this); diff --git a/src/mac/carbon/frame.cpp b/src/mac/carbon/frame.cpp index b56f24712b..4fba75bad2 100644 --- a/src/mac/carbon/frame.cpp +++ b/src/mac/carbon/frame.cpp @@ -62,31 +62,6 @@ void wxFrame::Init() #endif } -wxPoint wxFrame::GetClientAreaOrigin() const -{ - // on mac we are at position -1,-1 with the control - wxPoint pt(0, 0); - -#if wxUSE_TOOLBAR - if ( GetToolBar() ) - { - int w, h; - GetToolBar()->GetSize(& w, & h); - - if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) - { - pt.x += w - 1; - } - else - { - pt.y += h - 1 ; - } - } -#endif // wxUSE_TOOLBAR - - return pt; -} - bool wxFrame::Create(wxWindow *parent, wxWindowID id, const wxString& title, @@ -95,15 +70,11 @@ bool wxFrame::Create(wxWindow *parent, long style, const wxString& name) { - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) return FALSE; - MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; - - m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; - SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ; + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); wxModelessWindows.Append(this); @@ -254,22 +225,34 @@ void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) void wxFrame::DoGetClientSize(int *x, int *y) const { - wxWindow::DoGetClientSize( x , y ) ; + wxTopLevelWindow::DoGetClientSize( x , y ) ; #if wxUSE_STATUSBAR if ( GetStatusBar() && y ) { int statusX, statusY; - GetStatusBar()->GetClientSize(&statusX, &statusY); - *y -= statusY; + GetStatusBar()->GetSize(&statusX, &statusY); + if ( y) *y -= statusY; } #endif // wxUSE_STATUSBAR - wxPoint pt(GetClientAreaOrigin()); - if ( y ) - *y -= pt.y; - if ( x ) - *x -= pt.x; +#if wxUSE_TOOLBAR + wxToolBar *toolbar = GetToolBar(); + if ( toolbar && toolbar->IsShown() ) + { + int w, h; + toolbar->GetSize(&w, &h); + + if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) + { + if ( x ) *x -= w; + } + else + { + if ( y ) *y -= h; + } + } +#endif // wxUSE_TOOLBAR } void wxFrame::DoSetClientSize(int clientwidth, int clientheight) @@ -278,6 +261,10 @@ void wxFrame::DoSetClientSize(int clientwidth, int clientheight) int currentwidth , currentheight ; GetClientSize( ¤tclientwidth , ¤tclientheight ) ; + if ( clientwidth == -1 ) + clientwidth = currentclientwidth ; + if ( clientheight == -1 ) + clientheight = currentclientheight ; GetSize( ¤twidth , ¤theight ) ; // find the current client size @@ -306,8 +293,7 @@ void wxFrame::PositionToolBar() { int cw, ch; - cw = m_width ; - ch = m_height ; + GetSize( &cw , &ch ) ; if ( GetStatusBar() ) { @@ -318,20 +304,21 @@ void wxFrame::PositionToolBar() if (GetToolBar()) { - int tw, th; + int tx, ty, tw, th; + tx = ty = 0 ; + GetToolBar()->GetSize(& tw, & th); - if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) { // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS // means, pretend we don't have toolbar/status bar, so we // have the original client size. - GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); + GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS ); } else { // Use the 'real' position - GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); + GetToolBar()->SetSize(tx , ty , cw , th, wxSIZE_NO_ADJUSTMENTS ); } } } diff --git a/src/mac/carbon/gauge.cpp b/src/mac/carbon/gauge.cpp index 01a557e17c..19af6c6f41 100644 --- a/src/mac/carbon/gauge.cpp +++ b/src/mac/carbon/gauge.cpp @@ -29,12 +29,13 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - if ( !wxGaugeBase::Create(parent, id, range, pos, s, style, validator, name) ) + m_macIsUserPane = FALSE ; + + if ( !wxGaugeBase::Create(parent, id, range, pos, s, style & 0xE0FFFFFF, validator, name) ) return false; wxSize size = s ; - Rect bounds ; - Str255 title ; + m_rangeMax = range ; m_gaugePos = 0 ; @@ -43,12 +44,11 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id, size = wxSize( 200 , 16 ) ; } - MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style & 0xE0FFFFFF /* no borders on mac */ , validator , name , &bounds , title ) ; - - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , range, + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , range, kControlProgressBarProc , (long) this ) ; - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; return TRUE; } @@ -64,13 +64,13 @@ void wxGauge::SetBezelFace(int w) void wxGauge::SetRange(int r) { m_rangeMax = r; - ::SetControl32BitMaximum( (ControlHandle) m_macControl , m_rangeMax ) ; + ::SetControl32BitMaximum( (ControlRef) m_macControl , m_rangeMax ) ; } void wxGauge::SetValue(int pos) { m_gaugePos = pos; - ::SetControl32BitValue( (ControlHandle) m_macControl , m_gaugePos ) ; + ::SetControl32BitValue( (ControlRef) m_macControl , m_gaugePos ) ; } int wxGauge::GetShadowWidth() const diff --git a/src/mac/carbon/glcanvas.cpp b/src/mac/carbon/glcanvas.cpp index e208531ff4..a867fa651f 100644 --- a/src/mac/carbon/glcanvas.cpp +++ b/src/mac/carbon/glcanvas.cpp @@ -49,7 +49,7 @@ wxGLContext::wxGLContext( { m_window = win; - m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetRootWindow())); + m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetTopLevelWindowRef())); m_glContext = aglCreateContext(fmt, other ? other->m_glContext : NULL); wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") ); @@ -262,7 +262,7 @@ void wxGLCanvas::SetViewport() int width, height; GetClientSize(& width, & height); Rect bounds ; - GetWindowPortBounds( MAC_WXHWND(MacGetRootWindow()) , &bounds ) ; + GetWindowPortBounds( MAC_WXHWND(MacGetTopLevelWindowRef()) , &bounds ) ; GLint parms[4] ; parms[0] = x ; parms[1] = bounds.bottom - bounds.top - ( y + height ) ; @@ -331,7 +331,7 @@ bool wxGLCanvas::Show(bool show) } else { - if ( MacIsReallyShown() && !m_macCanvasIsShown ) + if ( IsControlVisible( (ControlRef) m_macControl ) && !m_macCanvasIsShown ) { m_macCanvasIsShown = true ; SetViewport() ; @@ -352,7 +352,7 @@ void wxGLCanvas::MacSuperShown( bool show ) } else { - if ( MacIsReallyShown() && !m_macCanvasIsShown ) + if ( IsControlVisible( (ControlRef) m_macControl ) && !m_macCanvasIsShown ) { m_macCanvasIsShown = true ; SetViewport() ; diff --git a/src/mac/carbon/gsockosx.cpp b/src/mac/carbon/gsockosx.cpp index 8d888ec8d0..b9df39196e 100644 --- a/src/mac/carbon/gsockosx.cpp +++ b/src/mac/carbon/gsockosx.cpp @@ -87,7 +87,7 @@ void _GSocket_GUI_Cleanup(void) int _GSocket_GUI_Init_Socket(GSocket *socket) { - struct MacGSocketData *data = (struct MacGSocketData *) malloc(sizeof(struct MacGSocketData)); + struct MacGSocketData *data = (struct MacGSocketData *)malloc(sizeof(struct MacGSocketData)); if (data) { socket->m_gui_dependent = (char*)data; diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp index 8322a7a2f2..3321963637 100644 --- a/src/mac/carbon/listbox.cpp +++ b/src/mac/carbon/listbox.cpp @@ -27,39 +27,812 @@ IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl) BEGIN_EVENT_TABLE(wxListBox, wxControl) +#if !TARGET_API_MAC_OSX EVT_SIZE( wxListBox::OnSize ) EVT_CHAR( wxListBox::OnChar ) +#endif END_EVENT_TABLE() #endif -#include "wx/mac/uma.h" +#include "wx/mac/uma.h" + +#if TARGET_API_MAC_OSX + +// new databrowserbased version + +// Listbox item +wxListBox::wxListBox() +{ + m_noItems = 0; + m_selected = 0; + m_macList = NULL ; +} + +bool wxListBox::Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos, + const wxSize& size, + const wxArrayString& choices, + long style, + const wxValidator& validator, + const wxString& name) +{ + wxCArrayString chs(choices); + + return Create(parent, id, pos, size, chs.GetCount(), chs.GetStrings(), + style, validator, name); +} + +static pascal OSStatus ListBoxGetSetItemData(ControlRef browser, + DataBrowserItemID itemID, DataBrowserPropertyID property, + DataBrowserItemDataRef itemData, Boolean changeValue) +{ + OSStatus err = errDataBrowserPropertyNotSupported; + + if ( ! changeValue ) + { + switch (property) + { + + case 1024: + { + long ref = GetControlReference( browser ) ; + if ( ref ) + { + wxListBox* list = wxDynamicCast( ref , wxListBox ) ; + for ( size_t i = 0 ; i < list->m_idArray.GetCount() ; ++i ) + if ( list->m_idArray[i] == (long) itemID ) + { + wxMacCFStringHolder cf( list->GetString(i) , list->GetFont().GetEncoding() ) ; + verify_noerr( ::SetDataBrowserItemDataText( itemData , cf ) ) ; + err = noErr ; + break ; + } + } + } + break; + + default: + + break; + } + } + + return err; +} +bool wxListBox::Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos, + const wxSize& size, + int n, const wxString choices[], + long style, + const wxValidator& validator, + const wxString& name) +{ + m_macIsUserPane = FALSE ; + + if ( !wxListBoxBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) ) + return false; + + m_noItems = 0 ; // this will be increased by our append command + m_selected = 0; + m_nextId = 1 ; + + + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + ControlRef browser ; + + verify_noerr( ::CreateDataBrowserControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, kDataBrowserListView , (ControlRef *)&m_macControl ) ); + browser = (ControlRef) m_macControl ; + + DataBrowserSelectionFlags options = kDataBrowserDragSelect ; + if ( style & wxLB_MULTIPLE ) + { + options += kDataBrowserAlwaysExtendSelection + kDataBrowserCmdTogglesSelection ; + } + else if ( style & wxLB_EXTENDED ) + { + // default behaviour + } + else + { + options += kDataBrowserSelectOnlyOne ; + } + verify_noerr(SetDataBrowserSelectionFlags (browser, options ) ); + + DataBrowserListViewColumnDesc columnDesc ; + columnDesc.headerBtnDesc.titleOffset = 0; + columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; + + columnDesc.headerBtnDesc.btnFontStyle.flags = + kControlUseFontMask | kControlUseJustMask; + + columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent; + columnDesc.propertyDesc.propertyType = kDataBrowserTextType; + columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault; + columnDesc.headerBtnDesc.minimumWidth = 0; + columnDesc.headerBtnDesc.maximumWidth = 10000; + + columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; + columnDesc.headerBtnDesc.btnFontStyle.style = normal; + columnDesc.headerBtnDesc.titleString = NULL ; // CFSTR( "" ); + + columnDesc.propertyDesc.propertyID = 1024; + columnDesc.propertyDesc.propertyType = kDataBrowserTextType; + columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewTypeSelectColumn | kDataBrowserTableViewSelectionColumn ; + + + verify_noerr(::AddDataBrowserListViewColumn(browser, &columnDesc, kDataBrowserListViewAppendColumn) ) ; + verify_noerr(::AutoSizeDataBrowserListViewColumns( browser ) ) ; + verify_noerr(::SetDataBrowserHasScrollBars( browser , false , true ) ) ; + verify_noerr(::SetDataBrowserTableViewHiliteStyle( browser, kDataBrowserTableViewFillHilite ) ) ; + verify_noerr(::SetDataBrowserListViewHeaderBtnHeight( browser , 0 ) ) ; + DataBrowserCallbacks callbacks ; + + callbacks.version = kDataBrowserLatestCallbacks; + + InitDataBrowserCallbacks(&callbacks); + + callbacks.u.v1.itemDataCallback = + NewDataBrowserItemDataUPP(ListBoxGetSetItemData); + + SetDataBrowserCallbacks(browser, &callbacks); + + MacPostControlCreate(pos,size) ; + + for ( int i = 0 ; i < n ; i++ ) + { + Append( choices[i] ) ; + } + + return TRUE; +} + +wxListBox::~wxListBox() +{ + SetControlReference( (ControlRef) m_macControl , NULL ) ; + FreeData() ; + // avoid access during destruction + if ( m_macList ) + { + m_macList = NULL ; + } +} + +void wxListBox::FreeData() +{ +#if wxUSE_OWNER_DRAWN + if ( m_windowStyle & wxLB_OWNERDRAW ) + { + size_t uiCount = m_aItems.Count(); + while ( uiCount-- != 0 ) { + delete m_aItems[uiCount]; + m_aItems[uiCount] = NULL; + } + + m_aItems.Clear(); + } + else +#endif // wxUSE_OWNER_DRAWN + if ( HasClientObjectData() ) + { + for ( size_t n = 0; n < (size_t)m_noItems; n++ ) + { + delete GetClientObject(n); + } + } +} + +void wxListBox::DoSetSize(int x, int y, + int width, int height, + int sizeFlags ) +{ + wxControl::DoSetSize( x , y , width , height , sizeFlags ) ; +} + +void wxListBox::DoSetFirstItem(int N) +{ + MacScrollTo( N ) ; +} + +void wxListBox::Delete(int N) +{ + wxCHECK_RET( N >= 0 && N < m_noItems, + wxT("invalid index in wxListBox::Delete") ); + +#if wxUSE_OWNER_DRAWN + delete m_aItems[N]; + m_aItems.RemoveAt(N); +#else // !wxUSE_OWNER_DRAWN + if ( HasClientObjectData() ) + { + delete GetClientObject(N); + } +#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN + m_stringArray.RemoveAt( N ) ; + m_dataArray.RemoveAt( N ) ; + m_noItems --; + + MacDelete( N ) ; +} + +int wxListBox::DoAppend(const wxString& item) +{ + int index = m_noItems ; + m_stringArray.Add( item ) ; + m_dataArray.Add( NULL ); + m_noItems ++; + DoSetItemClientData( index , NULL ) ; + MacAppend( item ) ; + + return index ; +} + +void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData) +{ + Clear() ; + int n = choices.GetCount(); + + for( int i = 0 ; i < n ; ++i ) + { + if ( clientData ) + { +#if wxUSE_OWNER_DRAWN + wxASSERT_MSG(clientData[i] == NULL, + wxT("Can't use client data with owner-drawn listboxes")); +#else // !wxUSE_OWNER_DRAWN + Append( choices[i] , clientData[i] ) ; +#endif + } + else + Append( choices[i] ) ; + } + +#if wxUSE_OWNER_DRAWN + if ( m_windowStyle & wxLB_OWNERDRAW ) { + // first delete old items + size_t ui = m_aItems.Count(); + while ( ui-- != 0 ) { + delete m_aItems[ui]; + m_aItems[ui] = NULL; + } + m_aItems.Empty(); + + // then create new ones + for ( ui = 0; ui < (size_t)m_noItems; ui++ ) { + wxOwnerDrawn *pNewItem = CreateItem(ui); + pNewItem->SetName(choices[ui]); + m_aItems.Add(pNewItem); + } + } +#endif // wxUSE_OWNER_DRAWN +} + +bool wxListBox::HasMultipleSelection() const +{ + return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED); +} + +int wxListBox::FindString(const wxString& s) const +{ + + if ( s.Right(1) == wxT("*") ) + { + wxString search = s.Left( s.Length() - 1 ) ; + int len = search.Length() ; + Str255 s1 , s2 ; + wxMacStringToPascal( search , s2 ) ; + + for ( int i = 0 ; i < m_noItems ; ++ i ) + { + wxMacStringToPascal( m_stringArray[i].Left( len ) , s1 ) ; + + if ( EqualString( s1 , s2 , false , false ) ) + return i ; + } + if ( s.Left(1) == wxT("*") && s.Length() > 1 ) + { + wxString st = s ; + st.MakeLower() ; + for ( int i = 0 ; i < m_noItems ; ++i ) + { + if ( GetString(i).Lower().Matches(st) ) + return i ; + } + } + + } + else + { + Str255 s1 , s2 ; + + wxMacStringToPascal( s , s2 ) ; + + for ( int i = 0 ; i < m_noItems ; ++ i ) + { + wxMacStringToPascal( m_stringArray[i] , s1 ) ; + + if ( EqualString( s1 , s2 , false , false ) ) + return i ; + } + } + return -1; +} + +void wxListBox::Clear() +{ + FreeData(); + m_noItems = 0; + m_stringArray.Empty() ; + m_dataArray.Empty() ; + MacClear() ; +} + +void wxListBox::SetSelection(int N, bool select) +{ + wxCHECK_RET( N >= 0 && N < m_noItems, + wxT("invalid index in wxListBox::SetSelection") ); + MacSetSelection( N , select ) ; + GetSelections( m_selectionPreImage ) ; +} + +bool wxListBox::IsSelected(int N) const +{ + wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE, + wxT("invalid index in wxListBox::Selected") ); + + return MacIsSelected( N ) ; +} + +void *wxListBox::DoGetItemClientData(int N) const +{ + wxCHECK_MSG( N >= 0 && N < m_noItems, NULL, + wxT("invalid index in wxListBox::GetClientData")); + + return (void *)m_dataArray[N]; +} + +wxClientData *wxListBox::DoGetItemClientObject(int N) const +{ + return (wxClientData *) DoGetItemClientData( N ) ; +} + +void wxListBox::DoSetItemClientData(int N, void *Client_data) +{ + wxCHECK_RET( N >= 0 && N < m_noItems, + wxT("invalid index in wxListBox::SetClientData") ); + +#if wxUSE_OWNER_DRAWN + if ( m_windowStyle & wxLB_OWNERDRAW ) + { + // client data must be pointer to wxOwnerDrawn, otherwise we would crash + // in OnMeasure/OnDraw. + wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes")); + } +#endif // wxUSE_OWNER_DRAWN + wxASSERT_MSG( m_dataArray.GetCount() >= (size_t) N , wxT("invalid client_data array") ) ; + + if ( m_dataArray.GetCount() > (size_t) N ) + { + m_dataArray[N] = (char*) Client_data ; + } + else + { + m_dataArray.Add( (char*) Client_data ) ; + } +} + +void wxListBox::DoSetItemClientObject(int n, wxClientData* clientData) +{ + DoSetItemClientData(n, clientData); +} + +// Return number of selections and an array of selected integers +int wxListBox::GetSelections(wxArrayInt& aSelections) const +{ + return MacGetSelections( aSelections ) ; +} + +// Get single selection, for single choice list items +int wxListBox::GetSelection() const +{ + return MacGetSelection() ; +} + +// Find string for position +wxString wxListBox::GetString(int N) const +{ + return m_stringArray[N] ; +} + +void wxListBox::DoInsertItems(const wxArrayString& items, int pos) +{ + wxCHECK_RET( pos >= 0 && pos <= m_noItems, + wxT("invalid index in wxListBox::InsertItems") ); + + int nItems = items.GetCount(); + + for ( int i = 0 ; i < nItems ; i++ ) + { + m_stringArray.Insert( items[i] , pos + i ) ; + m_dataArray.Insert( NULL , pos + i ) ; + MacInsert( pos + i , items[i] ) ; + } + + m_noItems += nItems; +} + +void wxListBox::SetString(int N, const wxString& s) +{ + m_stringArray[N] = s ; + MacSet( N , s ) ; +} + +wxSize wxListBox::DoGetBestSize() const +{ + int lbWidth = 100; // some defaults + int lbHeight = 110; + int wLine; + + { + wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetTopLevelWindowRef() ) ) ; + + if ( m_font.Ok() ) + { + ::TextFont( m_font.MacGetFontNum() ) ; + ::TextSize( m_font.MacGetFontSize() ) ; + ::TextFace( m_font.MacGetFontStyle() ) ; + } + else + { + ::TextFont( kFontIDMonaco ) ; + ::TextSize( 9 ); + ::TextFace( 0 ) ; + } + + // Find the widest line + for(int i = 0; i < GetCount(); i++) { + wxString str(GetString(i)); + #if wxUSE_UNICODE + Point bounds={0,0} ; + SInt16 baseline ; + ::GetThemeTextDimensions( wxMacCFStringHolder( str , m_font.GetEncoding() ) , + kThemeCurrentPortFont, + kThemeStateActive, + false, + &bounds, + &baseline ); + wLine = bounds.h ; + #else + wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ; + #endif + lbWidth = wxMax(lbWidth, wLine); + } + + // Add room for the scrollbar + lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); + + // And just a bit more + int cy = 12 ; + int cx = ::TextWidth( "X" , 0 , 1 ) ; + lbWidth += cx ; + + // don't make the listbox too tall (limit height to around 10 items) but don't + // make it too small neither + lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10); + } + + return wxSize(lbWidth, lbHeight); +} + +int wxListBox::GetCount() const +{ + return m_noItems; +} + +void wxListBox::Refresh(bool eraseBack, const wxRect *rect) +{ + wxControl::Refresh( eraseBack , rect ) ; + // MacRedrawControl() ; +} + +#if wxUSE_OWNER_DRAWN + +class wxListBoxItem : public wxOwnerDrawn +{ +public: + wxListBoxItem(const wxString& str = ""); +}; + +wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE) +{ + // no bitmaps/checkmarks + SetMarginWidth(0); +} + +wxOwnerDrawn *wxListBox::CreateItem(size_t n) +{ + return new wxListBoxItem(); +} + +#endif //USE_OWNER_DRAWN + +// ============================================================================ +// list box control implementation +// ============================================================================ + +void wxListBox::MacDelete( int N ) +{ + UInt32 id = m_idArray[N] ; + verify_noerr(::RemoveDataBrowserItems((ControlRef) m_macControl , kDataBrowserNoItem , 1 , (UInt32*) &id , kDataBrowserItemNoProperty ) ) ; + m_idArray.RemoveAt( N ) ; +} + +void wxListBox::MacInsert( int n , const wxString& text) +{ + verify_noerr(::AddDataBrowserItems( (ControlRef) m_macControl , kDataBrowserNoItem , 1 , (UInt32*) &m_nextId , kDataBrowserItemNoProperty ) ) ; + m_idArray.Insert( m_nextId , n ) ; + ++m_nextId ; +} + +void wxListBox::MacAppend( const wxString& text) +{ + verify_noerr(::AddDataBrowserItems( (ControlRef) m_macControl , kDataBrowserNoItem , 1 , (UInt32*) &m_nextId , kDataBrowserItemNoProperty ) ) ; + m_idArray.Add( m_nextId ) ; + ++m_nextId ; +} + +void wxListBox::MacClear() +{ + verify_noerr(::RemoveDataBrowserItems((ControlRef) m_macControl , kDataBrowserNoItem , 0 , NULL , kDataBrowserItemNoProperty ) ) ; + m_dataArray.Empty() ; +} + +void wxListBox::MacSetSelection( int n , bool select ) +{ + UInt32 id = m_idArray[n] ; + if ( ::IsDataBrowserItemSelected( (ControlRef) m_macControl , id ) != select ) + { + verify_noerr(::SetDataBrowserSelectedItems((ControlRef) m_macControl , 1 , & id , kDataBrowserItemsToggle ) ) ; + } + MacScrollTo( n ) ; +} + +bool wxListBox::MacIsSelected( int n ) const +{ + return ::IsDataBrowserItemSelected( (ControlRef) m_macControl , m_idArray[n] ) ; +} + +int wxListBox::MacGetSelection() const +{ + for ( size_t i = 0 ; i < m_idArray.GetCount() ; ++i ) + { + if ( ::IsDataBrowserItemSelected((ControlRef) m_macControl , m_idArray[i] ) ) + { + return i ; + } + } + return -1 ; +} + +int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const +{ + int no_sel = 0 ; + + aSelections.Empty(); + for ( size_t i = 0 ; i < m_idArray.GetCount() ; ++i ) + { + if ( ::IsDataBrowserItemSelected((ControlRef) m_macControl , m_idArray[i] ) ) + { + aSelections.Add( i ) ; + no_sel++ ; + } + } + return no_sel ; +} -#if PRAGMA_STRUCT_ALIGN - #pragma options align=mac68k -#elif PRAGMA_STRUCT_PACKPUSH - #pragma pack(push, 2) -#elif PRAGMA_STRUCT_PACK - #pragma pack(2) -#endif +void wxListBox::MacSet( int n , const wxString& text ) +{ + // as we don't store the strings we only have to issue a redraw + UInt32 id = m_idArray[n] ; + verify_noerr( ::UpdateDataBrowserItems( (ControlRef) m_macControl , kDataBrowserNoItem , 1 , &id , kDataBrowserItemNoProperty , kDataBrowserItemNoProperty ) ) ; +} -typedef struct { - unsigned short instruction; - void (*function)(); -} ldefRec, *ldefPtr, **ldefHandle; - -#if PRAGMA_STRUCT_ALIGN - #pragma options align=reset -#elif PRAGMA_STRUCT_PACKPUSH - #pragma pack(pop) -#elif PRAGMA_STRUCT_PACK - #pragma pack() -#endif +void wxListBox::MacScrollTo( int n ) +{ + // TODO implement scrolling +} + +void wxListBox::OnSize( wxSizeEvent &event) +{ +} + +void wxListBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) +{ + Boolean wasDoubleClick = false ; + long result ; + + ::GetControlData( (ControlRef) m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ; + if ( !wasDoubleClick ) + { + MacDoClick() ; + } + else + { + MacDoDoubleClick() ; + } +} + +void wxListBox::MacSetRedraw( bool doDraw ) +{ + // nothing to do in compositing mode +} + +void wxListBox::MacDoClick() +{ + wxArrayInt aSelections; + int n ; + size_t count = GetSelections(aSelections); + + if ( count == m_selectionPreImage.GetCount() ) + { + bool hasChanged = false ; + for ( size_t i = 0 ; i < count ; ++i ) + { + if ( aSelections[i] != m_selectionPreImage[i] ) + { + hasChanged = true ; + break ; + } + } + if ( !hasChanged ) + { + return ; + } + } + + m_selectionPreImage = aSelections; + + wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); + event.SetEventObject( this ); + + if ( count > 0 ) + { + n = aSelections[0]; + if ( HasClientObjectData() ) + event.SetClientObject( GetClientObject(n) ); + else if ( HasClientUntypedData() ) + event.SetClientData( GetClientData(n) ); + event.SetString( GetString(n) ); + } + else + { + n = -1; + } + + event.m_commandInt = n; + + GetEventHandler()->ProcessEvent(event); +} + +void wxListBox::MacDoDoubleClick() +{ + wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event) ; +} + +void wxListBox::OnChar(wxKeyEvent& event) +{ + // todo trigger proper events here + event.Skip() ; + return ; + + if ( event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) + { + wxWindow* parent = GetParent() ; + while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) + parent = parent->GetParent() ; + + if ( parent && parent->GetDefaultItem() ) + { + wxButton *def = wxDynamicCast(parent->GetDefaultItem(), + wxButton); + if ( def && def->IsEnabled() ) + { + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); + event.SetEventObject(def); + def->Command(event); + return ; + } + } + event.Skip() ; + } + /* generate wxID_CANCEL if command-. or has been pressed (typically in dialogs) */ + else if (event.GetKeyCode() == WXK_ESCAPE || (event.GetKeyCode() == '.' && event.MetaDown() ) ) + { + // FIXME: look in ancestors, not just parent. + wxWindow* win = GetParent()->FindWindow( wxID_CANCEL ) ; + if (win) + { + wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); + new_event.SetEventObject( win ); + win->GetEventHandler()->ProcessEvent( new_event ); + } + } + else if ( event.GetKeyCode() == WXK_TAB ) + { + wxNavigationKeyEvent new_event; + new_event.SetEventObject( this ); + new_event.SetDirection( !event.ShiftDown() ); + /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ + new_event.SetWindowChange( event.ControlDown() ); + new_event.SetCurrentFocus( this ); + if ( !GetEventHandler()->ProcessEvent( new_event ) ) + event.Skip() ; + } + else if ( event.GetKeyCode() == WXK_DOWN || event.GetKeyCode() == WXK_UP ) + { + // perform the default key handling first + wxControl::OnKeyDown( event ) ; + + wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); + event.SetEventObject( this ); + + wxArrayInt aSelections; + int n, count = GetSelections(aSelections); + if ( count > 0 ) + { + n = aSelections[0]; + if ( HasClientObjectData() ) + event.SetClientObject( GetClientObject(n) ); + else if ( HasClientUntypedData() ) + event.SetClientData( GetClientData(n) ); + event.SetString( GetString(n) ); + } + else + { + n = -1; + } + + event.m_commandInt = n; + + GetEventHandler()->ProcessEvent(event); + } + else + { + if ( event.GetTimestamp() > m_lastTypeIn + 60 ) + { + m_typeIn = wxEmptyString ; + } + m_lastTypeIn = event.GetTimestamp() ; + m_typeIn += (char) event.GetKeyCode() ; + int line = FindString(wxT("*")+m_typeIn+wxT("*")) ; + if ( line >= 0 ) + { + if ( GetSelection() != line ) + { + SetSelection(line) ; + wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId); + event.SetEventObject( this ); + + if ( HasClientObjectData() ) + event.SetClientObject( GetClientObject( line ) ); + else if ( HasClientUntypedData() ) + event.SetClientData( GetClientData(line) ); + event.SetString( GetString(line) ); + + event.m_commandInt = line ; + + GetEventHandler()->ProcessEvent(event); + } + } + } +} -#if TARGET_CARBON -const short kwxMacListItemHeight = 19 ; #else -const short kwxMacListItemHeight = 14 ; -#endif + +// old carbon version + +const short kwxMacListItemHeight = 19 ; extern "C" { @@ -68,15 +841,24 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect ListHandle listHandle ) ; } -static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *drawRect, +static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *d, Cell cell, short dataOffset, short dataLength, ListHandle listHandle ) { wxListBox* list; - list = (wxListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) ); - if ( list == NULL ) + Rect r = *d ; + Rect* drawRect = &r ; + + list = (wxListBox*) GetControlReference( (ControlRef) GetListRefCon(listHandle) ); + if ( list == NULL || list->GetHandle() == NULL || GetControlReference( ( ControlRef )list->GetHandle() ) == NULL ) return ; + // the bounds passed in are not correct, adjust the right border + int x = 0 , y = 0 ; + Rect bounds ; + GetControlBounds( (ControlRef) list->GetHandle() , &bounds ) ; + r.right = r.left + (bounds.right - bounds.left ) - 16 ; + GrafPtr savePort; GrafPtr grafPtr; RgnHandle savedClipRegion; @@ -104,16 +886,16 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect savedClipRegion = NewRgn(); GetClip( savedClipRegion ); - + ClipRect( drawRect ); EraseRect( drawRect ); const wxFont& font = list->GetFont(); if ( font.Ok() ) { - ::TextFont( font.GetMacFontNum() ) ; - ::TextSize( font.GetMacFontSize() ) ; - ::TextFace( font.GetMacFontStyle() ) ; + ::TextFont( font.MacGetFontNum() ) ; + ::TextSize( font.MacGetFontSize() ) ; + ::TextFace( font.MacGetFontStyle() ) ; } else { @@ -122,12 +904,12 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect ::TextFace( 0 ) ; } -#if TARGET_CARBON { Rect frame = { drawRect->top, drawRect->left + 4, drawRect->top + kwxMacListItemHeight, drawRect->right + 10000 } ; CFMutableStringRef mString = CFStringCreateMutableCopy( NULL , 0 , wxMacCFStringHolder(linetext , list->GetFont().GetEncoding()) ) ; ::TruncateThemeText( mString , kThemeCurrentPortFont, kThemeStateActive, drawRect->right - drawRect->left , truncEnd , NULL ) ; + ::DrawThemeTextBox( mString, kThemeCurrentPortFont, kThemeStateActive, @@ -135,15 +917,10 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect &frame, teJustLeft, nil ); + CFRelease( mString ) ; } -#else - { - wxCharBuffer text = linetext.mb_str( wxConvLocal) ; - MoveTo(drawRect->left + 4 , drawRect->top + 10 ); - DrawText(text, 0 , strlen(text) ); - } -#endif + // If the cell is hilited, do the hilite now. Paint the cell contents with the // appropriate QuickDraw transform mode. @@ -218,16 +995,15 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxListBoxBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) ) return false; m_noItems = 0 ; // this will be increased by our append command m_selected = 0; - Rect bounds ; - Str255 title ; - - MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ; + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; ListDefSpec listDef; listDef.defType = kListDefUserProcType; @@ -240,52 +1016,23 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, Str255 fontName ; SInt16 fontSize ; Style fontStyle ; -#if TARGET_CARBON + GetThemeFont(kThemeViewsFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; -#else - GetFontName( kFontIDMonaco , fontName ) ; - fontSize = 9 ; - fontStyle = normal ; -#endif + SetFont( wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , wxMacMakeStringFromPascal( fontName ) ) ) ; -#if TARGET_CARBON + Size asize; - CreateListBoxControl( MAC_WXHWND(parent->MacGetRootWindow()), &bounds, false, 0, 1, (style & wxLB_HSCROLL), true, + CreateListBoxControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, false, 0, 1, (style & wxLB_HSCROLL), true, kwxMacListItemHeight, kwxMacListItemHeight, false, &listDef, (ControlRef *)&m_macControl ); - GetControlData( (ControlHandle) m_macControl, kControlNoPart, kControlListBoxListHandleTag, + GetControlData( (ControlRef) m_macControl, kControlNoPart, kControlListBoxListHandleTag, sizeof(ListHandle), (Ptr) &m_macList, &asize); - SetControlReference( (ControlHandle) m_macControl, (long) this); - SetControlVisibility( (ControlHandle) m_macControl, false, false); - -#else - - long result ; - wxStAppResource resload ; - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , - (style & wxLB_HSCROLL) ? kwxMacListWithVerticalAndHorizontalScrollbar : kwxMacListWithVerticalScrollbar , - 0 , 0, kControlListBoxProc , (long) this ) ; - ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag , - sizeof( ListHandle ) , (char*) &m_macList , &result ) ; + SetControlReference( (ControlRef) m_macControl, (long) this); - HLock( (Handle) m_macList ) ; - ldefHandle ldef ; - ldef = (ldefHandle) NewHandle( sizeof(ldefRec) ) ; - if ( (**(ListHandle)m_macList).listDefProc != NULL ) - { - (**ldef).instruction = 0x4EF9; /* JMP instruction */ - (**ldef).function = (void(*)()) listDef.u.userProc; - (**(ListHandle)m_macList).listDefProc = (Handle) ldef ; - } - Point pt = (**(ListHandle)m_macList).cellSize ; - pt.v = kwxMacListItemHeight ; - LCellSize( pt , (ListHandle)m_macList ) ; - LAddColumn( 1 , 0 , (ListHandle)m_macList ) ; -#endif OptionBits options = 0; if ( style & wxLB_MULTIPLE ) { @@ -306,7 +1053,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, Append( choices[i] ) ; } - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; LSetDrawingMode( true , (ListHandle)m_macList ) ; @@ -315,15 +1062,11 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, wxListBox::~wxListBox() { + SetControlReference( (ControlRef) m_macControl , NULL ) ; FreeData() ; // avoid access during destruction - SetControlReference( (ControlHandle) m_macControl , NULL ) ; if ( m_macList ) { -#if !TARGET_CARBON - DisposeHandle( (**(ListHandle)m_macList).listDefProc ) ; - (**(ListHandle)m_macList).listDefProc = NULL ; -#endif m_macList = NULL ; } } @@ -359,7 +1102,7 @@ void wxListBox::DoSetSize(int x, int y, wxControl::DoSetSize( x , y , width , height , sizeFlags ) ; #if TARGET_CARBON Rect bounds ; - GetControlBounds( (ControlHandle) m_macControl , &bounds ) ; + GetControlBounds( (ControlRef) m_macControl , &bounds ) ; ControlRef control = GetListVerticalScrollBar( (ListHandle)m_macList ) ; if ( control ) { @@ -618,15 +1361,15 @@ wxSize wxListBox::DoGetBestSize() const int lbWidth = 100; // some defaults int lbHeight = 110; int wLine; - + { - wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ; + wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetTopLevelWindowRef() ) ) ; if ( m_font.Ok() ) { - ::TextFont( m_font.GetMacFontNum() ) ; - ::TextSize( m_font.GetMacFontSize() ) ; - ::TextFace( m_font.GetMacFontStyle() ) ; + ::TextFont( m_font.MacGetFontNum() ) ; + ::TextSize( m_font.MacGetFontSize() ) ; + ::TextFace( m_font.MacGetFontStyle() ) ; } else { @@ -666,6 +1409,7 @@ wxSize wxListBox::DoGetBestSize() const // make it too small neither lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10); } + return wxSize(lbWidth, lbHeight); } @@ -674,12 +1418,6 @@ int wxListBox::GetCount() const return m_noItems; } -void wxListBox::SetupColours() -{ - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - SetForegroundColour(GetParent()->GetForegroundColour()); -} - void wxListBox::Refresh(bool eraseBack, const wxRect *rect) { wxControl::Refresh( eraseBack , rect ) ; @@ -781,11 +1519,6 @@ bool wxListBox::MacIsSelected( int n ) const return LGetSelect( false , &cell , (ListHandle)m_macList ) ; } -void wxListBox::MacDestroy() -{ - // DisposeExtLDEFInfo( m_macList ) ; -} - int wxListBox::MacGetSelection() const { Cell cell = { 0 , 0 } ; @@ -837,7 +1570,9 @@ void wxListBox::OnSize( wxSizeEvent &event) #else pt = (**(ListHandle)m_macList).cellSize ; #endif - pt.h = m_width - 15 ; + int w, h ; + GetSize( &w , &h ) ; + pt.h = w - 15 ; LCellSize( pt , (ListHandle)m_macList ) ; } @@ -846,7 +1581,7 @@ void wxListBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart , Boolean wasDoubleClick = false ; long result ; - ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ; + ::GetControlData( (ControlRef) m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ; if ( !wasDoubleClick ) { MacDoClick() ; @@ -1021,3 +1756,4 @@ void wxListBox::OnChar(wxKeyEvent& event) } } +#endif diff --git a/src/mac/carbon/mdi.cpp b/src/mac/carbon/mdi.cpp index add9482e11..31d91ad9c8 100644 --- a/src/mac/carbon/mdi.cpp +++ b/src/mac/carbon/mdi.cpp @@ -262,9 +262,8 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; - m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; - SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ; - + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); + wxModelessWindows.Append(this); return FALSE; } diff --git a/src/mac/carbon/notebmac.cpp b/src/mac/carbon/notebmac.cpp index 9aa4fdf5b9..91c17ee434 100644 --- a/src/mac/carbon/notebmac.cpp +++ b/src/mac/carbon/notebmac.cpp @@ -58,82 +58,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) // implementation // ============================================================================ -// The Appearance Manager docs show using tab controls in either edge to edge -// mode, or inset. I think edge to edge conforms better to the other ports, -// and inset mode is better accomplished with space around the wxNotebook rather -// than within it. --Robin - -// CS : had to switch off tight spacing due to 10.3 problems -#define wxMAC_EDGE_TO_EDGE 0 - -static inline int wxMacTabMargin(long nbStyle, long side) -{ - static int tabMargin = -1; - static int otherMargin = -1; - - if ( tabMargin == -1) - { - if ( UMAHasAquaLayout() ) - { - tabMargin = 26; // From Appearance Manager docs for small tab control dimensions -#if wxMAC_EDGE_TO_EDGE - otherMargin = 0; -#else -// otherMargin = 20; - // JACS - this seems fine on 10.3; 20 is way too much - otherMargin = 8; -#endif - } - else - { - tabMargin = 30; -#if wxMAC_EDGE_TO_EDGE - otherMargin = 0; -#else - otherMargin = 16; -#endif - } - } - - // If the style matches the side asked for then return the tab margin, - // but we have to special case wxNB_TOP since it is zero... - if ( side == wxNB_TOP) - { - if ( nbStyle != 0 && nbStyle & (wxNB_LEFT|wxNB_RIGHT|wxNB_BOTTOM)) - { - return otherMargin; - } - else - { - return tabMargin; - } - } - else if ( nbStyle & side) - return tabMargin; - else - return otherMargin; -} - -static inline int wxMacTabLeftMargin(long style) -{ - return wxMacTabMargin(style, wxNB_LEFT); -} - -static inline int wxMacTabTopMargin(long style) -{ - return wxMacTabMargin(style, wxNB_TOP); -} - -static inline int wxMacTabRightMargin(long style) -{ - return wxMacTabMargin(style, wxNB_RIGHT); -} - -static inline int wxMacTabBottomMargin(long style) -{ - return wxMacTabMargin(style, wxNB_BOTTOM); -} - // ---------------------------------------------------------------------------- // wxNotebook construction // ---------------------------------------------------------------------------- @@ -141,13 +65,6 @@ static inline int wxMacTabBottomMargin(long style) // common part of all ctors void wxNotebook::Init() { - if ( UMAHasAquaLayout() ) - { - // Should these depend on wxMAC_EDGE_TO_EDGE too? - m_macHorizontalBorder = 7; - m_macVerticalBorder = 8; - } - m_nSelection = -1; } @@ -178,27 +95,40 @@ bool wxNotebook::Create(wxWindow *parent, long style, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxNotebookBase::Create(parent, id, pos, size, style, name) ) return false; - Rect bounds ; - Str255 title ; + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ; + if( bounds.right <= bounds.left ) + bounds.right = bounds.left + 100 ; + if ( bounds.bottom <= bounds.top ) + bounds.bottom = bounds.top + 100 ; - int tabstyle = kControlTabSmallNorthProc ; + UInt16 tabstyle = kControlTabDirectionNorth ; if ( HasFlag(wxNB_LEFT) ) - tabstyle = kControlTabSmallWestProc ; + tabstyle = kControlTabDirectionWest ; else if ( HasFlag( wxNB_RIGHT ) ) - tabstyle = kControlTabSmallEastProc ; + tabstyle = kControlTabDirectionEast ; else if ( HasFlag( wxNB_BOTTOM ) ) - tabstyle = kControlTabSmallSouthProc ; - - - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, - tabstyle , (long) this ) ; + tabstyle = kControlTabDirectionSouth ; + + ControlTabSize tabsize = kControlTabSizeLarge ; + if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL ) + tabsize = kControlTabSizeSmall ; + else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI ) + { + if (UMAGetSystemVersion() >= 0x1030 ) + tabsize = 3 ; + else + tabsize = kControlSizeSmall; + } - MacPostControlCreate() ; + ::CreateTabsControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , tabsize , tabstyle, 0, NULL, (ControlRef*) &m_macControl); + + MacPostControlCreate(pos,size) ; return TRUE ; } @@ -228,13 +158,7 @@ void wxNotebook::SetPageSize(const wxSize& size) wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const { - wxSize sizeTotal = sizePage; - sizeTotal.x += 2 * m_macHorizontalBorder + wxMacTabLeftMargin(GetWindowStyle()) + - wxMacTabRightMargin(GetWindowStyle()) ; - sizeTotal.y += 2 * m_macVerticalBorder + wxMacTabTopMargin(GetWindowStyle()) + - wxMacTabBottomMargin(GetWindowStyle()) ; - - return sizeTotal; + return DoGetSizeFromClientSize( sizePage ) ; } wxSize wxNotebook::DoGetBestSize() const @@ -405,7 +329,7 @@ bool wxNotebook::InsertPage(size_t nPage, { m_nSelection++; // while this still is the same page showing, we need to update the tabs - SetControl32BitValue( (ControlHandle) m_macControl , m_nSelection + 1 ) ; + SetControl32BitValue( (ControlRef) m_macControl , m_nSelection + 1 ) ; } // some page should be selected: either this one or the first one if there @@ -429,7 +353,7 @@ bool wxNotebook::InsertPage(size_t nPage, */ void wxNotebook::MacSetupTabs() { - SetControl32BitMaximum( (ControlHandle) m_macControl , GetPageCount() ) ; + SetControl32BitMaximum( (ControlRef) m_macControl , GetPageCount() ) ; wxNotebookPage *page; ControlTabInfoRec info; @@ -442,9 +366,9 @@ void wxNotebook::MacSetupTabs() info.iconSuiteID = 0; wxMacStringToPascal( page->GetLabel() , info.name ) ; - SetControlData( (ControlHandle) m_macControl, ii+1, kControlTabInfoTag, + SetControlData( (ControlRef) m_macControl, ii+1, kControlTabInfoTag, sizeof( ControlTabInfoRec) , (char*) &info ) ; - SetTabEnabled( (ControlHandle) m_macControl , ii+1 , true ) ; + SetTabEnabled( (ControlRef) m_macControl , ii+1 , true ) ; #if TARGET_CARBON if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 ) { @@ -473,7 +397,7 @@ void wxNotebook::MacSetupTabs() wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ; info.contentType = kControlContentIconRef ; info.u.iconRef = iconRef ; - SetControlData( (ControlHandle) m_macControl, ii+1,kControlTabImageContentTag, + SetControlData( (ControlRef) m_macControl, ii+1,kControlTabImageContentTag, sizeof( info ), (Ptr)&info ); wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ; if ( UMAGetSystemVersion() < 0x1030 ) @@ -488,21 +412,14 @@ void wxNotebook::MacSetupTabs() #endif } Rect bounds; - GetControlBounds((ControlHandle)m_macControl, &bounds); - InvalWindowRect((WindowRef)MacGetRootWindow(), &bounds); + UMAGetControlBoundsInWindowCoords((ControlRef)m_macControl, &bounds); + InvalWindowRect((WindowRef)MacGetTopLevelWindowRef(), &bounds); } wxRect wxNotebook::GetPageRect() const { - // fit the notebook page to the tab control's display area - int w, h; - GetSize(&w, &h); - - return wxRect( - wxMacTabLeftMargin(GetWindowStyle()) + m_macHorizontalBorder, - wxMacTabTopMargin(GetWindowStyle()) + m_macVerticalBorder, - w - wxMacTabLeftMargin(GetWindowStyle()) - wxMacTabRightMargin(GetWindowStyle()) - 2*m_macHorizontalBorder, - h - wxMacTabTopMargin(GetWindowStyle()) - wxMacTabBottomMargin(GetWindowStyle()) - 2*m_macVerticalBorder); + wxSize size = GetClientSize() ; + return wxRect( 0 , 0 , size.x , size.y ) ; } // ---------------------------------------------------------------------------- // wxNotebook callbacks @@ -647,13 +564,13 @@ void wxNotebook::ChangePage(int nOldSel, int nSel) } m_nSelection = nSel; - SetControl32BitValue( (ControlHandle) m_macControl , m_nSelection + 1 ) ; + SetControl32BitValue( (ControlRef) m_macControl , m_nSelection + 1 ) ; } void wxNotebook::OnMouse( wxMouseEvent &event ) { - if ( (ControlHandle) m_macControl == NULL ) + if ( (ControlRef) m_macControl == NULL ) { event.Skip() ; return ; @@ -664,9 +581,17 @@ void wxNotebook::OnMouse( wxMouseEvent &event ) int x = event.m_x ; int y = event.m_y ; - MacClientToRootWindow( &x , &y ) ; +#if TARGET_API_MAC_ISX + // OS Needs it in window not client coordinates + wxPoint origin = GetClientAreaOrigin() ; + x += origin.x ; + y += origin.y ; +#else + // OS Needs it in tlw content area coordinates + MacClientToRootWindow( &x , &y ) ; +#endif - ControlHandle control ; + ControlRef control ; Point localwhere ; SInt16 controlpart ; @@ -690,7 +615,7 @@ void wxNotebook::OnMouse( wxMouseEvent &event ) if ( event.m_metaDown ) modifiers |= cmdKey ; - control = (ControlHandle) m_macControl ; + control = (ControlRef) m_macControl ; if ( control && ::IsControlActive( control ) ) { { @@ -720,7 +645,7 @@ void wxNotebook::OnMouse( wxMouseEvent &event ) void wxNotebook::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) { #if 0 - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControl32BitValue((ControlHandle)m_macControl) - 1, m_nSelection); + wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId , ::GetControl32BitValue((ControlRef)m_macControl) - 1, m_nSelection); event.SetEventObject(this); ProcessEvent(event); diff --git a/src/mac/carbon/radiobox.cpp b/src/mac/carbon/radiobox.cpp index 103d68ca44..83bd0a1f78 100644 --- a/src/mac/carbon/radiobox.cpp +++ b/src/mac/carbon/radiobox.cpp @@ -112,6 +112,8 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, int majorDim, long style, const wxValidator& val, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxControl::Create(parent, id, pos, size, style, val, name) ) return false; @@ -127,12 +129,15 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, m_majorDim = majorDim ; - Rect bounds ; - Str255 title ; - - MacPreControlCreate( parent , id , wxStripMenuCodes(label) , pos , size ,style, val , name , &bounds , title ) ; - - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, + m_label = label ; + + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + if( bounds.right <= bounds.left ) + bounds.right = bounds.left + 100 ; + if ( bounds.bottom <= bounds.top ) + bounds.bottom = bounds.top + 100 ; + + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, kControlGroupBoxTextTitleProc , (long) this ) ; for (i = 0; i < n; i++) @@ -152,7 +157,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, } SetSelection(0); - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; return TRUE; } @@ -421,8 +426,8 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) int eachWidth[128],eachHeight[128]; int totWidth,totHeight; - SetFont(GetParent()->GetFont()); GetTextExtent(wxT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &charWidth, &charHeight); + charWidth/=52; maxWidth=-1; @@ -436,14 +441,16 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (maxHeight= 0x1030 ) - { - //need to add a few more pixels for the top border on panther - y_start = y_start + 5; //how many exactly should this be to meet the HIG? - } + x_start = 0; + y_start = 0 ; + x_offset = x_start; y_offset = y_start; @@ -510,6 +513,7 @@ wxSize wxRadioBox::DoGetBestSize() const wxFont font = GetParent()->GetFont(); GetTextExtent(wxT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), &charWidth, &charHeight, NULL, NULL, &font); + charWidth /= 52; maxWidth = -1; @@ -517,21 +521,20 @@ wxSize wxRadioBox::DoGetBestSize() const for (int i = 0 ; i < m_noItems; i++) { - GetTextExtent(GetString(i), &eachWidth, &eachHeight); + GetTextExtent(GetString(i), &eachWidth, &eachHeight,NULL, NULL, &font); eachWidth = (int)(eachWidth + RADIO_SIZE) ; eachHeight = (int)((3 * eachHeight) / 2); if (maxWidth < eachWidth) maxWidth = eachWidth; if (maxHeight < eachHeight) maxHeight = eachHeight; } - totHeight = GetRowCount() * (maxHeight + charHeight/2) + charHeight ; - totWidth = GetColumnCount() * (maxWidth + charWidth) + charWidth; + totHeight = GetRowCount() * (maxHeight ) ; + totWidth = GetColumnCount() * (maxWidth + charWidth) ; + + wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth , totHeight ) ) ; + totWidth = sz.x ; + totHeight = sz.y ; - if ( UMAGetSystemVersion() >= 0x1030 ) - { - //need to add a few more pixels for the static boxborder on panther - totHeight = totHeight + 10; //how many exactly should this be to meet the HIG? - } // handle radio box title as well GetTextExtent(GetTitle(), &eachWidth, NULL); eachWidth = (int)(eachWidth + RADIO_SIZE) + 3 * charWidth ; diff --git a/src/mac/carbon/radiobut.cpp b/src/mac/carbon/radiobut.cpp index 991c8be68f..c7101f60ad 100644 --- a/src/mac/carbon/radiobut.cpp +++ b/src/mac/carbon/radiobut.cpp @@ -30,18 +30,19 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) return false; - - Rect bounds ; - Str255 title ; - MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; + m_label = label ; + + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, kControlRadioButtonProc , (long) this ) ; - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; m_cycle = this ; @@ -72,10 +73,10 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, void wxRadioButton::SetValue(bool val) { wxRadioButton *cycle; - if ( GetControl32BitValue( (ControlHandle) m_macControl ) == val ) + if ( GetControl32BitValue( (ControlRef) m_macControl ) == val ) return ; - ::SetControl32BitValue( (ControlHandle) m_macControl , val ) ; + ::SetControl32BitValue( (ControlRef) m_macControl , val ) ; if (val) { cycle=this->NextInCycle(); @@ -91,7 +92,7 @@ void wxRadioButton::SetValue(bool val) bool wxRadioButton::GetValue() const { - return ::GetControl32BitValue( (ControlHandle) m_macControl ) ; + return ::GetControl32BitValue( (ControlRef) m_macControl ) ; } void wxRadioButton::Command (wxCommandEvent & event) diff --git a/src/mac/carbon/scrolbar.cpp b/src/mac/carbon/scrolbar.cpp index 3b08c25ecc..978292c9ca 100644 --- a/src/mac/carbon/scrolbar.cpp +++ b/src/mac/carbon/scrolbar.cpp @@ -40,23 +40,21 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) return FALSE; - Rect bounds ; - Str255 title ; - - MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ; - - m_macControl = ::NewControl(MAC_WXHWND(parent->MacGetRootWindow()) , - &bounds , title , false , 0 , 0 , 100, + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + m_macControl = (WXWidget) ::NewControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , + &bounds , "\p" , true , 0 , 0 , 100, kControlScrollBarLiveProc , (long) this) ; - wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; + wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; - ::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ; + ::SetControlAction( (ControlRef) m_macControl , wxMacLiveScrollbarActionUPP ) ; - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; return TRUE; } @@ -67,12 +65,12 @@ wxScrollBar::~wxScrollBar() void wxScrollBar::SetThumbPosition(int viewStart) { - ::SetControl32BitValue( (ControlHandle) m_macControl , viewStart ) ; + ::SetControl32BitValue( (ControlRef) m_macControl , viewStart ) ; } int wxScrollBar::GetThumbPosition() const { - return ::GetControl32BitValue( (ControlHandle) m_macControl ) ; + return ::GetControl32BitValue( (ControlRef) m_macControl ) ; } void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, @@ -84,15 +82,15 @@ void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageS int range1 = wxMax((m_objectSize - m_viewSize), 0) ; - SetControl32BitMaximum( (ControlHandle) m_macControl , range1 ) ; - SetControl32BitMinimum( (ControlHandle) m_macControl , 0 ) ; - SetControl32BitValue( (ControlHandle) m_macControl , position ) ; + SetControl32BitMaximum( (ControlRef) m_macControl , range1 ) ; + SetControl32BitMinimum( (ControlRef) m_macControl , 0 ) ; + SetControl32BitValue( (ControlRef) m_macControl , position ) ; if ( UMAGetAppearanceVersion() >= 0x0110 ) { if ( SetControlViewSize != (void*) kUnresolvedCFragSymbolAddress ) { - SetControlViewSize( (ControlHandle) m_macControl , m_viewSize ) ; + SetControlViewSize( (ControlRef) m_macControl , m_viewSize ) ; } } if ( refresh ) @@ -108,12 +106,12 @@ void wxScrollBar::Command(wxCommandEvent& event) void wxScrollBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) { - if ( (ControlHandle) m_macControl == NULL ) + if ( (ControlRef) m_macControl == NULL ) return ; - int position = GetControl32BitValue( (ControlHandle) m_macControl) ; - int minPos = GetControl32BitMinimum( (ControlHandle) m_macControl) ; - int maxPos = GetControl32BitMaximum( (ControlHandle) m_macControl) ; + int position = GetControl32BitValue( (ControlRef) m_macControl) ; + int minPos = GetControl32BitMinimum( (ControlRef) m_macControl) ; + int maxPos = GetControl32BitMaximum( (ControlRef) m_macControl) ; wxEventType scrollEvent = wxEVT_NULL; int nScrollInc = 0; diff --git a/src/mac/carbon/slider.cpp b/src/mac/carbon/slider.cpp index 4bd4bab532..0ee335f027 100644 --- a/src/mac/carbon/slider.cpp +++ b/src/mac/carbon/slider.cpp @@ -57,11 +57,11 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) return false; - Rect bounds ; - Str255 title ; SInt16 procID; m_macMinimumStatic = NULL ; @@ -77,8 +77,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, m_pageSize = (int)((maxValue-minValue)/10); - MacPreControlCreate( parent, id, wxEmptyString, pos, size, style, - validator, name, &bounds, title ); + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; procID = kControlSliderProc + kControlSliderLiveFeedback; if(style & wxSL_AUTOTICKS) { @@ -86,28 +85,13 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, } - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()), &bounds, title, false, + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, "\p", true, value, minValue, maxValue, procID, (long) this); - wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; - - ::SetControlAction( (ControlHandle) m_macControl , wxMacLiveScrollbarActionUPP ) ; - - if(style & wxSL_LABELS) - { - m_macMinimumStatic = new wxStaticText( this, -1, wxEmptyString ); - m_macMaximumStatic = new wxStaticText( this, -1, wxEmptyString ); - m_macValueStatic = new wxStaticText( this, -1, wxEmptyString ); - SetRange(minValue, maxValue); - SetValue(value); - } - - else { - m_macMinimumStatic = NULL ; - m_macMaximumStatic = NULL ; - m_macValueStatic = NULL ; - } + wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; + ::SetControlAction( (ControlRef) m_macControl , wxMacLiveScrollbarActionUPP ) ; + if(style & wxSL_VERTICAL) { SetSizeHints(10, -1, 10, -1); // Forces SetSize to use the proper width } @@ -118,18 +102,30 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, // proper dimensions, it also means other people cannot bugger the slider with // other values - MacPostControlCreate() ; + if(style & wxSL_LABELS) + { + m_macMinimumStatic = new wxStaticText( parent, -1, wxEmptyString ); + m_macMaximumStatic = new wxStaticText( parent, -1, wxEmptyString ); + m_macValueStatic = new wxStaticText( parent, -1, wxEmptyString ); + SetRange(minValue, maxValue); + SetValue(value); + } + + MacPostControlCreate(pos,size) ; return true; } wxSlider::~wxSlider() { + delete m_macMinimumStatic ; + delete m_macMaximumStatic ; + delete m_macValueStatic ; } int wxSlider::GetValue() const { - return GetControl32BitValue( (ControlHandle) m_macControl) ; + return GetControl32BitValue( (ControlRef) m_macControl) ; } void wxSlider::SetValue(int value) @@ -138,7 +134,7 @@ void wxSlider::SetValue(int value) valuestring.Printf( wxT("%d") , value ) ; if ( m_macValueStatic ) m_macValueStatic->SetLabel( valuestring ) ; - SetControl32BitValue( (ControlHandle) m_macControl , value ) ; + SetControl32BitValue( (ControlRef) m_macControl , value ) ; } void wxSlider::SetRange(int minValue, int maxValue) @@ -148,8 +144,8 @@ void wxSlider::SetRange(int minValue, int maxValue) m_rangeMin = minValue; m_rangeMax = maxValue; - SetControl32BitMinimum( (ControlHandle) m_macControl, m_rangeMin); - SetControl32BitMaximum( (ControlHandle) m_macControl, m_rangeMax); + SetControl32BitMinimum( (ControlRef) m_macControl, m_rangeMin); + SetControl32BitMaximum( (ControlRef) m_macControl, m_rangeMax); if(m_macMinimumStatic) { value.Printf(wxT("%d"), m_rangeMin); @@ -243,7 +239,7 @@ void wxSlider::Command (wxCommandEvent & event) void wxSlider::MacHandleControlClick( WXWidget control , wxInt16 controlpart, bool mouseStillDown ) { - SInt16 value = ::GetControl32BitValue( (ControlHandle) m_macControl ) ; + SInt16 value = ::GetControl32BitValue( (ControlRef) m_macControl ) ; SetValue( value ) ; @@ -334,26 +330,8 @@ wxSize wxSlider::DoGetBestSize() const return size; } -void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags) -{ - wxControl::DoSetSize( x, y , width , height ,sizeFlags ) ; -} - -void wxSlider::MacUpdateDimensions() +void wxSlider::DoSetSize(int x, int y, int w, int h, int sizeFlags) { - // actually in the current systems this should never be possible, but later reparenting - // may become a reality - - if ( (ControlHandle) m_macControl == NULL ) - return ; - - if ( GetParent() == NULL ) - return ; - - WindowRef rootwindow = (WindowRef) MacGetRootWindow() ; - if ( rootwindow == NULL ) - return ; - int xborder, yborder; int minValWidth, maxValWidth, textwidth, textheight; int sliderBreadth; @@ -388,43 +366,30 @@ void wxSlider::MacUpdateDimensions() if(GetWindowStyle() & wxSL_VERTICAL) { - m_macMinimumStatic->Move(sliderBreadth + wxSLIDER_BORDERTEXT, - m_height - yborder - textheight); - m_macMaximumStatic->Move(sliderBreadth + wxSLIDER_BORDERTEXT, 0); - m_macValueStatic->Move(0, m_height - textheight); + + if ( m_macMinimumStatic ) + m_macMinimumStatic->Move(x + sliderBreadth + wxSLIDER_BORDERTEXT, + y + h - yborder - textheight); + if ( m_macMaximumStatic ) + m_macMaximumStatic->Move(x + sliderBreadth + wxSLIDER_BORDERTEXT, y + 0); + if ( m_macValueStatic ) + m_macValueStatic->Move(0, y + h - textheight); + h = h - yborder ; } else { - m_macMinimumStatic->Move(0, sliderBreadth + wxSLIDER_BORDERTEXT); - m_macMaximumStatic->Move(m_width - xborder - maxValWidth / 2, - sliderBreadth + wxSLIDER_BORDERTEXT); - m_macValueStatic->Move(m_width - textwidth, 0); + if ( m_macMinimumStatic ) + m_macMinimumStatic->Move(x + 0, y + sliderBreadth + wxSLIDER_BORDERTEXT); + if ( m_macMaximumStatic ) + m_macMaximumStatic->Move(x + w - xborder - maxValWidth / 2, + y + sliderBreadth + wxSLIDER_BORDERTEXT); + if ( m_macValueStatic ) + m_macValueStatic->Move(x + w - textwidth, y + 0); + w = w - xborder ; } } - Rect oldBounds ; - GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ; - - int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ; - int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ; - int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder - xborder ; - int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder - yborder ; - - GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ; - bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ; - bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ; - if ( doMove || doResize ) - { - InvalWindowRect( rootwindow, &oldBounds ) ; - if ( doMove ) - { - UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ; - } - if ( doResize ) - { - UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ; - } - } + wxControl::DoSetSize( x, y , w , h ,sizeFlags ) ; } void wxSlider::DoMoveWindow(int x, int y, int width, int height) diff --git a/src/mac/carbon/spinbutt.cpp b/src/mac/carbon/spinbutt.cpp index f8dcca8bd9..c9140dc626 100644 --- a/src/mac/carbon/spinbutt.cpp +++ b/src/mac/carbon/spinbutt.cpp @@ -38,6 +38,8 @@ wxSpinButton::wxSpinButton() bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxSpinButtonBase::Create(parent, id, pos, size, style, wxDefaultValidator, name) ) return false; @@ -48,17 +50,14 @@ bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, c if (!parent) return FALSE; - Rect bounds ; - Str255 title ; - - MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style,*( (wxValidator*) NULL ) , name , &bounds , title ) ; + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 100, + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 100, kControlLittleArrowsProc , (long) this ) ; - wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; + wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; return TRUE; } @@ -94,8 +93,8 @@ void wxSpinButton::SetRange(int minVal, int maxVal) { m_min = minVal; m_max = maxVal; - SetControl32BitMaximum( (ControlHandle) m_macControl , maxVal ) ; - SetControl32BitMinimum((ControlHandle) m_macControl , minVal ) ; + SetControl32BitMaximum( (ControlRef) m_macControl , maxVal ) ; + SetControl32BitMinimum((ControlRef) m_macControl , minVal ) ; } void wxSpinButton::MacHandleValueChanged( int inc ) @@ -138,7 +137,7 @@ void wxSpinButton::MacHandleValueChanged( int inc ) { m_value = oldValue ; } - SetControl32BitValue( (ControlHandle) m_macControl , m_value ) ; + SetControl32BitValue( (ControlRef) m_macControl , m_value ) ; /* always send a thumbtrack event */ if (scrollEvent != wxEVT_SCROLL_THUMBTRACK) @@ -153,7 +152,7 @@ void wxSpinButton::MacHandleValueChanged( int inc ) void wxSpinButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) { - if ( (ControlHandle) m_macControl == NULL ) + if ( (ControlRef) m_macControl == NULL ) return ; int nScrollInc = 0; diff --git a/src/mac/carbon/statbox.cpp b/src/mac/carbon/statbox.cpp index 13c7daf669..2f6068ce96 100644 --- a/src/mac/carbon/statbox.cpp +++ b/src/mac/carbon/statbox.cpp @@ -20,11 +20,6 @@ #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl) - -BEGIN_EVENT_TABLE(wxStaticBox, wxControl) - EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground) -END_EVENT_TABLE() - #endif /* @@ -38,19 +33,20 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name) ) return false; - Rect bounds ; - Str255 title ; - - MacPreControlCreate( parent , id , label , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ; + m_label = label ; + + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, kControlGroupBoxTextTitleProc , (long) this ) ; - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; return TRUE; } diff --git a/src/mac/carbon/statbrma.cpp b/src/mac/carbon/statbrma.cpp index b2dba2135d..8f3562c074 100644 --- a/src/mac/carbon/statbrma.cpp +++ b/src/mac/carbon/statbrma.cpp @@ -50,17 +50,23 @@ bool wxStatusBarMac::Create(wxWindow *parent, wxWindowID id, long style , const wxString& name) { - return wxStatusBarGeneric::Create( parent , id , style , name ) ; + if( !wxStatusBarGeneric::Create( parent , id , style , name ) ) + return FALSE ; + + m_macBackgroundBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; + + return TRUE ; } void wxStatusBarMac::DrawFieldText(wxDC& dc, int i) { int leftMargin = 2; - + int w, h ; + GetSize( &w , &h ) ; wxRect rect; GetFieldRect(i, rect); - if ( !IsWindowHilited( MAC_WXHWND( MacGetRootWindow() ) ) ) + if ( !IsWindowHilited( MAC_WXHWND( MacGetTopLevelWindowRef() ) ) ) { dc.SetTextForeground( wxColour( 0x80 , 0x80 , 0x80 ) ) ; } @@ -74,7 +80,7 @@ void wxStatusBarMac::DrawFieldText(wxDC& dc, int i) int xpos = rect.x + leftMargin + 1 ; int ypos = 1 ; - dc.SetClippingRegion(rect.x, 0, rect.width, m_height); + dc.SetClippingRegion(rect.x, 0, rect.width, h); dc.DrawText(text, xpos, ypos); @@ -94,8 +100,10 @@ void wxStatusBarMac::SetStatusText(const wxString& text, int number) m_statusStrings[number] = text; wxRect rect; GetFieldRect(number, rect); + int w, h ; + GetSize( &w , &h ) ; rect.y=0; - rect.height = m_height ; + rect.height = h ; Refresh( TRUE , &rect ) ; Update(); } @@ -107,8 +115,10 @@ void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event) ) int major,minor; wxGetOsVersion( &major, &minor ); + int w, h ; + GetSize( &w , &h ) ; - if ( IsWindowHilited( MAC_WXHWND( MacGetRootWindow() ) ) ) + if ( IsWindowHilited( MAC_WXHWND( MacGetTopLevelWindowRef() ) ) ) { wxPen white( wxWHITE , 1 , wxSOLID ) ; if (major >= 10) @@ -122,10 +132,10 @@ void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event) ) dc.SetPen(black); } dc.DrawLine(0, 0 , - m_width , 0); + w , 0); dc.SetPen(white); dc.DrawLine(0, 1 , - m_width , 1); + w , 1); } else { @@ -136,7 +146,7 @@ void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event) ) dc.SetPen(wxPen(wxColour(0x80,0x80,0x80),1,wxSOLID)); dc.DrawLine(0, 0 , - m_width , 0); + w , 0); } int i; @@ -147,9 +157,3 @@ void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event) ) for ( i = 0; i < m_nFields; i ++ ) DrawField(dc, i); } - -void wxStatusBarMac::MacSuperEnabled( bool enabled ) -{ - Refresh(FALSE) ; - wxWindow::MacSuperEnabled( enabled ) ; -} diff --git a/src/mac/carbon/statlmac.cpp b/src/mac/carbon/statlmac.cpp index a7a116ba57..938aae0715 100644 --- a/src/mac/carbon/statlmac.cpp +++ b/src/mac/carbon/statlmac.cpp @@ -49,19 +49,17 @@ bool wxStaticLine::Create( wxWindow *parent, long style, const wxString &name) { + m_macIsUserPane = FALSE ; + if ( !wxStaticLineBase::Create(parent, id, pos, size, style, wxDefaultValidator, name) ) return false; - Rect bounds ; - Str255 title ; - - MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ; - - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, kControlSeparatorLineProc , (long) this ) ; - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; return TRUE; } diff --git a/src/mac/carbon/stattext.cpp b/src/mac/carbon/stattext.cpp index 1c0facdbf7..8437b9d5d1 100644 --- a/src/mac/carbon/stattext.cpp +++ b/src/mac/carbon/stattext.cpp @@ -30,10 +30,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) #include "wx/mac/uma.h" -BEGIN_EVENT_TABLE(wxStaticText, wxStaticTextBase) - EVT_PAINT(wxStaticText::OnPaint) -END_EVENT_TABLE() - bool wxStaticText::Create(wxWindow *parent, wxWindowID id, const wxString& label, const wxPoint& pos, @@ -41,6 +37,8 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name) { + m_macIsUserPane = FALSE ; + m_label = wxStripMenuCodes(label) ; if ( !wxControl::Create( parent, id, pos, size, style, @@ -49,196 +47,43 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, return false; } - SetBestSize( size ) ; - - return true; -} - -const wxString punct = wxT(" ,.-;:!?"); - -void wxStaticText::DrawParagraph(wxDC &dc, wxString paragraph, int &y) -{ - long width, height ; - - if (paragraph.Length() == 0) - { - // empty line - dc.GetTextExtent( wxT("H"), &width, &height ); - y += height; - - return; - } + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ; + verify_noerr(CreateStaticTextControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, str , + NULL , (ControlRef*)&m_macControl ) ) ; - int x = 0 ; + MacPostControlCreate(pos,size) ; - bool linedrawn = true; - while( paragraph.Length() > 0 ) - { - dc.GetTextExtent( paragraph , &width , &height ) ; - - if ( width > m_width ) - { - for ( size_t p = paragraph.Length() - 1 ; p > 0 ; --p ) - { - if ((punct.Find(paragraph[p]) != wxNOT_FOUND) || !linedrawn) - { - int blank = (paragraph[p] == ' ') ? 0 : 1; - - dc.GetTextExtent( paragraph.Left(p + blank) , &width , &height ) ; - - if ( width <= m_width ) - { - int pos = x ; - if ( HasFlag( wxALIGN_CENTER ) ) - { - pos += ( m_width - width ) / 2 ; - } - else if ( HasFlag( wxALIGN_RIGHT ) ) - { - pos += ( m_width - width ) ; - } - - dc.DrawText( paragraph.Left(p + blank), pos , y) ; - y += height ; - paragraph = paragraph.Mid(p+1) ; - linedrawn = true; - break ; - } - } - } - - linedrawn = false; - } - else - { - int pos = x ; - if ( HasFlag( wxALIGN_CENTER ) ) - { - pos += ( m_width - width ) / 2 ; - } - else if ( HasFlag( wxALIGN_RIGHT ) ) - { - pos += ( m_width - width ) ; - } - - dc.DrawText( paragraph, pos , y) ; - paragraph=wxEmptyString; - y += height ; - } - } + return true; } -void wxStaticText::OnDraw( wxDC &dc ) +wxSize wxStaticText::DoGetBestSize() const { - if (m_width <= 0 || m_height <= 0) - return; - /* - dc.Clear() ; - wxRect rect(0,0,m_width,m_height) ; - dc.SetFont(*wxSMALL_FONT) ; - - dc.DrawRectangle(rect) ; - */ - if ( !IsWindowHilited( (WindowRef) MacGetRootWindow() ) && - ( GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) - || GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) ) - { - dc.SetTextForeground( wxColour( 0x80 , 0x80 , 0x80 ) ) ; - } - else - { - dc.SetTextForeground( GetForegroundColour() ) ; - } + ControlFontStyleRec controlFont ; + Size outSize ; + verify_noerr( GetControlData( (ControlRef) m_macControl , kControlEntireControl , kControlFontStyleTag , sizeof(controlFont) , &controlFont , &outSize ) ) ; - wxString paragraph; - size_t i = 0 ; - wxString text = m_label; - int y = 0 ; - while (i < text.Length()) - { - - if (text[i] == 13 || text[i] == 10) - { - DrawParagraph(dc, paragraph,y); - paragraph = wxEmptyString ; - } - else - { - paragraph += text[i]; - } - ++i; - } - if (paragraph.Length() > 0) - DrawParagraph(dc, paragraph,y); -} + Point bounds ; + SInt16 baseline ; + wxMacCFStringHolder str(m_label , m_font.GetEncoding() ) ; + verify_noerr( GetThemeTextDimensions( str , m_font.MacGetThemeFontID() , kThemeStateActive , false , &bounds , &baseline ) ) ; -void wxStaticText::OnPaint( wxPaintEvent & WXUNUSED(event) ) -{ - wxPaintDC dc(this); - OnDraw( dc ) ; + return wxSize(bounds.h, bounds.v); } -wxSize wxStaticText::DoGetBestSize() const +void wxStaticText::SetLabel(const wxString& st ) { - int widthTextMax = 0, widthLine, - heightTextTotal = 0, heightLineDefault = 0, heightLine = 0; - - wxString curLine; - for ( const wxChar *pc = m_label; ; pc++ ) - { - if ( *pc == wxT('\n') || *pc == wxT('\r') || *pc == wxT('\0') ) - { - if ( !curLine ) - { - // we can't use GetTextExtent - it will return 0 for both width - // and height and an empty line should count in height - // calculation - if ( !heightLineDefault ) - heightLineDefault = heightLine; - if ( !heightLineDefault ) - GetTextExtent(_T("W"), NULL, &heightLineDefault); - - heightTextTotal += heightLineDefault; - - heightTextTotal++; // FIXME: why is this necessary? - } - else - { - GetTextExtent(curLine, &widthLine, &heightLine); - if ( widthLine > widthTextMax ) - widthTextMax = widthLine; - heightTextTotal += heightLine; - - heightTextTotal++; // FIXME: why is this necessary? - } - if ( *pc == wxT('\n') || *pc == wxT('\r')) { - curLine.Empty(); - } - else { - // the end of string - break; - } - } - else { - curLine += *pc; - } - } - - return wxSize(widthTextMax, heightTextTotal); -} + m_label = wxStripMenuCodes(st) ; + + wxMacCFStringHolder str(m_label,m_font.GetEncoding() ) ; + CFStringRef ref = str ; + SetControlData( (ControlRef) m_macControl, kControlEntireControl , kControlStaticTextCFStringTag, sizeof( CFStringRef ), + &ref ); -void wxStaticText::SetLabel(const wxString& st ) -{ - SetTitle( st ) ; - m_label = st ; if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) - { - // temporary fix until layout measurement and drawing are in synch again - Refresh() ; SetSize( GetBestSize() ) ; - } - Refresh() ; + Update() ; } @@ -248,14 +93,8 @@ bool wxStaticText::SetFont(const wxFont& font) if ( ret ) { - // adjust the size of the window to fit to the label unless autoresizing is - // disabled if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) - { - // temporary fix until layout measurement and drawing are in synch again - Refresh() ; SetSize( GetBestSize() ); - } } return ret; diff --git a/src/mac/carbon/tabctrl.cpp b/src/mac/carbon/tabctrl.cpp index f879b78447..ab984484fd 100644 --- a/src/mac/carbon/tabctrl.cpp +++ b/src/mac/carbon/tabctrl.cpp @@ -34,21 +34,19 @@ wxTabCtrl::wxTabCtrl() bool wxTabCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name) ) return false; - Rect bounds ; - Str255 title ; - m_imageList = NULL; - MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ; - - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1, kControlTabSmallProc , (long) this ) ; - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; return TRUE ; } diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index b937a08a1c..ffd659b5eb 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -62,8 +62,6 @@ #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL -extern wxControl *wxFindControlFromMacControl(ControlHandle inControl ) ; - // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have @@ -75,45 +73,20 @@ extern wxControl *wxFindControlFromMacControl(ControlHandle inControl ) ; in the text area of our control */ #define kmUPTextPart 1 -/* kmUPScrollPart is the part code we return to indicate the user has clicked - in the scroll bar part of the control. */ -#define kmUPScrollPart 2 - /* routines for using existing user pane controls. These routines are useful for cases where you would like to use an existing user pane control in, say, a dialog window as a scrolling text edit field.*/ -/* mUPOpenControl initializes a user pane control so it will be drawn - and will behave as a scrolling text edit field inside of a window. - This routine performs all of the initialization steps necessary, - except it does not create the user pane control itself. theControl - should refer to a user pane control that you have either created - yourself or extracted from a dialog's control heirarchy using - the GetDialogItemAsControl routine. */ -OSStatus mUPOpenControl(ControlHandle theControl, long wxStyle); - /* Utility Routines */ -enum { - kShiftKeyCode = 56 -}; - /* kUserClickedToFocusPart is a part code we pass to the SetKeyboardFocus routine. In our focus switching routine this part code is understood as meaning 'the user has clicked in the control and we need to switch the current focus to ourselves before we can continue'. */ #define kUserClickedToFocusPart 100 - -/* kmUPClickScrollDelayTicks is a time measurement in ticks used to - slow the speed of 'auto scrolling' inside of our clickloop routine. - This value prevents the text from wizzzzzing by while the mouse - is being held down inside of the text area. */ -#define kmUPClickScrollDelayTicks 3 - - /* STPTextPaneVars is a structure used for storing the the mUP Control's internal variables and state information. A handle to this record is stored in the pane control's reference value field using the @@ -123,25 +96,37 @@ typedef struct { /* OS records referenced */ TXNObject fTXNRec; /* the txn record */ TXNFrameID fTXNFrame; /* the txn frame ID */ - ControlHandle fUserPaneRec; /* handle to the user pane control */ + ControlRef fUserPaneRec; /* handle to the user pane control */ WindowPtr fOwner; /* window containing control */ GrafPtr fDrawingEnvironment; /* grafport where control is drawn */ /* flags */ Boolean fInFocus; /* true while the focus rect is drawn around the control */ Boolean fIsActive; /* true while the control is drawn in the active state */ - Boolean fTEActive; /* reflects the activation state of the text edit record */ - Boolean fInDialogWindow; /* true if displayed in a dialog window */ + Boolean fTXNObjectActive; /* reflects the activation state of the text edit record */ + Boolean fFocusDrawState; /* true if focus is drawn (default: true) */ /* calculated locations */ + Rect fRBounds; /* control bounds */ Rect fRTextArea; /* area where the text is drawn */ Rect fRFocusOutline; /* rectangle used to draw the focus box */ Rect fRTextOutline; /* rectangle used to draw the border */ - RgnHandle fTextBackgroundRgn; /* background region for the text, erased before calling TEUpdate */ + RgnHandle fRTextOutlineRegion; /* background region for the text, erased before calling TEUpdate */ /* our focus advance override routine */ EventHandlerUPP handlerUPP; EventHandlerRef handlerRef; + bool fNoBorders ; bool fMultiline ; + bool fVisible ; } STPTextPaneVars; +/* mUPOpenControl initializes a user pane control so it will be drawn + and will behave as a scrolling text edit field inside of a window. + This routine performs all of the initialization steps necessary, + except it does not create the user pane control itself. theControl + should refer to a user pane control that you have either created + yourself or extracted from a dialog's control heirarchy using + the GetDialogItemAsControl routine. */ +OSStatus mUPOpenControl(STPTextPaneVars* &handle, ControlRef theControl, long wxStyle); + @@ -156,106 +141,130 @@ ControlUserPaneKeyDownUPP gTPKeyProc = NULL; ControlUserPaneActivateUPP gTPActivateProc = NULL; ControlUserPaneFocusUPP gTPFocusProc = NULL; -/* TPActivatePaneText activates or deactivates the text edit record - according to the value of setActive. The primary purpose of this - routine is to ensure each call is only made once. */ -static void TPActivatePaneText(STPTextPaneVars **tpvars, Boolean setActive) { - STPTextPaneVars *varsp; - varsp = *tpvars; - if (varsp->fTEActive != setActive) { +// one place for calculating all +static void TPCalculateBounds(STPTextPaneVars *varsp, const Rect& bounds) +{ + SetRect(&varsp->fRBounds, bounds.left, bounds.top, bounds.right, bounds.bottom); + SetRect(&varsp->fRFocusOutline, bounds.left, bounds.top, bounds.right, bounds.bottom); + // eventually make TextOutline inset 1,1 + SetRect(&varsp->fRTextOutline, bounds.left, bounds.top, bounds.right, bounds.bottom); + if ( !varsp->fNoBorders ) + { + SetRect(&varsp->fRTextArea, bounds.left + 2 , bounds.top + (varsp->fMultiline ? 0 : 2) , + bounds.right - (varsp->fMultiline ? 0 : 2), bounds.bottom - (varsp->fMultiline ? 0 : 2)); + } + else + { + SetRect(&varsp->fRTextArea, bounds.left , bounds.top , + bounds.right, bounds.bottom); + } +} + +OSStatus MLTESetObjectVisibility( STPTextPaneVars *varsp, Boolean vis , long wxStyle) +{ + OSStatus err = noErr ; +#if TARGET_API_MAC_OSX + TXNControlTag iControlTags[1] = { kTXNVisibilityTag }; + TXNControlData iControlData[1] = {{ vis }}; + err = ::TXNSetTXNObjectControls( varsp->fTXNRec, false, 1, iControlTags, iControlData ); +#endif + if ( vis ) + { + Rect bounds ; + UMAGetControlBoundsInWindowCoords( varsp->fUserPaneRec, &bounds); + TPCalculateBounds( varsp , bounds ) ; + TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top, varsp->fRTextArea.left, + varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrame); + TXNShowSelection( varsp->fTXNRec, kTXNShowStart); + } + return err ; +} + +// make sure we don't miss changes as carbon events are not available for these under classic +static void TPUpdateVisibility(ControlRef theControl) { + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return ; + + STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; - varsp->fTEActive = setActive; + Rect bounds ; + UMAGetControlBoundsInWindowCoords(theControl, &bounds); + if ( textctrl->MacIsReallyShown() != varsp->fVisible ) + { + // invalidate old position + // InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ; + varsp->fVisible = textctrl->MacIsReallyShown() ; + } + if ( !EqualRect( &bounds , &varsp->fRBounds ) ) + { + // old position + Rect oldBounds = varsp->fRBounds ; + TPCalculateBounds( varsp , bounds ) ; + // we only recalculate when visible, otherwise scrollbars get drawn at incorrect places + if ( varsp->fVisible ) + { + TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top, varsp->fRTextArea.left, + varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrame); + } + InvalWindowRect( GetControlOwner( theControl ) , &oldBounds ) ; + InvalWindowRect( GetControlOwner( theControl ) , &varsp->fRBounds ) ; + } +} - TXNActivate(varsp->fTXNRec, varsp->fTXNFrame, varsp->fTEActive); +// make correct activations +static void TPActivatePaneText(STPTextPaneVars *varsp, Boolean setActive) { + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(varsp->fUserPaneRec); + if (varsp->fTXNObjectActive != setActive && textctrl->MacIsReallyShown() ) + { + varsp->fTXNObjectActive = setActive; + TXNActivate(varsp->fTXNRec, varsp->fTXNFrame, varsp->fTXNObjectActive); if (varsp->fInFocus) - TXNFocus( varsp->fTXNRec, varsp->fTEActive); + TXNFocus( varsp->fTXNRec, varsp->fTXNObjectActive); } } +// update focus outlines +static void TPRedrawFocusOutline(STPTextPaneVars *varsp) { -/* TPFocusPaneText set the focus state for the text record. */ -static void TPFocusPaneText(STPTextPaneVars **tpvars, Boolean setFocus) { - STPTextPaneVars *varsp; - varsp = *tpvars; - if (varsp->fInFocus != setFocus) { + /* state changed */ + if (varsp->fFocusDrawState != (varsp->fIsActive && varsp->fInFocus)) + { + varsp->fFocusDrawState = (varsp->fIsActive && varsp->fInFocus); + DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fFocusDrawState); + } +} + +// update TXN focus state +static void TPFocusPaneText(STPTextPaneVars *varsp, Boolean setFocus) { + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(varsp->fUserPaneRec); + + if (varsp->fInFocus != setFocus && textctrl->MacIsReallyShown()) { varsp->fInFocus = setFocus; TXNFocus( varsp->fTXNRec, varsp->fInFocus); } } - -/* TPPaneDrawProc is called to redraw the control and for update events - referring to the control. This routine erases the text area's background, - and redraws the text. This routine assumes the scroll bar has been - redrawn by a call to DrawControls. */ +// draw the control static pascal void TPPaneDrawProc(ControlRef theControl, ControlPartCode thePart) { - STPTextPaneVars **tpvars, *varsp; - char state; - Rect bounds; /* set up our globals */ - tpvars = (STPTextPaneVars **) GetControlReference(theControl); - if (tpvars != NULL) { - state = HGetState((Handle) tpvars); - HLock((Handle) tpvars); - varsp = *tpvars; - - /* save the drawing state */ - SetPort((**tpvars).fDrawingEnvironment); - /* verify our boundary */ - GetControlBounds(theControl, &bounds); - - wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; - if ( ! EqualRect(&bounds, &varsp->fRFocusOutline) ) { - // scrollbar is on the border, we add one - Rect oldbounds = varsp->fRFocusOutline ; - InsetRect( &oldbounds , -1 , -1 ) ; - - if ( IsControlVisible( theControl ) ) - InvalWindowRect( GetControlOwner( theControl ) , &oldbounds ) ; - SetRect(&varsp->fRFocusOutline, bounds.left, bounds.top, bounds.right, bounds.bottom); - SetRect(&varsp->fRTextOutline, bounds.left, bounds.top, bounds.right, bounds.bottom); - - if (!wxFindControlFromMacControl(theControl)->HasFlag(wxNO_BORDER)) - { - SetRect(&varsp->fRTextArea, bounds.left + 2 , bounds.top + (varsp->fMultiline ? 0 : 2) , - bounds.right - (varsp->fMultiline ? 0 : 2), bounds.bottom - (varsp->fMultiline ? 0 : 2)); - } - else - { - SetRect(&varsp->fRTextArea, bounds.left , bounds.top , - bounds.right, bounds.bottom); - } - RectRgn(varsp->fTextBackgroundRgn, &varsp->fRTextOutline); - if ( IsControlVisible( theControl ) ) - TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top, varsp->fRTextArea.left, - varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrame); - else - TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top + 30000 , varsp->fRTextArea.left + 30000 , - varsp->fRTextArea.bottom + 30000 , varsp->fRTextArea.right + 30000 , varsp->fTXNFrame); - - } - - if ( IsControlVisible( theControl ) ) - { - /* update the text region */ - RGBColor white = { 65535 , 65535 , 65535 } ; - RGBBackColor( &white ) ; - EraseRgn(varsp->fTextBackgroundRgn); - TXNDraw(varsp->fTXNRec, NULL); - /* restore the drawing environment */ - /* draw the text frame and focus frame (if necessary) */ - if (!wxFindControlFromMacControl(theControl)->HasFlag(wxNO_BORDER)) - { - DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); - if ((**tpvars).fIsActive && varsp->fInFocus) - DrawThemeFocusRect(&varsp->fRFocusOutline, true); - } - /* release our globals */ - HSetState((Handle) tpvars, state); - } + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return ; + TPUpdateVisibility( theControl ) ; + + STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; + if ( textctrl->MacIsReallyShown() ) + { + wxMacWindowClipper clipper( textctrl ) ; + TXNDraw(varsp->fTXNRec, NULL); + if ( !varsp->fNoBorders ) + DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); + TPRedrawFocusOutline( varsp ) ; } + } @@ -263,22 +272,21 @@ static pascal void TPPaneDrawProc(ControlRef theControl, ControlPartCode thePart like to determine what part of the control the mouse resides over. We also call this routine from our tracking proc to determine how to handle mouse clicks. */ -static pascal ControlPartCode TPPaneHitTestProc(ControlHandle theControl, Point where) { - STPTextPaneVars **tpvars; +static pascal ControlPartCode TPPaneHitTestProc(ControlRef theControl, Point where) { ControlPartCode result; - char state; /* set up our locals and lock down our globals*/ result = 0; - tpvars = (STPTextPaneVars **) GetControlReference(theControl); - if (tpvars != NULL && IsControlVisible( theControl) ) { - state = HGetState((Handle) tpvars); - HLock((Handle) tpvars); - /* find the region where we clicked */ - if (PtInRect(where, &(**tpvars).fRTextArea)) { + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return 0 ; + TPUpdateVisibility( theControl ) ; + STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; + if (textctrl->MacIsReallyShown() ) + { + if (PtInRect(where, &varsp->fRBounds)) result = kmUPTextPart; - } else result = 0; - /* release oure globals */ - HSetState((Handle) tpvars, state); + else + result = 0; } return result; } @@ -290,45 +298,51 @@ static pascal ControlPartCode TPPaneHitTestProc(ControlHandle theControl, Point /* TPPaneTrackingProc is called when the mouse is being held down over our control. This routine handles clicks in the text area and in the scroll bar. */ -static pascal ControlPartCode TPPaneTrackingProc(ControlHandle theControl, Point startPt, ControlActionUPP actionProc) { - STPTextPaneVars **tpvars, *varsp; - char state; +static pascal ControlPartCode TPPaneTrackingProc(ControlRef theControl, Point startPt, ControlActionUPP actionProc) { + ControlPartCode partCodeResult; - /* make sure we have some variables... */ + /* make sure we have some variables... */ partCodeResult = 0; - tpvars = (STPTextPaneVars **) GetControlReference(theControl); - if (tpvars != NULL && IsControlVisible( theControl ) ) { - /* lock 'em down */ - state = HGetState((Handle) tpvars); - HLock((Handle) tpvars); - varsp = *tpvars; - /* we don't do any of these functions unless we're in focus */ + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return 0; + TPUpdateVisibility( theControl ) ; + STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; + if (textctrl->MacIsReallyShown() ) + { + /* we don't do any of these functions unless we're in focus */ if ( ! varsp->fInFocus) { WindowPtr owner; owner = GetControlOwner(theControl); ClearKeyboardFocus(owner); SetKeyboardFocus(owner, theControl, kUserClickedToFocusPart); } - /* find the location for the click */ - switch (TPPaneHitTestProc(theControl, startPt)) { + /* find the location for the click */ + // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them + if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ) + { + int x = 0 , y = 0 ; + textctrl->MacClientToRootWindow( &x , &y ) ; + startPt.h += x ; + startPt.v += y ; + } - /* handle clicks in the text part */ + switch (TPPaneHitTestProc(theControl, startPt)) + { + + /* handle clicks in the text part */ case kmUPTextPart: - { SetPort((**tpvars).fDrawingEnvironment); - wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; -#if !TARGET_CARBON - TXNClick( varsp->fTXNRec, (const EventRecord*) wxTheApp->MacGetCurrentEvent()); -#else - EventRecord rec ; - ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ; - TXNClick( varsp->fTXNRec, &rec ); -#endif - } + { + wxMacWindowClipper clipper( textctrl ) ; + + EventRecord rec ; + ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ; + TXNClick( varsp->fTXNRec, &rec ); + + } break; - + } - - HSetState((Handle) tpvars, state); } return partCodeResult; } @@ -336,28 +350,25 @@ static pascal ControlPartCode TPPaneTrackingProc(ControlHandle theControl, Point /* TPPaneIdleProc is our user pane idle routine. When our text field is active and in focus, we use this routine to set the cursor. */ -static pascal void TPPaneIdleProc(ControlHandle theControl) { - STPTextPaneVars **tpvars, *varsp; +static pascal void TPPaneIdleProc(ControlRef theControl) { /* set up locals */ - tpvars = (STPTextPaneVars **) GetControlReference(theControl); - if (tpvars != NULL && IsControlVisible( theControl ) ) { + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return ; + TPUpdateVisibility( theControl ) ; + STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; + if (textctrl->MacIsReallyShown()) { /* if we're not active, then we have nothing to say about the cursor */ - if ((**tpvars).fIsActive) { - char state; + if (varsp->fIsActive) { Rect bounds; Point mousep; - /* lock down the globals */ - state = HGetState((Handle) tpvars); - HLock((Handle) tpvars); - varsp = *tpvars; - /* get the current mouse coordinates (in our window) */ - SetPortWindowPort(GetControlOwner(theControl)); - wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; + + wxMacWindowClipper clipper( textctrl ) ; GetMouse(&mousep); /* there's a 'focus thing' and an 'unfocused thing' */ if (varsp->fInFocus) { /* flash the cursor */ - SetPort((**tpvars).fDrawingEnvironment); + SetPort(varsp->fDrawingEnvironment); TXNIdle(varsp->fTXNRec); /* set the cursor */ if (PtInRect(mousep, &varsp->fRTextArea)) { @@ -372,14 +383,12 @@ static pascal void TPPaneIdleProc(ControlHandle theControl) { } } else { /* if it's in our bounds, set the cursor */ - GetControlBounds(theControl, &bounds); + UMAGetControlBoundsInWindowCoords(theControl, &bounds); if (PtInRect(mousep, &bounds)) { // SetThemeCursor(kThemeArrowCursor); } } - - HSetState((Handle) tpvars, state); } } } @@ -388,22 +397,25 @@ static pascal void TPPaneIdleProc(ControlHandle theControl) { /* TPPaneKeyDownProc is called whenever a keydown event is directed at our control. Here, we direct the keydown event to the text edit record and redraw the scroll bar and text field as appropriate. */ -static pascal ControlPartCode TPPaneKeyDownProc(ControlHandle theControl, +static pascal ControlPartCode TPPaneKeyDownProc(ControlRef theControl, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) { - STPTextPaneVars **tpvars; - tpvars = (STPTextPaneVars **) GetControlReference(theControl); - if (tpvars != NULL) { - if ((**tpvars).fInFocus) { - /* turn autoscrolling on and send the key event to text edit */ - SetPort((**tpvars).fDrawingEnvironment); - wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; - EventRecord ev ; - memset( &ev , 0 , sizeof( ev ) ) ; - ev.what = keyDown ; - ev.modifiers = modifiers ; - ev.message = (( keyCode << 8 ) & keyCodeMask ) + ( charCode & charCodeMask ) ; - TXNKeyDown( (**tpvars).fTXNRec, &ev); - } + + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return 0; + TPUpdateVisibility( theControl ) ; + + STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; + if (varsp->fInFocus) + { + /* turn autoscrolling on and send the key event to text edit */ + wxMacWindowClipper clipper( textctrl ) ; + EventRecord ev ; + memset( &ev , 0 , sizeof( ev ) ) ; + ev.what = keyDown ; + ev.modifiers = modifiers ; + ev.message = (( keyCode << 8 ) & keyCodeMask ) + ( charCode & charCodeMask ) ; + TXNKeyDown( varsp->fTXNRec, &ev); } return kControlEntireControl; } @@ -412,33 +424,25 @@ static pascal ControlPartCode TPPaneKeyDownProc(ControlHandle theControl, /* TPPaneActivateProc is called when the window containing the user pane control receives activate events. Here, we redraw the control and it's text as necessary for the activation state. */ -static pascal void TPPaneActivateProc(ControlHandle theControl, Boolean activating) { - Rect bounds; - STPTextPaneVars **tpvars, *varsp; - char state; +static pascal void TPPaneActivateProc(ControlRef theControl, Boolean activating) { /* set up locals */ - tpvars = (STPTextPaneVars **) GetControlReference(theControl); - if (tpvars != NULL) { - state = HGetState((Handle) tpvars); - HLock((Handle) tpvars); - varsp = *tpvars; - /* de/activate the text edit record */ - SetPort((**tpvars).fDrawingEnvironment); - wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; - GetControlBounds(theControl, &bounds); - varsp->fIsActive = activating; - TPActivatePaneText(tpvars, varsp->fIsActive && varsp->fInFocus); - /* redraw the frame */ - if ( IsControlVisible( theControl ) ) - { - if (!wxFindControlFromMacControl(theControl)->HasFlag(wxNO_BORDER)) - { - DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); - if (varsp->fInFocus) - DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fIsActive); - } - } - HSetState((Handle) tpvars, state); + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + + if ( textctrl == NULL ) + return ; + TPUpdateVisibility( theControl ) ; + + STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; + + varsp->fIsActive = activating; + wxMacWindowClipper clipper( textctrl ) ; + TPActivatePaneText(varsp, varsp->fIsActive && varsp->fInFocus); + /* redraw the frame */ + if ( textctrl->MacIsReallyShown() ) + { + if ( !varsp->fNoBorders ) + DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); + TPRedrawFocusOutline( varsp ) ; } } @@ -447,67 +451,58 @@ static pascal void TPPaneActivateProc(ControlHandle theControl, Boolean activati from our control. Herein, switch the focus appropriately according to the parameters and redraw the control as necessary. */ -static pascal ControlPartCode TPPaneFocusProc(ControlHandle theControl, ControlFocusPart action) { +static pascal ControlPartCode TPPaneFocusProc(ControlRef theControl, ControlFocusPart action) { ControlPartCode focusResult; - STPTextPaneVars **tpvars, *varsp; - char state; - /* set up locals */ + focusResult = kControlFocusNoPart; - tpvars = (STPTextPaneVars **) GetControlReference(theControl); - if (tpvars != NULL ) { - state = HGetState((Handle) tpvars); - HLock((Handle) tpvars); - varsp = *tpvars; - /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is - tabbing forwards (or shift tabbing backwards) through the items in the dialog, - and kControlFocusNextPart will be received. When the user clicks in our field - and it is not the current focus, then the constant kUserClickedToFocusPart will - be received. The constant kControlFocusNoPart will be received when our control - is the current focus and the user clicks in another control. In your focus routine, - you should respond to these codes as follows: - - kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw - the control and the focus rectangle as necessary. - - kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off - depending on its current state. redraw the control and the focus rectangle - as appropriate for the new focus state. If the focus state is 'off', return the constant - kControlFocusNoPart, otherwise return a non-zero part code. - kUserClickedToFocusPart - is a constant defined for this example. You should - define your own value for handling click-to-focus type events. */ - /* calculate the next highlight state */ - switch (action) { - default: - case kControlFocusNoPart: - TPFocusPaneText(tpvars, false); - focusResult = kControlFocusNoPart; - break; - case kUserClickedToFocusPart: - TPFocusPaneText(tpvars, true); - focusResult = 1; - break; - case kControlFocusPrevPart: - case kControlFocusNextPart: - TPFocusPaneText(tpvars, ( ! varsp->fInFocus)); - focusResult = varsp->fInFocus ? 1 : kControlFocusNoPart; - break; - } - TPActivatePaneText(tpvars, varsp->fIsActive && varsp->fInFocus); - /* redraw the text fram and focus rectangle to indicate the - new focus state */ - if ( IsControlVisible( theControl ) ) - { - if (!wxFindControlFromMacControl(theControl)->HasFlag(wxNO_BORDER)) - { - /* save the drawing state */ - SetPort((**tpvars).fDrawingEnvironment); - wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; - DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); - DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fIsActive && varsp->fInFocus); - } - } - /* done */ - HSetState((Handle) tpvars, state); + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(theControl); + if ( textctrl == NULL ) + return 0; + TPUpdateVisibility( theControl ) ; + STPTextPaneVars *varsp = (STPTextPaneVars *) textctrl->m_macTXNvars ; + /* if kControlFocusPrevPart and kControlFocusNextPart are received when the user is + tabbing forwards (or shift tabbing backwards) through the items in the dialog, + and kControlFocusNextPart will be received. When the user clicks in our field + and it is not the current focus, then the constant kUserClickedToFocusPart will + be received. The constant kControlFocusNoPart will be received when our control + is the current focus and the user clicks in another control. In your focus routine, + you should respond to these codes as follows: + + kControlFocusNoPart - turn off focus and return kControlFocusNoPart. redraw + the control and the focus rectangle as necessary. + + kControlFocusPrevPart or kControlFocusNextPart - toggle focus on or off + depending on its current state. redraw the control and the focus rectangle + as appropriate for the new focus state. If the focus state is 'off', return the constant + kControlFocusNoPart, otherwise return a non-zero part code. + kUserClickedToFocusPart - is a constant defined for this example. You should + define your own value for handling click-to-focus type events. */ + /* calculate the next highlight state */ + switch (action) { + default: + case kControlFocusNoPart: + TPFocusPaneText(varsp, false); + focusResult = kControlFocusNoPart; + break; + case kUserClickedToFocusPart: + TPFocusPaneText(varsp, true); + focusResult = 1; + break; + case kControlFocusPrevPart: + case kControlFocusNextPart: + TPFocusPaneText(varsp, ( ! varsp->fInFocus)); + focusResult = varsp->fInFocus ? 1 : kControlFocusNoPart; + break; + } + TPActivatePaneText(varsp, varsp->fIsActive && varsp->fInFocus); + /* redraw the text fram and focus rectangle to indicate the + new focus state */ + if ( textctrl->MacIsReallyShown() ) + { + wxMacWindowClipper c( textctrl ) ; + if ( !varsp->fNoBorders ) + DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); + TPRedrawFocusOutline( varsp ) ; } return focusResult; } @@ -520,14 +515,12 @@ static pascal ControlPartCode TPPaneFocusProc(ControlHandle theControl, ControlF should refer to a user pane control that you have either created yourself or extracted from a dialog's control heirarchy using the GetDialogItemAsControl routine. */ -OSStatus mUPOpenControl(ControlHandle theControl, long wxStyle ) +OSStatus mUPOpenControl(STPTextPaneVars* &handle, ControlRef theControl, long wxStyle ) { Rect bounds; WindowRef theWindow; - STPTextPaneVars **tpvars, *varsp; + STPTextPaneVars *varsp; OSStatus err = noErr ; - RGBColor rgbWhite = {0xFFFF, 0xFFFF, 0xFFFF}; - TXNBackground tback; /* set up our globals */ if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(TPPaneDrawProc); @@ -539,21 +532,23 @@ OSStatus mUPOpenControl(ControlHandle theControl, long wxStyle ) if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(TPPaneFocusProc); /* allocate our private storage */ - tpvars = (STPTextPaneVars **) NewHandleClear(sizeof(STPTextPaneVars)); - SetControlReference(theControl, (long) tpvars); - HLock((Handle) tpvars); - varsp = *tpvars; + varsp = (STPTextPaneVars *) malloc(sizeof(STPTextPaneVars)); + handle = varsp ; + /* set the initial settings for our private data */ varsp->fMultiline = wxStyle & wxTE_MULTILINE ; + varsp->fNoBorders = wxStyle & wxNO_BORDER ; varsp->fInFocus = false; varsp->fIsActive = true; - varsp->fTEActive = true; // in order to get a deactivate + varsp->fTXNObjectActive = false; + varsp->fFocusDrawState = false ; varsp->fUserPaneRec = theControl; + varsp->fVisible = true ; + theWindow = varsp->fOwner = GetControlOwner(theControl); varsp->fDrawingEnvironment = (GrafPtr) GetWindowPort(theWindow); - varsp->fInDialogWindow = ( GetWindowKind(varsp->fOwner) == kDialogWindowKind ); /* set up the user pane procedures */ SetControlData(theControl, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(gTPDrawProc), &gTPDrawProc); SetControlData(theControl, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(gTPHitProc), &gTPHitProc); @@ -562,25 +557,11 @@ OSStatus mUPOpenControl(ControlHandle theControl, long wxStyle ) SetControlData(theControl, kControlEntireControl, kControlUserPaneKeyDownProcTag, sizeof(gTPKeyProc), &gTPKeyProc); SetControlData(theControl, kControlEntireControl, kControlUserPaneActivateProcTag, sizeof(gTPActivateProc), &gTPActivateProc); SetControlData(theControl, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc); + /* calculate the rectangles used by the control */ - GetControlBounds(theControl, &bounds); - SetRect(&varsp->fRFocusOutline, bounds.left, bounds.top, bounds.right, bounds.bottom); - SetRect(&varsp->fRTextOutline, bounds.left, bounds.top, bounds.right, bounds.bottom); - if ((wxStyle & wxNO_BORDER) != wxNO_BORDER) - { - SetRect(&varsp->fRTextArea, bounds.left + 2 , bounds.top + (varsp->fMultiline ? 0 : 2) , - bounds.right - (varsp->fMultiline ? 0 : 2), bounds.bottom - (varsp->fMultiline ? 0 : 2)); - } - else - { - SetRect(&varsp->fRTextArea, bounds.left , bounds.top , - bounds.right, bounds.bottom); - } - - /* calculate the background region for the text. In this case, it's kindof - and irregular region because we're setting the scroll bar a little ways inside - of the text area. */ - RectRgn((varsp->fTextBackgroundRgn = NewRgn()), &varsp->fRTextOutline); + UMAGetControlBoundsInWindowCoords(theControl, &bounds); + varsp->fRTextOutlineRegion = NewRgn() ; + TPCalculateBounds( varsp , bounds ) ; /* set up the drawing environment */ SetPort(varsp->fDrawingEnvironment); @@ -608,55 +589,50 @@ OSStatus mUPOpenControl(ControlHandle theControl, long wxStyle ) else frameOptions |= kTXNSingleLineOnlyMask ; - if ( wxStyle & wxTE_READONLY ) - frameOptions |= kTXNReadOnlyMask ; - - TXNNewObject(NULL, varsp->fOwner, &varsp->fRTextArea, + verify_noerr(TXNNewObject(NULL, varsp->fOwner, &varsp->fRTextArea, frameOptions , kTXNTextEditStyleFrameType, kTXNTextensionFile, kTXNSystemDefaultEncoding, - &varsp->fTXNRec, &varsp->fTXNFrame, (TXNObjectRefcon) tpvars); - - if ( !IsControlVisible( theControl ) ) - TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top + 30000 , varsp->fRTextArea.left + 30000 , - varsp->fRTextArea.bottom + 30000 , varsp->fRTextArea.right + 30000 , varsp->fTXNFrame); + &varsp->fTXNRec, &varsp->fTXNFrame, (TXNObjectRefcon) varsp)); + + TXNControlTag iControlTags[3] = { kTXNDoFontSubstitution, kTXNWordWrapStateTag }; + TXNControlData iControlData[3] = { {false}, {kTXNAutoWrap} }; + int toptag = 2 ; +#if TARGET_API_MAC_OSX + iControlTags[2] = kTXNVisibilityTag ; + iControlData[2].uValue = false ; + toptag++ ; +#endif + iControlData[1].uValue = varsp->fVisible ; + + if ( (wxStyle & wxTE_MULTILINE) && (wxStyle & wxTE_DONTWRAP) ) + iControlData[2].uValue = kTXNNoAutoWrap ; + verify_noerr( TXNSetTXNObjectControls( varsp->fTXNRec, false, toptag, + iControlTags, iControlData )) ; - if ( (wxStyle & wxTE_MULTILINE) && (wxStyle & wxTE_DONTWRAP) ) - { - TXNControlTag tag = kTXNWordWrapStateTag ; - TXNControlData dat ; - dat.uValue = kTXNNoAutoWrap ; - TXNSetTXNObjectControls( varsp->fTXNRec , false , 1 , &tag , &dat ) ; - } - Str255 fontName ; - SInt16 fontSize ; - Style fontStyle ; + Str255 fontName ; + SInt16 fontSize ; + Style fontStyle ; - GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; + GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; - TXNTypeAttributes typeAttr[] = - { - { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } , - { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } , - { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } , - } ; + TXNTypeAttributes typeAttr[] = + { + { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } , + { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } , + { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } , + } ; err = TXNSetTypeAttributes (varsp->fTXNRec, sizeof( typeAttr ) / sizeof(TXNTypeAttributes) , typeAttr, kTXNStartOffset, kTXNEndOffset); - /* set the field's background */ - tback.bgType = kTXNBackgroundTypeRGB; - tback.bg.color = rgbWhite; - TXNSetBackground( varsp->fTXNRec, &tback); - /* unlock our storage */ - HUnlock((Handle) tpvars); /* perform final activations and setup for our text field. Here, we assume that the window is going to be the 'active' window. */ - TPActivatePaneText(tpvars, varsp->fIsActive && varsp->fInFocus); + TPActivatePaneText(varsp, varsp->fIsActive && varsp->fInFocus); /* all done */ return err; } @@ -684,7 +660,7 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) END_EVENT_TABLE() #endif -static void SetTXNData( TXNObject txn , const wxString& st , TXNOffset start , TXNOffset end ) +static void SetTXNData( STPTextPaneVars *varsp, TXNObject txn , const wxString& st , TXNOffset start , TXNOffset end ) { #if wxUSE_UNICODE #if SIZEOF_WCHAR_T == 2 @@ -704,16 +680,14 @@ static void SetTXNData( TXNObject txn , const wxString& st , TXNOffset start , T wxCharBuffer text = st.mb_str(wxConvLocal) ; TXNSetData( txn , kTXNTextData, (void*)text.data(), strlen( text ) , start, end); -#endif +#endif } // Text item void wxTextCtrl::Init() { - m_macTE = NULL ; m_macTXN = NULL ; m_macTXNvars = NULL ; - m_macUsesTXN = false ; m_editable = true ; m_dirty = false; @@ -723,18 +697,13 @@ void wxTextCtrl::Init() wxTextCtrl::~wxTextCtrl() { - if ( m_macUsesTXN ) - { - SetControlReference((ControlHandle)m_macControl, 0) ; - TXNDeleteObject((TXNObject)m_macTXN); - /* delete our private storage */ - DisposeHandle((Handle) m_macTXNvars); - /* zero the control reference */ - } + SetControlReference((ControlRef)m_macControl, 0) ; + TXNDeleteObject((TXNObject)m_macTXN); + /* delete our private storage */ + free(m_macTXNvars); + /* zero the control reference */ } -const short kVerticalMargin = 2 ; -const short kHorizontalMargin = 2 ; bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& str, @@ -743,51 +712,19 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - m_macTE = NULL ; + m_macIsUserPane = FALSE ; + m_macTXN = NULL ; m_macTXNvars = NULL ; - m_macUsesTXN = false ; m_editable = true ; - m_macUsesTXN = ! (style & wxTE_PASSWORD ) ; - - m_macUsesTXN &= (TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress) ; - // base initialization if ( !wxTextCtrlBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) ) return FALSE; wxSize mySize = size ; - if (style & wxNO_BORDER) - { - m_macHorizontalBorder = 0 ; - m_macVerticalBorder = 0 ; - } - else if ( m_macUsesTXN ) - { - m_macHorizontalBorder = 5 ; // additional pixels around the real control - m_macVerticalBorder = 3 ; - } - else - { - m_macHorizontalBorder = 5 ; // additional pixels around the real control - m_macVerticalBorder = 5 ; - } - - - Rect bounds ; - Str255 title ; - /* - if ( mySize.y == -1 ) - { - mySize.y = 13 ; - if ( m_windowStyle & wxTE_MULTILINE ) - mySize.y *= 5 ; - mySize.y += 2 * m_macVerticalBorder ; - } - */ - MacPreControlCreate( parent , id , wxEmptyString , pos , mySize ,style, validator , name , &bounds , title ) ; + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; if ( m_windowStyle & wxTE_MULTILINE ) { @@ -797,22 +734,8 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, m_windowStyle |= wxTE_PROCESS_ENTER; } - if ( m_windowStyle & wxTE_READONLY) - { - m_editable = FALSE ; - } - wxString st = str ; wxMacConvertNewlines13To10( &st ) ; - if ( !m_macUsesTXN ) - { - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , false , 0 , 0 , 1, - (style & wxTE_PASSWORD) ? kControlEditTextPasswordProc : kControlEditTextProc , (long) this ) ; - long size ; - ::GetControlData((ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*)((TEHandle *)&m_macTE) , &size ) ; - - } - else { short featurSet; @@ -820,57 +743,67 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, | kControlWantsActivate | kControlHandlesTracking | kControlHasSpecialBackground | kControlGetsFocusOnClick | kControlSupportsLiveFeedback; /* create the control */ - m_macControl = NewControl(MAC_WXHWND(parent->MacGetRootWindow()), &bounds, "\p", false , featurSet, 0, featurSet, kControlUserPaneProc, 0); + m_macControl = (WXWidget) ::NewControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, "\p", true , featurSet, 0, featurSet, kControlUserPaneProc, (long) this ); /* set up the mUP specific features and data */ - mUPOpenControl((ControlHandle) m_macControl, m_windowStyle ); + wxMacWindowClipper c(this) ; + STPTextPaneVars *varsp ; + mUPOpenControl( varsp, (ControlRef) m_macControl, m_windowStyle ); + m_macTXNvars = varsp ; + m_macTXN = varsp->fTXNRec ; + if ( style & wxTE_PASSWORD ) + { + UniChar c = 0xA5 ; + verify_noerr(TXNEchoMode( (TXNObject) m_macTXN , c , 0 , true )) ; + } } - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; + + if ( MacIsReallyShown() ) + MLTESetObjectVisibility( (STPTextPaneVars*) m_macTXNvars, true , GetWindowStyle() ) ; - if ( !m_macUsesTXN ) - { - wxCharBuffer text = st.mb_str(wxConvLocal) ; - ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , strlen(text) , text ) ; - } - else { - STPTextPaneVars **tpvars; - /* set up locals */ - tpvars = (STPTextPaneVars **) GetControlReference((ControlHandle) m_macControl); - /* set the text in the record */ - m_macTXN = (**tpvars).fTXNRec ; - SetTXNData( (TXNObject) m_macTXN , st , kTXNStartOffset, kTXNEndOffset ) ; - m_macTXNvars = tpvars ; - m_macUsesTXN = true ; + wxMacWindowClipper clipper( this ) ; + TPUpdateVisibility( (ControlRef) m_macControl ) ; + SetTXNData( (STPTextPaneVars *)m_macTXNvars , (TXNObject) m_macTXN , st , kTXNStartOffset, kTXNEndOffset ) ; + TXNSetSelection( (TXNObject) m_macTXN, 0, 0); TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart); } + SetBackgroundColour( *wxWHITE ) ; + + TXNBackground tback; + tback.bgType = kTXNBackgroundTypeRGB; + tback.bg.color = MAC_WXCOLORREF( GetBackgroundColour().GetPixel() ); + TXNSetBackground( (TXNObject) m_macTXN , &tback); + + if ( m_windowStyle & wxTE_READONLY) + { + SetEditable( false ) ; + } + return TRUE; } +void wxTextCtrl::MacVisibilityChanged() +{ + MLTESetObjectVisibility((STPTextPaneVars*) m_macTXNvars , MacIsReallyShown() , GetWindowStyle() ) ; + if ( !MacIsReallyShown() ) + InvalWindowRect( GetControlOwner( (ControlHandle) m_macControl ) , &((STPTextPaneVars *)m_macTXNvars)->fRBounds ) ; + +} + +void wxTextCtrl::MacEnabledStateChanged() +{ +} + + wxString wxTextCtrl::GetValue() const { Size actualSize = 0; wxString result ; OSStatus err ; - if ( !m_macUsesTXN ) - { - err = ::GetControlDataSize((ControlHandle) m_macControl, 0, - ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag, &actualSize ) ; - - if ( err ) - return wxEmptyString ; - - if ( actualSize > 0 ) - { - wxCharBuffer buf(actualSize) ; - ::GetControlData( (ControlHandle) m_macControl, 0, - ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag, - actualSize , buf.data() , &actualSize ) ; - result = wxString( buf , wxConvLocal) ; - } - } - else + { #if wxUSE_UNICODE Handle theText ; @@ -885,17 +818,26 @@ wxString wxTextCtrl::GetValue() const actualSize = GetHandleSize( theText ) / sizeof( UniChar) ; if ( actualSize > 0 ) { - wxChar *ptr = result.GetWriteBuf(actualSize*sizeof(wxChar)) ; -#if SIZEOF_WCHAR_T == 2 + wxChar *ptr = NULL ; +#if SIZEOF_WCHAR_T == 2 + ptr = new wxChar[actualSize + 1 ] ; wxStrncpy( ptr , (wxChar*) *theText , actualSize ) ; + #else - wxMBConvUTF16BE converter ; + SetHandleSize( theText , ( actualSize + 1 ) * sizeof( UniChar ) ) ; HLock( theText ) ; - converter.MB2WC( ptr , (const char*)*theText , actualSize ) ; + (((UniChar*)*theText)[actualSize]) = 0 ; + wxMBConvUTF16BE converter ; + size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; + ptr = new wxChar[noChars + 1] ; + + noChars = converter.MB2WC( ptr , (const char*)*theText , noChars ) ; + ptr[noChars] = 0 ; HUnlock( theText ) ; #endif ptr[actualSize] = 0 ; - result.UngetWriteBuf( actualSize *sizeof(wxChar) ) ; + result = wxString( ptr ) ; + delete[] ptr ; } DisposeHandle( theText ) ; } @@ -926,38 +868,32 @@ wxString wxTextCtrl::GetValue() const void wxTextCtrl::GetSelection(long* from, long* to) const { - if ( !m_macUsesTXN ) - { - *from = (**((TEHandle) m_macTE)).selStart; - *to = (**((TEHandle) m_macTE)).selEnd; - } - else - { - TXNGetSelection( (TXNObject) m_macTXN , (TXNOffset*) from , (TXNOffset*) to ) ; - } + TXNGetSelection( (TXNObject) m_macTXN , (TXNOffset*) from , (TXNOffset*) to ) ; } void wxTextCtrl::SetValue(const wxString& str) { + // optimize redraws + if ( GetValue() == str ) + return ; + wxString st = str ; wxMacConvertNewlines13To10( &st ) ; - if ( !m_macUsesTXN ) - { - wxCharBuffer text = st.mb_str(wxConvLocal) ; - ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , strlen(text) , text ) ; - } - else + { + wxMacWindowClipper c( this ) ; bool formerEditable = m_editable ; if ( !formerEditable ) SetEditable(true) ; - SetTXNData( (TXNObject) m_macTXN , st , kTXNStartOffset, kTXNEndOffset ) ; + + // otherwise scrolling might have problems ? + TPUpdateVisibility( ( (STPTextPaneVars *)m_macTXNvars)->fUserPaneRec ) ; + SetTXNData( (STPTextPaneVars *)m_macTXNvars , (TXNObject) m_macTXN , st , kTXNStartOffset, kTXNEndOffset ) ; TXNSetSelection( (TXNObject) m_macTXN, 0, 0); TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart); if ( !formerEditable ) SetEditable(formerEditable) ; } - MacRedrawControl() ; } void wxTextCtrl::SetMaxLength(unsigned long len) @@ -965,63 +901,101 @@ void wxTextCtrl::SetMaxLength(unsigned long len) m_maxLength = len ; } +bool wxTextCtrl::SetFont( const wxFont& font ) +{ + if ( !wxTextCtrlBase::SetFont( font ) ) + return FALSE ; + + wxMacWindowClipper c( this ) ; + bool formerEditable = m_editable ; + if ( !formerEditable ) + SetEditable(true) ; + + TXNTypeAttributes typeAttr[4] ; + Str255 fontName = "\pMonaco" ; + SInt16 fontSize = 12 ; + Style fontStyle = normal ; + int attrCounter = 0 ; + + wxMacStringToPascal( font.GetFaceName() , fontName ) ; + fontSize = font.MacGetFontSize() ; + fontStyle = font.MacGetFontStyle() ; + + typeAttr[attrCounter].tag = kTXNQDFontNameAttribute ; + typeAttr[attrCounter].size = kTXNQDFontNameAttributeSize ; + typeAttr[attrCounter].data.dataPtr = (void*) fontName ; + typeAttr[attrCounter+1].tag = kTXNQDFontSizeAttribute ; + typeAttr[attrCounter+1].size = kTXNFontSizeAttributeSize ; + typeAttr[attrCounter+1].data.dataValue = (fontSize << 16) ; + typeAttr[attrCounter+2].tag = kTXNQDFontStyleAttribute ; + typeAttr[attrCounter+2].size = kTXNQDFontStyleAttributeSize ; + typeAttr[attrCounter+2].data.dataValue = fontStyle ; + attrCounter += 3 ; + /* + typeAttr[attrCounter].tag = kTXNQDFontColorAttribute ; + typeAttr[attrCounter].size = kTXNQDFontColorAttributeSize ; + typeAttr[attrCounter].data.dataPtr = (void*) &color ; + color = MAC_WXCOLORREF(GetForegroundColour().GetPixel()) ; + attrCounter += 1 ; + */ + verify_noerr( TXNSetTypeAttributes ((TXNObject)m_macTXN, attrCounter , typeAttr, kTXNStartOffset,kTXNEndOffset) ); + + if ( !formerEditable ) + SetEditable(formerEditable) ; + return true ; +} + bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) { - if ( m_macUsesTXN ) + bool formerEditable = m_editable ; + if ( !formerEditable ) + SetEditable(true) ; + TXNTypeAttributes typeAttr[4] ; + Str255 fontName = "\pMonaco" ; + SInt16 fontSize = 12 ; + Style fontStyle = normal ; + RGBColor color ; + int attrCounter = 0 ; + if ( style.HasFont() ) { - bool formerEditable = m_editable ; - if ( !formerEditable ) - SetEditable(true) ; - TXNTypeAttributes typeAttr[4] ; - Str255 fontName = "\pMonaco" ; - SInt16 fontSize = 12 ; - Style fontStyle = normal ; - RGBColor color ; - int attrCounter = 0 ; - if ( style.HasFont() ) - { - const wxFont &font = style.GetFont() ; - wxMacStringToPascal( font.GetFaceName() , fontName ) ; - fontSize = font.GetPointSize() ; - if ( font.GetUnderlined() ) - fontStyle |= underline ; - if ( font.GetWeight() == wxBOLD ) - fontStyle |= bold ; - if ( font.GetStyle() == wxITALIC ) - fontStyle |= italic ; - - typeAttr[attrCounter].tag = kTXNQDFontNameAttribute ; - typeAttr[attrCounter].size = kTXNQDFontNameAttributeSize ; - typeAttr[attrCounter].data.dataPtr = (void*) fontName ; - typeAttr[attrCounter+1].tag = kTXNQDFontSizeAttribute ; - typeAttr[attrCounter+1].size = kTXNFontSizeAttributeSize ; - typeAttr[attrCounter+1].data.dataValue = (fontSize << 16) ; - typeAttr[attrCounter+2].tag = kTXNQDFontStyleAttribute ; - typeAttr[attrCounter+2].size = kTXNQDFontStyleAttributeSize ; - typeAttr[attrCounter+2].data.dataValue = fontStyle ; - attrCounter += 3 ; - - } - if ( style.HasTextColour() ) - { - typeAttr[attrCounter].tag = kTXNQDFontColorAttribute ; - typeAttr[attrCounter].size = kTXNQDFontColorAttributeSize ; - typeAttr[attrCounter].data.dataPtr = (void*) &color ; - color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ; - attrCounter += 1 ; - } + const wxFont &font = style.GetFont() ; + wxMacStringToPascal( font.GetFaceName() , fontName ) ; + fontSize = font.GetPointSize() ; + if ( font.GetUnderlined() ) + fontStyle |= underline ; + if ( font.GetWeight() == wxBOLD ) + fontStyle |= bold ; + if ( font.GetStyle() == wxITALIC ) + fontStyle |= italic ; + + typeAttr[attrCounter].tag = kTXNQDFontNameAttribute ; + typeAttr[attrCounter].size = kTXNQDFontNameAttributeSize ; + typeAttr[attrCounter].data.dataPtr = (void*) fontName ; + typeAttr[attrCounter+1].tag = kTXNQDFontSizeAttribute ; + typeAttr[attrCounter+1].size = kTXNFontSizeAttributeSize ; + typeAttr[attrCounter+1].data.dataValue = (fontSize << 16) ; + typeAttr[attrCounter+2].tag = kTXNQDFontStyleAttribute ; + typeAttr[attrCounter+2].size = kTXNQDFontStyleAttributeSize ; + typeAttr[attrCounter+2].data.dataValue = fontStyle ; + attrCounter += 3 ; + + } + if ( style.HasTextColour() ) + { + typeAttr[attrCounter].tag = kTXNQDFontColorAttribute ; + typeAttr[attrCounter].size = kTXNQDFontColorAttributeSize ; + typeAttr[attrCounter].data.dataPtr = (void*) &color ; + color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ; + attrCounter += 1 ; + } - if ( attrCounter > 0 ) - { -#ifdef __WXDEBUG__ - OSStatus status = -#endif // __WXDEBUG__ - TXNSetTypeAttributes ((TXNObject)m_macTXN, attrCounter , typeAttr, start,end); - wxASSERT_MSG( status == noErr , wxT("Couldn't set text attributes") ) ; - } - if ( !formerEditable ) - SetEditable(formerEditable) ; + if ( attrCounter > 0 ) + { + verify_noerr( TXNSetTypeAttributes ((TXNObject)m_macTXN, attrCounter , typeAttr, start,end) ); } + if ( !formerEditable ) + SetEditable(formerEditable) ; + return TRUE ; } @@ -1037,19 +1011,9 @@ void wxTextCtrl::Copy() { if (CanCopy()) { - if ( !m_macUsesTXN ) - { - TECopy( ((TEHandle) m_macTE) ) ; - ClearCurrentScrap(); - TEToScrap() ; - MacRedrawControl() ; - } - else - { - ClearCurrentScrap(); - TXNCopy((TXNObject)m_macTXN); - TXNConvertToPublicScrap(); - } + ClearCurrentScrap(); + TXNCopy((TXNObject)m_macTXN); + TXNConvertToPublicScrap(); } } @@ -1057,19 +1021,10 @@ void wxTextCtrl::Cut() { if (CanCut()) { - if ( !m_macUsesTXN ) - { - TECut( ((TEHandle) m_macTE) ) ; - ClearCurrentScrap(); - TEToScrap() ; - MacRedrawControl() ; - } - else - { - ClearCurrentScrap(); - TXNCut((TXNObject)m_macTXN); - TXNConvertToPublicScrap(); - } + ClearCurrentScrap(); + TXNCut((TXNObject)m_macTXN); + TXNConvertToPublicScrap(); + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); event.SetString( GetValue() ) ; event.SetEventObject( this ); @@ -1081,18 +1036,11 @@ void wxTextCtrl::Paste() { if (CanPaste()) { - if ( !m_macUsesTXN ) - { - TEFromScrap() ; - TEPaste( (TEHandle) m_macTE ) ; - MacRedrawControl() ; - } - else - { - TXNConvertFromPublicScrap(); - TXNPaste((TXNObject)m_macTXN); - SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ; - } + + TXNConvertFromPublicScrap(); + TXNPaste((TXNObject)m_macTXN); + SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ; + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); event.SetString( GetValue() ) ; event.SetEventObject( this ); @@ -1125,34 +1073,7 @@ bool wxTextCtrl::CanPaste() const if (!IsEditable()) return FALSE; -#if TARGET_CARBON - OSStatus err = noErr; - ScrapRef scrapRef; - - err = GetCurrentScrap( &scrapRef ); - if ( err != noTypeErr && err != memFullErr ) - { - ScrapFlavorFlags flavorFlags; - Size byteCount; - - if (( err = GetScrapFlavorFlags( scrapRef, 'TEXT', &flavorFlags )) == noErr) - { - if (( err = GetScrapFlavorSize( scrapRef, 'TEXT', &byteCount )) == noErr) - { - return TRUE ; - } - } - } - return FALSE; - -#else - long offset ; - if ( GetScrap( NULL , 'TEXT' , &offset ) > 0 ) - { - return TRUE ; - } -#endif - return FALSE ; + return TXNIsScrapPastable() ; } void wxTextCtrl::SetEditable(bool editable) @@ -1160,19 +1081,11 @@ void wxTextCtrl::SetEditable(bool editable) if ( editable != m_editable ) { m_editable = editable ; - if ( !m_macUsesTXN ) - { - if ( editable ) - UMAActivateControl( (ControlHandle) m_macControl ) ; - else - UMADeactivateControl((ControlHandle) m_macControl ) ; - } - else - { - TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; - TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ; - TXNSetTXNObjectControls( (TXNObject) m_macTXN , false , sizeof(tag) / sizeof (TXNControlTag) , tag , data ) ; - } + + TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; + TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ; + TXNSetTXNObjectControls( (TXNObject) m_macTXN , false , sizeof(tag) / sizeof (TXNControlTag) , tag , data ) ; + } } @@ -1196,116 +1109,64 @@ long wxTextCtrl::GetInsertionPoint() const long wxTextCtrl::GetLastPosition() const { - if ( !m_macUsesTXN ) + Handle theText ; + long actualsize ; + OSErr err = TXNGetDataEncoded( (TXNObject) m_macTXN, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); + /* all done */ + if ( err ) { - return (**((TEHandle) m_macTE)).teLength ; + actualsize = 0 ; } else { - Handle theText ; - long actualsize ; - OSErr err = TXNGetDataEncoded( (TXNObject) m_macTXN, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); - /* all done */ - if ( err ) - { - actualsize = 0 ; - } - else - { - actualsize = GetHandleSize( theText ) ; - DisposeHandle( theText ) ; - } - return actualsize ; + actualsize = GetHandleSize( theText ) ; + DisposeHandle( theText ) ; } + return actualsize ; } void wxTextCtrl::Replace(long from, long to, const wxString& str) { wxString value = str ; wxMacConvertNewlines13To10( &value ) ; - if ( !m_macUsesTXN ) - { - ControlEditTextSelectionRec selection ; - - selection.selStart = from ; - selection.selEnd = to ; - ::SetControlData((ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ; - TESetSelect( from , to , ((TEHandle) m_macTE) ) ; - TEDelete( ((TEHandle) m_macTE) ) ; - TEInsert( value , value.Length() , ((TEHandle) m_macTE) ) ; - } - else - { - bool formerEditable = m_editable ; - if ( !formerEditable ) - SetEditable(true) ; - TXNSetSelection( ((TXNObject) m_macTXN) , from , to ) ; - TXNClear( ((TXNObject) m_macTXN) ) ; - SetTXNData( (TXNObject) m_macTXN , str , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; - if ( !formerEditable ) - SetEditable( formerEditable ) ; - } + + bool formerEditable = m_editable ; + if ( !formerEditable ) + SetEditable(true) ; + TXNSetSelection( ((TXNObject) m_macTXN) , from , to ) ; + TXNClear( ((TXNObject) m_macTXN) ) ; + SetTXNData( (STPTextPaneVars *)m_macTXNvars , (TXNObject) m_macTXN , str , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; + if ( !formerEditable ) + SetEditable( formerEditable ) ; + Refresh() ; } void wxTextCtrl::Remove(long from, long to) { - if ( !m_macUsesTXN ) - { - ControlEditTextSelectionRec selection ; + bool formerEditable = m_editable ; + if ( !formerEditable ) + SetEditable(true) ; + TXNSetSelection( ((TXNObject) m_macTXN) , from , to ) ; + TXNClear( ((TXNObject) m_macTXN) ) ; + if ( !formerEditable ) + SetEditable( formerEditable ) ; - selection.selStart = from ; - selection.selEnd = to ; - ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ; - TEDelete( ((TEHandle) m_macTE) ) ; - } - else - { - bool formerEditable = m_editable ; - if ( !formerEditable ) - SetEditable(true) ; - TXNSetSelection( ((TXNObject) m_macTXN) , from , to ) ; - TXNClear( ((TXNObject) m_macTXN) ) ; - if ( !formerEditable ) - SetEditable( formerEditable ) ; - } Refresh() ; } void wxTextCtrl::SetSelection(long from, long to) { - if ( !m_macUsesTXN ) - { - ControlEditTextSelectionRec selection ; - if ((from == -1) && (to == -1)) - { - selection.selStart = 0 ; - selection.selEnd = 32767 ; - } - else - { - selection.selStart = from ; - selection.selEnd = to ; - } - - TESetSelect( selection.selStart , selection.selEnd , ((TEHandle) m_macTE) ) ; - ::SetControlData((ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ; - } + STPTextPaneVars *varsp = (STPTextPaneVars *) m_macTXNvars; + /* and our drawing environment as the operation + may force a redraw in the text area. */ + SetPort(varsp->fDrawingEnvironment); + /* change the selection */ + if ((from == -1) && (to == -1)) + TXNSelectAll((TXNObject) m_macTXN); else - { - STPTextPaneVars **tpvars; - /* set up our locals */ - tpvars = (STPTextPaneVars **) GetControlReference((ControlHandle) m_macControl); - /* and our drawing environment as the operation - may force a redraw in the text area. */ - SetPort((**tpvars).fDrawingEnvironment); - /* change the selection */ - if ((from == -1) && (to == -1)) - TXNSelectAll((TXNObject) m_macTXN); - else - TXNSetSelection( (**tpvars).fTXNRec, from, to); - TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart); - } + TXNSetSelection( varsp->fTXNRec, from, to); + TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart); } bool wxTextCtrl::LoadFile(const wxString& file) @@ -1322,24 +1183,18 @@ void wxTextCtrl::WriteText(const wxString& str) { wxString st = str ; wxMacConvertNewlines13To10( &st ) ; - if ( !m_macUsesTXN ) - { - wxCharBuffer text = st.mb_str(wxConvLocal) ; - TEInsert( text , strlen(text) , ((TEHandle) m_macTE) ) ; - } - else - { - bool formerEditable = m_editable ; - if ( !formerEditable ) - SetEditable(true) ; - long start , end , dummy ; - GetSelection( &start , &dummy ) ; - SetTXNData( (TXNObject) m_macTXN , st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; - GetSelection( &dummy , &end ) ; - SetStyle( start , end , GetDefaultStyle() ) ; - if ( !formerEditable ) - SetEditable( formerEditable ) ; - } + + bool formerEditable = m_editable ; + if ( !formerEditable ) + SetEditable(true) ; + long start , end , dummy ; + GetSelection( &start , &dummy ) ; + SetTXNData( (STPTextPaneVars *)m_macTXNvars , (TXNObject) m_macTXN , st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; + GetSelection( &dummy , &end ) ; + SetStyle( start , end , GetDefaultStyle() ) ; + if ( !formerEditable ) + SetEditable( formerEditable ) ; + MacRedrawControl() ; } @@ -1351,15 +1206,15 @@ void wxTextCtrl::AppendText(const wxString& text) void wxTextCtrl::Clear() { - if ( !m_macUsesTXN ) - { - ::SetControlData((ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ; - } - else - { - TXNSetSelection( (TXNObject)m_macTXN , kTXNStartOffset , kTXNEndOffset ) ; - TXNClear((TXNObject)m_macTXN); - } + bool formerEditable = m_editable ; + if ( !formerEditable ) + SetEditable(true) ; + TXNSetSelection( (TXNObject)m_macTXN , kTXNStartOffset , kTXNEndOffset ) ; + TXNClear((TXNObject)m_macTXN); + + if ( !formerEditable ) + SetEditable( formerEditable ) ; + Refresh() ; } @@ -1384,31 +1239,28 @@ wxSize wxTextCtrl::DoGetBestSize() const int wText = 100 ; int hText; - if ( m_macUsesTXN ) - { - hText = 17 ; - } - else + + switch( m_windowVariant ) { - hText = 13 ; + case wxWINDOW_VARIANT_NORMAL : + hText = 22 ; + break ; + case wxWINDOW_VARIANT_SMALL : + hText = 19 ; + break ; + case wxWINDOW_VARIANT_MINI : + hText= 15 ; + break ; + default : + hText = 22 ; + break ; } -/* - int cx, cy; - wxGetCharSize(GetHWND(), &cx, &cy, &GetFont()); - - int wText = DEFAULT_ITEM_WIDTH; - - int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); - return wxSize(wText, hText); -*/ if ( m_windowStyle & wxTE_MULTILINE ) { hText *= 5 ; } - hText += 2 * m_macVerticalBorder ; - wText += 2 * m_macHorizontalBorder ; - //else: for single line control everything is ok + return wxSize(wText, hText); } @@ -1420,10 +1272,7 @@ void wxTextCtrl::Undo() { if (CanUndo()) { - if ( m_macUsesTXN ) - { - TXNUndo((TXNObject)m_macTXN); - } + TXNUndo((TXNObject)m_macTXN); } } @@ -1431,10 +1280,7 @@ void wxTextCtrl::Redo() { if (CanRedo()) { - if ( m_macUsesTXN ) - { - TXNRedo((TXNObject)m_macTXN); - } + TXNRedo((TXNObject)m_macTXN); } } @@ -1444,11 +1290,7 @@ bool wxTextCtrl::CanUndo() const { return false ; } - if ( m_macUsesTXN ) - { - return TXNCanUndo((TXNObject)m_macTXN,NULL); - } - return FALSE ; + return TXNCanUndo((TXNObject)m_macTXN,NULL); } bool wxTextCtrl::CanRedo() const @@ -1457,11 +1299,7 @@ bool wxTextCtrl::CanRedo() const { return false ; } - if ( m_macUsesTXN ) - { - return TXNCanRedo((TXNObject)m_macTXN,NULL); - } - return FALSE ; + return TXNCanRedo((TXNObject)m_macTXN,NULL); } // Makes modifie or unmodified @@ -1477,23 +1315,9 @@ void wxTextCtrl::DiscardEdits() int wxTextCtrl::GetNumberOfLines() const { - if ( m_macUsesTXN ) - { - ItemCount lines ; - TXNGetLineCount((TXNObject)m_macTXN, &lines ) ; - return lines ; - } - else - { - wxString content = GetValue() ; - - int count = 1; - for (size_t i = 0; i < content.Length() ; i++) - { - if (content[i] == '\r') count++; - } - return count; - } + ItemCount lines ; + TXNGetLineCount((TXNObject)m_macTXN, &lines ) ; + return lines ; } long wxTextCtrl::XYToPosition(long x, long y) const @@ -1510,7 +1334,6 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const void wxTextCtrl::ShowPosition(long pos) { #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER) - if ( m_macUsesTXN ) { Point current ; Point desired ; @@ -1703,8 +1526,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) if (!eat_key) { // perform keystroke handling -#if TARGET_CARBON - if ( m_macUsesTXN && wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) + if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL ) CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ; else { @@ -1717,18 +1539,9 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) keychar = short(ev->message & charCodeMask); keycode = short(ev->message & keyCodeMask) >> 8 ; - ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ; + ::HandleControlKey( (ControlRef) m_macControl , keycode , keychar , ev->modifiers ) ; } } -#else - EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ; - short keycode ; - short keychar ; - keychar = short(ev->message & charCodeMask); - keycode = short(ev->message & keyCodeMask) >> 8 ; - - ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ; -#endif } if ( ( key >= 0x20 && key < WXK_START ) || key == WXK_RETURN || @@ -1742,40 +1555,6 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) } } -void wxTextCtrl::MacSuperShown( bool show ) -{ - bool former = m_macControlIsShown ; - wxControl::MacSuperShown( show ) ; - if ( (former != m_macControlIsShown) && m_macUsesTXN ) - { - if ( m_macControlIsShown ) - TXNSetFrameBounds( (TXNObject) m_macTXN, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.top, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.left, - (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.bottom,(**(STPTextPaneVars **)m_macTXNvars).fRTextArea.right, (**(STPTextPaneVars **)m_macTXNvars).fTXNFrame); - else - TXNSetFrameBounds( (TXNObject) m_macTXN, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.top + 30000, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.left, - (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.bottom + 30000, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.right, (**(STPTextPaneVars **)m_macTXNvars).fTXNFrame); - } -} - -bool wxTextCtrl::Show(bool show) -{ - bool former = m_macControlIsShown ; - - bool retval = wxControl::Show( show ) ; - - if ( former != m_macControlIsShown && m_macUsesTXN ) - { - if ( m_macControlIsShown ) - TXNSetFrameBounds( (TXNObject) m_macTXN, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.top, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.left, - (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.bottom,(**(STPTextPaneVars **)m_macTXNvars).fRTextArea.right, (**(STPTextPaneVars **)m_macTXNvars).fTXNFrame); - else - TXNSetFrameBounds( (TXNObject) m_macTXN, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.top + 30000, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.left, - (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.bottom + 30000, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.right, (**(STPTextPaneVars **)m_macTXNvars).fTXNFrame); - } - - return retval ; -} - // ---------------------------------------------------------------------------- // standard handlers for standard edit menu events // ---------------------------------------------------------------------------- @@ -1832,10 +1611,45 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) { - if ( m_macUsesTXN ) - return true ; - else - return wxWindow::MacSetupCursor( pt ) ; + return true ; +} + +// user pane implementation + +void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part) +{ +} + +wxInt16 wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) +{ + return kControlNoPart ; +} + +wxInt16 wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) +{ + return kControlNoPart ; +} + +void wxTextCtrl::MacControlUserPaneIdleProc() +{ +} + +wxInt16 wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) +{ + return kControlNoPart ; +} + +void wxTextCtrl::MacControlUserPaneActivateProc(bool activating) +{ +} + +wxInt16 wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action) +{ + return kControlNoPart ; +} + +void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info) +{ } #endif diff --git a/src/mac/carbon/tglbtn.cpp b/src/mac/carbon/tglbtn.cpp index aa7ee2bb3e..25c390aa8f 100644 --- a/src/mac/carbon/tglbtn.cpp +++ b/src/mac/carbon/tglbtn.cpp @@ -56,25 +56,19 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { + m_macIsUserPane = FALSE ; + if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) return false; - - Rect bounds ; - Str255 title ; - - if ( UMAHasAquaLayout() ) - { - m_macHorizontalBorder = kMacOSXHorizontalBorder; - m_macVerticalBorder = kMacOSXVerticalBorder; - } - MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; + m_label = label ; - m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , kControlBehaviorToggles , 1, + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , kControlBehaviorToggles , 1, kControlBevelButtonNormalBevelProc , (long) this ) ; - wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; + wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; - MacPostControlCreate() ; + MacPostControlCreate(pos,size) ; return TRUE; } @@ -88,22 +82,17 @@ wxSize wxToggleButton::DoGetBestSize() const if (lBtn > wBtn) wBtn = lBtn; - if ( UMAHasAquaLayout() ) - { - wBtn += 2 * kMacOSXHorizontalBorder ; - hBtn += 2 * kMacOSXVerticalBorder ; - } return wxSize ( wBtn , hBtn ) ; } void wxToggleButton::SetValue(bool val) { - ::SetControl32BitValue( (ControlHandle) m_macControl , val ) ; + ::SetControl32BitValue( (ControlRef) m_macControl , val ) ; } bool wxToggleButton::GetValue() const { - return GetControl32BitValue( (ControlHandle) m_macControl ) ; + return GetControl32BitValue( (ControlRef) m_macControl ) ; } void wxToggleButton::Command(wxCommandEvent & event) diff --git a/src/mac/carbon/timer.cpp b/src/mac/carbon/timer.cpp index a639e2c464..fe935003ca 100644 --- a/src/mac/carbon/timer.cpp +++ b/src/mac/carbon/timer.cpp @@ -114,11 +114,7 @@ bool wxTimer::Start(int milliseconds,bool mode) wxCHECK_MSG( m_milli > 0, FALSE, wxT("invalid value for timer timeout") ); wxCHECK_MSG( m_info->m_task.tmAddr == NULL , FALSE, wxT("attempting to restart a timer") ); -#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) m_info->m_task.tmAddr = NewTimerUPP( MacTimerProc ) ; -#else - m_info->m_task.tmAddr = NewTimerProc( MacTimerProc ) ; -#endif m_info->m_task.tmWakeUp = 0 ; m_info->m_task.tmReserved = 0 ; m_info->m_task.qType = 0 ; diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index d8bdac1326..2dd8872464 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -62,8 +62,8 @@ public: DisposeControl( m_controlHandle ) ; } - ControlHandle GetControlHandle() { return m_controlHandle ; } - void SetControlHandle( ControlHandle handle ) { m_controlHandle = handle ; } + WXWidget GetControlHandle() { return (WXWidget) m_controlHandle ; } + void SetControlHandle( ControlRef handle ) { m_controlHandle = handle ; } void SetSize(const wxSize& size) ; void SetPosition( const wxPoint& position ) ; @@ -94,12 +94,64 @@ private : { m_controlHandle = NULL ; } - ControlHandle m_controlHandle ; + ControlRef m_controlHandle ; wxCoord m_x; wxCoord m_y; }; +static const EventTypeSpec eventList[] = +{ + { kEventClassControl , kEventControlHit } , +} ; + +static pascal OSStatus wxMacToolBarToolControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +{ + OSStatus result = eventNotHandledErr ; + + wxMacCarbonEvent cEvent( event ) ; + + ControlRef controlRef ; + + cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; + + switch( GetEventKind( event ) ) + { + case kEventControlHit : + { + wxToolBarTool* tbartool = (wxToolBarTool*)data ; + if ( tbartool->CanBeToggled() ) + { + tbartool->Toggle( GetControl32BitValue( (ControlRef) tbartool->GetControlHandle() ) ) ; + } + ((wxToolBar*)tbartool->GetToolBar())->OnLeftClick( tbartool->GetId() , tbartool -> IsToggled() ) ; + + result = noErr; + } + break ; + default : + break ; + } + return result ; +} + +pascal OSStatus wxMacToolBarToolEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +{ + OSStatus result = eventNotHandledErr ; + + switch ( GetEventClass( event ) ) + { + case kEventClassControl : + result = wxMacToolBarToolControlEventHandler( handler, event, data ) ; + break ; + default : + break ; + } + return result ; +} + +DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler ) + // ============================================================================ // implementation // ============================================================================ @@ -125,12 +177,14 @@ void wxToolBarTool::SetPosition(const wxPoint& position) { int x , y ; x = y = 0 ; - WindowRef rootwindow = (WindowRef) GetToolBar()->MacGetRootWindow() ; + int mac_x = position.x ; + int mac_y = position.y ; +#if !TARGET_API_MAC_OSX + WindowRef rootwindow = (WindowRef) GetToolBar()->MacGetTopLevelWindowRef() ; GetToolBar()->MacWindowToRootWindow( &x , &y ) ; - int mac_x = x + position.x ; - int mac_y = y + position.y ; - - + mac_x += x; + mac_y += y; +#endif Rect contrlRect ; GetControlBounds( m_controlHandle , &contrlRect ) ; int former_mac_x = contrlRect.left ; @@ -139,15 +193,7 @@ void wxToolBarTool::SetPosition(const wxPoint& position) if ( mac_x != former_mac_x || mac_y != former_mac_y ) { - { - Rect inval = { former_mac_y , former_mac_x , former_mac_y + sz.y , former_mac_x + sz.x } ; - InvalWindowRect( rootwindow , &inval ) ; - } UMAMoveControl( m_controlHandle , mac_x , mac_y ) ; - { - Rect inval = { mac_y , mac_x , mac_y + sz.y , mac_x + sz.x } ; - InvalWindowRect( rootwindow , &inval ) ; - } } } else if ( IsControl() ) @@ -177,7 +223,7 @@ wxToolBarTool::wxToolBarTool(wxToolBar *tbar, if (id == wxID_SEPARATOR) return; - WindowRef window = (WindowRef) tbar->MacGetRootWindow() ; + WindowRef window = (WindowRef) tbar->MacGetTopLevelWindowRef() ; wxSize toolSize = tbar->GetToolSize() ; Rect toolrect = { 0, 0 , toolSize.y , toolSize.x } ; @@ -190,16 +236,18 @@ wxToolBarTool::wxToolBarTool(wxToolBar *tbar, if ( info.contentType != kControlNoContent ) { - m_controlHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , + m_controlHandle = ::NewControl( window , &toolrect , "\p" , true , 0 , behaviour + info.contentType , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; ::SetControlData( m_controlHandle , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; } else { - m_controlHandle = ::NewControl( window , &toolrect , "\p" , false , 0 , + m_controlHandle = ::NewControl( window , &toolrect , "\p" , true , 0 , behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; } + InstallControlEventHandler( (ControlRef) m_controlHandle, GetwxMacToolBarToolEventHandlerUPP(), + GetEventTypeCount(eventList), eventList, this,NULL); UMAShowControl( m_controlHandle ) ; if ( !IsEnabled() ) { @@ -214,7 +262,7 @@ wxToolBarTool::wxToolBarTool(wxToolBar *tbar, ::SetControl32BitValue( m_controlHandle , 0 ) ; } - ControlHandle container = (ControlHandle) tbar->MacGetContainerForEmbedding() ; + ControlRef container = (ControlRef) tbar->GetHandle() ; wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; ::EmbedControl( m_controlHandle , container ) ; } @@ -249,42 +297,8 @@ void wxToolBar::Init() bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { - int x = pos.x; - int y = pos.y; - int width = size.x; - int height = size.y; - - if (width <= 0) - width = 100; - if (height <= 0) - height = 30; - if (x < 0) - x = 0; - if (y < 0) - y = 0; - - SetName(name); - - m_windowStyle = style; - parent->AddChild(this); - - m_backgroundColour = parent->GetBackgroundColour() ; - m_foregroundColour = parent->GetForegroundColour() ; - - if (id == -1) - m_windowId = NewControlId(); - else - m_windowId = id; - - { - m_width = size.x ; - m_height = size.y ; - int x = pos.x ; - int y = pos.y ; - AdjustForParentClientOrigin(x, y, wxSIZE_USE_EXISTING); - m_x = x ; - m_y = y ; - } + if ( !wxToolBarBase::Create( parent , id , pos , size , style ) ) + return FALSE ; return TRUE; } @@ -376,7 +390,7 @@ bool wxToolBar::Realize() m_maxWidth = maxWidth ; } - SetSize(maxWidth, maxHeight); + SetSize( maxWidth, maxHeight ); return TRUE; } @@ -404,7 +418,7 @@ void wxToolBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , { if ( tool->CanBeToggled() ) { - tool->Toggle( GetControl32BitValue( (ControlHandle) control ) ) ; + tool->Toggle( GetControl32BitValue( (ControlRef) control ) ) ; } OnLeftClick( tool->GetId() , tool -> IsToggled() ) ; break ; @@ -471,9 +485,9 @@ void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) else if ( tool->IsButton() ) { if ( enable ) - UMAActivateControl( tool->GetControlHandle() ) ; + UMAActivateControl( (ControlRef) tool->GetControlHandle() ) ; else - UMADeactivateControl( tool->GetControlHandle() ) ; + UMADeactivateControl( (ControlRef) tool->GetControlHandle() ) ; } } @@ -485,7 +499,7 @@ void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) wxToolBarTool *tool = (wxToolBarTool *)t; if ( tool->IsButton() ) { - ::SetControl32BitValue( tool->GetControlHandle() , toggle ) ; + ::SetControl32BitValue( (ControlRef) tool->GetControlHandle() , toggle ) ; } } @@ -547,10 +561,19 @@ void wxToolBar::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this) ; wxMacPortSetter helper(&dc) ; + int w, h ; + GetSize( &w , &h ) ; Rect toolbarrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , - dc.YLOG2DEVMAC(m_height) , dc.XLOG2DEVMAC(m_width) } ; + dc.YLOG2DEVMAC(h) , dc.XLOG2DEVMAC(w) } ; +/* + if( toolbarrect.left < 0 ) + toolbarrect.left = 0 ; + if ( toolbarrect.top < 0 ) + toolbarrect.top = 0 ; +*/ UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; +/* { wxToolBarToolsList::Node *node; for ( node = m_tools.GetFirst(); node; node = node->GetNext() ) @@ -558,10 +581,12 @@ void wxToolBar::OnPaint(wxPaintEvent& event) wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ; if ( tool->IsButton() ) { - UMADrawControl( tool->GetControlHandle() ) ; + UMADrawControl( (ControlRef) tool->GetControlHandle() ) ; } } } +*/ + event.Skip() ; } void wxToolBar::OnMouse( wxMouseEvent &event ) @@ -574,10 +599,10 @@ void wxToolBar::OnMouse( wxMouseEvent &event ) MacClientToRootWindow( &x , &y ) ; - ControlHandle control ; + ControlRef control ; Point localwhere ; SInt16 controlpart ; - WindowRef window = (WindowRef) MacGetRootWindow() ; + WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; localwhere.h = x ; localwhere.v = y ; @@ -608,7 +633,7 @@ void wxToolBar::OnMouse( wxMouseEvent &event ) wxTheApp->s_lastMouseDown = 0 ; if ( control && controlpart != kControlNoPart ) // otherwise we will get the event twice { - MacHandleControlClick( control , controlpart , false /* not down anymore */ ) ; + MacHandleControlClick((WXWidget) control , controlpart , false /* not down anymore */ ) ; } } } diff --git a/src/mac/carbon/tooltip.cpp b/src/mac/carbon/tooltip.cpp index f269196711..934ef3e624 100644 --- a/src/mac/carbon/tooltip.cpp +++ b/src/mac/carbon/tooltip.cpp @@ -154,7 +154,7 @@ void wxToolTip::RelayEvent( wxWindow *win , wxMouseEvent &event ) s_ToolTipArea = wxRect2DInt( event.m_x - 2 , event.m_y - 2 , 4 , 4 ) ; s_LastWindowEntered = win ; - WindowRef window = MAC_WXHWND( win->MacGetRootWindow() ) ; + WindowRef window = MAC_WXHWND( win->MacGetTopLevelWindowRef() ) ; int x = event.m_x ; int y = event.m_y ; wxPoint local( x , y ) ; diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index 878c27f2a9..6d038b6fa8 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -48,12 +48,6 @@ #include - -#define wxMAC_DEBUG_REDRAW 0 -#ifndef wxMAC_DEBUG_REDRAW -#define wxMAC_DEBUG_REDRAW 0 -#endif - // ---------------------------------------------------------------------------- // globals // ---------------------------------------------------------------------------- @@ -61,50 +55,49 @@ // list of all frames and modeless dialogs wxWindowList wxModelessWindows; -// double click testing -static Point gs_lastWhere; -static long gs_lastWhen = 0; - - -#if TARGET_CARBON static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); -#endif // ============================================================================ // wxTopLevelWindowMac implementation // ============================================================================ +BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase) +END_EVENT_TABLE() + + // --------------------------------------------------------------------------- // Carbon Events // --------------------------------------------------------------------------- -#if TARGET_CARBON - extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; static const EventTypeSpec eventList[] = { + // TODO remove control related event like key and mouse (except for WindowLeave events) +#if !TARGET_API_MAC_OSX { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , { kEventClassKeyboard, kEventRawKeyDown } , { kEventClassKeyboard, kEventRawKeyRepeat } , { kEventClassKeyboard, kEventRawKeyUp } , { kEventClassKeyboard, kEventRawKeyModifiersChanged } , +#endif { kEventClassWindow , kEventWindowShown } , - { kEventClassWindow , kEventWindowUpdate } , { kEventClassWindow , kEventWindowActivated } , { kEventClassWindow , kEventWindowDeactivated } , { kEventClassWindow , kEventWindowBoundsChanging } , { kEventClassWindow , kEventWindowBoundsChanged } , { kEventClassWindow , kEventWindowClose } , + // we have to catch these events on the toplevel window level, as controls don't get the + // raw mouse events anymore + { kEventClassMouse , kEventMouseDown } , { kEventClassMouse , kEventMouseUp } , { kEventClassMouse , kEventMouseWheelMoved } , { kEventClassMouse , kEventMouseMoved } , { kEventClassMouse , kEventMouseDragged } , - } ; static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) @@ -135,7 +128,7 @@ static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , Even wxControl* control = wxDynamicCast( focus , wxControl ) ; if ( control ) { - ControlHandle macControl = (ControlHandle) control->GetMacControl() ; + ControlRef macControl = (ControlRef) control->GetHandle() ; if ( macControl ) { ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; @@ -247,128 +240,296 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event return result ; } -pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) -{ - OSStatus result = eventNotHandledErr ; +// we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr +// for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the +// mouse down at all - wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; - Point point ; - UInt32 modifiers = 0; - EventMouseButton button = 0 ; - UInt32 click = 0 ; +// This handler can also be called from app level where data (ie target window) may be null or a non wx window - GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, - sizeof( Point ), NULL, &point ); - GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, - sizeof( UInt32 ), NULL, &modifiers ); - GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL, - sizeof( EventMouseButton ), NULL, &button ); - GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL, - sizeof( UInt32 ), NULL, &click ); - - if ( button == 0 || GetEventKind( event ) == kEventMouseUp ) - modifiers += btnState ; - - // temporary hack to support true two button mouse - if ( button == kEventMouseButtonSecondary ) - { - modifiers |= controlKey ; - } - WindowRef window ; - short windowPart = ::FindWindow(point, &window); +wxWindow* g_MacLastWindow = NULL ; - // either we really are active or we are capturing mouse events +static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) +{ + UInt32 modifiers = cEvent.GetParameter(kEventParamKeyModifiers, typeUInt32) ; + Point screenMouseLocation = cEvent.GetParameter(kEventParamMouseLocation) ; - if ( (IsWindowActive(window) && windowPart == inContent) || - (wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindow() == toplevelWindow) ) + // this parameter are not given for all events + EventMouseButton button = 0 ; + UInt32 clickCount = 0 ; + cEvent.GetParameter(kEventParamMouseButton, typeMouseButton , &button) ; + cEvent.GetParameter(kEventParamClickCount, typeUInt32 , &clickCount ) ; + + wxevent.m_x = screenMouseLocation.h; + wxevent.m_y = screenMouseLocation.v; + wxevent.m_shiftDown = modifiers & shiftKey; + wxevent.m_controlDown = modifiers & controlKey; + wxevent.m_altDown = modifiers & optionKey; + wxevent.m_metaDown = modifiers & cmdKey; + wxevent.SetTimestamp( cEvent.GetTicks() ) ; + // a control click is interpreted as a right click + if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) ) { - switch ( GetEventKind( event ) ) + button = kEventMouseButtonSecondary ; + } + + // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers + // this button + if ( button != 0 && cEvent.GetKind() != kEventMouseUp ) + { + switch( button ) { - case kEventMouseDown : - toplevelWindow->MacFireMouseEvent( mouseDown , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; - result = noErr ; + case kEventMouseButtonPrimary : + wxevent.m_leftDown = true ; break ; - case kEventMouseUp : - toplevelWindow->MacFireMouseEvent( mouseUp , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; - result = noErr ; + case kEventMouseButtonSecondary : + wxevent.m_rightDown = true ; break ; - case kEventMouseMoved : - wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; - result = noErr ; + case kEventMouseButtonTertiary : + wxevent.m_middleDown = true ; break ; - case kEventMouseDragged : - toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; - result = noErr ; - break ; - case kEventMouseWheelMoved : + } + } + // determinate the correct click button + if ( button == kEventMouseButtonSecondary ) + { + if (cEvent.GetKind() == kEventMouseDown ) + wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DOWN : wxEVT_RIGHT_DCLICK ) ; + else if ( cEvent.GetKind() == kEventMouseUp ) + wxevent.SetEventType(wxEVT_RIGHT_UP ) ; + } + else if ( button == kEventMouseButtonTertiary ) + { + if (cEvent.GetKind() == kEventMouseDown ) + wxevent.SetEventType(clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ; + else if ( cEvent.GetKind() == kEventMouseUp ) + wxevent.SetEventType(wxEVT_MIDDLE_UP ) ; + } + else + { + if (cEvent.GetKind() == kEventMouseDown ) + wxevent.SetEventType(clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ; + else if ( cEvent.GetKind() == kEventMouseUp ) + wxevent.SetEventType(wxEVT_LEFT_UP ) ; + else if ( cEvent.GetKind() == kEventMouseWheelMoved ) + { + wxevent.SetEventType(wxEVT_MOUSEWHEEL ) ; + + // EventMouseWheelAxis axis = cEvent.GetParameter(kEventParamMouseWheelAxis, typeMouseWheelAxis) ; + SInt32 delta = cEvent.GetParameter(kEventParamMouseWheelDelta, typeLongInteger) ; + + wxevent.m_wheelRotation = delta; + wxevent.m_wheelDelta = 1; + wxevent.m_linesPerAction = 1; + } + else + wxevent.SetEventType(wxEVT_MOTION ) ; + } +} + +ControlRef wxMacFindSubControl( Point location , ControlRef superControl , ControlPartCode *outPart ) +{ + if ( superControl ) + { + UInt16 childrenCount = 0 ; + OSStatus err = CountSubControls( superControl , &childrenCount ) ; + if ( err == errControlIsNotEmbedder ) + return NULL ; + wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; + + for ( UInt16 i = childrenCount ; i >=1 ; --i ) + { + ControlHandle sibling ; + err = GetIndexedSubControl( superControl , i , & sibling ) ; + if ( err == errControlIsNotEmbedder ) + return NULL ; + + wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; + if ( IsControlVisible( sibling ) ) + { + Rect r ; + GetControlBounds( sibling , &r ) ; + if ( MacPtInRect( location , &r ) ) { - //bClearTooltip = false; - EventMouseWheelAxis axis = kEventMouseWheelAxisY; - SInt32 delta = 0; - Point mouseLoc = {0, 0}; - if (::GetEventParameter(event, kEventParamMouseWheelAxis, typeMouseWheelAxis, - NULL, sizeof(EventMouseWheelAxis), NULL, &axis) == noErr && - ::GetEventParameter(event, kEventParamMouseWheelDelta, typeLongInteger, - NULL, sizeof(SInt32), NULL, &delta) == noErr && - ::GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, - NULL, sizeof(Point), NULL, &mouseLoc) == noErr) + ControlHandle child = wxMacFindSubControl( location , sibling , outPart ) ; + if ( child ) + return child ; + else { - wxMouseEvent wheelEvent(wxEVT_MOUSEWHEEL); - - wheelEvent.m_x = mouseLoc.h; - wheelEvent.m_y = mouseLoc.v; - - wheelEvent.m_wheelRotation = delta; - wheelEvent.m_wheelDelta = 1; - wheelEvent.m_linesPerAction = 1; - - wxWindow* currentMouseWindow = NULL; - wxWindow::MacGetWindowFromPoint(wxPoint(mouseLoc.h, mouseLoc.v), ¤tMouseWindow); - - if (currentMouseWindow) - { - currentMouseWindow->GetEventHandler()->ProcessEvent(wheelEvent); - result = noErr; - } + *outPart = TestControl( sibling , location ) ; + return sibling ; } } - break ; - default : - break ; + } } } + return NULL ; +} - return result ; +ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart ) +{ +#if TARGET_API_MAC_OSX + return FindControlUnderMouse( location , window , outPart ) ; +#else + ControlRef rootControl = NULL ; + verify_noerr( GetRootControl( window , &rootControl ) ) ; + return wxMacFindSubControl( location , rootControl , outPart ) ; +#endif +} +pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +{ + + OSStatus result = eventNotHandledErr ; + + wxMacCarbonEvent cEvent( event ) ; + + Point screenMouseLocation = cEvent.GetParameter(kEventParamMouseLocation) ; + Point windowMouseLocation = screenMouseLocation ; + + WindowRef window ; + short windowPart = ::FindWindow(screenMouseLocation, &window); + + wxWindow* currentMouseWindow = NULL ; + if ( window ) + { + // calculate window relative coordinates + GrafPtr port; + ::GetPort( &port ) ; + ::SetPort( UMAGetWindowPort(window ) ) ; + ::GlobalToLocal( &windowMouseLocation ) ; + ::SetPort( port ) ; + + if ( wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent ) + { + currentMouseWindow = wxTheApp->s_captureWindow ; + } + else if ( (IsWindowActive(window) && windowPart == inContent) ) + { + ControlPartCode part ; + ControlRef control = wxMacFindControlUnderMouse( windowMouseLocation , window , &part ) ; + currentMouseWindow = wxFindControlFromMacControl( control ) ; + } + } + + wxMouseEvent wxevent(wxEVT_LEFT_DOWN); + SetupMouseEvent( wxevent , cEvent ) ; + + // handle all enter / leave events + + if ( currentMouseWindow != g_MacLastWindow ) + { + if ( g_MacLastWindow ) + { + wxMouseEvent eventleave(wxevent); + eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); + g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); + eventleave.SetEventObject( g_MacLastWindow ) ; + +#if wxUSE_TOOLTIPS + wxToolTip::RelayEvent( g_MacLastWindow , eventleave); +#endif // wxUSE_TOOLTIPS + g_MacLastWindow->GetEventHandler()->ProcessEvent(eventleave); + } + if ( currentMouseWindow ) + { + wxMouseEvent evententer(wxevent); + evententer.SetEventType( wxEVT_ENTER_WINDOW ); + currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); + evententer.SetEventObject( currentMouseWindow ) ; +#if wxUSE_TOOLTIPS + wxToolTip::RelayEvent( currentMouseWindow , evententer); +#endif // wxUSE_TOOLTIPS + currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); + } + g_MacLastWindow = currentMouseWindow ; + } + + if ( windowPart == inMenuBar ) + { + // special case menu bar, as we are having a low-level runloop we must do it ourselves + if ( cEvent.GetKind() == kEventMouseDown ) + { + ::MenuSelect( screenMouseLocation ) ; + result = noErr ; + } + } // if ( windowPart == inMenuBar ) + else if ( currentMouseWindow ) + { + currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ; + + wxevent.SetEventObject( currentMouseWindow ) ; + + // update cursor + + wxWindow* cursorTarget = currentMouseWindow ; + wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ; + + while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) + { + cursorTarget = cursorTarget->GetParent() ; + if ( cursorTarget ) + cursorPoint += cursorTarget->GetPosition() ; + } + // update focus + if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN ) + { + // set focus to this window + if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow) + currentMouseWindow->SetFocus(); + } + + // make tooltips current + + #if wxUSE_TOOLTIPS + if ( wxevent.GetEventType() == wxEVT_MOTION + || wxevent.GetEventType() == wxEVT_ENTER_WINDOW + || wxevent.GetEventType() == wxEVT_LEAVE_WINDOW ) + wxToolTip::RelayEvent( currentMouseWindow , wxevent); + #endif // wxUSE_TOOLTIPS + if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) ) + result = noErr; + if ( cEvent.GetKind() == kEventMouseUp && wxTheApp->s_captureWindow ) + { + wxTheApp->s_captureWindow = NULL ; + // update cursor ? + } + } // else if ( currentMouseWindow ) + return result ; } -static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) + +static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; - OSStatus err = noErr ; - UInt32 attributes; - WindowRef windowRef ; + wxMacCarbonEvent cEvent( event ) ; + + // WindowRef windowRef = cEvent.GetParameter(kEventParamDirectObject) ; wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; - GetEventParameter( event, kEventParamDirectObject, typeWindowRef, NULL, - sizeof( WindowRef ), NULL, &windowRef ); - switch( GetEventKind( event ) ) { - case kEventWindowUpdate : - if ( !wxPendingDelete.Member(toplevelWindow) ) - toplevelWindow->MacUpdate( EventTimeToTicks( GetEventTime( event ) ) ) ; - result = noErr ; - break ; case kEventWindowActivated : - toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , true) ; + { + toplevelWindow->MacActivate( cEvent.GetTicks() , true) ; + + wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId()); + wxevent.SetTimestamp( cEvent.GetTicks() ) ; + wxevent.SetEventObject(toplevelWindow); + toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); result = noErr ; break ; + } case kEventWindowDeactivated : - toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , false) ; + { + toplevelWindow->MacActivate(cEvent.GetTicks() , false) ; + wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId()); + wxevent.SetTimestamp( cEvent.GetTicks() ) ; + wxevent.SetEventObject(toplevelWindow); + toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); result = noErr ; break ; + } case kEventWindowShown : toplevelWindow->Refresh() ; result = noErr ; @@ -378,63 +539,78 @@ static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRe result = noErr ; break ; case kEventWindowBoundsChanged : - err = GetEventParameter( event, kEventParamAttributes, typeUInt32, - NULL, sizeof( UInt32 ), NULL, &attributes ); - if ( err == noErr ) + { + UInt32 attributes = cEvent.GetParameter(kEventParamAttributes,typeUInt32) ; + Rect newRect = cEvent.GetParameter(kEventParamCurrentBounds) ; + wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; + if ( attributes & kWindowBoundsChangeSizeChanged ) { - Rect newContentRect ; - - GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, - sizeof( newContentRect ), NULL, &newContentRect ); + // according to the other ports we handle this within the OS level + // resize event, not within a wxSizeEvent + wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ; + if ( frame ) + { + #if wxUSE_STATUSBAR + frame->PositionStatusBar(); + #endif + #if wxUSE_TOOLBAR + frame->PositionToolBar(); + #endif + } - toplevelWindow->SetSize( newContentRect.left , newContentRect.top , - newContentRect.right - newContentRect.left , - newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); + wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ; + event.SetEventObject( toplevelWindow ) ; - result = noErr; + toplevelWindow->GetEventHandler()->ProcessEvent(event) ; } + if ( attributes & kWindowBoundsChangeOriginChanged ) + { + wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ; + event.SetEventObject( toplevelWindow ) ; + toplevelWindow->GetEventHandler()->ProcessEvent(event) ; + } + result = noErr ; break ; + } case kEventWindowBoundsChanging : - err = GetEventParameter( event, kEventParamAttributes, typeUInt32, - NULL, sizeof( UInt32 ), NULL, &attributes ); - if ( err == noErr ) - { - Rect newContentRect ; - - GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, - sizeof( newContentRect ), NULL, &newContentRect ); - - wxSize formerSize = toplevelWindow->GetSize() ; - - if ( (attributes & kWindowBoundsChangeSizeChanged ) || - ( attributes & kWindowBoundsChangeOriginChanged ) ) - toplevelWindow->SetSize( newContentRect.left , newContentRect.top , - newContentRect.right - newContentRect.left , - newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); - - int x , y , w , h ; - toplevelWindow->GetPosition( &x , &y ) ; - toplevelWindow->GetSize( &w , &h ) ; - Rect adjustedRect = { y , x , y + h , x + w } ; + { + UInt32 attributes = cEvent.GetParameter(kEventParamAttributes,typeUInt32) ; + Rect newRect = cEvent.GetParameter(kEventParamCurrentBounds) ; + wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; - if ( !EqualRect( &newContentRect , &adjustedRect ) ) + if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) ) + { + // this is a EVT_SIZING not a EVT_SIZE type ! + wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ; + wxevent.SetEventObject( toplevelWindow ) ; + wxRect adjustR = r ; + if ( toplevelWindow->GetEventHandler()->ProcessEvent(wxevent) ) { - SetEventParameter( event , kEventParamCurrentBounds , typeQDRectangle, sizeof( adjustedRect ) , &adjustedRect ) ; + adjustR = wxevent.GetRect() ; } - - if ( toplevelWindow->GetSize() != formerSize ) - toplevelWindow->Update() ; - - result = noErr ; + if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() ) + adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ; + if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxHeight() ) + adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ; + if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() ) + adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ; + if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinHeight() ) + adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ; + Rect adjustedRect = { adjustR.y , adjustR.x , adjustR.y + adjustR.height , adjustR.x + adjustR.width } ; + if ( !EqualRect( &newRect , &adjustedRect ) ) + cEvent.SetParameter( kEventParamCurrentBounds , &adjustedRect ) ; } + + result = noErr ; break ; + } default : break ; } return result ; } -pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; @@ -447,10 +623,10 @@ pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef result = TextInputEventHandler( handler, event , data ) ; break ; case kEventClassWindow : - result = WindowEventHandler( handler, event , data ) ; + result = wxMacTopLevelWindowEventHandler( handler, event , data ) ; break ; case kEventClassMouse : - result = MouseEventHandler( handler, event , data ) ; + result = wxMacTopLevelMouseEventHandler( handler, event , data ) ; break ; default : break ; @@ -458,9 +634,7 @@ pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef return result ; } -DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) - -#endif +DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler ) // --------------------------------------------------------------------------- // wxWindowMac utility functions @@ -468,30 +642,30 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) // Find an item given the Macintosh Window Reference -wxList *wxWinMacWindowList = NULL; -wxTopLevelWindowMac *wxFindWinFromMacWindow(WXWindow inWindowRef) +wxList wxWinMacWindowList(wxKEY_INTEGER); +wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) { - if ( wxWinMacWindowList == NULL ) - return NULL ; - wxNode *node = wxWinMacWindowList->Find((long)inWindowRef); + wxNode *node = wxWinMacWindowList.Find((long)inWindowRef); if (!node) return NULL; return (wxTopLevelWindowMac *)node->GetData(); } -void wxAssociateWinWithMacWindow(WXWindow inWindowRef, wxTopLevelWindowMac *win) +void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ; +void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) { // adding NULL WindowRef is (first) surely a result of an error and // (secondly) breaks menu command processing wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); - if ( !wxWinMacWindowList->Find((long)inWindowRef) ) - wxWinMacWindowList->Append((long)inWindowRef, win); + if ( !wxWinMacWindowList.Find((long)inWindowRef) ) + wxWinMacWindowList.Append((long)inWindowRef, win); } +void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ; void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) { - wxWinMacWindowList->DeleteObject(win); + wxWinMacWindowList.DeleteObject(win); } @@ -499,21 +673,19 @@ void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) // wxTopLevelWindowMac creation // ---------------------------------------------------------------------------- -WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL; wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL; -bool wxTopLevelWindowMac::s_macWindowCompositing = FALSE; void wxTopLevelWindowMac::Init() { m_iconized = m_maximizeOnShow = FALSE; - m_macNoEraseUpdateRgn = NewRgn() ; - m_macNeedsErasing = false ; m_macWindow = NULL ; - m_macUsesCompositing = FALSE ; -#if TARGET_CARBON +#if TARGET_API_MAC_OSX + m_macUsesCompositing = TRUE; +#else + m_macUsesCompositing = FALSE; +#endif m_macEventHandler = NULL ; - #endif } class wxMacDeferredWindowDeleter : public wxObject @@ -548,6 +720,8 @@ bool wxTopLevelWindowMac::Create(wxWindow *parent, m_windowId = id == -1 ? NewControlId() : id; + MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; + wxTopLevelWindows.Append(this); if ( parent ) @@ -564,20 +738,16 @@ wxTopLevelWindowMac::~wxTopLevelWindowMac() wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; } -#if TARGET_CARBON if ( m_macEventHandler ) { ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); m_macEventHandler = NULL ; } -#endif wxRemoveMacWindowAssociation( this ) ; if ( wxModelessWindows.Find(this) ) wxModelessWindows.DeleteObject(this); - - DisposeRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; } @@ -590,6 +760,12 @@ void wxTopLevelWindowMac::Maximize(bool maximize) wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; wxMacWindowClipper clip (this); ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ; +/* + Rect r ; + GDHandle device = NULL ; + verify_noerr( GetWindowGreatestAreaDevice( (WindowRef) m_macWindow , kWindowContentRgn , + &device , NULL ) ; + verify_noerr( GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ) ; Rect tempRect ; GrafPtr port ; @@ -602,6 +778,7 @@ void wxTopLevelWindowMac::Maximize(bool maximize) GetWindowPortBounds((WindowRef)m_macWindow, &tempRect ) ; SetSize( pt.h , pt.v , tempRect.right-tempRect.left , tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING); +*/ } bool wxTopLevelWindowMac::IsMaximized() const @@ -629,12 +806,27 @@ void wxTopLevelWindowMac::Restore() // wxTopLevelWindowMac misc // ---------------------------------------------------------------------------- +wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const +{ + return wxPoint(0,0) ; +} + void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) { // this sets m_icon wxTopLevelWindowBase::SetIcon(icon); } +void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) +{ + wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ; + + if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT && m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme ) + { + SetThemeWindowBackground( (WindowRef) m_macWindow , m_macBackgroundBrush.MacGetTheme() , false ) ; + } +} + void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, const wxPoint& pos, const wxSize& size, @@ -650,17 +842,17 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, Rect theBoundsRect; - m_x = (int)pos.x; - m_y = (int)pos.y; - if ( m_y < 50 ) - m_y = 50 ; - if ( m_x < 20 ) - m_x = 20 ; + int x = (int)pos.x; + int y = (int)pos.y; + if ( y < 50 ) + y = 50 ; + if ( x < 20 ) + x = 20 ; - m_width = WidthDefault(size.x); - m_height = HeightDefault(size.y); + int w = WidthDefault(size.x); + int h = HeightDefault(size.y); - ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); + ::SetRect(&theBoundsRect, x, y , x + w, y + h); // translate the window attributes in the appropriate window class and attributes @@ -683,11 +875,7 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, } else { -#if TARGET_CARBON wclass = kPlainWindowClass ; -#else - wclass = kFloatingWindowClass ; -#endif } } else if ( HasFlag( wxCAPTION ) ) @@ -703,11 +891,7 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, } else { -#if TARGET_CARBON wclass = kPlainWindowClass ; -#else - wclass = kModalWindowClass ; -#endif } } @@ -730,33 +914,17 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, if (UMAGetSystemVersion() >= 0x1000) { - //turn on live resizing (OS X only) + // turn on live resizing (OS X only) attr |= kWindowLiveResizeAttribute; } -#if TARGET_CARBON -#if 0 // having problems right now with that if (HasFlag(wxSTAY_ON_TOP)) wclass = kUtilityWindowClass; -#endif -#endif - //this setup lets us have compositing and non-compositing - //windows in the same application. - -#if UNIVERSAL_INTERFACES_VERSION >= 0x0400 - if ( wxTopLevelWindowMac::s_macWindowCompositing ) - { - attr |= kWindowCompositingAttribute; - m_macUsesCompositing = TRUE; - } - else +#if TARGET_API_MAC_OSX + attr |= kWindowCompositingAttribute; #endif - { - m_macUsesCompositing = FALSE; - } -#if TARGET_CARBON if ( HasFlag(wxFRAME_SHAPED) ) { WindowDefSpec customWindowDefSpec; @@ -768,122 +936,45 @@ void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, (WindowRef*) &m_macWindow); } else -#endif { err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; } wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); - wxAssociateWinWithMacWindow( m_macWindow , this ) ; - UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ; - if ( wxTopLevelWindowMac::s_macWindowCompositing ) + wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ; + UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ; + if ( m_macUsesCompositing ) { - ::GetRootControl( (WindowRef)m_macWindow, (ControlHandle*)&m_macRootControl ) ; + ::GetRootControl( (WindowRef)m_macWindow, (ControlRef*)&m_macControl ) ; } else { - ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ; + ::CreateRootControl( (WindowRef)m_macWindow , (ControlRef*)&m_macControl ) ; + MacInstallEventHandler() ; } -#if TARGET_CARBON + InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; - InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(), + InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(), GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler); -#endif - m_macFocus = NULL ; + m_macFocus = NULL ; -#if TARGET_CARBON if ( HasFlag(wxFRAME_SHAPED) ) { // default shape matches the window size - wxRegion rgn(0, 0, m_width, m_height); + wxRegion rgn(0, 0, w, h); SetShape(rgn); } -#endif wxWindowCreateEvent event(this); GetEventHandler()->ProcessEvent(event); } -bool wxTopLevelWindowMac::MacEnableCompositing( bool useCompositing ) -{ - bool oldval = s_macWindowCompositing; - s_macWindowCompositing = useCompositing; - return oldval; -} - -void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXHWND *window , wxWindowMac** rootwin) -{ - ((Point*)localOrigin)->h = 0; - ((Point*)localOrigin)->v = 0; - ((Rect*)clipRect)->left = 0; - ((Rect*)clipRect)->top = 0; - ((Rect*)clipRect)->right = m_width; - ((Rect*)clipRect)->bottom = m_height; - *window = m_macWindow ; - *rootwin = this ; -} - void wxTopLevelWindowMac::ClearBackground() { wxWindow::ClearBackground() ; } -WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding() -{ - return m_macRootControl ; -} - - -void wxTopLevelWindowMac::MacUpdate( long timestamp) -{ - wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; - - RgnHandle visRgn = NewRgn() ; - GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), visRgn ); - BeginUpdate( (WindowRef)m_macWindow ) ; - - RgnHandle updateRgn = NewRgn(); - RgnHandle diffRgn = NewRgn() ; - - if ( updateRgn && diffRgn ) - { -#if 1 - // macos internal control redraws clean up areas we'd like to redraw ourselves - // therefore we pick the boundary rect and make sure we can redraw it - // this has to be intersected by the visRgn in order to avoid drawing over its own - // boundaries - RgnHandle trueUpdateRgn = NewRgn() ; - Rect trueUpdateRgnBoundary ; - GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), trueUpdateRgn ); - GetRegionBounds( trueUpdateRgn , &trueUpdateRgnBoundary ) ; - RectRgn( updateRgn , &trueUpdateRgnBoundary ) ; - SectRgn( updateRgn , visRgn , updateRgn ) ; - if ( trueUpdateRgn ) - DisposeRgn( trueUpdateRgn ) ; - SetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ) ; -#else - GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); -#endif - DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; - if ( !EmptyRgn( updateRgn ) ) - { - MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn ) ) ; - } - } - if ( updateRgn ) - DisposeRgn( updateRgn ); - if ( diffRgn ) - DisposeRgn( diffRgn ); - if ( visRgn ) - DisposeRgn( visRgn ) ; - - EndUpdate( (WindowRef)m_macWindow ) ; - SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ; - m_macNeedsErasing = false ; -} - - // Raise the window to the top of the Z order void wxTopLevelWindowMac::Raise() { @@ -896,142 +987,6 @@ void wxTopLevelWindowMac::Lower() ::SendBehind( (WindowRef)m_macWindow , NULL ) ; } -void wxTopLevelWindowMac::MacFireMouseEvent( - wxUint16 kind , wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp ) -{ - wxMouseEvent event(wxEVT_LEFT_DOWN); - bool isDown = !(modifiers & btnState) ; // 1 is for up - bool controlDown = modifiers & controlKey ; // for simulating right mouse - - event.m_leftDown = isDown && !controlDown; - - event.m_middleDown = FALSE; - event.m_rightDown = isDown && controlDown; - - if ( kind == mouseDown ) - { - if ( controlDown ) - event.SetEventType(wxEVT_RIGHT_DOWN ) ; - else - event.SetEventType(wxEVT_LEFT_DOWN ) ; - } - else if ( kind == mouseUp ) - { - if ( controlDown ) - event.SetEventType(wxEVT_RIGHT_UP ) ; - else - event.SetEventType(wxEVT_LEFT_UP ) ; - } - else - { - event.SetEventType(wxEVT_MOTION ) ; - } - - event.m_shiftDown = modifiers & shiftKey; - event.m_controlDown = modifiers & controlKey; - event.m_altDown = modifiers & optionKey; - event.m_metaDown = modifiers & cmdKey; - - Point localwhere ; - localwhere.h = x ; - localwhere.v = y ; - - GrafPtr port ; - ::GetPort( &port ) ; - ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ; - ::GlobalToLocal( &localwhere ) ; - ::SetPort( port ) ; - - if ( kind == mouseDown ) - { - if ( timestamp - gs_lastWhen <= (long) GetDblTime() ) - { - if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 ) - { - // This is not right if the second mouse down - // event occured in a differen window. We - // correct this in MacDispatchMouseEvent. - if ( controlDown ) - event.SetEventType(wxEVT_RIGHT_DCLICK ) ; - else - event.SetEventType(wxEVT_LEFT_DCLICK ) ; - } - gs_lastWhen = 0 ; - } - else - { - gs_lastWhen = timestamp ; - } - gs_lastWhere = localwhere ; - } - - event.m_x = localwhere.h; - event.m_y = localwhere.v; - event.m_x += m_x; - event.m_y += m_y; - - event.m_timeStamp = timestamp; - event.SetEventObject(this); - if ( wxTheApp->s_captureWindow ) - { - int x = event.m_x ; - int y = event.m_y ; - wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; - event.m_x = x ; - event.m_y = y ; - event.SetEventObject( wxTheApp->s_captureWindow ) ; - wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; - - if ( kind == mouseUp ) - { - wxTheApp->s_captureWindow = NULL ; - if ( !wxIsBusy() ) - { - m_cursor.MacInstall() ; - } - } - } - else - { - MacDispatchMouseEvent( event ) ; - } -} - -#if !TARGET_CARBON - -void wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part) -{ - MacFireMouseEvent( mouseDown , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , - ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; -} - -void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part) -{ - switch (part) - { - case inContent: - { - MacFireMouseEvent( mouseUp , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , - ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; - } - break ; - } -} - -void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part) -{ - switch (part) - { - case inContent: - { - MacFireMouseEvent( nullEvent /*moved*/ , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v , - ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ; - } - break ; - } -} - -#endif void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp) { @@ -1049,37 +1004,8 @@ void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) if(s_macDeactivateWindow==this) s_macDeactivateWindow=NULL; MacDelayedDeactivation(timestamp); - wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); - event.m_timeStamp = timestamp ; - event.SetEventObject(this); - - GetEventHandler()->ProcessEvent(event); - - UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ; - - // Early versions of MacOS X don't refresh backgrounds properly, - // so refresh the whole window on activation and deactivation. - long osVersion = UMAGetSystemVersion(); - if (osVersion >= 0x1000 && osVersion < 0x1020 ) - { - Refresh(TRUE); - } - else - { - // for the moment we have to resolve some redrawing issues like this - // the OS is stealing some redrawing areas as soon as it draws a control - Refresh(TRUE); - } -} - -#if !TARGET_CARBON - -void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev ) -{ } -#endif - void wxTopLevelWindowMac::SetTitle(const wxString& title) { wxWindow::SetTitle( title ) ; @@ -1088,7 +1014,7 @@ void wxTopLevelWindowMac::SetTitle(const wxString& title) bool wxTopLevelWindowMac::Show(bool show) { - if ( !wxWindow::Show(show) ) + if ( !wxTopLevelWindowBase::Show(show) ) return FALSE; if (show) @@ -1104,10 +1030,8 @@ bool wxTopLevelWindowMac::Show(bool show) ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); } ::SelectWindow( (WindowRef)m_macWindow ) ; - // no need to generate events here, they will get them triggered by macos - // actually they should be , but apparently they are not - wxSize size(m_width, m_height); - wxSizeEvent event(size, m_windowId); + // as apps expect a size event to occur at this moment + wxSizeEvent event( GetSize() , m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); } @@ -1125,178 +1049,77 @@ bool wxTopLevelWindowMac::Show(bool show) } } - if ( !show ) - { - } - else - { - Refresh() ; - } + MacPropagateVisibilityChanged() ; - return TRUE; + return TRUE ; } +// we are still using coordinates of the content view, todo switch to structure bounds + void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) { - wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; - wxMacWindowClipper clip (this); - - int former_x = m_x ; - int former_y = m_y ; - int former_w = m_width ; - int former_h = m_height ; - - int actualWidth = width; - int actualHeight = height; - int actualX = x; - int actualY = y; - - if ((m_minWidth != -1) && (actualWidth < m_minWidth)) - actualWidth = m_minWidth; - if ((m_minHeight != -1) && (actualHeight < m_minHeight)) - actualHeight = m_minHeight; - if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) - actualWidth = m_maxWidth; - if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) - actualHeight = m_maxHeight; - - bool doMove = false ; - bool doResize = false ; - - if ( actualX != former_x || actualY != former_y ) - { - doMove = true ; - } - if ( actualWidth != former_w || actualHeight != former_h ) - { - doResize = true ; - } - - if ( doMove || doResize ) - { - m_x = actualX ; - m_y = actualY ; - - if ( doMove ) - ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost - - m_width = actualWidth ; - m_height = actualHeight ; - - if ( doResize ) - ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true); - - // the OS takes care of invalidating and erasing the new area so we only have to - // take care of refreshing for full repaints - - if ( doResize && HasFlag(wxFULL_REPAINT_ON_RESIZE) ) - Refresh() ; - - - if ( IsKindOf( CLASSINFO( wxFrame ) ) ) - { - wxFrame* frame = (wxFrame*) this ; -#if wxUSE_STATUSBAR - frame->PositionStatusBar(); -#endif -#if wxUSE_TOOLBAR - frame->PositionToolBar(); -#endif - } - if ( doMove ) - wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified - - MacRepositionScrollBars() ; - if ( doMove ) - { - wxPoint point(m_x, m_y); - wxMoveEvent event(point, m_windowId); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event) ; - } - if ( doResize ) - { - MacRepositionScrollBars() ; - wxSize size(m_width, m_height); - wxSizeEvent event(size, m_windowId); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); - } - } - + Rect bounds = { y , x , y + height , x + width } ; + verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; } -/* - * Invalidation Mechanism - * - * The update mechanism reflects exactely the windows mechanism - * the rect gets added to the window invalidate region, if the eraseBackground flag - * has been true for any part of the update rgn the background is erased in the entire region - * not just in the specified rect. - * - * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have - * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event - * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window - * will get the eraseBackground event first - */ - -void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground ) +void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const { - GrafPtr formerPort ; - GetPort( &formerPort ) ; - SetPortWindowPort( (WindowRef)m_macWindow ) ; + Rect bounds ; + verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; + if(x) *x = bounds.left ; + if(y) *y = bounds.top ; +} +void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const +{ + Rect bounds ; + verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; + if(width) *width = bounds.right - bounds.left ; + if(height) *height = bounds.bottom - bounds.top ; +} - m_macNeedsErasing |= eraseBackground ; +void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const +{ + Rect bounds ; + verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ; + if(width) *width = bounds.right - bounds.left ; + if(height) *height = bounds.bottom - bounds.top ; +} - // if we already know that we will have to erase, there's no need to track the rest - if ( !m_macNeedsErasing) - { - // we end only here if eraseBackground is false - // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn - // we will have to erase anyway +void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) +{ +#if TARGET_API_MAC_OSX + UInt32 attr = 0 ; + GetWindowAttributes((WindowRef) m_macWindow , &attr ) ; + wxASSERT_MSG( attr & kWindowCompositingAttribute , + wxT("Cannot set metal appearance on a non-compositing window") ) ; + + MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , + set ? kWindowNoAttributes : kWindowMetalAttribute ) ; +#endif +} - RgnHandle updateRgn = NewRgn(); - RgnHandle diffRgn = NewRgn() ; - if ( updateRgn && diffRgn ) - { - GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn ); - Point pt = {0,0} ; - LocalToGlobal( &pt ) ; - OffsetRgn( updateRgn , -pt.h , -pt.v ) ; - DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; - if ( !EmptyRgn( diffRgn ) ) - { - m_macNeedsErasing = true ; - } - } - if ( updateRgn ) - DisposeRgn( updateRgn ); - if ( diffRgn ) - DisposeRgn( diffRgn ); +void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) +{ + ChangeWindowAttributes ( (WindowRef) m_macWindow , attributesToSet, attributesToClear ) ; +} - if ( !m_macNeedsErasing ) - { - RgnHandle rectRgn = NewRgn() ; - SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ; - UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ; - DisposeRgn( rectRgn ) ; - } - } - InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ; - // turn this on to debug the refreshing cycle -#if wxMAC_DEBUG_REDRAW - PaintRect( rect ) ; -#endif - SetPort( formerPort ) ; +wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const +{ + UInt32 attr = 0 ; + GetWindowAttributes((WindowRef) m_macWindow , &attr ) ; + return attr ; } +// --------------------------------------------------------------------------- +// Shape implementation +// --------------------------------------------------------------------------- + bool wxTopLevelWindowMac::SetShape(const wxRegion& region) { wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); -#if TARGET_CARBON // The empty region signifies that the shape should be removed from the // window. if ( region.IsEmpty() ) @@ -1321,9 +1144,6 @@ bool wxTopLevelWindowMac::SetShape(const wxRegion& region) // Tell the window manager that the window has changed shape ReshapeCustomWindow((WindowRef)MacGetWindowRef()); return TRUE; -#else - return FALSE; -#endif } // --------------------------------------------------------------------------- @@ -1331,8 +1151,6 @@ bool wxTopLevelWindowMac::SetShape(const wxRegion& region) // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm // --------------------------------------------------------------------------- -#if TARGET_CARBON - static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) { GetWindowPortBounds(window, inRect); @@ -1458,6 +1276,5 @@ static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 return 0; } -#endif // --------------------------------------------------------------------------- diff --git a/src/mac/carbon/uma.cpp b/src/mac/carbon/uma.cpp index 48a7599f04..aedb25e274 100644 --- a/src/mac/carbon/uma.cpp +++ b/src/mac/carbon/uma.cpp @@ -165,21 +165,13 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls, bool isEmbedded ) } ; int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ; - // kTXNAlwaysUseQuickDrawTextMask might be desirable because of speed increases but it crashes the app under OS X upon key stroke -#if 0 - // leads to unexpected content for clients, TODO configurable - OptionBits options = kTXNWantMoviesMask | kTXNWantSoundMask | kTXNWantGraphicsMask ; -#else OptionBits options = 0 ; -#endif -#if TARGET_CARBON - if ( !UMAHasAquaLayout() ) -#endif + if ( UMAGetSystemVersion() < 0x1000 ) { options |= kTXNAlwaysUseQuickDrawTextMask ; } - TXNInitTextension(fontDescriptions, noOfFontDescriptions, options ); + TXNInitTextension(fontDescriptions, noOfFontDescriptions, options ); } @@ -517,7 +509,7 @@ void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncodin // appearance additions -void UMASetControlTitle( ControlHandle inControl , const wxString& title , wxFontEncoding encoding) +void UMASetControlTitle( ControlRef inControl , const wxString& title , wxFontEncoding encoding) { #if TARGET_CARBON SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ; @@ -528,8 +520,9 @@ void UMASetControlTitle( ControlHandle inControl , const wxString& title , wxFon #endif } -void UMAActivateControl( ControlHandle inControl ) +void UMAActivateControl( ControlRef inControl ) { +#if !TARGET_API_MAC_OSX // we have to add the control after again to the update rgn // otherwise updates get lost if ( !IsControlActive( inControl ) ) @@ -537,17 +530,24 @@ void UMAActivateControl( ControlHandle inControl ) bool visible = IsControlVisible( inControl ) ; if ( visible ) SetControlVisibility( inControl , false , false ) ; +#endif ::ActivateControl( inControl ) ; +#if !TARGET_API_MAC_OSX if ( visible ) { SetControlVisibility( inControl , true , false ) ; + Rect ctrlBounds ; - InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; + InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ; } } +#endif } -void UMADrawControl( ControlHandle inControl ) +void UMADrawControl( ControlRef inControl ) { +#if TARGET_API_MAC_CARBON + ::Draw1Control( inControl ); +#else WindowRef theWindow = GetControlOwner(inControl) ; wxMacPortStateHelper help( (GrafPtr) GetWindowPort(theWindow) ) ; RgnHandle updateRgn = NewRgn() ; @@ -558,72 +558,85 @@ void UMADrawControl( ControlHandle inControl ) ::DrawControlInCurrentPort( inControl ) ; InvalWindowRgn( theWindow, updateRgn) ; DisposeRgn( updateRgn ) ; +#endif } -void UMAMoveControl( ControlHandle inControl , short x , short y ) +void UMAMoveControl( ControlRef inControl , short x , short y ) { +#if !TARGET_API_MAC_OSX bool visible = IsControlVisible( inControl ) ; if ( visible ) { SetControlVisibility( inControl , false , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; } +#endif ::MoveControl( inControl , x , y ) ; +#if !TARGET_API_MAC_OSX if ( visible ) { SetControlVisibility( inControl , true , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; } +#endif } -void UMASizeControl( ControlHandle inControl , short x , short y ) +void UMASizeControl( ControlRef inControl , short x , short y ) { +#if !TARGET_API_MAC_OSX bool visible = IsControlVisible( inControl ) ; if ( visible ) { SetControlVisibility( inControl , false , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; } +#endif ::SizeControl( inControl , x , y ) ; +#if !TARGET_API_MAC_OSX if ( visible ) { SetControlVisibility( inControl , true , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; } +#endif } -void UMADeactivateControl( ControlHandle inControl ) +void UMADeactivateControl( ControlRef inControl ) { +#if !TARGET_API_MAC_OSX // we have to add the control after again to the update rgn // otherwise updates get lost bool visible = IsControlVisible( inControl ) ; if ( visible ) SetControlVisibility( inControl , false , false ) ; +#endif ::DeactivateControl( inControl ) ; +#if !TARGET_API_MAC_OSX if ( visible ) { SetControlVisibility( inControl , true , false ) ; Rect ctrlBounds ; - InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; + InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ; } +#endif } // shows the control and adds the region to the update region -void UMAShowControl (ControlHandle inControl) +void UMAShowControl (ControlRef inControl) { SetControlVisibility( inControl , true , false ) ; Rect ctrlBounds ; - InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; + InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ; } -// shows the control and adds the region to the update region -void UMAHideControl (ControlHandle inControl) +// hides the control and adds the region to the update region +void UMAHideControl (ControlRef inControl) { SetControlVisibility( inControl , false , false ) ; Rect ctrlBounds ; - InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; + InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ; } // keyboard focus OSErr UMASetKeyboardFocus (WindowPtr inWindow, - ControlHandle inControl, + ControlRef inControl, ControlFocusPart inPart) { OSErr err = noErr; @@ -637,7 +650,6 @@ OSErr UMASetKeyboardFocus (WindowPtr inWindow, return err ; } - // events void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn ) { @@ -682,7 +694,7 @@ void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ) GetPort( &port ) ; SetPortWindowPort( inWindowRef ) ; HiliteWindow( inWindowRef , inActivate ) ; - ControlHandle control = NULL ; + ControlRef control = NULL ; ::GetRootControl( inWindowRef , & control ) ; if ( control ) { @@ -795,6 +807,29 @@ OSStatus UMAPutScrap( Size size , OSType type , void *data ) return err ; } +Rect* UMAGetControlBoundsInWindowCoords(ControlRef theControl, Rect *bounds) +{ + wxWindow* win = wxFindControlFromMacControl( theControl ) ; + + GetControlBounds( theControl , bounds ) ; +#if TARGET_API_MAC_OSX + if ( win != NULL && win->MacGetTopLevelWindow() != NULL ) + { + int x , y ; + x = 0 ; + y = 0 ; + + win->GetParent()->MacWindowToRootWindow( &x , & y ) ; + bounds->left += x ; + bounds->right += x ; + bounds->top += y ; + bounds->bottom += y ; + } +#endif + return bounds ; +} + + #endif // wxUSE_GUI #if wxUSE_BASE diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp index b64f77fae0..45e9cde839 100644 --- a/src/mac/carbon/utils.cpp +++ b/src/mac/carbon/utils.cpp @@ -456,7 +456,6 @@ void wxDisplaySizeMM(int *width, int *height) void wxClientDisplayRect(int *x, int *y, int *width, int *height) { -#if TARGET_CARBON Rect r ; GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ; if ( x ) @@ -467,32 +466,6 @@ void wxClientDisplayRect(int *x, int *y, int *width, int *height) *width = r.right - r.left ; if ( height ) *height = r.bottom - r.top ; -#else - BitMap screenBits; - GetQDGlobalsScreenBits( &screenBits ); - - if (x) *x = 0; - if (y) *y = 0; - - if (width != NULL) { - *width = screenBits.bounds.right - screenBits.bounds.left ; - } - if (height != NULL) { - *height = screenBits.bounds.bottom - screenBits.bounds.top ; - } - - SInt16 mheight ; -#if TARGET_CARBON - GetThemeMenuBarHeight( &mheight ) ; -#else - mheight = LMGetMBarHeight() ; -#endif - if (height != NULL) { - *height -= mheight ; - } - if (y) - *y = mheight ; -#endif } wxWindow* wxFindWindowAtPoint(const wxPoint& pt) @@ -560,6 +533,15 @@ bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree) // wxMac Specific utility functions //--------------------------------------------------------------------------- +Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size ) +{ + int x ,y , w ,h ; + + window->MacGetBoundsForControl( pos , size , x , y, w, h ) ; + Rect bounds = { y , x , y+h , x+w }; + return bounds ; +} + void wxMacStringToPascal( const wxString&from , StringPtr to ) { wxCharBuffer buf = from.mb_str( wxConvLocal ) ; @@ -1251,6 +1233,21 @@ void wxMacConvertNewlines10To13( wxChar * data ) } #endif +// ---------------------------------------------------------------------------- +// Carbon Event Support +// ---------------------------------------------------------------------------- + + +OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) +{ + return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ) ; +} + +OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, void * inData) +{ + return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ) ; +} + // ---------------------------------------------------------------------------- // debugging support // ---------------------------------------------------------------------------- diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index a5c56e4202..d8de01b229 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -23,15 +23,12 @@ #include "wx/panel.h" #include "wx/layout.h" #include "wx/dialog.h" -#include "wx/listbox.h" #include "wx/scrolbar.h" #include "wx/statbox.h" #include "wx/button.h" #include "wx/settings.h" #include "wx/msgdlg.h" #include "wx/frame.h" -#include "wx/notebook.h" -#include "wx/tabctrl.h" #include "wx/tooltip.h" #include "wx/statusbr.h" #include "wx/menuitem.h" @@ -39,6 +36,9 @@ #include "wx/log.h" #include "wx/geometry.h" +#include "wx/toolbar.h" +#include "wx/dc.h" + #if wxUSE_CARET #include "wx/caret.h" #endif // wxUSE_CARET @@ -53,6 +53,10 @@ #include #endif +#ifndef __HIVIEW__ + #include +#endif + #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" #endif @@ -71,12 +75,13 @@ wxWindowMac* gFocusWindow = NULL ; #if !USE_SHARED_LIBRARY BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) - EVT_NC_PAINT(wxWindowMac::OnNcPaint) - EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) - EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged) - EVT_INIT_DIALOG(wxWindowMac::OnInitDialog) - EVT_SET_FOCUS(wxWindowMac::OnSetFocus) - EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) + EVT_NC_PAINT(wxWindowMac::OnNcPaint) + EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) +// TODO EVT_PAINT(wxWindowMac::OnPaint) + EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged) + EVT_INIT_DIALOG(wxWindowMac::OnInitDialog) + EVT_SET_FOCUS(wxWindowMac::OnSetFocus) + EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) END_EVENT_TABLE() #endif @@ -88,14 +93,291 @@ END_EVENT_TABLE() #define wxMAC_USE_THEME_BORDER 0 +// --------------------------------------------------------------------------- +// Carbon Events +// --------------------------------------------------------------------------- + +extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; +pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) ; + +static const EventTypeSpec eventList[] = +{ +#if TARGET_API_MAC_OSX + { kEventClassControl , kEventControlDraw } , +// { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only +// { kEventClassControl , kEventControlBoundsChanged } , +#else + {} +#endif +} ; + +static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +{ + OSStatus result = eventNotHandledErr ; + + wxMacCarbonEvent cEvent( event ) ; + + ControlRef controlRef ; + wxWindowMac* thisWindow = (wxWindowMac*) data ; + + cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; + + switch( GetEventKind( event ) ) + { + case kEventControlDraw : + { + RgnHandle updateRgn = cEvent.GetParameter(kEventParamRgnHandle) ; + // GrafPtr myport = cEvent.GetParameter(kEventParamGrafPort,typeGrafPtr) ; + +#if 0 // in case we would need a coregraphics compliant background erase first + CGContextRef cgContext = cEvent.GetParameter(kEventParamCGContextRef) ; + if ( thisWindow->MacIsUserPane() ) + { + HIRect bounds; + err = HIViewGetBounds( controlRef, &bounds ); + CGContextSetRGBFillColor( cgContext, 1 , 1 , 1 , 1 ); +// CGContextSetRGBFillColor( cgContext, .95, .95, .95, 1 ); + CGContextFillRect( cgContext, bounds ); + } +#endif + if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) ) + result = noErr ; + else + result = eventNotHandledErr; + } + break ; + default : + break ; + } + return result ; +} + +pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +{ + OSStatus result = eventNotHandledErr ; + + switch ( GetEventClass( event ) ) + { + case kEventClassControl : + result = wxMacWindowControlEventHandler( handler, event, data ) ; + break ; + default : + break ; + } + return result ; +} + +DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) + +// --------------------------------------------------------------------------- +// UserPane events for non OSX builds +// --------------------------------------------------------------------------- + +static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) +{ + wxWindow * win = wxFindControlFromMacControl(control) ; + wxCHECK_RET( win , wxT("Callback from unkown control") ) ; + win->MacControlUserPaneDrawProc(part) ; +} + +static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) +{ + wxWindow * win = wxFindControlFromMacControl(control) ; + wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ; + return win->MacControlUserPaneHitTestProc(where.h , where.v) ; +} + +static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) +{ + wxWindow * win = wxFindControlFromMacControl(control) ; + wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ; + return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ; +} + +static pascal void wxMacControlUserPaneIdleProc(ControlRef control) +{ + wxWindow * win = wxFindControlFromMacControl(control) ; + wxCHECK_RET( win , wxT("Callback from unkown control") ) ; + win->MacControlUserPaneIdleProc() ; +} + +static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) +{ + wxWindow * win = wxFindControlFromMacControl(control) ; + wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ; + return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ; +} + +static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) +{ + wxWindow * win = wxFindControlFromMacControl(control) ; + wxCHECK_RET( win , wxT("Callback from unkown control") ) ; + win->MacControlUserPaneActivateProc(activating) ; +} + +static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) +{ + wxWindow * win = wxFindControlFromMacControl(control) ; + wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ; + return win->MacControlUserPaneFocusProc(action) ; +} + +static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) +{ + wxWindow * win = wxFindControlFromMacControl(control) ; + wxCHECK_RET( win , wxT("Callback from unkown control") ) ; + win->MacControlUserPaneBackgroundProc(info) ; +} + +void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part) +{ + MacDoRedraw( MacGetVisibleRegion().GetWXHRGN() , 0 ) ; +} + +wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) +{ + return kControlNoPart ; +} + +wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) +{ + return kControlNoPart ; +} + +void wxWindowMac::MacControlUserPaneIdleProc() +{ +} + +wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) +{ + return kControlNoPart ; +} + +void wxWindowMac::MacControlUserPaneActivateProc(bool activating) +{ +} + +wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action) +{ + return kControlNoPart ; +} + +void wxWindowMac::MacControlUserPaneBackgroundProc(void* info) +{ +} + +ControlUserPaneDrawUPP gControlUserPaneDrawUPP = NULL ; +ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP = NULL ; +ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP = NULL ; +ControlUserPaneIdleUPP gControlUserPaneIdleUPP = NULL ; +ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP = NULL ; +ControlUserPaneActivateUPP gControlUserPaneActivateUPP = NULL ; +ControlUserPaneFocusUPP gControlUserPaneFocusUPP = NULL ; +ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP = NULL ; // =========================================================================== // implementation // =========================================================================== +wxList wxWinMacControlList(wxKEY_INTEGER); + +wxWindow *wxFindControlFromMacControl(ControlRef inControl ) +{ + wxNode *node = wxWinMacControlList.Find((long)inControl); + if (!node) + return NULL; + return (wxControl *)node->GetData(); +} + +void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control) +{ + // adding NULL ControlRef is (first) surely a result of an error and + // (secondly) breaks native event processing + wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); + + if ( !wxWinMacControlList.Find((long)inControl) ) + wxWinMacControlList.Append((long)inControl, control); +} + +void wxRemoveMacControlAssociation(wxWindow *control) +{ + wxWinMacControlList.DeleteObject(control); +} + +// UPP functions +ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; + +ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ; + +// we have to setup the brush in the current port and return noErr +// or return an error code so that the control manager walks further up the +// hierarchy to find a correct background + +pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) +{ + OSStatus status = paramErr ; + switch( iMessage ) + { + case kControlMsgApplyTextColor : + break ; + case kControlMsgSetUpBackground : + { + wxWindow* wx = (wxWindow*) wxFindControlFromMacControl( iControl ) ; + if ( wx != NULL ) + { + /* + const wxBrush &brush = wx->MacGetBackgroundBrush() ; + if ( brush.Ok() ) + { + + wxDC::MacSetupBackgroundForCurrentPort( brush ) ; + */ + // this clipping is only needed for non HIView + + RgnHandle clip = NewRgn() ; + int x = 0 , y = 0; + + wx->MacWindowToRootWindow( &x,&y ) ; + CopyRgn( (RgnHandle) wx->MacGetVisibleRegion().GetWXHRGN() , clip ) ; + OffsetRgn( clip , x , y ) ; + SetClip( clip ) ; + DisposeRgn( clip ) ; + + status = noErr ; + /* + } + else if ( wx->MacIsUserPane() ) + { + // if we don't have a valid brush for such a control, we have to call the + // setup of our parent ourselves + status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ; + } + */ + } + } + break ; + default : + break ; + } + return status ; +} + + +pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ; +pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) +{ + if ( partCode != 0) + { + wxWindow* wx = wxFindControlFromMacControl( control ) ; + if ( wx ) + { + wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ; + } + } +} // ---------------------------------------------------------------------------- -// constructors and such + // constructors and such // ---------------------------------------------------------------------------- void wxWindowMac::Init() @@ -105,13 +387,37 @@ void wxWindowMac::Init() // as all windows are created with WS_VISIBLE style... m_isShown = TRUE; - m_x = 0; - m_y = 0 ; - m_width = 0 ; - m_height = 0 ; - m_hScrollBar = NULL ; m_vScrollBar = NULL ; + m_macBackgroundBrush = wxNullBrush ; + + m_macControl = NULL ; + + m_macIsUserPane = TRUE; + + // make sure all proc ptrs are available + + if ( gControlUserPaneDrawUPP == NULL ) + { + gControlUserPaneDrawUPP = NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc ) ; + gControlUserPaneHitTestUPP = NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc ) ; + gControlUserPaneTrackingUPP = NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc ) ; + gControlUserPaneIdleUPP = NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc ) ; + gControlUserPaneKeyDownUPP = NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc ) ; + gControlUserPaneActivateUPP = NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc ) ; + gControlUserPaneFocusUPP = NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc ) ; + gControlUserPaneBackgroundUPP = NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc ) ; + } + if ( wxMacLiveScrollbarActionUPP == NULL ) + { + wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc ); + } + + if ( wxMacSetupControlBackgroundUPP == NULL ) + { + wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ; + } + } // Destructor @@ -119,20 +425,6 @@ wxWindowMac::~wxWindowMac() { SendDestroyEvent(); - // deleting a window while it is shown invalidates the region - if ( IsShown() ) { - wxWindowMac* iter = this ; - while( iter ) { - if ( iter->IsTopLevel() ) - { - Refresh() ; - break ; - } - iter = iter->GetParent() ; - - } - } - m_isBeingDeleted = TRUE; #ifndef __WXUNIVERSAL__ @@ -150,10 +442,28 @@ wxWindowMac::~wxWindowMac() } } #endif // __WXUNIVERSAL__ + + // wxRemoveMacControlAssociation( this ) ; + // If we delete an item, we should initialize the parent panel, + // because it could now be invalid. + wxWindow *parent = GetParent() ; + if ( parent ) + { + if (parent->GetDefaultItem() == (wxButton*) this) + parent->SetDefaultItem(NULL); + } + if ( (ControlRef) m_macControl ) + { + // in case the callback might be called during destruction + wxRemoveMacControlAssociation( this) ; + ::SetControlColorProc( (ControlRef) m_macControl , NULL ) ; + ::DisposeControl( (ControlRef) m_macControl ) ; + m_macControl = NULL ; + } - if ( s_lastMouseWindow == this ) + if ( g_MacLastWindow == this ) { - s_lastMouseWindow = NULL ; + g_MacLastWindow = NULL ; } wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ; @@ -180,6 +490,16 @@ wxWindowMac::~wxWindowMac() #endif // wxUSE_DRAG_AND_DROP } +// + +void wxWindowMac::MacInstallEventHandler() +{ + InstallControlEventHandler( (ControlRef) m_macControl, GetwxMacWindowEventHandlerUPP(), + GetEventTypeCount(eventList), eventList, this, + (EventHandlerRef *)&m_macControlEventHandler); + +} + // Constructor bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, const wxPoint& pos, @@ -189,27 +509,41 @@ bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, { wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") ); -#if wxUSE_STATBOX - // wxGTK doesn't allow to create controls with static box as the parent so - // this will result in a crash when the program is ported to wxGTK - warn - // about it - // - // the correct solution is to create the controls as siblings of the - // static box - wxASSERT_MSG( !wxDynamicCast(parent, wxStaticBox), - _T("wxStaticBox can't be used as a window parent!") ); -#endif // wxUSE_STATBOX - if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) return FALSE; parent->AddChild(this); - m_x = (int)pos.x; - m_y = (int)pos.y; - AdjustForParentClientOrigin(m_x, m_y, wxSIZE_USE_EXISTING); - m_width = WidthDefault( size.x ); - m_height = HeightDefault( size.y ) ; + m_windowVariant = parent->GetWindowVariant() ; + + if ( m_macIsUserPane ) + { + Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; + + UInt32 features = kControlSupportsEmbedding | kControlSupportsLiveFeedback /*| kControlHasSpecialBackground */ | kControlSupportsCalcBestRect | kControlHandlesTracking | kControlSupportsFocus | kControlWantsActivate | kControlWantsIdle; + + ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features, (ControlRef*) &m_macControl); + + MacPostControlCreate(pos,size) ; +#if !TARGET_API_MAC_OSX + SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneDrawProcTag, + sizeof(gControlUserPaneDrawUPP),(Ptr) &gControlUserPaneDrawUPP); + SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneHitTestProcTag, + sizeof(gControlUserPaneHitTestUPP),(Ptr) &gControlUserPaneHitTestUPP); + SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneTrackingProcTag, + sizeof(gControlUserPaneTrackingUPP),(Ptr) &gControlUserPaneTrackingUPP); + SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneIdleProcTag, + sizeof(gControlUserPaneIdleUPP),(Ptr) &gControlUserPaneIdleUPP); + SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneKeyDownProcTag, + sizeof(gControlUserPaneKeyDownUPP),(Ptr) &gControlUserPaneKeyDownUPP); + SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneActivateProcTag, + sizeof(gControlUserPaneActivateUPP),(Ptr) &gControlUserPaneActivateUPP); + SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneFocusProcTag, + sizeof(gControlUserPaneFocusUPP),(Ptr) &gControlUserPaneFocusUPP); + SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneBackgroundProcTag, + sizeof(gControlUserPaneBackgroundUPP),(Ptr) &gControlUserPaneBackgroundUPP); +#endif + } #ifndef __WXUNIVERSAL__ // Don't give scrollbars to wxControls unless they ask for them if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) || @@ -225,6 +559,179 @@ bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, return TRUE; } +void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size) +{ + wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; + + wxAssociateControlWithMacControl( (ControlRef) m_macControl , this ) ; + ::SetControlReference( (ControlRef) m_macControl , (long) this ) ; + + MacInstallEventHandler(); + + ControlRef container = (ControlRef) GetParent()->GetHandle() ; + wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; + ::EmbedControl( (ControlRef) m_macControl , container ) ; + + // adjust font, controlsize etc + DoSetWindowVariant( m_windowVariant ) ; + +#if !TARGET_API_MAC_OSX + // eventually we can fix some clipping issues be reactivating this hook + //if ( m_macIsUserPane ) + // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ; +#endif + + UMASetControlTitle( (ControlRef) m_macControl , wxStripMenuCodes(m_label) , m_font.GetEncoding() ) ; + + wxSize new_size = size ; + if (!m_macIsUserPane) + { + wxSize best_size( DoGetBestSize() ); + + if (size.x == -1) { + new_size.x = best_size.x; + } + if (size.y == -1) { + new_size.y = best_size.y; + } + SetSize( pos.x, pos.y , new_size.x, new_size.y,wxSIZE_USE_EXISTING ); + } + + SetCursor( *wxSTANDARD_CURSOR ) ; + +} + +void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) +{ + wxASSERT( m_macControl != NULL ) ; + + m_windowVariant = variant ; + + ControlSize size ; + ThemeFontID themeFont = kThemeSystemFont ; + + // we will get that from the settings later + // and make this NORMAL later, but first + // we have a few calculations that we must fix + + switch ( variant ) + { + case wxWINDOW_VARIANT_NORMAL : + size = kControlSizeNormal; + themeFont = kThemeSystemFont ; + break ; + case wxWINDOW_VARIANT_SMALL : + size = kControlSizeSmall; + themeFont = kThemeSmallSystemFont ; + break ; + case wxWINDOW_VARIANT_MINI : + if (UMAGetSystemVersion() >= 0x1030 ) + { + // not always defined in the headers + size = 3 ; + themeFont = 109 ; + } + else + { + size = kControlSizeSmall; + themeFont = kThemeSmallSystemFont ; + } + break ; + case wxWINDOW_VARIANT_LARGE : + size = kControlSizeLarge; + themeFont = kThemeSystemFont ; + break ; + default: + wxFAIL_MSG(_T("unexpected window variant")); + break ; + } + ::SetControlData( (ControlRef) m_macControl , kControlEntireControl, kControlSizeTag, sizeof( ControlSize ), &size ); + + wxFont font ; + font.MacCreateThemeFont( themeFont ) ; + SetFont( font ) ; +} + +void wxWindowMac::MacUpdateControlFont() +{ + ControlFontStyleRec fontStyle; + if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont ) + { + switch( m_font.MacGetThemeFontID() ) + { + case kThemeSmallSystemFont : fontStyle.font = kControlFontSmallSystemFont ; break ; + case 109 /*mini font */ : fontStyle.font = -5 ; break ; + case kThemeSystemFont : fontStyle.font = kControlFontBigSystemFont ; break ; + default : fontStyle.font = kControlFontBigSystemFont ; break ; + } + fontStyle.flags = kControlUseFontMask ; + } + else + { + fontStyle.font = m_font.MacGetFontNum() ; + fontStyle.style = m_font.MacGetFontStyle() ; + fontStyle.size = m_font.MacGetFontSize() ; + fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask ; + } + fontStyle.foreColor = MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ; + fontStyle.flags |= kControlUseForeColorMask ; + ::SetControlFontStyle( (ControlRef) m_macControl , &fontStyle ); + Refresh() ; +} + +bool wxWindowMac::SetFont(const wxFont& font) +{ + bool retval = !wxWindowBase::SetFont( font ) ; + + MacUpdateControlFont() ; + + return retval; +} + +bool wxWindowMac::SetForegroundColour(const wxColour& col ) +{ + if ( !wxWindowBase::SetForegroundColour(col) ) + return false ; + + MacUpdateControlFont() ; + + return true ; +} + +bool wxWindowMac::SetBackgroundColour(const wxColour& col ) +{ + if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) + return false ; + + wxBrush brush ; + if ( col == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) + { + brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ; + } + else if ( col == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) + { + brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; + } + else + { + brush.SetColour( col ) ; + } + MacSetBackgroundBrush( brush ) ; + + MacUpdateControlFont() ; + + return true ; +} + + +bool wxWindowMac::MacCanFocus() const +{ + wxASSERT( m_macControl != NULL ) ; + + return true ; +} + + void wxWindowMac::SetFocus() { if ( gFocusWindow == this ) @@ -242,10 +749,11 @@ void wxWindowMac::SetFocus() } #endif // wxUSE_CARET #ifndef __WXUNIVERSAL__ - wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; - if ( control && control->GetMacControl() ) + wxWindow* control = wxDynamicCast( gFocusWindow , wxWindow ) ; + // TODO we must use the built-in focusing + if ( control && control->GetHandle() /* && control->MacIsReallyShown() */ ) { - UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNoPart ) ; + UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetTopLevelWindowRef() , (ControlRef) control->GetHandle() , kControlFocusNoPart ) ; control->MacRedrawControl() ; } #endif @@ -276,9 +784,9 @@ void wxWindowMac::SetFocus() #ifndef __WXUNIVERSAL__ wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; - if ( control && control->GetMacControl() ) + if ( control && control->GetHandle() ) { - UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNextPart ) ; + UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetTopLevelWindowRef() , (ControlRef) control->GetHandle() , kControlFocusNextPart ) ; } #endif wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); @@ -288,15 +796,6 @@ void wxWindowMac::SetFocus() } } -bool wxWindowMac::Enable(bool enable) -{ - if ( !wxWindowBase::Enable(enable) ) - return FALSE; - - MacSuperEnabled( enable ) ; - - return TRUE; -} void wxWindowMac::DoCaptureMouse() { @@ -336,107 +835,154 @@ void wxWindowMac::DragAcceptFiles(bool accept) // TODO } -// Get total size -void wxWindowMac::DoGetSize(int *x, int *y) const +void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y, + int& w, int& h) const { - if(x) *x = m_width ; - if(y) *y = m_height ; -} + Rect bounds ; + GetControlBounds( (ControlRef) m_macControl , &bounds ) ; -void wxWindowMac::DoGetPosition(int *x, int *y) const -{ - int xx,yy; - xx = m_x ; - yy = m_y ; - if ( !IsTopLevel() && GetParent()) + x = bounds.left ; + y = bounds.top ; + w = bounds.right - bounds.left ; + h = bounds.bottom - bounds.top ; + + wxTopLevelWindow* tlw = wxDynamicCast( this , wxTopLevelWindow ) ; + if ( tlw ) { - wxPoint pt(GetParent()->GetClientAreaOrigin()); - xx -= pt.x; - yy -= pt.y; + Point tlworigin = { 0 , 0 } ; + GrafPtr port ; + ::GetPort( &port ) ; + ::SetPort( UMAGetWindowPort( (WindowRef) tlw->MacGetWindowRef() ) ) ; + ::LocalToGlobal( &tlworigin ) ; + ::SetPort( port ) ; + x = tlworigin.h ; + y = tlworigin.v ; } - if(x) *x = xx; - if(y) *y = yy; } -#if wxUSE_MENUS -bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) +bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos, + const wxSize& size, + int& x, int& y, + int& w, int& h) const { - menu->SetInvokingWindow(this); - menu->UpdateUI(); - ClientToScreen( &x , &y ) ; + x = (int)pos.x; + y = (int)pos.y; + // todo the default calls may be used as soon as PostCreateControl Is moved here + w = size.x ; // WidthDefault( size.x ); + h = size.y ; // HeightDefault( size.y ) ; +#if !TARGET_API_MAC_OSX + GetParent()->MacWindowToRootWindow( &x , &y ) ; +#endif - menu->MacBeforeDisplay( true ) ; - long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ; - if ( HiWord(menuResult) != 0 ) + return true ; +} + +// Get total size +void wxWindowMac::DoGetSize(int *x, int *y) const +{ +#if TARGET_API_MAC_OSX + int x1 , y1 , w1 ,h1 ; + MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ; + if(x) *x = w1 ; + if(y) *y = h1 ; + +#else + Rect bounds ; + GetControlBounds( (ControlRef) m_macControl , &bounds ) ; + if(x) *x = bounds.right - bounds.left ; + if(y) *y = bounds.bottom - bounds.top ; +#endif +} + +void wxWindowMac::DoGetPosition(int *x, int *y) const +{ + #if TARGET_API_MAC_OSX + int x1 , y1 , w1 ,h1 ; + MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ; + if ( !IsTopLevel() ) { - MenuCommand id ; - GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ; - wxMenuItem* item = NULL ; - wxMenu* realmenu ; - item = menu->FindItem(id, &realmenu) ; - if (item->IsCheckable()) + wxWindow *parent = GetParent(); + if ( parent ) { - item->Check( !item->IsChecked() ) ; + wxPoint pt(parent->GetClientAreaOrigin()); + x1 -= pt.x ; + y1 -= pt.y ; } - menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; } - menu->MacAfterDisplay( true ) ; - - menu->SetInvokingWindow(NULL); + if(x) *x = x1 ; + if(y) *y = y1 ; + #else + Rect bounds ; + GetControlBounds( (ControlRef) m_macControl , &bounds ) ; + wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ; + + int xx = bounds.left ; + int yy = bounds.top ; + + if ( !GetParent()->IsTopLevel() ) + { + GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ; + + xx -= bounds.left ; + yy -= bounds.top ; + } + + wxPoint pt(GetParent()->GetClientAreaOrigin()); + xx -= pt.x; + yy -= pt.y; - return TRUE; -} + if(x) *x = xx; + if(y) *y = yy; #endif +} void wxWindowMac::DoScreenToClient(int *x, int *y) const { - WindowRef window = (WindowRef) MacGetRootWindow() ; - - Point localwhere = {0,0} ; - - if(x) localwhere.h = * x ; - if(y) localwhere.v = * y ; - - GrafPtr port ; - ::GetPort( &port ) ; - ::SetPort( UMAGetWindowPort( window ) ) ; - ::GlobalToLocal( &localwhere ) ; - ::SetPort( port ) ; + WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; + + wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; + + { + Point localwhere = {0,0} ; - if(x) *x = localwhere.h ; - if(y) *y = localwhere.v ; + if(x) localwhere.h = * x ; + if(y) localwhere.v = * y ; + + wxMacPortSaver s((GrafPtr)GetWindowPort( window )) ; + ::GlobalToLocal( &localwhere ) ; + if(x) *x = localwhere.h ; + if(y) *y = localwhere.v ; + } MacRootWindowToWindow( x , y ) ; - if ( x ) - *x -= MacGetLeftBorderSize() ; - if ( y ) - *y -= MacGetTopBorderSize() ; + + wxPoint origin = GetClientAreaOrigin() ; + if(x) *x -= origin.x ; + if(y) *y -= origin.y ; } void wxWindowMac::DoClientToScreen(int *x, int *y) const { - WindowRef window = (WindowRef) MacGetRootWindow() ; + WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; + wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ; - if ( x ) - *x += MacGetLeftBorderSize() ; - if ( y ) - *y += MacGetTopBorderSize() ; + wxPoint origin = GetClientAreaOrigin() ; + if(x) *x += origin.x ; + if(y) *y += origin.y ; MacWindowToRootWindow( x , y ) ; - Point localwhere = { 0,0 }; - if(x) localwhere.h = * x ; - if(y) localwhere.v = * y ; - - GrafPtr port ; - ::GetPort( &port ) ; - ::SetPort( UMAGetWindowPort( window ) ) ; + { + Point localwhere = { 0,0 }; + if(x) localwhere.h = * x ; + if(y) localwhere.v = * y ; - ::LocalToGlobal( &localwhere ) ; - ::SetPort( port ) ; - if(x) *x = localwhere.h ; - if(y) *y = localwhere.v ; + wxMacPortSaver s((GrafPtr)GetWindowPort( window )) ; + ::LocalToGlobal( &localwhere ) ; + if(x) *x = localwhere.h ; + if(y) *y = localwhere.v ; + } } void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const @@ -450,66 +996,107 @@ void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const { - wxPoint origin = GetClientAreaOrigin() ; MacRootWindowToWindow( x , y ) ; + + wxPoint origin = GetClientAreaOrigin() ; if(x) *x -= origin.x ; if(y) *y -= origin.y ; } void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const { + #if TARGET_API_MAC_OSX + HIPoint pt ; + if ( x ) pt.x = *x ; + if ( y ) pt.y = *y ; + + HIViewConvertPoint( &pt , (ControlRef) m_macControl , (ControlRef) MacGetTopLevelWindow()->GetHandle() ) ; + + if ( x ) *x = (int) pt.x ; + if ( y ) *y = (int) pt.y ; + #else if ( !IsTopLevel() ) { - if(x) *x += m_x ; - if(y) *y += m_y ; - GetParent()->MacWindowToRootWindow( x , y ) ; + Rect bounds ; + GetControlBounds( (ControlRef) m_macControl , &bounds ) ; + if(x) *x += bounds.left ; + if(y) *y += bounds.top ; } +#endif +} + +void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const +{ + int x1 , y1 ; + if ( x ) x1 = *x ; + if ( y ) y1 = *y ; + MacWindowToRootWindow( &x1 , &y1 ) ; + if ( x ) *x = x1 ; + if ( y ) *y = y1 ; } void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const { + #if TARGET_API_MAC_OSX + HIPoint pt ; + if ( x ) pt.x = *x ; + if ( y ) pt.y = *y ; + + HIViewConvertPoint( &pt , (ControlRef) MacGetTopLevelWindow()->GetHandle() , (ControlRef) m_macControl ) ; + + if ( x ) *x = (int) pt.x ; + if ( y ) *y = (int) pt.y ; + #else if ( !IsTopLevel() ) { - if(x) *x -= m_x ; - if(y) *y -= m_y ; - GetParent()->MacRootWindowToWindow( x , y ) ; + Rect bounds ; + GetControlBounds( (ControlRef) m_macControl , &bounds ) ; + if(x) *x -= bounds.left ; + if(y) *y -= bounds.top ; } +#endif } -bool wxWindowMac::SetCursor(const wxCursor& cursor) +void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const { - if (m_cursor == cursor) - return FALSE; + int x1 , y1 ; + if ( x ) x1 = *x ; + if ( y ) y1 = *y ; + MacRootWindowToWindow( &x1 , &y1 ) ; + if ( x ) *x = x1 ; + if ( y ) *y = y1 ; +} - if (wxNullCursor == cursor) +wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const +{ + wxSize sizeTotal = size; + + RgnHandle rgn = NewRgn() ; + + Rect content ; + + if ( GetControlRegion( (ControlRef) m_macControl , kControlContentMetaPart , rgn ) == noErr ) { - if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) - return FALSE ; + GetRegionBounds( rgn , &content ) ; + DisposeRgn( rgn ) ; } else { - if ( ! wxWindowBase::SetCursor( cursor ) ) - return FALSE ; + GetControlBounds( (ControlRef) m_macControl , &content ) ; } + Rect structure ; + GetControlBounds( (ControlRef) m_macControl , &structure ) ; +#if !TARGET_API_MAC_OSX + OffsetRect( &content , -structure.left , -structure.top ) ; +#endif - wxASSERT_MSG( m_cursor.Ok(), - wxT("cursor must be valid after call to the base version")); - - Point pt ; - wxWindowMac *mouseWin ; - GetMouse( &pt ) ; - - // Change the cursor NOW if we're within the correct window + sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ; + sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ; - if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) ) - { - if ( mouseWin == this && !wxIsBusy() ) - { - m_cursor.MacInstall() ; - } - } + sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; + sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; - return TRUE ; + return sizeTotal; } @@ -517,9 +1104,26 @@ bool wxWindowMac::SetCursor(const wxCursor& cursor) void wxWindowMac::DoGetClientSize(int *x, int *y) const { int ww, hh; - ww = m_width ; - hh = m_height ; + RgnHandle rgn = NewRgn() ; + Rect content ; + if ( GetControlRegion( (ControlRef) m_macControl , kControlContentMetaPart , rgn ) == noErr ) + { + GetRegionBounds( rgn , &content ) ; + DisposeRgn( rgn ) ; + } + else + { + GetControlBounds( (ControlRef) m_macControl , &content ) ; + } +#if !TARGET_API_MAC_OSX + Rect structure ; + GetControlBounds( (ControlRef) m_macControl , &structure ) ; + OffsetRect( &content , -structure.left , -structure.top ) ; +#endif + ww = content.right - content.left ; + hh = content.bottom - content.top ; + ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ); @@ -527,9 +1131,10 @@ void wxWindowMac::DoGetClientSize(int *x, int *y) const { int x1 = 0 ; int y1 = 0 ; - int w = m_width ; - int h = m_height ; - + int w ; + int h ; + GetSize( &w , &h ) ; + MacClientToRootWindow( &x1 , &y1 ) ; MacClientToRootWindow( &w , &h ) ; @@ -540,8 +1145,7 @@ void wxWindowMac::DoGetClientSize(int *x, int *y) const { if ( iter->IsTopLevel() ) { - totW = iter->m_width ; - totH = iter->m_height ; + iter->GetSize( &totW , &totH ) ; break ; } @@ -567,8 +1171,84 @@ void wxWindowMac::DoGetClientSize(int *x, int *y) const } if(x) *x = ww; if(y) *y = hh; + +} + +bool wxWindowMac::SetCursor(const wxCursor& cursor) +{ + if (m_cursor == cursor) + return FALSE; + + if (wxNullCursor == cursor) + { + if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) ) + return FALSE ; + } + else + { + if ( ! wxWindowBase::SetCursor( cursor ) ) + return FALSE ; + } + + wxASSERT_MSG( m_cursor.Ok(), + wxT("cursor must be valid after call to the base version")); + + /* + + TODO why do we have to use current coordinates ? + + Point pt ; + wxWindowMac *mouseWin ; + GetMouse( &pt ) ; + + // Change the cursor NOW if we're within the correct window + + + if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) ) + { + if ( mouseWin == this && !wxIsBusy() ) + { + m_cursor.MacInstall() ; + } + } + */ + if ( !wxIsBusy() ) + { + m_cursor.MacInstall() ; + } + + return TRUE ; } +#if wxUSE_MENUS +bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) +{ + menu->SetInvokingWindow(this); + menu->UpdateUI(); + ClientToScreen( &x , &y ) ; + + menu->MacBeforeDisplay( true ) ; + long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ; + if ( HiWord(menuResult) != 0 ) + { + MenuCommand id ; + GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ; + wxMenuItem* item = NULL ; + wxMenu* realmenu ; + item = menu->FindItem(id, &realmenu) ; + if (item->IsCheckable()) + { + item->Check( !item->IsChecked() ) ; + } + menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; + } + menu->MacAfterDisplay( true ) ; + + menu->SetInvokingWindow(NULL); + + return TRUE; +} +#endif // ---------------------------------------------------------------------------- // tooltips @@ -588,10 +1268,13 @@ void wxWindowMac::DoSetToolTip(wxToolTip *tooltip) void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) { - int former_x = m_x ; - int former_y = m_y ; - int former_w = m_width ; - int former_h = m_height ; + int former_x , former_y , former_w, former_h ; +#if !TARGET_API_MAC_OSX + DoGetPosition( &former_x , &former_y ) ; + DoGetSize( &former_w , &former_h ) ; +#else + MacGetPositionAndSizeFromControl( former_x , former_y , former_w , former_h ) ; +#endif int actualWidth = width; int actualHeight = height; @@ -621,85 +1304,19 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) if ( doMove || doResize ) { - // erase former position - - bool partialRepaint = false ; - - if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) ) - { - wxPoint oldPos( m_x , m_y ) ; - wxPoint newPos( actualX , actualY ) ; - MacWindowToRootWindow( &oldPos.x , &oldPos.y ) ; - MacWindowToRootWindow( &newPos.x , &newPos.y ) ; - if ( oldPos == newPos ) - { - partialRepaint = true ; - RgnHandle oldRgn,newRgn,diffRgn ; - oldRgn = NewRgn() ; - newRgn = NewRgn() ; - diffRgn = NewRgn() ; - - // invalidate the differences between the old and the new area - - SetRectRgn(oldRgn , oldPos.x , oldPos.y , oldPos.x + m_width , oldPos.y + m_height ) ; - SetRectRgn(newRgn , newPos.x , newPos.y , newPos.x + actualWidth , newPos.y + actualHeight ) ; - DiffRgn( newRgn , oldRgn , diffRgn ) ; - InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; - DiffRgn( oldRgn , newRgn , diffRgn ) ; - InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; - - // we also must invalidate the border areas, someone might optimize this one day to invalidate only the really - // changing pixels... - - if ( MacGetLeftBorderSize() != 0 || MacGetRightBorderSize() != 0 || - MacGetTopBorderSize() != 0 || MacGetBottomBorderSize() != 0 ) - { - RgnHandle innerOldRgn, innerNewRgn ; - innerOldRgn = NewRgn() ; - innerNewRgn = NewRgn() ; - - SetRectRgn(innerOldRgn , oldPos.x + MacGetLeftBorderSize() , oldPos.y + MacGetTopBorderSize() , - oldPos.x + m_width - MacGetRightBorderSize() , oldPos.y + m_height - MacGetBottomBorderSize() ) ; - DiffRgn( oldRgn , innerOldRgn , diffRgn ) ; - InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; - - SetRectRgn(innerNewRgn , newPos.x + MacGetLeftBorderSize() , newPos.y + MacGetTopBorderSize() , - newPos.x + actualWidth - MacGetRightBorderSize() , newPos.y + actualHeight - MacGetBottomBorderSize() ) ; - DiffRgn( newRgn , innerNewRgn , diffRgn ) ; - InvalWindowRgn( (WindowRef) MacGetRootWindow() , diffRgn ) ; - - DisposeRgn( innerOldRgn ) ; - DisposeRgn( innerNewRgn ) ; - } - - DisposeRgn(oldRgn) ; - DisposeRgn(newRgn) ; - DisposeRgn(diffRgn) ; - } - } - - if ( !partialRepaint ) - Refresh() ; - - m_x = actualX ; - m_y = actualY ; - m_width = actualWidth ; - m_height = actualHeight ; - - // update any low-level frame-relative positions - - MacUpdateDimensions() ; - // erase new position - - if ( !partialRepaint ) - Refresh() ; + Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) ) ; +#if TARGET_API_MAC_OSX + SetControlBounds( (ControlRef) m_macControl , &r ) ; +#else if ( doMove ) - wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified - + MoveControl( (ControlRef) m_macControl , r.left , r.top ) ; + if ( doSize ) + SizeControl( (ControlRef) m_macControl , r.right-r.left , r.bottom-r.top ) ; +#endif MacRepositionScrollBars() ; if ( doMove ) { - wxPoint point(m_x, m_y); + wxPoint point(actualX,actualY); wxMoveEvent event(point, m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event) ; @@ -707,7 +1324,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) if ( doResize ) { MacRepositionScrollBars() ; - wxSize size(m_width, m_height); + wxSize size(actualWidth, actualHeight); wxSizeEvent event(size, m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); @@ -716,6 +1333,42 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) } +wxSize wxWindowMac::DoGetBestSize() const +{ + Rect bestsize = { 0 , 0 , 0 , 0 } ; + short baselineoffset ; + int bestWidth, bestHeight ; + ::GetBestControlRect( (ControlRef) m_macControl , &bestsize , &baselineoffset ) ; + + if ( EmptyRect( &bestsize ) ) + { + baselineoffset = 0; + bestsize.left = bestsize.top = 0 ; + bestsize.right = 16 ; + bestsize.bottom = 16 ; + if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) + { + bestsize.bottom = 16 ; + } + else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) + { + bestsize.bottom = 24 ; + } + else + { + // return wxWindowBase::DoGetBestSize() ; + } + } + + bestWidth = bestsize.right - bestsize.left ; + bestHeight = bestsize.bottom - bestsize.top ; + if ( bestHeight < 10 ) + bestHeight = 13 ; + + return wxSize(bestWidth, bestHeight); +} + + // set the size of the window: if the dimensions are positive, just use them, // but if any of them is equal to -1, it means that we must find the value for // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in @@ -737,6 +1390,7 @@ void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) if ( x == currentX && y == currentY && width == currentW && height == currentH ) { + // TODO REMOVE MacRepositionScrollBars() ; // we might have a real position shift return; } @@ -785,17 +1439,47 @@ void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags) DoMoveWindow(x, y, width, height); } -// For implementation purposes - sometimes decorations make the client area -// smaller wxPoint wxWindowMac::GetClientAreaOrigin() const { - return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) ); + RgnHandle rgn = NewRgn() ; + Rect content ; + GetControlRegion( (ControlRef) m_macControl , kControlContentMetaPart , rgn ) ; + GetRegionBounds( rgn , &content ) ; + DisposeRgn( rgn ) ; +#if !TARGET_API_MAC_OSX + Rect structure ; + GetControlBounds( (ControlRef) m_macControl , &structure ) ; + OffsetRect( &content , -structure.left , -structure.top ) ; +#endif + + return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) ); +} + +void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) +{ + if ( clientheight != -1 || clientheight != -1 ) + { + int currentclientwidth , currentclientheight ; + int currentwidth , currentheight ; + + GetClientSize( ¤tclientwidth , ¤tclientheight ) ; + GetSize( ¤twidth , ¤theight ) ; + + DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , + currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; + } } void wxWindowMac::SetTitle(const wxString& title) { - m_label = title ; + m_label = wxStripMenuCodes(title) ; + + if ( m_macControl ) + { + UMASetControlTitle( (ControlRef) m_macControl , m_label , m_font.GetEncoding() ) ; + } + Refresh() ; } wxString wxWindowMac::GetTitle() const @@ -803,63 +1487,97 @@ wxString wxWindowMac::GetTitle() const return m_label ; } +void wxWindowMac::MacPropagateVisibilityChanged() +{ + MacVisibilityChanged() ; + + wxWindowListNode *node = GetChildren().GetFirst(); + while ( node ) + { + wxWindowMac *child = node->GetData(); + if ( child->IsShown() ) + child->MacPropagateVisibilityChanged( ) ; + node = node->GetNext(); + } +} + bool wxWindowMac::Show(bool show) { if ( !wxWindowBase::Show(show) ) return FALSE; + + // TODO use visibilityChanged Carbon Event for OSX + bool former = MacIsReallyShown() ; + + SetControlVisibility( (ControlRef) m_macControl , show , true ) ; + if ( former != MacIsReallyShown() ) + MacPropagateVisibilityChanged() ; + return TRUE; +} - MacSuperShown( show ) ; - Refresh() ; +bool wxWindowMac::MacIsReallyShown() +{ + // only under OSX the visibility of the TLW is taken into account +#if TARGET_API_MAC_OSX + return IsControlVisible( (ControlRef) m_macControl ) ; +#else + wxWindow* win = this ; + while( win->IsShown() ) + { + if ( win->IsTopLevel() ) + return true ; + + win = win->GetParent() ; + if ( win == NULL ) + return true ; + + } ; + return false ; +#endif +} - return TRUE; +void wxWindowMac::MacVisibilityChanged() +{ } -void wxWindowMac::MacSuperShown( bool show ) +void wxWindowMac::MacPropagateEnabledStateChanged( ) { + MacEnabledStateChanged() ; + wxWindowListNode *node = GetChildren().GetFirst(); while ( node ) { wxWindowMac *child = node->GetData(); - if ( child->m_isShown ) - child->MacSuperShown( show ) ; + if ( child->IsEnabled() ) + child->MacPropagateEnabledStateChanged() ; node = node->GetNext(); } } -void wxWindowMac::MacSuperEnabled( bool enabled ) +bool wxWindowMac::Enable(bool enable) { - if ( !IsTopLevel() ) - { - // to be absolutely correct we'd have to invalidate (with eraseBkground - // because unter MacOSX the frames are drawn with an addXXX mode) - // the borders area - } - wxWindowListNode *node = GetChildren().GetFirst(); - while ( node ) - { - wxWindowMac *child = (wxWindowMac *)node->GetData(); - if ( child->m_isShown ) - child->MacSuperEnabled( enabled ) ; - node = node->GetNext(); - } + wxASSERT( m_macControl != NULL ) ; + if ( !wxWindowBase::Enable(enable) ) + return FALSE; + + bool former = MacIsReallyEnabled() ; + if ( enable ) + UMAActivateControl( (ControlRef) m_macControl ) ; + else + UMADeactivateControl( (ControlRef) m_macControl ) ; + + if ( former != MacIsReallyEnabled() ) + MacPropagateEnabledStateChanged() ; + return TRUE; } -bool wxWindowMac::MacIsReallyShown() const +bool wxWindowMac::MacIsReallyEnabled() +{ + return IsControlEnabled( (ControlRef) m_macControl ) ; +} + +void wxWindowMac::MacEnabledStateChanged() { - if ( m_isShown && (m_parent != NULL && !IsTopLevel() ) ) { - return m_parent->MacIsReallyShown(); - } - return m_isShown; -/* - bool status = m_isShown ; - wxWindowMac * win = this ; - while ( status && win->m_parent != NULL ) - { - win = win->m_parent ; - status = win->m_isShown ; - } - return status ; -*/ } int wxWindowMac::GetCharHeight() const @@ -901,10 +1619,19 @@ void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y, void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) { +#if TARGET_API_MAC_OSX + HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ; +#else + if ( IsControlVisible( (ControlRef) m_macControl ) ) + { + SetControlVisibility( (ControlRef) m_macControl , false , false ) ; + SetControlVisibility( (ControlRef) m_macControl , true , true ) ; + } + /* if ( MacGetTopLevelWindow() == NULL ) return ; - if ( !MacIsReallyShown() ) + if ( !IsControlVisible( (ControlRef) m_macControl ) ) return ; wxPoint client = GetClientAreaOrigin(); @@ -939,7 +1666,34 @@ void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect) MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ; } + */ +#endif +} + +void wxWindowMac::MacRedrawControl() +{ +/* + if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) ) + { +#if TARGET_API_MAC_CARBON + Update() ; +#else + wxClientDC dc(this) ; + wxMacPortSetter helper(&dc) ; + wxMacWindowClipper clipper(this) ; + wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; + UMADrawControl( (ControlRef) m_macControl ) ; +#endif + } +*/ +} + +/* TODO +void wxWindowMac::OnPaint(wxPaintEvent& event) +{ + // why don't we skip that here ? } +*/ wxWindowMac *wxGetActiveWindow() { @@ -953,73 +1707,17 @@ void wxWindowMac::WarpPointer (int x_pos, int y_pos) // We really don't move the mouse programmatically under Mac. } -const wxBrush& wxWindowMac::MacGetBackgroundBrush() +void wxWindowMac::OnEraseBackground(wxEraseEvent& event) { - if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) - { - m_macBackgroundBrush.SetMacTheme( kThemeBrushDocumentWindowBackground ) ; - } - else if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) + event.Skip() ; +/* + if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) { - // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether - // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have - // either a non gray background color or a non control window - - WindowRef window = (WindowRef) MacGetRootWindow() ; - - wxWindowMac* parent = GetParent() ; - while( parent ) - { - if ( parent->MacGetRootWindow() != window ) - { - // we are in a different window on the mac system - parent = NULL ; - break ; - } - - { - if ( parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) - && parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) ) - { - // if we have any other colours in the hierarchy - m_macBackgroundBrush.SetColour( parent->m_backgroundColour ) ; - break ; - } - // if we have the normal colours in the hierarchy but another control etc. -> use it's background - if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) - { - Rect extent = { 0 , 0 , 0 , 0 } ; - int x , y ; - x = y = 0 ; - wxSize size = parent->GetSize() ; - parent->MacClientToRootWindow( &x , &y ) ; - extent.left = x ; - extent.top = y ; - extent.top-- ; - extent.right = x + size.x ; - extent.bottom = y + size.y ; - m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; // todo eventually change for inactive - break ; - } - } - parent = parent->GetParent() ; - } - if ( !parent ) - { - m_macBackgroundBrush.SetMacTheme( kThemeBrushDialogBackgroundActive ) ; // todo eventually change for inactive - } + event.Skip() ; } else - { - m_macBackgroundBrush.SetColour( m_backgroundColour ) ; - } - - return m_macBackgroundBrush ; -} - -void wxWindowMac::OnEraseBackground(wxEraseEvent& event) -{ - event.GetDC()->Clear() ; + event.GetDC()->Clear() ; +*/ } void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) @@ -1117,6 +1815,8 @@ void wxWindowMac::MacPaintBorders( int left , int top ) PenNormal() ; + int w , h ; + GetSize( &w , &h ) ; if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) { #if wxMAC_USE_THEME_BORDER @@ -1132,38 +1832,38 @@ void wxWindowMac::MacPaintBorders( int left , int top ) #else bool sunken = HasFlag( wxSUNKEN_BORDER ) ; RGBForeColor( &face ); - MoveTo( left + 0 , top + m_height - 2 ); + MoveTo( left + 0 , top + h - 2 ); LineTo( left + 0 , top + 0 ); - LineTo( left + m_width - 2 , top + 0 ); + LineTo( left + w - 2 , top + 0 ); - MoveTo( left + 2 , top + m_height - 3 ); - LineTo( left + m_width - 3 , top + m_height - 3 ); - LineTo( left + m_width - 3 , top + 2 ); + MoveTo( left + 2 , top + h - 3 ); + LineTo( left + w - 3 , top + h - 3 ); + LineTo( left + w - 3 , top + 2 ); RGBForeColor( sunken ? &face : &darkShadow ); - MoveTo( left + 0 , top + m_height - 1 ); - LineTo( left + m_width - 1 , top + m_height - 1 ); - LineTo( left + m_width - 1 , top + 0 ); + MoveTo( left + 0 , top + h - 1 ); + LineTo( left + w - 1 , top + h - 1 ); + LineTo( left + w - 1 , top + 0 ); RGBForeColor( sunken ? &lightShadow : &white ); - MoveTo( left + 1 , top + m_height - 3 ); + MoveTo( left + 1 , top + h - 3 ); LineTo( left + 1, top + 1 ); - LineTo( left + m_width - 3 , top + 1 ); + LineTo( left + w - 3 , top + 1 ); RGBForeColor( sunken ? &white : &lightShadow ); - MoveTo( left + 1 , top + m_height - 2 ); - LineTo( left + m_width - 2 , top + m_height - 2 ); - LineTo( left + m_width - 2 , top + 1 ); + MoveTo( left + 1 , top + h - 2 ); + LineTo( left + w - 2 , top + h - 2 ); + LineTo( left + w - 2 , top + 1 ); RGBForeColor( sunken ? &darkShadow : &face ); - MoveTo( left + 2 , top + m_height - 4 ); + MoveTo( left + 2 , top + h - 4 ); LineTo( left + 2 , top + 2 ); - LineTo( left + m_width - 4 , top + 2 ); + LineTo( left + w - 4 , top + 2 ); #endif } else if (HasFlag(wxSIMPLE_BORDER)) { - Rect rect = { top , left , m_height + top , m_width + left } ; + Rect rect = { top , left , h + top , w + left } ; RGBForeColor( &darkShadow ) ; FrameRect( &rect ) ; } @@ -1234,9 +1934,15 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) int width , height ; GetClientSize( &width , &height ) ; - Rect scrollrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , dc.YLOG2DEVMAC(height) , dc.XLOG2DEVMAC(width) } ; + + wxPoint pos; + pos.x = pos.y = 0; + + Rect scrollrect; + // TODO take out the boundaries + GetControlBounds( (ControlRef) m_macControl, &scrollrect); + RgnHandle updateRgn = NewRgn() ; - ClipRect( &scrollrect ) ; if ( rect ) { Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) , @@ -1244,9 +1950,17 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) SectRect( &scrollrect , &r , &scrollrect ) ; } ScrollRect( &scrollrect , dx , dy , updateRgn ) ; +#if TARGET_CARBON + //KO: The docs say ScrollRect creates an update region, which thus calls an update event + // but it seems the update only refreshes the background of the control, rather than calling + // kEventControlDraw, so we need to force a proper update here. There has to be a better + // way of doing this... (Note that code below under !TARGET_CARBON does not work either...) + Update(); +#endif // we also have to scroll the update rgn in this rectangle // in order not to loose updates - WindowRef rootWindow = (WindowRef) MacGetRootWindow() ; +#if !TARGET_CARBON + WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ; RgnHandle formerUpdateRgn = NewRgn() ; RgnHandle scrollRgn = NewRgn() ; RectRgn( scrollRgn , &scrollrect ) ; @@ -1265,6 +1979,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) DisposeRgn( updateRgn ) ; DisposeRgn( formerUpdateRgn ) ; DisposeRgn( scrollRgn ) ; +#endif } for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) @@ -1290,7 +2005,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) } } - Update() ; +// TODO remove, was moved higher up Update() ; } @@ -1346,13 +2061,6 @@ void wxWindowMac::OnSetFocus(wxFocusEvent& event) event.Skip(); } -// Setup background and foreground colours correctly -void wxWindowMac::SetupColours() -{ - if ( GetParent() ) - SetBackgroundColour(GetParent()->GetBackgroundColour()); -} - void wxWindowMac::OnInternalIdle() { // This calls the UI-update mechanism (querying windows for @@ -1371,95 +2079,8 @@ void wxWindowMac::Lower() { } -void wxWindowMac::DoSetClientSize(int width, int height) -{ - if ( width != -1 || height != -1 ) - { - - if ( width != -1 && m_vScrollBar ) - width += MAC_SCROLLBAR_SIZE ; - if ( height != -1 && m_vScrollBar ) - height += MAC_SCROLLBAR_SIZE ; - - width += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ; - height += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ; - - DoSetSize( -1 , -1 , width , height ) ; - } -} - - -wxWindowMac* wxWindowMac::s_lastMouseWindow = NULL ; - -bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin ) -{ - if ( IsTopLevel() ) - { - if ((point.x < 0) || (point.y < 0) || - (point.x > (m_width)) || (point.y > (m_height))) - return FALSE; - } - else - { - if ((point.x < m_x) || (point.y < m_y) || - (point.x > (m_x + m_width)) || (point.y > (m_y + m_height))) - return FALSE; - } - - WindowRef window = (WindowRef) MacGetRootWindow() ; - - wxPoint newPoint( point ) ; - - if ( !IsTopLevel() ) - { - newPoint.x -= m_x; - newPoint.y -= m_y; - } - - for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) - { - wxWindowMac *child = node->GetData(); - // added the m_isShown test --dmazzoni - if ( child->MacGetRootWindow() == window && child->m_isShown ) - { - if (child->MacGetWindowFromPointSub(newPoint , outWin )) - return TRUE; - } - } - - *outWin = this ; - return TRUE; -} - -bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin ) -{ - WindowRef window ; - - Point pt = { screenpoint.y , screenpoint.x } ; - if ( ::FindWindow( pt , &window ) == 3 ) - { - - wxWindowMac* win = wxFindWinFromMacWindow( window ) ; - if ( win ) - { - // No, this yields the CLIENT are, we need the whole frame. RR. - // point = win->ScreenToClient( point ) ; - - GrafPtr port; - ::GetPort( &port ) ; - ::SetPort( UMAGetWindowPort( window ) ) ; - ::GlobalToLocal( &pt ) ; - ::SetPort( port ) ; - wxPoint point( pt.h, pt.v ) ; - - return win->MacGetWindowFromPointSub( point , outWin ) ; - } - } - return FALSE ; -} - -static wxWindow *gs_lastWhich = NULL; +// static wxWindow *gs_lastWhich = NULL; bool wxWindowMac::MacSetupCursor( const wxPoint& pt) { @@ -1503,83 +2124,6 @@ bool wxWindowMac::MacSetupCursor( const wxPoint& pt) return cursor.Ok() ; } -bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event) -{ - if ((event.m_x < m_x) || (event.m_y < m_y) || - (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height))) - return FALSE; - - - if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) /* || IsKindOf( CLASSINFO( wxSpinCtrl ) ) */) - return FALSE ; - - WindowRef window = (WindowRef) MacGetRootWindow() ; - - event.m_x -= m_x; - event.m_y -= m_y; - - int x = event.m_x ; - int y = event.m_y ; - - for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) - { - wxWindowMac *child = node->GetData(); - if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() ) - { - if (child->MacDispatchMouseEvent(event)) - return TRUE; - } - } - - wxWindow* cursorTarget = this ; - wxPoint cursorPoint( x , y ) ; - - while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) - { - cursorTarget = cursorTarget->GetParent() ; - if ( cursorTarget ) - cursorPoint += cursorTarget->GetPosition() ; - } - event.m_x = x ; - event.m_y = y ; - event.SetEventObject( this ) ; - - if ( event.GetEventType() == wxEVT_LEFT_DOWN ) - { - // set focus to this window - if (AcceptsFocus() && FindFocus()!=this) - SetFocus(); - } - -#if wxUSE_TOOLTIPS - if ( event.GetEventType() == wxEVT_MOTION - || event.GetEventType() == wxEVT_ENTER_WINDOW - || event.GetEventType() == wxEVT_LEAVE_WINDOW ) - wxToolTip::RelayEvent( this , event); -#endif // wxUSE_TOOLTIPS - - if (gs_lastWhich != this) - { - gs_lastWhich = this; - - // Double clicks must always occur on the same window - if (event.GetEventType() == wxEVT_LEFT_DCLICK) - event.SetEventType( wxEVT_LEFT_DOWN ); - if (event.GetEventType() == wxEVT_RIGHT_DCLICK) - event.SetEventType( wxEVT_RIGHT_DOWN ); - - // Same for mouse up events - if (event.GetEventType() == wxEVT_LEFT_UP) - return TRUE; - if (event.GetEventType() == wxEVT_RIGHT_UP) - return TRUE; - } - - GetEventHandler()->ProcessEvent( event ) ; - - return TRUE; -} - wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) { if ( m_tooltip ) @@ -1591,77 +2135,67 @@ wxString wxWindowMac::MacGetToolTipString( wxPoint &pt ) void wxWindowMac::Update() { - wxRegion visRgn = MacGetVisibleRegion( false ) ; - int top = 0 , left = 0 ; - MacWindowToRootWindow( &left , &top ) ; - WindowRef rootWindow = (WindowRef) MacGetRootWindow() ; - RgnHandle updateRgn = NewRgn() ; - // getting the update region in macos local coordinates - GetWindowUpdateRgn( rootWindow , updateRgn ) ; - GrafPtr port ; - ::GetPort( &port ) ; - ::SetPort( UMAGetWindowPort( rootWindow ) ) ; - Point pt = {0,0} ; - LocalToGlobal( &pt ) ; - ::SetPort( port ) ; - OffsetRgn( updateRgn , -pt.h , -pt.v ) ; - // translate to window local coordinates - OffsetRgn( updateRgn , -left , -top ) ; - SectRgn( updateRgn , (RgnHandle) visRgn.GetWXHRGN() , updateRgn ) ; - MacRedraw( updateRgn , 0 , true ) ; - // for flushing and validating we need macos-local coordinates again - OffsetRgn( updateRgn , left , top ) ; -#if TARGET_API_MAC_CARBON - if ( QDIsPortBuffered( GetWindowPort( rootWindow ) ) ) - { - QDFlushPortBuffer( GetWindowPort( rootWindow ) , updateRgn ) ; - } +#if TARGET_API_MAC_OSX + HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ; +#else + ::Draw1Control( (ControlRef) m_macControl ) ; #endif - ValidWindowRgn( rootWindow , updateRgn ) ; - DisposeRgn( updateRgn ) ; } wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const { wxTopLevelWindowMac* win = NULL ; - WindowRef window = (WindowRef) MacGetRootWindow() ; + WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; if ( window ) { win = wxFindWinFromMacWindow( window ) ; } return win ; } - -const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSiblings ) +wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) { + + Rect r ; RgnHandle visRgn = NewRgn() ; RgnHandle tempRgn = NewRgn() ; - RgnHandle tempStaticBoxRgn = NewRgn() ; - - if ( MacIsReallyShown() ) + if ( IsControlVisible( (ControlRef) m_macControl ) ) { - SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ; - - //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox - if ( IsKindOf( CLASSINFO( wxStaticBox ) ) ) + GetControlBounds( (ControlRef) m_macControl , &r ) ; + if (! MacGetTopLevelWindow()->MacUsesCompositing() ) { - int borderTop = 14 ; - int borderOther = 4 ; - if ( UMAGetSystemVersion() >= 0x1030 ) - borderTop += 2 ; - - SetRectRgn( tempStaticBoxRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ; - DiffRgn( visRgn , tempStaticBoxRgn , visRgn ) ; + MacRootWindowToWindow( &r.left , & r.top ) ; + MacRootWindowToWindow( &r.right , & r.bottom ) ; } - + else + { + r.right -= r.left ; + r.bottom -= r.top ; + r.left = 0 ; + r.top = 0 ; + } + if ( includeOuterStructures ) + InsetRect( &r , -3 , -3 ) ; + RectRgn( visRgn , &r ) ; if ( !IsTopLevel() ) { - wxWindow* parent = GetParent() ; + wxWindow* child = this ; + wxWindow* parent = child->GetParent() ; while( parent ) { - wxSize size = parent->GetSize() ; int x , y ; - x = y = 0 ; + wxSize size ; + if ( parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) ) + { + size = parent->GetSize() ; + x = y = 0 ; + } + else + { + size = parent->GetClientSize() ; + wxPoint origin = parent->GetClientAreaOrigin() ; + x = origin.x ; + y = origin.y ; + } parent->MacWindowToRootWindow( &x, &y ) ; MacRootWindowToWindow( &x , &y ) ; @@ -1673,170 +2207,99 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling SectRgn( visRgn , tempRgn , visRgn ) ; if ( parent->IsTopLevel() ) break ; - parent = parent->GetParent() ; - } - } - if ( respectChildrenAndSiblings ) - { - if ( GetWindowStyle() & wxCLIP_CHILDREN ) - { - for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) - { - wxWindowMac *child = node->GetData(); - - if ( !child->IsTopLevel() && child->IsShown() ) - { - SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; - if ( child->IsKindOf( CLASSINFO( wxStaticBox ) ) ) - { - int borderTop = 14 ; - int borderOther = 4 ; - if ( UMAGetSystemVersion() >= 0x1030 ) - borderTop += 2 ; - - SetRectRgn( tempStaticBoxRgn , child->m_x + borderOther , child->m_y + borderTop , child->m_x + child->m_width - borderOther , child->m_y + child->m_height - borderOther ) ; - DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; - } - DiffRgn( visRgn , tempRgn , visRgn ) ; - } - } - } - - if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() ) - { - bool thisWindowThrough = false ; - for (wxWindowListNode *node = GetParent()->GetChildren().GetFirst(); node; node = node->GetNext()) - { - wxWindowMac *sibling = node->GetData(); - if ( sibling == this ) - { - thisWindowThrough = true ; - continue ; - } - if( !thisWindowThrough ) - { - continue ; - } - - if ( !sibling->IsTopLevel() && sibling->IsShown() ) - { - SetRectRgn( tempRgn , sibling->m_x - m_x , sibling->m_y - m_y , sibling->m_x + sibling->m_width - m_x , sibling->m_y + sibling->m_height - m_y ) ; - if ( sibling->IsKindOf( CLASSINFO( wxStaticBox ) ) ) - { - int borderTop = 14 ; - int borderOther = 4 ; - if ( UMAGetSystemVersion() >= 0x1030 ) - borderTop += 2 ; - - SetRectRgn( tempStaticBoxRgn , sibling->m_x - m_x + borderOther , sibling->m_y - m_y + borderTop , sibling->m_x + sibling->m_width - m_x - borderOther , sibling->m_y + sibling->m_height - m_y - borderOther ) ; - DiffRgn( tempRgn , tempStaticBoxRgn , tempRgn ) ; - } - DiffRgn( visRgn , tempRgn , visRgn ) ; - } - } + child = parent ; + parent = child->GetParent() ; } } } - m_macVisibleRegion = visRgn ; + + wxRegion vis = visRgn ; DisposeRgn( visRgn ) ; DisposeRgn( tempRgn ) ; - DisposeRgn( tempStaticBoxRgn ) ; - return m_macVisibleRegion ; + return vis ; } -void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase) +/* + This function must not change the updatergn ! + */ +bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time ) { RgnHandle updatergn = (RgnHandle) updatergnr ; - // updatergn is always already clipped to our boundaries - // it is in window coordinates, not in client coordinates - - WindowRef window = (WindowRef) MacGetRootWindow() ; - + bool handled = false ; + + // calculate a client-origin version of the update rgn and set m_updateRegion to that { - // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates - RgnHandle ownUpdateRgn = NewRgn() ; - CopyRgn( updatergn , ownUpdateRgn ) ; - - SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ; - - // newupdate is the update region in client coordinates RgnHandle newupdate = NewRgn() ; wxSize point = GetClientSize() ; wxPoint origin = GetClientAreaOrigin() ; SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ; - SectRgn( newupdate , ownUpdateRgn , newupdate ) ; + SectRgn( newupdate , updatergn , newupdate ) ; OffsetRgn( newupdate , -origin.x , -origin.y ) ; m_updateRegion = newupdate ; - DisposeRgn( newupdate ) ; // it's been cloned to m_updateRegion - - if ( erase && !EmptyRgn(ownUpdateRgn) ) - { - wxWindowDC dc(this); - if (!EmptyRgn(ownUpdateRgn)) - dc.SetClippingRegion(wxRegion(ownUpdateRgn)); - wxEraseEvent eevent( GetId(), &dc ); - eevent.SetEventObject( this ); - GetEventHandler()->ProcessEvent( eevent ); + DisposeRgn( newupdate ) ; + } - wxNcPaintEvent eventNc( GetId() ); - eventNc.SetEventObject( this ); - GetEventHandler()->ProcessEvent( eventNc ); - } - DisposeRgn( ownUpdateRgn ) ; + if ( !EmptyRgn(updatergn) ) + { + wxWindowDC dc(this); + if (!EmptyRgn(updatergn)) + dc.SetClippingRegion(wxRegion(updatergn)); + + wxEraseEvent eevent( GetId(), &dc ); + eevent.SetEventObject( this ); + GetEventHandler()->ProcessEvent( eevent ); + if ( !m_updateRegion.Empty() ) { - wxWindowList hiddenWindows ; - for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) - { - wxControl *child = wxDynamicCast( ( wxWindow*)node->GetData() , wxControl ) ; - - if ( child && child->MacGetRootWindow() == window && child->IsShown() && child->GetMacControl() ) - { - SetControlVisibility( (ControlHandle) child->GetMacControl() , false , false ) ; - hiddenWindows.Append( child ) ; - } - } - + // paint the window itself wxPaintEvent event; event.m_timeStamp = time ; event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); - - for (wxWindowListNode *node = hiddenWindows.GetFirst(); node; node = node->GetNext()) - { - wxControl *child = wxDynamicCast( ( wxWindow*)node->GetData() , wxControl ) ; + handled = GetEventHandler()->ProcessEvent(event); - if ( child && child->GetMacControl() ) - { - SetControlVisibility( (ControlHandle) child->GetMacControl() , true , false ) ; - } - } + // paint custom borders + wxNcPaintEvent eventNc( GetId() ); + eventNc.SetEventObject( this ); + GetEventHandler()->ProcessEvent( eventNc ); } } + return handled ; +} - // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively +void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase) +{ + RgnHandle updatergn = (RgnHandle) updatergnr ; + // updatergn is always already clipped to our boundaries + // if we are in compositing mode then it is in relative to the upper left of the control + // if we are in non-compositing, then it is relatvie to the uppder left of the content area + // of the toplevel window + // it is in window coordinates, not in client coordinates - RgnHandle childupdate = NewRgn() ; - for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext()) - { - // calculate the update region for the child windows by intersecting the window rectangle with our own - // passed in update region and then offset it to be client-wise window coordinates again - wxWindowMac *child = node->GetData(); - SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; - SectRgn( childupdate , updatergn , childupdate ) ; - OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; - if ( child->MacGetRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) ) - { - // because dialogs may also be children - child->MacRedraw( childupdate , time , erase ) ; - } + // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates + RgnHandle ownUpdateRgn = NewRgn() ; + CopyRgn( updatergn , ownUpdateRgn ) ; + + if ( MacGetTopLevelWindow()->MacUsesCompositing() == false ) + { + Rect bounds; + UMAGetControlBoundsInWindowCoords( (ControlRef)m_macControl, &bounds ); + RgnHandle controlRgn = NewRgn(); + RectRgn( controlRgn, &bounds ); + //KO: This sets the ownUpdateRgn to the area of this control that is inside + // the window update region + SectRgn( ownUpdateRgn, controlRgn, ownUpdateRgn ); + DisposeRgn( controlRgn ); + + //KO: convert ownUpdateRgn to local coordinates + OffsetRgn( ownUpdateRgn, -bounds.left, -bounds.top ); } - DisposeRgn( childupdate ) ; - // eventually a draw grow box here + + MacDoRedraw( ownUpdateRgn , time ) ; + DisposeRgn( ownUpdateRgn ) ; } -WXHWND wxWindowMac::MacGetRootWindow() const +WXWindow wxWindowMac::MacGetTopLevelWindowRef() const { wxWindowMac *iter = (wxWindowMac*)this ; @@ -1897,8 +2360,9 @@ void wxWindowMac::MacRepositionScrollBars() // get real client area - int width = m_width ; - int height = m_height ; + int width ; + int height ; + GetSize( &width , &height ) ; width -= MacGetLeftBorderSize() + MacGetRightBorderSize(); height -= MacGetTopBorderSize() + MacGetBottomBorderSize(); @@ -1910,8 +2374,9 @@ void wxWindowMac::MacRepositionScrollBars() int x = 0 ; int y = 0 ; - int w = m_width ; - int h = m_height ; + int w ; + int h ; + GetSize( &w , &h ) ; MacClientToRootWindow( &x , &y ) ; MacClientToRootWindow( &w , &h ) ; @@ -1923,8 +2388,7 @@ void wxWindowMac::MacRepositionScrollBars() { if ( iter->IsTopLevel() ) { - totW = iter->m_width ; - totH = iter->m_height ; + iter->GetSize( &totW , &totH ) ; break ; } @@ -1969,11 +2433,6 @@ bool wxWindowMac::AcceptsFocus() const return MacCanFocus() && wxWindowBase::AcceptsFocus(); } -WXWidget wxWindowMac::MacGetContainerForEmbedding() -{ - return GetParent()->MacGetContainerForEmbedding() ; -} - void wxWindowMac::MacSuperChangedPosition() { // only window-absolute structures have to be moved i.e. controls @@ -1999,6 +2458,7 @@ void wxWindowMac::MacTopLevelWindowChangedPosition() node = node->GetNext(); } } + long wxWindowMac::MacGetLeftBorderSize( ) const { if( IsTopLevel() ) @@ -2008,9 +2468,7 @@ long wxWindowMac::MacGetLeftBorderSize( ) const { SInt32 border = 3 ; #if wxMAC_USE_THEME_BORDER -#if TARGET_CARBON GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; -#endif #endif return border ; } @@ -2018,9 +2476,7 @@ long wxWindowMac::MacGetLeftBorderSize( ) const { SInt32 border = 3 ; #if wxMAC_USE_THEME_BORDER -#if TARGET_CARBON GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; -#endif #endif return border ; } @@ -2088,9 +2544,71 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) if ( ! GetEventHandler()->ProcessEvent(evtCtx) ) event.Skip() ; } - else - { - event.Skip() ; - } + else if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) + { + + int x = event.m_x ; + int y = event.m_y ; + + if ( MacGetTopLevelWindow()->MacUsesCompositing() == false ) + { + // OS Needs it in tlw content area coordinates + MacClientToRootWindow( &x , &y ) ; + } + else + { + // OS Needs it in window not client coordinates + wxPoint origin = GetClientAreaOrigin() ; + x += origin.x ; + y += origin.y ; + } + ControlRef control ; + Point localwhere ; + SInt16 controlpart ; + + localwhere.h = x ; + localwhere.v = y ; + + short modifiers = 0; + + if ( !event.m_leftDown && !event.m_rightDown ) + modifiers |= btnState ; + + if ( event.m_shiftDown ) + modifiers |= shiftKey ; + + if ( event.m_controlDown ) + modifiers |= controlKey ; + + if ( event.m_altDown ) + modifiers |= optionKey ; + + if ( event.m_metaDown ) + modifiers |= cmdKey ; + { + control = (ControlRef) m_macControl ; + if ( control && ::IsControlActive( control ) ) + { + { + controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; + wxTheApp->s_lastMouseDown = 0 ; + if ( control && controlpart != kControlNoPart ) + { + MacHandleControlClick((WXWidget) control , controlpart , false /* mouse not down anymore */ ) ; + } + } + } + } + } + else + { + event.Skip() ; + } } +void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) ) +{ + wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; +} + + diff --git a/src/mac/corefoundation/gsockosx.cpp b/src/mac/corefoundation/gsockosx.cpp index 8d888ec8d0..b9df39196e 100644 --- a/src/mac/corefoundation/gsockosx.cpp +++ b/src/mac/corefoundation/gsockosx.cpp @@ -87,7 +87,7 @@ void _GSocket_GUI_Cleanup(void) int _GSocket_GUI_Init_Socket(GSocket *socket) { - struct MacGSocketData *data = (struct MacGSocketData *) malloc(sizeof(struct MacGSocketData)); + struct MacGSocketData *data = (struct MacGSocketData *)malloc(sizeof(struct MacGSocketData)); if (data) { socket->m_gui_dependent = (char*)data; -- 2.45.2