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"
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 OnComboText(wxCommandEvent
& event
);
118 void OnCheckOrRadioBox(wxCommandEvent
& event
);
120 void OnTextPopupWidth(wxCommandEvent
& event
);
121 void OnTextPopupHeight(wxCommandEvent
& event
);
122 void OnTextButtonAll(wxCommandEvent
& event
);
124 void OnUpdateUICurText(wxUpdateUIEvent
& event
);
125 void OnUpdateUIInsertionPointText(wxUpdateUIEvent
& event
);
127 void OnUpdateUIInsert(wxUpdateUIEvent
& event
);
128 void OnUpdateUIAddSeveral(wxUpdateUIEvent
& event
);
129 void OnUpdateUIClearButton(wxUpdateUIEvent
& event
);
130 void OnUpdateUIDeleteButton(wxUpdateUIEvent
& event
);
131 void OnUpdateUIDeleteSelButton(wxUpdateUIEvent
& event
);
132 void OnUpdateUIResetButton(wxUpdateUIEvent
& event
);
134 // reset the odcombobox parameters
137 // (re)create the odcombobox
140 // helper that gets all button values from controls and calls SetButtonPosition
141 void GetButtonPosition();
143 // helper to create the button bitmap
144 wxBitmap
CreateBitmap(const wxColour
& colour
);
149 // the checkboxes for styles
150 wxCheckBox
*m_chkSort
,
156 // the text entries for popup and button adjustment
157 wxTextCtrl
*m_textPopupMinWidth
,
161 *m_textButtonSpacing
;
163 // the checkboxes for same
164 wxCheckBox
*m_chkAlignpopupright
,
167 // the combobox itself and the sizer it is in
168 wxOwnerDrawnComboBox
*m_combobox
;
169 wxSizer
*m_sizerCombo
;
171 // the text entries for "Add/change string" and "Delete" buttons
172 wxTextCtrl
*m_textInsert
,
178 DECLARE_EVENT_TABLE()
179 DECLARE_WIDGETS_PAGE(ODComboboxWidgetsPage
)
182 // ----------------------------------------------------------------------------
184 // ----------------------------------------------------------------------------
186 BEGIN_EVENT_TABLE(ODComboboxWidgetsPage
, WidgetsPage
)
187 EVT_BUTTON(ODComboPage_Reset
, ODComboboxWidgetsPage::OnButtonReset
)
188 EVT_BUTTON(ODComboPage_Change
, ODComboboxWidgetsPage::OnButtonChange
)
189 EVT_BUTTON(ODComboPage_Delete
, ODComboboxWidgetsPage::OnButtonDelete
)
190 EVT_BUTTON(ODComboPage_DeleteSel
, ODComboboxWidgetsPage::OnButtonDeleteSel
)
191 EVT_BUTTON(ODComboPage_Clear
, ODComboboxWidgetsPage::OnButtonClear
)
192 EVT_BUTTON(ODComboPage_Insert
, ODComboboxWidgetsPage::OnButtonInsert
)
193 EVT_BUTTON(ODComboPage_Add
, ODComboboxWidgetsPage::OnButtonAdd
)
194 EVT_BUTTON(ODComboPage_AddSeveral
, ODComboboxWidgetsPage::OnButtonAddSeveral
)
195 EVT_BUTTON(ODComboPage_AddMany
, ODComboboxWidgetsPage::OnButtonAddMany
)
196 EVT_BUTTON(ODComboPage_ContainerTests
, ItemContainerWidgetsPage::OnButtonTestItemContainer
)
198 EVT_TEXT_ENTER(ODComboPage_InsertText
, ODComboboxWidgetsPage::OnButtonInsert
)
199 EVT_TEXT_ENTER(ODComboPage_AddText
, ODComboboxWidgetsPage::OnButtonAdd
)
200 EVT_TEXT_ENTER(ODComboPage_DeleteText
, ODComboboxWidgetsPage::OnButtonDelete
)
202 EVT_TEXT(ODComboPage_PopupMinWidth
, ODComboboxWidgetsPage::OnTextPopupWidth
)
203 EVT_TEXT(ODComboPage_PopupHeight
, ODComboboxWidgetsPage::OnTextPopupHeight
)
204 EVT_TEXT(ODComboPage_ButtonWidth
, ODComboboxWidgetsPage::OnTextButtonAll
)
205 EVT_TEXT(ODComboPage_ButtonHeight
, ODComboboxWidgetsPage::OnTextButtonAll
)
206 EVT_TEXT(ODComboPage_ButtonSpacing
, ODComboboxWidgetsPage::OnTextButtonAll
)
208 EVT_UPDATE_UI(ODComboPage_CurText
, ODComboboxWidgetsPage::OnUpdateUICurText
)
209 EVT_UPDATE_UI(ODComboPage_InsertionPointText
, ODComboboxWidgetsPage::OnUpdateUIInsertionPointText
)
211 EVT_UPDATE_UI(ODComboPage_Reset
, ODComboboxWidgetsPage::OnUpdateUIResetButton
)
212 EVT_UPDATE_UI(ODComboPage_Insert
, ODComboboxWidgetsPage::OnUpdateUIInsert
)
213 EVT_UPDATE_UI(ODComboPage_AddSeveral
, ODComboboxWidgetsPage::OnUpdateUIAddSeveral
)
214 EVT_UPDATE_UI(ODComboPage_Clear
, ODComboboxWidgetsPage::OnUpdateUIClearButton
)
215 EVT_UPDATE_UI(ODComboPage_DeleteText
, ODComboboxWidgetsPage::OnUpdateUIClearButton
)
216 EVT_UPDATE_UI(ODComboPage_Delete
, ODComboboxWidgetsPage::OnUpdateUIDeleteButton
)
217 EVT_UPDATE_UI(ODComboPage_Change
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
218 EVT_UPDATE_UI(ODComboPage_ChangeText
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
219 EVT_UPDATE_UI(ODComboPage_DeleteSel
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
221 EVT_COMBOBOX(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboBox
)
222 EVT_TEXT(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboText
)
223 EVT_TEXT_ENTER(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboText
)
225 EVT_CHECKBOX(wxID_ANY
, ODComboboxWidgetsPage::OnCheckOrRadioBox
)
226 EVT_RADIOBOX(wxID_ANY
, ODComboboxWidgetsPage::OnCheckOrRadioBox
)
229 // ============================================================================
231 // ============================================================================
234 // wxOwnerDrawnComboBox needs to subclassed so that owner-drawing
235 // callbacks can be implemented.
236 class DemoODComboBox
: public wxOwnerDrawnComboBox
239 virtual void OnDrawItem(wxDC
& dc
,
242 int WXUNUSED(flags
)) const
244 if ( item
== wxNOT_FOUND
)
259 dc
.SetTextForeground(txtCol
);
261 dc
.DrawText(GetString(item
),
263 rect
.y
+ ((rect
.height
- dc
.GetCharHeight())/2)
267 virtual void OnDrawBackground(wxDC
& dc
, const wxRect
& rect
,
268 int item
, int flags
) const
271 // If item is selected or even, or we are painting the
272 // combo control itself, use the default rendering.
273 if ( (flags
& (wxODCB_PAINTING_CONTROL
|wxODCB_PAINTING_SELECTED
)) ||
276 wxOwnerDrawnComboBox::OnDrawBackground(dc
,rect
,item
,flags
);
280 // Otherwise, draw every other background with different colour.
281 wxColour
bgCol(240,240,250);
282 dc
.SetBrush(wxBrush(bgCol
));
283 dc
.SetPen(wxPen(bgCol
));
284 dc
.DrawRectangle(rect
);
287 virtual wxCoord
OnMeasureItem(size_t WXUNUSED(item
)) const
292 virtual wxCoord
OnMeasureItemWidth(size_t WXUNUSED(item
)) const
294 return -1; // default - will be measured from text width
299 IMPLEMENT_WIDGETS_PAGE(ODComboboxWidgetsPage
, wxT("OwnerDrawnCombobox"),
300 GENERIC_CTRLS
| WITH_ITEMS_CTRLS
| COMBO_CTRLS
303 ODComboboxWidgetsPage::ODComboboxWidgetsPage(WidgetsBookCtrl
*book
,
304 wxImageList
*imaglist
)
305 : ItemContainerWidgetsPage(book
, imaglist
, odcombobox_xpm
)
310 m_chkDclickcycles
= (wxCheckBox
*)NULL
;
312 m_combobox
= (wxOwnerDrawnComboBox
*)NULL
;
313 m_sizerCombo
= (wxSizer
*)NULL
;
316 void ODComboboxWidgetsPage::CreateContent()
319 What we create here is a frame having 3 panes: style pane is the
320 leftmost one, in the middle the pane with buttons allowing to perform
321 miscellaneous combobox operations and the pane containing the combobox
327 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
329 wxSizer
*sizerLeft
= new wxBoxSizer(wxVERTICAL
);
331 // left pane - style box
332 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, wxT("&Set style"));
334 wxSizer
*sizerStyle
= new wxStaticBoxSizer(box
, wxVERTICAL
);
336 m_chkSort
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Sort items"));
337 m_chkReadonly
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Read only"));
338 m_chkDclickcycles
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Double-click Cycles"));
340 sizerStyle
->AddSpacer(4);
342 m_chkBitmapbutton
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("&Bitmap button"));
343 m_chkStdbutton
= CreateCheckBoxAndAddToSizer(sizerStyle
, wxT("B&lank button background"));
345 wxButton
*btn
= new wxButton(this, ODComboPage_Reset
, wxT("&Reset"));
346 sizerStyle
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 3);
348 sizerLeft
->Add(sizerStyle
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
);
350 // left pane - popup adjustment box
351 box
= new wxStaticBox(this, wxID_ANY
, wxT("Adjust &popup"));
353 wxSizer
*sizerPopupPos
= new wxStaticBoxSizer(box
, wxVERTICAL
);
355 sizerRow
= CreateSizerWithTextAndLabel(wxT("Min. Width:"),
356 ODComboPage_PopupMinWidth
,
357 &m_textPopupMinWidth
);
358 m_textPopupMinWidth
->SetValue(wxT("-1"));
359 sizerPopupPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
361 sizerRow
= CreateSizerWithTextAndLabel(wxT("Max. Height:"),
362 ODComboPage_PopupHeight
,
364 m_textPopupHeight
->SetValue(wxT("-1"));
365 sizerPopupPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
367 m_chkAlignpopupright
= CreateCheckBoxAndAddToSizer(sizerPopupPos
, wxT("Align Right"));
369 sizerLeft
->Add(sizerPopupPos
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
| wxTOP
, 2);
371 // left pane - button adjustment box
372 box
= new wxStaticBox(this, wxID_ANY
, wxT("Adjust &button"));
374 wxSizer
*sizerButtonPos
= new wxStaticBoxSizer(box
, wxVERTICAL
);
376 sizerRow
= CreateSizerWithTextAndLabel(wxT("Width:"),
377 ODComboPage_ButtonWidth
,
379 m_textButtonWidth
->SetValue(wxT("-1"));
380 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
382 sizerRow
= CreateSizerWithTextAndLabel(wxT("VSpacing:"),
383 ODComboPage_ButtonSpacing
,
384 &m_textButtonSpacing
);
385 m_textButtonSpacing
->SetValue(wxT("0"));
386 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
388 sizerRow
= CreateSizerWithTextAndLabel(wxT("Height:"),
389 ODComboPage_ButtonHeight
,
390 &m_textButtonHeight
);
391 m_textButtonHeight
->SetValue(wxT("-1"));
392 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
394 m_chkAlignbutleft
= CreateCheckBoxAndAddToSizer(sizerButtonPos
, wxT("Align Left"));
396 sizerLeft
->Add(sizerButtonPos
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
| wxTOP
, 2);
399 wxStaticBox
*box2
= new wxStaticBox(this, wxID_ANY
,
400 wxT("&Change combobox contents"));
401 wxSizer
*sizerMiddle
= new wxStaticBoxSizer(box2
, wxVERTICAL
);
403 btn
= new wxButton(this, ODComboPage_ContainerTests
, wxT("Run &tests"));
404 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
406 sizerRow
= CreateSizerWithTextAndLabel(wxT("Current selection"),
409 text
->SetEditable(false);
411 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
413 sizerRow
= CreateSizerWithTextAndLabel(wxT("Insertion Point"),
414 ODComboPage_InsertionPointText
,
416 text
->SetEditable(false);
418 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
420 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Insert
,
421 wxT("&Insert this string"),
422 ODComboPage_InsertText
,
424 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
426 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Add
,
427 wxT("&Add this string"),
430 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
432 btn
= new wxButton(this, ODComboPage_AddSeveral
, wxT("&Append a few strings"));
433 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
435 btn
= new wxButton(this, ODComboPage_AddMany
, wxT("Append &many strings"));
436 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
438 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Change
,
439 wxT("C&hange current"),
440 ODComboPage_ChangeText
,
442 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
444 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Delete
,
445 wxT("&Delete this item"),
446 ODComboPage_DeleteText
,
448 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
450 btn
= new wxButton(this, ODComboPage_DeleteSel
, wxT("Delete &selection"));
451 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
453 btn
= new wxButton(this, ODComboPage_Clear
, wxT("&Clear"));
454 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
457 wxSizer
*sizerRight
= new wxBoxSizer(wxVERTICAL
);
458 m_combobox
= new DemoODComboBox();
459 m_combobox
->Create(this, ODComboPage_Combo
, wxEmptyString
,
460 wxDefaultPosition
, wxDefaultSize
,
463 sizerRight
->Add(m_combobox
, 0, wxGROW
| wxALL
, 5);
464 sizerRight
->SetMinSize(150, 0);
465 m_sizerCombo
= sizerRight
; // save it to modify it later
467 // the 3 panes panes compose the window
468 sizerTop
->Add(sizerLeft
, 4, wxGROW
| (wxALL
& ~wxLEFT
), 10);
469 sizerTop
->Add(sizerMiddle
, 5, wxGROW
| wxALL
, 10);
470 sizerTop
->Add(sizerRight
, 4, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
472 // final initializations
478 // ----------------------------------------------------------------------------
480 // ----------------------------------------------------------------------------
482 void ODComboboxWidgetsPage::Reset()
484 m_chkSort
->SetValue(false);
485 m_chkReadonly
->SetValue(false);
486 m_chkDclickcycles
->SetValue(false);
487 m_chkDclickcycles
->Enable(false);
488 m_chkBitmapbutton
->SetValue(false);
489 m_chkStdbutton
->SetValue(false);
490 m_chkStdbutton
->Enable(false);
493 void ODComboboxWidgetsPage::CreateCombo()
495 int flags
= ms_defaultFlags
;
497 if ( m_chkSort
->GetValue() )
499 if ( m_chkReadonly
->GetValue() )
500 flags
|= wxCB_READONLY
;
501 if ( m_chkDclickcycles
->GetValue() )
502 flags
|= wxODCB_DCLICK_CYCLES
;
507 unsigned int count
= m_combobox
->GetCount();
508 for ( unsigned int n
= 0; n
< count
; n
++ )
510 items
.Add(m_combobox
->GetString(n
));
513 m_sizerCombo
->Detach( m_combobox
);
517 m_combobox
= new DemoODComboBox();
518 m_combobox
->Create(this, ODComboPage_Combo
, wxEmptyString
,
519 wxDefaultPosition
, wxDefaultSize
,
523 unsigned int count
= items
.GetCount();
524 for ( unsigned int n
= 0; n
< count
; n
++ )
526 m_combobox
->Append(items
[n
]);
529 // Update from controls that edit popup position etc.
531 wxUpdateUIEvent tempEvt
;
532 OnTextPopupWidth(tempEvt
);
533 OnTextPopupHeight(tempEvt
);
536 m_combobox
->SetPopupAnchor( m_chkAlignpopupright
->GetValue() ? wxRIGHT
: wxLEFT
);
538 if ( m_chkBitmapbutton
->GetValue() )
540 wxBitmap bmpNormal
= CreateBitmap(wxColour(0,0,255));
541 wxBitmap bmpPressed
= CreateBitmap(wxColour(0,0,128));
542 wxBitmap bmpHover
= CreateBitmap(wxColour(128,128,255));
543 m_combobox
->SetButtonBitmaps(bmpNormal
,m_chkStdbutton
->GetValue(),bmpPressed
,bmpHover
);
546 m_sizerCombo
->Add(m_combobox
, 0, wxGROW
| wxALL
, 5);
547 m_sizerCombo
->Layout();
550 // ----------------------------------------------------------------------------
552 // ----------------------------------------------------------------------------
554 void ODComboboxWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
561 void ODComboboxWidgetsPage::OnButtonChange(wxCommandEvent
& WXUNUSED(event
))
563 int sel
= m_combobox
->GetSelection();
564 if ( sel
!= wxNOT_FOUND
)
567 m_combobox
->SetString(sel
, m_textChange
->GetValue());
569 wxLogMessage(wxT("Not implemented in wxGTK"));
574 void ODComboboxWidgetsPage::OnButtonDelete(wxCommandEvent
& WXUNUSED(event
))
577 if ( !m_textDelete
->GetValue().ToULong(&n
) ||
578 (n
>= m_combobox
->GetCount()) )
583 m_combobox
->Delete(n
);
586 void ODComboboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent
& WXUNUSED(event
))
588 int sel
= m_combobox
->GetSelection();
589 if ( sel
!= wxNOT_FOUND
)
591 m_combobox
->Delete(sel
);
595 void ODComboboxWidgetsPage::OnButtonClear(wxCommandEvent
& WXUNUSED(event
))
600 void ODComboboxWidgetsPage::OnButtonInsert(wxCommandEvent
& WXUNUSED(event
))
602 static unsigned int s_item
= 0;
604 wxString s
= m_textInsert
->GetValue();
605 if ( !m_textInsert
->IsModified() )
607 // update the default string
608 m_textInsert
->SetValue(wxString::Format(wxT("test item %u"), ++s_item
));
611 if (m_combobox
->GetSelection() >= 0)
612 m_combobox
->Insert(s
, m_combobox
->GetSelection());
615 void ODComboboxWidgetsPage::OnButtonAdd(wxCommandEvent
& WXUNUSED(event
))
617 static unsigned int s_item
= 0;
619 wxString s
= m_textAdd
->GetValue();
620 if ( !m_textAdd
->IsModified() )
622 // update the default string
623 m_textAdd
->SetValue(wxString::Format(wxT("test item %u"), ++s_item
));
626 m_combobox
->Append(s
);
629 void ODComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent
& WXUNUSED(event
))
631 // "many" means 1000 here
632 for ( unsigned int n
= 0; n
< 1000; n
++ )
634 m_combobox
->Append(wxString::Format(wxT("item #%u"), n
));
638 void ODComboboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent
& WXUNUSED(event
))
640 m_combobox
->Append(wxT("First"));
641 m_combobox
->Append(wxT("another one"));
642 m_combobox
->Append(wxT("and the last (very very very very very very very very very very long) one"));
645 void ODComboboxWidgetsPage::OnTextPopupWidth(wxCommandEvent
& WXUNUSED(event
))
649 m_textPopupMinWidth
->GetValue().ToLong(&l
);
651 if (m_combobox
&& l
> 0)
653 m_combobox
->SetPopupMinWidth(l
);
657 void ODComboboxWidgetsPage::OnTextPopupHeight(wxCommandEvent
& WXUNUSED(event
))
661 m_textPopupHeight
->GetValue().ToLong(&l
);
663 if (m_combobox
&& l
> 0)
665 m_combobox
->SetPopupMaxHeight(l
);
669 void ODComboboxWidgetsPage::GetButtonPosition()
675 m_textButtonWidth
->GetValue().ToLong(&w
);
676 m_textButtonSpacing
->GetValue().ToLong(&spacing
);
677 m_textButtonHeight
->GetValue().ToLong(&h
);
678 int align
= m_chkAlignbutleft
->GetValue() ?
681 m_combobox
->SetButtonPosition(w
,h
,align
,spacing
);
684 void ODComboboxWidgetsPage::OnTextButtonAll(wxCommandEvent
& WXUNUSED(event
))
688 if ( m_chkBitmapbutton
->GetValue() )
695 void ODComboboxWidgetsPage::OnUpdateUICurText(wxUpdateUIEvent
& event
)
698 event
.SetText( wxString::Format(wxT("%d"), m_combobox
->GetSelection()) );
701 void ODComboboxWidgetsPage::OnUpdateUIInsertionPointText(wxUpdateUIEvent
& event
)
704 event
.SetText( wxString::Format(wxT("%ld"), m_combobox
->GetInsertionPoint()) );
707 void ODComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent
& event
)
710 event
.Enable( m_chkSort
->GetValue() || m_chkReadonly
->GetValue() ||
711 m_chkBitmapbutton
->GetValue() );
714 void ODComboboxWidgetsPage::OnUpdateUIInsert(wxUpdateUIEvent
& event
)
718 bool enable
= !(m_combobox
->GetWindowStyle() & wxCB_SORT
) &&
719 (m_combobox
->GetSelection() >= 0);
721 event
.Enable(enable
);
725 void ODComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent
& event
)
730 event
.Enable(m_textDelete
->GetValue().ToULong(&n
) &&
731 (n
< (unsigned)m_combobox
->GetCount()));
735 void ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent
& event
)
738 event
.Enable(m_combobox
->GetSelection() != wxNOT_FOUND
);
741 void ODComboboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent
& event
)
744 event
.Enable(m_combobox
->GetCount() != 0);
747 void ODComboboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent
& event
)
750 event
.Enable(!(m_combobox
->GetWindowStyle() & wxCB_SORT
));
753 void ODComboboxWidgetsPage::OnComboText(wxCommandEvent
& event
)
758 wxString s
= event
.GetString();
760 wxASSERT_MSG( s
== m_combobox
->GetValue(),
761 wxT("event and combobox values should be the same") );
763 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
765 wxLogMessage(wxT("OwnerDrawnCombobox enter pressed (now '%s')"), s
.c_str());
769 wxLogMessage(wxT("OwnerDrawnCombobox text changed (now '%s')"), s
.c_str());
773 void ODComboboxWidgetsPage::OnComboBox(wxCommandEvent
& event
)
775 long sel
= event
.GetInt();
776 m_textDelete
->SetValue(wxString::Format(wxT("%ld"), sel
));
778 wxLogMessage(wxT("OwnerDrawnCombobox item %ld selected"), sel
);
780 wxLogMessage(wxT("OwnerDrawnCombobox GetValue(): %s"), m_combobox
->GetValue().c_str() );
783 void ODComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent
& event
)
785 wxObject
* ctrl
= event
.GetEventObject();
787 // Double-click cycles only applies to read-only combobox
788 if ( ctrl
== (wxObject
*) m_chkReadonly
)
790 m_chkDclickcycles
->Enable( m_chkReadonly
->GetValue() );
792 else if ( ctrl
== (wxObject
*) m_chkBitmapbutton
)
794 m_chkStdbutton
->Enable( m_chkBitmapbutton
->GetValue() );
796 else if ( ctrl
== (wxObject
*) m_chkAlignbutleft
)
798 wxUpdateUIEvent tempEvt
;
799 OnTextButtonAll(tempEvt
);
805 wxBitmap
ODComboboxWidgetsPage::CreateBitmap(const wxColour
& colour
)
807 int ch
= m_combobox
->GetClientSize().y
- 1;
813 m_textButtonWidth
->GetValue().ToLong(&w
);
814 m_textButtonHeight
->GetValue().ToLong(&h
);
825 dc
.SelectObject(bmp
);
827 // Draw transparent background
828 wxColour
magic(255,0,255);
829 wxBrush
magicBrush(magic
);
830 dc
.SetBrush(magicBrush
);
831 dc
.SetPen(*wxTRANSPARENT_PEN
);
832 dc
.DrawRectangle(0,0,bmp
.GetWidth(),bmp
.GetHeight());
834 // Draw image content
835 dc
.SetBrush(wxBrush(colour
));
836 dc
.DrawCircle(h
/2,h
/2+1,(h
/2));
838 dc
.SelectObject(wxNullBitmap
);
840 // Finalize transparency with a mask
841 wxMask
*mask
= new wxMask(bmp
, magic
);
847 #endif //wxUSE_ODCOMBOBOX