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
= linetext
.mb_str( wxConvLocal
) ;
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 if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
208 m_noItems
= 0 ; // this will be increased by our append command
214 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
217 listDef
.defType
= kListDefUserProcType
;
218 if ( macListDefUPP
== NULL
)
220 macListDefUPP
= NewListDefUPP( wxMacListDefinition
);
222 listDef
.u
.userProc
= macListDefUPP
;
228 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
230 GetFontName( kFontIDMonaco
, fontName
) ;
234 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) ) ) ;
239 CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, (style
& wxLB_HSCROLL
), true,
240 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
242 GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
243 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
245 SetControlReference( (ControlHandle
) m_macControl
, (long) this);
246 SetControlVisibility( (ControlHandle
) m_macControl
, false, false);
251 wxStAppResource resload
;
252 m_macControl
= ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false ,
253 (style
& wxLB_HSCROLL
) ? kwxMacListWithVerticalAndHorizontalScrollbar
: kwxMacListWithVerticalScrollbar
,
254 0 , 0, kControlListBoxProc
, (long) this ) ;
255 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
256 sizeof( ListHandle
) , (char*) &m_macList
, &result
) ;
258 HLock( (Handle
) m_macList
) ;
260 ldef
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ;
261 if ( (**(ListHandle
)m_macList
).listDefProc
!= NULL
)
263 (**ldef
).instruction
= 0x4EF9; /* JMP instruction */
264 (**ldef
).function
= (void(*)()) listDef
.u
.userProc
;
265 (**(ListHandle
)m_macList
).listDefProc
= (Handle
) ldef
;
268 Point pt
= (**(ListHandle
)m_macList
).cellSize
;
269 pt
.v
= kwxMacListItemHeight
;
270 LCellSize( pt
, (ListHandle
)m_macList
) ;
271 LAddColumn( 1 , 0 , (ListHandle
)m_macList
) ;
273 OptionBits options
= 0;
274 if ( style
& wxLB_MULTIPLE
)
276 options
+= lNoExtend
;
278 else if ( style
& wxLB_EXTENDED
)
280 options
+= lExtendDrag
;
284 options
= (OptionBits
) lOnlyOne
;
286 SetListSelectionFlags((ListHandle
)m_macList
, options
);
288 for ( int i
= 0 ; i
< n
; i
++ )
290 Append( choices
[i
] ) ;
293 MacPostControlCreate() ;
295 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
300 wxListBox::~wxListBox()
306 DisposeHandle( (**(ListHandle
)m_macList
).listDefProc
) ;
307 (**(ListHandle
)m_macList
).listDefProc
= NULL
;
313 void wxListBox::FreeData()
315 #if wxUSE_OWNER_DRAWN
316 if ( m_windowStyle
& wxLB_OWNERDRAW
)
318 size_t uiCount
= m_aItems
.Count();
319 while ( uiCount
-- != 0 ) {
320 delete m_aItems
[uiCount
];
321 m_aItems
[uiCount
] = NULL
;
327 #endif // wxUSE_OWNER_DRAWN
328 if ( HasClientObjectData() )
330 for ( size_t n
= 0; n
< (size_t)m_noItems
; n
++ )
332 delete GetClientObject(n
);
337 void wxListBox::DoSetSize(int x
, int y
,
338 int width
, int height
,
341 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
344 GetControlBounds( (ControlHandle
) m_macControl
, &bounds
) ;
345 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
349 GetControlBounds( control
, &scrollbounds
) ;
350 if( scrollbounds
.right
!= bounds
.right
+ 1 )
352 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
358 void wxListBox::DoSetFirstItem(int N
)
363 void wxListBox::Delete(int N
)
365 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
366 wxT("invalid index in wxListBox::Delete") );
368 #if wxUSE_OWNER_DRAWN
370 m_aItems
.RemoveAt(N
);
371 #else // !wxUSE_OWNER_DRAWN
372 if ( HasClientObjectData() )
374 delete GetClientObject(N
);
376 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
377 m_stringArray
.RemoveAt( N
) ;
378 m_dataArray
.RemoveAt( N
) ;
384 int wxListBox::DoAppend(const wxString
& item
)
386 int index
= m_noItems
;
387 m_stringArray
.Add( item
) ;
388 m_dataArray
.Add( NULL
);
390 DoSetItemClientData( index
, NULL
) ;
396 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
398 MacSetRedraw( false ) ;
400 int n
= choices
.GetCount();
402 for( int i
= 0 ; i
< n
; ++i
)
406 #if wxUSE_OWNER_DRAWN
407 wxASSERT_MSG(clientData
[i
] == NULL
,
408 wxT("Can't use client data with owner-drawn listboxes"));
409 #else // !wxUSE_OWNER_DRAWN
410 Append( choices
[i
] , clientData
[i
] ) ;
414 Append( choices
[i
] ) ;
417 #if wxUSE_OWNER_DRAWN
418 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
419 // first delete old items
420 size_t ui
= m_aItems
.Count();
421 while ( ui
-- != 0 ) {
427 // then create new ones
428 for ( ui
= 0; ui
< (size_t)m_noItems
; ui
++ ) {
429 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
430 pNewItem
->SetName(choices
[ui
]);
431 m_aItems
.Add(pNewItem
);
434 #endif // wxUSE_OWNER_DRAWN
435 MacSetRedraw( true ) ;
438 bool wxListBox::HasMultipleSelection() const
440 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
443 int wxListBox::FindString(const wxString
& s
) const
446 if ( s
.Right(1) == wxT("*") )
448 wxString search
= s
.Left( s
.Length() - 1 ) ;
449 int len
= search
.Length() ;
451 wxMacStringToPascal( search
, s2
) ;
453 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
455 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
457 if ( EqualString( s1
, s2
, false , false ) )
460 if ( s
.Left(1) == wxT("*") && s
.Length() > 1 )
464 for ( int i
= 0 ; i
< m_noItems
; ++i
)
466 if ( GetString(i
).Lower().Matches(st
) )
476 wxMacStringToPascal( s
, s2
) ;
478 for ( int i
= 0 ; i
< m_noItems
; ++ i
)
480 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
482 if ( EqualString( s1
, s2
, false , false ) )
489 void wxListBox::Clear()
493 m_stringArray
.Empty() ;
494 m_dataArray
.Empty() ;
498 void wxListBox::SetSelection(int N
, bool select
)
500 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
501 wxT("invalid index in wxListBox::SetSelection") );
502 MacSetSelection( N
, select
) ;
503 GetSelections( m_selectionPreImage
) ;
506 bool wxListBox::IsSelected(int N
) const
508 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, FALSE
,
509 wxT("invalid index in wxListBox::Selected") );
511 return MacIsSelected( N
) ;
514 void *wxListBox::DoGetItemClientData(int N
) const
516 wxCHECK_MSG( N
>= 0 && N
< m_noItems
, NULL
,
517 wxT("invalid index in wxListBox::GetClientData"));
519 return (void *)m_dataArray
[N
];
522 wxClientData
*wxListBox::DoGetItemClientObject(int N
) const
524 return (wxClientData
*) DoGetItemClientData( N
) ;
527 void wxListBox::DoSetItemClientData(int N
, void *Client_data
)
529 wxCHECK_RET( N
>= 0 && N
< m_noItems
,
530 wxT("invalid index in wxListBox::SetClientData") );
532 #if wxUSE_OWNER_DRAWN
533 if ( m_windowStyle
& wxLB_OWNERDRAW
)
535 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
536 // in OnMeasure/OnDraw.
537 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
539 #endif // wxUSE_OWNER_DRAWN
540 wxASSERT_MSG( m_dataArray
.GetCount() >= (size_t) N
, wxT("invalid client_data array") ) ;
542 if ( m_dataArray
.GetCount() > (size_t) N
)
544 m_dataArray
[N
] = (char*) Client_data
;
548 m_dataArray
.Add( (char*) Client_data
) ;
552 void wxListBox::DoSetItemClientObject(int n
, wxClientData
* clientData
)
554 DoSetItemClientData(n
, clientData
);
557 // Return number of selections and an array of selected integers
558 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
560 return MacGetSelections( aSelections
) ;
563 // Get single selection, for single choice list items
564 int wxListBox::GetSelection() const
566 return MacGetSelection() ;
569 // Find string for position
570 wxString
wxListBox::GetString(int N
) const
572 return m_stringArray
[N
] ;
575 void wxListBox::DoInsertItems(const wxArrayString
& items
, int pos
)
577 wxCHECK_RET( pos
>= 0 && pos
<= m_noItems
,
578 wxT("invalid index in wxListBox::InsertItems") );
580 int nItems
= items
.GetCount();
582 for ( int i
= 0 ; i
< nItems
; i
++ )
584 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
585 m_dataArray
.Insert( NULL
, pos
+ i
) ;
586 MacInsert( pos
+ i
, items
[i
] ) ;
592 void wxListBox::SetString(int N
, const wxString
& s
)
594 m_stringArray
[N
] = s
;
598 wxSize
wxListBox::DoGetBestSize() const
600 int lbWidth
= 100; // some defaults
605 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
607 wxFontRefData
* font
= (wxFontRefData
*) m_font
.GetRefData() ;
611 ::TextFont( font
->m_macFontNum
) ;
612 ::TextSize( short(font
->m_macFontSize
) ) ;
613 ::TextFace( font
->m_macFontStyle
) ;
617 ::TextFont( kFontIDMonaco
) ;
622 // Find the widest line
623 for(int i
= 0; i
< GetCount(); i
++) {
624 wxString
str(GetString(i
));
628 ::GetThemeTextDimensions( wxMacCFStringHolder( str
) ,
629 kThemeCurrentPortFont
,
636 wLine
= ::TextWidth( str
.c_str() , 0 , str
.Length() ) ;
638 lbWidth
= wxMax(lbWidth
, wLine
);
641 // Add room for the scrollbar
642 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
644 // And just a bit more
646 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
649 // don't make the listbox too tall (limit height to around 10 items) but don't
650 // make it too small neither
651 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
653 return wxSize(lbWidth
, lbHeight
);
656 int wxListBox::GetCount() const
661 void wxListBox::SetupColours()
663 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
664 SetForegroundColour(GetParent()->GetForegroundColour());
667 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
669 wxControl::Refresh( eraseBack
, rect
) ;
670 // MacRedrawControl() ;
673 #if wxUSE_OWNER_DRAWN
675 class wxListBoxItem
: public wxOwnerDrawn
678 wxListBoxItem(const wxString
& str
= "");
681 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, FALSE
)
683 // no bitmaps/checkmarks
687 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
689 return new wxListBoxItem();
692 #endif //USE_OWNER_DRAWN
694 // ============================================================================
695 // list box control implementation
696 // ============================================================================
699 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
702 // typecast our refCon
703 list = (wxListBox*)refCon;
705 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
706 const wxString text = list->m_stringArray[lCell.v] ;
707 ::TextFont( kFontIDMonaco ) ;
710 DrawText(text, 0 , text.Length());
714 void wxListBox::MacDelete( int N
)
716 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
720 void wxListBox::MacInsert( int n
, const wxString
& text
)
722 Cell cell
= { 0 , 0 } ;
724 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
725 // LSetCell(text, strlen(text), cell, m_macList);
729 void wxListBox::MacAppend( const wxString
& text
)
731 Cell cell
= { 0 , 0 } ;
732 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
733 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
734 // LSetCell(text, strlen(text), cell, m_macList);
738 void wxListBox::MacClear()
740 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
744 void wxListBox::MacSetSelection( int n
, bool select
)
746 Cell cell
= { 0 , 0 } ;
747 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
749 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
751 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
756 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
757 LAutoScroll( (ListHandle
)m_macList
) ;
761 bool wxListBox::MacIsSelected( int n
) const
763 Cell cell
= { 0 , 0 } ;
765 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
768 void wxListBox::MacDestroy()
770 // DisposeExtLDEFInfo( m_macList ) ;
773 int wxListBox::MacGetSelection() const
775 Cell cell
= { 0 , 0 } ;
776 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
782 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
788 Cell cell
= { 0 , 0 } ;
791 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
793 aSelections
.Add( cell
.v
) ;
800 void wxListBox::MacSet( int n
, const wxString
& text
)
802 // our implementation does not store anything in the list
803 // so we just have to redraw
804 Cell cell
= { 0 , 0 } ;
806 // LSetCell(text, strlen(text), cell, m_macList);
810 void wxListBox::MacScrollTo( int n
)
812 // TODO implement scrolling
815 void wxListBox::OnSize( const wxSizeEvent
&event
)
820 GetListCellSize((ListHandle
)m_macList
, &pt
);
822 pt
= (**(ListHandle
)m_macList
).cellSize
;
824 pt
.h
= m_width
- 15 ;
825 LCellSize( pt
, (ListHandle
)m_macList
) ;
828 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
830 Boolean wasDoubleClick
= false ;
833 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
834 if ( !wasDoubleClick
)
844 void wxListBox::MacSetRedraw( bool doDraw
)
846 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
850 void wxListBox::MacDoClick()
852 wxArrayInt aSelections
;
854 size_t count
= GetSelections(aSelections
);
856 if ( count
== m_selectionPreImage
.GetCount() )
858 bool hasChanged
= false ;
859 for ( size_t i
= 0 ; i
< count
; ++i
)
861 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
873 m_selectionPreImage
= aSelections
;
875 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
876 event
.SetEventObject( this );
881 if ( HasClientObjectData() )
882 event
.SetClientObject( GetClientObject(n
) );
883 else if ( HasClientUntypedData() )
884 event
.SetClientData( GetClientData(n
) );
885 event
.SetString( GetString(n
) );
892 event
.m_commandInt
= n
;
894 GetEventHandler()->ProcessEvent(event
);
897 void wxListBox::MacDoDoubleClick()
899 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
900 event
.SetEventObject( this );
901 GetEventHandler()->ProcessEvent(event
) ;
904 void wxListBox::OnChar(wxKeyEvent
& event
)
906 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
908 wxWindow
* parent
= GetParent() ;
909 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
910 parent
= parent
->GetParent() ;
912 if ( parent
&& parent
->GetDefaultItem() )
914 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
916 if ( def
&& def
->IsEnabled() )
918 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
919 event
.SetEventObject(def
);
926 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
927 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
929 // FIXME: look in ancestors, not just parent.
930 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
933 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
934 new_event
.SetEventObject( win
);
935 win
->GetEventHandler()->ProcessEvent( new_event
);
938 else if ( event
.GetKeyCode() == WXK_TAB
)
940 wxNavigationKeyEvent new_event
;
941 new_event
.SetEventObject( this );
942 new_event
.SetDirection( !event
.ShiftDown() );
943 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
944 new_event
.SetWindowChange( event
.ControlDown() );
945 new_event
.SetCurrentFocus( this );
946 if ( !GetEventHandler()->ProcessEvent( new_event
) )
949 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
951 // perform the default key handling first
952 wxControl::OnKeyDown( event
) ;
954 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
955 event
.SetEventObject( this );
957 wxArrayInt aSelections
;
958 int n
, count
= GetSelections(aSelections
);
962 if ( HasClientObjectData() )
963 event
.SetClientObject( GetClientObject(n
) );
964 else if ( HasClientUntypedData() )
965 event
.SetClientData( GetClientData(n
) );
966 event
.SetString( GetString(n
) );
973 event
.m_commandInt
= n
;
975 GetEventHandler()->ProcessEvent(event
);
979 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
981 m_typeIn
= wxEmptyString
;
983 m_lastTypeIn
= event
.GetTimestamp() ;
984 m_typeIn
+= (char) event
.GetKeyCode() ;
985 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
988 if ( GetSelection() != line
)
991 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
992 event
.SetEventObject( this );
994 if ( HasClientObjectData() )
995 event
.SetClientObject( GetClientObject( line
) );
996 else if ( HasClientUntypedData() )
997 event
.SetClientData( GetClientData(line
) );
998 event
.SetString( GetString(line
) );
1000 event
.m_commandInt
= line
;
1002 GetEventHandler()->ProcessEvent(event
);