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 // Licence: wxWindows licence
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"
48 #include "itemcontainer.h"
51 #include "icons/odcombobox.xpm"
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
60 ODComboPage_Reset
= wxID_HIGHEST
,
61 ODComboPage_PopupMinWidth
,
62 ODComboPage_PopupHeight
,
63 ODComboPage_ButtonWidth
,
64 ODComboPage_ButtonHeight
,
65 ODComboPage_ButtonSpacing
,
67 ODComboPage_InsertionPointText
,
69 ODComboPage_InsertText
,
72 ODComboPage_AddSeveral
,
76 ODComboPage_ChangeText
,
78 ODComboPage_DeleteText
,
79 ODComboPage_DeleteSel
,
81 ODComboPage_ContainerTests
85 // ----------------------------------------------------------------------------
86 // ODComboboxWidgetsPage
87 // ----------------------------------------------------------------------------
89 class ODComboboxWidgetsPage
: public ItemContainerWidgetsPage
92 ODComboboxWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
94 virtual wxControl
*GetWidget() const { return m_combobox
; }
95 virtual wxTextEntryBase
*GetTextEntry() const
96 { return m_combobox
? m_combobox
->GetTextCtrl() : NULL
; }
97 virtual wxItemContainer
* GetContainer() const { return m_combobox
; }
98 virtual void RecreateWidget() { CreateCombo(); }
100 // lazy creation of the content
101 virtual void CreateContent();
105 void OnButtonReset(wxCommandEvent
& event
);
106 void OnButtonChange(wxCommandEvent
& event
);
107 void OnButtonDelete(wxCommandEvent
& event
);
108 void OnButtonDeleteSel(wxCommandEvent
& event
);
109 void OnButtonClear(wxCommandEvent
& event
);
110 void OnButtonInsert(wxCommandEvent
&event
);
111 void OnButtonAdd(wxCommandEvent
& event
);
112 void OnButtonAddSeveral(wxCommandEvent
& event
);
113 void OnButtonAddMany(wxCommandEvent
& event
);
115 void OnComboBox(wxCommandEvent
& event
);
116 void OnDropDown(wxCommandEvent
& event
);
117 void OnCloseUp(wxCommandEvent
& event
);
118 void OnComboText(wxCommandEvent
& event
);
120 void OnCheckOrRadioBox(wxCommandEvent
& event
);
122 void OnTextPopupWidth(wxCommandEvent
& event
);
123 void OnTextPopupHeight(wxCommandEvent
& event
);
124 void OnTextButtonAll(wxCommandEvent
& event
);
126 void OnUpdateUICurText(wxUpdateUIEvent
& event
);
127 void OnUpdateUIInsertionPointText(wxUpdateUIEvent
& event
);
129 void OnUpdateUIInsert(wxUpdateUIEvent
& event
);
130 void OnUpdateUIAddSeveral(wxUpdateUIEvent
& event
);
131 void OnUpdateUIClearButton(wxUpdateUIEvent
& event
);
132 void OnUpdateUIDeleteButton(wxUpdateUIEvent
& event
);
133 void OnUpdateUIDeleteSelButton(wxUpdateUIEvent
& event
);
134 void OnUpdateUIResetButton(wxUpdateUIEvent
& event
);
136 // reset the odcombobox parameters
139 // (re)create the odcombobox
142 // helper that gets all button values from controls and calls SetButtonPosition
143 void GetButtonPosition();
145 // helper to create the button bitmap
146 wxBitmap
CreateBitmap(const wxColour
& colour
);
151 // the checkboxes for styles
152 wxCheckBox
*m_chkSort
,
158 // the text entries for popup and button adjustment
159 wxTextCtrl
*m_textPopupMinWidth
,
163 *m_textButtonSpacing
;
165 // the checkboxes for same
166 wxCheckBox
*m_chkAlignpopupright
,
169 // the combobox itself and the sizer it is in
170 wxOwnerDrawnComboBox
*m_combobox
;
171 wxSizer
*m_sizerCombo
;
173 // the text entries for "Add/change string" and "Delete" buttons
174 wxTextCtrl
*m_textInsert
,
180 DECLARE_EVENT_TABLE()
181 DECLARE_WIDGETS_PAGE(ODComboboxWidgetsPage
)
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
188 BEGIN_EVENT_TABLE(ODComboboxWidgetsPage
, WidgetsPage
)
189 EVT_BUTTON(ODComboPage_Reset
, ODComboboxWidgetsPage::OnButtonReset
)
190 EVT_BUTTON(ODComboPage_Change
, ODComboboxWidgetsPage::OnButtonChange
)
191 EVT_BUTTON(ODComboPage_Delete
, ODComboboxWidgetsPage::OnButtonDelete
)
192 EVT_BUTTON(ODComboPage_DeleteSel
, ODComboboxWidgetsPage::OnButtonDeleteSel
)
193 EVT_BUTTON(ODComboPage_Clear
, ODComboboxWidgetsPage::OnButtonClear
)
194 EVT_BUTTON(ODComboPage_Insert
, ODComboboxWidgetsPage::OnButtonInsert
)
195 EVT_BUTTON(ODComboPage_Add
, ODComboboxWidgetsPage::OnButtonAdd
)
196 EVT_BUTTON(ODComboPage_AddSeveral
, ODComboboxWidgetsPage::OnButtonAddSeveral
)
197 EVT_BUTTON(ODComboPage_AddMany
, ODComboboxWidgetsPage::OnButtonAddMany
)
198 EVT_BUTTON(ODComboPage_ContainerTests
, ItemContainerWidgetsPage::OnButtonTestItemContainer
)
200 EVT_TEXT_ENTER(ODComboPage_InsertText
, ODComboboxWidgetsPage::OnButtonInsert
)
201 EVT_TEXT_ENTER(ODComboPage_AddText
, ODComboboxWidgetsPage::OnButtonAdd
)
202 EVT_TEXT_ENTER(ODComboPage_DeleteText
, ODComboboxWidgetsPage::OnButtonDelete
)
204 EVT_TEXT(ODComboPage_PopupMinWidth
, ODComboboxWidgetsPage::OnTextPopupWidth
)
205 EVT_TEXT(ODComboPage_PopupHeight
, ODComboboxWidgetsPage::OnTextPopupHeight
)
206 EVT_TEXT(ODComboPage_ButtonWidth
, ODComboboxWidgetsPage::OnTextButtonAll
)
207 EVT_TEXT(ODComboPage_ButtonHeight
, ODComboboxWidgetsPage::OnTextButtonAll
)
208 EVT_TEXT(ODComboPage_ButtonSpacing
, ODComboboxWidgetsPage::OnTextButtonAll
)
210 EVT_UPDATE_UI(ODComboPage_CurText
, ODComboboxWidgetsPage::OnUpdateUICurText
)
211 EVT_UPDATE_UI(ODComboPage_InsertionPointText
, ODComboboxWidgetsPage::OnUpdateUIInsertionPointText
)
213 EVT_UPDATE_UI(ODComboPage_Reset
, ODComboboxWidgetsPage::OnUpdateUIResetButton
)
214 EVT_UPDATE_UI(ODComboPage_Insert
, ODComboboxWidgetsPage::OnUpdateUIInsert
)
215 EVT_UPDATE_UI(ODComboPage_AddSeveral
, ODComboboxWidgetsPage::OnUpdateUIAddSeveral
)
216 EVT_UPDATE_UI(ODComboPage_Clear
, ODComboboxWidgetsPage::OnUpdateUIClearButton
)
217 EVT_UPDATE_UI(ODComboPage_DeleteText
, ODComboboxWidgetsPage::OnUpdateUIClearButton
)
218 EVT_UPDATE_UI(ODComboPage_Delete
, ODComboboxWidgetsPage::OnUpdateUIDeleteButton
)
219 EVT_UPDATE_UI(ODComboPage_Change
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
220 EVT_UPDATE_UI(ODComboPage_ChangeText
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
221 EVT_UPDATE_UI(ODComboPage_DeleteSel
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
223 EVT_COMBOBOX_DROPDOWN(ODComboPage_Combo
, ODComboboxWidgetsPage::OnDropDown
)
224 EVT_COMBOBOX_CLOSEUP(ODComboPage_Combo
, ODComboboxWidgetsPage::OnCloseUp
)
225 EVT_COMBOBOX(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboBox
)
226 EVT_TEXT(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboText
)
227 EVT_TEXT_ENTER(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboText
)
229 EVT_CHECKBOX(wxID_ANY
, ODComboboxWidgetsPage::OnCheckOrRadioBox
)
230 EVT_RADIOBOX(wxID_ANY
, ODComboboxWidgetsPage::OnCheckOrRadioBox
)
233 // ============================================================================
235 // ============================================================================
238 // wxOwnerDrawnComboBox needs to subclassed so that owner-drawing
239 // callbacks can be implemented.
240 class DemoODComboBox
: public wxOwnerDrawnComboBox
243 virtual void OnDrawItem(wxDC
& dc
,
246 int WXUNUSED(flags
)) const
248 if ( item
== wxNOT_FOUND
)
263 dc
.SetTextForeground(txtCol
);
265 dc
.DrawText(GetString(item
),
267 rect
.y
+ ((rect
.height
- dc
.GetCharHeight())/2)
271 virtual void OnDrawBackground(wxDC
& dc
, const wxRect
& rect
,
272 int item
, int flags
) const
275 // If item is selected or even, or we are painting the
276 // combo control itself, use the default rendering.
277 if ( (flags
& (wxODCB_PAINTING_CONTROL
|wxODCB_PAINTING_SELECTED
)) ||
280 wxOwnerDrawnComboBox::OnDrawBackground(dc
,rect
,item
,flags
);
284 // Otherwise, draw every other background with different colour.
285 wxColour
bgCol(240,240,250);
286 dc
.SetBrush(wxBrush(bgCol
));
287 dc
.SetPen(wxPen(bgCol
));
288 dc
.DrawRectangle(rect
);
291 virtual wxCoord
OnMeasureItem(size_t WXUNUSED(item
)) const
296 virtual wxCoord
OnMeasureItemWidth(size_t WXUNUSED(item
)) const
298 return -1; // default - will be measured from text width
303 IMPLEMENT_WIDGETS_PAGE(ODComboboxWidgetsPage
, wxT("OwnerDrawnCombobox"),
304 GENERIC_CTRLS
| WITH_ITEMS_CTRLS
| COMBO_CTRLS
307 ODComboboxWidgetsPage::ODComboboxWidgetsPage(WidgetsBookCtrl
*book
,
308 wxImageList
*imaglist
)
309 : ItemContainerWidgetsPage(book
, imaglist
, odcombobox_xpm
)
314 m_chkDclickcycles
= (wxCheckBox
*)NULL
;
316 m_combobox
= (wxOwnerDrawnComboBox
*)NULL
;
317 m_sizerCombo
= (wxSizer
*)NULL
;
320 void ODComboboxWidgetsPage::CreateContent()
323 What we create here is a frame having 3 panes: style pane is the
324 leftmost one, in the middle the pane with buttons allowing to perform
325 miscellaneous combobox operations and the pane containing the combobox
331 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
333 wxSizer
*sizerLeft
= new wxBoxSizer(wxVERTICAL
);
335 // left pane - style box
336 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, wxT("&Set style"));
338 wxSizer
*sizerStyle
= new wxStaticBoxSizer(box
, wxVERTICAL
);
340 m_chkSort
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Sort items"));
341 m_chkReadonly
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Read only"));
342 m_chkDclickcycles
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Double-click Cycles"));
344 sizerStyle
->AddSpacer(4);
346 m_chkBitmapbutton
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Bitmap button"));
347 m_chkStdbutton
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("B&lank button background"));
349 wxButton
*btn
= new wxButton(this, ODComboPage_Reset
, wxT("&Reset"));
350 sizerStyle
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 3);
352 sizerLeft
->Add(sizerStyle
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
);
354 // left pane - popup adjustment box
355 box
= new wxStaticBox(this, wxID_ANY
, wxT("Adjust &popup"));
357 wxSizer
*sizerPopupPos
= new wxStaticBoxSizer(box
, wxVERTICAL
);
359 sizerRow
= CreateSizerWithTextAndLabel(wxT("Min. Width:"),
360 ODComboPage_PopupMinWidth
,
361 &m_textPopupMinWidth
);
362 m_textPopupMinWidth
->SetValue(wxT("-1"));
363 sizerPopupPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
365 sizerRow
= CreateSizerWithTextAndLabel(wxT("Max. Height:"),
366 ODComboPage_PopupHeight
,
368 m_textPopupHeight
->SetValue(wxT("-1"));
369 sizerPopupPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
371 m_chkAlignpopupright
= CreateCheckBoxAndAddToSizer(sizerPopupPos
, wxT("Align Right"));
373 sizerLeft
->Add(sizerPopupPos
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
| wxTOP
, 2);
375 // left pane - button adjustment box
376 box
= new wxStaticBox(this, wxID_ANY
, wxT("Adjust &button"));
378 wxSizer
*sizerButtonPos
= new wxStaticBoxSizer(box
, wxVERTICAL
);
380 sizerRow
= CreateSizerWithTextAndLabel(wxT("Width:"),
381 ODComboPage_ButtonWidth
,
383 m_textButtonWidth
->SetValue(wxT("-1"));
384 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
386 sizerRow
= CreateSizerWithTextAndLabel(wxT("VSpacing:"),
387 ODComboPage_ButtonSpacing
,
388 &m_textButtonSpacing
);
389 m_textButtonSpacing
->SetValue(wxT("0"));
390 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
392 sizerRow
= CreateSizerWithTextAndLabel(wxT("Height:"),
393 ODComboPage_ButtonHeight
,
394 &m_textButtonHeight
);
395 m_textButtonHeight
->SetValue(wxT("-1"));
396 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
398 m_chkAlignbutleft
= CreateCheckBoxAndAddToSizer(sizerButtonPos
, wxT("Align Left"));
400 sizerLeft
->Add(sizerButtonPos
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
| wxTOP
, 2);
403 wxStaticBox
*box2
= new wxStaticBox(this, wxID_ANY
,
404 wxT("&Change combobox contents"));
405 wxSizer
*sizerMiddle
= new wxStaticBoxSizer(box2
, wxVERTICAL
);
407 btn
= new wxButton(this, ODComboPage_ContainerTests
, wxT("Run &tests"));
408 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
410 sizerRow
= CreateSizerWithTextAndLabel(wxT("Current selection"),
413 text
->SetEditable(false);
415 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
417 sizerRow
= CreateSizerWithTextAndLabel(wxT("Insertion Point"),
418 ODComboPage_InsertionPointText
,
420 text
->SetEditable(false);
422 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
424 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Insert
,
425 wxT("&Insert this string"),
426 ODComboPage_InsertText
,
428 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
430 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Add
,
431 wxT("&Add this string"),
434 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
436 btn
= new wxButton(this, ODComboPage_AddSeveral
, wxT("&Append a few strings"));
437 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
439 btn
= new wxButton(this, ODComboPage_AddMany
, wxT("Append &many strings"));
440 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
442 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Change
,
443 wxT("C&hange current"),
444 ODComboPage_ChangeText
,
446 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
448 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Delete
,
449 wxT("&Delete this item"),
450 ODComboPage_DeleteText
,
452 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
454 btn
= new wxButton(this, ODComboPage_DeleteSel
, wxT("Delete &selection"));
455 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
457 btn
= new wxButton(this, ODComboPage_Clear
, wxT("&Clear"));
458 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
461 wxSizer
*sizerRight
= new wxBoxSizer(wxVERTICAL
);
462 m_combobox
= new DemoODComboBox();
463 m_combobox
->Create(this, ODComboPage_Combo
, wxEmptyString
,
464 wxDefaultPosition
, wxDefaultSize
,
467 sizerRight
->Add(m_combobox
, 0, wxGROW
| wxALL
, 5);
468 sizerRight
->SetMinSize(150, 0);
469 m_sizerCombo
= sizerRight
; // save it to modify it later
471 // the 3 panes panes compose the window
472 sizerTop
->Add(sizerLeft
, 4, wxGROW
| (wxALL
& ~wxLEFT
), 10);
473 sizerTop
->Add(sizerMiddle
, 5, wxGROW
| wxALL
, 10);
474 sizerTop
->Add(sizerRight
, 4, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
476 // final initializations
482 // ----------------------------------------------------------------------------
484 // ----------------------------------------------------------------------------
486 void ODComboboxWidgetsPage::Reset()
488 m_chkSort
->SetValue(false);
489 m_chkReadonly
->SetValue(false);
490 m_chkDclickcycles
->SetValue(false);
491 m_chkDclickcycles
->Enable(false);
492 m_chkBitmapbutton
->SetValue(false);
493 m_chkStdbutton
->SetValue(false);
494 m_chkStdbutton
->Enable(false);
497 void ODComboboxWidgetsPage::CreateCombo()
499 int flags
= ms_defaultFlags
;
501 if ( m_chkSort
->GetValue() )
503 if ( m_chkReadonly
->GetValue() )
504 flags
|= wxCB_READONLY
;
505 if ( m_chkDclickcycles
->GetValue() )
506 flags
|= wxODCB_DCLICK_CYCLES
;
511 unsigned int count
= m_combobox
->GetCount();
512 for ( unsigned int n
= 0; n
< count
; n
++ )
514 items
.Add(m_combobox
->GetString(n
));
517 m_sizerCombo
->Detach( m_combobox
);
521 m_combobox
= new DemoODComboBox();
522 m_combobox
->Create(this, ODComboPage_Combo
, wxEmptyString
,
523 wxDefaultPosition
, wxDefaultSize
,
527 unsigned int count
= items
.GetCount();
528 for ( unsigned int n
= 0; n
< count
; n
++ )
530 m_combobox
->Append(items
[n
]);
533 // Update from controls that edit popup position etc.
535 wxUpdateUIEvent tempEvt
;
536 OnTextPopupWidth(tempEvt
);
537 OnTextPopupHeight(tempEvt
);
540 m_combobox
->SetPopupAnchor( m_chkAlignpopupright
->GetValue() ? wxRIGHT
: wxLEFT
);
542 if ( m_chkBitmapbutton
->GetValue() )
544 wxBitmap bmpNormal
= CreateBitmap(wxColour(0,0,255));
545 wxBitmap bmpPressed
= CreateBitmap(wxColour(0,0,128));
546 wxBitmap bmpHover
= CreateBitmap(wxColour(128,128,255));
547 m_combobox
->SetButtonBitmaps(bmpNormal
,m_chkStdbutton
->GetValue(),bmpPressed
,bmpHover
);
550 m_sizerCombo
->Add(m_combobox
, 0, wxGROW
| wxALL
, 5);
551 m_sizerCombo
->Layout();
554 // ----------------------------------------------------------------------------
556 // ----------------------------------------------------------------------------
558 void ODComboboxWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
565 void ODComboboxWidgetsPage::OnButtonChange(wxCommandEvent
& WXUNUSED(event
))
567 int sel
= m_combobox
->GetSelection();
568 if ( sel
!= wxNOT_FOUND
)
571 m_combobox
->SetString(sel
, m_textChange
->GetValue());
573 wxLogMessage(wxT("Not implemented in wxGTK"));
578 void ODComboboxWidgetsPage::OnButtonDelete(wxCommandEvent
& WXUNUSED(event
))
581 if ( !m_textDelete
->GetValue().ToULong(&n
) ||
582 (n
>= m_combobox
->GetCount()) )
587 m_combobox
->Delete(n
);
590 void ODComboboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent
& WXUNUSED(event
))
592 int sel
= m_combobox
->GetSelection();
593 if ( sel
!= wxNOT_FOUND
)
595 m_combobox
->Delete(sel
);
599 void ODComboboxWidgetsPage::OnButtonClear(wxCommandEvent
& WXUNUSED(event
))
604 void ODComboboxWidgetsPage::OnButtonInsert(wxCommandEvent
& WXUNUSED(event
))
606 static unsigned int s_item
= 0;
608 wxString s
= m_textInsert
->GetValue();
609 if ( !m_textInsert
->IsModified() )
611 // update the default string
612 m_textInsert
->SetValue(wxString::Format(wxT("test item %u"), ++s_item
));
615 if (m_combobox
->GetSelection() >= 0)
616 m_combobox
->Insert(s
, m_combobox
->GetSelection());
619 void ODComboboxWidgetsPage::OnButtonAdd(wxCommandEvent
& WXUNUSED(event
))
621 static unsigned int s_item
= 0;
623 wxString s
= m_textAdd
->GetValue();
624 if ( !m_textAdd
->IsModified() )
626 // update the default string
627 m_textAdd
->SetValue(wxString::Format(wxT("test item %u"), ++s_item
));
630 m_combobox
->Append(s
);
633 void ODComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent
& WXUNUSED(event
))
635 // "many" means 1000 here
636 for ( unsigned int n
= 0; n
< 1000; n
++ )
638 m_combobox
->Append(wxString::Format(wxT("item #%u"), n
));
642 void ODComboboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent
& WXUNUSED(event
))
644 m_combobox
->Append(wxT("First"));
645 m_combobox
->Append(wxT("another one"));
646 m_combobox
->Append(wxT("and the last (very very very very very very very very very very long) one"));
649 void ODComboboxWidgetsPage::OnTextPopupWidth(wxCommandEvent
& WXUNUSED(event
))
653 m_textPopupMinWidth
->GetValue().ToLong(&l
);
655 if (m_combobox
&& l
> 0)
657 m_combobox
->SetPopupMinWidth(l
);
661 void ODComboboxWidgetsPage::OnTextPopupHeight(wxCommandEvent
& WXUNUSED(event
))
665 m_textPopupHeight
->GetValue().ToLong(&l
);
667 if (m_combobox
&& l
> 0)
669 m_combobox
->SetPopupMaxHeight(l
);
673 void ODComboboxWidgetsPage::GetButtonPosition()
679 m_textButtonWidth
->GetValue().ToLong(&w
);
680 m_textButtonSpacing
->GetValue().ToLong(&spacing
);
681 m_textButtonHeight
->GetValue().ToLong(&h
);
682 int align
= m_chkAlignbutleft
->GetValue() ?
685 m_combobox
->SetButtonPosition(w
,h
,align
,spacing
);
688 void ODComboboxWidgetsPage::OnTextButtonAll(wxCommandEvent
& WXUNUSED(event
))
692 if ( m_chkBitmapbutton
->GetValue() )
699 void ODComboboxWidgetsPage::OnUpdateUICurText(wxUpdateUIEvent
& event
)
702 event
.SetText( wxString::Format(wxT("%d"), m_combobox
->GetSelection()) );
705 void ODComboboxWidgetsPage::OnUpdateUIInsertionPointText(wxUpdateUIEvent
& event
)
708 event
.SetText( wxString::Format(wxT("%ld"), m_combobox
->GetInsertionPoint()) );
711 void ODComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent
& event
)
714 event
.Enable( m_chkSort
->GetValue() || m_chkReadonly
->GetValue() ||
715 m_chkBitmapbutton
->GetValue() );
718 void ODComboboxWidgetsPage::OnUpdateUIInsert(wxUpdateUIEvent
& event
)
722 bool enable
= !(m_combobox
->GetWindowStyle() & wxCB_SORT
) &&
723 (m_combobox
->GetSelection() >= 0);
725 event
.Enable(enable
);
729 void ODComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent
& event
)
734 event
.Enable(m_textDelete
->GetValue().ToULong(&n
) &&
735 (n
< (unsigned)m_combobox
->GetCount()));
739 void ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent
& event
)
742 event
.Enable(m_combobox
->GetSelection() != wxNOT_FOUND
);
745 void ODComboboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent
& event
)
748 event
.Enable(m_combobox
->GetCount() != 0);
751 void ODComboboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent
& event
)
754 event
.Enable(!(m_combobox
->GetWindowStyle() & wxCB_SORT
));
757 void ODComboboxWidgetsPage::OnComboText(wxCommandEvent
& event
)
762 wxString s
= event
.GetString();
764 wxASSERT_MSG( s
== m_combobox
->GetValue(),
765 wxT("event and combobox values should be the same") );
767 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
769 wxLogMessage(wxT("OwnerDrawnCombobox enter pressed (now '%s')"), s
.c_str());
773 wxLogMessage(wxT("OwnerDrawnCombobox text changed (now '%s')"), s
.c_str());
777 void ODComboboxWidgetsPage::OnComboBox(wxCommandEvent
& event
)
779 long sel
= event
.GetInt();
780 m_textDelete
->SetValue(wxString::Format(wxT("%ld"), sel
));
782 wxLogMessage(wxT("OwnerDrawnCombobox item %ld selected"), sel
);
784 wxLogMessage(wxT("OwnerDrawnCombobox GetValue(): %s"), m_combobox
->GetValue().c_str() );
787 void ODComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent
& event
)
789 wxObject
* ctrl
= event
.GetEventObject();
791 // Double-click cycles only applies to read-only combobox
792 if ( ctrl
== (wxObject
*) m_chkReadonly
)
794 m_chkDclickcycles
->Enable( m_chkReadonly
->GetValue() );
796 else if ( ctrl
== (wxObject
*) m_chkBitmapbutton
)
798 m_chkStdbutton
->Enable( m_chkBitmapbutton
->GetValue() );
800 else if ( ctrl
== (wxObject
*) m_chkAlignbutleft
)
802 wxUpdateUIEvent tempEvt
;
803 OnTextButtonAll(tempEvt
);
809 wxBitmap
ODComboboxWidgetsPage::CreateBitmap(const wxColour
& colour
)
811 int ch
= m_combobox
->GetClientSize().y
- 1;
817 m_textButtonWidth
->GetValue().ToLong(&w
);
818 m_textButtonHeight
->GetValue().ToLong(&h
);
829 dc
.SelectObject(bmp
);
831 // Draw transparent background
832 wxColour
magic(255,0,255);
833 wxBrush
magicBrush(magic
);
834 dc
.SetBrush(magicBrush
);
835 dc
.SetPen(*wxTRANSPARENT_PEN
);
836 dc
.DrawRectangle(0,0,bmp
.GetWidth(),bmp
.GetHeight());
838 // Draw image content
839 dc
.SetBrush(wxBrush(colour
));
840 dc
.DrawCircle(h
/2,h
/2+1,(h
/2));
842 dc
.SelectObject(wxNullBitmap
);
844 // Finalize transparency with a mask
845 wxMask
*mask
= new wxMask(bmp
, magic
);
851 void ODComboboxWidgetsPage::OnDropDown(wxCommandEvent
& WXUNUSED(event
))
853 wxLogMessage(wxT("Combobox dropped down"));
856 void ODComboboxWidgetsPage::OnCloseUp(wxCommandEvent
& WXUNUSED(event
))
858 wxLogMessage(wxT("Combobox closed up"));
861 #endif //wxUSE_ODCOMBOBOX