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
)
76 list
= (wxListBox
*) GetControlReference( (ControlHandle
) GetListRefCon(listHandle
) );
82 RgnHandle savedClipRegion
;
85 SetPort((**listHandle
).port
);
86 grafPtr
= (**listHandle
).port
;
87 // typecast our refCon
89 // Calculate the cell rect.
100 const wxString linetext
= list
->m_stringArray
[cell
.v
] ;
102 // Save the current clip region, and set the clip region to the area we are about
105 savedClipRegion
= NewRgn();
106 GetClip( savedClipRegion
);
108 ClipRect( drawRect
);
109 EraseRect( drawRect
);
111 const wxFont
& font
= list
->GetFont();
114 ::TextFont( font
.GetMacFontNum() ) ;
115 ::TextSize( font
.GetMacFontSize() ) ;
116 ::TextFace( font
.GetMacFontStyle() ) ;
120 ::TextFont( kFontIDMonaco
) ;
127 Rect frame
= { drawRect
->top
, drawRect
->left
+ 4,
128 drawRect
->top
+ kwxMacListItemHeight
, drawRect
->right
+ 10000 } ;
129 CFMutableStringRef mString
= CFStringCreateMutableCopy( NULL
, 0 , wxMacCFStringHolder(linetext
, list
->GetFont().GetEncoding()) ) ;
130 ::TruncateThemeText( mString
, kThemeCurrentPortFont
, kThemeStateActive
, drawRect
->right
- drawRect
->left
, truncEnd
, NULL
) ;
131 ::DrawThemeTextBox( mString
,
132 kThemeCurrentPortFont
,
138 CFRelease( mString
) ;
142 wxCharBuffer text
= linetext
.mb_str( wxConvLocal
) ;
143 MoveTo(drawRect
->left
+ 4 , drawRect
->top
+ 10 );
144 DrawText(text
, 0 , strlen(text
) );
147 // If the cell is hilited, do the hilite now. Paint the cell contents with the
148 // appropriate QuickDraw transform mode.
151 savedPenMode
= GetPortPenMode( (CGrafPtr
) grafPtr
);
152 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
153 PaintRect( drawRect
);
154 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
157 // Restore the saved clip region.
159 SetClip( savedClipRegion
);
160 DisposeRgn( savedClipRegion
);
165 // Hilite or unhilite the cell. Paint the cell contents with the
166 // appropriate QuickDraw transform mode.
169 savedPenMode
= GetPortPenMode( (CGrafPtr
)grafPtr
);
170 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
171 PaintRect( drawRect
);
172 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
180 extern "C" void MacDrawStringCell(Rect
*cellRect
, Cell lCell
, ListHandle theList
, long refCon
) ;
181 // resources ldef ids
182 const short kwxMacListWithVerticalScrollbar
= 128 ;
183 const short kwxMacListWithVerticalAndHorizontalScrollbar
= 129 ;
185 // ============================================================================
186 // list box control implementation
187 // ============================================================================
190 wxListBox::wxListBox()
197 static ListDefUPP macListDefUPP
= NULL
;
199 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
202 const wxArrayString
& choices
,
204 const wxValidator
& validator
,
205 const wxString
& name
)
207 wxCArrayString
chs(choices
);
209 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
210 style
, validator
, name
);
213 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
216 int n
, const wxString choices
[],
218 const wxValidator
& validator
,
219 const wxString
& name
)
221 if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
224 m_noItems
= 0 ; // this will be increased by our append command
230 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
233 listDef
.defType
= kListDefUserProcType
;
234 if ( macListDefUPP
== NULL
)
236 macListDefUPP
= NewListDefUPP( wxMacListDefinition
);
238 listDef
.u
.userProc
= macListDefUPP
;
244 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
246 GetFontName( kFontIDMonaco
, fontName
) ;
250 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) ) ) ;
255 CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, (style
& wxLB_HSCROLL
), true,
256 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
258 GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
259 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
261 SetControlReference( (ControlHandle
) m_macControl
, (long) this);
262 SetControlVisibility( (ControlHandle
) m_macControl
, false, false);
267 wxStAppResource resload
;
268 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false ,
269 (style
& wxLB_HSCROLL
) ? kwxMacListWithVerticalAndHorizontalScrollbar
: kwxMacListWithVerticalScrollbar
,
270 0 , 0, kControlListBoxProc
, (long) this ) ;
271 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
272 sizeof( ListHandle
) , (char*) &m_macList
, &result
) ;
274 HLock( (Handle
) m_macList
) ;
276 ldef
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ;
277 if ( (**(ListHandle
)m_macList
).listDefProc
!= NULL
)
279 (**ldef
).instruction
= 0x4EF9; /* JMP instruction */
280 (**ldef
).function
= (void(*)()) listDef
.u
.userProc
;
281 (**(ListHandle
)m_macList
).listDefProc
= (Handle
) ldef
;
284 Point pt
= (**(ListHandle
)m_macList
).cellSize
;
285 pt
.v
= kwxMacListItemHeight
;
286 LCellSize( pt
, (ListHandle
)m_macList
) ;
287 LAddColumn( 1 , 0 , (ListHandle
)m_macList
) ;
289 OptionBits options
= 0;
290 if ( style
& wxLB_MULTIPLE
)
292 options
+= lExtendDrag
+ lUseSense
;
294 else if ( style
& wxLB_EXTENDED
)
300 options
= (OptionBits
) lOnlyOne
;
302 SetListSelectionFlags((ListHandle
)m_macList
, options
);
304 for ( int i
= 0 ; i
< n
; i
++ )
306 Append( choices
[i
] ) ;
309 MacPostControlCreate() ;
311 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
316 wxListBox::~wxListBox()
319 // avoid access during destruction
320 SetControlReference( (ControlHandle
) m_macControl
, NULL
) ;
324 DisposeHandle( (**(ListHandle
)m_macList
).listDefProc
) ;
325 (**(ListHandle
)m_macList
).listDefProc
= NULL
;
331 void wxListBox::FreeData()
333 #if wxUSE_OWNER_DRAWN
334 if ( m_windowStyle
& wxLB_OWNERDRAW
)
336 size_t uiCount
= m_aItems
.Count();
337 while ( uiCount
-- != 0 ) {
338 delete m_aItems
[uiCount
];
339 m_aItems
[uiCount
] = NULL
;
345 #endif // wxUSE_OWNER_DRAWN
346 if ( HasClientObjectData() )
348 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
350 delete GetClientObject(n
);
355 void wxListBox::DoSetSize(int x
, int y
,
356 int width
, int height
,
359 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
362 GetControlBounds( (ControlHandle
) m_macControl
, &bounds
) ;
363 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
367 GetControlBounds( control
, &scrollbounds
) ;
368 if( scrollbounds
.right
!= bounds
.right
+ 1 )
370 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
376 void wxListBox::DoSetFirstItem(int N
)
381 void wxListBox::Delete(int N
)
383 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
384 wxT("invalid index in wxListBox::Delete") );
386 #if wxUSE_OWNER_DRAWN
388 m_aItems
.RemoveAt(N
);
389 #else // !wxUSE_OWNER_DRAWN
390 if ( HasClientObjectData() )
392 delete GetClientObject(N
);
394 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
395 m_stringArray
.RemoveAt( N
) ;
396 m_dataArray
.RemoveAt( N
) ;
402 int wxListBox::DoAppend(const wxString
& item
)
404 int index
= m_noItems
;
405 m_stringArray
.Add( item
) ;
406 m_dataArray
.Add( NULL
);
408 DoSetItemClientData( index
, NULL
) ;
414 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
416 MacSetRedraw( false ) ;
418 int n
= choices
.GetCount();
420 for( int i
= 0 ; i
< n
; ++i
)
424 #if wxUSE_OWNER_DRAWN
425 wxASSERT_MSG(clientData
[i
] == NULL
,
426 wxT("Can't use client data with owner-drawn listboxes"));
427 #else // !wxUSE_OWNER_DRAWN
428 Append( choices
[i
] , clientData
[i
] ) ;
432 Append( choices
[i
] ) ;
435 #if wxUSE_OWNER_DRAWN
436 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
437 // first delete old items
438 size_t ui
= m_aItems
.Count();
439 while ( ui
-- != 0 ) {
445 // then create new ones
446 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
447 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
448 pNewItem
->SetName(choices
[ui
]);
449 m_aItems
.Add(pNewItem
);
452 #endif // wxUSE_OWNER_DRAWN
453 MacSetRedraw( true ) ;
456 bool wxListBox::HasMultipleSelection() const
458 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
461 int wxListBox::FindString(const wxString
& s
) const
464 if ( s
.Right(1) == wxT("*") )
466 wxString search
= s
.Left( s
.Length() - 1 ) ;
467 int len
= search
.Length() ;
469 wxMacStringToPascal( search
, s2
) ;
471 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
473 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
475 if ( EqualString( s1
, s2
, false , false ) )
478 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
482 for ( int i
= 0 ; i
< m_noItems
; ++i
)
484 if ( GetString(i
).Lower().Matches(st
) )
494 wxMacStringToPascal( s
, s2
) ;
496 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
498 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
500 if ( EqualString( s1
, s2
, false , false ) )
507 void wxListBox::Clear()
511 m_stringArray
.Empty() ;
512 m_dataArray
.Empty() ;
516 void wxListBox::SetSelection(int N
, bool select
)
518 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
519 wxT("invalid index in wxListBox::SetSelection") );
520 MacSetSelection( N
, select
) ;
521 GetSelections( m_selectionPreImage
) ;
524 bool wxListBox::IsSelected(int N
) const
526 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
527 wxT("invalid index in wxListBox::Selected") );
529 return MacIsSelected( N
) ;
532 void *wxListBox::DoGetItemClientData(int N
) const
534 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
535 wxT("invalid index in wxListBox::GetClientData"));
537 return (void *)m_dataArray
[N
];
540 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
542 return (wxClientData
*) DoGetItemClientData( N
) ;
545 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
547 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
548 wxT("invalid index in wxListBox::SetClientData") );
550 #if wxUSE_OWNER_DRAWN
551 if ( m_windowStyle
& wxLB_OWNERDRAW
)
553 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
554 // in OnMeasure/OnDraw.
555 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
557 #endif // wxUSE_OWNER_DRAWN
558 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
560 if ( m_dataArray
.GetCount() > (size_t) N
)
562 m_dataArray
[N
] = (char*) Client_data
;
566 m_dataArray
.Add( (char*) Client_data
) ;
570 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
572 DoSetItemClientData(n
, clientData
);
575 // Return number of selections and an array of selected integers
576 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
578 return MacGetSelections( aSelections
) ;
581 // Get single selection, for single choice list items
582 int wxListBox::GetSelection() const
584 return MacGetSelection() ;
587 // Find string for position
588 wxString
wxListBox::GetString(int N
) const
590 return m_stringArray
[N
] ;
593 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
595 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
596 wxT("invalid index in wxListBox::InsertItems") );
598 int nItems
= items
.GetCount();
600 for ( int i
= 0 ; i
< nItems
; i
++ )
602 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
603 m_dataArray
.Insert( NULL
, pos
+ i
) ;
604 MacInsert( pos
+ i
, items
[i
] ) ;
610 void wxListBox::SetString(int N
, const wxString
& s
)
612 m_stringArray
[N
] = s
;
616 wxSize
wxListBox::DoGetBestSize() const
618 int lbWidth
= 100; // some defaults
623 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
627 ::TextFont( m_font
.GetMacFontNum() ) ;
628 ::TextSize( m_font
.GetMacFontSize() ) ;
629 ::TextFace( m_font
.GetMacFontStyle() ) ;
633 ::TextFont( kFontIDMonaco
) ;
638 // Find the widest line
639 for(int i
= 0; i
< GetCount(); i
++) {
640 wxString
str(GetString(i
));
644 ::GetThemeTextDimensions( wxMacCFStringHolder( str
, m_font
.GetEncoding() ) ,
645 kThemeCurrentPortFont
,
652 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
654 lbWidth
= wxMax(lbWidth
, wLine
);
657 // Add room for the scrollbar
658 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
660 // And just a bit more
662 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
665 // don't make the listbox too tall (limit height to around 10 items) but don't
666 // make it too small neither
667 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
669 return wxSize(lbWidth
, lbHeight
);
672 int wxListBox::GetCount() const
677 void wxListBox::SetupColours()
679 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
680 SetForegroundColour(GetParent()->GetForegroundColour());
683 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
685 wxControl::Refresh( eraseBack
, rect
) ;
686 // MacRedrawControl() ;
689 #if wxUSE_OWNER_DRAWN
691 class wxListBoxItem
: public wxOwnerDrawn
694 wxListBoxItem(const wxString
& str
= "");
697 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
699 // no bitmaps/checkmarks
703 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
705 return new wxListBoxItem();
708 #endif //USE_OWNER_DRAWN
710 // ============================================================================
711 // list box control implementation
712 // ============================================================================
715 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
718 // typecast our refCon
719 list = (wxListBox*)refCon;
721 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
722 const wxString text = list->m_stringArray[lCell.v] ;
723 ::TextFont( kFontIDMonaco ) ;
726 DrawText(text, 0 , text.Length());
730 void wxListBox::MacDelete( int N
)
732 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
736 void wxListBox::MacInsert( int n
, const wxString
& text
)
738 Cell cell
= { 0 , 0 } ;
740 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
741 // LSetCell(text, strlen(text), cell, m_macList);
745 void wxListBox::MacAppend( const wxString
& text
)
747 Cell cell
= { 0 , 0 } ;
748 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
749 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
750 // LSetCell(text, strlen(text), cell, m_macList);
754 void wxListBox::MacClear()
756 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
760 void wxListBox::MacSetSelection( int n
, bool select
)
762 Cell cell
= { 0 , 0 } ;
763 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
765 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
767 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
772 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
773 LAutoScroll( (ListHandle
)m_macList
) ;
777 bool wxListBox::MacIsSelected( int n
) const
779 Cell cell
= { 0 , 0 } ;
781 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
784 void wxListBox::MacDestroy()
786 // DisposeExtLDEFInfo( m_macList ) ;
789 int wxListBox::MacGetSelection() const
791 Cell cell
= { 0 , 0 } ;
792 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
798 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
804 Cell cell
= { 0 , 0 } ;
807 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
809 aSelections
.Add( cell
.v
) ;
816 void wxListBox::MacSet( int n
, const wxString
& text
)
818 // our implementation does not store anything in the list
819 // so we just have to redraw
820 Cell cell
= { 0 , 0 } ;
822 // LSetCell(text, strlen(text), cell, m_macList);
826 void wxListBox::MacScrollTo( int n
)
828 // TODO implement scrolling
831 void wxListBox::OnSize( wxSizeEvent
&event
)
836 GetListCellSize((ListHandle
)m_macList
, &pt
);
838 pt
= (**(ListHandle
)m_macList
).cellSize
;
840 pt
.h
= m_width
- 15 ;
841 LCellSize( pt
, (ListHandle
)m_macList
) ;
844 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
846 Boolean wasDoubleClick
= false ;
849 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
850 if ( !wasDoubleClick
)
860 void wxListBox::MacSetRedraw( bool doDraw
)
862 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
866 void wxListBox::MacDoClick()
868 wxArrayInt aSelections
;
870 size_t count
= GetSelections(aSelections
);
872 if ( count
== m_selectionPreImage
.GetCount() )
874 bool hasChanged
= false ;
875 for ( size_t i
= 0 ; i
< count
; ++i
)
877 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
889 m_selectionPreImage
= aSelections
;
891 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
892 event
.SetEventObject( this );
897 if ( HasClientObjectData() )
898 event
.SetClientObject( GetClientObject(n
) );
899 else if ( HasClientUntypedData() )
900 event
.SetClientData( GetClientData(n
) );
901 event
.SetString( GetString(n
) );
908 event
.m_commandInt
= n
;
910 GetEventHandler()->ProcessEvent(event
);
913 void wxListBox::MacDoDoubleClick()
915 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
916 event
.SetEventObject( this );
917 GetEventHandler()->ProcessEvent(event
) ;
920 void wxListBox::OnChar(wxKeyEvent
& event
)
922 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
924 wxWindow
* parent
= GetParent() ;
925 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
926 parent
= parent
->GetParent() ;
928 if ( parent
&& parent
->GetDefaultItem() )
930 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
932 if ( def
&& def
->IsEnabled() )
934 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
935 event
.SetEventObject(def
);
942 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
943 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
945 // FIXME: look in ancestors, not just parent.
946 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
949 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
950 new_event
.SetEventObject( win
);
951 win
->GetEventHandler()->ProcessEvent( new_event
);
954 else if ( event
.GetKeyCode() == WXK_TAB
)
956 wxNavigationKeyEvent new_event
;
957 new_event
.SetEventObject( this );
958 new_event
.SetDirection( !event
.ShiftDown() );
959 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
960 new_event
.SetWindowChange( event
.ControlDown() );
961 new_event
.SetCurrentFocus( this );
962 if ( !GetEventHandler()->ProcessEvent( new_event
) )
965 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
967 // perform the default key handling first
968 wxControl::OnKeyDown( event
) ;
970 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
971 event
.SetEventObject( this );
973 wxArrayInt aSelections
;
974 int n
, count
= GetSelections(aSelections
);
978 if ( HasClientObjectData() )
979 event
.SetClientObject( GetClientObject(n
) );
980 else if ( HasClientUntypedData() )
981 event
.SetClientData( GetClientData(n
) );
982 event
.SetString( GetString(n
) );
989 event
.m_commandInt
= n
;
991 GetEventHandler()->ProcessEvent(event
);
995 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
997 m_typeIn
= wxEmptyString
;
999 m_lastTypeIn
= event
.GetTimestamp() ;
1000 m_typeIn
+= (char) event
.GetKeyCode() ;
1001 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
1004 if ( GetSelection() != line
)
1006 SetSelection(line
) ;
1007 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1008 event
.SetEventObject( this );
1010 if ( HasClientObjectData() )
1011 event
.SetClientObject( GetClientObject( line
) );
1012 else if ( HasClientUntypedData() )
1013 event
.SetClientData( GetClientData(line
) );
1014 event
.SetString( GetString(line
) );
1016 event
.m_commandInt
= line
;
1018 GetEventHandler()->ProcessEvent(event
);