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 void OnShowComparison( wxCommandEvent
& event
);
83 // log wxComboCtrl events
84 void OnComboBoxUpdate( wxCommandEvent
& event
);
90 // Common list of items for all dialogs.
91 wxArrayString m_arrItems
;
94 // any class wishing to process wxWidgets events must use this macro
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 // IDs for the controls and the menu commands
105 ComboControl_Compare
= wxID_HIGHEST
,
108 ComboControl_Quit
= wxID_EXIT
,
110 // it is important for the id corresponding to the "About" command to have
111 // this standard value as otherwise it won't be handled properly under Mac
112 // (where it is special and put into the "Apple" menu)
113 ComboControl_About
= wxID_ABOUT
116 // ----------------------------------------------------------------------------
117 // event tables and other macros for wxWidgets
118 // ----------------------------------------------------------------------------
120 // the event tables connect the wxWidgets events with the functions (event
121 // handlers) which process them. It can be also done at run-time, but for the
122 // simple menu events like this the static method is much simpler.
123 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
124 EVT_TEXT(wxID_ANY
,MyFrame::OnComboBoxUpdate
)
125 EVT_COMBOBOX(wxID_ANY
,MyFrame::OnComboBoxUpdate
)
127 EVT_MENU(ComboControl_Compare
, MyFrame::OnShowComparison
)
128 EVT_MENU(ComboControl_Quit
, MyFrame::OnQuit
)
129 EVT_MENU(ComboControl_About
, MyFrame::OnAbout
)
132 // Create a new application object: this macro will allow wxWidgets to create
133 // the application object during program execution (it's better than using a
134 // static object for many reasons) and also implements the accessor function
135 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
139 // ============================================================================
141 // ============================================================================
143 // ----------------------------------------------------------------------------
144 // the application class
145 // ----------------------------------------------------------------------------
147 // 'Main program' equivalent: the program execution "starts" here
150 // create the main application window
151 MyFrame
*frame
= new MyFrame(_T("wxComboCtrl and wxOwnerDrawnComboBox Sample"));
153 // and show it (the frames, unlike simple controls, are not shown when
154 // created initially)
157 // success: wxApp::OnRun() will be called which will enter the main message
158 // loop and the application will run. If we returned false here, the
159 // application would exit immediately.
164 // ----------------------------------------------------------------------------
165 // wxOwnerDrawnComboBox with custom paint list items
166 // ----------------------------------------------------------------------------
168 class wxPenStyleComboBox
: public wxOwnerDrawnComboBox
171 virtual void OnDrawItem( wxDC
& dc
,
176 if ( item
== wxNOT_FOUND
)
183 int penStyle
= wxSOLID
;
185 penStyle
= wxTRANSPARENT
;
186 else if ( item
== 2 )
188 else if ( item
== 3 )
189 penStyle
= wxLONG_DASH
;
190 else if ( item
== 4 )
191 penStyle
= wxSHORT_DASH
;
192 else if ( item
== 5 )
193 penStyle
= wxDOT_DASH
;
194 else if ( item
== 6 )
195 penStyle
= wxBDIAGONAL_HATCH
;
196 else if ( item
== 7 )
197 penStyle
= wxCROSSDIAG_HATCH
;
198 else if ( item
== 8 )
199 penStyle
= wxFDIAGONAL_HATCH
;
200 else if ( item
== 9 )
201 penStyle
= wxCROSS_HATCH
;
202 else if ( item
== 10 )
203 penStyle
= wxHORIZONTAL_HATCH
;
204 else if ( item
== 11 )
205 penStyle
= wxVERTICAL_HATCH
;
207 wxPen
pen( dc
.GetTextForeground(), 3, penStyle
);
209 // Get text colour as pen colour
212 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
214 dc
.DrawText(GetString( item
),
216 (r
.y
+ 0) + ( (r
.height
/2) - dc
.GetCharHeight() )/2
219 dc
.DrawLine( r
.x
+5, r
.y
+((r
.height
/4)*3), r
.x
+r
.width
- 5, r
.y
+((r
.height
/4)*3) );
223 dc
.DrawLine( r
.x
+5, r
.y
+r
.height
/2, r
.x
+r
.width
- 5, r
.y
+r
.height
/2 );
227 virtual void OnDrawBackground( wxDC
& dc
, const wxRect
& rect
,
228 int item
, int flags
) const
231 // If item is selected or even, use the default rendering.
232 if ( GetVListBoxComboPopup()->IsCurrent((size_t)item
) ||
235 wxOwnerDrawnComboBox::OnDrawBackground(dc
,rect
,item
,flags
);
239 // Otherwise, draw every other background with different colour.
240 wxColour
bgCol(240,240,250);
241 dc
.SetBrush(wxBrush(bgCol
));
242 dc
.SetPen(wxPen(bgCol
));
243 dc
.DrawRectangle(rect
);
246 virtual wxCoord
OnMeasureItem( size_t item
) const
248 // Simply demonstrate the ability to have variable-height items
255 virtual wxCoord
OnMeasureItemWidth( size_t WXUNUSED(item
) ) const
257 return -1; // default - will be measured from text width
263 // ----------------------------------------------------------------------------
264 // wxListView Custom popup interface
265 // ----------------------------------------------------------------------------
267 #include <wx/listctrl.h>
269 class ListViewComboPopup
: public wxListView
, public wxComboPopup
276 m_itemHere
= -1; // hot item in list
279 virtual bool Create( wxWindow
* parent
)
281 return wxListView::Create(parent
,1,
282 wxPoint(0,0),wxDefaultSize
,
283 wxLC_LIST
|wxLC_SINGLE_SEL
|
284 wxLC_SORT_ASCENDING
|wxSIMPLE_BORDER
);
287 virtual wxWindow
*GetControl() { return this; }
289 virtual void SetStringValue( const wxString
& s
)
291 int n
= wxListView::FindItem(-1,s
);
292 if ( n
>= 0 && n
< GetItemCount() )
293 wxListView::Select(n
);
296 virtual wxString
GetStringValue() const
299 return wxListView::GetItemText(m_value
);
300 return wxEmptyString
;
304 // Popup event handlers
307 // Mouse hot-tracking
308 void OnMouseMove(wxMouseEvent
& event
)
310 // Move selection to cursor if it is inside the popup
313 int itemHere
= HitTest(event
.GetPosition(),resFlags
);
316 wxListView::Select(itemHere
,true);
317 m_itemHere
= itemHere
;
322 // On mouse left, set the value and close the popup
323 void OnMouseClick(wxMouseEvent
& WXUNUSED(event
))
325 m_value
= m_itemHere
;
331 // Utilies for item manipulation
334 void AddSelection( const wxString
& selstr
)
336 wxListView::InsertItem(GetItemCount(),selstr
);
341 int m_value
; // current item index
342 int m_itemHere
; // hot item in popup
345 DECLARE_EVENT_TABLE()
348 BEGIN_EVENT_TABLE(ListViewComboPopup
, wxListView
)
349 EVT_MOTION(ListViewComboPopup::OnMouseMove
)
350 // NOTE: Left down event is used instead of left up right now
351 // since MSW wxListCtrl doesn't seem to emit left ups
353 EVT_LEFT_DOWN(ListViewComboPopup::OnMouseClick
)
357 // ----------------------------------------------------------------------------
358 // wxTreeCtrl Custom popup interface
359 // ----------------------------------------------------------------------------
361 #include <wx/treectrl.h>
363 class TreeCtrlComboPopup
: public wxTreeCtrl
, public wxComboPopup
371 virtual bool Create( wxWindow
* parent
)
373 return wxTreeCtrl::Create(parent
,1,
374 wxPoint(0,0),wxDefaultSize
,
375 wxTR_HIDE_ROOT
|wxTR_HAS_BUTTONS
|
376 wxTR_SINGLE
|wxTR_LINES_AT_ROOT
|
380 virtual void OnShow()
382 // make sure selected item is visible
383 if ( m_value
.IsOk() )
384 EnsureVisible(m_value
);
387 virtual wxSize
GetAdjustedSize( int minWidth
,
388 int WXUNUSED(prefHeight
),
391 return wxSize(wxMax(300,minWidth
),wxMin(250,maxHeight
));
394 virtual wxWindow
*GetControl() { return this; }
396 // Needed by SetStringValue
397 wxTreeItemId
FindItemByText( wxTreeItemId parent
, const wxString
& text
)
399 wxTreeItemIdValue cookie
;
400 wxTreeItemId child
= GetFirstChild(parent
,cookie
);
401 while ( child
.IsOk() )
403 if ( GetItemText(child
) == text
)
407 if ( ItemHasChildren(child
) )
409 wxTreeItemId found
= FindItemByText(child
,text
);
413 child
= GetNextChild(parent
,cookie
);
415 return wxTreeItemId();
418 virtual void SetStringValue( const wxString
& s
)
420 wxTreeItemId root
= GetRootItem();
424 wxTreeItemId found
= FindItemByText(root
,s
);
427 m_value
= m_itemHere
= found
;
428 wxTreeCtrl::SelectItem(found
);
432 virtual wxString
GetStringValue() const
434 if ( m_value
.IsOk() )
435 return wxTreeCtrl::GetItemText(m_value
);
436 return wxEmptyString
;
440 // Popup event handlers
443 // Mouse hot-tracking
444 void OnMouseMove(wxMouseEvent
& event
)
447 wxTreeItemId itemHere
= HitTest(event
.GetPosition(),resFlags
);
448 if ( itemHere
.IsOk() && (resFlags
& wxTREE_HITTEST_ONITEMLABEL
) )
450 wxTreeCtrl::SelectItem(itemHere
,true);
451 m_itemHere
= itemHere
;
456 // On mouse left, set the value and close the popup
457 void OnMouseClick(wxMouseEvent
& event
)
460 wxTreeItemId itemHere
= HitTest(event
.GetPosition(),resFlags
);
461 if ( itemHere
.IsOk() && (resFlags
& wxTREE_HITTEST_ONITEMLABEL
) )
463 m_itemHere
= itemHere
;
473 wxTreeItemId m_value
; // current item index
474 wxTreeItemId m_itemHere
; // hot item in popup
477 DECLARE_EVENT_TABLE()
480 BEGIN_EVENT_TABLE(TreeCtrlComboPopup
, wxTreeCtrl
)
481 EVT_MOTION(TreeCtrlComboPopup::OnMouseMove
)
482 // NOTE: Left down event is used instead of left up right now
483 // since MSW wxTreeCtrl doesn't seem to emit left ups
485 EVT_LEFT_DOWN(TreeCtrlComboPopup::OnMouseClick
)
488 // ----------------------------------------------------------------------------
489 // wxComboCtrl with entirely custom button action (opens file dialog)
490 // ----------------------------------------------------------------------------
492 class wxFileSelectorCombo
: public wxComboCtrl
495 wxFileSelectorCombo() : wxComboCtrl() { Init(); }
497 wxFileSelectorCombo(wxWindow
*parent
,
498 wxWindowID id
= wxID_ANY
,
499 const wxString
& value
= wxEmptyString
,
500 const wxPoint
& pos
= wxDefaultPosition
,
501 const wxSize
& size
= wxDefaultSize
,
503 const wxValidator
& validator
= wxDefaultValidator
,
504 const wxString
& name
= wxComboBoxNameStr
)
508 Create(parent
,id
,value
,
510 // Style flag wxCC_STD_BUTTON makes the button
511 // behave more like a standard push button.
512 style
| wxCC_STD_BUTTON
,
516 // Prepare custom button bitmap (just '...' text)
519 dc
.SelectObject(bmp
);
521 // Draw transparent background
522 wxColour
magic(255,0,255);
523 wxBrush
magicBrush(magic
);
524 dc
.SetBrush( magicBrush
);
525 dc
.SetPen( *wxTRANSPARENT_PEN
);
526 dc
.DrawRectangle(0,0,bmp
.GetWidth(),bmp
.GetHeight());
529 wxString str
= wxT("...");
531 dc
.GetTextExtent(str
, &w
, &h
, 0, 0);
532 dc
.DrawText(str
, (bmp
.GetWidth()-w
)/2, (bmp
.GetHeight()-h
)/2);
534 dc
.SelectObject( wxNullBitmap
);
536 // Finalize transparency with a mask
537 wxMask
*mask
= new wxMask( bmp
, magic
);
540 SetButtonBitmaps(bmp
,true);
543 virtual void OnButtonClick()
545 // Show standard wxFileDialog on button click
547 wxFileDialog
dlg(this,
551 wxT("All files (*.*)|*.*"),
554 if ( dlg
.ShowModal() == wxID_OK
)
556 SetValue(dlg
.GetPath());
560 // Implement empty DoSetPopupControl to prevent assertion failure.
561 virtual void DoSetPopupControl(wxComboPopup
* WXUNUSED(popup
))
568 // Initialize member variables here
572 // ----------------------------------------------------------------------------
574 // ----------------------------------------------------------------------------
577 MyFrame::MyFrame(const wxString
& title
)
578 : wxFrame(NULL
, wxID_ANY
, title
)
580 wxBoxSizer
* topSizer
;
581 wxBoxSizer
* topRowSizer
;
582 wxBoxSizer
* colSizer
;
583 wxBoxSizer
* rowSizer
;
585 // set the frame icon
586 SetIcon(wxICON(sample
));
590 wxMenu
*fileMenu
= new wxMenu
;
592 // the "About" item should be in the help menu
593 wxMenu
*helpMenu
= new wxMenu
;
594 helpMenu
->Append(ComboControl_About
, _T("&About...\tF1"), _T("Show about dialog"));
596 fileMenu
->Append(ComboControl_Compare
, _T("&Compare against wxComboBox..."),
597 _T("Show some wxOwnerDrawnComboBoxes side-by-side with native wxComboBoxes."));
598 fileMenu
->AppendSeparator();
599 fileMenu
->Append(ComboControl_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
601 // now append the freshly created menu to the menu bar...
602 wxMenuBar
*menuBar
= new wxMenuBar();
603 menuBar
->Append(fileMenu
, _T("&File"));
604 menuBar
->Append(helpMenu
, _T("&Help"));
606 // ... and attach this menu bar to the frame
608 #endif // wxUSE_MENUS
610 wxPanel
* panel
= new wxPanel(this);
612 // Prepare log window right away since it shows EVT_TEXTs
613 m_logWin
= new wxTextCtrl( panel
, 105, wxEmptyString
, wxDefaultPosition
,
614 wxSize(-1,125), wxTE_MULTILINE
|wxFULL_REPAINT_ON_RESIZE
);
615 m_logWin
->SetEditable(false);
616 wxLogTextCtrl
* logger
= new wxLogTextCtrl( m_logWin
);
617 m_logOld
= logger
->SetActiveTarget( logger
);
618 logger
->SetTimestamp( NULL
);
621 topSizer
= new wxBoxSizer( wxVERTICAL
);
623 topRowSizer
= new wxBoxSizer( wxHORIZONTAL
);
625 colSizer
= new wxBoxSizer( wxVERTICAL
);
629 wxGenericComboControl
* gcc
;
630 wxOwnerDrawnComboBox
* odc
;
632 // Create common strings array
633 m_arrItems
.Add( wxT("Solid") );
634 m_arrItems
.Add( wxT("Transparent") );
635 m_arrItems
.Add( wxT("Dot") );
636 m_arrItems
.Add( wxT("Long Dash") );
637 m_arrItems
.Add( wxT("Short Dash") );
638 m_arrItems
.Add( wxT("Dot Dash") );
639 m_arrItems
.Add( wxT("Backward Diagonal Hatch") );
640 m_arrItems
.Add( wxT("Cross-diagonal Hatch") );
641 m_arrItems
.Add( wxT("Forward Diagonal Hatch") );
642 m_arrItems
.Add( wxT("Cross Hatch") );
643 m_arrItems
.Add( wxT("Horizontal Hatch") );
644 m_arrItems
.Add( wxT("Vertical Hatch") );
648 // Create pen selector ODComboBox with owner-drawn items
650 rowSizer
= new wxBoxSizer( wxHORIZONTAL
);
651 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
652 wxT("OwnerDrawnComboBox with owner-drawn items:")), 1,
653 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
654 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
656 rowSizer
= new wxBoxSizer( wxHORIZONTAL
);
659 // When defining derivative class for callbacks, we need
660 // to use two-stage creation (or redefine the common wx
662 odc
= new wxPenStyleComboBox();
663 odc
->Create(panel
,wxID_ANY
,wxEmptyString
,
664 wxDefaultPosition
, wxDefaultSize
,
666 wxCB_READONLY
//wxNO_BORDER | wxCB_READONLY
670 odc
->SetSelection(0);
672 rowSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
673 rowSizer
->AddStretchSpacer(1);
674 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
679 // Same but with changed button position
681 rowSizer
= new wxBoxSizer( wxHORIZONTAL
);
682 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
683 wxT("OwnerDrawnComboBox with owner-drawn items and button on the left:")), 1,
684 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
685 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
687 rowSizer
= new wxBoxSizer( wxHORIZONTAL
);
690 // When defining derivative class for callbacks, we need
691 // to use two-stage creation (or redefine the common wx
693 odc
= new wxPenStyleComboBox();
694 odc
->Create(panel
,wxID_ANY
,wxEmptyString
,
695 wxDefaultPosition
, wxDefaultSize
,
697 wxCB_READONLY
//wxNO_BORDER | wxCB_READONLY
701 odc
->SetSelection(0);
703 // Use button size that is slightly smaller than the default.
704 wxSize butSize
= odc
->GetButtonSize();
705 odc
->SetButtonPosition(butSize
.x
- 2, // button width
706 butSize
.y
- 6, // button height
708 2 // horizontal spacing
711 rowSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
712 rowSizer
->AddStretchSpacer(1);
713 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
717 // List View wxComboCtrl
720 rowSizer
= new wxBoxSizer( wxHORIZONTAL
);
721 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("List View wxComboCtrl:")), 1,
722 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
723 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Tree Ctrl wxComboControl:")), 1,
724 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
725 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
727 rowSizer
= new wxBoxSizer( wxHORIZONTAL
);
728 cc
= new wxComboCtrl(panel
,2,wxEmptyString
,
729 wxDefaultPosition
, wxDefaultSize
);
731 cc
->SetPopupMinWidth(300);
733 ListViewComboPopup
* iface
= new ListViewComboPopup();
734 cc
->SetPopupControl(iface
);
737 for ( i
=0; i
<100; i
++ )
738 iface
->AddSelection( wxString::Format(wxT("Item %02i"),i
));
740 rowSizer
->Add( cc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
744 // Tree Ctrl wxComboCtrl
747 // Note that we test that wxGenericComboControl works
748 gcc
= new wxGenericComboControl(panel
,wxID_ANY
,wxEmptyString
,
749 wxDefaultPosition
, wxDefaultSize
);
751 // Set popup interface right away, otherwise some of the calls
753 TreeCtrlComboPopup
* tcPopup
= new TreeCtrlComboPopup();
754 gcc
->SetPopupControl(tcPopup
);
756 // Add items using wxTreeCtrl methods directly
757 wxTreeItemId rootId
= tcPopup
->AddRoot(wxT("<hidden_root>"));
759 wxTreeItemId groupId
;
761 for ( i
=0; i
<4; i
++ )
763 groupId
= tcPopup
->AppendItem(rootId
,
764 wxString::Format(wxT("Branch %02i"),i
));
767 for ( n
=0; n
<25; n
++ )
768 tcPopup
->AppendItem(groupId
,
769 wxString::Format(wxT("Subitem %02i"),(i
*25)+n
));
772 gcc
->SetValue(wxT("Subitem 05"));
774 // Move button to left - it makes more sense for a tree ctrl
775 gcc
->SetButtonPosition(-1, // button width
778 0 // horizontal spacing
781 rowSizer
->Add( gcc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
783 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
786 wxInitAllImageHandlers();
789 // Custom Dropbutton Bitmaps
790 // (second one uses blank button background)
792 rowSizer
= new wxBoxSizer( wxHORIZONTAL
);
793 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
794 wxT("OwnerDrawnComboBox with simple dropbutton graphics:")), 1,
795 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
797 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
799 rowSizer
= new wxBoxSizer( wxHORIZONTAL
);
801 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
802 wxDefaultPosition
, wxDefaultSize
,
804 (long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
807 wxOwnerDrawnComboBox
* odc2
;
808 odc2
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
809 wxDefaultPosition
, wxDefaultSize
,
811 (long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
814 // Load images from disk
815 wxImage
imgNormal(wxT("dropbutn.png"));
816 wxImage
imgPressed(wxT("dropbutp.png"));
817 wxImage
imgHover(wxT("dropbuth.png"));
819 if ( imgNormal
.Ok() && imgPressed
.Ok() && imgHover
.Ok() )
821 wxBitmap
bmpNormal(imgNormal
);
822 wxBitmap
bmpPressed(imgPressed
);
823 wxBitmap
bmpHover(imgHover
);
824 odc
->SetButtonBitmaps(bmpNormal
,false,bmpPressed
,bmpHover
);
825 odc2
->SetButtonBitmaps(bmpNormal
,true,bmpPressed
,bmpHover
);
828 wxLogError(wxT("Dropbutton images not found"));
830 //odc2->SetButtonPosition(0, // width adjustment
831 // 0, // height adjustment
833 // 0 // horizontal spacing
836 rowSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
837 rowSizer
->Add( odc2
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
838 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
843 // wxComboCtrl with totally custom button action (open file dialog)
845 rowSizer
= new wxBoxSizer( wxHORIZONTAL
);
846 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
847 wxT("wxComboCtrl with custom button action:")), 1,
848 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
851 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
853 rowSizer
= new wxBoxSizer( wxHORIZONTAL
);
854 wxFileSelectorCombo
* fsc
;
856 fsc
= new wxFileSelectorCombo(panel
,wxID_ANY
,wxEmptyString
,
857 wxDefaultPosition
, wxDefaultSize
,
861 rowSizer
->Add( fsc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
862 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
865 // Make sure GetFeatures is implemented
866 wxComboCtrl::GetFeatures();
869 topRowSizer
->Add( colSizer
, 1, wxALL
, 2 );
871 topRowSizer
->Add( m_logWin
, 1, wxEXPAND
|wxALL
, 5 );
872 topSizer
->Add( topRowSizer
, 1, wxEXPAND
);
874 panel
->SetSizer( topSizer
);
875 topSizer
->SetSizeHints( panel
);
883 void MyFrame::OnComboBoxUpdate( wxCommandEvent
& event
)
885 // Don't show messages for the log output window (it'll crash)
886 if ( !event
.GetEventObject()->IsKindOf(CLASSINFO(wxComboCtrl
)) )
889 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
890 wxLogDebug(wxT("EVT_COMBOBOX(id=%i,selection=%i)"),event
.GetId(),event
.GetSelection());
891 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
892 wxLogDebug(wxT("EVT_TEXT(id=%i,string=\"%s\")"),event
.GetId(),event
.GetString().c_str());
895 void MyFrame::OnShowComparison( wxCommandEvent
& WXUNUSED(event
) )
898 // Show some wxOwnerDrawComboBoxes for comparison
901 wxBoxSizer
* colSizer
;
902 wxBoxSizer
* rowSizer
;
903 wxStaticBoxSizer
* groupSizer
;
906 wxOwnerDrawnComboBox
* odc
;
908 const int border
= 4;
910 wxDialog
* dlg
= new wxDialog(this,wxID_ANY
,
911 wxT("Compare against wxComboBox"),
912 wxDefaultPosition
,wxDefaultSize
,
913 wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
);
915 colSizer
= new wxBoxSizer( wxVERTICAL
);
917 rowSizer
= new wxBoxSizer(wxHORIZONTAL
);
919 groupSizer
= new wxStaticBoxSizer(new wxStaticBox(dlg
,wxID_ANY
,wxT(" wxOwnerDrawnComboBox ")),
922 groupSizer
->Add( new wxStaticText(dlg
,wxID_ANY
,wxT("Writable, sorted:")), 0,
923 wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxEXPAND
, border
);
925 odc
= new wxOwnerDrawnComboBox(dlg
,wxID_ANY
,wxEmptyString
,
926 wxDefaultPosition
, wxDefaultSize
,
928 wxCB_SORT
// wxNO_BORDER|wxCB_READONLY
931 odc
->Append(wxT("H - Appended Item")); // test sorting in append
933 odc
->SetValue(wxT("Dot Dash"));
935 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
938 // Readonly ODComboBox
939 groupSizer
->Add( new wxStaticText(dlg
,wxID_ANY
,wxT("Read-only:")), 0,
940 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
942 odc
= new wxOwnerDrawnComboBox(dlg
,wxID_ANY
,wxEmptyString
,
943 wxDefaultPosition
, wxDefaultSize
,
945 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
948 odc
->SetValue(wxT("Dot Dash"));
949 odc
->SetText(wxT("Dot Dash (Testing SetText)"));
951 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
954 // Disabled ODComboBox
955 groupSizer
->Add( new wxStaticText(dlg
,wxID_ANY
,wxT("Disabled:")), 0,
956 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
958 odc
= new wxOwnerDrawnComboBox(dlg
,wxID_ANY
,wxEmptyString
,
959 wxDefaultPosition
, wxDefaultSize
,
961 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
964 odc
->SetValue(wxT("Dot Dash"));
967 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
969 rowSizer
->Add( groupSizer
, 1, wxEXPAND
|wxALL
, border
);
972 groupSizer
= new wxStaticBoxSizer(new wxStaticBox(dlg
,wxID_ANY
,wxT(" wxComboBox ")),
978 groupSizer
->Add( new wxStaticText(dlg
,wxID_ANY
,wxT("Writable, sorted:")), 0,
979 wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxEXPAND
, border
);
981 cb
= new wxComboBox(dlg
,wxID_ANY
,wxEmptyString
,
982 wxDefaultPosition
, wxDefaultSize
,
984 wxCB_SORT
// wxNO_BORDER|wxCB_READONLY
987 cb
->Append(wxT("H - Appended Item")); // test sorting in append
989 cb
->SetValue(wxT("Dot Dash"));
991 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
994 // Readonly wxComboBox
995 groupSizer
->Add( new wxStaticText(dlg
,wxID_ANY
,wxT("Read-only:")), 0,
996 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
998 cb
= new wxComboBox(dlg
,wxID_ANY
,wxEmptyString
,
999 wxDefaultPosition
, wxDefaultSize
,
1001 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
1004 cb
->SetValue(wxT("Dot Dash"));
1006 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
1009 // Disabled wxComboBox
1010 groupSizer
->Add( new wxStaticText(dlg
,wxID_ANY
,wxT("Disabled:")), 0,
1011 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
1013 cb
= new wxComboBox(dlg
,wxID_ANY
,wxEmptyString
,
1014 wxDefaultPosition
, wxDefaultSize
,
1016 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
1019 cb
->SetValue(wxT("Dot Dash"));
1022 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
1024 rowSizer
->Add( groupSizer
, 1, wxEXPAND
|wxALL
, border
);
1026 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, border
);
1028 dlg
->SetSizer( colSizer
);
1029 colSizer
->SetSizeHints( dlg
);
1031 dlg
->SetSize(60,240);
1038 delete wxLog::SetActiveTarget(m_logOld
);
1041 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
1043 // true is to force the frame to close
1047 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
1049 wxMessageBox(wxString::Format(
1050 _T("Welcome to %s!\n")
1052 _T("This is the wxWidgets wxComboCtrl and wxOwnerDrawnComboBox sample\n")
1053 _T("running under %s."),
1055 wxGetOsDescription().c_str()
1057 _T("About wxComboCtrl sample"),
1058 wxOK
| wxICON_INFORMATION
,