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 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
) ;
125 Rect frame
= { drawRect
->top
, drawRect
->left
+ 4,
126 drawRect
->top
+ kwxMacListItemHeight
, drawRect
->right
+ 10000 } ;
127 CFMutableStringRef mString
= CFStringCreateMutableCopy( NULL
, 0 , wxMacCFStringHolder(linetext
) ) ;
128 ::TruncateThemeText( mString
, kThemeCurrentPortFont
, kThemeStateActive
, drawRect
->right
- drawRect
->left
, truncEnd
, NULL
) ;
129 ::DrawThemeTextBox( mString
,
130 kThemeCurrentPortFont
,
136 CFRelease( mString
) ;
140 wxCharBuffer text
= wxMacStringToCString( linetext
) ;
141 MoveTo(drawRect
->left
+ 4 , drawRect
->top
+ 10 );
142 DrawText(text
, 0 , strlen(text
) );
145 // If the cell is hilited, do the hilite now. Paint the cell contents with the
146 // appropriate QuickDraw transform mode.
149 savedPenMode
= GetPortPenMode( (CGrafPtr
) grafPtr
);
150 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
151 PaintRect( drawRect
);
152 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
155 // Restore the saved clip region.
157 SetClip( savedClipRegion
);
158 DisposeRgn( savedClipRegion
);
163 // Hilite or unhilite the cell. Paint the cell contents with the
164 // appropriate QuickDraw transform mode.
167 savedPenMode
= GetPortPenMode( (CGrafPtr
)grafPtr
);
168 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
169 PaintRect( drawRect
);
170 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
178 extern "C" void MacDrawStringCell(Rect
*cellRect
, Cell lCell
, ListHandle theList
, long refCon
) ;
179 // resources ldef ids
180 const short kwxMacListWithVerticalScrollbar
= 128 ;
181 const short kwxMacListWithVerticalAndHorizontalScrollbar
= 129 ;
183 // ============================================================================
184 // list box control implementation
185 // ============================================================================
188 wxListBox::wxListBox()
195 static ListDefUPP macListDefUPP
= NULL
;
197 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
200 int n
, const wxString choices
[],
202 const wxValidator
& validator
,
203 const wxString
& name
)
205 m_noItems
= 0 ; // this will be increased by our append command
211 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
214 listDef
.defType
= kListDefUserProcType
;
215 if ( macListDefUPP
== NULL
)
217 macListDefUPP
= NewListDefUPP( wxMacListDefinition
);
219 listDef
.u
.userProc
= macListDefUPP
;
225 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
227 GetFontName( kFontIDMonaco
, fontName
) ;
231 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) ) ) ;
236 CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, (style
& wxLB_HSCROLL
), true,
237 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
239 GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
240 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
242 SetControlReference( (ControlHandle
) m_macControl
, (long) this);
243 SetControlVisibility( (ControlHandle
) m_macControl
, false, false);
248 wxStAppResource resload
;
249 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false ,
250 (style
& wxLB_HSCROLL
) ? kwxMacListWithVerticalAndHorizontalScrollbar
: kwxMacListWithVerticalScrollbar
,
251 0 , 0, kControlListBoxProc
, (long) this ) ;
252 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
253 sizeof( ListHandle
) , (char*) &m_macList
, &result
) ;
255 HLock( (Handle
) m_macList
) ;
257 ldef
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ;
258 if ( (**(ListHandle
)m_macList
).listDefProc
!= NULL
)
260 (**ldef
).instruction
= 0x4EF9; /* JMP instruction */
261 (**ldef
).function
= (void(*)()) listDef
.u
.userProc
;
262 (**(ListHandle
)m_macList
).listDefProc
= (Handle
) ldef
;
265 Point pt
= (**(ListHandle
)m_macList
).cellSize
;
266 pt
.v
= kwxMacListItemHeight
;
267 LCellSize( pt
, (ListHandle
)m_macList
) ;
268 LAddColumn( 1 , 0 , (ListHandle
)m_macList
) ;
270 OptionBits options
= 0;
271 if ( style
& wxLB_MULTIPLE
)
273 options
+= lNoExtend
;
275 else if ( style
& wxLB_EXTENDED
)
277 options
+= lExtendDrag
;
281 options
= (OptionBits
) lOnlyOne
;
283 SetListSelectionFlags((ListHandle
)m_macList
, options
);
285 for ( int i
= 0 ; i
< n
; i
++ )
287 Append( choices
[i
] ) ;
290 MacPostControlCreate() ;
292 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
297 wxListBox::~wxListBox()
303 DisposeHandle( (**(ListHandle
)m_macList
).listDefProc
) ;
304 (**(ListHandle
)m_macList
).listDefProc
= NULL
;
310 void wxListBox::FreeData()
312 #if wxUSE_OWNER_DRAWN
313 if ( m_windowStyle
& wxLB_OWNERDRAW
)
315 size_t uiCount
= m_aItems
.Count();
316 while ( uiCount
-- != 0 ) {
317 delete m_aItems
[uiCount
];
318 m_aItems
[uiCount
] = NULL
;
324 #endif // wxUSE_OWNER_DRAWN
325 if ( HasClientObjectData() )
327 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
329 delete GetClientObject(n
);
334 void wxListBox::DoSetSize(int x
, int y
,
335 int width
, int height
,
338 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
341 GetControlBounds( (ControlHandle
) m_macControl
, &bounds
) ;
342 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
346 GetControlBounds( control
, &scrollbounds
) ;
347 if( scrollbounds
.right
!= bounds
.right
+ 1 )
349 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
355 void wxListBox::DoSetFirstItem(int N
)
360 void wxListBox::Delete(int N
)
362 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
363 wxT("invalid index in wxListBox::Delete") );
365 #if wxUSE_OWNER_DRAWN
367 m_aItems
.RemoveAt(N
);
368 #else // !wxUSE_OWNER_DRAWN
369 if ( HasClientObjectData() )
371 delete GetClientObject(N
);
373 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
374 m_stringArray
.RemoveAt( N
) ;
375 m_dataArray
.RemoveAt( N
) ;
381 int wxListBox::DoAppend(const wxString
& item
)
383 int index
= m_noItems
;
384 m_stringArray
.Add( item
) ;
385 m_dataArray
.Add( NULL
);
387 DoSetItemClientData( index
, NULL
) ;
393 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
395 MacSetRedraw( false ) ;
397 int n
= choices
.GetCount();
399 for( int i
= 0 ; i
< n
; ++i
)
403 #if wxUSE_OWNER_DRAWN
404 wxASSERT_MSG(clientData
[i
] == NULL
,
405 wxT("Can't use client data with owner-drawn listboxes"));
406 #else // !wxUSE_OWNER_DRAWN
407 Append( choices
[i
] , clientData
[i
] ) ;
411 Append( choices
[i
] ) ;
414 #if wxUSE_OWNER_DRAWN
415 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
416 // first delete old items
417 size_t ui
= m_aItems
.Count();
418 while ( ui
-- != 0 ) {
424 // then create new ones
425 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
426 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
427 pNewItem
->SetName(choices
[ui
]);
428 m_aItems
.Add(pNewItem
);
431 #endif // wxUSE_OWNER_DRAWN
432 MacSetRedraw( true ) ;
435 bool wxListBox::HasMultipleSelection() const
437 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
440 int wxListBox::FindString(const wxString
& s
) const
443 if ( s
.Right(1) == wxT("*") )
445 wxString search
= s
.Left( s
.Length() - 1 ) ;
446 int len
= search
.Length() ;
448 wxMacStringToPascal( search
, s2
) ;
450 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
452 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
454 if ( EqualString( s1
, s2
, false , false ) )
457 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
461 for ( int i
= 0 ; i
< m_noItems
; ++i
)
463 if ( GetString(i
).Lower().Matches(st
) )
473 wxMacStringToPascal( s
, s2
) ;
475 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
477 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
479 if ( EqualString( s1
, s2
, false , false ) )
486 void wxListBox::Clear()
490 m_stringArray
.Empty() ;
491 m_dataArray
.Empty() ;
495 void wxListBox::SetSelection(int N
, bool select
)
497 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
498 wxT("invalid index in wxListBox::SetSelection") );
499 MacSetSelection( N
, select
) ;
500 GetSelections( m_selectionPreImage
) ;
503 bool wxListBox::IsSelected(int N
) const
505 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
506 wxT("invalid index in wxListBox::Selected") );
508 return MacIsSelected( N
) ;
511 void *wxListBox::DoGetItemClientData(int N
) const
513 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
514 wxT("invalid index in wxListBox::GetClientData"));
516 return (void *)m_dataArray
[N
];
519 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
521 return (wxClientData
*) DoGetItemClientData( N
) ;
524 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
526 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
527 wxT("invalid index in wxListBox::SetClientData") );
529 #if wxUSE_OWNER_DRAWN
530 if ( m_windowStyle
& wxLB_OWNERDRAW
)
532 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
533 // in OnMeasure/OnDraw.
534 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
536 #endif // wxUSE_OWNER_DRAWN
537 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
539 if ( m_dataArray
.GetCount() > (size_t) N
)
541 m_dataArray
[N
] = (char*) Client_data
;
545 m_dataArray
.Add( (char*) Client_data
) ;
549 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
551 DoSetItemClientData(n
, clientData
);
554 // Return number of selections and an array of selected integers
555 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
557 return MacGetSelections( aSelections
) ;
560 // Get single selection, for single choice list items
561 int wxListBox::GetSelection() const
563 return MacGetSelection() ;
566 // Find string for position
567 wxString
wxListBox::GetString(int N
) const
569 return m_stringArray
[N
] ;
572 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
574 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
575 wxT("invalid index in wxListBox::InsertItems") );
577 int nItems
= items
.GetCount();
579 for ( int i
= 0 ; i
< nItems
; i
++ )
581 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
582 m_dataArray
.Insert( NULL
, pos
+ i
) ;
583 MacInsert( pos
+ i
, items
[i
] ) ;
589 void wxListBox::SetString(int N
, const wxString
& s
)
591 m_stringArray
[N
] = s
;
595 wxSize
wxListBox::DoGetBestSize() const
597 int lbWidth
= 100; // some defaults
602 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
604 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
608 ::TextFont( font
->m_macFontNum
) ;
609 ::TextSize( short(font
->m_macFontSize
) ) ;
610 ::TextFace( font
->m_macFontStyle
) ;
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 wxCharBuffer text
= wxMacStringToCString( str
) ;
634 wLine
= ::TextWidth( text
, 0 , strlen(text
) ) ;
636 lbWidth
= wxMax(lbWidth
, wLine
);
639 // Add room for the scrollbar
640 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
642 // And just a bit more
644 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
647 // don't make the listbox too tall (limit height to around 10 items) but don't
648 // make it too small neither
649 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
651 return wxSize(lbWidth
, lbHeight
);
654 int wxListBox::GetCount() const
659 void wxListBox::SetupColours()
661 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
662 SetForegroundColour(GetParent()->GetForegroundColour());
665 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
667 wxControl::Refresh( eraseBack
, rect
) ;
668 // MacRedrawControl() ;
671 #if wxUSE_OWNER_DRAWN
673 class wxListBoxItem
: public wxOwnerDrawn
676 wxListBoxItem(const wxString
& str
= "");
679 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
681 // no bitmaps/checkmarks
685 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
687 return new wxListBoxItem();
690 #endif //USE_OWNER_DRAWN
692 // ============================================================================
693 // list box control implementation
694 // ============================================================================
697 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
700 // typecast our refCon
701 list = (wxListBox*)refCon;
703 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
704 const wxString text = list->m_stringArray[lCell.v] ;
705 ::TextFont( kFontIDMonaco ) ;
708 DrawText(text, 0 , text.Length());
712 void wxListBox::MacDelete( int N
)
714 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
718 void wxListBox::MacInsert( int n
, const wxString
& text
)
720 Cell cell
= { 0 , 0 } ;
722 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
723 // LSetCell(text, strlen(text), cell, m_macList);
727 void wxListBox::MacAppend( const wxString
& text
)
729 Cell cell
= { 0 , 0 } ;
730 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
731 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
732 // LSetCell(text, strlen(text), cell, m_macList);
736 void wxListBox::MacClear()
738 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
742 void wxListBox::MacSetSelection( int n
, bool select
)
744 Cell cell
= { 0 , 0 } ;
745 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
747 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
749 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
754 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
755 LAutoScroll( (ListHandle
)m_macList
) ;
759 bool wxListBox::MacIsSelected( int n
) const
761 Cell cell
= { 0 , 0 } ;
763 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
766 void wxListBox::MacDestroy()
768 // DisposeExtLDEFInfo( m_macList ) ;
771 int wxListBox::MacGetSelection() const
773 Cell cell
= { 0 , 0 } ;
774 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
780 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
786 Cell cell
= { 0 , 0 } ;
789 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
791 aSelections
.Add( cell
.v
) ;
798 void wxListBox::MacSet( int n
, const wxString
& text
)
800 // our implementation does not store anything in the list
801 // so we just have to redraw
802 Cell cell
= { 0 , 0 } ;
804 // LSetCell(text, strlen(text), cell, m_macList);
808 void wxListBox::MacScrollTo( int n
)
810 // TODO implement scrolling
813 void wxListBox::OnSize( const wxSizeEvent
&event
)
818 GetListCellSize((ListHandle
)m_macList
, &pt
);
820 pt
= (**(ListHandle
)m_macList
).cellSize
;
822 pt
.h
= m_width
- 15 ;
823 LCellSize( pt
, (ListHandle
)m_macList
) ;
826 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
)
828 Boolean wasDoubleClick
= false ;
831 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
832 if ( !wasDoubleClick
)
842 void wxListBox::MacSetRedraw( bool doDraw
)
844 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
848 void wxListBox::MacDoClick()
850 wxArrayInt aSelections
;
852 size_t count
= GetSelections(aSelections
);
854 if ( count
== m_selectionPreImage
.GetCount() )
856 bool hasChanged
= false ;
857 for ( size_t i
= 0 ; i
< count
; ++i
)
859 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
871 m_selectionPreImage
= aSelections
;
873 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
874 event
.SetEventObject( this );
879 if ( HasClientObjectData() )
880 event
.SetClientObject( GetClientObject(n
) );
881 else if ( HasClientUntypedData() )
882 event
.SetClientData( GetClientData(n
) );
883 event
.SetString( GetString(n
) );
890 event
.m_commandInt
= n
;
892 GetEventHandler()->ProcessEvent(event
);
895 void wxListBox::MacDoDoubleClick()
897 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
898 event
.SetEventObject( this );
899 GetEventHandler()->ProcessEvent(event
) ;
902 void wxListBox::OnChar(wxKeyEvent
& event
)
904 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
906 wxWindow
* parent
= GetParent() ;
907 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
908 parent
= parent
->GetParent() ;
910 if ( parent
&& parent
->GetDefaultItem() )
912 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
914 if ( def
&& def
->IsEnabled() )
916 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
917 event
.SetEventObject(def
);
924 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
925 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
927 // FIXME: look in ancestors, not just parent.
928 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
931 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
932 new_event
.SetEventObject( win
);
933 win
->GetEventHandler()->ProcessEvent( new_event
);
936 else if ( event
.GetKeyCode() == WXK_TAB
)
938 wxNavigationKeyEvent new_event
;
939 new_event
.SetEventObject( this );
940 new_event
.SetDirection( !event
.ShiftDown() );
941 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
942 new_event
.SetWindowChange( event
.ControlDown() );
943 new_event
.SetCurrentFocus( this );
944 if ( !GetEventHandler()->ProcessEvent( new_event
) )
947 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
949 // perform the default key handling first
950 wxControl::OnKeyDown( event
) ;
952 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
953 event
.SetEventObject( this );
955 wxArrayInt aSelections
;
956 int n
, count
= GetSelections(aSelections
);
960 if ( HasClientObjectData() )
961 event
.SetClientObject( GetClientObject(n
) );
962 else if ( HasClientUntypedData() )
963 event
.SetClientData( GetClientData(n
) );
964 event
.SetString( GetString(n
) );
971 event
.m_commandInt
= n
;
973 GetEventHandler()->ProcessEvent(event
);
977 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
979 m_typeIn
= wxEmptyString
;
981 m_lastTypeIn
= event
.GetTimestamp() ;
982 m_typeIn
+= (char) event
.GetKeyCode() ;
983 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
986 if ( GetSelection() != line
)
989 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
990 event
.SetEventObject( this );
992 if ( HasClientObjectData() )
993 event
.SetClientObject( GetClientObject( line
) );
994 else if ( HasClientUntypedData() )
995 event
.SetClientData( GetClientData(line
) );
996 event
.SetString( GetString(line
) );
998 event
.m_commandInt
= line
;
1000 GetEventHandler()->ProcessEvent(event
);