Author Topic: Opening a window  (Read 5900 times)

Offline stardust

  • Multiple posting newcomer
  • *
  • Posts: 55
    • http://www.hightec-rt.com
Opening a window
« on: April 11, 2007, 10:09:02 am »
Hi,

in a plugin I intend to open a window to let the user enter some values.

As I am newbee, I had a peek at the sources of the code snippets plugin and how the windows stuff is implemented. So I tried to do the same: Derive a dialog from wxPanel and send a message to the dialog to let the window pop up. However, it does not work and I am clueless why no window is shown and C::B crashes.

This is the contructor:

Code
HtcToolchainConfigDialog::HtcToolchainConfigDialog (wxWindow * parent, int id)
: wxPanel (parent, id, wxDefaultPosition, wxDefaultSize)
{
Layout();
}
In a first step I just wanted an empty window and then work on that. To open i did
Code
void HtcToolchainPlugin::OnItemConfig (wxCommandEvent& event)
{
    if (!m_pConfigDialog)
        return;

    CodeBlocksDockEvent evt (cbEVT_SHOW_DOCK_WINDOW);
    evt.pWindow = m_pConfigDialog;
    Manager::Get()->GetAppWindow()->ProcessEvent (evt);
    Log (_("HTC: Config opened"));
}
Nothing happens except that C::B crashes when I exit...

===========================================

I then tried to use wxSmath for that and to make the dialog using the gui but that does not work either.

No windows comes up and C::B crashes *badly*: I coun not even login via ssh and had to hard reset my computer. Is tere som manual on the wxSmith stuff?

I am totally frustrated...

BTW: What is the ::Config method of the plugin for? There are no plugin configs in C::B's menues and the method has no effect and gets never called.
Own SVN builds (quite new) • SuSE Linux 10.0 • Linux kernel 2.6.13-15-default
gcc 4.0.2 (20050901)
wxGTK-2.6.1.0-4 • KDE 3.4.2b • gtk2 2.8.3-4

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Opening a window
« Reply #1 on: April 11, 2007, 02:24:23 pm »
As I am newbee, I had a peek at the sources of the code snippets plugin and how the windows stuff is implemented. So I tried to do the same: Derive a dialog from wxPanel and send a message to the dialog to let the window pop up. However, it does not work and I am clueless why no window is shown and C::B crashes.

This is the contructor:

Code
HtcToolchainConfigDialog::HtcToolchainConfigDialog (wxWindow * parent, int id)
: wxPanel (parent, id, wxDefaultPosition, wxDefaultSize)
{
Layout();
}
In a first step I just wanted an empty window and then work on that. To open i did
Code
void HtcToolchainPlugin::OnItemConfig (wxCommandEvent& event)
{
    if (!m_pConfigDialog)
        return;

    CodeBlocksDockEvent evt (cbEVT_SHOW_DOCK_WINDOW);
    evt.pWindow = m_pConfigDialog;
    Manager::Get()->GetAppWindow()->ProcessEvent (evt);
    Log (_("HTC: Config opened"));
}
Nothing happens except that C::B crashes when I exit...
The particular CodeSnippetsWindow you appear to be copying is actually not a traditional dialog window at all. It uses wxAUI, the docking system C::B uses, to create a panel that can float anywhere or be docked between other wxAUI panels. wxAUI panels are a bit tricker to create than more basic dialogs, so it's easy to miss something and mess things up.

It appears that, in emulating the CodeSnippets window, you missed a few important things that appear in the CodeSnippets::CreateSnippetWindow() function. Lines 198-210 in codesnippets.cpp perform the necessary initialization, informing the main Code::Blocks window of a new wxAUI panel to be added by using a cbEVT_ADD_DOCK_WINDOW CodeBlocksDockEvent. Only after this event has been successfully processed should a cbEVT_SHOW_DOCK_WINDOW event be used to show the panel.

If you don't need your dialog to be dockable, don't make it so. It's much simpler to just derive from wxDialog and show it modally or modelessly -- also, there are a few good helper functions in the C::B SDK for working with dialogs.

Quote
I then tried to use wxSmath for that and to make the dialog using the gui but that does not work either.

No windows comes up and C::B crashes *badly*: I coun not even login via ssh and had to hard reset my computer. Is tere som manual on the wxSmith stuff?
wxSmith is a generator for standard wxWidgets XRC and C++, so the XRC ("XML-based ResourCe system") section of the wxWidgets documentation would probably be helpful. Reading the generated code, as well.

Quote
BTW: What is the ::Config method of the plugin for? There are no plugin configs in C::B's menues and the method has no effect and gets never called.
It's a relic from RC2 days. The GetConfigurationPanel method is used now. The "Environment", "Editor", and "Compiler and debugger" settings dialogs are all candidates to contain plugin configuration pages; the plugin gets to choose which one to use.
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline stardust

  • Multiple posting newcomer
  • *
  • Posts: 55
    • http://www.hightec-rt.com
Re: Opening a window
« Reply #2 on: April 12, 2007, 12:39:21 pm »
If you don't need your dialog to be dockable, don't make it so. It's much simpler to just derive from wxDialog and show it modally or modelessly -- also, there are a few good helper functions in the C::B SDK for working with dialogs.
Yepp! That's exactly what I want and it works :-) Great

But there is no way with wxSmith... After C::B has eaten up more than 700MB of RAM my computer freezes and I am really getting problems...

So I want to do the creation "by hand" -- that technique is more robust, anyway...

But I cannot find a method to add controls to the wxDialog... There is just a wxWindow::AddChild(wxWindow*) whose documentation states that this method is internal to wxWidgets and should not be called by the user.

I guess the addition of a child must be done by sending an appropriate event but the wx documentation keeps silent on that...

Thank for a hint!
Own SVN builds (quite new) • SuSE Linux 10.0 • Linux kernel 2.6.13-15-default
gcc 4.0.2 (20050901)
wxGTK-2.6.1.0-4 • KDE 3.4.2b • gtk2 2.8.3-4

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Opening a window
« Reply #3 on: April 12, 2007, 02:28:50 pm »
But there is no way with wxSmith... After C::B has eaten up more than 700MB of RAM my computer freezes and I am really getting problems...
I really don't understand what you mean by this.

Quote
So I want to do the creation "by hand" -- that technique is more robust, anyway...
I disagree. I believe loading GUI resources from an XRC file is more robust by far. I use this technique constantly. So does C::B itself.

Quote
But I cannot find a method to add controls to the wxDialog... There is just a wxWindow::AddChild(wxWindow*) whose documentation states that this method is internal to wxWidgets and should not be called by the user.

I guess the addition of a child must be done by sending an appropriate event but the wx documentation keeps silent on that...

Thank for a hint!
Merely pass the appropriate parent window (in this case, your derived dialog class) as the parent argument to the control's constructor, and then add the control to the appropriate sizer, making sure to call Layout() when everything has been added. (This assumes you're using sizers for layout, because constraints are deprecated and absolute positioning is evil.)
« Last Edit: April 12, 2007, 02:30:54 pm by TDragon »
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)