1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        checkedlistctrl.h
3 // Purpose:     wxCheckedListCtrl
4 // Author:      Unknown ? (found at http://wiki.wxwidgets.org/wiki.pl?WxListCtrl)
5 // Modified by: Francesco Montorsi
6 // Created:     2005/06/29
7 // RCS-ID:      $Id$
8 // Copyright:   (c) 2005 Francesco Montorsi
9 // Licence:     wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef _WX_CHECKEDLISTCTRL_H_
14 #define _WX_CHECKEDLISTCTRL_H_
15 
16 #ifndef wxUSE_CHECKEDLISTCTRL
17     #define wxUSE_CHECKEDLISTCTRL                   1
18 #endif
19 
20 // wxWidgets headers
21 //#include "wx/webupdatedef.h"		// for the WXDLLIMPEXP_WEBUPDATE macro
22 // for shared builds
23 // NOTE: these were useful only when originally the WebUpdate component
24 //       was built as a library for full integration into the application
25 //       to update (see the design FAQ in the docs for more info).
26 //#ifdef WXMAKINGDLL_WEBUPDATE
27 //    #define WXDLLIMPEXP_WEBUPDATE               WXEXPORT
28 //    #define WXDLLIMPEXP_DATA_WEBUPDATE(type)    WXEXPORT type
29 //#elif defined(WXUSINGDLL)
30 //    #define WXDLLIMPEXP_WEBUPDATE WXIMPORT
31 //    #define WXDLLIMPEXP_DATA_WEBUPDATE(type)    WXIMPORT type
32 //#else // not making nor using DLL
33     #define WXDLLIMPEXP_WEBUPDATE
34     #define WXDLLIMPEXP_DATA_WEBUPDATE(type)    type
35 //#endif
36 
37 #include <wx/listctrl.h>
38 #include <wx/imaglist.h>
39 #include <wx/settings.h>
40 
41 #if wxUSE_CHECKEDLISTCTRL
42 
43 // image indexes (used internally by wxCheckedListCtrl)
44 #define wxCLC_UNCHECKED_IMGIDX				0		// unchecked & enabled
45 #define wxCLC_CHECKED_IMGIDX				1		// checked & enabled
46 #define wxCLC_DISABLED_UNCHECKED_IMGIDX		2		// unchecked & disabled
47 #define wxCLC_DISABLED_CHECKED_IMGIDX		3		// checked & disabled
48 
49 // additional state flags (wx's defines should end at 0x0100; see listbase.h)
50 #define wxLIST_STATE_CHECKED				0x010000
51 #define wxLIST_STATE_ENABLED				0x100000
52 
53 // additional wxCheckedListCtrl style flags
54 // (wx's defines should at 0x8000; see listbase.h)
55 #define wxCLC_CHECK_WHEN_SELECTING			0x10000
56 
57 
58 // -------------------------
59 // wxCheckedListCtrl events
60 // -------------------------
61 
62 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBUPDATE, wxEVT_COMMAND_LIST_ITEM_CHECKED, -1);
63 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_WEBUPDATE, wxEVT_COMMAND_LIST_ITEM_UNCHECKED, -1);
64 
65 
66 
67 //! This is the class which performs all transactions with the server.
68 //! It uses the wxSocket facilities.
69 class WXDLLIMPEXP_WEBUPDATE wxCheckedListCtrl : public wxListCtrl
70 {
71 protected:
72 
73     // we have to keep a different array to keep track of the additional
74     // states we support....
75     wxArrayInt m_stateList;
76 
77     // our set of checkbox images...
78     wxImageList m_imageList;
79 
80 public:
wxCheckedListCtrl()81     wxCheckedListCtrl() {}
82 
83     wxCheckedListCtrl(wxWindow *parent, wxWindowID id = -1,
84                         const wxPoint& pt = wxDefaultPosition,
85                         const wxSize& sz = wxDefaultSize,
86                         long style = wxCLC_CHECK_WHEN_SELECTING,
87                         const wxValidator& validator = wxDefaultValidator,
88                         const wxString& name = wxListCtrlNameStr)
89              { Create(parent, id, pt, sz, style, validator, name); }
90 
91     bool Create(wxWindow *parent, wxWindowID id = -1,
92                         const wxPoint& pt = wxDefaultPosition,
93                         const wxSize& sz = wxDefaultSize,
94                         long style = wxCLC_CHECK_WHEN_SELECTING,
95                         const wxValidator& validator = wxDefaultValidator,
96                         const wxString& name = wxListCtrlNameStr);
97 
~wxCheckedListCtrl()98     virtual ~wxCheckedListCtrl() {}
99 
100 
101 public:			// utilities
102 
103     // core overloads (i.e. the most generic overloads)
104     bool GetItem(wxListItem& info) const;
105     bool SetItem(wxListItem& info);
106     long InsertItem(wxListItem& info);
107     bool DeleteItem(long item);
DeleteAllItems()108     bool DeleteAllItems()
109         { m_stateList.Clear(); return wxListCtrl::DeleteAllItems(); }
110 
SortItems(wxListCtrlCompare,long)111     bool SortItems(wxListCtrlCompare, long)
112         { wxASSERT_MSG(0, wxT("Not implemented yet ! sorry... ")); return FALSE; }
113 
114     // shortcuts to the SetItemState function
115     void Check(long item, bool checked);
116     void Enable(long item, bool enable);
117     void CheckAll(bool checked = true);
118     void EnableAll(bool enable = true);
119 
120     // this needs to be redeclared otherwise it's hidden by our other Enable() function.
121     // However you should use #EnableAll instead of this function if you want to get
122     // good graphics (try to understand)
123     virtual bool Enable(bool enable = true)
124         { return wxListCtrl::Enable(enable); }
125 
126     // shortcuts to the GetItemState function
IsChecked(long item)127     bool IsChecked(long item) const
128         { return GetItemState(item, wxLIST_STATE_CHECKED) != 0; }
IsEnabled(long item)129     bool IsEnabled(long item) const
130         { return GetItemState(item, wxLIST_STATE_ENABLED) != 0; }
131 
132     // this needs to be redeclared otherwise it's hidden by our other IsEnabled() function.
IsEnabled()133     bool IsEnabled() const
134         { return wxWindow::IsEnabled(); }
135 
136     //! Returns the number of checked items in the control.
137     int GetCheckedItemCount() const;
138 
139     // we overload these so we are sure they will use our
140     // #GetItem and #SetItem functions...
141     bool SetItemState(long item, long state, long stateMask);
142     int GetItemState(long item, long stateMask) const;
143     long InsertItem( long index, const wxString& label, int imageIndex = -1);
144     long SetItem(long index, int col, const wxString& label, int imageId = -1);
145 
146     // the image associated with an element is already in used by wxCheckedListCtrl
147     // itself to show the checkbox and it cannot be handled by the user !
SetItemImage(long,int)148     bool SetItemImage(long, int)
149         { wxASSERT_MSG(0, wxT("This function cannot be used with wxCheckedListCtrl !")); return FALSE; }
150 
151 protected:		// event handlers
152 
153     void OnMouseEvent(wxMouseEvent& event);
154     void OnActivateEvent(wxListEvent& event);
155 
156 protected:		// internal utilities
157 
158     static int GetItemImageFromAdditionalState(int addstate);
159     static int GetAndRemoveAdditionalState(long *state, int statemask);
160     wxColour GetBgColourFromAdditionalState(int additionalstate);
161 
162 private:
163     DECLARE_CLASS(wxCheckedListCtrl)
164     DECLARE_EVENT_TABLE()
165 };
166 
167 
168 #endif	// wxUSE_CHECKEDLISTCTRL
169 
170 #endif	// _WX_CHECKEDLISTCTRL_H_
171 
172