1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/listbox.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/listbox.h"
19 #include "wx/dynarray.h"
24 #include "wx/button.h"
25 #include "wx/settings.h"
26 #include "wx/toplevel.h"
30 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
32 BEGIN_EVENT_TABLE(wxListBox
, wxControl
)
33 EVT_SIZE( wxListBox::OnSize
)
34 EVT_CHAR( wxListBox::OnChar
)
37 #include "wx/mac/uma.h"
39 #if PRAGMA_STRUCT_ALIGN
40 #pragma options align=mac68k
41 #elif PRAGMA_STRUCT_PACKPUSH
43 #elif PRAGMA_STRUCT_PACK
48 unsigned short instruction
;
50 } ldefRec
, *ldefPtr
, **ldefHandle
;
52 #if PRAGMA_STRUCT_ALIGN
53 #pragma options align=reset
54 #elif PRAGMA_STRUCT_PACKPUSH
56 #elif PRAGMA_STRUCT_PACK
61 const short kwxMacListItemHeight
= 19 ;
63 const short kwxMacListItemHeight
= 14 ;
68 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect
*drawRect
,
69 Cell cell
, short dataOffset
, short dataLength
,
70 ListHandle listHandle
) ;
73 static pascal void wxMacListDefinition( short message
, Boolean isSelected
, Rect
*drawRect
,
74 Cell cell
, short dataOffset
, short dataLength
,
75 ListHandle listHandle
)
78 list
= (wxListBox
*) GetControlReference( (ControlHandle
) GetListRefCon(listHandle
) );
84 RgnHandle savedClipRegion
;
87 SetPort((**listHandle
).port
);
88 grafPtr
= (**listHandle
).port
;
89 // typecast our refCon
91 // Calculate the cell rect.
102 const wxString linetext
= list
->m_stringArray
[cell
.v
] ;
104 // Save the current clip region, and set the clip region to the area we are about
107 savedClipRegion
= NewRgn();
108 GetClip( savedClipRegion
);
110 ClipRect( drawRect
);
111 EraseRect( drawRect
);
113 const wxFont
& font
= list
->GetFont();
116 ::TextFont( font
.GetMacFontNum() ) ;
117 ::TextSize( font
.GetMacFontSize() ) ;
118 ::TextFace( font
.GetMacFontStyle() ) ;
122 ::TextFont( kFontIDMonaco
) ;
129 Rect frame
= { drawRect
->top
, drawRect
->left
+ 4,
130 drawRect
->top
+ kwxMacListItemHeight
, drawRect
->right
+ 10000 } ;
131 CFMutableStringRef mString
= CFStringCreateMutableCopy( NULL
, 0 , wxMacCFStringHolder(linetext
, list
->GetFont().GetEncoding()) ) ;
132 ::TruncateThemeText( mString
, kThemeCurrentPortFont
, kThemeStateActive
, drawRect
->right
- drawRect
->left
, truncEnd
, NULL
) ;
133 ::DrawThemeTextBox( mString
,
134 kThemeCurrentPortFont
,
140 CFRelease( mString
) ;
144 wxCharBuffer text
= linetext
.mb_str( wxConvLocal
) ;
145 MoveTo(drawRect
->left
+ 4 , drawRect
->top
+ 10 );
146 DrawText(text
, 0 , strlen(text
) );
149 // If the cell is hilited, do the hilite now. Paint the cell contents with the
150 // appropriate QuickDraw transform mode.
153 savedPenMode
= GetPortPenMode( (CGrafPtr
) grafPtr
);
154 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
155 PaintRect( drawRect
);
156 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
159 // Restore the saved clip region.
161 SetClip( savedClipRegion
);
162 DisposeRgn( savedClipRegion
);
167 // Hilite or unhilite the cell. Paint the cell contents with the
168 // appropriate QuickDraw transform mode.
171 savedPenMode
= GetPortPenMode( (CGrafPtr
)grafPtr
);
172 SetPortPenMode( (CGrafPtr
)grafPtr
, hilitetransfermode
);
173 PaintRect( drawRect
);
174 SetPortPenMode( (CGrafPtr
)grafPtr
, savedPenMode
);
182 extern "C" void MacDrawStringCell(Rect
*cellRect
, Cell lCell
, ListHandle theList
, long refCon
) ;
183 // resources ldef ids
184 const short kwxMacListWithVerticalScrollbar
= 128 ;
185 const short kwxMacListWithVerticalAndHorizontalScrollbar
= 129 ;
187 // ============================================================================
188 // list box control implementation
189 // ============================================================================
192 wxListBox::wxListBox()
199 static ListDefUPP macListDefUPP
= NULL
;
201 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
204 const wxArrayString
& choices
,
206 const wxValidator
& validator
,
207 const wxString
& name
)
209 wxCArrayString
chs(choices
);
211 return Create(parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
212 style
, validator
, name
);
215 bool wxListBox::Create(wxWindow
*parent
, wxWindowID id
,
218 int n
, const wxString choices
[],
220 const wxValidator
& validator
,
221 const wxString
& name
)
223 if ( !wxListBoxBase::Create(parent
, id
, pos
, size
, style
& ~(wxHSCROLL
|wxVSCROLL
), validator
, name
) )
226 m_noItems
= 0 ; // this will be increased by our append command
232 MacPreControlCreate( parent
, id
, wxEmptyString
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
235 listDef
.defType
= kListDefUserProcType
;
236 if ( macListDefUPP
== NULL
)
238 macListDefUPP
= NewListDefUPP( wxMacListDefinition
);
240 listDef
.u
.userProc
= macListDefUPP
;
246 GetThemeFont(kThemeViewsFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
248 GetFontName( kFontIDMonaco
, fontName
) ;
252 SetFont( wxFont (fontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false , wxMacMakeStringFromPascal( fontName
) ) ) ;
257 CreateListBoxControl( MAC_WXHWND(parent
->MacGetRootWindow()), &bounds
, false, 0, 1, (style
& wxLB_HSCROLL
), true,
258 kwxMacListItemHeight
, kwxMacListItemHeight
, false, &listDef
, (ControlRef
*)&m_macControl
);
260 GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
261 sizeof(ListHandle
), (Ptr
) &m_macList
, &asize
);
263 SetControlReference( (ControlHandle
) m_macControl
, (long) this);
264 SetControlVisibility( (ControlHandle
) m_macControl
, false, false);
269 wxStAppResource resload
;
270 m_macControl
= (WXWidget
) ::NewControl( MAC_WXHWND(parent
->MacGetRootWindow()) , &bounds
, title
, false ,
271 (style
& wxLB_HSCROLL
) ? kwxMacListWithVerticalAndHorizontalScrollbar
: kwxMacListWithVerticalScrollbar
,
272 0 , 0, kControlListBoxProc
, (long) this ) ;
273 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxListHandleTag
,
274 sizeof( ListHandle
) , (char*) &m_macList
, &result
) ;
276 HLock( (Handle
) m_macList
) ;
278 ldef
= (ldefHandle
) NewHandle( sizeof(ldefRec
) ) ;
279 if ( (**(ListHandle
)m_macList
).listDefProc
!= NULL
)
281 (**ldef
).instruction
= 0x4EF9; /* JMP instruction */
282 (**ldef
).function
= (void(*)()) listDef
.u
.userProc
;
283 (**(ListHandle
)m_macList
).listDefProc
= (Handle
) ldef
;
286 Point pt
= (**(ListHandle
)m_macList
).cellSize
;
287 pt
.v
= kwxMacListItemHeight
;
288 LCellSize( pt
, (ListHandle
)m_macList
) ;
289 LAddColumn( 1 , 0 , (ListHandle
)m_macList
) ;
291 OptionBits options
= 0;
292 if ( style
& wxLB_MULTIPLE
)
294 options
+= lExtendDrag
+ lUseSense
;
296 else if ( style
& wxLB_EXTENDED
)
302 options
= (OptionBits
) lOnlyOne
;
304 SetListSelectionFlags((ListHandle
)m_macList
, options
);
306 for ( int i
= 0 ; i
< n
; i
++ )
308 Append( choices
[i
] ) ;
311 MacPostControlCreate() ;
313 LSetDrawingMode( true , (ListHandle
)m_macList
) ;
318 wxListBox::~wxListBox()
321 // avoid access during destruction
322 SetControlReference( (ControlHandle
) m_macControl
, NULL
) ;
326 DisposeHandle( (**(ListHandle
)m_macList
).listDefProc
) ;
327 (**(ListHandle
)m_macList
).listDefProc
= NULL
;
333 void wxListBox::FreeData()
335 #if wxUSE_OWNER_DRAWN
336 if ( m_windowStyle
& wxLB_OWNERDRAW
)
338 size_t uiCount
= m_aItems
.Count();
339 while ( uiCount
-- != 0 ) {
340 delete m_aItems
[uiCount
];
341 m_aItems
[uiCount
] = NULL
;
347 #endif // wxUSE_OWNER_DRAWN
348 if ( HasClientObjectData() )
350 for ( unsigned int n
= 0; n
< m_noItems
; n
++ )
352 delete GetClientObject(n
);
357 void wxListBox::DoSetSize(int x
, int y
,
358 int width
, int height
,
361 wxControl::DoSetSize( x
, y
, width
, height
, sizeFlags
) ;
364 GetControlBounds( (ControlHandle
) m_macControl
, &bounds
) ;
365 ControlRef control
= GetListVerticalScrollBar( (ListHandle
)m_macList
) ;
369 GetControlBounds( control
, &scrollbounds
) ;
370 if( scrollbounds
.right
!= bounds
.right
+ 1 )
372 UMAMoveControl( control
, bounds
.right
- (scrollbounds
.right
- scrollbounds
.left
) + 1 ,
378 void wxListBox::DoSetFirstItem(int N
)
383 void wxListBox::Delete(unsigned int n
)
385 wxCHECK_RET( IsValid(n
),
386 wxT("invalid index in wxListBox::Delete") );
388 #if wxUSE_OWNER_DRAWN
390 m_aItems
.RemoveAt(n
);
391 #else // !wxUSE_OWNER_DRAWN
392 if ( HasClientObjectData() )
394 delete GetClientObject(n
);
396 #endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
397 m_stringArray
.RemoveAt(n
) ;
398 m_dataArray
.RemoveAt(n
) ;
404 int wxListBox::DoAppend(const wxString
& item
)
406 InvalidateBestSize();
408 unsigned int index
= m_noItems
;
409 m_stringArray
.Add( item
) ;
410 m_dataArray
.Add( NULL
);
412 DoSetItemClientData( index
, NULL
) ;
418 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
420 MacSetRedraw( false ) ;
422 int n
= choices
.GetCount();
424 for( int i
= 0 ; i
< n
; ++i
)
428 #if wxUSE_OWNER_DRAWN
429 wxASSERT_MSG(clientData
[i
] == NULL
,
430 wxT("Can't use client data with owner-drawn listboxes"));
431 #else // !wxUSE_OWNER_DRAWN
432 Append( choices
[i
] , clientData
[i
] ) ;
436 Append( choices
[i
] ) ;
439 #if wxUSE_OWNER_DRAWN
440 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
441 // first delete old items
442 unsigned int ui
= m_aItems
.Count();
443 while ( ui
-- != 0 ) {
449 // then create new ones
450 for ( ui
= 0; ui
< m_noItems
; ui
++ ) {
451 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
452 pNewItem
->SetName(choices
[ui
]);
453 m_aItems
.Add(pNewItem
);
456 #endif // wxUSE_OWNER_DRAWN
457 MacSetRedraw( true ) ;
460 bool wxListBox::HasMultipleSelection() const
462 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
465 int wxListBox::FindString(const wxString
& s
, bool bCase
) const
467 if ( s
.Right(1) == wxT("*") )
469 wxString search
= s
.Left( s
.length() - 1 ) ;
470 int len
= search
.length() ;
472 wxMacStringToPascal( search
, s2
) ;
474 for ( unsigned int i
= 0 ; i
< m_noItems
; ++ i
)
476 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
478 if ( EqualString( s1
, s2
, bCase
, false ) )
481 if ( s
.Left(1) == wxT("*") && s
.length() > 1 )
485 for ( unsigned int i
= 0 ; i
< m_noItems
; ++i
)
487 if (GetString(i
).Lower().Matches(st
))
497 wxMacStringToPascal( s
, s2
) ;
499 for ( unsigned int i
= 0 ; i
< m_noItems
; ++ i
)
501 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
503 if ( EqualString( s1
, s2
, bCase
, false ) )
511 void wxListBox::Clear()
515 m_stringArray
.Empty() ;
516 m_dataArray
.Empty() ;
520 void wxListBox::DoSetSelection(int N
, bool select
)
522 wxCHECK_RET( IsValid(N
),
523 wxT("invalid index in wxListBox::SetSelection") );
524 MacSetSelection( N
, select
) ;
525 GetSelections( m_selectionPreImage
) ;
528 bool wxListBox::IsSelected(int N
) const
530 wxCHECK_MSG( IsValid(N
), false,
531 wxT("invalid index in wxListBox::Selected") );
533 return MacIsSelected( N
) ;
536 void *wxListBox::DoGetItemClientData(unsigned int n
) const
538 wxCHECK_MSG( IsValid(n
), NULL
,
539 wxT("invalid index in wxListBox::GetClientData"));
541 return (void *)m_dataArray
[n
];
544 wxClientData
*wxListBox::DoGetItemClientObject(unsigned int n
) const
546 return (wxClientData
*) DoGetItemClientData( n
) ;
549 void wxListBox::DoSetItemClientData(unsigned int n
, void *Client_data
)
551 wxCHECK_RET( IsValid(n
),
552 wxT("invalid index in wxListBox::SetClientData") );
554 #if wxUSE_OWNER_DRAWN
555 if ( m_windowStyle
& wxLB_OWNERDRAW
)
557 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
558 // in OnMeasure/OnDraw.
559 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
561 #endif // wxUSE_OWNER_DRAWN
562 wxASSERT_MSG( m_dataArray
.GetCount() >= (unsigned int) n
, wxT("invalid client_data array") ) ;
564 if ( m_dataArray
.GetCount() > (size_t) n
)
566 m_dataArray
[n
] = (char*) Client_data
;
570 m_dataArray
.Add( (char*) Client_data
) ;
574 void wxListBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
)
576 DoSetItemClientData(n
, clientData
);
579 // Return number of selections and an array of selected integers
580 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
582 return MacGetSelections( aSelections
) ;
585 // Get single selection, for single choice list items
586 int wxListBox::GetSelection() const
588 return MacGetSelection() ;
591 // Find string for position
592 wxString
wxListBox::GetString(unsigned int n
) const
594 return m_stringArray
[n
] ;
597 void wxListBox::DoInsertItems(const wxArrayString
& items
, unsigned int pos
)
599 wxCHECK_RET( IsValidInsert(pos
),
600 wxT("invalid index in wxListBox::InsertItems") );
602 InvalidateBestSize();
604 unsigned int nItems
= items
.GetCount();
606 for ( unsigned int i
= 0 ; i
< nItems
; i
++ )
608 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
609 m_dataArray
.Insert( NULL
, pos
+ i
) ;
610 MacInsert( pos
+ i
, items
[i
] ) ;
616 void wxListBox::SetString(unsigned int n
, const wxString
& s
)
618 m_stringArray
[n
] = s
;
622 wxSize
wxListBox::DoGetBestSize() const
624 int lbWidth
= 100; // some defaults
629 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
633 ::TextFont( m_font
.GetMacFontNum() ) ;
634 ::TextSize( m_font
.GetMacFontSize() ) ;
635 ::TextFace( m_font
.GetMacFontStyle() ) ;
639 ::TextFont( kFontIDMonaco
) ;
644 // Find the widest line
645 for(unsigned int i
= 0; i
< GetCount(); i
++) {
646 wxString
str(GetString(i
));
650 ::GetThemeTextDimensions( wxMacCFStringHolder( str
, m_font
.GetEncoding() ) ,
651 kThemeCurrentPortFont
,
658 wLine
= ::TextWidth( str
.c_str() , 0 , str
.length() ) ;
660 lbWidth
= wxMax(lbWidth
, wLine
);
663 // Add room for the scrollbar
664 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
666 // And just a bit more
668 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
671 // don't make the listbox too tall (limit height to around 10 items) but don't
672 // make it too small neither
673 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
675 return wxSize(lbWidth
, lbHeight
);
678 unsigned int wxListBox::GetCount() const
683 void wxListBox::SetupColours()
685 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
686 SetForegroundColour(GetParent()->GetForegroundColour());
689 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
691 wxControl::Refresh( eraseBack
, rect
) ;
692 // MacRedrawControl() ;
695 #if wxUSE_OWNER_DRAWN
697 class wxListBoxItem
: public wxOwnerDrawn
700 wxListBoxItem(const wxString
& str
= wxEmptyString
);
703 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, false)
705 // no bitmaps/checkmarks
709 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
711 return new wxListBoxItem();
714 #endif //USE_OWNER_DRAWN
716 // ============================================================================
717 // list box control implementation
718 // ============================================================================
721 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
724 // typecast our refCon
725 list = (wxListBox*)refCon;
727 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
728 const wxString text = list->m_stringArray[lCell.v] ;
729 ::TextFont( kFontIDMonaco ) ;
732 DrawText(text, 0 , text.length());
736 void wxListBox::MacDelete( int N
)
738 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
742 void wxListBox::MacInsert( int n
, const wxString
& text
)
744 Cell cell
= { 0 , 0 } ;
746 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
747 // LSetCell(text, strlen(text), cell, m_macList);
751 void wxListBox::MacAppend( const wxString
& text
)
753 Cell cell
= { 0 , 0 } ;
754 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
755 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
756 // LSetCell(text, strlen(text), cell, m_macList);
760 void wxListBox::MacClear()
762 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
766 void wxListBox::MacSetSelection( int n
, bool select
)
768 Cell cell
= { 0 , 0 } ;
769 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
771 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
773 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
778 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
779 LAutoScroll( (ListHandle
)m_macList
) ;
783 bool wxListBox::MacIsSelected( int n
) const
785 Cell cell
= { 0 , 0 } ;
787 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
790 void wxListBox::MacDestroy()
792 // DisposeExtLDEFInfo( m_macList ) ;
795 int wxListBox::MacGetSelection() const
797 Cell cell
= { 0 , 0 } ;
798 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
804 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
810 Cell cell
= { 0 , 0 } ;
813 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
815 aSelections
.Add( cell
.v
) ;
822 void wxListBox::MacSet( int n
, const wxString
& text
)
824 // our implementation does not store anything in the list
825 // so we just have to redraw
826 Cell cell
= { 0 , 0 } ;
828 // LSetCell(text, strlen(text), cell, m_macList);
832 void wxListBox::MacScrollTo( int n
)
834 // TODO implement scrolling
837 void wxListBox::OnSize( wxSizeEvent
&event
)
842 GetListCellSize((ListHandle
)m_macList
, &pt
);
844 pt
= (**(ListHandle
)m_macList
).cellSize
;
846 pt
.h
= m_width
- 15 ;
847 LCellSize( pt
, (ListHandle
)m_macList
) ;
850 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
852 Boolean wasDoubleClick
= false ;
855 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
856 if ( !wasDoubleClick
)
866 void wxListBox::MacSetRedraw( bool doDraw
)
868 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
871 void wxListBox::MacDoClick()
873 wxArrayInt aSelections
;
875 size_t count
= GetSelections(aSelections
);
877 if ( count
== m_selectionPreImage
.GetCount() )
879 bool hasChanged
= false ;
880 for ( size_t i
= 0 ; i
< count
; ++i
)
882 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
894 m_selectionPreImage
= aSelections
;
896 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
897 event
.SetEventObject( this );
902 if ( HasClientObjectData() )
903 event
.SetClientObject( GetClientObject(n
) );
904 else if ( HasClientUntypedData() )
905 event
.SetClientData( GetClientData(n
) );
906 event
.SetString(GetString(n
));
915 GetEventHandler()->ProcessEvent(event
);
918 void wxListBox::MacDoDoubleClick()
920 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
921 event
.SetEventObject( this );
922 GetEventHandler()->ProcessEvent(event
) ;
925 void wxListBox::OnChar(wxKeyEvent
& event
)
927 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
929 wxWindow
* parent
= GetParent() ;
930 while( parent
&& !parent
->IsTopLevel() && parent
->GetDefaultItem() == NULL
)
931 parent
= parent
->GetParent() ;
933 if ( parent
&& parent
->GetDefaultItem() )
935 wxButton
*def
= wxDynamicCast(parent
->GetDefaultItem(),
937 if ( def
&& def
->IsEnabled() )
939 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
940 event
.SetEventObject(def
);
947 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
948 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
950 // FIXME: look in ancestors, not just parent.
951 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
954 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
955 new_event
.SetEventObject( win
);
956 win
->GetEventHandler()->ProcessEvent( new_event
);
959 else if ( event
.GetKeyCode() == WXK_TAB
)
961 wxNavigationKeyEvent new_event
;
962 new_event
.SetEventObject( this );
963 new_event
.SetDirection( !event
.ShiftDown() );
964 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
965 new_event
.SetWindowChange( event
.ControlDown() );
966 new_event
.SetCurrentFocus( this );
967 if ( !GetEventHandler()->ProcessEvent( new_event
) )
970 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
972 // perform the default key handling first
973 wxControl::OnKeyDown( event
) ;
975 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
976 event
.SetEventObject( this );
978 wxArrayInt aSelections
;
979 int n
, count
= GetSelections(aSelections
);
983 if ( HasClientObjectData() )
984 event
.SetClientObject( GetClientObject(n
) );
985 else if ( HasClientUntypedData() )
986 event
.SetClientData( GetClientData(n
) );
987 event
.SetString(GetString(n
));
996 GetEventHandler()->ProcessEvent(event
);
1000 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
1002 m_typeIn
= wxEmptyString
;
1004 m_lastTypeIn
= event
.GetTimestamp() ;
1005 m_typeIn
+= (char) event
.GetKeyCode() ;
1006 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
1009 if ( GetSelection() != line
)
1011 SetSelection(line
) ;
1012 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1013 event
.SetEventObject( this );
1015 if ( HasClientObjectData() )
1016 event
.SetClientObject( GetClientObject( line
) );
1017 else if ( HasClientUntypedData() )
1018 event
.SetClientData( GetClientData(line
) );
1019 event
.SetString(GetString(line
));
1023 GetEventHandler()->ProcessEvent(event
);
1029 #endif // wxUSE_LISTBOX