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
, list
->GetFont().GetEncoding()) ) ;
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 const wxArrayString
& choices
,
201 const wxValidator
& validator
,
202 const wxString
& name
)
204 wxCArrayString
chs(choices
);
206 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
207 style
, validator
, name
);
210 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
213 int n
, const wxString choices
[],
215 const wxValidator
& validator
,
216 const wxString
& name
)
218 if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
221 m_noItems
= 0 ; // this will be increased by our append command
227 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
230 listDef
.defType
= kListDefUserProcType
;
231 if ( macListDefUPP
== NULL
)
233 macListDefUPP
= NewListDefUPP( wxMacListDefinition
);
235 listDef
.u
.userProc
= macListDefUPP
;
241 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
243 GetFontName( kFontIDMonaco
, fontName
) ;
247 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) ) ) ;
252 CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, (style
& wxLB_HSCROLL
), true,
253 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
255 GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
256 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
258 SetControlReference( (ControlHandle
) m_macControl
, (long) this);
259 SetControlVisibility( (ControlHandle
) m_macControl
, false, false);
264 wxStAppResource resload
;
265 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false ,
266 (style
& wxLB_HSCROLL
) ? kwxMacListWithVerticalAndHorizontalScrollbar
: kwxMacListWithVerticalScrollbar
,
267 0 , 0, kControlListBoxProc
, (long) this ) ;
268 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
269 sizeof( ListHandle
) , (char*) &m_macList
, &result
) ;
271 HLock( (Handle
) m_macList
) ;
273 ldef
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ;
274 if ( (**(ListHandle
)m_macList
).listDefProc
!= NULL
)
276 (**ldef
).instruction
= 0x4EF9; /* JMP instruction */
277 (**ldef
).function
= (void(*)()) listDef
.u
.userProc
;
278 (**(ListHandle
)m_macList
).listDefProc
= (Handle
) ldef
;
281 Point pt
= (**(ListHandle
)m_macList
).cellSize
;
282 pt
.v
= kwxMacListItemHeight
;
283 LCellSize( pt
, (ListHandle
)m_macList
) ;
284 LAddColumn( 1 , 0 , (ListHandle
)m_macList
) ;
286 OptionBits options
= 0;
287 if ( style
& wxLB_MULTIPLE
)
289 options
+= lNoExtend
;
291 else if ( style
& wxLB_EXTENDED
)
293 options
+= lExtendDrag
;
297 options
= (OptionBits
) lOnlyOne
;
299 SetListSelectionFlags((ListHandle
)m_macList
, options
);
301 for ( int i
= 0 ; i
< n
; i
++ )
303 Append( choices
[i
] ) ;
306 MacPostControlCreate() ;
308 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
313 wxListBox::~wxListBox()
319 DisposeHandle( (**(ListHandle
)m_macList
).listDefProc
) ;
320 (**(ListHandle
)m_macList
).listDefProc
= NULL
;
326 void wxListBox::FreeData()
328 #if wxUSE_OWNER_DRAWN
329 if ( m_windowStyle
& wxLB_OWNERDRAW
)
331 size_t uiCount
= m_aItems
.Count();
332 while ( uiCount
-- != 0 ) {
333 delete m_aItems
[uiCount
];
334 m_aItems
[uiCount
] = NULL
;
340 #endif // wxUSE_OWNER_DRAWN
341 if ( HasClientObjectData() )
343 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
345 delete GetClientObject(n
);
350 void wxListBox::DoSetSize(int x
, int y
,
351 int width
, int height
,
354 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
357 GetControlBounds( (ControlHandle
) m_macControl
, &bounds
) ;
358 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
362 GetControlBounds( control
, &scrollbounds
) ;
363 if( scrollbounds
.right
!= bounds
.right
+ 1 )
365 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
371 void wxListBox::DoSetFirstItem(int N
)
376 void wxListBox::Delete(int N
)
378 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
379 wxT("invalid index in wxListBox::Delete") );
381 #if wxUSE_OWNER_DRAWN
383 m_aItems
.RemoveAt(N
);
384 #else // !wxUSE_OWNER_DRAWN
385 if ( HasClientObjectData() )
387 delete GetClientObject(N
);
389 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
390 m_stringArray
.RemoveAt( N
) ;
391 m_dataArray
.RemoveAt( N
) ;
397 int wxListBox::DoAppend(const wxString
& item
)
399 int index
= m_noItems
;
400 m_stringArray
.Add( item
) ;
401 m_dataArray
.Add( NULL
);
403 DoSetItemClientData( index
, NULL
) ;
409 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
411 MacSetRedraw( false ) ;
413 int n
= choices
.GetCount();
415 for( int i
= 0 ; i
< n
; ++i
)
419 #if wxUSE_OWNER_DRAWN
420 wxASSERT_MSG(clientData
[i
] == NULL
,
421 wxT("Can't use client data with owner-drawn listboxes"));
422 #else // !wxUSE_OWNER_DRAWN
423 Append( choices
[i
] , clientData
[i
] ) ;
427 Append( choices
[i
] ) ;
430 #if wxUSE_OWNER_DRAWN
431 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
432 // first delete old items
433 size_t ui
= m_aItems
.Count();
434 while ( ui
-- != 0 ) {
440 // then create new ones
441 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
442 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
443 pNewItem
->SetName(choices
[ui
]);
444 m_aItems
.Add(pNewItem
);
447 #endif // wxUSE_OWNER_DRAWN
448 MacSetRedraw( true ) ;
451 bool wxListBox::HasMultipleSelection() const
453 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
456 int wxListBox::FindString(const wxString
& s
) const
459 if ( s
.Right(1) == wxT("*") )
461 wxString search
= s
.Left( s
.Length() - 1 ) ;
462 int len
= search
.Length() ;
464 wxMacStringToPascal( search
, s2
) ;
466 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
468 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
470 if ( EqualString( s1
, s2
, false , false ) )
473 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
477 for ( int i
= 0 ; i
< m_noItems
; ++i
)
479 if ( GetString(i
).Lower().Matches(st
) )
489 wxMacStringToPascal( s
, s2
) ;
491 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
493 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
495 if ( EqualString( s1
, s2
, false , false ) )
502 void wxListBox::Clear()
506 m_stringArray
.Empty() ;
507 m_dataArray
.Empty() ;
511 void wxListBox::SetSelection(int N
, bool select
)
513 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
514 wxT("invalid index in wxListBox::SetSelection") );
515 MacSetSelection( N
, select
) ;
516 GetSelections( m_selectionPreImage
) ;
519 bool wxListBox::IsSelected(int N
) const
521 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
522 wxT("invalid index in wxListBox::Selected") );
524 return MacIsSelected( N
) ;
527 void *wxListBox::DoGetItemClientData(int N
) const
529 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
530 wxT("invalid index in wxListBox::GetClientData"));
532 return (void *)m_dataArray
[N
];
535 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
537 return (wxClientData
*) DoGetItemClientData( N
) ;
540 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
542 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
543 wxT("invalid index in wxListBox::SetClientData") );
545 #if wxUSE_OWNER_DRAWN
546 if ( m_windowStyle
& wxLB_OWNERDRAW
)
548 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
549 // in OnMeasure/OnDraw.
550 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
552 #endif // wxUSE_OWNER_DRAWN
553 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
555 if ( m_dataArray
.GetCount() > (size_t) N
)
557 m_dataArray
[N
] = (char*) Client_data
;
561 m_dataArray
.Add( (char*) Client_data
) ;
565 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
567 DoSetItemClientData(n
, clientData
);
570 // Return number of selections and an array of selected integers
571 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
573 return MacGetSelections( aSelections
) ;
576 // Get single selection, for single choice list items
577 int wxListBox::GetSelection() const
579 return MacGetSelection() ;
582 // Find string for position
583 wxString
wxListBox::GetString(int N
) const
585 return m_stringArray
[N
] ;
588 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
590 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
591 wxT("invalid index in wxListBox::InsertItems") );
593 int nItems
= items
.GetCount();
595 for ( int i
= 0 ; i
< nItems
; i
++ )
597 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
598 m_dataArray
.Insert( NULL
, pos
+ i
) ;
599 MacInsert( pos
+ i
, items
[i
] ) ;
605 void wxListBox::SetString(int N
, const wxString
& s
)
607 m_stringArray
[N
] = s
;
611 wxSize
wxListBox::DoGetBestSize() const
613 int lbWidth
= 100; // some defaults
618 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
622 ::TextFont( m_font
.GetMacFontNum() ) ;
623 ::TextSize( m_font
.GetMacFontSize() ) ;
624 ::TextFace( m_font
.GetMacFontStyle() ) ;
628 ::TextFont( kFontIDMonaco
) ;
633 // Find the widest line
634 for(int i
= 0; i
< GetCount(); i
++) {
635 wxString
str(GetString(i
));
639 ::GetThemeTextDimensions( wxMacCFStringHolder( str
, m_font
.GetEncoding() ) ,
640 kThemeCurrentPortFont
,
647 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
649 lbWidth
= wxMax(lbWidth
, wLine
);
652 // Add room for the scrollbar
653 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
655 // And just a bit more
657 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
660 // don't make the listbox too tall (limit height to around 10 items) but don't
661 // make it too small neither
662 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
664 return wxSize(lbWidth
, lbHeight
);
667 int wxListBox::GetCount() const
672 void wxListBox::SetupColours()
674 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
675 SetForegroundColour(GetParent()->GetForegroundColour());
678 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
680 wxControl::Refresh( eraseBack
, rect
) ;
681 // MacRedrawControl() ;
684 #if wxUSE_OWNER_DRAWN
686 class wxListBoxItem
: public wxOwnerDrawn
689 wxListBoxItem(const wxString
& str
= "");
692 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
694 // no bitmaps/checkmarks
698 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
700 return new wxListBoxItem();
703 #endif //USE_OWNER_DRAWN
705 // ============================================================================
706 // list box control implementation
707 // ============================================================================
710 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
713 // typecast our refCon
714 list = (wxListBox*)refCon;
716 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
717 const wxString text = list->m_stringArray[lCell.v] ;
718 ::TextFont( kFontIDMonaco ) ;
721 DrawText(text, 0 , text.Length());
725 void wxListBox::MacDelete( int N
)
727 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
731 void wxListBox::MacInsert( int n
, const wxString
& text
)
733 Cell cell
= { 0 , 0 } ;
735 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
736 // LSetCell(text, strlen(text), cell, m_macList);
740 void wxListBox::MacAppend( const wxString
& text
)
742 Cell cell
= { 0 , 0 } ;
743 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
744 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
745 // LSetCell(text, strlen(text), cell, m_macList);
749 void wxListBox::MacClear()
751 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
755 void wxListBox::MacSetSelection( int n
, bool select
)
757 Cell cell
= { 0 , 0 } ;
758 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
760 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
762 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
767 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
768 LAutoScroll( (ListHandle
)m_macList
) ;
772 bool wxListBox::MacIsSelected( int n
) const
774 Cell cell
= { 0 , 0 } ;
776 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
779 void wxListBox::MacDestroy()
781 // DisposeExtLDEFInfo( m_macList ) ;
784 int wxListBox::MacGetSelection() const
786 Cell cell
= { 0 , 0 } ;
787 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
793 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
799 Cell cell
= { 0 , 0 } ;
802 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
804 aSelections
.Add( cell
.v
) ;
811 void wxListBox::MacSet( int n
, const wxString
& text
)
813 // our implementation does not store anything in the list
814 // so we just have to redraw
815 Cell cell
= { 0 , 0 } ;
817 // LSetCell(text, strlen(text), cell, m_macList);
821 void wxListBox::MacScrollTo( int n
)
823 // TODO implement scrolling
826 void wxListBox::OnSize( wxSizeEvent
&event
)
831 GetListCellSize((ListHandle
)m_macList
, &pt
);
833 pt
= (**(ListHandle
)m_macList
).cellSize
;
835 pt
.h
= m_width
- 15 ;
836 LCellSize( pt
, (ListHandle
)m_macList
) ;
839 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
841 Boolean wasDoubleClick
= false ;
844 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
845 if ( !wasDoubleClick
)
855 void wxListBox::MacSetRedraw( bool doDraw
)
857 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
861 void wxListBox::MacDoClick()
863 wxArrayInt aSelections
;
865 size_t count
= GetSelections(aSelections
);
867 if ( count
== m_selectionPreImage
.GetCount() )
869 bool hasChanged
= false ;
870 for ( size_t i
= 0 ; i
< count
; ++i
)
872 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
884 m_selectionPreImage
= aSelections
;
886 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
887 event
.SetEventObject( this );
892 if ( HasClientObjectData() )
893 event
.SetClientObject( GetClientObject(n
) );
894 else if ( HasClientUntypedData() )
895 event
.SetClientData( GetClientData(n
) );
896 event
.SetString( GetString(n
) );
903 event
.m_commandInt
= n
;
905 GetEventHandler()->ProcessEvent(event
);
908 void wxListBox::MacDoDoubleClick()
910 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
911 event
.SetEventObject( this );
912 GetEventHandler()->ProcessEvent(event
) ;
915 void wxListBox::OnChar(wxKeyEvent
& event
)
917 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
919 wxWindow
* parent
= GetParent() ;
920 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
921 parent
= parent
->GetParent() ;
923 if ( parent
&& parent
->GetDefaultItem() )
925 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
927 if ( def
&& def
->IsEnabled() )
929 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
930 event
.SetEventObject(def
);
937 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
938 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
940 // FIXME: look in ancestors, not just parent.
941 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
944 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
945 new_event
.SetEventObject( win
);
946 win
->GetEventHandler()->ProcessEvent( new_event
);
949 else if ( event
.GetKeyCode() == WXK_TAB
)
951 wxNavigationKeyEvent new_event
;
952 new_event
.SetEventObject( this );
953 new_event
.SetDirection( !event
.ShiftDown() );
954 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
955 new_event
.SetWindowChange( event
.ControlDown() );
956 new_event
.SetCurrentFocus( this );
957 if ( !GetEventHandler()->ProcessEvent( new_event
) )
960 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
962 // perform the default key handling first
963 wxControl::OnKeyDown( event
) ;
965 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
966 event
.SetEventObject( this );
968 wxArrayInt aSelections
;
969 int n
, count
= GetSelections(aSelections
);
973 if ( HasClientObjectData() )
974 event
.SetClientObject( GetClientObject(n
) );
975 else if ( HasClientUntypedData() )
976 event
.SetClientData( GetClientData(n
) );
977 event
.SetString( GetString(n
) );
984 event
.m_commandInt
= n
;
986 GetEventHandler()->ProcessEvent(event
);
990 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
992 m_typeIn
= wxEmptyString
;
994 m_lastTypeIn
= event
.GetTimestamp() ;
995 m_typeIn
+= (char) event
.GetKeyCode() ;
996 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
999 if ( GetSelection() != line
)
1001 SetSelection(line
) ;
1002 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1003 event
.SetEventObject( this );
1005 if ( HasClientObjectData() )
1006 event
.SetClientObject( GetClientObject( line
) );
1007 else if ( HasClientUntypedData() )
1008 event
.SetClientData( GetClientData(line
) );
1009 event
.SetString( GetString(line
) );
1011 event
.m_commandInt
= line
;
1013 GetEventHandler()->ProcessEvent(event
);