1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxComboControl 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)
33 #if !wxUSE_COMBOCONTROL
34 #error "Please set wxUSE_COMBOCONTROL 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 wxComboControl 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("wxComboControl 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
166 ListViewComboPopup(wxComboControlBase
* combo
)
167 : wxListView(), wxComboPopup(combo
)
170 m_itemHere
= -1; // hot item in list
173 virtual bool Create( wxWindow
* parent
)
175 return wxListView::Create(parent
,1,
176 wxPoint(0,0),wxDefaultSize
,
177 wxLC_LIST
|wxLC_SINGLE_SEL
|
178 wxLC_SORT_ASCENDING
|wxSIMPLE_BORDER
);
181 virtual wxWindow
*GetControl() { return this; }
183 virtual void SetStringValue( const wxString
& s
)
185 int n
= wxListView::FindItem(-1,s
);
186 if ( n
>= 0 && n
< GetItemCount() )
187 wxListView::Select(n
);
190 virtual wxString
GetStringValue() const
193 return wxListView::GetItemText(m_value
);
194 return wxEmptyString
;
198 // Popup event handlers
201 // Mouse hot-tracking
202 void OnMouseMove(wxMouseEvent
& event
)
204 // Move selection to cursor if it is inside the popup
207 int itemHere
= HitTest(event
.GetPosition(),resFlags
);
210 wxListView::Select(itemHere
,true);
211 m_itemHere
= itemHere
;
216 // On mouse left, set the value and close the popup
217 void OnMouseClick(wxMouseEvent
& WXUNUSED(event
))
219 m_value
= m_itemHere
;
225 // Utilies for item manipulation
228 void AddSelection( const wxString
& selstr
)
230 wxListView::InsertItem(GetItemCount(),selstr
);
235 int m_value
; // current item index
236 int m_itemHere
; // hot item in popup
239 DECLARE_EVENT_TABLE()
242 BEGIN_EVENT_TABLE(ListViewComboPopup
, wxListView
)
243 EVT_MOTION(ListViewComboPopup::OnMouseMove
)
244 // NOTE: Left down event is used instead of left up right now
245 // since MSW wxListCtrl doesn't seem to emit left ups
247 EVT_LEFT_DOWN(ListViewComboPopup::OnMouseClick
)
251 // ----------------------------------------------------------------------------
252 // wxTreeCtrl Custom popup interface
253 // ----------------------------------------------------------------------------
255 #include <wx/treectrl.h>
257 class TreeCtrlComboPopup
: public wxTreeCtrl
, public wxComboPopup
261 TreeCtrlComboPopup(wxComboControlBase
* combo
)
262 : wxTreeCtrl(), wxComboPopup(combo
)
266 virtual bool Create( wxWindow
* parent
)
268 return wxTreeCtrl::Create(parent
,1,
269 wxPoint(0,0),wxDefaultSize
,
270 wxTR_HIDE_ROOT
|wxTR_HAS_BUTTONS
|
271 wxTR_SINGLE
|wxTR_LINES_AT_ROOT
|
275 virtual void OnShow()
277 // make sure selected item is visible
278 if ( m_value
.IsOk() )
279 EnsureVisible(m_value
);
282 virtual wxSize
GetAdjustedSize( int minWidth
,
283 int WXUNUSED(prefHeight
),
286 return wxSize(wxMax(300,minWidth
),wxMin(250,maxHeight
));
289 virtual wxWindow
*GetControl() { return this; }
291 // Needed by SetStringValue
292 wxTreeItemId
FindItemByText( wxTreeItemId parent
, const wxString
& text
)
294 wxTreeItemIdValue cookie
;
295 wxTreeItemId child
= GetFirstChild(parent
,cookie
);
296 while ( child
.IsOk() )
298 if ( GetItemText(child
) == text
)
302 if ( ItemHasChildren(child
) )
304 wxTreeItemId found
= FindItemByText(child
,text
);
308 child
= GetNextChild(parent
,cookie
);
310 return wxTreeItemId();
313 virtual void SetStringValue( const wxString
& s
)
315 wxTreeItemId root
= GetRootItem();
319 wxTreeItemId found
= FindItemByText(root
,s
);
322 m_value
= m_itemHere
= found
;
323 wxTreeCtrl::SelectItem(found
);
327 virtual wxString
GetStringValue() const
329 if ( m_value
.IsOk() )
330 return wxTreeCtrl::GetItemText(m_value
);
331 return wxEmptyString
;
335 // Popup event handlers
338 // Mouse hot-tracking
339 void OnMouseMove(wxMouseEvent
& event
)
342 wxTreeItemId itemHere
= HitTest(event
.GetPosition(),resFlags
);
343 if ( itemHere
.IsOk() && (resFlags
& wxTREE_HITTEST_ONITEMLABEL
) )
345 wxTreeCtrl::SelectItem(itemHere
,true);
346 m_itemHere
= itemHere
;
351 // On mouse left, set the value and close the popup
352 void OnMouseClick(wxMouseEvent
& event
)
355 wxTreeItemId itemHere
= HitTest(event
.GetPosition(),resFlags
);
356 if ( itemHere
.IsOk() && (resFlags
& wxTREE_HITTEST_ONITEMLABEL
) )
358 m_itemHere
= itemHere
;
368 wxTreeItemId m_value
; // current item index
369 wxTreeItemId m_itemHere
; // hot item in popup
372 DECLARE_EVENT_TABLE()
375 BEGIN_EVENT_TABLE(TreeCtrlComboPopup
, wxTreeCtrl
)
376 EVT_MOTION(TreeCtrlComboPopup::OnMouseMove
)
377 // NOTE: Left down event is used instead of left up right now
378 // since MSW wxTreeCtrl doesn't seem to emit left ups
380 EVT_LEFT_DOWN(TreeCtrlComboPopup::OnMouseClick
)
383 // ----------------------------------------------------------------------------
384 // wxOwnerDrawnComboBox with custom paint list items
385 // ----------------------------------------------------------------------------
387 class wxPenStyleComboBox
: public wxOwnerDrawnComboBox
390 virtual bool OnDrawListItem( wxDC
& dc
, const wxRect
& rect
, int item
, int flags
)
396 int pen_style
= wxSOLID
;
398 pen_style
= wxTRANSPARENT
;
399 else if ( item
== 2 )
401 else if ( item
== 3 )
402 pen_style
= wxLONG_DASH
;
403 else if ( item
== 4 )
404 pen_style
= wxSHORT_DASH
;
405 else if ( item
== 5 )
406 pen_style
= wxDOT_DASH
;
407 else if ( item
== 6 )
408 pen_style
= wxBDIAGONAL_HATCH
;
409 else if ( item
== 7 )
410 pen_style
= wxCROSSDIAG_HATCH
;
411 else if ( item
== 8 )
412 pen_style
= wxFDIAGONAL_HATCH
;
413 else if ( item
== 9 )
414 pen_style
= wxCROSS_HATCH
;
415 else if ( item
== 10 )
416 pen_style
= wxHORIZONTAL_HATCH
;
417 else if ( item
== 11 )
418 pen_style
= wxVERTICAL_HATCH
;
420 wxPen
pen( dc
.GetTextForeground(), 3, pen_style
);
422 // Get text colour as pen colour
425 if ( !(flags
& wxCC_PAINTING_CONTROL
) )
427 dc
.DrawText(GetString( item
),
429 (r
.y
+ 0) + ( (r
.height
/2) - dc
.GetCharHeight() )/2
432 dc
.DrawLine( r
.x
+5, r
.y
+((r
.height
/4)*3), r
.x
+r
.width
- 5, r
.y
+((r
.height
/4)*3) );
435 dc.SetBrush( *wxTRANSPARENT_BRUSH );
436 dc.DrawRectangle( r );
438 dc.DrawText(GetString( item ),
440 (r.y + 0) + ( (r.height) - dc.GetCharHeight() )/2
446 dc
.DrawLine( r
.x
+5, r
.y
+r
.height
/2, r
.x
+r
.width
- 5, r
.y
+r
.height
/2 );
452 virtual wxCoord
OnMeasureListItem( int WXUNUSED(item
) )
457 virtual wxCoord
OnMeasureListItemWidth( int WXUNUSED(item
) )
459 return -1; // default - will be measured from text width
464 // ----------------------------------------------------------------------------
465 // wxComboControl with entirely custom button action (opens file dialog)
466 // ----------------------------------------------------------------------------
468 class wxFileSelectorCombo
: public wxComboControl
471 wxFileSelectorCombo() : wxComboControl() { Init(); }
473 wxFileSelectorCombo(wxWindow
*parent
,
474 wxWindowID id
= wxID_ANY
,
475 const wxString
& value
= wxEmptyString
,
476 const wxPoint
& pos
= wxDefaultPosition
,
477 const wxSize
& size
= wxDefaultSize
,
479 const wxValidator
& validator
= wxDefaultValidator
,
480 const wxString
& name
= wxComboBoxNameStr
)
484 Create(parent
,id
,value
,
486 // Style flag wxCC_STD_BUTTON makes the button
487 // behave more like a standard push button.
488 style
| wxCC_STD_BUTTON
,
492 // Prepare custom button bitmap (just '...' text)
495 dc
.SelectObject(bmp
);
497 // Draw transparent background
498 wxColour
magic(255,0,255);
499 wxBrush
magicBrush(magic
);
500 dc
.SetBrush( magicBrush
);
501 dc
.SetPen( *wxTRANSPARENT_PEN
);
502 dc
.DrawRectangle(0,0,bmp
.GetWidth(),bmp
.GetHeight());
505 wxString str
= wxT("...");
507 dc
.GetTextExtent(str
, &w
, &h
, 0, 0);
508 dc
.DrawText(str
, (bmp
.GetWidth()-w
)/2, (bmp
.GetHeight()-h
)/2);
510 dc
.SelectObject( wxNullBitmap
);
512 // Finalize transparency with a mask
513 wxMask
*mask
= new wxMask( bmp
, magic
);
516 SetButtonBitmaps(bmp
,true);
519 virtual void OnButtonClick()
521 // Show standard wxFileDialog on button click
523 wxFileDialog
dlg(this,
527 wxT("All files (*.*)|*.*"),
530 if ( dlg
.ShowModal() == wxID_OK
)
532 SetValue(dlg
.GetPath());
539 // Initialize member variables here
543 // ----------------------------------------------------------------------------
545 // ----------------------------------------------------------------------------
548 MyFrame::MyFrame(const wxString
& title
)
549 : wxFrame(NULL
, wxID_ANY
, title
)
551 wxBoxSizer
* topSizer
;
552 wxBoxSizer
* topRowSizer
;
553 wxBoxSizer
* colSizer
;
554 wxBoxSizer
* rowSizer
;
555 wxStaticBoxSizer
* groupSizer
;
557 // set the frame icon
558 SetIcon(wxICON(sample
));
562 wxMenu
*fileMenu
= new wxMenu
;
564 // the "About" item should be in the help menu
565 wxMenu
*helpMenu
= new wxMenu
;
566 helpMenu
->Append(ComboControl_About
, _T("&About...\tF1"), _T("Show about dialog"));
568 fileMenu
->Append(ComboControl_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
570 // now append the freshly created menu to the menu bar...
571 wxMenuBar
*menuBar
= new wxMenuBar();
572 menuBar
->Append(fileMenu
, _T("&File"));
573 menuBar
->Append(helpMenu
, _T("&Help"));
575 // ... and attach this menu bar to the frame
577 #endif // wxUSE_MENUS
579 wxPanel
* panel
= new wxPanel(this);
581 // Prepare log window right away since it shows EVT_TEXTs
582 m_logWin
= new wxTextCtrl( panel
, 105, wxEmptyString
, wxDefaultPosition
,
583 wxSize(-1,125), wxTE_MULTILINE
|wxFULL_REPAINT_ON_RESIZE
);
584 m_logWin
->SetEditable(false);
585 wxLogTextCtrl
* logger
= new wxLogTextCtrl( m_logWin
);
586 m_logOld
= logger
->SetActiveTarget( logger
);
587 logger
->SetTimestamp( NULL
);
590 topSizer
= new wxBoxSizer( wxVERTICAL
);
592 topRowSizer
= new wxBoxSizer( wxHORIZONTAL
);
594 colSizer
= new wxBoxSizer( wxVERTICAL
);
597 // Make sure GetFeatures is implemented
598 int features
= wxComboControl::GetFeatures();
599 wxLogDebug(wxT("wxComboControl features: 0x%X (all features: 0x%X)"),
600 features
,wxComboControlFeatures::All
);
605 wxGenericComboControl
* gcc
;
606 wxOwnerDrawnComboBox
* odc
;
608 // Create common strings array
609 wxArrayString arrItems
;
610 arrItems
.Add( wxT("Solid") );
611 arrItems
.Add( wxT("Transparent") );
612 arrItems
.Add( wxT("Dot") );
613 arrItems
.Add( wxT("Long Dash") );
614 arrItems
.Add( wxT("Short Dash") );
615 arrItems
.Add( wxT("Dot Dash") );
616 arrItems
.Add( wxT("Backward Diagonal Hatch") );
617 arrItems
.Add( wxT("Cross-diagonal Hatch") );
618 arrItems
.Add( wxT("Forward Diagonal Hatch") );
619 arrItems
.Add( wxT("Cross Hatch") );
620 arrItems
.Add( wxT("Horizontal Hatch") );
621 arrItems
.Add( wxT("Vertical Hatch") );
626 // Show some wxOwnerDrawComboBoxes for comparison
628 rowSizer
= new wxBoxSizer(wxHORIZONTAL
);
630 groupSizer
= new wxStaticBoxSizer(new wxStaticBox(panel
,wxID_ANY
,wxT(" wxOwnerDrawnComboBox ")),
633 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Writable, sorted:")), 0,
634 wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxEXPAND
, border
);
636 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
637 wxDefaultPosition
, wxDefaultSize
,
639 wxCB_SORT
// wxNO_BORDER|wxCB_READONLY
642 odc
->Append(wxT("H - Appended Item")); // test sorting in append
644 odc
->SetValue(wxT("Dot Dash"));
646 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
649 // Readonly ODComboBox
650 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Read-only:")), 0,
651 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
653 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
654 wxDefaultPosition
, wxDefaultSize
,
656 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
659 odc
->SetValue(wxT("Dot Dash"));
661 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
664 // Disabled ODComboBox
665 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Disabled:")), 0,
666 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
668 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
669 wxDefaultPosition
, wxDefaultSize
,
671 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
674 odc
->SetValue(wxT("Dot Dash"));
677 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
679 rowSizer
->Add( groupSizer
, 1, wxEXPAND
|wxALL
, border
);
682 groupSizer
= new wxStaticBoxSizer(new wxStaticBox(panel
,wxID_ANY
,wxT(" wxComboBox ")),
688 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Writable, sorted:")), 0,
689 wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxEXPAND
, border
);
691 cb
= new wxComboBox(panel
,wxID_ANY
,wxEmptyString
,
692 wxDefaultPosition
, wxDefaultSize
,
694 wxCB_SORT
// wxNO_BORDER|wxCB_READONLY
697 cb
->Append(wxT("H - Appended Item")); // test sorting in append
699 cb
->SetValue(wxT("Dot Dash"));
701 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
704 // Readonly wxComboBox
705 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Read-only:")), 0,
706 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
708 cb
= new wxComboBox(panel
,wxID_ANY
,wxEmptyString
,
709 wxDefaultPosition
, wxDefaultSize
,
711 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
714 cb
->SetValue(wxT("Dot Dash"));
716 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
719 // Disabled wxComboBox
720 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Disabled:")), 0,
721 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
723 cb
= new wxComboBox(panel
,wxID_ANY
,wxEmptyString
,
724 wxDefaultPosition
, wxDefaultSize
,
726 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
729 cb
->SetValue(wxT("Dot Dash"));
732 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
734 rowSizer
->Add( groupSizer
, 1, wxEXPAND
|wxALL
, border
);
737 colSizer
->Add( rowSizer
, 1, wxEXPAND
|wxALL
, border
);
741 // Pen selector ODComboBox with application painted items
743 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
744 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
745 wxT("OwnerDrawnComboBox with Custom Paint Items and Button Placing:")), 1,
746 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
747 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
749 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
751 // When defining derivative class for callbacks, we need
752 // to use two-stage creation (or redefine the common wx
754 odc
= new wxPenStyleComboBox();
755 odc
->Create(panel
,wxID_ANY
,wxEmptyString
,
756 wxDefaultPosition
, wxDefaultSize
,
758 wxCB_READONLY
//wxNO_BORDER | wxCB_READONLY
761 //m_odc->SetCustomPaintWidth( 60 );
762 odc
->SetSelection(0);
763 odc
->SetButtonPosition(-2, // width adjustment
764 -6, // height adjustment
766 2 // horizontal spacing
769 rowSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
770 rowSizer
->AddStretchSpacer(1);
771 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
775 // List View wxComboControl
778 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
779 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("List View wxComboControl:")), 1,
780 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
781 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Tree Ctrl wxGenericComboControl:")), 1,
782 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
783 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
785 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
786 cc
= new wxComboControl(panel
,2,wxEmptyString
,
787 wxDefaultPosition
, wxDefaultSize
);
789 cc
->SetPopupMinWidth(300);
791 ListViewComboPopup
* iface
= new ListViewComboPopup(cc
);
792 cc
->SetPopupControl(iface
);
794 iface
->AddSelection( wxT("Cabbage") );
795 iface
->AddSelection( wxT("Potato") );
796 iface
->AddSelection( wxT("Onion") );
797 iface
->AddSelection( wxT("Carrot") );
798 iface
->AddSelection( wxT("Cauliflower") );
799 iface
->AddSelection( wxT("Bean") );
800 iface
->AddSelection( wxT("Raddish") );
801 iface
->AddSelection( wxT("Banana") );
802 iface
->AddSelection( wxT("Apple") );
803 iface
->AddSelection( wxT("Orange") );
804 iface
->AddSelection( wxT("Kiwi") );
805 iface
->AddSelection( wxT("Strawberry") );
806 iface
->AddSelection( wxT("Cucumber") );
807 iface
->AddSelection( wxT("Blackberry") );
808 iface
->AddSelection( wxT("Melon") );
809 iface
->AddSelection( wxT("Cherry") );
810 iface
->AddSelection( wxT("Pea") );
811 iface
->AddSelection( wxT("Pear") );
813 rowSizer
->Add( cc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
817 // Tree Ctrl wxComboControl
820 // Note that we test that wxGenericComboControl works
821 gcc
= new wxGenericComboControl(panel
,wxID_ANY
,wxEmptyString
,
822 wxDefaultPosition
, wxDefaultSize
);
824 // Set popup interface right away, otherwise some of the calls
826 TreeCtrlComboPopup
* tcPopup
= new TreeCtrlComboPopup(gcc
);
827 gcc
->SetPopupControl(tcPopup
);
829 // Add items using wxTreeCtrl methods directly
830 wxTreeItemId rootId
= tcPopup
->AddRoot(wxT("<hidden_root>"));
832 wxTreeItemId groupId
;
834 groupId
= tcPopup
->AppendItem(rootId
,wxT("Controls"));
835 tcPopup
->AppendItem(groupId
,wxT("wxButton"));
836 tcPopup
->AppendItem(groupId
,wxT("wxCheckBox"));
837 tcPopup
->AppendItem(groupId
,wxT("wxListCtrl"));
838 tcPopup
->AppendItem(groupId
,wxT("wxStaticBox"));
839 tcPopup
->AppendItem(groupId
,wxT("wxStaticText"));
840 tcPopup
->AppendItem(groupId
,wxT("wxTextCtrl"));
841 tcPopup
->AppendItem(groupId
,wxT("wxTreeCtrl"));
842 groupId
= tcPopup
->AppendItem(rootId
,wxT("Dialogs"));
843 tcPopup
->AppendItem(groupId
,wxT("wxDirDialog"));
844 tcPopup
->AppendItem(groupId
,wxT("wxFileDialog"));
845 tcPopup
->AppendItem(groupId
,wxT("wxWizard"));
847 gcc
->SetValue(wxT("wxStaticBox"));
849 // Move button to left - it makes more sense for a tree ctrl
850 gcc
->SetButtonPosition(0, // width adjustment
851 0, // height adjustment
853 0 // horizontal spacing
856 rowSizer
->Add( gcc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
858 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
861 wxInitAllImageHandlers();
864 // Custom Dropbutton Bitmaps
865 // (second one uses blank button background)
867 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
868 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
869 wxT("OwnerDrawnComboBox with simple dropbutton graphics:")), 1,
870 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
872 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
874 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
876 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
877 wxDefaultPosition
, wxDefaultSize
,
879 (long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
882 wxOwnerDrawnComboBox
* odc2
;
883 odc2
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
884 wxDefaultPosition
, wxDefaultSize
,
886 (long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
889 // Load images from disk
890 wxImage
imgNormal(wxT("dropbutn.png"));
891 wxImage
imgPressed(wxT("dropbutp.png"));
892 wxImage
imgHover(wxT("dropbuth.png"));
894 if ( imgNormal
.Ok() && imgPressed
.Ok() && imgHover
.Ok() )
896 wxBitmap
bmpNormal(imgNormal
);
897 wxBitmap
bmpPressed(imgPressed
);
898 wxBitmap
bmpHover(imgHover
);
899 odc
->SetButtonBitmaps(bmpNormal
,false,bmpPressed
,bmpHover
);
900 odc2
->SetButtonBitmaps(bmpNormal
,true,bmpPressed
,bmpHover
);
903 wxLogError(wxT("Dropbutton images not found"));
905 //odc2->SetButtonPosition(0, // width adjustment
906 // 0, // height adjustment
908 // 0 // horizontal spacing
911 rowSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
912 rowSizer
->Add( odc2
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
913 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
918 // wxComboControl with totally custom button action (open file dialog)
920 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
921 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
922 wxT("wxComboControl with custom button action:")), 1,
923 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
926 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
928 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
929 wxFileSelectorCombo
* fsc
;
931 fsc
= new wxFileSelectorCombo(panel
,wxID_ANY
,wxEmptyString
,
932 wxDefaultPosition
, wxDefaultSize
,
936 rowSizer
->Add( fsc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
937 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
940 topRowSizer
->Add( colSizer
, 1, wxALL
, 2 );
942 topRowSizer
->Add( m_logWin
, 1, wxEXPAND
|wxALL
, 5 );
943 topSizer
->Add( topRowSizer
, 1, wxEXPAND
);
945 panel
->SetSizer( topSizer
);
946 topSizer
->SetSizeHints( panel
);
954 delete wxLog::SetActiveTarget(m_logOld
);
959 void MyFrame::OnComboBoxUpdate( wxCommandEvent
& event
)
961 // Don't show messages for the log output window (it'll crash)
962 if ( event
.GetId() == 105 )
965 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
966 wxLogDebug(wxT("EVT_COMBOBOX(id=%i,selection=%i)"),event
.GetId(),event
.GetSelection());
967 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
968 wxLogDebug(wxT("EVT_TEXT(id=%i,string=\"%s\")"),event
.GetId(),event
.GetString().c_str());
971 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
973 // true is to force the frame to close
977 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
979 wxMessageBox(wxString::Format(
980 _T("Welcome to %s!\n")
982 _T("This is the wxWidgets wxComboControl sample\n")
983 _T("running under %s."),
985 wxGetOsDescription().c_str()
987 _T("About wxComboControl sample"),
988 wxOK
| wxICON_INFORMATION
,