///////////////////////////////////////////////////////////////////////////////
-// Name: listbox.cpp
+// Name: src/mac/classic/listbox.cpp
// Purpose: wxListBox
// Author: Stefan Csomor
// Modified by:
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
-#pragma implementation "listbox.h"
-#endif
-
#include "wx/app.h"
#include "wx/listbox.h"
#include "wx/button.h"
#include "wx/utils.h"
-#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
BEGIN_EVENT_TABLE(wxListBox, wxControl)
EVT_SIZE( wxListBox::OnSize )
EVT_CHAR( wxListBox::OnChar )
END_EVENT_TABLE()
-#endif
#include "wx/mac/uma.h"
list = (wxListBox*) GetControlReference( (ControlHandle) GetListRefCon(listHandle) );
if ( list == NULL )
return ;
-
+
GrafPtr savePort;
GrafPtr grafPtr;
RgnHandle savedClipRegion;
SetPort((**listHandle).port);
grafPtr = (**listHandle).port ;
// typecast our refCon
-
+
// Calculate the cell rect.
-
+
switch( message ) {
case lInitMsg:
break;
-
+
case lCloseMsg:
break;
-
+
case lDrawMsg:
{
const wxString linetext = list->m_stringArray[cell.v] ;
-
+
// 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 );
-
+
const wxFont& font = list->GetFont();
if ( font.Ok() )
{
::TextSize( 9 );
::TextFace( 0 ) ;
}
-
+
#if TARGET_CARBON
- {
- Rect frame = { drawRect->top, drawRect->left + 4,
- drawRect->top + kwxMacListItemHeight, drawRect->right + 10000 } ;
- CFMutableStringRef mString = CFStringCreateMutableCopy( NULL , 0 , wxMacCFStringHolder(linetext , list->GetFont().GetEncoding()) ) ;
- ::TruncateThemeText( mString , kThemeCurrentPortFont, kThemeStateActive, drawRect->right - drawRect->left , truncEnd , NULL ) ;
- ::DrawThemeTextBox( mString,
- kThemeCurrentPortFont,
- kThemeStateActive,
- false,
- &frame,
- teJustLeft,
- nil );
- CFRelease( mString ) ;
- }
+ {
+ Rect frame = { drawRect->top, drawRect->left + 4,
+ drawRect->top + kwxMacListItemHeight, drawRect->right + 10000 } ;
+ CFMutableStringRef mString = CFStringCreateMutableCopy( NULL , 0 , wxMacCFStringHolder(linetext , list->GetFont().GetEncoding()) ) ;
+ ::TruncateThemeText( mString , kThemeCurrentPortFont, kThemeStateActive, drawRect->right - drawRect->left , truncEnd , NULL ) ;
+ ::DrawThemeTextBox( mString,
+ kThemeCurrentPortFont,
+ kThemeStateActive,
+ false,
+ &frame,
+ teJustLeft,
+ nil );
+ CFRelease( mString ) ;
+ }
#else
- {
- wxCharBuffer text = linetext.mb_str( wxConvLocal) ;
+ {
+ wxCharBuffer text = linetext.mb_str( wxConvLocal) ;
MoveTo(drawRect->left + 4 , drawRect->top + 10 );
DrawText(text, 0 , strlen(text) );
}
-#endif
+#endif
// 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 );
Rect bounds ;
Str255 title ;
-
+
MacPreControlCreate( parent , id , wxEmptyString , pos , size ,style, validator , name , &bounds , title ) ;
-
+
ListDefSpec listDef;
listDef.defType = kListDefUserProcType;
if ( macListDefUPP == NULL )
macListDefUPP = NewListDefUPP( wxMacListDefinition );
}
listDef.u.userProc = macListDefUPP ;
-
+
Str255 fontName ;
SInt16 fontSize ;
Style fontStyle ;
GetFontName( kFontIDMonaco , fontName ) ;
fontSize = 9 ;
fontStyle = normal ;
-#endif
+#endif
SetFont( wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , wxMacMakeStringFromPascal( fontName ) ) ) ;
#if TARGET_CARBON
Size asize;
long result ;
wxStAppResource resload ;
m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false ,
- (style & wxLB_HSCROLL) ? kwxMacListWithVerticalAndHorizontalScrollbar : kwxMacListWithVerticalScrollbar ,
+ (style & wxLB_HSCROLL) ? kwxMacListWithVerticalAndHorizontalScrollbar : kwxMacListWithVerticalScrollbar ,
0 , 0, kControlListBoxProc , (long) this ) ;
::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxListHandleTag ,
sizeof( ListHandle ) , (char*) &m_macList , &result ) ;
MacSetRedraw( false ) ;
Clear() ;
int n = choices.GetCount();
-
+
for( int i = 0 ; i < n ; ++i )
{
if ( clientData )
else
Append( choices[i] ) ;
}
-
+
#if wxUSE_OWNER_DRAWN
if ( m_windowStyle & wxLB_OWNERDRAW ) {
// first delete old items
m_aItems[ui] = NULL;
}
m_aItems.Empty();
-
+
// then create new ones
for ( ui = 0; ui < (size_t)m_noItems; ui++ ) {
wxOwnerDrawn *pNewItem = CreateItem(ui);
return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED);
}
-int wxListBox::FindString(const wxString& s) const
+int wxListBox::FindString(const wxString& s, bool bCase) const
{
-
if ( s.Right(1) == wxT("*") )
{
wxString search = s.Left( s.Length() - 1 ) ;
int len = search.Length() ;
Str255 s1 , s2 ;
wxMacStringToPascal( search , s2 ) ;
-
+
for ( int i = 0 ; i < m_noItems ; ++ i )
{
- wxMacStringToPascal( m_stringArray[i].Left( len ) , s1 ) ;
+ wxMacStringToPascal( m_stringArray[i].Left( len ) , s1 ) ;
- if ( EqualString( s1 , s2 , false , false ) )
+ if ( EqualString( s1 , s2 , bCase , false ) )
return i ;
}
if ( s.Left(1) == wxT("*") && s.Length() > 1 )
return i ;
}
}
-
+
}
else
{
Str255 s1 , s2 ;
-
+
wxMacStringToPascal( s , s2 ) ;
-
+
for ( int i = 0 ; i < m_noItems ; ++ i )
{
- wxMacStringToPascal( m_stringArray[i] , s1 ) ;
+ wxMacStringToPascal( m_stringArray[i] , s1 ) ;
- if ( EqualString( s1 , s2 , false , false ) )
+ if ( EqualString( s1 , s2 , bCase , false ) )
return i ;
}
}
- return -1;
+
+ return wxNOT_FOUND;
}
void wxListBox::Clear()
MacClear() ;
}
-void wxListBox::SetSelection(int N, bool select)
+void wxListBox::DoSetSelection(int N, bool select)
{
wxCHECK_RET( N >= 0 && N < m_noItems,
wxT("invalid index in wxListBox::SetSelection") );
{
wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE,
wxT("invalid index in wxListBox::Selected") );
-
+
return MacIsSelected( N ) ;
}
{
wxCHECK_MSG( N >= 0 && N < m_noItems, NULL,
wxT("invalid index in wxListBox::GetClientData"));
-
+
return (void *)m_dataArray[N];
}
{
wxCHECK_RET( N >= 0 && N < m_noItems,
wxT("invalid index in wxListBox::SetClientData") );
-
+
#if wxUSE_OWNER_DRAWN
if ( m_windowStyle & wxLB_OWNERDRAW )
{
}
#endif // wxUSE_OWNER_DRAWN
wxASSERT_MSG( m_dataArray.GetCount() >= (size_t) N , wxT("invalid client_data array") ) ;
-
+
if ( m_dataArray.GetCount() > (size_t) N )
{
m_dataArray[N] = (char*) Client_data ;
// Find string for position
wxString wxListBox::GetString(int N) const
{
- return m_stringArray[N] ;
+ return m_stringArray[N] ;
}
void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
{
wxCHECK_RET( pos >= 0 && pos <= m_noItems,
wxT("invalid index in wxListBox::InsertItems") );
-
+
InvalidateBestSize();
int nItems = items.GetCount();
-
+
for ( int i = 0 ; i < nItems ; i++ )
{
m_stringArray.Insert( items[i] , pos + i ) ;
m_dataArray.Insert( NULL , pos + i ) ;
MacInsert( pos + i , items[i] ) ;
}
-
+
m_noItems += nItems;
}
int lbWidth = 100; // some defaults
int lbHeight = 110;
int wLine;
-
+
{
- wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ;
-
+ wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetRootWindow() ) ) ;
+
if ( m_font.Ok() )
{
::TextFont( m_font.GetMacFontNum() ) ;
::TextSize( 9 );
::TextFace( 0 ) ;
}
-
+
// Find the widest line
for(int i = 0; i < GetCount(); i++) {
wxString str(GetString(i));
#endif
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);
class wxListBoxItem : public wxOwnerDrawn
{
public:
- wxListBoxItem(const wxString& str = "");
+ wxListBoxItem(const wxString& str = wxEmptyString);
};
wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
::TextSize( 9 );
::TextFace( 0 ) ;
DrawText(text, 0 , text.Length());
-
+
}
*/
void wxListBox::MacDelete( int N )
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 ) ;
void wxListBox::OnSize( wxSizeEvent &event)
{
Point pt;
-
+
#if TARGET_CARBON
GetListCellSize((ListHandle)m_macList, &pt);
#else
{
Boolean wasDoubleClick = false ;
long result ;
-
+
::GetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlListBoxDoubleClickTag , sizeof( wasDoubleClick ) , (char*) &wasDoubleClick , &result ) ;
if ( !wasDoubleClick )
{
void wxListBox::MacSetRedraw( bool doDraw )
{
LSetDrawingMode( doDraw , (ListHandle)m_macList ) ;
-
}
void wxListBox::MacDoClick()
wxArrayInt aSelections;
int n ;
size_t count = GetSelections(aSelections);
-
+
if ( count == m_selectionPreImage.GetCount() )
{
bool hasChanged = false ;
return ;
}
}
-
+
m_selectionPreImage = aSelections;
-
+
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
event.SetEventObject( this );
-
+
if ( count > 0 )
{
n = aSelections[0];
{
n = -1;
}
-
+
event.SetInt(n);
-
+
GetEventHandler()->ProcessEvent(event);
}
wxWindow* parent = GetParent() ;
while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL )
parent = parent->GetParent() ;
-
+
if ( parent && parent->GetDefaultItem() )
{
wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
/* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
else if (event.GetKeyCode() == WXK_ESCAPE || (event.GetKeyCode() == '.' && event.MetaDown() ) )
{
- // FIXME: look in ancestors, not just parent.
+ // FIXME: look in ancestors, not just parent.
wxWindow* win = GetParent()->FindWindow( wxID_CANCEL ) ;
if (win)
{
- wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
- new_event.SetEventObject( win );
- win->GetEventHandler()->ProcessEvent( new_event );
- }
+ wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
+ new_event.SetEventObject( win );
+ win->GetEventHandler()->ProcessEvent( new_event );
+ }
}
else if ( event.GetKeyCode() == WXK_TAB )
{
{
// perform the default key handling first
wxControl::OnKeyDown( event ) ;
-
+
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
event.SetEventObject( this );
-
+
wxArrayInt aSelections;
int n, count = GetSelections(aSelections);
if ( count > 0 )
{
n = -1;
}
-
+
event.SetInt(n);
-
+
GetEventHandler()->ProcessEvent(event);
}
else
SetSelection(line) ;
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
event.SetEventObject( this );
-
+
if ( HasClientObjectData() )
event.SetClientObject( GetClientObject( line ) );
else if ( HasClientUntypedData() )
event.SetClientData( GetClientData(line) );
event.SetString( GetString(line) );
-
+
event.SetInt(line);
-
+
GetEventHandler()->ProcessEvent(event);
}
}
}
}
-