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