Modifying wxGenericDirCtrl

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 ? Ask them here.
Post Reply
Rocketmagnet
Experienced Solver
Experienced Solver
Posts: 84
Joined: Wed Aug 09, 2006 11:14 pm
Location: London
Contact:

Modifying wxGenericDirCtrl

Post 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));
    }

};
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Modifying wxGenericDirCtrl

Post 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.
Rocketmagnet
Experienced Solver
Experienced Solver
Posts: 84
Joined: Wed Aug 09, 2006 11:14 pm
Location: London
Contact:

Re: Modifying wxGenericDirCtrl

Post 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
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Modifying wxGenericDirCtrl

Post 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.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Rocketmagnet
Experienced Solver
Experienced Solver
Posts: 84
Joined: Wed Aug 09, 2006 11:14 pm
Location: London
Contact:

Re: Modifying wxGenericDirCtrl

Post 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.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Modifying wxGenericDirCtrl

Post 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.
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Modifying wxGenericDirCtrl

Post 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.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Post Reply