1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: palmos/checklst.cpp
3 // Purpose: implementation of wxCheckListBox class
4 // Author: William Osborne
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "checklst.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/object.h"
35 #include "wx/colour.h"
37 #include "wx/bitmap.h"
38 #include "wx/window.h"
39 #include "wx/listbox.h"
40 #include "wx/dcmemory.h"
42 #include "wx/settings.h"
47 #include "wx/ownerdrw.h"
48 #include "wx/checklst.h"
50 #include "wx/palmos/wrapwin.h"
52 #include "wx/palmos/private.h"
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 // get item (converted to right type)
59 #define GetItem(n) ((wxCheckListBoxItem *)(GetItem(n)))
61 // ============================================================================
63 // ============================================================================
66 #if wxUSE_EXTENDED_RTTI
67 WX_DEFINE_FLAGS( wxCheckListBoxStyle
)
69 wxBEGIN_FLAGS( wxCheckListBoxStyle
)
70 // new style border flags, we put them first to
71 // use them for streaming out
72 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
73 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
74 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
75 wxFLAGS_MEMBER(wxBORDER_RAISED
)
76 wxFLAGS_MEMBER(wxBORDER_STATIC
)
77 wxFLAGS_MEMBER(wxBORDER_NONE
)
79 // old style border flags
80 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
81 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
82 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
83 wxFLAGS_MEMBER(wxRAISED_BORDER
)
84 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
85 wxFLAGS_MEMBER(wxBORDER
)
87 // standard window styles
88 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
89 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
90 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
91 wxFLAGS_MEMBER(wxWANTS_CHARS
)
92 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
93 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
94 wxFLAGS_MEMBER(wxVSCROLL
)
95 wxFLAGS_MEMBER(wxHSCROLL
)
97 wxFLAGS_MEMBER(wxLB_SINGLE
)
98 wxFLAGS_MEMBER(wxLB_MULTIPLE
)
99 wxFLAGS_MEMBER(wxLB_EXTENDED
)
100 wxFLAGS_MEMBER(wxLB_HSCROLL
)
101 wxFLAGS_MEMBER(wxLB_ALWAYS_SB
)
102 wxFLAGS_MEMBER(wxLB_NEEDED_SB
)
103 wxFLAGS_MEMBER(wxLB_SORT
)
104 wxFLAGS_MEMBER(wxLB_OWNERDRAW
)
106 wxEND_FLAGS( wxCheckListBoxStyle
)
108 IMPLEMENT_DYNAMIC_CLASS_XTI(wxCheckListBox
, wxListBox
,"wx/checklst.h")
110 wxBEGIN_PROPERTIES_TABLE(wxCheckListBox
)
111 wxEVENT_PROPERTY( Toggle
, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, wxCommandEvent
)
112 wxPROPERTY_FLAGS( WindowStyle
, wxCheckListBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, wxLB_OWNERDRAW
/*flags*/ , wxT("Helpstring") , wxT("group")) // style
113 wxEND_PROPERTIES_TABLE()
115 wxBEGIN_HANDLERS_TABLE(wxCheckListBox
)
116 wxEND_HANDLERS_TABLE()
118 wxCONSTRUCTOR_4( wxCheckListBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
)
121 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox
, wxListBox
)
124 // ----------------------------------------------------------------------------
125 // declaration and implementation of wxCheckListBoxItem class
126 // ----------------------------------------------------------------------------
128 class wxCheckListBoxItem
: public wxOwnerDrawn
130 friend class WXDLLEXPORT wxCheckListBox
;
133 wxCheckListBoxItem(wxCheckListBox
*pParent
, size_t nIndex
);
136 virtual bool OnDrawItem(wxDC
& dc
, const wxRect
& rc
, wxODAction act
, wxODStatus stat
);
138 // simple accessors and operations
139 bool IsChecked() const { return m_bChecked
; }
141 void Check(bool bCheck
);
142 void Toggle() { Check(!IsChecked()); }
148 DECLARE_NO_COPY_CLASS(wxCheckListBoxItem
)
150 wxCheckListBox
*m_pParent
;
154 wxCheckListBoxItem::wxCheckListBoxItem(wxCheckListBox
*pParent
, size_t nIndex
)
155 : wxOwnerDrawn(wxEmptyString
, TRUE
) // checkable
159 bool wxCheckListBoxItem::OnDrawItem(wxDC
& dc
, const wxRect
& rc
,
160 wxODAction act
, wxODStatus stat
)
165 // change the state of the item and redraw it
166 void wxCheckListBoxItem::Check(bool check
)
170 // send an "item checked" event
171 void wxCheckListBoxItem::SendEvent()
175 // ----------------------------------------------------------------------------
176 // implementation of wxCheckListBox class
177 // ----------------------------------------------------------------------------
179 // define event table
180 // ------------------
181 BEGIN_EVENT_TABLE(wxCheckListBox
, wxListBox
)
182 EVT_KEY_DOWN(wxCheckListBox::OnKeyDown
)
183 EVT_LEFT_DOWN(wxCheckListBox::OnLeftClick
)
189 // def ctor: use Create() to really create the control
190 wxCheckListBox::wxCheckListBox()
194 // ctor which creates the associated control
195 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
196 const wxPoint
& pos
, const wxSize
& size
,
197 int nStrings
, const wxString choices
[],
198 long style
, const wxValidator
& val
,
199 const wxString
& name
)
201 Create(parent
, id
, pos
, size
, nStrings
, choices
, style
, val
, name
);
204 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
205 const wxPoint
& pos
, const wxSize
& size
,
206 const wxArrayString
& choices
,
207 long style
, const wxValidator
& val
,
208 const wxString
& name
)
210 Create(parent
, id
, pos
, size
, choices
, style
, val
, name
);
213 bool wxCheckListBox::Create(wxWindow
*parent
, wxWindowID id
,
214 const wxPoint
& pos
, const wxSize
& size
,
215 int n
, const wxString choices
[],
217 const wxValidator
& validator
, const wxString
& name
)
219 return wxListBox::Create(parent
, id
, pos
, size
, n
, choices
,
220 style
| wxLB_OWNERDRAW
, validator
, name
);
223 bool wxCheckListBox::Create(wxWindow
*parent
, wxWindowID id
,
224 const wxPoint
& pos
, const wxSize
& size
,
225 const wxArrayString
& choices
,
227 const wxValidator
& validator
, const wxString
& name
)
229 return wxListBox::Create(parent
, id
, pos
, size
, choices
,
230 style
| wxLB_OWNERDRAW
, validator
, name
);
233 // misc overloaded methods
234 // -----------------------
236 void wxCheckListBox::Delete(int N
)
240 bool wxCheckListBox::SetFont( const wxFont
&font
)
245 // create/retrieve item
246 // --------------------
248 // create a check list box item
249 wxOwnerDrawn
*wxCheckListBox::CreateLboxItem(size_t nIndex
)
251 wxCheckListBoxItem
*pItem
= new wxCheckListBoxItem(this, nIndex
);
257 bool wxCheckListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
)
265 bool wxCheckListBox::IsChecked(size_t uiIndex
) const
270 void wxCheckListBox::Check(size_t uiIndex
, bool bCheck
)
277 void wxCheckListBox::OnKeyDown(wxKeyEvent
& event
)
281 void wxCheckListBox::OnLeftClick(wxMouseEvent
& event
)
285 int wxCheckListBox::DoHitTestItem(wxCoord x
, wxCoord y
) const