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"
23 #include "wx/button.h"
24 #include "wx/settings.h"
25 #include "wx/toplevel.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
30 BEGIN_EVENT_TABLE(wxListBox
, wxControl
)
31 EVT_SIZE( wxListBox::OnSize
)
32 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
= (WXWidget
) ::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 ( unsigned int n
= 0; n
< 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(unsigned int n
)
383 wxCHECK_RET( IsValid(n
),
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 InvalidateBestSize();
406 unsigned int index
= m_noItems
;
407 m_stringArray
.Add( item
) ;
408 m_dataArray
.Add( NULL
);
410 DoSetItemClientData( index
, NULL
) ;
416 void wxListBox::DoSetItems(const wxArrayString
& choices
, void** clientData
)
418 MacSetRedraw( false ) ;
420 int n
= choices
.GetCount();
422 for( int i
= 0 ; i
< n
; ++i
)
426 #if wxUSE_OWNER_DRAWN
427 wxASSERT_MSG(clientData
[i
] == NULL
,
428 wxT("Can't use client data with owner-drawn listboxes"));
429 #else // !wxUSE_OWNER_DRAWN
430 Append( choices
[i
] , clientData
[i
] ) ;
434 Append( choices
[i
] ) ;
437 #if wxUSE_OWNER_DRAWN
438 if ( m_windowStyle
& wxLB_OWNERDRAW
) {
439 // first delete old items
440 unsigned int ui
= m_aItems
.Count();
441 while ( ui
-- != 0 ) {
447 // then create new ones
448 for ( ui
= 0; ui
< m_noItems
; ui
++ ) {
449 wxOwnerDrawn
*pNewItem
= CreateItem(ui
);
450 pNewItem
->SetName(choices
[ui
]);
451 m_aItems
.Add(pNewItem
);
454 #endif // wxUSE_OWNER_DRAWN
455 MacSetRedraw( true ) ;
458 bool wxListBox::HasMultipleSelection() const
460 return (m_windowStyle
& wxLB_MULTIPLE
) || (m_windowStyle
& wxLB_EXTENDED
);
463 int wxListBox::FindString(const wxString
& s
, bool bCase
) const
465 if ( s
.Right(1) == wxT("*") )
467 wxString search
= s
.Left( s
.length() - 1 ) ;
468 int len
= search
.length() ;
470 wxMacStringToPascal( search
, s2
) ;
472 for ( unsigned int i
= 0 ; i
< m_noItems
; ++ i
)
474 wxMacStringToPascal( m_stringArray
[i
].Left( len
) , s1
) ;
476 if ( EqualString( s1
, s2
, bCase
, false ) )
479 if ( s
.Left(1) == wxT("*") && s
.length() > 1 )
483 for ( unsigned int i
= 0 ; i
< m_noItems
; ++i
)
485 if (GetString(i
).Lower().Matches(st
))
495 wxMacStringToPascal( s
, s2
) ;
497 for ( unsigned int i
= 0 ; i
< m_noItems
; ++ i
)
499 wxMacStringToPascal( m_stringArray
[i
] , s1
) ;
501 if ( EqualString( s1
, s2
, bCase
, false ) )
509 void wxListBox::Clear()
513 m_stringArray
.Empty() ;
514 m_dataArray
.Empty() ;
518 void wxListBox::DoSetSelection(int N
, bool select
)
520 wxCHECK_RET( IsValid(N
),
521 wxT("invalid index in wxListBox::SetSelection") );
522 MacSetSelection( N
, select
) ;
523 GetSelections( m_selectionPreImage
) ;
526 bool wxListBox::IsSelected(int N
) const
528 wxCHECK_MSG( IsValid(N
), false,
529 wxT("invalid index in wxListBox::Selected") );
531 return MacIsSelected( N
) ;
534 void *wxListBox::DoGetItemClientData(unsigned int n
) const
536 wxCHECK_MSG( IsValid(n
), NULL
,
537 wxT("invalid index in wxListBox::GetClientData"));
539 return (void *)m_dataArray
[n
];
542 wxClientData
*wxListBox::DoGetItemClientObject(unsigned int n
) const
544 return (wxClientData
*) DoGetItemClientData( n
) ;
547 void wxListBox::DoSetItemClientData(unsigned int n
, void *Client_data
)
549 wxCHECK_RET( IsValid(n
),
550 wxT("invalid index in wxListBox::SetClientData") );
552 #if wxUSE_OWNER_DRAWN
553 if ( m_windowStyle
& wxLB_OWNERDRAW
)
555 // client data must be pointer to wxOwnerDrawn, otherwise we would crash
556 // in OnMeasure/OnDraw.
557 wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
559 #endif // wxUSE_OWNER_DRAWN
560 wxASSERT_MSG( m_dataArray
.GetCount() >= (unsigned int) n
, wxT("invalid client_data array") ) ;
562 if ( m_dataArray
.GetCount() > (size_t) n
)
564 m_dataArray
[n
] = (char*) Client_data
;
568 m_dataArray
.Add( (char*) Client_data
) ;
572 void wxListBox::DoSetItemClientObject(unsigned int n
, wxClientData
* clientData
)
574 DoSetItemClientData(n
, clientData
);
577 // Return number of selections and an array of selected integers
578 int wxListBox::GetSelections(wxArrayInt
& aSelections
) const
580 return MacGetSelections( aSelections
) ;
583 // Get single selection, for single choice list items
584 int wxListBox::GetSelection() const
586 return MacGetSelection() ;
589 // Find string for position
590 wxString
wxListBox::GetString(unsigned int n
) const
592 return m_stringArray
[n
] ;
595 void wxListBox::DoInsertItems(const wxArrayString
& items
, unsigned int pos
)
597 wxCHECK_RET( IsValidInsert(pos
),
598 wxT("invalid index in wxListBox::InsertItems") );
600 InvalidateBestSize();
602 unsigned int nItems
= items
.GetCount();
604 for ( unsigned int i
= 0 ; i
< nItems
; i
++ )
606 m_stringArray
.Insert( items
[i
] , pos
+ i
) ;
607 m_dataArray
.Insert( NULL
, pos
+ i
) ;
608 MacInsert( pos
+ i
, items
[i
] ) ;
614 void wxListBox::SetString(unsigned int n
, const wxString
& s
)
616 m_stringArray
[n
] = s
;
620 wxSize
wxListBox::DoGetBestSize() const
622 int lbWidth
= 100; // some defaults
627 wxMacPortStateHelper
st( UMAGetWindowPort( (WindowRef
) MacGetRootWindow() ) ) ;
631 ::TextFont( m_font
.GetMacFontNum() ) ;
632 ::TextSize( m_font
.GetMacFontSize() ) ;
633 ::TextFace( m_font
.GetMacFontStyle() ) ;
637 ::TextFont( kFontIDMonaco
) ;
642 // Find the widest line
643 for(unsigned int i
= 0; i
< GetCount(); i
++) {
644 wxString
str(GetString(i
));
648 ::GetThemeTextDimensions( wxMacCFStringHolder( str
, m_font
.GetEncoding() ) ,
649 kThemeCurrentPortFont
,
656 wLine
= ::TextWidth( str
.c_str() , 0 , str
.length() ) ;
658 lbWidth
= wxMax(lbWidth
, wLine
);
661 // Add room for the scrollbar
662 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
664 // And just a bit more
666 int cx
= ::TextWidth( "X" , 0 , 1 ) ;
669 // don't make the listbox too tall (limit height to around 10 items) but don't
670 // make it too small neither
671 lbHeight
= (cy
+4) * wxMin(wxMax(GetCount(), 3), 10);
673 return wxSize(lbWidth
, lbHeight
);
676 unsigned int wxListBox::GetCount() const
681 void wxListBox::SetupColours()
683 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
684 SetForegroundColour(GetParent()->GetForegroundColour());
687 void wxListBox::Refresh(bool eraseBack
, const wxRect
*rect
)
689 wxControl::Refresh( eraseBack
, rect
) ;
690 // MacRedrawControl() ;
693 #if wxUSE_OWNER_DRAWN
695 class wxListBoxItem
: public wxOwnerDrawn
698 wxListBoxItem(const wxString
& str
= wxEmptyString
);
701 wxListBoxItem::wxListBoxItem(const wxString
& str
) : wxOwnerDrawn(str
, false)
703 // no bitmaps/checkmarks
707 wxOwnerDrawn
*wxListBox::CreateItem(size_t n
)
709 return new wxListBoxItem();
712 #endif //USE_OWNER_DRAWN
714 // ============================================================================
715 // list box control implementation
716 // ============================================================================
719 void MacDrawStringCell(Rect *cellRect, Cell lCell, ListHandle theList, long refCon)
722 // typecast our refCon
723 list = (wxListBox*)refCon;
725 MoveTo(cellRect->left + 4 , cellRect->top + 10 );
726 const wxString text = list->m_stringArray[lCell.v] ;
727 ::TextFont( kFontIDMonaco ) ;
730 DrawText(text, 0 , text.length());
734 void wxListBox::MacDelete( int N
)
736 LDelRow( 1 , N
, (ListHandle
)m_macList
) ;
740 void wxListBox::MacInsert( int n
, const wxString
& text
)
742 Cell cell
= { 0 , 0 } ;
744 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
745 // LSetCell(text, strlen(text), cell, m_macList);
749 void wxListBox::MacAppend( const wxString
& text
)
751 Cell cell
= { 0 , 0 } ;
752 cell
.v
= (**(ListHandle
)m_macList
).dataBounds
.bottom
;
753 LAddRow( 1 , cell
.v
, (ListHandle
)m_macList
) ;
754 // LSetCell(text, strlen(text), cell, m_macList);
758 void wxListBox::MacClear()
760 LDelRow( (**(ListHandle
)m_macList
).dataBounds
.bottom
, 0 ,(ListHandle
) m_macList
) ;
764 void wxListBox::MacSetSelection( int n
, bool select
)
766 Cell cell
= { 0 , 0 } ;
767 if ( ! (m_windowStyle
& wxLB_MULTIPLE
) )
769 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
771 LSetSelect( false , cell
, (ListHandle
)m_macList
) ;
776 LSetSelect( select
, cell
, (ListHandle
)m_macList
) ;
777 LAutoScroll( (ListHandle
)m_macList
) ;
781 bool wxListBox::MacIsSelected( int n
) const
783 Cell cell
= { 0 , 0 } ;
785 return LGetSelect( false , &cell
, (ListHandle
)m_macList
) ;
788 void wxListBox::MacDestroy()
790 // DisposeExtLDEFInfo( m_macList ) ;
793 int wxListBox::MacGetSelection() const
795 Cell cell
= { 0 , 0 } ;
796 if ( LGetSelect( true , &cell
, (ListHandle
)m_macList
) )
802 int wxListBox::MacGetSelections( wxArrayInt
& aSelections
) const
808 Cell cell
= { 0 , 0 } ;
811 while ( LGetSelect( true , &cell
,(ListHandle
) m_macList
) )
813 aSelections
.Add( cell
.v
) ;
820 void wxListBox::MacSet( int n
, const wxString
& text
)
822 // our implementation does not store anything in the list
823 // so we just have to redraw
824 Cell cell
= { 0 , 0 } ;
826 // LSetCell(text, strlen(text), cell, m_macList);
830 void wxListBox::MacScrollTo( int n
)
832 // TODO implement scrolling
835 void wxListBox::OnSize( wxSizeEvent
&event
)
840 GetListCellSize((ListHandle
)m_macList
, &pt
);
842 pt
= (**(ListHandle
)m_macList
).cellSize
;
844 pt
.h
= m_width
- 15 ;
845 LCellSize( pt
, (ListHandle
)m_macList
) ;
848 void wxListBox::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED(mouseStillDown
))
850 Boolean wasDoubleClick
= false ;
853 ::GetControlData( (ControlHandle
) m_macControl
, kControlNoPart
, kControlListBoxDoubleClickTag
, sizeof( wasDoubleClick
) , (char*) &wasDoubleClick
, &result
) ;
854 if ( !wasDoubleClick
)
864 void wxListBox::MacSetRedraw( bool doDraw
)
866 LSetDrawingMode( doDraw
, (ListHandle
)m_macList
) ;
869 void wxListBox::MacDoClick()
871 wxArrayInt aSelections
;
873 size_t count
= GetSelections(aSelections
);
875 if ( count
== m_selectionPreImage
.GetCount() )
877 bool hasChanged
= false ;
878 for ( size_t i
= 0 ; i
< count
; ++i
)
880 if ( aSelections
[i
] != m_selectionPreImage
[i
] )
892 m_selectionPreImage
= aSelections
;
894 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
895 event
.SetEventObject( this );
900 if ( HasClientObjectData() )
901 event
.SetClientObject( GetClientObject(n
) );
902 else if ( HasClientUntypedData() )
903 event
.SetClientData( GetClientData(n
) );
904 event
.SetString(GetString(n
));
913 GetEventHandler()->ProcessEvent(event
);
916 void wxListBox::MacDoDoubleClick()
918 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, m_windowId
);
919 event
.SetEventObject( this );
920 GetEventHandler()->ProcessEvent(event
) ;
923 void wxListBox::OnChar(wxKeyEvent
& event
)
925 if ( event
.GetKeyCode() == WXK_RETURN
|| event
.GetKeyCode() == WXK_NUMPAD_ENTER
)
927 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
928 if ( tlw
&& tlw
->GetDefaultItem() )
930 wxButton
*def
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
931 if ( def
&& def
->IsEnabled() )
933 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
934 event
.SetEventObject(def
);
941 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
942 else if (event
.GetKeyCode() == WXK_ESCAPE
|| (event
.GetKeyCode() == '.' && event
.MetaDown() ) )
944 // FIXME: look in ancestors, not just parent.
945 wxWindow
* win
= GetParent()->FindWindow( wxID_CANCEL
) ;
948 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
949 new_event
.SetEventObject( win
);
950 win
->GetEventHandler()->ProcessEvent( new_event
);
953 else if ( event
.GetKeyCode() == WXK_TAB
)
955 wxNavigationKeyEvent new_event
;
956 new_event
.SetEventObject( this );
957 new_event
.SetDirection( !event
.ShiftDown() );
958 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
959 new_event
.SetWindowChange( event
.ControlDown() );
960 new_event
.SetCurrentFocus( this );
961 if ( !GetEventHandler()->ProcessEvent( new_event
) )
964 else if ( event
.GetKeyCode() == WXK_DOWN
|| event
.GetKeyCode() == WXK_UP
)
966 // perform the default key handling first
967 wxControl::OnKeyDown( event
) ;
969 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
970 event
.SetEventObject( this );
972 wxArrayInt aSelections
;
973 int n
, count
= GetSelections(aSelections
);
977 if ( HasClientObjectData() )
978 event
.SetClientObject( GetClientObject(n
) );
979 else if ( HasClientUntypedData() )
980 event
.SetClientData( GetClientData(n
) );
981 event
.SetString(GetString(n
));
990 GetEventHandler()->ProcessEvent(event
);
994 if ( event
.GetTimestamp() > m_lastTypeIn
+ 60 )
996 m_typeIn
= wxEmptyString
;
998 m_lastTypeIn
= event
.GetTimestamp() ;
999 m_typeIn
+= (char) event
.GetKeyCode() ;
1000 int line
= FindString(wxT("*")+m_typeIn
+wxT("*")) ;
1003 if ( GetSelection() != line
)
1005 SetSelection(line
) ;
1006 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, m_windowId
);
1007 event
.SetEventObject( this );
1009 if ( HasClientObjectData() )
1010 event
.SetClientObject( GetClientObject( line
) );
1011 else if ( HasClientUntypedData() )
1012 event
.SetClientData( GetClientData(line
) );
1013 event
.SetString(GetString(line
));
1017 GetEventHandler()->ProcessEvent(event
);
1023 #endif // wxUSE_LISTBOX