From: Stefan Csomor Date: Thu, 9 Dec 1999 10:30:35 +0000 (+0000) Subject: small adaptions X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7c551d959447b3aea01cc35f45aa4cacff2173ba small adaptions git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4882 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/mac/app.cpp b/src/mac/app.cpp index 1bd9461b3d..e85f293e1c 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -504,6 +504,17 @@ void wxApp::CleanUp() int wxEntry( int argc, char *argv[] ) { +#ifdef __MWERKS__ +#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT + // This seems to be necessary since there are 'rogue' + // objects present at this point (perhaps global objects?) + // Setting a checkpoint will ignore them as far as the + // memory checking facility is concerned. + // Of course you may argue that memory allocated in globals should be + // checked, but this is a reasonable compromise. + wxDebugContext::SetCheckpoint(); +#endif +#endif if (!wxApp::Initialize()) return FALSE; if (!wxTheApp) @@ -1021,109 +1032,112 @@ void wxApp::MacHandleMouseUpEvent( EventRecord *ev ) } } -long wxMacTranslateKey(char key, char code) +long wxMacTranslateKey(unsigned char key, unsigned char code) { + long retval = key ; switch (key) { case 0x01 : - key = WXK_HOME; + retval = WXK_HOME; break; case 0x03 : - key = WXK_RETURN; + retval = WXK_RETURN; break; case 0x04 : - key = WXK_END; + retval = WXK_END; break; case 0x05 : - key = WXK_HELP; + retval = WXK_HELP; break; case 0x08 : - key = WXK_BACK; + retval = WXK_BACK; break; case 0x09 : - key = WXK_TAB; + retval = WXK_TAB; break; case 0x0b : - key = WXK_PAGEUP; + retval = WXK_PAGEUP; break; case 0x0c : - key = WXK_PAGEDOWN; + retval = WXK_PAGEDOWN; break; case 0x0d : - key = WXK_RETURN; + retval = WXK_RETURN; break; case 0x10 : { switch( code ) { case 0x7a : - key = WXK_F1 ; + retval = WXK_F1 ; break; case 0x78 : - key = WXK_F2 ; + retval = WXK_F2 ; break; case 0x63 : - key = WXK_F3 ; + retval = WXK_F3 ; break; case 0x76 : - key = WXK_F4 ; + retval = WXK_F4 ; break; case 0x60 : - key = WXK_F5 ; + retval = WXK_F5 ; break; case 0x61 : - key = WXK_F6 ; + retval = WXK_F6 ; break; case 0x62: - key = WXK_F7 ; + retval = WXK_F7 ; break; case 0x64 : - key = WXK_F8 ; + retval = WXK_F8 ; break; case 0x65 : - key = WXK_F9 ; + retval = WXK_F9 ; break; case 0x6D : - key = WXK_F10 ; + retval = WXK_F10 ; break; case 0x67 : - key = WXK_F11 ; + retval = WXK_F11 ; break; case 0x6F : - key = WXK_F12 ; + retval = WXK_F12 ; break; case 0x69 : - key = WXK_F13 ; + retval = WXK_F13 ; break; case 0x6B : - key = WXK_F14 ; + retval = WXK_F14 ; break; case 0x71 : - key = WXK_F15 ; + retval = WXK_F15 ; break; } } break ; case 0x1b : - key = WXK_DELETE ; + retval = WXK_ESCAPE ; break ; case 0x1c : - key = WXK_LEFT ; + retval = WXK_LEFT ; break ; case 0x1d : - key = WXK_RIGHT ; + retval = WXK_RIGHT ; break ; case 0x1e : - key = WXK_UP ; + retval = WXK_UP ; break ; case 0x1f : - key = WXK_DOWN ; + retval = WXK_DOWN ; break ; + case 0x7F : + retval = WXK_DELETE ; default: break ; } // end switch - return key; + return retval; } void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) @@ -1141,17 +1155,79 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) wxWindow* focus = wxWindow::FindFocus() ; if ( focus ) { - wxKeyEvent event(wxEVT_CHAR); + long keyval = wxMacTranslateKey(keychar, keycode) ; + + wxKeyEvent event(wxEVT_KEY_DOWN); event.m_shiftDown = ev->modifiers & shiftKey; event.m_controlDown = ev->modifiers & controlKey; event.m_altDown = ev->modifiers & optionKey; event.m_metaDown = ev->modifiers & cmdKey; - event.m_keyCode = wxMacTranslateKey(keychar, keycode); + event.m_keyCode = keyval; event.m_x = ev->where.h; event.m_y = ev->where.v; event.m_timeStamp = ev->when; event.SetEventObject(focus); - focus->GetEventHandler()->ProcessEvent( event ) ; + bool handled = focus->GetEventHandler()->ProcessEvent( event ) ; + if ( !handled ) + { + #if wxUSE_ACCEL + if (!handled) + { + wxWindow *ancestor = focus; + /* + while (ancestor) + { + int command = ancestor->GetAcceleratorTable()->GetCommand( event ); + if (command != -1) + { + wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); + handled = ancestor->GetEventHandler()->ProcessEvent( command_event ); + break; + } + if (ancestor->m_isFrame) + break; + ancestor = ancestor->GetParent(); + } + */ + } + #endif // wxUSE_ACCEL + } + if (!handled) + { + wxKeyEvent event(wxEVT_CHAR); + event.m_shiftDown = ev->modifiers & shiftKey; + event.m_controlDown = ev->modifiers & controlKey; + event.m_altDown = ev->modifiers & optionKey; + event.m_metaDown = ev->modifiers & cmdKey; + event.m_keyCode = keyval; + event.m_x = ev->where.h; + event.m_y = ev->where.v; + event.m_timeStamp = ev->when; + event.SetEventObject(focus); + handled = focus->GetEventHandler()->ProcessEvent( event ) ; + } + if ( !handled && + (keyval == WXK_TAB) && + (!focus->HasFlag(wxTE_PROCESS_TAB)) && + (focus->GetParent()) && + (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) ) + { + wxNavigationKeyEvent new_event; + new_event.SetEventObject( focus ); + new_event.SetDirection( !event.ShiftDown() ); + /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ + new_event.SetWindowChange( event.ControlDown() ); + new_event.SetCurrentFocus( focus ); + handled = focus->GetEventHandler()->ProcessEvent( new_event ); + } + /* generate wxID_CANCEL if command-. or has been pressed (typically in dialogs) */ + if ( (!handled) && + (keyval == '.' && event.ControlDown() ) ) + { + wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); + new_event.SetEventObject( focus ); + handled = focus->GetEventHandler()->ProcessEvent( new_event ); + } } } } diff --git a/src/mac/bmpbuttn.cpp b/src/mac/bmpbuttn.cpp index 169f0d557a..fecc971add 100644 --- a/src/mac/bmpbuttn.cpp +++ b/src/mac/bmpbuttn.cpp @@ -19,6 +19,10 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) #endif +#include + +PicHandle MakePict(GWorldPtr wp) ; + bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, @@ -26,13 +30,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit const wxString& name) { m_buttonBitmap = bitmap; - SetName(name); - SetValidator(validator); - parent->AddChild(this); - - m_backgroundColour = parent->GetBackgroundColour() ; - m_foregroundColour = parent->GetForegroundColour() ; - m_windowStyle = style; + m_marginX = 0; m_marginY = 0; @@ -52,14 +50,60 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit if ( height == -1 && bitmap.Ok()) height = bitmap.GetHeight() + 2*m_marginY; - /* TODO: create bitmap button - */ + m_macHorizontalBorder = 2 ; // additional pixels around the real control + m_macVerticalBorder = 2 ; + Rect bounds ; + Str255 title ; + MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ; + + m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , + kControlBehaviorOffsetContents + kControlContentPictHandle , 0, + kControlBevelButtonNormalBevelProc , (long) this ) ; + wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; + + m_buttonBitmap = bitmap; + PicHandle icon = NULL ; + if ( m_buttonBitmap.Ok() ) + { + wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ; + if ( bmap->m_bitmapType == kMacBitmapTypePict ) + icon = bmap->m_hPict ; + else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) + { + icon = MakePict( bmap->m_hBitmap ) ; + } + } + ControlButtonContentInfo info ; + + info.contentType = kControlContentPictHandle ; + info.u.picture = icon ; + + UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; + + MacPostControlCreate() ; - return FALSE; + return TRUE; } void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) { m_buttonBitmap = bitmap; + PicHandle icon = NULL ; + if ( m_buttonBitmap.Ok() ) + { + wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ; + if ( bmap->m_bitmapType == kMacBitmapTypePict ) + icon = bmap->m_hPict ; + else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) + { + icon = MakePict( bmap->m_hBitmap ) ; + } + } + ControlButtonContentInfo info ; + + info.contentType = kControlContentPictHandle ; + info.u.picture = icon ; + + UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; } diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index 1bd9461b3d..e85f293e1c 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -504,6 +504,17 @@ void wxApp::CleanUp() int wxEntry( int argc, char *argv[] ) { +#ifdef __MWERKS__ +#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT + // This seems to be necessary since there are 'rogue' + // objects present at this point (perhaps global objects?) + // Setting a checkpoint will ignore them as far as the + // memory checking facility is concerned. + // Of course you may argue that memory allocated in globals should be + // checked, but this is a reasonable compromise. + wxDebugContext::SetCheckpoint(); +#endif +#endif if (!wxApp::Initialize()) return FALSE; if (!wxTheApp) @@ -1021,109 +1032,112 @@ void wxApp::MacHandleMouseUpEvent( EventRecord *ev ) } } -long wxMacTranslateKey(char key, char code) +long wxMacTranslateKey(unsigned char key, unsigned char code) { + long retval = key ; switch (key) { case 0x01 : - key = WXK_HOME; + retval = WXK_HOME; break; case 0x03 : - key = WXK_RETURN; + retval = WXK_RETURN; break; case 0x04 : - key = WXK_END; + retval = WXK_END; break; case 0x05 : - key = WXK_HELP; + retval = WXK_HELP; break; case 0x08 : - key = WXK_BACK; + retval = WXK_BACK; break; case 0x09 : - key = WXK_TAB; + retval = WXK_TAB; break; case 0x0b : - key = WXK_PAGEUP; + retval = WXK_PAGEUP; break; case 0x0c : - key = WXK_PAGEDOWN; + retval = WXK_PAGEDOWN; break; case 0x0d : - key = WXK_RETURN; + retval = WXK_RETURN; break; case 0x10 : { switch( code ) { case 0x7a : - key = WXK_F1 ; + retval = WXK_F1 ; break; case 0x78 : - key = WXK_F2 ; + retval = WXK_F2 ; break; case 0x63 : - key = WXK_F3 ; + retval = WXK_F3 ; break; case 0x76 : - key = WXK_F4 ; + retval = WXK_F4 ; break; case 0x60 : - key = WXK_F5 ; + retval = WXK_F5 ; break; case 0x61 : - key = WXK_F6 ; + retval = WXK_F6 ; break; case 0x62: - key = WXK_F7 ; + retval = WXK_F7 ; break; case 0x64 : - key = WXK_F8 ; + retval = WXK_F8 ; break; case 0x65 : - key = WXK_F9 ; + retval = WXK_F9 ; break; case 0x6D : - key = WXK_F10 ; + retval = WXK_F10 ; break; case 0x67 : - key = WXK_F11 ; + retval = WXK_F11 ; break; case 0x6F : - key = WXK_F12 ; + retval = WXK_F12 ; break; case 0x69 : - key = WXK_F13 ; + retval = WXK_F13 ; break; case 0x6B : - key = WXK_F14 ; + retval = WXK_F14 ; break; case 0x71 : - key = WXK_F15 ; + retval = WXK_F15 ; break; } } break ; case 0x1b : - key = WXK_DELETE ; + retval = WXK_ESCAPE ; break ; case 0x1c : - key = WXK_LEFT ; + retval = WXK_LEFT ; break ; case 0x1d : - key = WXK_RIGHT ; + retval = WXK_RIGHT ; break ; case 0x1e : - key = WXK_UP ; + retval = WXK_UP ; break ; case 0x1f : - key = WXK_DOWN ; + retval = WXK_DOWN ; break ; + case 0x7F : + retval = WXK_DELETE ; default: break ; } // end switch - return key; + return retval; } void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) @@ -1141,17 +1155,79 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) wxWindow* focus = wxWindow::FindFocus() ; if ( focus ) { - wxKeyEvent event(wxEVT_CHAR); + long keyval = wxMacTranslateKey(keychar, keycode) ; + + wxKeyEvent event(wxEVT_KEY_DOWN); event.m_shiftDown = ev->modifiers & shiftKey; event.m_controlDown = ev->modifiers & controlKey; event.m_altDown = ev->modifiers & optionKey; event.m_metaDown = ev->modifiers & cmdKey; - event.m_keyCode = wxMacTranslateKey(keychar, keycode); + event.m_keyCode = keyval; event.m_x = ev->where.h; event.m_y = ev->where.v; event.m_timeStamp = ev->when; event.SetEventObject(focus); - focus->GetEventHandler()->ProcessEvent( event ) ; + bool handled = focus->GetEventHandler()->ProcessEvent( event ) ; + if ( !handled ) + { + #if wxUSE_ACCEL + if (!handled) + { + wxWindow *ancestor = focus; + /* + while (ancestor) + { + int command = ancestor->GetAcceleratorTable()->GetCommand( event ); + if (command != -1) + { + wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); + handled = ancestor->GetEventHandler()->ProcessEvent( command_event ); + break; + } + if (ancestor->m_isFrame) + break; + ancestor = ancestor->GetParent(); + } + */ + } + #endif // wxUSE_ACCEL + } + if (!handled) + { + wxKeyEvent event(wxEVT_CHAR); + event.m_shiftDown = ev->modifiers & shiftKey; + event.m_controlDown = ev->modifiers & controlKey; + event.m_altDown = ev->modifiers & optionKey; + event.m_metaDown = ev->modifiers & cmdKey; + event.m_keyCode = keyval; + event.m_x = ev->where.h; + event.m_y = ev->where.v; + event.m_timeStamp = ev->when; + event.SetEventObject(focus); + handled = focus->GetEventHandler()->ProcessEvent( event ) ; + } + if ( !handled && + (keyval == WXK_TAB) && + (!focus->HasFlag(wxTE_PROCESS_TAB)) && + (focus->GetParent()) && + (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) ) + { + wxNavigationKeyEvent new_event; + new_event.SetEventObject( focus ); + new_event.SetDirection( !event.ShiftDown() ); + /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ + new_event.SetWindowChange( event.ControlDown() ); + new_event.SetCurrentFocus( focus ); + handled = focus->GetEventHandler()->ProcessEvent( new_event ); + } + /* generate wxID_CANCEL if command-. or has been pressed (typically in dialogs) */ + if ( (!handled) && + (keyval == '.' && event.ControlDown() ) ) + { + wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); + new_event.SetEventObject( focus ); + handled = focus->GetEventHandler()->ProcessEvent( new_event ); + } } } } diff --git a/src/mac/carbon/bmpbuttn.cpp b/src/mac/carbon/bmpbuttn.cpp index 169f0d557a..fecc971add 100644 --- a/src/mac/carbon/bmpbuttn.cpp +++ b/src/mac/carbon/bmpbuttn.cpp @@ -19,6 +19,10 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) #endif +#include + +PicHandle MakePict(GWorldPtr wp) ; + bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, @@ -26,13 +30,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit const wxString& name) { m_buttonBitmap = bitmap; - SetName(name); - SetValidator(validator); - parent->AddChild(this); - - m_backgroundColour = parent->GetBackgroundColour() ; - m_foregroundColour = parent->GetForegroundColour() ; - m_windowStyle = style; + m_marginX = 0; m_marginY = 0; @@ -52,14 +50,60 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit if ( height == -1 && bitmap.Ok()) height = bitmap.GetHeight() + 2*m_marginY; - /* TODO: create bitmap button - */ + m_macHorizontalBorder = 2 ; // additional pixels around the real control + m_macVerticalBorder = 2 ; + Rect bounds ; + Str255 title ; + MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ; + + m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , + kControlBehaviorOffsetContents + kControlContentPictHandle , 0, + kControlBevelButtonNormalBevelProc , (long) this ) ; + wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; + + m_buttonBitmap = bitmap; + PicHandle icon = NULL ; + if ( m_buttonBitmap.Ok() ) + { + wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ; + if ( bmap->m_bitmapType == kMacBitmapTypePict ) + icon = bmap->m_hPict ; + else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) + { + icon = MakePict( bmap->m_hBitmap ) ; + } + } + ControlButtonContentInfo info ; + + info.contentType = kControlContentPictHandle ; + info.u.picture = icon ; + + UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; + + MacPostControlCreate() ; - return FALSE; + return TRUE; } void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) { m_buttonBitmap = bitmap; + PicHandle icon = NULL ; + if ( m_buttonBitmap.Ok() ) + { + wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ; + if ( bmap->m_bitmapType == kMacBitmapTypePict ) + icon = bmap->m_hPict ; + else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) + { + icon = MakePict( bmap->m_hBitmap ) ; + } + } + ControlButtonContentInfo info ; + + info.contentType = kControlContentPictHandle ; + info.u.picture = icon ; + + UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; } diff --git a/src/mac/carbon/choice.cpp b/src/mac/carbon/choice.cpp index da3c4efc92..42c52012b2 100644 --- a/src/mac/carbon/choice.cpp +++ b/src/mac/carbon/choice.cpp @@ -89,9 +89,8 @@ void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId ); event.SetInt(GetSelection()); event.SetEventObject(this); - event.SetString(copystring(GetStringSelection())); + event.SetString(GetStringSelection()); ProcessCommand(event); - delete[] event.GetString(); } diff --git a/src/mac/carbon/pnghand.cpp b/src/mac/carbon/pnghand.cpp index d8a662d7da..8d6d6544f5 100644 --- a/src/mac/carbon/pnghand.cpp +++ b/src/mac/carbon/pnghand.cpp @@ -106,14 +106,15 @@ wxPNGReader::Create(int width, int height, int depth, int colortype) { Width = width; Height = height; Depth = depth; ColorType = (colortype>=0) ? colortype: ((Depth>8) ? COLORTYPE_COLOR: 0); + delete Palette; + delete[] RawImage ; + RawImage = 0; + Palette = 0; if (lpbi) { wxMacDestroyGWorld( lpbi ) ; -// delete Palette; } - RawImage = 0; - Palette = 0; if (lpbi = wxMacCreateGWorld( Width , Height , Depth) ) { EfeWidth = (long)(((long)Width*Depth + 31) / 32) * 4; @@ -197,10 +198,11 @@ bool wxPNGReader::SetRGB(int x, int y, byte r, byte g, byte b) bool wxPNGReader::SetPalette(wxPalette* colourmap) { + delete Palette ; if (!colourmap) return FALSE; ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR); - Palette = colourmap; + Palette = new wxPalette( *colourmap ); return true ; // return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0); } @@ -208,6 +210,7 @@ bool wxPNGReader::SetPalette(wxPalette* colourmap) bool wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b) { + delete Palette ; Palette = new wxPalette(); if (!Palette) return FALSE; @@ -223,6 +226,7 @@ wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b) bool wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct) { + delete Palette ; Palette = new wxPalette(); if (!Palette) return FALSE; @@ -249,6 +253,10 @@ wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct) void wxPNGReader::NullData() { + if (lpbi) { + wxMacDestroyGWorld( lpbi ) ; + } + delete Palette; lpbi = NULL; Palette = NULL; } @@ -516,30 +524,47 @@ bool wxPNGReader::ReadFile(char * ImageFileName) { if ( pixel_depth == 8 ) { + for ( int i = 0 ; i < info_ptr->width ; ++i ) + { + png_color_struct* color ; + RGBColor col ; + + int index = row_pointers[i] ; + color = &info_ptr->palette[index] ; + col.red = (((int)color->red) << 8) | ((int)color->red) ; + col.green = (((int)color->green) << 8) | ((int)color->green) ; + col.blue = (((int)color->blue) << 8) | ((int)color->blue) ; + SetCPixel( i, y, &col); + } + /* png_color_struct* color ; RGBColor col ; unsigned char* p = &row_pointers[0] ; + PenNormal() ; MoveTo( 0 , y ) ; - unsigned char lastcol = *p ; - color = &info_ptr->palette[lastcol] ; + int index = *p ; + color = &info_ptr->palette[index] ; col.red = (color->red << 8) | color->red ; col.green = (color->green << 8) | color->green ; col.blue = (color->blue << 8) | color->blue ; RGBForeColor( &col ) ; + col.red = col.green = col.blue = 0xFFFF ; + RGBBackColor( &col ) ; for ( int i = 0 ; i < info_ptr->width ; ++i , ++p) { - if ( *p != lastcol ) + if ( *p != index ) { LineTo( i , y ) ; - lastcol = *p ; - color = &info_ptr->palette[lastcol] ; - col.red = (color->red << 8) | color->red ; - col.green = (color->green << 8) | color->green ; - col.blue = (color->blue << 8) | color->blue ; + index = *p ; + color = &info_ptr->palette[index] ; + col.red = (((int)color->red) << 8) | ((int)color->red) ; + col.green = (((int)color->green) << 8) | ((int)color->green) ; + col.blue = (((int)color->blue) << 8) | ((int)color->blue) ; RGBForeColor( &col ) ; } } - LineTo( info_ptr->width - 1 , y ) ; + LineTo( info_ptr->width , y ) ; + */ } else { @@ -553,9 +578,9 @@ bool wxPNGReader::ReadFile(char * ImageFileName) int index = ( row_pointers[byte] >> offset ) & ( 0xFF >> ( 8 - pixel_depth ) ); color = &info_ptr->palette[index] ; - col.red = (color->red << 8) | color->red ; - col.green = (color->green << 8) | color->green ; - col.blue = (color->blue << 8) | color->blue ; + col.red = (((int)color->red) << 8) | ((int)color->red) ; + col.green = (((int)color->green) << 8) | ((int)color->green) ; + col.blue = (((int)color->blue) << 8) | ((int)color->blue) ; SetCPixel( i, y, &col); } } @@ -567,9 +592,9 @@ bool wxPNGReader::ReadFile(char * ImageFileName) png_color_struct* color ; RGBColor col ; color =(png_color_struct*) (&row_pointers[i*3]) ; - col.red = (color->red << 8) | color->red ; - col.green = (color->green << 8) | color->green ; - col.blue = (color->blue << 8) | color->blue ; + col.red = (((int)color->red) << 8) | ((int)color->red) ; + col.green = (((int)color->green) << 8) | ((int)color->green) ; + col.blue = (((int)color->blue) << 8) | ((int)color->blue) ; SetCPixel( i, y, &col); } } diff --git a/src/mac/carbon/statbmp.cpp b/src/mac/carbon/statbmp.cpp index 721c254234..86a8528929 100644 --- a/src/mac/carbon/statbmp.cpp +++ b/src/mac/carbon/statbmp.cpp @@ -34,9 +34,12 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name) { - m_messageBitmap = bitmap; SetName(name); - if (parent) parent->AddChild(this); + + m_backgroundColour = parent->GetBackgroundColour() ; + m_foregroundColour = parent->GetForegroundColour() ; + + m_messageBitmap = bitmap; if ( id == -1 ) m_windowId = (int)NewControlId(); @@ -46,7 +49,9 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, m_windowStyle = style; bool ret = wxControl::Create( parent, id, pos, size, style , name ); - + + SetSizeOrDefault() ; + return ret; } @@ -58,14 +63,21 @@ void wxStaticBitmap::SetSize(int x, int y, int width, int height, int sizeFlags) void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap) { m_messageBitmap = bitmap; - - Refresh() ; + SetSizeOrDefault(); } void wxStaticBitmap::OnPaint( wxPaintEvent &event ) { wxPaintDC dc(this); PrepareDC(dc); - dc.SetPalette( *m_messageBitmap.GetPalette() ) ; - dc.DrawBitmap( m_messageBitmap , 0 , 0 ) ; + dc.SetPalette( *m_messageBitmap.GetPalette() ) ; + dc.DrawBitmap( m_messageBitmap , 0 , 0 ) ; +} + +wxSize wxStaticBitmap::DoGetBestSize() const +{ + if ( m_messageBitmap.Ok() ) + return wxSize(m_messageBitmap.GetWidth(), m_messageBitmap.GetHeight()); + else + return wxSize(16, 16); // completely arbitrary } diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index 0620c12afb..56654a1af6 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -40,8 +40,7 @@ wxToolBar::wxToolBar() bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { - m_maxWidth = -1; - m_maxHeight = -1; + m_maxWidth = m_maxHeight = 0; m_defaultWidth = 24; m_defaultHeight = 22; @@ -152,7 +151,9 @@ bool wxToolBar::CreateTools() wxNode *node = m_tools.First(); int noButtons = 0; int x = 0 ; - + wxSize toolSize = GetToolSize() ; + int tw, th; + GetSize(& tw, & th); while (node) { wxToolBarTool *tool = (wxToolBarTool *)node->Data(); @@ -161,8 +162,8 @@ bool wxToolBar::CreateTools() if( tool->m_toolStyle != wxTOOL_STYLE_SEPARATOR ) { Rect toolrect = { toolbarrect.top + kwxMacToolBarTopMargin , toolbarrect.left + x + kwxMacToolBarLeftMargin , 0 , 0 } ; - toolrect.right = toolrect.left + m_defaultWidth ; - toolrect.bottom = toolrect.top + m_defaultHeight ; + toolrect.right = toolrect.left + toolSize.x ; + toolrect.bottom = toolrect.top + toolSize.y ; PicHandle icon = NULL ; if ( bmap ) @@ -197,17 +198,37 @@ bool wxToolBar::CreateTools() UMASetControlFontStyle( m_macToolHandle , &controlstyle ) ; UMAEmbedControl( m_macToolHandle , m_macControl ) ; - x += (int)m_defaultWidth; + x += (int)toolSize.x; noButtons ++; } else { m_macToolHandles.Add( NULL ) ; - x += (int)m_defaultWidth / 4; + x += (int)toolSize.x / 4; } + if ( toolbarrect.left + x + kwxMacToolBarLeftMargin > m_maxWidth) + m_maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin; + if (toolbarrect.top + kwxMacToolBarTopMargin + toolSize.y > m_maxHeight) + m_maxHeight = toolbarrect.top + kwxMacToolBarTopMargin ; + node = node->Next(); } + if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) + { + m_maxWidth = tw ; // +=toolSize.x; + m_maxHeight += toolSize.y; + m_maxHeight += m_yMargin; + } + else + { + m_maxHeight = th ;// += toolSize.y; + m_maxWidth += toolSize.x; + m_maxWidth += m_xMargin; + } + + SetSize(m_maxWidth, m_maxHeight); + return TRUE; } @@ -218,8 +239,7 @@ void wxToolBar::SetToolBitmapSize(const wxSize& size) wxSize wxToolBar::GetMaxSize() const { - // TODO - return wxSize(0, 0); + return wxSize(m_maxWidth, m_maxHeight); } // The button size is bigger than the bitmap size @@ -291,7 +311,13 @@ wxToolBarTool *wxToolBar::AddTool(int index, const wxBitmap& bitmap, const wxBit else tool->m_y = m_yMargin; - tool->SetSize(m_defaultWidth, m_defaultHeight); + tool->SetSize(GetToolSize().x, GetToolSize().y); + + if ((tool->m_x + bitmap.GetWidth() + m_xMargin) > m_maxWidth) + m_maxWidth = (tool->m_x + tool->GetWidth() + m_xMargin); + + if ((tool->m_y + bitmap.GetHeight() + m_yMargin) > m_maxHeight) + m_maxHeight = (tool->m_y + tool->GetHeight() + m_yMargin); m_tools.Append((long)index, tool); return tool; diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index 43e490d70b..ed8396c774 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -35,6 +35,10 @@ #include "wx/menuitem.h" #include "wx/log.h" +#if wxUSE_CARET + #include "wx/caret.h" +#endif // wxUSE_CARET + #define wxWINDOW_HSCROLL 5998 #define wxWINDOW_VSCROLL 5997 #define MAC_SCROLLBAR_SIZE 16 @@ -198,25 +202,45 @@ void wxWindow::SetFocus() { if (gFocusWindow ) { + #if wxUSE_CARET + // Deal with caret + if ( gFocusWindow->m_caret ) + { + gFocusWindow->m_caret->OnKillFocus(); + } + #endif // wxUSE_CARET wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; if ( control && control->GetMacControl() ) { UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ; } - wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); - event.SetEventObject(gFocusWindow); + wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); + event.SetEventObject(gFocusWindow); gFocusWindow->GetEventHandler()->ProcessEvent(event) ; } gFocusWindow = this ; { + #if wxUSE_CARET + // Deal with caret + if ( m_caret ) + { + m_caret->OnSetFocus(); + } + #endif // wxUSE_CARET + // panel wants to track the window which was the last to have focus in it + wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); + if ( panel ) + { + panel->SetLastFocus(this); + } wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; if ( control && control->GetMacControl() ) { UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlEditTextPart ) ; } - wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); - event.SetEventObject(this); + wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); + event.SetEventObject(this); GetEventHandler()->ProcessEvent(event) ; } } @@ -1348,6 +1372,9 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) if ( focus.Ok() ) { WindowRef window = GetMacRootWindow() ; + bool eraseBackground = false ; + if ( m_macWindowData ) + eraseBackground = true ; if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) { UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ; @@ -1374,13 +1401,13 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) { // if we have any other colours in the hierarchy - RGBBackColor( &parent->m_backgroundColour.GetPixel()) ; - break ; + RGBBackColor( &parent->m_backgroundColour.GetPixel()) ; + break ; } // if we have the normal colours in the hierarchy but another control etc. -> use it's background if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) { - ApplyThemeBackground (kThemeBackgroundTabPane, &(**updatergn).rgnBBox , kThemeStateActive,8,true); + ApplyThemeBackground(kThemeBackgroundTabPane, &(**updatergn).rgnBBox , kThemeStateActive,8,true); break ; } } @@ -1401,8 +1428,13 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) { RGBBackColor( &m_backgroundColour.GetPixel()) ; } + if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() ) + eraseBackground = true ; SetClip( updatergn ) ; - EraseRgn( updatergn ) ; + if ( eraseBackground ) + { + EraseRgn( updatergn ) ; + } } } @@ -1553,7 +1585,10 @@ void wxWindow::MacKeyDown( EventRecord *ev ) } - +bool wxWindow::AcceptsFocus() const +{ + return MacCanFocus() && wxWindowBase::AcceptsFocus(); +} ControlHandle wxWindow::MacGetContainerForEmbedding() { diff --git a/src/mac/choice.cpp b/src/mac/choice.cpp index da3c4efc92..42c52012b2 100644 --- a/src/mac/choice.cpp +++ b/src/mac/choice.cpp @@ -89,9 +89,8 @@ void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId ); event.SetInt(GetSelection()); event.SetEventObject(this); - event.SetString(copystring(GetStringSelection())); + event.SetString(GetStringSelection()); ProcessCommand(event); - delete[] event.GetString(); } diff --git a/src/mac/ldef/extldef.c b/src/mac/ldef/extldef.c new file mode 100644 index 0000000000..8e53fbf046 --- /dev/null +++ b/src/mac/ldef/extldef.c @@ -0,0 +1,91 @@ +#include "extldef.h" + +/************************************************************************* + + function prototypes + +*************************************************************************/ + +void DrawMsg(Boolean fSelect, Rect *r, Cell cell, ListHandle lh); +void HiliteMsg(Boolean fSelect, Rect *r); + +/************************************************************************* + + main + +*************************************************************************/ + +pascal void main(short message, Boolean fSelect, Rect *r, Cell cell, + short dataOffset, short dataLen, ListHandle lh) +{ + + switch(message) { + case lInitMsg: + break; + + case lDrawMsg: + DrawMsg(fSelect, r, cell, lh); + break; + + case lHiliteMsg: + HiliteMsg(fSelect, r); + break; + + case lCloseMsg: + break; + + default: + break; + } +} + +/************************************************************************* + + DrawMsg + +*************************************************************************/ + +void DrawMsg(Boolean fSelect, Rect *r, Cell cell, ListHandle lh) +{ + ExtLDEFInfo* info = (ExtLDEFInfo*) (**lh).refCon ; + GrafPtr savePort; + + // set up the port + GetPort(&savePort); + SetPort((**lh).port); + PenNormal(); + ForeColor( blackColor ) ; + BackColor( whiteColor ) ; + + EraseRect(r); + if ( info ) + { + if ( info->drawProc) + { + CallExtLDEFDrawProc(info->drawProc, r, cell, lh, info->refCon ); + } + + } + // hilite if selected + if (fSelect) + HiliteMsg(fSelect, r); + + SetPort(savePort); + +} + +/************************************************************************* + + HiliteMsg + +*************************************************************************/ + +void HiliteMsg(Boolean fSelect, Rect *r) +{ + unsigned char hMode; + + hMode = LMGetHiliteMode(); + BitClr((Ptr)(&hMode),(long)pHiliteBit); + LMSetHiliteMode(hMode); + InvertRect(r); +} diff --git a/src/mac/ldef/extldef.h b/src/mac/ldef/extldef.h new file mode 100644 index 0000000000..683219907d --- /dev/null +++ b/src/mac/ldef/extldef.h @@ -0,0 +1,59 @@ +#pragma once + +#include +#include + +#define kExtLDEFID 128 // resource id of our LDEF resource + +typedef void (*ExtLDEFDrawProcType)(Rect *r, Cell cell, ListHandle lh, long refcon); + +enum { + uppExtLDEFDrawProcInfo = kCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Rect *))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Cell))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(ListHandle))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long))) +}; + +#if USESROUTINEDESCRIPTORS +typedef UniversalProcPtr ExtLDEFDrawProcUPP; + +#define CallExtLDEFDrawProc(userRoutine, r, cell, lh , refcon ) \ + CallUniversalProc((UniversalProcPtr)(userRoutine), uppExtLDEFDrawProcInfo, r, cell, lh , refcon ) +#define NewExtLDEFDrawProc(userRoutine) \ + (ExtLDEFDrawProcUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppExtLDEFDrawProcInfo, GetCurrentISA()) + +#else +typedef ExtLDEFDrawProcType ExtLDEFDrawProcUPP; + +#define CallExtLDEFDrawProc(userRoutine, r, cell, lh , refcon) \ + (*(userRoutine))(r, cell, lh, refcon) +#define NewExtLDEFDrawProc(userRoutine) \ + (ExtLDEFDrawProcUPP)(userRoutine) +#endif + +typedef struct +{ + long refCon ; + ExtLDEFDrawProcUPP drawProc ; +} ExtLDEFInfo ; + +static void NewExtLDEFInfo( ListHandle lh , ExtLDEFDrawProcType drawproc , long refcon ) ; +static void NewExtLDEFInfo( ListHandle lh , ExtLDEFDrawProcType drawproc , long refcon ) +{ + ExtLDEFInfo* info = (ExtLDEFInfo* ) malloc( sizeof( ExtLDEFInfo ) ) ; + info->drawProc = NewExtLDEFDrawProc( drawproc ) ; + info->refCon = refcon ; + (**lh).refCon = (long) info ; +} + +static void DisposeExtLDEFInfo( ListHandle lh) ; +static void DisposeExtLDEFInfo( ListHandle lh) +{ + ExtLDEFInfo* info = (ExtLDEFInfo* ) (**lh).refCon ; + if ( info ) + { + DisposeRoutineDescriptor( (RoutineDescriptor*) info->drawProc ) ; + free( (void*) (**lh).refCon ) ; + } +} diff --git a/src/mac/ldef/extldef.mcp b/src/mac/ldef/extldef.mcp new file mode 100644 index 0000000000..12bf6effdd Binary files /dev/null and b/src/mac/ldef/extldef.mcp differ diff --git a/src/mac/pnghand.cpp b/src/mac/pnghand.cpp index d8a662d7da..8d6d6544f5 100644 --- a/src/mac/pnghand.cpp +++ b/src/mac/pnghand.cpp @@ -106,14 +106,15 @@ wxPNGReader::Create(int width, int height, int depth, int colortype) { Width = width; Height = height; Depth = depth; ColorType = (colortype>=0) ? colortype: ((Depth>8) ? COLORTYPE_COLOR: 0); + delete Palette; + delete[] RawImage ; + RawImage = 0; + Palette = 0; if (lpbi) { wxMacDestroyGWorld( lpbi ) ; -// delete Palette; } - RawImage = 0; - Palette = 0; if (lpbi = wxMacCreateGWorld( Width , Height , Depth) ) { EfeWidth = (long)(((long)Width*Depth + 31) / 32) * 4; @@ -197,10 +198,11 @@ bool wxPNGReader::SetRGB(int x, int y, byte r, byte g, byte b) bool wxPNGReader::SetPalette(wxPalette* colourmap) { + delete Palette ; if (!colourmap) return FALSE; ColorType |= (COLORTYPE_PALETTE | COLORTYPE_COLOR); - Palette = colourmap; + Palette = new wxPalette( *colourmap ); return true ; // return (DibSetUsage(lpbi, (HPALETTE) Palette->GetHPALETTE(), WXIMA_COLORS ) != 0); } @@ -208,6 +210,7 @@ bool wxPNGReader::SetPalette(wxPalette* colourmap) bool wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b) { + delete Palette ; Palette = new wxPalette(); if (!Palette) return FALSE; @@ -223,6 +226,7 @@ wxPNGReader::SetPalette(int n, byte *r, byte *g, byte *b) bool wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct) { + delete Palette ; Palette = new wxPalette(); if (!Palette) return FALSE; @@ -249,6 +253,10 @@ wxPNGReader::SetPalette(int n, rgb_color_struct *rgb_struct) void wxPNGReader::NullData() { + if (lpbi) { + wxMacDestroyGWorld( lpbi ) ; + } + delete Palette; lpbi = NULL; Palette = NULL; } @@ -516,30 +524,47 @@ bool wxPNGReader::ReadFile(char * ImageFileName) { if ( pixel_depth == 8 ) { + for ( int i = 0 ; i < info_ptr->width ; ++i ) + { + png_color_struct* color ; + RGBColor col ; + + int index = row_pointers[i] ; + color = &info_ptr->palette[index] ; + col.red = (((int)color->red) << 8) | ((int)color->red) ; + col.green = (((int)color->green) << 8) | ((int)color->green) ; + col.blue = (((int)color->blue) << 8) | ((int)color->blue) ; + SetCPixel( i, y, &col); + } + /* png_color_struct* color ; RGBColor col ; unsigned char* p = &row_pointers[0] ; + PenNormal() ; MoveTo( 0 , y ) ; - unsigned char lastcol = *p ; - color = &info_ptr->palette[lastcol] ; + int index = *p ; + color = &info_ptr->palette[index] ; col.red = (color->red << 8) | color->red ; col.green = (color->green << 8) | color->green ; col.blue = (color->blue << 8) | color->blue ; RGBForeColor( &col ) ; + col.red = col.green = col.blue = 0xFFFF ; + RGBBackColor( &col ) ; for ( int i = 0 ; i < info_ptr->width ; ++i , ++p) { - if ( *p != lastcol ) + if ( *p != index ) { LineTo( i , y ) ; - lastcol = *p ; - color = &info_ptr->palette[lastcol] ; - col.red = (color->red << 8) | color->red ; - col.green = (color->green << 8) | color->green ; - col.blue = (color->blue << 8) | color->blue ; + index = *p ; + color = &info_ptr->palette[index] ; + col.red = (((int)color->red) << 8) | ((int)color->red) ; + col.green = (((int)color->green) << 8) | ((int)color->green) ; + col.blue = (((int)color->blue) << 8) | ((int)color->blue) ; RGBForeColor( &col ) ; } } - LineTo( info_ptr->width - 1 , y ) ; + LineTo( info_ptr->width , y ) ; + */ } else { @@ -553,9 +578,9 @@ bool wxPNGReader::ReadFile(char * ImageFileName) int index = ( row_pointers[byte] >> offset ) & ( 0xFF >> ( 8 - pixel_depth ) ); color = &info_ptr->palette[index] ; - col.red = (color->red << 8) | color->red ; - col.green = (color->green << 8) | color->green ; - col.blue = (color->blue << 8) | color->blue ; + col.red = (((int)color->red) << 8) | ((int)color->red) ; + col.green = (((int)color->green) << 8) | ((int)color->green) ; + col.blue = (((int)color->blue) << 8) | ((int)color->blue) ; SetCPixel( i, y, &col); } } @@ -567,9 +592,9 @@ bool wxPNGReader::ReadFile(char * ImageFileName) png_color_struct* color ; RGBColor col ; color =(png_color_struct*) (&row_pointers[i*3]) ; - col.red = (color->red << 8) | color->red ; - col.green = (color->green << 8) | color->green ; - col.blue = (color->blue << 8) | color->blue ; + col.red = (((int)color->red) << 8) | ((int)color->red) ; + col.green = (((int)color->green) << 8) | ((int)color->green) ; + col.blue = (((int)color->blue) << 8) | ((int)color->blue) ; SetCPixel( i, y, &col); } } diff --git a/src/mac/statbmp.cpp b/src/mac/statbmp.cpp index 721c254234..86a8528929 100644 --- a/src/mac/statbmp.cpp +++ b/src/mac/statbmp.cpp @@ -34,9 +34,12 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name) { - m_messageBitmap = bitmap; SetName(name); - if (parent) parent->AddChild(this); + + m_backgroundColour = parent->GetBackgroundColour() ; + m_foregroundColour = parent->GetForegroundColour() ; + + m_messageBitmap = bitmap; if ( id == -1 ) m_windowId = (int)NewControlId(); @@ -46,7 +49,9 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, m_windowStyle = style; bool ret = wxControl::Create( parent, id, pos, size, style , name ); - + + SetSizeOrDefault() ; + return ret; } @@ -58,14 +63,21 @@ void wxStaticBitmap::SetSize(int x, int y, int width, int height, int sizeFlags) void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap) { m_messageBitmap = bitmap; - - Refresh() ; + SetSizeOrDefault(); } void wxStaticBitmap::OnPaint( wxPaintEvent &event ) { wxPaintDC dc(this); PrepareDC(dc); - dc.SetPalette( *m_messageBitmap.GetPalette() ) ; - dc.DrawBitmap( m_messageBitmap , 0 , 0 ) ; + dc.SetPalette( *m_messageBitmap.GetPalette() ) ; + dc.DrawBitmap( m_messageBitmap , 0 , 0 ) ; +} + +wxSize wxStaticBitmap::DoGetBestSize() const +{ + if ( m_messageBitmap.Ok() ) + return wxSize(m_messageBitmap.GetWidth(), m_messageBitmap.GetHeight()); + else + return wxSize(16, 16); // completely arbitrary } diff --git a/src/mac/toolbar.cpp b/src/mac/toolbar.cpp index 0620c12afb..56654a1af6 100644 --- a/src/mac/toolbar.cpp +++ b/src/mac/toolbar.cpp @@ -40,8 +40,7 @@ wxToolBar::wxToolBar() bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { - m_maxWidth = -1; - m_maxHeight = -1; + m_maxWidth = m_maxHeight = 0; m_defaultWidth = 24; m_defaultHeight = 22; @@ -152,7 +151,9 @@ bool wxToolBar::CreateTools() wxNode *node = m_tools.First(); int noButtons = 0; int x = 0 ; - + wxSize toolSize = GetToolSize() ; + int tw, th; + GetSize(& tw, & th); while (node) { wxToolBarTool *tool = (wxToolBarTool *)node->Data(); @@ -161,8 +162,8 @@ bool wxToolBar::CreateTools() if( tool->m_toolStyle != wxTOOL_STYLE_SEPARATOR ) { Rect toolrect = { toolbarrect.top + kwxMacToolBarTopMargin , toolbarrect.left + x + kwxMacToolBarLeftMargin , 0 , 0 } ; - toolrect.right = toolrect.left + m_defaultWidth ; - toolrect.bottom = toolrect.top + m_defaultHeight ; + toolrect.right = toolrect.left + toolSize.x ; + toolrect.bottom = toolrect.top + toolSize.y ; PicHandle icon = NULL ; if ( bmap ) @@ -197,17 +198,37 @@ bool wxToolBar::CreateTools() UMASetControlFontStyle( m_macToolHandle , &controlstyle ) ; UMAEmbedControl( m_macToolHandle , m_macControl ) ; - x += (int)m_defaultWidth; + x += (int)toolSize.x; noButtons ++; } else { m_macToolHandles.Add( NULL ) ; - x += (int)m_defaultWidth / 4; + x += (int)toolSize.x / 4; } + if ( toolbarrect.left + x + kwxMacToolBarLeftMargin > m_maxWidth) + m_maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin; + if (toolbarrect.top + kwxMacToolBarTopMargin + toolSize.y > m_maxHeight) + m_maxHeight = toolbarrect.top + kwxMacToolBarTopMargin ; + node = node->Next(); } + if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) + { + m_maxWidth = tw ; // +=toolSize.x; + m_maxHeight += toolSize.y; + m_maxHeight += m_yMargin; + } + else + { + m_maxHeight = th ;// += toolSize.y; + m_maxWidth += toolSize.x; + m_maxWidth += m_xMargin; + } + + SetSize(m_maxWidth, m_maxHeight); + return TRUE; } @@ -218,8 +239,7 @@ void wxToolBar::SetToolBitmapSize(const wxSize& size) wxSize wxToolBar::GetMaxSize() const { - // TODO - return wxSize(0, 0); + return wxSize(m_maxWidth, m_maxHeight); } // The button size is bigger than the bitmap size @@ -291,7 +311,13 @@ wxToolBarTool *wxToolBar::AddTool(int index, const wxBitmap& bitmap, const wxBit else tool->m_y = m_yMargin; - tool->SetSize(m_defaultWidth, m_defaultHeight); + tool->SetSize(GetToolSize().x, GetToolSize().y); + + if ((tool->m_x + bitmap.GetWidth() + m_xMargin) > m_maxWidth) + m_maxWidth = (tool->m_x + tool->GetWidth() + m_xMargin); + + if ((tool->m_y + bitmap.GetHeight() + m_yMargin) > m_maxHeight) + m_maxHeight = (tool->m_y + tool->GetHeight() + m_yMargin); m_tools.Append((long)index, tool); return tool; diff --git a/src/mac/window.cpp b/src/mac/window.cpp index 43e490d70b..ed8396c774 100644 --- a/src/mac/window.cpp +++ b/src/mac/window.cpp @@ -35,6 +35,10 @@ #include "wx/menuitem.h" #include "wx/log.h" +#if wxUSE_CARET + #include "wx/caret.h" +#endif // wxUSE_CARET + #define wxWINDOW_HSCROLL 5998 #define wxWINDOW_VSCROLL 5997 #define MAC_SCROLLBAR_SIZE 16 @@ -198,25 +202,45 @@ void wxWindow::SetFocus() { if (gFocusWindow ) { + #if wxUSE_CARET + // Deal with caret + if ( gFocusWindow->m_caret ) + { + gFocusWindow->m_caret->OnKillFocus(); + } + #endif // wxUSE_CARET wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; if ( control && control->GetMacControl() ) { UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ; } - wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); - event.SetEventObject(gFocusWindow); + wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId); + event.SetEventObject(gFocusWindow); gFocusWindow->GetEventHandler()->ProcessEvent(event) ; } gFocusWindow = this ; { + #if wxUSE_CARET + // Deal with caret + if ( m_caret ) + { + m_caret->OnSetFocus(); + } + #endif // wxUSE_CARET + // panel wants to track the window which was the last to have focus in it + wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); + if ( panel ) + { + panel->SetLastFocus(this); + } wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ; if ( control && control->GetMacControl() ) { UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlEditTextPart ) ; } - wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); - event.SetEventObject(this); + wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); + event.SetEventObject(this); GetEventHandler()->ProcessEvent(event) ; } } @@ -1348,6 +1372,9 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) if ( focus.Ok() ) { WindowRef window = GetMacRootWindow() ; + bool eraseBackground = false ; + if ( m_macWindowData ) + eraseBackground = true ; if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) { UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ; @@ -1374,13 +1401,13 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) ) { // if we have any other colours in the hierarchy - RGBBackColor( &parent->m_backgroundColour.GetPixel()) ; - break ; + RGBBackColor( &parent->m_backgroundColour.GetPixel()) ; + break ; } // if we have the normal colours in the hierarchy but another control etc. -> use it's background if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) { - ApplyThemeBackground (kThemeBackgroundTabPane, &(**updatergn).rgnBBox , kThemeStateActive,8,true); + ApplyThemeBackground(kThemeBackgroundTabPane, &(**updatergn).rgnBBox , kThemeStateActive,8,true); break ; } } @@ -1401,8 +1428,13 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) { RGBBackColor( &m_backgroundColour.GetPixel()) ; } + if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() ) + eraseBackground = true ; SetClip( updatergn ) ; - EraseRgn( updatergn ) ; + if ( eraseBackground ) + { + EraseRgn( updatergn ) ; + } } } @@ -1553,7 +1585,10 @@ void wxWindow::MacKeyDown( EventRecord *ev ) } - +bool wxWindow::AcceptsFocus() const +{ + return MacCanFocus() && wxWindowBase::AcceptsFocus(); +} ControlHandle wxWindow::MacGetContainerForEmbedding() {