X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2c1a331259c998fdf79ae0303a1845863de6afbb..8471ea90331c42693823ede04ded5fd4d5bf008b:/src/mac/listbox.cpp diff --git a/src/mac/listbox.cpp b/src/mac/listbox.cpp index 656a835b6e..8322a7a2f2 100644 --- a/src/mac/listbox.cpp +++ b/src/mac/listbox.cpp @@ -72,16 +72,19 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect Cell cell, short dataOffset, short dataLength, ListHandle listHandle ) { + wxListBox* list; + list = (wxListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) ); + if ( list == NULL ) + return ; + GrafPtr savePort; GrafPtr grafPtr; RgnHandle savedClipRegion; SInt32 savedPenMode; - wxListBox* list; GetPort(&savePort); SetPort((**listHandle).port); grafPtr = (**listHandle).port ; // typecast our refCon - list = (wxListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) ); // Calculate the cell rect. @@ -105,13 +108,12 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect ClipRect( drawRect ); EraseRect( drawRect ); - wxFontRefData * font = (wxFontRefData*) list->GetFont().GetRefData() ; - - if ( font ) + const wxFont& font = list->GetFont(); + if ( font.Ok() ) { - ::TextFont( font->m_macFontNum ) ; - ::TextSize( short(font->m_macFontSize) ) ; - ::TextFace( font->m_macFontStyle ) ; + ::TextFont( font.GetMacFontNum() ) ; + ::TextSize( font.GetMacFontSize() ) ; + ::TextFace( font.GetMacFontStyle() ) ; } else { @@ -124,7 +126,7 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect { Rect frame = { drawRect->top, drawRect->left + 4, drawRect->top + kwxMacListItemHeight, drawRect->right + 10000 } ; - CFMutableStringRef mString = CFStringCreateMutableCopy( NULL , 0 , wxMacCFStringHolder(linetext) ) ; + CFMutableStringRef mString = CFStringCreateMutableCopy( NULL , 0 , wxMacCFStringHolder(linetext , list->GetFont().GetEncoding()) ) ; ::TruncateThemeText( mString , kThemeCurrentPortFont, kThemeStateActive, drawRect->right - drawRect->left , truncEnd , NULL ) ; ::DrawThemeTextBox( mString, kThemeCurrentPortFont, @@ -137,7 +139,7 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect } #else { - wxCharBuffer text = wxMacStringToCString( linetext ) ; + wxCharBuffer text = linetext.mb_str( wxConvLocal) ; MoveTo(drawRect->left + 4 , drawRect->top + 10 ); DrawText(text, 0 , strlen(text) ); } @@ -194,6 +196,20 @@ wxListBox::wxListBox() static ListDefUPP macListDefUPP = NULL ; +bool wxListBox::Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos, + const wxSize& size, + const wxArrayString& choices, + long style, + const wxValidator& validator, + const wxString& name) +{ + wxCArrayString chs(choices); + + return Create(parent, id, pos, size, chs.GetCount(), chs.GetStrings(), + style, validator, name); +} + bool wxListBox::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, @@ -202,6 +218,9 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { + if ( !wxListBoxBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) ) + return false; + m_noItems = 0 ; // this will be increased by our append command m_selected = 0; @@ -221,7 +240,6 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, Str255 fontName ; SInt16 fontSize ; Style fontStyle ; - SInt16 fontNum ; #if TARGET_CARBON GetThemeFont(kThemeViewsFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; #else @@ -271,11 +289,11 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, OptionBits options = 0; if ( style & wxLB_MULTIPLE ) { - options += lNoExtend ; + options += lExtendDrag + lUseSense ; } else if ( style & wxLB_EXTENDED ) { - options += lExtendDrag ; + // default behaviour } else { @@ -298,6 +316,8 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, wxListBox::~wxListBox() { FreeData() ; + // avoid access during destruction + SetControlReference( (ControlHandle) m_macControl , NULL ) ; if ( m_macList ) { #if !TARGET_CARBON @@ -602,13 +622,11 @@ wxSize wxListBox::DoGetBestSize() const { wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ; - wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; - - if ( font ) + if ( m_font.Ok() ) { - ::TextFont( font->m_macFontNum ) ; - ::TextSize( short(font->m_macFontSize) ) ; - ::TextFace( font->m_macFontStyle ) ; + ::TextFont( m_font.GetMacFontNum() ) ; + ::TextSize( m_font.GetMacFontSize() ) ; + ::TextFace( m_font.GetMacFontStyle() ) ; } else { @@ -623,7 +641,7 @@ wxSize wxListBox::DoGetBestSize() const #if wxUSE_UNICODE Point bounds={0,0} ; SInt16 baseline ; - ::GetThemeTextDimensions( wxMacCFStringHolder( str ) , + ::GetThemeTextDimensions( wxMacCFStringHolder( str , m_font.GetEncoding() ) , kThemeCurrentPortFont, kThemeStateActive, false, @@ -631,8 +649,7 @@ wxSize wxListBox::DoGetBestSize() const &baseline ); wLine = bounds.h ; #else - wxCharBuffer text = wxMacStringToCString( str ) ; - wLine = ::TextWidth( text , 0 , strlen(text) ) ; + wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ; #endif lbWidth = wxMax(lbWidth, wLine); } @@ -811,7 +828,7 @@ void wxListBox::MacScrollTo( int n ) // TODO implement scrolling } -void wxListBox::OnSize( const wxSizeEvent &event) +void wxListBox::OnSize( wxSizeEvent &event) { Point pt; @@ -824,7 +841,7 @@ void wxListBox::OnSize( const wxSizeEvent &event) LCellSize( pt , (ListHandle)m_macList ) ; } -void wxListBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) +void wxListBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) { Boolean wasDoubleClick = false ; long result ; @@ -925,10 +942,14 @@ void wxListBox::OnChar(wxKeyEvent& event) /* generate wxID_CANCEL if command-. or has been pressed (typically in dialogs) */ else if (event.GetKeyCode() == WXK_ESCAPE || (event.GetKeyCode() == '.' && event.MetaDown() ) ) { + // FIXME: look in ancestors, not just parent. wxWindow* win = GetParent()->FindWindow( wxID_CANCEL ) ; - wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); - new_event.SetEventObject( win ); - win->GetEventHandler()->ProcessEvent( new_event ); + if (win) + { + wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); + new_event.SetEventObject( win ); + win->GetEventHandler()->ProcessEvent( new_event ); + } } else if ( event.GetKeyCode() == WXK_TAB ) {