1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/checklst.cpp
3 // Purpose: implementation of wxCheckListBox class
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/object.h"
31 #include "wx/colour.h"
33 #include "wx/bitmap.h"
34 #include "wx/window.h"
35 #include "wx/listbox.h"
36 #include "wx/dcmemory.h"
38 #include "wx/settings.h"
43 #include "wx/ownerdrw.h"
44 #include "wx/checklst.h"
46 #include "wx/palmos/wrapwin.h"
48 #include "wx/palmos/private.h"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 // get item (converted to right type)
55 #define GetItem(n) ((wxCheckListBoxItem *)(GetItem(n)))
57 // ============================================================================
59 // ============================================================================
62 #if wxUSE_EXTENDED_RTTI
63 WX_DEFINE_FLAGS( wxCheckListBoxStyle
)
65 wxBEGIN_FLAGS( wxCheckListBoxStyle
)
66 // new style border flags, we put them first to
67 // use them for streaming out
68 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
69 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
70 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
71 wxFLAGS_MEMBER(wxBORDER_RAISED
)
72 wxFLAGS_MEMBER(wxBORDER_STATIC
)
73 wxFLAGS_MEMBER(wxBORDER_NONE
)
75 // old style border flags
76 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
77 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
78 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
79 wxFLAGS_MEMBER(wxRAISED_BORDER
)
80 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
81 wxFLAGS_MEMBER(wxBORDER
)
83 // standard window styles
84 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
85 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
86 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
87 wxFLAGS_MEMBER(wxWANTS_CHARS
)
88 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
89 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
90 wxFLAGS_MEMBER(wxVSCROLL
)
91 wxFLAGS_MEMBER(wxHSCROLL
)
93 wxFLAGS_MEMBER(wxLB_SINGLE
)
94 wxFLAGS_MEMBER(wxLB_MULTIPLE
)
95 wxFLAGS_MEMBER(wxLB_EXTENDED
)
96 wxFLAGS_MEMBER(wxLB_HSCROLL
)
97 wxFLAGS_MEMBER(wxLB_ALWAYS_SB
)
98 wxFLAGS_MEMBER(wxLB_NEEDED_SB
)
99 wxFLAGS_MEMBER(wxLB_SORT
)
100 wxFLAGS_MEMBER(wxLB_OWNERDRAW
)
102 wxEND_FLAGS( wxCheckListBoxStyle
)
104 IMPLEMENT_DYNAMIC_CLASS_XTI(wxCheckListBox
, wxListBox
,"wx/checklst.h")
106 wxBEGIN_PROPERTIES_TABLE(wxCheckListBox
)
107 wxEVENT_PROPERTY( Toggle
, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, wxCommandEvent
)
108 wxPROPERTY_FLAGS( WindowStyle
, wxCheckListBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, wxLB_OWNERDRAW
/*flags*/ , wxT("Helpstring") , wxT("group")) // style
109 wxEND_PROPERTIES_TABLE()
111 wxBEGIN_HANDLERS_TABLE(wxCheckListBox
)
112 wxEND_HANDLERS_TABLE()
114 wxCONSTRUCTOR_4( wxCheckListBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
)
117 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox
, wxListBox
)
120 // ----------------------------------------------------------------------------
121 // declaration and implementation of wxCheckListBoxItem class
122 // ----------------------------------------------------------------------------
124 class wxCheckListBoxItem
: public wxOwnerDrawn
126 friend class WXDLLEXPORT wxCheckListBox
;
129 wxCheckListBoxItem(wxCheckListBox
*pParent
, size_t nIndex
);
132 virtual bool OnDrawItem(wxDC
& dc
, const wxRect
& rc
, wxODAction act
, wxODStatus stat
);
134 // simple accessors and operations
135 bool IsChecked() const { return m_bChecked
; }
137 void Check(bool bCheck
);
138 void Toggle() { Check(!IsChecked()); }
144 DECLARE_NO_COPY_CLASS(wxCheckListBoxItem
)
146 wxCheckListBox
*m_pParent
;
150 wxCheckListBoxItem::wxCheckListBoxItem(wxCheckListBox
*pParent
, size_t nIndex
)
151 : wxOwnerDrawn(wxEmptyString
, true) // checkable
155 bool wxCheckListBoxItem::OnDrawItem(wxDC
& dc
, const wxRect
& rc
,
156 wxODAction act
, wxODStatus stat
)
161 // change the state of the item and redraw it
162 void wxCheckListBoxItem::Check(bool check
)
166 // send an "item checked" event
167 void wxCheckListBoxItem::SendEvent()
171 // ----------------------------------------------------------------------------
172 // implementation of wxCheckListBox class
173 // ----------------------------------------------------------------------------
175 // define event table
176 // ------------------
177 BEGIN_EVENT_TABLE(wxCheckListBox
, wxListBox
)
178 EVT_KEY_DOWN(wxCheckListBox::OnKeyDown
)
179 EVT_LEFT_DOWN(wxCheckListBox::OnLeftClick
)
185 // def ctor: use Create() to really create the control
186 wxCheckListBox::wxCheckListBox()
190 // ctor which creates the associated control
191 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
192 const wxPoint
& pos
, const wxSize
& size
,
193 int nStrings
, const wxString choices
[],
194 long style
, const wxValidator
& val
,
195 const wxString
& name
)
197 Create(parent
, id
, pos
, size
, nStrings
, choices
, style
, val
, name
);
200 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
201 const wxPoint
& pos
, const wxSize
& size
,
202 const wxArrayString
& choices
,
203 long style
, const wxValidator
& val
,
204 const wxString
& name
)
206 Create(parent
, id
, pos
, size
, choices
, style
, val
, name
);
209 bool wxCheckListBox::Create(wxWindow
*parent
, wxWindowID id
,
210 const wxPoint
& pos
, const wxSize
& size
,
211 int n
, const wxString choices
[],
213 const wxValidator
& validator
, const wxString
& name
)
215 return wxListBox::Create(parent
, id
, pos
, size
, n
, choices
,
216 style
| wxLB_OWNERDRAW
, validator
, name
);
219 bool wxCheckListBox::Create(wxWindow
*parent
, wxWindowID id
,
220 const wxPoint
& pos
, const wxSize
& size
,
221 const wxArrayString
& choices
,
223 const wxValidator
& validator
, const wxString
& name
)
225 return wxListBox::Create(parent
, id
, pos
, size
, choices
,
226 style
| wxLB_OWNERDRAW
, validator
, name
);
229 // misc overloaded methods
230 // -----------------------
232 void wxCheckListBox::Delete(unsigned int n
)
236 bool wxCheckListBox::SetFont( const wxFont
&font
)
241 // create/retrieve item
242 // --------------------
244 // create a check list box item
245 wxOwnerDrawn
*wxCheckListBox::CreateLboxItem(size_t nIndex
)
247 wxCheckListBoxItem
*pItem
= new wxCheckListBoxItem(this, nIndex
);
253 bool wxCheckListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
)
261 bool wxCheckListBox::IsChecked(unsigned int uiIndex
) const
266 void wxCheckListBox::Check(unsigned int uiIndex
, bool bCheck
)
273 void wxCheckListBox::OnKeyDown(wxKeyEvent
& event
)
277 void wxCheckListBox::OnLeftClick(wxMouseEvent
& event
)
281 int wxCheckListBox::DoHitTestItem(wxCoord x
, wxCoord y
) const