]>
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
7 // Copyright: (c) 2000 Brian Gavin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_XRC && wxUSE_LISTCTRL
20 #include "wx/xrc/xh_listc.h"
23 #include "wx/textctrl.h"
26 #include "wx/listctrl.h"
27 #include "wx/imaglist.h"
30 IMPLEMENT_DYNAMIC_CLASS(wxListCtrlXmlHandler
, wxXmlResourceHandler
)
32 wxListCtrlXmlHandler::wxListCtrlXmlHandler()
33 : wxXmlResourceHandler()
36 XRC_ADD_STYLE(wxLIST_FORMAT_LEFT
);
37 XRC_ADD_STYLE(wxLIST_FORMAT_RIGHT
);
38 XRC_ADD_STYLE(wxLIST_FORMAT_CENTRE
);
39 XRC_ADD_STYLE(wxLIST_MASK_STATE
);
40 XRC_ADD_STYLE(wxLIST_MASK_TEXT
);
41 XRC_ADD_STYLE(wxLIST_MASK_IMAGE
);
42 XRC_ADD_STYLE(wxLIST_MASK_DATA
);
43 XRC_ADD_STYLE(wxLIST_MASK_WIDTH
);
44 XRC_ADD_STYLE(wxLIST_MASK_FORMAT
);
45 XRC_ADD_STYLE(wxLIST_STATE_DONTCARE
);
46 XRC_ADD_STYLE(wxLIST_STATE_DROPHILITED
);
47 XRC_ADD_STYLE(wxLIST_STATE_FOCUSED
);
48 XRC_ADD_STYLE(wxLIST_STATE_SELECTED
);
49 XRC_ADD_STYLE(wxLIST_STATE_CUT
);
52 XRC_ADD_STYLE(wxLC_LIST
);
53 XRC_ADD_STYLE(wxLC_REPORT
);
54 XRC_ADD_STYLE(wxLC_ICON
);
55 XRC_ADD_STYLE(wxLC_SMALL_ICON
);
56 XRC_ADD_STYLE(wxLC_ALIGN_TOP
);
57 XRC_ADD_STYLE(wxLC_ALIGN_LEFT
);
58 XRC_ADD_STYLE(wxLC_AUTOARRANGE
);
59 XRC_ADD_STYLE(wxLC_USER_TEXT
);
60 XRC_ADD_STYLE(wxLC_EDIT_LABELS
);
61 XRC_ADD_STYLE(wxLC_NO_HEADER
);
62 XRC_ADD_STYLE(wxLC_SINGLE_SEL
);
63 XRC_ADD_STYLE(wxLC_SORT_ASCENDING
);
64 XRC_ADD_STYLE(wxLC_SORT_DESCENDING
);
65 XRC_ADD_STYLE(wxLC_VIRTUAL
);
66 XRC_ADD_STYLE(wxLC_HRULES
);
67 XRC_ADD_STYLE(wxLC_VRULES
);
68 XRC_ADD_STYLE(wxLC_NO_SORT_HEADER
);
72 wxObject
*wxListCtrlXmlHandler::DoCreateResource()
74 if (m_class
== wxT("listitem"))
77 return m_parentAsWindow
;
80 return Handle_wxListCtrl();
83 bool wxListCtrlXmlHandler::CanHandle(wxXmlNode
*node
)
85 return IsOfClass(node
, wxT("wxListCtrl")) ||
86 IsOfClass(node
, wxT("listitem"));
89 long wxListCtrlXmlHandler::Handle_wxListItem()
91 wxListCtrl
* const list
= wxDynamicCast(m_parentAsWindow
, wxListCtrl
);
92 wxCHECK_MSG( list
, -1, "must have wxListCtrl parent" );
96 if (HasParam(wxT("align")))
97 item
.SetAlign((wxListColumnFormat
)GetStyle(wxT("align")));
98 if (HasParam(wxT("bg")))
99 item
.SetBackgroundColour(GetColour(wxT("bg")));
100 if (HasParam(wxT("col")))
101 item
.SetColumn((int)GetLong(wxT("col")));
102 if (HasParam(wxT("data")))
103 item
.SetData(GetLong(wxT("data")));
104 if (HasParam(wxT("font")))
105 item
.SetFont(GetFont());
106 if (HasParam(wxT("mask")))
107 item
.SetMask(GetStyle(wxT("mask")));
108 if (HasParam(wxT("state")))
109 item
.SetState(GetStyle(wxT("state")));
110 if (HasParam(wxT("statemask")))
111 item
.SetStateMask(GetStyle(wxT("statemask")));
112 if (HasParam(wxT("text")))
113 item
.SetText(GetText(wxT("text")));
114 if (HasParam(wxT("textcolour")))
115 item
.SetTextColour(GetColour(wxT("textcolour")));
116 if (HasParam(wxT("textcolor")))
117 item
.SetTextColour(GetColour(wxT("textcolor")));
118 if (HasParam(wxT("width")))
119 item
.SetWidth((int)GetLong(wxT("width")));
121 // the list control icon style, may be 0
123 if ( list
->HasFlag(wxLC_ICON
) )
124 image
= GetImageIndex(list
, wxIMAGE_LIST_NORMAL
);
125 else if ( list
->HasFlag(wxLC_SMALL_ICON
) )
126 image
= GetImageIndex(list
, wxIMAGE_LIST_SMALL
);
130 if ( image
!= wxNOT_FOUND
)
131 item
.SetImage(image
);
133 // append the list item to the control
134 item
.SetId(list
->GetItemCount());
136 return list
->InsertItem(item
);
139 wxObject
* wxListCtrlXmlHandler::Handle_wxListCtrl()
141 XRC_MAKE_INSTANCE(list
, wxListCtrl
)
143 list
->Create(m_parentAsWindow
,
145 GetPosition(), GetSize(),
150 // we can optionally have normal and/or small image lists
151 wxImageList
*imagelist
;
152 imagelist
= GetImageList(wxT("imagelist"));
154 list
->AssignImageList(imagelist
, wxIMAGE_LIST_NORMAL
);
155 imagelist
= GetImageList(wxT("imagelist-small"));
157 list
->AssignImageList(imagelist
, wxIMAGE_LIST_SMALL
);
159 CreateChildrenPrivately(list
);
165 long wxListCtrlXmlHandler::GetImageIndex(wxListCtrl
*listctrl
, int which
)
167 // use different tag names depending on whether we need a normal or small
174 case wxIMAGE_LIST_SMALL
:
175 bmpParam
+= "-small";
176 imgParam
+= "-small";
179 case wxIMAGE_LIST_NORMAL
:
184 wxFAIL_MSG( "unsupported image list kind" );
188 // look for either bitmap or image tags
189 int imgIndex
= wxNOT_FOUND
;
190 if ( HasParam(bmpParam
) )
192 // we implicitly construct an image list containing the specified
194 wxBitmap bmp
= GetBitmap(bmpParam
, wxART_OTHER
);
196 // create the image list on demand for the first bitmap
197 wxImageList
*imgList
= listctrl
->GetImageList(which
);
200 imgList
= new wxImageList( bmp
.GetWidth(), bmp
.GetHeight() );
201 listctrl
->AssignImageList( imgList
, which
);
204 imgIndex
= imgList
->Add(bmp
);
207 if ( HasParam(imgParam
) )
209 if ( imgIndex
!= wxNOT_FOUND
)
211 // TODO: we should really check that only bitmap or only image tags
212 // are used across all items of the control, not just in this
214 ReportError(wxString::Format(
215 "listitem %s attribute ignored because %s is also specified",
216 bmpParam
, imgParam
));
219 // just use the specified index directly
220 imgIndex
= GetLong(imgParam
);
226 #endif // wxUSE_XRC && wxUSE_LISTCTRL