MDI and button controls

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.
Post Reply
D.Bane
Posts: 78
Joined: Thu Jul 29, 2010 2:51 pm

MDI and button controls

Post by D.Bane »

Hi all :)

Well I know that Microsoft has been saying the MDI are not a way to go, as well as probably a lot of others did, but for applications for office use this is still the best way to go, and as I looked trough the IDE source, it seams that it's all 'preloaded', but I don't know what will be opened so I need user to select this and that,and isn't (if many windows are loaded at startup) it memory inefficient? Or have I not catch it correctly?

So there are few buttons, and every one of them should open the new window indicating which book would be opened, or what to get from db... Now if I click on the button the window that is called isn't shown..

Code: Select all

SomeWindow{this};
nor

Code: Select all

SomeWindow{this.parent};
nor

Code: Select all

SomeWindow{MainWindow};
I even tried with .Activate() and .Visible = true but than it errors..

I searched the net prior to this post, but there was nothing that would help me with this and was in c..or I haven't query in the best way..

Thank you for your time and help.
D.Bane :)
No army is to big, if the heart is beating strong.
There's no bad luck, it's just easier to blame someone else.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: MDI and button controls

Post by jerome »

Hi D.Bane,

I think indeed MDI is not the best way to go.
But we sort of support it already in Ecere (that's how the IDE is currently set up, although we are planning to switch to a tabbed document/docking panel layout).

Your question however seems to be "How to dynamically create a Window?", e.g. as a response to a user action. Luckily, Ecere makes that extremely easy.

I will show you how to do it in a second, but first I'd like to point out our identifier naming convention standards: classes always start with an uppercase, variables with a lowercase.

Your identifiers in your example are quite confusing. SomeWindow seems to be a class, not an instance, because you use it to try to create a new instance. MainWindow however you seem to be passing to the parent property (the first property) of SomeWindow. Judging both by the name (how it's named similarly to SomeWindow) and our convention, MainWindow would be a class... But the parent property expects a parent window (an instance). Just trying to clarify this out. If you don't specify any parent, by default the desktop will be the parent. In MDI usually you want to set parent to be your main window.

Ok so now the one thing you're missing, is to invoke the Window::Create method.
Windows added to a window before it's created (including the top level windows in the desktop instantiated globally) automatically get created when their parent gets created (or when the GUI application gets initialized for the case of the top level windows). That is as long as their autoCreate property is set to true (which is the default for most windows, except for the common dialogs).

Because you are creating windows dynamically, you need to explicitly call Create().

Here is some sample code showing a very simple MDI setup, which dynamically creates a new window when you select the File/New menu item:

Code: Select all

import "ecere"
 
class ChildWindow : Window
{
   borderStyle = sizable;
   hasMaximize = true;
   hasMinimize = true;
   hasClose = true;
   isActiveClient = true;
   isDocument = true;
   text = "Child Window";
   anchor = { { cascade } };
   // Once the parent is set, unlock the cascade anchor
   watch(parent) { size = size; position = position; };
}
 
class MainWindow : Window
{
   background = activeBorder;
   borderStyle = sizable;
   hasMaximize = true, hasMinimize = true, hasClose = true;
   hasHorzScroll = true;
   hasVertScroll = true;
   hasMenuBar = true;
   drawBehind = true;
   text = "MainForm", size = { 640, 480 };
 
   Menu fileMenu { menu, text = "File", hotKey = f };
      MenuItem newItem
      {
         fileMenu, text = "New Window", n, ctrlN;
 
         bool NotifySelect(MenuItem selection, Modifiers mods)
         {
            ChildWindow { this }.Create();
            return true;
         }
      };
      MenuItem fileCloseItem { fileMenu, "Close", c, ctrlF4, NotifySelect = MenuFileClose };
      MenuDivider { fileMenu };
      MenuItem exitItem { fileMenu, "Exit", x, altF4, NotifySelect = MenuFileExit };
 
   Menu windowMenu { menu, "Window", w };
      MenuItem { windowMenu, "Close All", l, NotifySelect = MenuWindowCloseAll };
      MenuDivider { windowMenu };
      MenuItem { windowMenu, "Next", n, f6, NotifySelect = MenuWindowNext };
      MenuItem { windowMenu, "Previous", p, shiftF6, NotifySelect = MenuWindowPrevious };
      MenuDivider { windowMenu };
      MenuItem { windowMenu, "Cascade", c, NotifySelect = MenuWindowCascade };
      MenuItem { windowMenu, "Tile Horizontally", h, NotifySelect = MenuWindowTileHorz };
      MenuItem { windowMenu, "Tile Vertically", v, NotifySelect = MenuWindowTileVert };
      MenuItem { windowMenu, "Arrange Icons", a, NotifySelect = MenuWindowArrangeIcons };
      MenuDivider { windowMenu };
      MenuItem { windowMenu, "Windows...", w, NotifySelect = MenuWindowWindows };
}
 
MainWindow parent { };
Please note that as soon as you enable the scrollbars in the MainWindow, you will get the same window trails you reported before in http://ecere.com/mantis/view.php?id=537 .
They are actually more problematic than I originally thought, and I looked to make a quick fix that could resolve this for you. I'm hoping to put up an updated bleeding edge SDK tarball very soon and I will include that fix in there.

Cheers,

Jerome

EDIT: I added a minor tweak to 'unlock' the anchor, so that if you resize the MainWindow before moving the child window, the window keeps its original position and size.

EDIT: You can grab the patched Ecere SDK source code at http://www.ecere.com/downloads/ecere-sd ... 25.tar.bz2
D.Bane
Posts: 78
Joined: Thu Jul 29, 2010 2:51 pm

Re: MDI and button controls

Post by D.Bane »

Thank you :)
I'm sorry I haven't replied sooner, had to some stuff without the computer :)

That's what I needed, just didn't know that they are dynamically created..Tried to use .activate and .visible = true..nothing else worked, I haven't seen .Create.. :( :)

Yes, I read Tao, and I'm using it like that..it was "class SomeWindow{}" and "class MainWindow{}", as I tried to put class as parent cause it's variable didn't work, so tried like this too.. variables are "frmWindowThatAndThat"..

Yes, I see why the tabbed version should be more desirable, but to me it's for applications like notepad (Notepad++) or MS Word, here there is a need to have more windows and there should not be two working apps at the same time.

As usual you helped me, and I'm thanking you again, and just to ask, did you look at what I wrote at Mantis? It removed the trails if after every moving of a child there is a check, and parents scroll area is adjusted, ( in function "CheckChildrenPos" in the file I attached..), there is to make it window tight or to make some room around them.. It probably needs tweaking..
And thanks for the link. To use it I should do "make install" again, but from folder where this is extracted?
No army is to big, if the heart is beating strong.
There's no bad luck, it's just easier to blame someone else.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: MDI and button controls

Post by jerome »

D.Bane,

Did you take a look at the multi document notepad application in samples/guiAndGfx/Notepad ?

Just another sample that might be useful to you.

I did take a look at that Mantis issue, and I saw you attached a file, but iirc I was not able to compile it. Regardless, I think the trails were just an area not being updated when it should, and the patch I put in should solve that issue.

The link I put in is a full SDK folder, so you just need to build it and install it on top of your current SDK (You can make a backup of Program Files/Ecere SDK/bin first if you like, assuming you're on Windows)
You can also just use the pre-build binaries at http://www.ecere.com/downloads/winbin.zip if you prefer.

To build and install it, just make sure you first close all instances of Ecere apps including the Ecere IDE, and start an administrator command prompt (On Vista/7 you need to do Start, type 'cmd', right click the icon that comes up and do 'Run as administrator; On 2000/XP things are easier: any Command Prompt when you're logged in as an Administrator will work fine).

Then you just go into whichever folder where you extracted the source code (I suggest 7-zip, if you don't have it installed already, to extract the .tar.bz2), and from the top level directory (ecere-sdk-***) just run 'mingw32-make'. If all goes well it should report that the Ecere SDK was built successfully.

Once make succeeds run 'mingw32-make install'. If all goes well it should report that the Ecere SDK was installed successfully.
D.Bane
Posts: 78
Joined: Thu Jul 29, 2010 2:51 pm

Re: MDI and button controls

Post by D.Bane »

Installed, using it :) Thanks :)
No army is to big, if the heart is beating strong.
There's no bad luck, it's just easier to blame someone else.
Post Reply