[litwindow-users] Re: wxListCtrl and library status
Status: Alpha
Brought to you by:
hajokirchhoff
From: Hajo K. <mai...@ha...> - 2005-04-17 17:55:57
|
yrs90 wrote: > I have left the existing interface the same, making minimal modifications > and additions to handle multi-columns. I am not yet comfortable with how > much of the interface can/should be modified. > > I have no idea either. We'll just have to wait and see. > flawed. I thought it would be nice to pass an aggregate to a function, say > SetColumns(), and have the columns created from the struct elements. Take a look at wxTextCtrl. It accepts an accessor as a parameter, much like you are planning to do with SetColumns. As for the internal names I would suggest a new properties: ColumnTitles, perhaps even a combination of title-member variable name. Example: ListCtrl.ColumnTitles:="m_id=ID, m_name=Name" where the string consists of membername=columnheader pairs separated by a , > I made enough progress that my ListCtrl without distinct columns is being > populated. This was a straightforward modeled after wxListBox. When I tried > to extend it to include columns I encountered two problems. First, I tried > to add two functions, SetColumns and GetColumns. > > Class wxListCtrlAdapter { > ... > void SetColumns(const accessor &newValue); > const accessor &GetColumns() const; > ... > } > > BEGIN_ADAPTER_NO_COPY(wxListCtrlAdapter) > PROP_I(lwListAdapterBase) > PROP_GetSet(accessor, Columns) > END_ADAPTER() > > However, when I create a rule: > > RULE("m_IPListWindow.Columns", make_expr<accessor>("m_targetlist")) > > I get an error thrown stating that the "GetAccessor couldn't find a variable > ' m_IPListWindow.Columns'" > > Yes, you overlooked one important point. You have created a data adapter for the wxListCtrlAdapter, but I guess that you haven't created a data adapter for wxListCtrl itself. I call the concept behind this a 'co-object'. Essentially you are trying to extend wxListCtrl, but without modifying the wxListCtrl sources. So I introduced a wxSomethingAdapter class that contains the extensions. The following code binds this adapter class to the original class: BEGIN_ADAPTER_NO_COPY(wxListCtrl) PROP_CO(wxListCtrlAdapter) PROP_I(wxControl) END_ADAPTER() It is almost as if you are adding a new superclass wxListCtrlAdapter to wxListCtrl. While the C++ inheritance looks like this: class wxListCtrl:public wxControl the data adapter inheritance is this: class wxListCtrl:public wxListCtrlAdapter, public wxControl In other words, when a wxListCtrl object is accessed through a data adapter, it 'inherites' not only wxControl properties but also wxListCtrlAdapter properties. Have a look at base_objects.cpp and how this is done with the wxListBoxAdapter. In order to make this work, the co-object mechanism needs a way to create the co-object and attach it to the original object. This is done through template overloading, which tells the mechanism to call 'new wxListCtrlAdapter' the first time the PROP_CO(wxListCtrlAdapter) is seen. The pointer to this object must then be stored someplace. I currently attach the new adapter object as a handler to the original wxWidgets object and destroy the object when the wxEVT_DESTROY_WINDOW event comes my way. Just take a close look at the connection between BEGIN_ADAPTER_NO_COPY(wxListBox) and BEGIN_ADAPTER_NO_COPY(wxListBoxAdapter). The template overloading function is somewere there. > My second problem, is one related to my original design. I am not sure how > to initialize the columns if I don't have an instance of the aggregate to > pass. Perhaps, though, there is a better way to pass the column names and > associations between the columns and the aggregate contents. Any > suggestions on this front? > > You could create the ColumnHeader property I described above if you want to create the columns before you actually pass in a container. But keep in mind that the columns of the control might change over time. So I'd create them only after I actually have a container and change them everytime the element type of the container changes. Regards, and thanks for your work. It is very appreciated. Hajo |