]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_listc.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_listc.cpp
3 // Purpose: XRC resource for wxListCtrl
4 // Author: Brian Gavin, Kinaou Hervé, Vadim Zeitlin
7 // Copyright: (c) 2000 Brian Gavin
8 // (c) 2009 Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxUSE_XRC && wxUSE_LISTCTRL
21 #include "wx/xrc/xh_listc.h"
24 #include "wx/textctrl.h"
27 #include "wx/listctrl.h"
28 #include "wx/imaglist.h"
33 const char *LISTCTRL_CLASS_NAME
= "wxListCtrl";
34 const char *LISTITEM_CLASS_NAME
= "listitem";
35 const char *LISTCOL_CLASS_NAME
= "listcol";
37 } // anonymous namespace
40 IMPLEMENT_DYNAMIC_CLASS(wxListCtrlXmlHandler
, wxXmlResourceHandler
)
42 wxListCtrlXmlHandler::wxListCtrlXmlHandler()
43 : wxXmlResourceHandler()
46 XRC_ADD_STYLE(wxLIST_FORMAT_LEFT
);
47 XRC_ADD_STYLE(wxLIST_FORMAT_RIGHT
);
48 XRC_ADD_STYLE(wxLIST_FORMAT_CENTRE
);
49 XRC_ADD_STYLE(wxLIST_MASK_STATE
);
50 XRC_ADD_STYLE(wxLIST_MASK_TEXT
);
51 XRC_ADD_STYLE(wxLIST_MASK_IMAGE
);
52 XRC_ADD_STYLE(wxLIST_MASK_DATA
);
53 XRC_ADD_STYLE(wxLIST_MASK_WIDTH
);
54 XRC_ADD_STYLE(wxLIST_MASK_FORMAT
);
55 XRC_ADD_STYLE(wxLIST_STATE_FOCUSED
);
56 XRC_ADD_STYLE(wxLIST_STATE_SELECTED
);
59 XRC_ADD_STYLE(wxLC_LIST
);
60 XRC_ADD_STYLE(wxLC_REPORT
);
61 XRC_ADD_STYLE(wxLC_ICON
);
62 XRC_ADD_STYLE(wxLC_SMALL_ICON
);
63 XRC_ADD_STYLE(wxLC_ALIGN_TOP
);
64 XRC_ADD_STYLE(wxLC_ALIGN_LEFT
);
65 XRC_ADD_STYLE(wxLC_AUTOARRANGE
);
66 XRC_ADD_STYLE(wxLC_USER_TEXT
);
67 XRC_ADD_STYLE(wxLC_EDIT_LABELS
);
68 XRC_ADD_STYLE(wxLC_NO_HEADER
);
69 XRC_ADD_STYLE(wxLC_SINGLE_SEL
);
70 XRC_ADD_STYLE(wxLC_SORT_ASCENDING
);
71 XRC_ADD_STYLE(wxLC_SORT_DESCENDING
);
72 XRC_ADD_STYLE(wxLC_VIRTUAL
);
73 XRC_ADD_STYLE(wxLC_HRULES
);
74 XRC_ADD_STYLE(wxLC_VRULES
);
75 XRC_ADD_STYLE(wxLC_NO_SORT_HEADER
);
79 wxObject
*wxListCtrlXmlHandler::DoCreateResource()
81 if ( m_class
== LISTITEM_CLASS_NAME
)
85 else if ( m_class
== LISTCOL_CLASS_NAME
)
91 wxASSERT_MSG( m_class
== LISTCTRL_CLASS_NAME
,
92 "can't handle unknown node" );
94 return HandleListCtrl();
97 return m_parentAsWindow
;
100 bool wxListCtrlXmlHandler::CanHandle(wxXmlNode
*node
)
102 return IsOfClass(node
, LISTCTRL_CLASS_NAME
) ||
103 IsOfClass(node
, LISTITEM_CLASS_NAME
) ||
104 IsOfClass(node
, LISTCOL_CLASS_NAME
);
107 void wxListCtrlXmlHandler::HandleCommonItemAttrs(wxListItem
& item
)
109 if (HasParam(wxT("align")))
110 item
.SetAlign((wxListColumnFormat
)GetStyle(wxT("align")));
111 if (HasParam(wxT("text")))
112 item
.SetText(GetText(wxT("text")));
115 void wxListCtrlXmlHandler::HandleListCol()
117 wxListCtrl
* const list
= wxDynamicCast(m_parentAsWindow
, wxListCtrl
);
118 wxCHECK_RET( list
, "must have wxListCtrl parent" );
120 if ( !list
->HasFlag(wxLC_REPORT
) )
122 ReportError("Only report mode list controls can have columns.");
128 HandleCommonItemAttrs(item
);
129 if (HasParam(wxT("width")))
130 item
.SetWidth((int)GetLong(wxT("width")));
131 if (HasParam(wxT("image")))
132 item
.SetImage((int)GetLong(wxT("image")));
134 list
->InsertColumn(list
->GetColumnCount(), item
);
137 void wxListCtrlXmlHandler::HandleListItem()
139 wxListCtrl
* const list
= wxDynamicCast(m_parentAsWindow
, wxListCtrl
);
140 wxCHECK_RET( list
, "must have wxListCtrl parent" );
144 HandleCommonItemAttrs(item
);
146 if (HasParam(wxT("bg")))
147 item
.SetBackgroundColour(GetColour(wxT("bg")));
148 if (HasParam(wxT("col")))
149 item
.SetColumn((int)GetLong(wxT("col")));
150 if (HasParam(wxT("data")))
151 item
.SetData(GetLong(wxT("data")));
152 if (HasParam(wxT("font")))
153 item
.SetFont(GetFont());
154 if (HasParam(wxT("state")))
155 item
.SetState(GetStyle(wxT("state")));
156 if (HasParam(wxT("textcolour")))
157 item
.SetTextColour(GetColour(wxT("textcolour")));
158 if (HasParam(wxT("textcolor")))
159 item
.SetTextColour(GetColour(wxT("textcolor")));
161 // the list control icon style, may be 0
163 if ( list
->HasFlag(wxLC_ICON
) )
164 image
= GetImageIndex(list
, wxIMAGE_LIST_NORMAL
);
165 else if ( list
->HasFlag(wxLC_SMALL_ICON
) || list
->HasFlag(wxLC_REPORT
) || list
->HasFlag(wxLC_LIST
) )
166 image
= GetImageIndex(list
, wxIMAGE_LIST_SMALL
);
170 if ( image
!= wxNOT_FOUND
)
171 item
.SetImage(image
);
173 // append the list item to the control
174 item
.SetId(list
->GetItemCount());
176 list
->InsertItem(item
);
179 wxListCtrl
*wxListCtrlXmlHandler::HandleListCtrl()
181 XRC_MAKE_INSTANCE(list
, wxListCtrl
)
183 list
->Create(m_parentAsWindow
,
185 GetPosition(), GetSize(),
190 // we can optionally have normal and/or small image lists
191 wxImageList
*imagelist
;
192 imagelist
= GetImageList(wxT("imagelist"));
194 list
->AssignImageList(imagelist
, wxIMAGE_LIST_NORMAL
);
195 imagelist
= GetImageList(wxT("imagelist-small"));
197 list
->AssignImageList(imagelist
, wxIMAGE_LIST_SMALL
);
199 CreateChildrenPrivately(list
);
205 long wxListCtrlXmlHandler::GetImageIndex(wxListCtrl
*listctrl
, int which
)
207 // use different tag names depending on whether we need a normal or small
214 case wxIMAGE_LIST_SMALL
:
215 bmpParam
+= "-small";
216 imgParam
+= "-small";
219 case wxIMAGE_LIST_NORMAL
:
224 wxFAIL_MSG( "unsupported image list kind" );
228 // look for either bitmap or image tags
229 int imgIndex
= wxNOT_FOUND
;
230 if ( HasParam(bmpParam
) )
232 // we implicitly construct an image list containing the specified
234 wxBitmap bmp
= GetBitmap(bmpParam
, wxART_OTHER
);
236 // create the image list on demand for the first bitmap
237 wxImageList
*imgList
= listctrl
->GetImageList(which
);
240 imgList
= new wxImageList( bmp
.GetWidth(), bmp
.GetHeight() );
241 listctrl
->AssignImageList( imgList
, which
);
244 imgIndex
= imgList
->Add(bmp
);
247 if ( HasParam(imgParam
) )
249 if ( imgIndex
!= wxNOT_FOUND
)
251 // TODO: we should really check that only bitmap or only image tags
252 // are used across all items of the control, not just in this
254 ReportError(wxString::Format(
255 "listitem %s attribute ignored because %s is also specified",
256 bmpParam
, imgParam
));
259 // just use the specified index directly
260 imgIndex
= GetLong(imgParam
);
266 #endif // wxUSE_XRC && wxUSE_LISTCTRL