1 ///////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
13 #include "wx/listbox.h"
14 #include "wx/button.h"
15 #include "wx/settings.h"
16 #include "wx/toplevel.h"
17 #include "wx/dynarray.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
24 BEGIN_EVENT_TABLE(wxListBox
, wxControl
)
25 EVT_SIZE( wxListBox::OnSize
)
26 EVT_CHAR( wxListBox::OnChar
)
29 #include "wx/mac/uma.h"
31 #if PRAGMA_STRUCT_ALIGN
32 #pragma options align=mac68k
33 #elif PRAGMA_STRUCT_PACKPUSH
35 #elif PRAGMA_STRUCT_PACK
40 unsigned short instruction
;
42 } ldefRec
, *ldefPtr
, **ldefHandle
;
44 #if PRAGMA_STRUCT_ALIGN
45 #pragma options align=reset
46 #elif PRAGMA_STRUCT_PACKPUSH
48 #elif PRAGMA_STRUCT_PACK
53 const short kwxMacListItemHeight
= 19 ;
55 const short kwxMacListItemHeight
= 14 ;
60 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect
*drawRect
,
61 Cell cell
, short dataOffset
, short dataLength
,
62 ListHandle listHandle
) ;
65 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect
*drawRect
,
66 Cell cell
, short dataOffset
, short dataLength
,
67 ListHandle listHandle
)
70 list
= (wxListBox
*) GetControlReference( (ControlHandle
) GetListRefCon(listHandle
) );
76 RgnHandle savedClipRegion
;
79 SetPort((**listHandle
).port
);
80 grafPtr
= (**listHandle
).port
;
81 // typecast our refCon
83 // Calculate the cell rect.
94 const wxString linetext
= list
->m_stringArray
[cell
.v
] ;
96 // Save the current clip region, and set the clip region to the area we are about
99 savedClipRegion
= NewRgn();
100 GetClip( savedClipRegion
);
102 ClipRect( drawRect
);
103 EraseRect( drawRect
);
105 const wxFont
& font
= list
->GetFont();
108 ::TextFont( font
.GetMacFontNum() ) ;
109 ::TextSize( font
.GetMacFontSize() ) ;
110 ::TextFace( font
.GetMacFontStyle() ) ;
114 ::TextFont( kFontIDMonaco
) ;
121 Rect frame
= { drawRect
->top
, drawRect
->left
+ 4,
122 drawRect
->top
+ kwxMacListItemHeight
, drawRect
->right
+ 10000 } ;
123 CFMutableStringRef mString
= CFStringCreateMutableCopy( NULL
, 0 , wxMacCFStringHolder(linetext
, list
->GetFont().GetEncoding()) ) ;
124 ::TruncateThemeText( mString
, kThemeCurrentPortFont
, kThemeStateActive
, drawRect
->right
- drawRect
->left
, truncEnd
, NULL
) ;
125 ::DrawThemeTextBox( mString
,
126 kThemeCurrentPortFont
,
132 CFRelease( mString
) ;
136 wxCharBuffer text
= linetext
.mb_str( wxConvLocal
) ;
137 MoveTo(drawRect
->left
+ 4 , drawRect
->top
+ 10 );
138 DrawText(text
, 0 , strlen(text
) );
141 // If the cell is hilited, do the hilite now. Paint the cell contents with the
142 // appropriate QuickDraw transform mode.
145 savedPenMode
= GetPortPenMode( (CGrafPtr
) grafPtr
);
146 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
147 PaintRect( drawRect
);
148 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
151 // Restore the saved clip region.
153 SetClip( savedClipRegion
);
154 DisposeRgn( savedClipRegion
);
159 // Hilite or unhilite the cell. Paint the cell contents with the
160 // appropriate QuickDraw transform mode.
163 savedPenMode
= GetPortPenMode( (CGrafPtr
)grafPtr
);
164 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
165 PaintRect( drawRect
);
166 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
174 extern "C" void MacDrawStringCell(Rect
*cellRect
, Cell lCell
, ListHandle theList
, long refCon
) ;
175 // resources ldef ids
176 const short kwxMacListWithVerticalScrollbar
= 128 ;
177 const short kwxMacListWithVerticalAndHorizontalScrollbar
= 129 ;
179 // ============================================================================
180 // list box control implementation
181 // ============================================================================
184 wxListBox::wxListBox()
191 static ListDefUPP macListDefUPP
= NULL
;
193 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
196 const wxArrayString
& choices
,
198 const wxValidator
& validator
,
199 const wxString
& name
)
201 wxCArrayString
chs(choices
);
203 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
204 style
, validator
, name
);
207 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
210 int n
, const wxString choices
[],
212 const wxValidator
& validator
,
213 const wxString
& name
)
215 if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
218 m_noItems
= 0 ; // this will be increased by our append command
224 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
227 listDef
.defType
= kListDefUserProcType
;
228 if ( macListDefUPP
== NULL
)
230 macListDefUPP
= NewListDefUPP( wxMacListDefinition
);
232 listDef
.u
.userProc
= macListDefUPP
;
238 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
240 GetFontName( kFontIDMonaco
, fontName
) ;
244 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) ) ) ;
249 CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, (style
& wxLB_HSCROLL
), true,
250 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
252 GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
253 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
255 SetControlReference( (ControlHandle
) m_macControl
, (long) this);
256 SetControlVisibility( (ControlHandle
) m_macControl
, false, false);
261 wxStAppResource resload
;
262 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false ,
263 (style
& wxLB_HSCROLL
) ? kwxMacListWithVerticalAndHorizontalScrollbar
: kwxMacListWithVerticalScrollbar
,
264 0 , 0, kControlListBoxProc
, (long) this ) ;
265 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
266 sizeof( ListHandle
) , (char*) &m_macList
, &result
) ;
268 HLock( (Handle
) m_macList
) ;
270 ldef
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ;
271 if ( (**(ListHandle
)m_macList
).listDefProc
!= NULL
)
273 (**ldef
).instruction
= 0x4EF9; /* JMP instruction */
274 (**ldef
).function
= (void(*)()) listDef
.u
.userProc
;
275 (**(ListHandle
)m_macList
).listDefProc
= (Handle
) ldef
;
278 Point pt
= (**(ListHandle
)m_macList
).cellSize
;
279 pt
.v
= kwxMacListItemHeight
;
280 LCellSize( pt
, (ListHandle
)m_macList
) ;
281 LAddColumn( 1 , 0 , (ListHandle
)m_macList
) ;
283 OptionBits options
= 0;
284 if ( style
& wxLB_MULTIPLE
)
286 options
+= lExtendDrag
+ lUseSense
;
288 else if ( style
& wxLB_EXTENDED
)
294 options
= (OptionBits
) lOnlyOne
;
296 SetListSelectionFlags((ListHandle
)m_macList
, options
);
298 for ( int i
= 0 ; i
< n
; i
++ )
300 Append( choices
[i
] ) ;
303 MacPostControlCreate() ;
305 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
310 wxListBox::~wxListBox()
313 // avoid access during destruction
314 SetControlReference( (ControlHandle
) m_macControl
, NULL
) ;
318 DisposeHandle( (**(ListHandle
)m_macList
).listDefProc
) ;
319 (**(ListHandle
)m_macList
).listDefProc
= NULL
;
325 void wxListBox::FreeData()
327 #if wxUSE_OWNER_DRAWN
328 if ( m_windowStyle
& wxLB_OWNERDRAW
)
330 size_t uiCount
= m_aItems
.Count();
331 while ( uiCount
-- != 0 ) {
332 delete m_aItems
[uiCount
];
333 m_aItems
[uiCount
] = NULL
;
339 #endif // wxUSE_OWNER_DRAWN
340 if ( HasClientObjectData() )
342 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
344 delete GetClientObject(n
);
349 void wxListBox::DoSetSize(int x
, int y
,
350 int width
, int height
,
353 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
356 GetControlBounds( (ControlHandle
) m_macControl
, &bounds
) ;
357 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
361 GetControlBounds( control
, &scrollbounds
) ;
362 if( scrollbounds
.right
!= bounds
.right
+ 1 )
364 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
370 void wxListBox::DoSetFirstItem(int N
)
375 void wxListBox::Delete(int N
)
377 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
378 wxT("invalid index in wxListBox::Delete") );
380 #if wxUSE_OWNER_DRAWN
382 m_aItems
.RemoveAt(N
);
383 #else // !wxUSE_OWNER_DRAWN
384 if ( HasClientObjectData() )
386 delete GetClientObject(N
);
388 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
389 m_stringArray
.RemoveAt( N
) ;
390 m_dataArray
.RemoveAt( N
) ;
396 int wxListBox::DoAppend(const wxString
& item
)
398 InvalidateBestSize();
400 int index
= m_noItems
;
401 m_stringArray
.Add( item
) ;
402 m_dataArray
.Add( NULL
);
404 DoSetItemClientData( index
, NULL
) ;
410 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
412 MacSetRedraw( false ) ;
414 int n
= choices
.GetCount();
416 for( int i
= 0 ; i
< n
; ++i
)
420 #if wxUSE_OWNER_DRAWN
421 wxASSERT_MSG(clientData
[i
] == NULL
,
422 wxT("Can't use client data with owner-drawn listboxes"));
423 #else // !wxUSE_OWNER_DRAWN
424 Append( choices
[i
] , clientData
[i
] ) ;
428 Append( choices
[i
] ) ;
431 #if wxUSE_OWNER_DRAWN
432 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
433 // first delete old items
434 size_t ui
= m_aItems
.Count();
435 while ( ui
-- != 0 ) {
441 // then create new ones
442 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
443 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
444 pNewItem
->SetName(choices
[ui
]);
445 m_aItems
.Add(pNewItem
);
448 #endif // wxUSE_OWNER_DRAWN
449 MacSetRedraw( true ) ;
452 bool wxListBox::HasMultipleSelection() const
454 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
457 int wxListBox::FindString(const wxString
& s
) const
460 if ( s
.Right(1) == wxT("*") )
462 wxString search
= s
.Left( s
.Length() - 1 ) ;
463 int len
= search
.Length() ;
465 wxMacStringToPascal( search
, s2
) ;
467 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
469 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
471 if ( EqualString( s1
, s2
, false , false ) )
474 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
478 for ( int i
= 0 ; i
< m_noItems
; ++i
)
480 if ( GetString(i
).Lower().Matches(st
) )
490 wxMacStringToPascal( s
, s2
) ;
492 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
494 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
496 if ( EqualString( s1
, s2
, false , false ) )
503 void wxListBox::Clear()
507 m_stringArray
.Empty() ;
508 m_dataArray
.Empty() ;
512 void wxListBox::DoSetSelection(int N
, bool select
)
514 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
515 wxT("invalid index in wxListBox::SetSelection") );
516 MacSetSelection( N
, select
) ;
517 GetSelections( m_selectionPreImage
) ;
520 bool wxListBox::IsSelected(int N
) const
522 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
523 wxT("invalid index in wxListBox::Selected") );
525 return MacIsSelected( N
) ;
528 void *wxListBox::DoGetItemClientData(int N
) const
530 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
531 wxT("invalid index in wxListBox::GetClientData"));
533 return (void *)m_dataArray
[N
];
536 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
538 return (wxClientData
*) DoGetItemClientData( N
) ;
541 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
543 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
544 wxT("invalid index in wxListBox::SetClientData") );
546 #if wxUSE_OWNER_DRAWN
547 if ( m_windowStyle
& wxLB_OWNERDRAW
)
549 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
550 // in OnMeasure/OnDraw.
551 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
553 #endif // wxUSE_OWNER_DRAWN
554 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
556 if ( m_dataArray
.GetCount() > (size_t) N
)
558 m_dataArray
[N
] = (char*) Client_data
;
562 m_dataArray
.Add( (char*) Client_data
) ;
566 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
568 DoSetItemClientData(n
, clientData
);
571 // Return number of selections and an array of selected integers
572 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
574 return MacGetSelections( aSelections
) ;
577 // Get single selection, for single choice list items
578 int wxListBox::GetSelection() const
580 return MacGetSelection() ;
583 // Find string for position
584 wxString
wxListBox::GetString(int N
) const
586 return m_stringArray
[N
] ;
589 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
591 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
592 wxT("invalid index in wxListBox::InsertItems") );
594 InvalidateBestSize();
596 int nItems
= items
.GetCount();
598 for ( int i
= 0 ; i
< nItems
; i
++ )
600 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
601 m_dataArray
.Insert( NULL
, pos
+ i
) ;
602 MacInsert( pos
+ i
, items
[i
] ) ;
608 void wxListBox::SetString(int N
, const wxString
& s
)
610 m_stringArray
[N
] = s
;
614 wxSize
wxListBox::DoGetBestSize() const
616 int lbWidth
= 100; // some defaults
621 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
625 ::TextFont( m_font
.GetMacFontNum() ) ;
626 ::TextSize( m_font
.GetMacFontSize() ) ;
627 ::TextFace( m_font
.GetMacFontStyle() ) ;
631 ::TextFont( kFontIDMonaco
) ;
636 // Find the widest line
637 for(int i
= 0; i
< GetCount(); i
++) {
638 wxString
str(GetString(i
));
642 ::GetThemeTextDimensions( wxMacCFStringHolder( str
, m_font
.GetEncoding() ) ,
643 kThemeCurrentPortFont
,
650 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
652 lbWidth
= wxMax(lbWidth
, wLine
);
655 // Add room for the scrollbar
656 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
658 // And just a bit more
660 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
663 // don't make the listbox too tall (limit height to around 10 items) but don't
664 // make it too small neither
665 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
667 return wxSize(lbWidth
, lbHeight
);
670 int wxListBox::GetCount() const
675 void wxListBox::SetupColours()
677 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
678 SetForegroundColour(GetParent()->GetForegroundColour());
681 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
683 wxControl::Refresh( eraseBack
, rect
) ;
684 // MacRedrawControl() ;
687 #if wxUSE_OWNER_DRAWN
689 class wxListBoxItem
: public wxOwnerDrawn
692 wxListBoxItem(const wxString
& str
= "");
695 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
697 // no bitmaps/checkmarks
701 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
703 return new wxListBoxItem();
706 #endif //USE_OWNER_DRAWN
708 // ============================================================================
709 // list box control implementation
710 // ============================================================================
713 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
716 // typecast our refCon
717 list = (wxListBox*)refCon;
719 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
720 const wxString text = list->m_stringArray[lCell.v] ;
721 ::TextFont( kFontIDMonaco ) ;
724 DrawText(text, 0 , text.Length());
728 void wxListBox::MacDelete( int N
)
730 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
734 void wxListBox::MacInsert( int n
, const wxString
& text
)
736 Cell cell
= { 0 , 0 } ;
738 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
739 // LSetCell(text, strlen(text), cell, m_macList);
743 void wxListBox::MacAppend( const wxString
& text
)
745 Cell cell
= { 0 , 0 } ;
746 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
747 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
748 // LSetCell(text, strlen(text), cell, m_macList);
752 void wxListBox::MacClear()
754 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
758 void wxListBox::MacSetSelection( int n
, bool select
)
760 Cell cell
= { 0 , 0 } ;
761 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
763 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
765 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
770 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
771 LAutoScroll( (ListHandle
)m_macList
) ;
775 bool wxListBox::MacIsSelected( int n
) const
777 Cell cell
= { 0 , 0 } ;
779 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
782 void wxListBox::MacDestroy()
784 // DisposeExtLDEFInfo( m_macList ) ;
787 int wxListBox::MacGetSelection() const
789 Cell cell
= { 0 , 0 } ;
790 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
796 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
802 Cell cell
= { 0 , 0 } ;
805 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
807 aSelections
.Add( cell
.v
) ;
814 void wxListBox::MacSet( int n
, const wxString
& text
)
816 // our implementation does not store anything in the list
817 // so we just have to redraw
818 Cell cell
= { 0 , 0 } ;
820 // LSetCell(text, strlen(text), cell, m_macList);
824 void wxListBox::MacScrollTo( int n
)
826 // TODO implement scrolling
829 void wxListBox::OnSize( wxSizeEvent
&event
)
834 GetListCellSize((ListHandle
)m_macList
, &pt
);
836 pt
= (**(ListHandle
)m_macList
).cellSize
;
838 pt
.h
= m_width
- 15 ;
839 LCellSize( pt
, (ListHandle
)m_macList
) ;
842 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
844 Boolean wasDoubleClick
= false ;
847 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
848 if ( !wasDoubleClick
)
858 void wxListBox::MacSetRedraw( bool doDraw
)
860 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
864 void wxListBox::MacDoClick()
866 wxArrayInt aSelections
;
868 size_t count
= GetSelections(aSelections
);
870 if ( count
== m_selectionPreImage
.GetCount() )
872 bool hasChanged
= false ;
873 for ( size_t i
= 0 ; i
< count
; ++i
)
875 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
887 m_selectionPreImage
= aSelections
;
889 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
890 event
.SetEventObject( this );
895 if ( HasClientObjectData() )
896 event
.SetClientObject( GetClientObject(n
) );
897 else if ( HasClientUntypedData() )
898 event
.SetClientData( GetClientData(n
) );
899 event
.SetString( GetString(n
) );
908 GetEventHandler()->ProcessEvent(event
);
911 void wxListBox::MacDoDoubleClick()
913 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
914 event
.SetEventObject( this );
915 GetEventHandler()->ProcessEvent(event
) ;
918 void wxListBox::OnChar(wxKeyEvent
& event
)
920 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
922 wxWindow
* parent
= GetParent() ;
923 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
924 parent
= parent
->GetParent() ;
926 if ( parent
&& parent
->GetDefaultItem() )
928 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
930 if ( def
&& def
->IsEnabled() )
932 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
933 event
.SetEventObject(def
);
940 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
941 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
943 // FIXME: look in ancestors, not just parent.
944 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
947 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
948 new_event
.SetEventObject( win
);
949 win
->GetEventHandler()->ProcessEvent( new_event
);
952 else if ( event
.GetKeyCode() == WXK_TAB
)
954 wxNavigationKeyEvent new_event
;
955 new_event
.SetEventObject( this );
956 new_event
.SetDirection( !event
.ShiftDown() );
957 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
958 new_event
.SetWindowChange( event
.ControlDown() );
959 new_event
.SetCurrentFocus( this );
960 if ( !GetEventHandler()->ProcessEvent( new_event
) )
963 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
965 // perform the default key handling first
966 wxControl::OnKeyDown( event
) ;
968 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
969 event
.SetEventObject( this );
971 wxArrayInt aSelections
;
972 int n
, count
= GetSelections(aSelections
);
976 if ( HasClientObjectData() )
977 event
.SetClientObject( GetClientObject(n
) );
978 else if ( HasClientUntypedData() )
979 event
.SetClientData( GetClientData(n
) );
980 event
.SetString( GetString(n
) );
989 GetEventHandler()->ProcessEvent(event
);
993 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
995 m_typeIn
= wxEmptyString
;
997 m_lastTypeIn
= event
.GetTimestamp() ;
998 m_typeIn
+= (char) event
.GetKeyCode() ;
999 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
1002 if ( GetSelection() != line
)
1004 SetSelection(line
) ;
1005 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1006 event
.SetEventObject( this );
1008 if ( HasClientObjectData() )
1009 event
.SetClientObject( GetClientObject( line
) );
1010 else if ( HasClientUntypedData() )
1011 event
.SetClientData( GetClientData(line
) );
1012 event
.SetString( GetString(line
) );
1016 GetEventHandler()->ProcessEvent(event
);