1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
3 // Name: odcombobox.cpp
4 // Purpose: Part of the widgets sample showing wxOwnerDrawnComboBox
5 // Author: Jaakko Salli (based on combobox page by Vadim Zeitlin)
6 // Created: Jul-28-2006
8 // Copyright: (c) 2006 Jaakko Salli
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
29 // for all others, include the necessary headers
33 #include "wx/bitmap.h"
34 #include "wx/button.h"
35 #include "wx/checkbox.h"
36 #include "wx/combobox.h"
37 #include "wx/radiobox.h"
38 #include "wx/statbox.h"
39 #include "wx/textctrl.h"
43 #include "wx/dcmemory.h"
45 #include "wx/odcombo.h"
50 #include "icons/odcombobox.xpm"
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
59 ODComboPage_Reset
= wxID_HIGHEST
,
60 ODComboPage_PopupMinWidth
,
61 ODComboPage_PopupHeight
,
62 ODComboPage_ButtonWidth
,
63 ODComboPage_ButtonHeight
,
64 ODComboPage_ButtonSpacing
,
66 ODComboPage_InsertionPointText
,
68 ODComboPage_InsertText
,
71 ODComboPage_AddSeveral
,
75 ODComboPage_ChangeText
,
77 ODComboPage_DeleteText
,
78 ODComboPage_DeleteSel
,
83 // ----------------------------------------------------------------------------
84 // ODComboboxWidgetsPage
85 // ----------------------------------------------------------------------------
87 class ODComboboxWidgetsPage
: public WidgetsPage
90 ODComboboxWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
92 virtual wxControl
*GetWidget() const { return m_combobox
; }
93 virtual void RecreateWidget() { CreateCombo(); }
95 // lazy creation of the content
96 virtual void CreateContent();
100 void OnButtonReset(wxCommandEvent
& event
);
101 void OnButtonChange(wxCommandEvent
& event
);
102 void OnButtonDelete(wxCommandEvent
& event
);
103 void OnButtonDeleteSel(wxCommandEvent
& event
);
104 void OnButtonClear(wxCommandEvent
& event
);
105 void OnButtonInsert(wxCommandEvent
&event
);
106 void OnButtonAdd(wxCommandEvent
& event
);
107 void OnButtonAddSeveral(wxCommandEvent
& event
);
108 void OnButtonAddMany(wxCommandEvent
& event
);
110 void OnComboBox(wxCommandEvent
& event
);
111 void OnComboText(wxCommandEvent
& event
);
113 void OnCheckOrRadioBox(wxCommandEvent
& event
);
115 void OnTextPopupWidth(wxCommandEvent
& event
);
116 void OnTextPopupHeight(wxCommandEvent
& event
);
117 void OnTextButtonAll(wxCommandEvent
& event
);
119 void OnUpdateUICurText(wxUpdateUIEvent
& event
);
120 void OnUpdateUIInsertionPointText(wxUpdateUIEvent
& event
);
122 void OnUpdateUIInsert(wxUpdateUIEvent
& event
);
123 void OnUpdateUIAddSeveral(wxUpdateUIEvent
& event
);
124 void OnUpdateUIClearButton(wxUpdateUIEvent
& event
);
125 void OnUpdateUIDeleteButton(wxUpdateUIEvent
& event
);
126 void OnUpdateUIDeleteSelButton(wxUpdateUIEvent
& event
);
127 void OnUpdateUIResetButton(wxUpdateUIEvent
& event
);
129 // reset the odcombobox parameters
132 // (re)create the odcombobox
135 // helper that gets all button values from controls and calls SetButtonPosition
136 void GetButtonPosition();
138 // helper to create the button bitmap
139 wxBitmap
CreateBitmap(const wxColour
& colour
);
144 // the checkboxes for styles
145 wxCheckBox
*m_chkSort
,
151 // the text entries for popup and button adjustment
152 wxTextCtrl
*m_textPopupMinWidth
,
156 *m_textButtonSpacing
;
158 // the checkboxes for same
159 wxCheckBox
*m_chkAlignpopupright
,
162 // the combobox itself and the sizer it is in
163 wxOwnerDrawnComboBox
*m_combobox
;
164 wxSizer
*m_sizerCombo
;
166 // the text entries for "Add/change string" and "Delete" buttons
167 wxTextCtrl
*m_textInsert
,
173 DECLARE_EVENT_TABLE()
174 DECLARE_WIDGETS_PAGE(ODComboboxWidgetsPage
)
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
181 BEGIN_EVENT_TABLE(ODComboboxWidgetsPage
, WidgetsPage
)
182 EVT_BUTTON(ODComboPage_Reset
, ODComboboxWidgetsPage::OnButtonReset
)
183 EVT_BUTTON(ODComboPage_Change
, ODComboboxWidgetsPage::OnButtonChange
)
184 EVT_BUTTON(ODComboPage_Delete
, ODComboboxWidgetsPage::OnButtonDelete
)
185 EVT_BUTTON(ODComboPage_DeleteSel
, ODComboboxWidgetsPage::OnButtonDeleteSel
)
186 EVT_BUTTON(ODComboPage_Clear
, ODComboboxWidgetsPage::OnButtonClear
)
187 EVT_BUTTON(ODComboPage_Insert
, ODComboboxWidgetsPage::OnButtonInsert
)
188 EVT_BUTTON(ODComboPage_Add
, ODComboboxWidgetsPage::OnButtonAdd
)
189 EVT_BUTTON(ODComboPage_AddSeveral
, ODComboboxWidgetsPage::OnButtonAddSeveral
)
190 EVT_BUTTON(ODComboPage_AddMany
, ODComboboxWidgetsPage::OnButtonAddMany
)
192 EVT_TEXT_ENTER(ODComboPage_InsertText
, ODComboboxWidgetsPage::OnButtonInsert
)
193 EVT_TEXT_ENTER(ODComboPage_AddText
, ODComboboxWidgetsPage::OnButtonAdd
)
194 EVT_TEXT_ENTER(ODComboPage_DeleteText
, ODComboboxWidgetsPage::OnButtonDelete
)
196 EVT_TEXT(ODComboPage_PopupMinWidth
, ODComboboxWidgetsPage::OnTextPopupWidth
)
197 EVT_TEXT(ODComboPage_PopupHeight
, ODComboboxWidgetsPage::OnTextPopupHeight
)
198 EVT_TEXT(ODComboPage_ButtonWidth
, ODComboboxWidgetsPage::OnTextButtonAll
)
199 EVT_TEXT(ODComboPage_ButtonHeight
, ODComboboxWidgetsPage::OnTextButtonAll
)
200 EVT_TEXT(ODComboPage_ButtonSpacing
, ODComboboxWidgetsPage::OnTextButtonAll
)
202 EVT_UPDATE_UI(ODComboPage_CurText
, ODComboboxWidgetsPage::OnUpdateUICurText
)
203 EVT_UPDATE_UI(ODComboPage_InsertionPointText
, ODComboboxWidgetsPage::OnUpdateUIInsertionPointText
)
205 EVT_UPDATE_UI(ODComboPage_Reset
, ODComboboxWidgetsPage::OnUpdateUIResetButton
)
206 EVT_UPDATE_UI(ODComboPage_Insert
, ODComboboxWidgetsPage::OnUpdateUIInsert
)
207 EVT_UPDATE_UI(ODComboPage_AddSeveral
, ODComboboxWidgetsPage::OnUpdateUIAddSeveral
)
208 EVT_UPDATE_UI(ODComboPage_Clear
, ODComboboxWidgetsPage::OnUpdateUIClearButton
)
209 EVT_UPDATE_UI(ODComboPage_DeleteText
, ODComboboxWidgetsPage::OnUpdateUIClearButton
)
210 EVT_UPDATE_UI(ODComboPage_Delete
, ODComboboxWidgetsPage::OnUpdateUIDeleteButton
)
211 EVT_UPDATE_UI(ODComboPage_Change
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
212 EVT_UPDATE_UI(ODComboPage_ChangeText
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
213 EVT_UPDATE_UI(ODComboPage_DeleteSel
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
215 EVT_COMBOBOX(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboBox
)
216 EVT_TEXT(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboText
)
217 EVT_TEXT_ENTER(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboText
)
219 EVT_CHECKBOX(wxID_ANY
, ODComboboxWidgetsPage::OnCheckOrRadioBox
)
220 EVT_RADIOBOX(wxID_ANY
, ODComboboxWidgetsPage::OnCheckOrRadioBox
)
223 // ============================================================================
225 // ============================================================================
228 // wxOwnerDrawnComboBox needs to subclassed so that owner-drawing
229 // callbacks can be implemented.
230 class DemoODComboBox
: public wxOwnerDrawnComboBox
233 virtual void OnDrawItem(wxDC
& dc
,
236 int WXUNUSED(flags
)) const
238 if ( item
== wxNOT_FOUND
)
253 dc
.SetTextForeground(txtCol
);
255 dc
.DrawText(GetString(item
),
257 rect
.y
+ ((rect
.height
- dc
.GetCharHeight())/2)
261 virtual void OnDrawBackground(wxDC
& dc
, const wxRect
& rect
,
262 int item
, int flags
) const
265 // If item is selected or even, or we are painting the
266 // combo control itself, use the default rendering.
267 if ( GetVListBoxComboPopup()->IsCurrent((size_t)item
) ||
268 (flags
& wxODCB_PAINTING_CONTROL
) ||
271 wxOwnerDrawnComboBox::OnDrawBackground(dc
,rect
,item
,flags
);
275 // Otherwise, draw every other background with different colour.
276 wxColour
bgCol(240,240,250);
277 dc
.SetBrush(wxBrush(bgCol
));
278 dc
.SetPen(wxPen(bgCol
));
279 dc
.DrawRectangle(rect
);
282 virtual wxCoord
OnMeasureItem(size_t WXUNUSED(item
)) const
287 virtual wxCoord
OnMeasureItemWidth(size_t WXUNUSED(item
)) const
289 return -1; // default - will be measured from text width
294 IMPLEMENT_WIDGETS_PAGE(ODComboboxWidgetsPage
, _T("OwnerDrawnCombobox"),
295 GENERIC_CTRLS
| WITH_ITEMS_CTRLS
| COMBO_CTRLS
298 ODComboboxWidgetsPage::ODComboboxWidgetsPage(WidgetsBookCtrl
*book
,
299 wxImageList
*imaglist
)
300 : WidgetsPage(book
, imaglist
, odcombobox_xpm
)
305 m_chkDclickcycles
= (wxCheckBox
*)NULL
;
307 m_combobox
= (wxOwnerDrawnComboBox
*)NULL
;
308 m_sizerCombo
= (wxSizer
*)NULL
;
311 void ODComboboxWidgetsPage::CreateContent()
314 What we create here is a frame having 3 panes: style pane is the
315 leftmost one, in the middle the pane with buttons allowing to perform
316 miscellaneous combobox operations and the pane containing the combobox
322 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
324 wxSizer
*sizerLeft
= new wxBoxSizer(wxVERTICAL
);
326 // left pane - style box
327 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, _T("&Set style"));
329 wxSizer
*sizerStyle
= new wxStaticBoxSizer(box
, wxVERTICAL
);
331 m_chkSort
= CreateCheckBoxAndAddToSizer(sizerStyle
, _T("&Sort items"));
332 m_chkReadonly
= CreateCheckBoxAndAddToSizer(sizerStyle
, _T("&Read only"));
333 m_chkDclickcycles
= CreateCheckBoxAndAddToSizer(sizerStyle
, _T("&Double-click Cycles"));
335 sizerStyle
->AddSpacer(4);
337 m_chkBitmapbutton
= CreateCheckBoxAndAddToSizer(sizerStyle
, _T("&Bitmap button"));
338 m_chkStdbutton
= CreateCheckBoxAndAddToSizer(sizerStyle
, _T("B&lank button background"));
340 wxButton
*btn
= new wxButton(this, ODComboPage_Reset
, _T("&Reset"));
341 sizerStyle
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 3);
343 sizerLeft
->Add(sizerStyle
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
);
345 // left pane - popup adjustment box
346 box
= new wxStaticBox(this, wxID_ANY
, _T("Adjust &popup"));
348 wxSizer
*sizerPopupPos
= new wxStaticBoxSizer(box
, wxVERTICAL
);
350 sizerRow
= CreateSizerWithTextAndLabel(_T("Min. Width:"),
351 ODComboPage_PopupMinWidth
,
352 &m_textPopupMinWidth
);
353 m_textPopupMinWidth
->SetValue(wxT("-1"));
354 sizerPopupPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
356 sizerRow
= CreateSizerWithTextAndLabel(_T("Max. Height:"),
357 ODComboPage_PopupHeight
,
359 m_textPopupHeight
->SetValue(wxT("-1"));
360 sizerPopupPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
362 m_chkAlignpopupright
= CreateCheckBoxAndAddToSizer(sizerPopupPos
, _T("Align Right"));
364 sizerLeft
->Add(sizerPopupPos
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
| wxTOP
, 2);
366 // left pane - button adjustment box
367 box
= new wxStaticBox(this, wxID_ANY
, _T("Adjust &button"));
369 wxSizer
*sizerButtonPos
= new wxStaticBoxSizer(box
, wxVERTICAL
);
371 sizerRow
= CreateSizerWithTextAndLabel(_T("Width:"),
372 ODComboPage_ButtonWidth
,
374 m_textButtonWidth
->SetValue(wxT("-1"));
375 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
377 sizerRow
= CreateSizerWithTextAndLabel(_T("VSpacing:"),
378 ODComboPage_ButtonSpacing
,
379 &m_textButtonSpacing
);
380 m_textButtonSpacing
->SetValue(wxT("0"));
381 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
383 sizerRow
= CreateSizerWithTextAndLabel(_T("Height:"),
384 ODComboPage_ButtonHeight
,
385 &m_textButtonHeight
);
386 m_textButtonHeight
->SetValue(wxT("-1"));
387 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
389 m_chkAlignbutleft
= CreateCheckBoxAndAddToSizer(sizerButtonPos
, _T("Align Left"));
391 sizerLeft
->Add(sizerButtonPos
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
| wxTOP
, 2);
394 wxStaticBox
*box2
= new wxStaticBox(this, wxID_ANY
,
395 _T("&Change combobox contents"));
396 wxSizer
*sizerMiddle
= new wxStaticBoxSizer(box2
, wxVERTICAL
);
398 sizerRow
= CreateSizerWithTextAndLabel(_T("Current selection"),
401 text
->SetEditable(false);
403 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
405 sizerRow
= CreateSizerWithTextAndLabel(_T("Insertion Point"),
406 ODComboPage_InsertionPointText
,
408 text
->SetEditable(false);
410 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
412 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Insert
,
413 _T("&Insert this string"),
414 ODComboPage_InsertText
,
416 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
418 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Add
,
419 _T("&Add this string"),
422 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
424 btn
= new wxButton(this, ODComboPage_AddSeveral
, _T("&Append a few strings"));
425 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
427 btn
= new wxButton(this, ODComboPage_AddMany
, _T("Append &many strings"));
428 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
430 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Change
,
431 _T("C&hange current"),
432 ODComboPage_ChangeText
,
434 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
436 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Delete
,
437 _T("&Delete this item"),
438 ODComboPage_DeleteText
,
440 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
442 btn
= new wxButton(this, ODComboPage_DeleteSel
, _T("Delete &selection"));
443 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
445 btn
= new wxButton(this, ODComboPage_Clear
, _T("&Clear"));
446 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
449 wxSizer
*sizerRight
= new wxBoxSizer(wxVERTICAL
);
450 m_combobox
= new DemoODComboBox();
451 m_combobox
->Create(this, ODComboPage_Combo
, wxEmptyString
,
452 wxDefaultPosition
, wxDefaultSize
,
455 sizerRight
->Add(m_combobox
, 0, wxGROW
| wxALL
, 5);
456 sizerRight
->SetMinSize(150, 0);
457 m_sizerCombo
= sizerRight
; // save it to modify it later
459 // the 3 panes panes compose the window
460 sizerTop
->Add(sizerLeft
, 4, wxGROW
| (wxALL
& ~wxLEFT
), 10);
461 sizerTop
->Add(sizerMiddle
, 5, wxGROW
| wxALL
, 10);
462 sizerTop
->Add(sizerRight
, 4, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
464 // final initializations
472 // ----------------------------------------------------------------------------
474 // ----------------------------------------------------------------------------
476 void ODComboboxWidgetsPage::Reset()
478 m_chkSort
->SetValue(false);
479 m_chkReadonly
->SetValue(false);
480 m_chkDclickcycles
->SetValue(false);
481 m_chkDclickcycles
->Enable(false);
482 m_chkBitmapbutton
->SetValue(false);
483 m_chkStdbutton
->SetValue(false);
484 m_chkStdbutton
->Enable(false);
487 void ODComboboxWidgetsPage::CreateCombo()
489 int flags
= ms_defaultFlags
;
491 if ( m_chkSort
->GetValue() )
493 if ( m_chkReadonly
->GetValue() )
494 flags
|= wxCB_READONLY
;
495 if ( m_chkDclickcycles
->GetValue() )
496 flags
|= wxODCB_DCLICK_CYCLES
;
501 unsigned int count
= m_combobox
->GetCount();
502 for ( unsigned int n
= 0; n
< count
; n
++ )
504 items
.Add(m_combobox
->GetString(n
));
507 m_sizerCombo
->Detach( m_combobox
);
511 m_combobox
= new DemoODComboBox();
512 m_combobox
->Create(this, ODComboPage_Combo
, wxEmptyString
,
513 wxDefaultPosition
, wxDefaultSize
,
517 unsigned int count
= items
.GetCount();
518 for ( unsigned int n
= 0; n
< count
; n
++ )
520 m_combobox
->Append(items
[n
]);
523 // Update from controls that edit popup position etc.
525 wxUpdateUIEvent tempEvt
;
526 OnTextPopupWidth(tempEvt
);
527 OnTextPopupHeight(tempEvt
);
530 m_combobox
->SetPopupAnchor( m_chkAlignpopupright
->GetValue() ? wxRIGHT
: wxLEFT
);
532 if ( m_chkBitmapbutton
->GetValue() )
534 wxBitmap bmpNormal
= CreateBitmap(wxColour(0,0,255));
535 wxBitmap bmpPressed
= CreateBitmap(wxColour(0,0,128));
536 wxBitmap bmpHover
= CreateBitmap(wxColour(128,128,255));
537 m_combobox
->SetButtonBitmaps(bmpNormal
,m_chkStdbutton
->GetValue(),bmpPressed
,bmpHover
);
540 m_sizerCombo
->Add(m_combobox
, 0, wxGROW
| wxALL
, 5);
541 m_sizerCombo
->Layout();
544 // ----------------------------------------------------------------------------
546 // ----------------------------------------------------------------------------
548 void ODComboboxWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
555 void ODComboboxWidgetsPage::OnButtonChange(wxCommandEvent
& WXUNUSED(event
))
557 int sel
= m_combobox
->GetSelection();
558 if ( sel
!= wxNOT_FOUND
)
561 m_combobox
->SetString(sel
, m_textChange
->GetValue());
563 wxLogMessage(_T("Not implemented in wxGTK"));
568 void ODComboboxWidgetsPage::OnButtonDelete(wxCommandEvent
& WXUNUSED(event
))
571 if ( !m_textDelete
->GetValue().ToULong(&n
) ||
572 (n
>= m_combobox
->GetCount()) )
577 m_combobox
->Delete(n
);
580 void ODComboboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent
& WXUNUSED(event
))
582 int sel
= m_combobox
->GetSelection();
583 if ( sel
!= wxNOT_FOUND
)
585 m_combobox
->Delete(sel
);
589 void ODComboboxWidgetsPage::OnButtonClear(wxCommandEvent
& WXUNUSED(event
))
594 void ODComboboxWidgetsPage::OnButtonInsert(wxCommandEvent
& WXUNUSED(event
))
596 static unsigned int s_item
= 0;
598 wxString s
= m_textInsert
->GetValue();
599 if ( !m_textInsert
->IsModified() )
601 // update the default string
602 m_textInsert
->SetValue(wxString::Format(_T("test item %u"), ++s_item
));
605 if (m_combobox
->GetSelection() >= 0)
606 m_combobox
->Insert(s
, m_combobox
->GetSelection());
609 void ODComboboxWidgetsPage::OnButtonAdd(wxCommandEvent
& WXUNUSED(event
))
611 static unsigned int s_item
= 0;
613 wxString s
= m_textAdd
->GetValue();
614 if ( !m_textAdd
->IsModified() )
616 // update the default string
617 m_textAdd
->SetValue(wxString::Format(_T("test item %u"), ++s_item
));
620 m_combobox
->Append(s
);
623 void ODComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent
& WXUNUSED(event
))
625 // "many" means 1000 here
626 for ( unsigned int n
= 0; n
< 1000; n
++ )
628 m_combobox
->Append(wxString::Format(_T("item #%u"), n
));
632 void ODComboboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent
& WXUNUSED(event
))
634 m_combobox
->Append(_T("First"));
635 m_combobox
->Append(_T("another one"));
636 m_combobox
->Append(_T("and the last (very very very very very very very very very very long) one"));
639 void ODComboboxWidgetsPage::OnTextPopupWidth(wxCommandEvent
& WXUNUSED(event
))
643 m_textPopupMinWidth
->GetValue().ToLong(&l
);
645 if (m_combobox
&& l
> 0)
647 m_combobox
->SetPopupMinWidth(l
);
651 void ODComboboxWidgetsPage::OnTextPopupHeight(wxCommandEvent
& WXUNUSED(event
))
655 m_textPopupHeight
->GetValue().ToLong(&l
);
657 if (m_combobox
&& l
> 0)
659 m_combobox
->SetPopupMaxHeight(l
);
663 void ODComboboxWidgetsPage::GetButtonPosition()
669 m_textButtonWidth
->GetValue().ToLong(&w
);
670 m_textButtonSpacing
->GetValue().ToLong(&spacing
);
671 m_textButtonHeight
->GetValue().ToLong(&h
);
672 int align
= m_chkAlignbutleft
->GetValue() ?
675 m_combobox
->SetButtonPosition(w
,h
,align
,spacing
);
678 void ODComboboxWidgetsPage::OnTextButtonAll(wxCommandEvent
& WXUNUSED(event
))
682 if ( m_chkBitmapbutton
->GetValue() )
689 void ODComboboxWidgetsPage::OnUpdateUICurText(wxUpdateUIEvent
& event
)
692 event
.SetText( wxString::Format(_T("%d"), m_combobox
->GetSelection()) );
695 void ODComboboxWidgetsPage::OnUpdateUIInsertionPointText(wxUpdateUIEvent
& event
)
698 event
.SetText( wxString::Format(_T("%ld"), m_combobox
->GetInsertionPoint()) );
701 void ODComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent
& event
)
704 event
.Enable( m_chkSort
->GetValue() || m_chkReadonly
->GetValue() ||
705 m_chkBitmapbutton
->GetValue() );
708 void ODComboboxWidgetsPage::OnUpdateUIInsert(wxUpdateUIEvent
& event
)
712 bool enable
= !(m_combobox
->GetWindowStyle() & wxCB_SORT
) &&
713 (m_combobox
->GetSelection() >= 0);
715 event
.Enable(enable
);
719 void ODComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent
& event
)
724 event
.Enable(m_textDelete
->GetValue().ToULong(&n
) &&
725 (n
< (unsigned)m_combobox
->GetCount()));
729 void ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent
& event
)
732 event
.Enable(m_combobox
->GetSelection() != wxNOT_FOUND
);
735 void ODComboboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent
& event
)
738 event
.Enable(m_combobox
->GetCount() != 0);
741 void ODComboboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent
& event
)
744 event
.Enable(!(m_combobox
->GetWindowStyle() & wxCB_SORT
));
747 void ODComboboxWidgetsPage::OnComboText(wxCommandEvent
& event
)
752 wxString s
= event
.GetString();
754 wxASSERT_MSG( s
== m_combobox
->GetValue(),
755 _T("event and combobox values should be the same") );
757 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
758 wxLogMessage(_T("OwnerDrawnCombobox enter pressed (now '%s')"), s
.c_str());
760 wxLogMessage(_T("OwnerDrawnCombobox text changed (now '%s')"), s
.c_str());
763 void ODComboboxWidgetsPage::OnComboBox(wxCommandEvent
& event
)
765 long sel
= event
.GetInt();
766 m_textDelete
->SetValue(wxString::Format(_T("%ld"), sel
));
768 wxLogMessage(_T("OwnerDrawnCombobox item %ld selected"), sel
);
770 wxLogMessage(_T("OwnerDrawnCombobox GetValue(): %s"), m_combobox
->GetValue().c_str() );
773 void ODComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent
& event
)
775 wxObject
* ctrl
= event
.GetEventObject();
777 // Double-click cycles only applies to read-only combobox
778 if ( ctrl
== (wxObject
*) m_chkReadonly
)
780 m_chkDclickcycles
->Enable( m_chkReadonly
->GetValue() );
782 else if ( ctrl
== (wxObject
*) m_chkBitmapbutton
)
784 m_chkStdbutton
->Enable( m_chkBitmapbutton
->GetValue() );
786 else if ( ctrl
== (wxObject
*) m_chkAlignbutleft
)
788 wxUpdateUIEvent tempEvt
;
789 OnTextButtonAll(tempEvt
);
795 wxBitmap
ODComboboxWidgetsPage::CreateBitmap(const wxColour
& colour
)
797 int ch
= m_combobox
->GetClientSize().y
- 1;
803 m_textButtonWidth
->GetValue().ToLong(&w
);
804 m_textButtonHeight
->GetValue().ToLong(&h
);
815 dc
.SelectObject(bmp
);
817 // Draw transparent background
818 wxColour
magic(255,0,255);
819 wxBrush
magicBrush(magic
);
820 dc
.SetBrush(magicBrush
);
821 dc
.SetPen(*wxTRANSPARENT_PEN
);
822 dc
.DrawRectangle(0,0,bmp
.GetWidth(),bmp
.GetHeight());
824 // Draw image content
825 dc
.SetBrush(wxBrush(colour
));
826 dc
.DrawCircle(h
/2,h
/2+1,(h
/2));
828 dc
.SelectObject(wxNullBitmap
);
830 // Finalize transparency with a mask
831 wxMask
*mask
= new wxMask(bmp
, magic
);
837 #endif //wxUSE_ODCOMBOBOX