]> git.saurik.com Git - wxWidgets.git/commitdiff
add support for defining list control columns in XRC too (and correct a few things...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 25 May 2009 13:00:28 +0000 (13:00 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 25 May 2009 13:00:28 +0000 (13:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60738 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/doxygen/overviews/xrc_format.h
include/wx/xrc/xh_listc.h
samples/xrc/myframe.cpp
samples/xrc/rc/controls.xrc
src/xrc/xh_listc.cpp

index d94c3c86dd90be03d1bea5c211c45d1971a9f65a..4f525f48a8edbd87ba47687157125f8fbed0fdb0 100644 (file)
@@ -334,7 +334,7 @@ All:
 All (GUI):
 
 - wxWindow::SetAutoLayout() now works for all windows, not just panels.
 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.
 - wxGrid: add possibility to prevent resizing of individual rows/columns.
 - wxHTML: add support for table borders width (Laurent Humbertclaude).
 - Added wxMouseEventsManager.
index bc07cb0c45589c874e9ff1cb0545a475f15c222d..aeb6780ad15a07e6131d65c9cd2949c8e20d9102 100644 (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
 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.
 
 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:
 
 The @c listitem is a child object for the class @ref xrc_wxlistctrl.
 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
     @ref xrc_wxlistctrl parent and associate it with this item.
     If the 'small' imagelist is not defined it will be created implicitly.}
     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{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{data, integer,
     The client data for the item.}
 @row3col{font, @ref overview_xrcformat_type_font,
@@ -1001,33 +1024,14 @@ It can have the following properties:
 @row3col{image, integer,
     The zero-based index of the image associated with the item
     into the image list.}
 @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,
 @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_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,
 @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{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
 @endTable
 
 Notice that the item position can't be specified here, the items are appended
index 5ca936f28bb1382ae8dfe35a4881647077aea254..ecb38b67615ac5b995fbc2573bce73705b36a423 100644 (file)
@@ -16,6 +16,7 @@
 #if wxUSE_XRC && wxUSE_LISTCTRL
 
 class WXDLLIMPEXP_FWD_CORE wxListCtrl;
 #if wxUSE_XRC && wxUSE_LISTCTRL
 
 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);
 
 private:
     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)
 
     // 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)
index 3a6453d3e8461956b370c4164aa6a210401f9ff3..175d883bae04cb49370dd3c08cec5ee7a4865879 100644 (file)
@@ -207,22 +207,20 @@ void MyFrame::OnControlsToolOrMenuCommand(wxCommandEvent& WXUNUSED(event))
     wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("controls_dialog"));
 
 #if wxUSE_LISTCTRL
     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.
 
 #if wxUSE_TREECTRL
     // There is no data in the tree ctrl. These lines will add some.
index c93c7d9cdc638fa98fe4ab2d2e19cdb473cdc61e..3ce4f099fdb77db3098ad29f3b839c9fc1feedae 100644 (file)
                                 <border>5</border>
                                 <object class="wxListCtrl" name="controls_listctrl">
                                     <size>220,160</size>
                                 <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">
                                 </object>
                             </object>
                             <object class="sizeritem">
                                 <border>5</border>
                                 <object class="wxListCtrl" name="controls_listctrl2">
                                     <size>220,160</size>
                                 <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"/>
                                     <object class="listitem">
                                         <text>Information</text>
                                         <bitmap stock_id="wxART_INFORMATION"/>
                                 <border>5</border>
                                 <object class="wxListCtrl" name="controls_listctrl3">
                                     <size>220,160</size>
                                 <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"/>
                                     <imagelist-small>
                                         <size>20,20</size>
                                         <bitmap stock_id="wxART_INFORMATION"/>
index db99373ef725ab6c974c968229e0fbc5636e53db..a6499e422aa3c91e967892019fc809235fd56d55 100644 (file)
@@ -1,10 +1,11 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        src/xrc/xh_listc.cpp
 // Purpose:     XRC resource for wxListCtrl
 /////////////////////////////////////////////////////////////////////////////
 // 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
 // Created:     2000/09/09
 // RCS-ID:      $Id$
 // Copyright:   (c) 2000 Brian Gavin
+//              (c) 2009 Vadim Zeitlin
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/listctrl.h"
 #include "wx/imaglist.h"
 
 #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()
 
 IMPLEMENT_DYNAMIC_CLASS(wxListCtrlXmlHandler, wxXmlResourceHandler)
 
 wxListCtrlXmlHandler::wxListCtrlXmlHandler()
-: wxXmlResourceHandler()
+    : wxXmlResourceHandler()
 {
     // wxListItem styles
     XRC_ADD_STYLE(wxLIST_FORMAT_LEFT);
 {
     // wxListItem styles
     XRC_ADD_STYLE(wxLIST_FORMAT_LEFT);
@@ -42,11 +52,8 @@ wxListCtrlXmlHandler::wxListCtrlXmlHandler()
     XRC_ADD_STYLE(wxLIST_MASK_DATA);
     XRC_ADD_STYLE(wxLIST_MASK_WIDTH);
     XRC_ADD_STYLE(wxLIST_MASK_FORMAT);
     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_FOCUSED);
     XRC_ADD_STYLE(wxLIST_STATE_SELECTED);
-    XRC_ADD_STYLE(wxLIST_STATE_CUT);
 
     // wxListCtrl styles
     XRC_ADD_STYLE(wxLC_LIST);
 
     // wxListCtrl styles
     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 )
+    {
+        HandleListItem();
+    }
+    else if ( m_class == LISTCOL_CLASS_NAME )
     {
     {
-        Handle_wxListItem();
-        return m_parentAsWindow;
+        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")) ||
-            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);
 {
     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")))
-        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")))
     if (HasParam(wxT("bg")))
         item.SetBackgroundColour(GetColour(wxT("bg")));
     if (HasParam(wxT("col")))
@@ -103,20 +149,12 @@ long wxListCtrlXmlHandler::Handle_wxListItem()
         item.SetData(GetLong(wxT("data")));
     if (HasParam(wxT("font")))
         item.SetFont(GetFont());
         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("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("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;
 
     // the list control icon style, may be 0
     int image;
@@ -133,10 +171,10 @@ long wxListCtrlXmlHandler::Handle_wxListItem()
     // append the list item to the control
     item.SetId(list->GetItemCount());
 
     // 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)
 
 {
     XRC_MAKE_INSTANCE(list, wxListCtrl)