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
;
228 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
230 GetFontName( kFontIDMonaco
, fontName
) ;
234 CopyPascalStringToC( fontName
, (char*) fontName
) ;
235 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , fontName
) ) ;
240 CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, false, true,
241 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
243 GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
244 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
246 SetControlReference( (ControlHandle
) m_macControl
, (long) this);
247 SetControlVisibility( (ControlHandle
) m_macControl
, false, false);
252 wxStAppResource resload
;
253 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false ,
254 kwxMacListWithVerticalScrollbar
, 0 , 0,
255 kControlListBoxProc
, (long) this ) ;
256 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
257 sizeof( ListHandle
) , (char*) &m_macList
, &result
) ;
259 HLock( (Handle
) m_macList
) ;
261 ldef
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ;
262 if ( (**(ListHandle
)m_macList
).listDefProc
!= NULL
)
264 (**ldef
).instruction
= 0x4EF9; /* JMP instruction */
265 (**ldef
).function
= (void(*)()) listDef
.u
.userProc
;
266 (**(ListHandle
)m_macList
).listDefProc
= (Handle
) ldef
;
269 Point pt
= (**(ListHandle
)m_macList
).cellSize
;
270 pt
.v
= kwxMacListItemHeight
;
271 LCellSize( pt
, (ListHandle
)m_macList
) ;
272 LAddColumn( 1 , 0 , (ListHandle
)m_macList
) ;
274 OptionBits options
= 0;
275 if ( style
& wxLB_MULTIPLE
)
277 options
+= lNoExtend
;
279 else if ( style
& wxLB_EXTENDED
)
281 options
+= lExtendDrag
;
285 options
= (OptionBits
) lOnlyOne
;
287 SetListSelectionFlags((ListHandle
)m_macList
, options
);
289 for ( int i
= 0 ; i
< n
; i
++ )
291 Append( choices
[i
] ) ;
294 MacPostControlCreate() ;
296 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
301 wxListBox::~wxListBox()
307 DisposeHandle( (**(ListHandle
)m_macList
).listDefProc
) ;
308 (**(ListHandle
)m_macList
).listDefProc
= NULL
;
314 void wxListBox::FreeData()
316 #if wxUSE_OWNER_DRAWN
317 if ( m_windowStyle
& wxLB_OWNERDRAW
)
319 size_t uiCount
= m_aItems
.Count();
320 while ( uiCount
-- != 0 ) {
321 delete m_aItems
[uiCount
];
322 m_aItems
[uiCount
] = NULL
;
328 #endif // wxUSE_OWNER_DRAWN
329 if ( HasClientObjectData() )
331 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
333 delete GetClientObject(n
);
338 void wxListBox::DoSetSize(int x
, int y
,
339 int width
, int height
,
342 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
345 GetControlBounds( (ControlHandle
) m_macControl
, &bounds
) ;
346 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
350 GetControlBounds( control
, &scrollbounds
) ;
351 if( scrollbounds
.right
!= bounds
.right
+ 1 )
353 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
359 void wxListBox::DoSetFirstItem(int N
)
364 void wxListBox::Delete(int N
)
366 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
367 wxT("invalid index in wxListBox::Delete") );
369 #if wxUSE_OWNER_DRAWN
371 m_aItems
.RemoveAt(N
);
372 #else // !wxUSE_OWNER_DRAWN
373 if ( HasClientObjectData() )
375 delete GetClientObject(N
);
377 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
378 m_stringArray
.RemoveAt( N
) ;
379 m_dataArray
.RemoveAt( N
) ;
385 int wxListBox::DoAppend(const wxString
& item
)
387 int index
= m_noItems
;
388 if( wxApp::s_macDefaultEncodingIsPC
)
390 m_stringArray
.Add( wxMacMakeMacStringFromPC( item
) ) ;
391 m_dataArray
.Add( NULL
);
394 m_stringArray
.Add( item
) ;
395 m_dataArray
.Add( NULL
);
398 DoSetItemClientData( index
, NULL
) ;
404 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
406 MacSetRedraw( false ) ;
408 int n
= choices
.GetCount();
410 for( int i
= 0 ; i
< n
; ++i
)
414 #if wxUSE_OWNER_DRAWN
415 wxASSERT_MSG(clientData
[i
] == NULL
,
416 wxT("Can't use client data with owner-drawn listboxes"));
417 #else // !wxUSE_OWNER_DRAWN
418 Append( choices
[i
] , clientData
[i
] ) ;
422 Append( choices
[i
] ) ;
425 #if wxUSE_OWNER_DRAWN
426 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
427 // first delete old items
428 size_t ui
= m_aItems
.Count();
429 while ( ui
-- != 0 ) {
435 // then create new ones
436 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
437 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
438 pNewItem
->SetName(choices
[ui
]);
439 m_aItems
.Add(pNewItem
);
442 #endif // wxUSE_OWNER_DRAWN
443 MacSetRedraw( true ) ;
446 bool wxListBox::HasMultipleSelection() const
448 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
451 int wxListBox::FindString(const wxString
& st
) const
454 if( wxApp::s_macDefaultEncodingIsPC
)
456 s
= wxMacMakeMacStringFromPC( st
) ;
461 if ( s
.Right(1) == "*" )
463 wxString search
= s
.Left( s
.Length() - 1 ) ;
464 int len
= search
.Length() ;
468 c2pstrcpy( (StringPtr
) s2
, search
.c_str() ) ;
470 strcpy( (char *) s2
, search
.c_str() ) ;
471 c2pstr( (char *) s2
) ;
474 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
477 c2pstrcpy( (StringPtr
) s1
, m_stringArray
[i
].Left( len
).c_str() ) ;
479 strcpy( (char *) s1
, m_stringArray
[i
].Left( len
).c_str() ) ;
480 c2pstr( (char *) s1
) ;
482 if ( EqualString( s1
, s2
, false , false ) )
485 if ( s
.Left(1) == "*" && s
.Length() > 1 )
489 for ( int i
= 0 ; i
< m_noItems
; ++i
)
491 if ( GetString(i
).Lower().Matches(s
) )
502 c2pstrcpy( (StringPtr
) s2
, s
.c_str() ) ;
504 strcpy( (char *) s2
, s
.c_str() ) ;
505 c2pstr( (char *) s2
) ;
508 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
511 c2pstrcpy( (StringPtr
) s1
, m_stringArray
[i
].c_str() ) ;
513 strcpy( (char *) s1
, m_stringArray
[i
].c_str() ) ;
514 c2pstr( (char *) s1
) ;
516 if ( EqualString( s1
, s2
, false , false ) )
523 void wxListBox::Clear()
527 m_stringArray
.Empty() ;
528 m_dataArray
.Empty() ;
532 void wxListBox::SetSelection(int N
, bool select
)
534 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
535 "invalid index in wxListBox::SetSelection" );
536 MacSetSelection( N
, select
) ;
537 GetSelections( m_selectionPreImage
) ;
540 bool wxListBox::IsSelected(int N
) const
542 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
543 "invalid index in wxListBox::Selected" );
545 return MacIsSelected( N
) ;
548 void *wxListBox::DoGetItemClientData(int N
) const
550 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
551 wxT("invalid index in wxListBox::GetClientData"));
553 return (void *)m_dataArray
[N
];
556 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
558 return (wxClientData
*) DoGetItemClientData( N
) ;
561 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
563 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
564 "invalid index in wxListBox::SetClientData" );
566 #if wxUSE_OWNER_DRAWN
567 if ( m_windowStyle
& wxLB_OWNERDRAW
)
569 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
570 // in OnMeasure/OnDraw.
571 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
573 #endif // wxUSE_OWNER_DRAWN
574 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, "invalid client_data array" ) ;
576 if ( m_dataArray
.GetCount() > (size_t) N
)
578 m_dataArray
[N
] = (char*) Client_data
;
582 m_dataArray
.Add( (char*) Client_data
) ;
586 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
588 DoSetItemClientData(n
, clientData
);
591 // Return number of selections and an array of selected integers
592 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
594 return MacGetSelections( aSelections
) ;
597 // Get single selection, for single choice list items
598 int wxListBox::GetSelection() const
600 return MacGetSelection() ;
603 // Find string for position
604 wxString
wxListBox::GetString(int N
) const
606 if( wxApp::s_macDefaultEncodingIsPC
)
608 return wxMacMakePCStringFromMac( m_stringArray
[N
] ) ;
611 return m_stringArray
[N
] ;
614 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
616 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
617 wxT("invalid index in wxListBox::InsertItems") );
619 int nItems
= items
.GetCount();
621 for ( int i
= 0 ; i
< nItems
; i
++ )
623 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
624 m_dataArray
.Insert( NULL
, pos
+ i
) ;
625 MacInsert( pos
+ i
, items
[i
] ) ;
631 void wxListBox::SetString(int N
, const wxString
& s
)
634 if( wxApp::s_macDefaultEncodingIsPC
)
636 str
= wxMacMakeMacStringFromPC( s
) ;
640 m_stringArray
[N
] = str
;
644 wxSize
wxListBox::DoGetBestSize() const
646 int lbWidth
= 100; // some defaults
651 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
653 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
657 ::TextFont( font
->m_macFontNum
) ;
658 ::TextSize( short(font
->m_macFontSize
) ) ;
659 ::TextFace( font
->m_macFontStyle
) ;
663 ::TextFont( kFontIDMonaco
) ;
668 // Find the widest line
669 for(int i
= 0; i
< GetCount(); i
++) {
670 wxString
str(GetString(i
));
671 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
672 lbWidth
= wxMax(lbWidth
, wLine
);
675 // Add room for the scrollbar
676 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
678 // And just a bit more
680 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
683 // don't make the listbox too tall (limit height to around 10 items) but don't
684 // make it too small neither
685 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
687 return wxSize(lbWidth
, lbHeight
);
690 int wxListBox::GetCount() const
695 void wxListBox::SetupColours()
697 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
698 SetForegroundColour(GetParent()->GetForegroundColour());
701 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
703 wxControl::Refresh( eraseBack
, rect
) ;
704 // MacRedrawControl() ;
707 #if wxUSE_OWNER_DRAWN
709 class wxListBoxItem
: public wxOwnerDrawn
712 wxListBoxItem(const wxString
& str
= "");
715 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
717 // no bitmaps/checkmarks
721 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
723 return new wxListBoxItem();
726 #endif //USE_OWNER_DRAWN
728 // ============================================================================
729 // list box control implementation
730 // ============================================================================
733 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
736 // typecast our refCon
737 list = (wxListBox*)refCon;
739 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
740 const wxString text = list->m_stringArray[lCell.v] ;
741 ::TextFont( kFontIDMonaco ) ;
744 DrawText(text, 0 , text.Length());
748 void wxListBox::MacDelete( int N
)
750 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
754 void wxListBox::MacInsert( int n
, const char * text
)
756 Cell cell
= { 0 , 0 } ;
758 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
759 // LSetCell(text, strlen(text), cell, m_macList);
763 void wxListBox::MacAppend( const char * text
)
765 Cell cell
= { 0 , 0 } ;
766 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
767 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
768 // LSetCell(text, strlen(text), cell, m_macList);
772 void wxListBox::MacClear()
774 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
778 void wxListBox::MacSetSelection( int n
, bool select
)
780 Cell cell
= { 0 , 0 } ;
781 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
783 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
785 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
790 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
791 LAutoScroll( (ListHandle
)m_macList
) ;
795 bool wxListBox::MacIsSelected( int n
) const
797 Cell cell
= { 0 , 0 } ;
799 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
802 void wxListBox::MacDestroy()
804 // DisposeExtLDEFInfo( m_macList ) ;
807 int wxListBox::MacGetSelection() const
809 Cell cell
= { 0 , 0 } ;
810 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
816 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
822 Cell cell
= { 0 , 0 } ;
825 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
827 aSelections
.Add( cell
.v
) ;
834 void wxListBox::MacSet( int n
, const char * text
)
836 // our implementation does not store anything in the list
837 // so we just have to redraw
838 Cell cell
= { 0 , 0 } ;
840 // LSetCell(text, strlen(text), cell, m_macList);
844 void wxListBox::MacScrollTo( int n
)
846 // TODO implement scrolling
849 void wxListBox::OnSize( const wxSizeEvent
&event
)
854 GetListCellSize((ListHandle
)m_macList
, &pt
);
856 pt
= (**(ListHandle
)m_macList
).cellSize
;
858 pt
.h
= m_width
- 15 ;
859 LCellSize( pt
, (ListHandle
)m_macList
) ;
862 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
)
864 Boolean wasDoubleClick
= false ;
867 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
868 if ( !wasDoubleClick
)
878 void wxListBox::MacSetRedraw( bool doDraw
)
880 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
884 void wxListBox::MacDoClick()
886 wxArrayInt aSelections
;
888 size_t count
= GetSelections(aSelections
);
890 if ( count
== m_selectionPreImage
.GetCount() )
892 bool hasChanged
= false ;
893 for ( size_t i
= 0 ; i
< count
; ++i
)
895 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
907 m_selectionPreImage
= aSelections
;
909 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
910 event
.SetEventObject( this );
915 if ( HasClientObjectData() )
916 event
.SetClientObject( GetClientObject(n
) );
917 else if ( HasClientUntypedData() )
918 event
.SetClientData( GetClientData(n
) );
919 event
.SetString( GetString(n
) );
926 event
.m_commandInt
= n
;
928 GetEventHandler()->ProcessEvent(event
);
931 void wxListBox::MacDoDoubleClick()
933 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
934 event
.SetEventObject( this );
935 GetEventHandler()->ProcessEvent(event
) ;
938 void wxListBox::OnChar(wxKeyEvent
& event
)
940 if ( event
.KeyCode() == WXK_RETURN
|| event
.KeyCode() == WXK_NUMPAD_ENTER
)
942 wxWindow
* parent
= GetParent() ;
943 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
944 parent
= parent
->GetParent() ;
946 if ( parent
&& parent
->GetDefaultItem() )
948 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
950 if ( def
&& def
->IsEnabled() )
952 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
953 event
.SetEventObject(def
);
960 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
961 else if (event
.KeyCode() == WXK_ESCAPE
|| (event
.KeyCode() == '.' && event
.MetaDown() ) )
963 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
964 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
965 new_event
.SetEventObject( win
);
966 win
->GetEventHandler()->ProcessEvent( new_event
);
968 else if ( event
.KeyCode() == WXK_TAB
)
970 wxNavigationKeyEvent new_event
;
971 new_event
.SetEventObject( this );
972 new_event
.SetDirection( !event
.ShiftDown() );
973 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
974 new_event
.SetWindowChange( event
.ControlDown() );
975 new_event
.SetCurrentFocus( this );
976 if ( !GetEventHandler()->ProcessEvent( new_event
) )
979 else if ( event
.KeyCode() == WXK_DOWN
|| event
.KeyCode() == WXK_UP
)
981 // perform the default key handling first
982 wxControl::OnKeyDown( event
) ;
984 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
985 event
.SetEventObject( this );
987 wxArrayInt aSelections
;
988 int n
, count
= GetSelections(aSelections
);
992 if ( HasClientObjectData() )
993 event
.SetClientObject( GetClientObject(n
) );
994 else if ( HasClientUntypedData() )
995 event
.SetClientData( GetClientData(n
) );
996 event
.SetString( GetString(n
) );
1003 event
.m_commandInt
= n
;
1005 GetEventHandler()->ProcessEvent(event
);
1009 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
1013 m_lastTypeIn
= event
.GetTimestamp() ;
1014 m_typeIn
+= (char) event
.KeyCode() ;
1015 int line
= FindString("*"+m_typeIn
+"*") ;
1018 if ( GetSelection() != line
)
1020 SetSelection(line
) ;
1021 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1022 event
.SetEventObject( this );
1024 if ( HasClientObjectData() )
1025 event
.SetClientObject( GetClientObject( line
) );
1026 else if ( HasClientUntypedData() )
1027 event
.SetClientData( GetClientData(line
) );
1028 event
.SetString( GetString(line
) );
1030 event
.m_commandInt
= line
;
1032 GetEventHandler()->ProcessEvent(event
);