add support for defining list control columns in XRC too (and correct a few things in previously added list items support)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60738 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-05-25 13:00:28 +00:00
parent 9cd203f776
commit ef18e79223
6 changed files with 128 additions and 73 deletions

View File

@@ -334,7 +334,7 @@ All:
All (GUI): All (GUI):
- wxWindow::SetAutoLayout() now works for all windows, not just panels. - wxWindow::SetAutoLayout() now works for all windows, not just panels.
- Support loading wxListCtrl items and image lists from XRC (Kinaou Herv<72>). - Support wxListCtrl columns, items and image lists in XRC (Kinaou Herv<72>).
- wxGrid: add possibility to prevent resizing of individual rows/columns. - wxGrid: add possibility to prevent resizing of individual rows/columns.
- wxHTML: add support for table borders width (Laurent Humbertclaude). - wxHTML: add support for table borders width (Laurent Humbertclaude).
- Added wxMouseEventsManager. - Added wxMouseEventsManager.

View File

@@ -959,13 +959,36 @@ Each @c listbookpage has exactly one non-toplevel window as its child.
@subsubsection xrc_wxlistctrl wxListCtrl @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 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 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 style or using @c \<imagelist-small\> tag for the control with @c
wxLC_SMALL_ICON style. 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. The @c listitem is a child object for the class @ref xrc_wxlistctrl.
It can have the following properties: It can have the following properties:
@@ -986,14 +1009,14 @@ It can have the following properties:
Add a bitmap in the 'small' @ref xrc_wximagelist associated with the Add a bitmap in the 'small' @ref xrc_wximagelist associated with the
@ref xrc_wxlistctrl parent and associate it with this item. @ref xrc_wxlistctrl parent and associate it with this item.
If the 'small' imagelist is not defined it will be created implicitly.} If the 'small' imagelist is not defined it will be created implicitly.}
@row3col{col, integer,
The zero-based column index.}
@row3col{image, integer, @row3col{image, integer,
The zero-based index of the image associated with the item The zero-based index of the image associated with the item
in the (normal) image list.} in the (normal) image list.}
@row3col{image-small, integer, @row3col{image-small, integer,
The zero-based index of the image associated with the item The zero-based index of the image associated with the item
in the 'small' image list.} in the 'small' image list.}
@row3col{col, integer,
The zero-based column index.}
@row3col{data, integer, @row3col{data, integer,
The client data for the item.} The client data for the item.}
@row3col{font, @ref overview_xrcformat_type_font, @row3col{font, @ref overview_xrcformat_type_font,
@@ -1001,33 +1024,14 @@ It can have the following properties:
@row3col{image, integer, @row3col{image, integer,
The zero-based index of the image associated with the item The zero-based index of the image associated with the item
into the image list.} 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, @row3col{state, @ref overview_xrcformat_type_style,
The item state flags (note that the valid state flags are influenced The item state. Can be any combination of the following values:
by the value of the @c statemask, see below).
Can be any combination of the following values:
- @c wxLIST_STATE_FOCUSED: The item has the focus. - @c wxLIST_STATE_FOCUSED: The item has the focus.
- @c wxLIST_STATE_SELECTED: The item is selected. - @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, @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, @row3col{textcolour, @ref overview_xrcformat_type_colour,
The text colour for the item. } The text colour for the item. }
@row3col{width, integer,
The column width. }
@endTable @endTable
Notice that the item position can't be specified here, the items are appended Notice that the item position can't be specified here, the items are appended

View File

@@ -16,6 +16,7 @@
#if wxUSE_XRC && wxUSE_LISTCTRL #if wxUSE_XRC && wxUSE_LISTCTRL
class WXDLLIMPEXP_FWD_CORE wxListCtrl; class WXDLLIMPEXP_FWD_CORE wxListCtrl;
class WXDLLIMPEXP_FWD_CORE wxListItem;
class WXDLLIMPEXP_XRC wxListCtrlXmlHandler : public wxXmlResourceHandler class WXDLLIMPEXP_XRC wxListCtrlXmlHandler : public wxXmlResourceHandler
{ {
@@ -25,8 +26,13 @@ public:
virtual bool CanHandle(wxXmlNode *node); virtual bool CanHandle(wxXmlNode *node);
private: private:
long Handle_wxListItem(); // handlers for wxListCtrl itself and its listcol and listitem children
wxObject* Handle_wxListCtrl(); 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 // 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) // which is wxIMAGE_LIST_NORMAL or small if it is wxIMAGE_LIST_SMALL)

View File

@@ -207,22 +207,20 @@ void MyFrame::OnControlsToolOrMenuCommand(wxCommandEvent& WXUNUSED(event))
wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("controls_dialog")); wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("controls_dialog"));
#if wxUSE_LISTCTRL #if wxUSE_LISTCTRL
// There is no data in the listctrl. This will add some columns // The resource file specifies the columns of the control as they are
// and some data. You don't need to use any pointers // typically static while the items themselves are added from here as
// at all to manipulate the controls, just simply use the XRCCTL(...) macros. // usually they are not static (but if they are, they can be defined in the
// "controls_treectrl" is the name of this control in the XRC. // resources too, see the two other list controls definitions in
// (1) Insert a column, with the column header of "Name" // controls.xrc)
// (The '_' function around "Name" marks this string as one to translate).
XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertColumn( 0, // Insert some items into the listctrl: notice that we can access it using
_("Name"), // XRCCTRL
wxLIST_FORMAT_LEFT, wxListCtrl * const list = XRCCTRL(dlg, "controls_listctrl", wxListCtrl);
( 200 )
); list->InsertItem(0, "Athos"); list->SetItem(0, 1, "90");
// (2) Insert some items into the listctrl list->InsertItem(1, "Porthos"); list->SetItem(1, 1, "120");
XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(0,wxT("Todd Hope")); list->InsertItem(2, "Aramis"); list->SetItem(2, 1, "80");
XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(1,wxT("Kim Wynd")); #endif // wxUSE_LISTCTRL
XRCCTRL(dlg, "controls_listctrl", wxListCtrl)->InsertItem(2,wxT("Leon Li"));
#endif
#if wxUSE_TREECTRL #if wxUSE_TREECTRL
// There is no data in the tree ctrl. These lines will add some. // There is no data in the tree ctrl. These lines will add some.

View File

@@ -584,8 +584,17 @@
<border>5</border> <border>5</border>
<object class="wxListCtrl" name="controls_listctrl"> <object class="wxListCtrl" name="controls_listctrl">
<size>220,160</size> <size>220,160</size>
<style>wxLC_REPORT</style> <style>wxLC_REPORT|wxBORDER_SIMPLE</style>
<!-- this control is filled in from the code --> <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> </object>
<object class="sizeritem"> <object class="sizeritem">
@@ -593,7 +602,7 @@
<border>5</border> <border>5</border>
<object class="wxListCtrl" name="controls_listctrl2"> <object class="wxListCtrl" name="controls_listctrl2">
<size>220,160</size> <size>220,160</size>
<style>wxLC_ICON</style> <style>wxLC_ICON|wxBORDER_SIMPLE</style>
<object class="listitem"> <object class="listitem">
<text>Information</text> <text>Information</text>
<bitmap stock_id="wxART_INFORMATION"/> <bitmap stock_id="wxART_INFORMATION"/>
@@ -609,7 +618,7 @@
<border>5</border> <border>5</border>
<object class="wxListCtrl" name="controls_listctrl3"> <object class="wxListCtrl" name="controls_listctrl3">
<size>220,160</size> <size>220,160</size>
<style>wxLC_SMALL_ICON</style> <style>wxLC_SMALL_ICON|wxBORDER_SIMPLE</style>
<imagelist-small> <imagelist-small>
<size>20,20</size> <size>20,20</size>
<bitmap stock_id="wxART_INFORMATION"/> <bitmap stock_id="wxART_INFORMATION"/>

View File

@@ -1,10 +1,11 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: src/xrc/xh_listc.cpp // Name: src/xrc/xh_listc.cpp
// Purpose: XRC resource for wxListCtrl // Purpose: XRC resource for wxListCtrl
// Author: Brian Gavin // Author: Brian Gavin, Kinaou Hervé, Vadim Zeitlin
// Created: 2000/09/09 // Created: 2000/09/09
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 2000 Brian Gavin // Copyright: (c) 2000 Brian Gavin
// (c) 2009 Vadim Zeitlin
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@@ -26,6 +27,15 @@
#include "wx/listctrl.h" #include "wx/listctrl.h"
#include "wx/imaglist.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) IMPLEMENT_DYNAMIC_CLASS(wxListCtrlXmlHandler, wxXmlResourceHandler)
@@ -42,11 +52,8 @@ wxListCtrlXmlHandler::wxListCtrlXmlHandler()
XRC_ADD_STYLE(wxLIST_MASK_DATA); XRC_ADD_STYLE(wxLIST_MASK_DATA);
XRC_ADD_STYLE(wxLIST_MASK_WIDTH); XRC_ADD_STYLE(wxLIST_MASK_WIDTH);
XRC_ADD_STYLE(wxLIST_MASK_FORMAT); 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_FOCUSED);
XRC_ADD_STYLE(wxLIST_STATE_SELECTED); XRC_ADD_STYLE(wxLIST_STATE_SELECTED);
XRC_ADD_STYLE(wxLIST_STATE_CUT);
// wxListCtrl styles // wxListCtrl styles
XRC_ADD_STYLE(wxLC_LIST); XRC_ADD_STYLE(wxLC_LIST);
@@ -71,30 +78,69 @@ wxListCtrlXmlHandler::wxListCtrlXmlHandler()
wxObject *wxListCtrlXmlHandler::DoCreateResource() wxObject *wxListCtrlXmlHandler::DoCreateResource()
{ {
if (m_class == wxT("listitem")) if ( m_class == LISTITEM_CLASS_NAME )
{ {
Handle_wxListItem(); HandleListItem();
return m_parentAsWindow; }
else if ( m_class == LISTCOL_CLASS_NAME )
{
HandleListCol();
} }
else 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) bool wxListCtrlXmlHandler::CanHandle(wxXmlNode *node)
{ {
return IsOfClass(node, wxT("wxListCtrl")) || return IsOfClass(node, LISTCTRL_CLASS_NAME) ||
IsOfClass(node, wxT("listitem")); 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); 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; wxListItem item;
if (HasParam(wxT("align"))) HandleCommonItemAttrs(item);
item.SetAlign((wxListColumnFormat)GetStyle(wxT("align"))); 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"))) if (HasParam(wxT("bg")))
item.SetBackgroundColour(GetColour(wxT("bg"))); item.SetBackgroundColour(GetColour(wxT("bg")));
if (HasParam(wxT("col"))) if (HasParam(wxT("col")))
@@ -103,20 +149,12 @@ long wxListCtrlXmlHandler::Handle_wxListItem()
item.SetData(GetLong(wxT("data"))); item.SetData(GetLong(wxT("data")));
if (HasParam(wxT("font"))) if (HasParam(wxT("font")))
item.SetFont(GetFont()); item.SetFont(GetFont());
if (HasParam(wxT("mask")))
item.SetMask(GetStyle(wxT("mask")));
if (HasParam(wxT("state"))) if (HasParam(wxT("state")))
item.SetState(GetStyle(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"))) if (HasParam(wxT("textcolour")))
item.SetTextColour(GetColour(wxT("textcolour"))); item.SetTextColour(GetColour(wxT("textcolour")));
if (HasParam(wxT("textcolor"))) if (HasParam(wxT("textcolor")))
item.SetTextColour(GetColour(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 // the list control icon style, may be 0
int image; int image;
@@ -133,10 +171,10 @@ long wxListCtrlXmlHandler::Handle_wxListItem()
// append the list item to the control // append the list item to the control
item.SetId(list->GetItemCount()); item.SetId(list->GetItemCount());
return list->InsertItem(item); list->InsertItem(item);
} }
wxObject* wxListCtrlXmlHandler::Handle_wxListCtrl() wxListCtrl *wxListCtrlXmlHandler::HandleListCtrl()
{ {
XRC_MAKE_INSTANCE(list, wxListCtrl) XRC_MAKE_INSTANCE(list, wxListCtrl)