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
7 // Copyright: (c) 2006 Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
28 // for all others, include the necessary headers
32 #include "wx/bitmap.h"
33 #include "wx/button.h"
34 #include "wx/checkbox.h"
35 #include "wx/combobox.h"
36 #include "wx/radiobox.h"
37 #include "wx/statbox.h"
38 #include "wx/textctrl.h"
42 #include "wx/dcmemory.h"
44 #include "wx/odcombo.h"
47 #include "itemcontainer.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
,
80 ODComboPage_ContainerTests
84 // ----------------------------------------------------------------------------
85 // ODComboboxWidgetsPage
86 // ----------------------------------------------------------------------------
88 class ODComboboxWidgetsPage
: public ItemContainerWidgetsPage
91 ODComboboxWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
93 virtual wxControl
*GetWidget() const { return m_combobox
; }
94 virtual wxTextEntryBase
*GetTextEntry() const
95 { return m_combobox
? m_combobox
->GetTextCtrl() : NULL
; }
96 virtual wxItemContainer
* GetContainer() const { return m_combobox
; }
97 virtual void RecreateWidget() { CreateCombo(); }
99 // lazy creation of the content
100 virtual void CreateContent();
104 void OnButtonReset(wxCommandEvent
& event
);
105 void OnButtonChange(wxCommandEvent
& event
);
106 void OnButtonDelete(wxCommandEvent
& event
);
107 void OnButtonDeleteSel(wxCommandEvent
& event
);
108 void OnButtonClear(wxCommandEvent
& event
);
109 void OnButtonInsert(wxCommandEvent
&event
);
110 void OnButtonAdd(wxCommandEvent
& event
);
111 void OnButtonAddSeveral(wxCommandEvent
& event
);
112 void OnButtonAddMany(wxCommandEvent
& event
);
114 void OnComboBox(wxCommandEvent
& event
);
115 void OnDropDown(wxCommandEvent
& event
);
116 void OnCloseUp(wxCommandEvent
& event
);
117 void OnComboText(wxCommandEvent
& event
);
119 void OnCheckOrRadioBox(wxCommandEvent
& event
);
121 void OnTextPopupWidth(wxCommandEvent
& event
);
122 void OnTextPopupHeight(wxCommandEvent
& event
);
123 void OnTextButtonAll(wxCommandEvent
& event
);
125 void OnUpdateUICurText(wxUpdateUIEvent
& event
);
126 void OnUpdateUIInsertionPointText(wxUpdateUIEvent
& event
);
128 void OnUpdateUIInsert(wxUpdateUIEvent
& event
);
129 void OnUpdateUIAddSeveral(wxUpdateUIEvent
& event
);
130 void OnUpdateUIClearButton(wxUpdateUIEvent
& event
);
131 void OnUpdateUIDeleteButton(wxUpdateUIEvent
& event
);
132 void OnUpdateUIDeleteSelButton(wxUpdateUIEvent
& event
);
133 void OnUpdateUIResetButton(wxUpdateUIEvent
& event
);
135 // reset the odcombobox parameters
138 // (re)create the odcombobox
141 // helper that gets all button values from controls and calls SetButtonPosition
142 void GetButtonPosition();
144 // helper to create the button bitmap
145 wxBitmap
CreateBitmap(const wxColour
& colour
);
150 // the checkboxes for styles
151 wxCheckBox
*m_chkSort
,
157 // the text entries for popup and button adjustment
158 wxTextCtrl
*m_textPopupMinWidth
,
162 *m_textButtonSpacing
;
164 // the checkboxes for same
165 wxCheckBox
*m_chkAlignpopupright
,
168 // the combobox itself and the sizer it is in
169 wxOwnerDrawnComboBox
*m_combobox
;
170 wxSizer
*m_sizerCombo
;
172 // the text entries for "Add/change string" and "Delete" buttons
173 wxTextCtrl
*m_textInsert
,
179 DECLARE_EVENT_TABLE()
180 DECLARE_WIDGETS_PAGE(ODComboboxWidgetsPage
)
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 BEGIN_EVENT_TABLE(ODComboboxWidgetsPage
, WidgetsPage
)
188 EVT_BUTTON(ODComboPage_Reset
, ODComboboxWidgetsPage::OnButtonReset
)
189 EVT_BUTTON(ODComboPage_Change
, ODComboboxWidgetsPage::OnButtonChange
)
190 EVT_BUTTON(ODComboPage_Delete
, ODComboboxWidgetsPage::OnButtonDelete
)
191 EVT_BUTTON(ODComboPage_DeleteSel
, ODComboboxWidgetsPage::OnButtonDeleteSel
)
192 EVT_BUTTON(ODComboPage_Clear
, ODComboboxWidgetsPage::OnButtonClear
)
193 EVT_BUTTON(ODComboPage_Insert
, ODComboboxWidgetsPage::OnButtonInsert
)
194 EVT_BUTTON(ODComboPage_Add
, ODComboboxWidgetsPage::OnButtonAdd
)
195 EVT_BUTTON(ODComboPage_AddSeveral
, ODComboboxWidgetsPage::OnButtonAddSeveral
)
196 EVT_BUTTON(ODComboPage_AddMany
, ODComboboxWidgetsPage::OnButtonAddMany
)
197 EVT_BUTTON(ODComboPage_ContainerTests
, ItemContainerWidgetsPage::OnButtonTestItemContainer
)
199 EVT_TEXT_ENTER(ODComboPage_InsertText
, ODComboboxWidgetsPage::OnButtonInsert
)
200 EVT_TEXT_ENTER(ODComboPage_AddText
, ODComboboxWidgetsPage::OnButtonAdd
)
201 EVT_TEXT_ENTER(ODComboPage_DeleteText
, ODComboboxWidgetsPage::OnButtonDelete
)
203 EVT_TEXT(ODComboPage_PopupMinWidth
, ODComboboxWidgetsPage::OnTextPopupWidth
)
204 EVT_TEXT(ODComboPage_PopupHeight
, ODComboboxWidgetsPage::OnTextPopupHeight
)
205 EVT_TEXT(ODComboPage_ButtonWidth
, ODComboboxWidgetsPage::OnTextButtonAll
)
206 EVT_TEXT(ODComboPage_ButtonHeight
, ODComboboxWidgetsPage::OnTextButtonAll
)
207 EVT_TEXT(ODComboPage_ButtonSpacing
, ODComboboxWidgetsPage::OnTextButtonAll
)
209 EVT_UPDATE_UI(ODComboPage_CurText
, ODComboboxWidgetsPage::OnUpdateUICurText
)
210 EVT_UPDATE_UI(ODComboPage_InsertionPointText
, ODComboboxWidgetsPage::OnUpdateUIInsertionPointText
)
212 EVT_UPDATE_UI(ODComboPage_Reset
, ODComboboxWidgetsPage::OnUpdateUIResetButton
)
213 EVT_UPDATE_UI(ODComboPage_Insert
, ODComboboxWidgetsPage::OnUpdateUIInsert
)
214 EVT_UPDATE_UI(ODComboPage_AddSeveral
, ODComboboxWidgetsPage::OnUpdateUIAddSeveral
)
215 EVT_UPDATE_UI(ODComboPage_Clear
, ODComboboxWidgetsPage::OnUpdateUIClearButton
)
216 EVT_UPDATE_UI(ODComboPage_DeleteText
, ODComboboxWidgetsPage::OnUpdateUIClearButton
)
217 EVT_UPDATE_UI(ODComboPage_Delete
, ODComboboxWidgetsPage::OnUpdateUIDeleteButton
)
218 EVT_UPDATE_UI(ODComboPage_Change
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
219 EVT_UPDATE_UI(ODComboPage_ChangeText
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
220 EVT_UPDATE_UI(ODComboPage_DeleteSel
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
222 EVT_COMBOBOX_DROPDOWN(ODComboPage_Combo
, ODComboboxWidgetsPage::OnDropDown
)
223 EVT_COMBOBOX_CLOSEUP(ODComboPage_Combo
, ODComboboxWidgetsPage::OnCloseUp
)
224 EVT_COMBOBOX(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboBox
)
225 EVT_TEXT(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboText
)
226 EVT_TEXT_ENTER(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboText
)
228 EVT_CHECKBOX(wxID_ANY
, ODComboboxWidgetsPage::OnCheckOrRadioBox
)
229 EVT_RADIOBOX(wxID_ANY
, ODComboboxWidgetsPage::OnCheckOrRadioBox
)
232 // ============================================================================
234 // ============================================================================
237 // wxOwnerDrawnComboBox needs to subclassed so that owner-drawing
238 // callbacks can be implemented.
239 class DemoODComboBox
: public wxOwnerDrawnComboBox
242 virtual void OnDrawItem(wxDC
& dc
,
245 int WXUNUSED(flags
)) const
247 if ( item
== wxNOT_FOUND
)
262 dc
.SetTextForeground(txtCol
);
264 dc
.DrawText(GetString(item
),
266 rect
.y
+ ((rect
.height
- dc
.GetCharHeight())/2)
270 virtual void OnDrawBackground(wxDC
& dc
, const wxRect
& rect
,
271 int item
, int flags
) const
274 // If item is selected or even, or we are painting the
275 // combo control itself, use the default rendering.
276 if ( (flags
& (wxODCB_PAINTING_CONTROL
|wxODCB_PAINTING_SELECTED
)) ||
279 wxOwnerDrawnComboBox::OnDrawBackground(dc
,rect
,item
,flags
);
283 // Otherwise, draw every other background with different colour.
284 wxColour
bgCol(240,240,250);
285 dc
.SetBrush(wxBrush(bgCol
));
286 dc
.SetPen(wxPen(bgCol
));
287 dc
.DrawRectangle(rect
);
290 virtual wxCoord
OnMeasureItem(size_t WXUNUSED(item
)) const
295 virtual wxCoord
OnMeasureItemWidth(size_t WXUNUSED(item
)) const
297 return -1; // default - will be measured from text width
302 IMPLEMENT_WIDGETS_PAGE(ODComboboxWidgetsPage
, wxT("OwnerDrawnCombobox"),
303 GENERIC_CTRLS
| WITH_ITEMS_CTRLS
| COMBO_CTRLS
306 ODComboboxWidgetsPage::ODComboboxWidgetsPage(WidgetsBookCtrl
*book
,
307 wxImageList
*imaglist
)
308 : ItemContainerWidgetsPage(book
, imaglist
, odcombobox_xpm
)
313 m_chkDclickcycles
= (wxCheckBox
*)NULL
;
315 m_combobox
= (wxOwnerDrawnComboBox
*)NULL
;
316 m_sizerCombo
= (wxSizer
*)NULL
;
319 void ODComboboxWidgetsPage::CreateContent()
322 What we create here is a frame having 3 panes: style pane is the
323 leftmost one, in the middle the pane with buttons allowing to perform
324 miscellaneous combobox operations and the pane containing the combobox
330 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
332 wxSizer
*sizerLeft
= new wxBoxSizer(wxVERTICAL
);
334 // left pane - style box
335 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, wxT("&Set style"));
337 wxSizer
*sizerStyle
= new wxStaticBoxSizer(box
, wxVERTICAL
);
339 m_chkSort
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Sort items"));
340 m_chkReadonly
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Read only"));
341 m_chkDclickcycles
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Double-click Cycles"));
343 sizerStyle
->AddSpacer(4);
345 m_chkBitmapbutton
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Bitmap button"));
346 m_chkStdbutton
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("B&lank button background"));
348 wxButton
*btn
= new wxButton(this, ODComboPage_Reset
, wxT("&Reset"));
349 sizerStyle
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 3);
351 sizerLeft
->Add(sizerStyle
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
);
353 // left pane - popup adjustment box
354 box
= new wxStaticBox(this, wxID_ANY
, wxT("Adjust &popup"));
356 wxSizer
*sizerPopupPos
= new wxStaticBoxSizer(box
, wxVERTICAL
);
358 sizerRow
= CreateSizerWithTextAndLabel(wxT("Min. Width:"),
359 ODComboPage_PopupMinWidth
,
360 &m_textPopupMinWidth
);
361 m_textPopupMinWidth
->SetValue(wxT("-1"));
362 sizerPopupPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
364 sizerRow
= CreateSizerWithTextAndLabel(wxT("Max. Height:"),
365 ODComboPage_PopupHeight
,
367 m_textPopupHeight
->SetValue(wxT("-1"));
368 sizerPopupPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
370 m_chkAlignpopupright
= CreateCheckBoxAndAddToSizer(sizerPopupPos
, wxT("Align Right"));
372 sizerLeft
->Add(sizerPopupPos
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
| wxTOP
, 2);
374 // left pane - button adjustment box
375 box
= new wxStaticBox(this, wxID_ANY
, wxT("Adjust &button"));
377 wxSizer
*sizerButtonPos
= new wxStaticBoxSizer(box
, wxVERTICAL
);
379 sizerRow
= CreateSizerWithTextAndLabel(wxT("Width:"),
380 ODComboPage_ButtonWidth
,
382 m_textButtonWidth
->SetValue(wxT("-1"));
383 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
385 sizerRow
= CreateSizerWithTextAndLabel(wxT("VSpacing:"),
386 ODComboPage_ButtonSpacing
,
387 &m_textButtonSpacing
);
388 m_textButtonSpacing
->SetValue(wxT("0"));
389 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
391 sizerRow
= CreateSizerWithTextAndLabel(wxT("Height:"),
392 ODComboPage_ButtonHeight
,
393 &m_textButtonHeight
);
394 m_textButtonHeight
->SetValue(wxT("-1"));
395 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
397 m_chkAlignbutleft
= CreateCheckBoxAndAddToSizer(sizerButtonPos
, wxT("Align Left"));
399 sizerLeft
->Add(sizerButtonPos
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
| wxTOP
, 2);
402 wxStaticBox
*box2
= new wxStaticBox(this, wxID_ANY
,
403 wxT("&Change combobox contents"));
404 wxSizer
*sizerMiddle
= new wxStaticBoxSizer(box2
, wxVERTICAL
);
406 btn
= new wxButton(this, ODComboPage_ContainerTests
, wxT("Run &tests"));
407 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
409 sizerRow
= CreateSizerWithTextAndLabel(wxT("Current selection"),
412 text
->SetEditable(false);
414 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
416 sizerRow
= CreateSizerWithTextAndLabel(wxT("Insertion Point"),
417 ODComboPage_InsertionPointText
,
419 text
->SetEditable(false);
421 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
423 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Insert
,
424 wxT("&Insert this string"),
425 ODComboPage_InsertText
,
427 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
429 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Add
,
430 wxT("&Add this string"),
433 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
435 btn
= new wxButton(this, ODComboPage_AddSeveral
, wxT("&Append a few strings"));
436 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
438 btn
= new wxButton(this, ODComboPage_AddMany
, wxT("Append &many strings"));
439 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
441 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Change
,
442 wxT("C&hange current"),
443 ODComboPage_ChangeText
,
445 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
447 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Delete
,
448 wxT("&Delete this item"),
449 ODComboPage_DeleteText
,
451 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
453 btn
= new wxButton(this, ODComboPage_DeleteSel
, wxT("Delete &selection"));
454 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
456 btn
= new wxButton(this, ODComboPage_Clear
, wxT("&Clear"));
457 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
460 wxSizer
*sizerRight
= new wxBoxSizer(wxVERTICAL
);
461 m_combobox
= new DemoODComboBox();
462 m_combobox
->Create(this, ODComboPage_Combo
, wxEmptyString
,
463 wxDefaultPosition
, wxDefaultSize
,
466 sizerRight
->Add(m_combobox
, 0, wxGROW
| wxALL
, 5);
467 sizerRight
->SetMinSize(150, 0);
468 m_sizerCombo
= sizerRight
; // save it to modify it later
470 // the 3 panes panes compose the window
471 sizerTop
->Add(sizerLeft
, 4, wxGROW
| (wxALL
& ~wxLEFT
), 10);
472 sizerTop
->Add(sizerMiddle
, 5, wxGROW
| wxALL
, 10);
473 sizerTop
->Add(sizerRight
, 4, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
475 // final initializations
481 // ----------------------------------------------------------------------------
483 // ----------------------------------------------------------------------------
485 void ODComboboxWidgetsPage::Reset()
487 m_chkSort
->SetValue(false);
488 m_chkReadonly
->SetValue(false);
489 m_chkDclickcycles
->SetValue(false);
490 m_chkDclickcycles
->Enable(false);
491 m_chkBitmapbutton
->SetValue(false);
492 m_chkStdbutton
->SetValue(false);
493 m_chkStdbutton
->Enable(false);
496 void ODComboboxWidgetsPage::CreateCombo()
498 int flags
= ms_defaultFlags
;
500 if ( m_chkSort
->GetValue() )
502 if ( m_chkReadonly
->GetValue() )
503 flags
|= wxCB_READONLY
;
504 if ( m_chkDclickcycles
->GetValue() )
505 flags
|= wxODCB_DCLICK_CYCLES
;
510 unsigned int count
= m_combobox
->GetCount();
511 for ( unsigned int n
= 0; n
< count
; n
++ )
513 items
.Add(m_combobox
->GetString(n
));
516 m_sizerCombo
->Detach( m_combobox
);
520 m_combobox
= new DemoODComboBox();
521 m_combobox
->Create(this, ODComboPage_Combo
, wxEmptyString
,
522 wxDefaultPosition
, wxDefaultSize
,
526 unsigned int count
= items
.GetCount();
527 for ( unsigned int n
= 0; n
< count
; n
++ )
529 m_combobox
->Append(items
[n
]);
532 // Update from controls that edit popup position etc.
534 wxUpdateUIEvent tempEvt
;
535 OnTextPopupWidth(tempEvt
);
536 OnTextPopupHeight(tempEvt
);
539 m_combobox
->SetPopupAnchor( m_chkAlignpopupright
->GetValue() ? wxRIGHT
: wxLEFT
);
541 if ( m_chkBitmapbutton
->GetValue() )
543 wxBitmap bmpNormal
= CreateBitmap(*wxBLUE
);
544 wxBitmap bmpPressed
= CreateBitmap(wxColour(0,0,128));
545 wxBitmap bmpHover
= CreateBitmap(wxColour(128,128,255));
546 m_combobox
->SetButtonBitmaps(bmpNormal
,m_chkStdbutton
->GetValue(),bmpPressed
,bmpHover
);
549 m_sizerCombo
->Add(m_combobox
, 0, wxGROW
| wxALL
, 5);
550 m_sizerCombo
->Layout();
553 // ----------------------------------------------------------------------------
555 // ----------------------------------------------------------------------------
557 void ODComboboxWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
564 void ODComboboxWidgetsPage::OnButtonChange(wxCommandEvent
& WXUNUSED(event
))
566 int sel
= m_combobox
->GetSelection();
567 if ( sel
!= wxNOT_FOUND
)
570 m_combobox
->SetString(sel
, m_textChange
->GetValue());
572 wxLogMessage(wxT("Not implemented in wxGTK"));
577 void ODComboboxWidgetsPage::OnButtonDelete(wxCommandEvent
& WXUNUSED(event
))
580 if ( !m_textDelete
->GetValue().ToULong(&n
) ||
581 (n
>= m_combobox
->GetCount()) )
586 m_combobox
->Delete(n
);
589 void ODComboboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent
& WXUNUSED(event
))
591 int sel
= m_combobox
->GetSelection();
592 if ( sel
!= wxNOT_FOUND
)
594 m_combobox
->Delete(sel
);
598 void ODComboboxWidgetsPage::OnButtonClear(wxCommandEvent
& WXUNUSED(event
))
603 void ODComboboxWidgetsPage::OnButtonInsert(wxCommandEvent
& WXUNUSED(event
))
605 static unsigned int s_item
= 0;
607 wxString s
= m_textInsert
->GetValue();
608 if ( !m_textInsert
->IsModified() )
610 // update the default string
611 m_textInsert
->SetValue(wxString::Format(wxT("test item %u"), ++s_item
));
614 if (m_combobox
->GetSelection() >= 0)
615 m_combobox
->Insert(s
, m_combobox
->GetSelection());
618 void ODComboboxWidgetsPage::OnButtonAdd(wxCommandEvent
& WXUNUSED(event
))
620 static unsigned int s_item
= 0;
622 wxString s
= m_textAdd
->GetValue();
623 if ( !m_textAdd
->IsModified() )
625 // update the default string
626 m_textAdd
->SetValue(wxString::Format(wxT("test item %u"), ++s_item
));
629 m_combobox
->Append(s
);
632 void ODComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent
& WXUNUSED(event
))
634 // "many" means 1000 here
635 for ( unsigned int n
= 0; n
< 1000; n
++ )
637 m_combobox
->Append(wxString::Format(wxT("item #%u"), n
));
641 void ODComboboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent
& WXUNUSED(event
))
643 m_combobox
->Append(wxT("First"));
644 m_combobox
->Append(wxT("another one"));
645 m_combobox
->Append(wxT("and the last (very very very very very very very very very very long) one"));
648 void ODComboboxWidgetsPage::OnTextPopupWidth(wxCommandEvent
& WXUNUSED(event
))
652 m_textPopupMinWidth
->GetValue().ToLong(&l
);
654 if (m_combobox
&& l
> 0)
656 m_combobox
->SetPopupMinWidth(l
);
660 void ODComboboxWidgetsPage::OnTextPopupHeight(wxCommandEvent
& WXUNUSED(event
))
664 m_textPopupHeight
->GetValue().ToLong(&l
);
666 if (m_combobox
&& l
> 0)
668 m_combobox
->SetPopupMaxHeight(l
);
672 void ODComboboxWidgetsPage::GetButtonPosition()
678 m_textButtonWidth
->GetValue().ToLong(&w
);
679 m_textButtonSpacing
->GetValue().ToLong(&spacing
);
680 m_textButtonHeight
->GetValue().ToLong(&h
);
681 int align
= m_chkAlignbutleft
->GetValue() ?
684 m_combobox
->SetButtonPosition(w
,h
,align
,spacing
);
687 void ODComboboxWidgetsPage::OnTextButtonAll(wxCommandEvent
& WXUNUSED(event
))
691 if ( m_chkBitmapbutton
->GetValue() )
698 void ODComboboxWidgetsPage::OnUpdateUICurText(wxUpdateUIEvent
& event
)
701 event
.SetText( wxString::Format(wxT("%d"), m_combobox
->GetSelection()) );
704 void ODComboboxWidgetsPage::OnUpdateUIInsertionPointText(wxUpdateUIEvent
& event
)
707 event
.SetText( wxString::Format(wxT("%ld"), m_combobox
->GetInsertionPoint()) );
710 void ODComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent
& event
)
713 event
.Enable( m_chkSort
->GetValue() || m_chkReadonly
->GetValue() ||
714 m_chkBitmapbutton
->GetValue() );
717 void ODComboboxWidgetsPage::OnUpdateUIInsert(wxUpdateUIEvent
& event
)
721 bool enable
= !(m_combobox
->GetWindowStyle() & wxCB_SORT
) &&
722 (m_combobox
->GetSelection() >= 0);
724 event
.Enable(enable
);
728 void ODComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent
& event
)
733 event
.Enable(m_textDelete
->GetValue().ToULong(&n
) &&
734 (n
< (unsigned)m_combobox
->GetCount()));
738 void ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent
& event
)
741 event
.Enable(m_combobox
->GetSelection() != wxNOT_FOUND
);
744 void ODComboboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent
& event
)
747 event
.Enable(m_combobox
->GetCount() != 0);
750 void ODComboboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent
& event
)
753 event
.Enable(!(m_combobox
->GetWindowStyle() & wxCB_SORT
));
756 void ODComboboxWidgetsPage::OnComboText(wxCommandEvent
& event
)
761 wxString s
= event
.GetString();
763 wxASSERT_MSG( s
== m_combobox
->GetValue(),
764 wxT("event and combobox values should be the same") );
766 if (event
.GetEventType() == wxEVT_TEXT_ENTER
)
768 wxLogMessage(wxT("OwnerDrawnCombobox enter pressed (now '%s')"), s
.c_str());
772 wxLogMessage(wxT("OwnerDrawnCombobox text changed (now '%s')"), s
.c_str());
776 void ODComboboxWidgetsPage::OnComboBox(wxCommandEvent
& event
)
778 long sel
= event
.GetInt();
779 m_textDelete
->SetValue(wxString::Format(wxT("%ld"), sel
));
781 wxLogMessage(wxT("OwnerDrawnCombobox item %ld selected"), sel
);
783 wxLogMessage(wxT("OwnerDrawnCombobox GetValue(): %s"), m_combobox
->GetValue().c_str() );
786 void ODComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent
& event
)
788 wxObject
* ctrl
= event
.GetEventObject();
790 // Double-click cycles only applies to read-only combobox
791 if ( ctrl
== (wxObject
*) m_chkReadonly
)
793 m_chkDclickcycles
->Enable( m_chkReadonly
->GetValue() );
795 else if ( ctrl
== (wxObject
*) m_chkBitmapbutton
)
797 m_chkStdbutton
->Enable( m_chkBitmapbutton
->GetValue() );
799 else if ( ctrl
== (wxObject
*) m_chkAlignbutleft
)
801 wxUpdateUIEvent tempEvt
;
802 OnTextButtonAll(tempEvt
);
808 wxBitmap
ODComboboxWidgetsPage::CreateBitmap(const wxColour
& colour
)
810 int ch
= m_combobox
->GetClientSize().y
- 1;
816 m_textButtonWidth
->GetValue().ToLong(&w
);
817 m_textButtonHeight
->GetValue().ToLong(&h
);
828 dc
.SelectObject(bmp
);
830 // Draw transparent background
831 wxColour
magic(255,0,255);
832 wxBrush
magicBrush(magic
);
833 dc
.SetBrush(magicBrush
);
834 dc
.SetPen(*wxTRANSPARENT_PEN
);
835 dc
.DrawRectangle(0,0,bmp
.GetWidth(),bmp
.GetHeight());
837 // Draw image content
838 dc
.SetBrush(wxBrush(colour
));
839 dc
.DrawCircle(h
/2,h
/2+1,(h
/2));
841 dc
.SelectObject(wxNullBitmap
);
843 // Finalize transparency with a mask
844 wxMask
*mask
= new wxMask(bmp
, magic
);
850 void ODComboboxWidgetsPage::OnDropDown(wxCommandEvent
& WXUNUSED(event
))
852 wxLogMessage(wxT("Combobox dropped down"));
855 void ODComboboxWidgetsPage::OnCloseUp(wxCommandEvent
& WXUNUSED(event
))
857 wxLogMessage(wxT("Combobox closed up"));
860 #endif //wxUSE_ODCOMBOBOX