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
;
226 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
228 GetFontName( kFontIDMonaco
, fontName
) ;
232 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) ) ) ;
237 CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, (style
& wxLB_HSCROLL
), true,
238 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
240 GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
241 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
243 SetControlReference( (ControlHandle
) m_macControl
, (long) this);
244 SetControlVisibility( (ControlHandle
) m_macControl
, false, false);
249 wxStAppResource resload
;
250 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false ,
251 (style
& wxLB_HSCROLL
) ? kwxMacListWithVerticalAndHorizontalScrollbar
: kwxMacListWithVerticalScrollbar
,
252 0 , 0, kControlListBoxProc
, (long) this ) ;
253 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
254 sizeof( ListHandle
) , (char*) &m_macList
, &result
) ;
256 HLock( (Handle
) m_macList
) ;
258 ldef
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ;
259 if ( (**(ListHandle
)m_macList
).listDefProc
!= NULL
)
261 (**ldef
).instruction
= 0x4EF9; /* JMP instruction */
262 (**ldef
).function
= (void(*)()) listDef
.u
.userProc
;
263 (**(ListHandle
)m_macList
).listDefProc
= (Handle
) ldef
;
266 Point pt
= (**(ListHandle
)m_macList
).cellSize
;
267 pt
.v
= kwxMacListItemHeight
;
268 LCellSize( pt
, (ListHandle
)m_macList
) ;
269 LAddColumn( 1 , 0 , (ListHandle
)m_macList
) ;
271 OptionBits options
= 0;
272 if ( style
& wxLB_MULTIPLE
)
274 options
+= lNoExtend
;
276 else if ( style
& wxLB_EXTENDED
)
278 options
+= lExtendDrag
;
282 options
= (OptionBits
) lOnlyOne
;
284 SetListSelectionFlags((ListHandle
)m_macList
, options
);
286 for ( int i
= 0 ; i
< n
; i
++ )
288 Append( choices
[i
] ) ;
291 MacPostControlCreate() ;
293 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
298 wxListBox::~wxListBox()
304 DisposeHandle( (**(ListHandle
)m_macList
).listDefProc
) ;
305 (**(ListHandle
)m_macList
).listDefProc
= NULL
;
311 void wxListBox::FreeData()
313 #if wxUSE_OWNER_DRAWN
314 if ( m_windowStyle
& wxLB_OWNERDRAW
)
316 size_t uiCount
= m_aItems
.Count();
317 while ( uiCount
-- != 0 ) {
318 delete m_aItems
[uiCount
];
319 m_aItems
[uiCount
] = NULL
;
325 #endif // wxUSE_OWNER_DRAWN
326 if ( HasClientObjectData() )
328 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
330 delete GetClientObject(n
);
335 void wxListBox::DoSetSize(int x
, int y
,
336 int width
, int height
,
339 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
342 GetControlBounds( (ControlHandle
) m_macControl
, &bounds
) ;
343 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
347 GetControlBounds( control
, &scrollbounds
) ;
348 if( scrollbounds
.right
!= bounds
.right
+ 1 )
350 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
356 void wxListBox::DoSetFirstItem(int N
)
361 void wxListBox::Delete(int N
)
363 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
364 wxT("invalid index in wxListBox::Delete") );
366 #if wxUSE_OWNER_DRAWN
368 m_aItems
.RemoveAt(N
);
369 #else // !wxUSE_OWNER_DRAWN
370 if ( HasClientObjectData() )
372 delete GetClientObject(N
);
374 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
375 m_stringArray
.RemoveAt( N
) ;
376 m_dataArray
.RemoveAt( N
) ;
382 int wxListBox::DoAppend(const wxString
& item
)
384 int index
= m_noItems
;
385 m_stringArray
.Add( item
) ;
386 m_dataArray
.Add( NULL
);
388 DoSetItemClientData( index
, NULL
) ;
394 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
396 MacSetRedraw( false ) ;
398 int n
= choices
.GetCount();
400 for( int i
= 0 ; i
< n
; ++i
)
404 #if wxUSE_OWNER_DRAWN
405 wxASSERT_MSG(clientData
[i
] == NULL
,
406 wxT("Can't use client data with owner-drawn listboxes"));
407 #else // !wxUSE_OWNER_DRAWN
408 Append( choices
[i
] , clientData
[i
] ) ;
412 Append( choices
[i
] ) ;
415 #if wxUSE_OWNER_DRAWN
416 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
417 // first delete old items
418 size_t ui
= m_aItems
.Count();
419 while ( ui
-- != 0 ) {
425 // then create new ones
426 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
427 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
428 pNewItem
->SetName(choices
[ui
]);
429 m_aItems
.Add(pNewItem
);
432 #endif // wxUSE_OWNER_DRAWN
433 MacSetRedraw( true ) ;
436 bool wxListBox::HasMultipleSelection() const
438 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
441 int wxListBox::FindString(const wxString
& s
) const
444 if ( s
.Right(1) == wxT("*") )
446 wxString search
= s
.Left( s
.Length() - 1 ) ;
447 int len
= search
.Length() ;
449 wxMacStringToPascal( search
, s2
) ;
451 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
453 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
455 if ( EqualString( s1
, s2
, false , false ) )
458 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
462 for ( int i
= 0 ; i
< m_noItems
; ++i
)
464 if ( GetString(i
).Lower().Matches(st
) )
474 wxMacStringToPascal( s
, s2
) ;
476 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
478 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
480 if ( EqualString( s1
, s2
, false , false ) )
487 void wxListBox::Clear()
491 m_stringArray
.Empty() ;
492 m_dataArray
.Empty() ;
496 void wxListBox::SetSelection(int N
, bool select
)
498 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
499 wxT("invalid index in wxListBox::SetSelection") );
500 MacSetSelection( N
, select
) ;
501 GetSelections( m_selectionPreImage
) ;
504 bool wxListBox::IsSelected(int N
) const
506 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
507 wxT("invalid index in wxListBox::Selected") );
509 return MacIsSelected( N
) ;
512 void *wxListBox::DoGetItemClientData(int N
) const
514 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
515 wxT("invalid index in wxListBox::GetClientData"));
517 return (void *)m_dataArray
[N
];
520 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
522 return (wxClientData
*) DoGetItemClientData( N
) ;
525 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
527 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
528 wxT("invalid index in wxListBox::SetClientData") );
530 #if wxUSE_OWNER_DRAWN
531 if ( m_windowStyle
& wxLB_OWNERDRAW
)
533 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
534 // in OnMeasure/OnDraw.
535 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
537 #endif // wxUSE_OWNER_DRAWN
538 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
540 if ( m_dataArray
.GetCount() > (size_t) N
)
542 m_dataArray
[N
] = (char*) Client_data
;
546 m_dataArray
.Add( (char*) Client_data
) ;
550 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
552 DoSetItemClientData(n
, clientData
);
555 // Return number of selections and an array of selected integers
556 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
558 return MacGetSelections( aSelections
) ;
561 // Get single selection, for single choice list items
562 int wxListBox::GetSelection() const
564 return MacGetSelection() ;
567 // Find string for position
568 wxString
wxListBox::GetString(int N
) const
570 return m_stringArray
[N
] ;
573 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
575 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
576 wxT("invalid index in wxListBox::InsertItems") );
578 int nItems
= items
.GetCount();
580 for ( int i
= 0 ; i
< nItems
; i
++ )
582 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
583 m_dataArray
.Insert( NULL
, pos
+ i
) ;
584 MacInsert( pos
+ i
, items
[i
] ) ;
590 void wxListBox::SetString(int N
, const wxString
& s
)
592 m_stringArray
[N
] = s
;
596 wxSize
wxListBox::DoGetBestSize() const
598 int lbWidth
= 100; // some defaults
603 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
605 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
609 ::TextFont( font
->m_macFontNum
) ;
610 ::TextSize( short(font
->m_macFontSize
) ) ;
611 ::TextFace( font
->m_macFontStyle
) ;
615 ::TextFont( kFontIDMonaco
) ;
620 // Find the widest line
621 for(int i
= 0; i
< GetCount(); i
++) {
622 wxString
str(GetString(i
));
626 ::GetThemeTextDimensions( wxMacCFStringHolder( str
) ,
627 kThemeCurrentPortFont
,
634 wxCharBuffer text
= wxMacStringToCString( str
) ;
635 wLine
= ::TextWidth( text
, 0 , strlen(text
) ) ;
637 lbWidth
= wxMax(lbWidth
, wLine
);
640 // Add room for the scrollbar
641 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
643 // And just a bit more
645 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
648 // don't make the listbox too tall (limit height to around 10 items) but don't
649 // make it too small neither
650 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
652 return wxSize(lbWidth
, lbHeight
);
655 int wxListBox::GetCount() const
660 void wxListBox::SetupColours()
662 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
663 SetForegroundColour(GetParent()->GetForegroundColour());
666 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
668 wxControl::Refresh( eraseBack
, rect
) ;
669 // MacRedrawControl() ;
672 #if wxUSE_OWNER_DRAWN
674 class wxListBoxItem
: public wxOwnerDrawn
677 wxListBoxItem(const wxString
& str
= "");
680 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
682 // no bitmaps/checkmarks
686 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
688 return new wxListBoxItem();
691 #endif //USE_OWNER_DRAWN
693 // ============================================================================
694 // list box control implementation
695 // ============================================================================
698 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
701 // typecast our refCon
702 list = (wxListBox*)refCon;
704 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
705 const wxString text = list->m_stringArray[lCell.v] ;
706 ::TextFont( kFontIDMonaco ) ;
709 DrawText(text, 0 , text.Length());
713 void wxListBox::MacDelete( int N
)
715 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
719 void wxListBox::MacInsert( int n
, const wxString
& text
)
721 Cell cell
= { 0 , 0 } ;
723 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
724 // LSetCell(text, strlen(text), cell, m_macList);
728 void wxListBox::MacAppend( const wxString
& text
)
730 Cell cell
= { 0 , 0 } ;
731 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
732 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
733 // LSetCell(text, strlen(text), cell, m_macList);
737 void wxListBox::MacClear()
739 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
743 void wxListBox::MacSetSelection( int n
, bool select
)
745 Cell cell
= { 0 , 0 } ;
746 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
748 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
750 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
755 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
756 LAutoScroll( (ListHandle
)m_macList
) ;
760 bool wxListBox::MacIsSelected( int n
) const
762 Cell cell
= { 0 , 0 } ;
764 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
767 void wxListBox::MacDestroy()
769 // DisposeExtLDEFInfo( m_macList ) ;
772 int wxListBox::MacGetSelection() const
774 Cell cell
= { 0 , 0 } ;
775 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
781 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
787 Cell cell
= { 0 , 0 } ;
790 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
792 aSelections
.Add( cell
.v
) ;
799 void wxListBox::MacSet( int n
, const wxString
& text
)
801 // our implementation does not store anything in the list
802 // so we just have to redraw
803 Cell cell
= { 0 , 0 } ;
805 // LSetCell(text, strlen(text), cell, m_macList);
809 void wxListBox::MacScrollTo( int n
)
811 // TODO implement scrolling
814 void wxListBox::OnSize( const wxSizeEvent
&event
)
819 GetListCellSize((ListHandle
)m_macList
, &pt
);
821 pt
= (**(ListHandle
)m_macList
).cellSize
;
823 pt
.h
= m_width
- 15 ;
824 LCellSize( pt
, (ListHandle
)m_macList
) ;
827 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
)
829 Boolean wasDoubleClick
= false ;
832 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
833 if ( !wasDoubleClick
)
843 void wxListBox::MacSetRedraw( bool doDraw
)
845 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
849 void wxListBox::MacDoClick()
851 wxArrayInt aSelections
;
853 size_t count
= GetSelections(aSelections
);
855 if ( count
== m_selectionPreImage
.GetCount() )
857 bool hasChanged
= false ;
858 for ( size_t i
= 0 ; i
< count
; ++i
)
860 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
872 m_selectionPreImage
= aSelections
;
874 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
875 event
.SetEventObject( this );
880 if ( HasClientObjectData() )
881 event
.SetClientObject( GetClientObject(n
) );
882 else if ( HasClientUntypedData() )
883 event
.SetClientData( GetClientData(n
) );
884 event
.SetString( GetString(n
) );
891 event
.m_commandInt
= n
;
893 GetEventHandler()->ProcessEvent(event
);
896 void wxListBox::MacDoDoubleClick()
898 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
899 event
.SetEventObject( this );
900 GetEventHandler()->ProcessEvent(event
) ;
903 void wxListBox::OnChar(wxKeyEvent
& event
)
905 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
907 wxWindow
* parent
= GetParent() ;
908 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
909 parent
= parent
->GetParent() ;
911 if ( parent
&& parent
->GetDefaultItem() )
913 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
915 if ( def
&& def
->IsEnabled() )
917 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
918 event
.SetEventObject(def
);
925 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
926 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
928 // FIXME: look in ancestors, not just parent.
929 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
932 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
933 new_event
.SetEventObject( win
);
934 win
->GetEventHandler()->ProcessEvent( new_event
);
937 else if ( event
.GetKeyCode() == WXK_TAB
)
939 wxNavigationKeyEvent new_event
;
940 new_event
.SetEventObject( this );
941 new_event
.SetDirection( !event
.ShiftDown() );
942 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
943 new_event
.SetWindowChange( event
.ControlDown() );
944 new_event
.SetCurrentFocus( this );
945 if ( !GetEventHandler()->ProcessEvent( new_event
) )
948 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
950 // perform the default key handling first
951 wxControl::OnKeyDown( event
) ;
953 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
954 event
.SetEventObject( this );
956 wxArrayInt aSelections
;
957 int n
, count
= GetSelections(aSelections
);
961 if ( HasClientObjectData() )
962 event
.SetClientObject( GetClientObject(n
) );
963 else if ( HasClientUntypedData() )
964 event
.SetClientData( GetClientData(n
) );
965 event
.SetString( GetString(n
) );
972 event
.m_commandInt
= n
;
974 GetEventHandler()->ProcessEvent(event
);
978 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
980 m_typeIn
= wxEmptyString
;
982 m_lastTypeIn
= event
.GetTimestamp() ;
983 m_typeIn
+= (char) event
.GetKeyCode() ;
984 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
987 if ( GetSelection() != line
)
990 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
991 event
.SetEventObject( this );
993 if ( HasClientObjectData() )
994 event
.SetClientObject( GetClientObject( line
) );
995 else if ( HasClientUntypedData() )
996 event
.SetClientData( GetClientData(line
) );
997 event
.SetString( GetString(line
) );
999 event
.m_commandInt
= line
;
1001 GetEventHandler()->ProcessEvent(event
);