1 ///////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
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 const short kwxMacListWithVerticalScrollbar
= 128 ;
186 // ============================================================================
187 // list box control implementation
188 // ============================================================================
191 wxListBox::wxListBox()
198 static ListDefUPP macListDefUPP
= NULL
;
200 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
203 int n
, const wxString choices
[],
205 const wxValidator
& validator
,
206 const wxString
& name
)
208 m_noItems
= 0 ; // this will be increased by our append command
214 MacPreControlCreate( parent
, id
, "" , pos
, size
,style
, validator
, name
, &bounds
, title
) ;
217 listDef
.defType
= kListDefUserProcType
;
218 if ( macListDefUPP
== NULL
)
220 macListDefUPP
= NewListDefUPP( wxMacListDefinition
);
222 listDef
.u
.userProc
= macListDefUPP
;
229 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
231 GetFontName( kFontIDMonaco
, fontName
) ;
235 CopyPascalStringToC( fontName
, (char*) fontName
) ;
236 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , fontName
) ) ;
241 CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, false, true,
242 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
244 GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
245 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
247 SetControlReference( (ControlHandle
) m_macControl
, (long) this);
248 SetControlVisibility( (ControlHandle
) m_macControl
, false, false);
253 wxStAppResource resload
;
254 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false ,
255 kwxMacListWithVerticalScrollbar
, 0 , 0,
256 kControlListBoxProc
, (long) this ) ;
257 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
258 sizeof( ListHandle
) , (char*) &m_macList
, &result
) ;
260 HLock( (Handle
) m_macList
) ;
262 ldef
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ;
263 if ( (**(ListHandle
)m_macList
).listDefProc
!= NULL
)
265 (**ldef
).instruction
= 0x4EF9; /* JMP instruction */
266 (**ldef
).function
= (void(*)()) listDef
.u
.userProc
;
267 (**(ListHandle
)m_macList
).listDefProc
= (Handle
) ldef
;
270 Point pt
= (**(ListHandle
)m_macList
).cellSize
;
271 pt
.v
= kwxMacListItemHeight
;
272 LCellSize( pt
, (ListHandle
)m_macList
) ;
273 LAddColumn( 1 , 0 , (ListHandle
)m_macList
) ;
275 OptionBits options
= 0;
276 if ( style
& wxLB_MULTIPLE
)
278 options
+= lNoExtend
;
280 else if ( style
& wxLB_EXTENDED
)
282 options
+= lExtendDrag
;
286 options
= (OptionBits
) lOnlyOne
;
288 SetListSelectionFlags((ListHandle
)m_macList
, options
);
290 for ( int i
= 0 ; i
< n
; i
++ )
292 Append( choices
[i
] ) ;
295 MacPostControlCreate() ;
297 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
302 wxListBox::~wxListBox()
308 DisposeHandle( (**(ListHandle
)m_macList
).listDefProc
) ;
309 (**(ListHandle
)m_macList
).listDefProc
= NULL
;
315 void wxListBox::FreeData()
317 #if wxUSE_OWNER_DRAWN
318 if ( m_windowStyle
& wxLB_OWNERDRAW
)
320 size_t uiCount
= m_aItems
.Count();
321 while ( uiCount
-- != 0 ) {
322 delete m_aItems
[uiCount
];
323 m_aItems
[uiCount
] = NULL
;
329 #endif // wxUSE_OWNER_DRAWN
330 if ( HasClientObjectData() )
332 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
334 delete GetClientObject(n
);
339 void wxListBox::DoSetSize(int x
, int y
,
340 int width
, int height
,
343 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
346 GetControlBounds( (ControlHandle
) m_macControl
, &bounds
) ;
347 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
351 GetControlBounds( control
, &scrollbounds
) ;
352 if( scrollbounds
.right
!= bounds
.right
+ 1 )
354 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
360 void wxListBox::DoSetFirstItem(int N
)
365 void wxListBox::Delete(int N
)
367 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
368 wxT("invalid index in wxListBox::Delete") );
370 #if wxUSE_OWNER_DRAWN
372 m_aItems
.RemoveAt(N
);
373 #else // !wxUSE_OWNER_DRAWN
374 if ( HasClientObjectData() )
376 delete GetClientObject(N
);
378 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
379 m_stringArray
.RemoveAt( N
) ;
380 m_dataArray
.RemoveAt( N
) ;
386 int wxListBox::DoAppend(const wxString
& item
)
388 int index
= m_noItems
;
389 if( wxApp::s_macDefaultEncodingIsPC
)
391 m_stringArray
.Add( wxMacMakeMacStringFromPC( item
) ) ;
392 m_dataArray
.Add( NULL
);
395 m_stringArray
.Add( item
) ;
396 m_dataArray
.Add( NULL
);
399 DoSetItemClientData( index
, NULL
) ;
405 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
407 MacSetRedraw( false ) ;
409 int n
= choices
.GetCount();
411 for( int i
= 0 ; i
< n
; ++i
)
415 #if wxUSE_OWNER_DRAWN
416 wxASSERT_MSG(clientData
[i
] == NULL
,
417 wxT("Can't use client data with owner-drawn listboxes"));
418 #else // !wxUSE_OWNER_DRAWN
419 Append( choices
[i
] , clientData
[i
] ) ;
423 Append( choices
[i
] ) ;
426 #if wxUSE_OWNER_DRAWN
427 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
428 // first delete old items
429 size_t ui
= m_aItems
.Count();
430 while ( ui
-- != 0 ) {
436 // then create new ones
437 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
438 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
439 pNewItem
->SetName(choices
[ui
]);
440 m_aItems
.Add(pNewItem
);
443 #endif // wxUSE_OWNER_DRAWN
444 MacSetRedraw( true ) ;
447 bool wxListBox::HasMultipleSelection() const
449 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
452 int wxListBox::FindString(const wxString
& st
) const
455 if( wxApp::s_macDefaultEncodingIsPC
)
457 s
= wxMacMakeMacStringFromPC( st
) ;
462 if ( s
.Right(1) == "*" )
464 wxString search
= s
.Left( s
.Length() - 1 ) ;
465 int len
= search
.Length() ;
469 c2pstrcpy( (StringPtr
) s2
, search
.c_str() ) ;
471 strcpy( (char *) s2
, search
.c_str() ) ;
472 c2pstr( (char *) s2
) ;
475 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
478 c2pstrcpy( (StringPtr
) s1
, m_stringArray
[i
].Left( len
).c_str() ) ;
480 strcpy( (char *) s1
, m_stringArray
[i
].Left( len
).c_str() ) ;
481 c2pstr( (char *) s1
) ;
483 if ( EqualString( s1
, s2
, false , false ) )
486 if ( s
.Left(1) == "*" && s
.Length() > 1 )
490 for ( int i
= 0 ; i
< m_noItems
; ++i
)
492 if ( GetString(i
).Lower().Matches(s
) )
503 c2pstrcpy( (StringPtr
) s2
, s
.c_str() ) ;
505 strcpy( (char *) s2
, s
.c_str() ) ;
506 c2pstr( (char *) s2
) ;
509 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
512 c2pstrcpy( (StringPtr
) s1
, m_stringArray
[i
].c_str() ) ;
514 strcpy( (char *) s1
, m_stringArray
[i
].c_str() ) ;
515 c2pstr( (char *) s1
) ;
517 if ( EqualString( s1
, s2
, false , false ) )
524 void wxListBox::Clear()
528 m_stringArray
.Empty() ;
529 m_dataArray
.Empty() ;
533 void wxListBox::SetSelection(int N
, bool select
)
535 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
536 "invalid index in wxListBox::SetSelection" );
537 MacSetSelection( N
, select
) ;
538 GetSelections( m_selectionPreImage
) ;
541 bool wxListBox::IsSelected(int N
) const
543 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
544 "invalid index in wxListBox::Selected" );
546 return MacIsSelected( N
) ;
549 void *wxListBox::DoGetItemClientData(int N
) const
551 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
552 wxT("invalid index in wxListBox::GetClientData"));
554 return (void *)m_dataArray
[N
];
557 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
559 return (wxClientData
*) DoGetItemClientData( N
) ;
562 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
564 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
565 "invalid index in wxListBox::SetClientData" );
567 #if wxUSE_OWNER_DRAWN
568 if ( m_windowStyle
& wxLB_OWNERDRAW
)
570 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
571 // in OnMeasure/OnDraw.
572 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
574 #endif // wxUSE_OWNER_DRAWN
575 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, "invalid client_data array" ) ;
577 if ( m_dataArray
.GetCount() > (size_t) N
)
579 m_dataArray
[N
] = (char*) Client_data
;
583 m_dataArray
.Add( (char*) Client_data
) ;
587 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
589 DoSetItemClientData(n
, clientData
);
592 // Return number of selections and an array of selected integers
593 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
595 return MacGetSelections( aSelections
) ;
598 // Get single selection, for single choice list items
599 int wxListBox::GetSelection() const
601 return MacGetSelection() ;
604 // Find string for position
605 wxString
wxListBox::GetString(int N
) const
607 if( wxApp::s_macDefaultEncodingIsPC
)
609 return wxMacMakePCStringFromMac( m_stringArray
[N
] ) ;
612 return m_stringArray
[N
] ;
615 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
617 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
618 wxT("invalid index in wxListBox::InsertItems") );
620 int nItems
= items
.GetCount();
622 for ( int i
= 0 ; i
< nItems
; i
++ )
624 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
625 m_dataArray
.Insert( NULL
, pos
+ i
) ;
626 MacInsert( pos
+ i
, items
[i
] ) ;
632 void wxListBox::SetString(int N
, const wxString
& s
)
635 if( wxApp::s_macDefaultEncodingIsPC
)
637 str
= wxMacMakeMacStringFromPC( s
) ;
641 m_stringArray
[N
] = str
;
645 wxSize
wxListBox::DoGetBestSize() const
647 int lbWidth
= 100; // some defaults
652 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
655 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
659 ::TextFont( font
->m_macFontNum
) ;
660 ::TextSize( short(font
->m_macFontSize
) ) ;
661 ::TextFace( font
->m_macFontStyle
) ;
665 ::TextFont( kFontIDMonaco
) ;
670 // Find the widest line
671 for(int i
= 0; i
< GetCount(); i
++) {
672 wxString
str(GetString(i
));
673 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
674 lbWidth
= wxMax(lbWidth
, wLine
);
677 // Add room for the scrollbar
678 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
680 // And just a bit more
682 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
685 // don't make the listbox too tall (limit height to around 10 items) but don't
686 // make it too small neither
687 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
689 return wxSize(lbWidth
, lbHeight
);
692 int wxListBox::GetCount() const
697 void wxListBox::SetupColours()
699 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
700 SetForegroundColour(GetParent()->GetForegroundColour());
703 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
705 wxControl::Refresh( eraseBack
, rect
) ;
706 // MacRedrawControl() ;
709 #if wxUSE_OWNER_DRAWN
711 class wxListBoxItem
: public wxOwnerDrawn
714 wxListBoxItem(const wxString
& str
= "");
717 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
719 // no bitmaps/checkmarks
723 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
725 return new wxListBoxItem();
728 #endif //USE_OWNER_DRAWN
730 // ============================================================================
731 // list box control implementation
732 // ============================================================================
735 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
738 // typecast our refCon
739 list = (wxListBox*)refCon;
741 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
742 const wxString text = list->m_stringArray[lCell.v] ;
743 ::TextFont( kFontIDMonaco ) ;
746 DrawText(text, 0 , text.Length());
750 void wxListBox::MacDelete( int N
)
752 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
756 void wxListBox::MacInsert( int n
, const char * text
)
758 Cell cell
= { 0 , 0 } ;
760 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
761 // LSetCell(text, strlen(text), cell, m_macList);
765 void wxListBox::MacAppend( const char * text
)
767 Cell cell
= { 0 , 0 } ;
768 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
769 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
770 // LSetCell(text, strlen(text), cell, m_macList);
774 void wxListBox::MacClear()
776 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
780 void wxListBox::MacSetSelection( int n
, bool select
)
782 Cell cell
= { 0 , 0 } ;
783 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
785 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
787 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
792 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
793 LAutoScroll( (ListHandle
)m_macList
) ;
797 bool wxListBox::MacIsSelected( int n
) const
799 Cell cell
= { 0 , 0 } ;
801 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
804 void wxListBox::MacDestroy()
806 // DisposeExtLDEFInfo( m_macList ) ;
809 int wxListBox::MacGetSelection() const
811 Cell cell
= { 0 , 0 } ;
812 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
818 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
824 Cell cell
= { 0 , 0 } ;
827 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
829 aSelections
.Add( cell
.v
) ;
836 void wxListBox::MacSet( int n
, const char * text
)
838 // our implementation does not store anything in the list
839 // so we just have to redraw
840 Cell cell
= { 0 , 0 } ;
842 // LSetCell(text, strlen(text), cell, m_macList);
846 void wxListBox::MacScrollTo( int n
)
848 // TODO implement scrolling
851 void wxListBox::OnSize( const wxSizeEvent
&event
)
856 GetListCellSize((ListHandle
)m_macList
, &pt
);
858 pt
= (**(ListHandle
)m_macList
).cellSize
;
860 pt
.h
= m_width
- 15 ;
861 LCellSize( pt
, (ListHandle
)m_macList
) ;
864 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
)
866 Boolean wasDoubleClick
= false ;
869 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
870 if ( !wasDoubleClick
)
880 void wxListBox::MacSetRedraw( bool doDraw
)
882 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
886 void wxListBox::MacDoClick()
888 wxArrayInt aSelections
;
890 size_t count
= GetSelections(aSelections
);
892 if ( count
== m_selectionPreImage
.GetCount() )
894 bool hasChanged
= false ;
895 for ( size_t i
= 0 ; i
< count
; ++i
)
897 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
909 m_selectionPreImage
= aSelections
;
911 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
912 event
.SetEventObject( this );
917 if ( HasClientObjectData() )
918 event
.SetClientObject( GetClientObject(n
) );
919 else if ( HasClientUntypedData() )
920 event
.SetClientData( GetClientData(n
) );
921 event
.SetString( GetString(n
) );
928 event
.m_commandInt
= n
;
930 GetEventHandler()->ProcessEvent(event
);
933 void wxListBox::MacDoDoubleClick()
935 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
936 event
.SetEventObject( this );
937 GetEventHandler()->ProcessEvent(event
) ;
940 void wxListBox::OnChar(wxKeyEvent
& event
)
942 if ( event
.KeyCode() == WXK_RETURN
|| event
.KeyCode() == WXK_NUMPAD_ENTER
)
944 wxWindow
* parent
= GetParent() ;
945 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
946 parent
= parent
->GetParent() ;
948 if ( parent
&& parent
->GetDefaultItem() )
950 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
952 if ( def
&& def
->IsEnabled() )
954 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
955 event
.SetEventObject(def
);
962 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
963 else if (event
.KeyCode() == WXK_ESCAPE
|| (event
.KeyCode() == '.' && event
.MetaDown() ) )
965 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
966 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
967 new_event
.SetEventObject( win
);
968 win
->GetEventHandler()->ProcessEvent( new_event
);
970 else if ( event
.KeyCode() == WXK_TAB
)
972 wxNavigationKeyEvent new_event
;
973 new_event
.SetEventObject( this );
974 new_event
.SetDirection( !event
.ShiftDown() );
975 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
976 new_event
.SetWindowChange( event
.ControlDown() );
977 new_event
.SetCurrentFocus( this );
978 if ( !GetEventHandler()->ProcessEvent( new_event
) )
981 else if ( event
.KeyCode() == WXK_DOWN
|| event
.KeyCode() == WXK_UP
)
983 // perform the default key handling first
984 wxControl::OnKeyDown( event
) ;
986 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
987 event
.SetEventObject( this );
989 wxArrayInt aSelections
;
990 int n
, count
= GetSelections(aSelections
);
994 if ( HasClientObjectData() )
995 event
.SetClientObject( GetClientObject(n
) );
996 else if ( HasClientUntypedData() )
997 event
.SetClientData( GetClientData(n
) );
998 event
.SetString( GetString(n
) );
1005 event
.m_commandInt
= n
;
1007 GetEventHandler()->ProcessEvent(event
);
1011 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
1015 m_lastTypeIn
= event
.GetTimestamp() ;
1016 m_typeIn
+= (char) event
.KeyCode() ;
1017 int line
= FindString("*"+m_typeIn
+"*") ;
1020 if ( GetSelection() != line
)
1022 SetSelection(line
) ;
1023 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1024 event
.SetEventObject( this );
1026 if ( HasClientObjectData() )
1027 event
.SetClientObject( GetClientObject( line
) );
1028 else if ( HasClientUntypedData() )
1029 event
.SetClientData( GetClientData(line
) );
1030 event
.SetString( GetString(line
) );
1032 event
.m_commandInt
= line
;
1034 GetEventHandler()->ProcessEvent(event
);