X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dc0ace7cddf87db31af84c438a3ca45c306e95c5..408ad8789c6834825d0a2792d43afd14e6f7acb2:/src/mac/listbox.cpp diff --git a/src/mac/listbox.cpp b/src/mac/listbox.cpp index 8aa10ed2ab..be7155a4d0 100644 --- a/src/mac/listbox.cpp +++ b/src/mac/listbox.cpp @@ -105,16 +105,34 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect ClipRect( drawRect ); EraseRect( drawRect ); + wxFontRefData * font = (wxFontRefData*) list->GetFont().GetRefData() ; + + if ( font ) + { + ::TextFont( font->m_macFontNum ) ; + ::TextSize( short(font->m_macFontSize) ) ; + ::TextFace( font->m_macFontStyle ) ; + } + else + { + ::TextFont( kFontIDMonaco ) ; + ::TextSize( 9 ); + ::TextFace( 0 ) ; + } + #if TARGET_CARBON bool useDrawThemeText = ( DrawThemeTextBox != (void*) kUnresolvedCFragSymbolAddress ) ; if ( useDrawThemeText ) { Rect frame = { drawRect->top, drawRect->left + 4, - drawRect->top + kwxMacListItemHeight, drawRect->right} ; - CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text.c_str(), text.Length(), CFStringGetSystemEncoding(), false ) ; + drawRect->top + kwxMacListItemHeight, drawRect->right + 10000 } ; + CFStringRef sString = CFStringCreateWithBytes( NULL , (UInt8*) text.c_str(), text.Length(), CFStringGetSystemEncoding(), false ) ; + CFMutableStringRef mString = CFStringCreateMutableCopy( NULL , 0 , sString ) ; + CFRelease( sString ) ; + ::TruncateThemeText( mString , kThemeCurrentPortFont, kThemeStateActive, drawRect->right - drawRect->left , truncEnd , NULL ) ; ::DrawThemeTextBox( mString, - kThemeViewsFont, + kThemeCurrentPortFont, kThemeStateActive, false, &frame, @@ -126,9 +144,6 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect #endif { MoveTo(drawRect->left + 4 , drawRect->top + 10 ); - ::TextFont( kFontIDMonaco ) ; - ::TextSize( 9 ); - ::TextFace( 0 ) ; DrawText(text, 0 , text.Length()); } @@ -166,7 +181,9 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect } extern "C" void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) ; +// resources ldef ids const short kwxMacListWithVerticalScrollbar = 128 ; +const short kwxMacListWithVerticalAndHorizontalScrollbar = 129 ; // ============================================================================ // list box control implementation @@ -206,11 +223,24 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, } listDef.u.userProc = macListDefUPP ; + Str255 fontName ; + SInt16 fontSize ; + Style fontStyle ; + SInt16 fontNum ; +#if TARGET_CARBON + GetThemeFont(kThemeViewsFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; +#else + GetFontName( kFontIDMonaco , fontName ) ; + fontSize = 9 ; + fontStyle = normal ; +#endif + CopyPascalStringToC( fontName , (char*) fontName ) ; + SetFont( wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , fontName ) ) ; #if TARGET_CARBON Size asize; - CreateListBoxControl( MAC_WXHWND(parent->MacGetRootWindow()), &bounds, false, 0, 1, false, true, + CreateListBoxControl( MAC_WXHWND(parent->MacGetRootWindow()), &bounds, false, 0, 1, (style & wxLB_HSCROLL), true, kwxMacListItemHeight, kwxMacListItemHeight, false, &listDef, (ControlRef *)&m_macControl ); GetControlData( (ControlHandle) m_macControl, kControlNoPart, kControlListBoxListHandleTag, @@ -224,8 +254,8 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, long result ; wxStAppResource resload ; m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , - kwxMacListWithVerticalScrollbar , 0 , 0, - kControlListBoxProc , (long) this ) ; + (style & wxLB_HSCROLL) ? kwxMacListWithVerticalAndHorizontalScrollbar : kwxMacListWithVerticalScrollbar , + 0 , 0, kControlListBoxProc , (long) this ) ; ::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag , sizeof( ListHandle ) , (char*) &m_macList , &result ) ; @@ -255,17 +285,17 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, } else { - options = lOnlyOne ; + options = (OptionBits) lOnlyOne ; } SetListSelectionFlags((ListHandle)m_macList, options); - MacPostControlCreate() ; - for ( int i = 0 ; i < n ; i++ ) { Append( choices[i] ) ; } + MacPostControlCreate() ; + LSetDrawingMode( true , (ListHandle)m_macList ) ; return TRUE; @@ -544,9 +574,9 @@ void wxListBox::DoSetItemClientData(int N, void *Client_data) wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes")); } #endif // wxUSE_OWNER_DRAWN - wxASSERT_MSG( m_dataArray.GetCount() >= N , "invalid client_data array" ) ; + wxASSERT_MSG( m_dataArray.GetCount() >= (size_t) N , "invalid client_data array" ) ; - if ( m_dataArray.GetCount() > N ) + if ( m_dataArray.GetCount() > (size_t) N ) { m_dataArray[N] = (char*) Client_data ; } @@ -616,7 +646,48 @@ void wxListBox::SetString(int N, const wxString& s) wxSize wxListBox::DoGetBestSize() const { - return wxSize(100, 100); + int lbWidth = 100; // some defaults + int lbHeight = 110; + int wLine; + + { + wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ; + + wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; + + if ( font ) + { + ::TextFont( font->m_macFontNum ) ; + ::TextSize( short(font->m_macFontSize) ) ; + ::TextFace( font->m_macFontStyle ) ; + } + else + { + ::TextFont( kFontIDMonaco ) ; + ::TextSize( 9 ); + ::TextFace( 0 ) ; + } + + // Find the widest line + for(int i = 0; i < GetCount(); i++) { + wxString str(GetString(i)); + wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ; + lbWidth = wxMax(lbWidth, wLine); + } + + // Add room for the scrollbar + lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); + + // And just a bit more + int cy = 12 ; + int cx = ::TextWidth( "X" , 0 , 1 ) ; + lbWidth += cx ; + + // don't make the listbox too tall (limit height to around 10 items) but don't + // make it too small neither + lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10); + } + return wxSize(lbWidth, lbHeight); } int wxListBox::GetCount() const @@ -661,6 +732,7 @@ wxOwnerDrawn *wxListBox::CreateItem(size_t n) // list box control implementation // ============================================================================ +/* void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) { wxListBox* list; @@ -675,7 +747,7 @@ void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refC DrawText(text, 0 , text.Length()); } - +*/ void wxListBox::MacDelete( int N ) { LDelRow( 1 , N , (ListHandle)m_macList) ; @@ -815,12 +887,13 @@ void wxListBox::MacSetRedraw( bool doDraw ) void wxListBox::MacDoClick() { wxArrayInt aSelections; - int n, count = GetSelections(aSelections); + int n ; + size_t count = GetSelections(aSelections); if ( count == m_selectionPreImage.GetCount() ) { bool hasChanged = false ; - for ( int i = 0 ; i < count ; ++i ) + for ( size_t i = 0 ; i < count ; ++i ) { if ( aSelections[i] != m_selectionPreImage[i] ) { @@ -865,11 +938,9 @@ void wxListBox::MacDoDoubleClick() GetEventHandler()->ProcessEvent(event) ; } -static long sLastTypeIn = 0 ; - void wxListBox::OnChar(wxKeyEvent& event) { - if ( event.KeyCode() == WXK_RETURN || event.KeyCode() == WXK_NUMPAD_ENTER) + if ( event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) { wxWindow* parent = GetParent() ; while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) @@ -890,14 +961,14 @@ void wxListBox::OnChar(wxKeyEvent& event) event.Skip() ; } /* generate wxID_CANCEL if command-. or has been pressed (typically in dialogs) */ - else if (event.KeyCode() == WXK_ESCAPE || (event.KeyCode() == '.' && event.MetaDown() ) ) + else if (event.GetKeyCode() == WXK_ESCAPE || (event.GetKeyCode() == '.' && event.MetaDown() ) ) { wxWindow* win = GetParent()->FindWindow( wxID_CANCEL ) ; wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); new_event.SetEventObject( win ); win->GetEventHandler()->ProcessEvent( new_event ); } - else if ( event.KeyCode() == WXK_TAB ) + else if ( event.GetKeyCode() == WXK_TAB ) { wxNavigationKeyEvent new_event; new_event.SetEventObject( this ); @@ -908,7 +979,7 @@ void wxListBox::OnChar(wxKeyEvent& event) if ( !GetEventHandler()->ProcessEvent( new_event ) ) event.Skip() ; } - else if ( event.KeyCode() == WXK_DOWN || event.KeyCode() == WXK_UP ) + else if ( event.GetKeyCode() == WXK_DOWN || event.GetKeyCode() == WXK_UP ) { // perform the default key handling first wxControl::OnKeyDown( event ) ; @@ -943,7 +1014,7 @@ void wxListBox::OnChar(wxKeyEvent& event) m_typeIn = "" ; } m_lastTypeIn = event.GetTimestamp() ; - m_typeIn += (char) event.KeyCode() ; + m_typeIn += (char) event.GetKeyCode() ; int line = FindString("*"+m_typeIn+"*") ; if ( line >= 0 ) {