From 2f1ae4143271ae63a17e052a1a471d16e9cd8c44 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Wed, 9 Aug 2000 10:10:14 +0000 Subject: [PATCH] merge with latest sources git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@7985 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/accel.cpp | 2 + src/mac/aga.cpp | 149 ++++--- src/mac/app.cpp | 353 ++++++++++------ src/mac/bitmap.cpp | 48 +-- src/mac/bmpbuttn.cpp | 24 +- src/mac/brush.cpp | 2 + src/mac/button.cpp | 22 +- src/mac/carbon/accel.cpp | 2 + src/mac/carbon/aga.cpp | 149 ++++--- src/mac/carbon/app.cpp | 353 ++++++++++------ src/mac/carbon/bitmap.cpp | 48 +-- src/mac/carbon/bmpbuttn.cpp | 24 +- src/mac/carbon/brush.cpp | 2 + src/mac/carbon/button.cpp | 22 +- src/mac/carbon/checkbox.cpp | 2 + src/mac/carbon/checklst.cpp | 2 + src/mac/carbon/choice.cpp | 41 +- src/mac/carbon/clipbrd.cpp | 221 ++++++++-- src/mac/carbon/colordlg.cpp | 2 + src/mac/carbon/colour.cpp | 2 + src/mac/carbon/combobox.cpp | 10 +- src/mac/carbon/control.cpp | 138 +++++-- src/mac/carbon/cursor.cpp | 20 +- src/mac/carbon/data.cpp | 16 +- src/mac/carbon/dataobj.cpp | 87 ++-- src/mac/carbon/dc.cpp | 452 +++++++++----------- src/mac/carbon/dcclient.cpp | 27 +- src/mac/carbon/dcmemory.cpp | 11 + src/mac/carbon/dcprint.cpp | 64 ++- src/mac/carbon/dcscreen.cpp | 19 + src/mac/carbon/dialog.cpp | 292 ++++--------- src/mac/carbon/dir.cpp | 31 +- src/mac/carbon/dirdlg.cpp | 42 +- src/mac/carbon/dnd.cpp | 3 + src/mac/carbon/filedlg.cpp | 65 +-- src/mac/carbon/font.cpp | 4 +- src/mac/carbon/fontdlg.cpp | 2 + src/mac/carbon/fontutil.cpp | 15 +- src/mac/carbon/frame.cpp | 481 +++++----------------- src/mac/carbon/gauge.cpp | 8 +- src/mac/carbon/gdiobj.cpp | 2 + src/mac/carbon/helpxxxx.cpp | 2 + src/mac/carbon/icon.cpp | 39 +- src/mac/carbon/imaglist.cpp | 2 + src/mac/carbon/listbox.cpp | 57 ++- src/mac/carbon/listctrl.cpp | 2 + src/mac/carbon/mdi.cpp | 10 +- src/mac/carbon/menu.cpp | 339 +++------------ src/mac/carbon/menuitem.cpp | 157 ++++++- src/mac/carbon/metafile.cpp | 27 +- src/mac/carbon/minifram.cpp | 2 + src/mac/carbon/msgdlg.cpp | 3 +- src/mac/carbon/palette.cpp | 2 + src/mac/carbon/pen.cpp | 10 +- src/mac/carbon/printdlg.cpp | 27 +- src/mac/carbon/printmac.cpp | 100 ++--- src/mac/carbon/radiobox.cpp | 14 +- src/mac/carbon/radiobut.cpp | 6 +- src/mac/carbon/region.cpp | 9 +- src/mac/carbon/scrolbar.cpp | 2 + src/mac/carbon/settings.cpp | 1 - src/mac/carbon/slider.cpp | 2 + src/mac/carbon/spinbutt.cpp | 2 + src/mac/carbon/statbmp.cpp | 8 +- src/mac/carbon/statbox.cpp | 4 +- src/mac/carbon/stattext.cpp | 237 ++++++++--- src/mac/carbon/tabctrl.cpp | 4 +- src/mac/carbon/textctrl.cpp | 536 ++++++++++++------------ src/mac/carbon/timer.cpp | 64 ++- src/mac/carbon/toolbar.cpp | 345 ++++++++++++---- src/mac/carbon/treectrl.cpp | 2 + src/mac/carbon/uma.cpp | 503 ++++++++++++++++++++++- src/mac/carbon/utils.cpp | 66 ++- src/mac/carbon/window.cpp | 751 ++++++++++++++++++++++++++-------- src/mac/checkbox.cpp | 2 + src/mac/checklst.cpp | 2 + src/mac/choice.cpp | 41 +- src/mac/clipbrd.cpp | 221 ++++++++-- src/mac/colordlg.cpp | 2 + src/mac/colour.cpp | 2 + src/mac/combobox.cpp | 10 +- src/mac/control.cpp | 138 +++++-- src/mac/cursor.cpp | 20 +- src/mac/data.cpp | 16 +- src/mac/dataobj.cpp | 87 ++-- src/mac/dc.cpp | 452 +++++++++----------- src/mac/dcclient.cpp | 27 +- src/mac/dcmemory.cpp | 11 + src/mac/dcprint.cpp | 64 ++- src/mac/dcscreen.cpp | 19 + src/mac/dialog.cpp | 292 ++++--------- src/mac/dir.cpp | 31 +- src/mac/dirdlg.cpp | 42 +- src/mac/dnd.cpp | 3 + src/mac/filedlg.cpp | 65 +-- src/mac/font.cpp | 4 +- src/mac/fontdlg.cpp | 2 + src/mac/fontutil.cpp | 15 +- src/mac/frame.cpp | 481 +++++----------------- src/mac/gauge.cpp | 8 +- src/mac/gdiobj.cpp | 2 + src/mac/helpxxxx.cpp | 2 + src/mac/icon.cpp | 39 +- src/mac/imaglist.cpp | 2 + src/mac/ldef/extldef.h | 2 + src/mac/listbox.cpp | 57 ++- src/mac/listctrl.cpp | 2 + src/mac/mdi.cpp | 10 +- src/mac/menu.cpp | 339 +++------------ src/mac/menuitem.cpp | 157 ++++++- src/mac/metafile.cpp | 27 +- src/mac/minifram.cpp | 2 + src/mac/morefile/Director.cpp | 52 ++- src/mac/morefile/Director.h | 4 +- src/mac/morefile/FSpCompa.cpp | 4 +- src/mac/morefile/FSpCompa.h | 4 +- src/mac/morefile/FileCopy.cpp | 16 +- src/mac/morefile/FileCopy.h | 4 +- src/mac/morefile/FullPath.cpp | 8 +- src/mac/morefile/FullPath.h | 5 +- src/mac/morefile/IterateD.cpp | 22 +- src/mac/morefile/IterateD.h | 4 +- src/mac/morefile/MoreDesk.cpp | 32 +- src/mac/morefile/MoreDesk.h | 4 +- src/mac/morefile/MoreExtr.cpp | 70 +++- src/mac/morefile/MoreExtr.h | 20 +- src/mac/morefile/MoreFile.cpp | 4 +- src/mac/morefile/MoreFile.h | 4 +- src/mac/morefile/Optim.h | 91 ++-- src/mac/msgdlg.cpp | 3 +- src/mac/palette.cpp | 2 + src/mac/pen.cpp | 10 +- src/mac/printdlg.cpp | 27 +- src/mac/printmac.cpp | 100 ++--- src/mac/radiobox.cpp | 14 +- src/mac/radiobut.cpp | 6 +- src/mac/region.cpp | 9 +- src/mac/scrolbar.cpp | 2 + src/mac/settings.cpp | 1 - src/mac/slider.cpp | 2 + src/mac/spinbutt.cpp | 2 + src/mac/statbmp.cpp | 8 +- src/mac/statbox.cpp | 4 +- src/mac/stattext.cpp | 237 ++++++++--- src/mac/tabctrl.cpp | 4 +- src/mac/textctrl.cpp | 536 ++++++++++++------------ src/mac/timer.cpp | 64 ++- src/mac/toolbar.cpp | 345 ++++++++++++---- src/mac/treectrl.cpp | 2 + src/mac/uma.cpp | 503 ++++++++++++++++++++++- src/mac/utils.cpp | 66 ++- src/mac/window.cpp | 751 ++++++++++++++++++++++++++-------- src/mac/xpm/Attrib.c | 2 +- src/mac/xpm/CrBufFrI.c | 2 +- src/mac/xpm/CrDatFrI.c | 2 +- src/mac/xpm/CrIFrBuf.c | 2 +- src/mac/xpm/CrIFrDat.c | 2 +- src/mac/xpm/Image.c | 2 +- src/mac/xpm/Info.c | 2 +- src/mac/xpm/RdFToBuf.c | 8 +- src/mac/xpm/RdFToDat.c | 2 +- src/mac/xpm/RdFToI.c | 8 +- src/mac/xpm/WrFFrBuf.c | 2 +- src/mac/xpm/WrFFrDat.c | 2 +- src/mac/xpm/WrFFrI.c | 2 +- src/mac/xpm/create.c | 2 +- src/mac/xpm/data.c | 2 +- src/mac/xpm/hashtab.c | 2 +- src/mac/xpm/macx.c | 346 +--------------- src/mac/xpm/misc.c | 2 +- src/mac/xpm/parse.c | 2 +- src/mac/xpm/rgb.c | 6 +- src/mac/xpm/rgbtab.h | 10 +- src/mac/xpm/scan.c | 2 +- src/mac/xpm/simx.c | 6 +- src/mac/xpm/simx.h | 4 +- 176 files changed, 7689 insertions(+), 5071 deletions(-) diff --git a/src/mac/accel.cpp b/src/mac/accel.cpp index f8796e111a..b0b8734d55 100644 --- a/src/mac/accel.cpp +++ b/src/mac/accel.cpp @@ -17,7 +17,9 @@ #include "wx/accel.h" #include "wx/string.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) +#endif class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData { diff --git a/src/mac/aga.cpp b/src/mac/aga.cpp index 40abb5cbb9..6b14ecd9c0 100644 --- a/src/mac/aga.cpp +++ b/src/mac/aga.cpp @@ -1,3 +1,5 @@ +#if !TARGET_CARBON + #include #include #include @@ -600,6 +602,10 @@ void AGADeactivateControl( ControlHandle inControl ) } } } + else + { + ::HiliteControl( inControl , 255 ) ; + } } void AGAActivateControl( ControlHandle inControl ) @@ -615,6 +621,10 @@ void AGAActivateControl( ControlHandle inControl ) } } } + else + { + ::HiliteControl( inControl , 0 ) ; + } } OSErr AGASetKeyboardFocus (WindowPtr inWindow, @@ -718,6 +728,7 @@ void DisposeExtCDEFInfo( ControlHandle theControl) DisposeHandle( info->children ) ; info->children = NULL ; free( (void*) (**theControl).contrlRfCon ) ; + (**theControl).contrlRfCon = NULL ; } } } @@ -922,51 +933,6 @@ void AGASetFontStyle( ControlFontStyleRec *fontstyle ) ::RGBBackColor( &fontstyle->backColor ) ; } ; -class AGAPortHelper -{ -public : - AGAPortHelper() - { - GetPenState( &oldPenState ) ; - GetBackColor( &oldBackColor ) ; - GetForeColor( &oldForeColor ) ; - - GetPort( &port ) ; - clip = NewRgn() ; - GetClip( clip ); - font = port->txFont; - size = port->txSize; - style = port->txFace; - mode = port->txMode; - - } - ~AGAPortHelper() - { - SetPort( port ) ; - SetClip( clip ) ; - DisposeRgn( clip ) ; - RGBForeColor(&oldForeColor); - RGBBackColor(&oldBackColor); - SetPenState(&oldPenState); - - TextFont( font ); - TextSize( size ); - TextFace( style ); - TextMode( mode ); - } - -private : - GrafPtr port ; - PenState oldPenState ; - RGBColor oldForeColor ; - RGBColor oldBackColor ; - RgnHandle clip ; - short font ; - short size ; - short style ; - short mode ; -} ; - pascal SInt32 AGAProgressBarDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param) { switch( message ) @@ -1079,7 +1045,7 @@ pascal SInt32 AGABevelButtonDefProc (SInt16 procID, ControlHandle theControl, Co return 0 ; { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; Boolean mRadioBehavior = false ; @@ -1219,7 +1185,7 @@ pascal SInt32 AGAButtonDefProc (SInt16 procID, ControlHandle theControl, Control return 0 ; { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; Boolean mRadioBehavior = false ; @@ -1456,7 +1422,7 @@ pascal SInt32 AGACheckBoxDefProc (SInt16 procID, ControlHandle theControl, Contr return 0 ; { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; Rect frame = (**theControl).contrlRect ; Boolean hasColor = true; Boolean disabled = (*theControl)->contrlHilite == 255 ; @@ -1844,7 +1810,7 @@ pascal SInt32 AGAStaticGroupBoxTextDefProc (SInt16 procID, ControlHandle theCont { bool disabled = false ; bool hasColor = true ; - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; FontInfo fi ; ::GetFontInfo( &fi ) ; @@ -1930,7 +1896,7 @@ pascal SInt32 AGAStaticTextDefProc (SInt16 procID, ControlHandle theControl, Con return 0 ; { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; int x = (**theControl).contrlRect.left ; int y = (**theControl).contrlRect.top ; @@ -2125,7 +2091,7 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr { case initCntl : { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; SetPort( (**theControl).contrlOwner ) ; ::TextFont( kFontIDGeneva ) ; ::TextSize( 10 ) ; @@ -2147,7 +2113,7 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr break ; case drawCntl : { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; SetPort( (**theControl).contrlOwner ) ; RGBBackColor( &gAGARamp[ kAGAWhite ] ) ; @@ -2254,9 +2220,8 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr break ; case kControlMsgKeyDown : { - AGAPortHelper help() ; + AGAPortHelper help( (**theControl).contrlOwner ) ; AGASetFontStyle( &info->fontStyle ) ; - SetPort( (**theControl).contrlOwner ) ; RGBBackColor( &gAGARamp[ kAGAWhite ] ) ; RGBForeColor( &gAGARamp[ kAGABlack ] ) ; ControlKeyDownRec * rec = (ControlKeyDownRec*) param ; @@ -2364,7 +2329,7 @@ pascal SInt32 AGAListControlDefProc (SInt16 procID, ControlHandle theControl, Co break ; case drawCntl : { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; RGBBackColor( &gAGARamp[ kAGAWhite ] ) ; EraseRect( &(**theControl).contrlRect ) ; @@ -2578,4 +2543,78 @@ void AGASetThemeWindowBackground (WindowRef inWindow, SetPort( port ) ; } +void AGAApplyThemeBackground(ThemeBackgroundKind inKind, + const Rect * bounds, + ThemeDrawState inState, + SInt16 inDepth, + Boolean inColorDev) +{ +} + +#endif +AGAPortHelper::AGAPortHelper( GrafPtr newport) +{ + GetPort( &port ) ; + SetPort( newport ) ; +// wxASSERT( newport->portRect.left == 0 && newport->portRect.top == 0 ) ; + GetPenState( &oldPenState ) ; + GetBackColor( &oldBackColor ) ; + GetForeColor( &oldForeColor ) ; + + clip = NewRgn() ; + GetClip( clip ); + font = GetPortTextFont( newport); + size = GetPortTextSize( newport); + style = GetPortTextFace( newport); + mode = GetPortTextMode( newport); + nport = newport ; + +} +AGAPortHelper::AGAPortHelper() +{ + clip = NULL ; +} +void AGAPortHelper::Setup( GrafPtr newport ) +{ + GetPort( &port ) ; + SetPort( newport ) ; +// wxASSERT( newport->portRect.left == 0 && newport->portRect.top == 0 ) ; + GetPenState( &oldPenState ) ; + GetBackColor( &oldBackColor ) ; + GetForeColor( &oldForeColor ) ; + + clip = NewRgn() ; + GetClip( clip ); + font = GetPortTextFont( newport); + size = GetPortTextSize( newport); + style = GetPortTextFace( newport); + mode = GetPortTextMode( newport); + nport = newport ; +} +void AGAPortHelper::Clear() +{ + if ( clip ) + { + DisposeRgn( clip ) ; + clip = NULL ; + } +} +AGAPortHelper::~AGAPortHelper() +{ + if ( clip ) + { + SetPort( nport ) ; + SetClip( clip ) ; + DisposeRgn( clip ) ; + RGBForeColor(&oldForeColor); + RGBBackColor(&oldBackColor); + SetPenState(&oldPenState); + + TextFont( font ); + TextSize( size ); + TextFace( style ); + TextMode( mode ); + SetPort( port ) ; + } +} diff --git a/src/mac/app.cpp b/src/mac/app.cpp index d5bb4c82d1..a11ff6db93 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -28,7 +28,7 @@ #include "wx/log.h" #include "wx/module.h" #include "wx/memory.h" - +#include "wx/tooltip.h" #if wxUSE_WX_RESOURCES #include "wx/resource.h" #endif @@ -44,6 +44,12 @@ #include "apprsrc.h" #include +#include + +#if wxUSE_SOCKETS +#include +#include +#endif extern char *wxBuffer; extern wxList wxPendingDelete; @@ -52,10 +58,14 @@ extern wxList *wxWinMacControlList; wxApp *wxTheApp = NULL; +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) EVT_IDLE(wxApp::OnIdle) + EVT_END_SESSION(wxApp::OnEndSession) + EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession) END_EVENT_TABLE() +#endif const short kMacMinHeap = (29 * 1024) ; @@ -76,25 +86,25 @@ bool wxApp::s_macSupportPCMenuShortcuts = true ; long wxApp::s_macAboutMenuItemId = wxID_ABOUT ; wxString wxApp::s_macHelpMenuTitleName = "&Help" ; -OSErr AEHandleODoc( AppleEvent *event , AppleEvent *reply , long refcon ) +pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEODoc( event , reply) ; } -OSErr AEHandleOApp( AppleEvent *event , AppleEvent *reply , long refcon ) +pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEOApp( event , reply ) ; } -OSErr AEHandlePDoc( AppleEvent *event , AppleEvent *reply , long refcon ) +pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEPDoc( event , reply ) ; } -OSErr AEHandleQuit( AppleEvent *event , AppleEvent *reply , long refcon ) +pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEQuit( event , reply) ; @@ -133,14 +143,14 @@ OSErr wxApp::MacHandleAEQuit(AppleEvent *event , AppleEvent *reply) return noErr ; } -char StringMac[] = "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" +char StringMac[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf" "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf" "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf" "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ; -char StringANSI[] = "\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8" +char StringANSI[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8" "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC" "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8" "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8" @@ -321,9 +331,6 @@ bool wxApp::Initialize() AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , NewAEEventHandlerProc(AEHandleOApp) , (long) wxTheApp , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , NewAEEventHandlerProc(AEHandlePDoc) , (long) wxTheApp , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerProc(AEHandleQuit) , (long) wxTheApp , FALSE ) ; -#if 0 - GUSISetup(GUSIwithInternetSockets); -#endif // test the minimal configuration necessary @@ -378,7 +385,7 @@ bool wxApp::Initialize() } #if __option(profile) - ProfilerInit( collectDetailed, bestTimeBase , 20000 , 30 ) ; + ProfilerInit( collectDetailed, bestTimeBase , 20000 , 40 ) ; #endif // now avoid exceptions thrown for new (bad_alloc) @@ -393,17 +400,15 @@ bool wxApp::Initialize() wxBuffer = new char[BUFSIZ + 512]; #endif -/* No longer used -#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT + wxClassInfo::InitializeClasses(); - streambuf* sBuf = new wxDebugStreamBuf; - ostream* oStr = new ostream(sBuf) ; - wxDebugContext::SetStream(oStr, sBuf); +#if wxUSE_RESOURCES +// wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion); #endif -*/ - - wxClassInfo::InitializeClasses(); +#if wxUSE_THREADS + wxPendingEventsLocker = new wxCriticalSection; +#endif wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING); wxTheColourDatabase->Initialize(); @@ -423,13 +428,29 @@ bool wxApp::Initialize() wxWinMacWindowList = new wxList(wxKEY_INTEGER); wxWinMacControlList = new wxList(wxKEY_INTEGER); - UMAShowArrowCursor() ; + wxMacCreateNotifierTable() ; + UMAShowArrowCursor() ; + return TRUE; } void wxApp::CleanUp() { +#if wxUSE_LOG + // flush the logged messages if any and install a 'safer' log target: the + // default one (wxLogGui) can't be used after the resources are freed just + // below and the user suppliedo ne might be even more unsafe (using any + // wxWindows GUI function is unsafe starting from now) + wxLog::DontCreateOnDemand(); + + // this will flush the old messages if any + delete wxLog::SetActiveTarget(new wxLogStderr); +#endif // wxUSE_LOG + + // One last chance for pending objects to be cleaned up + wxTheApp->DeletePendingObjects(); + wxModule::CleanUpModules(); #if wxUSE_WX_RESOURCES @@ -438,19 +459,8 @@ void wxApp::CleanUp() wxDeleteStockObjects() ; - // Destroy all GDI lists, etc. - - delete wxTheBrushList; - wxTheBrushList = NULL; - - delete wxThePenList; - wxThePenList = NULL; - - delete wxTheFontList; - wxTheFontList = NULL; - - delete wxTheBitmapList; - wxTheBitmapList = NULL; + // Destroy all GDI lists, etc. + wxDeleteStockLists(); delete wxTheColourDatabase; wxTheColourDatabase = NULL; @@ -460,9 +470,17 @@ void wxApp::CleanUp() delete[] wxBuffer; wxBuffer = NULL; + wxMacDestroyNotifierTable() ; if (wxWinMacWindowList) delete wxWinMacWindowList ; + delete wxPendingEvents; +#if wxUSE_THREADS + delete wxPendingEventsLocker; + // If we don't do the following, we get an apparent memory leak. + ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker(); +#endif + wxClassInfo::CleanUpClasses(); #if __option(profile) @@ -474,33 +492,33 @@ void wxApp::CleanUp() wxTheApp = NULL; #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT - // At this point we want to check if there are any memory - // blocks that aren't part of the wxDebugContext itself, - // as a special case. Then when dumping we need to ignore - // wxDebugContext, too. - if (wxDebugContext::CountObjectsLeft() > 0) - { - wxTrace("There were memory leaks.\n"); - wxDebugContext::Dump(); - wxDebugContext::PrintStatistics(); - } -// wxDebugContext::SetStream(NULL, NULL); + // At this point we want to check if there are any memory + // blocks that aren't part of the wxDebugContext itself, + // as a special case. Then when dumping we need to ignore + // wxDebugContext, too. + if (wxDebugContext::CountObjectsLeft(TRUE) > 0) + { + wxLogDebug(wxT("There were memory leaks.")); + wxDebugContext::Dump(); + wxDebugContext::PrintStatistics(); + } + // wxDebugContext::SetStream(NULL, NULL); #endif - // do it as the very last thing because everything else can log messages - wxLog::DontCreateOnDemand(); - // do it as the very last thing because everything else can log messages - delete wxLog::SetActiveTarget(NULL); +#if wxUSE_LOG + // do it as the very last thing because everything else can log messages + delete wxLog::SetActiveTarget(NULL); +#endif // wxUSE_LOG - ::PrClose() ; if (s_macCursorRgn) ::DisposeRgn(s_macCursorRgn); + #if 0 TerminateAE() ; #endif } -int wxEntry( int argc, char *argv[] ) +int wxEntry( int argc, char *argv[] , bool enterLoop ) { #ifdef __MWERKS__ #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT @@ -513,27 +531,24 @@ int wxEntry( int argc, char *argv[] ) wxDebugContext::SetCheckpoint(); #endif #endif - if (!wxApp::Initialize()) - return FALSE; - if (!wxTheApp) - { - if (!wxApp::GetInitializerFunction()) + if (!wxApp::Initialize()) + return 0; + // create the application object or ensure that one already exists + if (!wxTheApp) { - printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" ); - return 0; - }; + // The app may have declared a global application object, but we recommend + // the IMPLEMENT_APP macro is used instead, which sets an initializer + // function for delayed, dynamic app object construction. + wxCHECK_MSG( wxApp::GetInitializerFunction(), 0, + wxT("No initializer - use IMPLEMENT_APP macro.") ); - wxTheApp = (wxApp*) (* wxApp::GetInitializerFunction()) (); - }; + wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) (); + } - if (!wxTheApp) - { - printf( "wxWindows error: wxTheApp == NULL\n" ); - return 0; - }; + wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") ); #ifdef __WXMAC__ - argc = 1 ; // currently we don't support files as parameters + argc = 0 ; // currently we don't support files as parameters #endif wxTheApp->argc = argc; @@ -549,42 +564,58 @@ int wxEntry( int argc, char *argv[] ) // into wxTopLevelWindows by getting created // in OnInit(). - if (!wxTheApp->OnInit()) return 0; - int retValue = 0; - if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun(); - - if (wxTheApp->GetTopWindow()) - { - delete wxTheApp->GetTopWindow(); - wxTheApp->SetTopWindow(NULL); - } - - wxTheApp->DeletePendingObjects(); - - wxTheApp->OnExit(); - - wxApp::CleanUp(); + if ( wxTheApp->OnInit() ) + { + if ( enterLoop ) + { + retValue = wxTheApp->OnRun(); + } + else + // We want to initialize, but not run or exit immediately. + return 1; + } + //else: app initialization failed, so we skipped OnRun() - return retValue; + wxWindow *topWindow = wxTheApp->GetTopWindow(); + if ( topWindow ) + { + // Forcibly delete the window. + if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) || + topWindow->IsKindOf(CLASSINFO(wxDialog)) ) + { + topWindow->Close(TRUE); + wxTheApp->DeletePendingObjects(); + } + else + { + delete topWindow; + wxTheApp->SetTopWindow(NULL); + } + } + + wxTheApp->OnExit(); + + wxApp::CleanUp(); + + return retValue; }; // Static member initialization -wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL; +wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL; wxApp::wxApp() { m_topWindow = NULL; wxTheApp = this; - m_className = ""; + m_wantDebugOutput = TRUE ; - m_appName = ""; + argc = 0; argv = NULL; m_printMode = wxPRINT_WINDOWS; - m_exitOnFrameDelete = TRUE; m_auto3D = TRUE; } @@ -640,13 +671,14 @@ void wxApp::Dispatch() void wxApp::OnIdle(wxIdleEvent& event) { - static bool inOnIdle = FALSE; + static bool s_inOnIdle = FALSE; - // Avoid recursion (via ProcessEvent default case) - if (inOnIdle) - return; + // Avoid recursion (via ProcessEvent default case) + if ( s_inOnIdle ) + return; - inOnIdle = TRUE; + + s_inOnIdle = TRUE; // 'Garbage' collection of windows deleted with Close(). DeletePendingObjects(); @@ -662,13 +694,17 @@ void wxApp::OnIdle(wxIdleEvent& event) if (needMore) event.RequestMore(TRUE); - inOnIdle = FALSE; + // If they are pending events, we must process them: pending events are + // either events to the threads other than main or events posted with + // wxPostEvent() functions + wxMacProcessNotifierAndPendingEvents(); + + s_inOnIdle = FALSE; } void wxWakeUpIdle() { - // **** please implement me! **** - // Wake up the idle handler processor, even if it is in another thread... + wxMacWakeUp() ; } // Send idle event to all top-level windows @@ -729,32 +765,76 @@ void wxApp::DeletePendingObjects() } } -wxLog* wxApp::CreateLogTarget() +wxIcon +wxApp::GetStdIcon(int which) const { - return new wxLogGui; -} + switch(which) + { + case wxICON_INFORMATION: + return wxIcon("wxICON_INFO"); -wxWindow* wxApp::GetTopWindow() const -{ - if (m_topWindow) - return m_topWindow; - else if (wxTopLevelWindows.Number() > 0) - return (wxWindow*) wxTopLevelWindows.First()->Data(); - else - return NULL; + case wxICON_QUESTION: + return wxIcon("wxICON_QUESTION"); + + case wxICON_EXCLAMATION: + return wxIcon("wxICON_WARNING"); + + default: + wxFAIL_MSG(wxT("requested non existent standard icon")); + // still fall through + + case wxICON_HAND: + return wxIcon("wxICON_ERROR"); + } } void wxExit() { - wxApp::CleanUp(); + wxLogError(_("Fatal error: exiting")); + + wxApp::CleanUp(); ::ExitToShell() ; } +void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event)) +{ + if (GetTopWindow()) + GetTopWindow()->Close(TRUE); +} + +// Default behaviour: close the application with prompts. The +// user can veto the close, and therefore the end session. +void wxApp::OnQueryEndSession(wxCloseEvent& event) +{ + if (GetTopWindow()) + { + if (!GetTopWindow()->Close(!event.CanVeto())) + event.Veto(TRUE); + } +} + +extern "C" void wxCYield() ; +void wxCYield() +{ + wxYield() ; +} + // Yield to other processes bool wxYield() { -// YieldToAnyThread() ; - SystemTask() ; +#if wxUSE_THREADS + YieldToAnyThread() ; +#endif + EventRecord event ; + + long sleepTime = 0 ; //::GetCaretTime(); + + while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, wxApp::s_macCursorRgn)) + { + wxTheApp->MacHandleOneEvent( &event ); + } + + wxMacProcessNotifierAndPendingEvents() ; return TRUE; } @@ -762,6 +842,12 @@ bool wxYield() void wxApp::MacSuspend( bool convertClipboard ) { + // we have to deactive the window manually + + wxWindow* window = GetTopWindow() ; + if ( window ) + window->MacActivate( MacGetCurrentEvent() , false ) ; + s_lastMouseDown = 0 ; if( convertClipboard ) { @@ -784,13 +870,10 @@ void wxApp::MacResume( bool convertClipboard ) void wxApp::MacConvertPrivateToPublicScrap() { - ::ZeroScrap(); - ::TEToScrap(); } void wxApp::MacConvertPublicToPrivateScrap() { - ::TEFromScrap() ; } void wxApp::MacDoOneEvent() @@ -817,9 +900,7 @@ void wxApp::MacDoOneEvent() // repeaters -#if 0 - wxMacProcessSocketEvents() ; -#endif + wxMacProcessNotifierAndPendingEvents() ; } void wxApp::MacHandleOneEvent( EventRecord *ev ) @@ -874,6 +955,7 @@ void wxApp::MacHandleOneEvent( EventRecord *ev ) default: break; } + wxMacProcessNotifierAndPendingEvents() ; } void wxApp::MacHandleHighLevelEvent( EventRecord *ev ) @@ -885,6 +967,8 @@ bool s_macIsInModalLoop = false ; void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) { + wxToolTip::RemoveToolTips() ; + WindowRef window; WindowRef frontWindow = UMAFrontNonFloatingWindow() ; WindowAttributes frontWindowAttributes = NULL ; @@ -894,6 +978,9 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) short windowPart = ::FindWindow(ev->where, &window); wxWindow* win = wxFindWinFromMacWindow( window ) ; + BitMap screenBits; + GetQDGlobalsScreenBits( &screenBits ); + switch (windowPart) { case inMenuBar : @@ -908,10 +995,12 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) s_lastMouseDown = 0; } break ; +#if !TARGET_CARBON case inSysWindow : SystemClick( ev , window ) ; s_lastMouseDown = 0; break ; +#endif case inDrag : if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) ) { @@ -919,13 +1008,17 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) } else { - DragWindow(window, ev->where, &qd.screenBits.bounds); + DragWindow(window, ev->where, &screenBits.bounds); if (win) { GrafPtr port ; GetPort( &port ) ; Point pt = { 0, 0 } ; - SetPort( window ) ; + #if TARGET_CARBON + SetPort( GetWindowPort(window) ) ; + #else + SetPort( (window) ) ; + #endif SetOrigin( 0 , 0 ) ; LocalToGlobal( &pt ) ; SetPort( port ) ; @@ -944,7 +1037,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) s_lastMouseDown = 0; break; case inGrow: - int growResult = GrowWindow(window , ev->where, &qd.screenBits.bounds); + int growResult = GrowWindow(window , ev->where, &screenBits.bounds); if (growResult != 0) { int newWidth = LoWord(growResult); @@ -969,8 +1062,13 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) // TODO setup size event ZoomWindow( window , windowPart , false ) ; if (win) - win->SetSize( -1, -1, window->portRect.right-window->portRect.left , - window->portRect.bottom-window->portRect.top, wxSIZE_USE_EXISTING); + { + Rect tempRect ; + + GetWindowPortBounds(window, &tempRect ) ; + win->SetSize( -1, -1, tempRect.right-tempRect.left , + tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING); + } } s_lastMouseDown = 0; break; @@ -980,6 +1078,17 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) break ; case inContent : + { + GrafPtr port ; + GetPort( &port ) ; + #if TARGET_CARBON + SetPort( GetWindowPort(window) ) ; + #else + SetPort( (window) ) ; + #endif + SetOrigin( 0 , 0 ) ; + SetPort( port ) ; + } if ( window != frontWindow ) { if ( s_macIsInModalLoop ) @@ -1140,6 +1249,8 @@ long wxMacTranslateKey(unsigned char key, unsigned char code) void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) { + wxToolTip::RemoveToolTips() ; + UInt32 menuresult = UMAMenuEvent(ev) ; if ( HiWord( menuresult ) ) MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ; @@ -1268,12 +1379,14 @@ void wxApp::MacHandleDiskEvent( EventRecord *ev ) { if ( HiWord( ev->message ) != noErr ) { + #if !TARGET_CARBON OSErr err ; Point point ; SetPt( &point , 100 , 100 ) ; - err = DIBadMount( point , ev->message ) ; + err = DIBadMount( point , ev->message ) ; wxASSERT( err == noErr ) ; +#endif } } diff --git a/src/mac/bitmap.cpp b/src/mac/bitmap.cpp index 1ae5a445d4..2eddb0d5b9 100644 --- a/src/mac/bitmap.cpp +++ b/src/mac/bitmap.cpp @@ -25,8 +25,10 @@ extern "C" #include "xpm.h" } ; +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) +#endif #include @@ -69,16 +71,7 @@ GWorldPtr wxMacCreateGWorld( int height , int width , int depth ) if ( depth < 0 ) { - // get max pixel depth - CGrafPtr port ; - GetCWMgrPort( &port ) ; - GDHandle maxDevice ; - - maxDevice = GetMaxDevice( &port->portRect ) ; - if ( maxDevice ) - depth = (**((**maxDevice).gdPMap)).pixelSize ; - else - depth = 8 ; + depth = wxDisplayDepth() ; } err = NewGWorld( &port , depth , &rect , NULL , NULL , 0 ) ; @@ -178,7 +171,8 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits GetGWorld( &origPort , &origDevice ) ; SetGWorld( M_BITMAPDATA->m_hBitmap , NULL ) ; - + LockPixels( GetGWorldPixMap( (CGrafPtr) M_BITMAPDATA->m_hBitmap ) ) ; + // bits is a word aligned array unsigned char* linestart = (unsigned char*) bits ; @@ -211,6 +205,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits } } + UnlockPixels( GetGWorldPixMap( (CGrafPtr) M_BITMAPDATA->m_hBitmap ) ) ; SetGWorld( origPort , origDevice ) ; } @@ -514,6 +509,8 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) } m_maskBitmap = wxMacCreateGWorld( bitmap.GetWidth() , bitmap.GetHeight() , 1 ) ; + LockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ; + LockPixels( GetGWorldPixMap( (CGrafPtr) ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap ) ) ; RGBColor maskColor = colour.GetPixel() ; // this is not very efficient, but I can't think @@ -545,6 +542,8 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) } } } + UnlockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ; + UnlockPixels( GetGWorldPixMap( ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap ) ) ; SetGWorld( origPort , origDevice ) ; return TRUE; @@ -712,8 +711,8 @@ bool wxXPMFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type if (dc) { if (SelectObject(dc, (HBITMAP) M_BITMAPHANDLERDATA->m_hBitmap)) - { /* for following SetPixel */ - /* fill the XImage struct 'by hand' */ + { + ximage.width = M_BITMAPHANDLERDATA->m_width; ximage.height = M_BITMAPHANDLERDATA->m_height; ximage.depth = M_BITMAPHANDLERDATA->m_depth; @@ -725,7 +724,7 @@ bool wxXPMFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type DeleteDC(dc); if (errorStatus == XpmSuccess) - return TRUE; /* no error */ + return TRUE; else return FALSE; } else return FALSE; @@ -809,19 +808,6 @@ bool wxBMPResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long int desiredWidth, int desiredHeight) { // TODO: load colourmap. -/* - M_BITMAPHANDLERDATA->m_hBitmap = (WXHBITMAP) ::LoadBitmap(wxGetInstance(), name); - if (M_BITMAPHANDLERDATA->m_hBitmap) - { - M_BITMAPHANDLERDATA->m_ok = TRUE; - BITMAP bm; - GetObject((HBITMAP) M_BITMAPHANDLERDATA->m_hBitmap, sizeof(BITMAP), (LPSTR) &bm); - M_BITMAPHANDLERDATA->m_width = bm.bmWidth; - M_BITMAPHANDLERDATA->m_height = bm.bmHeight; - M_BITMAPHANDLERDATA->m_depth = bm.bmBitsPixel; - return TRUE; - } -*/ // it's probably not found wxLogError("Can't load bitmap '%s' from resources! Check .rc file.", name.c_str()); @@ -852,11 +838,6 @@ bool wxBMPFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long fla #if USE_IMAGE_LOADING_IN_MSW wxPalette *palette = NULL; bool success = FALSE; -/* - if (type & wxBITMAP_DISCARD_COLOURMAP) - success = wxLoadIntoBitmap(WXSTRINGCAST name, bitmap); - else -*/ success = (wxLoadIntoBitmap(WXSTRINGCAST name, bitmap, &palette) != 0); if (!success && palette) { @@ -884,7 +865,6 @@ bool wxBMPFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type } - void wxBitmap::CleanUpHandlers() { wxNode *node = sm_handlers.First(); @@ -903,7 +883,7 @@ void wxBitmap::InitStandardHandlers() AddHandler( new wxPICTResourceHandler ) ; AddHandler( new wxICONResourceHandler ) ; AddHandler(new wxXPMFileHandler); - AddHandler(new wxXPMDataHandler); + AddHandler(new wxXPMDataHandler); AddHandler(new wxBMPResourceHandler); AddHandler(new wxBMPFileHandler); } diff --git a/src/mac/bmpbuttn.cpp b/src/mac/bmpbuttn.cpp index 569a2cd338..c143138609 100644 --- a/src/mac/bmpbuttn.cpp +++ b/src/mac/bmpbuttn.cpp @@ -15,11 +15,13 @@ #include "wx/bmpbuttn.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) +#endif #include -PicHandle MakePict(GWorldPtr wp) ; +PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ; bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, @@ -48,8 +50,6 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit if ( height == -1 && bitmap.Ok()) height = bitmap.GetHeight() + 2*m_marginY; - m_macHorizontalBorder = 0 ; // additional pixels around the real control - m_macVerticalBorder = 0 ; Rect bounds ; Str255 title ; MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ; @@ -68,7 +68,14 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit icon = bmap->m_hPict ; else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) { - icon = MakePict( bmap->m_hBitmap ) ; + if ( m_buttonBitmap.GetMask() ) + { + icon = MakePict( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ) ; + } + else + { + icon = MakePict( bmap->m_hBitmap , NULL ) ; + } } } ControlButtonContentInfo info ; @@ -94,7 +101,14 @@ void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) icon = bmap->m_hPict ; else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) { - icon = MakePict( bmap->m_hBitmap ) ; + if ( m_buttonBitmap.GetMask() ) + { + icon = MakePict( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ) ; + } + else + { + icon = MakePict( bmap->m_hBitmap , NULL ) ; + } } } ControlButtonContentInfo info ; diff --git a/src/mac/brush.cpp b/src/mac/brush.cpp index 7ba6dfc990..cb9d76d1ab 100644 --- a/src/mac/brush.cpp +++ b/src/mac/brush.cpp @@ -17,7 +17,9 @@ #include "wx/utils.h" #include "wx/brush.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) +#endif wxBrushRefData::wxBrushRefData() { diff --git a/src/mac/button.cpp b/src/mac/button.cpp index 4635492a17..47f66425e2 100644 --- a/src/mac/button.cpp +++ b/src/mac/button.cpp @@ -15,7 +15,9 @@ #include "wx/button.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) +#endif #include // Button @@ -29,8 +31,6 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, { Rect bounds ; Str255 title ; - m_macHorizontalBorder = 2 ; // additional pixels around the real control - m_macVerticalBorder = 2 ; MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; @@ -66,22 +66,32 @@ void wxButton::SetDefault() wxSize wxButton::DoGetBestSize() const { - int wBtn = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder; - int hBtn = 13 + 2 * m_macVerticalBorder; + int wBtn = m_label.Length() * 8 + 12 ; + int hBtn = 20 ; + + if ( wBtn < 80 ) + wBtn = 80 ; return wxSize(wBtn, hBtn); } wxSize wxButton::GetDefaultSize() { - int wBtn = 15 * 8 + 12 + 2 * 2; - int hBtn = 13 + 2 * 2; + int wBtn = 80 /* + 2 * m_macHorizontalBorder */ ; + int hBtn = 20 /* + 2 * m_macVerticalBorder */ ; return wxSize(wBtn, hBtn); } void wxButton::Command (wxCommandEvent & event) { + if ( m_macControl ) + { + HiliteControl( m_macControl , kControlButtonPart ) ; + unsigned long finalTicks ; + Delay( 8 , &finalTicks ) ; + HiliteControl( m_macControl , 0 ) ; + } ProcessCommand (event); } diff --git a/src/mac/carbon/accel.cpp b/src/mac/carbon/accel.cpp index f8796e111a..b0b8734d55 100644 --- a/src/mac/carbon/accel.cpp +++ b/src/mac/carbon/accel.cpp @@ -17,7 +17,9 @@ #include "wx/accel.h" #include "wx/string.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) +#endif class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData { diff --git a/src/mac/carbon/aga.cpp b/src/mac/carbon/aga.cpp index 40abb5cbb9..6b14ecd9c0 100644 --- a/src/mac/carbon/aga.cpp +++ b/src/mac/carbon/aga.cpp @@ -1,3 +1,5 @@ +#if !TARGET_CARBON + #include #include #include @@ -600,6 +602,10 @@ void AGADeactivateControl( ControlHandle inControl ) } } } + else + { + ::HiliteControl( inControl , 255 ) ; + } } void AGAActivateControl( ControlHandle inControl ) @@ -615,6 +621,10 @@ void AGAActivateControl( ControlHandle inControl ) } } } + else + { + ::HiliteControl( inControl , 0 ) ; + } } OSErr AGASetKeyboardFocus (WindowPtr inWindow, @@ -718,6 +728,7 @@ void DisposeExtCDEFInfo( ControlHandle theControl) DisposeHandle( info->children ) ; info->children = NULL ; free( (void*) (**theControl).contrlRfCon ) ; + (**theControl).contrlRfCon = NULL ; } } } @@ -922,51 +933,6 @@ void AGASetFontStyle( ControlFontStyleRec *fontstyle ) ::RGBBackColor( &fontstyle->backColor ) ; } ; -class AGAPortHelper -{ -public : - AGAPortHelper() - { - GetPenState( &oldPenState ) ; - GetBackColor( &oldBackColor ) ; - GetForeColor( &oldForeColor ) ; - - GetPort( &port ) ; - clip = NewRgn() ; - GetClip( clip ); - font = port->txFont; - size = port->txSize; - style = port->txFace; - mode = port->txMode; - - } - ~AGAPortHelper() - { - SetPort( port ) ; - SetClip( clip ) ; - DisposeRgn( clip ) ; - RGBForeColor(&oldForeColor); - RGBBackColor(&oldBackColor); - SetPenState(&oldPenState); - - TextFont( font ); - TextSize( size ); - TextFace( style ); - TextMode( mode ); - } - -private : - GrafPtr port ; - PenState oldPenState ; - RGBColor oldForeColor ; - RGBColor oldBackColor ; - RgnHandle clip ; - short font ; - short size ; - short style ; - short mode ; -} ; - pascal SInt32 AGAProgressBarDefProc (SInt16 procID, ControlHandle theControl, ControlDefProcMessage message, SInt32 param) { switch( message ) @@ -1079,7 +1045,7 @@ pascal SInt32 AGABevelButtonDefProc (SInt16 procID, ControlHandle theControl, Co return 0 ; { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; Boolean mRadioBehavior = false ; @@ -1219,7 +1185,7 @@ pascal SInt32 AGAButtonDefProc (SInt16 procID, ControlHandle theControl, Control return 0 ; { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; Boolean mRadioBehavior = false ; @@ -1456,7 +1422,7 @@ pascal SInt32 AGACheckBoxDefProc (SInt16 procID, ControlHandle theControl, Contr return 0 ; { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; Rect frame = (**theControl).contrlRect ; Boolean hasColor = true; Boolean disabled = (*theControl)->contrlHilite == 255 ; @@ -1844,7 +1810,7 @@ pascal SInt32 AGAStaticGroupBoxTextDefProc (SInt16 procID, ControlHandle theCont { bool disabled = false ; bool hasColor = true ; - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; FontInfo fi ; ::GetFontInfo( &fi ) ; @@ -1930,7 +1896,7 @@ pascal SInt32 AGAStaticTextDefProc (SInt16 procID, ControlHandle theControl, Con return 0 ; { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; int x = (**theControl).contrlRect.left ; int y = (**theControl).contrlRect.top ; @@ -2125,7 +2091,7 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr { case initCntl : { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; SetPort( (**theControl).contrlOwner ) ; ::TextFont( kFontIDGeneva ) ; ::TextSize( 10 ) ; @@ -2147,7 +2113,7 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr break ; case drawCntl : { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; SetPort( (**theControl).contrlOwner ) ; RGBBackColor( &gAGARamp[ kAGAWhite ] ) ; @@ -2254,9 +2220,8 @@ pascal SInt32 AGAEditTextDefProc (SInt16 procID, ControlHandle theControl, Contr break ; case kControlMsgKeyDown : { - AGAPortHelper help() ; + AGAPortHelper help( (**theControl).contrlOwner ) ; AGASetFontStyle( &info->fontStyle ) ; - SetPort( (**theControl).contrlOwner ) ; RGBBackColor( &gAGARamp[ kAGAWhite ] ) ; RGBForeColor( &gAGARamp[ kAGABlack ] ) ; ControlKeyDownRec * rec = (ControlKeyDownRec*) param ; @@ -2364,7 +2329,7 @@ pascal SInt32 AGAListControlDefProc (SInt16 procID, ControlHandle theControl, Co break ; case drawCntl : { - AGAPortHelper help() ; + AGAPortHelper help((**theControl).contrlOwner) ; AGASetFontStyle( &info->fontStyle ) ; RGBBackColor( &gAGARamp[ kAGAWhite ] ) ; EraseRect( &(**theControl).contrlRect ) ; @@ -2578,4 +2543,78 @@ void AGASetThemeWindowBackground (WindowRef inWindow, SetPort( port ) ; } +void AGAApplyThemeBackground(ThemeBackgroundKind inKind, + const Rect * bounds, + ThemeDrawState inState, + SInt16 inDepth, + Boolean inColorDev) +{ +} + +#endif +AGAPortHelper::AGAPortHelper( GrafPtr newport) +{ + GetPort( &port ) ; + SetPort( newport ) ; +// wxASSERT( newport->portRect.left == 0 && newport->portRect.top == 0 ) ; + GetPenState( &oldPenState ) ; + GetBackColor( &oldBackColor ) ; + GetForeColor( &oldForeColor ) ; + + clip = NewRgn() ; + GetClip( clip ); + font = GetPortTextFont( newport); + size = GetPortTextSize( newport); + style = GetPortTextFace( newport); + mode = GetPortTextMode( newport); + nport = newport ; + +} +AGAPortHelper::AGAPortHelper() +{ + clip = NULL ; +} +void AGAPortHelper::Setup( GrafPtr newport ) +{ + GetPort( &port ) ; + SetPort( newport ) ; +// wxASSERT( newport->portRect.left == 0 && newport->portRect.top == 0 ) ; + GetPenState( &oldPenState ) ; + GetBackColor( &oldBackColor ) ; + GetForeColor( &oldForeColor ) ; + + clip = NewRgn() ; + GetClip( clip ); + font = GetPortTextFont( newport); + size = GetPortTextSize( newport); + style = GetPortTextFace( newport); + mode = GetPortTextMode( newport); + nport = newport ; +} +void AGAPortHelper::Clear() +{ + if ( clip ) + { + DisposeRgn( clip ) ; + clip = NULL ; + } +} +AGAPortHelper::~AGAPortHelper() +{ + if ( clip ) + { + SetPort( nport ) ; + SetClip( clip ) ; + DisposeRgn( clip ) ; + RGBForeColor(&oldForeColor); + RGBBackColor(&oldBackColor); + SetPenState(&oldPenState); + + TextFont( font ); + TextSize( size ); + TextFace( style ); + TextMode( mode ); + SetPort( port ) ; + } +} diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index d5bb4c82d1..a11ff6db93 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -28,7 +28,7 @@ #include "wx/log.h" #include "wx/module.h" #include "wx/memory.h" - +#include "wx/tooltip.h" #if wxUSE_WX_RESOURCES #include "wx/resource.h" #endif @@ -44,6 +44,12 @@ #include "apprsrc.h" #include +#include + +#if wxUSE_SOCKETS +#include +#include +#endif extern char *wxBuffer; extern wxList wxPendingDelete; @@ -52,10 +58,14 @@ extern wxList *wxWinMacControlList; wxApp *wxTheApp = NULL; +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) EVT_IDLE(wxApp::OnIdle) + EVT_END_SESSION(wxApp::OnEndSession) + EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession) END_EVENT_TABLE() +#endif const short kMacMinHeap = (29 * 1024) ; @@ -76,25 +86,25 @@ bool wxApp::s_macSupportPCMenuShortcuts = true ; long wxApp::s_macAboutMenuItemId = wxID_ABOUT ; wxString wxApp::s_macHelpMenuTitleName = "&Help" ; -OSErr AEHandleODoc( AppleEvent *event , AppleEvent *reply , long refcon ) +pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEODoc( event , reply) ; } -OSErr AEHandleOApp( AppleEvent *event , AppleEvent *reply , long refcon ) +pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEOApp( event , reply ) ; } -OSErr AEHandlePDoc( AppleEvent *event , AppleEvent *reply , long refcon ) +pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEPDoc( event , reply ) ; } -OSErr AEHandleQuit( AppleEvent *event , AppleEvent *reply , long refcon ) +pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEQuit( event , reply) ; @@ -133,14 +143,14 @@ OSErr wxApp::MacHandleAEQuit(AppleEvent *event , AppleEvent *reply) return noErr ; } -char StringMac[] = "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" +char StringMac[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf" "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf" "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf" "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ; -char StringANSI[] = "\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8" +char StringANSI[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8" "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC" "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8" "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8" @@ -321,9 +331,6 @@ bool wxApp::Initialize() AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , NewAEEventHandlerProc(AEHandleOApp) , (long) wxTheApp , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , NewAEEventHandlerProc(AEHandlePDoc) , (long) wxTheApp , FALSE ) ; AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerProc(AEHandleQuit) , (long) wxTheApp , FALSE ) ; -#if 0 - GUSISetup(GUSIwithInternetSockets); -#endif // test the minimal configuration necessary @@ -378,7 +385,7 @@ bool wxApp::Initialize() } #if __option(profile) - ProfilerInit( collectDetailed, bestTimeBase , 20000 , 30 ) ; + ProfilerInit( collectDetailed, bestTimeBase , 20000 , 40 ) ; #endif // now avoid exceptions thrown for new (bad_alloc) @@ -393,17 +400,15 @@ bool wxApp::Initialize() wxBuffer = new char[BUFSIZ + 512]; #endif -/* No longer used -#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT + wxClassInfo::InitializeClasses(); - streambuf* sBuf = new wxDebugStreamBuf; - ostream* oStr = new ostream(sBuf) ; - wxDebugContext::SetStream(oStr, sBuf); +#if wxUSE_RESOURCES +// wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion); #endif -*/ - - wxClassInfo::InitializeClasses(); +#if wxUSE_THREADS + wxPendingEventsLocker = new wxCriticalSection; +#endif wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING); wxTheColourDatabase->Initialize(); @@ -423,13 +428,29 @@ bool wxApp::Initialize() wxWinMacWindowList = new wxList(wxKEY_INTEGER); wxWinMacControlList = new wxList(wxKEY_INTEGER); - UMAShowArrowCursor() ; + wxMacCreateNotifierTable() ; + UMAShowArrowCursor() ; + return TRUE; } void wxApp::CleanUp() { +#if wxUSE_LOG + // flush the logged messages if any and install a 'safer' log target: the + // default one (wxLogGui) can't be used after the resources are freed just + // below and the user suppliedo ne might be even more unsafe (using any + // wxWindows GUI function is unsafe starting from now) + wxLog::DontCreateOnDemand(); + + // this will flush the old messages if any + delete wxLog::SetActiveTarget(new wxLogStderr); +#endif // wxUSE_LOG + + // One last chance for pending objects to be cleaned up + wxTheApp->DeletePendingObjects(); + wxModule::CleanUpModules(); #if wxUSE_WX_RESOURCES @@ -438,19 +459,8 @@ void wxApp::CleanUp() wxDeleteStockObjects() ; - // Destroy all GDI lists, etc. - - delete wxTheBrushList; - wxTheBrushList = NULL; - - delete wxThePenList; - wxThePenList = NULL; - - delete wxTheFontList; - wxTheFontList = NULL; - - delete wxTheBitmapList; - wxTheBitmapList = NULL; + // Destroy all GDI lists, etc. + wxDeleteStockLists(); delete wxTheColourDatabase; wxTheColourDatabase = NULL; @@ -460,9 +470,17 @@ void wxApp::CleanUp() delete[] wxBuffer; wxBuffer = NULL; + wxMacDestroyNotifierTable() ; if (wxWinMacWindowList) delete wxWinMacWindowList ; + delete wxPendingEvents; +#if wxUSE_THREADS + delete wxPendingEventsLocker; + // If we don't do the following, we get an apparent memory leak. + ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker(); +#endif + wxClassInfo::CleanUpClasses(); #if __option(profile) @@ -474,33 +492,33 @@ void wxApp::CleanUp() wxTheApp = NULL; #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT - // At this point we want to check if there are any memory - // blocks that aren't part of the wxDebugContext itself, - // as a special case. Then when dumping we need to ignore - // wxDebugContext, too. - if (wxDebugContext::CountObjectsLeft() > 0) - { - wxTrace("There were memory leaks.\n"); - wxDebugContext::Dump(); - wxDebugContext::PrintStatistics(); - } -// wxDebugContext::SetStream(NULL, NULL); + // At this point we want to check if there are any memory + // blocks that aren't part of the wxDebugContext itself, + // as a special case. Then when dumping we need to ignore + // wxDebugContext, too. + if (wxDebugContext::CountObjectsLeft(TRUE) > 0) + { + wxLogDebug(wxT("There were memory leaks.")); + wxDebugContext::Dump(); + wxDebugContext::PrintStatistics(); + } + // wxDebugContext::SetStream(NULL, NULL); #endif - // do it as the very last thing because everything else can log messages - wxLog::DontCreateOnDemand(); - // do it as the very last thing because everything else can log messages - delete wxLog::SetActiveTarget(NULL); +#if wxUSE_LOG + // do it as the very last thing because everything else can log messages + delete wxLog::SetActiveTarget(NULL); +#endif // wxUSE_LOG - ::PrClose() ; if (s_macCursorRgn) ::DisposeRgn(s_macCursorRgn); + #if 0 TerminateAE() ; #endif } -int wxEntry( int argc, char *argv[] ) +int wxEntry( int argc, char *argv[] , bool enterLoop ) { #ifdef __MWERKS__ #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT @@ -513,27 +531,24 @@ int wxEntry( int argc, char *argv[] ) wxDebugContext::SetCheckpoint(); #endif #endif - if (!wxApp::Initialize()) - return FALSE; - if (!wxTheApp) - { - if (!wxApp::GetInitializerFunction()) + if (!wxApp::Initialize()) + return 0; + // create the application object or ensure that one already exists + if (!wxTheApp) { - printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" ); - return 0; - }; + // The app may have declared a global application object, but we recommend + // the IMPLEMENT_APP macro is used instead, which sets an initializer + // function for delayed, dynamic app object construction. + wxCHECK_MSG( wxApp::GetInitializerFunction(), 0, + wxT("No initializer - use IMPLEMENT_APP macro.") ); - wxTheApp = (wxApp*) (* wxApp::GetInitializerFunction()) (); - }; + wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) (); + } - if (!wxTheApp) - { - printf( "wxWindows error: wxTheApp == NULL\n" ); - return 0; - }; + wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") ); #ifdef __WXMAC__ - argc = 1 ; // currently we don't support files as parameters + argc = 0 ; // currently we don't support files as parameters #endif wxTheApp->argc = argc; @@ -549,42 +564,58 @@ int wxEntry( int argc, char *argv[] ) // into wxTopLevelWindows by getting created // in OnInit(). - if (!wxTheApp->OnInit()) return 0; - int retValue = 0; - if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun(); - - if (wxTheApp->GetTopWindow()) - { - delete wxTheApp->GetTopWindow(); - wxTheApp->SetTopWindow(NULL); - } - - wxTheApp->DeletePendingObjects(); - - wxTheApp->OnExit(); - - wxApp::CleanUp(); + if ( wxTheApp->OnInit() ) + { + if ( enterLoop ) + { + retValue = wxTheApp->OnRun(); + } + else + // We want to initialize, but not run or exit immediately. + return 1; + } + //else: app initialization failed, so we skipped OnRun() - return retValue; + wxWindow *topWindow = wxTheApp->GetTopWindow(); + if ( topWindow ) + { + // Forcibly delete the window. + if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) || + topWindow->IsKindOf(CLASSINFO(wxDialog)) ) + { + topWindow->Close(TRUE); + wxTheApp->DeletePendingObjects(); + } + else + { + delete topWindow; + wxTheApp->SetTopWindow(NULL); + } + } + + wxTheApp->OnExit(); + + wxApp::CleanUp(); + + return retValue; }; // Static member initialization -wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL; +wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL; wxApp::wxApp() { m_topWindow = NULL; wxTheApp = this; - m_className = ""; + m_wantDebugOutput = TRUE ; - m_appName = ""; + argc = 0; argv = NULL; m_printMode = wxPRINT_WINDOWS; - m_exitOnFrameDelete = TRUE; m_auto3D = TRUE; } @@ -640,13 +671,14 @@ void wxApp::Dispatch() void wxApp::OnIdle(wxIdleEvent& event) { - static bool inOnIdle = FALSE; + static bool s_inOnIdle = FALSE; - // Avoid recursion (via ProcessEvent default case) - if (inOnIdle) - return; + // Avoid recursion (via ProcessEvent default case) + if ( s_inOnIdle ) + return; - inOnIdle = TRUE; + + s_inOnIdle = TRUE; // 'Garbage' collection of windows deleted with Close(). DeletePendingObjects(); @@ -662,13 +694,17 @@ void wxApp::OnIdle(wxIdleEvent& event) if (needMore) event.RequestMore(TRUE); - inOnIdle = FALSE; + // If they are pending events, we must process them: pending events are + // either events to the threads other than main or events posted with + // wxPostEvent() functions + wxMacProcessNotifierAndPendingEvents(); + + s_inOnIdle = FALSE; } void wxWakeUpIdle() { - // **** please implement me! **** - // Wake up the idle handler processor, even if it is in another thread... + wxMacWakeUp() ; } // Send idle event to all top-level windows @@ -729,32 +765,76 @@ void wxApp::DeletePendingObjects() } } -wxLog* wxApp::CreateLogTarget() +wxIcon +wxApp::GetStdIcon(int which) const { - return new wxLogGui; -} + switch(which) + { + case wxICON_INFORMATION: + return wxIcon("wxICON_INFO"); -wxWindow* wxApp::GetTopWindow() const -{ - if (m_topWindow) - return m_topWindow; - else if (wxTopLevelWindows.Number() > 0) - return (wxWindow*) wxTopLevelWindows.First()->Data(); - else - return NULL; + case wxICON_QUESTION: + return wxIcon("wxICON_QUESTION"); + + case wxICON_EXCLAMATION: + return wxIcon("wxICON_WARNING"); + + default: + wxFAIL_MSG(wxT("requested non existent standard icon")); + // still fall through + + case wxICON_HAND: + return wxIcon("wxICON_ERROR"); + } } void wxExit() { - wxApp::CleanUp(); + wxLogError(_("Fatal error: exiting")); + + wxApp::CleanUp(); ::ExitToShell() ; } +void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event)) +{ + if (GetTopWindow()) + GetTopWindow()->Close(TRUE); +} + +// Default behaviour: close the application with prompts. The +// user can veto the close, and therefore the end session. +void wxApp::OnQueryEndSession(wxCloseEvent& event) +{ + if (GetTopWindow()) + { + if (!GetTopWindow()->Close(!event.CanVeto())) + event.Veto(TRUE); + } +} + +extern "C" void wxCYield() ; +void wxCYield() +{ + wxYield() ; +} + // Yield to other processes bool wxYield() { -// YieldToAnyThread() ; - SystemTask() ; +#if wxUSE_THREADS + YieldToAnyThread() ; +#endif + EventRecord event ; + + long sleepTime = 0 ; //::GetCaretTime(); + + while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, wxApp::s_macCursorRgn)) + { + wxTheApp->MacHandleOneEvent( &event ); + } + + wxMacProcessNotifierAndPendingEvents() ; return TRUE; } @@ -762,6 +842,12 @@ bool wxYield() void wxApp::MacSuspend( bool convertClipboard ) { + // we have to deactive the window manually + + wxWindow* window = GetTopWindow() ; + if ( window ) + window->MacActivate( MacGetCurrentEvent() , false ) ; + s_lastMouseDown = 0 ; if( convertClipboard ) { @@ -784,13 +870,10 @@ void wxApp::MacResume( bool convertClipboard ) void wxApp::MacConvertPrivateToPublicScrap() { - ::ZeroScrap(); - ::TEToScrap(); } void wxApp::MacConvertPublicToPrivateScrap() { - ::TEFromScrap() ; } void wxApp::MacDoOneEvent() @@ -817,9 +900,7 @@ void wxApp::MacDoOneEvent() // repeaters -#if 0 - wxMacProcessSocketEvents() ; -#endif + wxMacProcessNotifierAndPendingEvents() ; } void wxApp::MacHandleOneEvent( EventRecord *ev ) @@ -874,6 +955,7 @@ void wxApp::MacHandleOneEvent( EventRecord *ev ) default: break; } + wxMacProcessNotifierAndPendingEvents() ; } void wxApp::MacHandleHighLevelEvent( EventRecord *ev ) @@ -885,6 +967,8 @@ bool s_macIsInModalLoop = false ; void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) { + wxToolTip::RemoveToolTips() ; + WindowRef window; WindowRef frontWindow = UMAFrontNonFloatingWindow() ; WindowAttributes frontWindowAttributes = NULL ; @@ -894,6 +978,9 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) short windowPart = ::FindWindow(ev->where, &window); wxWindow* win = wxFindWinFromMacWindow( window ) ; + BitMap screenBits; + GetQDGlobalsScreenBits( &screenBits ); + switch (windowPart) { case inMenuBar : @@ -908,10 +995,12 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) s_lastMouseDown = 0; } break ; +#if !TARGET_CARBON case inSysWindow : SystemClick( ev , window ) ; s_lastMouseDown = 0; break ; +#endif case inDrag : if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) ) { @@ -919,13 +1008,17 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) } else { - DragWindow(window, ev->where, &qd.screenBits.bounds); + DragWindow(window, ev->where, &screenBits.bounds); if (win) { GrafPtr port ; GetPort( &port ) ; Point pt = { 0, 0 } ; - SetPort( window ) ; + #if TARGET_CARBON + SetPort( GetWindowPort(window) ) ; + #else + SetPort( (window) ) ; + #endif SetOrigin( 0 , 0 ) ; LocalToGlobal( &pt ) ; SetPort( port ) ; @@ -944,7 +1037,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) s_lastMouseDown = 0; break; case inGrow: - int growResult = GrowWindow(window , ev->where, &qd.screenBits.bounds); + int growResult = GrowWindow(window , ev->where, &screenBits.bounds); if (growResult != 0) { int newWidth = LoWord(growResult); @@ -969,8 +1062,13 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) // TODO setup size event ZoomWindow( window , windowPart , false ) ; if (win) - win->SetSize( -1, -1, window->portRect.right-window->portRect.left , - window->portRect.bottom-window->portRect.top, wxSIZE_USE_EXISTING); + { + Rect tempRect ; + + GetWindowPortBounds(window, &tempRect ) ; + win->SetSize( -1, -1, tempRect.right-tempRect.left , + tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING); + } } s_lastMouseDown = 0; break; @@ -980,6 +1078,17 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) break ; case inContent : + { + GrafPtr port ; + GetPort( &port ) ; + #if TARGET_CARBON + SetPort( GetWindowPort(window) ) ; + #else + SetPort( (window) ) ; + #endif + SetOrigin( 0 , 0 ) ; + SetPort( port ) ; + } if ( window != frontWindow ) { if ( s_macIsInModalLoop ) @@ -1140,6 +1249,8 @@ long wxMacTranslateKey(unsigned char key, unsigned char code) void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) { + wxToolTip::RemoveToolTips() ; + UInt32 menuresult = UMAMenuEvent(ev) ; if ( HiWord( menuresult ) ) MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ; @@ -1268,12 +1379,14 @@ void wxApp::MacHandleDiskEvent( EventRecord *ev ) { if ( HiWord( ev->message ) != noErr ) { + #if !TARGET_CARBON OSErr err ; Point point ; SetPt( &point , 100 , 100 ) ; - err = DIBadMount( point , ev->message ) ; + err = DIBadMount( point , ev->message ) ; wxASSERT( err == noErr ) ; +#endif } } diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index 1ae5a445d4..2eddb0d5b9 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -25,8 +25,10 @@ extern "C" #include "xpm.h" } ; +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) +#endif #include @@ -69,16 +71,7 @@ GWorldPtr wxMacCreateGWorld( int height , int width , int depth ) if ( depth < 0 ) { - // get max pixel depth - CGrafPtr port ; - GetCWMgrPort( &port ) ; - GDHandle maxDevice ; - - maxDevice = GetMaxDevice( &port->portRect ) ; - if ( maxDevice ) - depth = (**((**maxDevice).gdPMap)).pixelSize ; - else - depth = 8 ; + depth = wxDisplayDepth() ; } err = NewGWorld( &port , depth , &rect , NULL , NULL , 0 ) ; @@ -178,7 +171,8 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits GetGWorld( &origPort , &origDevice ) ; SetGWorld( M_BITMAPDATA->m_hBitmap , NULL ) ; - + LockPixels( GetGWorldPixMap( (CGrafPtr) M_BITMAPDATA->m_hBitmap ) ) ; + // bits is a word aligned array unsigned char* linestart = (unsigned char*) bits ; @@ -211,6 +205,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits } } + UnlockPixels( GetGWorldPixMap( (CGrafPtr) M_BITMAPDATA->m_hBitmap ) ) ; SetGWorld( origPort , origDevice ) ; } @@ -514,6 +509,8 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) } m_maskBitmap = wxMacCreateGWorld( bitmap.GetWidth() , bitmap.GetHeight() , 1 ) ; + LockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ; + LockPixels( GetGWorldPixMap( (CGrafPtr) ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap ) ) ; RGBColor maskColor = colour.GetPixel() ; // this is not very efficient, but I can't think @@ -545,6 +542,8 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) } } } + UnlockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ; + UnlockPixels( GetGWorldPixMap( ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap ) ) ; SetGWorld( origPort , origDevice ) ; return TRUE; @@ -712,8 +711,8 @@ bool wxXPMFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type if (dc) { if (SelectObject(dc, (HBITMAP) M_BITMAPHANDLERDATA->m_hBitmap)) - { /* for following SetPixel */ - /* fill the XImage struct 'by hand' */ + { + ximage.width = M_BITMAPHANDLERDATA->m_width; ximage.height = M_BITMAPHANDLERDATA->m_height; ximage.depth = M_BITMAPHANDLERDATA->m_depth; @@ -725,7 +724,7 @@ bool wxXPMFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type DeleteDC(dc); if (errorStatus == XpmSuccess) - return TRUE; /* no error */ + return TRUE; else return FALSE; } else return FALSE; @@ -809,19 +808,6 @@ bool wxBMPResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long int desiredWidth, int desiredHeight) { // TODO: load colourmap. -/* - M_BITMAPHANDLERDATA->m_hBitmap = (WXHBITMAP) ::LoadBitmap(wxGetInstance(), name); - if (M_BITMAPHANDLERDATA->m_hBitmap) - { - M_BITMAPHANDLERDATA->m_ok = TRUE; - BITMAP bm; - GetObject((HBITMAP) M_BITMAPHANDLERDATA->m_hBitmap, sizeof(BITMAP), (LPSTR) &bm); - M_BITMAPHANDLERDATA->m_width = bm.bmWidth; - M_BITMAPHANDLERDATA->m_height = bm.bmHeight; - M_BITMAPHANDLERDATA->m_depth = bm.bmBitsPixel; - return TRUE; - } -*/ // it's probably not found wxLogError("Can't load bitmap '%s' from resources! Check .rc file.", name.c_str()); @@ -852,11 +838,6 @@ bool wxBMPFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long fla #if USE_IMAGE_LOADING_IN_MSW wxPalette *palette = NULL; bool success = FALSE; -/* - if (type & wxBITMAP_DISCARD_COLOURMAP) - success = wxLoadIntoBitmap(WXSTRINGCAST name, bitmap); - else -*/ success = (wxLoadIntoBitmap(WXSTRINGCAST name, bitmap, &palette) != 0); if (!success && palette) { @@ -884,7 +865,6 @@ bool wxBMPFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type } - void wxBitmap::CleanUpHandlers() { wxNode *node = sm_handlers.First(); @@ -903,7 +883,7 @@ void wxBitmap::InitStandardHandlers() AddHandler( new wxPICTResourceHandler ) ; AddHandler( new wxICONResourceHandler ) ; AddHandler(new wxXPMFileHandler); - AddHandler(new wxXPMDataHandler); + AddHandler(new wxXPMDataHandler); AddHandler(new wxBMPResourceHandler); AddHandler(new wxBMPFileHandler); } diff --git a/src/mac/carbon/bmpbuttn.cpp b/src/mac/carbon/bmpbuttn.cpp index 569a2cd338..c143138609 100644 --- a/src/mac/carbon/bmpbuttn.cpp +++ b/src/mac/carbon/bmpbuttn.cpp @@ -15,11 +15,13 @@ #include "wx/bmpbuttn.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) +#endif #include -PicHandle MakePict(GWorldPtr wp) ; +PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ; bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, @@ -48,8 +50,6 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit if ( height == -1 && bitmap.Ok()) height = bitmap.GetHeight() + 2*m_marginY; - m_macHorizontalBorder = 0 ; // additional pixels around the real control - m_macVerticalBorder = 0 ; Rect bounds ; Str255 title ; MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ; @@ -68,7 +68,14 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit icon = bmap->m_hPict ; else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) { - icon = MakePict( bmap->m_hBitmap ) ; + if ( m_buttonBitmap.GetMask() ) + { + icon = MakePict( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ) ; + } + else + { + icon = MakePict( bmap->m_hBitmap , NULL ) ; + } } } ControlButtonContentInfo info ; @@ -94,7 +101,14 @@ void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) icon = bmap->m_hPict ; else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) { - icon = MakePict( bmap->m_hBitmap ) ; + if ( m_buttonBitmap.GetMask() ) + { + icon = MakePict( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ) ; + } + else + { + icon = MakePict( bmap->m_hBitmap , NULL ) ; + } } } ControlButtonContentInfo info ; diff --git a/src/mac/carbon/brush.cpp b/src/mac/carbon/brush.cpp index 7ba6dfc990..cb9d76d1ab 100644 --- a/src/mac/carbon/brush.cpp +++ b/src/mac/carbon/brush.cpp @@ -17,7 +17,9 @@ #include "wx/utils.h" #include "wx/brush.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) +#endif wxBrushRefData::wxBrushRefData() { diff --git a/src/mac/carbon/button.cpp b/src/mac/carbon/button.cpp index 4635492a17..47f66425e2 100644 --- a/src/mac/carbon/button.cpp +++ b/src/mac/carbon/button.cpp @@ -15,7 +15,9 @@ #include "wx/button.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) +#endif #include // Button @@ -29,8 +31,6 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, { Rect bounds ; Str255 title ; - m_macHorizontalBorder = 2 ; // additional pixels around the real control - m_macVerticalBorder = 2 ; MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; @@ -66,22 +66,32 @@ void wxButton::SetDefault() wxSize wxButton::DoGetBestSize() const { - int wBtn = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder; - int hBtn = 13 + 2 * m_macVerticalBorder; + int wBtn = m_label.Length() * 8 + 12 ; + int hBtn = 20 ; + + if ( wBtn < 80 ) + wBtn = 80 ; return wxSize(wBtn, hBtn); } wxSize wxButton::GetDefaultSize() { - int wBtn = 15 * 8 + 12 + 2 * 2; - int hBtn = 13 + 2 * 2; + int wBtn = 80 /* + 2 * m_macHorizontalBorder */ ; + int hBtn = 20 /* + 2 * m_macVerticalBorder */ ; return wxSize(wBtn, hBtn); } void wxButton::Command (wxCommandEvent & event) { + if ( m_macControl ) + { + HiliteControl( m_macControl , kControlButtonPart ) ; + unsigned long finalTicks ; + Delay( 8 , &finalTicks ) ; + HiliteControl( m_macControl , 0 ) ; + } ProcessCommand (event); } diff --git a/src/mac/carbon/checkbox.cpp b/src/mac/carbon/checkbox.cpp index df3424b88f..c3d4ce9709 100644 --- a/src/mac/carbon/checkbox.cpp +++ b/src/mac/carbon/checkbox.cpp @@ -15,8 +15,10 @@ #include "wx/checkbox.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) +#endif #include diff --git a/src/mac/carbon/checklst.cpp b/src/mac/carbon/checklst.cpp index 7387e3e471..2f43152c2a 100644 --- a/src/mac/carbon/checklst.cpp +++ b/src/mac/carbon/checklst.cpp @@ -23,7 +23,9 @@ // implementation // ============================================================================ +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox) +#endif // ---------------------------------------------------------------------------- // implementation of wxCheckListBox class diff --git a/src/mac/carbon/choice.cpp b/src/mac/carbon/choice.cpp index 343f3d239e..1c36eef12d 100644 --- a/src/mac/carbon/choice.cpp +++ b/src/mac/carbon/choice.cpp @@ -17,7 +17,9 @@ #include "wx/choice.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl) +#endif bool wxChoice::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, @@ -27,13 +29,12 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - m_noStrings = n; Rect bounds ; Str255 title ; MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; - + m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0 , kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ; @@ -41,11 +42,15 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; for ( int i = 0 ; i < n ; i++ ) { - appendmenu( m_macPopUpMenuHandle , choices[i] ) ; + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; + m_strings.Add( choices[i] ) ; } SetControlMinimum( m_macControl , 0 ) ; - SetControlMaximum( m_macControl , m_noStrings) ; - SetControlValue( m_macControl , 1 ) ; + SetControlMaximum( m_macControl , Number()) ; + if ( n > 0 ) + SetControlValue( m_macControl , 1 ) ; MacPostControlCreate() ; @@ -54,27 +59,28 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, void wxChoice::Append(const wxString& item) { - appendmenu( m_macPopUpMenuHandle , item ) ; - m_noStrings ++; - SetControlMaximum( m_macControl , m_noStrings) ; + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; + m_strings.Add( item ) ; + SetControlMaximum( m_macControl , Number()) ; } void wxChoice::Delete(int n) { - wxASSERT( n < m_noStrings ) ; ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ; - m_noStrings --; - SetControlMaximum( m_macControl , m_noStrings) ; + m_strings.Remove( n ) ; + SetControlMaximum( m_macControl , Number()) ; } void wxChoice::Clear() { - for ( int i = 0 ; i < m_noStrings ; i++ ) + for ( int i = 0 ; i < Number() ; i++ ) { ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ; } - m_noStrings = 0; - SetControlMaximum( m_macControl , m_noStrings) ; + m_strings.Clear() ; + SetControlMaximum( m_macControl , Number()) ; } int wxChoice::GetSelection() const @@ -99,7 +105,7 @@ void wxChoice::SetSelection(int n) int wxChoice::FindString(const wxString& s) const { - for( int i = 0 ; i < m_noStrings ; i++ ) + for( int i = 0 ; i < Number() ; i++ ) { if ( GetString( i ) == s ) return i ; @@ -109,10 +115,7 @@ int wxChoice::FindString(const wxString& s) const wxString wxChoice::GetString(int n) const { - Str255 text ; - ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , text ) ; - p2cstr( text ) ; - return wxString( text ); + return m_strings[n] ; } void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags) diff --git a/src/mac/carbon/clipbrd.cpp b/src/mac/carbon/clipbrd.cpp index 36f4c0f4d9..ca5b793396 100644 --- a/src/mac/carbon/clipbrd.cpp +++ b/src/mac/carbon/clipbrd.cpp @@ -21,48 +21,214 @@ #include "wx/metafile.h" #include "wx/clipbrd.h" +#define wxUSE_DATAOBJ 1 + #include // open/close + +bool clipboard_opened = false ; + bool wxOpenClipboard() { + clipboard_opened = true ; return TRUE; } bool wxCloseClipboard() { + clipboard_opened = false ; return TRUE; } bool wxIsClipboardOpened() { - return TRUE; + return clipboard_opened; } -// get/set data - bool wxEmptyClipboard() { - ZeroScrap() ; + +#if TARGET_CARBON + OSStatus err ; + err = ClearCurrentScrap( ); +#else + OSErr err ; + err = ZeroScrap( ); +#endif + if ( err ) + { + wxLogSysError(_("Failed to empty the clipboard.")); + return FALSE ; + } return TRUE; } -bool wxSetClipboardData(wxDataFormat dataFormat,const void *data,int width , int height) +// get/set data + +// clipboard formats + +bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat) { - 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, dataFormat.GetFormatId(), &flavorFlags )) == noErr) + { + if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr) + { + return TRUE ; + } + } + } + return FALSE; + +#else + long offset ; + if ( GetScrap( NULL , dataFormat.GetFormatId() , &offset ) > 0 ) + { + return TRUE ; + } + return FALSE; +#endif } -void *wxGetClipboardData(wxDataFormat dataFormat, long *len) +bool wxSetClipboardData(wxDataFormat dataFormat,const void *data,int width , int height) { - return NULL; -} +#if !TARGET_CARBON + OSErr err = noErr ; +#else + OSStatus err = noErr ; +#endif + + switch (dataFormat.GetType()) + { + case wxDF_BITMAP: + { + /* + wxBitmap *bitmap = (wxBitmap *)data; + + HDC hdcMem = CreateCompatibleDC((HDC) NULL); + HDC hdcSrc = CreateCompatibleDC((HDC) NULL); + HBITMAP old = (HBITMAP) + ::SelectObject(hdcSrc, (HBITMAP)bitmap->GetHBITMAP()); + HBITMAP hBitmap = CreateCompatibleBitmap(hdcSrc, + bitmap->GetWidth(), + bitmap->GetHeight()); + if (!hBitmap) + { + SelectObject(hdcSrc, old); + DeleteDC(hdcMem); + DeleteDC(hdcSrc); + return FALSE; + } + + HBITMAP old1 = (HBITMAP) SelectObject(hdcMem, hBitmap); + BitBlt(hdcMem, 0, 0, bitmap->GetWidth(), bitmap->GetHeight(), + hdcSrc, 0, 0, SRCCOPY); + + // Select new bitmap out of memory DC + SelectObject(hdcMem, old1); + + // Set the data + handle = ::SetClipboardData(CF_BITMAP, hBitmap); + + // Clean up + SelectObject(hdcSrc, old); + DeleteDC(hdcSrc); + DeleteDC(hdcMem); + */ + break; + } + case wxDF_DIB: + { + /* +#if wxUSE_IMAGE_LOADING_IN_MSW + wxBitmap *bitmap = (wxBitmap *)data; + HBITMAP hBitmap = (HBITMAP)bitmap->GetHBITMAP(); + // NULL palette means to use the system one + HANDLE hDIB = wxBitmapToDIB(hBitmap, (HPALETTE)NULL); + handle = SetClipboardData(CF_DIB, hDIB); +#endif // wxUSE_IMAGE_LOADING_IN_MSW +*/ + break; + } -// clipboard formats +#if wxUSE_METAFILE + case wxDF_METAFILE: + { + wxMetafile *wxMF = (wxMetafile *)data; + PicHandle pict = wxMF->GetHMETAFILE() ; + HLock( (Handle) pict ) ; +#if !TARGET_CARBON + err = PutScrap( GetHandleSize( (Handle) pict ) , 'PICT' , *pict ) ; +#else + ScrapRef scrap; + err = GetCurrentScrap (&scrap); + if ( !err ) + { + err = PutScrapFlavor (scrap, 'PICT', 0, GetHandleSize((Handle) pict), *pict); + } +#endif + HUnlock( (Handle) pict ) ; + break; + } +#endif + case wxDF_SYLK: + case wxDF_DIF: + case wxDF_TIFF: + case wxDF_PALETTE: + default: + { + wxLogError(_("Unsupported clipboard format.")); + return FALSE; + } -bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat) -{ - return FALSE; + case wxDF_OEMTEXT: + dataFormat = wxDF_TEXT; + // fall through + + case wxDF_TEXT: + { + wxString mac ; + if ( wxApp::s_macDefaultEncodingIsPC ) + { + mac = wxMacMakeMacStringFromPC((char *)data) ; + } + else + { + mac = (char *)data ; + } +#if !TARGET_CARBON + err = PutScrap( mac.Length() , 'TEXT' , mac.c_str() ) ; +#else + ScrapRef scrap; + err = GetCurrentScrap (&scrap); + if ( !err ) + { + err = PutScrapFlavor (scrap, 'TEXT', 0, mac.Length(), mac.c_str()); + } +#endif + break; + } + } + + if ( err ) + { + wxLogSysError(_("Failed to set clipboard data.")); + + return FALSE; + } + + return TRUE; } wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat) @@ -80,11 +246,17 @@ bool wxGetClipboardFormatName(wxDataFormat dataFormat, wxChar *formatName, int m return FALSE; } +void *wxGetClipboardData(wxDataFormat dataFormat, long *len) +{ + return NULL; +} + + /* * Generalized clipboard implementation by Matthew Flatt */ -IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject) +IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxClipboardBase) wxClipboard::wxClipboard() { @@ -143,9 +315,9 @@ bool wxClipboard::AddData( wxDataObject *data ) #if wxUSE_DATAOBJ wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") ); - wxDataFormat format = data->GetFormat(); + wxDataFormat format = data->GetPreferredFormat(); - switch ( format ) + switch ( format.GetType() ) { case wxDF_TEXT: case wxDF_OEMTEXT: @@ -160,10 +332,10 @@ bool wxClipboard::AddData( wxDataObject *data ) { wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data; wxBitmap bitmap(bitmapDataObject->GetBitmap()); - return wxSetClipboardData(data->GetFormat(), &bitmap); + return wxSetClipboardData(format, &bitmap); } -#if wxUSE_METAFILE +#if 0 // wxUSE_METAFILE case wxDF_METAFILE: { wxMetafileDataObject* metaFileDataObject = @@ -176,11 +348,12 @@ bool wxClipboard::AddData( wxDataObject *data ) #endif // wxUSE_METAFILE default: - return wxSetClipboardData(data); + // return wxSetClipboardData(data); + break ; } #else // !wxUSE_DATAOBJ - return FALSE; #endif + return FALSE; } void wxClipboard::Close() @@ -188,7 +361,7 @@ void wxClipboard::Close() wxCloseClipboard(); } -bool wxClipboard::IsSupported( wxDataFormat format ) +bool wxClipboard::IsSupported( const wxDataFormat &format ) { return wxIsClipboardFormatAvailable(format); } @@ -198,7 +371,7 @@ bool wxClipboard::GetData( wxDataObject& data ) #if wxUSE_DATAOBJ wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") ); - wxDataFormat format = data.GetFormat(); + wxDataFormat format = data.GetPreferredFormat(); switch ( format ) { case wxDF_TEXT: @@ -219,7 +392,7 @@ bool wxClipboard::GetData( wxDataObject& data ) case wxDF_DIB: { wxBitmapDataObject& bitmapDataObject = (wxBitmapDataObject &)data; - wxBitmap* bitmap = (wxBitmap *)wxGetClipboardData(data->GetFormat()); + wxBitmap* bitmap = (wxBitmap *)wxGetClipboardData(format ); if ( !bitmap ) return FALSE; @@ -228,7 +401,7 @@ bool wxClipboard::GetData( wxDataObject& data ) return TRUE; } -#if wxUSE_METAFILE +#if 0 // wxUSE_METAFILE case wxDF_METAFILE: { wxMetafileDataObject& metaFileDataObject = (wxMetafileDataObject &)data; diff --git a/src/mac/carbon/colordlg.cpp b/src/mac/carbon/colordlg.cpp index e91938f8ad..c6037a9f96 100644 --- a/src/mac/carbon/colordlg.cpp +++ b/src/mac/carbon/colordlg.cpp @@ -16,7 +16,9 @@ #include "wx/mac/colordlg.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog) +#endif /* * wxColourDialog diff --git a/src/mac/carbon/colour.cpp b/src/mac/carbon/colour.cpp index 68abfa77bd..cc549b5f11 100644 --- a/src/mac/carbon/colour.cpp +++ b/src/mac/carbon/colour.cpp @@ -16,7 +16,9 @@ #include "wx/gdicmn.h" #include "wx/colour.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject) +#endif // Colour diff --git a/src/mac/carbon/combobox.cpp b/src/mac/carbon/combobox.cpp index d1fd686a85..1689c15490 100644 --- a/src/mac/carbon/combobox.cpp +++ b/src/mac/carbon/combobox.cpp @@ -16,7 +16,9 @@ #include "wx/combobox.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) +#endif // right now we don't support editable comboboxes @@ -44,7 +46,9 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; for ( int i = 0 ; i < n ; i++ ) { - appendmenu( m_macPopUpMenuHandle , choices[i] ) ; + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; } SetControlMinimum( m_macControl , 0 ) ; SetControlMaximum( m_macControl , m_noStrings) ; @@ -125,7 +129,9 @@ void wxComboBox::SetSelection(long from, long to) void wxComboBox::Append(const wxString& item) { - appendmenu( m_macPopUpMenuHandle , item ) ; + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; m_noStrings ++; SetControlMaximum( m_macControl , m_noStrings) ; } diff --git a/src/mac/carbon/control.cpp b/src/mac/carbon/control.cpp index f6fa56cb91..161d1b71b1 100644 --- a/src/mac/carbon/control.cpp +++ b/src/mac/carbon/control.cpp @@ -16,15 +16,18 @@ #include "wx/control.h" #include "wx/notebook.h" #include "wx/tabctrl.h" +#include "wx/radiobox.h" #include "wx/spinbutt.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) -BEGIN_EVENT_TABLE(wxControl, wxControlBase) +BEGIN_EVENT_TABLE(wxControl, wxWindow) EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) EVT_CHAR( wxControl::OnKeyDown ) EVT_PAINT( wxControl::OnPaint ) END_EVENT_TABLE() +#endif #include @@ -32,6 +35,7 @@ END_EVENT_TABLE() ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; +pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ; pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) { if ( partCode != 0) @@ -46,9 +50,9 @@ pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCod wxControl::wxControl() { - m_macControl = NULL ; - m_macHorizontalBorder = 0 ; // additional pixels around the real control - m_macVerticalBorder = 0 ; + m_macControl = NULL ; + m_macHorizontalBorder = 0 ; // additional pixels around the real control + m_macVerticalBorder = 0 ; m_backgroundColour = *wxWHITE; m_foregroundColour = *wxBLACK; #if WXWIN_COMPATIBILITY @@ -61,6 +65,24 @@ wxControl::wxControl() } } +bool wxControl::Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos, + const wxSize& size, long style, + 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 (rval) { +#if wxUSE_VALIDATORS + SetValidator(validator); +#endif + } + return rval; +} + wxControl::~wxControl() { m_isBeingDeleted = TRUE; @@ -79,21 +101,6 @@ wxControl::~wxControl() } } -bool wxControl::Create(wxWindow *parent, wxWindowID id, - const wxPoint& pos, - const wxSize& size, long style, - const wxValidator& validator, - const wxString& name) -{ - bool rval = wxWindow::Create(parent, id, pos, size, style, name); - if (rval) { -#if wxUSE_VALIDATORS - SetValidator(validator); -#endif - } - return rval; -} - void wxControl::SetLabel(const wxString& title) { m_label = title ; @@ -222,7 +229,7 @@ void wxControl::MacPostControlCreate() { // no font } - else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) ) + else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) { ControlFontStyleRec controlstyle ; controlstyle.flags = kControlUseFontMask ; @@ -275,14 +282,16 @@ void wxControl::MacAdjustControlRect() { if ( IsKindOf( CLASSINFO( wxButton ) ) ) { - m_width = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder; + m_width = m_label.Length() * 8 + 12 ; } else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) { m_width = m_label.Length() * 8 ; } else - m_width = bestsize.right - bestsize.left + 2 * m_macHorizontalBorder; + m_width = bestsize.right - bestsize.left ; + + m_width += 2 * m_macHorizontalBorder ; } if ( m_height == -1 ) { @@ -296,7 +305,7 @@ void wxControl::MacAdjustControlRect() wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ; if ( helper.Ok() ) { - UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; + UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; } } } @@ -312,8 +321,10 @@ void wxControl::MacSuperChangedPosition() { if ( m_macControl ) { - int former_mac_x = (**m_macControl).contrlRect.left ; - int former_mac_y = (**m_macControl).contrlRect.top ; + Rect contrlRect ; + GetControlBounds( m_macControl , &contrlRect ) ; + int former_mac_x = contrlRect.left ; + int former_mac_y = contrlRect.top ; int mac_x = m_x ; int mac_y = m_y ; GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ; @@ -327,12 +338,12 @@ void wxControl::MacSuperChangedPosition() { { Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; - InvalRect( &inval ) ; + InvalWindowRect( rootwindow , &inval ) ; } - UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; + UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; { Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; - InvalRect( &inval ) ; + InvalWindowRect( rootwindow , &inval ) ; } } if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) @@ -378,7 +389,7 @@ void wxControl::MacSuperEnabled( bool enabled ) } } wxWindow::MacSuperEnabled( enabled ) ; - */ +*/ } void wxControl::MacSuperShown( bool show ) @@ -418,8 +429,10 @@ void wxControl::DoSetSize(int x, int y, int former_w = m_width ; int former_h = m_height ; - int former_mac_x = (**m_macControl).contrlRect.left ; - int former_mac_y = (**m_macControl).contrlRect.top ; + Rect contrlRect ; + GetControlBounds( m_macControl , &contrlRect ) ; + int former_mac_x = contrlRect.left ; + int former_mac_y = contrlRect.top ; int currentX, currentY; GetPosition(¤tX, ¤tY); @@ -430,9 +443,9 @@ void wxControl::DoSetSize(int x, int y, int actualHeight = height; int actualX = x; int actualY = y; - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualX = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualY = currentY; if (width == -1) actualWidth = currentW ; @@ -443,7 +456,8 @@ void wxControl::DoSetSize(int x, int y, return ; AdjustForParentClientOrigin(actualX, actualY, sizeFlags); - wxMacDrawingHelper focus( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ; + WindowRef macrootwindow = GetMacRootWindow() ; + wxMacDrawingHelper focus( wxFindWinFromMacWindow( macrootwindow ) ) ; int mac_x = actualX ; int mac_y = actualY ; @@ -453,12 +467,12 @@ void wxControl::DoSetSize(int x, int y, { { Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; - InvalRect( &inval ) ; + InvalWindowRect( macrootwindow, &inval ) ; } - UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; + UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; { Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; - InvalRect( &inval ) ; + InvalWindowRect(macrootwindow, &inval ) ; } } @@ -477,15 +491,15 @@ void wxControl::DoSetSize(int x, int y, { { Rect inval = { mac_y , mac_x , mac_y + former_h , mac_x + former_w } ; - InvalRect( &inval ) ; + InvalWindowRect( macrootwindow, &inval ) ; } m_width = actualWidth ; m_height = actualHeight ; - UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; + UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; { Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; - InvalRect( &inval ) ; + InvalWindowRect( macrootwindow , &inval ) ; } MacRepositionScrollBars() ; @@ -555,6 +569,47 @@ void wxControl::Refresh(bool eraseBack, const wxRect *rect) } } +void wxControl::MacRedrawControl() +{ + if ( m_macControl ) + { + WindowRef window = GetMacRootWindow() ; + if ( window ) + { + wxWindow* win = wxFindWinFromMacWindow( window ) ; + if ( win ) + { + wxMacDrawingHelper help( win ) ; + // the mac control manager always assumes to have the origin at 0,0 + SetOrigin( 0 , 0 ) ; + + bool hasTabBehind = false ; + wxWindow* parent = GetParent() ; + while ( parent ) + { + if( parent->MacGetWindowData() ) + { + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; + break ; + } + + if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) + { + if ( ((wxControl*)parent)->m_macControl ) + SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ; + break ; + } + + parent = parent->GetParent() ; + } + + UMADrawControl( m_macControl ) ; + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; + } + } + } +} + void wxControl::OnPaint(wxPaintEvent& event) { if ( m_macControl ) @@ -566,6 +621,7 @@ void wxControl::OnPaint(wxPaintEvent& event) if ( win ) { wxMacDrawingHelper help( win ) ; + // the mac control manager always assumes to have the origin at 0,0 SetOrigin( 0 , 0 ) ; bool hasTabBehind = false ; @@ -629,7 +685,7 @@ void wxControl::OnMouseEvent( wxMouseEvent &event ) return ; } - if (event.GetEventType() == wxEVT_LEFT_DOWN ) + if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) { int x = event.m_x ; diff --git a/src/mac/carbon/cursor.cpp b/src/mac/carbon/cursor.cpp index dee7c92b5f..fa0bbf76b2 100644 --- a/src/mac/carbon/cursor.cpp +++ b/src/mac/carbon/cursor.cpp @@ -16,17 +16,33 @@ #include "wx/cursor.h" #include "wx/icon.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap) +#endif const short kwxCursorHandId = 9 ; const short kwxCursorSizeWEId = 10 ; const short kwxCursorSizeNSId = 11 ; +#if !TARGET_CARBON Cursor* MacArrowCursorPtr = &qd.arrow ; CursHandle MacArrowCursor = &MacArrowCursorPtr ; +#else +bool MacArrowInstalled = false ; +Cursor MacArrow ; +Cursor* MacArrowCursorPtr = &MacArrow ; +CursHandle MacArrowCursor = &MacArrowCursorPtr ; +#endif CursHandle gMacCurrentCursor = NULL ; wxCursorRefData::wxCursorRefData() { +#if TARGET_CARBON + if ( !MacArrowInstalled ) + { + MacArrowCursorPtr = GetQDGlobalsArrow( &MacArrow ) ; + MacArrowInstalled = true ; + } +#endif m_width = 32; m_height = 32; m_hCursor = NULL ; @@ -34,8 +50,8 @@ wxCursorRefData::wxCursorRefData() wxCursorRefData::~wxCursorRefData() { - if ( m_hCursor && ( m_hCursor != MacArrowCursor ) ) - ::DisposeHandle( (Handle) m_hCursor ) ; +// if ( m_hCursor && ( m_hCursor != MacArrowCursor ) ) +// ::ReleaseResource( (Handle) m_hCursor ) ; } // Cursors diff --git a/src/mac/carbon/data.cpp b/src/mac/carbon/data.cpp index fab57c49fe..cb3ff34b9c 100644 --- a/src/mac/carbon/data.cpp +++ b/src/mac/carbon/data.cpp @@ -102,8 +102,8 @@ const wxChar *wxFrameNameStr = wxT("frame"); const wxChar *wxGaugeNameStr = wxT("gauge"); const wxChar *wxStaticBoxNameStr = wxT("groupBox"); const wxChar *wxListBoxNameStr = wxT("listBox"); -const wxChar *wxStaticTextNameStr = wxT("message"); -const wxChar *wxStaticBitmapNameStr = wxT("message"); +const wxChar *wxStaticTextNameStr = wxT("statictext"); +const wxChar *wxStaticBitmapNameStr = wxT("staticbitmap"); const wxChar *wxMultiTextNameStr = wxT("multitext"); const wxChar *wxPanelNameStr = wxT("panel"); const wxChar *wxRadioBoxNameStr = wxT("radioBox"); @@ -134,5 +134,17 @@ const wxChar *wxDirDialogDefaultFolderStr = wxT("/"); const wxChar *wxFloatToStringStr = wxT("%.2f"); const wxChar *wxDoubleToStringStr = wxT("%.2f"); +#if wxUSE_SHARED_LIBRARY +///// Event tables (also must be in one, statically-linked file for shared libraries) + +// This is the base, wxEvtHandler 'bootstrap' code which is expanded manually here +const wxEventTable *wxEvtHandler::GetEventTable() const { return &wxEvtHandler::sm_eventTable; } + +const wxEventTable wxEvtHandler::sm_eventTable = + { NULL, &wxEvtHandler::sm_eventTableEntries[0] }; + +const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = { { 0, 0, 0, NULL } }; +#endif + const wxSize wxDefaultSize(-1, -1); const wxPoint wxDefaultPosition(-1, -1); diff --git a/src/mac/carbon/dataobj.cpp b/src/mac/carbon/dataobj.cpp index fbaf93061d..67f938b414 100644 --- a/src/mac/carbon/dataobj.cpp +++ b/src/mac/carbon/dataobj.cpp @@ -44,56 +44,40 @@ wxDataFormat::wxDataFormat() { - m_vType = wxDF_INVALID; - m_vFormat = 0; + m_type = wxDF_INVALID; + m_format = 0; } -wxDataFormat::wxDataFormat( - wxDataFormatId vType -) +wxDataFormat::wxDataFormat( wxDataFormatId vType ) { - PrepareFormats(); SetType(vType); } -wxDataFormat::wxDataFormat( - const wxChar* zId -) +wxDataFormat::wxDataFormat( const wxChar* zId) { - PrepareFormats(); SetId(zId); } -wxDataFormat::wxDataFormat( - const wxString& rId -) +wxDataFormat::wxDataFormat( const wxString& rId) { - PrepareFormats(); SetId(rId); } -wxDataFormat::wxDataFormat( - NativeFormat vFormat -) +wxDataFormat::wxDataFormat( NativeFormat vFormat) { - PrepareFormats(); SetId(vFormat); } -void wxDataFormat::SetType( - wxDataFormatId vType -) +void wxDataFormat::SetType( wxDataFormatId Type ) { - m_vType = vType; - - if (m_vType == wxDF_TEXT) - m_vFormat = 0; - else - if (m_vType == wxDF_BITMAP) - m_vFormat = 0; - else - if (m_vType == wxDF_FILENAME) - m_vFormat = 0; + m_type = Type; + + if (m_type == wxDF_TEXT) + m_format = 'TEXT'; + else if (m_type == wxDF_BITMAP || m_type == wxDF_METAFILE ) + m_format = 'PICT'; + else if (m_type == wxDF_FILENAME) + m_format = 'SPEC'; else { wxFAIL_MSG( wxT("invalid dataformat") ); @@ -102,56 +86,37 @@ void wxDataFormat::SetType( wxDataFormatId wxDataFormat::GetType() const { - return m_vType; + return m_type; } wxString wxDataFormat::GetId() const { - wxString sRet(""); // TODO: gdk_atom_name( m_format ) ); + wxString sRet(""); // TODO: to name of ( m_format ) ); return sRet; } -void wxDataFormat::SetId( - NativeFormat vFormat -) +void wxDataFormat::SetId( NativeFormat format ) { - m_vFormat = vFormat; -// TODO: -/* - if (m_format == g_textAtom) + m_format = format; + + if (m_format == 'TEXT') m_type = wxDF_TEXT; else - if (m_format == g_pngAtom) + if (m_format == 'PICT') m_type = wxDF_BITMAP; else - if (m_format == g_fileAtom) + if (m_format == 'SPEC') m_type = wxDF_FILENAME; else m_type = wxDF_PRIVATE; -*/ } -void wxDataFormat::SetId( - const wxChar* zId -) +void wxDataFormat::SetId( const wxChar* zId ) { wxString tmp(zId); - m_vType = wxDF_PRIVATE; - m_vFormat = 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); -} - -void wxDataFormat::PrepareFormats() -{ -// TODO: -/* - if (!g_textAtom) - g_textAtom = gdk_atom_intern( "STRING", FALSE ); - if (!g_pngAtom) - g_pngAtom = gdk_atom_intern( "image/png", FALSE ); - if (!g_fileAtom) - g_fileAtom = gdk_atom_intern( "file:ALL", FALSE ); -*/ + m_type = wxDF_PRIVATE; + m_format = 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); } //------------------------------------------------------------------------- diff --git a/src/mac/carbon/dc.cpp b/src/mac/carbon/dc.cpp index ecbb3ca703..1682209492 100644 --- a/src/mac/carbon/dc.cpp +++ b/src/mac/carbon/dc.cpp @@ -14,8 +14,11 @@ #endif #include "wx/dc.h" +#include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) +#endif //----------------------------------------------------------------------------- // constants @@ -34,7 +37,7 @@ long wxDC::m_macCurrentPortId = 1 ; // wxDC //----------------------------------------------------------------------------- -wxDC::wxDC(void) +wxDC::wxDC() { m_ok = FALSE; m_optimize = FALSE; @@ -42,8 +45,8 @@ wxDC::wxDC(void) m_colour = TRUE; m_clipping = FALSE; - m_mm_to_pix_x = 1.0; - m_mm_to_pix_y = 1.0; + m_mm_to_pix_x = mm2pt; + m_mm_to_pix_y = mm2pt; m_logicalOriginX = 0; m_logicalOriginY = 0; @@ -102,20 +105,32 @@ wxDC::wxDC(void) wxDC::~wxDC(void) { + if ( !m_macPortHelper.IsCleared() ) + { + GrafPtr port ; + GetPort( &port ) ; + SetPort( m_macPortHelper.GetCurrentPort() ) ; + SetOrigin( 0 , 0 ) ; + SetPort( port ) ; + } + /* if ( m_macPort ) { + ::SetPort( m_macPort ) ; ::SetOrigin( 0 , 0 ) ; ::ClipRect( &m_macPort->portRect ) ; ::PenNormal() ; ::SetPort( m_macOrigPort ) ; } + */ ++m_macCurrentPortId ; }; void wxDC::MacSetupPort() const { + AGAPortHelper* help = &m_macPortHelper ; + help->Setup( m_macPort ) ; m_macPortId = ++m_macCurrentPortId ; - ::SetPort(m_macPort); ::SetOrigin(-m_macLocalOrigin.h, -m_macLocalOrigin.v); ::ClipRect(&m_macClipRect); @@ -124,8 +139,10 @@ void wxDC::MacSetupPort() const m_macPenInstalled = false ; } -void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) +void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ) { + float scale = 1.0 ; + if (!Ok()) return; MacVerifySetup() ; @@ -140,7 +157,7 @@ void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) { if ( bmap->m_bitmapType == kMacBitmapTypePict ) { - Rect bitmaprect = { 0 , 0 , bmap->m_height , bmap->m_width } ; + Rect bitmaprect = { 0 , 0 , bmap->m_height * scale , bmap->m_width * scale} ; ::OffsetRect( &bitmaprect , xx1 , yy1 ) ; ::DrawPicture( bmap->m_hPict , &bitmaprect ) ; } @@ -165,20 +182,21 @@ void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) source.bottom = bmap->m_height ; dest.top = YLOG2DEV(y) ; dest.left = XLOG2DEV(x) ; - dest.bottom = YLOG2DEV(y + bmap->m_height ) ; - dest.right = XLOG2DEV(x + bmap->m_width ) ; + dest.bottom = YLOG2DEV(y + bmap->m_height * scale) ; + dest.right = XLOG2DEV(x + bmap->m_width * scale ) ; if ( useMask && bmp.GetMask() ) { if ( LockPixels( GetGWorldPixMap( bmp.GetMask()->GetMaskBitmap( ) ) ) ) { - CopyMask( &GrafPtr( bmapworld )->portBits , &GrafPtr( bmp.GetMask()->GetMaskBitmap( ) )->portBits , &GrafPtr( m_macPort )->portBits , + CopyMask( GetPortBitMapForCopyBits( bmapworld ) , GetPortBitMapForCopyBits( bmp.GetMask()->GetMaskBitmap( ) ) , + GetPortBitMapForCopyBits( m_macPort ) , &source, &source , &dest ) ; UnlockPixels( GetGWorldPixMap( bmp.GetMask()->GetMaskBitmap( ) ) ) ; } } else - CopyBits( &GrafPtr( bmapworld )->portBits , &GrafPtr( m_macPort )->portBits , + CopyBits( GetPortBitMapForCopyBits( bmapworld ) , GetPortBitMapForCopyBits( m_macPort ), &source, &dest, srcCopy, NULL ) ; UnlockPixels( bmappixels ) ; @@ -192,7 +210,7 @@ void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) } } -void wxDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask ) +void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) { if (!Ok()) return; @@ -213,69 +231,9 @@ void wxDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask ) } }; -void wxDC::DrawPoint( wxPoint& point ) -{ - DrawPoint( point.x, point.y ); -}; - -void wxDC::DrawPolygon( wxList *list, long xoffset, long yoffset, int fillStyle ) -{ - int n = list->Number(); - wxPoint *points = new wxPoint[n]; - - int i = 0; - for( wxNode *node = list->First(); node; node = node->Next() ) - { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - }; - DrawPolygon( n, points, xoffset, yoffset, fillStyle ); - delete[] points; -}; - -void wxDC::DrawLines( wxList *list, long xoffset, long yoffset ) -{ - int n = list->Number(); - wxPoint *points = new wxPoint[n]; - - int i = 0; - for( wxNode *node = list->First(); node; node = node->Next() ) - { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - }; - DrawLines( n, points, xoffset, yoffset ); - delete []points; -}; - -void wxDC::DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 ) +void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) { - wxList list; - list.Append( (wxObject*)new wxPoint(x1, y1) ); - list.Append( (wxObject*)new wxPoint(x2, y2) ); - list.Append( (wxObject*)new wxPoint(x3, y3) ); - DrawSpline(&list); - wxNode *node = list.First(); - while (node) - { - wxPoint *p = (wxPoint*)node->Data(); - delete p; - node = node->Next(); - }; -}; - -void wxDC::DrawSpline( int n, wxPoint points[] ) -{ - wxList list; - for (int i = 0; i < n; i++) list.Append( (wxObject*)&points[i] ); - DrawSpline( &list ); -}; - -void wxDC::SetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) -{ - MacVerifySetup() ; + MacVerifySetup() ; if( m_clipping ) { m_clipX1 = wxMax( m_clipX1 , x ) ; @@ -300,13 +258,24 @@ void wxDC::SetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord heigh Rect clip = { y1 , x1 , y2 , x2 } ; - ::ClipRect( &clip ) ; + ::ClipRect( &clip ) ; }; -void wxDC::SetClippingRegion(const wxRect& rect) -{ - SetClippingRegion(rect.x, rect.y, rect.width, rect.height); +void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) +{ + wxCHECK_RET( Ok(), wxT("invalid window dc") ); + + MacVerifySetup() ; + if (region.Empty()) + { + DestroyClippingRegion(); + return; + } + + wxCoord xx, yy, ww, hh; + region.GetBox( xx, yy, ww, hh ); + wxDC::DoSetClippingRegion( xx, yy, ww, hh ); } void wxDC::DestroyClippingRegion(void) @@ -316,48 +285,14 @@ void wxDC::DestroyClippingRegion(void) // Rect clip = { -32000 , -32000 , 32000 , 32000 } ; ::ClipRect(&m_macClipRect); }; - -void wxDC::GetClippingBox( wxCoord *x, wxCoord *y, wxCoord *width, wxCoord *height ) const -{ - if (m_clipping) - { - if (x) *x = m_clipX1; - if (y) *y = m_clipY1; - if (width) *width = (m_clipX2 - m_clipX1); - if (height) *height = (m_clipY2 - m_clipY1); - } - else - *x = *y = *width = *height = 0; -}; - -void wxDC::GetClippingBox( long *x, long *y, long *width, long *height ) const -{ - if (m_clipping) - { - if (x) *x = m_clipX1; - if (y) *y = m_clipY1; - if (width) *width = (m_clipX2 - m_clipX1); - if (height) *height = (m_clipY2 - m_clipY1); - } - else - *x = *y = *width = *height = 0; -}; - -void wxDC::GetClippingBox(wxRect& rect) const -{ - // Necessary to use intermediate variables for 16-bit compilation - wxCoord x, y, w, h; - GetClippingBox(&x, &y, &w, &h); - rect.x = x; rect.y = y; rect.width = w; rect.height = h; -} -void wxDC::GetSize( int* width, int* height ) const +void wxDC::DoGetSize( int* width, int* height ) const { *width = m_maxX-m_minX; *height = m_maxY-m_minY; }; -void wxDC::GetSizeMM( long* width, long* height ) const +void wxDC::DoGetSizeMM( int* width, int* height ) const { int w = 0; int h = 0; @@ -416,12 +351,6 @@ void wxDC::SetUserScale( double x, double y ) ComputeScaleAndOrigin(); }; -void wxDC::GetUserScale( double *x, double *y ) -{ - if (x) *x = m_userScaleX; - if (y) *y = m_userScaleY; -}; - void wxDC::SetLogicalScale( double x, double y ) { // allow negative ? @@ -430,40 +359,20 @@ void wxDC::SetLogicalScale( double x, double y ) ComputeScaleAndOrigin(); }; -void wxDC::GetLogicalScale( double *x, double *y ) -{ - if (x) *x = m_logicalScaleX; - if (y) *y = m_logicalScaleY; -}; - -void wxDC::SetLogicalOrigin( long x, long y ) +void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) { m_logicalOriginX = x * m_signX; // is this still correct ? m_logicalOriginY = y * m_signY; ComputeScaleAndOrigin(); }; -void wxDC::GetLogicalOrigin( long *x, long *y ) -{ - if (x) *x = m_logicalOriginX; - if (y) *y = m_logicalOriginY; -}; - -void wxDC::SetDeviceOrigin( long x, long y ) +void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) { m_externalDeviceOriginX = x; m_externalDeviceOriginY = y; ComputeScaleAndOrigin(); }; - -void wxDC::GetDeviceOrigin( long *x, long *y ) -{ -// if (x) *x = m_externalDeviceOriginX; -// if (y) *y = m_externalDeviceOriginY; - if (x) *x = m_deviceOriginX; - if (y) *y = m_deviceOriginY; -}; - +/* void wxDC::SetInternalDeviceOrigin( long x, long y ) { m_internalDeviceOriginX = x; @@ -476,53 +385,14 @@ void wxDC::GetInternalDeviceOrigin( long *x, long *y ) if (x) *x = m_internalDeviceOriginX; if (y) *y = m_internalDeviceOriginY; }; - +*/ void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) { m_signX = (xLeftRight ? 1 : -1); m_signY = (yBottomUp ? -1 : 1); ComputeScaleAndOrigin(); }; - -long wxDC::DeviceToLogicalX(long x) const -{ - return XDEV2LOG(x); -}; - -long wxDC::DeviceToLogicalY(long y) const -{ - return YDEV2LOG(y); -}; - -long wxDC::DeviceToLogicalXRel(long x) const -{ - return XDEV2LOGREL(x); -}; - -long wxDC::DeviceToLogicalYRel(long y) const -{ - return YDEV2LOGREL(y); -}; - -long wxDC::LogicalToDeviceX(long x) const -{ - return XLOG2DEV(x); -}; - -long wxDC::LogicalToDeviceY(long y) const -{ - return YLOG2DEV(y); -}; - -long wxDC::LogicalToDeviceXRel(long x) const -{ - return XLOG2DEVREL(x); -}; - -long wxDC::LogicalToDeviceYRel(long y) const -{ - return YLOG2DEVREL(y); -}; +/* void wxDC::CalcBoundingBox( long x, long y ) { @@ -531,6 +401,16 @@ void wxDC::CalcBoundingBox( long x, long y ) if (x > m_maxX) m_maxX = x; if (y > m_maxY) m_maxY = y; }; +*/ +wxSize wxDC::GetPPI() const +{ + return wxSize(72, 72); +} + +int wxDC::GetDepth() const +{ + return wxDisplayDepth() ; +} void wxDC::ComputeScaleAndOrigin(void) { @@ -547,12 +427,7 @@ void wxDC::ComputeScaleAndOrigin(void) // CMB: if scale has changed call SetPen to recalulate the line width if (m_scaleX != origScaleX || m_scaleY != origScaleY) { - // this is a bit artificial, but we need to force wxDC to think - // the pen has changed - wxPen* pen = & GetPen(); - wxPen tempPen; - m_pen = tempPen; - SetPen(* pen); + // TODO : set internal flags for recalc } }; @@ -634,16 +509,17 @@ void wxDC::SetLogicalFunction( int function ) m_macPenInstalled = false ; } -void wxDC::FloodFill( long x1, long y1, const wxColour& col, int style ) +void wxDC::DoFloodFill( wxCoord x, wxCoord y, const wxColour& col, + int style ) { } -bool wxDC::GetPixel( long x1, long y1, wxColour *col ) const +bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const { return true ; } -void wxDC::DrawLine( long x1, long y1, long x2, long y2 ) +void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) { if (!Ok()) return; @@ -664,19 +540,22 @@ void wxDC::DrawLine( long x1, long y1, long x2, long y2 ) }; } -void wxDC::CrossHair( long x, long y ) +void wxDC::DoCrossHair( wxCoord x, wxCoord y ) { } -void wxDC::DrawArc( long x1, long y1, long x2, long y2, long xc, long yc ) +void wxDC::DoDrawArc( wxCoord x1, wxCoord y1, + wxCoord x2, wxCoord y2, + wxCoord xc, wxCoord yc ) { } -void wxDC::DrawEllipticArc( long x, long y, long width, long height, double sa, double ea ) +void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, + double sa, double ea ) { } -void wxDC::DrawPoint( long x, long y ) +void wxDC::DoDrawPoint( wxCoord x, wxCoord y ) { if (!Ok()) return; @@ -694,7 +573,8 @@ void wxDC::DrawPoint( long x, long y ) }; } -void wxDC::DrawLines( int n, wxPoint points[], long xoffset , long yoffset ) +void wxDC::DoDrawLines(int n, wxPoint points[], + wxCoord xoffset, wxCoord yoffset) { if (!Ok()) return; @@ -719,8 +599,9 @@ void wxDC::DrawLines( int n, wxPoint points[], long xoffset , long yoffset ) } } -void wxDC::DrawPolygon( int n, wxPoint points[], long xoffset , long yoffset , - int fillStyle ) +void wxDC::DoDrawPolygon(int n, wxPoint points[], + wxCoord xoffset, wxCoord yoffset, + int fillStyle ) { if (!Ok()) return; @@ -754,7 +635,7 @@ void wxDC::DrawPolygon( int n, wxPoint points[], long xoffset , long yoffset , KillPoly( polygon ) ; } -void wxDC::DrawRectangle( long x, long y, long width, long height ) +void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { if (!Ok()) return; @@ -797,7 +678,9 @@ void wxDC::DrawRectangle( long x, long y, long width, long height ) }; } -void wxDC::DrawRoundedRectangle( long x, long y, long width, long height, double radius ) +void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, + wxCoord width, wxCoord height, + double radius) { if (!Ok()) return; @@ -843,7 +726,7 @@ void wxDC::DrawRoundedRectangle( long x, long y, long width, long height, doubl }; } -void wxDC::DrawEllipse( long x, long y, long width, long height ) +void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { if (!Ok()) return; @@ -1001,7 +884,7 @@ static void wx_spline_draw_point_array(wxDC *dc) } } -void wxDC::DrawSpline( wxList *points ) +void wxDC::DoDrawSpline(wxList *points) { wxPoint *p; double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; @@ -1059,8 +942,8 @@ bool wxDC::CanDrawBitmap(void) const } -bool wxDC::Blit( long xdest, long ydest, long width, long height, - wxDC *source, long xsrc, long ysrc, int logical_func , bool useMask ) +bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, + wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask ) { if (!Ok()) return FALSE; MacVerifySetup() ; @@ -1069,8 +952,8 @@ bool wxDC::Blit( long xdest, long ydest, long width, long height, PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ; RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ; RGBColor black = { 0,0,0} ; - RGBForeColor( &m_textForegroundColour.GetPixel() ) ; - RGBBackColor( &m_textBackgroundColour.GetPixel() ) ; + RGBForeColor( &m_textForegroundColour.GetPixel() ) ; + RGBBackColor( &m_textBackgroundColour.GetPixel() ) ; if ( LockPixels(bmappixels) ) { @@ -1094,7 +977,7 @@ bool wxDC::Blit( long xdest, long ydest, long width, long height, logical_func == wxXOR ? srcXor : // logical_func == wxOR_REVERSE ? MERGEPAINT : // logical_func == wxAND_REVERSE ? SRCERASE : - logical_func == wxSRC_OR ? srcOr : + // logical_func == wxSRC_OR ? srcOr : // logical_func == wxSRC_AND ? SRCAND : srcCopy ); @@ -1103,14 +986,15 @@ bool wxDC::Blit( long xdest, long ydest, long width, long height, wxASSERT( mode == srcCopy ) ; if ( LockPixels( GetGWorldPixMap( source->m_macMask ) ) ) { - CopyMask( &GrafPtr( sourcePort )->portBits , &GrafPtr( source->m_macMask )->portBits , &GrafPtr( m_macPort )->portBits , + CopyMask( GetPortBitMapForCopyBits( sourcePort ) , GetPortBitMapForCopyBits( source->m_macMask ) , + GetPortBitMapForCopyBits( m_macPort ) , &srcrect, &srcrect , &dstrect ) ; UnlockPixels( GetGWorldPixMap( source->m_macMask ) ) ; } } else { - CopyBits( &GrafPtr( sourcePort )->portBits , &GrafPtr( m_macPort )->portBits , + CopyBits( GetPortBitMapForCopyBits( sourcePort ) , GetPortBitMapForCopyBits( m_macPort ) , &srcrect, &dstrect, mode, NULL ) ; } UnlockPixels( bmappixels ) ; @@ -1123,7 +1007,11 @@ bool wxDC::Blit( long xdest, long ydest, long width, long height, return TRUE; } -void wxDC::DrawText( const wxString &string, long x, long y, bool use16) +void wxDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, + double angle) +{ +} +void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) { if (!Ok()) return; @@ -1161,14 +1049,14 @@ void wxDC::DrawText( const wxString &string, long x, long y, bool use16) if ( wxApp::s_macDefaultEncodingIsPC ) { - macText = wxMacMakeMacStringFromPC( string ) ; + macText = wxMacMakeMacStringFromPC( strtext ) ; text = macText ; length = macText.Length() ; } else { - text = string ; - length = string.Length() ; + text = strtext ; + length = strtext.Length() ; } int laststop = 0 ; @@ -1200,9 +1088,9 @@ bool wxDC::CanGetTextExtent(void) const return true ; } -void wxDC::GetTextExtent( const wxString &string, long *width, long *height, - long *descent, long *externalLeading , - wxFont *theFont , bool use16 ) const +void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *height, + wxCoord *descent, wxCoord *externalLeading , + wxFont *theFont ) const { if (!Ok()) return; @@ -1217,11 +1105,8 @@ void wxDC::GetTextExtent( const wxString &string, long *width, long *height, if ( font ) { - long yy1 = YLOG2DEV(0); - long yy2 = YLOG2DEV(font->m_macFontSize); - ::TextFont( font->m_macFontNum ) ; - ::TextSize( abs( yy2-yy1) ) ; + ::TextSize( YLOG2DEVREL( font->m_macFontSize) ) ; ::TextFace( font->m_macFontStyle ) ; } } @@ -1233,9 +1118,12 @@ void wxDC::GetTextExtent( const wxString &string, long *width, long *height, FontInfo fi ; ::GetFontInfo( &fi ) ; - *height = fi.descent + fi.ascent ; - *descent = fi.descent ; - *externalLeading = fi.leading ; + if ( height ) + *height = YDEV2LOGREL( fi.descent + fi.ascent ) ; + if ( descent ) + *descent =YDEV2LOGREL( fi.descent ); + if ( externalLeading ) + *externalLeading = YDEV2LOGREL( fi.leading ) ; const char *text = NULL ; int length = 0 ; @@ -1255,24 +1143,28 @@ void wxDC::GetTextExtent( const wxString &string, long *width, long *height, int laststop = 0 ; int i = 0 ; int curwidth = 0 ; - *width = 0 ; - - while( i < length ) + if ( width ) { - if( text[i] == 13 || text[i] == 10) + *width = 0 ; + + while( i < length ) { - *height += fi.descent + fi.ascent + fi.leading; - curwidth = ::TextWidth( text , laststop , i - laststop ) ; - if ( curwidth > *width ) - *width = curwidth ; - laststop = i+1 ; + if( text[i] == 13 || text[i] == 10) + { + if ( height ) + *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ; + curwidth = ::TextWidth( text , laststop , i - laststop ) ; + if ( curwidth > *width ) + *width = XDEV2LOGREL( curwidth ) ; + laststop = i+1 ; + } + i++ ; } - i++ ; + + curwidth = ::TextWidth( text , laststop , i - laststop ) ; + if ( curwidth > *width ) + *width = XDEV2LOGREL( curwidth ) ; } - - curwidth = ::TextWidth( text , laststop , i - laststop ) ; - if ( curwidth > *width ) - *width = curwidth ; if ( theFont ) { @@ -1292,7 +1184,7 @@ wxCoord wxDC::GetCharWidth(void) const FontInfo fi ; ::GetFontInfo( &fi ) ; - return (fi.descent + fi.ascent) / 2 ; + return YDEV2LOGREL((fi.descent + fi.ascent) / 2) ; } wxCoord wxDC::GetCharHeight(void) const @@ -1307,7 +1199,7 @@ wxCoord wxDC::GetCharHeight(void) const FontInfo fi ; ::GetFontInfo( &fi ) ; - return fi.descent + fi.ascent ; + return YDEV2LOGREL( fi.descent + fi.ascent ); } void wxDC::Clear(void) @@ -1332,7 +1224,8 @@ void wxDC::MacInstallFont() const if ( m_macFontInstalled ) return ; - + Pattern blackColor ; + wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; if ( font ) @@ -1377,7 +1270,7 @@ void wxDC::MacInstallFont() const mode = patCopy ; break ; case wxINVERT: // NOT dst - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); mode = patXor ; break ; case wxXOR: // src XOR dst @@ -1403,8 +1296,8 @@ void wxDC::MacInstallFont() const case wxNAND: // (NOT src) OR (NOT dst) case wxOR: // src OR dst case wxSET: // 1 - case wxSRC_OR: // source _bitmap_ OR destination - case wxSRC_AND: // source _bitmap_ AND destination +// case wxSRC_OR: // source _bitmap_ OR destination +// case wxSRC_AND: // source _bitmap_ AND destination break ; } ::PenMode( mode ) ; @@ -1447,6 +1340,8 @@ void wxDC::MacInstallPen() const return; MacVerifySetup() ; + Pattern blackColor; + if ( m_macPenInstalled ) return ; @@ -1460,7 +1355,7 @@ void wxDC::MacInstallPen() const int penStyle = m_pen.GetStyle(); if (penStyle == wxSOLID) - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); else if (IS_HATCH(penStyle)) { Pattern pat ; @@ -1469,7 +1364,7 @@ void wxDC::MacInstallPen() const } else { - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); } short mode = patCopy ; @@ -1482,7 +1377,7 @@ void wxDC::MacInstallPen() const mode = patCopy ; break ; case wxINVERT: // NOT dst - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); mode = patXor ; break ; case wxXOR: // src XOR dst @@ -1508,8 +1403,8 @@ void wxDC::MacInstallPen() const case wxNAND: // (NOT src) OR (NOT dst) case wxOR: // src OR dst case wxSET: // 1 - case wxSRC_OR: // source _bitmap_ OR destination - case wxSRC_AND: // source _bitmap_ AND destination +// case wxSRC_OR: // source _bitmap_ OR destination +// case wxSRC_AND: // source _bitmap_ AND destination break ; } ::PenMode( mode ) ; @@ -1523,7 +1418,7 @@ void wxDC::MacInstallBrush() const if (!Ok()) return; MacVerifySetup() ; - + Pattern blackColor, whiteColor ; if ( m_macBrushInstalled ) return ; @@ -1534,7 +1429,7 @@ void wxDC::MacInstallBrush() const int brushStyle = m_brush.GetStyle(); if (brushStyle == wxSOLID) - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); else if (IS_HATCH(brushStyle)) { Pattern pat ; @@ -1543,7 +1438,7 @@ void wxDC::MacInstallBrush() const } else { - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); } @@ -1551,7 +1446,7 @@ void wxDC::MacInstallBrush() const brushStyle = m_backgroundBrush.GetStyle(); if (brushStyle == wxSOLID) - ::BackPat(&qd.white); + ::BackPat(GetQDGlobalsWhite(&whiteColor)); else if (IS_HATCH(brushStyle)) { Pattern pat ; @@ -1560,7 +1455,7 @@ void wxDC::MacInstallBrush() const } else { - ::BackPat(&qd.white); + ::BackPat(GetQDGlobalsWhite(&whiteColor)); } short mode = patCopy ; @@ -1573,7 +1468,7 @@ void wxDC::MacInstallBrush() const mode = patCopy ; break ; case wxINVERT: // NOT dst - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); mode = patXor ; break ; case wxXOR: // src XOR dst @@ -1599,8 +1494,8 @@ void wxDC::MacInstallBrush() const case wxNAND: // (NOT src) OR (NOT dst) case wxOR: // src OR dst case wxSET: // 1 - case wxSRC_OR: // source _bitmap_ OR destination - case wxSRC_AND: // source _bitmap_ AND destination +// case wxSRC_OR: // source _bitmap_ OR destination +// case wxSRC_AND: // source _bitmap_ AND destination break ; } ::PenMode( mode ) ; @@ -1609,4 +1504,47 @@ void wxDC::MacInstallBrush() const m_macFontInstalled = false ; } +// --------------------------------------------------------------------------- +// coordinates transformations +// --------------------------------------------------------------------------- + +wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const +{ + return ((wxDC *)this)->XDEV2LOG(x); +} + +wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const +{ + return ((wxDC *)this)->YDEV2LOG(y); +} + +wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const +{ + return ((wxDC *)this)->XDEV2LOGREL(x); +} + +wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const +{ + return ((wxDC *)this)->YDEV2LOGREL(y); +} + +wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const +{ + return ((wxDC *)this)->XLOG2DEV(x); +} + +wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const +{ + return ((wxDC *)this)->YLOG2DEV(y); +} + +wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const +{ + return ((wxDC *)this)->XLOG2DEVREL(x); +} + +wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const +{ + return ((wxDC *)this)->YLOG2DEVREL(y); +} diff --git a/src/mac/carbon/dcclient.cpp b/src/mac/carbon/dcclient.cpp index 12100b81cd..6f3a6b3517 100644 --- a/src/mac/carbon/dcclient.cpp +++ b/src/mac/carbon/dcclient.cpp @@ -28,9 +28,11 @@ // wxPaintDC //----------------------------------------------------------------------------- +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) +#endif /* * wxWindowDC @@ -38,11 +40,11 @@ IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) #include -wxWindowDC::wxWindowDC(void) +wxWindowDC::wxWindowDC() { } -wxWindowDC::wxWindowDC(wxWindow *the_canvas) +wxWindowDC::wxWindowDC(wxWindow *the_canvas) { WindowRef windowref ; wxWindow* rootwindow ; @@ -51,11 +53,16 @@ wxWindowDC::wxWindowDC(wxWindow *the_canvas) the_canvas->MacGetPortParams(&m_macLocalOrigin, &m_macClipRect , &windowref , &rootwindow ); m_macPort = UMAGetWindowPort( windowref ) ; + m_minY = m_minX = 0; + wxSize size = the_canvas->GetSize() ; + m_maxX = size.x ; + m_maxY = size.y ; + MacSetupPort() ; m_ok = TRUE ; } -wxWindowDC::~wxWindowDC(void) +wxWindowDC::~wxWindowDC() { } @@ -63,7 +70,7 @@ wxWindowDC::~wxWindowDC(void) * wxClientDC */ -wxClientDC::wxClientDC(void) +wxClientDC::wxClientDC() { } @@ -75,12 +82,16 @@ wxClientDC::wxClientDC(wxWindow *window) window->MacGetPortClientParams(&m_macLocalOrigin, &m_macClipRect , &windowref , &rootwindow ); m_macPort = UMAGetWindowPort( windowref ) ; MacSetupPort() ; + m_minY = m_minX = 0; + wxSize size = window->GetSize() ; + m_maxX = size.x ; + m_maxY = size.y ; m_ok = TRUE ; SetBackground(wxBrush(window->GetBackgroundColour(), wxSOLID)); SetFont( window->GetFont() ) ; } -wxClientDC::~wxClientDC(void) +wxClientDC::~wxClientDC() { } @@ -88,7 +99,7 @@ wxClientDC::~wxClientDC(void) * wxPaintDC */ -wxPaintDC::wxPaintDC(void) +wxPaintDC::wxPaintDC() { } @@ -104,6 +115,10 @@ wxPaintDC::wxPaintDC(wxWindow *window) m_ok = TRUE ; long x , y ,w , h ; window->GetUpdateRegion().GetBox( x , y , w , h ) ; + m_minY = m_minX = 0; + wxSize size = window->GetSize() ; + m_maxX = size.x ; + m_maxY = size.y ; SetClippingRegion( x , y , w , h ) ; SetBackground(wxBrush(window->GetBackgroundColour(), wxSOLID)); SetFont(window->GetFont() ) ; diff --git a/src/mac/carbon/dcmemory.cpp b/src/mac/carbon/dcmemory.cpp index fe88bf806c..a56c7b5c49 100644 --- a/src/mac/carbon/dcmemory.cpp +++ b/src/mac/carbon/dcmemory.cpp @@ -33,10 +33,20 @@ wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) ) wxMemoryDC::~wxMemoryDC(void) { + if ( m_selected.Ok() ) + { + wxBitmapRefData * bmap = (wxBitmapRefData*) (m_selected.GetRefData()) ; + UnlockPixels( GetGWorldPixMap( (CGrafPtr) bmap->m_hBitmap ) ) ; + } }; void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) { + if ( m_selected.Ok() ) + { + wxBitmapRefData * bmap = (wxBitmapRefData*) (m_selected.GetRefData()) ; + UnlockPixels( GetGWorldPixMap( (CGrafPtr) bmap->m_hBitmap ) ) ; + } m_selected = bitmap; if (m_selected.Ok()) { @@ -44,6 +54,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) if ( bmap->m_hBitmap ) { m_macPort = (GrafPtr) bmap->m_hBitmap ; + LockPixels( GetGWorldPixMap( (CGrafPtr) m_macPort ) ) ; wxMask * mask = bitmap.GetMask() ; if ( mask ) { diff --git a/src/mac/carbon/dcprint.cpp b/src/mac/carbon/dcprint.cpp index 449f44e206..257c74206b 100644 --- a/src/mac/carbon/dcprint.cpp +++ b/src/mac/carbon/dcprint.cpp @@ -25,31 +25,36 @@ #include "wx/dcprint.h" #include "math.h" +#include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_CLASS(wxPrinterDC, wxDC) +#endif GrafPtr macPrintFormerPort = NULL ; wxPrinterDC::wxPrinterDC(const wxPrintData& printdata) { +#if !TARGET_CARBON OSErr err ; wxString message ; m_printData = printdata ; m_printData.ConvertToNative() ; - ::PrOpen() ; + ::UMAPrOpen() ; err = PrError() ; if ( err ) { message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; - PrClose() ; + UMAPrClose() ; } if ( ::PrValidate( m_printData.m_macPrintInfo ) ) { + ::PrStlDialog( m_printData.m_macPrintInfo ) ; // the driver has changed in the mean time, should we pop up a page setup dialog ? } err = PrError() ; @@ -57,20 +62,31 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata) { message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; - PrClose() ; + UMAPrClose() ; } ::GetPort( &macPrintFormerPort ) ; m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ; + err = PrError() ; + if ( err ) + { + message.Printf( "Print Error %d", err ) ; + wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; + UMAPrClose() ; + } // sets current port m_macPort = (GrafPtr ) m_macPrintPort ; m_ok = TRUE ; m_minY = m_minX = 0 ; m_maxX = (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ; m_maxY = (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ; +#else +#pragma warning "TODO:printing support for carbon" +#endif } wxPrinterDC::~wxPrinterDC(void) { +#if !TARGET_CARBON if ( m_ok ) { OSErr err ; @@ -91,11 +107,16 @@ wxPrinterDC::~wxPrinterDC(void) { message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; - PrClose() ; + UMAPrClose() ; } - ::PrClose() ; - ::SetPort( macPrintFormerPort ) ; + ::UMAPrClose() ; +// ::SetPort( macPrintFormerPort ) ; + ::SetPort( LMGetWMgrPort() ) ; + m_macPortHelper.Clear() ; } +#else +#pragma warning "TODO:printing support for carbon" +#endif } bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) ) @@ -109,13 +130,30 @@ void wxPrinterDC::EndDoc(void) void wxPrinterDC::StartPage(void) { +#if !TARGET_CARBON if ( !m_ok ) return ; + + m_logicalFunction = wxCOPY; +// m_textAlignment = wxALIGN_TOP_LEFT; + m_backgroundMode = wxTRANSPARENT; + + m_textForegroundColour = *wxBLACK; + m_textBackgroundColour = *wxWHITE; + m_pen = *wxBLACK_PEN; + m_font = *wxNORMAL_FONT; + m_brush = *wxTRANSPARENT_BRUSH; + m_backgroundBrush = *wxWHITE_BRUSH; + + m_macFontInstalled = false ; + m_macBrushInstalled = false ; + m_macPenInstalled = false ; + OSErr err ; wxString message ; - PrOpenPage( m_macPrintPort , NULL ) ; + PrOpenPage( m_macPrintPort , NULL ) ; SetOrigin( - (**m_printData.m_macPrintInfo).rPaper.left , - (**m_printData.m_macPrintInfo).rPaper.top ) ; Rect clip = { -32000 , -32000 , 32000 , 32000 } ; ::ClipRect( &clip ) ; @@ -126,14 +164,18 @@ void wxPrinterDC::StartPage(void) wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; ::PrClosePage( m_macPrintPort) ; ::PrCloseDoc( m_macPrintPort ) ; - ::PrClose() ; + ::UMAPrClose() ; ::SetPort( macPrintFormerPort ) ; m_ok = FALSE ; } +#else +#pragma warning "TODO:printing support for carbon" +#endif } void wxPrinterDC::EndPage(void) { +#if !TARGET_CARBON if ( !m_ok ) return ; @@ -147,8 +189,12 @@ void wxPrinterDC::EndPage(void) message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; ::PrCloseDoc( m_macPrintPort ) ; - ::PrClose() ; + ::UMAPrClose() ; ::SetPort( macPrintFormerPort ) ; m_ok = FALSE ; } +#else +#pragma warning "TODO:printing support for carbon" +#endif + } diff --git a/src/mac/carbon/dcscreen.cpp b/src/mac/carbon/dcscreen.cpp index 1d802afba4..c47126248e 100644 --- a/src/mac/carbon/dcscreen.cpp +++ b/src/mac/carbon/dcscreen.cpp @@ -14,15 +14,34 @@ #endif #include "wx/dcscreen.h" +#include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC) +#endif // Create a DC representing the whole screen wxScreenDC::wxScreenDC() { +#if TARGET_CARBON + m_macPort = GetQDGlobalsThePort() ; +#else m_macPort = LMGetWMgrPort() ; +#endif MacSetupPort() ; m_ok = TRUE ; + BitMap screenBits; + GetQDGlobalsScreenBits( &screenBits ); + m_minX = screenBits.bounds.left ; + #if TARGET_CARBON + SInt16 height ; + GetThemeMenuBarHeight( &height ) ; + m_minY = screenBits.bounds.top + height ; + #else + m_minY = screenBits.bounds.top + LMGetMBarHeight() ; + #endif + m_maxX = screenBits.bounds.right ; + m_maxY = screenBits.bounds.bottom ; } wxScreenDC::~wxScreenDC() diff --git a/src/mac/carbon/dialog.cpp b/src/mac/carbon/dialog.cpp index d75706f6a3..760c07680a 100644 --- a/src/mac/carbon/dialog.cpp +++ b/src/mac/carbon/dialog.cpp @@ -27,6 +27,7 @@ wxList wxModalDialogs; wxList wxModelessWindows; // Frames and modeless dialogs extern wxList wxPendingDelete; +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel) BEGIN_EVENT_TABLE(wxDialog, wxPanel) @@ -39,11 +40,11 @@ BEGIN_EVENT_TABLE(wxDialog, wxPanel) EVT_CLOSE(wxDialog::OnCloseWindow) END_EVENT_TABLE() +#endif wxDialog::wxDialog() { - m_isShown = FALSE; - m_modalShowing = FALSE; + m_isShown = FALSE; SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); } @@ -54,15 +55,8 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name) { - m_windowStyle = style; - m_isShown = FALSE; - m_modalShowing = FALSE; -#if wxUSE_TOOLTIPS - m_hwndToolTip = 0; -#endif SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); - SetName(name); if (!parent) wxTopLevelWindows.Append(this); @@ -74,59 +68,26 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, else m_windowId = id; - 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 ; - - m_width = size.x; - if (m_width == -1) - m_width = 20; - m_height = size.y; - if (m_height == -1) - m_height = 20; - - ::SetRect(&theBoundsRect, m_x, m_y, m_x + m_width, m_y + m_height); - m_macWindowData = new MacWindowData() ; - - WindowClass wclass = kMovableModalWindowClass ; - WindowAttributes attr = kWindowNoAttributes ; - - if ( ( m_windowStyle & wxMINIMIZE_BOX ) || ( m_windowStyle & wxMAXIMIZE_BOX ) ) - { - attr |= kWindowFullZoomAttribute ; - attr |= kWindowResizableAttribute ; - } + MacCreateRealWindow( title , pos , size , MacRemoveBordersFromStyle(style) , name ) ; - UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ; - wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ; - wxString label ; - if( wxApp::s_macDefaultEncodingIsPC ) - label = wxMacMakeMacStringFromPC( title ) ; - else - label = title ; - UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDialogBackgroundActive ; - UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; - m_macWindowData->m_macFocus = NULL ; return TRUE; } void wxDialog::SetModal(bool flag) { - if ( flag ) - m_windowStyle |= wxDIALOG_MODAL ; - else - if ( m_windowStyle & wxDIALOG_MODAL ) - m_windowStyle -= wxDIALOG_MODAL ; - - wxModelessWindows.DeleteObject(this); - if (!flag) - wxModelessWindows.Append(this); + if ( flag ) + { + m_windowStyle |= wxDIALOG_MODAL; + + wxModelessWindows.DeleteObject(this); + } + else + { + m_windowStyle &= ~wxDIALOG_MODAL; + + wxModelessWindows.Append(this); + } } wxDialog::~wxDialog() @@ -134,10 +95,10 @@ wxDialog::~wxDialog() m_isBeingDeleted = TRUE ; wxTopLevelWindows.DeleteObject(this); - m_modalShowing = FALSE; + Show(FALSE); - if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL ) - wxModelessWindows.DeleteObject(this); + if ( !IsModal() ) + wxModelessWindows.DeleteObject(this); // If this is the last top-level window, exit. if (wxTheApp && (wxTopLevelWindows.Number() == 0)) @@ -184,19 +145,20 @@ void wxDialog::DoSetClientSize(int width, int height) wxWindow::DoSetClientSize( width , height ) ; } -void wxDialog::GetPosition(int *x, int *y) const +void wxDialog::DoGetPosition(int *x, int *y) const { - DoGetPosition( x , y ) ; + wxWindow::DoGetPosition( x , y ) ; } -bool wxDialog::IsShown() const +bool wxDialog::IsModal() const { - return m_isShown; + return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0; } -bool wxDialog::IsModal() const + +bool wxDialog::IsModalShowing() const { - return wxModalDialogs.Find((wxDialog *)this) != 0; // const_cast + return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast } @@ -204,122 +166,77 @@ extern bool s_macIsInModalLoop ; bool wxDialog::Show(bool show) { - m_isShown = show; - - if (show) - InitDialog(); + if ( !wxDialogBase::Show(show) ) + { + // nothing to do + return FALSE; + } - bool modal = ((GetWindowStyleFlag() & wxDIALOG_MODAL) == wxDIALOG_MODAL) ; + if ( show ) + { + // usually will result in TransferDataToWindow() being called + InitDialog(); + } -#if WXGARBAGE_COLLECTION_ON /* MATTHEW: GC */ - if (!modal) - { - if (show) + if ( IsModal() ) { - if (!wxModelessWindows.Find(this)) - wxModelessWindows.Append(this); - } - else - wxModelessWindows.DeleteObject(this); - } - if (show) - { - if (!wxTopLevelWindows.Find(this)) - wxTopLevelWindows.Append(this); - } - else - wxTopLevelWindows.DeleteObject(this); -#endif + if ( show ) + { + DoShowModal(); + } + else // end of modal dialog + { + // this will cause IsModalShowing() return FALSE and our local + // message loop will terminate + wxModalDialogs.DeleteObject(this); + } + } - if ( modal ) - { - s_macIsInModalLoop = true ; - if (show) - { - if (m_modalShowing) - { -// BringWindowToTop((HWND) GetHWND()); - return TRUE; - } - - m_modalShowing = TRUE; - // if we don't do it, some window might be deleted while we have pointers - // to them in our disabledWindows list and the program will crash when it - // will try to reenable them after the modal dialog end - wxTheApp->DeletePendingObjects(); - - UMAShowWindow( m_macWindowData->m_macWindow ) ; - UMASelectWindow( m_macWindowData->m_macWindow ) ; - - if (!wxModalDialogs.Member(this)) - wxModalDialogs.Append(this); - - while (wxModalDialogs.Member(this) ) - { - wxTheApp->MacDoOneEvent() ; - } - } - else - { - wxModalDialogs.DeleteObject(this); - UMAHideWindow( m_macWindowData->m_macWindow ) ; - } - s_macIsInModalLoop = false ; - } - else // !modal - { - if (show) - { - UMAShowWindow( m_macWindowData->m_macWindow ) ; - UMASelectWindow( m_macWindowData->m_macWindow ) ; - } - else - { - UMAHideWindow( m_macWindowData->m_macWindow ) ; - } - } - return TRUE ; + return TRUE; } -void wxDialog::SetTitle(const wxString& title) +void wxDialog::DoShowModal() { - wxWindow::SetTitle( title ) ; -} + wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") ); -wxString wxDialog::GetTitle() const -{ - return wxWindow::GetTitle() ; -} + wxModalDialogs.Append(this); -void wxDialog::Centre(int direction) -{ - int x_offset,y_offset ; - int display_width, display_height; - int width, height, x, y; - wxWindow *parent = GetParent(); - if ((direction & wxCENTER_FRAME) && parent) - { - parent->GetPosition(&x_offset,&y_offset) ; - parent->GetSize(&display_width,&display_height) ; - } - else - { - wxDisplaySize(&display_width, &display_height); - x_offset = 0 ; - y_offset = 0 ; - } + wxWindow *parent = GetParent(); + + // remember where the focus was + wxWindow *winFocus = FindFocus(); + if ( !winFocus ) + { + winFocus = parent; + } + if ( !winFocus ) + { + winFocus = wxTheApp->GetTopWindow(); + } + // TODO : test whether parent gets disabled + + s_macIsInModalLoop = true ; - GetSize(&width, &height); - GetPosition(&x, &y); + while ( IsModalShowing() ) + { + while ( !wxTheApp->Pending() && wxTheApp->ProcessIdle() ) + { + } + wxTheApp->MacDoOneEvent() ; + } + + s_macIsInModalLoop = false ; - if (direction & wxHORIZONTAL) - x = (int)((display_width - width)/2); - if (direction & wxVERTICAL) - y = (int)((display_height - height)/2); + // TODO probably reenable the parent window if any - SetSize(x+x_offset, y+y_offset, width, height); + // and restore focus + if ( winFocus ) + { + winFocus->SetFocus(); + } } + // Replacement for Show(TRUE) for modal dialogs - returns return code int wxDialog::ShowModal() { @@ -328,6 +245,8 @@ int wxDialog::ShowModal() return GetReturnCode(); } +// NB: this function (surprizingly) may be called for both modal and modeless +// dialogs and should work for both of them void wxDialog::EndModal(int retCode) { SetReturnCode(retCode); @@ -339,13 +258,7 @@ void wxDialog::OnOK(wxCommandEvent& event) { if ( Validate() && TransferDataFromWindow() ) { - if ( IsModal() ) - EndModal(wxID_OK); - else - { - SetReturnCode(wxID_OK); - this->Show(FALSE); - } + EndModal(wxID_OK); } } @@ -358,20 +271,7 @@ void wxDialog::OnApply(wxCommandEvent& event) void wxDialog::OnCancel(wxCommandEvent& event) { - if ( IsModal() ) EndModal(wxID_CANCEL); - else - { - SetReturnCode(wxID_CANCEL); - this->Show(FALSE); - } -} - -void wxDialog::OnPaint(wxPaintEvent& event) -{ - // No: if you call the default procedure, it makes - // the following painting code not work. -// wxWindow::OnPaint(event); } void wxDialog::OnCloseWindow(wxCloseEvent& event) @@ -407,30 +307,16 @@ void wxDialog::OnCloseWindow(wxCloseEvent& event) // Destroy the window (delayed, if a managed window) bool wxDialog::Destroy() { - if (!wxPendingDelete.Member(this)) + wxCHECK_MSG( !wxPendingDelete.Member(this), FALSE, + _T("wxDialog destroyed twice") ); + wxPendingDelete.Append(this); return TRUE; } -void wxDialog::OnSize(wxSizeEvent& WXUNUSED(event)) -{ - // if we're using constraints - do use them - #if wxUSE_CONSTRAINTS - if ( GetAutoLayout() ) - { - Layout(); - } - #endif -} - void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event) { SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); Refresh(); } -void wxDialog::Fit() -{ - wxWindow::Fit(); -} - diff --git a/src/mac/carbon/dir.cpp b/src/mac/carbon/dir.cpp index ec94a4e1ec..f0b6664010 100644 --- a/src/mac/carbon/dir.cpp +++ b/src/mac/carbon/dir.cpp @@ -147,6 +147,7 @@ bool wxDirData::Read(wxString *filename) if ( err != noErr ) break ; + p2cstr( m_name ) ; if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) ) // we have a directory break ; @@ -156,17 +157,37 @@ bool wxDirData::Read(wxString *filename) if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) ) // its hidden but we don't want it continue ; + wxString file( m_name ) ; + if ( m_filespec.IsEmpty() || m_filespec == "*.*" ) + { + } + else if ( m_filespec.Length() > 1 && m_filespec.Left(1) =="*" ) + { + if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() ) + { + continue ; + } + } + else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == "*" ) + { + if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() ) + { + continue ; + } + } + else if ( file.Upper() != m_filespec.Upper() ) + { + continue ; + } + break ; } if ( err != noErr ) { return FALSE ; } - FSSpec spec ; - - FSMakeFSSpecCompat(m_CPB.hFileInfo.ioVRefNum, m_dirId, m_name,&spec) ; - - *filename = wxMacFSSpec2UnixFilename( &spec ) ; + + *filename = (char*) m_name ; return TRUE; } diff --git a/src/mac/carbon/dirdlg.cpp b/src/mac/carbon/dirdlg.cpp index 344b8b32b9..02bbef6a20 100644 --- a/src/mac/carbon/dirdlg.cpp +++ b/src/mac/carbon/dirdlg.cpp @@ -20,19 +20,9 @@ #include "wx/cmndata.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_CLASS(wxDirDialog, wxDialog) - -enum { - kSelectItem = 10, // select button item number - kSFGetFolderDlgID = 250, // dialog resource number - kStrListID = 250, // our strings - kSelectStrNum = 1, // word 'Select: ' for button - kDesktopStrNum = 2, // word 'Desktop' for button - kSelectNoQuoteStrNum = 3, // word 'Select: ' for button - - kUseQuotes = true, // parameter for SetButtonName - kDontUseQuotes = false -}; +#endif // the data we need to pass to our standard file hook routine // includes a pointer to the dialog, a pointer to the standard @@ -48,6 +38,21 @@ struct UserDataRec { typedef struct UserDataRec UserDataRec, *UserDataRecPtr; +#if !TARGET_CARBON + +enum { + kSelectItem = 10, // select button item number + kSFGetFolderDlgID = 250, // dialog resource number + kStrListID = 250, // our strings + kSelectStrNum = 1, // word 'Select: ' for button + kDesktopStrNum = 2, // word 'Desktop' for button + kSelectNoQuoteStrNum = 3, // word 'Select: ' for button + + kUseQuotes = true, // parameter for SetButtonName + kDontUseQuotes = false +}; + + static void GetLabelString(StringPtr theStr, short stringNum) { GetIndString(theStr, kStrListID, stringNum); @@ -302,6 +307,7 @@ static pascal short SFGetFolderDialogHook(short item, DialogPtr theDlgPtr, Ptr d return item; } +#endif void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileFilterYDUPP fileFilter, StandardFileReply *theSFR) { @@ -321,7 +327,7 @@ void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileF // set initial contents of Select button to a space - CopyPStr("\p ", theSFR->sfFile.name); + memcpy(theSFR->sfFile.name, "\p ", 2); // point the user data parameter at the reply record so we can get to it later @@ -329,6 +335,8 @@ void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileF // display the dialog + #if !TARGET_CARBON + dlgHookUPP = NewDlgHookYDProc(SFGetFolderDialogHook); myModalFilterUPP = NewModalFilterYDProc(SFGetFolderModalDialogFilter); @@ -350,6 +358,8 @@ void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileF DisposeRoutineDescriptor(dlgHookUPP); DisposeRoutineDescriptor(myModalFilterUPP); + #else + #endif // if cancel wasn't pressed and no fatal error occurred... @@ -445,14 +455,18 @@ int wxDirDialog::ShowModal() strcpy((char *)path, m_path ) ; c2pstr((char *)path ) ; - FileFilterYDUPP invisiblesExcludedCustomFilterUPP; StandardFileReply reply ; + FileFilterYDUPP invisiblesExcludedCustomFilterUPP = 0 ; + #if !TARGET_CARBON invisiblesExcludedCustomFilterUPP = NewFileFilterYDProc(OnlyVisibleFoldersCustomFileFilter); + #endif StandardGetFolder( prompt , path , invisiblesExcludedCustomFilterUPP, &reply); + #if !TARGET_CARBON DisposeRoutineDescriptor(invisiblesExcludedCustomFilterUPP); + #endif if ( reply.sfGood == false ) { m_path = "" ; diff --git a/src/mac/carbon/dnd.cpp b/src/mac/carbon/dnd.cpp index 32088eef0f..cebcd3aab0 100644 --- a/src/mac/carbon/dnd.cpp +++ b/src/mac/carbon/dnd.cpp @@ -18,6 +18,8 @@ #include "wx/app.h" #include "wx/gdicmn.h" +#if wxUSE_DRAG_AND_DROP + // ---------------------------------------------------------------------------- // global // ---------------------------------------------------------------------------- @@ -131,3 +133,4 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) return wxDragError; }; +#endif \ No newline at end of file diff --git a/src/mac/carbon/filedlg.cpp b/src/mac/carbon/filedlg.cpp index ee50e2e6bd..7837183e2a 100644 --- a/src/mac/carbon/filedlg.cpp +++ b/src/mac/carbon/filedlg.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: filedlg.cpp -// Purpose: wxFileDialog +// Purpose: wxFileDialog // Author: AUTHOR // Modified by: // Created: ??/??/98 @@ -19,7 +19,9 @@ #include "wx/filedlg.h" #include "wx/intl.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_CLASS(wxFileDialog, wxDialog) +#endif // begin wxmac @@ -43,6 +45,27 @@ OSType gfiltersmac[] = '****' } ; +// the data we need to pass to our standard file hook routine +// includes a pointer to the dialog, a pointer to the standard +// file reply record (so we can inspect the current selection) +// and a copy of the "previous" file spec of the reply record +// so we can see if the selection has changed + +const int kwxMacFileTypes = 10 ; + +struct OpenUserDataRec { + StandardFileReply *sfrPtr; + FSSpec oldSelectionFSSpec; + char filter[kwxMacFileTypes][10] ; + OSType filtermactypes[kwxMacFileTypes] ; + int numfilters ; + DialogPtr theDlgPtr; +}; +typedef struct OpenUserDataRec + OpenUserDataRec, *OpenUserDataRecPtr; + +#if !TARGET_CARBON + static void wxMacSetupStandardFile(short newVRefNum, long newDirID) { enum @@ -97,25 +120,6 @@ enum { kDontUseQuotes = false }; -// the data we need to pass to our standard file hook routine -// includes a pointer to the dialog, a pointer to the standard -// file reply record (so we can inspect the current selection) -// and a copy of the "previous" file spec of the reply record -// so we can see if the selection has changed - -const int kwxMacFileTypes = 10 ; - -struct OpenUserDataRec { - StandardFileReply *sfrPtr; - FSSpec oldSelectionFSSpec; - char filter[kwxMacFileTypes][10] ; - OSType filtermactypes[kwxMacFileTypes] ; - int numfilters ; - DialogPtr theDlgPtr; -}; -typedef struct OpenUserDataRec - OpenUserDataRec, *OpenUserDataRecPtr; - static void GetLabelString(StringPtr theStr, short stringNum) { GetIndString(theStr, kStrListID, stringNum); @@ -185,6 +189,7 @@ static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRec return false; } +#endif void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const char *filter , FileFilterYDUPP fileFilter, StandardFileReply *theSFR) { @@ -204,7 +209,7 @@ void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const // set initial contents of Select button to a space - CopyPStr("\p ", theSFR->sfFile.name); + memcpy( theSFR->sfFile.name , "\p " , 2 ) ; // point the user data parameter at the reply record so we can get to it later @@ -240,6 +245,8 @@ void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const myData.numfilters = 0 ; } // display the dialog + +#if !TARGET_CARBON dlgHookUPP = NULL ; // dlgHookUPP = NewDlgHookYDProc(SFGetFolderDialogHook); @@ -263,7 +270,8 @@ void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const DisposeRoutineDescriptor(dlgHookUPP); DisposeRoutineDescriptor(myModalFilterUPP); - +#else +#endif // if cancel wasn't pressed and no fatal error occurred... if (theSFR->sfGood) @@ -454,8 +462,12 @@ int wxFileDialog::ShowModal() strcpy((char *)filename, m_fileName) ; c2pstr((char *)filename ) ; + #if !TARGET_CARBON StandardPutFile( prompt , filename , &reply ) ; + + #else + #endif if ( reply.sfGood == false ) { m_path = "" ; @@ -479,14 +491,17 @@ int wxFileDialog::ShowModal() strcpy((char *)path, m_path ) ; c2pstr((char *)path ) ; - FileFilterYDUPP crossPlatformFileFilterUPP; StandardFileReply reply ; + FileFilterYDUPP crossPlatformFileFilterUPP = 0 ; + #if !TARGET_CARBON crossPlatformFileFilterUPP = NewFileFilterYDProc(CrossPlatformFileFilter); + #endif ExtendedOpenFile( prompt , path , m_wildCard , crossPlatformFileFilterUPP, &reply); - - DisposeRoutineDescriptor(crossPlatformFileFilterUPP); + #if !TARGET_CARBON + DisposeFileFilterYDUPP(crossPlatformFileFilterUPP); + #endif if ( reply.sfGood == false ) { m_path = "" ; diff --git a/src/mac/carbon/font.cpp b/src/mac/carbon/font.cpp index a5df9049a2..4f26c04f91 100644 --- a/src/mac/carbon/font.cpp +++ b/src/mac/carbon/font.cpp @@ -18,7 +18,9 @@ #include "wx/font.h" #include "wx/gdicmn.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) +#endif @@ -77,7 +79,7 @@ void wxFontRefData::MacFindFont() ::GetFNum( "\pTimes" , &m_macFontNum) ; break ; case wxSWISS : - ::GetFNum( "\pHelvetica" , &m_macFontNum) ; + ::GetFNum( "\pGeneva" , &m_macFontNum) ; break ; case wxMODERN : ::GetFNum( "\pMonaco" , &m_macFontNum) ; diff --git a/src/mac/carbon/fontdlg.cpp b/src/mac/carbon/fontdlg.cpp index 9a0843d64b..d775c24c16 100644 --- a/src/mac/carbon/fontdlg.cpp +++ b/src/mac/carbon/fontdlg.cpp @@ -17,7 +17,9 @@ #include "wx/mac/fontdlg.h" #include "wx/cmndata.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) +#endif /* * wxFontDialog diff --git a/src/mac/carbon/fontutil.cpp b/src/mac/carbon/fontutil.cpp index c5a0f583d6..4f61d13ff4 100644 --- a/src/mac/carbon/fontutil.cpp +++ b/src/mac/carbon/fontutil.cpp @@ -48,18 +48,12 @@ // ---------------------------------------------------------------------------- // convert to/from the string representation: format is -// encodingid;facename[;charset] +// facename[;charset] bool wxNativeEncodingInfo::FromString(const wxString& s) { wxStringTokenizer tokenizer(s, _T(";")); - wxString encid = tokenizer.GetNextToken(); - long enc; - if ( !encid.ToLong(&enc) ) - return FALSE; - encoding = (wxFontEncoding)enc; - facename = tokenizer.GetNextToken(); if ( !facename ) return FALSE; @@ -85,10 +79,7 @@ bool wxNativeEncodingInfo::FromString(const wxString& s) wxString wxNativeEncodingInfo::ToString() const { - wxString s; - - s << (long)encoding << _T(';') << facename; - + wxString s(facename); if ( charset != 0 ) { s << _T(';') << charset; @@ -159,8 +150,6 @@ bool wxGetNativeFontEncoding(wxFontEncoding encoding, return FALSE; } - info->encoding = encoding; - return TRUE; } diff --git a/src/mac/carbon/frame.cpp b/src/mac/carbon/frame.cpp index cded59c604..b5498fec48 100644 --- a/src/mac/carbon/frame.cpp +++ b/src/mac/carbon/frame.cpp @@ -14,7 +14,7 @@ #endif #include "wx/frame.h" -#include "wx/statusbr.h" +#include "wx/mac/statusbr.h" #include "wx/toolbar.h" #include "wx/menuitem.h" #include "wx/menu.h" @@ -28,16 +28,18 @@ extern wxList wxModelessWindows; extern wxList wxPendingDelete; -BEGIN_EVENT_TABLE(wxFrame, wxWindow) - EVT_SIZE(wxFrame::OnSize) +#if !USE_SHARED_LIBRARY +BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) +// EVT_SIZE(wxFrame::OnSize) EVT_ACTIVATE(wxFrame::OnActivate) - EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) + // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) - EVT_IDLE(wxFrame::OnIdle) - EVT_CLOSE(wxFrame::OnCloseWindow) +// EVT_IDLE(wxFrame::OnIdle) +// EVT_CLOSE(wxFrame::OnCloseWindow) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) +#endif #if wxUSE_NATIVE_STATUSBAR bool wxFrame::m_useNativeStatusBar = TRUE; @@ -45,17 +47,43 @@ bool wxFrame::m_useNativeStatusBar = TRUE; bool wxFrame::m_useNativeStatusBar = FALSE; #endif -wxFrame::wxFrame() +#define WX_MAC_STATUSBAR_HEIGHT 15 +// ---------------------------------------------------------------------------- +// creation/destruction +// ---------------------------------------------------------------------------- + +void wxFrame::Init() { -#if wxUSE_TOOLBAR - m_frameToolBar = NULL ; + m_iconized = FALSE; + +#if wxUSE_TOOLTIPS + m_hwndToolTip = 0; #endif +} - // in order to be able to give size events on show - m_frameMenuBar = NULL; - m_frameStatusBar = NULL; - m_iconized = FALSE; - m_isShown = FALSE; +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, @@ -66,13 +94,7 @@ bool wxFrame::Create(wxWindow *parent, long style, const wxString& name) { - if (!parent) - wxTopLevelWindows.Append(this); - - SetName(name); - m_windowStyle = style; m_frameMenuBar = NULL; - m_isShown = FALSE; #if wxUSE_TOOLBAR m_frameToolBar = NULL ; @@ -88,74 +110,24 @@ bool wxFrame::Create(wxWindow *parent, if (parent) parent->AddChild(this); - wxModelessWindows.Append(this); - - // create frame. - - 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 ; - - m_width = size.x; - if (m_width == -1) - m_width = 20; - m_height = size.y; - if (m_height == -1) - m_height = 20; + if (!parent) + wxTopLevelWindows.Append(this); - m_macWindowData = new MacWindowData() ; + MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; + + m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; - ::SetRect(&theBoundsRect, m_x, m_y, m_x + m_width, m_y + m_height); + wxModelessWindows.Append(this); - WindowClass wclass = kDocumentWindowClass ; - WindowAttributes attr = kWindowNoAttributes ; - - if ( ( m_windowStyle & wxMINIMIZE_BOX ) || ( m_windowStyle & wxMAXIMIZE_BOX ) ) - { - attr |= kWindowFullZoomAttribute ; - attr |= kWindowResizableAttribute ; - } - if ( m_windowStyle & wxSTAY_ON_TOP ) - { - wclass = kFloatingWindowClass ; - -// if ( m_windowStyle & wxCAPTION ) -// attr |= kHasPaletteTitlebarMask ; - } - else - { - } - if ( m_windowStyle & wxSYSTEM_MENU ) - { - attr |= kWindowCloseBoxAttribute ; - } - UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ; - wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ; - wxString label ; - if( wxApp::s_macDefaultEncodingIsPC ) - label = wxMacMakeMacStringFromPC( title ) ; - else - label = title ; - UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; - UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; - m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; - m_macWindowData->m_macFocus = NULL ; return TRUE; } wxFrame::~wxFrame() { + m_isBeingDeleted = TRUE; wxTopLevelWindows.DeleteObject(this); - if (m_frameStatusBar) - delete m_frameStatusBar; - if (m_frameMenuBar) - delete m_frameMenuBar; + DeleteAllBars(); /* Check if it's the last top-level window */ @@ -173,11 +145,21 @@ wxFrame::~wxFrame() } -void wxFrame::Iconize(bool iconize) +bool wxFrame::Enable(bool enable) { - // TODO -} + if ( !wxWindow::Enable(enable) ) + return FALSE; + if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) + { + for ( int i = 0 ; i < m_frameMenuBar->GetMenuCount() ; ++ i ) + { + m_frameMenuBar->EnableTop( i , enable ) ; + } + } + + return TRUE; +} // Equivalent to maximize/restore in Windows void wxFrame::Maximize(bool maximize) { @@ -190,6 +172,11 @@ bool wxFrame::IsIconized() const return FALSE; } +void wxFrame::Iconize(bool iconize) +{ + // TODO +} + // Is the frame maximized? bool wxFrame::IsMaximized(void) const { @@ -197,10 +184,14 @@ bool wxFrame::IsMaximized(void) const return FALSE; } +void wxFrame::Restore() +{ + // TODO +} + void wxFrame::SetIcon(const wxIcon& icon) { - m_icon = icon; - // TODO + wxFrameBase::SetIcon(icon); } wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, @@ -208,61 +199,12 @@ wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, { wxStatusBar *statusBar = NULL; - statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 17), - style, name); - - // Set the height according to the font and the border size - // we shouldn't do this on the mac, because we have to fit the grow box - /* - wxClientDC dc(statusBar); - dc.SetFont(statusBar->GetFont()); - - long x, y; - dc.GetTextExtent("X", &x, &y); - - int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); - - statusBar->SetSize(-1, -1, 100, height); - - */ + statusBar = new wxStatusBar(this, id, style, name); statusBar->SetFieldsCount(number); return statusBar; } -wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id, - const wxString& name) -{ - // Calling CreateStatusBar twice is an error. - wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, - "recreating status bar in wxFrame" ); - - m_frameStatusBar = OnCreateStatusBar(number, style, id, - name); - if ( m_frameStatusBar ) - { - PositionStatusBar(); - return m_frameStatusBar; - } - else - return NULL; -} - -void wxFrame::SetStatusText(const wxString& text, int number) -{ - wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); - - m_frameStatusBar->SetStatusText(text, number); -} - -void wxFrame::SetStatusWidths(int n, const int widths_field[]) -{ - wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); - - m_frameStatusBar->SetStatusWidths(n, widths_field); - PositionStatusBar(); -} - void wxFrame::PositionStatusBar() { if (m_frameStatusBar ) @@ -274,7 +216,7 @@ void wxFrame::PositionStatusBar() // Since we wish the status bar to be directly under the client area, // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. - m_frameStatusBar->SetSize(0, h, w, sh); + m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT ); } } @@ -282,43 +224,15 @@ void wxFrame::SetMenuBar(wxMenuBar *menuBar) { if (!menuBar) { - m_frameMenuBar = NULL; return; } + m_frameMenuBar = NULL; m_frameMenuBar = menuBar; - // TODO : we move this into the app code m_frameMenuBar->MacInstallMenuBar() ; + m_frameMenuBar->Attach(this); } -void wxFrame::Fit() -{ - // Work out max. size - wxNode *node = GetChildren().First(); - int max_width = 0; - int max_height = 0; - while (node) - { - // Find a child that's a subwindow, but not a dialog box. - wxWindow *win = (wxWindow *)node->Data(); - - if (!win->IsKindOf(CLASSINFO(wxFrame)) && - !win->IsKindOf(CLASSINFO(wxDialog))) - { - int width, height; - int x, y; - win->GetSize(&width, &height); - win->GetPosition(&x, &y); - - if ((x + width) > max_width) - max_width = x + width; - if ((y + height) > max_height) - max_height = y + height; - } - node = node->Next(); - } - SetClientSize(max_width, max_height); -} // Responds to colour changes, and passes event on to children. void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) @@ -337,217 +251,55 @@ void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) wxWindow::OnSysColourChanged(event); } -// Default resizing behaviour - if only ONE subwindow, -// resize to client rectangle size -void wxFrame::OnIdle(wxIdleEvent& WXUNUSED(event) ) -{ - DoMenuUpdates(); -} - - -// update all menus -void wxFrame::DoMenuUpdates() -{ - wxMenuBar* bar = GetMenuBar(); - - if ( bar != NULL ) - { - int nCount = bar->GetMenuCount(); - for (int n = 0; n < nCount; n++) - DoMenuUpdates(bar->GetMenu(n), (wxWindow*) NULL); - } -} - -// update a menu and all submenus recursively -void wxFrame::DoMenuUpdates(wxMenu* menu, wxWindow* WXUNUSED(focusWin)) -{ - wxEvtHandler* evtHandler = GetEventHandler(); - wxMenuItemList::Node* node = menu->GetMenuItems().GetFirst(); - while (node) - { - wxMenuItem* item = node->GetData(); - if ( !item->IsSeparator() ) - { - wxWindowID id = item->GetId(); - wxUpdateUIEvent event(id); - event.SetEventObject( this ); - - if (evtHandler->ProcessEvent(event)) - { - if (event.GetSetText()) - menu->SetLabel(id, event.GetText()); - if (event.GetSetChecked()) - menu->Check(id, event.GetChecked()); - if (event.GetSetEnabled()) - menu->Enable(id, event.GetEnabled()); - } - - if (item->GetSubMenu()) - DoMenuUpdates(item->GetSubMenu(), (wxWindow*) NULL); - } - node = node->GetNext(); - } -} - -void wxFrame::OnSize(wxSizeEvent& event) -{ - // if we're using constraints - do use them - #if wxUSE_CONSTRAINTS - if ( GetAutoLayout() ) { - Layout(); - return; - } - #endif - - // do we have _exactly_ one child? - wxWindow *child = NULL; - for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) - { - wxWindow *win = (wxWindow *)node->Data(); - if ( !win->IsKindOf(CLASSINFO(wxFrame)) && - !win->IsKindOf(CLASSINFO(wxDialog)) && - (win != GetStatusBar()) -#if wxUSE_TOOLBAR - && - (win != GetToolBar()) -#endif - ) - { - if ( child ) - return; // it's our second subwindow - nothing to do - child = win; - } - } - - if ( child ) { - // we have exactly one child - set it's size to fill the whole frame - int clientW, clientH; - GetClientSize(&clientW, &clientH); - - int x = 0; - int y = 0; - - child->SetSize(x, y, clientW, clientH); - } -} // Default activation behaviour - set the focus for the first child // subwindow found. void wxFrame::OnActivate(wxActivateEvent& event) { - for(wxNode *node = GetChildren().First(); node; node = node->Next()) - { - // Find a child that's a subwindow, but not a dialog box. - wxWindow *child = (wxWindow *)node->Data(); - if (!child->IsKindOf(CLASSINFO(wxFrame)) && - !child->IsKindOf(CLASSINFO(wxDialog))) + if ( !event.GetActive() ) { - child->SetFocus(); - return; + event.Skip(); + return; } - } -} - -// The default implementation for the close window event. -void wxFrame::OnCloseWindow(wxCloseEvent& event) -{ - this->Destroy(); -} - -// Destroy the window (delayed, if a managed window) -bool wxFrame::Destroy() -{ - if (!wxPendingDelete.Member(this)) - wxPendingDelete.Append(this); - return TRUE; -} -// Default menu selection behaviour - display a help string -void wxFrame::OnMenuHighlight(wxMenuEvent& event) -{ - if (GetStatusBar()) - { - if (event.GetMenuId() == -1) - SetStatusText(""); - else + for ( wxWindowList::Node *node = GetChildren().GetFirst(); + node; + node = node->GetNext() ) { - wxMenuBar *menuBar = GetMenuBar(); - if (menuBar) - { - wxString helpString(menuBar->GetHelpString(event.GetMenuId())); - if (helpString != "") - SetStatusText(helpString); - } - } - } -} - -wxMenuBar *wxFrame::GetMenuBar() const -{ - return m_frameMenuBar; -} + // FIXME all this is totally bogus - we need to do the same as wxPanel, + // but how to do it without duplicating the code? + // restore focus + wxWindow *child = node->GetData(); -// Call this to simulate a menu command -void wxFrame::Command(int id) -{ - ProcessCommand(id); -} - -void wxFrame::ProcessCommand(int id) -{ - wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); - commandEvent.SetInt( id ); - commandEvent.SetEventObject( this ); - - wxMenuBar *bar = GetMenuBar() ; - if (!bar) - return; - -/* TODO: check the menu item if required - wxMenuItem *item = bar->FindItemForId(id) ; - if (item && item->IsCheckable()) - { - bar->Check(id,!bar->Checked(id)) ; - } -*/ - - GetEventHandler()->ProcessEvent(commandEvent); -} - -// Checks if there is a toolbar, and returns the first free client position -wxPoint wxFrame::GetClientAreaOrigin() const -{ - wxPoint pt(0, 0); + if ( !child->IsTopLevel() #if wxUSE_TOOLBAR - if (GetToolBar()) - { - int w, h; - GetToolBar()->GetSize(& w, & h); - - if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) + && !wxDynamicCast(child, wxToolBar) +#endif // wxUSE_TOOLBAR +#if wxUSE_STATUSBAR + && !wxDynamicCast(child, wxStatusBar) +#endif // wxUSE_STATUSBAR + ) { - pt.x += w; - } - else - { - pt.y += h; + child->SetFocus(); + return; } } -#endif - return pt; } void wxFrame::DoGetClientSize(int *x, int *y) const { wxWindow::DoGetClientSize( x , y ) ; +#if wxUSE_STATUSBAR if ( GetStatusBar() ) { int statusX, statusY; GetStatusBar()->GetClientSize(&statusX, &statusY); - *y -= statusY; + // right now this is a constant, this might change someday + *y -= WX_MAC_STATUSBAR_HEIGHT ; } +#endif // wxUSE_STATUSBAR wxPoint pt(GetClientAreaOrigin()); *y -= pt.y; @@ -576,39 +328,20 @@ void wxFrame::DoSetClientSize(int clientwidth, int clientheight) #if wxUSE_TOOLBAR wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) { - wxCHECK_MSG( m_frameToolBar == NULL, FALSE, - "recreating toolbar in wxFrame" ); - - wxToolBar* toolBar = OnCreateToolBar(style, id, name); - if (toolBar) + if ( wxFrameBase::CreateToolBar(style, id, name) ) { - SetToolBar(toolBar); PositionToolBar(); - return toolBar; - } - else - { - return NULL; } -} -wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name) -{ - return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name); + return m_frameToolBar; } void wxFrame::PositionToolBar() { int cw, ch; - // TODO: we actually need to use the low-level client size, before - // the toolbar/status bar were added. - // So DEFINITELY replace the line below with something appropriate. - - // GetClientSize(& cw, &ch); - - cw = m_width ; - ch = m_height ; + cw = m_width ; + ch = m_height ; if ( GetStatusBar() ) { @@ -627,12 +360,12 @@ void wxFrame::PositionToolBar() // 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(0, 0, tw, ch, wxSIZE_NO_ADJUSTMENTS); + GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); } else { // Use the 'real' position - GetToolBar()->SetSize(0, 0, cw, th, wxSIZE_NO_ADJUSTMENTS); + GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); } } } diff --git a/src/mac/carbon/gauge.cpp b/src/mac/carbon/gauge.cpp index be0d0d0a3c..67d5dd9c84 100644 --- a/src/mac/carbon/gauge.cpp +++ b/src/mac/carbon/gauge.cpp @@ -15,7 +15,9 @@ #include "wx/gauge.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) +#endif #include @@ -31,15 +33,13 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id, Rect bounds ; Str255 title ; m_rangeMax = range ; - m_macHorizontalBorder = 2 ; // additional pixels around the real control - m_macVerticalBorder = 2 ; if ( size.x == wxDefaultSize.x && size.y == wxDefaultSize.y) { size = wxSize( 200 , 16 ) ; } - MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; + MacPreControlCreate( parent , id , "" , pos , size ,style & 0xE0FFFFFF /* no borders on mac */ , validator , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , range, kControlProgressBarProc , (long) this ) ; @@ -66,7 +66,7 @@ void wxGauge::SetRange(int r) void wxGauge::SetValue(int pos) { m_gaugePos = pos; - ::SetControlValue( m_macControl , m_gaugePos ) ; + ::SetControlValue( m_macControl , m_gaugePos ) ; } int wxGauge::GetShadowWidth() const diff --git a/src/mac/carbon/gdiobj.cpp b/src/mac/carbon/gdiobj.cpp index 46b1aa871f..63697c8354 100644 --- a/src/mac/carbon/gdiobj.cpp +++ b/src/mac/carbon/gdiobj.cpp @@ -15,6 +15,8 @@ #include "wx/gdiobj.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxGDIObject, wxObject) +#endif // TODO: Nothing to do, unless you want to. diff --git a/src/mac/carbon/helpxxxx.cpp b/src/mac/carbon/helpxxxx.cpp index b7f0babfa2..086762c646 100644 --- a/src/mac/carbon/helpxxxx.cpp +++ b/src/mac/carbon/helpxxxx.cpp @@ -17,7 +17,9 @@ #include +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxXXXXHelpController, wxHelpControllerBase) +#endif wxXXXXHelpController::wxXXXXHelpController() { diff --git a/src/mac/carbon/icon.cpp b/src/mac/carbon/icon.cpp index 2fb0616ba8..4ec1f1b5e9 100644 --- a/src/mac/carbon/icon.cpp +++ b/src/mac/carbon/icon.cpp @@ -15,7 +15,9 @@ #include "wx/icon.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) +#endif /* * Icons @@ -58,6 +60,14 @@ wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(he { } +wxIcon::wxIcon( const char **bits, int width, int height ) +{ +} + +wxIcon::wxIcon( char **bits, int width, int height ) +{ +} + wxIcon::wxIcon(const wxString& icon_file, long flags, int desiredWidth, int desiredHeight) @@ -96,20 +106,23 @@ bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, lo c2pstr( (char*) theName ) ; Handle resHandle = GetNamedResource( 'cicn' , theName ) ; - GetResInfo( resHandle , &theId , &theType , theName ) ; - ReleaseResource( resHandle ) ; - - CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ; - if ( theIcon ) + if ( resHandle != 0L ) { - M_ICONHANDLERDATA->m_hIcon = theIcon ; - M_ICONHANDLERDATA->m_width = 32 ; - M_ICONHANDLERDATA->m_height = 32 ; + GetResInfo( resHandle , &theId , &theType , theName ) ; + ReleaseResource( resHandle ) ; - M_ICONHANDLERDATA->m_depth = 8 ; - M_ICONHANDLERDATA->m_ok = true ; - M_ICONHANDLERDATA->m_numColors = 256 ; - return TRUE ; + CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ; + if ( theIcon ) + { + M_ICONHANDLERDATA->m_hIcon = theIcon ; + M_ICONHANDLERDATA->m_width = 32 ; + M_ICONHANDLERDATA->m_height = 32 ; + + M_ICONHANDLERDATA->m_depth = 8 ; + M_ICONHANDLERDATA->m_ok = true ; + M_ICONHANDLERDATA->m_numColors = 256 ; + return TRUE ; + } } return FALSE ; -} +} \ No newline at end of file diff --git a/src/mac/carbon/imaglist.cpp b/src/mac/carbon/imaglist.cpp index cb4b9ff01c..4cb47b4e69 100644 --- a/src/mac/carbon/imaglist.cpp +++ b/src/mac/carbon/imaglist.cpp @@ -15,7 +15,9 @@ #include "wx/stubs/imaglist.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject) +#endif wxImageList::wxImageList() { diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp index c518ad035c..6564af7b77 100644 --- a/src/mac/carbon/listbox.cpp +++ b/src/mac/carbon/listbox.cpp @@ -21,11 +21,13 @@ #include "wx/utils.h" #include "extldef.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl) BEGIN_EVENT_TABLE(wxListBox, wxControl) EVT_SIZE( wxListBox::OnSize ) END_EVENT_TABLE() +#endif #include @@ -41,6 +43,7 @@ wxListBox::wxListBox() { m_noItems = 0; m_selected = 0; + m_macList = NULL ; } bool wxListBox::Create(wxWindow *parent, wxWindowID id, @@ -56,8 +59,6 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, Rect bounds ; Str255 title ; - m_macHorizontalBorder = 5 ; // additional pixels around the real control - m_macVerticalBorder = 5 ; MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; @@ -67,6 +68,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, long result ; UMAGetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag , sizeof( ListHandle ) , (char*) &m_macList , &result ) ; + HLock( (Handle) m_macList ) ; NewExtLDEFInfo( m_macList , MacDrawStringCell , (long) this ) ; (**m_macList).selFlags = 0 ; if ( style & wxLB_MULTIPLE ) @@ -109,7 +111,11 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, wxListBox::~wxListBox() { Free() ; - DisposeExtLDEFInfo( m_macList ) ; + if ( m_macList ) + { + DisposeExtLDEFInfo( m_macList ) ; + m_macList = NULL ; + } } void wxListBox::Free() @@ -156,7 +162,7 @@ void wxListBox::Delete(int N) #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN m_stringArray.Remove( N ) ; m_dataArray.Remove( N ) ; - m_noItems --; + m_noItems --; MacDelete( N ) ; } @@ -236,19 +242,29 @@ int wxListBox::FindString(const wxString& st) const { wxString search = s.Left( s.Length() - 1 ) ; int len = search.Length() ; - for ( int i = 0 ; i < m_noItems ; ++ i ) - { - if ( equalstring( m_stringArray[i].Left( len ) , search , false , false ) ) - return i ; - } + Str255 s1 , s2 ; + strcpy( (char*) s2 , search.c_str() ) ; + c2pstr( (char*) s2 ) ; + for ( int i = 0 ; i < m_noItems ; ++ i ) + { + strcpy( (char*) s1 , m_stringArray[i].Left( len ).c_str() ) ; + c2pstr( (char*) s1 ) ; + if ( EqualString( s1 , s2 , false , false ) ) + return i ; + } } else { - for ( int i = 0 ; i < m_noItems ; ++ i ) - { - if ( equalstring( m_stringArray[i] , s , false , false ) ) - return i ; - } + Str255 s1 , s2 ; + strcpy( (char*) s2 , s.c_str() ) ; + c2pstr( (char*) s2 ) ; + for ( int i = 0 ; i < m_noItems ; ++ i ) + { + strcpy( (char*) s1 , m_stringArray[i].c_str() ) ; + c2pstr( (char*) s1 ) ; + if ( EqualString( s1 , s2 , false , false ) ) + return i ; + } } return -1; } @@ -308,7 +324,7 @@ void wxListBox::DoSetItemClientData(int N, void *Client_data) if ( m_dataArray.GetCount() > N ) { m_dataArray[N] = (char*) Client_data ; - } + } else { m_dataArray.Add( (char*) Client_data ) ; @@ -379,7 +395,14 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos) void wxListBox::SetString(int N, const wxString& s) { - m_stringArray[N] = s ; + wxString str ; + if( wxApp::s_macDefaultEncodingIsPC ) + { + str = wxMacMakeMacStringFromPC( s ) ; + } + else + str = s ; + m_stringArray[N] = str ; MacSet( N , s ) ; } @@ -539,7 +562,7 @@ void wxListBox::MacScrollTo( int n ) void wxListBox::OnSize( const wxSizeEvent &event) { Point pt = (**m_macList).cellSize ; - pt.h = m_width - 15 /* scrollbar */ - m_macHorizontalBorder * 2 ; + pt.h = m_width - 15 ; LCellSize( pt , m_macList ) ; } diff --git a/src/mac/carbon/listctrl.cpp b/src/mac/carbon/listctrl.cpp index 2c11981bf2..d1d8445652 100644 --- a/src/mac/carbon/listctrl.cpp +++ b/src/mac/carbon/listctrl.cpp @@ -16,9 +16,11 @@ #include "wx/stubs/textctrl.h" #include "wx/stubs/listctrl.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) +#endif wxListCtrl::wxListCtrl() { diff --git a/src/mac/carbon/mdi.cpp b/src/mac/carbon/mdi.cpp index 8672b2f897..887f726504 100644 --- a/src/mac/carbon/mdi.cpp +++ b/src/mac/carbon/mdi.cpp @@ -19,6 +19,7 @@ extern wxList wxModelessWindows; +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame) IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame) IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow) @@ -33,6 +34,7 @@ BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) EVT_SCROLL(wxMDIClientWindow::OnScroll) END_EVENT_TABLE() +#endif // Parent frame @@ -61,7 +63,7 @@ bool wxMDIParentFrame::Create(wxWindow *parent, else m_windowId = (int)NewControlId(); - // TODO: create MDI parent frame + // this window does not exist really wxModelessWindows.Append(this); @@ -75,7 +77,7 @@ wxMDIParentFrame::~wxMDIParentFrame() // Get size *available for subwindows* i.e. excluding menu bar. void wxMDIParentFrame::DoGetClientSize(int *x, int *y) const { - wxFrame::DoGetClientSize( x , y ) ; + wxDisplaySize( x , y ) ; } void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) @@ -175,7 +177,9 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, if (parent) parent->AddChild(this); - // TODO: create child frame + MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; + + m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; wxModelessWindows.Append(this); return FALSE; diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp index 427db90852..9a66f806d2 100644 --- a/src/mac/carbon/menu.cpp +++ b/src/mac/carbon/menu.cpp @@ -33,8 +33,10 @@ // ---------------------- #include +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler) +#endif // the (popup) menu title has this special id static const int idMenuTitle = -2; @@ -47,145 +49,6 @@ const short kwxMacAppleMenuId = 1 ; // implementation // ============================================================================ -// -// Helper Functions to get Mac Menus the way they should be ;-) -// - -void wxMacCtoPString(const char* theCString, Str255 thePString); - -// remove inappropriate characters, if useShortcuts is false, the ampersand will not auto-generate a mac menu-shortcut - -void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemText , bool useShortcuts ) -{ - char *p = (char *) &outMacItemText[1] ; - short macModifiers = 0 ; - char macShortCut = 0 ; - const char *inItemName ; - wxString inItemTextMac ; - - if (wxApp::s_macDefaultEncodingIsPC) - { - inItemTextMac = wxMacMakeMacStringFromPC( inItemText ) ; - inItemName = inItemTextMac ; - } - else - { - inItemName = inItemText ; - } - - if ( useShortcuts && !wxApp::s_macSupportPCMenuShortcuts ) - useShortcuts = false ; - - // we have problems with a leading hypen - it will be taken as a separator - - while ( *inItemName == '-' ) - inItemName++ ; - - while( *inItemName ) - { - switch ( *inItemName ) - { - // special characters for macintosh menus -> use some replacement - case ';' : - *p++ = ',' ; - break ; - case '^' : - *p++ = ' ' ; - break ; - case '!' : - *p++ = ' ' ; - break ; - case '<' : - *p++ = ' ' ; - break ; - case '/' : - *p++ = '|' ; - break ; - case '(' : - *p++ = '[' ; - break ; - case ')' : - *p++ = ']' ; - break ; - // shortcuts - case '&' : - { - ++inItemName ; - if ( *inItemName ) - { - *p++ = *inItemName ; - if ( useShortcuts ) - macShortCut = *inItemName ; - } - else - --inItemName ; - } - break ; - // win-like accelerators - case '\t' : - { - ++inItemName ; - while( *inItemName ) - { - if (strncmp("Ctrl", inItemName, 4) == 0) - { - inItemName = inItemName + 5; - macShortCut = *inItemName; - } - else if (strncmp("Cntrl", inItemName, 5) == 0) - { - inItemName = inItemName + 6; - macShortCut = *inItemName; - } - else if (strncmp("Alt", inItemName, 3) == 0) - { - inItemName = inItemName + 4; - macModifiers |= kMenuOptionModifier ; - macShortCut = *inItemName ; - } - else if (strncmp("Shift", inItemName, 5) == 0) - { - inItemName = inItemName + 6; - macModifiers |= kMenuShiftModifier ; - macShortCut = *inItemName ; - } - else if (strncmp("F", inItemName, 1) == 0) - { - inItemName += strlen( inItemName ) ; - // no function keys at the moment - // macModifiers |= kMenuShiftModifier ; - // macShortCut = *inItemName ; - } - else - { - break ; - } - } - - if ( *inItemName == 0 ) - --inItemName ; - - } - break ; - default : - *p++ = *inItemName ; - } - ++inItemName ; - } - - outMacItemText[0] = (p - (char *)outMacItemText) - 1; - if ( outMacShortcutChar ) - *outMacShortcutChar = macShortCut ; - if ( outMacModifiers ) - *outMacModifiers = macModifiers ; - if ( macShortCut ) - { - int pos = outMacItemText[0] ; - outMacItemText[++pos] = '/'; - outMacItemText[++pos] = toupper( macShortCut ); - outMacItemText[0] = pos ; - } -} // Menus @@ -199,10 +62,10 @@ void wxMenu::Init() // create the menu Str255 label; - wxMacBuildMenuString( label, NULL , NULL , m_title , false ); + wxMenuItem::MacBuildMenuString( label, NULL , NULL , m_title , false ); m_macMenuId = s_macNextMenuId++; wxCHECK_RET( s_macNextMenuId < 236 , "menu ids > 235 cannot be used for submenus on mac" ); - m_hMenu = ::NewMenu(m_macMenuId, label); + m_hMenu = UMANewMenu(m_macMenuId, label); if ( !m_hMenu ) { @@ -220,7 +83,7 @@ void wxMenu::Init() wxMenu::~wxMenu() { if (m_hMenu) - ::DisposeMenu(m_hMenu); + UMADisposeMenu(m_hMenu); #if wxUSE_ACCEL // delete accels @@ -310,38 +173,28 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) Str255 label; wxASSERT_MSG( pSubMenu->m_hMenu != NULL , "invalid submenu added"); pSubMenu->m_menuParent = this ; - wxMacBuildMenuString( label , NULL , NULL , pItem->GetText() ,false); - - // hardcoded adding of the submenu combination for mac + wxMenuItem::MacBuildMenuString( label , NULL , NULL , pItem->GetText() ,false); - int theEnd = label[0] + 1; - if (theEnd > 251) - theEnd = 251; // mac allows only 255 characters - label[theEnd++] = '/'; - label[theEnd++] = hMenuCmd; - label[theEnd++] = '!'; - label[theEnd++] = pSubMenu->m_macMenuId; - label[theEnd] = 0x00; - label[0] = theEnd; - if (wxMenuBar::MacGetInstalledMenuBar() == m_menuBar) { - ::InsertMenu( pSubMenu->m_hMenu , -1 ) ; + UMAInsertMenu( pSubMenu->m_hMenu , -1 ) ; } if ( pos == (size_t)-1 ) { - MacAppendMenu(m_hMenu, label); + UMAAppendSubMenuItem(m_hMenu, label, pSubMenu->m_macMenuId); } else { - MacInsertMenuItem(m_hMenu, label , pos); + UMAInsertSubMenuItem(m_hMenu, label , pos, pSubMenu->m_macMenuId); } } else { Str255 label ; - wxMacBuildMenuString( label , NULL , NULL , pItem->GetText(), pItem->GetId() == wxApp::s_macAboutMenuItemId); + UInt8 modifiers ; + SInt16 key ; + wxMenuItem::MacBuildMenuString( label, &key , &modifiers , pItem->GetText(), pItem->GetId() == wxApp::s_macAboutMenuItemId); if ( label[0] == 0 ) { // we cannot add empty menus on mac @@ -350,17 +203,17 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) } if ( pos == (size_t)-1 ) { - MacAppendMenu(m_hMenu, label); + UMAAppendMenuItem(m_hMenu, label,key,modifiers); } else { - MacInsertMenuItem(m_hMenu, label , pos); + UMAInsertMenuItem(m_hMenu, label , pos,key,modifiers); } if ( pItem->GetId() == idMenuTitle ) { if ( pos == (size_t)-1 ) { - UMADisableMenuItem( m_hMenu , CountMItems( m_hMenu ) ) ; + UMADisableMenuItem( m_hMenu , CountMenuItems( m_hMenu ) ) ; } else { @@ -452,113 +305,9 @@ void wxMenu::SetTitle(const wxString& label) { Str255 title ; m_title = label ; - wxMacBuildMenuString( title, NULL , NULL , label , false ); + wxMenuItem::MacBuildMenuString( title, NULL , NULL , label , false ); UMASetMenuTitle( m_hMenu , title ) ; } - -/* - -void wxMenu::SetLabel(int id, const wxString& label) -{ - Str255 maclabel ; - int index ; - wxMenuItem *item = FindItemForId(id) ; - if (item==NULL) - return; - - index = MacGetIndexFromItem( item ) ; - if (index < 1) - return; - - if (item->GetSubMenu()==NULL) - { - wxMacBuildMenuString( maclabel , NULL , NULL , label , false ); - ::SetMenuItemText( m_hMenu , index , maclabel ) ; - } - else - { - wxMacBuildMenuString( maclabel , NULL , NULL , label , false ); - ::SetMenuItemText( m_hMenu , index , maclabel ) ; - } - item->SetName(label); -} - -wxString wxMenu::GetLabel(int Id) const -{ - wxMenuItem *pItem = FindItemForId(Id) ; - return pItem->GetName() ; -} - -// Finds the item id matching the given string, -1 if not found. -int wxMenu::FindItem (const wxString& itemString) const -{ - char buf1[200]; - char buf2[200]; - wxStripMenuCodes ((char *)(const char *)itemString, buf1); - - for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) - { - wxMenuItem *item = (wxMenuItem *) node->Data (); - if (item->GetSubMenu()) - { - int ans = item->GetSubMenu()->FindItem(itemString); - if (ans > -1) - return ans; - } - if ( !item->IsSeparator() ) - { - wxStripMenuCodes((char *)item->GetName().c_str(), buf2); - if (strcmp(buf1, buf2) == 0) - return item->GetId(); - } - } - - return -1; -} - -wxMenuItem *wxMenu::FindItemForId(int itemId, wxMenu ** itemMenu) const -{ - if (itemMenu) - *itemMenu = NULL; - for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) - { - wxMenuItem *item = (wxMenuItem *) node->Data (); - - if (item->GetId() == itemId) - { - if (itemMenu) - *itemMenu = (wxMenu *) this; - return item; - } - - if (item->GetSubMenu()) - { - wxMenuItem *ans = item->GetSubMenu()->FindItemForId (itemId, itemMenu); - if (ans) - return ans; - } - } - - if (itemMenu) - *itemMenu = NULL; - return NULL; -} - -void wxMenu::SetHelpString(int itemId, const wxString& helpString) -{ - wxMenuItem *item = FindItemForId (itemId); - if (item) - item->SetHelp(helpString); -} - -wxString wxMenu::GetHelpString (int itemId) const -{ - wxMenuItem *item = FindItemForId (itemId); - wxString str(""); - return (item == NULL) ? str : item->GetHelp(); -} -*/ - bool wxMenu::ProcessCommand(wxCommandEvent & event) { bool processed = FALSE; @@ -678,7 +427,10 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in if (node) { wxMenuItem *pItem = (wxMenuItem*)node->Data(); - + + if (pItem->IsCheckable()) + pItem->Check(! pItem->IsChecked()); + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, pItem->GetId()); event.m_timeStamp = when; event.SetEventObject(handler); @@ -892,7 +644,8 @@ void wxMenuBar::MacInstallMenuBar() int pos ; wxMenu* menu = m_menus[i] , *subMenu = NULL ; - +#if !TARGET_CARBON + /* the help menu does not exist in CARBON anymore */ if( m_titles[i] == "?" || m_titles[i] == "&?" || m_titles[i] == wxApp::s_macHelpMenuTitleName ) { MenuHandle mh = NULL ; @@ -906,8 +659,8 @@ void wxMenuBar::MacInstallMenuBar() formerHelpMenuItems = CountMenuItems( mh ) ; } - for (pos = 0 , node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) - { + for (pos = 0 , node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) + { item = (wxMenuItem *)node->Data(); subMenu = item->GetSubMenu() ; if (subMenu) @@ -919,12 +672,14 @@ void wxMenuBar::MacInstallMenuBar() if ( item->IsSeparator() ) { if ( mh ) - ::AppendMenu(mh, "\p-" ); + UMAAppendMenuItem(mh, "\p-" ); } else { Str255 label ; - wxMacBuildMenuString( label , NULL , NULL , item->GetText(), item->GetId() != wxApp::s_macAboutMenuItemId); // no shortcut in about menu + UInt8 modifiers ; + SInt16 key ; + wxMenuItem::MacBuildMenuString( label, &key , &modifiers , item->GetText(), item->GetId() != wxApp::s_macAboutMenuItemId); // no shortcut in about menu if ( label[0] == 0 ) { // we cannot add empty menus on mac @@ -933,36 +688,36 @@ void wxMenuBar::MacInstallMenuBar() } if ( item->GetId() == wxApp::s_macAboutMenuItemId ) { - ::SetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , label ); - // ::EnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 ); - ::EnableItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 ); + UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , label ); + UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 ); } else { if ( mh ) - ::AppendMenu(mh, label ); + UMAAppendMenuItem(mh, label , key , modifiers ); } } } } } else +#endif { - wxMacBuildMenuString( label, NULL , NULL , m_titles[i] , false ); + wxMenuItem::MacBuildMenuString( label, NULL , NULL , m_titles[i] , false ); UMASetMenuTitle( menu->GetHMenu() , label ) ; - for (pos = 0, node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) - { + for (pos = 0, node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) + { item = (wxMenuItem *)node->Data(); subMenu = item->GetSubMenu() ; if (subMenu) { - ::InsertMenu( subMenu->GetHMenu() , -1 ) ; + UMAInsertMenu( subMenu->GetHMenu() , -1 ) ; } } - ::InsertMenu(m_menus[i]->GetHMenu(), 0); + UMAInsertMenu(m_menus[i]->GetHMenu(), 0); } } - ::DrawMenuBar() ; + UMADrawMenuBar() ; s_macInstalledMenuBar = this; } @@ -1037,18 +792,18 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) { if (s_macInstalledMenuBar == this) { - ::DeleteMenu( menuOld->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ; + UMADeleteMenu( menuOld->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ; { Str255 label; - wxMacBuildMenuString( label, NULL , NULL , title , false ); + wxMenuItem::MacBuildMenuString( label, NULL , NULL , title , false ); UMASetMenuTitle( menu->GetHMenu() , label ) ; if ( pos == m_menus.GetCount() - 1) { - ::InsertMenu( menu->GetHMenu() , 0 ) ; + UMAInsertMenu( menu->GetHMenu() , 0 ) ; } else { - ::InsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ; + UMAInsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ; } } } @@ -1206,6 +961,16 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title) return TRUE; } +void wxMenuBar::Attach(wxFrame *frame) +{ +// wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") ); + + m_menuBarFrame = frame; + +#if wxUSE_ACCEL + RebuildAccelTable(); +#endif // wxUSE_ACCEL +} // --------------------------------------------------------------------------- // wxMenuBar searching for menu items // --------------------------------------------------------------------------- diff --git a/src/mac/carbon/menuitem.cpp b/src/mac/carbon/menuitem.cpp index 22b07f575d..153c750c44 100644 --- a/src/mac/carbon/menuitem.cpp +++ b/src/mac/carbon/menuitem.cpp @@ -25,19 +25,152 @@ // dynamic classes implementation // ---------------------------------------------------------------------------- +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) - -void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) ; - -wxString wxMenuItemBase::GetLabelFromText(const wxString& text) -{ - return wxStripMenuCodes(text); -} +#endif //USE_SHARED_LIBRARY // ---------------------------------------------------------------------------- // wxMenuItem // ---------------------------------------------------------------------------- +// +// Helper Functions to get Mac Menus the way they should be ;-) +// + +void wxMacCtoPString(const char* theCString, Str255 thePString); + +// remove inappropriate characters, if useShortcuts is false, the ampersand will not auto-generate a mac menu-shortcut + +wxMenuItem::MacBuildMenuString(StringPtr outMacItemText, SInt16 *outMacShortcutChar , UInt8 *outMacModifiers , const char *inItemText , bool useShortcuts ) +{ + char *p = (char *) &outMacItemText[1] ; + short macModifiers = 0 ; + char macShortCut = 0 ; + const char *inItemName ; + wxString inItemTextMac ; + + if (wxApp::s_macDefaultEncodingIsPC) + { + inItemTextMac = wxMacMakeMacStringFromPC( inItemText ) ; + inItemName = inItemTextMac ; + } + else + { + inItemName = inItemText ; + } + + if ( useShortcuts && !wxApp::s_macSupportPCMenuShortcuts ) + useShortcuts = false ; + + // we have problems with a leading hypen - it will be taken as a separator + + while ( *inItemName == '-' ) + inItemName++ ; + + while( *inItemName ) + { + switch ( *inItemName ) + { + // special characters for macintosh menus -> use some replacement + case ';' : + *p++ = ',' ; + break ; + case '^' : + *p++ = ' ' ; + break ; + case '!' : + *p++ = ' ' ; + break ; + case '<' : + *p++ = '[' ; + break ; + case '>' : + *p++ = ']' ; + break ; + case '/' : + *p++ = '|' ; + break ; + case '(' : + *p++ = '[' ; + break ; + case ')' : + *p++ = ']' ; + break ; + // shortcuts + case '&' : + { + ++inItemName ; + if ( *inItemName ) + { + *p++ = *inItemName ; + if ( useShortcuts ) + macShortCut = *inItemName ; + } + else + --inItemName ; + } + break ; + // win-like accelerators + case '\t' : + { + ++inItemName ; + while( *inItemName ) + { + if (strncmp("Ctrl", inItemName, 4) == 0) + { + inItemName = inItemName + 5; + macShortCut = *inItemName; + } + else if (strncmp("Cntrl", inItemName, 5) == 0) + { + inItemName = inItemName + 6; + macShortCut = *inItemName; + } + else if (strncmp("Alt", inItemName, 3) == 0) + { + inItemName = inItemName + 4; + macModifiers |= kMenuOptionModifier ; + macShortCut = *inItemName ; + } + else if (strncmp("Shift", inItemName, 5) == 0) + { + inItemName = inItemName + 6; + macModifiers |= kMenuShiftModifier ; + macShortCut = *inItemName ; + } + else if (strncmp("F", inItemName, 1) == 0) + { + inItemName += strlen( inItemName ) ; + // no function keys at the moment + // macModifiers |= kMenuShiftModifier ; + // macShortCut = *inItemName ; + } + else + { + break ; + } + } + + if ( *inItemName == 0 ) + --inItemName ; + + } + break ; + default : + *p++ = *inItemName ; + } + ++inItemName ; + } + + outMacItemText[0] = (p - (char *)outMacItemText) - 1; + if ( outMacShortcutChar ) + *outMacShortcutChar = macShortCut ; + if ( outMacModifiers ) + *outMacModifiers = macModifiers ; + + return 0 ; +} + // ctor & dtor // ----------- @@ -184,8 +317,8 @@ void wxMenuItem::SetText(const wxString& text) if ( index >= 1 ) { Str255 label; - wxMacBuildMenuString( label , NULL , NULL , text ,false); - ::SetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark + MacBuildMenuString( label , NULL , NULL , text ,false); + UMASetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark } } @@ -204,6 +337,12 @@ void wxMenuItem::SetCheckable(bool checkable) // wxMenuItemBase // ---------------------------------------------------------------------------- +/* static */ +wxString wxMenuItemBase::GetLabelFromText(const wxString& text) +{ + return wxStripMenuCodes(text); +} + wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, int id, const wxString& name, diff --git a/src/mac/carbon/metafile.cpp b/src/mac/carbon/metafile.cpp index 5742ba4ce6..fc6c64b825 100644 --- a/src/mac/carbon/metafile.cpp +++ b/src/mac/carbon/metafile.cpp @@ -39,8 +39,10 @@ extern bool wxClipboardIsOpen; +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject) IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC) +#endif /* * Metafiles @@ -57,7 +59,7 @@ wxMetafileRefData::~wxMetafileRefData(void) { if (m_metafile) { - KillPicture( m_metafile ) ; + KillPicture( m_metafile ) ; m_metafile = 0; } } @@ -83,7 +85,7 @@ bool wxMetaFile::SetClipboard(int width, int height) { if (!m_refData) return FALSE; -/* + bool alreadyOpen=wxClipboardOpen(); if (!alreadyOpen) { @@ -92,11 +94,19 @@ bool wxMetaFile::SetClipboard(int width, int height) } bool success = wxSetClipboardData(wxDF_METAFILE, this, width,height); if (!alreadyOpen) wxCloseClipboard(); - return (bool) success; - */ + return (bool) success; + return TRUE ; } +void wxMetafile::SetHMETAFILE(PicHandle mf) +{ + if (!m_refData) + m_refData = new wxMetafileRefData; + + M_METAFILEDATA->m_metafile = mf; +} + bool wxMetaFile::Play(wxDC *dc) { if (!m_refData) @@ -142,11 +152,11 @@ wxMetaFileDC::wxMetaFileDC(const wxString& file) wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ; - m_metaFile = new wxMetaFile("") ; - Rect r={0,0,100,100} ; + m_metaFile = new wxMetaFile("") ; + Rect r={0,0,1000,1000} ; - m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ; - ::GetPort( &m_macPort ) ; + m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ; + ::GetPort( &m_macPort ) ; m_ok = TRUE ; SetMapMode(wxMM_TEXT); @@ -184,5 +194,4 @@ wxMetaFile *wxMetaFileDC::Close() return m_metaFile; } - #endif diff --git a/src/mac/carbon/minifram.cpp b/src/mac/carbon/minifram.cpp index cbe09b7d81..4f6f5e5fcb 100644 --- a/src/mac/carbon/minifram.cpp +++ b/src/mac/carbon/minifram.cpp @@ -15,6 +15,8 @@ #include "wx/minifram.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame, wxFrame) +#endif diff --git a/src/mac/carbon/msgdlg.cpp b/src/mac/carbon/msgdlg.cpp index cf229e5200..bbdea6abf8 100644 --- a/src/mac/carbon/msgdlg.cpp +++ b/src/mac/carbon/msgdlg.cpp @@ -16,7 +16,9 @@ #include "wx/msgdlg.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_CLASS(wxMessageDialog, wxDialog) +#endif #define kMacOKAlertResourceID 128 #define kMacYesNoAlertResourceID 129 @@ -70,7 +72,6 @@ int wxMessageDialog::ShowModal() Str255 pascalTitle ; Str255 pascalText ; - if (wxApp::s_macDefaultEncodingIsPC) { strcpy( (char*) pascalTitle , wxMacMakeMacStringFromPC( m_caption ) ) ; diff --git a/src/mac/carbon/palette.cpp b/src/mac/carbon/palette.cpp index 676f54739a..85a9fd16d8 100644 --- a/src/mac/carbon/palette.cpp +++ b/src/mac/carbon/palette.cpp @@ -15,7 +15,9 @@ #include "wx/palette.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject) +#endif /* * Palette diff --git a/src/mac/carbon/pen.cpp b/src/mac/carbon/pen.cpp index 65da06087d..1e3ced2a3a 100644 --- a/src/mac/carbon/pen.cpp +++ b/src/mac/carbon/pen.cpp @@ -17,7 +17,9 @@ #include "wx/utils.h" #include "wx/pen.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject) +#endif wxPenRefData::wxPenRefData() { @@ -26,7 +28,7 @@ wxPenRefData::wxPenRefData() m_join = wxJOIN_ROUND ; m_cap = wxCAP_ROUND ; m_nbDash = 0 ; - m_dash = (wxMACDash*)NULL; + m_dash = 0 ; /* TODO: null data m_hPen = 0; */ @@ -76,7 +78,7 @@ wxPen::wxPen(const wxColour& col, int Width, int Style) M_PENDATA->m_join = wxJOIN_ROUND ; M_PENDATA->m_cap = wxCAP_ROUND ; M_PENDATA->m_nbDash = 0 ; - M_PENDATA->m_dash = (wxMACDash*)NULL; + M_PENDATA->m_dash = 0 ; RealizeResource(); @@ -94,7 +96,7 @@ wxPen::wxPen(const wxBitmap& stipple, int Width) M_PENDATA->m_join = wxJOIN_ROUND ; M_PENDATA->m_cap = wxCAP_ROUND ; M_PENDATA->m_nbDash = 0 ; - M_PENDATA->m_dash = (wxMACDash*)NULL; + M_PENDATA->m_dash = 0 ; RealizeResource(); @@ -168,7 +170,7 @@ void wxPen::SetDashes(int nb_dashes, const wxDash *Dash) Unshare(); M_PENDATA->m_nbDash = nb_dashes; - M_PENDATA->m_dash = (wxMACDash *)Dash; + M_PENDATA->m_dash = (wxDash *)Dash; RealizeResource(); } diff --git a/src/mac/carbon/printdlg.cpp b/src/mac/carbon/printdlg.cpp index a1f8f6b196..a5c41e0737 100644 --- a/src/mac/carbon/printdlg.cpp +++ b/src/mac/carbon/printdlg.cpp @@ -16,11 +16,14 @@ #include "wx/object.h" #include "wx/printdlg.h" #include "wx/dcprint.h" +#include "wx/mac/uma.h" // Use generic page setup dialog: use your own native one if one exists. +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog) IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog) +#endif wxPrintDialog::wxPrintDialog() { @@ -64,15 +67,17 @@ wxPrintDialog::~wxPrintDialog() int wxPrintDialog::ShowModal() { int result = wxID_CANCEL ; + #if !TARGET_CARBON + OSErr err ; wxString message ; - ::PrOpen() ; + ::UMAPrOpen() ; err = PrError() ; if ( !err ) { m_printDialogData.ConvertToNative() ; - if ( m_printDialogData.m_macPrintInfo && ::PrJobDialog( m_printDialogData.m_macPrintInfo ) ) + if ( ::PrJobDialog( m_printDialogData.GetPrintData().m_macPrintInfo ) ) { m_printDialogData.ConvertFromNative() ; result = wxID_OK ; @@ -84,8 +89,10 @@ int wxPrintDialog::ShowModal() message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; } - ::PrClose() ; - + ::UMAPrClose() ; + #else + #pragma warning "TODO:Printing for carbon" + #endif return result ; } @@ -127,15 +134,17 @@ wxPageSetupDialog::~wxPageSetupDialog() int wxPageSetupDialog::ShowModal() { int result = wxID_CANCEL ; +#if !TARGET_CARBON + OSErr err ; wxString message ; - ::PrOpen() ; + ::UMAPrOpen() ; err = PrError() ; if ( !err ) { m_pageSetupData.ConvertToNative() ; - if ( m_pageSetupData.m_macPageSetupInfo && ::PrStlDialog( m_pageSetupData.m_macPageSetupInfo ) ) + if ( ::PrStlDialog( m_pageSetupData.GetPrintData().m_macPrintInfo ) ) { m_pageSetupData.ConvertFromNative() ; result = wxID_OK ; @@ -147,8 +156,10 @@ int wxPageSetupDialog::ShowModal() message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; } - ::PrClose() ; - + ::UMAPrClose() ; +#else +#pragma warning "TODO:printing for carbon" +#endif return result ; } diff --git a/src/mac/carbon/printmac.cpp b/src/mac/carbon/printmac.cpp index 0d4862cfa2..08a6bf77ad 100644 --- a/src/mac/carbon/printmac.cpp +++ b/src/mac/carbon/printmac.cpp @@ -35,8 +35,10 @@ #include +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase) IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase) +#endif /* * Printer @@ -92,31 +94,16 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) else m_printDialogData.EnablePageNumbers(FALSE); - // Create a suitable device context // Create a suitable device context wxDC *dc = NULL; if (prompt) { - PrOpen() ; - m_printDialogData.ConvertToNative() ; // make sure we have a valid handle - if ( m_printDialogData.m_macPrintInfo ) - { - // todo incorporate the changes from a global page setup - if ( ::PrStlDialog( m_printDialogData.m_macPrintInfo ) ) // we should have the page setup dialog - { - PrClose() ; - wxPrintDialog dialog(parent, & m_printDialogData); - if (dialog.ShowModal() == wxID_OK) - { - dc = dialog.GetPrintDC(); - m_printDialogData = dialog.GetPrintData(); - } - } - else - { - PrClose() ; - } - } + wxPrintDialog dialog(parent, & m_printDialogData); + if (dialog.ShowModal() == wxID_OK) + { + dc = dialog.GetPrintDC(); + m_printDialogData = dialog.GetPrintData(); + } } else { @@ -140,7 +127,7 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) printout->SetDC(dc); int w, h; - long ww, hh; + wxCoord ww, hh; dc->GetSize(&w, &h); printout->SetPageSizePixels((int)w, (int)h); dc->GetSizeMM(&ww, &hh); @@ -278,50 +265,35 @@ bool wxMacPrintPreview::Print(bool interactive) void wxMacPrintPreview::DetermineScaling(void) { -/* - HDC dc = ::GetDC(NULL); - int screenWidth = ::GetDeviceCaps(dc, HORZSIZE); -// int screenHeight = ::GetDeviceCaps(dc, VERTSIZE); - int screenXRes = ::GetDeviceCaps(dc, HORZRES); -// int screenYRes = ::GetDeviceCaps(dc, VERTRES); - int logPPIScreenX = ::GetDeviceCaps(dc, LOGPIXELSX); - int logPPIScreenY = ::GetDeviceCaps(dc, LOGPIXELSY); - m_previewPrintout->SetPPIScreen(logPPIScreenX, logPPIScreenY); - - ::ReleaseDC(NULL, dc); + int screenWidth , screenHeight ; + wxDisplaySize( &screenWidth , &screenHeight ) ; + + m_previewPrintout->SetPPIScreen( 72 , 72 ) ; + m_previewPrintout->SetPPIPrinter( 72 , 72 ) ; + m_previewPrintout->SetPageSizeMM( 8 * 25.6 , 11 * 25.6 ) ; + m_previewPrintout->SetPageSizePixels( 8 * 72 , 11 * 72 ) ; + m_pageWidth = 8 * 72 ; + m_pageHeight = 11 * 72 ; + m_previewScale = 1 ; // Get a device context for the currently selected printer - wxPrinterDC printerDC("", "", "", FALSE, m_printDialogData.GetOrientation()); - - int printerWidth = 150; - int printerHeight = 250; - int printerXRes = 1500; - int printerYRes = 2500; - - if (printerDC.GetHDC()) + wxPrinterDC printerDC(m_printDialogData.GetPrintData()); + if (printerDC.Ok()) { - printerWidth = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZSIZE); - printerHeight = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTSIZE); - printerXRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZRES); - printerYRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTRES); - - int logPPIPrinterX = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSX); - int logPPIPrinterY = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSY); - - m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); - m_previewPrintout->SetPageSizeMM(printerWidth, printerHeight); - - if (logPPIPrinterX == 0 || logPPIPrinterY == 0 || printerWidth == 0 || printerHeight == 0) - m_isOk = FALSE; - } - else - m_isOk = FALSE; - - m_pageWidth = printerXRes; - m_pageHeight = printerYRes; - + int x , y ; + wxCoord ww, hh; + printerDC.GetSizeMM(&ww, &hh); + printerDC.GetSize( &x , &y ) ; + m_previewPrintout->SetPageSizeMM((int)ww, (int)hh); + m_previewPrintout->SetPageSizePixels( x , y) ; + m_pageWidth = x ; + m_pageHeight = y ; + m_isOk = true ; + + } // At 100%, the page should look about page-size on the screen. - m_previewScale = (float)((float)screenWidth/(float)printerWidth); - m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerYRes); -*/ + // m_previewScale = (float)((float)screenWidth/(float)printerWidth); + // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes); + + m_previewScale = 1 ; } diff --git a/src/mac/carbon/radiobox.cpp b/src/mac/carbon/radiobox.cpp index 416ba0b18f..1f74fae6d2 100644 --- a/src/mac/carbon/radiobox.cpp +++ b/src/mac/carbon/radiobox.cpp @@ -20,7 +20,9 @@ #include "wx/radiobox.h" #include +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) +#endif #pragma mark - #pragma mark ### Constructors & destructor ### @@ -93,7 +95,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, Rect bounds ; Str255 title ; - MacPreControlCreate( parent , id , label , pos , size ,style, *((wxValidator*)NULL) , name , &bounds , title ) ; + MacPreControlCreate( parent , id , label , pos , size ,style, val , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1, kControlGroupBoxTextTitleProc , (long) this ) ; @@ -435,9 +437,9 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) x_offset = x; y_offset = y; GetPosition(&x_current, &y_current); - if ((x == -1) || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if ((x == -1) && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) x_offset = x_current; - if ((y == -1) || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if ((y == -1)&& !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) y_offset = y_current; // define size @@ -490,7 +492,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) x_start = charWidth; - y_start = charHeight*3/2; + y_start = 15 ; x_offset = x_start; y_offset = y_start; @@ -507,7 +509,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) else { x_offset = x_start; - y_offset += maxHeight + charHeight/2; + y_offset += maxHeight ; /*+ charHeight/2;*/ } } @@ -515,7 +517,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) current=current->NextInCycle(); if (m_windowStyle & wxRA_SPECIFY_ROWS) - y_offset += maxHeight + charHeight/2; + y_offset += maxHeight ; /*+ charHeight/2;*/ else x_offset += maxWidth + charWidth; } diff --git a/src/mac/carbon/radiobut.cpp b/src/mac/carbon/radiobut.cpp index f5f95dfab2..9a93378c0c 100644 --- a/src/mac/carbon/radiobut.cpp +++ b/src/mac/carbon/radiobut.cpp @@ -15,7 +15,9 @@ #include "wx/radiobut.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) +#endif #include @@ -48,7 +50,8 @@ void wxRadioButton::SetValue(bool val) ::SetControlValue( m_macControl , val ) ; - if (val) { + if (val) + { cycle=this->NextInCycle(); if (cycle!=NULL) { while (cycle!=this) { @@ -94,4 +97,3 @@ wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle) return(cycle); } } - diff --git a/src/mac/carbon/region.cpp b/src/mac/carbon/region.cpp index 5c01ddd438..afe12ce603 100644 --- a/src/mac/carbon/region.cpp +++ b/src/mac/carbon/region.cpp @@ -14,9 +14,12 @@ #include "wx/region.h" #include "wx/gdicmn.h" +#include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject) +#endif //----------------------------------------------------------------------------- // wxRegionRefData implementation @@ -195,7 +198,8 @@ void wxRegion::GetBox(long& x, long& y, long&w, long &h) const { if (m_refData) { - Rect box = (**M_REGION).rgnBBox ; + Rect box ; + GetRegionBounds( M_REGION , &box ) ; x = box.left ; y = box.top ; w = box.right - box.left ; @@ -329,7 +333,8 @@ void wxRegionIterator::Reset(const wxRegion& region) { // we cannot dissolve it into rects on mac m_rects = new wxRect[1]; - Rect rect = (**OTHER_M_REGION( region )).rgnBBox ; + Rect rect ; + GetRegionBounds( OTHER_M_REGION( region ) , &rect ) ; m_rects[0].x = rect.left; m_rects[0].y = rect.top; m_rects[0].width = rect.right - rect.left; diff --git a/src/mac/carbon/scrolbar.cpp b/src/mac/carbon/scrolbar.cpp index 2db4a175bb..92d6dd1faf 100644 --- a/src/mac/carbon/scrolbar.cpp +++ b/src/mac/carbon/scrolbar.cpp @@ -16,11 +16,13 @@ #include "wx/scrolbar.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) BEGIN_EVENT_TABLE(wxScrollBar, wxControl) END_EVENT_TABLE() +#endif extern ControlActionUPP wxMacLiveScrollbarActionUPP ; diff --git a/src/mac/carbon/settings.cpp b/src/mac/carbon/settings.cpp index 2d72222ab8..b13b5733cc 100644 --- a/src/mac/carbon/settings.cpp +++ b/src/mac/carbon/settings.cpp @@ -74,7 +74,6 @@ wxColour wxSystemSettings::GetSystemColour(int index) break ; case wxSYS_COLOUR_INFOBK : case wxSYS_COLOUR_APPWORKSPACE: - case wxSYS_COLOUR_LISTBOX: return *wxWHITE ; break ; } diff --git a/src/mac/carbon/slider.cpp b/src/mac/carbon/slider.cpp index 9218d560bb..936ccddb47 100644 --- a/src/mac/carbon/slider.cpp +++ b/src/mac/carbon/slider.cpp @@ -16,10 +16,12 @@ #include "wx/slider.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) BEGIN_EVENT_TABLE(wxSlider, wxControl) END_EVENT_TABLE() +#endif diff --git a/src/mac/carbon/spinbutt.cpp b/src/mac/carbon/spinbutt.cpp index 944f72dc10..f5ac7bc9bb 100644 --- a/src/mac/carbon/spinbutt.cpp +++ b/src/mac/carbon/spinbutt.cpp @@ -24,8 +24,10 @@ // wxWin macros // ---------------------------------------------------------------------------- +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent); +#endif bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) diff --git a/src/mac/carbon/statbmp.cpp b/src/mac/carbon/statbmp.cpp index ce1e5d1ec8..fa75e68fd5 100644 --- a/src/mac/carbon/statbmp.cpp +++ b/src/mac/carbon/statbmp.cpp @@ -15,7 +15,9 @@ #include "wx/statbmp.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl) +#endif /* * wxStaticBitmap @@ -28,11 +30,12 @@ END_EVENT_TABLE() bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, - const wxSize& size, + const wxSize& s, long style, const wxString& name) { SetName(name); + wxSize size = s ; m_backgroundColour = parent->GetBackgroundColour() ; m_foregroundColour = parent->GetForegroundColour() ; @@ -47,9 +50,8 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, m_windowStyle = style; bool ret = wxControl::Create( parent, id, pos, size, style , wxDefaultValidator , name ); + SetSizeOrDefault( size ) ; - SetSizeOrDefault() ; - return ret; } diff --git a/src/mac/carbon/statbox.cpp b/src/mac/carbon/statbox.cpp index ea7ca9dfbb..e0d8257d0f 100644 --- a/src/mac/carbon/statbox.cpp +++ b/src/mac/carbon/statbox.cpp @@ -16,12 +16,14 @@ #include "wx/statbox.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl) BEGIN_EVENT_TABLE(wxStaticBox, wxControl) EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground) END_EVENT_TABLE() +#endif /* * Static box @@ -37,7 +39,7 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, Rect bounds ; Str255 title ; - MacPreControlCreate( parent , id , label , pos , size ,style, *((wxValidator*)NULL) , name , &bounds , title ) ; + MacPreControlCreate( parent , id , label , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1, kControlGroupBoxTextTitleProc , (long) this ) ; diff --git a/src/mac/carbon/stattext.cpp b/src/mac/carbon/stattext.cpp index b249fc0e11..22653f651e 100644 --- a/src/mac/carbon/stattext.cpp +++ b/src/mac/carbon/stattext.cpp @@ -18,7 +18,9 @@ #include +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) +#endif #include @@ -51,69 +53,208 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, return ret; } -void wxStaticText::OnPaint( wxPaintEvent &event ) +void wxStaticText::OnDraw( wxDC &dc ) { - wxPaintDC dc(this); PrepareDC(dc); dc.Clear() ; - dc.DrawText( m_label , 0 , 0 ) ; -} + + int x = 0 ; + int y = 0 ; + wxString text = m_label ; + wxString paragraph ; + int i = 0 ; + int laststop = 0 ; + long width, height ; -wxSize wxStaticText::DoGetBestSize() const -{ - int x , y ; - GetTextExtent( m_label , &x , &y ) ; - return wxSize( x , y ) ; + while( i < text.Length() ) + { + if( text[i] == 13 || text[i] == 10) + { + paragraph = text.Mid( laststop , i - laststop ) ; + while( paragraph.Length() > 0 ) + { + dc.GetTextExtent( paragraph , &width , &height ) ; + if ( width > m_width ) + { + for ( int p = paragraph.Length() -1 ; p > 0 ; --p ) + { + if ( paragraph[p]=='.' ) + { + dc.GetTextExtent( paragraph.Left(p+1) , &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+1), pos , y) ; + y += height ; + paragraph = paragraph.Mid(p+1) ; + break ; + } + } + if ( paragraph[p]==' ' ) + { + dc.GetTextExtent( paragraph.Left(p) , &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), pos , y) ; + y += height ; + paragraph = paragraph.Mid(p+1) ; + break ; + } + } + } + } + else + { + dc.DrawText( paragraph, x , y) ; + paragraph=""; + y += height ; + } + } + laststop = i+1 ; + } + ++i ; + } + paragraph = text.Mid( laststop , text.Length() - laststop ) ; + while( paragraph.Length() > 0 ) + { + dc.GetTextExtent( paragraph , &width , &height ) ; + if ( width > m_width ) + { + for ( int p = paragraph.Length() -1 ; p > 0 ; --p ) + { + if ( paragraph[p]=='.' ) + { + dc.GetTextExtent( paragraph.Left(p+1) , &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+1), pos , y) ; + y += height ; + paragraph = paragraph.Mid(p+1) ; + break ; + } + } + if ( paragraph[p]==' ' ) + { + dc.GetTextExtent( paragraph.Left(p) , &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), pos , y) ; + y += height ; + paragraph = paragraph.Mid(p+1) ; + break ; + } + } + } + } + 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=""; + y += height ; + } + } } -void wxStaticText::SetLabel(const wxString& st , bool resize ) -{ - SetTitle( st ) ; - m_label = st ; - if ( resize ) - SetSizeOrDefault() ; - else - Refresh() ; -} -/* -void wxStaticText::SetSize(int x, int y, int width, int height, int sizeFlags) +void wxStaticText::OnPaint( wxPaintEvent &event ) { - wxControl::SetSize( x , y , width , height , sizeFlags ) ; + wxPaintDC dc(this); + OnDraw( dc ) ; } -bool wxStaticText::Create(wxWindow *parent, wxWindowID id, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) +wxSize wxStaticText::DoGetBestSize() const { - Rect bounds ; - Str255 title ; - - MacPreControlCreate( parent , id , label , pos , size ,style, *((wxValidator*)NULL) , name , &bounds , title ) ; + int x , y ; + int widthTextMax = 0, widthLine, + heightTextTotal = 0, heightLineDefault = 0, heightLine = 0; - m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, - kControlStaticTextProc , (long) this ) ; - ::UMASetControlData( m_macControl, kControlLabelPart, kControlStaticTextTextTag , (long) title[0] , (char*) &title[1] ) ; - - MacPostControlCreate() ; + wxString curLine; + for ( const wxChar *pc = m_label; ; pc++ ) { + if ( *pc == wxT('\n') || *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; + } + else { + GetTextExtent(curLine, &widthLine, &heightLine); + if ( widthLine > widthTextMax ) + widthTextMax = widthLine; + heightTextTotal += heightLine; + } + + if ( *pc == wxT('\n') ) { + curLine.Empty(); + } + else { + // the end of string + break; + } + } + else { + curLine += *pc; + } + } - return TRUE; + return wxSize(widthTextMax, heightTextTotal); } -void wxStaticText::SetLabel(const wxString& st , bool resize ) +void wxStaticText::SetLabel(const wxString& st ) { SetTitle( st ) ; - wxString label ; + m_label = st ; + if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) + SetSizeOrDefault() ; - if( wxApp::s_macDefaultEncodingIsPC ) - label = wxMacMakeMacStringFromPC( st ) ; - else - label = st ; - - ::UMASetControlData( m_macControl, kControlLabelPart, kControlStaticTextTextTag , (long) label.Length() , (char*)(const char*) label ) ; - Refresh() ; + wxClientDC dc(this); + OnDraw( dc ) ; } -*/ - diff --git a/src/mac/carbon/tabctrl.cpp b/src/mac/carbon/tabctrl.cpp index ed13c3ac8a..5482141268 100644 --- a/src/mac/carbon/tabctrl.cpp +++ b/src/mac/carbon/tabctrl.cpp @@ -17,10 +17,12 @@ #include "wx/tabctrl.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxTabCtrl, wxControl) BEGIN_EVENT_TABLE(wxTabCtrl, wxControl) END_EVENT_TABLE() +#endif wxTabCtrl::wxTabCtrl() { @@ -35,7 +37,7 @@ bool wxTabCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons m_imageList = NULL; - MacPreControlCreate( parent , id , "" , pos , size ,style, *((wxValidator*)NULL) , name , &bounds , title ) ; + MacPreControlCreate( parent , id , "" , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1, kControlTabSmallProc , (long) this ) ; diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index c1b98861b0..af3919bb7b 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -38,22 +38,34 @@ #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) EVT_DROP_FILES(wxTextCtrl::OnDropFiles) EVT_CHAR(wxTextCtrl::OnChar) + EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) + EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) + EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) + EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) + EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) + + EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) + EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) + EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) + EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) + EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) END_EVENT_TABLE() +#endif // Text item wxTextCtrl::wxTextCtrl() -#ifndef NO_TEXT_WINDOW_STREAM - :streambuf() -#endif { - m_fileName = ""; } +const short kVerticalMargin = 2 ; +const short kHorizontalMargin = 2 ; + bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& st, const wxPoint& pos, @@ -61,25 +73,40 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - m_macHorizontalBorder = 2 ; // additional pixels around the real control - m_macVerticalBorder = 2 ; + // base initialization + if ( !CreateBase(parent, id, pos, size, style, validator, name) ) + return FALSE; wxSize mySize = size ; + if ( UMAHasAppearance() ) + { + m_macHorizontalBorder = 5 ; // additional pixels around the real control + m_macVerticalBorder = 5 ; + } + else + { + m_macHorizontalBorder = 0 ; // additional pixels around the real control + m_macVerticalBorder = 0 ; + } + Rect bounds ; Str255 title ; - + if ( mySize.y == -1 ) { if ( UMAHasAppearance() ) - mySize.y = 16 ; + mySize.y = 13 ; else mySize.y = 24 ; + + mySize.y += 2 * m_macVerticalBorder ; } + MacPreControlCreate( parent , id , "" , pos , mySize ,style, validator , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, - kControlEditTextProc , (long) this ) ; + ( style & wxTE_PASSWORD ) ? kControlEditTextPasswordProc : kControlEditTextProc , (long) this ) ; MacPostControlCreate() ; wxString value ; @@ -88,7 +115,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, value = wxMacMakeMacStringFromPC( st ) ; else value = st ; - UMASetControlData( m_macControl, 0, kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ; + UMASetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ; return TRUE; } @@ -96,7 +123,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, wxString wxTextCtrl::GetValue() const { Size actualsize; - UMAGetControlData( m_macControl, 0, kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ; + UMAGetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ; wxBuffer[actualsize] = 0 ; if( wxApp::s_macDefaultEncodingIsPC ) return wxMacMakePCStringFromMac( wxBuffer ) ; @@ -104,6 +131,18 @@ wxString wxTextCtrl::GetValue() const return wxString(wxBuffer); } +void wxTextCtrl::GetSelection(long* from, long* to) const +{ + ControlEditTextSelectionRec selection ; + TEHandle teH ; + long size ; + + UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; + + *from = (**teH).selStart; + *to = (**teH).selEnd; +} + void wxTextCtrl::SetValue(const wxString& st) { wxString value ; @@ -112,44 +151,116 @@ void wxTextCtrl::SetValue(const wxString& st) value = wxMacMakeMacStringFromPC( st ) ; else value = st ; - UMASetControlData( m_macControl, 0, kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ; + UMASetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ; Refresh() ; // MacInvalidateControl() ; } -void wxTextCtrl::SetSize(int x, int y, int width, int height, int sizeFlags) -{ - wxControl::SetSize( x , y , width , height , sizeFlags ) ; -} - // Clipboard operations void wxTextCtrl::Copy() { - TEHandle teH ; - long size ; + if (CanCopy()) + { + TEHandle teH ; + long size ; - UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; - TECopy( teH ) ; + UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; + TECopy( teH ) ; +#if TARGET_CARBON + OSStatus err ; + err = ClearCurrentScrap( ); +#else + OSErr err ; + err = ZeroScrap( ); +#endif + TEToScrap() ; + } } void wxTextCtrl::Cut() { - TEHandle teH ; - long size ; + if (CanCut()) + { + TEHandle teH ; + long size ; - UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; - TECut( teH ) ; -// MacInvalidateControl() ; + UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; + TECut( teH ) ; +#if TARGET_CARBON + OSStatus err ; + err = ClearCurrentScrap( ); +#else + OSErr err ; + err = ZeroScrap( ); +#endif + TEToScrap() ; + // MacInvalidateControl() ; + } } void wxTextCtrl::Paste() { - TEHandle teH ; - long size ; + if (CanPaste()) + { + TEHandle teH ; + long size ; - UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; - TEPaste( teH ) ; + UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; + TEFromScrap() ; + TEPaste( teH ) ; // MacInvalidateControl() ; + } +} + +bool wxTextCtrl::CanCopy() const +{ + // Can copy if there's a selection + long from, to; + GetSelection(& from, & to); + return (from != to); +} + +bool wxTextCtrl::CanCut() const +{ + // Can cut if there's a selection + long from, to; + GetSelection(& from, & to); + return (from != to); +} + +bool wxTextCtrl::CanPaste() const +{ + if (!IsEditable()) + return FALSE; + + long offset ; +#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 + if ( GetScrap( NULL , 'TEXT' , &offset ) > 0 ) + { + return TRUE ; + } +#endif + return FALSE ; } void wxTextCtrl::SetEditable(bool editable) @@ -243,65 +354,10 @@ void wxTextCtrl::SetSelection(long from, long to) bool wxTextCtrl::LoadFile(const wxString& file) { - if (!wxFileExists(file)) - return FALSE; - - m_fileName = file; - - Clear(); - -#ifndef __WXMAC__ - ifstream input((char*) (const char*) file, ios::nocreate | ios::in); -#else - ifstream input((char*) (const char*) file, ios::in); -#endif - if (!input.bad()) + if ( wxTextCtrlBase::LoadFile(file) ) { - struct stat stat_buf; - if (stat(file, &stat_buf) < 0) - return FALSE; - // This may need to be a bigger buffer than the file size suggests, - // if it's a UNIX file. Give it an extra 1000 just in case. - char *tmp_buffer = (char*)malloc((size_t)(stat_buf.st_size+1+1000)); - long no_lines = 0; - long pos = 0; - while (!input.eof() && input.peek() != EOF) - { - input.getline(wxBuffer, 500); - int len = strlen(wxBuffer); - wxBuffer[len] = 13; - wxBuffer[len+1] = 10; - wxBuffer[len+2] = 0; - strcpy(tmp_buffer+pos, wxBuffer); - pos += strlen(wxBuffer); - no_lines++; - } - - // TODO add line - - free(tmp_buffer); - - return TRUE; + return TRUE; } - return FALSE; -} - -// If file is null, try saved file name first -// Returns TRUE if succeeds. -bool wxTextCtrl::SaveFile(const wxString& file) -{ - wxString theFile(file); - if (theFile == "") - theFile = m_fileName; - if (theFile == "") - return FALSE; - m_fileName = theFile; - - ofstream output((char*) (const char*) theFile); - if (output.bad()) - return FALSE; - - // TODO get and save text return FALSE; } @@ -329,18 +385,8 @@ void wxTextCtrl::AppendText(const wxString& text) void wxTextCtrl::Clear() { - TEHandle teH ; - long size ; - ControlEditTextSelectionRec selection ; - - selection.selStart = 0 ; - selection.selEnd = 32767 ; - - UMASetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ; - - UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; - TECut( teH ) ; -// MacInvalidateControl() ; + UMASetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ; + Refresh() ; } bool wxTextCtrl::IsModified() const @@ -348,6 +394,73 @@ bool wxTextCtrl::IsModified() const return TRUE; } +bool wxTextCtrl::IsEditable() const +{ + return IsEnabled(); +} + +bool wxTextCtrl::AcceptsFocus() const +{ + // we don't want focus if we can't be edited + return IsEditable() && wxControl::AcceptsFocus(); +} + +wxSize wxTextCtrl::DoGetBestSize() const +{ + int wText = 100 ; + + int hText ; + if ( UMAHasAppearance() ) + hText = 13 ; + else + hText = 24 ; + hText += 2 * m_macHorizontalBorder ; +/* + 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 *= wxMin(GetNumberOfLines(), 5); + } + //else: for single line control everything is ok + return wxSize(wText, hText); +} + +// ---------------------------------------------------------------------------- +// Undo/redo +// ---------------------------------------------------------------------------- + +void wxTextCtrl::Undo() +{ + if (CanUndo()) + { + } +} + +void wxTextCtrl::Redo() +{ + if (CanRedo()) + { + } +} + +bool wxTextCtrl::CanUndo() const +{ + return FALSE ; +} + +bool wxTextCtrl::CanRedo() const +{ + return FALSE ; +} + // Makes 'unmodified' void wxTextCtrl::DiscardEdits() { @@ -366,9 +479,9 @@ long wxTextCtrl::XYToPosition(long x, long y) const return 0; } -void wxTextCtrl::PositionToXY(long pos, long *x, long *y) const +bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const { - // TODO + return FALSE ; } void wxTextCtrl::ShowPosition(long pos) @@ -407,204 +520,125 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) void wxTextCtrl::OnChar(wxKeyEvent& event) { - switch( event.KeyCode() ) + switch ( event.KeyCode() ) { case WXK_RETURN: - { - if ( !(m_windowStyle & wxTE_MULTILINE) ) - { + if (m_windowStyle & wxPROCESS_ENTER) + { wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); event.SetEventObject( this ); if ( GetEventHandler()->ProcessEvent(event) ) return; + } + if ( !(m_windowStyle & wxTE_MULTILINE) ) + { + wxWindow *parent = GetParent(); + wxPanel *panel = wxDynamicCast(parent, wxPanel); + while ( parent != NULL && panel == NULL ) + { + parent = parent->GetParent() ; + panel = wxDynamicCast(parent, wxPanel); + } + if ( panel && panel->GetDefaultItem() ) + { + wxButton *def = panel->GetDefaultItem() ; + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); + event.SetEventObject(def); + def->Command(event); + event.Skip() ; + return ; + } } //else: multiline controls need Enter for themselves break; - } + case WXK_TAB: // always produce navigation event - even if we process TAB // ourselves the fact that we got here means that the user code // decided to skip processing of this TAB - probably to let it // do its default job. - // - // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is - // handled by Windows { wxNavigationKeyEvent eventNav; eventNav.SetDirection(!event.ShiftDown()); - eventNav.SetWindowChange(FALSE); + eventNav.SetWindowChange(event.ControlDown()); eventNav.SetEventObject(this); - if ( GetEventHandler()->ProcessEvent(eventNav) ) + if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) return; + event.Skip() ; + return ; } break; - - default: - event.Skip(); - return; } - // don't just call event.Skip() because this will cause TABs and ENTERs - // be passed upwards and we don't always want this - instead process it - // right here - - // FIXME - event.Skip(); -} -// The streambuf code was partly taken from chapter 3 by Jerry Schwarz of -// AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers - -//========================================================================= -// Called then the buffer is full (gcc 2.6.3) -// or when "endl" is output (Borland 4.5) -//========================================================================= -// Class declaration using multiple inheritance doesn't work properly for -// Borland. See note in wb_text.h. -#ifndef NO_TEXT_WINDOW_STREAM -int wxTextCtrl::overflow(int c) -{ - // Make sure there is a holding area - if ( allocate()==EOF ) - { - wxError("Streambuf allocation failed","Internal error"); - return EOF; - } - - // Verify that there are no characters in get area - if ( gptr() && gptr() < egptr() ) - { - wxError("Who's trespassing my get area?","Internal error"); - return EOF; - } - - // Reset get area - setg(0,0,0); - - // Make sure there is a put area - if ( ! pptr() ) - { -/* This doesn't seem to be fatal so comment out error message */ -// wxError("Put area not opened","Internal error"); - setp( base(), base() ); - } - - // Determine how many characters have been inserted but no consumed - int plen = pptr() - pbase(); - - // Now Jerry relies on the fact that the buffer is at least 2 chars - // long, but the holding area "may be as small as 1" ??? - // And we need an additional \0, so let's keep this inefficient but - // safe copy. - - // If c!=EOF, it is a character that must also be comsumed - int xtra = c==EOF? 0 : 1; - - // Write temporary C-string to wxTextWindow - { - char *txt = new char[plen+xtra+1]; - memcpy(txt, pbase(), plen); - txt[plen] = (char)c; // append c - txt[plen+xtra] = '\0'; // append '\0' or overwrite c - // If the put area already contained \0, output will be truncated there - AppendText(txt); - delete[] txt; - } - - // Reset put area - setp(pbase(), epptr()); - -#if defined(__WATCOMC__) - return __NOT_EOF; -#elif defined(zapeof) // HP-UX (all cfront based?) - return zapeof(c); -#else - return c!=EOF ? c : 0; // this should make everybody happy -#endif + EventRecord *ev = wxTheApp->MacGetCurrentEvent() ; + short keycode ; + short keychar ; + keychar = short(ev->message & charCodeMask); + keycode = short(ev->message & keyCodeMask) >> 8 ; + UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ; + if ( keychar >= 0x20 || event.KeyCode() == WXK_RETURN) + { + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); + event.SetString( GetValue() ) ; + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); + } + } -//========================================================================= -// called then "endl" is output (gcc) or then explicit sync is done (Borland) -//========================================================================= -int wxTextCtrl::sync() -{ - // Verify that there are no characters in get area - if ( gptr() && gptr() < egptr() ) - { - wxError("Who's trespassing my get area?","Internal error"); - return EOF; - } - - if ( pptr() && pptr() > pbase() ) return overflow(EOF); - - return 0; -/* OLD CODE - int len = pptr() - pbase(); - char *txt = new char[len+1]; - strncpy(txt, pbase(), len); - txt[len] = '\0'; - (*this) << txt; - setp(pbase(), epptr()); - delete[] txt; - return 0; -*/ +// ---------------------------------------------------------------------------- +// standard handlers for standard edit menu events +// ---------------------------------------------------------------------------- + +void wxTextCtrl::OnCut(wxCommandEvent& event) +{ + Cut(); } -//========================================================================= -// Should not be called by a "ostream". Used by a "istream" -//========================================================================= -int wxTextCtrl::underflow() +void wxTextCtrl::OnCopy(wxCommandEvent& event) { - return EOF; + Copy(); } -#endif -wxTextCtrl& wxTextCtrl::operator<<(const wxString& s) +void wxTextCtrl::OnPaste(wxCommandEvent& event) { - AppendText(s); - return *this; + Paste(); } -wxTextCtrl& wxTextCtrl::operator<<(float f) +void wxTextCtrl::OnUndo(wxCommandEvent& event) { - wxString str; - str.Printf("%.2f", f); - AppendText(str); - return *this; + Undo(); } -wxTextCtrl& wxTextCtrl::operator<<(double d) +void wxTextCtrl::OnRedo(wxCommandEvent& event) { - wxString str; - str.Printf("%.2f", d); - AppendText(str); - return *this; + Redo(); } -wxTextCtrl& wxTextCtrl::operator<<(int i) +void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) { - wxString str; - str.Printf("%d", i); - AppendText(str); - return *this; + event.Enable( CanCut() ); } -wxTextCtrl& wxTextCtrl::operator<<(long i) +void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) { - wxString str; - str.Printf("%ld", i); - AppendText(str); - return *this; + event.Enable( CanCopy() ); } -wxTextCtrl& wxTextCtrl::operator<<(const char c) +void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) { - char buf[2]; + event.Enable( CanPaste() ); +} - buf[0] = c; - buf[1] = 0; - AppendText(buf); - return *this; +void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) +{ + event.Enable( CanUndo() ); +} + +void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) +{ + event.Enable( CanRedo() ); } diff --git a/src/mac/carbon/timer.cpp b/src/mac/carbon/timer.cpp index d845d50108..3d0bb31c08 100644 --- a/src/mac/carbon/timer.cpp +++ b/src/mac/carbon/timer.cpp @@ -15,13 +15,48 @@ #include "wx/timer.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject) +#endif + +static void wxProcessTimer( unsigned long event , void *data ) ; + +pascal void MacTimerProc( TMTask * t ) +{ + MacTimerInfo * tm = (MacTimerInfo*) t ; + wxMacAddEvent( tm->m_table , wxProcessTimer, 0 , (void*) tm->m_timer , TRUE ) ; +} + +void wxProcessTimer( unsigned long event , void *data ) +{ + if ( !data ) + return ; + + wxTimer* timer = (wxTimer*) data ; + if ( timer->IsOneShot() ) + timer->Stop() ; + + timer->Notify(); + + if ( timer->m_info.m_task.tmAddr && !timer->IsOneShot() ) + { + PrimeTime( (QElemPtr) &timer->m_info.m_task , timer->GetInterval() ) ; + } +} wxTimer::wxTimer() { - m_milli = 0 ; - m_id = 0; - m_oneShot = FALSE; + m_info.m_task.tmAddr = NULL ; + m_info.m_task.tmWakeUp = 0 ; + m_info.m_task.tmReserved = 0 ; + m_info.m_task.qType = 0 ; + m_info.m_table = wxMacGetNotifierTable() ; + m_info.m_timer = this ; +} + +bool wxTimer::IsRunning() const +{ + return ( m_info.m_task.qType & kTMTaskActive ) ; } wxTimer::~wxTimer() @@ -31,20 +66,31 @@ wxTimer::~wxTimer() bool wxTimer::Start(int milliseconds,bool mode) { - m_oneShot = mode ; - if (milliseconds <= 0) - return FALSE; + (void)wxTimerBase::Start(milliseconds, mode); - m_milli = milliseconds; + wxCHECK_MSG( m_milli > 0, FALSE, wxT("invalid value for timer timeour") ); + wxCHECK_MSG( m_info.m_task.tmAddr == NULL , FALSE, wxT("attempting to restart a timer") ); - // TODO: set the timer going. + m_milli = milliseconds; + m_info.m_task.tmAddr = NewTimerProc( MacTimerProc ) ; + m_info.m_task.tmWakeUp = 0 ; + m_info.m_task.tmReserved = 0 ; + InsXTime((QElemPtr) &m_info.m_task ) ; + PrimeTime( (QElemPtr) &m_info.m_task , m_milli ) ; return FALSE; } void wxTimer::Stop() { - m_id = 0 ; m_milli = 0 ; + if ( m_info.m_task.tmAddr ) + { + RmvTime( (QElemPtr) &m_info.m_task ) ; + DisposeTimerUPP(m_info.m_task.tmAddr) ; + m_info.m_task.tmAddr = NULL ; + } + wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ; } + diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index e4bd0aff79..e118add0ed 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -5,8 +5,7 @@ // Modified by: // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) AUTHOR -// Licence: wxWindows licence +// Copyright: (c) AUTHORy ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -18,11 +17,17 @@ #if wxUSE_TOOLBAR #include "wx/toolbar.h" +#include "wx/notebook.h" +#include "wx/tabctrl.h" -IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase) +#if !USE_SHARED_LIBRARY +IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) + EVT_MOUSE_EVENTS( wxToolBar::OnMouse ) + EVT_PAINT( wxToolBar::OnPaint ) END_EVENT_TABLE() +#endif #include @@ -45,14 +50,14 @@ public: clientData, shortHelpString, longHelpString) { m_nSepCount = 0; - m_index = 0 ; + m_index = -1 ; } wxToolBarTool(wxToolBar *tbar, wxControl *control) : wxToolBarToolBase(tbar, control) { m_nSepCount = 1; - m_index = 0 ; + m_index = -1 ; } // set/get the number of separators which we use to cover the space used by @@ -74,6 +79,9 @@ private: // wxToolBarTool // ---------------------------------------------------------------------------- +const short defwidth = 24 ; +const short defheight = 22 ; + wxToolBarToolBase *wxToolBar::CreateTool(int id, const wxBitmap& bitmap1, const wxBitmap& bitmap2, @@ -91,16 +99,12 @@ wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) return new wxToolBarTool(this, control); } -// ---------------------------------------------------------------------------- -// wxToolBar construction -// ---------------------------------------------------------------------------- - void wxToolBar::Init() { m_maxWidth = -1; m_maxHeight = -1; - m_defaultWidth = 24; - m_defaultHeight = 22; + m_defaultWidth = defwidth; + m_defaultHeight = defheight; // TODO } @@ -109,8 +113,8 @@ bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons { m_maxWidth = m_maxHeight = 0; - m_defaultWidth = 24; - m_defaultHeight = 22; + m_defaultWidth = defwidth; + m_defaultHeight = defheight; int x = pos.x; int y = pos.y; @@ -125,16 +129,39 @@ bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons x = 0; if (y < 0) y = 0; - +#if 1 + { + 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 ; + } +#else Rect bounds ; Str255 title ; - MacPreControlCreate( parent , id , "" , wxPoint( x , y ) , wxSize( width , height ) ,style, *((wxValidator*)NULL) , name , &bounds , title ) ; + MacPreControlCreate( parent , id , "" , wxPoint( x , y ) , wxSize( width , height ) ,style, wxDefaultValidator , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, kControlPlacardProc , (long) this ) ; MacPostControlCreate() ; - +#endif return TRUE; } @@ -143,7 +170,8 @@ wxToolBar::~wxToolBar() // TODO } -PicHandle MakePict(GWorldPtr wp) +PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ; +PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) { CGrafPtr origPort ; GDHandle origDev ; @@ -151,52 +179,77 @@ PicHandle MakePict(GWorldPtr wp) PicHandle pict; // this is the Picture we give back RGBColor gray = { 0xCCCC ,0xCCCC , 0xCCCC } ; + RGBColor white = { 0xffff ,0xffff , 0xffff } ; + RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ; - GetGWorld( &origPort , &origDev ) ; - SetGWorld( wp , NULL ) ; - - pict = OpenPicture(&wp->portRect); // open a picture, this disables drawing - if(!pict) - return NULL; - - RGBBackColor( &gray ) ; - EraseRect(&wp->portRect) ; - CopyBits((BitMap*)*wp->portPixMap, // src PixMap - we copy image over itself - - (BitMap*)*wp->portPixMap, // dst PixMap - no drawing occurs - - &wp->portRect, // srcRect - it will be recorded and compressed - - &wp->portRect, // dstRect - into the picture that is open - - srcCopy,NULL); // copyMode and no clip region - - ClosePicture(); // We are done recording the picture - SetGWorld( origPort , origDev ) ; - return pict; // return our groovy pict handle -} - -PicHandle MakePictWhite(GWorldPtr wp) -{ - CGrafPtr origPort ; - GDHandle origDev ; + unsigned char *maskimage = NULL ; + Rect portRect ; + GetPortBounds( wp , &portRect ) ; + int width = portRect.right - portRect.left ; + int height = portRect.bottom - portRect.top ; - PicHandle pict; // this is the Picture we give back + LockPixels( GetGWorldPixMap( wp ) ) ; + GetGWorld( &origPort , &origDev ) ; - RGBColor white = { 0xFFFF ,0xFFFF , 0xFFFF } ; + if ( mask ) + { + + maskimage = (unsigned char*) malloc( width * height ) ; + SetGWorld( mask , NULL ) ; + LockPixels( GetGWorldPixMap( mask ) ) ; + for ( int y = 0 ; y < height ; ++y ) + { + for( int x = 0 ; x < width ; ++x ) + { + RGBColor col ; + + GetCPixel( x + portRect.left , y + portRect.top , &col ) ; + maskimage[y*width + x] = ( col.red == 0 ) ; // for monochrome masks + } + } + UnlockPixels( GetGWorldPixMap( mask ) ) ; + } - GetGWorld( &origPort , &origDev ) ; SetGWorld( wp , NULL ) ; - pict = OpenPicture(&wp->portRect); // open a picture, this disables drawing + pict = OpenPicture(&portRect); // open a picture, this disables drawing if(!pict) return NULL; - + + RGBBackColor( &gray ) ; + RGBForeColor( &black ) ; + EraseRect(&portRect) ; RGBBackColor( &white ) ; - EraseRect(&wp->portRect) ; - CopyBits((BitMap*)*wp->portPixMap, // src PixMap - we copy image over itself - - (BitMap*)*wp->portPixMap, // dst PixMap - no drawing occurs - - &wp->portRect, // srcRect - it will be recorded and compressed - - &wp->portRect, // dstRect - into the picture that is open - + + if ( maskimage ) + { + for ( int y = 0 ; y < height ; ++y ) + { + for( int x = 0 ; x < width ; ++x ) + { + if ( maskimage[y*width + x] ) + { + RGBColor col ; + + GetCPixel( x + portRect.left , y + portRect.top , &col ) ; + SetCPixel( x + portRect.left , y + portRect.top , &col ) ; + } + } + } + free( maskimage ) ; + maskimage = NULL ; + } + else + { + CopyBits(GetPortBitMapForCopyBits(wp), // src PixMap - we copy image over itself - + GetPortBitMapForCopyBits(wp), // dst PixMap - no drawing occurs - + &portRect, // srcRect - it will be recorded and compressed - + &portRect, // dstRect - into the picture that is open - srcCopy,NULL); // copyMode and no clip region + } ClosePicture(); // We are done recording the picture + UnlockPixels( GetGWorldPixMap( wp ) ) ; SetGWorld( origPort , origDev ) ; return pict; // return our groovy pict handle } @@ -226,7 +279,7 @@ bool wxToolBar::Realize() wxToolBarTool *tool = (wxToolBarTool *)node->Data(); wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->GetBitmap1().GetRefData()) ; - if( !tool->IsSeparator() ) + if( !tool->IsSeparator() ) { Rect toolrect = { toolbarrect.top + kwxMacToolBarTopMargin , toolbarrect.left + x + kwxMacToolBarLeftMargin , 0 , 0 } ; toolrect.right = toolrect.left + toolSize.x ; @@ -239,12 +292,19 @@ bool wxToolBar::Realize() icon = bmap->m_hPict ; else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) { - icon = MakePict( bmap->m_hBitmap ) ; + if ( tool->GetBitmap1().GetMask() ) + { + icon = MakePict( bmap->m_hBitmap , tool->GetBitmap1().GetMask()->GetMaskBitmap() ) ; + } + else + { + icon = MakePict( bmap->m_hBitmap , NULL ) ; + } } } ControlHandle m_macToolHandle ; - + SInt16 behaviour = kControlBehaviorOffsetContents ; if ( tool->CanBeToggled() ) behaviour += kControlBehaviorToggles ; @@ -266,8 +326,19 @@ bool wxToolBar::Realize() behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; } m_macToolHandles.Add( m_macToolHandle ) ; + tool->m_index = m_macToolHandles.Count() -1 ; + if ( !tool->IsEnabled() ) + { + UMADeactivateControl( m_macToolHandle ) ; + } + if ( tool->CanBeToggled() && tool->IsToggled() ) + { + ::SetControlValue( m_macToolHandle , 1 ) ; + } UMASetControlFontStyle( m_macToolHandle , &controlstyle ) ; - UMAEmbedControl( m_macToolHandle , m_macControl ) ; + ControlHandle container = GetParent()->MacGetContainerForEmbedding() ; + wxASSERT_MSG( container != NULL , "No valid mac container control" ) ; + UMAEmbedControl( m_macToolHandle , container ) ; x += (int)toolSize.x; noButtons ++; @@ -311,7 +382,7 @@ void wxToolBar::SetToolBitmapSize(const wxSize& size) // The button size is bigger than the bitmap size wxSize wxToolBar::GetToolSize() const { - return wxSize(m_defaultWidth + 8, m_defaultHeight + 7); + return wxSize(m_defaultWidth + 4, m_defaultHeight + 4); } void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) @@ -321,7 +392,13 @@ void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpar { if ( m_macToolHandles[index] == (void*) control ) { - OnLeftClick( ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->m_index , ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->IsToggled() ) ; + wxToolBarTool *tool = (wxToolBarTool *)m_tools.Nth( index )->Data(); + if ( tool->CanBeToggled() ) + { + tool->Toggle( GetControlValue( control ) ) ; + } + OnLeftClick( tool->GetId() , tool -> IsToggled() ) ; + break ; } } } @@ -340,43 +417,54 @@ void wxToolBar::SetRows(int nRows) wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const { MacClientToRootWindow( &x , &y ) ; - Point pt = { x ,y } ; + Point pt = { y ,x } ; int index = 0 ; for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) { - if ( PtInRect( pt , &(**(ControlHandle)(m_macToolHandles[index])).contrlRect) ) + if ( m_macToolHandles[index] ) { - return (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ; + Rect bounds ; + GetControlBounds((ControlHandle) m_macToolHandles[index], &bounds ) ; + if ( PtInRect( pt , &bounds ) ) + { + return (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ; + } } } return (wxToolBarToolBase *)NULL; } +wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) +{ + wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ; + if ( tool ) + { + return tool->GetShortHelp() ; + } + return "" ; +} + void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) { wxToolBarTool *tool = (wxToolBarTool *)t; + if ( tool->m_index < 0 ) + return ; + ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ; - if ( UMAHasAppearance() ) - { - if ( enable ) - ::ActivateControl( control ) ; - else - ::DeactivateControl( control ) ; - } + + if ( enable ) + UMAActivateControl( control ) ; else - { - if ( enable ) - ::HiliteControl( control , 0 ) ; - else - ::HiliteControl( control , 255 ) ; - } + UMADeactivateControl( control ) ; } void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) { wxToolBarTool *tool = (wxToolBarTool *)t; + if ( tool->m_index < 0 ) + return ; ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ; ::SetControlValue( control , toggle ) ; @@ -402,5 +490,116 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) { return TRUE ; } + +void wxToolBar::OnPaint(wxPaintEvent& event) +{ + WindowRef window = GetMacRootWindow() ; + if ( window ) + { + wxWindow* win = wxFindWinFromMacWindow( window ) ; + if ( win ) + { + wxMacDrawingHelper help( win ) ; + // the mac control manager always assumes to have the origin at 0,0 + SetOrigin( 0 , 0 ) ; + + bool hasTabBehind = false ; + wxWindow* parent = GetParent() ; + while ( parent ) + { + if( parent->MacGetWindowData() ) + { + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; + break ; + } + + if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) + { + if ( ((wxControl*)parent)->GetMacControl() ) + SetUpControlBackground( ((wxControl*)parent)->GetMacControl() , -1 , true ) ; + break ; + } + + parent = parent->GetParent() ; + } + Rect toolbarrect = { m_y , m_x , m_y + m_height , m_x + m_width } ; + + UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; + { + int index = 0 ; + for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) + { + if ( m_macToolHandles[index] ) + { + UMADrawControl( (ControlHandle) m_macToolHandles[index] ) ; + } + } + } + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; + } + } +} +void wxToolBar::OnMouse( wxMouseEvent &event ) +{ + + 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 ; + GrafPtr port ; + SInt16 controlpart ; + WindowRef window = GetMacRootWindow() ; + + 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 ; + + controlpart = FindControl( localwhere , window , &control ) ; + { + if ( AcceptsFocus() && FindFocus() != this ) + { + SetFocus() ; + } + if ( control && UMAIsControlActive( control ) ) + { + { + if ( controlpart == kControlIndicatorPart && !UMAHasAppearance() ) + controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) NULL ) ; + else + controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; + wxTheApp->s_lastMouseDown = 0 ; + if ( controlpart && ! ( ( UMAHasAppearance() || (controlpart != kControlIndicatorPart) ) + && (IsKindOf( CLASSINFO( wxScrollBar ) ) ) ) ) // otherwise we will get the event twice + { + MacHandleControlClick( control , controlpart ) ; + } + } + } + } + } +} + #endif // wxUSE_TOOLBAR diff --git a/src/mac/carbon/treectrl.cpp b/src/mac/carbon/treectrl.cpp index 3aea32e970..137a885dbf 100644 --- a/src/mac/carbon/treectrl.cpp +++ b/src/mac/carbon/treectrl.cpp @@ -16,9 +16,11 @@ #include "wx/stubs/textctrl.h" #include "wx/stubs/treectrl.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject) +#endif wxTreeCtrl::wxTreeCtrl() { diff --git a/src/mac/carbon/uma.cpp b/src/mac/carbon/uma.cpp index ba96908df9..4dce1ce377 100644 --- a/src/mac/carbon/uma.cpp +++ b/src/mac/carbon/uma.cpp @@ -33,7 +33,7 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) long total,contig; PurgeSpace(&total, &contig); #else - InitMenus() ; + InitCursor(); #endif #if UMA_USE_APPEARANCE @@ -87,7 +87,7 @@ bool UMAGetProcessModeDoesActivateOnFGSwitch() // menu manager -void UMASetMenuTitle( MenuRef menu , ConstStr255Param title ) +void UMASetMenuTitle( MenuRef menu , StringPtr title ) { #if !TARGET_CARBON long size = GetHandleSize( (Handle) menu ) ; @@ -117,11 +117,13 @@ void UMASetMenuTitle( MenuRef menu , ConstStr255Param title ) UInt32 UMAMenuEvent( EventRecord *inEvent ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return MenuEvent( inEvent ) ; } else +#endif { if ( inEvent->what == keyDown && inEvent->modifiers & cmdKey) { @@ -133,7 +135,7 @@ UInt32 UMAMenuEvent( EventRecord *inEvent ) void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem ) { -#if UMA_USE_8_6 +#if UMA_USE_8_6 || TARGET_CARBON EnableMenuItem( inMenu , inItem ) ; #else EnableItem( inMenu , inItem ) ; @@ -142,14 +144,145 @@ void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem ) void UMADisableMenuItem( MenuRef inMenu , MenuItemIndex inItem ) { -#if UMA_USE_8_6 +#if UMA_USE_8_6 || TARGET_CARBON DisableMenuItem( inMenu , inItem ) ; #else DisableItem( inMenu , inItem ) ; #endif } + +void UMAAppendSubMenuItem( MenuRef menu , StringPtr l , SInt16 id ) +{ + Str255 label ; + memcpy( label , l , l[0]+1 ) ; + // hardcoded adding of the submenu combination for mac + + int theEnd = label[0] + 1; + if (theEnd > 251) + theEnd = 251; // mac allows only 255 characters + label[theEnd++] = '/'; + label[theEnd++] = hMenuCmd; + label[theEnd++] = '!'; + label[theEnd++] = id ; + label[theEnd] = 0x00; + label[0] = theEnd; + MacAppendMenu(menu, label); +} + +void UMAInsertSubMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 id ) +{ + Str255 label ; + memcpy( label , l , l[0]+1 ) ; + // hardcoded adding of the submenu combination for mac + + int theEnd = label[0] + 1; + if (theEnd > 251) + theEnd = 251; // mac allows only 255 characters + label[theEnd++] = '/'; + label[theEnd++] = hMenuCmd; + label[theEnd++] = '!'; + label[theEnd++] = id; + label[theEnd] = 0x00; + label[0] = theEnd; + MacInsertMenuItem(menu, label , item); +} + +void UMAAppendMenuItem( MenuRef menu , StringPtr l , SInt16 key, UInt8 modifiers ) +{ + Str255 label ; + memcpy( label , l , l[0]+1 ) ; + if ( key ) + { + int pos = label[0] ; + label[++pos] = '/'; + label[++pos] = toupper( key ); + label[0] = pos ; + } + MacAppendMenu( menu , label ) ; +} + +void UMAInsertMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 key, UInt8 modifiers ) +{ + Str255 label ; + memcpy( label , l , l[0]+1 ) ; + if ( key ) + { + int pos = label[0] ; + label[++pos] = '/'; + label[++pos] = toupper( key ); + label[0] = pos ; + } + MacInsertMenuItem( menu , label , item) ; +} + +void UMADrawMenuBar() +{ + DrawMenuBar() ; +} + + +void UMASetMenuItemText( MenuRef menu , MenuItemIndex item , StringPtr label ) +{ + ::SetMenuItemText( menu , item , label ) ; +} + +MenuRef UMANewMenu( SInt16 menuid , StringPtr label ) +{ + return ::NewMenu(menuid, label); +} + +void UMADisposeMenu( MenuRef menu ) +{ + DisposeMenu( menu ) ; +} +void UMADeleteMenu( SInt16 menuId ) +{ + ::DeleteMenu( menuId ) ; +} + +void UMAInsertMenu( MenuRef insertMenu , SInt16 afterId ) +{ + ::InsertMenu( insertMenu , afterId ) ; +} + + // quickdraw +int gPrOpenCounter = 0 ; + +void UMAPrOpen() +{ +#if !TARGET_CARBON + OSErr err = noErr ; + ++gPrOpenCounter ; + if ( gPrOpenCounter == 1 ) + { + PrOpen() ; + err = PrError() ; + wxASSERT( err == noErr ) ; + } +#else + #pragma warning "TODO Printing for Carbon" +#endif +} + +void UMAPrClose() +{ +#if !TARGET_CARBON + OSErr err = noErr ; + wxASSERT( gPrOpenCounter >= 1 ) ; + if ( gPrOpenCounter == 1 ) + { + PrClose() ; + err = PrError() ; + wxASSERT( err == noErr ) ; + } + --gPrOpenCounter ; +#else + #pragma warning "TODO Printing for Carbon" +#endif +} + #if !TARGET_CARBON pascal QDGlobalsPtr GetQDGlobalsPtr (void) @@ -260,77 +393,145 @@ void UMACloseWindow(WindowRef inWindowRef) void UMAActivateControl( ControlHandle inControl ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::ActivateControl( inControl ) ; } else +#endif +#if !TARGET_CARBON { AGAActivateControl( inControl ) ; } +#else + { + } +#endif } void UMADrawControl( ControlHandle inControl ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::DrawControlInCurrentPort( inControl ) ; } else +#endif +#if !TARGET_CARBON { AGADrawControl( inControl ) ; } +#else + { + } +#endif } void UMAMoveControl( ControlHandle inControl , short x , short y ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::MoveControl( inControl , x , y ) ; } else +#endif +#if !TARGET_CARBON { AGAMoveControl( inControl , x ,y ) ; } +#else + { + } +#endif } void UMASizeControl( ControlHandle inControl , short x , short y ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::SizeControl( inControl , x , y ) ; } else +#endif +#if !TARGET_CARBON { AGASizeControl( inControl , x ,y ) ; } +#else + { + } +#endif } void UMADeactivateControl( ControlHandle inControl ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::DeactivateControl( inControl ) ; } else +#endif +#if !TARGET_CARBON { AGADeactivateControl( inControl ) ; } +#else + { + } +#endif } void UMASetThemeWindowBackground (WindowRef inWindow, ThemeBrush inBrush, - Boolean inUpdate){ + Boolean inUpdate) +{ +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::SetThemeWindowBackground( inWindow ,inBrush , inUpdate ) ; } else +#endif +#if !TARGET_CARBON { AGASetThemeWindowBackground( inWindow , inBrush , inUpdate ) ; } +#else + { + } +#endif } +void UMAApplyThemeBackground (ThemeBackgroundKind inKind, + const Rect * bounds, + ThemeDrawState inState, + SInt16 inDepth, + Boolean inColorDev) +{ +#if UMA_USE_APPEARANCE + if ( UMAHasAppearance() ) + { + /* + if ( sUMAAppearanceVersion >= 0x0110 ) + ::ApplyThemeBackground( inKind ,bounds , inState , inDepth , inColorDev ) ; + */ + } + else +#endif +#if !TARGET_CARBON + { + AGAApplyThemeBackground( inKind ,bounds , inState , inDepth , inColorDev ) ; + } +#else + { + } +#endif +} ControlHandle UMANewControl(WindowPtr owningWindow, const Rect * boundsRect, @@ -343,16 +544,23 @@ ControlHandle UMANewControl(WindowPtr owningWindow, SInt32 controlReference) { ControlHandle theControl = NULL ; +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { theControl = NewControl( owningWindow , boundsRect , controlTitle , initiallyVisible , initialValue , minimumValue , maximumValue , procID , controlReference ) ; } else +#endif +#if !TARGET_CARBON { theControl = AGANewControl( owningWindow , boundsRect , controlTitle , initiallyVisible , initialValue , minimumValue , maximumValue , procID , controlReference ) ; } +#else + { + } +#endif return theControl ; } @@ -415,7 +623,9 @@ void UMASetControlVisibility (ControlHandle inControl, { if ( UMAHasAppearance() ) { +#if UMA_USE_APPEARANCE ::SetControlVisibility( inControl , inIsVisible, inDoDraw ) ; +#endif } } @@ -423,21 +633,29 @@ void UMASetControlVisibility (ControlHandle inControl, bool UMAIsControlActive (ControlHandle inControl) { +#if TARGET_CARBON + return IsControlActive( inControl ) ; +#else +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return IsControlActive( inControl ) ; } else +#endif return (**inControl).contrlHilite == 0 ; +#endif } bool UMAIsControlVisible (ControlHandle inControl) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return IsControlVisible( inControl ) ; } +#endif return true ; } @@ -445,26 +663,42 @@ OSErr UMAGetBestControlRect (ControlHandle inControl, Rect * outRect, SInt16 * outBaseLineOffset) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return GetBestControlRect( inControl , outRect , outBaseLineOffset ) ; } else +#endif +#if !TARGET_CARBON { return AGAGetBestControlRect( inControl , outRect , outBaseLineOffset ) ; } +#else + { + return noErr ; + } +#endif } OSErr UMASetControlFontStyle (ControlHandle inControl, const ControlFontStyleRec * inStyle) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return ::SetControlFontStyle( inControl , inStyle ) ; } else +#endif +#if !TARGET_CARBON return AGASetControlFontStyle( inControl , inStyle ) ; +#else + { + return noErr ; + } +#endif } @@ -474,12 +708,20 @@ OSErr UMASetControlFontStyle (ControlHandle inControl, OSErr UMACreateRootControl (WindowPtr inWindow, ControlHandle * outControl) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return CreateRootControl( inWindow , outControl ) ; } else +#endif +#if !TARGET_CARBON return AGACreateRootControl( inWindow , outControl ) ; +#else + { + return noErr ; + } +#endif } @@ -487,12 +729,20 @@ OSErr UMACreateRootControl (WindowPtr inWindow, OSErr UMAEmbedControl (ControlHandle inControl, ControlHandle inContainer) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return EmbedControl( inControl , inContainer ) ; } else +#endif +#if !TARGET_CARBON return AGAEmbedControl( inControl , inContainer ) ; ; +#else + { + return noErr ; + } +#endif } @@ -502,12 +752,30 @@ OSErr UMASetKeyboardFocus (WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) { + OSErr err = noErr; + GrafPtr port ; + GetPort( &port ) ; +#if TARGET_CARBON + SetPort( GetWindowPort( inWindow ) ) ; +#else + SetPort( inWindow ) ; +#endif + SetOrigin( 0 , 0 ) ; +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { - return SetKeyboardFocus( inWindow , inControl , inPart ) ; + err = SetKeyboardFocus( inWindow , inControl , inPart ) ; } else - return AGASetKeyboardFocus( inWindow , inControl , inPart ) ; +#endif +#if !TARGET_CARBON + err = AGASetKeyboardFocus( inWindow , inControl , inPart ) ; +#else + { + } +#endif + SetPort( port ) ; + return err ; } @@ -520,14 +788,22 @@ ControlPartCode UMAHandleControlClick (ControlHandle inControl, SInt16 inModifiers, ControlActionUPP inAction) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return HandleControlClick( inControl , inWhere , inModifiers , inAction ) ; } else +#endif +#if !TARGET_CARBON { return AGAHandleControlClick( inControl , inWhere , inModifiers , inAction ) ; } +#else + { + return noErr ; + } +#endif } @@ -536,52 +812,82 @@ SInt16 UMAHandleControlKey (ControlHandle inControl, SInt16 inCharCode, SInt16 inModifiers) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return HandleControlKey( inControl , inKeyCode , inCharCode , inModifiers ) ; } else +#endif +#if !TARGET_CARBON { return AGAHandleControlKey(inControl , inKeyCode , inCharCode , inModifiers ) ; } +#else + { + return noErr ; + } +#endif } void UMAIdleControls (WindowPtr inWindow) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { IdleControls( inWindow ) ; } else +#endif +#if !TARGET_CARBON { AGAIdleControls( inWindow ) ; } +#else + { + } +#endif } void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { UpdateControls( inWindow , inRgn ) ; } else +#endif +#if !TARGET_CARBON { AGAUpdateControls( inWindow , inRgn ) ; } +#else + { + } +#endif } OSErr UMAGetRootControl( WindowPtr inWindow , ControlHandle *outControl ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return GetRootControl( inWindow , outControl ) ; } else +#endif +#if !TARGET_CARBON { return AGAGetRootControl( inWindow , outControl ) ; } +#else + { + return noErr ; + } +#endif } @@ -593,12 +899,20 @@ OSErr UMASetControlData (ControlHandle inControl, Size inSize, Ptr inData) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return SetControlData( inControl , inPart , inTagName , inSize , inData ) ; } else +#endif +#if !TARGET_CARBON return AGASetControlData( inControl , inPart , inTagName , inSize , inData ) ; +#else + { + return noErr ; + } +#endif } @@ -610,15 +924,22 @@ OSErr UMAGetControlData (ControlHandle inControl, Ptr outBuffer, Size * outActualSize) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return ::GetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ; } else +#endif +#if !TARGET_CARBON { return AGAGetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ; } - +#else + { + return noErr ; + } +#endif } @@ -627,14 +948,22 @@ OSErr UMAGetControlDataSize (ControlHandle inControl, ResType inTagName, Size * outMaxSize) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return GetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ; } else +#endif +#if !TARGET_CARBON { return AGAGetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ; } +#else + { + return noErr ; + } +#endif } @@ -711,11 +1040,70 @@ OSStatus UMACreateNewWindow( WindowClass windowClass , WindowAttributes attribu case kMovableModalWindowClass : procID = kWindowMovableModalDialogProc; break ; - case kDocumentWindowClass : - procID = kWindowFullZoomGrowDocumentProc; + case kModalWindowClass : + procID = kWindowShadowDialogProc; + break ; + case kFloatingWindowClass : + if ( attributes & kWindowSideTitlebarAttribute ) + { + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = kWindowFloatSideFullZoomGrowProc ; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = kWindowFloatSideFullZoomProc; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = kWindowFloatSideGrowProc; + } + else + { + procID = kWindowFloatSideProc; + } + } + else + { + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = kWindowFloatFullZoomGrowProc ; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = kWindowFloatFullZoomProc; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = kWindowFloatGrowProc; + } + else + { + procID = kWindowFloatProc; + } + } break ; + case kDocumentWindowClass : default : - procID = kWindowMovableModalDialogProc; + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = kWindowFullZoomGrowDocumentProc; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = kWindowFullZoomDocumentProc; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = kWindowGrowDocumentProc; + } + else + { + procID = kWindowDocumentProc; + } break ; } } @@ -725,13 +1113,72 @@ OSStatus UMACreateNewWindow( WindowClass windowClass , WindowAttributes attribu { case kMovableModalWindowClass : procID = movableDBoxProc; -// procID += kMovableModalDialogVariantCode; break ; - case kDocumentWindowClass : - procID = zoomDocProc; + case kModalWindowClass : + procID = altDBoxProc; + break ; + case kFloatingWindowClass : + if ( attributes & kWindowSideTitlebarAttribute ) + { + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = floatSideZoomGrowProc ; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = floatSideZoomProc; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = floatSideGrowProc; + } + else + { + procID = floatSideProc; + } + } + else + { + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = floatZoomGrowProc ; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = floatZoomProc; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = floatGrowProc; + } + else + { + procID = floatProc; + } + } break ; + case kDocumentWindowClass : default : - procID = documentProc; + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = zoomDocProc; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = zoomNoGrow; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = documentProc; + } + else + { + procID = noGrowDocProc; + } + break ; break ; } } @@ -853,6 +1300,32 @@ void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ) // bool isHighlighted = IsWindowHighlited( inWindowRef ) ; // if ( inActivate != isHightlited ) HiliteWindow( inWindowRef , inActivate ) ; + ControlHandle control = NULL ; + UMAGetRootControl( inWindowRef , & control ) ; + if ( control ) + { + if ( inActivate ) + UMAActivateControl( control ) ; + else + UMADeactivateControl( control ) ; + } } } +OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ) +{ +#if UMA_USE_APPEARANCE + if ( UMAHasAppearance() ) + { + ::DrawThemePlacard( inRect , inState ) ; + } + else +#endif +#if !TARGET_CARBON + { + } +#else + { + } +#endif +} diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp index 817138cb63..0031f1efad 100644 --- a/src/mac/carbon/utils.cpp +++ b/src/mac/carbon/utils.cpp @@ -18,6 +18,7 @@ #include "wx/setup.h" #include "wx/utils.h" #include "wx/app.h" +#include "wx/mac/uma.h" #include @@ -26,7 +27,13 @@ #include #include -// Get full hostname (eg. DoDo.BSn-Germany.crg.de) +// get full hostname (with domain name if possible) +bool wxGetFullHostName(wxChar *buf, int maxSize) +{ + return wxGetHostName(buf, maxSize); +} + +// Get hostname only (without domain name) bool wxGetHostName(char *buf, int maxSize) { // TODO @@ -227,7 +234,10 @@ void wxEndBusyCursor() if ( gMacStoredActiveCursor ) ::SetCursor( *gMacStoredActiveCursor ) ; else - ::SetCursor( &qd.arrow ) ; + { + Cursor MacArrow ; + ::SetCursor( GetQDGlobalsArrow( &MacArrow ) ) ; + } gMacStoredActiveCursor = NULL ; } } @@ -238,6 +248,25 @@ bool wxIsBusy() return (wxBusyCursorCount > 0); } +wxString wxMacFindFolder( short vol, + OSType folderType, + Boolean createFolder) +{ + short vRefNum ; + long dirID ; + wxString strDir ; + + if ( FindFolder( vol, folderType, createFolder, &vRefNum, &dirID) == noErr) + { + FSSpec file ; + if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr ) + { + strDir = wxMacFSSpec2UnixFilename( &file ) + "/" ; + } + } + return strDir ; +} + char *wxGetUserHome (const wxString& user) { // TODO @@ -271,23 +300,32 @@ bool wxColourDisplay() // Returns depth of screen int wxDisplayDepth() { - // get max pixel depth - CGrafPtr port ; - GetCWMgrPort( &port ) ; - GDHandle maxDevice ; + Rect globRect ; + SetRect(&globRect, -32760, -32760, 32760, 32760); + GDHandle theMaxDevice; + + int theDepth = 8; + theMaxDevice = GetMaxDevice(&globRect); + if (theMaxDevice != nil) + theDepth = (**(**theMaxDevice).gdPMap).pixelSize; - maxDevice = GetMaxDevice( &port->portRect ) ; - if ( maxDevice ) - return (**((**maxDevice).gdPMap)).pixelSize ; - else - return 8 ; + return theDepth ; } // Get size of display void wxDisplaySize(int *width, int *height) { - *width = qd.screenBits.bounds.right - qd.screenBits.bounds.left ; - *height = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top ; - *height -= LMGetMBarHeight() ; + BitMap screenBits; + GetQDGlobalsScreenBits( &screenBits ); + + *width = screenBits.bounds.right - screenBits.bounds.left ; + *height = screenBits.bounds.bottom - screenBits.bounds.top ; + #if TARGET_CARBON + SInt16 mheight ; + GetThemeMenuBarHeight( &mheight ) ; + *height -= mheight ; +#else + *height -= LMGetMBarHeight() ; + #endif } diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index f8099265a2..3dd198b369 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -29,6 +29,7 @@ #include "wx/frame.h" #include "wx/notebook.h" #include "wx/tabctrl.h" +#include "wx/tooltip.h" // TODO remove the line below, just for lookup-up convenience CS #include "wx/mac/window.h" @@ -54,8 +55,8 @@ extern wxList wxPendingDelete; wxWindow* gFocusWindow = NULL ; +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) - BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) @@ -64,6 +65,7 @@ BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) // EVT_SCROLL(wxWindow::OnScroll) END_EVENT_TABLE() +#endif @@ -163,6 +165,7 @@ wxWindow::~wxWindow() if ( m_macWindowData ) { + wxToolTip::NotifyWindowDelete(m_macWindowData->m_macWindow) ; UMADisposeWindow( m_macWindowData->m_macWindow ) ; delete m_macWindowData ; wxRemoveMacWindowAssociation( this ) ; @@ -189,7 +192,10 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, m_width = WidthDefault( size.x ); m_height = HeightDefault( size.y ) ; - MacCreateScrollBars( style ) ; + if ( ! IsKindOf( CLASSINFO ( wxControl ) ) ) + { + MacCreateScrollBars( style ) ; + } return TRUE; } @@ -211,6 +217,7 @@ void wxWindow::SetFocus() if ( control && control->GetMacControl() ) { UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ; + control->MacRedrawControl() ; } wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); event.SetEventObject(gFocusWindow); @@ -248,11 +255,6 @@ bool wxWindow::Enable(bool enable) { if ( !wxWindowBase::Enable(enable) ) return FALSE; -/* - HWND hWnd = GetHwnd(); - if ( hWnd ) - ::EnableWindow(hWnd, (BOOL)enable); -*/ wxWindowList::Node *node = GetChildren().GetFirst(); while ( node ) @@ -319,9 +321,6 @@ void wxWindow::DoGetPosition(int *x, int *y) const } - - - bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) { menu->SetInvokingWindow(this); @@ -370,6 +369,7 @@ void wxWindow::DoClientToScreen(int *x, int *y) const GrafPtr port ; ::GetPort( &port ) ; ::SetPort( UMAGetWindowPort( window ) ) ; + ::SetOrigin( 0 , 0 ) ; ::LocalToGlobal( &localwhere ) ; ::SetPort( port ) ; *x = localwhere.h ; @@ -437,10 +437,52 @@ void wxWindow::DoGetClientSize(int *x, int *y) const *x = m_width ; *y = m_height ; - if (m_vScrollBar && m_vScrollBar->IsShown() ) - (*x) -= MAC_SCROLLBAR_SIZE; - if (m_hScrollBar && m_hScrollBar->IsShown() ) - (*y) -= MAC_SCROLLBAR_SIZE; + *x -= 2 * MacGetBorderSize( ) ; + *y -= 2 * MacGetBorderSize( ) ; + + if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) ) + { + int x1 = 0 ; + int y1 = 0 ; + int w = m_width ; + int h = m_height ; + + MacClientToRootWindow( &x1 , &y1 ) ; + MacClientToRootWindow( &w , &h ) ; + + WindowRef window = NULL ; + wxWindow *iter = (wxWindow*)this ; + + int totW = 10000 , totH = 10000; + while( iter ) + { + if ( iter->m_macWindowData ) + { + totW = iter->m_width ; + totH = iter->m_height ; + break ; + } + + iter = iter->GetParent() ; + } + + if (m_hScrollBar && m_hScrollBar->IsShown() ) + { + (*y) -= MAC_SCROLLBAR_SIZE; + if ( h-y1 >= totH ) + { + (*y)+= 1 ; + } + } + if (m_vScrollBar && m_vScrollBar->IsShown() ) + { + (*x) -= MAC_SCROLLBAR_SIZE; + if ( w-x1 >= totW ) + { + (*x) += 1 ; + } + } + } } @@ -454,8 +496,8 @@ void wxWindow::DoSetToolTip(wxToolTip *tooltip) { wxWindowBase::DoSetToolTip(tooltip); -// if ( m_tooltip ) -// m_tooltip->SetWindow(this); + if ( m_tooltip ) + m_tooltip->SetWindow(this); } #endif // wxUSE_TOOLTIPS @@ -467,6 +509,7 @@ void wxWindow::DoMoveWindow(int x, int y, int width, int height) void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) { + int former_x = m_x ; int former_y = m_y ; int former_w = m_width ; @@ -481,9 +524,9 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) int actualHeight = height; int actualX = x; int actualY = y; - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualX = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualY = currentY; if (width == -1) actualWidth = currentW ; @@ -524,7 +567,7 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) if ( focus.Ok() ) { Rect clientrect = { 0 , 0 , m_height , m_width } ; - InvalRect( &clientrect ) ; + InvalWindowRect( GetMacRootWindow() , &clientrect ) ; } } } @@ -535,18 +578,18 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) if ( m_macWindowData ) { if ( doMove ) - ::MoveWindow(m_macWindowData->m_macWindow, m_x, m_y, false); // don't make frontmost + ::MoveWindow(m_macWindowData->m_macWindow, m_x, m_y , false); // don't make frontmost if ( doResize ) - ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height, true); + ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height , true); // the OS takes care of invalidating and erasing if ( IsKindOf( CLASSINFO( wxFrame ) ) ) { wxFrame* frame = (wxFrame*) this ; - frame->PositionStatusBar(); - frame->PositionToolBar(); + frame->PositionStatusBar(); + frame->PositionToolBar(); } } else @@ -556,8 +599,8 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxMacDrawingClientHelper focus( this ) ; if ( focus.Ok() ) { - Rect clientrect = { 0 , 0 , m_height , m_width } ; - InvalRect( &clientrect ) ; + Rect clientrect = { 0 , 0 , m_height , m_width } ; + InvalWindowRect( GetMacRootWindow() , &clientrect ) ; } } if ( doMove ) @@ -566,17 +609,17 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) MacRepositionScrollBars() ; if ( doMove ) { - wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event) ; - } - if ( doResize ) - { + wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event) ; + } + if ( doResize ) + { MacRepositionScrollBars() ; - wxSizeEvent event(wxSize(m_width, m_height), m_windowId); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); - } + wxSizeEvent event(wxSize(m_width, m_height), m_windowId); + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); + } } } // For implementation purposes - sometimes decorations make the client area @@ -584,7 +627,7 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxPoint wxWindow::GetClientAreaOrigin() const { - return wxPoint(0, 0); + return wxPoint(MacGetBorderSize( ) , MacGetBorderSize( ) ); } // Makes an adjustment to the window position (for example, a frame that has @@ -632,7 +675,8 @@ bool wxWindow::Show(bool show) { UMAShowWindow( m_macWindowData->m_macWindow ) ; UMASelectWindow( m_macWindowData->m_macWindow ) ; - // no need to generate events here, they will get them triggered by macos + // no need to generate events here, they will get them triggered by macos + // actually they should be , but apparently they are not wxSizeEvent event(wxSize(m_width, m_height), m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); @@ -644,6 +688,8 @@ bool wxWindow::Show(bool show) } MacSuperShown( show ) ; Refresh() ; + if(m_macWindowData) + MacUpdateImmediately() ; return TRUE; } @@ -682,10 +728,14 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, wxClientDC dc( this ) ; long lx,ly,ld,le ; dc.GetTextExtent( string , &lx , &ly , &ld, &le, fontToUse ) ; - *externalLeading = le ; - *descent = ld ; - *x = lx ; - *y = ly ; + if ( externalLeading ) + *externalLeading = le ; + if ( descent ) + *descent = ld ; + if ( x ) + *x = lx ; + if ( y ) + *y = ly ; } void wxWindow::MacEraseBackground( Rect *rect ) @@ -715,7 +765,7 @@ void wxWindow::MacEraseBackground( Rect *rect ) // 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 ) )) { - ApplyThemeBackground (kThemeBackgroundTabPane, rect, kThemeStateActive,8,true); + UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true); break ; } } @@ -743,10 +793,6 @@ void wxWindow::MacEraseBackground( Rect *rect ) for (wxNode *node = GetChildren().First(); node; node = node->Next()) { wxWindow *child = (wxWindow*)node->Data(); -// int width ; -// int height ; - -// child->GetClientSize( &width , &height ) ; Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ; SectRect( &clientrect , rect , &clientrect ) ; @@ -765,26 +811,18 @@ void wxWindow::MacEraseBackground( Rect *rect ) void wxWindow::Refresh(bool eraseBack, const wxRect *rect) { - wxMacDrawingClientHelper focus( this ) ; + wxMacDrawingHelper focus( this ) ; if ( focus.Ok() ) { - int width , height ; - GetClientSize( &width , &height ) ; - Rect clientrect = { 0 , 0 , height , width } ; - ClipRect( &clientrect ) ; + Rect clientrect = { 0 , 0 , m_height , m_width } ; + ClipRect( &clientrect ) ; - if ( rect ) - { - Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; + if ( rect ) + { + Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; SectRect( &clientrect , &r , &clientrect ) ; - } - InvalRect( &clientrect ) ; - /* - if ( eraseBack ) - { - MacEraseBackground( &clientrect ) ; - } - */ + } + InvalWindowRect( GetMacRootWindow() , &clientrect ) ; } } @@ -927,41 +965,222 @@ void wxWindow::SetScrollPos(int orient, int pos, bool refresh) } } -void wxWindow::MacPaint( wxPaintEvent &event ) +void wxWindow::MacCreateRealWindow( const wxString& title, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name ) { - wxPaintDC dc(this); - PrepareDC(dc); + SetName(name); + m_windowStyle = style; + m_isShown = FALSE; - if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) ) - { - bool sunken = HasFlag( wxSUNKEN_BORDER ) ; + // create frame. - wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ; - wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ; - - wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN; - wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow; - wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow; - wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN; + 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 ; + + m_width = size.x; + if (m_width == -1) + m_width = 20; + m_height = size.y; + if (m_height == -1) + m_height = 20; + + m_macWindowData = new MacWindowData() ; + + ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); + + // translate the window attributes in the appropriate window class and attributes + + WindowClass wclass ; + WindowAttributes attr ; - dc.SetPen(wxPen1); - dc.DrawRectangle(0, 0, m_width, m_height); // outer - right and button + if ( HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) ) + { + wclass = kFloatingWindowClass ; + if ( HasFlag(wxTINY_CAPTION_VERT) ) + { + attr |= kWindowSideTitlebarAttribute ; + } + } + else if ( HasFlag( wxTHICK_FRAME ) ) + { + if ( HasFlag( wxDIALOG_MODAL ) ) + { + wclass = kMovableModalWindowClass ; + } + else if ( HasFlag( wxDIALOG_MODELESS ) ) + { + wclass = kDocumentWindowClass ; + } + else + { + if ( HasFlag( wxCAPTION ) ) + { + wclass = kDocumentWindowClass ; + } + else + { + wclass = kModalWindowClass ; + } + } + } + else + { + wclass = kModalWindowClass ; + } - dc.SetPen(wxPen2); - dc.DrawRectangle(1, 1, m_width-1, m_height-1); // outer - left and top + attr = kWindowNoAttributes ; - dc.SetPen(wxPen3); - dc.DrawRectangle(0, 0, m_width-2, m_height-2); // inner - right and button + if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) + { + attr |= kWindowFullZoomAttribute ; + attr |= kWindowCollapseBoxAttribute ; + } + if ( HasFlag( wxRESIZE_BORDER ) ) + { + attr |= kWindowResizableAttribute ; + } + if ( HasFlag( wxSYSTEM_MENU ) ) + { + attr |= kWindowCloseBoxAttribute ; + } - dc.SetPen(wxPen4); - dc.DrawLine(0, 0, m_width-3, 0); // inner - left and top - dc.DrawLine(0, 0, 0, m_height-3); + UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ; + wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ; + wxString label ; + if( wxApp::s_macDefaultEncodingIsPC ) + label = wxMacMakeMacStringFromPC( title ) ; + else + label = title ; + UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; + UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; + + m_macWindowData->m_macFocus = NULL ; +} + +void wxWindow::MacPaint( wxPaintEvent &event ) +{ +} + +void wxWindow::MacPaintBorders( ) +{ + if( m_macWindowData ) + return ; + + RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ; + RGBColor black = { 0x0000, 0x0000 , 0x0000 } ; + RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ; + RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ; + PenNormal() ; + + if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) + { + bool sunken = HasFlag( wxSUNKEN_BORDER ) ; + RGBColor pen1 = sunken ? white : black ; + RGBColor pen2 = sunken ? shadow : face ; + RGBColor pen3 = sunken ? face : shadow ; + RGBColor pen4 = sunken ? black : white ; + + RGBForeColor( &pen1 ) ; + { + Rect rect = { 0 , 0 , m_height , m_width } ; + FrameRect( &rect ) ; + } + RGBForeColor( &pen2 ) ; + { + Rect rect = { 1 , 1 , m_height -1 , m_width -1} ; + FrameRect( &rect ) ; + } + RGBForeColor( &pen3 ) ; + { + Rect rect = { 0 , 0 , m_height -2 , m_width -2} ; + FrameRect( &rect ) ; + } + RGBForeColor( &pen4 ) ; + { + MoveTo( 0 , 0 ) ; + LineTo( m_width - 3 , 0 ) ; + MoveTo( 0 , 0 ) ; + LineTo( 0 , m_height - 3 ) ; + } } else if (HasFlag(wxSIMPLE_BORDER)) { - dc.SetPen(*wxBLACK_PEN); - dc.DrawRectangle(0, 0, m_width, m_height); + Rect rect = { 0 , 0 , m_height , m_width } ; + RGBForeColor( &black ) ; + FrameRect( &rect ) ; + } +/* + if ( this->GetParent() ) + { + wxPaintDC dc(GetParent()); + GetParent()->PrepareDC(dc); + + if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) ) + { + bool sunken = HasFlag( wxSUNKEN_BORDER ) ; + + wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ; + wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ; + + wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN; + wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow; + wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow; + wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN; + + dc.SetPen(wxPen1); + dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button + + dc.SetPen(wxPen2); + dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top + + dc.SetPen(wxPen3); + dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button + + dc.SetPen(wxPen4); + dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top + dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3); + } + else if (HasFlag(wxDOUBLE_BORDER)) + { + bool sunken = HasFlag( wxSUNKEN_BORDER ) ; + + wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ; + wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ; + + wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN; + wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow; + wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow; + wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN; + + dc.SetPen(wxPen1); + dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button + + dc.SetPen(wxPen2); + dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top + + dc.SetPen(wxPen3); + dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button + + dc.SetPen(wxPen4); + dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top + dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3); + } + else if (HasFlag(wxSIMPLE_BORDER)) + { + dc.SetPen(*wxBLACK_PEN); + dc.DrawRectangle(m_x, m_y, m_width, m_height); + } } + */ } // New function that will replace some of the above. @@ -1011,20 +1230,21 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) wxMacDrawingClientHelper focus( this ) ; if ( focus.Ok() ) { - int width , height ; - GetClientSize( &width , &height ) ; - Rect scrollrect = { 0 , 0 , height , width } ; + int width , height ; + GetClientSize( &width , &height ) ; + + Rect scrollrect = { 0 , 0 , height , width } ; - RgnHandle updateRgn = NewRgn() ; - ClipRect( &scrollrect ) ; - if ( rect ) - { - Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; + RgnHandle updateRgn = NewRgn() ; + ClipRect( &scrollrect ) ; + if ( rect ) + { + Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; SectRect( &scrollrect , &r , &scrollrect ) ; - } - ScrollRect( &scrollrect , dx , dy , updateRgn ) ; - InvalRgn( updateRgn ) ; - DisposeRgn( updateRgn ) ; + } + ScrollRect( &scrollrect , dx , dy , updateRgn ) ; + InvalWindowRgn( GetMacRootWindow() , updateRgn ) ; + DisposeRgn( updateRgn ) ; } } @@ -1136,9 +1356,9 @@ void wxWindow::Clear() else { wxClientDC dc(this); - wxBrush brush(GetBackgroundColour(), wxSOLID); - dc.SetBackground(brush); - dc.Clear(); + wxBrush brush(GetBackgroundColour(), wxSOLID); + dc.SetBackground(brush); + dc.Clear(); } } @@ -1193,6 +1413,9 @@ void wxWindow::DoSetClientSize(int width, int height) if ( height != -1 && m_vScrollBar ) height += MAC_SCROLLBAR_SIZE ; + width += 2 * MacGetBorderSize( ) ; + height += 2 * MacGetBorderSize( ) ; + DoSetSize( -1 , -1 , width , height ) ; } } @@ -1249,6 +1472,7 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event) (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height))) return FALSE; + if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) ) return FALSE ; @@ -1277,10 +1501,28 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event) { m_cursor.MacInstall() ; } + +#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 GetEventHandler()->ProcessEvent( event ) ; return TRUE; } +Point lastWhere ; +long lastWhen = 0 ; + +wxString wxWindow::MacGetToolTipString( wxPoint &pt ) +{ + if ( m_tooltip ) + { + return m_tooltip->GetTip() ; + } + return "" ; +} void wxWindow::MacFireMouseEvent( EventRecord *ev ) { wxMouseEvent event(wxEVT_LEFT_DOWN); @@ -1323,6 +1565,22 @@ void wxWindow::MacFireMouseEvent( EventRecord *ev ) ::GlobalToLocal( &localwhere ) ; ::SetPort( port ) ; + if ( ev->what == mouseDown ) + { + if ( ev->when - lastWhen <= GetDblTime() ) + { + if ( abs( localwhere.h - lastWhere.h ) < 3 || abs( localwhere.v - lastWhere.v ) < 3 ) + { + if ( controlDown ) + event.SetEventType(wxEVT_RIGHT_DCLICK ) ; + else + event.SetEventType(wxEVT_LEFT_DCLICK ) ; + } + } + lastWhen = ev->when ; + lastWhere = localwhere ; + } + event.m_x = localwhere.h; event.m_y = localwhere.v; event.m_x += m_x; @@ -1407,7 +1665,7 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) WindowRef window = GetMacRootWindow() ; wxWindow* win = wxFindWinFromMacWindow( window ) ; { - wxMacDrawingClientHelper focus( this ) ; + wxMacDrawingHelper focus( this ) ; // was client if ( focus.Ok() ) { WindowRef window = GetMacRootWindow() ; @@ -1446,7 +1704,9 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) // 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 ) )) { - ApplyThemeBackground(kThemeBackgroundTabPane, &(**updatergn).rgnBBox , kThemeStateActive,8,true); + Rect box ; + GetRegionBounds( updatergn , &box) ; + UMAApplyThemeBackground(kThemeBackgroundTabPane, &box , kThemeStateActive,8,true); break ; } } @@ -1475,32 +1735,39 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) EraseRgn( updatergn ) ; } } + + m_macUpdateRgn = updatergn ; + { + 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 , m_macUpdateRgn , newupdate ) ; + OffsetRgn( newupdate , -origin.x , -origin.y ) ; + m_updateRegion = newupdate ; + DisposeRgn( newupdate ) ; + } + + MacPaintBorders() ; + wxPaintEvent event; + event.m_timeStamp = time ; + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); + } + { } - m_updateRegion = updatergn ; - wxPaintEvent event; - event.m_timeStamp = time ; - event.SetEventObject(this); - - wxPaintEvent event2( event ) ; - GetEventHandler()->ProcessEvent(event); - MacPaint( event2 ) ; RgnHandle childupdate = NewRgn() ; for (wxNode *node = GetChildren().First(); node; node = node->Next()) { wxWindow *child = (wxWindow*)node->Data(); - int width ; - int height ; - - child->GetClientSize( &width , &height ) ; - - SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x +width , child->m_y + height ) ; - SectRgn( childupdate , m_updateRegion.GetWXHRGN() , childupdate ) ; + SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; + SectRgn( childupdate , m_macUpdateRgn , childupdate ) ; OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; - if ( child->GetMacRootWindow() == window && child->IsShown() ) + if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) ) { // because dialogs may also be children child->MacRedraw( childupdate , time ) ; @@ -1516,24 +1783,28 @@ void wxWindow::MacUpdateImmediately() if ( window ) { wxWindow* win = wxFindWinFromMacWindow( window ) ; + #if TARGET_CARBON + AGAPortHelper help( GetWindowPort(window) ) ; + #else + AGAPortHelper help( (window) ) ; + #endif + SetOrigin( 0 , 0 ) ; BeginUpdate( window ) ; if ( win ) { - #if ! TARGET_CARBON - if ( !EmptyRgn( window->visRgn ) ) - #endif + RgnHandle region = NewRgn(); + + if ( region ) { - win->MacRedraw( window->visRgn , wxTheApp->sm_lastMessageTime ) ; -/* - { - wxMacDrawingHelper help( win ) ; - SetOrigin( 0 , 0 ) ; - UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; - UMAUpdateControls( window , window->visRgn ) ; - UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ; - } -*/ - } + GetPortVisibleRegion( GetWindowPort( window ), region ); + + // if windowshade gives incompatibility , take the follwing out + if ( !EmptyRgn( region ) ) + { + win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ; + } + DisposeRgn( region ); + } } EndUpdate( window ) ; } @@ -1543,26 +1814,28 @@ void wxWindow::MacUpdate( EventRecord *ev ) { WindowRef window = (WindowRef) ev->message ; wxWindow * win = wxFindWinFromMacWindow( window ) ; - + #if TARGET_CARBON + AGAPortHelper help( GetWindowPort(window) ) ; + #else + AGAPortHelper help( (window) ) ; + #endif + SetOrigin( 0 , 0 ) ; BeginUpdate( window ) ; if ( win ) { - // if windowshade gives incompatibility , take the follwing out - #if ! TARGET_CARBON - if ( !EmptyRgn( window->visRgn ) ) - #endif + RgnHandle region = NewRgn(); + + if ( region ) { - MacRedraw( window->visRgn , ev->when ) ; - /* - { - wxMacDrawingHelper help( this ) ; - SetOrigin( 0 , 0 ) ; - UMASetThemeWindowBackground( m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; - UMAUpdateControls( window , window->visRgn ) ; - UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ; - } - */ - } + GetPortVisibleRegion( GetWindowPort( window ), region ); + + // if windowshade gives incompatibility , take the follwing out + if ( !EmptyRgn( region ) ) + { + MacRedraw( region , ev->when ) ; + } + DisposeRgn( region ); + } } EndUpdate( window ) ; } @@ -1586,20 +1859,36 @@ WindowRef wxWindow::GetMacRootWindow() const void wxWindow::MacCreateScrollBars( long style ) { wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ; + bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ; + int width, height ; + GetClientSize( &width , &height ) ; + wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; + wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; + wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; + wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; + + m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint, + vSize , wxVERTICAL); + if ( style & wxVSCROLL ) { - m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, wxPoint(m_width-MAC_SCROLLBAR_SIZE, 0), - wxSize(MAC_SCROLLBAR_SIZE, m_height - adjust), wxVERTICAL); -// m_vScrollBar->PushEventHandler( this ) ; + + } + else + { + m_vScrollBar->Show(false) ; } + m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint, + hSize , wxHORIZONTAL); if ( style & wxHSCROLL ) { - m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, wxPoint(0 , m_height-MAC_SCROLLBAR_SIZE ), - wxSize( m_width - adjust, MAC_SCROLLBAR_SIZE), wxHORIZONTAL); -// m_hScrollBar->PushEventHandler( this ) ; + } + else + { + m_hScrollBar->Show(false) ; } // because the create does not take into account the client area origin @@ -1611,18 +1900,79 @@ void wxWindow::MacRepositionScrollBars() bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ; + // get real client area + + int width = m_width ; + int height = m_height ; + + width -= 2 * MacGetBorderSize() ; + height -= 2 * MacGetBorderSize() ; + + wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; + wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; + wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; + wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; + + int x = 0 ; + int y = 0 ; + int w = m_width ; + int h = m_height ; + + MacClientToRootWindow( &x , &y ) ; + MacClientToRootWindow( &w , &h ) ; + + WindowRef window = NULL ; + wxWindow *iter = (wxWindow*)this ; + + int totW = 10000 , totH = 10000; + while( iter ) + { + if ( iter->m_macWindowData ) + { + totW = iter->m_width ; + totH = iter->m_height ; + break ; + } + + iter = iter->GetParent() ; + } + + if ( x == 0 ) + { + hPoint.x = -1 ; + hSize.x += 1 ; + } + if ( y == 0 ) + { + vPoint.y = -1 ; + vSize.y += 1 ; + } + + if ( w-x >= totW ) + { + hSize.x += 1 ; + vPoint.x += 1 ; + } + + if ( h-y >= totH ) + { + vSize.y += 1 ; + hPoint.y += 1 ; + } + if ( m_vScrollBar ) { - m_vScrollBar->SetSize( m_width-MAC_SCROLLBAR_SIZE, 0, MAC_SCROLLBAR_SIZE, m_height - adjust , wxSIZE_USE_EXISTING); + m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE); } if ( m_hScrollBar ) { - m_hScrollBar->SetSize( 0 , m_height-MAC_SCROLLBAR_SIZE ,m_width - adjust, MAC_SCROLLBAR_SIZE, wxSIZE_USE_EXISTING); + m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE); } } void wxWindow::MacKeyDown( EventRecord *ev ) { + } @@ -1651,7 +2001,8 @@ void wxWindow::MacSuperChangedPosition() node = node->Next(); } } - +/* + bool wxWindow::MacSetupFocusPort( ) { Point localOrigin ; @@ -1699,7 +2050,7 @@ bool wxWindow::MacSetupDrawingClientPort( ) MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; } - +*/ bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win ) { @@ -1714,6 +2065,7 @@ bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & cl if (currPort != port ) ::SetPort(port); +// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ; ::SetOrigin(-localOrigin.h, -localOrigin.v); return true; } @@ -1729,14 +2081,16 @@ bool wxWindow::MacSetPortDrawingParams( const Point & localOrigin, const Rect & port = UMAGetWindowPort( window) ; if (currPort != port ) ::SetPort(port); - +// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ; ::SetOrigin(-localOrigin.h, -localOrigin.v); ::ClipRect(&clipRect); ::PenNormal() ; ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ; ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ; - ::BackPat( &qd.white ) ; + Pattern whiteColor ; + + ::BackPat( GetQDGlobalsWhite( &whiteColor) ) ; ::UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ; return true; } @@ -1771,10 +2125,10 @@ void wxWindow::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *w } } -void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin ) +void wxWindow::MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin ) { - int width , height ; - GetClientSize( &width , &height ) ; +// int width , height ; +// GetClientSize( &width , &height ) ; if ( m_macWindowData ) { @@ -1791,7 +2145,7 @@ void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, Window { wxASSERT( GetParent() != NULL ) ; - GetParent()->MacGetPortClientParams( localOrigin , clipRect , window, rootwin) ; + GetParent()->MacDoGetPortClientParams( localOrigin , clipRect , window, rootwin) ; localOrigin->h += m_x; localOrigin->v += m_y; @@ -1800,12 +2154,58 @@ void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, Window Rect myClip; myClip.left = 0; myClip.top = 0; - myClip.right = width; - myClip.bottom = height; + myClip.right = m_width ;//width; + myClip.bottom = m_height ;// height; SectRect(clipRect, &myClip, clipRect); } } +void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin ) +{ + MacDoGetPortClientParams( localOrigin , clipRect , window , rootwin ) ; + + int width , height ; + GetClientSize( &width , &height ) ; + wxPoint client ; + client = GetClientAreaOrigin( ) ; + + localOrigin->h += client.x; + localOrigin->v += client.y; + OffsetRect(clipRect, -client.x, -client.y); + + Rect myClip; + myClip.left = 0; + myClip.top = 0; + myClip.right = width; + myClip.bottom = height; + SectRect(clipRect, &myClip, clipRect); +} + +long wxWindow::MacGetBorderSize( ) const +{ + if( m_macWindowData ) + return 0 ; + + if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) + { + return 2 ; + } + else if ( m_windowStyle &wxDOUBLE_BORDER) + { + return 2 ; + } + else if (m_windowStyle &wxSIMPLE_BORDER) + { + return 1 ; + } + return 0 ; +} + +long wxWindow::MacRemoveBordersFromStyle( long style ) +{ + return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; +} +/* wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow ) { m_ok = false ; @@ -1829,12 +2229,13 @@ wxMacFocusHelper::~wxMacFocusHelper() { if ( m_ok ) { + SetPort( m_currentPort ) ; SetOrigin( 0 , 0 ) ; } if ( m_formerPort != m_currentPort ) SetPort( m_formerPort ) ; } - +*/ wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow ) { m_ok = false ; @@ -1861,15 +2262,18 @@ wxMacDrawingHelper::~wxMacDrawingHelper() { if ( m_ok ) { + SetPort( m_currentPort ) ; SetPenState( &m_savedPenState ) ; SetOrigin( 0 , 0 ) ; - ClipRect( &m_currentPort->portRect ) ; + Rect portRect ; + GetPortBounds( m_currentPort , &portRect ) ; + ClipRect( &portRect ) ; } if ( m_formerPort != m_currentPort ) SetPort( m_formerPort ) ; } - +/* wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow * theWindow ) { m_ok = false ; @@ -1894,11 +2298,13 @@ wxMacFocusClientHelper::~wxMacFocusClientHelper() { if ( m_ok ) { + SetPort( m_currentPort ) ; SetOrigin( 0 , 0 ) ; } if ( m_formerPort != m_currentPort ) SetPort( m_formerPort ) ; } +*/ wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow * theWindow ) { @@ -1927,9 +2333,12 @@ wxMacDrawingClientHelper::~wxMacDrawingClientHelper() { if ( m_ok ) { + SetPort( m_currentPort ) ; SetPenState( &m_savedPenState ) ; SetOrigin( 0 , 0 ) ; - ClipRect( &m_currentPort->portRect ) ; + Rect portRect ; + GetPortBounds( m_currentPort , &portRect ) ; + ClipRect( &portRect ) ; } if ( m_formerPort != m_currentPort ) diff --git a/src/mac/checkbox.cpp b/src/mac/checkbox.cpp index df3424b88f..c3d4ce9709 100644 --- a/src/mac/checkbox.cpp +++ b/src/mac/checkbox.cpp @@ -15,8 +15,10 @@ #include "wx/checkbox.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) +#endif #include diff --git a/src/mac/checklst.cpp b/src/mac/checklst.cpp index 7387e3e471..2f43152c2a 100644 --- a/src/mac/checklst.cpp +++ b/src/mac/checklst.cpp @@ -23,7 +23,9 @@ // implementation // ============================================================================ +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox) +#endif // ---------------------------------------------------------------------------- // implementation of wxCheckListBox class diff --git a/src/mac/choice.cpp b/src/mac/choice.cpp index 343f3d239e..1c36eef12d 100644 --- a/src/mac/choice.cpp +++ b/src/mac/choice.cpp @@ -17,7 +17,9 @@ #include "wx/choice.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl) +#endif bool wxChoice::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, @@ -27,13 +29,12 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - m_noStrings = n; Rect bounds ; Str255 title ; MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; - + m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0 , kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ; @@ -41,11 +42,15 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; for ( int i = 0 ; i < n ; i++ ) { - appendmenu( m_macPopUpMenuHandle , choices[i] ) ; + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; + m_strings.Add( choices[i] ) ; } SetControlMinimum( m_macControl , 0 ) ; - SetControlMaximum( m_macControl , m_noStrings) ; - SetControlValue( m_macControl , 1 ) ; + SetControlMaximum( m_macControl , Number()) ; + if ( n > 0 ) + SetControlValue( m_macControl , 1 ) ; MacPostControlCreate() ; @@ -54,27 +59,28 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, void wxChoice::Append(const wxString& item) { - appendmenu( m_macPopUpMenuHandle , item ) ; - m_noStrings ++; - SetControlMaximum( m_macControl , m_noStrings) ; + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; + m_strings.Add( item ) ; + SetControlMaximum( m_macControl , Number()) ; } void wxChoice::Delete(int n) { - wxASSERT( n < m_noStrings ) ; ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ; - m_noStrings --; - SetControlMaximum( m_macControl , m_noStrings) ; + m_strings.Remove( n ) ; + SetControlMaximum( m_macControl , Number()) ; } void wxChoice::Clear() { - for ( int i = 0 ; i < m_noStrings ; i++ ) + for ( int i = 0 ; i < Number() ; i++ ) { ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ; } - m_noStrings = 0; - SetControlMaximum( m_macControl , m_noStrings) ; + m_strings.Clear() ; + SetControlMaximum( m_macControl , Number()) ; } int wxChoice::GetSelection() const @@ -99,7 +105,7 @@ void wxChoice::SetSelection(int n) int wxChoice::FindString(const wxString& s) const { - for( int i = 0 ; i < m_noStrings ; i++ ) + for( int i = 0 ; i < Number() ; i++ ) { if ( GetString( i ) == s ) return i ; @@ -109,10 +115,7 @@ int wxChoice::FindString(const wxString& s) const wxString wxChoice::GetString(int n) const { - Str255 text ; - ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , text ) ; - p2cstr( text ) ; - return wxString( text ); + return m_strings[n] ; } void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags) diff --git a/src/mac/clipbrd.cpp b/src/mac/clipbrd.cpp index 36f4c0f4d9..ca5b793396 100644 --- a/src/mac/clipbrd.cpp +++ b/src/mac/clipbrd.cpp @@ -21,48 +21,214 @@ #include "wx/metafile.h" #include "wx/clipbrd.h" +#define wxUSE_DATAOBJ 1 + #include // open/close + +bool clipboard_opened = false ; + bool wxOpenClipboard() { + clipboard_opened = true ; return TRUE; } bool wxCloseClipboard() { + clipboard_opened = false ; return TRUE; } bool wxIsClipboardOpened() { - return TRUE; + return clipboard_opened; } -// get/set data - bool wxEmptyClipboard() { - ZeroScrap() ; + +#if TARGET_CARBON + OSStatus err ; + err = ClearCurrentScrap( ); +#else + OSErr err ; + err = ZeroScrap( ); +#endif + if ( err ) + { + wxLogSysError(_("Failed to empty the clipboard.")); + return FALSE ; + } return TRUE; } -bool wxSetClipboardData(wxDataFormat dataFormat,const void *data,int width , int height) +// get/set data + +// clipboard formats + +bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat) { - 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, dataFormat.GetFormatId(), &flavorFlags )) == noErr) + { + if (( err = GetScrapFlavorSize( scrapRef, dataFormat.GetFormatId(), &byteCount )) == noErr) + { + return TRUE ; + } + } + } + return FALSE; + +#else + long offset ; + if ( GetScrap( NULL , dataFormat.GetFormatId() , &offset ) > 0 ) + { + return TRUE ; + } + return FALSE; +#endif } -void *wxGetClipboardData(wxDataFormat dataFormat, long *len) +bool wxSetClipboardData(wxDataFormat dataFormat,const void *data,int width , int height) { - return NULL; -} +#if !TARGET_CARBON + OSErr err = noErr ; +#else + OSStatus err = noErr ; +#endif + + switch (dataFormat.GetType()) + { + case wxDF_BITMAP: + { + /* + wxBitmap *bitmap = (wxBitmap *)data; + + HDC hdcMem = CreateCompatibleDC((HDC) NULL); + HDC hdcSrc = CreateCompatibleDC((HDC) NULL); + HBITMAP old = (HBITMAP) + ::SelectObject(hdcSrc, (HBITMAP)bitmap->GetHBITMAP()); + HBITMAP hBitmap = CreateCompatibleBitmap(hdcSrc, + bitmap->GetWidth(), + bitmap->GetHeight()); + if (!hBitmap) + { + SelectObject(hdcSrc, old); + DeleteDC(hdcMem); + DeleteDC(hdcSrc); + return FALSE; + } + + HBITMAP old1 = (HBITMAP) SelectObject(hdcMem, hBitmap); + BitBlt(hdcMem, 0, 0, bitmap->GetWidth(), bitmap->GetHeight(), + hdcSrc, 0, 0, SRCCOPY); + + // Select new bitmap out of memory DC + SelectObject(hdcMem, old1); + + // Set the data + handle = ::SetClipboardData(CF_BITMAP, hBitmap); + + // Clean up + SelectObject(hdcSrc, old); + DeleteDC(hdcSrc); + DeleteDC(hdcMem); + */ + break; + } + case wxDF_DIB: + { + /* +#if wxUSE_IMAGE_LOADING_IN_MSW + wxBitmap *bitmap = (wxBitmap *)data; + HBITMAP hBitmap = (HBITMAP)bitmap->GetHBITMAP(); + // NULL palette means to use the system one + HANDLE hDIB = wxBitmapToDIB(hBitmap, (HPALETTE)NULL); + handle = SetClipboardData(CF_DIB, hDIB); +#endif // wxUSE_IMAGE_LOADING_IN_MSW +*/ + break; + } -// clipboard formats +#if wxUSE_METAFILE + case wxDF_METAFILE: + { + wxMetafile *wxMF = (wxMetafile *)data; + PicHandle pict = wxMF->GetHMETAFILE() ; + HLock( (Handle) pict ) ; +#if !TARGET_CARBON + err = PutScrap( GetHandleSize( (Handle) pict ) , 'PICT' , *pict ) ; +#else + ScrapRef scrap; + err = GetCurrentScrap (&scrap); + if ( !err ) + { + err = PutScrapFlavor (scrap, 'PICT', 0, GetHandleSize((Handle) pict), *pict); + } +#endif + HUnlock( (Handle) pict ) ; + break; + } +#endif + case wxDF_SYLK: + case wxDF_DIF: + case wxDF_TIFF: + case wxDF_PALETTE: + default: + { + wxLogError(_("Unsupported clipboard format.")); + return FALSE; + } -bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat) -{ - return FALSE; + case wxDF_OEMTEXT: + dataFormat = wxDF_TEXT; + // fall through + + case wxDF_TEXT: + { + wxString mac ; + if ( wxApp::s_macDefaultEncodingIsPC ) + { + mac = wxMacMakeMacStringFromPC((char *)data) ; + } + else + { + mac = (char *)data ; + } +#if !TARGET_CARBON + err = PutScrap( mac.Length() , 'TEXT' , mac.c_str() ) ; +#else + ScrapRef scrap; + err = GetCurrentScrap (&scrap); + if ( !err ) + { + err = PutScrapFlavor (scrap, 'TEXT', 0, mac.Length(), mac.c_str()); + } +#endif + break; + } + } + + if ( err ) + { + wxLogSysError(_("Failed to set clipboard data.")); + + return FALSE; + } + + return TRUE; } wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat) @@ -80,11 +246,17 @@ bool wxGetClipboardFormatName(wxDataFormat dataFormat, wxChar *formatName, int m return FALSE; } +void *wxGetClipboardData(wxDataFormat dataFormat, long *len) +{ + return NULL; +} + + /* * Generalized clipboard implementation by Matthew Flatt */ -IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject) +IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxClipboardBase) wxClipboard::wxClipboard() { @@ -143,9 +315,9 @@ bool wxClipboard::AddData( wxDataObject *data ) #if wxUSE_DATAOBJ wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") ); - wxDataFormat format = data->GetFormat(); + wxDataFormat format = data->GetPreferredFormat(); - switch ( format ) + switch ( format.GetType() ) { case wxDF_TEXT: case wxDF_OEMTEXT: @@ -160,10 +332,10 @@ bool wxClipboard::AddData( wxDataObject *data ) { wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data; wxBitmap bitmap(bitmapDataObject->GetBitmap()); - return wxSetClipboardData(data->GetFormat(), &bitmap); + return wxSetClipboardData(format, &bitmap); } -#if wxUSE_METAFILE +#if 0 // wxUSE_METAFILE case wxDF_METAFILE: { wxMetafileDataObject* metaFileDataObject = @@ -176,11 +348,12 @@ bool wxClipboard::AddData( wxDataObject *data ) #endif // wxUSE_METAFILE default: - return wxSetClipboardData(data); + // return wxSetClipboardData(data); + break ; } #else // !wxUSE_DATAOBJ - return FALSE; #endif + return FALSE; } void wxClipboard::Close() @@ -188,7 +361,7 @@ void wxClipboard::Close() wxCloseClipboard(); } -bool wxClipboard::IsSupported( wxDataFormat format ) +bool wxClipboard::IsSupported( const wxDataFormat &format ) { return wxIsClipboardFormatAvailable(format); } @@ -198,7 +371,7 @@ bool wxClipboard::GetData( wxDataObject& data ) #if wxUSE_DATAOBJ wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") ); - wxDataFormat format = data.GetFormat(); + wxDataFormat format = data.GetPreferredFormat(); switch ( format ) { case wxDF_TEXT: @@ -219,7 +392,7 @@ bool wxClipboard::GetData( wxDataObject& data ) case wxDF_DIB: { wxBitmapDataObject& bitmapDataObject = (wxBitmapDataObject &)data; - wxBitmap* bitmap = (wxBitmap *)wxGetClipboardData(data->GetFormat()); + wxBitmap* bitmap = (wxBitmap *)wxGetClipboardData(format ); if ( !bitmap ) return FALSE; @@ -228,7 +401,7 @@ bool wxClipboard::GetData( wxDataObject& data ) return TRUE; } -#if wxUSE_METAFILE +#if 0 // wxUSE_METAFILE case wxDF_METAFILE: { wxMetafileDataObject& metaFileDataObject = (wxMetafileDataObject &)data; diff --git a/src/mac/colordlg.cpp b/src/mac/colordlg.cpp index e91938f8ad..c6037a9f96 100644 --- a/src/mac/colordlg.cpp +++ b/src/mac/colordlg.cpp @@ -16,7 +16,9 @@ #include "wx/mac/colordlg.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog) +#endif /* * wxColourDialog diff --git a/src/mac/colour.cpp b/src/mac/colour.cpp index 68abfa77bd..cc549b5f11 100644 --- a/src/mac/colour.cpp +++ b/src/mac/colour.cpp @@ -16,7 +16,9 @@ #include "wx/gdicmn.h" #include "wx/colour.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject) +#endif // Colour diff --git a/src/mac/combobox.cpp b/src/mac/combobox.cpp index d1fd686a85..1689c15490 100644 --- a/src/mac/combobox.cpp +++ b/src/mac/combobox.cpp @@ -16,7 +16,9 @@ #include "wx/combobox.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) +#endif // right now we don't support editable comboboxes @@ -44,7 +46,9 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; for ( int i = 0 ; i < n ; i++ ) { - appendmenu( m_macPopUpMenuHandle , choices[i] ) ; + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; } SetControlMinimum( m_macControl , 0 ) ; SetControlMaximum( m_macControl , m_noStrings) ; @@ -125,7 +129,9 @@ void wxComboBox::SetSelection(long from, long to) void wxComboBox::Append(const wxString& item) { - appendmenu( m_macPopUpMenuHandle , item ) ; + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; m_noStrings ++; SetControlMaximum( m_macControl , m_noStrings) ; } diff --git a/src/mac/control.cpp b/src/mac/control.cpp index f6fa56cb91..161d1b71b1 100644 --- a/src/mac/control.cpp +++ b/src/mac/control.cpp @@ -16,15 +16,18 @@ #include "wx/control.h" #include "wx/notebook.h" #include "wx/tabctrl.h" +#include "wx/radiobox.h" #include "wx/spinbutt.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) -BEGIN_EVENT_TABLE(wxControl, wxControlBase) +BEGIN_EVENT_TABLE(wxControl, wxWindow) EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) EVT_CHAR( wxControl::OnKeyDown ) EVT_PAINT( wxControl::OnPaint ) END_EVENT_TABLE() +#endif #include @@ -32,6 +35,7 @@ END_EVENT_TABLE() ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; +pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ; pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) { if ( partCode != 0) @@ -46,9 +50,9 @@ pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCod wxControl::wxControl() { - m_macControl = NULL ; - m_macHorizontalBorder = 0 ; // additional pixels around the real control - m_macVerticalBorder = 0 ; + m_macControl = NULL ; + m_macHorizontalBorder = 0 ; // additional pixels around the real control + m_macVerticalBorder = 0 ; m_backgroundColour = *wxWHITE; m_foregroundColour = *wxBLACK; #if WXWIN_COMPATIBILITY @@ -61,6 +65,24 @@ wxControl::wxControl() } } +bool wxControl::Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos, + const wxSize& size, long style, + 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 (rval) { +#if wxUSE_VALIDATORS + SetValidator(validator); +#endif + } + return rval; +} + wxControl::~wxControl() { m_isBeingDeleted = TRUE; @@ -79,21 +101,6 @@ wxControl::~wxControl() } } -bool wxControl::Create(wxWindow *parent, wxWindowID id, - const wxPoint& pos, - const wxSize& size, long style, - const wxValidator& validator, - const wxString& name) -{ - bool rval = wxWindow::Create(parent, id, pos, size, style, name); - if (rval) { -#if wxUSE_VALIDATORS - SetValidator(validator); -#endif - } - return rval; -} - void wxControl::SetLabel(const wxString& title) { m_label = title ; @@ -222,7 +229,7 @@ void wxControl::MacPostControlCreate() { // no font } - else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) ) + else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) { ControlFontStyleRec controlstyle ; controlstyle.flags = kControlUseFontMask ; @@ -275,14 +282,16 @@ void wxControl::MacAdjustControlRect() { if ( IsKindOf( CLASSINFO( wxButton ) ) ) { - m_width = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder; + m_width = m_label.Length() * 8 + 12 ; } else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) { m_width = m_label.Length() * 8 ; } else - m_width = bestsize.right - bestsize.left + 2 * m_macHorizontalBorder; + m_width = bestsize.right - bestsize.left ; + + m_width += 2 * m_macHorizontalBorder ; } if ( m_height == -1 ) { @@ -296,7 +305,7 @@ void wxControl::MacAdjustControlRect() wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ; if ( helper.Ok() ) { - UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; + UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; } } } @@ -312,8 +321,10 @@ void wxControl::MacSuperChangedPosition() { if ( m_macControl ) { - int former_mac_x = (**m_macControl).contrlRect.left ; - int former_mac_y = (**m_macControl).contrlRect.top ; + Rect contrlRect ; + GetControlBounds( m_macControl , &contrlRect ) ; + int former_mac_x = contrlRect.left ; + int former_mac_y = contrlRect.top ; int mac_x = m_x ; int mac_y = m_y ; GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ; @@ -327,12 +338,12 @@ void wxControl::MacSuperChangedPosition() { { Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; - InvalRect( &inval ) ; + InvalWindowRect( rootwindow , &inval ) ; } - UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; + UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; { Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; - InvalRect( &inval ) ; + InvalWindowRect( rootwindow , &inval ) ; } } if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) @@ -378,7 +389,7 @@ void wxControl::MacSuperEnabled( bool enabled ) } } wxWindow::MacSuperEnabled( enabled ) ; - */ +*/ } void wxControl::MacSuperShown( bool show ) @@ -418,8 +429,10 @@ void wxControl::DoSetSize(int x, int y, int former_w = m_width ; int former_h = m_height ; - int former_mac_x = (**m_macControl).contrlRect.left ; - int former_mac_y = (**m_macControl).contrlRect.top ; + Rect contrlRect ; + GetControlBounds( m_macControl , &contrlRect ) ; + int former_mac_x = contrlRect.left ; + int former_mac_y = contrlRect.top ; int currentX, currentY; GetPosition(¤tX, ¤tY); @@ -430,9 +443,9 @@ void wxControl::DoSetSize(int x, int y, int actualHeight = height; int actualX = x; int actualY = y; - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualX = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualY = currentY; if (width == -1) actualWidth = currentW ; @@ -443,7 +456,8 @@ void wxControl::DoSetSize(int x, int y, return ; AdjustForParentClientOrigin(actualX, actualY, sizeFlags); - wxMacDrawingHelper focus( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ; + WindowRef macrootwindow = GetMacRootWindow() ; + wxMacDrawingHelper focus( wxFindWinFromMacWindow( macrootwindow ) ) ; int mac_x = actualX ; int mac_y = actualY ; @@ -453,12 +467,12 @@ void wxControl::DoSetSize(int x, int y, { { Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; - InvalRect( &inval ) ; + InvalWindowRect( macrootwindow, &inval ) ; } - UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; + UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; { Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; - InvalRect( &inval ) ; + InvalWindowRect(macrootwindow, &inval ) ; } } @@ -477,15 +491,15 @@ void wxControl::DoSetSize(int x, int y, { { Rect inval = { mac_y , mac_x , mac_y + former_h , mac_x + former_w } ; - InvalRect( &inval ) ; + InvalWindowRect( macrootwindow, &inval ) ; } m_width = actualWidth ; m_height = actualHeight ; - UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; + UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; { Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; - InvalRect( &inval ) ; + InvalWindowRect( macrootwindow , &inval ) ; } MacRepositionScrollBars() ; @@ -555,6 +569,47 @@ void wxControl::Refresh(bool eraseBack, const wxRect *rect) } } +void wxControl::MacRedrawControl() +{ + if ( m_macControl ) + { + WindowRef window = GetMacRootWindow() ; + if ( window ) + { + wxWindow* win = wxFindWinFromMacWindow( window ) ; + if ( win ) + { + wxMacDrawingHelper help( win ) ; + // the mac control manager always assumes to have the origin at 0,0 + SetOrigin( 0 , 0 ) ; + + bool hasTabBehind = false ; + wxWindow* parent = GetParent() ; + while ( parent ) + { + if( parent->MacGetWindowData() ) + { + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; + break ; + } + + if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) + { + if ( ((wxControl*)parent)->m_macControl ) + SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ; + break ; + } + + parent = parent->GetParent() ; + } + + UMADrawControl( m_macControl ) ; + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; + } + } + } +} + void wxControl::OnPaint(wxPaintEvent& event) { if ( m_macControl ) @@ -566,6 +621,7 @@ void wxControl::OnPaint(wxPaintEvent& event) if ( win ) { wxMacDrawingHelper help( win ) ; + // the mac control manager always assumes to have the origin at 0,0 SetOrigin( 0 , 0 ) ; bool hasTabBehind = false ; @@ -629,7 +685,7 @@ void wxControl::OnMouseEvent( wxMouseEvent &event ) return ; } - if (event.GetEventType() == wxEVT_LEFT_DOWN ) + if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) { int x = event.m_x ; diff --git a/src/mac/cursor.cpp b/src/mac/cursor.cpp index dee7c92b5f..fa0bbf76b2 100644 --- a/src/mac/cursor.cpp +++ b/src/mac/cursor.cpp @@ -16,17 +16,33 @@ #include "wx/cursor.h" #include "wx/icon.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxBitmap) +#endif const short kwxCursorHandId = 9 ; const short kwxCursorSizeWEId = 10 ; const short kwxCursorSizeNSId = 11 ; +#if !TARGET_CARBON Cursor* MacArrowCursorPtr = &qd.arrow ; CursHandle MacArrowCursor = &MacArrowCursorPtr ; +#else +bool MacArrowInstalled = false ; +Cursor MacArrow ; +Cursor* MacArrowCursorPtr = &MacArrow ; +CursHandle MacArrowCursor = &MacArrowCursorPtr ; +#endif CursHandle gMacCurrentCursor = NULL ; wxCursorRefData::wxCursorRefData() { +#if TARGET_CARBON + if ( !MacArrowInstalled ) + { + MacArrowCursorPtr = GetQDGlobalsArrow( &MacArrow ) ; + MacArrowInstalled = true ; + } +#endif m_width = 32; m_height = 32; m_hCursor = NULL ; @@ -34,8 +50,8 @@ wxCursorRefData::wxCursorRefData() wxCursorRefData::~wxCursorRefData() { - if ( m_hCursor && ( m_hCursor != MacArrowCursor ) ) - ::DisposeHandle( (Handle) m_hCursor ) ; +// if ( m_hCursor && ( m_hCursor != MacArrowCursor ) ) +// ::ReleaseResource( (Handle) m_hCursor ) ; } // Cursors diff --git a/src/mac/data.cpp b/src/mac/data.cpp index fab57c49fe..cb3ff34b9c 100644 --- a/src/mac/data.cpp +++ b/src/mac/data.cpp @@ -102,8 +102,8 @@ const wxChar *wxFrameNameStr = wxT("frame"); const wxChar *wxGaugeNameStr = wxT("gauge"); const wxChar *wxStaticBoxNameStr = wxT("groupBox"); const wxChar *wxListBoxNameStr = wxT("listBox"); -const wxChar *wxStaticTextNameStr = wxT("message"); -const wxChar *wxStaticBitmapNameStr = wxT("message"); +const wxChar *wxStaticTextNameStr = wxT("statictext"); +const wxChar *wxStaticBitmapNameStr = wxT("staticbitmap"); const wxChar *wxMultiTextNameStr = wxT("multitext"); const wxChar *wxPanelNameStr = wxT("panel"); const wxChar *wxRadioBoxNameStr = wxT("radioBox"); @@ -134,5 +134,17 @@ const wxChar *wxDirDialogDefaultFolderStr = wxT("/"); const wxChar *wxFloatToStringStr = wxT("%.2f"); const wxChar *wxDoubleToStringStr = wxT("%.2f"); +#if wxUSE_SHARED_LIBRARY +///// Event tables (also must be in one, statically-linked file for shared libraries) + +// This is the base, wxEvtHandler 'bootstrap' code which is expanded manually here +const wxEventTable *wxEvtHandler::GetEventTable() const { return &wxEvtHandler::sm_eventTable; } + +const wxEventTable wxEvtHandler::sm_eventTable = + { NULL, &wxEvtHandler::sm_eventTableEntries[0] }; + +const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = { { 0, 0, 0, NULL } }; +#endif + const wxSize wxDefaultSize(-1, -1); const wxPoint wxDefaultPosition(-1, -1); diff --git a/src/mac/dataobj.cpp b/src/mac/dataobj.cpp index fbaf93061d..67f938b414 100644 --- a/src/mac/dataobj.cpp +++ b/src/mac/dataobj.cpp @@ -44,56 +44,40 @@ wxDataFormat::wxDataFormat() { - m_vType = wxDF_INVALID; - m_vFormat = 0; + m_type = wxDF_INVALID; + m_format = 0; } -wxDataFormat::wxDataFormat( - wxDataFormatId vType -) +wxDataFormat::wxDataFormat( wxDataFormatId vType ) { - PrepareFormats(); SetType(vType); } -wxDataFormat::wxDataFormat( - const wxChar* zId -) +wxDataFormat::wxDataFormat( const wxChar* zId) { - PrepareFormats(); SetId(zId); } -wxDataFormat::wxDataFormat( - const wxString& rId -) +wxDataFormat::wxDataFormat( const wxString& rId) { - PrepareFormats(); SetId(rId); } -wxDataFormat::wxDataFormat( - NativeFormat vFormat -) +wxDataFormat::wxDataFormat( NativeFormat vFormat) { - PrepareFormats(); SetId(vFormat); } -void wxDataFormat::SetType( - wxDataFormatId vType -) +void wxDataFormat::SetType( wxDataFormatId Type ) { - m_vType = vType; - - if (m_vType == wxDF_TEXT) - m_vFormat = 0; - else - if (m_vType == wxDF_BITMAP) - m_vFormat = 0; - else - if (m_vType == wxDF_FILENAME) - m_vFormat = 0; + m_type = Type; + + if (m_type == wxDF_TEXT) + m_format = 'TEXT'; + else if (m_type == wxDF_BITMAP || m_type == wxDF_METAFILE ) + m_format = 'PICT'; + else if (m_type == wxDF_FILENAME) + m_format = 'SPEC'; else { wxFAIL_MSG( wxT("invalid dataformat") ); @@ -102,56 +86,37 @@ void wxDataFormat::SetType( wxDataFormatId wxDataFormat::GetType() const { - return m_vType; + return m_type; } wxString wxDataFormat::GetId() const { - wxString sRet(""); // TODO: gdk_atom_name( m_format ) ); + wxString sRet(""); // TODO: to name of ( m_format ) ); return sRet; } -void wxDataFormat::SetId( - NativeFormat vFormat -) +void wxDataFormat::SetId( NativeFormat format ) { - m_vFormat = vFormat; -// TODO: -/* - if (m_format == g_textAtom) + m_format = format; + + if (m_format == 'TEXT') m_type = wxDF_TEXT; else - if (m_format == g_pngAtom) + if (m_format == 'PICT') m_type = wxDF_BITMAP; else - if (m_format == g_fileAtom) + if (m_format == 'SPEC') m_type = wxDF_FILENAME; else m_type = wxDF_PRIVATE; -*/ } -void wxDataFormat::SetId( - const wxChar* zId -) +void wxDataFormat::SetId( const wxChar* zId ) { wxString tmp(zId); - m_vType = wxDF_PRIVATE; - m_vFormat = 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); -} - -void wxDataFormat::PrepareFormats() -{ -// TODO: -/* - if (!g_textAtom) - g_textAtom = gdk_atom_intern( "STRING", FALSE ); - if (!g_pngAtom) - g_pngAtom = gdk_atom_intern( "image/png", FALSE ); - if (!g_fileAtom) - g_fileAtom = gdk_atom_intern( "file:ALL", FALSE ); -*/ + m_type = wxDF_PRIVATE; + m_format = 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); } //------------------------------------------------------------------------- diff --git a/src/mac/dc.cpp b/src/mac/dc.cpp index ecbb3ca703..1682209492 100644 --- a/src/mac/dc.cpp +++ b/src/mac/dc.cpp @@ -14,8 +14,11 @@ #endif #include "wx/dc.h" +#include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) +#endif //----------------------------------------------------------------------------- // constants @@ -34,7 +37,7 @@ long wxDC::m_macCurrentPortId = 1 ; // wxDC //----------------------------------------------------------------------------- -wxDC::wxDC(void) +wxDC::wxDC() { m_ok = FALSE; m_optimize = FALSE; @@ -42,8 +45,8 @@ wxDC::wxDC(void) m_colour = TRUE; m_clipping = FALSE; - m_mm_to_pix_x = 1.0; - m_mm_to_pix_y = 1.0; + m_mm_to_pix_x = mm2pt; + m_mm_to_pix_y = mm2pt; m_logicalOriginX = 0; m_logicalOriginY = 0; @@ -102,20 +105,32 @@ wxDC::wxDC(void) wxDC::~wxDC(void) { + if ( !m_macPortHelper.IsCleared() ) + { + GrafPtr port ; + GetPort( &port ) ; + SetPort( m_macPortHelper.GetCurrentPort() ) ; + SetOrigin( 0 , 0 ) ; + SetPort( port ) ; + } + /* if ( m_macPort ) { + ::SetPort( m_macPort ) ; ::SetOrigin( 0 , 0 ) ; ::ClipRect( &m_macPort->portRect ) ; ::PenNormal() ; ::SetPort( m_macOrigPort ) ; } + */ ++m_macCurrentPortId ; }; void wxDC::MacSetupPort() const { + AGAPortHelper* help = &m_macPortHelper ; + help->Setup( m_macPort ) ; m_macPortId = ++m_macCurrentPortId ; - ::SetPort(m_macPort); ::SetOrigin(-m_macLocalOrigin.h, -m_macLocalOrigin.v); ::ClipRect(&m_macClipRect); @@ -124,8 +139,10 @@ void wxDC::MacSetupPort() const m_macPenInstalled = false ; } -void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) +void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ) { + float scale = 1.0 ; + if (!Ok()) return; MacVerifySetup() ; @@ -140,7 +157,7 @@ void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) { if ( bmap->m_bitmapType == kMacBitmapTypePict ) { - Rect bitmaprect = { 0 , 0 , bmap->m_height , bmap->m_width } ; + Rect bitmaprect = { 0 , 0 , bmap->m_height * scale , bmap->m_width * scale} ; ::OffsetRect( &bitmaprect , xx1 , yy1 ) ; ::DrawPicture( bmap->m_hPict , &bitmaprect ) ; } @@ -165,20 +182,21 @@ void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) source.bottom = bmap->m_height ; dest.top = YLOG2DEV(y) ; dest.left = XLOG2DEV(x) ; - dest.bottom = YLOG2DEV(y + bmap->m_height ) ; - dest.right = XLOG2DEV(x + bmap->m_width ) ; + dest.bottom = YLOG2DEV(y + bmap->m_height * scale) ; + dest.right = XLOG2DEV(x + bmap->m_width * scale ) ; if ( useMask && bmp.GetMask() ) { if ( LockPixels( GetGWorldPixMap( bmp.GetMask()->GetMaskBitmap( ) ) ) ) { - CopyMask( &GrafPtr( bmapworld )->portBits , &GrafPtr( bmp.GetMask()->GetMaskBitmap( ) )->portBits , &GrafPtr( m_macPort )->portBits , + CopyMask( GetPortBitMapForCopyBits( bmapworld ) , GetPortBitMapForCopyBits( bmp.GetMask()->GetMaskBitmap( ) ) , + GetPortBitMapForCopyBits( m_macPort ) , &source, &source , &dest ) ; UnlockPixels( GetGWorldPixMap( bmp.GetMask()->GetMaskBitmap( ) ) ) ; } } else - CopyBits( &GrafPtr( bmapworld )->portBits , &GrafPtr( m_macPort )->portBits , + CopyBits( GetPortBitMapForCopyBits( bmapworld ) , GetPortBitMapForCopyBits( m_macPort ), &source, &dest, srcCopy, NULL ) ; UnlockPixels( bmappixels ) ; @@ -192,7 +210,7 @@ void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) } } -void wxDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask ) +void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) { if (!Ok()) return; @@ -213,69 +231,9 @@ void wxDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask ) } }; -void wxDC::DrawPoint( wxPoint& point ) -{ - DrawPoint( point.x, point.y ); -}; - -void wxDC::DrawPolygon( wxList *list, long xoffset, long yoffset, int fillStyle ) -{ - int n = list->Number(); - wxPoint *points = new wxPoint[n]; - - int i = 0; - for( wxNode *node = list->First(); node; node = node->Next() ) - { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - }; - DrawPolygon( n, points, xoffset, yoffset, fillStyle ); - delete[] points; -}; - -void wxDC::DrawLines( wxList *list, long xoffset, long yoffset ) -{ - int n = list->Number(); - wxPoint *points = new wxPoint[n]; - - int i = 0; - for( wxNode *node = list->First(); node; node = node->Next() ) - { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - }; - DrawLines( n, points, xoffset, yoffset ); - delete []points; -}; - -void wxDC::DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 ) +void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) { - wxList list; - list.Append( (wxObject*)new wxPoint(x1, y1) ); - list.Append( (wxObject*)new wxPoint(x2, y2) ); - list.Append( (wxObject*)new wxPoint(x3, y3) ); - DrawSpline(&list); - wxNode *node = list.First(); - while (node) - { - wxPoint *p = (wxPoint*)node->Data(); - delete p; - node = node->Next(); - }; -}; - -void wxDC::DrawSpline( int n, wxPoint points[] ) -{ - wxList list; - for (int i = 0; i < n; i++) list.Append( (wxObject*)&points[i] ); - DrawSpline( &list ); -}; - -void wxDC::SetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) -{ - MacVerifySetup() ; + MacVerifySetup() ; if( m_clipping ) { m_clipX1 = wxMax( m_clipX1 , x ) ; @@ -300,13 +258,24 @@ void wxDC::SetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord heigh Rect clip = { y1 , x1 , y2 , x2 } ; - ::ClipRect( &clip ) ; + ::ClipRect( &clip ) ; }; -void wxDC::SetClippingRegion(const wxRect& rect) -{ - SetClippingRegion(rect.x, rect.y, rect.width, rect.height); +void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) +{ + wxCHECK_RET( Ok(), wxT("invalid window dc") ); + + MacVerifySetup() ; + if (region.Empty()) + { + DestroyClippingRegion(); + return; + } + + wxCoord xx, yy, ww, hh; + region.GetBox( xx, yy, ww, hh ); + wxDC::DoSetClippingRegion( xx, yy, ww, hh ); } void wxDC::DestroyClippingRegion(void) @@ -316,48 +285,14 @@ void wxDC::DestroyClippingRegion(void) // Rect clip = { -32000 , -32000 , 32000 , 32000 } ; ::ClipRect(&m_macClipRect); }; - -void wxDC::GetClippingBox( wxCoord *x, wxCoord *y, wxCoord *width, wxCoord *height ) const -{ - if (m_clipping) - { - if (x) *x = m_clipX1; - if (y) *y = m_clipY1; - if (width) *width = (m_clipX2 - m_clipX1); - if (height) *height = (m_clipY2 - m_clipY1); - } - else - *x = *y = *width = *height = 0; -}; - -void wxDC::GetClippingBox( long *x, long *y, long *width, long *height ) const -{ - if (m_clipping) - { - if (x) *x = m_clipX1; - if (y) *y = m_clipY1; - if (width) *width = (m_clipX2 - m_clipX1); - if (height) *height = (m_clipY2 - m_clipY1); - } - else - *x = *y = *width = *height = 0; -}; - -void wxDC::GetClippingBox(wxRect& rect) const -{ - // Necessary to use intermediate variables for 16-bit compilation - wxCoord x, y, w, h; - GetClippingBox(&x, &y, &w, &h); - rect.x = x; rect.y = y; rect.width = w; rect.height = h; -} -void wxDC::GetSize( int* width, int* height ) const +void wxDC::DoGetSize( int* width, int* height ) const { *width = m_maxX-m_minX; *height = m_maxY-m_minY; }; -void wxDC::GetSizeMM( long* width, long* height ) const +void wxDC::DoGetSizeMM( int* width, int* height ) const { int w = 0; int h = 0; @@ -416,12 +351,6 @@ void wxDC::SetUserScale( double x, double y ) ComputeScaleAndOrigin(); }; -void wxDC::GetUserScale( double *x, double *y ) -{ - if (x) *x = m_userScaleX; - if (y) *y = m_userScaleY; -}; - void wxDC::SetLogicalScale( double x, double y ) { // allow negative ? @@ -430,40 +359,20 @@ void wxDC::SetLogicalScale( double x, double y ) ComputeScaleAndOrigin(); }; -void wxDC::GetLogicalScale( double *x, double *y ) -{ - if (x) *x = m_logicalScaleX; - if (y) *y = m_logicalScaleY; -}; - -void wxDC::SetLogicalOrigin( long x, long y ) +void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) { m_logicalOriginX = x * m_signX; // is this still correct ? m_logicalOriginY = y * m_signY; ComputeScaleAndOrigin(); }; -void wxDC::GetLogicalOrigin( long *x, long *y ) -{ - if (x) *x = m_logicalOriginX; - if (y) *y = m_logicalOriginY; -}; - -void wxDC::SetDeviceOrigin( long x, long y ) +void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) { m_externalDeviceOriginX = x; m_externalDeviceOriginY = y; ComputeScaleAndOrigin(); }; - -void wxDC::GetDeviceOrigin( long *x, long *y ) -{ -// if (x) *x = m_externalDeviceOriginX; -// if (y) *y = m_externalDeviceOriginY; - if (x) *x = m_deviceOriginX; - if (y) *y = m_deviceOriginY; -}; - +/* void wxDC::SetInternalDeviceOrigin( long x, long y ) { m_internalDeviceOriginX = x; @@ -476,53 +385,14 @@ void wxDC::GetInternalDeviceOrigin( long *x, long *y ) if (x) *x = m_internalDeviceOriginX; if (y) *y = m_internalDeviceOriginY; }; - +*/ void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) { m_signX = (xLeftRight ? 1 : -1); m_signY = (yBottomUp ? -1 : 1); ComputeScaleAndOrigin(); }; - -long wxDC::DeviceToLogicalX(long x) const -{ - return XDEV2LOG(x); -}; - -long wxDC::DeviceToLogicalY(long y) const -{ - return YDEV2LOG(y); -}; - -long wxDC::DeviceToLogicalXRel(long x) const -{ - return XDEV2LOGREL(x); -}; - -long wxDC::DeviceToLogicalYRel(long y) const -{ - return YDEV2LOGREL(y); -}; - -long wxDC::LogicalToDeviceX(long x) const -{ - return XLOG2DEV(x); -}; - -long wxDC::LogicalToDeviceY(long y) const -{ - return YLOG2DEV(y); -}; - -long wxDC::LogicalToDeviceXRel(long x) const -{ - return XLOG2DEVREL(x); -}; - -long wxDC::LogicalToDeviceYRel(long y) const -{ - return YLOG2DEVREL(y); -}; +/* void wxDC::CalcBoundingBox( long x, long y ) { @@ -531,6 +401,16 @@ void wxDC::CalcBoundingBox( long x, long y ) if (x > m_maxX) m_maxX = x; if (y > m_maxY) m_maxY = y; }; +*/ +wxSize wxDC::GetPPI() const +{ + return wxSize(72, 72); +} + +int wxDC::GetDepth() const +{ + return wxDisplayDepth() ; +} void wxDC::ComputeScaleAndOrigin(void) { @@ -547,12 +427,7 @@ void wxDC::ComputeScaleAndOrigin(void) // CMB: if scale has changed call SetPen to recalulate the line width if (m_scaleX != origScaleX || m_scaleY != origScaleY) { - // this is a bit artificial, but we need to force wxDC to think - // the pen has changed - wxPen* pen = & GetPen(); - wxPen tempPen; - m_pen = tempPen; - SetPen(* pen); + // TODO : set internal flags for recalc } }; @@ -634,16 +509,17 @@ void wxDC::SetLogicalFunction( int function ) m_macPenInstalled = false ; } -void wxDC::FloodFill( long x1, long y1, const wxColour& col, int style ) +void wxDC::DoFloodFill( wxCoord x, wxCoord y, const wxColour& col, + int style ) { } -bool wxDC::GetPixel( long x1, long y1, wxColour *col ) const +bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const { return true ; } -void wxDC::DrawLine( long x1, long y1, long x2, long y2 ) +void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) { if (!Ok()) return; @@ -664,19 +540,22 @@ void wxDC::DrawLine( long x1, long y1, long x2, long y2 ) }; } -void wxDC::CrossHair( long x, long y ) +void wxDC::DoCrossHair( wxCoord x, wxCoord y ) { } -void wxDC::DrawArc( long x1, long y1, long x2, long y2, long xc, long yc ) +void wxDC::DoDrawArc( wxCoord x1, wxCoord y1, + wxCoord x2, wxCoord y2, + wxCoord xc, wxCoord yc ) { } -void wxDC::DrawEllipticArc( long x, long y, long width, long height, double sa, double ea ) +void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, + double sa, double ea ) { } -void wxDC::DrawPoint( long x, long y ) +void wxDC::DoDrawPoint( wxCoord x, wxCoord y ) { if (!Ok()) return; @@ -694,7 +573,8 @@ void wxDC::DrawPoint( long x, long y ) }; } -void wxDC::DrawLines( int n, wxPoint points[], long xoffset , long yoffset ) +void wxDC::DoDrawLines(int n, wxPoint points[], + wxCoord xoffset, wxCoord yoffset) { if (!Ok()) return; @@ -719,8 +599,9 @@ void wxDC::DrawLines( int n, wxPoint points[], long xoffset , long yoffset ) } } -void wxDC::DrawPolygon( int n, wxPoint points[], long xoffset , long yoffset , - int fillStyle ) +void wxDC::DoDrawPolygon(int n, wxPoint points[], + wxCoord xoffset, wxCoord yoffset, + int fillStyle ) { if (!Ok()) return; @@ -754,7 +635,7 @@ void wxDC::DrawPolygon( int n, wxPoint points[], long xoffset , long yoffset , KillPoly( polygon ) ; } -void wxDC::DrawRectangle( long x, long y, long width, long height ) +void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { if (!Ok()) return; @@ -797,7 +678,9 @@ void wxDC::DrawRectangle( long x, long y, long width, long height ) }; } -void wxDC::DrawRoundedRectangle( long x, long y, long width, long height, double radius ) +void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, + wxCoord width, wxCoord height, + double radius) { if (!Ok()) return; @@ -843,7 +726,7 @@ void wxDC::DrawRoundedRectangle( long x, long y, long width, long height, doubl }; } -void wxDC::DrawEllipse( long x, long y, long width, long height ) +void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { if (!Ok()) return; @@ -1001,7 +884,7 @@ static void wx_spline_draw_point_array(wxDC *dc) } } -void wxDC::DrawSpline( wxList *points ) +void wxDC::DoDrawSpline(wxList *points) { wxPoint *p; double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; @@ -1059,8 +942,8 @@ bool wxDC::CanDrawBitmap(void) const } -bool wxDC::Blit( long xdest, long ydest, long width, long height, - wxDC *source, long xsrc, long ysrc, int logical_func , bool useMask ) +bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, + wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask ) { if (!Ok()) return FALSE; MacVerifySetup() ; @@ -1069,8 +952,8 @@ bool wxDC::Blit( long xdest, long ydest, long width, long height, PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ; RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ; RGBColor black = { 0,0,0} ; - RGBForeColor( &m_textForegroundColour.GetPixel() ) ; - RGBBackColor( &m_textBackgroundColour.GetPixel() ) ; + RGBForeColor( &m_textForegroundColour.GetPixel() ) ; + RGBBackColor( &m_textBackgroundColour.GetPixel() ) ; if ( LockPixels(bmappixels) ) { @@ -1094,7 +977,7 @@ bool wxDC::Blit( long xdest, long ydest, long width, long height, logical_func == wxXOR ? srcXor : // logical_func == wxOR_REVERSE ? MERGEPAINT : // logical_func == wxAND_REVERSE ? SRCERASE : - logical_func == wxSRC_OR ? srcOr : + // logical_func == wxSRC_OR ? srcOr : // logical_func == wxSRC_AND ? SRCAND : srcCopy ); @@ -1103,14 +986,15 @@ bool wxDC::Blit( long xdest, long ydest, long width, long height, wxASSERT( mode == srcCopy ) ; if ( LockPixels( GetGWorldPixMap( source->m_macMask ) ) ) { - CopyMask( &GrafPtr( sourcePort )->portBits , &GrafPtr( source->m_macMask )->portBits , &GrafPtr( m_macPort )->portBits , + CopyMask( GetPortBitMapForCopyBits( sourcePort ) , GetPortBitMapForCopyBits( source->m_macMask ) , + GetPortBitMapForCopyBits( m_macPort ) , &srcrect, &srcrect , &dstrect ) ; UnlockPixels( GetGWorldPixMap( source->m_macMask ) ) ; } } else { - CopyBits( &GrafPtr( sourcePort )->portBits , &GrafPtr( m_macPort )->portBits , + CopyBits( GetPortBitMapForCopyBits( sourcePort ) , GetPortBitMapForCopyBits( m_macPort ) , &srcrect, &dstrect, mode, NULL ) ; } UnlockPixels( bmappixels ) ; @@ -1123,7 +1007,11 @@ bool wxDC::Blit( long xdest, long ydest, long width, long height, return TRUE; } -void wxDC::DrawText( const wxString &string, long x, long y, bool use16) +void wxDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, + double angle) +{ +} +void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) { if (!Ok()) return; @@ -1161,14 +1049,14 @@ void wxDC::DrawText( const wxString &string, long x, long y, bool use16) if ( wxApp::s_macDefaultEncodingIsPC ) { - macText = wxMacMakeMacStringFromPC( string ) ; + macText = wxMacMakeMacStringFromPC( strtext ) ; text = macText ; length = macText.Length() ; } else { - text = string ; - length = string.Length() ; + text = strtext ; + length = strtext.Length() ; } int laststop = 0 ; @@ -1200,9 +1088,9 @@ bool wxDC::CanGetTextExtent(void) const return true ; } -void wxDC::GetTextExtent( const wxString &string, long *width, long *height, - long *descent, long *externalLeading , - wxFont *theFont , bool use16 ) const +void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *height, + wxCoord *descent, wxCoord *externalLeading , + wxFont *theFont ) const { if (!Ok()) return; @@ -1217,11 +1105,8 @@ void wxDC::GetTextExtent( const wxString &string, long *width, long *height, if ( font ) { - long yy1 = YLOG2DEV(0); - long yy2 = YLOG2DEV(font->m_macFontSize); - ::TextFont( font->m_macFontNum ) ; - ::TextSize( abs( yy2-yy1) ) ; + ::TextSize( YLOG2DEVREL( font->m_macFontSize) ) ; ::TextFace( font->m_macFontStyle ) ; } } @@ -1233,9 +1118,12 @@ void wxDC::GetTextExtent( const wxString &string, long *width, long *height, FontInfo fi ; ::GetFontInfo( &fi ) ; - *height = fi.descent + fi.ascent ; - *descent = fi.descent ; - *externalLeading = fi.leading ; + if ( height ) + *height = YDEV2LOGREL( fi.descent + fi.ascent ) ; + if ( descent ) + *descent =YDEV2LOGREL( fi.descent ); + if ( externalLeading ) + *externalLeading = YDEV2LOGREL( fi.leading ) ; const char *text = NULL ; int length = 0 ; @@ -1255,24 +1143,28 @@ void wxDC::GetTextExtent( const wxString &string, long *width, long *height, int laststop = 0 ; int i = 0 ; int curwidth = 0 ; - *width = 0 ; - - while( i < length ) + if ( width ) { - if( text[i] == 13 || text[i] == 10) + *width = 0 ; + + while( i < length ) { - *height += fi.descent + fi.ascent + fi.leading; - curwidth = ::TextWidth( text , laststop , i - laststop ) ; - if ( curwidth > *width ) - *width = curwidth ; - laststop = i+1 ; + if( text[i] == 13 || text[i] == 10) + { + if ( height ) + *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ; + curwidth = ::TextWidth( text , laststop , i - laststop ) ; + if ( curwidth > *width ) + *width = XDEV2LOGREL( curwidth ) ; + laststop = i+1 ; + } + i++ ; } - i++ ; + + curwidth = ::TextWidth( text , laststop , i - laststop ) ; + if ( curwidth > *width ) + *width = XDEV2LOGREL( curwidth ) ; } - - curwidth = ::TextWidth( text , laststop , i - laststop ) ; - if ( curwidth > *width ) - *width = curwidth ; if ( theFont ) { @@ -1292,7 +1184,7 @@ wxCoord wxDC::GetCharWidth(void) const FontInfo fi ; ::GetFontInfo( &fi ) ; - return (fi.descent + fi.ascent) / 2 ; + return YDEV2LOGREL((fi.descent + fi.ascent) / 2) ; } wxCoord wxDC::GetCharHeight(void) const @@ -1307,7 +1199,7 @@ wxCoord wxDC::GetCharHeight(void) const FontInfo fi ; ::GetFontInfo( &fi ) ; - return fi.descent + fi.ascent ; + return YDEV2LOGREL( fi.descent + fi.ascent ); } void wxDC::Clear(void) @@ -1332,7 +1224,8 @@ void wxDC::MacInstallFont() const if ( m_macFontInstalled ) return ; - + Pattern blackColor ; + wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; if ( font ) @@ -1377,7 +1270,7 @@ void wxDC::MacInstallFont() const mode = patCopy ; break ; case wxINVERT: // NOT dst - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); mode = patXor ; break ; case wxXOR: // src XOR dst @@ -1403,8 +1296,8 @@ void wxDC::MacInstallFont() const case wxNAND: // (NOT src) OR (NOT dst) case wxOR: // src OR dst case wxSET: // 1 - case wxSRC_OR: // source _bitmap_ OR destination - case wxSRC_AND: // source _bitmap_ AND destination +// case wxSRC_OR: // source _bitmap_ OR destination +// case wxSRC_AND: // source _bitmap_ AND destination break ; } ::PenMode( mode ) ; @@ -1447,6 +1340,8 @@ void wxDC::MacInstallPen() const return; MacVerifySetup() ; + Pattern blackColor; + if ( m_macPenInstalled ) return ; @@ -1460,7 +1355,7 @@ void wxDC::MacInstallPen() const int penStyle = m_pen.GetStyle(); if (penStyle == wxSOLID) - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); else if (IS_HATCH(penStyle)) { Pattern pat ; @@ -1469,7 +1364,7 @@ void wxDC::MacInstallPen() const } else { - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); } short mode = patCopy ; @@ -1482,7 +1377,7 @@ void wxDC::MacInstallPen() const mode = patCopy ; break ; case wxINVERT: // NOT dst - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); mode = patXor ; break ; case wxXOR: // src XOR dst @@ -1508,8 +1403,8 @@ void wxDC::MacInstallPen() const case wxNAND: // (NOT src) OR (NOT dst) case wxOR: // src OR dst case wxSET: // 1 - case wxSRC_OR: // source _bitmap_ OR destination - case wxSRC_AND: // source _bitmap_ AND destination +// case wxSRC_OR: // source _bitmap_ OR destination +// case wxSRC_AND: // source _bitmap_ AND destination break ; } ::PenMode( mode ) ; @@ -1523,7 +1418,7 @@ void wxDC::MacInstallBrush() const if (!Ok()) return; MacVerifySetup() ; - + Pattern blackColor, whiteColor ; if ( m_macBrushInstalled ) return ; @@ -1534,7 +1429,7 @@ void wxDC::MacInstallBrush() const int brushStyle = m_brush.GetStyle(); if (brushStyle == wxSOLID) - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); else if (IS_HATCH(brushStyle)) { Pattern pat ; @@ -1543,7 +1438,7 @@ void wxDC::MacInstallBrush() const } else { - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); } @@ -1551,7 +1446,7 @@ void wxDC::MacInstallBrush() const brushStyle = m_backgroundBrush.GetStyle(); if (brushStyle == wxSOLID) - ::BackPat(&qd.white); + ::BackPat(GetQDGlobalsWhite(&whiteColor)); else if (IS_HATCH(brushStyle)) { Pattern pat ; @@ -1560,7 +1455,7 @@ void wxDC::MacInstallBrush() const } else { - ::BackPat(&qd.white); + ::BackPat(GetQDGlobalsWhite(&whiteColor)); } short mode = patCopy ; @@ -1573,7 +1468,7 @@ void wxDC::MacInstallBrush() const mode = patCopy ; break ; case wxINVERT: // NOT dst - ::PenPat(&qd.black); + ::PenPat(GetQDGlobalsBlack(&blackColor)); mode = patXor ; break ; case wxXOR: // src XOR dst @@ -1599,8 +1494,8 @@ void wxDC::MacInstallBrush() const case wxNAND: // (NOT src) OR (NOT dst) case wxOR: // src OR dst case wxSET: // 1 - case wxSRC_OR: // source _bitmap_ OR destination - case wxSRC_AND: // source _bitmap_ AND destination +// case wxSRC_OR: // source _bitmap_ OR destination +// case wxSRC_AND: // source _bitmap_ AND destination break ; } ::PenMode( mode ) ; @@ -1609,4 +1504,47 @@ void wxDC::MacInstallBrush() const m_macFontInstalled = false ; } +// --------------------------------------------------------------------------- +// coordinates transformations +// --------------------------------------------------------------------------- + +wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const +{ + return ((wxDC *)this)->XDEV2LOG(x); +} + +wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const +{ + return ((wxDC *)this)->YDEV2LOG(y); +} + +wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const +{ + return ((wxDC *)this)->XDEV2LOGREL(x); +} + +wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const +{ + return ((wxDC *)this)->YDEV2LOGREL(y); +} + +wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const +{ + return ((wxDC *)this)->XLOG2DEV(x); +} + +wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const +{ + return ((wxDC *)this)->YLOG2DEV(y); +} + +wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const +{ + return ((wxDC *)this)->XLOG2DEVREL(x); +} + +wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const +{ + return ((wxDC *)this)->YLOG2DEVREL(y); +} diff --git a/src/mac/dcclient.cpp b/src/mac/dcclient.cpp index 12100b81cd..6f3a6b3517 100644 --- a/src/mac/dcclient.cpp +++ b/src/mac/dcclient.cpp @@ -28,9 +28,11 @@ // wxPaintDC //----------------------------------------------------------------------------- +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) +#endif /* * wxWindowDC @@ -38,11 +40,11 @@ IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) #include -wxWindowDC::wxWindowDC(void) +wxWindowDC::wxWindowDC() { } -wxWindowDC::wxWindowDC(wxWindow *the_canvas) +wxWindowDC::wxWindowDC(wxWindow *the_canvas) { WindowRef windowref ; wxWindow* rootwindow ; @@ -51,11 +53,16 @@ wxWindowDC::wxWindowDC(wxWindow *the_canvas) the_canvas->MacGetPortParams(&m_macLocalOrigin, &m_macClipRect , &windowref , &rootwindow ); m_macPort = UMAGetWindowPort( windowref ) ; + m_minY = m_minX = 0; + wxSize size = the_canvas->GetSize() ; + m_maxX = size.x ; + m_maxY = size.y ; + MacSetupPort() ; m_ok = TRUE ; } -wxWindowDC::~wxWindowDC(void) +wxWindowDC::~wxWindowDC() { } @@ -63,7 +70,7 @@ wxWindowDC::~wxWindowDC(void) * wxClientDC */ -wxClientDC::wxClientDC(void) +wxClientDC::wxClientDC() { } @@ -75,12 +82,16 @@ wxClientDC::wxClientDC(wxWindow *window) window->MacGetPortClientParams(&m_macLocalOrigin, &m_macClipRect , &windowref , &rootwindow ); m_macPort = UMAGetWindowPort( windowref ) ; MacSetupPort() ; + m_minY = m_minX = 0; + wxSize size = window->GetSize() ; + m_maxX = size.x ; + m_maxY = size.y ; m_ok = TRUE ; SetBackground(wxBrush(window->GetBackgroundColour(), wxSOLID)); SetFont( window->GetFont() ) ; } -wxClientDC::~wxClientDC(void) +wxClientDC::~wxClientDC() { } @@ -88,7 +99,7 @@ wxClientDC::~wxClientDC(void) * wxPaintDC */ -wxPaintDC::wxPaintDC(void) +wxPaintDC::wxPaintDC() { } @@ -104,6 +115,10 @@ wxPaintDC::wxPaintDC(wxWindow *window) m_ok = TRUE ; long x , y ,w , h ; window->GetUpdateRegion().GetBox( x , y , w , h ) ; + m_minY = m_minX = 0; + wxSize size = window->GetSize() ; + m_maxX = size.x ; + m_maxY = size.y ; SetClippingRegion( x , y , w , h ) ; SetBackground(wxBrush(window->GetBackgroundColour(), wxSOLID)); SetFont(window->GetFont() ) ; diff --git a/src/mac/dcmemory.cpp b/src/mac/dcmemory.cpp index fe88bf806c..a56c7b5c49 100644 --- a/src/mac/dcmemory.cpp +++ b/src/mac/dcmemory.cpp @@ -33,10 +33,20 @@ wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) ) wxMemoryDC::~wxMemoryDC(void) { + if ( m_selected.Ok() ) + { + wxBitmapRefData * bmap = (wxBitmapRefData*) (m_selected.GetRefData()) ; + UnlockPixels( GetGWorldPixMap( (CGrafPtr) bmap->m_hBitmap ) ) ; + } }; void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) { + if ( m_selected.Ok() ) + { + wxBitmapRefData * bmap = (wxBitmapRefData*) (m_selected.GetRefData()) ; + UnlockPixels( GetGWorldPixMap( (CGrafPtr) bmap->m_hBitmap ) ) ; + } m_selected = bitmap; if (m_selected.Ok()) { @@ -44,6 +54,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) if ( bmap->m_hBitmap ) { m_macPort = (GrafPtr) bmap->m_hBitmap ; + LockPixels( GetGWorldPixMap( (CGrafPtr) m_macPort ) ) ; wxMask * mask = bitmap.GetMask() ; if ( mask ) { diff --git a/src/mac/dcprint.cpp b/src/mac/dcprint.cpp index 449f44e206..257c74206b 100644 --- a/src/mac/dcprint.cpp +++ b/src/mac/dcprint.cpp @@ -25,31 +25,36 @@ #include "wx/dcprint.h" #include "math.h" +#include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_CLASS(wxPrinterDC, wxDC) +#endif GrafPtr macPrintFormerPort = NULL ; wxPrinterDC::wxPrinterDC(const wxPrintData& printdata) { +#if !TARGET_CARBON OSErr err ; wxString message ; m_printData = printdata ; m_printData.ConvertToNative() ; - ::PrOpen() ; + ::UMAPrOpen() ; err = PrError() ; if ( err ) { message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; - PrClose() ; + UMAPrClose() ; } if ( ::PrValidate( m_printData.m_macPrintInfo ) ) { + ::PrStlDialog( m_printData.m_macPrintInfo ) ; // the driver has changed in the mean time, should we pop up a page setup dialog ? } err = PrError() ; @@ -57,20 +62,31 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata) { message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; - PrClose() ; + UMAPrClose() ; } ::GetPort( &macPrintFormerPort ) ; m_macPrintPort = ::PrOpenDoc( m_printData.m_macPrintInfo , NULL , NULL ) ; + err = PrError() ; + if ( err ) + { + message.Printf( "Print Error %d", err ) ; + wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; + UMAPrClose() ; + } // sets current port m_macPort = (GrafPtr ) m_macPrintPort ; m_ok = TRUE ; m_minY = m_minX = 0 ; m_maxX = (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ; m_maxY = (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ; +#else +#pragma warning "TODO:printing support for carbon" +#endif } wxPrinterDC::~wxPrinterDC(void) { +#if !TARGET_CARBON if ( m_ok ) { OSErr err ; @@ -91,11 +107,16 @@ wxPrinterDC::~wxPrinterDC(void) { message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; - PrClose() ; + UMAPrClose() ; } - ::PrClose() ; - ::SetPort( macPrintFormerPort ) ; + ::UMAPrClose() ; +// ::SetPort( macPrintFormerPort ) ; + ::SetPort( LMGetWMgrPort() ) ; + m_macPortHelper.Clear() ; } +#else +#pragma warning "TODO:printing support for carbon" +#endif } bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) ) @@ -109,13 +130,30 @@ void wxPrinterDC::EndDoc(void) void wxPrinterDC::StartPage(void) { +#if !TARGET_CARBON if ( !m_ok ) return ; + + m_logicalFunction = wxCOPY; +// m_textAlignment = wxALIGN_TOP_LEFT; + m_backgroundMode = wxTRANSPARENT; + + m_textForegroundColour = *wxBLACK; + m_textBackgroundColour = *wxWHITE; + m_pen = *wxBLACK_PEN; + m_font = *wxNORMAL_FONT; + m_brush = *wxTRANSPARENT_BRUSH; + m_backgroundBrush = *wxWHITE_BRUSH; + + m_macFontInstalled = false ; + m_macBrushInstalled = false ; + m_macPenInstalled = false ; + OSErr err ; wxString message ; - PrOpenPage( m_macPrintPort , NULL ) ; + PrOpenPage( m_macPrintPort , NULL ) ; SetOrigin( - (**m_printData.m_macPrintInfo).rPaper.left , - (**m_printData.m_macPrintInfo).rPaper.top ) ; Rect clip = { -32000 , -32000 , 32000 , 32000 } ; ::ClipRect( &clip ) ; @@ -126,14 +164,18 @@ void wxPrinterDC::StartPage(void) wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; ::PrClosePage( m_macPrintPort) ; ::PrCloseDoc( m_macPrintPort ) ; - ::PrClose() ; + ::UMAPrClose() ; ::SetPort( macPrintFormerPort ) ; m_ok = FALSE ; } +#else +#pragma warning "TODO:printing support for carbon" +#endif } void wxPrinterDC::EndPage(void) { +#if !TARGET_CARBON if ( !m_ok ) return ; @@ -147,8 +189,12 @@ void wxPrinterDC::EndPage(void) message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; ::PrCloseDoc( m_macPrintPort ) ; - ::PrClose() ; + ::UMAPrClose() ; ::SetPort( macPrintFormerPort ) ; m_ok = FALSE ; } +#else +#pragma warning "TODO:printing support for carbon" +#endif + } diff --git a/src/mac/dcscreen.cpp b/src/mac/dcscreen.cpp index 1d802afba4..c47126248e 100644 --- a/src/mac/dcscreen.cpp +++ b/src/mac/dcscreen.cpp @@ -14,15 +14,34 @@ #endif #include "wx/dcscreen.h" +#include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC) +#endif // Create a DC representing the whole screen wxScreenDC::wxScreenDC() { +#if TARGET_CARBON + m_macPort = GetQDGlobalsThePort() ; +#else m_macPort = LMGetWMgrPort() ; +#endif MacSetupPort() ; m_ok = TRUE ; + BitMap screenBits; + GetQDGlobalsScreenBits( &screenBits ); + m_minX = screenBits.bounds.left ; + #if TARGET_CARBON + SInt16 height ; + GetThemeMenuBarHeight( &height ) ; + m_minY = screenBits.bounds.top + height ; + #else + m_minY = screenBits.bounds.top + LMGetMBarHeight() ; + #endif + m_maxX = screenBits.bounds.right ; + m_maxY = screenBits.bounds.bottom ; } wxScreenDC::~wxScreenDC() diff --git a/src/mac/dialog.cpp b/src/mac/dialog.cpp index d75706f6a3..760c07680a 100644 --- a/src/mac/dialog.cpp +++ b/src/mac/dialog.cpp @@ -27,6 +27,7 @@ wxList wxModalDialogs; wxList wxModelessWindows; // Frames and modeless dialogs extern wxList wxPendingDelete; +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel) BEGIN_EVENT_TABLE(wxDialog, wxPanel) @@ -39,11 +40,11 @@ BEGIN_EVENT_TABLE(wxDialog, wxPanel) EVT_CLOSE(wxDialog::OnCloseWindow) END_EVENT_TABLE() +#endif wxDialog::wxDialog() { - m_isShown = FALSE; - m_modalShowing = FALSE; + m_isShown = FALSE; SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); } @@ -54,15 +55,8 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name) { - m_windowStyle = style; - m_isShown = FALSE; - m_modalShowing = FALSE; -#if wxUSE_TOOLTIPS - m_hwndToolTip = 0; -#endif SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); - SetName(name); if (!parent) wxTopLevelWindows.Append(this); @@ -74,59 +68,26 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, else m_windowId = id; - 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 ; - - m_width = size.x; - if (m_width == -1) - m_width = 20; - m_height = size.y; - if (m_height == -1) - m_height = 20; - - ::SetRect(&theBoundsRect, m_x, m_y, m_x + m_width, m_y + m_height); - m_macWindowData = new MacWindowData() ; - - WindowClass wclass = kMovableModalWindowClass ; - WindowAttributes attr = kWindowNoAttributes ; - - if ( ( m_windowStyle & wxMINIMIZE_BOX ) || ( m_windowStyle & wxMAXIMIZE_BOX ) ) - { - attr |= kWindowFullZoomAttribute ; - attr |= kWindowResizableAttribute ; - } + MacCreateRealWindow( title , pos , size , MacRemoveBordersFromStyle(style) , name ) ; - UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ; - wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ; - wxString label ; - if( wxApp::s_macDefaultEncodingIsPC ) - label = wxMacMakeMacStringFromPC( title ) ; - else - label = title ; - UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDialogBackgroundActive ; - UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; - m_macWindowData->m_macFocus = NULL ; return TRUE; } void wxDialog::SetModal(bool flag) { - if ( flag ) - m_windowStyle |= wxDIALOG_MODAL ; - else - if ( m_windowStyle & wxDIALOG_MODAL ) - m_windowStyle -= wxDIALOG_MODAL ; - - wxModelessWindows.DeleteObject(this); - if (!flag) - wxModelessWindows.Append(this); + if ( flag ) + { + m_windowStyle |= wxDIALOG_MODAL; + + wxModelessWindows.DeleteObject(this); + } + else + { + m_windowStyle &= ~wxDIALOG_MODAL; + + wxModelessWindows.Append(this); + } } wxDialog::~wxDialog() @@ -134,10 +95,10 @@ wxDialog::~wxDialog() m_isBeingDeleted = TRUE ; wxTopLevelWindows.DeleteObject(this); - m_modalShowing = FALSE; + Show(FALSE); - if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL ) - wxModelessWindows.DeleteObject(this); + if ( !IsModal() ) + wxModelessWindows.DeleteObject(this); // If this is the last top-level window, exit. if (wxTheApp && (wxTopLevelWindows.Number() == 0)) @@ -184,19 +145,20 @@ void wxDialog::DoSetClientSize(int width, int height) wxWindow::DoSetClientSize( width , height ) ; } -void wxDialog::GetPosition(int *x, int *y) const +void wxDialog::DoGetPosition(int *x, int *y) const { - DoGetPosition( x , y ) ; + wxWindow::DoGetPosition( x , y ) ; } -bool wxDialog::IsShown() const +bool wxDialog::IsModal() const { - return m_isShown; + return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0; } -bool wxDialog::IsModal() const + +bool wxDialog::IsModalShowing() const { - return wxModalDialogs.Find((wxDialog *)this) != 0; // const_cast + return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast } @@ -204,122 +166,77 @@ extern bool s_macIsInModalLoop ; bool wxDialog::Show(bool show) { - m_isShown = show; - - if (show) - InitDialog(); + if ( !wxDialogBase::Show(show) ) + { + // nothing to do + return FALSE; + } - bool modal = ((GetWindowStyleFlag() & wxDIALOG_MODAL) == wxDIALOG_MODAL) ; + if ( show ) + { + // usually will result in TransferDataToWindow() being called + InitDialog(); + } -#if WXGARBAGE_COLLECTION_ON /* MATTHEW: GC */ - if (!modal) - { - if (show) + if ( IsModal() ) { - if (!wxModelessWindows.Find(this)) - wxModelessWindows.Append(this); - } - else - wxModelessWindows.DeleteObject(this); - } - if (show) - { - if (!wxTopLevelWindows.Find(this)) - wxTopLevelWindows.Append(this); - } - else - wxTopLevelWindows.DeleteObject(this); -#endif + if ( show ) + { + DoShowModal(); + } + else // end of modal dialog + { + // this will cause IsModalShowing() return FALSE and our local + // message loop will terminate + wxModalDialogs.DeleteObject(this); + } + } - if ( modal ) - { - s_macIsInModalLoop = true ; - if (show) - { - if (m_modalShowing) - { -// BringWindowToTop((HWND) GetHWND()); - return TRUE; - } - - m_modalShowing = TRUE; - // if we don't do it, some window might be deleted while we have pointers - // to them in our disabledWindows list and the program will crash when it - // will try to reenable them after the modal dialog end - wxTheApp->DeletePendingObjects(); - - UMAShowWindow( m_macWindowData->m_macWindow ) ; - UMASelectWindow( m_macWindowData->m_macWindow ) ; - - if (!wxModalDialogs.Member(this)) - wxModalDialogs.Append(this); - - while (wxModalDialogs.Member(this) ) - { - wxTheApp->MacDoOneEvent() ; - } - } - else - { - wxModalDialogs.DeleteObject(this); - UMAHideWindow( m_macWindowData->m_macWindow ) ; - } - s_macIsInModalLoop = false ; - } - else // !modal - { - if (show) - { - UMAShowWindow( m_macWindowData->m_macWindow ) ; - UMASelectWindow( m_macWindowData->m_macWindow ) ; - } - else - { - UMAHideWindow( m_macWindowData->m_macWindow ) ; - } - } - return TRUE ; + return TRUE; } -void wxDialog::SetTitle(const wxString& title) +void wxDialog::DoShowModal() { - wxWindow::SetTitle( title ) ; -} + wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") ); -wxString wxDialog::GetTitle() const -{ - return wxWindow::GetTitle() ; -} + wxModalDialogs.Append(this); -void wxDialog::Centre(int direction) -{ - int x_offset,y_offset ; - int display_width, display_height; - int width, height, x, y; - wxWindow *parent = GetParent(); - if ((direction & wxCENTER_FRAME) && parent) - { - parent->GetPosition(&x_offset,&y_offset) ; - parent->GetSize(&display_width,&display_height) ; - } - else - { - wxDisplaySize(&display_width, &display_height); - x_offset = 0 ; - y_offset = 0 ; - } + wxWindow *parent = GetParent(); + + // remember where the focus was + wxWindow *winFocus = FindFocus(); + if ( !winFocus ) + { + winFocus = parent; + } + if ( !winFocus ) + { + winFocus = wxTheApp->GetTopWindow(); + } + // TODO : test whether parent gets disabled + + s_macIsInModalLoop = true ; - GetSize(&width, &height); - GetPosition(&x, &y); + while ( IsModalShowing() ) + { + while ( !wxTheApp->Pending() && wxTheApp->ProcessIdle() ) + { + } + wxTheApp->MacDoOneEvent() ; + } + + s_macIsInModalLoop = false ; - if (direction & wxHORIZONTAL) - x = (int)((display_width - width)/2); - if (direction & wxVERTICAL) - y = (int)((display_height - height)/2); + // TODO probably reenable the parent window if any - SetSize(x+x_offset, y+y_offset, width, height); + // and restore focus + if ( winFocus ) + { + winFocus->SetFocus(); + } } + // Replacement for Show(TRUE) for modal dialogs - returns return code int wxDialog::ShowModal() { @@ -328,6 +245,8 @@ int wxDialog::ShowModal() return GetReturnCode(); } +// NB: this function (surprizingly) may be called for both modal and modeless +// dialogs and should work for both of them void wxDialog::EndModal(int retCode) { SetReturnCode(retCode); @@ -339,13 +258,7 @@ void wxDialog::OnOK(wxCommandEvent& event) { if ( Validate() && TransferDataFromWindow() ) { - if ( IsModal() ) - EndModal(wxID_OK); - else - { - SetReturnCode(wxID_OK); - this->Show(FALSE); - } + EndModal(wxID_OK); } } @@ -358,20 +271,7 @@ void wxDialog::OnApply(wxCommandEvent& event) void wxDialog::OnCancel(wxCommandEvent& event) { - if ( IsModal() ) EndModal(wxID_CANCEL); - else - { - SetReturnCode(wxID_CANCEL); - this->Show(FALSE); - } -} - -void wxDialog::OnPaint(wxPaintEvent& event) -{ - // No: if you call the default procedure, it makes - // the following painting code not work. -// wxWindow::OnPaint(event); } void wxDialog::OnCloseWindow(wxCloseEvent& event) @@ -407,30 +307,16 @@ void wxDialog::OnCloseWindow(wxCloseEvent& event) // Destroy the window (delayed, if a managed window) bool wxDialog::Destroy() { - if (!wxPendingDelete.Member(this)) + wxCHECK_MSG( !wxPendingDelete.Member(this), FALSE, + _T("wxDialog destroyed twice") ); + wxPendingDelete.Append(this); return TRUE; } -void wxDialog::OnSize(wxSizeEvent& WXUNUSED(event)) -{ - // if we're using constraints - do use them - #if wxUSE_CONSTRAINTS - if ( GetAutoLayout() ) - { - Layout(); - } - #endif -} - void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event) { SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); Refresh(); } -void wxDialog::Fit() -{ - wxWindow::Fit(); -} - diff --git a/src/mac/dir.cpp b/src/mac/dir.cpp index ec94a4e1ec..f0b6664010 100644 --- a/src/mac/dir.cpp +++ b/src/mac/dir.cpp @@ -147,6 +147,7 @@ bool wxDirData::Read(wxString *filename) if ( err != noErr ) break ; + p2cstr( m_name ) ; if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) ) // we have a directory break ; @@ -156,17 +157,37 @@ bool wxDirData::Read(wxString *filename) if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) ) // its hidden but we don't want it continue ; + wxString file( m_name ) ; + if ( m_filespec.IsEmpty() || m_filespec == "*.*" ) + { + } + else if ( m_filespec.Length() > 1 && m_filespec.Left(1) =="*" ) + { + if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() ) + { + continue ; + } + } + else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == "*" ) + { + if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() ) + { + continue ; + } + } + else if ( file.Upper() != m_filespec.Upper() ) + { + continue ; + } + break ; } if ( err != noErr ) { return FALSE ; } - FSSpec spec ; - - FSMakeFSSpecCompat(m_CPB.hFileInfo.ioVRefNum, m_dirId, m_name,&spec) ; - - *filename = wxMacFSSpec2UnixFilename( &spec ) ; + + *filename = (char*) m_name ; return TRUE; } diff --git a/src/mac/dirdlg.cpp b/src/mac/dirdlg.cpp index 344b8b32b9..02bbef6a20 100644 --- a/src/mac/dirdlg.cpp +++ b/src/mac/dirdlg.cpp @@ -20,19 +20,9 @@ #include "wx/cmndata.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_CLASS(wxDirDialog, wxDialog) - -enum { - kSelectItem = 10, // select button item number - kSFGetFolderDlgID = 250, // dialog resource number - kStrListID = 250, // our strings - kSelectStrNum = 1, // word 'Select: ' for button - kDesktopStrNum = 2, // word 'Desktop' for button - kSelectNoQuoteStrNum = 3, // word 'Select: ' for button - - kUseQuotes = true, // parameter for SetButtonName - kDontUseQuotes = false -}; +#endif // the data we need to pass to our standard file hook routine // includes a pointer to the dialog, a pointer to the standard @@ -48,6 +38,21 @@ struct UserDataRec { typedef struct UserDataRec UserDataRec, *UserDataRecPtr; +#if !TARGET_CARBON + +enum { + kSelectItem = 10, // select button item number + kSFGetFolderDlgID = 250, // dialog resource number + kStrListID = 250, // our strings + kSelectStrNum = 1, // word 'Select: ' for button + kDesktopStrNum = 2, // word 'Desktop' for button + kSelectNoQuoteStrNum = 3, // word 'Select: ' for button + + kUseQuotes = true, // parameter for SetButtonName + kDontUseQuotes = false +}; + + static void GetLabelString(StringPtr theStr, short stringNum) { GetIndString(theStr, kStrListID, stringNum); @@ -302,6 +307,7 @@ static pascal short SFGetFolderDialogHook(short item, DialogPtr theDlgPtr, Ptr d return item; } +#endif void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileFilterYDUPP fileFilter, StandardFileReply *theSFR) { @@ -321,7 +327,7 @@ void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileF // set initial contents of Select button to a space - CopyPStr("\p ", theSFR->sfFile.name); + memcpy(theSFR->sfFile.name, "\p ", 2); // point the user data parameter at the reply record so we can get to it later @@ -329,6 +335,8 @@ void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileF // display the dialog + #if !TARGET_CARBON + dlgHookUPP = NewDlgHookYDProc(SFGetFolderDialogHook); myModalFilterUPP = NewModalFilterYDProc(SFGetFolderModalDialogFilter); @@ -350,6 +358,8 @@ void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileF DisposeRoutineDescriptor(dlgHookUPP); DisposeRoutineDescriptor(myModalFilterUPP); + #else + #endif // if cancel wasn't pressed and no fatal error occurred... @@ -445,14 +455,18 @@ int wxDirDialog::ShowModal() strcpy((char *)path, m_path ) ; c2pstr((char *)path ) ; - FileFilterYDUPP invisiblesExcludedCustomFilterUPP; StandardFileReply reply ; + FileFilterYDUPP invisiblesExcludedCustomFilterUPP = 0 ; + #if !TARGET_CARBON invisiblesExcludedCustomFilterUPP = NewFileFilterYDProc(OnlyVisibleFoldersCustomFileFilter); + #endif StandardGetFolder( prompt , path , invisiblesExcludedCustomFilterUPP, &reply); + #if !TARGET_CARBON DisposeRoutineDescriptor(invisiblesExcludedCustomFilterUPP); + #endif if ( reply.sfGood == false ) { m_path = "" ; diff --git a/src/mac/dnd.cpp b/src/mac/dnd.cpp index 32088eef0f..cebcd3aab0 100644 --- a/src/mac/dnd.cpp +++ b/src/mac/dnd.cpp @@ -18,6 +18,8 @@ #include "wx/app.h" #include "wx/gdicmn.h" +#if wxUSE_DRAG_AND_DROP + // ---------------------------------------------------------------------------- // global // ---------------------------------------------------------------------------- @@ -131,3 +133,4 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) return wxDragError; }; +#endif \ No newline at end of file diff --git a/src/mac/filedlg.cpp b/src/mac/filedlg.cpp index ee50e2e6bd..7837183e2a 100644 --- a/src/mac/filedlg.cpp +++ b/src/mac/filedlg.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: filedlg.cpp -// Purpose: wxFileDialog +// Purpose: wxFileDialog // Author: AUTHOR // Modified by: // Created: ??/??/98 @@ -19,7 +19,9 @@ #include "wx/filedlg.h" #include "wx/intl.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_CLASS(wxFileDialog, wxDialog) +#endif // begin wxmac @@ -43,6 +45,27 @@ OSType gfiltersmac[] = '****' } ; +// the data we need to pass to our standard file hook routine +// includes a pointer to the dialog, a pointer to the standard +// file reply record (so we can inspect the current selection) +// and a copy of the "previous" file spec of the reply record +// so we can see if the selection has changed + +const int kwxMacFileTypes = 10 ; + +struct OpenUserDataRec { + StandardFileReply *sfrPtr; + FSSpec oldSelectionFSSpec; + char filter[kwxMacFileTypes][10] ; + OSType filtermactypes[kwxMacFileTypes] ; + int numfilters ; + DialogPtr theDlgPtr; +}; +typedef struct OpenUserDataRec + OpenUserDataRec, *OpenUserDataRecPtr; + +#if !TARGET_CARBON + static void wxMacSetupStandardFile(short newVRefNum, long newDirID) { enum @@ -97,25 +120,6 @@ enum { kDontUseQuotes = false }; -// the data we need to pass to our standard file hook routine -// includes a pointer to the dialog, a pointer to the standard -// file reply record (so we can inspect the current selection) -// and a copy of the "previous" file spec of the reply record -// so we can see if the selection has changed - -const int kwxMacFileTypes = 10 ; - -struct OpenUserDataRec { - StandardFileReply *sfrPtr; - FSSpec oldSelectionFSSpec; - char filter[kwxMacFileTypes][10] ; - OSType filtermactypes[kwxMacFileTypes] ; - int numfilters ; - DialogPtr theDlgPtr; -}; -typedef struct OpenUserDataRec - OpenUserDataRec, *OpenUserDataRecPtr; - static void GetLabelString(StringPtr theStr, short stringNum) { GetIndString(theStr, kStrListID, stringNum); @@ -185,6 +189,7 @@ static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRec return false; } +#endif void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const char *filter , FileFilterYDUPP fileFilter, StandardFileReply *theSFR) { @@ -204,7 +209,7 @@ void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const // set initial contents of Select button to a space - CopyPStr("\p ", theSFR->sfFile.name); + memcpy( theSFR->sfFile.name , "\p " , 2 ) ; // point the user data parameter at the reply record so we can get to it later @@ -240,6 +245,8 @@ void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const myData.numfilters = 0 ; } // display the dialog + +#if !TARGET_CARBON dlgHookUPP = NULL ; // dlgHookUPP = NewDlgHookYDProc(SFGetFolderDialogHook); @@ -263,7 +270,8 @@ void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const DisposeRoutineDescriptor(dlgHookUPP); DisposeRoutineDescriptor(myModalFilterUPP); - +#else +#endif // if cancel wasn't pressed and no fatal error occurred... if (theSFR->sfGood) @@ -454,8 +462,12 @@ int wxFileDialog::ShowModal() strcpy((char *)filename, m_fileName) ; c2pstr((char *)filename ) ; + #if !TARGET_CARBON StandardPutFile( prompt , filename , &reply ) ; + + #else + #endif if ( reply.sfGood == false ) { m_path = "" ; @@ -479,14 +491,17 @@ int wxFileDialog::ShowModal() strcpy((char *)path, m_path ) ; c2pstr((char *)path ) ; - FileFilterYDUPP crossPlatformFileFilterUPP; StandardFileReply reply ; + FileFilterYDUPP crossPlatformFileFilterUPP = 0 ; + #if !TARGET_CARBON crossPlatformFileFilterUPP = NewFileFilterYDProc(CrossPlatformFileFilter); + #endif ExtendedOpenFile( prompt , path , m_wildCard , crossPlatformFileFilterUPP, &reply); - - DisposeRoutineDescriptor(crossPlatformFileFilterUPP); + #if !TARGET_CARBON + DisposeFileFilterYDUPP(crossPlatformFileFilterUPP); + #endif if ( reply.sfGood == false ) { m_path = "" ; diff --git a/src/mac/font.cpp b/src/mac/font.cpp index a5df9049a2..4f26c04f91 100644 --- a/src/mac/font.cpp +++ b/src/mac/font.cpp @@ -18,7 +18,9 @@ #include "wx/font.h" #include "wx/gdicmn.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) +#endif @@ -77,7 +79,7 @@ void wxFontRefData::MacFindFont() ::GetFNum( "\pTimes" , &m_macFontNum) ; break ; case wxSWISS : - ::GetFNum( "\pHelvetica" , &m_macFontNum) ; + ::GetFNum( "\pGeneva" , &m_macFontNum) ; break ; case wxMODERN : ::GetFNum( "\pMonaco" , &m_macFontNum) ; diff --git a/src/mac/fontdlg.cpp b/src/mac/fontdlg.cpp index 9a0843d64b..d775c24c16 100644 --- a/src/mac/fontdlg.cpp +++ b/src/mac/fontdlg.cpp @@ -17,7 +17,9 @@ #include "wx/mac/fontdlg.h" #include "wx/cmndata.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) +#endif /* * wxFontDialog diff --git a/src/mac/fontutil.cpp b/src/mac/fontutil.cpp index c5a0f583d6..4f61d13ff4 100644 --- a/src/mac/fontutil.cpp +++ b/src/mac/fontutil.cpp @@ -48,18 +48,12 @@ // ---------------------------------------------------------------------------- // convert to/from the string representation: format is -// encodingid;facename[;charset] +// facename[;charset] bool wxNativeEncodingInfo::FromString(const wxString& s) { wxStringTokenizer tokenizer(s, _T(";")); - wxString encid = tokenizer.GetNextToken(); - long enc; - if ( !encid.ToLong(&enc) ) - return FALSE; - encoding = (wxFontEncoding)enc; - facename = tokenizer.GetNextToken(); if ( !facename ) return FALSE; @@ -85,10 +79,7 @@ bool wxNativeEncodingInfo::FromString(const wxString& s) wxString wxNativeEncodingInfo::ToString() const { - wxString s; - - s << (long)encoding << _T(';') << facename; - + wxString s(facename); if ( charset != 0 ) { s << _T(';') << charset; @@ -159,8 +150,6 @@ bool wxGetNativeFontEncoding(wxFontEncoding encoding, return FALSE; } - info->encoding = encoding; - return TRUE; } diff --git a/src/mac/frame.cpp b/src/mac/frame.cpp index cded59c604..b5498fec48 100644 --- a/src/mac/frame.cpp +++ b/src/mac/frame.cpp @@ -14,7 +14,7 @@ #endif #include "wx/frame.h" -#include "wx/statusbr.h" +#include "wx/mac/statusbr.h" #include "wx/toolbar.h" #include "wx/menuitem.h" #include "wx/menu.h" @@ -28,16 +28,18 @@ extern wxList wxModelessWindows; extern wxList wxPendingDelete; -BEGIN_EVENT_TABLE(wxFrame, wxWindow) - EVT_SIZE(wxFrame::OnSize) +#if !USE_SHARED_LIBRARY +BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) +// EVT_SIZE(wxFrame::OnSize) EVT_ACTIVATE(wxFrame::OnActivate) - EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) + // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) - EVT_IDLE(wxFrame::OnIdle) - EVT_CLOSE(wxFrame::OnCloseWindow) +// EVT_IDLE(wxFrame::OnIdle) +// EVT_CLOSE(wxFrame::OnCloseWindow) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) +#endif #if wxUSE_NATIVE_STATUSBAR bool wxFrame::m_useNativeStatusBar = TRUE; @@ -45,17 +47,43 @@ bool wxFrame::m_useNativeStatusBar = TRUE; bool wxFrame::m_useNativeStatusBar = FALSE; #endif -wxFrame::wxFrame() +#define WX_MAC_STATUSBAR_HEIGHT 15 +// ---------------------------------------------------------------------------- +// creation/destruction +// ---------------------------------------------------------------------------- + +void wxFrame::Init() { -#if wxUSE_TOOLBAR - m_frameToolBar = NULL ; + m_iconized = FALSE; + +#if wxUSE_TOOLTIPS + m_hwndToolTip = 0; #endif +} - // in order to be able to give size events on show - m_frameMenuBar = NULL; - m_frameStatusBar = NULL; - m_iconized = FALSE; - m_isShown = FALSE; +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, @@ -66,13 +94,7 @@ bool wxFrame::Create(wxWindow *parent, long style, const wxString& name) { - if (!parent) - wxTopLevelWindows.Append(this); - - SetName(name); - m_windowStyle = style; m_frameMenuBar = NULL; - m_isShown = FALSE; #if wxUSE_TOOLBAR m_frameToolBar = NULL ; @@ -88,74 +110,24 @@ bool wxFrame::Create(wxWindow *parent, if (parent) parent->AddChild(this); - wxModelessWindows.Append(this); - - // create frame. - - 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 ; - - m_width = size.x; - if (m_width == -1) - m_width = 20; - m_height = size.y; - if (m_height == -1) - m_height = 20; + if (!parent) + wxTopLevelWindows.Append(this); - m_macWindowData = new MacWindowData() ; + MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; + + m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; - ::SetRect(&theBoundsRect, m_x, m_y, m_x + m_width, m_y + m_height); + wxModelessWindows.Append(this); - WindowClass wclass = kDocumentWindowClass ; - WindowAttributes attr = kWindowNoAttributes ; - - if ( ( m_windowStyle & wxMINIMIZE_BOX ) || ( m_windowStyle & wxMAXIMIZE_BOX ) ) - { - attr |= kWindowFullZoomAttribute ; - attr |= kWindowResizableAttribute ; - } - if ( m_windowStyle & wxSTAY_ON_TOP ) - { - wclass = kFloatingWindowClass ; - -// if ( m_windowStyle & wxCAPTION ) -// attr |= kHasPaletteTitlebarMask ; - } - else - { - } - if ( m_windowStyle & wxSYSTEM_MENU ) - { - attr |= kWindowCloseBoxAttribute ; - } - UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ; - wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ; - wxString label ; - if( wxApp::s_macDefaultEncodingIsPC ) - label = wxMacMakeMacStringFromPC( title ) ; - else - label = title ; - UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; - UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; - m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; - m_macWindowData->m_macFocus = NULL ; return TRUE; } wxFrame::~wxFrame() { + m_isBeingDeleted = TRUE; wxTopLevelWindows.DeleteObject(this); - if (m_frameStatusBar) - delete m_frameStatusBar; - if (m_frameMenuBar) - delete m_frameMenuBar; + DeleteAllBars(); /* Check if it's the last top-level window */ @@ -173,11 +145,21 @@ wxFrame::~wxFrame() } -void wxFrame::Iconize(bool iconize) +bool wxFrame::Enable(bool enable) { - // TODO -} + if ( !wxWindow::Enable(enable) ) + return FALSE; + if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) + { + for ( int i = 0 ; i < m_frameMenuBar->GetMenuCount() ; ++ i ) + { + m_frameMenuBar->EnableTop( i , enable ) ; + } + } + + return TRUE; +} // Equivalent to maximize/restore in Windows void wxFrame::Maximize(bool maximize) { @@ -190,6 +172,11 @@ bool wxFrame::IsIconized() const return FALSE; } +void wxFrame::Iconize(bool iconize) +{ + // TODO +} + // Is the frame maximized? bool wxFrame::IsMaximized(void) const { @@ -197,10 +184,14 @@ bool wxFrame::IsMaximized(void) const return FALSE; } +void wxFrame::Restore() +{ + // TODO +} + void wxFrame::SetIcon(const wxIcon& icon) { - m_icon = icon; - // TODO + wxFrameBase::SetIcon(icon); } wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, @@ -208,61 +199,12 @@ wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, { wxStatusBar *statusBar = NULL; - statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 17), - style, name); - - // Set the height according to the font and the border size - // we shouldn't do this on the mac, because we have to fit the grow box - /* - wxClientDC dc(statusBar); - dc.SetFont(statusBar->GetFont()); - - long x, y; - dc.GetTextExtent("X", &x, &y); - - int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); - - statusBar->SetSize(-1, -1, 100, height); - - */ + statusBar = new wxStatusBar(this, id, style, name); statusBar->SetFieldsCount(number); return statusBar; } -wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id, - const wxString& name) -{ - // Calling CreateStatusBar twice is an error. - wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, - "recreating status bar in wxFrame" ); - - m_frameStatusBar = OnCreateStatusBar(number, style, id, - name); - if ( m_frameStatusBar ) - { - PositionStatusBar(); - return m_frameStatusBar; - } - else - return NULL; -} - -void wxFrame::SetStatusText(const wxString& text, int number) -{ - wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); - - m_frameStatusBar->SetStatusText(text, number); -} - -void wxFrame::SetStatusWidths(int n, const int widths_field[]) -{ - wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); - - m_frameStatusBar->SetStatusWidths(n, widths_field); - PositionStatusBar(); -} - void wxFrame::PositionStatusBar() { if (m_frameStatusBar ) @@ -274,7 +216,7 @@ void wxFrame::PositionStatusBar() // Since we wish the status bar to be directly under the client area, // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. - m_frameStatusBar->SetSize(0, h, w, sh); + m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT ); } } @@ -282,43 +224,15 @@ void wxFrame::SetMenuBar(wxMenuBar *menuBar) { if (!menuBar) { - m_frameMenuBar = NULL; return; } + m_frameMenuBar = NULL; m_frameMenuBar = menuBar; - // TODO : we move this into the app code m_frameMenuBar->MacInstallMenuBar() ; + m_frameMenuBar->Attach(this); } -void wxFrame::Fit() -{ - // Work out max. size - wxNode *node = GetChildren().First(); - int max_width = 0; - int max_height = 0; - while (node) - { - // Find a child that's a subwindow, but not a dialog box. - wxWindow *win = (wxWindow *)node->Data(); - - if (!win->IsKindOf(CLASSINFO(wxFrame)) && - !win->IsKindOf(CLASSINFO(wxDialog))) - { - int width, height; - int x, y; - win->GetSize(&width, &height); - win->GetPosition(&x, &y); - - if ((x + width) > max_width) - max_width = x + width; - if ((y + height) > max_height) - max_height = y + height; - } - node = node->Next(); - } - SetClientSize(max_width, max_height); -} // Responds to colour changes, and passes event on to children. void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) @@ -337,217 +251,55 @@ void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) wxWindow::OnSysColourChanged(event); } -// Default resizing behaviour - if only ONE subwindow, -// resize to client rectangle size -void wxFrame::OnIdle(wxIdleEvent& WXUNUSED(event) ) -{ - DoMenuUpdates(); -} - - -// update all menus -void wxFrame::DoMenuUpdates() -{ - wxMenuBar* bar = GetMenuBar(); - - if ( bar != NULL ) - { - int nCount = bar->GetMenuCount(); - for (int n = 0; n < nCount; n++) - DoMenuUpdates(bar->GetMenu(n), (wxWindow*) NULL); - } -} - -// update a menu and all submenus recursively -void wxFrame::DoMenuUpdates(wxMenu* menu, wxWindow* WXUNUSED(focusWin)) -{ - wxEvtHandler* evtHandler = GetEventHandler(); - wxMenuItemList::Node* node = menu->GetMenuItems().GetFirst(); - while (node) - { - wxMenuItem* item = node->GetData(); - if ( !item->IsSeparator() ) - { - wxWindowID id = item->GetId(); - wxUpdateUIEvent event(id); - event.SetEventObject( this ); - - if (evtHandler->ProcessEvent(event)) - { - if (event.GetSetText()) - menu->SetLabel(id, event.GetText()); - if (event.GetSetChecked()) - menu->Check(id, event.GetChecked()); - if (event.GetSetEnabled()) - menu->Enable(id, event.GetEnabled()); - } - - if (item->GetSubMenu()) - DoMenuUpdates(item->GetSubMenu(), (wxWindow*) NULL); - } - node = node->GetNext(); - } -} - -void wxFrame::OnSize(wxSizeEvent& event) -{ - // if we're using constraints - do use them - #if wxUSE_CONSTRAINTS - if ( GetAutoLayout() ) { - Layout(); - return; - } - #endif - - // do we have _exactly_ one child? - wxWindow *child = NULL; - for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) - { - wxWindow *win = (wxWindow *)node->Data(); - if ( !win->IsKindOf(CLASSINFO(wxFrame)) && - !win->IsKindOf(CLASSINFO(wxDialog)) && - (win != GetStatusBar()) -#if wxUSE_TOOLBAR - && - (win != GetToolBar()) -#endif - ) - { - if ( child ) - return; // it's our second subwindow - nothing to do - child = win; - } - } - - if ( child ) { - // we have exactly one child - set it's size to fill the whole frame - int clientW, clientH; - GetClientSize(&clientW, &clientH); - - int x = 0; - int y = 0; - - child->SetSize(x, y, clientW, clientH); - } -} // Default activation behaviour - set the focus for the first child // subwindow found. void wxFrame::OnActivate(wxActivateEvent& event) { - for(wxNode *node = GetChildren().First(); node; node = node->Next()) - { - // Find a child that's a subwindow, but not a dialog box. - wxWindow *child = (wxWindow *)node->Data(); - if (!child->IsKindOf(CLASSINFO(wxFrame)) && - !child->IsKindOf(CLASSINFO(wxDialog))) + if ( !event.GetActive() ) { - child->SetFocus(); - return; + event.Skip(); + return; } - } -} - -// The default implementation for the close window event. -void wxFrame::OnCloseWindow(wxCloseEvent& event) -{ - this->Destroy(); -} - -// Destroy the window (delayed, if a managed window) -bool wxFrame::Destroy() -{ - if (!wxPendingDelete.Member(this)) - wxPendingDelete.Append(this); - return TRUE; -} -// Default menu selection behaviour - display a help string -void wxFrame::OnMenuHighlight(wxMenuEvent& event) -{ - if (GetStatusBar()) - { - if (event.GetMenuId() == -1) - SetStatusText(""); - else + for ( wxWindowList::Node *node = GetChildren().GetFirst(); + node; + node = node->GetNext() ) { - wxMenuBar *menuBar = GetMenuBar(); - if (menuBar) - { - wxString helpString(menuBar->GetHelpString(event.GetMenuId())); - if (helpString != "") - SetStatusText(helpString); - } - } - } -} - -wxMenuBar *wxFrame::GetMenuBar() const -{ - return m_frameMenuBar; -} + // FIXME all this is totally bogus - we need to do the same as wxPanel, + // but how to do it without duplicating the code? + // restore focus + wxWindow *child = node->GetData(); -// Call this to simulate a menu command -void wxFrame::Command(int id) -{ - ProcessCommand(id); -} - -void wxFrame::ProcessCommand(int id) -{ - wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); - commandEvent.SetInt( id ); - commandEvent.SetEventObject( this ); - - wxMenuBar *bar = GetMenuBar() ; - if (!bar) - return; - -/* TODO: check the menu item if required - wxMenuItem *item = bar->FindItemForId(id) ; - if (item && item->IsCheckable()) - { - bar->Check(id,!bar->Checked(id)) ; - } -*/ - - GetEventHandler()->ProcessEvent(commandEvent); -} - -// Checks if there is a toolbar, and returns the first free client position -wxPoint wxFrame::GetClientAreaOrigin() const -{ - wxPoint pt(0, 0); + if ( !child->IsTopLevel() #if wxUSE_TOOLBAR - if (GetToolBar()) - { - int w, h; - GetToolBar()->GetSize(& w, & h); - - if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) + && !wxDynamicCast(child, wxToolBar) +#endif // wxUSE_TOOLBAR +#if wxUSE_STATUSBAR + && !wxDynamicCast(child, wxStatusBar) +#endif // wxUSE_STATUSBAR + ) { - pt.x += w; - } - else - { - pt.y += h; + child->SetFocus(); + return; } } -#endif - return pt; } void wxFrame::DoGetClientSize(int *x, int *y) const { wxWindow::DoGetClientSize( x , y ) ; +#if wxUSE_STATUSBAR if ( GetStatusBar() ) { int statusX, statusY; GetStatusBar()->GetClientSize(&statusX, &statusY); - *y -= statusY; + // right now this is a constant, this might change someday + *y -= WX_MAC_STATUSBAR_HEIGHT ; } +#endif // wxUSE_STATUSBAR wxPoint pt(GetClientAreaOrigin()); *y -= pt.y; @@ -576,39 +328,20 @@ void wxFrame::DoSetClientSize(int clientwidth, int clientheight) #if wxUSE_TOOLBAR wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) { - wxCHECK_MSG( m_frameToolBar == NULL, FALSE, - "recreating toolbar in wxFrame" ); - - wxToolBar* toolBar = OnCreateToolBar(style, id, name); - if (toolBar) + if ( wxFrameBase::CreateToolBar(style, id, name) ) { - SetToolBar(toolBar); PositionToolBar(); - return toolBar; - } - else - { - return NULL; } -} -wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name) -{ - return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name); + return m_frameToolBar; } void wxFrame::PositionToolBar() { int cw, ch; - // TODO: we actually need to use the low-level client size, before - // the toolbar/status bar were added. - // So DEFINITELY replace the line below with something appropriate. - - // GetClientSize(& cw, &ch); - - cw = m_width ; - ch = m_height ; + cw = m_width ; + ch = m_height ; if ( GetStatusBar() ) { @@ -627,12 +360,12 @@ void wxFrame::PositionToolBar() // 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(0, 0, tw, ch, wxSIZE_NO_ADJUSTMENTS); + GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); } else { // Use the 'real' position - GetToolBar()->SetSize(0, 0, cw, th, wxSIZE_NO_ADJUSTMENTS); + GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); } } } diff --git a/src/mac/gauge.cpp b/src/mac/gauge.cpp index be0d0d0a3c..67d5dd9c84 100644 --- a/src/mac/gauge.cpp +++ b/src/mac/gauge.cpp @@ -15,7 +15,9 @@ #include "wx/gauge.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) +#endif #include @@ -31,15 +33,13 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id, Rect bounds ; Str255 title ; m_rangeMax = range ; - m_macHorizontalBorder = 2 ; // additional pixels around the real control - m_macVerticalBorder = 2 ; if ( size.x == wxDefaultSize.x && size.y == wxDefaultSize.y) { size = wxSize( 200 , 16 ) ; } - MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; + MacPreControlCreate( parent , id , "" , pos , size ,style & 0xE0FFFFFF /* no borders on mac */ , validator , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , range, kControlProgressBarProc , (long) this ) ; @@ -66,7 +66,7 @@ void wxGauge::SetRange(int r) void wxGauge::SetValue(int pos) { m_gaugePos = pos; - ::SetControlValue( m_macControl , m_gaugePos ) ; + ::SetControlValue( m_macControl , m_gaugePos ) ; } int wxGauge::GetShadowWidth() const diff --git a/src/mac/gdiobj.cpp b/src/mac/gdiobj.cpp index 46b1aa871f..63697c8354 100644 --- a/src/mac/gdiobj.cpp +++ b/src/mac/gdiobj.cpp @@ -15,6 +15,8 @@ #include "wx/gdiobj.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxGDIObject, wxObject) +#endif // TODO: Nothing to do, unless you want to. diff --git a/src/mac/helpxxxx.cpp b/src/mac/helpxxxx.cpp index b7f0babfa2..086762c646 100644 --- a/src/mac/helpxxxx.cpp +++ b/src/mac/helpxxxx.cpp @@ -17,7 +17,9 @@ #include +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxXXXXHelpController, wxHelpControllerBase) +#endif wxXXXXHelpController::wxXXXXHelpController() { diff --git a/src/mac/icon.cpp b/src/mac/icon.cpp index 2fb0616ba8..4ec1f1b5e9 100644 --- a/src/mac/icon.cpp +++ b/src/mac/icon.cpp @@ -15,7 +15,9 @@ #include "wx/icon.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) +#endif /* * Icons @@ -58,6 +60,14 @@ wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(he { } +wxIcon::wxIcon( const char **bits, int width, int height ) +{ +} + +wxIcon::wxIcon( char **bits, int width, int height ) +{ +} + wxIcon::wxIcon(const wxString& icon_file, long flags, int desiredWidth, int desiredHeight) @@ -96,20 +106,23 @@ bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, lo c2pstr( (char*) theName ) ; Handle resHandle = GetNamedResource( 'cicn' , theName ) ; - GetResInfo( resHandle , &theId , &theType , theName ) ; - ReleaseResource( resHandle ) ; - - CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ; - if ( theIcon ) + if ( resHandle != 0L ) { - M_ICONHANDLERDATA->m_hIcon = theIcon ; - M_ICONHANDLERDATA->m_width = 32 ; - M_ICONHANDLERDATA->m_height = 32 ; + GetResInfo( resHandle , &theId , &theType , theName ) ; + ReleaseResource( resHandle ) ; - M_ICONHANDLERDATA->m_depth = 8 ; - M_ICONHANDLERDATA->m_ok = true ; - M_ICONHANDLERDATA->m_numColors = 256 ; - return TRUE ; + CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ; + if ( theIcon ) + { + M_ICONHANDLERDATA->m_hIcon = theIcon ; + M_ICONHANDLERDATA->m_width = 32 ; + M_ICONHANDLERDATA->m_height = 32 ; + + M_ICONHANDLERDATA->m_depth = 8 ; + M_ICONHANDLERDATA->m_ok = true ; + M_ICONHANDLERDATA->m_numColors = 256 ; + return TRUE ; + } } return FALSE ; -} +} \ No newline at end of file diff --git a/src/mac/imaglist.cpp b/src/mac/imaglist.cpp index cb4b9ff01c..4cb47b4e69 100644 --- a/src/mac/imaglist.cpp +++ b/src/mac/imaglist.cpp @@ -15,7 +15,9 @@ #include "wx/stubs/imaglist.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxImageList, wxObject) +#endif wxImageList::wxImageList() { diff --git a/src/mac/ldef/extldef.h b/src/mac/ldef/extldef.h index 683219907d..8daa77eb88 100644 --- a/src/mac/ldef/extldef.h +++ b/src/mac/ldef/extldef.h @@ -53,7 +53,9 @@ static void DisposeExtLDEFInfo( ListHandle lh) ExtLDEFInfo* info = (ExtLDEFInfo* ) (**lh).refCon ; if ( info ) { + #if !TARGET_CARBON DisposeRoutineDescriptor( (RoutineDescriptor*) info->drawProc ) ; + #endif free( (void*) (**lh).refCon ) ; } } diff --git a/src/mac/listbox.cpp b/src/mac/listbox.cpp index c518ad035c..6564af7b77 100644 --- a/src/mac/listbox.cpp +++ b/src/mac/listbox.cpp @@ -21,11 +21,13 @@ #include "wx/utils.h" #include "extldef.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl) BEGIN_EVENT_TABLE(wxListBox, wxControl) EVT_SIZE( wxListBox::OnSize ) END_EVENT_TABLE() +#endif #include @@ -41,6 +43,7 @@ wxListBox::wxListBox() { m_noItems = 0; m_selected = 0; + m_macList = NULL ; } bool wxListBox::Create(wxWindow *parent, wxWindowID id, @@ -56,8 +59,6 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, Rect bounds ; Str255 title ; - m_macHorizontalBorder = 5 ; // additional pixels around the real control - m_macVerticalBorder = 5 ; MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; @@ -67,6 +68,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, long result ; UMAGetControlData( m_macControl , kControlNoPart , kControlListBoxListHandleTag , sizeof( ListHandle ) , (char*) &m_macList , &result ) ; + HLock( (Handle) m_macList ) ; NewExtLDEFInfo( m_macList , MacDrawStringCell , (long) this ) ; (**m_macList).selFlags = 0 ; if ( style & wxLB_MULTIPLE ) @@ -109,7 +111,11 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, wxListBox::~wxListBox() { Free() ; - DisposeExtLDEFInfo( m_macList ) ; + if ( m_macList ) + { + DisposeExtLDEFInfo( m_macList ) ; + m_macList = NULL ; + } } void wxListBox::Free() @@ -156,7 +162,7 @@ void wxListBox::Delete(int N) #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN m_stringArray.Remove( N ) ; m_dataArray.Remove( N ) ; - m_noItems --; + m_noItems --; MacDelete( N ) ; } @@ -236,19 +242,29 @@ int wxListBox::FindString(const wxString& st) const { wxString search = s.Left( s.Length() - 1 ) ; int len = search.Length() ; - for ( int i = 0 ; i < m_noItems ; ++ i ) - { - if ( equalstring( m_stringArray[i].Left( len ) , search , false , false ) ) - return i ; - } + Str255 s1 , s2 ; + strcpy( (char*) s2 , search.c_str() ) ; + c2pstr( (char*) s2 ) ; + for ( int i = 0 ; i < m_noItems ; ++ i ) + { + strcpy( (char*) s1 , m_stringArray[i].Left( len ).c_str() ) ; + c2pstr( (char*) s1 ) ; + if ( EqualString( s1 , s2 , false , false ) ) + return i ; + } } else { - for ( int i = 0 ; i < m_noItems ; ++ i ) - { - if ( equalstring( m_stringArray[i] , s , false , false ) ) - return i ; - } + Str255 s1 , s2 ; + strcpy( (char*) s2 , s.c_str() ) ; + c2pstr( (char*) s2 ) ; + for ( int i = 0 ; i < m_noItems ; ++ i ) + { + strcpy( (char*) s1 , m_stringArray[i].c_str() ) ; + c2pstr( (char*) s1 ) ; + if ( EqualString( s1 , s2 , false , false ) ) + return i ; + } } return -1; } @@ -308,7 +324,7 @@ void wxListBox::DoSetItemClientData(int N, void *Client_data) if ( m_dataArray.GetCount() > N ) { m_dataArray[N] = (char*) Client_data ; - } + } else { m_dataArray.Add( (char*) Client_data ) ; @@ -379,7 +395,14 @@ void wxListBox::DoInsertItems(const wxArrayString& items, int pos) void wxListBox::SetString(int N, const wxString& s) { - m_stringArray[N] = s ; + wxString str ; + if( wxApp::s_macDefaultEncodingIsPC ) + { + str = wxMacMakeMacStringFromPC( s ) ; + } + else + str = s ; + m_stringArray[N] = str ; MacSet( N , s ) ; } @@ -539,7 +562,7 @@ void wxListBox::MacScrollTo( int n ) void wxListBox::OnSize( const wxSizeEvent &event) { Point pt = (**m_macList).cellSize ; - pt.h = m_width - 15 /* scrollbar */ - m_macHorizontalBorder * 2 ; + pt.h = m_width - 15 ; LCellSize( pt , m_macList ) ; } diff --git a/src/mac/listctrl.cpp b/src/mac/listctrl.cpp index 2c11981bf2..d1d8445652 100644 --- a/src/mac/listctrl.cpp +++ b/src/mac/listctrl.cpp @@ -16,9 +16,11 @@ #include "wx/stubs/textctrl.h" #include "wx/stubs/listctrl.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) +#endif wxListCtrl::wxListCtrl() { diff --git a/src/mac/mdi.cpp b/src/mac/mdi.cpp index 8672b2f897..887f726504 100644 --- a/src/mac/mdi.cpp +++ b/src/mac/mdi.cpp @@ -19,6 +19,7 @@ extern wxList wxModelessWindows; +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame) IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame) IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow) @@ -33,6 +34,7 @@ BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) EVT_SCROLL(wxMDIClientWindow::OnScroll) END_EVENT_TABLE() +#endif // Parent frame @@ -61,7 +63,7 @@ bool wxMDIParentFrame::Create(wxWindow *parent, else m_windowId = (int)NewControlId(); - // TODO: create MDI parent frame + // this window does not exist really wxModelessWindows.Append(this); @@ -75,7 +77,7 @@ wxMDIParentFrame::~wxMDIParentFrame() // Get size *available for subwindows* i.e. excluding menu bar. void wxMDIParentFrame::DoGetClientSize(int *x, int *y) const { - wxFrame::DoGetClientSize( x , y ) ; + wxDisplaySize( x , y ) ; } void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) @@ -175,7 +177,9 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, if (parent) parent->AddChild(this); - // TODO: create child frame + MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; + + m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; wxModelessWindows.Append(this); return FALSE; diff --git a/src/mac/menu.cpp b/src/mac/menu.cpp index 427db90852..9a66f806d2 100644 --- a/src/mac/menu.cpp +++ b/src/mac/menu.cpp @@ -33,8 +33,10 @@ // ---------------------- #include +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler) +#endif // the (popup) menu title has this special id static const int idMenuTitle = -2; @@ -47,145 +49,6 @@ const short kwxMacAppleMenuId = 1 ; // implementation // ============================================================================ -// -// Helper Functions to get Mac Menus the way they should be ;-) -// - -void wxMacCtoPString(const char* theCString, Str255 thePString); - -// remove inappropriate characters, if useShortcuts is false, the ampersand will not auto-generate a mac menu-shortcut - -void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemText , bool useShortcuts ) -{ - char *p = (char *) &outMacItemText[1] ; - short macModifiers = 0 ; - char macShortCut = 0 ; - const char *inItemName ; - wxString inItemTextMac ; - - if (wxApp::s_macDefaultEncodingIsPC) - { - inItemTextMac = wxMacMakeMacStringFromPC( inItemText ) ; - inItemName = inItemTextMac ; - } - else - { - inItemName = inItemText ; - } - - if ( useShortcuts && !wxApp::s_macSupportPCMenuShortcuts ) - useShortcuts = false ; - - // we have problems with a leading hypen - it will be taken as a separator - - while ( *inItemName == '-' ) - inItemName++ ; - - while( *inItemName ) - { - switch ( *inItemName ) - { - // special characters for macintosh menus -> use some replacement - case ';' : - *p++ = ',' ; - break ; - case '^' : - *p++ = ' ' ; - break ; - case '!' : - *p++ = ' ' ; - break ; - case '<' : - *p++ = ' ' ; - break ; - case '/' : - *p++ = '|' ; - break ; - case '(' : - *p++ = '[' ; - break ; - case ')' : - *p++ = ']' ; - break ; - // shortcuts - case '&' : - { - ++inItemName ; - if ( *inItemName ) - { - *p++ = *inItemName ; - if ( useShortcuts ) - macShortCut = *inItemName ; - } - else - --inItemName ; - } - break ; - // win-like accelerators - case '\t' : - { - ++inItemName ; - while( *inItemName ) - { - if (strncmp("Ctrl", inItemName, 4) == 0) - { - inItemName = inItemName + 5; - macShortCut = *inItemName; - } - else if (strncmp("Cntrl", inItemName, 5) == 0) - { - inItemName = inItemName + 6; - macShortCut = *inItemName; - } - else if (strncmp("Alt", inItemName, 3) == 0) - { - inItemName = inItemName + 4; - macModifiers |= kMenuOptionModifier ; - macShortCut = *inItemName ; - } - else if (strncmp("Shift", inItemName, 5) == 0) - { - inItemName = inItemName + 6; - macModifiers |= kMenuShiftModifier ; - macShortCut = *inItemName ; - } - else if (strncmp("F", inItemName, 1) == 0) - { - inItemName += strlen( inItemName ) ; - // no function keys at the moment - // macModifiers |= kMenuShiftModifier ; - // macShortCut = *inItemName ; - } - else - { - break ; - } - } - - if ( *inItemName == 0 ) - --inItemName ; - - } - break ; - default : - *p++ = *inItemName ; - } - ++inItemName ; - } - - outMacItemText[0] = (p - (char *)outMacItemText) - 1; - if ( outMacShortcutChar ) - *outMacShortcutChar = macShortCut ; - if ( outMacModifiers ) - *outMacModifiers = macModifiers ; - if ( macShortCut ) - { - int pos = outMacItemText[0] ; - outMacItemText[++pos] = '/'; - outMacItemText[++pos] = toupper( macShortCut ); - outMacItemText[0] = pos ; - } -} // Menus @@ -199,10 +62,10 @@ void wxMenu::Init() // create the menu Str255 label; - wxMacBuildMenuString( label, NULL , NULL , m_title , false ); + wxMenuItem::MacBuildMenuString( label, NULL , NULL , m_title , false ); m_macMenuId = s_macNextMenuId++; wxCHECK_RET( s_macNextMenuId < 236 , "menu ids > 235 cannot be used for submenus on mac" ); - m_hMenu = ::NewMenu(m_macMenuId, label); + m_hMenu = UMANewMenu(m_macMenuId, label); if ( !m_hMenu ) { @@ -220,7 +83,7 @@ void wxMenu::Init() wxMenu::~wxMenu() { if (m_hMenu) - ::DisposeMenu(m_hMenu); + UMADisposeMenu(m_hMenu); #if wxUSE_ACCEL // delete accels @@ -310,38 +173,28 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) Str255 label; wxASSERT_MSG( pSubMenu->m_hMenu != NULL , "invalid submenu added"); pSubMenu->m_menuParent = this ; - wxMacBuildMenuString( label , NULL , NULL , pItem->GetText() ,false); - - // hardcoded adding of the submenu combination for mac + wxMenuItem::MacBuildMenuString( label , NULL , NULL , pItem->GetText() ,false); - int theEnd = label[0] + 1; - if (theEnd > 251) - theEnd = 251; // mac allows only 255 characters - label[theEnd++] = '/'; - label[theEnd++] = hMenuCmd; - label[theEnd++] = '!'; - label[theEnd++] = pSubMenu->m_macMenuId; - label[theEnd] = 0x00; - label[0] = theEnd; - if (wxMenuBar::MacGetInstalledMenuBar() == m_menuBar) { - ::InsertMenu( pSubMenu->m_hMenu , -1 ) ; + UMAInsertMenu( pSubMenu->m_hMenu , -1 ) ; } if ( pos == (size_t)-1 ) { - MacAppendMenu(m_hMenu, label); + UMAAppendSubMenuItem(m_hMenu, label, pSubMenu->m_macMenuId); } else { - MacInsertMenuItem(m_hMenu, label , pos); + UMAInsertSubMenuItem(m_hMenu, label , pos, pSubMenu->m_macMenuId); } } else { Str255 label ; - wxMacBuildMenuString( label , NULL , NULL , pItem->GetText(), pItem->GetId() == wxApp::s_macAboutMenuItemId); + UInt8 modifiers ; + SInt16 key ; + wxMenuItem::MacBuildMenuString( label, &key , &modifiers , pItem->GetText(), pItem->GetId() == wxApp::s_macAboutMenuItemId); if ( label[0] == 0 ) { // we cannot add empty menus on mac @@ -350,17 +203,17 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) } if ( pos == (size_t)-1 ) { - MacAppendMenu(m_hMenu, label); + UMAAppendMenuItem(m_hMenu, label,key,modifiers); } else { - MacInsertMenuItem(m_hMenu, label , pos); + UMAInsertMenuItem(m_hMenu, label , pos,key,modifiers); } if ( pItem->GetId() == idMenuTitle ) { if ( pos == (size_t)-1 ) { - UMADisableMenuItem( m_hMenu , CountMItems( m_hMenu ) ) ; + UMADisableMenuItem( m_hMenu , CountMenuItems( m_hMenu ) ) ; } else { @@ -452,113 +305,9 @@ void wxMenu::SetTitle(const wxString& label) { Str255 title ; m_title = label ; - wxMacBuildMenuString( title, NULL , NULL , label , false ); + wxMenuItem::MacBuildMenuString( title, NULL , NULL , label , false ); UMASetMenuTitle( m_hMenu , title ) ; } - -/* - -void wxMenu::SetLabel(int id, const wxString& label) -{ - Str255 maclabel ; - int index ; - wxMenuItem *item = FindItemForId(id) ; - if (item==NULL) - return; - - index = MacGetIndexFromItem( item ) ; - if (index < 1) - return; - - if (item->GetSubMenu()==NULL) - { - wxMacBuildMenuString( maclabel , NULL , NULL , label , false ); - ::SetMenuItemText( m_hMenu , index , maclabel ) ; - } - else - { - wxMacBuildMenuString( maclabel , NULL , NULL , label , false ); - ::SetMenuItemText( m_hMenu , index , maclabel ) ; - } - item->SetName(label); -} - -wxString wxMenu::GetLabel(int Id) const -{ - wxMenuItem *pItem = FindItemForId(Id) ; - return pItem->GetName() ; -} - -// Finds the item id matching the given string, -1 if not found. -int wxMenu::FindItem (const wxString& itemString) const -{ - char buf1[200]; - char buf2[200]; - wxStripMenuCodes ((char *)(const char *)itemString, buf1); - - for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) - { - wxMenuItem *item = (wxMenuItem *) node->Data (); - if (item->GetSubMenu()) - { - int ans = item->GetSubMenu()->FindItem(itemString); - if (ans > -1) - return ans; - } - if ( !item->IsSeparator() ) - { - wxStripMenuCodes((char *)item->GetName().c_str(), buf2); - if (strcmp(buf1, buf2) == 0) - return item->GetId(); - } - } - - return -1; -} - -wxMenuItem *wxMenu::FindItemForId(int itemId, wxMenu ** itemMenu) const -{ - if (itemMenu) - *itemMenu = NULL; - for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) - { - wxMenuItem *item = (wxMenuItem *) node->Data (); - - if (item->GetId() == itemId) - { - if (itemMenu) - *itemMenu = (wxMenu *) this; - return item; - } - - if (item->GetSubMenu()) - { - wxMenuItem *ans = item->GetSubMenu()->FindItemForId (itemId, itemMenu); - if (ans) - return ans; - } - } - - if (itemMenu) - *itemMenu = NULL; - return NULL; -} - -void wxMenu::SetHelpString(int itemId, const wxString& helpString) -{ - wxMenuItem *item = FindItemForId (itemId); - if (item) - item->SetHelp(helpString); -} - -wxString wxMenu::GetHelpString (int itemId) const -{ - wxMenuItem *item = FindItemForId (itemId); - wxString str(""); - return (item == NULL) ? str : item->GetHelp(); -} -*/ - bool wxMenu::ProcessCommand(wxCommandEvent & event) { bool processed = FALSE; @@ -678,7 +427,10 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in if (node) { wxMenuItem *pItem = (wxMenuItem*)node->Data(); - + + if (pItem->IsCheckable()) + pItem->Check(! pItem->IsChecked()); + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, pItem->GetId()); event.m_timeStamp = when; event.SetEventObject(handler); @@ -892,7 +644,8 @@ void wxMenuBar::MacInstallMenuBar() int pos ; wxMenu* menu = m_menus[i] , *subMenu = NULL ; - +#if !TARGET_CARBON + /* the help menu does not exist in CARBON anymore */ if( m_titles[i] == "?" || m_titles[i] == "&?" || m_titles[i] == wxApp::s_macHelpMenuTitleName ) { MenuHandle mh = NULL ; @@ -906,8 +659,8 @@ void wxMenuBar::MacInstallMenuBar() formerHelpMenuItems = CountMenuItems( mh ) ; } - for (pos = 0 , node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) - { + for (pos = 0 , node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) + { item = (wxMenuItem *)node->Data(); subMenu = item->GetSubMenu() ; if (subMenu) @@ -919,12 +672,14 @@ void wxMenuBar::MacInstallMenuBar() if ( item->IsSeparator() ) { if ( mh ) - ::AppendMenu(mh, "\p-" ); + UMAAppendMenuItem(mh, "\p-" ); } else { Str255 label ; - wxMacBuildMenuString( label , NULL , NULL , item->GetText(), item->GetId() != wxApp::s_macAboutMenuItemId); // no shortcut in about menu + UInt8 modifiers ; + SInt16 key ; + wxMenuItem::MacBuildMenuString( label, &key , &modifiers , item->GetText(), item->GetId() != wxApp::s_macAboutMenuItemId); // no shortcut in about menu if ( label[0] == 0 ) { // we cannot add empty menus on mac @@ -933,36 +688,36 @@ void wxMenuBar::MacInstallMenuBar() } if ( item->GetId() == wxApp::s_macAboutMenuItemId ) { - ::SetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , label ); - // ::EnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 ); - ::EnableItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 ); + UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , label ); + UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 ); } else { if ( mh ) - ::AppendMenu(mh, label ); + UMAAppendMenuItem(mh, label , key , modifiers ); } } } } } else +#endif { - wxMacBuildMenuString( label, NULL , NULL , m_titles[i] , false ); + wxMenuItem::MacBuildMenuString( label, NULL , NULL , m_titles[i] , false ); UMASetMenuTitle( menu->GetHMenu() , label ) ; - for (pos = 0, node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) - { + for (pos = 0, node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) + { item = (wxMenuItem *)node->Data(); subMenu = item->GetSubMenu() ; if (subMenu) { - ::InsertMenu( subMenu->GetHMenu() , -1 ) ; + UMAInsertMenu( subMenu->GetHMenu() , -1 ) ; } } - ::InsertMenu(m_menus[i]->GetHMenu(), 0); + UMAInsertMenu(m_menus[i]->GetHMenu(), 0); } } - ::DrawMenuBar() ; + UMADrawMenuBar() ; s_macInstalledMenuBar = this; } @@ -1037,18 +792,18 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) { if (s_macInstalledMenuBar == this) { - ::DeleteMenu( menuOld->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ; + UMADeleteMenu( menuOld->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ; { Str255 label; - wxMacBuildMenuString( label, NULL , NULL , title , false ); + wxMenuItem::MacBuildMenuString( label, NULL , NULL , title , false ); UMASetMenuTitle( menu->GetHMenu() , label ) ; if ( pos == m_menus.GetCount() - 1) { - ::InsertMenu( menu->GetHMenu() , 0 ) ; + UMAInsertMenu( menu->GetHMenu() , 0 ) ; } else { - ::InsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ; + UMAInsertMenu( menu->GetHMenu() , m_menus[pos+1]->MacGetMenuId() ) ; } } } @@ -1206,6 +961,16 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title) return TRUE; } +void wxMenuBar::Attach(wxFrame *frame) +{ +// wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") ); + + m_menuBarFrame = frame; + +#if wxUSE_ACCEL + RebuildAccelTable(); +#endif // wxUSE_ACCEL +} // --------------------------------------------------------------------------- // wxMenuBar searching for menu items // --------------------------------------------------------------------------- diff --git a/src/mac/menuitem.cpp b/src/mac/menuitem.cpp index 22b07f575d..153c750c44 100644 --- a/src/mac/menuitem.cpp +++ b/src/mac/menuitem.cpp @@ -25,19 +25,152 @@ // dynamic classes implementation // ---------------------------------------------------------------------------- +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) - -void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) ; - -wxString wxMenuItemBase::GetLabelFromText(const wxString& text) -{ - return wxStripMenuCodes(text); -} +#endif //USE_SHARED_LIBRARY // ---------------------------------------------------------------------------- // wxMenuItem // ---------------------------------------------------------------------------- +// +// Helper Functions to get Mac Menus the way they should be ;-) +// + +void wxMacCtoPString(const char* theCString, Str255 thePString); + +// remove inappropriate characters, if useShortcuts is false, the ampersand will not auto-generate a mac menu-shortcut + +wxMenuItem::MacBuildMenuString(StringPtr outMacItemText, SInt16 *outMacShortcutChar , UInt8 *outMacModifiers , const char *inItemText , bool useShortcuts ) +{ + char *p = (char *) &outMacItemText[1] ; + short macModifiers = 0 ; + char macShortCut = 0 ; + const char *inItemName ; + wxString inItemTextMac ; + + if (wxApp::s_macDefaultEncodingIsPC) + { + inItemTextMac = wxMacMakeMacStringFromPC( inItemText ) ; + inItemName = inItemTextMac ; + } + else + { + inItemName = inItemText ; + } + + if ( useShortcuts && !wxApp::s_macSupportPCMenuShortcuts ) + useShortcuts = false ; + + // we have problems with a leading hypen - it will be taken as a separator + + while ( *inItemName == '-' ) + inItemName++ ; + + while( *inItemName ) + { + switch ( *inItemName ) + { + // special characters for macintosh menus -> use some replacement + case ';' : + *p++ = ',' ; + break ; + case '^' : + *p++ = ' ' ; + break ; + case '!' : + *p++ = ' ' ; + break ; + case '<' : + *p++ = '[' ; + break ; + case '>' : + *p++ = ']' ; + break ; + case '/' : + *p++ = '|' ; + break ; + case '(' : + *p++ = '[' ; + break ; + case ')' : + *p++ = ']' ; + break ; + // shortcuts + case '&' : + { + ++inItemName ; + if ( *inItemName ) + { + *p++ = *inItemName ; + if ( useShortcuts ) + macShortCut = *inItemName ; + } + else + --inItemName ; + } + break ; + // win-like accelerators + case '\t' : + { + ++inItemName ; + while( *inItemName ) + { + if (strncmp("Ctrl", inItemName, 4) == 0) + { + inItemName = inItemName + 5; + macShortCut = *inItemName; + } + else if (strncmp("Cntrl", inItemName, 5) == 0) + { + inItemName = inItemName + 6; + macShortCut = *inItemName; + } + else if (strncmp("Alt", inItemName, 3) == 0) + { + inItemName = inItemName + 4; + macModifiers |= kMenuOptionModifier ; + macShortCut = *inItemName ; + } + else if (strncmp("Shift", inItemName, 5) == 0) + { + inItemName = inItemName + 6; + macModifiers |= kMenuShiftModifier ; + macShortCut = *inItemName ; + } + else if (strncmp("F", inItemName, 1) == 0) + { + inItemName += strlen( inItemName ) ; + // no function keys at the moment + // macModifiers |= kMenuShiftModifier ; + // macShortCut = *inItemName ; + } + else + { + break ; + } + } + + if ( *inItemName == 0 ) + --inItemName ; + + } + break ; + default : + *p++ = *inItemName ; + } + ++inItemName ; + } + + outMacItemText[0] = (p - (char *)outMacItemText) - 1; + if ( outMacShortcutChar ) + *outMacShortcutChar = macShortCut ; + if ( outMacModifiers ) + *outMacModifiers = macModifiers ; + + return 0 ; +} + // ctor & dtor // ----------- @@ -184,8 +317,8 @@ void wxMenuItem::SetText(const wxString& text) if ( index >= 1 ) { Str255 label; - wxMacBuildMenuString( label , NULL , NULL , text ,false); - ::SetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark + MacBuildMenuString( label , NULL , NULL , text ,false); + UMASetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark } } @@ -204,6 +337,12 @@ void wxMenuItem::SetCheckable(bool checkable) // wxMenuItemBase // ---------------------------------------------------------------------------- +/* static */ +wxString wxMenuItemBase::GetLabelFromText(const wxString& text) +{ + return wxStripMenuCodes(text); +} + wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, int id, const wxString& name, diff --git a/src/mac/metafile.cpp b/src/mac/metafile.cpp index 5742ba4ce6..fc6c64b825 100644 --- a/src/mac/metafile.cpp +++ b/src/mac/metafile.cpp @@ -39,8 +39,10 @@ extern bool wxClipboardIsOpen; +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject) IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC) +#endif /* * Metafiles @@ -57,7 +59,7 @@ wxMetafileRefData::~wxMetafileRefData(void) { if (m_metafile) { - KillPicture( m_metafile ) ; + KillPicture( m_metafile ) ; m_metafile = 0; } } @@ -83,7 +85,7 @@ bool wxMetaFile::SetClipboard(int width, int height) { if (!m_refData) return FALSE; -/* + bool alreadyOpen=wxClipboardOpen(); if (!alreadyOpen) { @@ -92,11 +94,19 @@ bool wxMetaFile::SetClipboard(int width, int height) } bool success = wxSetClipboardData(wxDF_METAFILE, this, width,height); if (!alreadyOpen) wxCloseClipboard(); - return (bool) success; - */ + return (bool) success; + return TRUE ; } +void wxMetafile::SetHMETAFILE(PicHandle mf) +{ + if (!m_refData) + m_refData = new wxMetafileRefData; + + M_METAFILEDATA->m_metafile = mf; +} + bool wxMetaFile::Play(wxDC *dc) { if (!m_refData) @@ -142,11 +152,11 @@ wxMetaFileDC::wxMetaFileDC(const wxString& file) wxASSERT_MSG( file.IsEmpty() , "no file based metafile support yet") ; - m_metaFile = new wxMetaFile("") ; - Rect r={0,0,100,100} ; + m_metaFile = new wxMetaFile("") ; + Rect r={0,0,1000,1000} ; - m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ; - ::GetPort( &m_macPort ) ; + m_metaFile->SetHMETAFILE( OpenPicture( &r ) ) ; + ::GetPort( &m_macPort ) ; m_ok = TRUE ; SetMapMode(wxMM_TEXT); @@ -184,5 +194,4 @@ wxMetaFile *wxMetaFileDC::Close() return m_metaFile; } - #endif diff --git a/src/mac/minifram.cpp b/src/mac/minifram.cpp index cbe09b7d81..4f6f5e5fcb 100644 --- a/src/mac/minifram.cpp +++ b/src/mac/minifram.cpp @@ -15,6 +15,8 @@ #include "wx/minifram.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMiniFrame, wxFrame) +#endif diff --git a/src/mac/morefile/Director.cpp b/src/mac/morefile/Director.cpp index f8b0d0a891..635877693f 100644 --- a/src/mac/morefile/Director.cpp +++ b/src/mac/morefile/Director.cpp @@ -27,11 +27,11 @@ #define __COMPILINGMOREFILES -#include "MoreFile.h" -#include "MoreExtr.h" -#include "MoreDesk.h" -#include "FileCopy.h" -#include "Director.h" +#include "morefile.h" +#include "moreextr.h" +#include "moredesk.h" +#include "filecopy.h" +#include "director.h" /*****************************************************************************/ @@ -52,9 +52,14 @@ enum ** stack space used when recursively calling CopyLevel and to hold ** global information that might be needed at any time. */ -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=mac68k +#if PRAGMA_STRUCT_ALIGN + #pragma options align=mac68k +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(push, 2) +#elif PRAGMA_STRUCT_PACK + #pragma pack(2) #endif + struct EnumerateGlobals { Ptr copyBuffer; /* pointer to buffer used for file copy operations */ @@ -67,8 +72,12 @@ struct EnumerateGlobals Str63 itemName; /* the name of the current item */ CInfoPBRec myCPB; /* the parameter block used for PBGetCatInfo calls */ }; -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=reset +#if PRAGMA_STRUCT_ALIGN + #pragma options align=reset +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(pop) +#elif PRAGMA_STRUCT_PACK + #pragma pack() #endif typedef struct EnumerateGlobals EnumerateGlobals; @@ -79,9 +88,14 @@ typedef EnumerateGlobals *EnumerateGlobalsPtr; ** stack space used when recursively calling GetLevelSize and to hold ** global information that might be needed at any time. */ -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=mac68k +#if PRAGMA_STRUCT_ALIGN + #pragma options align=mac68k +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(push, 2) +#elif PRAGMA_STRUCT_PACK + #pragma pack(2) #endif + struct PreflightGlobals { OSErr result; /* temporary holder of results - saves 2 bytes of stack each level */ @@ -95,8 +109,12 @@ struct PreflightGlobals unsigned long tempBlocks; /* temporary storage for calculations (save some stack space) */ CopyFilterProcPtr copyFilterProc; /* pointer to filter function */ }; -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=reset +#if PRAGMA_STRUCT_ALIGN + #pragma options align=reset +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(pop) +#elif PRAGMA_STRUCT_PACK + #pragma pack() #endif typedef struct PreflightGlobals PreflightGlobals; @@ -196,6 +214,9 @@ static void GetLevelSize(long currentDirID, } while ( theGlobals->result == noErr ); } + +#if !TARGET_CARBON + /*****************************************************************************/ static OSErr PreflightDirectoryCopySpace(short srcVRefNum, @@ -213,7 +234,8 @@ static OSErr PreflightDirectoryCopySpace(short srcVRefNum, if ( error == noErr ) { /* Convert freeBytes to free disk blocks (512-byte blocks) */ - dstFreeBlocks = (pb.ioVFreeBytes.hi << 23) + (pb.ioVFreeBytes.lo >> 9); + // dstFreeBlocks = (pb.ioVFreeBytes.hi << 23) + (pb.ioVFreeBytes.lo >> 9); + dstFreeBlocks = pb.ioVFreeBytes >> 9 ; /* get allocation block size (always multiple of 512) and divide by 512 to get number of 512-byte blocks per allocation block */ @@ -237,7 +259,7 @@ static OSErr PreflightDirectoryCopySpace(short srcVRefNum, return ( error ); } - +#endif /*****************************************************************************/ static void CopyLevel(long sourceDirID, diff --git a/src/mac/morefile/Director.h b/src/mac/morefile/Director.h index a042fd721d..a05335a63b 100644 --- a/src/mac/morefile/Director.h +++ b/src/mac/morefile/Director.h @@ -25,7 +25,7 @@ #include #include -#include "Optim.h" +#include "optim.h" #ifdef __cplusplus extern "C" { @@ -488,6 +488,6 @@ pascal OSErr FSpDirectoryCopy(const FSSpec *srcSpec, } #endif -#include "OptimEnd.h" +#include "optimend.h" #endif /* __DIRECTORYCOPY__ */ diff --git a/src/mac/morefile/FSpCompa.cpp b/src/mac/morefile/FSpCompa.cpp index b35e20eb01..b6a538acb5 100644 --- a/src/mac/morefile/FSpCompa.cpp +++ b/src/mac/morefile/FSpCompa.cpp @@ -37,8 +37,8 @@ #define __COMPILINGMOREFILES -#include "MoreExtr.h" -#include "FSpCompa.h" +#include "moreextr.h" +#include "fspcompa.h" /*****************************************************************************/ diff --git a/src/mac/morefile/FSpCompa.h b/src/mac/morefile/FSpCompa.h index 1dbc11f22b..d808ad8b93 100644 --- a/src/mac/morefile/FSpCompa.h +++ b/src/mac/morefile/FSpCompa.h @@ -25,7 +25,7 @@ #include #include -#include "Optim.h" +#include "optim.h" #ifdef __cplusplus extern "C" { @@ -482,7 +482,7 @@ pascal void FSpCreateResFileCompat(const FSSpec *spec, } #endif -#include "OptimEnd.h" +#include "optimend.h" #endif /* __FSPCOMPAT__ */ diff --git a/src/mac/morefile/FileCopy.cpp b/src/mac/morefile/FileCopy.cpp index 8843c9b988..acb9c92d11 100644 --- a/src/mac/morefile/FileCopy.cpp +++ b/src/mac/morefile/FileCopy.cpp @@ -23,13 +23,14 @@ #include #include #include +#include #define __COMPILINGMOREFILES -#include "MoreFile.h" -#include "MoreExtr.h" -#include "MoreDesk.h" -#include "FileCopy.h" +#include "morefile.h" +#include "moreextr.h" +#include "moredesk.h" +#include "filecopy.h" /*****************************************************************************/ @@ -160,6 +161,8 @@ static OSErr CheckForForks(short vRefNum, /*****************************************************************************/ +#if !TARGET_CARBON + static OSErr PreflightFileCopySpace(short srcVRefNum, long srcDirID, ConstStr255Param srcName, @@ -182,7 +185,8 @@ static OSErr PreflightFileCopySpace(short srcVRefNum, dstBlksPerAllocBlk = ((unsigned long)pb.xPB.ioVAlBlkSiz >> 9); /* Convert freeBytes to free disk blocks (512-byte blocks) */ - dstFreeBlocks = (pb.xPB.ioVFreeBytes.hi << 23) + (pb.xPB.ioVFreeBytes.lo >> 9); + // dstFreeBlocks = (pb.xPB.ioVFreeBytes.hi << 23) + (pb.xPB.ioVFreeBytes.lo >> 9); + dstFreeBlocks = pb.xPB.ioVFreeBytes >> 9 ; /* Now, get the size of the file's data resource forks */ pb.hPB.fileParam.ioNamePtr = (StringPtr)srcName; @@ -243,7 +247,7 @@ static OSErr PreflightFileCopySpace(short srcVRefNum, return ( error ); } - +#endif /*****************************************************************************/ pascal OSErr FileCopy(short srcVRefNum, diff --git a/src/mac/morefile/FileCopy.h b/src/mac/morefile/FileCopy.h index 5f4c008e25..257a73315c 100644 --- a/src/mac/morefile/FileCopy.h +++ b/src/mac/morefile/FileCopy.h @@ -25,7 +25,7 @@ #include #include -#include "Optim.h" +#include "optim.h" #ifdef __cplusplus extern "C" { @@ -215,6 +215,6 @@ pascal OSErr FSpFileCopy(const FSSpec *srcSpec, } #endif -#include "OptimEnd.h" +#include "optimend.h" #endif /* __FILECOPY__ */ diff --git a/src/mac/morefile/FullPath.cpp b/src/mac/morefile/FullPath.cpp index 3ad50b412d..7e54d6c5fa 100644 --- a/src/mac/morefile/FullPath.cpp +++ b/src/mac/morefile/FullPath.cpp @@ -28,8 +28,8 @@ #define __COMPILINGMOREFILES -#include "FSpCompa.h" -#include "FullPath.h" +#include "fspcompa.h" +#include "fullpath.h" /* IMPORTANT NOTE: @@ -180,7 +180,11 @@ pascal OSErr FSpGetFullPath(const FSSpec *spec, if ( result == noErr ) { /* Return the length */ +#if TARGET_CARBON + *fullPathLength = GetHandleSize(*fullPath); +#else *fullPathLength = InlineGetHandleSize(*fullPath); +#endif result = realResult; // return realResult in case it was fnfErr } else diff --git a/src/mac/morefile/FullPath.h b/src/mac/morefile/FullPath.h index 3594a174eb..cf18a9741c 100644 --- a/src/mac/morefile/FullPath.h +++ b/src/mac/morefile/FullPath.h @@ -25,7 +25,7 @@ #include #include -#include "Optim.h" +#include "optim.h" #ifdef __cplusplus extern "C" { @@ -238,5 +238,6 @@ pascal OSErr LocationFromFullPath(short fullPathLength, } #endif -#include "OptimEnd.h" +#include "optimend.h" +#endif /* __FULLPATH__ */ \ No newline at end of file diff --git a/src/mac/morefile/IterateD.cpp b/src/mac/morefile/IterateD.cpp index 6b7e52a78c..4786b80c01 100644 --- a/src/mac/morefile/IterateD.cpp +++ b/src/mac/morefile/IterateD.cpp @@ -22,8 +22,8 @@ #define __COMPILINGMOREFILES -#include "MoreExtr.h" -#include "IterateD.h" +#include "moreextr.h" +#include "iterated.h" /* ** Type definitions @@ -33,9 +33,14 @@ ** stack space used when recursively calling IterateDirectoryLevel ** and to hold global information that might be needed at any time. */ -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=mac68k +#if PRAGMA_STRUCT_ALIGN + #pragma options align=mac68k +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(push, 2) +#elif PRAGMA_STRUCT_PACK + #pragma pack(2) #endif + struct IterateGlobals { IterateFilterProcPtr iterateFilter; /* pointer to IterateFilterProc */ @@ -47,8 +52,13 @@ struct IterateGlobals unsigned short currentLevel; /* The current level IterateLevel is on */ void *yourDataPtr; /* A pointer to caller data the filter may need to access */ }; -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=reset + +#if PRAGMA_STRUCT_ALIGN + #pragma options align=reset +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(pop) +#elif PRAGMA_STRUCT_PACK + #pragma pack() #endif typedef struct IterateGlobals IterateGlobals; diff --git a/src/mac/morefile/IterateD.h b/src/mac/morefile/IterateD.h index ec36ee43bf..46fafb9fe1 100644 --- a/src/mac/morefile/IterateD.h +++ b/src/mac/morefile/IterateD.h @@ -22,7 +22,7 @@ #include #include -#include "Optim.h" +#include "optim.h" #ifdef __cplusplus extern "C" { @@ -166,6 +166,6 @@ pascal OSErr FSpIterateDirectory(const FSSpec *spec, } #endif -#include "OptimEnd.h" +#include "optimend.h" #endif /* __ITERATEDIRECTORY__ */ diff --git a/src/mac/morefile/MoreDesk.cpp b/src/mac/morefile/MoreDesk.cpp index 74a59fd8d1..5c74005ffd 100644 --- a/src/mac/morefile/MoreDesk.cpp +++ b/src/mac/morefile/MoreDesk.cpp @@ -32,10 +32,10 @@ #define __COMPILINGMOREFILES -#include "MoreFile.h" -#include "MoreExtr.h" -#include "Search.h" -#include "MoreDesk.h" +#include "morefile.h" +#include "moreextr.h" +#include "mfsearch.h" +#include "moredesk.h" /*****************************************************************************/ @@ -80,8 +80,12 @@ enum /* local data structures */ -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=mac68k +#if PRAGMA_STRUCT_ALIGN + #pragma options align=mac68k +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(push, 2) +#elif PRAGMA_STRUCT_PACK + #pragma pack(2) #endif struct IDRec @@ -129,8 +133,12 @@ struct APPLRec typedef struct APPLRec APPLRec; typedef APPLRec *APPLRecPtr; -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=reset +#if PRAGMA_STRUCT_ALIGN + #pragma options align=reset +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(pop) +#elif PRAGMA_STRUCT_PACK + #pragma pack() #endif /*****************************************************************************/ @@ -309,7 +317,11 @@ static OSErr GetAPPLFromDesktopFile(ConstStr255Param volName, applResHandle = Get1Resource(kAPPLResType, 0); if ( applResHandle != NULL ) { +#if !TARGET_CARBON applSize = InlineGetHandleSize((Handle)applResHandle); +#else + applSize = GetHandleSize((Handle)applResHandle); +#endif if ( applSize != 0 ) /* make sure the APPL resource isn't empty */ { foundCreator = false; @@ -1105,7 +1117,11 @@ static OSErr GetCommentFromDesktopFile(short vRefNum, commentHandle = (StringHandle)Get1Resource(kFCMTResType,commentID); if ( commentHandle != NULL ) { +#if !TARGET_CARBON if ( InlineGetHandleSize((Handle)commentHandle) > 0 ) +#else + if ( GetHandleSize((Handle)commentHandle) > 0 ) +#endif { BlockMoveData(*commentHandle, comment, *commentHandle[0] + 1); } diff --git a/src/mac/morefile/MoreDesk.h b/src/mac/morefile/MoreDesk.h index be2bfd341d..ee8dbb4f80 100644 --- a/src/mac/morefile/MoreDesk.h +++ b/src/mac/morefile/MoreDesk.h @@ -29,7 +29,7 @@ #include #include -#include "Optim.h" +#include "optim.h" #ifdef __cplusplus extern "C" { @@ -536,6 +536,6 @@ pascal OSErr FSpDTCopyComment(const FSSpec *srcSpec, } #endif -#include "OptimEnd.h" +#include "optimend.h" #endif /* __MOREDESKTOPMGR__ */ diff --git a/src/mac/morefile/MoreExtr.cpp b/src/mac/morefile/MoreExtr.cpp index cc64cd6a15..26b7c2c393 100644 --- a/src/mac/morefile/MoreExtr.cpp +++ b/src/mac/morefile/MoreExtr.cpp @@ -34,13 +34,14 @@ #include #include #include +#include #define __COMPILINGMOREFILES -#include "MoreFile.h" -#include "MoreExtr.h" -#include "MoreDesk.h" -#include "FSpCompa.h" +#include "morefile.h" +#include "moreextr.h" +#include "moredesk.h" +#include "fspcompa.h" /*****************************************************************************/ @@ -50,8 +51,12 @@ ** stack space used when recursively calling DeleteLevel and to hold ** global information that might be needed at any time. */ -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=mac68k +#if PRAGMA_STRUCT_ALIGN + #pragma options align=mac68k +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(push, 2) +#elif PRAGMA_STRUCT_PACK + #pragma pack(2) #endif struct DeleteEnumGlobals { @@ -59,8 +64,12 @@ struct DeleteEnumGlobals Str63 itemName; /* the name of the current item */ UniversalFMPB myPB; /* the parameter block used for PBGetCatInfo calls */ }; -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=reset +#if PRAGMA_STRUCT_ALIGN + #pragma options align=reset +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(pop) +#elif PRAGMA_STRUCT_PACK + #pragma pack() #endif typedef struct DeleteEnumGlobals DeleteEnumGlobals; @@ -82,7 +91,11 @@ pascal void TruncPString(StringPtr destination, /* a multi-byte character. */ while (maxLength != 0) { +#if TARGET_CARBON + charType = CharacterByteType((Ptr)&source[1], maxLength,smAllScripts); +#else charType = CharByte((Ptr)&source[1], maxLength); +#endif if ( (charType == smSingleByte) || (charType == smLastByte) ) break; /* source[maxLength] is now a valid last character */ --maxLength; @@ -221,6 +234,9 @@ pascal OSErr GetVolumeInfoNoName(ConstStr255Param pathname, ** the parameter block is always returned as NULL (since it might point ** to the local tempPathname). */ + +#if !TARGET_CARBON + pascal OSErr XGetVolumeInfoNoName(ConstStr255Param pathname, short vRefNum, XVolumeParamPtr pb) @@ -275,6 +291,8 @@ pascal OSErr XGetVolumeInfoNoName(ConstStr255Param pathname, return ( error ); } +#endif + /*****************************************************************************/ pascal OSErr GetCatInfoNoName(short vRefNum, @@ -323,6 +341,7 @@ pascal OSErr DetermineVRefNum(ConstStr255Param pathname, /*****************************************************************************/ +#if !TARGET_CARBON pascal OSErr HGetVInfo(short volReference, StringPtr volName, short *vRefNum, @@ -402,7 +421,7 @@ pascal OSErr HGetVInfo(short volReference, return ( result ); } - +#endif /*****************************************************************************/ /* @@ -421,7 +440,12 @@ pascal OSErr HGetVInfo(short volReference, #undef pascal #endif +#if !TARGET_CARBON + #if GENERATINGCFM + +#if UNIVERSAL_INTERFACES_VERSION < 0x0301 + pascal OSErr PBXGetVolInfoSync(XVolumeParamPtr paramBlock) { enum @@ -444,10 +468,16 @@ pascal OSErr PBXGetVolInfoSync(XVolumeParamPtr paramBlock) } #endif +#endif + +#endif + #if __WANTPASCALELIMINATION #define pascal #endif +#if !TARGET_CARBON + /*****************************************************************************/ pascal OSErr XGetVInfo(short volReference, @@ -476,8 +506,8 @@ pascal OSErr XGetVInfo(short volReference, *vRefNum = pb.ioVRefNum; /* return the freeBytes and totalBytes */ - *totalBytes = pb.ioVTotalBytes; - *freeBytes = pb.ioVFreeBytes; + *totalBytes = UInt64ToUnsignedWide(pb.ioVTotalBytes); + *freeBytes = UInt64ToUnsignedWide(pb.ioVFreeBytes); } } else @@ -495,7 +525,7 @@ pascal OSErr XGetVInfo(short volReference, } return ( result ); } - +#endif /*****************************************************************************/ pascal OSErr CheckVolLock(ConstStr255Param pathname, @@ -522,6 +552,8 @@ pascal OSErr CheckVolLock(ConstStr255Param pathname, /*****************************************************************************/ +#if !TARGET_CARBON + pascal OSErr GetDriverName(short driverRefNum, Str255 driverName) { @@ -554,7 +586,9 @@ pascal OSErr GetDriverName(short driverRefNum, return ( result ); } +#endif /*****************************************************************************/ +#if !TARGET_CARBON pascal OSErr FindDrive(ConstStr255Param pathname, short vRefNum, @@ -619,8 +653,10 @@ pascal OSErr FindDrive(ConstStr255Param pathname, return ( result ); } +#endif /*****************************************************************************/ +#if !TARGET_CARBON pascal OSErr GetDiskBlocks(ConstStr255Param pathname, short vRefNum, @@ -757,6 +793,7 @@ pascal OSErr GetDiskBlocks(ConstStr255Param pathname, return ( result ); } +#endif /*****************************************************************************/ @@ -777,6 +814,7 @@ pascal OSErr GetVolFileSystemID(ConstStr255Param pathname, } /*****************************************************************************/ +#if !TARGET_CARBON pascal OSErr GetVolState(ConstStr255Param pathname, short vRefNum, @@ -875,8 +913,9 @@ pascal OSErr GetVolState(ConstStr255Param pathname, return ( error ); } - +#endif /*****************************************************************************/ +#if !TARGET_CARBON pascal OSErr UnmountAndEject(ConstStr255Param pathname, short vRefNum) @@ -952,6 +991,7 @@ pascal OSErr UnmountAndEject(ConstStr255Param pathname, return ( error ); } +#endif /*****************************************************************************/ @@ -1011,6 +1051,8 @@ pascal OSErr SetDefault(short newVRefNum, /*****************************************************************************/ +#if !TARGET_CARBON + pascal OSErr RestoreDefault(short oldVRefNum, long oldDirID) { @@ -1038,7 +1080,7 @@ pascal OSErr RestoreDefault(short oldVRefNum, return ( error ); } - +#endif /*****************************************************************************/ pascal OSErr GetDInfo(short vRefNum, diff --git a/src/mac/morefile/MoreExtr.h b/src/mac/morefile/MoreExtr.h index 927a824d98..c0fd7a006b 100644 --- a/src/mac/morefile/MoreExtr.h +++ b/src/mac/morefile/MoreExtr.h @@ -30,7 +30,7 @@ #define false 0 #endif -#include "Optim.h" +#include "optim.h" #ifdef __cplusplus extern "C" { @@ -215,8 +215,12 @@ enum /*****************************************************************************/ -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=mac68k +#if PRAGMA_STRUCT_ALIGN + #pragma options align=mac68k +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(push, 2) +#elif PRAGMA_STRUCT_PACK + #pragma pack(2) #endif /* @@ -322,8 +326,12 @@ struct MyAFPXVolMountInfo typedef struct MyAFPXVolMountInfo MyAFPXVolMountInfo; typedef MyAFPXVolMountInfo *MyAFPXVolMountInfoPtr, **MyAFPXVolMountInfoHandle; -#if PRAGMA_ALIGN_SUPPORTED -#pragma options align=reset +#if PRAGMA_STRUCT_ALIGN + #pragma options align=reset +#elif PRAGMA_STRUCT_PACKPUSH + #pragma pack(pop) +#elif PRAGMA_STRUCT_PACK + #pragma pack() #endif /*****************************************************************************/ @@ -3136,6 +3144,6 @@ pascal OSErr GetUGEntries(short objType, } #endif -#include "OptimEnd.h" +#include "optimend.h" #endif /* __MOREFILESEXTRAS__ */ diff --git a/src/mac/morefile/MoreFile.cpp b/src/mac/morefile/MoreFile.cpp index 16795680b6..581e1b742a 100644 --- a/src/mac/morefile/MoreFile.cpp +++ b/src/mac/morefile/MoreFile.cpp @@ -25,8 +25,8 @@ #define __COMPILINGMOREFILES -#include "MoreFile.h" -#include "MoreExtr.h" +#include "morefile.h" +#include "moreextr.h" /*****************************************************************************/ diff --git a/src/mac/morefile/MoreFile.h b/src/mac/morefile/MoreFile.h index e4d4bb8a7f..a2b069279c 100644 --- a/src/mac/morefile/MoreFile.h +++ b/src/mac/morefile/MoreFile.h @@ -30,7 +30,7 @@ #define false 0 #endif -#include "Optim.h" +#include "optim.h" #ifdef __cplusplus extern "C" { @@ -1239,6 +1239,6 @@ pascal OSErr GetUGEntry(short objType, } #endif -#include "OptimEnd.h" +#include "optimend.h" #endif /* __MOREFILES__ */ diff --git a/src/mac/morefile/Optim.h b/src/mac/morefile/Optim.h index d09caf71c0..ff5a1d5d57 100644 --- a/src/mac/morefile/Optim.h +++ b/src/mac/morefile/Optim.h @@ -52,40 +52,69 @@ ** File: Optimization.h */ +#if TARGET_CARBON -#ifndef __MACOSSEVENFIVEONEORLATER - #define __MACOSSEVENFIVEONEORLATER 0 -#endif - -#ifndef __MACOSSEVENFIVEORLATER - #define __MACOSSEVENFIVEORLATER __MACOSSEVENFIVEONEORLATER -#endif - -#ifndef __MACOSSEVENORLATER - #if GENERATINGCFM - #define __MACOSSEVENORLATER 1 - #else - #define __MACOSSEVENORLATER __MACOSSEVENFIVEORLATER + #define __MACOSSEVENFIVEONEORLATER 1 + + #define __MACOSSEVENORLATER 1 + + #ifndef __WANTPASCALELIMINATION + #define __WANTPASCALELIMINATION 0 #endif -#endif - - -#ifndef __WANTPASCALELIMINATION - #define __WANTPASCALELIMINATION 0 -#endif - -#if __WANTPASCALELIMINATION - #define pascal -#endif - + + #if __WANTPASCALELIMINATION + #define pascal + #endif + + + #ifndef __USEPRAGMAINTERNAL + #define __USEPRAGMAINTERNAL 0 + #endif + + #if __USEPRAGMAINTERNAL + #if defined(__MWERKS__) + #pragma internal on + #endif + #endif +#else -#ifndef __USEPRAGMAINTERNAL - #define __USEPRAGMAINTERNAL 0 -#endif + // we have a basic requirements of 7.5.3 Rev 2 or 7.6 + + #define __MACOSSEVENFIVEONEORLATER 1 -#if __USEPRAGMAINTERNAL - #if defined(__MWERKS__) - #pragma internal on + #ifndef __MACOSSEVENFIVEONEORLATER + #define __MACOSSEVENFIVEONEORLATER 0 + #endif + + #ifndef __MACOSSEVENFIVEORLATER + #define __MACOSSEVENFIVEORLATER __MACOSSEVENFIVEONEORLATER + #endif + + #ifndef __MACOSSEVENORLATER + #if GENERATINGCFM + #define __MACOSSEVENORLATER 1 + #else + #define __MACOSSEVENORLATER __MACOSSEVENFIVEORLATER + #endif + #endif + + + #ifndef __WANTPASCALELIMINATION + #define __WANTPASCALELIMINATION 0 + #endif + + #if __WANTPASCALELIMINATION + #define pascal + #endif + + + #ifndef __USEPRAGMAINTERNAL + #define __USEPRAGMAINTERNAL 0 + #endif + + #if __USEPRAGMAINTERNAL + #if defined(__MWERKS__) + #pragma internal on + #endif #endif #endif - diff --git a/src/mac/msgdlg.cpp b/src/mac/msgdlg.cpp index cf229e5200..bbdea6abf8 100644 --- a/src/mac/msgdlg.cpp +++ b/src/mac/msgdlg.cpp @@ -16,7 +16,9 @@ #include "wx/msgdlg.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_CLASS(wxMessageDialog, wxDialog) +#endif #define kMacOKAlertResourceID 128 #define kMacYesNoAlertResourceID 129 @@ -70,7 +72,6 @@ int wxMessageDialog::ShowModal() Str255 pascalTitle ; Str255 pascalText ; - if (wxApp::s_macDefaultEncodingIsPC) { strcpy( (char*) pascalTitle , wxMacMakeMacStringFromPC( m_caption ) ) ; diff --git a/src/mac/palette.cpp b/src/mac/palette.cpp index 676f54739a..85a9fd16d8 100644 --- a/src/mac/palette.cpp +++ b/src/mac/palette.cpp @@ -15,7 +15,9 @@ #include "wx/palette.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject) +#endif /* * Palette diff --git a/src/mac/pen.cpp b/src/mac/pen.cpp index 65da06087d..1e3ced2a3a 100644 --- a/src/mac/pen.cpp +++ b/src/mac/pen.cpp @@ -17,7 +17,9 @@ #include "wx/utils.h" #include "wx/pen.h" +#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject) +#endif wxPenRefData::wxPenRefData() { @@ -26,7 +28,7 @@ wxPenRefData::wxPenRefData() m_join = wxJOIN_ROUND ; m_cap = wxCAP_ROUND ; m_nbDash = 0 ; - m_dash = (wxMACDash*)NULL; + m_dash = 0 ; /* TODO: null data m_hPen = 0; */ @@ -76,7 +78,7 @@ wxPen::wxPen(const wxColour& col, int Width, int Style) M_PENDATA->m_join = wxJOIN_ROUND ; M_PENDATA->m_cap = wxCAP_ROUND ; M_PENDATA->m_nbDash = 0 ; - M_PENDATA->m_dash = (wxMACDash*)NULL; + M_PENDATA->m_dash = 0 ; RealizeResource(); @@ -94,7 +96,7 @@ wxPen::wxPen(const wxBitmap& stipple, int Width) M_PENDATA->m_join = wxJOIN_ROUND ; M_PENDATA->m_cap = wxCAP_ROUND ; M_PENDATA->m_nbDash = 0 ; - M_PENDATA->m_dash = (wxMACDash*)NULL; + M_PENDATA->m_dash = 0 ; RealizeResource(); @@ -168,7 +170,7 @@ void wxPen::SetDashes(int nb_dashes, const wxDash *Dash) Unshare(); M_PENDATA->m_nbDash = nb_dashes; - M_PENDATA->m_dash = (wxMACDash *)Dash; + M_PENDATA->m_dash = (wxDash *)Dash; RealizeResource(); } diff --git a/src/mac/printdlg.cpp b/src/mac/printdlg.cpp index a1f8f6b196..a5c41e0737 100644 --- a/src/mac/printdlg.cpp +++ b/src/mac/printdlg.cpp @@ -16,11 +16,14 @@ #include "wx/object.h" #include "wx/printdlg.h" #include "wx/dcprint.h" +#include "wx/mac/uma.h" // Use generic page setup dialog: use your own native one if one exists. +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxPrintDialog, wxDialog) IMPLEMENT_CLASS(wxPageSetupDialog, wxDialog) +#endif wxPrintDialog::wxPrintDialog() { @@ -64,15 +67,17 @@ wxPrintDialog::~wxPrintDialog() int wxPrintDialog::ShowModal() { int result = wxID_CANCEL ; + #if !TARGET_CARBON + OSErr err ; wxString message ; - ::PrOpen() ; + ::UMAPrOpen() ; err = PrError() ; if ( !err ) { m_printDialogData.ConvertToNative() ; - if ( m_printDialogData.m_macPrintInfo && ::PrJobDialog( m_printDialogData.m_macPrintInfo ) ) + if ( ::PrJobDialog( m_printDialogData.GetPrintData().m_macPrintInfo ) ) { m_printDialogData.ConvertFromNative() ; result = wxID_OK ; @@ -84,8 +89,10 @@ int wxPrintDialog::ShowModal() message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; } - ::PrClose() ; - + ::UMAPrClose() ; + #else + #pragma warning "TODO:Printing for carbon" + #endif return result ; } @@ -127,15 +134,17 @@ wxPageSetupDialog::~wxPageSetupDialog() int wxPageSetupDialog::ShowModal() { int result = wxID_CANCEL ; +#if !TARGET_CARBON + OSErr err ; wxString message ; - ::PrOpen() ; + ::UMAPrOpen() ; err = PrError() ; if ( !err ) { m_pageSetupData.ConvertToNative() ; - if ( m_pageSetupData.m_macPageSetupInfo && ::PrStlDialog( m_pageSetupData.m_macPageSetupInfo ) ) + if ( ::PrStlDialog( m_pageSetupData.GetPrintData().m_macPrintInfo ) ) { m_pageSetupData.ConvertFromNative() ; result = wxID_OK ; @@ -147,8 +156,10 @@ int wxPageSetupDialog::ShowModal() message.Printf( "Print Error %d", err ) ; wxMessageDialog dialog( NULL , message , "", wxICON_HAND | wxOK) ; } - ::PrClose() ; - + ::UMAPrClose() ; +#else +#pragma warning "TODO:printing for carbon" +#endif return result ; } diff --git a/src/mac/printmac.cpp b/src/mac/printmac.cpp index 0d4862cfa2..08a6bf77ad 100644 --- a/src/mac/printmac.cpp +++ b/src/mac/printmac.cpp @@ -35,8 +35,10 @@ #include +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase) IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase) +#endif /* * Printer @@ -92,31 +94,16 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) else m_printDialogData.EnablePageNumbers(FALSE); - // Create a suitable device context // Create a suitable device context wxDC *dc = NULL; if (prompt) { - PrOpen() ; - m_printDialogData.ConvertToNative() ; // make sure we have a valid handle - if ( m_printDialogData.m_macPrintInfo ) - { - // todo incorporate the changes from a global page setup - if ( ::PrStlDialog( m_printDialogData.m_macPrintInfo ) ) // we should have the page setup dialog - { - PrClose() ; - wxPrintDialog dialog(parent, & m_printDialogData); - if (dialog.ShowModal() == wxID_OK) - { - dc = dialog.GetPrintDC(); - m_printDialogData = dialog.GetPrintData(); - } - } - else - { - PrClose() ; - } - } + wxPrintDialog dialog(parent, & m_printDialogData); + if (dialog.ShowModal() == wxID_OK) + { + dc = dialog.GetPrintDC(); + m_printDialogData = dialog.GetPrintData(); + } } else { @@ -140,7 +127,7 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) printout->SetDC(dc); int w, h; - long ww, hh; + wxCoord ww, hh; dc->GetSize(&w, &h); printout->SetPageSizePixels((int)w, (int)h); dc->GetSizeMM(&ww, &hh); @@ -278,50 +265,35 @@ bool wxMacPrintPreview::Print(bool interactive) void wxMacPrintPreview::DetermineScaling(void) { -/* - HDC dc = ::GetDC(NULL); - int screenWidth = ::GetDeviceCaps(dc, HORZSIZE); -// int screenHeight = ::GetDeviceCaps(dc, VERTSIZE); - int screenXRes = ::GetDeviceCaps(dc, HORZRES); -// int screenYRes = ::GetDeviceCaps(dc, VERTRES); - int logPPIScreenX = ::GetDeviceCaps(dc, LOGPIXELSX); - int logPPIScreenY = ::GetDeviceCaps(dc, LOGPIXELSY); - m_previewPrintout->SetPPIScreen(logPPIScreenX, logPPIScreenY); - - ::ReleaseDC(NULL, dc); + int screenWidth , screenHeight ; + wxDisplaySize( &screenWidth , &screenHeight ) ; + + m_previewPrintout->SetPPIScreen( 72 , 72 ) ; + m_previewPrintout->SetPPIPrinter( 72 , 72 ) ; + m_previewPrintout->SetPageSizeMM( 8 * 25.6 , 11 * 25.6 ) ; + m_previewPrintout->SetPageSizePixels( 8 * 72 , 11 * 72 ) ; + m_pageWidth = 8 * 72 ; + m_pageHeight = 11 * 72 ; + m_previewScale = 1 ; // Get a device context for the currently selected printer - wxPrinterDC printerDC("", "", "", FALSE, m_printDialogData.GetOrientation()); - - int printerWidth = 150; - int printerHeight = 250; - int printerXRes = 1500; - int printerYRes = 2500; - - if (printerDC.GetHDC()) + wxPrinterDC printerDC(m_printDialogData.GetPrintData()); + if (printerDC.Ok()) { - printerWidth = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZSIZE); - printerHeight = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTSIZE); - printerXRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), HORZRES); - printerYRes = ::GetDeviceCaps((HDC) printerDC.GetHDC(), VERTRES); - - int logPPIPrinterX = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSX); - int logPPIPrinterY = ::GetDeviceCaps((HDC) printerDC.GetHDC(), LOGPIXELSY); - - m_previewPrintout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY); - m_previewPrintout->SetPageSizeMM(printerWidth, printerHeight); - - if (logPPIPrinterX == 0 || logPPIPrinterY == 0 || printerWidth == 0 || printerHeight == 0) - m_isOk = FALSE; - } - else - m_isOk = FALSE; - - m_pageWidth = printerXRes; - m_pageHeight = printerYRes; - + int x , y ; + wxCoord ww, hh; + printerDC.GetSizeMM(&ww, &hh); + printerDC.GetSize( &x , &y ) ; + m_previewPrintout->SetPageSizeMM((int)ww, (int)hh); + m_previewPrintout->SetPageSizePixels( x , y) ; + m_pageWidth = x ; + m_pageHeight = y ; + m_isOk = true ; + + } // At 100%, the page should look about page-size on the screen. - m_previewScale = (float)((float)screenWidth/(float)printerWidth); - m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerYRes); -*/ + // m_previewScale = (float)((float)screenWidth/(float)printerWidth); + // m_previewScale = m_previewScale * (float)((float)screenXRes/(float)printerXRes); + + m_previewScale = 1 ; } diff --git a/src/mac/radiobox.cpp b/src/mac/radiobox.cpp index 416ba0b18f..1f74fae6d2 100644 --- a/src/mac/radiobox.cpp +++ b/src/mac/radiobox.cpp @@ -20,7 +20,9 @@ #include "wx/radiobox.h" #include +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) +#endif #pragma mark - #pragma mark ### Constructors & destructor ### @@ -93,7 +95,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, Rect bounds ; Str255 title ; - MacPreControlCreate( parent , id , label , pos , size ,style, *((wxValidator*)NULL) , name , &bounds , title ) ; + MacPreControlCreate( parent , id , label , pos , size ,style, val , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1, kControlGroupBoxTextTitleProc , (long) this ) ; @@ -435,9 +437,9 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) x_offset = x; y_offset = y; GetPosition(&x_current, &y_current); - if ((x == -1) || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if ((x == -1) && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) x_offset = x_current; - if ((y == -1) || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if ((y == -1)&& !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) y_offset = y_current; // define size @@ -490,7 +492,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) x_start = charWidth; - y_start = charHeight*3/2; + y_start = 15 ; x_offset = x_start; y_offset = y_start; @@ -507,7 +509,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) else { x_offset = x_start; - y_offset += maxHeight + charHeight/2; + y_offset += maxHeight ; /*+ charHeight/2;*/ } } @@ -515,7 +517,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) current=current->NextInCycle(); if (m_windowStyle & wxRA_SPECIFY_ROWS) - y_offset += maxHeight + charHeight/2; + y_offset += maxHeight ; /*+ charHeight/2;*/ else x_offset += maxWidth + charWidth; } diff --git a/src/mac/radiobut.cpp b/src/mac/radiobut.cpp index f5f95dfab2..9a93378c0c 100644 --- a/src/mac/radiobut.cpp +++ b/src/mac/radiobut.cpp @@ -15,7 +15,9 @@ #include "wx/radiobut.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) +#endif #include @@ -48,7 +50,8 @@ void wxRadioButton::SetValue(bool val) ::SetControlValue( m_macControl , val ) ; - if (val) { + if (val) + { cycle=this->NextInCycle(); if (cycle!=NULL) { while (cycle!=this) { @@ -94,4 +97,3 @@ wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle) return(cycle); } } - diff --git a/src/mac/region.cpp b/src/mac/region.cpp index 5c01ddd438..afe12ce603 100644 --- a/src/mac/region.cpp +++ b/src/mac/region.cpp @@ -14,9 +14,12 @@ #include "wx/region.h" #include "wx/gdicmn.h" +#include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject) +#endif //----------------------------------------------------------------------------- // wxRegionRefData implementation @@ -195,7 +198,8 @@ void wxRegion::GetBox(long& x, long& y, long&w, long &h) const { if (m_refData) { - Rect box = (**M_REGION).rgnBBox ; + Rect box ; + GetRegionBounds( M_REGION , &box ) ; x = box.left ; y = box.top ; w = box.right - box.left ; @@ -329,7 +333,8 @@ void wxRegionIterator::Reset(const wxRegion& region) { // we cannot dissolve it into rects on mac m_rects = new wxRect[1]; - Rect rect = (**OTHER_M_REGION( region )).rgnBBox ; + Rect rect ; + GetRegionBounds( OTHER_M_REGION( region ) , &rect ) ; m_rects[0].x = rect.left; m_rects[0].y = rect.top; m_rects[0].width = rect.right - rect.left; diff --git a/src/mac/scrolbar.cpp b/src/mac/scrolbar.cpp index 2db4a175bb..92d6dd1faf 100644 --- a/src/mac/scrolbar.cpp +++ b/src/mac/scrolbar.cpp @@ -16,11 +16,13 @@ #include "wx/scrolbar.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) BEGIN_EVENT_TABLE(wxScrollBar, wxControl) END_EVENT_TABLE() +#endif extern ControlActionUPP wxMacLiveScrollbarActionUPP ; diff --git a/src/mac/settings.cpp b/src/mac/settings.cpp index 2d72222ab8..b13b5733cc 100644 --- a/src/mac/settings.cpp +++ b/src/mac/settings.cpp @@ -74,7 +74,6 @@ wxColour wxSystemSettings::GetSystemColour(int index) break ; case wxSYS_COLOUR_INFOBK : case wxSYS_COLOUR_APPWORKSPACE: - case wxSYS_COLOUR_LISTBOX: return *wxWHITE ; break ; } diff --git a/src/mac/slider.cpp b/src/mac/slider.cpp index 9218d560bb..936ccddb47 100644 --- a/src/mac/slider.cpp +++ b/src/mac/slider.cpp @@ -16,10 +16,12 @@ #include "wx/slider.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) BEGIN_EVENT_TABLE(wxSlider, wxControl) END_EVENT_TABLE() +#endif diff --git a/src/mac/spinbutt.cpp b/src/mac/spinbutt.cpp index 944f72dc10..f5ac7bc9bb 100644 --- a/src/mac/spinbutt.cpp +++ b/src/mac/spinbutt.cpp @@ -24,8 +24,10 @@ // wxWin macros // ---------------------------------------------------------------------------- +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent); +#endif bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) diff --git a/src/mac/statbmp.cpp b/src/mac/statbmp.cpp index ce1e5d1ec8..fa75e68fd5 100644 --- a/src/mac/statbmp.cpp +++ b/src/mac/statbmp.cpp @@ -15,7 +15,9 @@ #include "wx/statbmp.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl) +#endif /* * wxStaticBitmap @@ -28,11 +30,12 @@ END_EVENT_TABLE() bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, - const wxSize& size, + const wxSize& s, long style, const wxString& name) { SetName(name); + wxSize size = s ; m_backgroundColour = parent->GetBackgroundColour() ; m_foregroundColour = parent->GetForegroundColour() ; @@ -47,9 +50,8 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, m_windowStyle = style; bool ret = wxControl::Create( parent, id, pos, size, style , wxDefaultValidator , name ); + SetSizeOrDefault( size ) ; - SetSizeOrDefault() ; - return ret; } diff --git a/src/mac/statbox.cpp b/src/mac/statbox.cpp index ea7ca9dfbb..e0d8257d0f 100644 --- a/src/mac/statbox.cpp +++ b/src/mac/statbox.cpp @@ -16,12 +16,14 @@ #include "wx/statbox.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl) BEGIN_EVENT_TABLE(wxStaticBox, wxControl) EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground) END_EVENT_TABLE() +#endif /* * Static box @@ -37,7 +39,7 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, Rect bounds ; Str255 title ; - MacPreControlCreate( parent , id , label , pos , size ,style, *((wxValidator*)NULL) , name , &bounds , title ) ; + MacPreControlCreate( parent , id , label , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1, kControlGroupBoxTextTitleProc , (long) this ) ; diff --git a/src/mac/stattext.cpp b/src/mac/stattext.cpp index b249fc0e11..22653f651e 100644 --- a/src/mac/stattext.cpp +++ b/src/mac/stattext.cpp @@ -18,7 +18,9 @@ #include +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) +#endif #include @@ -51,69 +53,208 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, return ret; } -void wxStaticText::OnPaint( wxPaintEvent &event ) +void wxStaticText::OnDraw( wxDC &dc ) { - wxPaintDC dc(this); PrepareDC(dc); dc.Clear() ; - dc.DrawText( m_label , 0 , 0 ) ; -} + + int x = 0 ; + int y = 0 ; + wxString text = m_label ; + wxString paragraph ; + int i = 0 ; + int laststop = 0 ; + long width, height ; -wxSize wxStaticText::DoGetBestSize() const -{ - int x , y ; - GetTextExtent( m_label , &x , &y ) ; - return wxSize( x , y ) ; + while( i < text.Length() ) + { + if( text[i] == 13 || text[i] == 10) + { + paragraph = text.Mid( laststop , i - laststop ) ; + while( paragraph.Length() > 0 ) + { + dc.GetTextExtent( paragraph , &width , &height ) ; + if ( width > m_width ) + { + for ( int p = paragraph.Length() -1 ; p > 0 ; --p ) + { + if ( paragraph[p]=='.' ) + { + dc.GetTextExtent( paragraph.Left(p+1) , &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+1), pos , y) ; + y += height ; + paragraph = paragraph.Mid(p+1) ; + break ; + } + } + if ( paragraph[p]==' ' ) + { + dc.GetTextExtent( paragraph.Left(p) , &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), pos , y) ; + y += height ; + paragraph = paragraph.Mid(p+1) ; + break ; + } + } + } + } + else + { + dc.DrawText( paragraph, x , y) ; + paragraph=""; + y += height ; + } + } + laststop = i+1 ; + } + ++i ; + } + paragraph = text.Mid( laststop , text.Length() - laststop ) ; + while( paragraph.Length() > 0 ) + { + dc.GetTextExtent( paragraph , &width , &height ) ; + if ( width > m_width ) + { + for ( int p = paragraph.Length() -1 ; p > 0 ; --p ) + { + if ( paragraph[p]=='.' ) + { + dc.GetTextExtent( paragraph.Left(p+1) , &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+1), pos , y) ; + y += height ; + paragraph = paragraph.Mid(p+1) ; + break ; + } + } + if ( paragraph[p]==' ' ) + { + dc.GetTextExtent( paragraph.Left(p) , &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), pos , y) ; + y += height ; + paragraph = paragraph.Mid(p+1) ; + break ; + } + } + } + } + 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=""; + y += height ; + } + } } -void wxStaticText::SetLabel(const wxString& st , bool resize ) -{ - SetTitle( st ) ; - m_label = st ; - if ( resize ) - SetSizeOrDefault() ; - else - Refresh() ; -} -/* -void wxStaticText::SetSize(int x, int y, int width, int height, int sizeFlags) +void wxStaticText::OnPaint( wxPaintEvent &event ) { - wxControl::SetSize( x , y , width , height , sizeFlags ) ; + wxPaintDC dc(this); + OnDraw( dc ) ; } -bool wxStaticText::Create(wxWindow *parent, wxWindowID id, - const wxString& label, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) +wxSize wxStaticText::DoGetBestSize() const { - Rect bounds ; - Str255 title ; - - MacPreControlCreate( parent , id , label , pos , size ,style, *((wxValidator*)NULL) , name , &bounds , title ) ; + int x , y ; + int widthTextMax = 0, widthLine, + heightTextTotal = 0, heightLineDefault = 0, heightLine = 0; - m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, - kControlStaticTextProc , (long) this ) ; - ::UMASetControlData( m_macControl, kControlLabelPart, kControlStaticTextTextTag , (long) title[0] , (char*) &title[1] ) ; - - MacPostControlCreate() ; + wxString curLine; + for ( const wxChar *pc = m_label; ; pc++ ) { + if ( *pc == wxT('\n') || *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; + } + else { + GetTextExtent(curLine, &widthLine, &heightLine); + if ( widthLine > widthTextMax ) + widthTextMax = widthLine; + heightTextTotal += heightLine; + } + + if ( *pc == wxT('\n') ) { + curLine.Empty(); + } + else { + // the end of string + break; + } + } + else { + curLine += *pc; + } + } - return TRUE; + return wxSize(widthTextMax, heightTextTotal); } -void wxStaticText::SetLabel(const wxString& st , bool resize ) +void wxStaticText::SetLabel(const wxString& st ) { SetTitle( st ) ; - wxString label ; + m_label = st ; + if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) + SetSizeOrDefault() ; - if( wxApp::s_macDefaultEncodingIsPC ) - label = wxMacMakeMacStringFromPC( st ) ; - else - label = st ; - - ::UMASetControlData( m_macControl, kControlLabelPart, kControlStaticTextTextTag , (long) label.Length() , (char*)(const char*) label ) ; - Refresh() ; + wxClientDC dc(this); + OnDraw( dc ) ; } -*/ - diff --git a/src/mac/tabctrl.cpp b/src/mac/tabctrl.cpp index ed13c3ac8a..5482141268 100644 --- a/src/mac/tabctrl.cpp +++ b/src/mac/tabctrl.cpp @@ -17,10 +17,12 @@ #include "wx/tabctrl.h" #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxTabCtrl, wxControl) BEGIN_EVENT_TABLE(wxTabCtrl, wxControl) END_EVENT_TABLE() +#endif wxTabCtrl::wxTabCtrl() { @@ -35,7 +37,7 @@ bool wxTabCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons m_imageList = NULL; - MacPreControlCreate( parent , id , "" , pos , size ,style, *((wxValidator*)NULL) , name , &bounds , title ) ; + MacPreControlCreate( parent , id , "" , pos , size ,style, wxDefaultValidator , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1, kControlTabSmallProc , (long) this ) ; diff --git a/src/mac/textctrl.cpp b/src/mac/textctrl.cpp index c1b98861b0..af3919bb7b 100644 --- a/src/mac/textctrl.cpp +++ b/src/mac/textctrl.cpp @@ -38,22 +38,34 @@ #include "wx/mac/uma.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) EVT_DROP_FILES(wxTextCtrl::OnDropFiles) EVT_CHAR(wxTextCtrl::OnChar) + EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) + EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) + EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) + EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) + EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) + + EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) + EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) + EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) + EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) + EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) END_EVENT_TABLE() +#endif // Text item wxTextCtrl::wxTextCtrl() -#ifndef NO_TEXT_WINDOW_STREAM - :streambuf() -#endif { - m_fileName = ""; } +const short kVerticalMargin = 2 ; +const short kHorizontalMargin = 2 ; + bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& st, const wxPoint& pos, @@ -61,25 +73,40 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - m_macHorizontalBorder = 2 ; // additional pixels around the real control - m_macVerticalBorder = 2 ; + // base initialization + if ( !CreateBase(parent, id, pos, size, style, validator, name) ) + return FALSE; wxSize mySize = size ; + if ( UMAHasAppearance() ) + { + m_macHorizontalBorder = 5 ; // additional pixels around the real control + m_macVerticalBorder = 5 ; + } + else + { + m_macHorizontalBorder = 0 ; // additional pixels around the real control + m_macVerticalBorder = 0 ; + } + Rect bounds ; Str255 title ; - + if ( mySize.y == -1 ) { if ( UMAHasAppearance() ) - mySize.y = 16 ; + mySize.y = 13 ; else mySize.y = 24 ; + + mySize.y += 2 * m_macVerticalBorder ; } + MacPreControlCreate( parent , id , "" , pos , mySize ,style, validator , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, - kControlEditTextProc , (long) this ) ; + ( style & wxTE_PASSWORD ) ? kControlEditTextPasswordProc : kControlEditTextProc , (long) this ) ; MacPostControlCreate() ; wxString value ; @@ -88,7 +115,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, value = wxMacMakeMacStringFromPC( st ) ; else value = st ; - UMASetControlData( m_macControl, 0, kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ; + UMASetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ; return TRUE; } @@ -96,7 +123,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, wxString wxTextCtrl::GetValue() const { Size actualsize; - UMAGetControlData( m_macControl, 0, kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ; + UMAGetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ; wxBuffer[actualsize] = 0 ; if( wxApp::s_macDefaultEncodingIsPC ) return wxMacMakePCStringFromMac( wxBuffer ) ; @@ -104,6 +131,18 @@ wxString wxTextCtrl::GetValue() const return wxString(wxBuffer); } +void wxTextCtrl::GetSelection(long* from, long* to) const +{ + ControlEditTextSelectionRec selection ; + TEHandle teH ; + long size ; + + UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; + + *from = (**teH).selStart; + *to = (**teH).selEnd; +} + void wxTextCtrl::SetValue(const wxString& st) { wxString value ; @@ -112,44 +151,116 @@ void wxTextCtrl::SetValue(const wxString& st) value = wxMacMakeMacStringFromPC( st ) ; else value = st ; - UMASetControlData( m_macControl, 0, kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ; + UMASetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ; Refresh() ; // MacInvalidateControl() ; } -void wxTextCtrl::SetSize(int x, int y, int width, int height, int sizeFlags) -{ - wxControl::SetSize( x , y , width , height , sizeFlags ) ; -} - // Clipboard operations void wxTextCtrl::Copy() { - TEHandle teH ; - long size ; + if (CanCopy()) + { + TEHandle teH ; + long size ; - UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; - TECopy( teH ) ; + UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; + TECopy( teH ) ; +#if TARGET_CARBON + OSStatus err ; + err = ClearCurrentScrap( ); +#else + OSErr err ; + err = ZeroScrap( ); +#endif + TEToScrap() ; + } } void wxTextCtrl::Cut() { - TEHandle teH ; - long size ; + if (CanCut()) + { + TEHandle teH ; + long size ; - UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; - TECut( teH ) ; -// MacInvalidateControl() ; + UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; + TECut( teH ) ; +#if TARGET_CARBON + OSStatus err ; + err = ClearCurrentScrap( ); +#else + OSErr err ; + err = ZeroScrap( ); +#endif + TEToScrap() ; + // MacInvalidateControl() ; + } } void wxTextCtrl::Paste() { - TEHandle teH ; - long size ; + if (CanPaste()) + { + TEHandle teH ; + long size ; - UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; - TEPaste( teH ) ; + UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; + TEFromScrap() ; + TEPaste( teH ) ; // MacInvalidateControl() ; + } +} + +bool wxTextCtrl::CanCopy() const +{ + // Can copy if there's a selection + long from, to; + GetSelection(& from, & to); + return (from != to); +} + +bool wxTextCtrl::CanCut() const +{ + // Can cut if there's a selection + long from, to; + GetSelection(& from, & to); + return (from != to); +} + +bool wxTextCtrl::CanPaste() const +{ + if (!IsEditable()) + return FALSE; + + long offset ; +#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 + if ( GetScrap( NULL , 'TEXT' , &offset ) > 0 ) + { + return TRUE ; + } +#endif + return FALSE ; } void wxTextCtrl::SetEditable(bool editable) @@ -243,65 +354,10 @@ void wxTextCtrl::SetSelection(long from, long to) bool wxTextCtrl::LoadFile(const wxString& file) { - if (!wxFileExists(file)) - return FALSE; - - m_fileName = file; - - Clear(); - -#ifndef __WXMAC__ - ifstream input((char*) (const char*) file, ios::nocreate | ios::in); -#else - ifstream input((char*) (const char*) file, ios::in); -#endif - if (!input.bad()) + if ( wxTextCtrlBase::LoadFile(file) ) { - struct stat stat_buf; - if (stat(file, &stat_buf) < 0) - return FALSE; - // This may need to be a bigger buffer than the file size suggests, - // if it's a UNIX file. Give it an extra 1000 just in case. - char *tmp_buffer = (char*)malloc((size_t)(stat_buf.st_size+1+1000)); - long no_lines = 0; - long pos = 0; - while (!input.eof() && input.peek() != EOF) - { - input.getline(wxBuffer, 500); - int len = strlen(wxBuffer); - wxBuffer[len] = 13; - wxBuffer[len+1] = 10; - wxBuffer[len+2] = 0; - strcpy(tmp_buffer+pos, wxBuffer); - pos += strlen(wxBuffer); - no_lines++; - } - - // TODO add line - - free(tmp_buffer); - - return TRUE; + return TRUE; } - return FALSE; -} - -// If file is null, try saved file name first -// Returns TRUE if succeeds. -bool wxTextCtrl::SaveFile(const wxString& file) -{ - wxString theFile(file); - if (theFile == "") - theFile = m_fileName; - if (theFile == "") - return FALSE; - m_fileName = theFile; - - ofstream output((char*) (const char*) theFile); - if (output.bad()) - return FALSE; - - // TODO get and save text return FALSE; } @@ -329,18 +385,8 @@ void wxTextCtrl::AppendText(const wxString& text) void wxTextCtrl::Clear() { - TEHandle teH ; - long size ; - ControlEditTextSelectionRec selection ; - - selection.selStart = 0 ; - selection.selEnd = 32767 ; - - UMASetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ; - - UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ; - TECut( teH ) ; -// MacInvalidateControl() ; + UMASetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ; + Refresh() ; } bool wxTextCtrl::IsModified() const @@ -348,6 +394,73 @@ bool wxTextCtrl::IsModified() const return TRUE; } +bool wxTextCtrl::IsEditable() const +{ + return IsEnabled(); +} + +bool wxTextCtrl::AcceptsFocus() const +{ + // we don't want focus if we can't be edited + return IsEditable() && wxControl::AcceptsFocus(); +} + +wxSize wxTextCtrl::DoGetBestSize() const +{ + int wText = 100 ; + + int hText ; + if ( UMAHasAppearance() ) + hText = 13 ; + else + hText = 24 ; + hText += 2 * m_macHorizontalBorder ; +/* + 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 *= wxMin(GetNumberOfLines(), 5); + } + //else: for single line control everything is ok + return wxSize(wText, hText); +} + +// ---------------------------------------------------------------------------- +// Undo/redo +// ---------------------------------------------------------------------------- + +void wxTextCtrl::Undo() +{ + if (CanUndo()) + { + } +} + +void wxTextCtrl::Redo() +{ + if (CanRedo()) + { + } +} + +bool wxTextCtrl::CanUndo() const +{ + return FALSE ; +} + +bool wxTextCtrl::CanRedo() const +{ + return FALSE ; +} + // Makes 'unmodified' void wxTextCtrl::DiscardEdits() { @@ -366,9 +479,9 @@ long wxTextCtrl::XYToPosition(long x, long y) const return 0; } -void wxTextCtrl::PositionToXY(long pos, long *x, long *y) const +bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const { - // TODO + return FALSE ; } void wxTextCtrl::ShowPosition(long pos) @@ -407,204 +520,125 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) void wxTextCtrl::OnChar(wxKeyEvent& event) { - switch( event.KeyCode() ) + switch ( event.KeyCode() ) { case WXK_RETURN: - { - if ( !(m_windowStyle & wxTE_MULTILINE) ) - { + if (m_windowStyle & wxPROCESS_ENTER) + { wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); event.SetEventObject( this ); if ( GetEventHandler()->ProcessEvent(event) ) return; + } + if ( !(m_windowStyle & wxTE_MULTILINE) ) + { + wxWindow *parent = GetParent(); + wxPanel *panel = wxDynamicCast(parent, wxPanel); + while ( parent != NULL && panel == NULL ) + { + parent = parent->GetParent() ; + panel = wxDynamicCast(parent, wxPanel); + } + if ( panel && panel->GetDefaultItem() ) + { + wxButton *def = panel->GetDefaultItem() ; + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); + event.SetEventObject(def); + def->Command(event); + event.Skip() ; + return ; + } } //else: multiline controls need Enter for themselves break; - } + case WXK_TAB: // always produce navigation event - even if we process TAB // ourselves the fact that we got here means that the user code // decided to skip processing of this TAB - probably to let it // do its default job. - // - // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is - // handled by Windows { wxNavigationKeyEvent eventNav; eventNav.SetDirection(!event.ShiftDown()); - eventNav.SetWindowChange(FALSE); + eventNav.SetWindowChange(event.ControlDown()); eventNav.SetEventObject(this); - if ( GetEventHandler()->ProcessEvent(eventNav) ) + if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) return; + event.Skip() ; + return ; } break; - - default: - event.Skip(); - return; } - // don't just call event.Skip() because this will cause TABs and ENTERs - // be passed upwards and we don't always want this - instead process it - // right here - - // FIXME - event.Skip(); -} -// The streambuf code was partly taken from chapter 3 by Jerry Schwarz of -// AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers - -//========================================================================= -// Called then the buffer is full (gcc 2.6.3) -// or when "endl" is output (Borland 4.5) -//========================================================================= -// Class declaration using multiple inheritance doesn't work properly for -// Borland. See note in wb_text.h. -#ifndef NO_TEXT_WINDOW_STREAM -int wxTextCtrl::overflow(int c) -{ - // Make sure there is a holding area - if ( allocate()==EOF ) - { - wxError("Streambuf allocation failed","Internal error"); - return EOF; - } - - // Verify that there are no characters in get area - if ( gptr() && gptr() < egptr() ) - { - wxError("Who's trespassing my get area?","Internal error"); - return EOF; - } - - // Reset get area - setg(0,0,0); - - // Make sure there is a put area - if ( ! pptr() ) - { -/* This doesn't seem to be fatal so comment out error message */ -// wxError("Put area not opened","Internal error"); - setp( base(), base() ); - } - - // Determine how many characters have been inserted but no consumed - int plen = pptr() - pbase(); - - // Now Jerry relies on the fact that the buffer is at least 2 chars - // long, but the holding area "may be as small as 1" ??? - // And we need an additional \0, so let's keep this inefficient but - // safe copy. - - // If c!=EOF, it is a character that must also be comsumed - int xtra = c==EOF? 0 : 1; - - // Write temporary C-string to wxTextWindow - { - char *txt = new char[plen+xtra+1]; - memcpy(txt, pbase(), plen); - txt[plen] = (char)c; // append c - txt[plen+xtra] = '\0'; // append '\0' or overwrite c - // If the put area already contained \0, output will be truncated there - AppendText(txt); - delete[] txt; - } - - // Reset put area - setp(pbase(), epptr()); - -#if defined(__WATCOMC__) - return __NOT_EOF; -#elif defined(zapeof) // HP-UX (all cfront based?) - return zapeof(c); -#else - return c!=EOF ? c : 0; // this should make everybody happy -#endif + EventRecord *ev = wxTheApp->MacGetCurrentEvent() ; + short keycode ; + short keychar ; + keychar = short(ev->message & charCodeMask); + keycode = short(ev->message & keyCodeMask) >> 8 ; + UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ; + if ( keychar >= 0x20 || event.KeyCode() == WXK_RETURN) + { + wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); + event.SetString( GetValue() ) ; + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); + } + } -//========================================================================= -// called then "endl" is output (gcc) or then explicit sync is done (Borland) -//========================================================================= -int wxTextCtrl::sync() -{ - // Verify that there are no characters in get area - if ( gptr() && gptr() < egptr() ) - { - wxError("Who's trespassing my get area?","Internal error"); - return EOF; - } - - if ( pptr() && pptr() > pbase() ) return overflow(EOF); - - return 0; -/* OLD CODE - int len = pptr() - pbase(); - char *txt = new char[len+1]; - strncpy(txt, pbase(), len); - txt[len] = '\0'; - (*this) << txt; - setp(pbase(), epptr()); - delete[] txt; - return 0; -*/ +// ---------------------------------------------------------------------------- +// standard handlers for standard edit menu events +// ---------------------------------------------------------------------------- + +void wxTextCtrl::OnCut(wxCommandEvent& event) +{ + Cut(); } -//========================================================================= -// Should not be called by a "ostream". Used by a "istream" -//========================================================================= -int wxTextCtrl::underflow() +void wxTextCtrl::OnCopy(wxCommandEvent& event) { - return EOF; + Copy(); } -#endif -wxTextCtrl& wxTextCtrl::operator<<(const wxString& s) +void wxTextCtrl::OnPaste(wxCommandEvent& event) { - AppendText(s); - return *this; + Paste(); } -wxTextCtrl& wxTextCtrl::operator<<(float f) +void wxTextCtrl::OnUndo(wxCommandEvent& event) { - wxString str; - str.Printf("%.2f", f); - AppendText(str); - return *this; + Undo(); } -wxTextCtrl& wxTextCtrl::operator<<(double d) +void wxTextCtrl::OnRedo(wxCommandEvent& event) { - wxString str; - str.Printf("%.2f", d); - AppendText(str); - return *this; + Redo(); } -wxTextCtrl& wxTextCtrl::operator<<(int i) +void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) { - wxString str; - str.Printf("%d", i); - AppendText(str); - return *this; + event.Enable( CanCut() ); } -wxTextCtrl& wxTextCtrl::operator<<(long i) +void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) { - wxString str; - str.Printf("%ld", i); - AppendText(str); - return *this; + event.Enable( CanCopy() ); } -wxTextCtrl& wxTextCtrl::operator<<(const char c) +void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) { - char buf[2]; + event.Enable( CanPaste() ); +} - buf[0] = c; - buf[1] = 0; - AppendText(buf); - return *this; +void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) +{ + event.Enable( CanUndo() ); +} + +void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) +{ + event.Enable( CanRedo() ); } diff --git a/src/mac/timer.cpp b/src/mac/timer.cpp index d845d50108..3d0bb31c08 100644 --- a/src/mac/timer.cpp +++ b/src/mac/timer.cpp @@ -15,13 +15,48 @@ #include "wx/timer.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_ABSTRACT_CLASS(wxTimer, wxObject) +#endif + +static void wxProcessTimer( unsigned long event , void *data ) ; + +pascal void MacTimerProc( TMTask * t ) +{ + MacTimerInfo * tm = (MacTimerInfo*) t ; + wxMacAddEvent( tm->m_table , wxProcessTimer, 0 , (void*) tm->m_timer , TRUE ) ; +} + +void wxProcessTimer( unsigned long event , void *data ) +{ + if ( !data ) + return ; + + wxTimer* timer = (wxTimer*) data ; + if ( timer->IsOneShot() ) + timer->Stop() ; + + timer->Notify(); + + if ( timer->m_info.m_task.tmAddr && !timer->IsOneShot() ) + { + PrimeTime( (QElemPtr) &timer->m_info.m_task , timer->GetInterval() ) ; + } +} wxTimer::wxTimer() { - m_milli = 0 ; - m_id = 0; - m_oneShot = FALSE; + m_info.m_task.tmAddr = NULL ; + m_info.m_task.tmWakeUp = 0 ; + m_info.m_task.tmReserved = 0 ; + m_info.m_task.qType = 0 ; + m_info.m_table = wxMacGetNotifierTable() ; + m_info.m_timer = this ; +} + +bool wxTimer::IsRunning() const +{ + return ( m_info.m_task.qType & kTMTaskActive ) ; } wxTimer::~wxTimer() @@ -31,20 +66,31 @@ wxTimer::~wxTimer() bool wxTimer::Start(int milliseconds,bool mode) { - m_oneShot = mode ; - if (milliseconds <= 0) - return FALSE; + (void)wxTimerBase::Start(milliseconds, mode); - m_milli = milliseconds; + wxCHECK_MSG( m_milli > 0, FALSE, wxT("invalid value for timer timeour") ); + wxCHECK_MSG( m_info.m_task.tmAddr == NULL , FALSE, wxT("attempting to restart a timer") ); - // TODO: set the timer going. + m_milli = milliseconds; + m_info.m_task.tmAddr = NewTimerProc( MacTimerProc ) ; + m_info.m_task.tmWakeUp = 0 ; + m_info.m_task.tmReserved = 0 ; + InsXTime((QElemPtr) &m_info.m_task ) ; + PrimeTime( (QElemPtr) &m_info.m_task , m_milli ) ; return FALSE; } void wxTimer::Stop() { - m_id = 0 ; m_milli = 0 ; + if ( m_info.m_task.tmAddr ) + { + RmvTime( (QElemPtr) &m_info.m_task ) ; + DisposeTimerUPP(m_info.m_task.tmAddr) ; + m_info.m_task.tmAddr = NULL ; + } + wxMacRemoveAllNotifiersForData( wxMacGetNotifierTable() , this ) ; } + diff --git a/src/mac/toolbar.cpp b/src/mac/toolbar.cpp index e4bd0aff79..e118add0ed 100644 --- a/src/mac/toolbar.cpp +++ b/src/mac/toolbar.cpp @@ -5,8 +5,7 @@ // Modified by: // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) AUTHOR -// Licence: wxWindows licence +// Copyright: (c) AUTHORy ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -18,11 +17,17 @@ #if wxUSE_TOOLBAR #include "wx/toolbar.h" +#include "wx/notebook.h" +#include "wx/tabctrl.h" -IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase) +#if !USE_SHARED_LIBRARY +IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) + EVT_MOUSE_EVENTS( wxToolBar::OnMouse ) + EVT_PAINT( wxToolBar::OnPaint ) END_EVENT_TABLE() +#endif #include @@ -45,14 +50,14 @@ public: clientData, shortHelpString, longHelpString) { m_nSepCount = 0; - m_index = 0 ; + m_index = -1 ; } wxToolBarTool(wxToolBar *tbar, wxControl *control) : wxToolBarToolBase(tbar, control) { m_nSepCount = 1; - m_index = 0 ; + m_index = -1 ; } // set/get the number of separators which we use to cover the space used by @@ -74,6 +79,9 @@ private: // wxToolBarTool // ---------------------------------------------------------------------------- +const short defwidth = 24 ; +const short defheight = 22 ; + wxToolBarToolBase *wxToolBar::CreateTool(int id, const wxBitmap& bitmap1, const wxBitmap& bitmap2, @@ -91,16 +99,12 @@ wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) return new wxToolBarTool(this, control); } -// ---------------------------------------------------------------------------- -// wxToolBar construction -// ---------------------------------------------------------------------------- - void wxToolBar::Init() { m_maxWidth = -1; m_maxHeight = -1; - m_defaultWidth = 24; - m_defaultHeight = 22; + m_defaultWidth = defwidth; + m_defaultHeight = defheight; // TODO } @@ -109,8 +113,8 @@ bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons { m_maxWidth = m_maxHeight = 0; - m_defaultWidth = 24; - m_defaultHeight = 22; + m_defaultWidth = defwidth; + m_defaultHeight = defheight; int x = pos.x; int y = pos.y; @@ -125,16 +129,39 @@ bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, cons x = 0; if (y < 0) y = 0; - +#if 1 + { + 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 ; + } +#else Rect bounds ; Str255 title ; - MacPreControlCreate( parent , id , "" , wxPoint( x , y ) , wxSize( width , height ) ,style, *((wxValidator*)NULL) , name , &bounds , title ) ; + MacPreControlCreate( parent , id , "" , wxPoint( x , y ) , wxSize( width , height ) ,style, wxDefaultValidator , name , &bounds , title ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, kControlPlacardProc , (long) this ) ; MacPostControlCreate() ; - +#endif return TRUE; } @@ -143,7 +170,8 @@ wxToolBar::~wxToolBar() // TODO } -PicHandle MakePict(GWorldPtr wp) +PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ; +PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) { CGrafPtr origPort ; GDHandle origDev ; @@ -151,52 +179,77 @@ PicHandle MakePict(GWorldPtr wp) PicHandle pict; // this is the Picture we give back RGBColor gray = { 0xCCCC ,0xCCCC , 0xCCCC } ; + RGBColor white = { 0xffff ,0xffff , 0xffff } ; + RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ; - GetGWorld( &origPort , &origDev ) ; - SetGWorld( wp , NULL ) ; - - pict = OpenPicture(&wp->portRect); // open a picture, this disables drawing - if(!pict) - return NULL; - - RGBBackColor( &gray ) ; - EraseRect(&wp->portRect) ; - CopyBits((BitMap*)*wp->portPixMap, // src PixMap - we copy image over itself - - (BitMap*)*wp->portPixMap, // dst PixMap - no drawing occurs - - &wp->portRect, // srcRect - it will be recorded and compressed - - &wp->portRect, // dstRect - into the picture that is open - - srcCopy,NULL); // copyMode and no clip region - - ClosePicture(); // We are done recording the picture - SetGWorld( origPort , origDev ) ; - return pict; // return our groovy pict handle -} - -PicHandle MakePictWhite(GWorldPtr wp) -{ - CGrafPtr origPort ; - GDHandle origDev ; + unsigned char *maskimage = NULL ; + Rect portRect ; + GetPortBounds( wp , &portRect ) ; + int width = portRect.right - portRect.left ; + int height = portRect.bottom - portRect.top ; - PicHandle pict; // this is the Picture we give back + LockPixels( GetGWorldPixMap( wp ) ) ; + GetGWorld( &origPort , &origDev ) ; - RGBColor white = { 0xFFFF ,0xFFFF , 0xFFFF } ; + if ( mask ) + { + + maskimage = (unsigned char*) malloc( width * height ) ; + SetGWorld( mask , NULL ) ; + LockPixels( GetGWorldPixMap( mask ) ) ; + for ( int y = 0 ; y < height ; ++y ) + { + for( int x = 0 ; x < width ; ++x ) + { + RGBColor col ; + + GetCPixel( x + portRect.left , y + portRect.top , &col ) ; + maskimage[y*width + x] = ( col.red == 0 ) ; // for monochrome masks + } + } + UnlockPixels( GetGWorldPixMap( mask ) ) ; + } - GetGWorld( &origPort , &origDev ) ; SetGWorld( wp , NULL ) ; - pict = OpenPicture(&wp->portRect); // open a picture, this disables drawing + pict = OpenPicture(&portRect); // open a picture, this disables drawing if(!pict) return NULL; - + + RGBBackColor( &gray ) ; + RGBForeColor( &black ) ; + EraseRect(&portRect) ; RGBBackColor( &white ) ; - EraseRect(&wp->portRect) ; - CopyBits((BitMap*)*wp->portPixMap, // src PixMap - we copy image over itself - - (BitMap*)*wp->portPixMap, // dst PixMap - no drawing occurs - - &wp->portRect, // srcRect - it will be recorded and compressed - - &wp->portRect, // dstRect - into the picture that is open - + + if ( maskimage ) + { + for ( int y = 0 ; y < height ; ++y ) + { + for( int x = 0 ; x < width ; ++x ) + { + if ( maskimage[y*width + x] ) + { + RGBColor col ; + + GetCPixel( x + portRect.left , y + portRect.top , &col ) ; + SetCPixel( x + portRect.left , y + portRect.top , &col ) ; + } + } + } + free( maskimage ) ; + maskimage = NULL ; + } + else + { + CopyBits(GetPortBitMapForCopyBits(wp), // src PixMap - we copy image over itself - + GetPortBitMapForCopyBits(wp), // dst PixMap - no drawing occurs - + &portRect, // srcRect - it will be recorded and compressed - + &portRect, // dstRect - into the picture that is open - srcCopy,NULL); // copyMode and no clip region + } ClosePicture(); // We are done recording the picture + UnlockPixels( GetGWorldPixMap( wp ) ) ; SetGWorld( origPort , origDev ) ; return pict; // return our groovy pict handle } @@ -226,7 +279,7 @@ bool wxToolBar::Realize() wxToolBarTool *tool = (wxToolBarTool *)node->Data(); wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->GetBitmap1().GetRefData()) ; - if( !tool->IsSeparator() ) + if( !tool->IsSeparator() ) { Rect toolrect = { toolbarrect.top + kwxMacToolBarTopMargin , toolbarrect.left + x + kwxMacToolBarLeftMargin , 0 , 0 } ; toolrect.right = toolrect.left + toolSize.x ; @@ -239,12 +292,19 @@ bool wxToolBar::Realize() icon = bmap->m_hPict ; else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) { - icon = MakePict( bmap->m_hBitmap ) ; + if ( tool->GetBitmap1().GetMask() ) + { + icon = MakePict( bmap->m_hBitmap , tool->GetBitmap1().GetMask()->GetMaskBitmap() ) ; + } + else + { + icon = MakePict( bmap->m_hBitmap , NULL ) ; + } } } ControlHandle m_macToolHandle ; - + SInt16 behaviour = kControlBehaviorOffsetContents ; if ( tool->CanBeToggled() ) behaviour += kControlBehaviorToggles ; @@ -266,8 +326,19 @@ bool wxToolBar::Realize() behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; } m_macToolHandles.Add( m_macToolHandle ) ; + tool->m_index = m_macToolHandles.Count() -1 ; + if ( !tool->IsEnabled() ) + { + UMADeactivateControl( m_macToolHandle ) ; + } + if ( tool->CanBeToggled() && tool->IsToggled() ) + { + ::SetControlValue( m_macToolHandle , 1 ) ; + } UMASetControlFontStyle( m_macToolHandle , &controlstyle ) ; - UMAEmbedControl( m_macToolHandle , m_macControl ) ; + ControlHandle container = GetParent()->MacGetContainerForEmbedding() ; + wxASSERT_MSG( container != NULL , "No valid mac container control" ) ; + UMAEmbedControl( m_macToolHandle , container ) ; x += (int)toolSize.x; noButtons ++; @@ -311,7 +382,7 @@ void wxToolBar::SetToolBitmapSize(const wxSize& size) // The button size is bigger than the bitmap size wxSize wxToolBar::GetToolSize() const { - return wxSize(m_defaultWidth + 8, m_defaultHeight + 7); + return wxSize(m_defaultWidth + 4, m_defaultHeight + 4); } void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) @@ -321,7 +392,13 @@ void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpar { if ( m_macToolHandles[index] == (void*) control ) { - OnLeftClick( ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->m_index , ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->IsToggled() ) ; + wxToolBarTool *tool = (wxToolBarTool *)m_tools.Nth( index )->Data(); + if ( tool->CanBeToggled() ) + { + tool->Toggle( GetControlValue( control ) ) ; + } + OnLeftClick( tool->GetId() , tool -> IsToggled() ) ; + break ; } } } @@ -340,43 +417,54 @@ void wxToolBar::SetRows(int nRows) wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const { MacClientToRootWindow( &x , &y ) ; - Point pt = { x ,y } ; + Point pt = { y ,x } ; int index = 0 ; for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) { - if ( PtInRect( pt , &(**(ControlHandle)(m_macToolHandles[index])).contrlRect) ) + if ( m_macToolHandles[index] ) { - return (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ; + Rect bounds ; + GetControlBounds((ControlHandle) m_macToolHandles[index], &bounds ) ; + if ( PtInRect( pt , &bounds ) ) + { + return (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ; + } } } return (wxToolBarToolBase *)NULL; } +wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) +{ + wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ; + if ( tool ) + { + return tool->GetShortHelp() ; + } + return "" ; +} + void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) { wxToolBarTool *tool = (wxToolBarTool *)t; + if ( tool->m_index < 0 ) + return ; + ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ; - if ( UMAHasAppearance() ) - { - if ( enable ) - ::ActivateControl( control ) ; - else - ::DeactivateControl( control ) ; - } + + if ( enable ) + UMAActivateControl( control ) ; else - { - if ( enable ) - ::HiliteControl( control , 0 ) ; - else - ::HiliteControl( control , 255 ) ; - } + UMADeactivateControl( control ) ; } void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) { wxToolBarTool *tool = (wxToolBarTool *)t; + if ( tool->m_index < 0 ) + return ; ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ; ::SetControlValue( control , toggle ) ; @@ -402,5 +490,116 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) { return TRUE ; } + +void wxToolBar::OnPaint(wxPaintEvent& event) +{ + WindowRef window = GetMacRootWindow() ; + if ( window ) + { + wxWindow* win = wxFindWinFromMacWindow( window ) ; + if ( win ) + { + wxMacDrawingHelper help( win ) ; + // the mac control manager always assumes to have the origin at 0,0 + SetOrigin( 0 , 0 ) ; + + bool hasTabBehind = false ; + wxWindow* parent = GetParent() ; + while ( parent ) + { + if( parent->MacGetWindowData() ) + { + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; + break ; + } + + if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) + { + if ( ((wxControl*)parent)->GetMacControl() ) + SetUpControlBackground( ((wxControl*)parent)->GetMacControl() , -1 , true ) ; + break ; + } + + parent = parent->GetParent() ; + } + Rect toolbarrect = { m_y , m_x , m_y + m_height , m_x + m_width } ; + + UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; + { + int index = 0 ; + for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) + { + if ( m_macToolHandles[index] ) + { + UMADrawControl( (ControlHandle) m_macToolHandles[index] ) ; + } + } + } + UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; + } + } +} +void wxToolBar::OnMouse( wxMouseEvent &event ) +{ + + 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 ; + GrafPtr port ; + SInt16 controlpart ; + WindowRef window = GetMacRootWindow() ; + + 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 ; + + controlpart = FindControl( localwhere , window , &control ) ; + { + if ( AcceptsFocus() && FindFocus() != this ) + { + SetFocus() ; + } + if ( control && UMAIsControlActive( control ) ) + { + { + if ( controlpart == kControlIndicatorPart && !UMAHasAppearance() ) + controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) NULL ) ; + else + controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; + wxTheApp->s_lastMouseDown = 0 ; + if ( controlpart && ! ( ( UMAHasAppearance() || (controlpart != kControlIndicatorPart) ) + && (IsKindOf( CLASSINFO( wxScrollBar ) ) ) ) ) // otherwise we will get the event twice + { + MacHandleControlClick( control , controlpart ) ; + } + } + } + } + } +} + #endif // wxUSE_TOOLBAR diff --git a/src/mac/treectrl.cpp b/src/mac/treectrl.cpp index 3aea32e970..137a885dbf 100644 --- a/src/mac/treectrl.cpp +++ b/src/mac/treectrl.cpp @@ -16,9 +16,11 @@ #include "wx/stubs/textctrl.h" #include "wx/stubs/treectrl.h" +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject) +#endif wxTreeCtrl::wxTreeCtrl() { diff --git a/src/mac/uma.cpp b/src/mac/uma.cpp index ba96908df9..4dce1ce377 100644 --- a/src/mac/uma.cpp +++ b/src/mac/uma.cpp @@ -33,7 +33,7 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) long total,contig; PurgeSpace(&total, &contig); #else - InitMenus() ; + InitCursor(); #endif #if UMA_USE_APPEARANCE @@ -87,7 +87,7 @@ bool UMAGetProcessModeDoesActivateOnFGSwitch() // menu manager -void UMASetMenuTitle( MenuRef menu , ConstStr255Param title ) +void UMASetMenuTitle( MenuRef menu , StringPtr title ) { #if !TARGET_CARBON long size = GetHandleSize( (Handle) menu ) ; @@ -117,11 +117,13 @@ void UMASetMenuTitle( MenuRef menu , ConstStr255Param title ) UInt32 UMAMenuEvent( EventRecord *inEvent ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return MenuEvent( inEvent ) ; } else +#endif { if ( inEvent->what == keyDown && inEvent->modifiers & cmdKey) { @@ -133,7 +135,7 @@ UInt32 UMAMenuEvent( EventRecord *inEvent ) void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem ) { -#if UMA_USE_8_6 +#if UMA_USE_8_6 || TARGET_CARBON EnableMenuItem( inMenu , inItem ) ; #else EnableItem( inMenu , inItem ) ; @@ -142,14 +144,145 @@ void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem ) void UMADisableMenuItem( MenuRef inMenu , MenuItemIndex inItem ) { -#if UMA_USE_8_6 +#if UMA_USE_8_6 || TARGET_CARBON DisableMenuItem( inMenu , inItem ) ; #else DisableItem( inMenu , inItem ) ; #endif } + +void UMAAppendSubMenuItem( MenuRef menu , StringPtr l , SInt16 id ) +{ + Str255 label ; + memcpy( label , l , l[0]+1 ) ; + // hardcoded adding of the submenu combination for mac + + int theEnd = label[0] + 1; + if (theEnd > 251) + theEnd = 251; // mac allows only 255 characters + label[theEnd++] = '/'; + label[theEnd++] = hMenuCmd; + label[theEnd++] = '!'; + label[theEnd++] = id ; + label[theEnd] = 0x00; + label[0] = theEnd; + MacAppendMenu(menu, label); +} + +void UMAInsertSubMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 id ) +{ + Str255 label ; + memcpy( label , l , l[0]+1 ) ; + // hardcoded adding of the submenu combination for mac + + int theEnd = label[0] + 1; + if (theEnd > 251) + theEnd = 251; // mac allows only 255 characters + label[theEnd++] = '/'; + label[theEnd++] = hMenuCmd; + label[theEnd++] = '!'; + label[theEnd++] = id; + label[theEnd] = 0x00; + label[0] = theEnd; + MacInsertMenuItem(menu, label , item); +} + +void UMAAppendMenuItem( MenuRef menu , StringPtr l , SInt16 key, UInt8 modifiers ) +{ + Str255 label ; + memcpy( label , l , l[0]+1 ) ; + if ( key ) + { + int pos = label[0] ; + label[++pos] = '/'; + label[++pos] = toupper( key ); + label[0] = pos ; + } + MacAppendMenu( menu , label ) ; +} + +void UMAInsertMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 key, UInt8 modifiers ) +{ + Str255 label ; + memcpy( label , l , l[0]+1 ) ; + if ( key ) + { + int pos = label[0] ; + label[++pos] = '/'; + label[++pos] = toupper( key ); + label[0] = pos ; + } + MacInsertMenuItem( menu , label , item) ; +} + +void UMADrawMenuBar() +{ + DrawMenuBar() ; +} + + +void UMASetMenuItemText( MenuRef menu , MenuItemIndex item , StringPtr label ) +{ + ::SetMenuItemText( menu , item , label ) ; +} + +MenuRef UMANewMenu( SInt16 menuid , StringPtr label ) +{ + return ::NewMenu(menuid, label); +} + +void UMADisposeMenu( MenuRef menu ) +{ + DisposeMenu( menu ) ; +} +void UMADeleteMenu( SInt16 menuId ) +{ + ::DeleteMenu( menuId ) ; +} + +void UMAInsertMenu( MenuRef insertMenu , SInt16 afterId ) +{ + ::InsertMenu( insertMenu , afterId ) ; +} + + // quickdraw +int gPrOpenCounter = 0 ; + +void UMAPrOpen() +{ +#if !TARGET_CARBON + OSErr err = noErr ; + ++gPrOpenCounter ; + if ( gPrOpenCounter == 1 ) + { + PrOpen() ; + err = PrError() ; + wxASSERT( err == noErr ) ; + } +#else + #pragma warning "TODO Printing for Carbon" +#endif +} + +void UMAPrClose() +{ +#if !TARGET_CARBON + OSErr err = noErr ; + wxASSERT( gPrOpenCounter >= 1 ) ; + if ( gPrOpenCounter == 1 ) + { + PrClose() ; + err = PrError() ; + wxASSERT( err == noErr ) ; + } + --gPrOpenCounter ; +#else + #pragma warning "TODO Printing for Carbon" +#endif +} + #if !TARGET_CARBON pascal QDGlobalsPtr GetQDGlobalsPtr (void) @@ -260,77 +393,145 @@ void UMACloseWindow(WindowRef inWindowRef) void UMAActivateControl( ControlHandle inControl ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::ActivateControl( inControl ) ; } else +#endif +#if !TARGET_CARBON { AGAActivateControl( inControl ) ; } +#else + { + } +#endif } void UMADrawControl( ControlHandle inControl ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::DrawControlInCurrentPort( inControl ) ; } else +#endif +#if !TARGET_CARBON { AGADrawControl( inControl ) ; } +#else + { + } +#endif } void UMAMoveControl( ControlHandle inControl , short x , short y ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::MoveControl( inControl , x , y ) ; } else +#endif +#if !TARGET_CARBON { AGAMoveControl( inControl , x ,y ) ; } +#else + { + } +#endif } void UMASizeControl( ControlHandle inControl , short x , short y ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::SizeControl( inControl , x , y ) ; } else +#endif +#if !TARGET_CARBON { AGASizeControl( inControl , x ,y ) ; } +#else + { + } +#endif } void UMADeactivateControl( ControlHandle inControl ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::DeactivateControl( inControl ) ; } else +#endif +#if !TARGET_CARBON { AGADeactivateControl( inControl ) ; } +#else + { + } +#endif } void UMASetThemeWindowBackground (WindowRef inWindow, ThemeBrush inBrush, - Boolean inUpdate){ + Boolean inUpdate) +{ +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { ::SetThemeWindowBackground( inWindow ,inBrush , inUpdate ) ; } else +#endif +#if !TARGET_CARBON { AGASetThemeWindowBackground( inWindow , inBrush , inUpdate ) ; } +#else + { + } +#endif } +void UMAApplyThemeBackground (ThemeBackgroundKind inKind, + const Rect * bounds, + ThemeDrawState inState, + SInt16 inDepth, + Boolean inColorDev) +{ +#if UMA_USE_APPEARANCE + if ( UMAHasAppearance() ) + { + /* + if ( sUMAAppearanceVersion >= 0x0110 ) + ::ApplyThemeBackground( inKind ,bounds , inState , inDepth , inColorDev ) ; + */ + } + else +#endif +#if !TARGET_CARBON + { + AGAApplyThemeBackground( inKind ,bounds , inState , inDepth , inColorDev ) ; + } +#else + { + } +#endif +} ControlHandle UMANewControl(WindowPtr owningWindow, const Rect * boundsRect, @@ -343,16 +544,23 @@ ControlHandle UMANewControl(WindowPtr owningWindow, SInt32 controlReference) { ControlHandle theControl = NULL ; +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { theControl = NewControl( owningWindow , boundsRect , controlTitle , initiallyVisible , initialValue , minimumValue , maximumValue , procID , controlReference ) ; } else +#endif +#if !TARGET_CARBON { theControl = AGANewControl( owningWindow , boundsRect , controlTitle , initiallyVisible , initialValue , minimumValue , maximumValue , procID , controlReference ) ; } +#else + { + } +#endif return theControl ; } @@ -415,7 +623,9 @@ void UMASetControlVisibility (ControlHandle inControl, { if ( UMAHasAppearance() ) { +#if UMA_USE_APPEARANCE ::SetControlVisibility( inControl , inIsVisible, inDoDraw ) ; +#endif } } @@ -423,21 +633,29 @@ void UMASetControlVisibility (ControlHandle inControl, bool UMAIsControlActive (ControlHandle inControl) { +#if TARGET_CARBON + return IsControlActive( inControl ) ; +#else +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return IsControlActive( inControl ) ; } else +#endif return (**inControl).contrlHilite == 0 ; +#endif } bool UMAIsControlVisible (ControlHandle inControl) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return IsControlVisible( inControl ) ; } +#endif return true ; } @@ -445,26 +663,42 @@ OSErr UMAGetBestControlRect (ControlHandle inControl, Rect * outRect, SInt16 * outBaseLineOffset) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return GetBestControlRect( inControl , outRect , outBaseLineOffset ) ; } else +#endif +#if !TARGET_CARBON { return AGAGetBestControlRect( inControl , outRect , outBaseLineOffset ) ; } +#else + { + return noErr ; + } +#endif } OSErr UMASetControlFontStyle (ControlHandle inControl, const ControlFontStyleRec * inStyle) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return ::SetControlFontStyle( inControl , inStyle ) ; } else +#endif +#if !TARGET_CARBON return AGASetControlFontStyle( inControl , inStyle ) ; +#else + { + return noErr ; + } +#endif } @@ -474,12 +708,20 @@ OSErr UMASetControlFontStyle (ControlHandle inControl, OSErr UMACreateRootControl (WindowPtr inWindow, ControlHandle * outControl) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return CreateRootControl( inWindow , outControl ) ; } else +#endif +#if !TARGET_CARBON return AGACreateRootControl( inWindow , outControl ) ; +#else + { + return noErr ; + } +#endif } @@ -487,12 +729,20 @@ OSErr UMACreateRootControl (WindowPtr inWindow, OSErr UMAEmbedControl (ControlHandle inControl, ControlHandle inContainer) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return EmbedControl( inControl , inContainer ) ; } else +#endif +#if !TARGET_CARBON return AGAEmbedControl( inControl , inContainer ) ; ; +#else + { + return noErr ; + } +#endif } @@ -502,12 +752,30 @@ OSErr UMASetKeyboardFocus (WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) { + OSErr err = noErr; + GrafPtr port ; + GetPort( &port ) ; +#if TARGET_CARBON + SetPort( GetWindowPort( inWindow ) ) ; +#else + SetPort( inWindow ) ; +#endif + SetOrigin( 0 , 0 ) ; +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { - return SetKeyboardFocus( inWindow , inControl , inPart ) ; + err = SetKeyboardFocus( inWindow , inControl , inPart ) ; } else - return AGASetKeyboardFocus( inWindow , inControl , inPart ) ; +#endif +#if !TARGET_CARBON + err = AGASetKeyboardFocus( inWindow , inControl , inPart ) ; +#else + { + } +#endif + SetPort( port ) ; + return err ; } @@ -520,14 +788,22 @@ ControlPartCode UMAHandleControlClick (ControlHandle inControl, SInt16 inModifiers, ControlActionUPP inAction) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return HandleControlClick( inControl , inWhere , inModifiers , inAction ) ; } else +#endif +#if !TARGET_CARBON { return AGAHandleControlClick( inControl , inWhere , inModifiers , inAction ) ; } +#else + { + return noErr ; + } +#endif } @@ -536,52 +812,82 @@ SInt16 UMAHandleControlKey (ControlHandle inControl, SInt16 inCharCode, SInt16 inModifiers) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return HandleControlKey( inControl , inKeyCode , inCharCode , inModifiers ) ; } else +#endif +#if !TARGET_CARBON { return AGAHandleControlKey(inControl , inKeyCode , inCharCode , inModifiers ) ; } +#else + { + return noErr ; + } +#endif } void UMAIdleControls (WindowPtr inWindow) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { IdleControls( inWindow ) ; } else +#endif +#if !TARGET_CARBON { AGAIdleControls( inWindow ) ; } +#else + { + } +#endif } void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { UpdateControls( inWindow , inRgn ) ; } else +#endif +#if !TARGET_CARBON { AGAUpdateControls( inWindow , inRgn ) ; } +#else + { + } +#endif } OSErr UMAGetRootControl( WindowPtr inWindow , ControlHandle *outControl ) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return GetRootControl( inWindow , outControl ) ; } else +#endif +#if !TARGET_CARBON { return AGAGetRootControl( inWindow , outControl ) ; } +#else + { + return noErr ; + } +#endif } @@ -593,12 +899,20 @@ OSErr UMASetControlData (ControlHandle inControl, Size inSize, Ptr inData) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return SetControlData( inControl , inPart , inTagName , inSize , inData ) ; } else +#endif +#if !TARGET_CARBON return AGASetControlData( inControl , inPart , inTagName , inSize , inData ) ; +#else + { + return noErr ; + } +#endif } @@ -610,15 +924,22 @@ OSErr UMAGetControlData (ControlHandle inControl, Ptr outBuffer, Size * outActualSize) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return ::GetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ; } else +#endif +#if !TARGET_CARBON { return AGAGetControlData( inControl , inPart , inTagName , inBufferSize , outBuffer , outActualSize ) ; } - +#else + { + return noErr ; + } +#endif } @@ -627,14 +948,22 @@ OSErr UMAGetControlDataSize (ControlHandle inControl, ResType inTagName, Size * outMaxSize) { +#if UMA_USE_APPEARANCE if ( UMAHasAppearance() ) { return GetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ; } else +#endif +#if !TARGET_CARBON { return AGAGetControlDataSize( inControl , inPart , inTagName , outMaxSize ) ; } +#else + { + return noErr ; + } +#endif } @@ -711,11 +1040,70 @@ OSStatus UMACreateNewWindow( WindowClass windowClass , WindowAttributes attribu case kMovableModalWindowClass : procID = kWindowMovableModalDialogProc; break ; - case kDocumentWindowClass : - procID = kWindowFullZoomGrowDocumentProc; + case kModalWindowClass : + procID = kWindowShadowDialogProc; + break ; + case kFloatingWindowClass : + if ( attributes & kWindowSideTitlebarAttribute ) + { + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = kWindowFloatSideFullZoomGrowProc ; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = kWindowFloatSideFullZoomProc; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = kWindowFloatSideGrowProc; + } + else + { + procID = kWindowFloatSideProc; + } + } + else + { + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = kWindowFloatFullZoomGrowProc ; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = kWindowFloatFullZoomProc; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = kWindowFloatGrowProc; + } + else + { + procID = kWindowFloatProc; + } + } break ; + case kDocumentWindowClass : default : - procID = kWindowMovableModalDialogProc; + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = kWindowFullZoomGrowDocumentProc; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = kWindowFullZoomDocumentProc; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = kWindowGrowDocumentProc; + } + else + { + procID = kWindowDocumentProc; + } break ; } } @@ -725,13 +1113,72 @@ OSStatus UMACreateNewWindow( WindowClass windowClass , WindowAttributes attribu { case kMovableModalWindowClass : procID = movableDBoxProc; -// procID += kMovableModalDialogVariantCode; break ; - case kDocumentWindowClass : - procID = zoomDocProc; + case kModalWindowClass : + procID = altDBoxProc; + break ; + case kFloatingWindowClass : + if ( attributes & kWindowSideTitlebarAttribute ) + { + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = floatSideZoomGrowProc ; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = floatSideZoomProc; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = floatSideGrowProc; + } + else + { + procID = floatSideProc; + } + } + else + { + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = floatZoomGrowProc ; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = floatZoomProc; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = floatGrowProc; + } + else + { + procID = floatProc; + } + } break ; + case kDocumentWindowClass : default : - procID = documentProc; + if( ( attributes & kWindowResizableAttribute ) && + ( attributes & kWindowFullZoomAttribute ) ) + { + procID = zoomDocProc; + } + else if( attributes & kWindowFullZoomAttribute ) + { + procID = zoomNoGrow; + } + else if ( attributes & kWindowResizableAttribute ) + { + procID = documentProc; + } + else + { + procID = noGrowDocProc; + } + break ; break ; } } @@ -853,6 +1300,32 @@ void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ) // bool isHighlighted = IsWindowHighlited( inWindowRef ) ; // if ( inActivate != isHightlited ) HiliteWindow( inWindowRef , inActivate ) ; + ControlHandle control = NULL ; + UMAGetRootControl( inWindowRef , & control ) ; + if ( control ) + { + if ( inActivate ) + UMAActivateControl( control ) ; + else + UMADeactivateControl( control ) ; + } } } +OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ) +{ +#if UMA_USE_APPEARANCE + if ( UMAHasAppearance() ) + { + ::DrawThemePlacard( inRect , inState ) ; + } + else +#endif +#if !TARGET_CARBON + { + } +#else + { + } +#endif +} diff --git a/src/mac/utils.cpp b/src/mac/utils.cpp index 817138cb63..0031f1efad 100644 --- a/src/mac/utils.cpp +++ b/src/mac/utils.cpp @@ -18,6 +18,7 @@ #include "wx/setup.h" #include "wx/utils.h" #include "wx/app.h" +#include "wx/mac/uma.h" #include @@ -26,7 +27,13 @@ #include #include -// Get full hostname (eg. DoDo.BSn-Germany.crg.de) +// get full hostname (with domain name if possible) +bool wxGetFullHostName(wxChar *buf, int maxSize) +{ + return wxGetHostName(buf, maxSize); +} + +// Get hostname only (without domain name) bool wxGetHostName(char *buf, int maxSize) { // TODO @@ -227,7 +234,10 @@ void wxEndBusyCursor() if ( gMacStoredActiveCursor ) ::SetCursor( *gMacStoredActiveCursor ) ; else - ::SetCursor( &qd.arrow ) ; + { + Cursor MacArrow ; + ::SetCursor( GetQDGlobalsArrow( &MacArrow ) ) ; + } gMacStoredActiveCursor = NULL ; } } @@ -238,6 +248,25 @@ bool wxIsBusy() return (wxBusyCursorCount > 0); } +wxString wxMacFindFolder( short vol, + OSType folderType, + Boolean createFolder) +{ + short vRefNum ; + long dirID ; + wxString strDir ; + + if ( FindFolder( vol, folderType, createFolder, &vRefNum, &dirID) == noErr) + { + FSSpec file ; + if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr ) + { + strDir = wxMacFSSpec2UnixFilename( &file ) + "/" ; + } + } + return strDir ; +} + char *wxGetUserHome (const wxString& user) { // TODO @@ -271,23 +300,32 @@ bool wxColourDisplay() // Returns depth of screen int wxDisplayDepth() { - // get max pixel depth - CGrafPtr port ; - GetCWMgrPort( &port ) ; - GDHandle maxDevice ; + Rect globRect ; + SetRect(&globRect, -32760, -32760, 32760, 32760); + GDHandle theMaxDevice; + + int theDepth = 8; + theMaxDevice = GetMaxDevice(&globRect); + if (theMaxDevice != nil) + theDepth = (**(**theMaxDevice).gdPMap).pixelSize; - maxDevice = GetMaxDevice( &port->portRect ) ; - if ( maxDevice ) - return (**((**maxDevice).gdPMap)).pixelSize ; - else - return 8 ; + return theDepth ; } // Get size of display void wxDisplaySize(int *width, int *height) { - *width = qd.screenBits.bounds.right - qd.screenBits.bounds.left ; - *height = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top ; - *height -= LMGetMBarHeight() ; + BitMap screenBits; + GetQDGlobalsScreenBits( &screenBits ); + + *width = screenBits.bounds.right - screenBits.bounds.left ; + *height = screenBits.bounds.bottom - screenBits.bounds.top ; + #if TARGET_CARBON + SInt16 mheight ; + GetThemeMenuBarHeight( &mheight ) ; + *height -= mheight ; +#else + *height -= LMGetMBarHeight() ; + #endif } diff --git a/src/mac/window.cpp b/src/mac/window.cpp index f8099265a2..3dd198b369 100644 --- a/src/mac/window.cpp +++ b/src/mac/window.cpp @@ -29,6 +29,7 @@ #include "wx/frame.h" #include "wx/notebook.h" #include "wx/tabctrl.h" +#include "wx/tooltip.h" // TODO remove the line below, just for lookup-up convenience CS #include "wx/mac/window.h" @@ -54,8 +55,8 @@ extern wxList wxPendingDelete; wxWindow* gFocusWindow = NULL ; +#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) - BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) @@ -64,6 +65,7 @@ BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) // EVT_SCROLL(wxWindow::OnScroll) END_EVENT_TABLE() +#endif @@ -163,6 +165,7 @@ wxWindow::~wxWindow() if ( m_macWindowData ) { + wxToolTip::NotifyWindowDelete(m_macWindowData->m_macWindow) ; UMADisposeWindow( m_macWindowData->m_macWindow ) ; delete m_macWindowData ; wxRemoveMacWindowAssociation( this ) ; @@ -189,7 +192,10 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, m_width = WidthDefault( size.x ); m_height = HeightDefault( size.y ) ; - MacCreateScrollBars( style ) ; + if ( ! IsKindOf( CLASSINFO ( wxControl ) ) ) + { + MacCreateScrollBars( style ) ; + } return TRUE; } @@ -211,6 +217,7 @@ void wxWindow::SetFocus() if ( control && control->GetMacControl() ) { UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ; + control->MacRedrawControl() ; } wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); event.SetEventObject(gFocusWindow); @@ -248,11 +255,6 @@ bool wxWindow::Enable(bool enable) { if ( !wxWindowBase::Enable(enable) ) return FALSE; -/* - HWND hWnd = GetHwnd(); - if ( hWnd ) - ::EnableWindow(hWnd, (BOOL)enable); -*/ wxWindowList::Node *node = GetChildren().GetFirst(); while ( node ) @@ -319,9 +321,6 @@ void wxWindow::DoGetPosition(int *x, int *y) const } - - - bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) { menu->SetInvokingWindow(this); @@ -370,6 +369,7 @@ void wxWindow::DoClientToScreen(int *x, int *y) const GrafPtr port ; ::GetPort( &port ) ; ::SetPort( UMAGetWindowPort( window ) ) ; + ::SetOrigin( 0 , 0 ) ; ::LocalToGlobal( &localwhere ) ; ::SetPort( port ) ; *x = localwhere.h ; @@ -437,10 +437,52 @@ void wxWindow::DoGetClientSize(int *x, int *y) const *x = m_width ; *y = m_height ; - if (m_vScrollBar && m_vScrollBar->IsShown() ) - (*x) -= MAC_SCROLLBAR_SIZE; - if (m_hScrollBar && m_hScrollBar->IsShown() ) - (*y) -= MAC_SCROLLBAR_SIZE; + *x -= 2 * MacGetBorderSize( ) ; + *y -= 2 * MacGetBorderSize( ) ; + + if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) ) + { + int x1 = 0 ; + int y1 = 0 ; + int w = m_width ; + int h = m_height ; + + MacClientToRootWindow( &x1 , &y1 ) ; + MacClientToRootWindow( &w , &h ) ; + + WindowRef window = NULL ; + wxWindow *iter = (wxWindow*)this ; + + int totW = 10000 , totH = 10000; + while( iter ) + { + if ( iter->m_macWindowData ) + { + totW = iter->m_width ; + totH = iter->m_height ; + break ; + } + + iter = iter->GetParent() ; + } + + if (m_hScrollBar && m_hScrollBar->IsShown() ) + { + (*y) -= MAC_SCROLLBAR_SIZE; + if ( h-y1 >= totH ) + { + (*y)+= 1 ; + } + } + if (m_vScrollBar && m_vScrollBar->IsShown() ) + { + (*x) -= MAC_SCROLLBAR_SIZE; + if ( w-x1 >= totW ) + { + (*x) += 1 ; + } + } + } } @@ -454,8 +496,8 @@ void wxWindow::DoSetToolTip(wxToolTip *tooltip) { wxWindowBase::DoSetToolTip(tooltip); -// if ( m_tooltip ) -// m_tooltip->SetWindow(this); + if ( m_tooltip ) + m_tooltip->SetWindow(this); } #endif // wxUSE_TOOLTIPS @@ -467,6 +509,7 @@ void wxWindow::DoMoveWindow(int x, int y, int width, int height) void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) { + int former_x = m_x ; int former_y = m_y ; int former_w = m_width ; @@ -481,9 +524,9 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) int actualHeight = height; int actualX = x; int actualY = y; - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualX = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualY = currentY; if (width == -1) actualWidth = currentW ; @@ -524,7 +567,7 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) if ( focus.Ok() ) { Rect clientrect = { 0 , 0 , m_height , m_width } ; - InvalRect( &clientrect ) ; + InvalWindowRect( GetMacRootWindow() , &clientrect ) ; } } } @@ -535,18 +578,18 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) if ( m_macWindowData ) { if ( doMove ) - ::MoveWindow(m_macWindowData->m_macWindow, m_x, m_y, false); // don't make frontmost + ::MoveWindow(m_macWindowData->m_macWindow, m_x, m_y , false); // don't make frontmost if ( doResize ) - ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height, true); + ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height , true); // the OS takes care of invalidating and erasing if ( IsKindOf( CLASSINFO( wxFrame ) ) ) { wxFrame* frame = (wxFrame*) this ; - frame->PositionStatusBar(); - frame->PositionToolBar(); + frame->PositionStatusBar(); + frame->PositionToolBar(); } } else @@ -556,8 +599,8 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxMacDrawingClientHelper focus( this ) ; if ( focus.Ok() ) { - Rect clientrect = { 0 , 0 , m_height , m_width } ; - InvalRect( &clientrect ) ; + Rect clientrect = { 0 , 0 , m_height , m_width } ; + InvalWindowRect( GetMacRootWindow() , &clientrect ) ; } } if ( doMove ) @@ -566,17 +609,17 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) MacRepositionScrollBars() ; if ( doMove ) { - wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event) ; - } - if ( doResize ) - { + wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event) ; + } + if ( doResize ) + { MacRepositionScrollBars() ; - wxSizeEvent event(wxSize(m_width, m_height), m_windowId); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); - } + wxSizeEvent event(wxSize(m_width, m_height), m_windowId); + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); + } } } // For implementation purposes - sometimes decorations make the client area @@ -584,7 +627,7 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxPoint wxWindow::GetClientAreaOrigin() const { - return wxPoint(0, 0); + return wxPoint(MacGetBorderSize( ) , MacGetBorderSize( ) ); } // Makes an adjustment to the window position (for example, a frame that has @@ -632,7 +675,8 @@ bool wxWindow::Show(bool show) { UMAShowWindow( m_macWindowData->m_macWindow ) ; UMASelectWindow( m_macWindowData->m_macWindow ) ; - // no need to generate events here, they will get them triggered by macos + // no need to generate events here, they will get them triggered by macos + // actually they should be , but apparently they are not wxSizeEvent event(wxSize(m_width, m_height), m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); @@ -644,6 +688,8 @@ bool wxWindow::Show(bool show) } MacSuperShown( show ) ; Refresh() ; + if(m_macWindowData) + MacUpdateImmediately() ; return TRUE; } @@ -682,10 +728,14 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, wxClientDC dc( this ) ; long lx,ly,ld,le ; dc.GetTextExtent( string , &lx , &ly , &ld, &le, fontToUse ) ; - *externalLeading = le ; - *descent = ld ; - *x = lx ; - *y = ly ; + if ( externalLeading ) + *externalLeading = le ; + if ( descent ) + *descent = ld ; + if ( x ) + *x = lx ; + if ( y ) + *y = ly ; } void wxWindow::MacEraseBackground( Rect *rect ) @@ -715,7 +765,7 @@ void wxWindow::MacEraseBackground( Rect *rect ) // 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 ) )) { - ApplyThemeBackground (kThemeBackgroundTabPane, rect, kThemeStateActive,8,true); + UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true); break ; } } @@ -743,10 +793,6 @@ void wxWindow::MacEraseBackground( Rect *rect ) for (wxNode *node = GetChildren().First(); node; node = node->Next()) { wxWindow *child = (wxWindow*)node->Data(); -// int width ; -// int height ; - -// child->GetClientSize( &width , &height ) ; Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ; SectRect( &clientrect , rect , &clientrect ) ; @@ -765,26 +811,18 @@ void wxWindow::MacEraseBackground( Rect *rect ) void wxWindow::Refresh(bool eraseBack, const wxRect *rect) { - wxMacDrawingClientHelper focus( this ) ; + wxMacDrawingHelper focus( this ) ; if ( focus.Ok() ) { - int width , height ; - GetClientSize( &width , &height ) ; - Rect clientrect = { 0 , 0 , height , width } ; - ClipRect( &clientrect ) ; + Rect clientrect = { 0 , 0 , m_height , m_width } ; + ClipRect( &clientrect ) ; - if ( rect ) - { - Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; + if ( rect ) + { + Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; SectRect( &clientrect , &r , &clientrect ) ; - } - InvalRect( &clientrect ) ; - /* - if ( eraseBack ) - { - MacEraseBackground( &clientrect ) ; - } - */ + } + InvalWindowRect( GetMacRootWindow() , &clientrect ) ; } } @@ -927,41 +965,222 @@ void wxWindow::SetScrollPos(int orient, int pos, bool refresh) } } -void wxWindow::MacPaint( wxPaintEvent &event ) +void wxWindow::MacCreateRealWindow( const wxString& title, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name ) { - wxPaintDC dc(this); - PrepareDC(dc); + SetName(name); + m_windowStyle = style; + m_isShown = FALSE; - if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) ) - { - bool sunken = HasFlag( wxSUNKEN_BORDER ) ; + // create frame. - wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ; - wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ; - - wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN; - wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow; - wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow; - wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN; + 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 ; + + m_width = size.x; + if (m_width == -1) + m_width = 20; + m_height = size.y; + if (m_height == -1) + m_height = 20; + + m_macWindowData = new MacWindowData() ; + + ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height); + + // translate the window attributes in the appropriate window class and attributes + + WindowClass wclass ; + WindowAttributes attr ; - dc.SetPen(wxPen1); - dc.DrawRectangle(0, 0, m_width, m_height); // outer - right and button + if ( HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) ) + { + wclass = kFloatingWindowClass ; + if ( HasFlag(wxTINY_CAPTION_VERT) ) + { + attr |= kWindowSideTitlebarAttribute ; + } + } + else if ( HasFlag( wxTHICK_FRAME ) ) + { + if ( HasFlag( wxDIALOG_MODAL ) ) + { + wclass = kMovableModalWindowClass ; + } + else if ( HasFlag( wxDIALOG_MODELESS ) ) + { + wclass = kDocumentWindowClass ; + } + else + { + if ( HasFlag( wxCAPTION ) ) + { + wclass = kDocumentWindowClass ; + } + else + { + wclass = kModalWindowClass ; + } + } + } + else + { + wclass = kModalWindowClass ; + } - dc.SetPen(wxPen2); - dc.DrawRectangle(1, 1, m_width-1, m_height-1); // outer - left and top + attr = kWindowNoAttributes ; - dc.SetPen(wxPen3); - dc.DrawRectangle(0, 0, m_width-2, m_height-2); // inner - right and button + if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) + { + attr |= kWindowFullZoomAttribute ; + attr |= kWindowCollapseBoxAttribute ; + } + if ( HasFlag( wxRESIZE_BORDER ) ) + { + attr |= kWindowResizableAttribute ; + } + if ( HasFlag( wxSYSTEM_MENU ) ) + { + attr |= kWindowCloseBoxAttribute ; + } - dc.SetPen(wxPen4); - dc.DrawLine(0, 0, m_width-3, 0); // inner - left and top - dc.DrawLine(0, 0, 0, m_height-3); + UMACreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ; + wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ; + wxString label ; + if( wxApp::s_macDefaultEncodingIsPC ) + label = wxMacMakeMacStringFromPC( title ) ; + else + label = title ; + UMASetWTitleC( m_macWindowData->m_macWindow , label ) ; + UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ; + + m_macWindowData->m_macFocus = NULL ; +} + +void wxWindow::MacPaint( wxPaintEvent &event ) +{ +} + +void wxWindow::MacPaintBorders( ) +{ + if( m_macWindowData ) + return ; + + RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ; + RGBColor black = { 0x0000, 0x0000 , 0x0000 } ; + RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ; + RGBColor shadow = { 0x4444, 0x4444 , 0x4444 } ; + PenNormal() ; + + if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) + { + bool sunken = HasFlag( wxSUNKEN_BORDER ) ; + RGBColor pen1 = sunken ? white : black ; + RGBColor pen2 = sunken ? shadow : face ; + RGBColor pen3 = sunken ? face : shadow ; + RGBColor pen4 = sunken ? black : white ; + + RGBForeColor( &pen1 ) ; + { + Rect rect = { 0 , 0 , m_height , m_width } ; + FrameRect( &rect ) ; + } + RGBForeColor( &pen2 ) ; + { + Rect rect = { 1 , 1 , m_height -1 , m_width -1} ; + FrameRect( &rect ) ; + } + RGBForeColor( &pen3 ) ; + { + Rect rect = { 0 , 0 , m_height -2 , m_width -2} ; + FrameRect( &rect ) ; + } + RGBForeColor( &pen4 ) ; + { + MoveTo( 0 , 0 ) ; + LineTo( m_width - 3 , 0 ) ; + MoveTo( 0 , 0 ) ; + LineTo( 0 , m_height - 3 ) ; + } } else if (HasFlag(wxSIMPLE_BORDER)) { - dc.SetPen(*wxBLACK_PEN); - dc.DrawRectangle(0, 0, m_width, m_height); + Rect rect = { 0 , 0 , m_height , m_width } ; + RGBForeColor( &black ) ; + FrameRect( &rect ) ; + } +/* + if ( this->GetParent() ) + { + wxPaintDC dc(GetParent()); + GetParent()->PrepareDC(dc); + + if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) ) + { + bool sunken = HasFlag( wxSUNKEN_BORDER ) ; + + wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ; + wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ; + + wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN; + wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow; + wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow; + wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN; + + dc.SetPen(wxPen1); + dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button + + dc.SetPen(wxPen2); + dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top + + dc.SetPen(wxPen3); + dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button + + dc.SetPen(wxPen4); + dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top + dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3); + } + else if (HasFlag(wxDOUBLE_BORDER)) + { + bool sunken = HasFlag( wxSUNKEN_BORDER ) ; + + wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ; + wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ; + + wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN; + wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow; + wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow; + wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN; + + dc.SetPen(wxPen1); + dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button + + dc.SetPen(wxPen2); + dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top + + dc.SetPen(wxPen3); + dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button + + dc.SetPen(wxPen4); + dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top + dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3); + } + else if (HasFlag(wxSIMPLE_BORDER)) + { + dc.SetPen(*wxBLACK_PEN); + dc.DrawRectangle(m_x, m_y, m_width, m_height); + } } + */ } // New function that will replace some of the above. @@ -1011,20 +1230,21 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) wxMacDrawingClientHelper focus( this ) ; if ( focus.Ok() ) { - int width , height ; - GetClientSize( &width , &height ) ; - Rect scrollrect = { 0 , 0 , height , width } ; + int width , height ; + GetClientSize( &width , &height ) ; + + Rect scrollrect = { 0 , 0 , height , width } ; - RgnHandle updateRgn = NewRgn() ; - ClipRect( &scrollrect ) ; - if ( rect ) - { - Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; + RgnHandle updateRgn = NewRgn() ; + ClipRect( &scrollrect ) ; + if ( rect ) + { + Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ; SectRect( &scrollrect , &r , &scrollrect ) ; - } - ScrollRect( &scrollrect , dx , dy , updateRgn ) ; - InvalRgn( updateRgn ) ; - DisposeRgn( updateRgn ) ; + } + ScrollRect( &scrollrect , dx , dy , updateRgn ) ; + InvalWindowRgn( GetMacRootWindow() , updateRgn ) ; + DisposeRgn( updateRgn ) ; } } @@ -1136,9 +1356,9 @@ void wxWindow::Clear() else { wxClientDC dc(this); - wxBrush brush(GetBackgroundColour(), wxSOLID); - dc.SetBackground(brush); - dc.Clear(); + wxBrush brush(GetBackgroundColour(), wxSOLID); + dc.SetBackground(brush); + dc.Clear(); } } @@ -1193,6 +1413,9 @@ void wxWindow::DoSetClientSize(int width, int height) if ( height != -1 && m_vScrollBar ) height += MAC_SCROLLBAR_SIZE ; + width += 2 * MacGetBorderSize( ) ; + height += 2 * MacGetBorderSize( ) ; + DoSetSize( -1 , -1 , width , height ) ; } } @@ -1249,6 +1472,7 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event) (event.m_x > (m_x + m_width)) || (event.m_y > (m_y + m_height))) return FALSE; + if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) ) return FALSE ; @@ -1277,10 +1501,28 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event) { m_cursor.MacInstall() ; } + +#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 GetEventHandler()->ProcessEvent( event ) ; return TRUE; } +Point lastWhere ; +long lastWhen = 0 ; + +wxString wxWindow::MacGetToolTipString( wxPoint &pt ) +{ + if ( m_tooltip ) + { + return m_tooltip->GetTip() ; + } + return "" ; +} void wxWindow::MacFireMouseEvent( EventRecord *ev ) { wxMouseEvent event(wxEVT_LEFT_DOWN); @@ -1323,6 +1565,22 @@ void wxWindow::MacFireMouseEvent( EventRecord *ev ) ::GlobalToLocal( &localwhere ) ; ::SetPort( port ) ; + if ( ev->what == mouseDown ) + { + if ( ev->when - lastWhen <= GetDblTime() ) + { + if ( abs( localwhere.h - lastWhere.h ) < 3 || abs( localwhere.v - lastWhere.v ) < 3 ) + { + if ( controlDown ) + event.SetEventType(wxEVT_RIGHT_DCLICK ) ; + else + event.SetEventType(wxEVT_LEFT_DCLICK ) ; + } + } + lastWhen = ev->when ; + lastWhere = localwhere ; + } + event.m_x = localwhere.h; event.m_y = localwhere.v; event.m_x += m_x; @@ -1407,7 +1665,7 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) WindowRef window = GetMacRootWindow() ; wxWindow* win = wxFindWinFromMacWindow( window ) ; { - wxMacDrawingClientHelper focus( this ) ; + wxMacDrawingHelper focus( this ) ; // was client if ( focus.Ok() ) { WindowRef window = GetMacRootWindow() ; @@ -1446,7 +1704,9 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) // 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 ) )) { - ApplyThemeBackground(kThemeBackgroundTabPane, &(**updatergn).rgnBBox , kThemeStateActive,8,true); + Rect box ; + GetRegionBounds( updatergn , &box) ; + UMAApplyThemeBackground(kThemeBackgroundTabPane, &box , kThemeStateActive,8,true); break ; } } @@ -1475,32 +1735,39 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) EraseRgn( updatergn ) ; } } + + m_macUpdateRgn = updatergn ; + { + 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 , m_macUpdateRgn , newupdate ) ; + OffsetRgn( newupdate , -origin.x , -origin.y ) ; + m_updateRegion = newupdate ; + DisposeRgn( newupdate ) ; + } + + MacPaintBorders() ; + wxPaintEvent event; + event.m_timeStamp = time ; + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); + } + { } - m_updateRegion = updatergn ; - wxPaintEvent event; - event.m_timeStamp = time ; - event.SetEventObject(this); - - wxPaintEvent event2( event ) ; - GetEventHandler()->ProcessEvent(event); - MacPaint( event2 ) ; RgnHandle childupdate = NewRgn() ; for (wxNode *node = GetChildren().First(); node; node = node->Next()) { wxWindow *child = (wxWindow*)node->Data(); - int width ; - int height ; - - child->GetClientSize( &width , &height ) ; - - SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x +width , child->m_y + height ) ; - SectRgn( childupdate , m_updateRegion.GetWXHRGN() , childupdate ) ; + SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ; + SectRgn( childupdate , m_macUpdateRgn , childupdate ) ; OffsetRgn( childupdate , -child->m_x , -child->m_y ) ; - if ( child->GetMacRootWindow() == window && child->IsShown() ) + if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) ) { // because dialogs may also be children child->MacRedraw( childupdate , time ) ; @@ -1516,24 +1783,28 @@ void wxWindow::MacUpdateImmediately() if ( window ) { wxWindow* win = wxFindWinFromMacWindow( window ) ; + #if TARGET_CARBON + AGAPortHelper help( GetWindowPort(window) ) ; + #else + AGAPortHelper help( (window) ) ; + #endif + SetOrigin( 0 , 0 ) ; BeginUpdate( window ) ; if ( win ) { - #if ! TARGET_CARBON - if ( !EmptyRgn( window->visRgn ) ) - #endif + RgnHandle region = NewRgn(); + + if ( region ) { - win->MacRedraw( window->visRgn , wxTheApp->sm_lastMessageTime ) ; -/* - { - wxMacDrawingHelper help( win ) ; - SetOrigin( 0 , 0 ) ; - UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; - UMAUpdateControls( window , window->visRgn ) ; - UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ; - } -*/ - } + GetPortVisibleRegion( GetWindowPort( window ), region ); + + // if windowshade gives incompatibility , take the follwing out + if ( !EmptyRgn( region ) ) + { + win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ; + } + DisposeRgn( region ); + } } EndUpdate( window ) ; } @@ -1543,26 +1814,28 @@ void wxWindow::MacUpdate( EventRecord *ev ) { WindowRef window = (WindowRef) ev->message ; wxWindow * win = wxFindWinFromMacWindow( window ) ; - + #if TARGET_CARBON + AGAPortHelper help( GetWindowPort(window) ) ; + #else + AGAPortHelper help( (window) ) ; + #endif + SetOrigin( 0 , 0 ) ; BeginUpdate( window ) ; if ( win ) { - // if windowshade gives incompatibility , take the follwing out - #if ! TARGET_CARBON - if ( !EmptyRgn( window->visRgn ) ) - #endif + RgnHandle region = NewRgn(); + + if ( region ) { - MacRedraw( window->visRgn , ev->when ) ; - /* - { - wxMacDrawingHelper help( this ) ; - SetOrigin( 0 , 0 ) ; - UMASetThemeWindowBackground( m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; - UMAUpdateControls( window , window->visRgn ) ; - UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ; - } - */ - } + GetPortVisibleRegion( GetWindowPort( window ), region ); + + // if windowshade gives incompatibility , take the follwing out + if ( !EmptyRgn( region ) ) + { + MacRedraw( region , ev->when ) ; + } + DisposeRgn( region ); + } } EndUpdate( window ) ; } @@ -1586,20 +1859,36 @@ WindowRef wxWindow::GetMacRootWindow() const void wxWindow::MacCreateScrollBars( long style ) { wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , "attempt to create window twice" ) ; + bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ; int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ; + int width, height ; + GetClientSize( &width , &height ) ; + wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; + wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; + wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; + wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; + + m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint, + vSize , wxVERTICAL); + if ( style & wxVSCROLL ) { - m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, wxPoint(m_width-MAC_SCROLLBAR_SIZE, 0), - wxSize(MAC_SCROLLBAR_SIZE, m_height - adjust), wxVERTICAL); -// m_vScrollBar->PushEventHandler( this ) ; + + } + else + { + m_vScrollBar->Show(false) ; } + m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint, + hSize , wxHORIZONTAL); if ( style & wxHSCROLL ) { - m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, wxPoint(0 , m_height-MAC_SCROLLBAR_SIZE ), - wxSize( m_width - adjust, MAC_SCROLLBAR_SIZE), wxHORIZONTAL); -// m_hScrollBar->PushEventHandler( this ) ; + } + else + { + m_hScrollBar->Show(false) ; } // because the create does not take into account the client area origin @@ -1611,18 +1900,79 @@ void wxWindow::MacRepositionScrollBars() bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ; int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ; + // get real client area + + int width = m_width ; + int height = m_height ; + + width -= 2 * MacGetBorderSize() ; + height -= 2 * MacGetBorderSize() ; + + wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ; + wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ; + wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ; + wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ; + + int x = 0 ; + int y = 0 ; + int w = m_width ; + int h = m_height ; + + MacClientToRootWindow( &x , &y ) ; + MacClientToRootWindow( &w , &h ) ; + + WindowRef window = NULL ; + wxWindow *iter = (wxWindow*)this ; + + int totW = 10000 , totH = 10000; + while( iter ) + { + if ( iter->m_macWindowData ) + { + totW = iter->m_width ; + totH = iter->m_height ; + break ; + } + + iter = iter->GetParent() ; + } + + if ( x == 0 ) + { + hPoint.x = -1 ; + hSize.x += 1 ; + } + if ( y == 0 ) + { + vPoint.y = -1 ; + vSize.y += 1 ; + } + + if ( w-x >= totW ) + { + hSize.x += 1 ; + vPoint.x += 1 ; + } + + if ( h-y >= totH ) + { + vSize.y += 1 ; + hPoint.y += 1 ; + } + if ( m_vScrollBar ) { - m_vScrollBar->SetSize( m_width-MAC_SCROLLBAR_SIZE, 0, MAC_SCROLLBAR_SIZE, m_height - adjust , wxSIZE_USE_EXISTING); + m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE); } if ( m_hScrollBar ) { - m_hScrollBar->SetSize( 0 , m_height-MAC_SCROLLBAR_SIZE ,m_width - adjust, MAC_SCROLLBAR_SIZE, wxSIZE_USE_EXISTING); + m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE); } } void wxWindow::MacKeyDown( EventRecord *ev ) { + } @@ -1651,7 +2001,8 @@ void wxWindow::MacSuperChangedPosition() node = node->Next(); } } - +/* + bool wxWindow::MacSetupFocusPort( ) { Point localOrigin ; @@ -1699,7 +2050,7 @@ bool wxWindow::MacSetupDrawingClientPort( ) MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; } - +*/ bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win ) { @@ -1714,6 +2065,7 @@ bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & cl if (currPort != port ) ::SetPort(port); +// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ; ::SetOrigin(-localOrigin.h, -localOrigin.v); return true; } @@ -1729,14 +2081,16 @@ bool wxWindow::MacSetPortDrawingParams( const Point & localOrigin, const Rect & port = UMAGetWindowPort( window) ; if (currPort != port ) ::SetPort(port); - +// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ; ::SetOrigin(-localOrigin.h, -localOrigin.v); ::ClipRect(&clipRect); ::PenNormal() ; ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ; ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ; - ::BackPat( &qd.white ) ; + Pattern whiteColor ; + + ::BackPat( GetQDGlobalsWhite( &whiteColor) ) ; ::UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ; return true; } @@ -1771,10 +2125,10 @@ void wxWindow::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *w } } -void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin ) +void wxWindow::MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin ) { - int width , height ; - GetClientSize( &width , &height ) ; +// int width , height ; +// GetClientSize( &width , &height ) ; if ( m_macWindowData ) { @@ -1791,7 +2145,7 @@ void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, Window { wxASSERT( GetParent() != NULL ) ; - GetParent()->MacGetPortClientParams( localOrigin , clipRect , window, rootwin) ; + GetParent()->MacDoGetPortClientParams( localOrigin , clipRect , window, rootwin) ; localOrigin->h += m_x; localOrigin->v += m_y; @@ -1800,12 +2154,58 @@ void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, Window Rect myClip; myClip.left = 0; myClip.top = 0; - myClip.right = width; - myClip.bottom = height; + myClip.right = m_width ;//width; + myClip.bottom = m_height ;// height; SectRect(clipRect, &myClip, clipRect); } } +void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin ) +{ + MacDoGetPortClientParams( localOrigin , clipRect , window , rootwin ) ; + + int width , height ; + GetClientSize( &width , &height ) ; + wxPoint client ; + client = GetClientAreaOrigin( ) ; + + localOrigin->h += client.x; + localOrigin->v += client.y; + OffsetRect(clipRect, -client.x, -client.y); + + Rect myClip; + myClip.left = 0; + myClip.top = 0; + myClip.right = width; + myClip.bottom = height; + SectRect(clipRect, &myClip, clipRect); +} + +long wxWindow::MacGetBorderSize( ) const +{ + if( m_macWindowData ) + return 0 ; + + if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER ) + { + return 2 ; + } + else if ( m_windowStyle &wxDOUBLE_BORDER) + { + return 2 ; + } + else if (m_windowStyle &wxSIMPLE_BORDER) + { + return 1 ; + } + return 0 ; +} + +long wxWindow::MacRemoveBordersFromStyle( long style ) +{ + return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; +} +/* wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow ) { m_ok = false ; @@ -1829,12 +2229,13 @@ wxMacFocusHelper::~wxMacFocusHelper() { if ( m_ok ) { + SetPort( m_currentPort ) ; SetOrigin( 0 , 0 ) ; } if ( m_formerPort != m_currentPort ) SetPort( m_formerPort ) ; } - +*/ wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow ) { m_ok = false ; @@ -1861,15 +2262,18 @@ wxMacDrawingHelper::~wxMacDrawingHelper() { if ( m_ok ) { + SetPort( m_currentPort ) ; SetPenState( &m_savedPenState ) ; SetOrigin( 0 , 0 ) ; - ClipRect( &m_currentPort->portRect ) ; + Rect portRect ; + GetPortBounds( m_currentPort , &portRect ) ; + ClipRect( &portRect ) ; } if ( m_formerPort != m_currentPort ) SetPort( m_formerPort ) ; } - +/* wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow * theWindow ) { m_ok = false ; @@ -1894,11 +2298,13 @@ wxMacFocusClientHelper::~wxMacFocusClientHelper() { if ( m_ok ) { + SetPort( m_currentPort ) ; SetOrigin( 0 , 0 ) ; } if ( m_formerPort != m_currentPort ) SetPort( m_formerPort ) ; } +*/ wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow * theWindow ) { @@ -1927,9 +2333,12 @@ wxMacDrawingClientHelper::~wxMacDrawingClientHelper() { if ( m_ok ) { + SetPort( m_currentPort ) ; SetPenState( &m_savedPenState ) ; SetOrigin( 0 , 0 ) ; - ClipRect( &m_currentPort->portRect ) ; + Rect portRect ; + GetPortBounds( m_currentPort , &portRect ) ; + ClipRect( &portRect ) ; } if ( m_formerPort != m_currentPort ) diff --git a/src/mac/xpm/Attrib.c b/src/mac/xpm/Attrib.c index 2373190136..04b843b995 100644 --- a/src/mac/xpm/Attrib.c +++ b/src/mac/xpm/Attrib.c @@ -32,7 +32,7 @@ * Developed by Arnaud Le Hors * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" /* 3.2 backward compatibility code */ LFUNC(CreateOldColorTable, int, (XpmColor *ct, int ncolors, diff --git a/src/mac/xpm/CrBufFrI.c b/src/mac/xpm/CrBufFrI.c index 59b89c1a99..2bac74c316 100644 --- a/src/mac/xpm/CrBufFrI.c +++ b/src/mac/xpm/CrBufFrI.c @@ -32,7 +32,7 @@ * Developed by Arnaud Le Hors * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" LFUNC(WriteColors, int, (char **dataptr, unsigned int *data_size, unsigned int *used_size, XpmColor *colors, diff --git a/src/mac/xpm/CrDatFrI.c b/src/mac/xpm/CrDatFrI.c index 3a21e3d064..bb0d2d293a 100644 --- a/src/mac/xpm/CrDatFrI.c +++ b/src/mac/xpm/CrDatFrI.c @@ -32,7 +32,7 @@ * Developed by Arnaud Le Hors * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" LFUNC(CreateColors, int, (char **dataptr, unsigned int *data_size, XpmColor *colors, unsigned int ncolors, diff --git a/src/mac/xpm/CrIFrBuf.c b/src/mac/xpm/CrIFrBuf.c index 4b5ad72822..ba863ac3e0 100644 --- a/src/mac/xpm/CrIFrBuf.c +++ b/src/mac/xpm/CrIFrBuf.c @@ -32,7 +32,7 @@ * Developed by Arnaud Le Hors * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" LFUNC(OpenBuffer, void, (char *buffer, xpmData *mdata)); diff --git a/src/mac/xpm/CrIFrDat.c b/src/mac/xpm/CrIFrDat.c index bb342d2743..f3c19c7cd6 100644 --- a/src/mac/xpm/CrIFrDat.c +++ b/src/mac/xpm/CrIFrDat.c @@ -32,7 +32,7 @@ * Developed by Arnaud Le Hors * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" LFUNC(OpenArray, void, (char **data, xpmData *mdata)); diff --git a/src/mac/xpm/Image.c b/src/mac/xpm/Image.c index 9d4057ad3a..0753622186 100644 --- a/src/mac/xpm/Image.c +++ b/src/mac/xpm/Image.c @@ -32,7 +32,7 @@ * Developed by Arnaud Le Hors * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" /* * Init returned data to free safely later on diff --git a/src/mac/xpm/Info.c b/src/mac/xpm/Info.c index f15c6c9b57..9bc41c89eb 100644 --- a/src/mac/xpm/Info.c +++ b/src/mac/xpm/Info.c @@ -32,7 +32,7 @@ * Developed by Arnaud Le Hors * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" /* * Init returned data to free safely later on diff --git a/src/mac/xpm/RdFToBuf.c b/src/mac/xpm/RdFToBuf.c index 2745583cf0..abab09c787 100644 --- a/src/mac/xpm/RdFToBuf.c +++ b/src/mac/xpm/RdFToBuf.c @@ -37,18 +37,20 @@ * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94 */ +#include "wx/setup.h" + #ifdef macintosh #ifdef __std #undef __std #define __std() #endif - #include #include - #include #include + #include + #include #endif -#include "xpmi.h" +#include "XpmI.h" #ifndef macintosh #include diff --git a/src/mac/xpm/RdFToDat.c b/src/mac/xpm/RdFToDat.c index 58a97c4542..4bb28fce2d 100644 --- a/src/mac/xpm/RdFToDat.c +++ b/src/mac/xpm/RdFToDat.c @@ -32,7 +32,7 @@ * Developed by Dan Greening dgreen@cs.ucla.edu / dgreen@sti.com * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" int XpmReadFileToData(filename, data_return) diff --git a/src/mac/xpm/RdFToI.c b/src/mac/xpm/RdFToI.c index 83bf922489..3339bbdde0 100644 --- a/src/mac/xpm/RdFToI.c +++ b/src/mac/xpm/RdFToI.c @@ -32,20 +32,22 @@ * Developed by Arnaud Le Hors * \*****************************************************************************/ +#include "wx/setup.h" + #ifdef macintosh #ifdef __std #undef __std #define __std() #endif - #include #include - #include #include + #include + #include #undef NO_ZPIPE #define NO_ZPIPE #endif -#include "xpmi.h" +#include "XpmI.h" #ifndef macintosh #include #if !defined(NO_ZPIPE) && defined(WIN32) diff --git a/src/mac/xpm/WrFFrBuf.c b/src/mac/xpm/WrFFrBuf.c index 907100aee0..3ed6685ada 100644 --- a/src/mac/xpm/WrFFrBuf.c +++ b/src/mac/xpm/WrFFrBuf.c @@ -32,7 +32,7 @@ * Developed by Arnaud Le Hors * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" int XpmWriteFileFromBuffer(filename, buffer) diff --git a/src/mac/xpm/WrFFrDat.c b/src/mac/xpm/WrFFrDat.c index eaf5eec4a9..bfaa9097da 100644 --- a/src/mac/xpm/WrFFrDat.c +++ b/src/mac/xpm/WrFFrDat.c @@ -32,7 +32,7 @@ * Developed by Dan Greening dgreen@cs.ucla.edu / dgreen@sti.com * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" int XpmWriteFileFromData(filename, data) diff --git a/src/mac/xpm/WrFFrI.c b/src/mac/xpm/WrFFrI.c index be8812001b..4f5c1bfdaa 100644 --- a/src/mac/xpm/WrFFrI.c +++ b/src/mac/xpm/WrFFrI.c @@ -37,7 +37,7 @@ * Lorens Younes (d93-hyo@nada.kth.se) 4/96 */ -#include "xpmi.h" +#include "XpmI.h" #ifdef macintosh #undef NO_ZPIPE #define NO_ZPIPE diff --git a/src/mac/xpm/create.c b/src/mac/xpm/create.c index b529e65c54..fe27a219cb 100644 --- a/src/mac/xpm/create.c +++ b/src/mac/xpm/create.c @@ -43,7 +43,7 @@ * Lorens Younes (d93-hyo@nada.kth.se) 4/96 */ -#include "xpmi.h" +#include "XpmI.h" #include LFUNC(xpmVisualType, int, (Visual *visual)); diff --git a/src/mac/xpm/data.c b/src/mac/xpm/data.c index b26f3eb112..2a9d2ece2e 100644 --- a/src/mac/xpm/data.c +++ b/src/mac/xpm/data.c @@ -39,7 +39,7 @@ static char *RCS_Version = "$XpmVersion: 3.4k $"; /* Internal version number */ static char *RCS_Id = "$Id$"; -#include "xpmi.h" +#include "XpmI.h" #endif #include diff --git a/src/mac/xpm/hashtab.c b/src/mac/xpm/hashtab.c index bea343d58d..7d596ec429 100644 --- a/src/mac/xpm/hashtab.c +++ b/src/mac/xpm/hashtab.c @@ -33,7 +33,7 @@ * * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" LFUNC(AtomMake, xpmHashAtom, (char *name, void *data)); LFUNC(HashTableGrows, int, (xpmHashTable * table)); diff --git a/src/mac/xpm/macx.c b/src/mac/xpm/macx.c index 3f83af3ac8..22368ffac0 100644 --- a/src/mac/xpm/macx.c +++ b/src/mac/xpm/macx.c @@ -33,7 +33,7 @@ * Revised 4/96 * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" //#include "macx.h" #include "simx.h" @@ -58,6 +58,7 @@ AllocXImage ( NewGWorld( &img->gworldptr , depth , &rect , NULL , NULL , 0 ) ; + LockPixels( GetGWorldPixMap( img->gworldptr ) ) ; if (img->gworldptr == NULL) { XDestroyImage (img); @@ -67,346 +68,3 @@ AllocXImage ( return img; } - -/* - -static struct RastPort * -AllocRastPort (unsigned int, unsigned int, unsigned int); -static void -FreeRastPort (struct RastPort *, unsigned int,unsigned int); - - -static struct RastPort * -AllocRastPort ( - unsigned int width, - unsigned int height, - unsigned int depth) -{ - struct RastPort *rp; - - rp = XpmMalloc (sizeof (*rp)); - if (rp != NULL) - { - InitRastPort (rp); - if (GfxBase->LibNode.lib_Version >= 39) - { - rp->BitMap = AllocBitMap (width, height, depth, BMF_CLEAR, NULL); - if (rp->BitMap == NULL) - { - FreeRastPort (rp, width, height); - return NULL; - } - } - else - { - unsigned int i; - - rp->BitMap = XpmMalloc (sizeof (*rp->BitMap)); - if (rp->BitMap == NULL) - { - FreeRastPort (rp, width, height); - return NULL; - } - - InitBitMap (rp->BitMap, depth, width, height); - for (i = 0; i < depth; ++i) - rp->BitMap->Planes[i] = NULL; - for (i = 0; i < depth; ++i) - { - rp->BitMap->Planes[i] = (PLANEPTR)AllocRaster (width, height); - if (rp->BitMap->Planes[i] == NULL) - { - FreeRastPort (rp, width, height); - return NULL; - } - } - } - } - - return rp; -} - - -static void -FreeRastPort ( - struct RastPort *rp, - unsigned int width, - unsigned int height) -{ - if (rp != NULL) - { - if (rp->BitMap != NULL) - { - WaitBlit (); - if (GfxBase->LibNode.lib_Version >= 39) - FreeBitMap (rp->BitMap); - else - { - unsigned int i; - - for (i = 0; i < rp->BitMap->Depth; ++i) - { - if (rp->BitMap->Planes[i] != NULL) - FreeRaster (rp->BitMap->Planes[i], width, height); - } - XpmFree (rp->BitMap); - } - } - XpmFree (rp); - } -} - - -XImage * -AllocXImage ( - unsigned int width, - unsigned int height, - unsigned int depth) -{ - XImage *img; - - img = XpmMalloc (sizeof (*img)); - if (img != NULL) - { - img->width = width; - img->height = height; - img->rp = AllocRastPort (img->width, img->height, depth); - if (img->rp == NULL) - { - FreeXImage (img); - return NULL; - } - } - - return img; -} - - -int -FreeXImage ( - XImage *ximage) -{ - if (ximage != NULL) - { - FreeRastPort (ximage->rp, ximage->width, ximage->height); - XpmFree (ximage); - } - - return Success; -} - - -int -XPutPixel ( - XImage *ximage, - int x, - int y, - unsigned long pixel) -{ - SetAPen (ximage->rp, pixel); - WritePixel (ximage->rp, x, y); - - return Success; -} - - -Status -AllocBestPen ( - Colormap colormap, - XColor *screen_in_out, - unsigned long precision, - Bool fail_if_bad) -{ - if (GfxBase->LibNode.lib_Version >= 39) - { - unsigned long r, g, b; - - r = screen_in_out->red * 0x00010001; - g = screen_in_out->green * 0x00010001; - b = screen_in_out->blue * 0x00010001; - screen_in_out->pixel = ObtainBestPen (colormap, r, g, b, - OBP_Precision, precision, - OBP_FailIfBad, fail_if_bad, - TAG_DONE); - if (screen_in_out->pixel == -1) - return False; - - QueryColor (colormap, screen_in_out); - } - else - { - XColor nearest, trial; - long nearest_delta, trial_delta; - int num_cells, i; - - num_cells = colormap->Count; - nearest.pixel = 0; - QueryColor (colormap, &nearest); - nearest_delta = ((((screen_in_out->red >> 8) - (nearest.red >> 8)) - * ((screen_in_out->red >> 8) - (nearest.red >> 8))) - + - (((screen_in_out->green >> 8) - (nearest.green >> 8)) - * ((screen_in_out->green >> 8) - (nearest.green >> 8))) - + - (((screen_in_out->blue >> 8) - (nearest.blue >> 8)) - * ((screen_in_out->blue >> 8) - (nearest.blue >> 8)))); - for (i = 1; i < num_cells; i++) - { - // precision and fail_if_bad is ignored under pre V39 - trial.pixel = i; - QueryColor (colormap, &trial); - trial_delta = ((((screen_in_out->red >> 8) - (trial.red >> 8)) - * ((screen_in_out->red >> 8) - (trial.red >> 8))) - + - (((screen_in_out->green >> 8) - (trial.green >> 8)) - * ((screen_in_out->green >> 8) - (trial.green >> 8))) - + - (((screen_in_out->blue >> 8) - (trial.blue >> 8)) - * ((screen_in_out->blue >> 8) - (trial.blue >> 8)))); - if (trial_delta < nearest_delta) - { - nearest = trial; - nearest_delta = trial_delta; - } - } - screen_in_out->pixel = nearest.pixel; - screen_in_out->red = nearest.red; - screen_in_out->green = nearest.green; - screen_in_out->blue = nearest.blue; - } - - return True; -} - - -int -FreePens ( - Colormap colormap, - unsigned long *pixels, - int npixels) -{ - if (GfxBase->LibNode.lib_Version >= 39) - { - int i; - - for (i = 0; i < npixels; i++) - ReleasePen (colormap, pixels[i]); - } - - return Success; -} - - -Status -ParseColor ( - char *spec, - XColor *exact_def_return) -{ - int spec_length; - - if (spec == 0) - return False; - - spec_length = strlen(spec); - if (spec[0] == '#') - { - int hexlen; - char hexstr[10]; - - hexlen = (spec_length - 1) / 3; - if (hexlen < 1 || hexlen > 4 || hexlen * 3 != spec_length - 1) - return False; - - hexstr[hexlen] = '\0'; - strncpy (hexstr, spec + 1, hexlen); - exact_def_return->red = strtoul (hexstr, NULL, 16) << (16 - 4*hexlen); - strncpy (hexstr, spec + 1 + hexlen, hexlen); - exact_def_return->green = strtoul (hexstr, NULL, 16) << (16 - 4*hexlen); - strncpy (hexstr, spec + 1 + 2 * hexlen, hexlen); - exact_def_return->blue = strtoul (hexstr, NULL, 16) << (16 - 4*hexlen); - - return True; - } - else - { - FILE *rgbf; - int items, red, green, blue; - char line[512], name[512]; - Bool success = False; - - rgbf = fopen ("LIBS:rgb.txt", "r"); - if (rgbf == NULL) - return False; - - while (fgets(line, sizeof (line), rgbf) && !success) - { - items = sscanf (line, "%d %d %d %[^\n]\n", - &red, &green, &blue, name); - if (items != 4) - continue; - - if (red < 0 || red > 0xFF - || green < 0 || green > 0xFF - || blue < 0 || blue > 0xFF) - { - continue; - } - - if (0 == xpmstrcasecmp (spec, name)) - { - exact_def_return->red = red * 0x0101; - exact_def_return->green = green * 0x0101; - exact_def_return->blue = blue * 0x0101; - success = True; - } - } - fclose (rgbf); - - return success; - } -} - - -int -QueryColor ( - Colormap colormap, - XColor *def_in_out) -{ - if (GfxBase->LibNode.lib_Version >= 39) - { - unsigned long rgb[3]; - - GetRGB32 (colormap, def_in_out->pixel, 1, rgb); - def_in_out->red = rgb[0] >> 16; - def_in_out->green = rgb[1] >> 16; - def_in_out->blue = rgb[2] >> 16; - } - else - { - unsigned short rgb; - - rgb = GetRGB4 (colormap, def_in_out->pixel); - def_in_out->red = ((rgb >> 8) & 0xF) * 0x1111; - def_in_out->green = ((rgb >> 4) & 0xF) * 0x1111; - def_in_out->blue = (rgb & 0xF) * 0x1111; - } - - return Success; -} - - -int -QueryColors ( - Colormap colormap, - XColor *defs_in_out, - int ncolors) -{ - int i; - - for (i = 0; i < ncolors; i++) - QueryColor (colormap, &defs_in_out[i]); - - return Success; -} - -*/ diff --git a/src/mac/xpm/misc.c b/src/mac/xpm/misc.c index 868c447910..7a9ecb58ae 100644 --- a/src/mac/xpm/misc.c +++ b/src/mac/xpm/misc.c @@ -32,7 +32,7 @@ * Developed by Arnaud Le Hors * \*****************************************************************************/ -#include "xpmi.h" +#include "XpmI.h" #ifdef NEED_STRDUP /* diff --git a/src/mac/xpm/parse.c b/src/mac/xpm/parse.c index c7716897b8..905666777f 100644 --- a/src/mac/xpm/parse.c +++ b/src/mac/xpm/parse.c @@ -38,7 +38,7 @@ * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94 */ -#include "xpmi.h" +#include "XpmI.h" #include LFUNC(ParsePixels, int, (xpmData *data, unsigned int width, diff --git a/src/mac/xpm/rgb.c b/src/mac/xpm/rgb.c index 0a0ae388c8..a5c4c35592 100644 --- a/src/mac/xpm/rgb.c +++ b/src/mac/xpm/rgb.c @@ -42,7 +42,7 @@ * W. Snitily but has been modified for my special need */ -#include "xpmi.h" +#include "XpmI.h" #include #include "rgbtab.h" /* hard coded rgb.txt table */ @@ -75,7 +75,7 @@ xpmGetRgbName(rgbn, rgbn_max, red, green, blue) { int i; - unsigned long rgbVal; + RGBColor rgbVal; i = 0; while (i < numTheRGBRecords) { @@ -97,7 +97,7 @@ xpmGetRGBfromName(inname, r, g, b) { int left, right, middle; int cmp; - unsigned long rgbVal; + RGBColor rgbVal; char *name; char *grey, *p; diff --git a/src/mac/xpm/rgbtab.h b/src/mac/xpm/rgbtab.h index 717dfe4947..71ea23e2de 100644 --- a/src/mac/xpm/rgbtab.h +++ b/src/mac/xpm/rgbtab.h @@ -40,7 +40,7 @@ typedef struct { char *name; - unsigned long rgb; /* it's unsigned long */ + RGBColor rgb; /* it's unsigned long */ } rgbRecord; /* @@ -50,10 +50,10 @@ typedef struct { #ifdef FOR_MSW #define myRGB(r,g,b) RGB(r,g,b) /* MSW has this macro */ #else -#define myRGB(r,g,b)((r<<16)+(g<<8)+(b)) -#define GetRValue(c) ((((c&0x00FF0000)>>16)<<8)+((c&0x00FF0000)>>16)) -#define GetGValue(c) ((((c&0x0000FF00)>>8)<<8)+((c&0x0000FF00)>>8)) -#define GetBValue(c) (((c&0x000000FF)<<8)+(c&0x000000FF)) +#define myRGB(r,g,b) { ((r) << 8) + (r) , ((g) << 8) + (g), ((b) << 8) + (b) } +#define GetRValue(c) ((c).red) +#define GetGValue(c) ((c).green) +#define GetBValue(c) ((c).blue) #endif static rgbRecord theRGBRecords[] = diff --git a/src/mac/xpm/scan.c b/src/mac/xpm/scan.c index ebab00d365..1b56e3c9b3 100644 --- a/src/mac/xpm/scan.c +++ b/src/mac/xpm/scan.c @@ -42,7 +42,7 @@ * Lorens Younes (d93-hyo@nada.kth.se) 4/96 */ -#include "xpmi.h" +#include "XpmI.h" #define MAXPRINTABLE 92 /* number of printable ascii chars * minus \ and " for string compat diff --git a/src/mac/xpm/simx.c b/src/mac/xpm/simx.c index eac5bd39bd..48dc21b037 100644 --- a/src/mac/xpm/simx.c +++ b/src/mac/xpm/simx.c @@ -35,7 +35,7 @@ #include "xpm.h" #include "xpmi.h" /* for XpmMalloc */ - +#include "rgbtab.h" #ifdef FOR_MSW /* @@ -310,6 +310,7 @@ XCreateImage(Display *d, Visual *v, rect.bottom = height ; NewGWorld( &img->gworldptr , depth , &rect , NULL , NULL , 0 ) ; + LockPixels( GetGWorldPixMap( img->gworldptr ) ) ; if (img->gworldptr == NULL) { XDestroyImage (img); @@ -347,7 +348,10 @@ XDestroyImage(XImage *img) DeleteObject(img->bitmap); /* check return ??? */ #elif macintosh if ( img->gworldptr ) + { + UnlockPixels( GetGWorldPixMap( img->gworldptr ) ) ; DisposeGWorld( img->gworldptr ) ; + } #endif XImageFree(img); } diff --git a/src/mac/xpm/simx.h b/src/mac/xpm/simx.h index a70ad187a6..4922f1f58a 100644 --- a/src/mac/xpm/simx.h +++ b/src/mac/xpm/simx.h @@ -90,7 +90,9 @@ typedef struct { } XImage; #elif macintosh - +#ifndef __MWERKS__ +#include +#endif /* define Mac types for X window types */ typedef GDevice* Display; /* this should be similar */ -- 2.45.2