All (GUI):
- wxWindow::SetAutoLayout() now works for all windows, not just panels.
-- Support loading wxListCtrl items and image lists from XRC (Kinaou Hervé).
+- Support wxListCtrl columns, items and image lists in XRC (Kinaou Hervé).
- wxGrid: add possibility to prevent resizing of individual rows/columns.
- wxHTML: add support for table borders width (Laurent Humbertclaude).
- Added wxMouseEventsManager.
@subsubsection xrc_wxlistctrl wxListCtrl
-A listctrl can have one or more child objects of the class @ref xrc_wxlistitem
+A list control can have one or more child objects of the class @ref xrc_wxlistitem
and one or more objects of the @ref xrc_wximagelist class. The latter is
defined either using @c \<imagelist\> tag for the control with @c wxLC_ICON
style or using @c \<imagelist-small\> tag for the control with @c
wxLC_SMALL_ICON style.
-@subsubsection xrc_wxlistitem wxListItem
+Report mode list controls (i.e. created with @c wxLC_REPORT style) can in
+addition have one or more @ref xrc_wxlistcol child elements.
+
+@subsubsection xrc_wxlistcol listcol
+
+The @c listcol class can only be used for wxListCtrl children. It can have the
+following properties:
+@beginTable
+@hdr3col{property, type, description}
+@row3col{align, wxListColumnFormat,
+ The alignment for the item.
+ Can be one of @c wxLIST_FORMAT_LEFT, @c wxLIST_FORMAT_RIGHT or
+ @c wxLIST_FORMAT_CENTRE.}
+@row3col{text, @ref overview_xrcformat_type_string,
+ The title of the column. }
+@row3col{width, integer,
+ The column width. }
+@endTable
+
+The columns are appended to the control in order of their appearance and may be
+referenced by 0-based index in the @c col attributes of subsequent @c listitem
+objects.
+
+@subsubsection xrc_wxlistitem listitem
The @c listitem is a child object for the class @ref xrc_wxlistctrl.
It can have the following properties:
Add a bitmap in the 'small' @ref xrc_wximagelist associated with the
@ref xrc_wxlistctrl parent and associate it with this item.
If the 'small' imagelist is not defined it will be created implicitly.}
+@row3col{col, integer,
+ The zero-based column index.}
@row3col{image, integer,
The zero-based index of the image associated with the item
in the (normal) image list.}
@row3col{image-small, integer,
The zero-based index of the image associated with the item
in the 'small' image list.}
-@row3col{col, integer,
- The zero-based column index.}
@row3col{data, integer,
The client data for the item.}
@row3col{font, @ref overview_xrcformat_type_font,
@row3col{image, integer,
The zero-based index of the image associated with the item
into the image list.}
-@row3col{mask, @ref overview_xrcformat_type_style,
- The mask indicating which fields of this class are valid.
- Can be any combination of the following values:
- - wxLIST_MASK_STATE: @b GetState is valid.
- - wxLIST_MASK_TEXT: @b GetText is valid.
- - wxLIST_MASK_IMAGE: @b GetImage is valid.
- - wxLIST_MASK_DATA: @b GetData is valid.
- - wxLIST_MASK_WIDTH: @b GetWidth is valid.
- - wxLIST_MASK_FORMAT: @b GetFormat is valid. }
@row3col{state, @ref overview_xrcformat_type_style,
- The item state flags (note that the valid state flags are influenced
- by the value of the @c statemask, see below).
- Can be any combination of the following values:
+ The item state. Can be any combination of the following values:
- @c wxLIST_STATE_FOCUSED: The item has the focus.
- @c wxLIST_STATE_SELECTED: The item is selected.
- - @c wxLIST_STATE_DONTCARE: Don't care what the state is. Win32 only.
- - @c wxLIST_STATE_DROPHILITED: The item is highlighted to receive a drop event. Win32 only.
- - @c wxLIST_STATE_CUT: The item is in the cut state. Win32 only. }
-@row3col{statemask, bitlist,
- A mask indicating which state flags are valid. This is a bitlist of the
- flags reported above for the item state. }
@row3col{text, @ref overview_xrcformat_type_string,
- The text label (or header for columns) for the item. }
+ The text label for the item. }
@row3col{textcolour, @ref overview_xrcformat_type_colour,
The text colour for the item. }
-@row3col{width, integer,
- The column width. }
@endTable
Notice that the item position can't be specified here, the items are appended
#if wxUSE_XRC && wxUSE_LISTCTRL
class WXDLLIMPEXP_FWD_CORE wxListCtrl;
+class WXDLLIMPEXP_FWD_CORE wxListItem;
class WXDLLIMPEXP_XRC wxListCtrlXmlHandler : public wxXmlResourceHandler
{
virtual bool CanHandle(wxXmlNode *node);
private:
- long Handle_wxListItem();
- wxObject* Handle_wxListCtrl();
+ // handlers for wxListCtrl itself and its listcol and listitem children
+ wxListCtrl *HandleListCtrl();
+ void HandleListCol();
+ void HandleListItem();
+
+ // common part to HandleList{Col,Item}()
+ void HandleCommonItemAttrs(wxListItem& item);
// gets the items image index in the corresponding image list (normal if
// which is wxIMAGE_LIST_NORMAL or small if it is wxIMAGE_LIST_SMALL)
wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("controls_dialog"));
#if wxUSE_LISTCTRL
- // There is no data in the listctrl. This will add some columns
- // and some data. You don't need to use any pointers
- // at all to manipulate the controls, just simply use the XRCCTL(...) macros.
- // "controls_treectrl" is the name of this control in the XRC.
- // (1) Insert a column, with the column header of "Name"
- // (The '_' function around "Name" marks this string as one to translate).
- XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertColumn( 0,
- _("Name"),
- wxLIST_FORMAT_LEFT,
- ( 200 )
- );
- // (2) Insert some items into the listctrl
- XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(0,wxT("Todd Hope"));
- XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(1,wxT("Kim Wynd"));
- XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(2,wxT("Leon Li"));
-#endif
+ // The resource file specifies the columns of the control as they are
+ // typically static while the items themselves are added from here as
+ // usually they are not static (but if they are, they can be defined in the
+ // resources too, see the two other list controls definitions in
+ // controls.xrc)
+
+ // Insert some items into the listctrl: notice that we can access it using
+ // XRCCTRL
+ wxListCtrl * const list = XRCCTRL(dlg, "controls_listctrl", wxListCtrl);
+
+ list->InsertItem(0, "Athos"); list->SetItem(0, 1, "90");
+ list->InsertItem(1, "Porthos"); list->SetItem(1, 1, "120");
+ list->InsertItem(2, "Aramis"); list->SetItem(2, 1, "80");
+#endif // wxUSE_LISTCTRL
#if wxUSE_TREECTRL
// There is no data in the tree ctrl. These lines will add some.
<border>5</border>
<object class="wxListCtrl" name="controls_listctrl">
<size>220,160</size>
- <style>wxLC_REPORT</style>
- <!-- this control is filled in from the code -->
+ <style>wxLC_REPORT|wxBORDER_SIMPLE</style>
+ <object class="listcol">
+ <text>Name</text>
+ <width>150</width>
+ </object>
+ <object class="listcol">
+ <text>Weight</text>
+ <align>wxLIST_FORMAT_RIGHT</align>
+ <width>50</width>
+ </object>
+ <!-- the items are added from the code -->
</object>
</object>
<object class="sizeritem">
<border>5</border>
<object class="wxListCtrl" name="controls_listctrl2">
<size>220,160</size>
- <style>wxLC_ICON</style>
+ <style>wxLC_ICON|wxBORDER_SIMPLE</style>
<object class="listitem">
<text>Information</text>
<bitmap stock_id="wxART_INFORMATION"/>
<border>5</border>
<object class="wxListCtrl" name="controls_listctrl3">
<size>220,160</size>
- <style>wxLC_SMALL_ICON</style>
+ <style>wxLC_SMALL_ICON|wxBORDER_SIMPLE</style>
<imagelist-small>
<size>20,20</size>
<bitmap stock_id="wxART_INFORMATION"/>
/////////////////////////////////////////////////////////////////////////////
// Name: src/xrc/xh_listc.cpp
// Purpose: XRC resource for wxListCtrl
-// Author: Brian Gavin
+// Author: Brian Gavin, Kinaou Hervé, Vadim Zeitlin
// Created: 2000/09/09
// RCS-ID: $Id$
// Copyright: (c) 2000 Brian Gavin
+// (c) 2009 Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/listctrl.h"
#include "wx/imaglist.h"
+namespace
+{
+
+const char *LISTCTRL_CLASS_NAME = "wxListCtrl";
+const char *LISTITEM_CLASS_NAME = "listitem";
+const char *LISTCOL_CLASS_NAME = "listcol";
+
+} // anonymous namespace
+
IMPLEMENT_DYNAMIC_CLASS(wxListCtrlXmlHandler, wxXmlResourceHandler)
wxListCtrlXmlHandler::wxListCtrlXmlHandler()
-: wxXmlResourceHandler()
+ : wxXmlResourceHandler()
{
// wxListItem styles
XRC_ADD_STYLE(wxLIST_FORMAT_LEFT);
XRC_ADD_STYLE(wxLIST_MASK_DATA);
XRC_ADD_STYLE(wxLIST_MASK_WIDTH);
XRC_ADD_STYLE(wxLIST_MASK_FORMAT);
- XRC_ADD_STYLE(wxLIST_STATE_DONTCARE);
- XRC_ADD_STYLE(wxLIST_STATE_DROPHILITED);
XRC_ADD_STYLE(wxLIST_STATE_FOCUSED);
XRC_ADD_STYLE(wxLIST_STATE_SELECTED);
- XRC_ADD_STYLE(wxLIST_STATE_CUT);
// wxListCtrl styles
XRC_ADD_STYLE(wxLC_LIST);
wxObject *wxListCtrlXmlHandler::DoCreateResource()
{
- if (m_class == wxT("listitem"))
+ if ( m_class == LISTITEM_CLASS_NAME )
+ {
+ HandleListItem();
+ }
+ else if ( m_class == LISTCOL_CLASS_NAME )
{
- Handle_wxListItem();
- return m_parentAsWindow;
+ HandleListCol();
}
else
- return Handle_wxListCtrl();
+ {
+ wxASSERT_MSG( m_class == LISTCTRL_CLASS_NAME,
+ "can't handle unknown node" );
+
+ return HandleListCtrl();
+ }
+
+ return m_parentAsWindow;
}
bool wxListCtrlXmlHandler::CanHandle(wxXmlNode *node)
{
- return IsOfClass(node, wxT("wxListCtrl")) ||
- IsOfClass(node, wxT("listitem"));
+ return IsOfClass(node, LISTCTRL_CLASS_NAME) ||
+ IsOfClass(node, LISTITEM_CLASS_NAME) ||
+ IsOfClass(node, LISTCOL_CLASS_NAME);
}
-long wxListCtrlXmlHandler::Handle_wxListItem()
+void wxListCtrlXmlHandler::HandleCommonItemAttrs(wxListItem& item)
+{
+ if (HasParam(wxT("align")))
+ item.SetAlign((wxListColumnFormat)GetStyle(wxT("align")));
+ if (HasParam(wxT("text")))
+ item.SetText(GetText(wxT("text")));
+}
+
+void wxListCtrlXmlHandler::HandleListCol()
{
wxListCtrl * const list = wxDynamicCast(m_parentAsWindow, wxListCtrl);
- wxCHECK_MSG( list, -1, "must have wxListCtrl parent" );
+ wxCHECK_RET( list, "must have wxListCtrl parent" );
+
+ if ( !list->HasFlag(wxLC_REPORT) )
+ {
+ ReportError("Only report mode list controls can have columns.");
+ return;
+ }
wxListItem item;
- if (HasParam(wxT("align")))
- item.SetAlign((wxListColumnFormat)GetStyle(wxT("align")));
+ HandleCommonItemAttrs(item);
+ if (HasParam(wxT("width")))
+ item.SetWidth((int)GetLong(wxT("width")));
+
+ list->InsertColumn(list->GetColumnCount(), item);
+}
+
+void wxListCtrlXmlHandler::HandleListItem()
+{
+ wxListCtrl * const list = wxDynamicCast(m_parentAsWindow, wxListCtrl);
+ wxCHECK_RET( list, "must have wxListCtrl parent" );
+
+ wxListItem item;
+
+ HandleCommonItemAttrs(item);
+
if (HasParam(wxT("bg")))
item.SetBackgroundColour(GetColour(wxT("bg")));
if (HasParam(wxT("col")))
item.SetData(GetLong(wxT("data")));
if (HasParam(wxT("font")))
item.SetFont(GetFont());
- if (HasParam(wxT("mask")))
- item.SetMask(GetStyle(wxT("mask")));
if (HasParam(wxT("state")))
item.SetState(GetStyle(wxT("state")));
- if (HasParam(wxT("statemask")))
- item.SetStateMask(GetStyle(wxT("statemask")));
- if (HasParam(wxT("text")))
- item.SetText(GetText(wxT("text")));
if (HasParam(wxT("textcolour")))
item.SetTextColour(GetColour(wxT("textcolour")));
if (HasParam(wxT("textcolor")))
item.SetTextColour(GetColour(wxT("textcolor")));
- if (HasParam(wxT("width")))
- item.SetWidth((int)GetLong(wxT("width")));
// the list control icon style, may be 0
int image;
// append the list item to the control
item.SetId(list->GetItemCount());
- return list->InsertItem(item);
+ list->InsertItem(item);
}
-wxObject* wxListCtrlXmlHandler::Handle_wxListCtrl()
+wxListCtrl *wxListCtrlXmlHandler::HandleListCtrl()
{
XRC_MAKE_INSTANCE(list, wxListCtrl)