1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxComboCtrl sample
4 // Author: Jaakko Salli
6 // Created: Apr-30-2006
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWidgets headers)
34 #error "Please set wxUSE_COMBOCTRL to 1 and rebuild the library."
40 #include "wx/odcombo.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 // the application icon (under Windows and OS/2 it is in resources and even
47 // though we could still include the XPM here it would be unused)
48 #if !defined(__WXMSW__) && !defined(__WXPM__)
49 #include "../sample.xpm"
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 // Define a new application type, each program should derive a class from wxApp
57 class MyApp
: public wxApp
60 // override base class virtuals
61 // ----------------------------
63 // this one is called on application startup and is a good place for the app
64 // initialization (doing it here and not in the ctor allows to have an error
65 // return: if OnInit() returns false, the application terminates)
66 virtual bool OnInit();
69 // Define a new frame type: this is going to be our main frame
70 class MyFrame
: public wxFrame
74 MyFrame(const wxString
& title
);
77 // event handlers (these functions should _not_ be virtual)
78 void OnQuit(wxCommandEvent
& event
);
79 void OnAbout(wxCommandEvent
& event
);
81 // log wxComboCtrl events
82 void OnComboBoxUpdate( wxCommandEvent
& event
);
89 // any class wishing to process wxWidgets events must use this macro
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 // IDs for the controls and the menu commands
101 ComboControl_Quit
= wxID_EXIT
,
103 // it is important for the id corresponding to the "About" command to have
104 // this standard value as otherwise it won't be handled properly under Mac
105 // (where it is special and put into the "Apple" menu)
106 ComboControl_About
= wxID_ABOUT
109 // ----------------------------------------------------------------------------
110 // event tables and other macros for wxWidgets
111 // ----------------------------------------------------------------------------
113 // the event tables connect the wxWidgets events with the functions (event
114 // handlers) which process them. It can be also done at run-time, but for the
115 // simple menu events like this the static method is much simpler.
116 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
117 EVT_TEXT(wxID_ANY
,MyFrame::OnComboBoxUpdate
)
118 EVT_COMBOBOX(wxID_ANY
,MyFrame::OnComboBoxUpdate
)
120 EVT_MENU(ComboControl_Quit
, MyFrame::OnQuit
)
121 EVT_MENU(ComboControl_About
, MyFrame::OnAbout
)
124 // Create a new application object: this macro will allow wxWidgets to create
125 // the application object during program execution (it's better than using a
126 // static object for many reasons) and also implements the accessor function
127 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
131 // ============================================================================
133 // ============================================================================
135 // ----------------------------------------------------------------------------
136 // the application class
137 // ----------------------------------------------------------------------------
139 // 'Main program' equivalent: the program execution "starts" here
142 // create the main application window
143 MyFrame
*frame
= new MyFrame(_T("wxComboCtrl Sample"));
145 // and show it (the frames, unlike simple controls, are not shown when
146 // created initially)
149 // success: wxApp::OnRun() will be called which will enter the main message
150 // loop and the application will run. If we returned false here, the
151 // application would exit immediately.
156 // ----------------------------------------------------------------------------
157 // wxListView Custom popup interface
158 // ----------------------------------------------------------------------------
160 #include <wx/listctrl.h>
162 class ListViewComboPopup
: public wxListView
, public wxComboPopup
167 ListViewComboPopup(wxComboCtrlBase* combo)
168 : wxListView(), wxComboPopup(combo)
171 m_itemHere = -1; // hot item in list
177 m_itemHere
= -1; // hot item in list
180 virtual bool Create( wxWindow
* parent
)
182 return wxListView::Create(parent
,1,
183 wxPoint(0,0),wxDefaultSize
,
184 wxLC_LIST
|wxLC_SINGLE_SEL
|
185 wxLC_SORT_ASCENDING
|wxSIMPLE_BORDER
);
188 virtual wxWindow
*GetControl() { return this; }
190 virtual void SetStringValue( const wxString
& s
)
192 int n
= wxListView::FindItem(-1,s
);
193 if ( n
>= 0 && n
< GetItemCount() )
194 wxListView::Select(n
);
197 virtual wxString
GetStringValue() const
200 return wxListView::GetItemText(m_value
);
201 return wxEmptyString
;
205 // Popup event handlers
208 // Mouse hot-tracking
209 void OnMouseMove(wxMouseEvent
& event
)
211 // Move selection to cursor if it is inside the popup
214 int itemHere
= HitTest(event
.GetPosition(),resFlags
);
217 wxListView::Select(itemHere
,true);
218 m_itemHere
= itemHere
;
223 // On mouse left, set the value and close the popup
224 void OnMouseClick(wxMouseEvent
& WXUNUSED(event
))
226 m_value
= m_itemHere
;
232 // Utilies for item manipulation
235 void AddSelection( const wxString
& selstr
)
237 wxListView::InsertItem(GetItemCount(),selstr
);
242 int m_value
; // current item index
243 int m_itemHere
; // hot item in popup
246 DECLARE_EVENT_TABLE()
249 BEGIN_EVENT_TABLE(ListViewComboPopup
, wxListView
)
250 EVT_MOTION(ListViewComboPopup::OnMouseMove
)
251 // NOTE: Left down event is used instead of left up right now
252 // since MSW wxListCtrl doesn't seem to emit left ups
254 EVT_LEFT_DOWN(ListViewComboPopup::OnMouseClick
)
258 // ----------------------------------------------------------------------------
259 // wxTreeCtrl Custom popup interface
260 // ----------------------------------------------------------------------------
262 #include <wx/treectrl.h>
264 class TreeCtrlComboPopup
: public wxTreeCtrl
, public wxComboPopup
269 TreeCtrlComboPopup(wxComboCtrlBase* combo)
270 : wxTreeCtrl(), wxComboPopup(combo)
279 virtual bool Create( wxWindow
* parent
)
281 return wxTreeCtrl::Create(parent
,1,
282 wxPoint(0,0),wxDefaultSize
,
283 wxTR_HIDE_ROOT
|wxTR_HAS_BUTTONS
|
284 wxTR_SINGLE
|wxTR_LINES_AT_ROOT
|
288 virtual void OnShow()
290 // make sure selected item is visible
291 if ( m_value
.IsOk() )
292 EnsureVisible(m_value
);
295 virtual wxSize
GetAdjustedSize( int minWidth
,
296 int WXUNUSED(prefHeight
),
299 return wxSize(wxMax(300,minWidth
),wxMin(250,maxHeight
));
302 virtual wxWindow
*GetControl() { return this; }
304 // Needed by SetStringValue
305 wxTreeItemId
FindItemByText( wxTreeItemId parent
, const wxString
& text
)
307 wxTreeItemIdValue cookie
;
308 wxTreeItemId child
= GetFirstChild(parent
,cookie
);
309 while ( child
.IsOk() )
311 if ( GetItemText(child
) == text
)
315 if ( ItemHasChildren(child
) )
317 wxTreeItemId found
= FindItemByText(child
,text
);
321 child
= GetNextChild(parent
,cookie
);
323 return wxTreeItemId();
326 virtual void SetStringValue( const wxString
& s
)
328 wxTreeItemId root
= GetRootItem();
332 wxTreeItemId found
= FindItemByText(root
,s
);
335 m_value
= m_itemHere
= found
;
336 wxTreeCtrl::SelectItem(found
);
340 virtual wxString
GetStringValue() const
342 if ( m_value
.IsOk() )
343 return wxTreeCtrl::GetItemText(m_value
);
344 return wxEmptyString
;
348 // Popup event handlers
351 // Mouse hot-tracking
352 void OnMouseMove(wxMouseEvent
& event
)
355 wxTreeItemId itemHere
= HitTest(event
.GetPosition(),resFlags
);
356 if ( itemHere
.IsOk() && (resFlags
& wxTREE_HITTEST_ONITEMLABEL
) )
358 wxTreeCtrl::SelectItem(itemHere
,true);
359 m_itemHere
= itemHere
;
364 // On mouse left, set the value and close the popup
365 void OnMouseClick(wxMouseEvent
& event
)
368 wxTreeItemId itemHere
= HitTest(event
.GetPosition(),resFlags
);
369 if ( itemHere
.IsOk() && (resFlags
& wxTREE_HITTEST_ONITEMLABEL
) )
371 m_itemHere
= itemHere
;
381 wxTreeItemId m_value
; // current item index
382 wxTreeItemId m_itemHere
; // hot item in popup
385 DECLARE_EVENT_TABLE()
388 BEGIN_EVENT_TABLE(TreeCtrlComboPopup
, wxTreeCtrl
)
389 EVT_MOTION(TreeCtrlComboPopup::OnMouseMove
)
390 // NOTE: Left down event is used instead of left up right now
391 // since MSW wxTreeCtrl doesn't seem to emit left ups
393 EVT_LEFT_DOWN(TreeCtrlComboPopup::OnMouseClick
)
396 // ----------------------------------------------------------------------------
397 // wxOwnerDrawnComboBox with custom paint list items
398 // ----------------------------------------------------------------------------
400 class wxPenStyleComboBox
: public wxOwnerDrawnComboBox
403 virtual void OnDrawItem( wxDC
& dc
,
408 if ( item
== wxNOT_FOUND
)
415 int pen_style
= wxSOLID
;
417 pen_style
= wxTRANSPARENT
;
418 else if ( item
== 2 )
420 else if ( item
== 3 )
421 pen_style
= wxLONG_DASH
;
422 else if ( item
== 4 )
423 pen_style
= wxSHORT_DASH
;
424 else if ( item
== 5 )
425 pen_style
= wxDOT_DASH
;
426 else if ( item
== 6 )
427 pen_style
= wxBDIAGONAL_HATCH
;
428 else if ( item
== 7 )
429 pen_style
= wxCROSSDIAG_HATCH
;
430 else if ( item
== 8 )
431 pen_style
= wxFDIAGONAL_HATCH
;
432 else if ( item
== 9 )
433 pen_style
= wxCROSS_HATCH
;
434 else if ( item
== 10 )
435 pen_style
= wxHORIZONTAL_HATCH
;
436 else if ( item
== 11 )
437 pen_style
= wxVERTICAL_HATCH
;
439 wxPen
pen( dc
.GetTextForeground(), 3, pen_style
);
441 // Get text colour as pen colour
444 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
446 dc
.DrawText(GetString( item
),
448 (r
.y
+ 0) + ( (r
.height
/2) - dc
.GetCharHeight() )/2
451 dc
.DrawLine( r
.x
+5, r
.y
+((r
.height
/4)*3), r
.x
+r
.width
- 5, r
.y
+((r
.height
/4)*3) );
455 dc
.DrawLine( r
.x
+5, r
.y
+r
.height
/2, r
.x
+r
.width
- 5, r
.y
+r
.height
/2 );
459 virtual wxCoord
OnMeasureItem( size_t WXUNUSED(item
) ) const
464 virtual wxCoord
OnMeasureItemWidth( size_t WXUNUSED(item
) ) const
466 return -1; // default - will be measured from text width
471 // ----------------------------------------------------------------------------
472 // wxComboCtrl with entirely custom button action (opens file dialog)
473 // ----------------------------------------------------------------------------
475 class wxFileSelectorCombo
: public wxComboCtrl
478 wxFileSelectorCombo() : wxComboCtrl() { Init(); }
480 wxFileSelectorCombo(wxWindow
*parent
,
481 wxWindowID id
= wxID_ANY
,
482 const wxString
& value
= wxEmptyString
,
483 const wxPoint
& pos
= wxDefaultPosition
,
484 const wxSize
& size
= wxDefaultSize
,
486 const wxValidator
& validator
= wxDefaultValidator
,
487 const wxString
& name
= wxComboBoxNameStr
)
491 Create(parent
,id
,value
,
493 // Style flag wxCC_STD_BUTTON makes the button
494 // behave more like a standard push button.
495 style
| wxCC_STD_BUTTON
,
499 // Prepare custom button bitmap (just '...' text)
502 dc
.SelectObject(bmp
);
504 // Draw transparent background
505 wxColour
magic(255,0,255);
506 wxBrush
magicBrush(magic
);
507 dc
.SetBrush( magicBrush
);
508 dc
.SetPen( *wxTRANSPARENT_PEN
);
509 dc
.DrawRectangle(0,0,bmp
.GetWidth(),bmp
.GetHeight());
512 wxString str
= wxT("...");
514 dc
.GetTextExtent(str
, &w
, &h
, 0, 0);
515 dc
.DrawText(str
, (bmp
.GetWidth()-w
)/2, (bmp
.GetHeight()-h
)/2);
517 dc
.SelectObject( wxNullBitmap
);
519 // Finalize transparency with a mask
520 wxMask
*mask
= new wxMask( bmp
, magic
);
523 SetButtonBitmaps(bmp
,true);
526 virtual void OnButtonClick()
528 // Show standard wxFileDialog on button click
530 wxFileDialog
dlg(this,
534 wxT("All files (*.*)|*.*"),
537 if ( dlg
.ShowModal() == wxID_OK
)
539 SetValue(dlg
.GetPath());
546 // Initialize member variables here
550 // ----------------------------------------------------------------------------
552 // ----------------------------------------------------------------------------
555 MyFrame::MyFrame(const wxString
& title
)
556 : wxFrame(NULL
, wxID_ANY
, title
)
558 wxBoxSizer
* topSizer
;
559 wxBoxSizer
* topRowSizer
;
560 wxBoxSizer
* colSizer
;
561 wxBoxSizer
* rowSizer
;
562 wxStaticBoxSizer
* groupSizer
;
564 // set the frame icon
565 SetIcon(wxICON(sample
));
569 wxMenu
*fileMenu
= new wxMenu
;
571 // the "About" item should be in the help menu
572 wxMenu
*helpMenu
= new wxMenu
;
573 helpMenu
->Append(ComboControl_About
, _T("&About...\tF1"), _T("Show about dialog"));
575 fileMenu
->Append(ComboControl_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
577 // now append the freshly created menu to the menu bar...
578 wxMenuBar
*menuBar
= new wxMenuBar();
579 menuBar
->Append(fileMenu
, _T("&File"));
580 menuBar
->Append(helpMenu
, _T("&Help"));
582 // ... and attach this menu bar to the frame
584 #endif // wxUSE_MENUS
586 wxPanel
* panel
= new wxPanel(this);
588 // Prepare log window right away since it shows EVT_TEXTs
589 m_logWin
= new wxTextCtrl( panel
, 105, wxEmptyString
, wxDefaultPosition
,
590 wxSize(-1,125), wxTE_MULTILINE
|wxFULL_REPAINT_ON_RESIZE
);
591 m_logWin
->SetEditable(false);
592 wxLogTextCtrl
* logger
= new wxLogTextCtrl( m_logWin
);
593 m_logOld
= logger
->SetActiveTarget( logger
);
594 logger
->SetTimestamp( NULL
);
597 topSizer
= new wxBoxSizer( wxVERTICAL
);
599 topRowSizer
= new wxBoxSizer( wxHORIZONTAL
);
601 colSizer
= new wxBoxSizer( wxVERTICAL
);
604 // Make sure GetFeatures is implemented
605 int features
= wxComboCtrl::GetFeatures();
606 wxLogDebug(wxT("wxComboCtrl features: 0x%X (all features: 0x%X)"),
607 features
,wxComboCtrlFeatures::All
);
612 wxGenericComboControl
* gcc
;
613 wxOwnerDrawnComboBox
* odc
;
615 // Create common strings array
616 wxArrayString arrItems
;
617 arrItems
.Add( wxT("Solid") );
618 arrItems
.Add( wxT("Transparent") );
619 arrItems
.Add( wxT("Dot") );
620 arrItems
.Add( wxT("Long Dash") );
621 arrItems
.Add( wxT("Short Dash") );
622 arrItems
.Add( wxT("Dot Dash") );
623 arrItems
.Add( wxT("Backward Diagonal Hatch") );
624 arrItems
.Add( wxT("Cross-diagonal Hatch") );
625 arrItems
.Add( wxT("Forward Diagonal Hatch") );
626 arrItems
.Add( wxT("Cross Hatch") );
627 arrItems
.Add( wxT("Horizontal Hatch") );
628 arrItems
.Add( wxT("Vertical Hatch") );
633 // Show some wxOwnerDrawComboBoxes for comparison
635 rowSizer
= new wxBoxSizer(wxHORIZONTAL
);
637 groupSizer
= new wxStaticBoxSizer(new wxStaticBox(panel
,wxID_ANY
,wxT(" wxOwnerDrawnComboBox ")),
640 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Writable, sorted:")), 0,
641 wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxEXPAND
, border
);
643 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
644 wxDefaultPosition
, wxDefaultSize
,
646 wxCB_SORT
// wxNO_BORDER|wxCB_READONLY
649 odc
->Append(wxT("H - Appended Item")); // test sorting in append
651 odc
->SetValue(wxT("Dot Dash"));
653 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
656 // Readonly ODComboBox
657 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Read-only:")), 0,
658 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
660 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
661 wxDefaultPosition
, wxDefaultSize
,
663 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
666 odc
->SetValue(wxT("Dot Dash"));
667 odc
->SetText(wxT("Dot Dash (Testing SetText)"));
669 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
672 // Disabled ODComboBox
673 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Disabled:")), 0,
674 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
676 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
677 wxDefaultPosition
, wxDefaultSize
,
679 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
682 odc
->SetValue(wxT("Dot Dash"));
685 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
687 rowSizer
->Add( groupSizer
, 1, wxEXPAND
|wxALL
, border
);
690 groupSizer
= new wxStaticBoxSizer(new wxStaticBox(panel
,wxID_ANY
,wxT(" wxComboBox ")),
696 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Writable, sorted:")), 0,
697 wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxEXPAND
, border
);
699 cb
= new wxComboBox(panel
,wxID_ANY
,wxEmptyString
,
700 wxDefaultPosition
, wxDefaultSize
,
702 wxCB_SORT
// wxNO_BORDER|wxCB_READONLY
705 cb
->Append(wxT("H - Appended Item")); // test sorting in append
707 cb
->SetValue(wxT("Dot Dash"));
709 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
712 // Readonly wxComboBox
713 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Read-only:")), 0,
714 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
716 cb
= new wxComboBox(panel
,wxID_ANY
,wxEmptyString
,
717 wxDefaultPosition
, wxDefaultSize
,
719 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
722 cb
->SetValue(wxT("Dot Dash"));
724 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
727 // Disabled wxComboBox
728 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Disabled:")), 0,
729 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
731 cb
= new wxComboBox(panel
,wxID_ANY
,wxEmptyString
,
732 wxDefaultPosition
, wxDefaultSize
,
734 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
737 cb
->SetValue(wxT("Dot Dash"));
740 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
742 rowSizer
->Add( groupSizer
, 1, wxEXPAND
|wxALL
, border
);
745 colSizer
->Add( rowSizer
, 1, wxEXPAND
|wxALL
, border
);
749 // Pen selector ODComboBox with application painted items
751 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
752 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
753 wxT("OwnerDrawnComboBox with Custom Paint Items and Button Placing:")), 1,
754 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
755 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
757 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
759 // When defining derivative class for callbacks, we need
760 // to use two-stage creation (or redefine the common wx
762 odc
= new wxPenStyleComboBox();
763 odc
->Create(panel
,wxID_ANY
,wxEmptyString
,
764 wxDefaultPosition
, wxDefaultSize
,
766 wxCB_READONLY
//wxNO_BORDER | wxCB_READONLY
769 odc
->SetSelection(0);
770 odc
->SetButtonPosition(-2, // width adjustment
771 -6, // height adjustment
773 2 // horizontal spacing
776 rowSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
777 rowSizer
->AddStretchSpacer(1);
778 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
782 // List View wxComboCtrl
785 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
786 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("List View wxComboCtrl:")), 1,
787 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
788 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Tree Ctrl wxGenericComboControl:")), 1,
789 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
790 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
792 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
793 cc
= new wxComboCtrl(panel
,2,wxEmptyString
,
794 wxDefaultPosition
, wxDefaultSize
);
796 cc
->SetPopupMinWidth(300);
798 ListViewComboPopup
* iface
= new ListViewComboPopup();
799 cc
->SetPopupControl(iface
);
801 iface
->AddSelection( wxT("Cabbage") );
802 iface
->AddSelection( wxT("Potato") );
803 iface
->AddSelection( wxT("Onion") );
804 iface
->AddSelection( wxT("Carrot") );
805 iface
->AddSelection( wxT("Cauliflower") );
806 iface
->AddSelection( wxT("Bean") );
807 iface
->AddSelection( wxT("Raddish") );
808 iface
->AddSelection( wxT("Banana") );
809 iface
->AddSelection( wxT("Apple") );
810 iface
->AddSelection( wxT("Orange") );
811 iface
->AddSelection( wxT("Kiwi") );
812 iface
->AddSelection( wxT("Strawberry") );
813 iface
->AddSelection( wxT("Cucumber") );
814 iface
->AddSelection( wxT("Blackberry") );
815 iface
->AddSelection( wxT("Melon") );
816 iface
->AddSelection( wxT("Cherry") );
817 iface
->AddSelection( wxT("Pea") );
818 iface
->AddSelection( wxT("Pear") );
820 rowSizer
->Add( cc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
824 // Tree Ctrl wxComboCtrl
827 // Note that we test that wxGenericComboControl works
828 gcc
= new wxGenericComboControl(panel
,wxID_ANY
,wxEmptyString
,
829 wxDefaultPosition
, wxDefaultSize
);
831 // Set popup interface right away, otherwise some of the calls
833 TreeCtrlComboPopup
* tcPopup
= new TreeCtrlComboPopup();
834 gcc
->SetPopupControl(tcPopup
);
836 // Add items using wxTreeCtrl methods directly
837 wxTreeItemId rootId
= tcPopup
->AddRoot(wxT("<hidden_root>"));
839 wxTreeItemId groupId
;
841 groupId
= tcPopup
->AppendItem(rootId
,wxT("Controls"));
842 tcPopup
->AppendItem(groupId
,wxT("wxButton"));
843 tcPopup
->AppendItem(groupId
,wxT("wxCheckBox"));
844 tcPopup
->AppendItem(groupId
,wxT("wxListCtrl"));
845 tcPopup
->AppendItem(groupId
,wxT("wxStaticBox"));
846 tcPopup
->AppendItem(groupId
,wxT("wxStaticText"));
847 tcPopup
->AppendItem(groupId
,wxT("wxTextCtrl"));
848 tcPopup
->AppendItem(groupId
,wxT("wxTreeCtrl"));
849 groupId
= tcPopup
->AppendItem(rootId
,wxT("Dialogs"));
850 tcPopup
->AppendItem(groupId
,wxT("wxDirDialog"));
851 tcPopup
->AppendItem(groupId
,wxT("wxFileDialog"));
852 tcPopup
->AppendItem(groupId
,wxT("wxWizard"));
854 gcc
->SetValue(wxT("wxStaticBox"));
856 // Move button to left - it makes more sense for a tree ctrl
857 gcc
->SetButtonPosition(0, // width adjustment
858 0, // height adjustment
860 0 // horizontal spacing
863 rowSizer
->Add( gcc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
865 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
868 wxInitAllImageHandlers();
871 // Custom Dropbutton Bitmaps
872 // (second one uses blank button background)
874 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
875 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
876 wxT("OwnerDrawnComboBox with simple dropbutton graphics:")), 1,
877 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
879 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
881 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
883 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
884 wxDefaultPosition
, wxDefaultSize
,
886 (long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
889 wxOwnerDrawnComboBox
* odc2
;
890 odc2
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
891 wxDefaultPosition
, wxDefaultSize
,
893 (long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
896 // Load images from disk
897 wxImage
imgNormal(wxT("dropbutn.png"));
898 wxImage
imgPressed(wxT("dropbutp.png"));
899 wxImage
imgHover(wxT("dropbuth.png"));
901 if ( imgNormal
.Ok() && imgPressed
.Ok() && imgHover
.Ok() )
903 wxBitmap
bmpNormal(imgNormal
);
904 wxBitmap
bmpPressed(imgPressed
);
905 wxBitmap
bmpHover(imgHover
);
906 odc
->SetButtonBitmaps(bmpNormal
,false,bmpPressed
,bmpHover
);
907 odc2
->SetButtonBitmaps(bmpNormal
,true,bmpPressed
,bmpHover
);
910 wxLogError(wxT("Dropbutton images not found"));
912 //odc2->SetButtonPosition(0, // width adjustment
913 // 0, // height adjustment
915 // 0 // horizontal spacing
918 rowSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
919 rowSizer
->Add( odc2
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
920 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
925 // wxComboCtrl with totally custom button action (open file dialog)
927 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
928 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
929 wxT("wxComboCtrl with custom button action:")), 1,
930 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
933 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
935 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
936 wxFileSelectorCombo
* fsc
;
938 fsc
= new wxFileSelectorCombo(panel
,wxID_ANY
,wxEmptyString
,
939 wxDefaultPosition
, wxDefaultSize
,
943 rowSizer
->Add( fsc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
944 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
947 topRowSizer
->Add( colSizer
, 1, wxALL
, 2 );
949 topRowSizer
->Add( m_logWin
, 1, wxEXPAND
|wxALL
, 5 );
950 topSizer
->Add( topRowSizer
, 1, wxEXPAND
);
952 panel
->SetSizer( topSizer
);
953 topSizer
->SetSizeHints( panel
);
961 delete wxLog::SetActiveTarget(m_logOld
);
966 void MyFrame::OnComboBoxUpdate( wxCommandEvent
& event
)
968 // Don't show messages for the log output window (it'll crash)
969 if ( event
.GetId() == 105 )
972 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
973 wxLogDebug(wxT("EVT_COMBOBOX(id=%i,selection=%i)"),event
.GetId(),event
.GetSelection());
974 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
975 wxLogDebug(wxT("EVT_TEXT(id=%i,string=\"%s\")"),event
.GetId(),event
.GetString().c_str());
978 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
980 // true is to force the frame to close
984 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
986 wxMessageBox(wxString::Format(
987 _T("Welcome to %s!\n")
989 _T("This is the wxWidgets wxComboCtrl sample\n")
990 _T("running under %s."),
992 wxGetOsDescription().c_str()
994 _T("About wxComboCtrl sample"),
995 wxOK
| wxICON_INFORMATION
,