#include "wx/app.h"
#include "wx/listbox.h"
+#include "wx/button.h"
#include "wx/settings.h"
#include "wx/toplevel.h"
#include "wx/dynarray.h"
IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
BEGIN_EVENT_TABLE(wxListBox, wxControl)
- EVT_SIZE( wxListBox::OnSize )
+ EVT_SIZE( wxListBox::OnSize )
EVT_CHAR( wxListBox::OnChar )
END_EVENT_TABLE()
#endif
#pragma pack()
#endif
+#if TARGET_CARBON
+const short kwxMacListItemHeight = 19 ;
+#else
+const short kwxMacListItemHeight = 14 ;
+#endif
+
extern "C"
{
static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect *drawRect,
grafPtr = (**listHandle).port ;
// typecast our refCon
list = (wxListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) );
-
+
// Calculate the cell rect.
-
+
switch( message ) {
case lInitMsg:
break;
// Save the current clip region, and set the clip region to the area we are about
// to draw.
-
+
savedClipRegion = NewRgn();
GetClip( savedClipRegion );
ClipRect( drawRect );
EraseRect( drawRect );
-
- MoveTo(drawRect->left + 4 , drawRect->top + 10 );
- ::TextFont( kFontIDMonaco ) ;
- ::TextSize( 9 );
- ::TextFace( 0 ) ;
-
- DrawText(text, 0 , text.Length());
+
+ 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 + 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,
+ kThemeCurrentPortFont,
+ kThemeStateActive,
+ false,
+ &frame,
+ teJustLeft,
+ nil );
+ CFRelease( mString ) ;
+ }
+ else
+#endif
+ {
+ MoveTo(drawRect->left + 4 , drawRect->top + 10 );
+ DrawText(text, 0 , text.Length());
+ }
+
// If the cell is hilited, do the hilite now. Paint the cell contents with the
// appropriate QuickDraw transform mode.
-
+
if( isSelected ) {
savedPenMode = GetPortPenMode( (CGrafPtr) grafPtr );
SetPortPenMode( (CGrafPtr)grafPtr, hilitetransfermode );
PaintRect( drawRect );
SetPortPenMode( (CGrafPtr)grafPtr, savedPenMode );
}
-
+
// Restore the saved clip region.
-
+
SetClip( savedClipRegion );
DisposeRgn( savedClipRegion );
}
break;
case lHiliteMsg:
-
+
// Hilite or unhilite the cell. Paint the cell contents with the
// appropriate QuickDraw transform mode.
-
+
GetPort( &grafPtr );
savedPenMode = GetPortPenMode( (CGrafPtr)grafPtr );
SetPortPenMode( (CGrafPtr)grafPtr, hilitetransfermode );
default :
break ;
}
- SetPort(savePort);
+ SetPort(savePort);
}
extern "C" void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon) ;
const short kwxMacListWithVerticalScrollbar = 128 ;
-const short kwxMacListItemHeight = 14 ;
// ============================================================================
// list box control implementation
{
m_noItems = 0 ; // this will be increased by our append command
m_selected = 0;
-
+
Rect bounds ;
Str255 title ;
-
+
MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
ListDefSpec listDef;
listDef.defType = kListDefUserProcType;
if ( macListDefUPP == NULL )
{
- macListDefUPP = NewListDefUPP( wxMacListDefinition );
+ macListDefUPP = NewListDefUPP( wxMacListDefinition );
}
listDef.u.userProc = macListDefUPP ;
+ Str255 fontName ;
+ SInt16 fontSize ;
+ Style fontStyle ;
+#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;
long result ;
wxStAppResource resload ;
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false ,
- kwxMacListWithVerticalScrollbar , 0 , 0,
+ kwxMacListWithVerticalScrollbar , 0 , 0,
kControlListBoxProc , (long) this ) ;
::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
sizeof( ListHandle ) , (char*) &m_macList , &result ) ;
(**ldef).function = (void(*)()) listDef.u.userProc;
(**(ListHandle)m_macList).listDefProc = (Handle) ldef ;
}
-
+
Point pt = (**(ListHandle)m_macList).cellSize ;
pt.v = kwxMacListItemHeight ;
LCellSize( pt , (ListHandle)m_macList ) ;
}
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;
GetControlBounds( control , &scrollbounds ) ;
if( scrollbounds.right != bounds.right + 1 )
{
- UMAMoveControl( control , bounds.right - (scrollbounds.right - scrollbounds.left) + 1 ,
+ UMAMoveControl( control , bounds.right - (scrollbounds.right - scrollbounds.left) + 1 ,
scrollbounds.top ) ;
}
}
m_stringArray.RemoveAt( N ) ;
m_dataArray.RemoveAt( N ) ;
m_noItems --;
-
+
MacDelete( N ) ;
}
}
void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
-{
+{
MacSetRedraw( false ) ;
- Clear() ;
+ Clear() ;
int n = choices.GetCount();
for( int i = 0 ; i < n ; ++i )
}
else
s = st ;
-
+
if ( s.Right(1) == "*" )
{
wxString search = s.Left( s.Length() - 1 ) ;
if ( GetString(i).Lower().Matches(s) )
return i ;
}
- }
+ }
}
else
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" ) ;
-
- if ( m_dataArray.GetCount() > N )
+ wxASSERT_MSG( m_dataArray.GetCount() >= (size_t) N , "invalid client_data array" ) ;
+
+ if ( m_dataArray.GetCount() > (size_t) N )
{
m_dataArray[N] = (char*) Client_data ;
}
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
// list box control implementation
// ============================================================================
+/*
void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
{
wxListBox* list;
// typecast our refCon
list = (wxListBox*)refCon;
-
+
MoveTo(cellRect->left + 4 , cellRect->top + 10 );
const wxString text = list->m_stringArray[lCell.v] ;
::TextFont( kFontIDMonaco ) ;
::TextSize( 9 );
::TextFace( 0 ) ;
DrawText(text, 0 , text.Length());
-
-}
+}
+*/
void wxListBox::MacDelete( int N )
{
LDelRow( 1 , N , (ListHandle)m_macList) ;
Refresh();
}
-void wxListBox::MacInsert( int n , const char * text)
+void wxListBox::MacInsert( int n , const char * text)
{
Cell cell = { 0 , 0 } ;
cell.v = n ;
Refresh();
}
-void wxListBox::MacAppend( const char * text)
+void wxListBox::MacAppend( const char * text)
{
Cell cell = { 0 , 0 } ;
cell.v = (**(ListHandle)m_macList).dataBounds.bottom ;
Refresh();
}
-void wxListBox::MacClear()
+void wxListBox::MacClear()
{
LDelRow( (**(ListHandle)m_macList).dataBounds.bottom , 0 ,(ListHandle) m_macList ) ;
Refresh();
LSetSelect( false , cell , (ListHandle)m_macList ) ;
}
}
-
+
cell.v = n ;
LSetSelect( select , cell , (ListHandle)m_macList ) ;
LAutoScroll( (ListHandle)m_macList ) ;
int wxListBox::MacGetSelections( wxArrayInt& aSelections ) const
{
int no_sel = 0 ;
-
+
aSelections.Empty();
Cell cell = { 0 , 0 } ;
cell.v = 0 ;
-
+
while ( LGetSelect( true , &cell ,(ListHandle) m_macList ) )
{
aSelections.Add( cell.v ) ;
LCellSize( pt , (ListHandle)m_macList ) ;
}
-void wxListBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart )
+void wxListBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart )
{
Boolean wasDoubleClick = false ;
long result ;
}
}
-void wxListBox::MacSetRedraw( bool doDraw )
+void wxListBox::MacSetRedraw( bool doDraw )
{
LSetDrawingMode( doDraw , (ListHandle)m_macList ) ;
-
+
}
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] )
{
return ;
}
}
-
+
m_selectionPreImage = aSelections;
-
+
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
event.SetEventObject( this );
{
n = -1;
}
-
+
event.m_commandInt = n;
GetEventHandler()->ProcessEvent(event);
{
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
event.SetEventObject( this );
- GetEventHandler()->ProcessEvent(event) ;
+ GetEventHandler()->ProcessEvent(event) ;
}
-static long sLastTypeIn = 0 ;
-
void wxListBox::OnChar(wxKeyEvent& event)
{
if ( event.KeyCode() == WXK_RETURN || event.KeyCode() == WXK_NUMPAD_ENTER)
wxWindow* parent = GetParent() ;
while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL )
parent = parent->GetParent() ;
-
+
if ( parent && parent->GetDefaultItem() )
{
wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
if ( !GetEventHandler()->ProcessEvent( new_event ) )
event.Skip() ;
}
- else if ( event.KeyCode() == WXK_SPACE || event.KeyCode() == WXK_DOWN || event.KeyCode() == WXK_UP )
+ else if ( event.KeyCode() == WXK_DOWN || event.KeyCode() == WXK_UP )
{
// perform the default key handling first
- if ( event.KeyCode() == WXK_DOWN || event.KeyCode() == WXK_UP )
- wxControl::OnKeyDown( event ) ;
-
+ wxControl::OnKeyDown( event ) ;
+
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
event.SetEventObject( this );