1 ///////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "listbox.h"
17 #include "wx/listbox.h"
18 #include "wx/button.h"
19 #include "wx/settings.h"
20 #include "wx/toplevel.h"
21 #include "wx/dynarray.h"
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
29 BEGIN_EVENT_TABLE(wxListBox
, wxControl
)
30 EVT_SIZE( wxListBox::OnSize
)
31 EVT_CHAR( wxListBox::OnChar
)
35 #include "wx/mac/uma.h"
37 #if PRAGMA_STRUCT_ALIGN
38 #pragma options align=mac68k
39 #elif PRAGMA_STRUCT_PACKPUSH
41 #elif PRAGMA_STRUCT_PACK
46 unsigned short instruction
;
48 } ldefRec
, *ldefPtr
, **ldefHandle
;
50 #if PRAGMA_STRUCT_ALIGN
51 #pragma options align=reset
52 #elif PRAGMA_STRUCT_PACKPUSH
54 #elif PRAGMA_STRUCT_PACK
59 const short kwxMacListItemHeight
= 19 ;
61 const short kwxMacListItemHeight
= 14 ;
66 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect
*drawRect
,
67 Cell cell
, short dataOffset
, short dataLength
,
68 ListHandle listHandle
) ;
71 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect
*drawRect
,
72 Cell cell
, short dataOffset
, short dataLength
,
73 ListHandle listHandle
)
77 RgnHandle savedClipRegion
;
81 SetPort((**listHandle
).port
);
82 grafPtr
= (**listHandle
).port
;
83 // typecast our refCon
84 list
= (wxListBox
*) GetControlReference( (ControlHandle
) GetListRefCon(listHandle
) );
86 // Calculate the cell rect.
97 const wxString text
= list
->m_stringArray
[cell
.v
] ;
99 // Save the current clip region, and set the clip region to the area we are about
102 savedClipRegion
= NewRgn();
103 GetClip( savedClipRegion
);
105 ClipRect( drawRect
);
106 EraseRect( drawRect
);
108 wxFontRefData
* font
= (wxFontRefData
*) list
->GetFont().GetRefData() ;
112 ::TextFont( font
->m_macFontNum
) ;
113 ::TextSize( short(font
->m_macFontSize
) ) ;
114 ::TextFace( font
->m_macFontStyle
) ;
118 ::TextFont( kFontIDMonaco
) ;
124 bool useDrawThemeText
= ( DrawThemeTextBox
!= (void*) kUnresolvedCFragSymbolAddress
) ;
126 if ( useDrawThemeText
)
128 Rect frame
= { drawRect
->top
, drawRect
->left
+ 4,
129 drawRect
->top
+ kwxMacListItemHeight
, drawRect
->right
+ 10000 } ;
130 CFStringRef sString
= CFStringCreateWithBytes( NULL
, (UInt8
*) text
.c_str(), text
.Length(), CFStringGetSystemEncoding(), false ) ;
131 CFMutableStringRef mString
= CFStringCreateMutableCopy( NULL
, 0 , sString
) ;
132 CFRelease( sString
) ;
133 ::TruncateThemeText( mString
, kThemeCurrentPortFont
, kThemeStateActive
, drawRect
->right
- drawRect
->left
, truncEnd
, NULL
) ;
134 ::DrawThemeTextBox( mString
,
135 kThemeCurrentPortFont
,
141 CFRelease( mString
) ;
146 MoveTo(drawRect
->left
+ 4 , drawRect
->top
+ 10 );
147 DrawText(text
, 0 , text
.Length());
150 // If the cell is hilited, do the hilite now. Paint the cell contents with the
151 // appropriate QuickDraw transform mode.
154 savedPenMode
= GetPortPenMode( (CGrafPtr
) grafPtr
);
155 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
156 PaintRect( drawRect
);
157 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
160 // Restore the saved clip region.
162 SetClip( savedClipRegion
);
163 DisposeRgn( savedClipRegion
);
168 // Hilite or unhilite the cell. Paint the cell contents with the
169 // appropriate QuickDraw transform mode.
172 savedPenMode
= GetPortPenMode( (CGrafPtr
)grafPtr
);
173 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
174 PaintRect( drawRect
);
175 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
183 extern "C" void MacDrawStringCell(Rect
*cellRect
, Cell lCell
, ListHandle theList
, long refCon
) ;
184 // resources ldef ids
185 const short kwxMacListWithVerticalScrollbar
= 128 ;
186 const short kwxMacListWithVerticalAndHorizontalScrollbar
= 129 ;
188 // ============================================================================
189 // list box control implementation
190 // ============================================================================
193 wxListBox::wxListBox()
200 static ListDefUPP macListDefUPP
= NULL
;
202 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
205 int n
, const wxString choices
[],
207 const wxValidator
& validator
,
208 const wxString
& name
)
210 m_noItems
= 0 ; // this will be increased by our append command
216 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
219 listDef
.defType
= kListDefUserProcType
;
220 if ( macListDefUPP
== NULL
)
222 macListDefUPP
= NewListDefUPP( wxMacListDefinition
);
224 listDef
.u
.userProc
= macListDefUPP
;
231 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
233 GetFontName( kFontIDMonaco
, fontName
) ;
237 CopyPascalStringToC( fontName
, (char*) fontName
) ;
238 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , fontName
) ) ;
243 CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, (style
& wxLB_HSCROLL
), true,
244 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
246 GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
247 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
249 SetControlReference( (ControlHandle
) m_macControl
, (long) this);
250 SetControlVisibility( (ControlHandle
) m_macControl
, false, false);
255 wxStAppResource resload
;
256 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false ,
257 (style
& wxLB_HSCROLL
) ? kwxMacListWithVerticalAndHorizontalScrollbar
: kwxMacListWithVerticalScrollbar
,
258 0 , 0, kControlListBoxProc
, (long) this ) ;
259 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
260 sizeof( ListHandle
) , (char*) &m_macList
, &result
) ;
262 HLock( (Handle
) m_macList
) ;
264 ldef
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ;
265 if ( (**(ListHandle
)m_macList
).listDefProc
!= NULL
)
267 (**ldef
).instruction
= 0x4EF9; /* JMP instruction */
268 (**ldef
).function
= (void(*)()) listDef
.u
.userProc
;
269 (**(ListHandle
)m_macList
).listDefProc
= (Handle
) ldef
;
272 Point pt
= (**(ListHandle
)m_macList
).cellSize
;
273 pt
.v
= kwxMacListItemHeight
;
274 LCellSize( pt
, (ListHandle
)m_macList
) ;
275 LAddColumn( 1 , 0 , (ListHandle
)m_macList
) ;
277 OptionBits options
= 0;
278 if ( style
& wxLB_MULTIPLE
)
280 options
+= lNoExtend
;
282 else if ( style
& wxLB_EXTENDED
)
284 options
+= lExtendDrag
;
288 options
= (OptionBits
) lOnlyOne
;
290 SetListSelectionFlags((ListHandle
)m_macList
, options
);
292 for ( int i
= 0 ; i
< n
; i
++ )
294 Append( choices
[i
] ) ;
297 MacPostControlCreate() ;
299 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
304 wxListBox::~wxListBox()
310 DisposeHandle( (**(ListHandle
)m_macList
).listDefProc
) ;
311 (**(ListHandle
)m_macList
).listDefProc
= NULL
;
317 void wxListBox::FreeData()
319 #if wxUSE_OWNER_DRAWN
320 if ( m_windowStyle
& wxLB_OWNERDRAW
)
322 size_t uiCount
= m_aItems
.Count();
323 while ( uiCount
-- != 0 ) {
324 delete m_aItems
[uiCount
];
325 m_aItems
[uiCount
] = NULL
;
331 #endif // wxUSE_OWNER_DRAWN
332 if ( HasClientObjectData() )
334 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
336 delete GetClientObject(n
);
341 void wxListBox::DoSetSize(int x
, int y
,
342 int width
, int height
,
345 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
348 GetControlBounds( (ControlHandle
) m_macControl
, &bounds
) ;
349 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
353 GetControlBounds( control
, &scrollbounds
) ;
354 if( scrollbounds
.right
!= bounds
.right
+ 1 )
356 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
362 void wxListBox::DoSetFirstItem(int N
)
367 void wxListBox::Delete(int N
)
369 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
370 wxT("invalid index in wxListBox::Delete") );
372 #if wxUSE_OWNER_DRAWN
374 m_aItems
.RemoveAt(N
);
375 #else // !wxUSE_OWNER_DRAWN
376 if ( HasClientObjectData() )
378 delete GetClientObject(N
);
380 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
381 m_stringArray
.RemoveAt( N
) ;
382 m_dataArray
.RemoveAt( N
) ;
388 int wxListBox::DoAppend(const wxString
& item
)
390 int index
= m_noItems
;
391 if( wxApp::s_macDefaultEncodingIsPC
)
393 m_stringArray
.Add( wxMacMakeMacStringFromPC( item
) ) ;
394 m_dataArray
.Add( NULL
);
397 m_stringArray
.Add( item
) ;
398 m_dataArray
.Add( NULL
);
401 DoSetItemClientData( index
, NULL
) ;
407 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
409 MacSetRedraw( false ) ;
411 int n
= choices
.GetCount();
413 for( int i
= 0 ; i
< n
; ++i
)
417 #if wxUSE_OWNER_DRAWN
418 wxASSERT_MSG(clientData
[i
] == NULL
,
419 wxT("Can't use client data with owner-drawn listboxes"));
420 #else // !wxUSE_OWNER_DRAWN
421 Append( choices
[i
] , clientData
[i
] ) ;
425 Append( choices
[i
] ) ;
428 #if wxUSE_OWNER_DRAWN
429 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
430 // first delete old items
431 size_t ui
= m_aItems
.Count();
432 while ( ui
-- != 0 ) {
438 // then create new ones
439 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
440 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
441 pNewItem
->SetName(choices
[ui
]);
442 m_aItems
.Add(pNewItem
);
445 #endif // wxUSE_OWNER_DRAWN
446 MacSetRedraw( true ) ;
449 bool wxListBox::HasMultipleSelection() const
451 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
454 int wxListBox::FindString(const wxString
& st
) const
457 if( wxApp::s_macDefaultEncodingIsPC
)
459 s
= wxMacMakeMacStringFromPC( st
) ;
464 if ( s
.Right(1) == "*" )
466 wxString search
= s
.Left( s
.Length() - 1 ) ;
467 int len
= search
.Length() ;
471 c2pstrcpy( (StringPtr
) s2
, search
.c_str() ) ;
473 strcpy( (char *) s2
, search
.c_str() ) ;
474 c2pstr( (char *) s2
) ;
477 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
480 c2pstrcpy( (StringPtr
) s1
, m_stringArray
[i
].Left( len
).c_str() ) ;
482 strcpy( (char *) s1
, m_stringArray
[i
].Left( len
).c_str() ) ;
483 c2pstr( (char *) s1
) ;
485 if ( EqualString( s1
, s2
, false , false ) )
488 if ( s
.Left(1) == "*" && s
.Length() > 1 )
492 for ( int i
= 0 ; i
< m_noItems
; ++i
)
494 if ( GetString(i
).Lower().Matches(s
) )
505 c2pstrcpy( (StringPtr
) s2
, s
.c_str() ) ;
507 strcpy( (char *) s2
, s
.c_str() ) ;
508 c2pstr( (char *) s2
) ;
511 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
514 c2pstrcpy( (StringPtr
) s1
, m_stringArray
[i
].c_str() ) ;
516 strcpy( (char *) s1
, m_stringArray
[i
].c_str() ) ;
517 c2pstr( (char *) s1
) ;
519 if ( EqualString( s1
, s2
, false , false ) )
526 void wxListBox::Clear()
530 m_stringArray
.Empty() ;
531 m_dataArray
.Empty() ;
535 void wxListBox::SetSelection(int N
, bool select
)
537 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
538 "invalid index in wxListBox::SetSelection" );
539 MacSetSelection( N
, select
) ;
540 GetSelections( m_selectionPreImage
) ;
543 bool wxListBox::IsSelected(int N
) const
545 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
546 "invalid index in wxListBox::Selected" );
548 return MacIsSelected( N
) ;
551 void *wxListBox::DoGetItemClientData(int N
) const
553 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
554 wxT("invalid index in wxListBox::GetClientData"));
556 return (void *)m_dataArray
[N
];
559 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
561 return (wxClientData
*) DoGetItemClientData( N
) ;
564 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
566 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
567 "invalid index in wxListBox::SetClientData" );
569 #if wxUSE_OWNER_DRAWN
570 if ( m_windowStyle
& wxLB_OWNERDRAW
)
572 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
573 // in OnMeasure/OnDraw.
574 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
576 #endif // wxUSE_OWNER_DRAWN
577 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, "invalid client_data array" ) ;
579 if ( m_dataArray
.GetCount() > (size_t) N
)
581 m_dataArray
[N
] = (char*) Client_data
;
585 m_dataArray
.Add( (char*) Client_data
) ;
589 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
591 DoSetItemClientData(n
, clientData
);
594 // Return number of selections and an array of selected integers
595 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
597 return MacGetSelections( aSelections
) ;
600 // Get single selection, for single choice list items
601 int wxListBox::GetSelection() const
603 return MacGetSelection() ;
606 // Find string for position
607 wxString
wxListBox::GetString(int N
) const
609 if( wxApp::s_macDefaultEncodingIsPC
)
611 return wxMacMakePCStringFromMac( m_stringArray
[N
] ) ;
614 return m_stringArray
[N
] ;
617 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
619 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
620 wxT("invalid index in wxListBox::InsertItems") );
622 int nItems
= items
.GetCount();
624 for ( int i
= 0 ; i
< nItems
; i
++ )
626 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
627 m_dataArray
.Insert( NULL
, pos
+ i
) ;
628 MacInsert( pos
+ i
, items
[i
] ) ;
634 void wxListBox::SetString(int N
, const wxString
& s
)
637 if( wxApp::s_macDefaultEncodingIsPC
)
639 str
= wxMacMakeMacStringFromPC( s
) ;
643 m_stringArray
[N
] = str
;
647 wxSize
wxListBox::DoGetBestSize() const
649 int lbWidth
= 100; // some defaults
654 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
656 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
660 ::TextFont( font
->m_macFontNum
) ;
661 ::TextSize( short(font
->m_macFontSize
) ) ;
662 ::TextFace( font
->m_macFontStyle
) ;
666 ::TextFont( kFontIDMonaco
) ;
671 // Find the widest line
672 for(int i
= 0; i
< GetCount(); i
++) {
673 wxString
str(GetString(i
));
674 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
675 lbWidth
= wxMax(lbWidth
, wLine
);
678 // Add room for the scrollbar
679 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
681 // And just a bit more
683 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
686 // don't make the listbox too tall (limit height to around 10 items) but don't
687 // make it too small neither
688 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
690 return wxSize(lbWidth
, lbHeight
);
693 int wxListBox::GetCount() const
698 void wxListBox::SetupColours()
700 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
701 SetForegroundColour(GetParent()->GetForegroundColour());
704 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
706 wxControl::Refresh( eraseBack
, rect
) ;
707 // MacRedrawControl() ;
710 #if wxUSE_OWNER_DRAWN
712 class wxListBoxItem
: public wxOwnerDrawn
715 wxListBoxItem(const wxString
& str
= "");
718 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
720 // no bitmaps/checkmarks
724 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
726 return new wxListBoxItem();
729 #endif //USE_OWNER_DRAWN
731 // ============================================================================
732 // list box control implementation
733 // ============================================================================
736 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
739 // typecast our refCon
740 list = (wxListBox*)refCon;
742 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
743 const wxString text = list->m_stringArray[lCell.v] ;
744 ::TextFont( kFontIDMonaco ) ;
747 DrawText(text, 0 , text.Length());
751 void wxListBox::MacDelete( int N
)
753 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
757 void wxListBox::MacInsert( int n
, const char * text
)
759 Cell cell
= { 0 , 0 } ;
761 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
762 // LSetCell(text, strlen(text), cell, m_macList);
766 void wxListBox::MacAppend( const char * text
)
768 Cell cell
= { 0 , 0 } ;
769 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
770 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
771 // LSetCell(text, strlen(text), cell, m_macList);
775 void wxListBox::MacClear()
777 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
781 void wxListBox::MacSetSelection( int n
, bool select
)
783 Cell cell
= { 0 , 0 } ;
784 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
786 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
788 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
793 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
794 LAutoScroll( (ListHandle
)m_macList
) ;
798 bool wxListBox::MacIsSelected( int n
) const
800 Cell cell
= { 0 , 0 } ;
802 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
805 void wxListBox::MacDestroy()
807 // DisposeExtLDEFInfo( m_macList ) ;
810 int wxListBox::MacGetSelection() const
812 Cell cell
= { 0 , 0 } ;
813 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
819 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
825 Cell cell
= { 0 , 0 } ;
828 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
830 aSelections
.Add( cell
.v
) ;
837 void wxListBox::MacSet( int n
, const char * text
)
839 // our implementation does not store anything in the list
840 // so we just have to redraw
841 Cell cell
= { 0 , 0 } ;
843 // LSetCell(text, strlen(text), cell, m_macList);
847 void wxListBox::MacScrollTo( int n
)
849 // TODO implement scrolling
852 void wxListBox::OnSize( const wxSizeEvent
&event
)
857 GetListCellSize((ListHandle
)m_macList
, &pt
);
859 pt
= (**(ListHandle
)m_macList
).cellSize
;
861 pt
.h
= m_width
- 15 ;
862 LCellSize( pt
, (ListHandle
)m_macList
) ;
865 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
)
867 Boolean wasDoubleClick
= false ;
870 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
871 if ( !wasDoubleClick
)
881 void wxListBox::MacSetRedraw( bool doDraw
)
883 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
887 void wxListBox::MacDoClick()
889 wxArrayInt aSelections
;
891 size_t count
= GetSelections(aSelections
);
893 if ( count
== m_selectionPreImage
.GetCount() )
895 bool hasChanged
= false ;
896 for ( size_t i
= 0 ; i
< count
; ++i
)
898 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
910 m_selectionPreImage
= aSelections
;
912 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
913 event
.SetEventObject( this );
918 if ( HasClientObjectData() )
919 event
.SetClientObject( GetClientObject(n
) );
920 else if ( HasClientUntypedData() )
921 event
.SetClientData( GetClientData(n
) );
922 event
.SetString( GetString(n
) );
929 event
.m_commandInt
= n
;
931 GetEventHandler()->ProcessEvent(event
);
934 void wxListBox::MacDoDoubleClick()
936 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
937 event
.SetEventObject( this );
938 GetEventHandler()->ProcessEvent(event
) ;
941 void wxListBox::OnChar(wxKeyEvent
& event
)
943 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
945 wxWindow
* parent
= GetParent() ;
946 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
947 parent
= parent
->GetParent() ;
949 if ( parent
&& parent
->GetDefaultItem() )
951 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
953 if ( def
&& def
->IsEnabled() )
955 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
956 event
.SetEventObject(def
);
963 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
964 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
966 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
967 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
968 new_event
.SetEventObject( win
);
969 win
->GetEventHandler()->ProcessEvent( new_event
);
971 else if ( event
.GetKeyCode() == WXK_TAB
)
973 wxNavigationKeyEvent new_event
;
974 new_event
.SetEventObject( this );
975 new_event
.SetDirection( !event
.ShiftDown() );
976 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
977 new_event
.SetWindowChange( event
.ControlDown() );
978 new_event
.SetCurrentFocus( this );
979 if ( !GetEventHandler()->ProcessEvent( new_event
) )
982 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
984 // perform the default key handling first
985 wxControl::OnKeyDown( event
) ;
987 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
988 event
.SetEventObject( this );
990 wxArrayInt aSelections
;
991 int n
, count
= GetSelections(aSelections
);
995 if ( HasClientObjectData() )
996 event
.SetClientObject( GetClientObject(n
) );
997 else if ( HasClientUntypedData() )
998 event
.SetClientData( GetClientData(n
) );
999 event
.SetString( GetString(n
) );
1006 event
.m_commandInt
= n
;
1008 GetEventHandler()->ProcessEvent(event
);
1012 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
1016 m_lastTypeIn
= event
.GetTimestamp() ;
1017 m_typeIn
+= (char) event
.GetKeyCode() ;
1018 int line
= FindString("*"+m_typeIn
+"*") ;
1021 if ( GetSelection() != line
)
1023 SetSelection(line
) ;
1024 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1025 event
.SetEventObject( this );
1027 if ( HasClientObjectData() )
1028 event
.SetClientObject( GetClientObject( line
) );
1029 else if ( HasClientUntypedData() )
1030 event
.SetClientData( GetClientData(line
) );
1031 event
.SetString( GetString(line
) );
1033 event
.m_commandInt
= line
;
1035 GetEventHandler()->ProcessEvent(event
);