Page 1 of 1

Modifying wxGenericDirCtrl

Posted: Thu Feb 01, 2018 5:34 pm
by Rocketmagnet
Hi,

I'd like to modify the way wxGenericDirCtrl behaves. Specifically, I'd like the option to sort directories by date, rather than alphabetically.

I have tried to inherit from it, so that I can overload ExpandDir() (which is virtual, so I guess it's designed to be overloaded), and have it call a different version of PopulateNode(). However, I hit a couple of problems.

1. All of the member variables of wxGenericDirCtrl are private, so my new class doesn't have access to them.
2. Even when I sneakily changed them to protected, my new ExpandDir() function wasn't called.

My questions are:
1. Am I doing something wrong here? Is there some correct way to overload wxGenericDirCtrl::ExpandDir()?
2. Has anyone ever tried something similar?
3. Why are some of wxGenericDirCtrl's functions virtual, while all of its member functions are private?

Thanks
Hugo

Code: Select all

class PowerDirCtrl : public wxGenericDirCtrl
{
public:

    PowerDirCtrl(      wxWindow    *parent,
                       wxWindowID   id            = wxID_ANY,
                 const wxString    &dir           = wxDirDialogDefaultFolderStr,
                 const wxPoint&     pos           = wxDefaultPosition,
                 const wxSize&      size          = wxDefaultSize,
                       long         style         = wxDIRCTRL_DEFAULT_STYLE,
                 const wxString    &filter        = wxEmptyString,
                       int          defaultFilter = 0,
                 const wxString    &name          = wxTreeCtrlNameStr)
        :wxGenericDirCtrl(parent, id, dir, pos, size, style, filter, defaultFilter, name)
    {
        //Init();
        //Create(parent, id, dir, pos, size, style, filter, defaultFilter, name);
    }


    void ExpandDir(wxTreeItemId parentId)
    {
        PopulateNode2(parentId);
    }

private:
    void PopulateNode2(wxTreeItemId node);

    wxDirItemData* GetItemData2(wxTreeItemId itemId)
    {
        return static_cast<wxDirItemData*>(m_treeCtrl->GetItemData(itemId));
    }

};

Re: Modifying wxGenericDirCtrl

Posted: Thu Feb 01, 2018 6:54 pm
by ONEEYEMAN
Hi,
Are you looking for a Windows version?
Will this be configurable?

In any case - questions 1 and 3 belong to the wx-dev ML. This forum is for wxWidgets users and no wx core developers are here.

Thank you.

Re: Modifying wxGenericDirCtrl

Posted: Thu Feb 01, 2018 7:59 pm
by Rocketmagnet
Hi ONEEYEMAN,

I'm surprised, since many of the questions I see in this forum seem to be along similar lines, about modifying the behaviour of wx classes. Indeed, the description of this forum:
Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from
I thought that's what I was doing? I am not a core developer. Anyhow, I'll take my question there.

Thanks

Re: Modifying wxGenericDirCtrl

Posted: Thu Feb 01, 2018 8:29 pm
by eranon
Rocketmagnet wrote: 3. Why are some of wxGenericDirCtrl's functions virtual, while all of its member functions are private?
Hello, I don't know the wxWidgets specific reason/design, but in general (at least in C++) there's no contradiction between private and virtual. Private means it will be not callable by its derived classes, while virtual means every derived class can write its own version. Otherwise said, it's absolutely legitimate to override a private method even if the concerned derived class cannot call the base version.

Re: Modifying wxGenericDirCtrl

Posted: Thu Feb 01, 2018 8:42 pm
by Rocketmagnet
eranon,

Sure, I can write my own function with the same name etc., but I cannot override it, in the sense that other functions of the base class will still call the original function, and will not call my new one. For those functions to call my new code will require a virtual function.

Re: Modifying wxGenericDirCtrl

Posted: Thu Feb 01, 2018 8:51 pm
by ONEEYEMAN
Hi,
The reason I sent you to the ML is that you are extending the one of the wxWidgets classes to write your own implementation.
Therefore all design issues on the wxGenericDirCtrl should be answered by wx core devs.

I can only guess/speculate that the design is just a follow of the native wxDirCtrl.

Thank you.

Re: Modifying wxGenericDirCtrl

Posted: Thu Feb 01, 2018 9:08 pm
by eranon
Rocketmagnet wrote:eranon, [...]
As ONEEYEMAN states above, it's not the right place to talk about code design, but here are some lightning links about private virtual method in C++: http://google.fr/search?q=private+virtu ... in+c%2B%2B.