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 linetext
= 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 const wxFont
& font
= list
->GetFont();
111 ::TextFont( font
.GetMacFontNum() ) ;
112 ::TextSize( font
.GetMacFontSize() ) ;
113 ::TextFace( font
.GetMacFontStyle() ) ;
117 ::TextFont( kFontIDMonaco
) ;
124 Rect frame
= { drawRect
->top
, drawRect
->left
+ 4,
125 drawRect
->top
+ kwxMacListItemHeight
, drawRect
->right
+ 10000 } ;
126 CFMutableStringRef mString
= CFStringCreateMutableCopy( NULL
, 0 , wxMacCFStringHolder(linetext
) ) ;
127 ::TruncateThemeText( mString
, kThemeCurrentPortFont
, kThemeStateActive
, drawRect
->right
- drawRect
->left
, truncEnd
, NULL
) ;
128 ::DrawThemeTextBox( mString
,
129 kThemeCurrentPortFont
,
135 CFRelease( mString
) ;
139 wxCharBuffer text
= linetext
.mb_str( wxConvLocal
) ;
140 MoveTo(drawRect
->left
+ 4 , drawRect
->top
+ 10 );
141 DrawText(text
, 0 , strlen(text
) );
144 // If the cell is hilited, do the hilite now. Paint the cell contents with the
145 // appropriate QuickDraw transform mode.
148 savedPenMode
= GetPortPenMode( (CGrafPtr
) grafPtr
);
149 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
150 PaintRect( drawRect
);
151 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
154 // Restore the saved clip region.
156 SetClip( savedClipRegion
);
157 DisposeRgn( savedClipRegion
);
162 // Hilite or unhilite the cell. Paint the cell contents with the
163 // appropriate QuickDraw transform mode.
166 savedPenMode
= GetPortPenMode( (CGrafPtr
)grafPtr
);
167 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
168 PaintRect( drawRect
);
169 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
177 extern "C" void MacDrawStringCell(Rect
*cellRect
, Cell lCell
, ListHandle theList
, long refCon
) ;
178 // resources ldef ids
179 const short kwxMacListWithVerticalScrollbar
= 128 ;
180 const short kwxMacListWithVerticalAndHorizontalScrollbar
= 129 ;
182 // ============================================================================
183 // list box control implementation
184 // ============================================================================
187 wxListBox::wxListBox()
194 static ListDefUPP macListDefUPP
= NULL
;
196 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
199 int n
, const wxString choices
[],
201 const wxValidator
& validator
,
202 const wxString
& name
)
204 if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
207 m_noItems
= 0 ; // this will be increased by our append command
213 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
216 listDef
.defType
= kListDefUserProcType
;
217 if ( macListDefUPP
== NULL
)
219 macListDefUPP
= NewListDefUPP( wxMacListDefinition
);
221 listDef
.u
.userProc
= macListDefUPP
;
227 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
229 GetFontName( kFontIDMonaco
, fontName
) ;
233 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) ) ) ;
238 CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, (style
& wxLB_HSCROLL
), true,
239 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
241 GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
242 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
244 SetControlReference( (ControlHandle
) m_macControl
, (long) this);
245 SetControlVisibility( (ControlHandle
) m_macControl
, false, false);
250 wxStAppResource resload
;
251 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false ,
252 (style
& wxLB_HSCROLL
) ? kwxMacListWithVerticalAndHorizontalScrollbar
: kwxMacListWithVerticalScrollbar
,
253 0 , 0, kControlListBoxProc
, (long) this ) ;
254 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
255 sizeof( ListHandle
) , (char*) &m_macList
, &result
) ;
257 HLock( (Handle
) m_macList
) ;
259 ldef
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ;
260 if ( (**(ListHandle
)m_macList
).listDefProc
!= NULL
)
262 (**ldef
).instruction
= 0x4EF9; /* JMP instruction */
263 (**ldef
).function
= (void(*)()) listDef
.u
.userProc
;
264 (**(ListHandle
)m_macList
).listDefProc
= (Handle
) ldef
;
267 Point pt
= (**(ListHandle
)m_macList
).cellSize
;
268 pt
.v
= kwxMacListItemHeight
;
269 LCellSize( pt
, (ListHandle
)m_macList
) ;
270 LAddColumn( 1 , 0 , (ListHandle
)m_macList
) ;
272 OptionBits options
= 0;
273 if ( style
& wxLB_MULTIPLE
)
275 options
+= lNoExtend
;
277 else if ( style
& wxLB_EXTENDED
)
279 options
+= lExtendDrag
;
283 options
= (OptionBits
) lOnlyOne
;
285 SetListSelectionFlags((ListHandle
)m_macList
, options
);
287 for ( int i
= 0 ; i
< n
; i
++ )
289 Append( choices
[i
] ) ;
292 MacPostControlCreate() ;
294 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
299 wxListBox::~wxListBox()
305 DisposeHandle( (**(ListHandle
)m_macList
).listDefProc
) ;
306 (**(ListHandle
)m_macList
).listDefProc
= NULL
;
312 void wxListBox::FreeData()
314 #if wxUSE_OWNER_DRAWN
315 if ( m_windowStyle
& wxLB_OWNERDRAW
)
317 size_t uiCount
= m_aItems
.Count();
318 while ( uiCount
-- != 0 ) {
319 delete m_aItems
[uiCount
];
320 m_aItems
[uiCount
] = NULL
;
326 #endif // wxUSE_OWNER_DRAWN
327 if ( HasClientObjectData() )
329 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
331 delete GetClientObject(n
);
336 void wxListBox::DoSetSize(int x
, int y
,
337 int width
, int height
,
340 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
343 GetControlBounds( (ControlHandle
) m_macControl
, &bounds
) ;
344 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
348 GetControlBounds( control
, &scrollbounds
) ;
349 if( scrollbounds
.right
!= bounds
.right
+ 1 )
351 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
357 void wxListBox::DoSetFirstItem(int N
)
362 void wxListBox::Delete(int N
)
364 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
365 wxT("invalid index in wxListBox::Delete") );
367 #if wxUSE_OWNER_DRAWN
369 m_aItems
.RemoveAt(N
);
370 #else // !wxUSE_OWNER_DRAWN
371 if ( HasClientObjectData() )
373 delete GetClientObject(N
);
375 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
376 m_stringArray
.RemoveAt( N
) ;
377 m_dataArray
.RemoveAt( N
) ;
383 int wxListBox::DoAppend(const wxString
& item
)
385 int index
= m_noItems
;
386 m_stringArray
.Add( item
) ;
387 m_dataArray
.Add( NULL
);
389 DoSetItemClientData( index
, NULL
) ;
395 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
397 MacSetRedraw( false ) ;
399 int n
= choices
.GetCount();
401 for( int i
= 0 ; i
< n
; ++i
)
405 #if wxUSE_OWNER_DRAWN
406 wxASSERT_MSG(clientData
[i
] == NULL
,
407 wxT("Can't use client data with owner-drawn listboxes"));
408 #else // !wxUSE_OWNER_DRAWN
409 Append( choices
[i
] , clientData
[i
] ) ;
413 Append( choices
[i
] ) ;
416 #if wxUSE_OWNER_DRAWN
417 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
418 // first delete old items
419 size_t ui
= m_aItems
.Count();
420 while ( ui
-- != 0 ) {
426 // then create new ones
427 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
428 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
429 pNewItem
->SetName(choices
[ui
]);
430 m_aItems
.Add(pNewItem
);
433 #endif // wxUSE_OWNER_DRAWN
434 MacSetRedraw( true ) ;
437 bool wxListBox::HasMultipleSelection() const
439 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
442 int wxListBox::FindString(const wxString
& s
) const
445 if ( s
.Right(1) == wxT("*") )
447 wxString search
= s
.Left( s
.Length() - 1 ) ;
448 int len
= search
.Length() ;
450 wxMacStringToPascal( search
, s2
) ;
452 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
454 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
456 if ( EqualString( s1
, s2
, false , false ) )
459 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
463 for ( int i
= 0 ; i
< m_noItems
; ++i
)
465 if ( GetString(i
).Lower().Matches(st
) )
475 wxMacStringToPascal( s
, s2
) ;
477 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
479 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
481 if ( EqualString( s1
, s2
, false , false ) )
488 void wxListBox::Clear()
492 m_stringArray
.Empty() ;
493 m_dataArray
.Empty() ;
497 void wxListBox::SetSelection(int N
, bool select
)
499 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
500 wxT("invalid index in wxListBox::SetSelection") );
501 MacSetSelection( N
, select
) ;
502 GetSelections( m_selectionPreImage
) ;
505 bool wxListBox::IsSelected(int N
) const
507 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
508 wxT("invalid index in wxListBox::Selected") );
510 return MacIsSelected( N
) ;
513 void *wxListBox::DoGetItemClientData(int N
) const
515 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
516 wxT("invalid index in wxListBox::GetClientData"));
518 return (void *)m_dataArray
[N
];
521 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
523 return (wxClientData
*) DoGetItemClientData( N
) ;
526 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
528 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
529 wxT("invalid index in wxListBox::SetClientData") );
531 #if wxUSE_OWNER_DRAWN
532 if ( m_windowStyle
& wxLB_OWNERDRAW
)
534 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
535 // in OnMeasure/OnDraw.
536 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
538 #endif // wxUSE_OWNER_DRAWN
539 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
541 if ( m_dataArray
.GetCount() > (size_t) N
)
543 m_dataArray
[N
] = (char*) Client_data
;
547 m_dataArray
.Add( (char*) Client_data
) ;
551 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
553 DoSetItemClientData(n
, clientData
);
556 // Return number of selections and an array of selected integers
557 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
559 return MacGetSelections( aSelections
) ;
562 // Get single selection, for single choice list items
563 int wxListBox::GetSelection() const
565 return MacGetSelection() ;
568 // Find string for position
569 wxString
wxListBox::GetString(int N
) const
571 return m_stringArray
[N
] ;
574 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
576 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
577 wxT("invalid index in wxListBox::InsertItems") );
579 int nItems
= items
.GetCount();
581 for ( int i
= 0 ; i
< nItems
; i
++ )
583 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
584 m_dataArray
.Insert( NULL
, pos
+ i
) ;
585 MacInsert( pos
+ i
, items
[i
] ) ;
591 void wxListBox::SetString(int N
, const wxString
& s
)
593 m_stringArray
[N
] = s
;
597 wxSize
wxListBox::DoGetBestSize() const
599 int lbWidth
= 100; // some defaults
604 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
608 ::TextFont( m_font
.GetMacFontNum() ) ;
609 ::TextSize( m_font
.GetMacFontSize() ) ;
610 ::TextFace( m_font
.GetMacFontStyle() ) ;
614 ::TextFont( kFontIDMonaco
) ;
619 // Find the widest line
620 for(int i
= 0; i
< GetCount(); i
++) {
621 wxString
str(GetString(i
));
625 ::GetThemeTextDimensions( wxMacCFStringHolder( str
) ,
626 kThemeCurrentPortFont
,
633 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
635 lbWidth
= wxMax(lbWidth
, wLine
);
638 // Add room for the scrollbar
639 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
641 // And just a bit more
643 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
646 // don't make the listbox too tall (limit height to around 10 items) but don't
647 // make it too small neither
648 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
650 return wxSize(lbWidth
, lbHeight
);
653 int wxListBox::GetCount() const
658 void wxListBox::SetupColours()
660 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
661 SetForegroundColour(GetParent()->GetForegroundColour());
664 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
666 wxControl::Refresh( eraseBack
, rect
) ;
667 // MacRedrawControl() ;
670 #if wxUSE_OWNER_DRAWN
672 class wxListBoxItem
: public wxOwnerDrawn
675 wxListBoxItem(const wxString
& str
= "");
678 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
680 // no bitmaps/checkmarks
684 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
686 return new wxListBoxItem();
689 #endif //USE_OWNER_DRAWN
691 // ============================================================================
692 // list box control implementation
693 // ============================================================================
696 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
699 // typecast our refCon
700 list = (wxListBox*)refCon;
702 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
703 const wxString text = list->m_stringArray[lCell.v] ;
704 ::TextFont( kFontIDMonaco ) ;
707 DrawText(text, 0 , text.Length());
711 void wxListBox::MacDelete( int N
)
713 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
717 void wxListBox::MacInsert( int n
, const wxString
& text
)
719 Cell cell
= { 0 , 0 } ;
721 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
722 // LSetCell(text, strlen(text), cell, m_macList);
726 void wxListBox::MacAppend( const wxString
& text
)
728 Cell cell
= { 0 , 0 } ;
729 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
730 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
731 // LSetCell(text, strlen(text), cell, m_macList);
735 void wxListBox::MacClear()
737 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
741 void wxListBox::MacSetSelection( int n
, bool select
)
743 Cell cell
= { 0 , 0 } ;
744 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
746 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
748 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
753 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
754 LAutoScroll( (ListHandle
)m_macList
) ;
758 bool wxListBox::MacIsSelected( int n
) const
760 Cell cell
= { 0 , 0 } ;
762 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
765 void wxListBox::MacDestroy()
767 // DisposeExtLDEFInfo( m_macList ) ;
770 int wxListBox::MacGetSelection() const
772 Cell cell
= { 0 , 0 } ;
773 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
779 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
785 Cell cell
= { 0 , 0 } ;
788 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
790 aSelections
.Add( cell
.v
) ;
797 void wxListBox::MacSet( int n
, const wxString
& text
)
799 // our implementation does not store anything in the list
800 // so we just have to redraw
801 Cell cell
= { 0 , 0 } ;
803 // LSetCell(text, strlen(text), cell, m_macList);
807 void wxListBox::MacScrollTo( int n
)
809 // TODO implement scrolling
812 void wxListBox::OnSize( const wxSizeEvent
&event
)
817 GetListCellSize((ListHandle
)m_macList
, &pt
);
819 pt
= (**(ListHandle
)m_macList
).cellSize
;
821 pt
.h
= m_width
- 15 ;
822 LCellSize( pt
, (ListHandle
)m_macList
) ;
825 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
827 Boolean wasDoubleClick
= false ;
830 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
831 if ( !wasDoubleClick
)
841 void wxListBox::MacSetRedraw( bool doDraw
)
843 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
847 void wxListBox::MacDoClick()
849 wxArrayInt aSelections
;
851 size_t count
= GetSelections(aSelections
);
853 if ( count
== m_selectionPreImage
.GetCount() )
855 bool hasChanged
= false ;
856 for ( size_t i
= 0 ; i
< count
; ++i
)
858 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
870 m_selectionPreImage
= aSelections
;
872 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
873 event
.SetEventObject( this );
878 if ( HasClientObjectData() )
879 event
.SetClientObject( GetClientObject(n
) );
880 else if ( HasClientUntypedData() )
881 event
.SetClientData( GetClientData(n
) );
882 event
.SetString( GetString(n
) );
889 event
.m_commandInt
= n
;
891 GetEventHandler()->ProcessEvent(event
);
894 void wxListBox::MacDoDoubleClick()
896 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
897 event
.SetEventObject( this );
898 GetEventHandler()->ProcessEvent(event
) ;
901 void wxListBox::OnChar(wxKeyEvent
& event
)
903 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
905 wxWindow
* parent
= GetParent() ;
906 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
907 parent
= parent
->GetParent() ;
909 if ( parent
&& parent
->GetDefaultItem() )
911 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
913 if ( def
&& def
->IsEnabled() )
915 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
916 event
.SetEventObject(def
);
923 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
924 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
926 // FIXME: look in ancestors, not just parent.
927 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
930 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
931 new_event
.SetEventObject( win
);
932 win
->GetEventHandler()->ProcessEvent( new_event
);
935 else if ( event
.GetKeyCode() == WXK_TAB
)
937 wxNavigationKeyEvent new_event
;
938 new_event
.SetEventObject( this );
939 new_event
.SetDirection( !event
.ShiftDown() );
940 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
941 new_event
.SetWindowChange( event
.ControlDown() );
942 new_event
.SetCurrentFocus( this );
943 if ( !GetEventHandler()->ProcessEvent( new_event
) )
946 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
948 // perform the default key handling first
949 wxControl::OnKeyDown( event
) ;
951 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
952 event
.SetEventObject( this );
954 wxArrayInt aSelections
;
955 int n
, count
= GetSelections(aSelections
);
959 if ( HasClientObjectData() )
960 event
.SetClientObject( GetClientObject(n
) );
961 else if ( HasClientUntypedData() )
962 event
.SetClientData( GetClientData(n
) );
963 event
.SetString( GetString(n
) );
970 event
.m_commandInt
= n
;
972 GetEventHandler()->ProcessEvent(event
);
976 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
978 m_typeIn
= wxEmptyString
;
980 m_lastTypeIn
= event
.GetTimestamp() ;
981 m_typeIn
+= (char) event
.GetKeyCode() ;
982 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
985 if ( GetSelection() != line
)
988 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
989 event
.SetEventObject( this );
991 if ( HasClientObjectData() )
992 event
.SetClientObject( GetClientObject( line
) );
993 else if ( HasClientUntypedData() )
994 event
.SetClientData( GetClientData(line
) );
995 event
.SetString( GetString(line
) );
997 event
.m_commandInt
= line
;
999 GetEventHandler()->ProcessEvent(event
);