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
167 ListViewComboPopup(wxComboControlBase* 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(wxComboControlBase* 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 bool OnDrawListItem( wxDC& dc, const wxRect& rect, int item, int flags )
409 int pen_style = wxSOLID;
411 pen_style = wxTRANSPARENT;
412 else if ( item == 2 )
414 else if ( item == 3 )
415 pen_style = wxLONG_DASH;
416 else if ( item == 4 )
417 pen_style = wxSHORT_DASH;
418 else if ( item == 5 )
419 pen_style = wxDOT_DASH;
420 else if ( item == 6 )
421 pen_style = wxBDIAGONAL_HATCH;
422 else if ( item == 7 )
423 pen_style = wxCROSSDIAG_HATCH;
424 else if ( item == 8 )
425 pen_style = wxFDIAGONAL_HATCH;
426 else if ( item == 9 )
427 pen_style = wxCROSS_HATCH;
428 else if ( item == 10 )
429 pen_style = wxHORIZONTAL_HATCH;
430 else if ( item == 11 )
431 pen_style = wxVERTICAL_HATCH;
433 wxPen pen( dc.GetTextForeground(), 3, pen_style );
435 // Get text colour as pen colour
438 if ( !(flags & wxCP_PAINTING_CONTROL) )
440 dc.DrawText(GetString( item ),
442 (r.y + 0) + ( (r.height/2) - dc.GetCharHeight() )/2
445 dc.DrawLine( r.x+5, r.y+((r.height/4)*3), r.x+r.width - 5, r.y+((r.height/4)*3) );
449 dc.DrawLine( r.x+5, r.y+r.height/2, r.x+r.width - 5, r.y+r.height/2 );
455 virtual wxCoord OnMeasureListItem( int WXUNUSED(item) )
460 virtual wxCoord OnMeasureListItemWidth( int WXUNUSED(item) )
462 return -1; // default - will be measured from text width
468 class wxPenStylePopup
: public wxVListBoxComboPopup
471 virtual void OnDrawItem( wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
473 if ( item
== wxNOT_FOUND
)
480 int pen_style
= wxSOLID
;
482 pen_style
= wxTRANSPARENT
;
483 else if ( item
== 2 )
485 else if ( item
== 3 )
486 pen_style
= wxLONG_DASH
;
487 else if ( item
== 4 )
488 pen_style
= wxSHORT_DASH
;
489 else if ( item
== 5 )
490 pen_style
= wxDOT_DASH
;
491 else if ( item
== 6 )
492 pen_style
= wxBDIAGONAL_HATCH
;
493 else if ( item
== 7 )
494 pen_style
= wxCROSSDIAG_HATCH
;
495 else if ( item
== 8 )
496 pen_style
= wxFDIAGONAL_HATCH
;
497 else if ( item
== 9 )
498 pen_style
= wxCROSS_HATCH
;
499 else if ( item
== 10 )
500 pen_style
= wxHORIZONTAL_HATCH
;
501 else if ( item
== 11 )
502 pen_style
= wxVERTICAL_HATCH
;
504 wxPen
pen( dc
.GetTextForeground(), 3, pen_style
);
506 // Get text colour as pen colour
509 if ( !(flags
& wxCP_PAINTING_CONTROL
) )
511 dc
.DrawText(GetString( item
),
513 (r
.y
+ 0) + ( (r
.height
/2) - dc
.GetCharHeight() )/2
516 dc
.DrawLine( r
.x
+5, r
.y
+((r
.height
/4)*3), r
.x
+r
.width
- 5, r
.y
+((r
.height
/4)*3) );
520 dc
.DrawLine( r
.x
+5, r
.y
+r
.height
/2, r
.x
+r
.width
- 5, r
.y
+r
.height
/2 );
524 virtual wxCoord
OnMeasureItem( size_t WXUNUSED(item
) ) const
529 virtual wxCoord
OnMeasureItemWidth( size_t WXUNUSED(item
) ) const
531 return -1; // default - will be measured from text width
536 // ----------------------------------------------------------------------------
537 // wxComboControl with entirely custom button action (opens file dialog)
538 // ----------------------------------------------------------------------------
540 class wxFileSelectorCombo
: public wxComboControl
543 wxFileSelectorCombo() : wxComboControl() { Init(); }
545 wxFileSelectorCombo(wxWindow
*parent
,
546 wxWindowID id
= wxID_ANY
,
547 const wxString
& value
= wxEmptyString
,
548 const wxPoint
& pos
= wxDefaultPosition
,
549 const wxSize
& size
= wxDefaultSize
,
551 const wxValidator
& validator
= wxDefaultValidator
,
552 const wxString
& name
= wxComboBoxNameStr
)
556 Create(parent
,id
,value
,
558 // Style flag wxCC_STD_BUTTON makes the button
559 // behave more like a standard push button.
560 style
| wxCC_STD_BUTTON
,
564 // Prepare custom button bitmap (just '...' text)
567 dc
.SelectObject(bmp
);
569 // Draw transparent background
570 wxColour
magic(255,0,255);
571 wxBrush
magicBrush(magic
);
572 dc
.SetBrush( magicBrush
);
573 dc
.SetPen( *wxTRANSPARENT_PEN
);
574 dc
.DrawRectangle(0,0,bmp
.GetWidth(),bmp
.GetHeight());
577 wxString str
= wxT("...");
579 dc
.GetTextExtent(str
, &w
, &h
, 0, 0);
580 dc
.DrawText(str
, (bmp
.GetWidth()-w
)/2, (bmp
.GetHeight()-h
)/2);
582 dc
.SelectObject( wxNullBitmap
);
584 // Finalize transparency with a mask
585 wxMask
*mask
= new wxMask( bmp
, magic
);
588 SetButtonBitmaps(bmp
,true);
591 virtual void OnButtonClick()
593 // Show standard wxFileDialog on button click
595 wxFileDialog
dlg(this,
599 wxT("All files (*.*)|*.*"),
602 if ( dlg
.ShowModal() == wxID_OK
)
604 SetValue(dlg
.GetPath());
611 // Initialize member variables here
615 // ----------------------------------------------------------------------------
617 // ----------------------------------------------------------------------------
620 MyFrame::MyFrame(const wxString
& title
)
621 : wxFrame(NULL
, wxID_ANY
, title
)
623 wxBoxSizer
* topSizer
;
624 wxBoxSizer
* topRowSizer
;
625 wxBoxSizer
* colSizer
;
626 wxBoxSizer
* rowSizer
;
627 wxStaticBoxSizer
* groupSizer
;
629 // set the frame icon
630 SetIcon(wxICON(sample
));
634 wxMenu
*fileMenu
= new wxMenu
;
636 // the "About" item should be in the help menu
637 wxMenu
*helpMenu
= new wxMenu
;
638 helpMenu
->Append(ComboControl_About
, _T("&About...\tF1"), _T("Show about dialog"));
640 fileMenu
->Append(ComboControl_Quit
, _T("E&xit\tAlt-X"), _T("Quit this program"));
642 // now append the freshly created menu to the menu bar...
643 wxMenuBar
*menuBar
= new wxMenuBar();
644 menuBar
->Append(fileMenu
, _T("&File"));
645 menuBar
->Append(helpMenu
, _T("&Help"));
647 // ... and attach this menu bar to the frame
649 #endif // wxUSE_MENUS
651 wxPanel
* panel
= new wxPanel(this);
653 // Prepare log window right away since it shows EVT_TEXTs
654 m_logWin
= new wxTextCtrl( panel
, 105, wxEmptyString
, wxDefaultPosition
,
655 wxSize(-1,125), wxTE_MULTILINE
|wxFULL_REPAINT_ON_RESIZE
);
656 m_logWin
->SetEditable(false);
657 wxLogTextCtrl
* logger
= new wxLogTextCtrl( m_logWin
);
658 m_logOld
= logger
->SetActiveTarget( logger
);
659 logger
->SetTimestamp( NULL
);
662 topSizer
= new wxBoxSizer( wxVERTICAL
);
664 topRowSizer
= new wxBoxSizer( wxHORIZONTAL
);
666 colSizer
= new wxBoxSizer( wxVERTICAL
);
669 // Make sure GetFeatures is implemented
670 int features
= wxComboControl::GetFeatures();
671 wxLogDebug(wxT("wxComboControl features: 0x%X (all features: 0x%X)"),
672 features
,wxComboControlFeatures::All
);
677 wxGenericComboControl
* gcc
;
678 wxOwnerDrawnComboBox
* odc
;
680 // Create common strings array
681 wxArrayString arrItems
;
682 arrItems
.Add( wxT("Solid") );
683 arrItems
.Add( wxT("Transparent") );
684 arrItems
.Add( wxT("Dot") );
685 arrItems
.Add( wxT("Long Dash") );
686 arrItems
.Add( wxT("Short Dash") );
687 arrItems
.Add( wxT("Dot Dash") );
688 arrItems
.Add( wxT("Backward Diagonal Hatch") );
689 arrItems
.Add( wxT("Cross-diagonal Hatch") );
690 arrItems
.Add( wxT("Forward Diagonal Hatch") );
691 arrItems
.Add( wxT("Cross Hatch") );
692 arrItems
.Add( wxT("Horizontal Hatch") );
693 arrItems
.Add( wxT("Vertical Hatch") );
698 // Show some wxOwnerDrawComboBoxes for comparison
700 rowSizer
= new wxBoxSizer(wxHORIZONTAL
);
702 groupSizer
= new wxStaticBoxSizer(new wxStaticBox(panel
,wxID_ANY
,wxT(" wxOwnerDrawnComboBox ")),
705 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Writable, sorted:")), 0,
706 wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxEXPAND
, border
);
708 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
709 wxDefaultPosition
, wxDefaultSize
,
711 wxCB_SORT
// wxNO_BORDER|wxCB_READONLY
714 odc
->Append(wxT("H - Appended Item")); // test sorting in append
716 odc
->SetValue(wxT("Dot Dash"));
718 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
721 // Readonly ODComboBox
722 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Read-only:")), 0,
723 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
725 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
726 wxDefaultPosition
, wxDefaultSize
,
728 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
731 odc
->SetValue(wxT("Dot Dash"));
732 odc
->SetText(wxT("Dot Dash (Testing SetText)"));
734 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
737 // Disabled ODComboBox
738 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Disabled:")), 0,
739 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
741 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
742 wxDefaultPosition
, wxDefaultSize
,
744 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
747 odc
->SetValue(wxT("Dot Dash"));
750 groupSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
752 rowSizer
->Add( groupSizer
, 1, wxEXPAND
|wxALL
, border
);
755 groupSizer
= new wxStaticBoxSizer(new wxStaticBox(panel
,wxID_ANY
,wxT(" wxComboBox ")),
761 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Writable, sorted:")), 0,
762 wxALIGN_CENTER_VERTICAL
|wxRIGHT
|wxEXPAND
, border
);
764 cb
= new wxComboBox(panel
,wxID_ANY
,wxEmptyString
,
765 wxDefaultPosition
, wxDefaultSize
,
767 wxCB_SORT
// wxNO_BORDER|wxCB_READONLY
770 cb
->Append(wxT("H - Appended Item")); // test sorting in append
772 cb
->SetValue(wxT("Dot Dash"));
774 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
777 // Readonly wxComboBox
778 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Read-only:")), 0,
779 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
781 cb
= new wxComboBox(panel
,wxID_ANY
,wxEmptyString
,
782 wxDefaultPosition
, wxDefaultSize
,
784 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
787 cb
->SetValue(wxT("Dot Dash"));
789 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
792 // Disabled wxComboBox
793 groupSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Disabled:")), 0,
794 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, border
);
796 cb
= new wxComboBox(panel
,wxID_ANY
,wxEmptyString
,
797 wxDefaultPosition
, wxDefaultSize
,
799 wxCB_SORT
|wxCB_READONLY
// wxNO_BORDER|wxCB_READONLY
802 cb
->SetValue(wxT("Dot Dash"));
805 groupSizer
->Add( cb
, 1, wxALIGN_CENTER_VERTICAL
|wxEXPAND
|wxALL
, border
);
807 rowSizer
->Add( groupSizer
, 1, wxEXPAND
|wxALL
, border
);
810 colSizer
->Add( rowSizer
, 1, wxEXPAND
|wxALL
, border
);
814 // Pen selector ODComboBox with application painted items
816 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
817 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
818 wxT("OwnerDrawnComboBox with Custom Paint Items and Button Placing:")), 1,
819 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
820 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
822 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
824 // When defining derivative class for callbacks, we need
825 // to use two-stage creation (or redefine the common wx
827 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
828 wxDefaultPosition
, wxDefaultSize
,
830 wxCB_READONLY
//wxNO_BORDER | wxCB_READONLY
833 odc
->SetPopupControl( new wxPenStylePopup() );
835 //m_odc->SetCustomPaintWidth( 60 );
836 odc
->SetSelection(0);
837 odc
->SetButtonPosition(-2, // width adjustment
838 -6, // height adjustment
840 2 // horizontal spacing
843 rowSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
844 rowSizer
->AddStretchSpacer(1);
845 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
849 // List View wxComboControl
852 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
853 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("List View wxComboControl:")), 1,
854 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
855 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,wxT("Tree Ctrl wxGenericComboControl:")), 1,
856 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
857 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
859 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
860 cc
= new wxComboControl(panel
,2,wxEmptyString
,
861 wxDefaultPosition
, wxDefaultSize
);
863 cc
->SetPopupMinWidth(300);
865 ListViewComboPopup
* iface
= new ListViewComboPopup();
866 cc
->SetPopupControl(iface
);
868 iface
->AddSelection( wxT("Cabbage") );
869 iface
->AddSelection( wxT("Potato") );
870 iface
->AddSelection( wxT("Onion") );
871 iface
->AddSelection( wxT("Carrot") );
872 iface
->AddSelection( wxT("Cauliflower") );
873 iface
->AddSelection( wxT("Bean") );
874 iface
->AddSelection( wxT("Raddish") );
875 iface
->AddSelection( wxT("Banana") );
876 iface
->AddSelection( wxT("Apple") );
877 iface
->AddSelection( wxT("Orange") );
878 iface
->AddSelection( wxT("Kiwi") );
879 iface
->AddSelection( wxT("Strawberry") );
880 iface
->AddSelection( wxT("Cucumber") );
881 iface
->AddSelection( wxT("Blackberry") );
882 iface
->AddSelection( wxT("Melon") );
883 iface
->AddSelection( wxT("Cherry") );
884 iface
->AddSelection( wxT("Pea") );
885 iface
->AddSelection( wxT("Pear") );
887 rowSizer
->Add( cc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
891 // Tree Ctrl wxComboControl
894 // Note that we test that wxGenericComboControl works
895 gcc
= new wxGenericComboControl(panel
,wxID_ANY
,wxEmptyString
,
896 wxDefaultPosition
, wxDefaultSize
);
898 // Set popup interface right away, otherwise some of the calls
900 TreeCtrlComboPopup
* tcPopup
= new TreeCtrlComboPopup();
901 gcc
->SetPopupControl(tcPopup
);
903 // Add items using wxTreeCtrl methods directly
904 wxTreeItemId rootId
= tcPopup
->AddRoot(wxT("<hidden_root>"));
906 wxTreeItemId groupId
;
908 groupId
= tcPopup
->AppendItem(rootId
,wxT("Controls"));
909 tcPopup
->AppendItem(groupId
,wxT("wxButton"));
910 tcPopup
->AppendItem(groupId
,wxT("wxCheckBox"));
911 tcPopup
->AppendItem(groupId
,wxT("wxListCtrl"));
912 tcPopup
->AppendItem(groupId
,wxT("wxStaticBox"));
913 tcPopup
->AppendItem(groupId
,wxT("wxStaticText"));
914 tcPopup
->AppendItem(groupId
,wxT("wxTextCtrl"));
915 tcPopup
->AppendItem(groupId
,wxT("wxTreeCtrl"));
916 groupId
= tcPopup
->AppendItem(rootId
,wxT("Dialogs"));
917 tcPopup
->AppendItem(groupId
,wxT("wxDirDialog"));
918 tcPopup
->AppendItem(groupId
,wxT("wxFileDialog"));
919 tcPopup
->AppendItem(groupId
,wxT("wxWizard"));
921 gcc
->SetValue(wxT("wxStaticBox"));
923 // Move button to left - it makes more sense for a tree ctrl
924 gcc
->SetButtonPosition(0, // width adjustment
925 0, // height adjustment
927 0 // horizontal spacing
930 rowSizer
->Add( gcc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5 );
932 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
935 wxInitAllImageHandlers();
938 // Custom Dropbutton Bitmaps
939 // (second one uses blank button background)
941 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
942 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
943 wxT("OwnerDrawnComboBox with simple dropbutton graphics:")), 1,
944 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
946 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
948 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
950 odc
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
951 wxDefaultPosition
, wxDefaultSize
,
953 (long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
956 wxOwnerDrawnComboBox
* odc2
;
957 odc2
= new wxOwnerDrawnComboBox(panel
,wxID_ANY
,wxEmptyString
,
958 wxDefaultPosition
, wxDefaultSize
,
960 (long)0 // wxCB_SORT // wxNO_BORDER | wxCB_READONLY
963 // Load images from disk
964 wxImage
imgNormal(wxT("dropbutn.png"));
965 wxImage
imgPressed(wxT("dropbutp.png"));
966 wxImage
imgHover(wxT("dropbuth.png"));
968 if ( imgNormal
.Ok() && imgPressed
.Ok() && imgHover
.Ok() )
970 wxBitmap
bmpNormal(imgNormal
);
971 wxBitmap
bmpPressed(imgPressed
);
972 wxBitmap
bmpHover(imgHover
);
973 odc
->SetButtonBitmaps(bmpNormal
,false,bmpPressed
,bmpHover
);
974 odc2
->SetButtonBitmaps(bmpNormal
,true,bmpPressed
,bmpHover
);
977 wxLogError(wxT("Dropbutton images not found"));
979 //odc2->SetButtonPosition(0, // width adjustment
980 // 0, // height adjustment
982 // 0 // horizontal spacing
985 rowSizer
->Add( odc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
986 rowSizer
->Add( odc2
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
987 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
992 // wxComboControl with totally custom button action (open file dialog)
994 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
995 rowSizer
->Add( new wxStaticText(panel
,wxID_ANY
,
996 wxT("wxComboControl with custom button action:")), 1,
997 wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4 );
1000 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
1002 rowSizer
= new wxBoxSizer ( wxHORIZONTAL
);
1003 wxFileSelectorCombo
* fsc
;
1005 fsc
= new wxFileSelectorCombo(panel
,wxID_ANY
,wxEmptyString
,
1006 wxDefaultPosition
, wxDefaultSize
,
1010 rowSizer
->Add( fsc
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 4 );
1011 colSizer
->Add( rowSizer
, 0, wxEXPAND
|wxALL
, 5 );
1014 topRowSizer
->Add( colSizer
, 1, wxALL
, 2 );
1016 topRowSizer
->Add( m_logWin
, 1, wxEXPAND
|wxALL
, 5 );
1017 topSizer
->Add( topRowSizer
, 1, wxEXPAND
);
1019 panel
->SetSizer( topSizer
);
1020 topSizer
->SetSizeHints( panel
);
1028 delete wxLog::SetActiveTarget(m_logOld
);
1033 void MyFrame::OnComboBoxUpdate( wxCommandEvent
& event
)
1035 // Don't show messages for the log output window (it'll crash)
1036 if ( event
.GetId() == 105 )
1039 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1040 wxLogDebug(wxT("EVT_COMBOBOX(id=%i,selection=%i)"),event
.GetId(),event
.GetSelection());
1041 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1042 wxLogDebug(wxT("EVT_TEXT(id=%i,string=\"%s\")"),event
.GetId(),event
.GetString().c_str());
1045 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
1047 // true is to force the frame to close
1051 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
1053 wxMessageBox(wxString::Format(
1054 _T("Welcome to %s!\n")
1056 _T("This is the wxWidgets wxComboControl sample\n")
1057 _T("running under %s."),
1059 wxGetOsDescription().c_str()
1061 _T("About wxComboControl sample"),
1062 wxOK
| wxICON_INFORMATION
,