[wx-dev] custom controls in file dialog, was: Minimum GTK+ 2.X requirement for wxWidgets 3.0

Marcin Wojdyr wojdyr at gmail.com
Sat Nov 3 09:50:51 PDT 2007


On Nov 2, 2007 8:57 PM, robert at roebling.de <robert at roebling.de> wrote:
>
> > On GTK the main problem is taking gtk widget from wxWindow -
> > it somehow works using the same hacks as in wxNotebook
> > (what implies that the control that is added must be a child
> > of wxFileDialog).
>
> Could you specify what problem you means, what "hack"

I meant:
1. setting m_insertCallback (overwritting wxInsertChildInWindow).
2. unparenting. Quote from src/gtk/notebook.cpp:
    // Hack Alert! (Part II): See above in wxInsertChildInNotebook callback
    // why this has to be done.  NOTE: using gtk_widget_unparent here does not
    // work as it seems to undo too much and will cause errors in the
    // gtk_notebook_insert_page below, so instead just clear the parent by
    // hand here.
    win->m_widget->parent = NULL;
This is enough to add custom control (or wxPanel with controls) to
wxFileDialog, although I haven't tested if everything works yet.

Is there another way to do this?

> you mean and in what why this will limit the functionality.

I don't think it will limit functionality, the only limitation is that
window that is to be added to wxFileDialog must be a child of
wxFileDialog. It may complicate things if wxFileDialog has other
childs. But I'm not an expert here.

> Indeed, knowing the rough API would also be helpful
> in finding a solution.

The most natural API for me was analogous to set_extra_widget() in GTK:

bool wxFileDialog::SetExtraControl(wxWindow *win)

Add extra window to the file dialog. The window is typically placed
below the list of files and above the buttons.
SetExtraControl can be called only once, before the file dialog is
shown. Extra window must have wxFileDialog as a parent. If the
function returns true, do not explicitly delete the window, it is
managed by wxFileDialog.
Return value:
 true if there is a support for extra controls.

and it can be used in this way:

wxFileDialog fdlg(...);
wxPanel *panel_with_custom_controls = ...
if (!fdlg.SetExtraControl(panel_with_custom_controls) {
    // use a separate dialog to show the panel before or
    // after the file dialog is shown
}


Marcin

-- 
Marcin Wojdyr | http://www.unipress.waw.pl/~wojdyr/




More information about the wx-dev mailing list