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 wxItemContainer
* GetContainer() const { return m_combobox
; }
96 virtual void RecreateWidget() { CreateCombo(); }
98 // lazy creation of the content
99 virtual void CreateContent();
103 void OnButtonReset(wxCommandEvent
& event
);
104 void OnButtonChange(wxCommandEvent
& event
);
105 void OnButtonDelete(wxCommandEvent
& event
);
106 void OnButtonDeleteSel(wxCommandEvent
& event
);
107 void OnButtonClear(wxCommandEvent
& event
);
108 void OnButtonInsert(wxCommandEvent
&event
);
109 void OnButtonAdd(wxCommandEvent
& event
);
110 void OnButtonAddSeveral(wxCommandEvent
& event
);
111 void OnButtonAddMany(wxCommandEvent
& event
);
113 void OnComboBox(wxCommandEvent
& event
);
114 void OnComboText(wxCommandEvent
& event
);
116 void OnCheckOrRadioBox(wxCommandEvent
& event
);
118 void OnTextPopupWidth(wxCommandEvent
& event
);
119 void OnTextPopupHeight(wxCommandEvent
& event
);
120 void OnTextButtonAll(wxCommandEvent
& event
);
122 void OnUpdateUICurText(wxUpdateUIEvent
& event
);
123 void OnUpdateUIInsertionPointText(wxUpdateUIEvent
& event
);
125 void OnUpdateUIInsert(wxUpdateUIEvent
& event
);
126 void OnUpdateUIAddSeveral(wxUpdateUIEvent
& event
);
127 void OnUpdateUIClearButton(wxUpdateUIEvent
& event
);
128 void OnUpdateUIDeleteButton(wxUpdateUIEvent
& event
);
129 void OnUpdateUIDeleteSelButton(wxUpdateUIEvent
& event
);
130 void OnUpdateUIResetButton(wxUpdateUIEvent
& event
);
132 // reset the odcombobox parameters
135 // (re)create the odcombobox
138 // helper that gets all button values from controls and calls SetButtonPosition
139 void GetButtonPosition();
141 // helper to create the button bitmap
142 wxBitmap
CreateBitmap(const wxColour
& colour
);
147 // the checkboxes for styles
148 wxCheckBox
*m_chkSort
,
154 // the text entries for popup and button adjustment
155 wxTextCtrl
*m_textPopupMinWidth
,
159 *m_textButtonSpacing
;
161 // the checkboxes for same
162 wxCheckBox
*m_chkAlignpopupright
,
165 // the combobox itself and the sizer it is in
166 wxOwnerDrawnComboBox
*m_combobox
;
167 wxSizer
*m_sizerCombo
;
169 // the text entries for "Add/change string" and "Delete" buttons
170 wxTextCtrl
*m_textInsert
,
176 DECLARE_EVENT_TABLE()
177 DECLARE_WIDGETS_PAGE(ODComboboxWidgetsPage
)
180 // ----------------------------------------------------------------------------
182 // ----------------------------------------------------------------------------
184 BEGIN_EVENT_TABLE(ODComboboxWidgetsPage
, WidgetsPage
)
185 EVT_BUTTON(ODComboPage_Reset
, ODComboboxWidgetsPage::OnButtonReset
)
186 EVT_BUTTON(ODComboPage_Change
, ODComboboxWidgetsPage::OnButtonChange
)
187 EVT_BUTTON(ODComboPage_Delete
, ODComboboxWidgetsPage::OnButtonDelete
)
188 EVT_BUTTON(ODComboPage_DeleteSel
, ODComboboxWidgetsPage::OnButtonDeleteSel
)
189 EVT_BUTTON(ODComboPage_Clear
, ODComboboxWidgetsPage::OnButtonClear
)
190 EVT_BUTTON(ODComboPage_Insert
, ODComboboxWidgetsPage::OnButtonInsert
)
191 EVT_BUTTON(ODComboPage_Add
, ODComboboxWidgetsPage::OnButtonAdd
)
192 EVT_BUTTON(ODComboPage_AddSeveral
, ODComboboxWidgetsPage::OnButtonAddSeveral
)
193 EVT_BUTTON(ODComboPage_AddMany
, ODComboboxWidgetsPage::OnButtonAddMany
)
194 EVT_BUTTON(ODComboPage_ContainerTests
, ItemContainerWidgetsPage::OnButtonTestItemContainer
)
196 EVT_TEXT_ENTER(ODComboPage_InsertText
, ODComboboxWidgetsPage::OnButtonInsert
)
197 EVT_TEXT_ENTER(ODComboPage_AddText
, ODComboboxWidgetsPage::OnButtonAdd
)
198 EVT_TEXT_ENTER(ODComboPage_DeleteText
, ODComboboxWidgetsPage::OnButtonDelete
)
200 EVT_TEXT(ODComboPage_PopupMinWidth
, ODComboboxWidgetsPage::OnTextPopupWidth
)
201 EVT_TEXT(ODComboPage_PopupHeight
, ODComboboxWidgetsPage::OnTextPopupHeight
)
202 EVT_TEXT(ODComboPage_ButtonWidth
, ODComboboxWidgetsPage::OnTextButtonAll
)
203 EVT_TEXT(ODComboPage_ButtonHeight
, ODComboboxWidgetsPage::OnTextButtonAll
)
204 EVT_TEXT(ODComboPage_ButtonSpacing
, ODComboboxWidgetsPage::OnTextButtonAll
)
206 EVT_UPDATE_UI(ODComboPage_CurText
, ODComboboxWidgetsPage::OnUpdateUICurText
)
207 EVT_UPDATE_UI(ODComboPage_InsertionPointText
, ODComboboxWidgetsPage::OnUpdateUIInsertionPointText
)
209 EVT_UPDATE_UI(ODComboPage_Reset
, ODComboboxWidgetsPage::OnUpdateUIResetButton
)
210 EVT_UPDATE_UI(ODComboPage_Insert
, ODComboboxWidgetsPage::OnUpdateUIInsert
)
211 EVT_UPDATE_UI(ODComboPage_AddSeveral
, ODComboboxWidgetsPage::OnUpdateUIAddSeveral
)
212 EVT_UPDATE_UI(ODComboPage_Clear
, ODComboboxWidgetsPage::OnUpdateUIClearButton
)
213 EVT_UPDATE_UI(ODComboPage_DeleteText
, ODComboboxWidgetsPage::OnUpdateUIClearButton
)
214 EVT_UPDATE_UI(ODComboPage_Delete
, ODComboboxWidgetsPage::OnUpdateUIDeleteButton
)
215 EVT_UPDATE_UI(ODComboPage_Change
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
216 EVT_UPDATE_UI(ODComboPage_ChangeText
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
217 EVT_UPDATE_UI(ODComboPage_DeleteSel
, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton
)
219 EVT_COMBOBOX(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboBox
)
220 EVT_TEXT(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboText
)
221 EVT_TEXT_ENTER(ODComboPage_Combo
, ODComboboxWidgetsPage::OnComboText
)
223 EVT_CHECKBOX(wxID_ANY
, ODComboboxWidgetsPage::OnCheckOrRadioBox
)
224 EVT_RADIOBOX(wxID_ANY
, ODComboboxWidgetsPage::OnCheckOrRadioBox
)
227 // ============================================================================
229 // ============================================================================
232 // wxOwnerDrawnComboBox needs to subclassed so that owner-drawing
233 // callbacks can be implemented.
234 class DemoODComboBox
: public wxOwnerDrawnComboBox
237 virtual void OnDrawItem(wxDC
& dc
,
240 int WXUNUSED(flags
)) const
242 if ( item
== wxNOT_FOUND
)
257 dc
.SetTextForeground(txtCol
);
259 dc
.DrawText(GetString(item
),
261 rect
.y
+ ((rect
.height
- dc
.GetCharHeight())/2)
265 virtual void OnDrawBackground(wxDC
& dc
, const wxRect
& rect
,
266 int item
, int flags
) const
269 // If item is selected or even, or we are painting the
270 // combo control itself, use the default rendering.
271 if ( (flags
& (wxODCB_PAINTING_CONTROL
|wxODCB_PAINTING_SELECTED
)) ||
274 wxOwnerDrawnComboBox::OnDrawBackground(dc
,rect
,item
,flags
);
278 // Otherwise, draw every other background with different colour.
279 wxColour
bgCol(240,240,250);
280 dc
.SetBrush(wxBrush(bgCol
));
281 dc
.SetPen(wxPen(bgCol
));
282 dc
.DrawRectangle(rect
);
285 virtual wxCoord
OnMeasureItem(size_t WXUNUSED(item
)) const
290 virtual wxCoord
OnMeasureItemWidth(size_t WXUNUSED(item
)) const
292 return -1; // default - will be measured from text width
297 IMPLEMENT_WIDGETS_PAGE(ODComboboxWidgetsPage
, _T("OwnerDrawnCombobox"),
298 GENERIC_CTRLS
| WITH_ITEMS_CTRLS
| COMBO_CTRLS
301 ODComboboxWidgetsPage::ODComboboxWidgetsPage(WidgetsBookCtrl
*book
,
302 wxImageList
*imaglist
)
303 : ItemContainerWidgetsPage(book
, imaglist
, odcombobox_xpm
)
308 m_chkDclickcycles
= (wxCheckBox
*)NULL
;
310 m_combobox
= (wxOwnerDrawnComboBox
*)NULL
;
311 m_sizerCombo
= (wxSizer
*)NULL
;
314 void ODComboboxWidgetsPage::CreateContent()
317 What we create here is a frame having 3 panes: style pane is the
318 leftmost one, in the middle the pane with buttons allowing to perform
319 miscellaneous combobox operations and the pane containing the combobox
325 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
327 wxSizer
*sizerLeft
= new wxBoxSizer(wxVERTICAL
);
329 // left pane - style box
330 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, _T("&Set style"));
332 wxSizer
*sizerStyle
= new wxStaticBoxSizer(box
, wxVERTICAL
);
334 m_chkSort
= CreateCheckBoxAndAddToSizer(sizerStyle
, _T("&Sort items"));
335 m_chkReadonly
= CreateCheckBoxAndAddToSizer(sizerStyle
, _T("&Read only"));
336 m_chkDclickcycles
= CreateCheckBoxAndAddToSizer(sizerStyle
, _T("&Double-click Cycles"));
338 sizerStyle
->AddSpacer(4);
340 m_chkBitmapbutton
= CreateCheckBoxAndAddToSizer(sizerStyle
, _T("&Bitmap button"));
341 m_chkStdbutton
= CreateCheckBoxAndAddToSizer(sizerStyle
, _T("B&lank button background"));
343 wxButton
*btn
= new wxButton(this, ODComboPage_Reset
, _T("&Reset"));
344 sizerStyle
->Add(btn
, 0, wxALIGN_CENTRE_HORIZONTAL
| wxALL
, 3);
346 sizerLeft
->Add(sizerStyle
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
);
348 // left pane - popup adjustment box
349 box
= new wxStaticBox(this, wxID_ANY
, _T("Adjust &popup"));
351 wxSizer
*sizerPopupPos
= new wxStaticBoxSizer(box
, wxVERTICAL
);
353 sizerRow
= CreateSizerWithTextAndLabel(_T("Min. Width:"),
354 ODComboPage_PopupMinWidth
,
355 &m_textPopupMinWidth
);
356 m_textPopupMinWidth
->SetValue(wxT("-1"));
357 sizerPopupPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
359 sizerRow
= CreateSizerWithTextAndLabel(_T("Max. Height:"),
360 ODComboPage_PopupHeight
,
362 m_textPopupHeight
->SetValue(wxT("-1"));
363 sizerPopupPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
365 m_chkAlignpopupright
= CreateCheckBoxAndAddToSizer(sizerPopupPos
, _T("Align Right"));
367 sizerLeft
->Add(sizerPopupPos
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
| wxTOP
, 2);
369 // left pane - button adjustment box
370 box
= new wxStaticBox(this, wxID_ANY
, _T("Adjust &button"));
372 wxSizer
*sizerButtonPos
= new wxStaticBoxSizer(box
, wxVERTICAL
);
374 sizerRow
= CreateSizerWithTextAndLabel(_T("Width:"),
375 ODComboPage_ButtonWidth
,
377 m_textButtonWidth
->SetValue(wxT("-1"));
378 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
380 sizerRow
= CreateSizerWithTextAndLabel(_T("VSpacing:"),
381 ODComboPage_ButtonSpacing
,
382 &m_textButtonSpacing
);
383 m_textButtonSpacing
->SetValue(wxT("0"));
384 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
386 sizerRow
= CreateSizerWithTextAndLabel(_T("Height:"),
387 ODComboPage_ButtonHeight
,
388 &m_textButtonHeight
);
389 m_textButtonHeight
->SetValue(wxT("-1"));
390 sizerButtonPos
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
392 m_chkAlignbutleft
= CreateCheckBoxAndAddToSizer(sizerButtonPos
, _T("Align Left"));
394 sizerLeft
->Add(sizerButtonPos
, 0, wxGROW
| wxALIGN_CENTRE_HORIZONTAL
| wxTOP
, 2);
397 wxStaticBox
*box2
= new wxStaticBox(this, wxID_ANY
,
398 _T("&Change combobox contents"));
399 wxSizer
*sizerMiddle
= new wxStaticBoxSizer(box2
, wxVERTICAL
);
401 btn
= new wxButton(this, ODComboPage_ContainerTests
, _T("Run &tests"));
402 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
404 sizerRow
= CreateSizerWithTextAndLabel(_T("Current selection"),
407 text
->SetEditable(false);
409 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
411 sizerRow
= CreateSizerWithTextAndLabel(_T("Insertion Point"),
412 ODComboPage_InsertionPointText
,
414 text
->SetEditable(false);
416 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
418 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Insert
,
419 _T("&Insert this string"),
420 ODComboPage_InsertText
,
422 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
424 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Add
,
425 _T("&Add this string"),
428 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
430 btn
= new wxButton(this, ODComboPage_AddSeveral
, _T("&Append a few strings"));
431 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
433 btn
= new wxButton(this, ODComboPage_AddMany
, _T("Append &many strings"));
434 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
436 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Change
,
437 _T("C&hange current"),
438 ODComboPage_ChangeText
,
440 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
442 sizerRow
= CreateSizerWithTextAndButton(ODComboPage_Delete
,
443 _T("&Delete this item"),
444 ODComboPage_DeleteText
,
446 sizerMiddle
->Add(sizerRow
, 0, wxALL
| wxGROW
, 5);
448 btn
= new wxButton(this, ODComboPage_DeleteSel
, _T("Delete &selection"));
449 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
451 btn
= new wxButton(this, ODComboPage_Clear
, _T("&Clear"));
452 sizerMiddle
->Add(btn
, 0, wxALL
| wxGROW
, 5);
455 wxSizer
*sizerRight
= new wxBoxSizer(wxVERTICAL
);
456 m_combobox
= new DemoODComboBox();
457 m_combobox
->Create(this, ODComboPage_Combo
, wxEmptyString
,
458 wxDefaultPosition
, wxDefaultSize
,
461 sizerRight
->Add(m_combobox
, 0, wxGROW
| wxALL
, 5);
462 sizerRight
->SetMinSize(150, 0);
463 m_sizerCombo
= sizerRight
; // save it to modify it later
465 // the 3 panes panes compose the window
466 sizerTop
->Add(sizerLeft
, 4, wxGROW
| (wxALL
& ~wxLEFT
), 10);
467 sizerTop
->Add(sizerMiddle
, 5, wxGROW
| wxALL
, 10);
468 sizerTop
->Add(sizerRight
, 4, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
470 // final initializations
476 // ----------------------------------------------------------------------------
478 // ----------------------------------------------------------------------------
480 void ODComboboxWidgetsPage::Reset()
482 m_chkSort
->SetValue(false);
483 m_chkReadonly
->SetValue(false);
484 m_chkDclickcycles
->SetValue(false);
485 m_chkDclickcycles
->Enable(false);
486 m_chkBitmapbutton
->SetValue(false);
487 m_chkStdbutton
->SetValue(false);
488 m_chkStdbutton
->Enable(false);
491 void ODComboboxWidgetsPage::CreateCombo()
493 int flags
= ms_defaultFlags
;
495 if ( m_chkSort
->GetValue() )
497 if ( m_chkReadonly
->GetValue() )
498 flags
|= wxCB_READONLY
;
499 if ( m_chkDclickcycles
->GetValue() )
500 flags
|= wxODCB_DCLICK_CYCLES
;
505 unsigned int count
= m_combobox
->GetCount();
506 for ( unsigned int n
= 0; n
< count
; n
++ )
508 items
.Add(m_combobox
->GetString(n
));
511 m_sizerCombo
->Detach( m_combobox
);
515 m_combobox
= new DemoODComboBox();
516 m_combobox
->Create(this, ODComboPage_Combo
, wxEmptyString
,
517 wxDefaultPosition
, wxDefaultSize
,
521 unsigned int count
= items
.GetCount();
522 for ( unsigned int n
= 0; n
< count
; n
++ )
524 m_combobox
->Append(items
[n
]);
527 // Update from controls that edit popup position etc.
529 wxUpdateUIEvent tempEvt
;
530 OnTextPopupWidth(tempEvt
);
531 OnTextPopupHeight(tempEvt
);
534 m_combobox
->SetPopupAnchor( m_chkAlignpopupright
->GetValue() ? wxRIGHT
: wxLEFT
);
536 if ( m_chkBitmapbutton
->GetValue() )
538 wxBitmap bmpNormal
= CreateBitmap(wxColour(0,0,255));
539 wxBitmap bmpPressed
= CreateBitmap(wxColour(0,0,128));
540 wxBitmap bmpHover
= CreateBitmap(wxColour(128,128,255));
541 m_combobox
->SetButtonBitmaps(bmpNormal
,m_chkStdbutton
->GetValue(),bmpPressed
,bmpHover
);
544 m_sizerCombo
->Add(m_combobox
, 0, wxGROW
| wxALL
, 5);
545 m_sizerCombo
->Layout();
548 // ----------------------------------------------------------------------------
550 // ----------------------------------------------------------------------------
552 void ODComboboxWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
559 void ODComboboxWidgetsPage::OnButtonChange(wxCommandEvent
& WXUNUSED(event
))
561 int sel
= m_combobox
->GetSelection();
562 if ( sel
!= wxNOT_FOUND
)
565 m_combobox
->SetString(sel
, m_textChange
->GetValue());
567 wxLogMessage(_T("Not implemented in wxGTK"));
572 void ODComboboxWidgetsPage::OnButtonDelete(wxCommandEvent
& WXUNUSED(event
))
575 if ( !m_textDelete
->GetValue().ToULong(&n
) ||
576 (n
>= m_combobox
->GetCount()) )
581 m_combobox
->Delete(n
);
584 void ODComboboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent
& WXUNUSED(event
))
586 int sel
= m_combobox
->GetSelection();
587 if ( sel
!= wxNOT_FOUND
)
589 m_combobox
->Delete(sel
);
593 void ODComboboxWidgetsPage::OnButtonClear(wxCommandEvent
& WXUNUSED(event
))
598 void ODComboboxWidgetsPage::OnButtonInsert(wxCommandEvent
& WXUNUSED(event
))
600 static unsigned int s_item
= 0;
602 wxString s
= m_textInsert
->GetValue();
603 if ( !m_textInsert
->IsModified() )
605 // update the default string
606 m_textInsert
->SetValue(wxString::Format(_T("test item %u"), ++s_item
));
609 if (m_combobox
->GetSelection() >= 0)
610 m_combobox
->Insert(s
, m_combobox
->GetSelection());
613 void ODComboboxWidgetsPage::OnButtonAdd(wxCommandEvent
& WXUNUSED(event
))
615 static unsigned int s_item
= 0;
617 wxString s
= m_textAdd
->GetValue();
618 if ( !m_textAdd
->IsModified() )
620 // update the default string
621 m_textAdd
->SetValue(wxString::Format(_T("test item %u"), ++s_item
));
624 m_combobox
->Append(s
);
627 void ODComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent
& WXUNUSED(event
))
629 // "many" means 1000 here
630 for ( unsigned int n
= 0; n
< 1000; n
++ )
632 m_combobox
->Append(wxString::Format(_T("item #%u"), n
));
636 void ODComboboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent
& WXUNUSED(event
))
638 m_combobox
->Append(_T("First"));
639 m_combobox
->Append(_T("another one"));
640 m_combobox
->Append(_T("and the last (very very very very very very very very very very long) one"));
643 void ODComboboxWidgetsPage::OnTextPopupWidth(wxCommandEvent
& WXUNUSED(event
))
647 m_textPopupMinWidth
->GetValue().ToLong(&l
);
649 if (m_combobox
&& l
> 0)
651 m_combobox
->SetPopupMinWidth(l
);
655 void ODComboboxWidgetsPage::OnTextPopupHeight(wxCommandEvent
& WXUNUSED(event
))
659 m_textPopupHeight
->GetValue().ToLong(&l
);
661 if (m_combobox
&& l
> 0)
663 m_combobox
->SetPopupMaxHeight(l
);
667 void ODComboboxWidgetsPage::GetButtonPosition()
673 m_textButtonWidth
->GetValue().ToLong(&w
);
674 m_textButtonSpacing
->GetValue().ToLong(&spacing
);
675 m_textButtonHeight
->GetValue().ToLong(&h
);
676 int align
= m_chkAlignbutleft
->GetValue() ?
679 m_combobox
->SetButtonPosition(w
,h
,align
,spacing
);
682 void ODComboboxWidgetsPage::OnTextButtonAll(wxCommandEvent
& WXUNUSED(event
))
686 if ( m_chkBitmapbutton
->GetValue() )
693 void ODComboboxWidgetsPage::OnUpdateUICurText(wxUpdateUIEvent
& event
)
696 event
.SetText( wxString::Format(_T("%d"), m_combobox
->GetSelection()) );
699 void ODComboboxWidgetsPage::OnUpdateUIInsertionPointText(wxUpdateUIEvent
& event
)
702 event
.SetText( wxString::Format(_T("%ld"), m_combobox
->GetInsertionPoint()) );
705 void ODComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent
& event
)
708 event
.Enable( m_chkSort
->GetValue() || m_chkReadonly
->GetValue() ||
709 m_chkBitmapbutton
->GetValue() );
712 void ODComboboxWidgetsPage::OnUpdateUIInsert(wxUpdateUIEvent
& event
)
716 bool enable
= !(m_combobox
->GetWindowStyle() & wxCB_SORT
) &&
717 (m_combobox
->GetSelection() >= 0);
719 event
.Enable(enable
);
723 void ODComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent
& event
)
728 event
.Enable(m_textDelete
->GetValue().ToULong(&n
) &&
729 (n
< (unsigned)m_combobox
->GetCount()));
733 void ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent
& event
)
736 event
.Enable(m_combobox
->GetSelection() != wxNOT_FOUND
);
739 void ODComboboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent
& event
)
742 event
.Enable(m_combobox
->GetCount() != 0);
745 void ODComboboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent
& event
)
748 event
.Enable(!(m_combobox
->GetWindowStyle() & wxCB_SORT
));
751 void ODComboboxWidgetsPage::OnComboText(wxCommandEvent
& event
)
756 wxString s
= event
.GetString();
758 wxASSERT_MSG( s
== m_combobox
->GetValue(),
759 _T("event and combobox values should be the same") );
761 if (event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
762 wxLogMessage(_T("OwnerDrawnCombobox enter pressed (now '%s')"), s
.c_str());
764 wxLogMessage(_T("OwnerDrawnCombobox text changed (now '%s')"), s
.c_str());
767 void ODComboboxWidgetsPage::OnComboBox(wxCommandEvent
& event
)
769 long sel
= event
.GetInt();
770 m_textDelete
->SetValue(wxString::Format(_T("%ld"), sel
));
772 wxLogMessage(_T("OwnerDrawnCombobox item %ld selected"), sel
);
774 wxLogMessage(_T("OwnerDrawnCombobox GetValue(): %s"), m_combobox
->GetValue().c_str() );
777 void ODComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent
& event
)
779 wxObject
* ctrl
= event
.GetEventObject();
781 // Double-click cycles only applies to read-only combobox
782 if ( ctrl
== (wxObject
*) m_chkReadonly
)
784 m_chkDclickcycles
->Enable( m_chkReadonly
->GetValue() );
786 else if ( ctrl
== (wxObject
*) m_chkBitmapbutton
)
788 m_chkStdbutton
->Enable( m_chkBitmapbutton
->GetValue() );
790 else if ( ctrl
== (wxObject
*) m_chkAlignbutleft
)
792 wxUpdateUIEvent tempEvt
;
793 OnTextButtonAll(tempEvt
);
799 wxBitmap
ODComboboxWidgetsPage::CreateBitmap(const wxColour
& colour
)
801 int ch
= m_combobox
->GetClientSize().y
- 1;
807 m_textButtonWidth
->GetValue().ToLong(&w
);
808 m_textButtonHeight
->GetValue().ToLong(&h
);
819 dc
.SelectObject(bmp
);
821 // Draw transparent background
822 wxColour
magic(255,0,255);
823 wxBrush
magicBrush(magic
);
824 dc
.SetBrush(magicBrush
);
825 dc
.SetPen(*wxTRANSPARENT_PEN
);
826 dc
.DrawRectangle(0,0,bmp
.GetWidth(),bmp
.GetHeight());
828 // Draw image content
829 dc
.SetBrush(wxBrush(colour
));
830 dc
.DrawCircle(h
/2,h
/2+1,(h
/2));
832 dc
.SelectObject(wxNullBitmap
);
834 // Finalize transparency with a mask
835 wxMask
*mask
= new wxMask(bmp
, magic
);
841 #endif //wxUSE_ODCOMBOBOX