From 34a22d83b5d2f56accbe1d7d5610bc3697a29b3a Mon Sep 17 00:00:00 2001 From: Gary Willoughby Date: Mon, 5 May 2014 11:57:45 +0100 Subject: [PATCH] Moved some source files around into much logical locations. This should also resolve a forward reference bug. --- README.md | 14 +- docs/tkd/tkdapplication.html | 317 ----------- docs/tkd/{ => window}/dialog/colordialog.html | 12 +- docs/tkd/{ => window}/dialog/dialog.html | 8 +- .../{ => window}/dialog/directorydialog.html | 8 +- docs/tkd/{ => window}/dialog/filedialog.html | 8 +- docs/tkd/{ => window}/dialog/fontdialog.html | 16 +- .../{ => window}/dialog/messagedialog.html | 8 +- .../{ => window}/dialog/openfiledialog.html | 10 +- .../{ => window}/dialog/savefiledialog.html | 8 +- docs/tkd/window/window.html | 347 ++++++++++++ source/tkd/dialog/package.d | 14 - source/tkd/tkdapplication.d | 520 +---------------- source/tkd/widget/menu/menubar.d | 2 +- source/tkd/widget/package.d | 4 +- source/tkd/{ => window}/dialog/colordialog.d | 9 +- source/tkd/{ => window}/dialog/dialog.d | 6 +- .../tkd/{ => window}/dialog/directorydialog.d | 5 +- source/tkd/{ => window}/dialog/filedialog.d | 6 +- source/tkd/{ => window}/dialog/fontdialog.d | 13 +- .../tkd/{ => window}/dialog/messagedialog.d | 5 +- .../tkd/{ => window}/dialog/openfiledialog.d | 7 +- source/tkd/window/dialog/package.d | 14 + .../tkd/{ => window}/dialog/savefiledialog.d | 5 +- source/tkd/window/package.d | 10 + source/tkd/window/window.d | 536 ++++++++++++++++++ 26 files changed, 988 insertions(+), 924 deletions(-) rename docs/tkd/{ => window}/dialog/colordialog.html (84%) rename docs/tkd/{ => window}/dialog/dialog.html (88%) rename docs/tkd/{ => window}/dialog/directorydialog.html (90%) rename docs/tkd/{ => window}/dialog/filedialog.html (92%) rename docs/tkd/{ => window}/dialog/fontdialog.html (86%) rename docs/tkd/{ => window}/dialog/messagedialog.html (95%) rename docs/tkd/{ => window}/dialog/openfiledialog.html (89%) rename docs/tkd/{ => window}/dialog/savefiledialog.html (90%) create mode 100644 docs/tkd/window/window.html delete mode 100644 source/tkd/dialog/package.d rename source/tkd/{ => window}/dialog/colordialog.d (88%) rename source/tkd/{ => window}/dialog/dialog.d (91%) rename source/tkd/{ => window}/dialog/directorydialog.d (96%) rename source/tkd/{ => window}/dialog/filedialog.d (97%) rename source/tkd/{ => window}/dialog/fontdialog.d (90%) rename source/tkd/{ => window}/dialog/messagedialog.d (98%) rename source/tkd/{ => window}/dialog/openfiledialog.d (95%) create mode 100644 source/tkd/window/dialog/package.d rename source/tkd/{ => window}/dialog/savefiledialog.d (96%) create mode 100644 source/tkd/window/package.d create mode 100644 source/tkd/window/window.d diff --git a/README.md b/README.md index 71dfe2c..066ce82 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ program. Every application has at least one top level window. | Window | Description | | :----- | :---------- | -| [Window](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/tkdapplication.html#Window) | A window is similar to a frame except that it is created as a top level window. The primary purpose of a window is to serve as a dialog box and/or collections of widgets. | +| [Window](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/window/window.html) | A window is similar to a frame except that it is created as a top level window. The primary purpose of a window is to serve as a dialog box and/or collections of widgets. | #### Menus @@ -139,12 +139,12 @@ These are pre-built dialog boxes to gather various pieces of data from a user. | Dialog box | Description | | :----- | :---------- | -| [ColorDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/dialog/colordialog.html) | Pops up a dialog box for the user to select a color. | -| [DirectoryDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/dialog/directorydialog.html) | Pops up a dialog box for the user to select a directory. | -| [FontDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/dialog/fontdialog.html) | Pops up a dialog box for the user to select a font. | -| [MessageDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/dialog/messagedialog.html) | Pops up a dialog box with a user defined message and buttons. | -| [OpenFileDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/dialog/openfiledialog.html) | Pops up a dialog box for the user to open a file. | -| [SaveFileDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/dialog/savefiledialog.html) | Pops up a dialog box for the user to save a file. | +| [ColorDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/window/dialog/colordialog.html) | Pops up a dialog box for the user to select a color. | +| [DirectoryDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/window/dialog/directorydialog.html) | Pops up a dialog box for the user to select a directory. | +| [FontDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/window/dialog/fontdialog.html) | Pops up a dialog box for the user to select a font. | +| [MessageDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/window/dialog/messagedialog.html) | Pops up a dialog box with a user defined message and buttons. | +| [OpenFileDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/window/dialog/openfiledialog.html) | Pops up a dialog box for the user to open a file. | +| [SaveFileDialog](http://htmlpreview.github.io/?https://github.com/nomad-software/tkd/master/docs/tkd/window/dialog/savefiledialog.html) | Pops up a dialog box for the user to save a file. | ## Building diff --git a/docs/tkd/tkdapplication.html b/docs/tkd/tkdapplication.html index 44a9f6f..ca54964 100644 --- a/docs/tkd/tkdapplication.html +++ b/docs/tkd/tkdapplication.html @@ -136,323 +136,6 @@

protected abstract void -

class Window: tkd.element.uielement.UiElement; -

-

The Window class creates a new toplevel window. -

-

A window is similar to a frame except that it is created as a top-level - widget. The primary purpose of a toplevel is to serve as a container for - dialog boxes and other collections of widgets. - -

-

Example:

-
auto window = new Window("New window")
-	.setGeometry(640, 480, 10, 10)
-	.setDefaultIcon(new Png!("icon.png"))
-	.setMaxSize(1024, 768)
-	.addProtocolCommand(WindowProtocol.deleteWindow, delegate(CommandArgs args){ ... });
-
-

-

Additional Events:

-Additional events that can also be bound to using the bind method. -

<<PrevWindow>>, - <Alt-Key>, - <Key-Tab>, - <Key-F10>, -

- -

-

See Also

tkd.element.uielement

-
-

this(Window parent, string title, bool waitForWindow = true); -

-

Constructor. -

-

It's important to understand that the window will be drawn immediately - by default. This means that the window will display before any other - actions take place, including drawing or managing other widgets. This is - so other methods (such as platformId) that rely on the window being - drawn don't fail if immediately used afterwards. -

- - This behaviour can be overridden by passing false as the waitForWindow - argument which is useful if you want the entire UI belonging to the new - window to be drawn before actaully showing it. -

- - The parent window is responsible for the life of this window. If the - parent window is destroyed, this one will be too. - -

-

Parameters

- - - - - -
Window parentThe window to act as a parent.
string titleThe title of the window.
bool waitForWindowWhether to wait for the window to be drawn before continuing.
-
-
-

this(string title, bool waitForWindow = true); -

-

Constructor. -

-

It's important to understand that the window will be drawn immediately - by default. This means that the window will display before any other - actions take place, including drawing or managing other widgets. This is - so other methods (such as platformId) that rely on the window being - drawn don't fail if immediately used afterwards. -

- - This behaviour can be overridden by passing false as the waitForWindow - argument which is useful if you want the entire UI belonging to the new - window to be drawn before actaully showing it. -

- - If no parent is specified the new window with be a child of the main - window. - -

-

Parameters

- - - -
string titleThe title of the window.
bool waitForWindowWhether to wait for the window to be drawn before continuing.
-
-
-

auto setTitle(this T)(string title); -

-

Set the title of the window. -

-

Parameters

- -
string titleThe title of the window.
-

Return Value

This widget to aid method chaining.

-
-
-

auto setOpacity(this T)(double opacity); -

-

Set the opacity of the window. -

-

Parameters

- -
double opacityA number between 0.0 and 1.0 specifying the transparency.
-

Return Value

This widget to aid method chaining.

-
-
-

auto setFullscreen(this T)(bool fullscreen); -

-

Handle setting the window to fullscreen. -

-

Parameters

- -
bool fullscreenA boolean specifying if the window should be fullscreen or not.
-

Return Value

This widget to aid method chaining.

-
-
-

auto setTopmost(this T)(bool topmost); -

-

Handle setting the window to be the top-most. This makes the window not - able to be lowered behind any others. -

-

Parameters

- -
bool topmostA boolean specifying if the window should be top-most or not.
-

Return Value

This widget to aid method chaining.

-
-
-

auto deiconify(this T)(); -

-

Restore the window's state to before it was minimised or withdrawn. -

-

Return Value

This widget to aid method chaining.

-
-
-

auto iconify(this T)(); -

-

Minimise the window. -

-

Return Value

This widget to aid method chaining.

-
-
-

auto setGeometry(this T)(int width, int height, int xPos, int yPos); -

-

Set the size and postition of the window. -

-

Parameters

- - - - - - - -
int widthThe width of the window.
int heightThe height of the window.
int xPosThe horizontal position of the window.
int yPosThe vertical position of the window.
-

Return Value

This widget to aid method chaining.

-
-
-

auto setDefaultIcon(this T)(Image[] images...); -

-

Set the default icon for this window. This is applied to all future - child windows as well. -

-

The data in the images is taken as a snapshot at the time of invocation. - If the images are later changed, this is not reflected to the titlebar - icons. Multiple images are accepted to allow different images sizes - (e.g., 16x16 and 32x32) to be provided. The window manager may scale - provided icons to an appropriate size. - -

-

Parameters

- -
Image[] imagesA variadic list of images.
-

Return Value

This widget to aid method chaining.

-
-
-

auto setIcon(this T)(Image[] images...); -

-

Set the icon for this window, this overrides the default icon. -

-

Parameters

- -
Image[] imagesA variadic list of images.
-

Return Value

This widget to aid method chaining.

-
-
-

auto setMaxSize(this T)(int width, int height); -

-

Set the maximum size of the window. -

-

Parameters

- - - -
int widthThe maximum width of the window.
int heightThe maximum height of the window.
-

Return Value

This widget to aid method chaining.

-
-
-

auto setMinSize(this T)(int width, int height); -

-

Set the minimum size of the window. -

-

Parameters

- - - -
int widthThe minimum width of the window.
int heightThe minimum height of the window.
-

Return Value

This widget to aid method chaining.

-
-
-

auto addProtocolCommand(this T)(string protocol, CommandCallback callback); -

-

This command is used to manage window manager protocols such as - WM_DELETE_WINDOW. Protocol is the name of an atom corresponding to a - window manager protocol, such as WM_DELETE_WINDOW or WM_SAVE_YOURSELF or - WM_TAKE_FOCUS. -

-

Parameters

- - - -
string protocolThe protocol to respond to.
CommandCallback callbackThe callback to invoke when the protocol is encountered.
-

Return Value

This widget to aid method chaining. - -

-

Callback Arguments:

-These are the fields within the callback's CommandArgs parameter which - are populated by this method when the callback is executed. -

- - -
CommandArgs.elementThe window that executed the callback.
CommandArgs.uniqueDataThe protocol that was responded to.
CommandArgs.callbackThe callback which was executed.
-

- -

-

See Also

tkd.element.element.CommandCallback
- tkd.tkdapplication.WindowProtocol

-
-
-

auto removeProtocolCommand(this T)(string protocol); -

-

Remove a previously set protocol command. -

-

Parameters

- -
string protocolThe protocol which will have the command removed.
-

Return Value

This widget to aid method chaining. - -

-

See Also

tkd.tkdapplication.WindowProtocol

-
-
-

auto setResizable(this T)(bool resizeWidth, bool resizeHeight); -

-

Set if the width and height can be resized. -

-

Parameters

- - - -
bool resizeWidthTrue to allow width resizing, false to disable.
bool resizeHeightTrue to allow height resizing, false to disable.
-

Return Value

This widget to aid method chaining.

-
-
-

bool isAbove(Window other); -

-

Determine if this window is above another. -

-

Parameters

- -
Window otherThe other window to check this one is above.
-

Return Value

true if this window is above other, false if not.

-
-
-

bool isBelow(Window other); -

-

Determine if this window is below another. -

-

Parameters

- -
Window otherThe other window to check this one is below.
-

Return Value

true if this window is below other, false if not.

-
-
-

auto withdraw(this T)(); -

-

Withdraw a window from being displayed/mapped by the window manager. -

-

Return Value

This widget to aid method chaining.

-
-
-

auto wait(this T)(); -

-

Wait until this window has been destroyed. -

-

Return Value

This widget to aid method chaining.

-
-
-
-
-

enum WindowProtocol: string; -

-

Window manager protocols. -

-

Bugs

This list is incomplete.

-
-

deleteWindow

-

Issued when the window is to be deleted.

-
-
-

saveYourself

-

Issued when the window is required to save itself.

-
-
-

takeFocus

-

Issued then the window is focused.

-
-
-
-
diff --git a/docs/tkd/dialog/colordialog.html b/docs/tkd/window/dialog/colordialog.html similarity index 84% rename from docs/tkd/dialog/colordialog.html rename to docs/tkd/window/dialog/colordialog.html index eb2262b..a508bc6 100644 --- a/docs/tkd/dialog/colordialog.html +++ b/docs/tkd/window/dialog/colordialog.html @@ -6,16 +6,16 @@ - tkd.dialog.colordialog + tkd.window.dialog.colordialog -

tkd.dialog.colordialog

- +

tkd.window.dialog.colordialog

+

Dialog module.

License

MIT. See LICENSE for full details.

-

class ColorDialog: tkd.dialog.dialog.Dialog; +

class ColorDialog: tkd.window.dialog.dialog.Dialog;

Pops up a dialog box for the user to select a color.

@@ -57,7 +57,7 @@

Parameters

auto setInitialColor(this T)(string color);

Set the initial color to display in the dialog. - Use colors from the preset color list or a web style hex color. + Use colors from the preset color list or a web style hex color.

Parameters

string title
@@ -65,7 +65,7 @@

Parameters

string color The initial color.

Return Value

This dialog to aid method chaining.

-

See Also

tkd.widget.color
+

See Also

tkd.widget.color

Caveats:

diff --git a/docs/tkd/dialog/dialog.html b/docs/tkd/window/dialog/dialog.html similarity index 88% rename from docs/tkd/dialog/dialog.html rename to docs/tkd/window/dialog/dialog.html index 43a266e..317e5bc 100644 --- a/docs/tkd/dialog/dialog.html +++ b/docs/tkd/window/dialog/dialog.html @@ -6,11 +6,11 @@ - tkd.dialog.dialog + tkd.window.dialog.dialog -

tkd.dialog.dialog

- +

tkd.window.dialog.dialog

+

Dialog module.

License

MIT. See LICENSE for full details.

@@ -19,7 +19,7 @@

License

MIT. See LICENSE for full details.

Abstract base class for all dialog boxes.

-

See Also

tkd.element.element

+

See Also

tkd.element.element

this(Window parent, string title);

diff --git a/docs/tkd/dialog/directorydialog.html b/docs/tkd/window/dialog/directorydialog.html similarity index 90% rename from docs/tkd/dialog/directorydialog.html rename to docs/tkd/window/dialog/directorydialog.html index c3af2d6..6da39f9 100644 --- a/docs/tkd/dialog/directorydialog.html +++ b/docs/tkd/window/dialog/directorydialog.html @@ -6,16 +6,16 @@ - tkd.dialog.directorydialog + tkd.window.dialog.directorydialog -

tkd.dialog.directorydialog

- +

tkd.window.dialog.directorydialog

+

Dialog module.

License

MIT. See LICENSE for full details.

-

class DirectoryDialog: tkd.dialog.dialog.Dialog; +

class DirectoryDialog: tkd.window.dialog.dialog.Dialog;

Pops up a dialog box for the user to select a directory.

diff --git a/docs/tkd/dialog/filedialog.html b/docs/tkd/window/dialog/filedialog.html similarity index 92% rename from docs/tkd/dialog/filedialog.html rename to docs/tkd/window/dialog/filedialog.html index 7d9e4b2..28294bc 100644 --- a/docs/tkd/dialog/filedialog.html +++ b/docs/tkd/window/dialog/filedialog.html @@ -6,16 +6,16 @@ - tkd.dialog.filedialog + tkd.window.dialog.filedialog -

tkd.dialog.filedialog

- +

tkd.window.dialog.filedialog

+

Dialog module.

License

MIT. See LICENSE for full details.

-

abstract class FileDialog: tkd.dialog.dialog.Dialog; +

abstract class FileDialog: tkd.window.dialog.dialog.Dialog;

Pops up a dialog box for the user to select a color.

diff --git a/docs/tkd/dialog/fontdialog.html b/docs/tkd/window/dialog/fontdialog.html similarity index 86% rename from docs/tkd/dialog/fontdialog.html rename to docs/tkd/window/dialog/fontdialog.html index ac26a82..61c011b 100644 --- a/docs/tkd/dialog/fontdialog.html +++ b/docs/tkd/window/dialog/fontdialog.html @@ -6,16 +6,16 @@ - tkd.dialog.fontdialog + tkd.window.dialog.fontdialog -

tkd.dialog.fontdialog

- +

tkd.window.dialog.fontdialog

+

Dialog module.

License

MIT. See LICENSE for full details.

-

class FontDialog: tkd.dialog.dialog.Dialog; +

class FontDialog: tkd.window.dialog.dialog.Dialog;

The font dialog allows users to choose a font installed on the system. It uses the native platform font selection dialog where available, or a dialog @@ -35,7 +35,7 @@

License

MIT. See LICENSE for full details.

Additional Events:

-Additional events that can also be bound to using the bind method. +Additional events that can also be bound to using the bind method.

<<TkFontchooserFontChanged>>, <<TkFontchooserVisibility>>,

@@ -80,7 +80,7 @@

Return Value

This dialog to aid method chaining.

Callback Arguments:

-These are the fields within the callback's CommandArgs parameter which +These are the fields within the callback's CommandArgs parameter which are populated by this method when the callback is executed.

string color
@@ -89,8 +89,8 @@

Return Value

This dialog to aid method chaining.

-

See Also

tkd.element.element.CommandArgs
- tkd.element.element.CommandCallback

+

See Also

tkd.element.element.CommandArgs
+ tkd.element.element.CommandCallback

auto removeCommand(this T)(); diff --git a/docs/tkd/dialog/messagedialog.html b/docs/tkd/window/dialog/messagedialog.html similarity index 95% rename from docs/tkd/dialog/messagedialog.html rename to docs/tkd/window/dialog/messagedialog.html index 5444cf1..69e799d 100644 --- a/docs/tkd/dialog/messagedialog.html +++ b/docs/tkd/window/dialog/messagedialog.html @@ -6,16 +6,16 @@ - tkd.dialog.messagedialog + tkd.window.dialog.messagedialog -

tkd.dialog.messagedialog

- +

tkd.window.dialog.messagedialog

+

Dialog module.

License

MIT. See LICENSE for full details.

-

class MessageDialog: tkd.dialog.dialog.Dialog; +

class MessageDialog: tkd.window.dialog.dialog.Dialog;

Pops up a dialog box with a user defined message and buttons.

diff --git a/docs/tkd/dialog/openfiledialog.html b/docs/tkd/window/dialog/openfiledialog.html similarity index 89% rename from docs/tkd/dialog/openfiledialog.html rename to docs/tkd/window/dialog/openfiledialog.html index 6142606..6382126 100644 --- a/docs/tkd/dialog/openfiledialog.html +++ b/docs/tkd/window/dialog/openfiledialog.html @@ -6,22 +6,22 @@ - tkd.dialog.openfiledialog + tkd.window.dialog.openfiledialog -

tkd.dialog.openfiledialog

- +

tkd.window.dialog.openfiledialog

+

Dialog module.

License

MIT. See LICENSE for full details.

-

class OpenFileDialog: tkd.dialog.filedialog.FileDialog; +

class OpenFileDialog: tkd.window.dialog.filedialog.FileDialog;

Pops up a dialog box for the user to open a file.

Example:

auto dialog = new OpenFileDialog("Open a file")
-	.setMultiSelection(flase)
+	.setMultiSelection(false)
 	.setDefaultExtension(".txt")
 	.addFileType("{{All files} {*}}")
 	.addFileType("{{Text files} {.txt}}")
diff --git a/docs/tkd/dialog/savefiledialog.html b/docs/tkd/window/dialog/savefiledialog.html
similarity index 90%
rename from docs/tkd/dialog/savefiledialog.html
rename to docs/tkd/window/dialog/savefiledialog.html
index 383d0d9..f6faf2c 100644
--- a/docs/tkd/dialog/savefiledialog.html
+++ b/docs/tkd/window/dialog/savefiledialog.html
@@ -6,16 +6,16 @@
 		
 		
 		
-		tkd.dialog.savefiledialog
+		tkd.window.dialog.savefiledialog
 	
 	
-		

tkd.dialog.savefiledialog

- +

tkd.window.dialog.savefiledialog

+

Dialog module.

License

MIT. See LICENSE for full details.

-

class SaveFileDialog: tkd.dialog.filedialog.FileDialog; +

class SaveFileDialog: tkd.window.dialog.filedialog.FileDialog;

Pops up a dialog box for the user to save a file.

diff --git a/docs/tkd/window/window.html b/docs/tkd/window/window.html new file mode 100644 index 0000000..e924828 --- /dev/null +++ b/docs/tkd/window/window.html @@ -0,0 +1,347 @@ + + + + + + + + + tkd.window.window + + +

tkd.window.window

+ +

Window module. +

+

License

MIT. See LICENSE for full details.

+
+

class Window: tkd.element.uielement.UiElement; +

+

The Window class creates a new toplevel window. +

+

A window is similar to a frame except that it is created as a top-level + widget. The primary purpose of a toplevel is to serve as a container for + dialog boxes and other collections of widgets. + +

+

Example:

+
auto window = new Window("New window")
+	.setGeometry(640, 480, 10, 10)
+	.setDefaultIcon(new Png!("icon.png"))
+	.setMaxSize(1024, 768)
+	.addProtocolCommand(WindowProtocol.deleteWindow, delegate(CommandArgs args){ ... });
+
+

+

Additional Events:

+Additional events that can also be bound to using the bind method. +

<<PrevWindow>>, + <Alt-Key>, + <Key-Tab>, + <Key-F10>, +

+ +

+

See Also

tkd.element.uielement

+
+

this(); +

+

Constructor. +

+

This constructor is mainly for internal use. When creating a window + using this constructor what you are really doing is creating a new + reference to the main application window.

+
+
+

this(Window parent, string title, bool waitForWindow = true); +

+

Constructor. +

+

It's important to understand that the window will be drawn immediately + by default. This means that the window will display before any other + actions take place, including drawing or managing other widgets. This is + so other methods (such as platformId) that rely on the window being + drawn don't fail if immediately used afterwards. +

+ + This behaviour can be overridden by passing false as the waitForWindow + argument which is useful if you want the entire UI belonging to the new + window to be drawn before actaully showing it. +

+ + The parent window is responsible for the life of this window. If the + parent window is destroyed, this one will be too. + +

+

Parameters

CommandArgs.elementThe element that executed the callback.
CommandArgs.callbackThe callback which was executed.
+ + + + + +
Window parentThe window to act as a parent.
string titleThe title of the window.
bool waitForWindowWhether to wait for the window to be drawn before continuing.
+
+
+

this(string title, bool waitForWindow = true); +

+

Constructor. +

+

It's important to understand that the window will be drawn immediately + by default. This means that the window will display before any other + actions take place, including drawing or managing other widgets. This is + so other methods (such as platformId) that rely on the window being + drawn don't fail if immediately used afterwards. +

+ + This behaviour can be overridden by passing false as the waitForWindow + argument which is useful if you want the entire UI belonging to the new + window to be drawn before actaully showing it. +

+ + If no parent is specified the new window with be a child of the main + window. + +

+

Parameters

+ + + +
string titleThe title of the window.
bool waitForWindowWhether to wait for the window to be drawn before continuing.
+
+
+

auto setTitle(this T)(string title); +

+

Set the title of the window. +

+

Parameters

+ +
string titleThe title of the window.
+

Return Value

This widget to aid method chaining.

+
+
+

auto setOpacity(this T)(double opacity); +

+

Set the opacity of the window. +

+

Parameters

+ +
double opacityA number between 0.0 and 1.0 specifying the transparency.
+

Return Value

This widget to aid method chaining.

+
+
+

auto setFullscreen(this T)(bool fullscreen); +

+

Handle setting the window to fullscreen. +

+

Parameters

+ +
bool fullscreenA boolean specifying if the window should be fullscreen or not.
+

Return Value

This widget to aid method chaining.

+
+
+

auto setTopmost(this T)(bool topmost); +

+

Handle setting the window to be the top-most. This makes the window not + able to be lowered behind any others. +

+

Parameters

+ +
bool topmostA boolean specifying if the window should be top-most or not.
+

Return Value

This widget to aid method chaining.

+
+
+

auto deiconify(this T)(); +

+

Restore the window's state to before it was minimised or withdrawn. +

+

Return Value

This widget to aid method chaining.

+
+
+

auto iconify(this T)(); +

+

Minimise the window. +

+

Return Value

This widget to aid method chaining.

+
+
+

auto setGeometry(this T)(int width, int height, int xPos, int yPos); +

+

Set the size and postition of the window. +

+

Parameters

+ + + + + + + +
int widthThe width of the window.
int heightThe height of the window.
int xPosThe horizontal position of the window.
int yPosThe vertical position of the window.
+

Return Value

This widget to aid method chaining.

+
+
+

auto setDefaultIcon(this T)(Image[] images...); +

+

Set the default icon for this window. This is applied to all future + child windows as well. +

+

The data in the images is taken as a snapshot at the time of invocation. + If the images are later changed, this is not reflected to the titlebar + icons. Multiple images are accepted to allow different images sizes + (e.g., 16x16 and 32x32) to be provided. The window manager may scale + provided icons to an appropriate size. + +

+

Parameters

+ +
Image[] imagesA variadic list of images.
+

Return Value

This widget to aid method chaining.

+
+
+

auto setIcon(this T)(Image[] images...); +

+

Set the icon for this window, this overrides the default icon. +

+

Parameters

+ +
Image[] imagesA variadic list of images.
+

Return Value

This widget to aid method chaining.

+
+
+

auto setMaxSize(this T)(int width, int height); +

+

Set the maximum size of the window. +

+

Parameters

+ + + +
int widthThe maximum width of the window.
int heightThe maximum height of the window.
+

Return Value

This widget to aid method chaining.

+
+
+

auto setMinSize(this T)(int width, int height); +

+

Set the minimum size of the window. +

+

Parameters

+ + + +
int widthThe minimum width of the window.
int heightThe minimum height of the window.
+

Return Value

This widget to aid method chaining.

+
+
+

auto addProtocolCommand(this T)(string protocol, CommandCallback callback); +

+

This command is used to manage window manager protocols such as + WM_DELETE_WINDOW. Protocol is the name of an atom corresponding to a + window manager protocol, such as WM_DELETE_WINDOW or WM_SAVE_YOURSELF or + WM_TAKE_FOCUS. +

+

Parameters

+ + + +
string protocolThe protocol to respond to.
CommandCallback callbackThe callback to invoke when the protocol is encountered.
+

Return Value

This widget to aid method chaining. + +

+

Callback Arguments:

+These are the fields within the callback's CommandArgs parameter which + are populated by this method when the callback is executed. +

+ + +
CommandArgs.elementThe window that executed the callback.
CommandArgs.uniqueDataThe protocol that was responded to.
CommandArgs.callbackThe callback which was executed.
+

+ +

+

See Also

tkd.element.element.CommandCallback
+ tkd.tkdapplication.WindowProtocol

+
+
+

auto removeProtocolCommand(this T)(string protocol); +

+

Remove a previously set protocol command. +

+

Parameters

+ +
string protocolThe protocol which will have the command removed.
+

Return Value

This widget to aid method chaining. + +

+

See Also

tkd.tkdapplication.WindowProtocol

+
+
+

auto setResizable(this T)(bool resizeWidth, bool resizeHeight); +

+

Set if the width and height can be resized. +

+

Parameters

+ + + +
bool resizeWidthTrue to allow width resizing, false to disable.
bool resizeHeightTrue to allow height resizing, false to disable.
+

Return Value

This widget to aid method chaining.

+
+
+

bool isAbove(Window other); +

+

Determine if this window is above another. +

+

Parameters

+ +
Window otherThe other window to check this one is above.
+

Return Value

true if this window is above other, false if not.

+
+
+

bool isBelow(Window other); +

+

Determine if this window is below another. +

+

Parameters

+ +
Window otherThe other window to check this one is below.
+

Return Value

true if this window is below other, false if not.

+
+
+

auto withdraw(this T)(); +

+

Withdraw a window from being displayed/mapped by the window manager. +

+

Return Value

This widget to aid method chaining.

+
+
+

auto wait(this T)(); +

+

Wait until this window has been destroyed. +

+

Return Value

This widget to aid method chaining.

+
+
+
+

+

enum WindowProtocol: string; +

+

Window manager protocols. +

+

Bugs

This list is incomplete.

+
+

deleteWindow

+

Issued when the window is to be deleted.

+
+
+

saveYourself

+

Issued when the window is required to save itself.

+
+
+

takeFocus

+

Issued then the window is focused.

+
+
+
+
+ + + + diff --git a/source/tkd/dialog/package.d b/source/tkd/dialog/package.d deleted file mode 100644 index 37f1291..0000000 --- a/source/tkd/dialog/package.d +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Dialog module. - * - * License: - * MIT. See LICENSE for full details. - */ -module tkd.dialog; - -public import tkd.dialog.colordialog; -public import tkd.dialog.directorydialog; -public import tkd.dialog.fontdialog; -public import tkd.dialog.messagedialog; -public import tkd.dialog.openfiledialog; -public import tkd.dialog.savefiledialog; diff --git a/source/tkd/tkdapplication.d b/source/tkd/tkdapplication.d index 89f8caa..c3cd5dc 100644 --- a/source/tkd/tkdapplication.d +++ b/source/tkd/tkdapplication.d @@ -16,11 +16,11 @@ import tkd.interpreter; /** * Public imports. */ -public import tkd.dialog; public import tkd.element; public import tkd.image; public import tkd.theme; public import tkd.widget; +public import tkd.window; /** * Base class of all Tkd gui applications. @@ -190,521 +190,3 @@ abstract class TkdApplication */ abstract protected void initInterface(); } - -/** - * The Window class creates a new toplevel window. - * - * A window is similar to a frame except that it is created as a top-level - * widget. The primary purpose of a toplevel is to serve as a container for - * dialog boxes and other collections of widgets. - * - * Example: - * --- - * auto window = new Window("New window") - * .setGeometry(640, 480, 10, 10) - * .setDefaultIcon(new Png!("icon.png")) - * .setMaxSize(1024, 768) - * .addProtocolCommand(WindowProtocol.deleteWindow, delegate(CommandArgs args){ ... }); - * --- - * Additional_Events: - * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. - * $(P - * <<PrevWindow>>, - * <Alt-Key>, - * <Key-Tab>, - * <Key-F10>, - * ) - * - * See_Also: - * $(LINK2 ./element/uielement.html, tkd.element.uielement) - */ -class Window : UiElement -{ - /** - * Constructor. - */ - private this() - { - super(); - this.overrideGeneratedId("."); - } - - /** - * Constructor. - * - * It's important to understand that the window will be drawn immediately - * by default. This means that the window will display before any other - * actions take place, including drawing or managing other widgets. This is - * so other methods (such as platformId) that rely on the window being - * drawn don't fail if immediately used afterwards. - * - * This behaviour can be overridden by passing false as the waitForWindow - * argument which is useful if you want the entire UI belonging to the new - * window to be drawn before actaully showing it. - * - * The parent window is responsible for the life of this window. If the - * parent window is destroyed, this one will be too. - * - * Params: - * parent = The window to act as a parent. - * title = The title of the window. - * waitForWindow = Whether to wait for the window to be drawn before continuing. - */ - public this(Window parent, string title, bool waitForWindow = true) - { - super(parent); - this._elementId = "window"; - this._tk.eval("toplevel %s", this.id); - - if (waitForWindow) - { - // This tip was gathered from the following post, if it proves not - // to be cross-platform there are other tips in this post that - // could be used. - // http://stackoverflow.com/questions/8929031/grabbing-a-new-window-in-tcl-tk - this._tk.eval("tkwait visibility %s", this.id); - } - - this.setTitle(title); - } - - /** - * Constructor. - * - * It's important to understand that the window will be drawn immediately - * by default. This means that the window will display before any other - * actions take place, including drawing or managing other widgets. This is - * so other methods (such as platformId) that rely on the window being - * drawn don't fail if immediately used afterwards. - * - * This behaviour can be overridden by passing false as the waitForWindow - * argument which is useful if you want the entire UI belonging to the new - * window to be drawn before actaully showing it. - * - * If no parent is specified the new window with be a child of the main - * window. - * - * Params: - * title = The title of the window. - * waitForWindow = Whether to wait for the window to be drawn before continuing. - */ - public this(string title, bool waitForWindow = true) - { - this(new Window(), title, waitForWindow); - } - - /** - * Set the title of the window. - * - * Params: - * title = The title of the window. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setTitle(this T)(string title) - { - this._tk.eval("wm title %s {%s}", this.id, title); - - return cast(T) this; - } - - /** - * Set the opacity of the window. - * - * Params: - * opacity = A number between 0.0 and 1.0 specifying the transparency. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setOpacity(this T)(double opacity) - { - assert(opacity >= 0 && opacity <= 1, "Opacity must be between 0.0 and 1.0."); - - this._tk.eval("wm attributes %s -alpha %s", this.id, opacity); - - return cast(T) this; - } - - /** - * Handle setting the window to fullscreen. - * - * Params: - * fullscreen = A boolean specifying if the window should be fullscreen or not. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setFullscreen(this T)(bool fullscreen) - { - this._tk.eval("wm attributes %s -fullscreen %s", this.id, fullscreen); - - return cast(T) this; - } - - /** - * Handle setting the window to be the top-most. This makes the window not - * able to be lowered behind any others. - * - * Params: - * topmost = A boolean specifying if the window should be top-most or not. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setTopmost(this T)(bool topmost) - { - this._tk.eval("wm attributes %s -topmost %s", this.id, topmost); - - return cast(T) this; - } - - version (Windows) - { - /** - * Handle disabling the window. Windows only. - * - * Params: - * disabled = A boolean specifying if the window should be disabled or not. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setDisabled(this T)(bool disabled) - { - this._tk.eval("wm attributes %s -disabled %s", this.id, disabled); - - return cast(T) this; - } - - /** - * Handle changing the window to a tool window. Windows only. - * - * Params: - * toolWindow = A boolean specifying if the window should be a tool window or not. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setToolWindow(this T)(bool toolWindow) - { - this._tk.eval("wm attributes %s -toolwindow %s", this.id, toolWindow); - - return cast(T) this; - } - } - - version (OSX) - { - /** - * Set the modified state of the window. Mac OSX only. - * - * Params: - * modified = A boolean specifying if the window should show it's been modified or not. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setModified(this T)(bool modified) - { - this._tk.eval("wm attributes %s -modified %s", this.id, modified); - - return cast(T) this; - } - - /** - * Set the notify state of the window. On Mac OS it usually bounces the - * dock icon. Mac OSX only. - * - * Params: - * modified = A boolean specifying if the window should show a notification or not. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setNotify(this T)(bool modified) - { - this._tk.eval("wm attributes %s -notify %s", this.id, modified); - - return cast(T) this; - } - } - - /** - * Restore the window's state to before it was minimised or withdrawn. - * - * Returns: - * This widget to aid method chaining. - */ - public auto deiconify(this T)() - { - this._tk.eval("wm deiconify %s", this.id); - - return cast(T) this; - } - - /** - * Minimise the window. - * - * Returns: - * This widget to aid method chaining. - */ - public auto iconify(this T)() - { - this._tk.eval("wm iconify %s", this.id); - - return cast(T) this; - } - - /** - * Set the size and postition of the window. - * - * Params: - * width = The width of the window. - * height = The height of the window. - * xPos = The horizontal position of the window. - * yPos = The vertical position of the window. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setGeometry(this T)(int width, int height, int xPos, int yPos) - { - this._tk.eval("wm geometry %s %sx%s+%s+%s", this.id, width, height, xPos, yPos); - - return cast(T) this; - } - - /** - * Set the default icon for this window. This is applied to all future - * child windows as well. - * - * The data in the images is taken as a snapshot at the time of invocation. - * If the images are later changed, this is not reflected to the titlebar - * icons. Multiple images are accepted to allow different images sizes - * (e.g., 16x16 and 32x32) to be provided. The window manager may scale - * provided icons to an appropriate size. - * - * Params: - * images = A variadic list of images. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setDefaultIcon(this T)(Image[] images ...) - { - string defaultImages; - - foreach (image; images) - { - defaultImages ~= format("%s ", image.id); - } - - this._tk.eval("wm iconphoto %s -default %s", this.id, defaultImages); - - return cast(T) this; - } - - /** - * Set the icon for this window, this overrides the default icon. - * - * Params: - * images = A variadic list of images. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setIcon(this T)(Image[] images ...) - { - string defaultImages; - - foreach (image; images) - { - defaultImages ~= format("%s ", image.id); - } - - this._tk.eval("wm iconphoto %s %s", this.id, defaultImages); - - return cast(T) this; - } - - /** - * Set the maximum size of the window. - * - * Params: - * width = The maximum width of the window. - * height = The maximum height of the window. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setMaxSize(this T)(int width, int height) - { - this._tk.eval("wm maxsize %s %s %s", this.id, width, height); - - return cast(T) this; - } - - /** - * Set the minimum size of the window. - * - * Params: - * width = The minimum width of the window. - * height = The minimum height of the window. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setMinSize(this T)(int width, int height) - { - this._tk.eval("wm minsize %s %s %s", this.id, width, height); - - return cast(T) this; - } - - /** - * This command is used to manage window manager protocols such as - * WM_DELETE_WINDOW. Protocol is the name of an atom corresponding to a - * window manager protocol, such as WM_DELETE_WINDOW or WM_SAVE_YOURSELF or - * WM_TAKE_FOCUS. - * - * Params: - * protocol = The protocol to respond to. - * callback = The callback to invoke when the protocol is encountered. - * - * Returns: - * This widget to aid method chaining. - * - * Callback_Arguments: - * These are the fields within the callback's $(LINK2 - * ./element/element.html#CommandArgs, CommandArgs) parameter which - * are populated by this method when the callback is executed. - * $(P - * $(PARAM_TABLE - * $(PARAM_ROW CommandArgs.element, The window that executed the callback.) - * $(PARAM_ROW CommandArgs.uniqueData, The protocol that was responded to.) - * $(PARAM_ROW CommandArgs.callback, The callback which was executed.) - * ) - * ) - * - * See_Also: - * $(LINK2 ./element/element.html#CommandCallback, tkd.element.element.CommandCallback) $(BR) - * $(LINK2 ./tkdapplication.html#WindowProtocol, tkd.tkdapplication.WindowProtocol) $(BR) - */ - public auto addProtocolCommand(this T)(string protocol, CommandCallback callback) - { - string command = this.createCommand(callback, protocol); - this._tk.eval("wm protocol %s %s %s", this.id, protocol, command); - - return cast(T) this; - } - - /** - * Remove a previously set protocol command. - * - * Params: - * protocol = The protocol which will have the command removed. - * - * Returns: - * This widget to aid method chaining. - * - * See_Also: - * $(LINK2 ./tkdapplication.html#WindowProtocol, tkd.tkdapplication.WindowProtocol) - */ - public auto removeProtocolCommand(this T)(string protocol) - { - this._tk.deleteCommand(this.getCommandName(protocol)); - this._tk.eval("wm protocol %s %s {}", this.id, protocol); - - return cast(T) this; - } - - /** - * Set if the width and height can be resized. - * - * Params: - * resizeWidth = True to allow width resizing, false to disable. - * resizeHeight = True to allow height resizing, false to disable. - * - * Returns: - * This widget to aid method chaining. - */ - public auto setResizable(this T)(bool resizeWidth, bool resizeHeight) - { - this._tk.eval("wm resizable %s %s %s", this.id, resizeWidth, resizeHeight); - - return cast(T) this; - } - - /** - * Determine if this window is above another. - * - * Params: - * other = The other window to check this one is above. - * - * Returns: - * true if this window is above other, false if not. - */ - public bool isAbove(Window other) - { - this._tk.eval("wm stackorder %s isabove %s", this.id, other.id); - - return this._tk.getResult!(int) == 1; - } - - /** - * Determine if this window is below another. - * - * Params: - * other = The other window to check this one is below. - * - * Returns: - * true if this window is below other, false if not. - */ - public bool isBelow(Window other) - { - this._tk.eval("wm stackorder %s isbelow %s", this.id, other.id); - - return this._tk.getResult!(int) == 1; - } - - /** - * Withdraw a window from being displayed/mapped by the window manager. - * - * Returns: - * This widget to aid method chaining. - */ - public auto withdraw(this T)() - { - this._tk.eval("wm withdraw %s", this.id); - - return cast(T) this; - } - - /** - * Wait until this window has been destroyed. - * - * Returns: - * This widget to aid method chaining. - */ - public auto wait(this T)() - { - this._tk.eval("tkwait window %s", this.id); - - return cast(T) this; - } -} - -/** - * Window manager protocols. - * - * Bugs: - * This list is incomplete. - */ -enum WindowProtocol : string -{ - deleteWindow = "WM_DELETE_WINDOW", /// Issued when the window is to be deleted. - saveYourself = "WM_SAVE_YOURSELF", /// Issued when the window is required to save itself. - takeFocus = "WM_TAKE_FOCUS", /// Issued then the window is focused. -} diff --git a/source/tkd/widget/menu/menubar.d b/source/tkd/widget/menu/menubar.d index c845553..8403c24 100644 --- a/source/tkd/widget/menu/menubar.d +++ b/source/tkd/widget/menu/menubar.d @@ -10,7 +10,7 @@ module tkd.widget.menu.menubar; * Imports. */ import tkd.element.uielement; -import tkd.tkdapplication : Window; +import tkd.window.window; /** * A menubar is the bar across the top of a window holding the menu items. diff --git a/source/tkd/widget/package.d b/source/tkd/widget/package.d index 19c4238..a3e784e 100644 --- a/source/tkd/widget/package.d +++ b/source/tkd/widget/package.d @@ -6,7 +6,7 @@ */ module tkd.widget; -public import tkd.element.element : CommandCallback, CommandArgs; +public import tkd.element.element : CommandArgs; public import tkd.widget.alignment; public import tkd.widget.anchorposition; public import tkd.widget.button; @@ -36,4 +36,4 @@ public import tkd.widget.style; public import tkd.widget.text; public import tkd.widget.textwrapmode; public import tkd.widget.treeview; -public import tkd.widget.widget : GeometrySide, GeometryFill; +public import tkd.widget.widget : GeometrySide, GeometryFill, GeometryBorderMode; diff --git a/source/tkd/dialog/colordialog.d b/source/tkd/window/dialog/colordialog.d similarity index 88% rename from source/tkd/dialog/colordialog.d rename to source/tkd/window/dialog/colordialog.d index f420365..2e71799 100644 --- a/source/tkd/dialog/colordialog.d +++ b/source/tkd/window/dialog/colordialog.d @@ -4,14 +4,15 @@ * License: * MIT. See LICENSE for full details. */ -module tkd.dialog.colordialog; +module tkd.window.dialog.colordialog; /** * Imports. */ import std.regex; -import tkd.dialog.dialog; import tkd.element.color; +import tkd.window.dialog.dialog; +import tkd.window.window; /** * Pops up a dialog box for the user to select a color. @@ -63,7 +64,7 @@ class ColorDialog : Dialog /** * Set the initial color to display in the dialog. - * Use colors from the preset color $(LINK2 ../element/color.html, list) or a web style hex color. + * Use colors from the preset color $(LINK2 ../../element/color.html, list) or a web style hex color. * * Params: * color = The initial color. @@ -72,7 +73,7 @@ class ColorDialog : Dialog * This dialog to aid method chaining. * * See_Also: - * $(LINK2 ../element/color.html, tkd.widget.color) $(BR) + * $(LINK2 ../../element/color.html, tkd.widget.color) $(BR) * * Caveats: * If the passed color is not recognised the dialog will fail to show. diff --git a/source/tkd/dialog/dialog.d b/source/tkd/window/dialog/dialog.d similarity index 91% rename from source/tkd/dialog/dialog.d rename to source/tkd/window/dialog/dialog.d index 57309be..4b22cac 100644 --- a/source/tkd/dialog/dialog.d +++ b/source/tkd/window/dialog/dialog.d @@ -4,20 +4,20 @@ * License: * MIT. See LICENSE for full details. */ -module tkd.dialog.dialog; +module tkd.window.dialog.dialog; /** * Imports. */ import std.regex; import tkd.element.element; -import tkd.tkdapplication : Window; +import tkd.window.window; /** * Abstract base class for all dialog boxes. * * See_Also: - * $(LINK2 ../element/element.html, tkd.element.element) $(BR) + * $(LINK2 ../../element/element.html, tkd.element.element) $(BR) */ abstract class Dialog : Element { diff --git a/source/tkd/dialog/directorydialog.d b/source/tkd/window/dialog/directorydialog.d similarity index 96% rename from source/tkd/dialog/directorydialog.d rename to source/tkd/window/dialog/directorydialog.d index 595bc6d..562a882 100644 --- a/source/tkd/dialog/directorydialog.d +++ b/source/tkd/window/dialog/directorydialog.d @@ -4,13 +4,14 @@ * License: * MIT. See LICENSE for full details. */ -module tkd.dialog.directorydialog; +module tkd.window.dialog.directorydialog; /** * Imports. */ import std.regex; -import tkd.dialog.dialog; +import tkd.window.dialog.dialog; +import tkd.window.window; /** * Pops up a dialog box for the user to select a directory. diff --git a/source/tkd/dialog/filedialog.d b/source/tkd/window/dialog/filedialog.d similarity index 97% rename from source/tkd/dialog/filedialog.d rename to source/tkd/window/dialog/filedialog.d index 21f63a7..9c6362d 100644 --- a/source/tkd/dialog/filedialog.d +++ b/source/tkd/window/dialog/filedialog.d @@ -4,15 +4,15 @@ * License: * MIT. See LICENSE for full details. */ -module tkd.dialog.filedialog; +module tkd.window.dialog.filedialog; /** * Imports. */ import std.regex; import std.string; -import tkd.dialog.dialog; -import tkd.tkdapplication : Window; +import tkd.window.dialog.dialog; +import tkd.window.window; /** * Pops up a dialog box for the user to select a color. diff --git a/source/tkd/dialog/fontdialog.d b/source/tkd/window/dialog/fontdialog.d similarity index 90% rename from source/tkd/dialog/fontdialog.d rename to source/tkd/window/dialog/fontdialog.d index 718ec12..81e16b6 100644 --- a/source/tkd/dialog/fontdialog.d +++ b/source/tkd/window/dialog/fontdialog.d @@ -4,13 +4,14 @@ * License: * MIT. See LICENSE for full details. */ -module tkd.dialog.fontdialog; +module tkd.window.dialog.fontdialog; /** * Imports. */ -import tkd.dialog.dialog; +import tkd.window.dialog.dialog; import tkd.element.element; +import tkd.window.window; /** * The font dialog allows users to choose a font installed on the system. It @@ -31,7 +32,7 @@ import tkd.element.element; * --- * * Additional_Events: - * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. + * Additional events that can also be bound to using the $(LINK2 ../../element/uielement.html#UiElement.bind, bind) method. * $(P * <<TkFontchooserFontChanged>>, * <<TkFontchooserVisibility>>, @@ -86,7 +87,7 @@ class FontDialog : Dialog * * Callback_Arguments: * These are the fields within the callback's $(LINK2 - * ../element/element.html#CommandArgs, CommandArgs) parameter which + * ../../element/element.html#CommandArgs, CommandArgs) parameter which * are populated by this method when the callback is executed. * $(P * $(PARAM_TABLE @@ -97,8 +98,8 @@ class FontDialog : Dialog * ) * * See_Also: - * $(LINK2 ../element/element.html#CommandArgs, tkd.element.element.CommandArgs) $(BR) - * $(LINK2 ../element/element.html#CommandCallback, tkd.element.element.CommandCallback) $(BR) + * $(LINK2 ../../element/element.html#CommandArgs, tkd.element.element.CommandArgs) $(BR) + * $(LINK2 ../../element/element.html#CommandCallback, tkd.element.element.CommandCallback) $(BR) */ public auto setCommand(this T)(CommandCallback callback) { diff --git a/source/tkd/dialog/messagedialog.d b/source/tkd/window/dialog/messagedialog.d similarity index 98% rename from source/tkd/dialog/messagedialog.d rename to source/tkd/window/dialog/messagedialog.d index 1a16df7..0b1b160 100644 --- a/source/tkd/dialog/messagedialog.d +++ b/source/tkd/window/dialog/messagedialog.d @@ -4,13 +4,14 @@ * License: * MIT. See LICENSE for full details. */ -module tkd.dialog.messagedialog; +module tkd.window.dialog.messagedialog; /** * Imports. */ import std.regex; -import tkd.dialog.dialog; +import tkd.window.dialog.dialog; +import tkd.window.window; /** * Pops up a dialog box with a user defined message and buttons. diff --git a/source/tkd/dialog/openfiledialog.d b/source/tkd/window/dialog/openfiledialog.d similarity index 95% rename from source/tkd/dialog/openfiledialog.d rename to source/tkd/window/dialog/openfiledialog.d index 23ff081..290634b 100644 --- a/source/tkd/dialog/openfiledialog.d +++ b/source/tkd/window/dialog/openfiledialog.d @@ -4,14 +4,15 @@ * License: * MIT. See LICENSE for full details. */ -module tkd.dialog.openfiledialog; +module tkd.window.dialog.openfiledialog; /** * Imports. */ import std.array; import std.regex; -import tkd.dialog.filedialog; +import tkd.window.dialog.filedialog; +import tkd.window.window; /** * Pops up a dialog box for the user to open a file. @@ -19,7 +20,7 @@ import tkd.dialog.filedialog; * Example: * --- * auto dialog = new OpenFileDialog("Open a file") - * .setMultiSelection(flase) + * .setMultiSelection(false) * .setDefaultExtension(".txt") * .addFileType("{{All files} {*}}") * .addFileType("{{Text files} {.txt}}") diff --git a/source/tkd/window/dialog/package.d b/source/tkd/window/dialog/package.d new file mode 100644 index 0000000..edd27e4 --- /dev/null +++ b/source/tkd/window/dialog/package.d @@ -0,0 +1,14 @@ +/** + * Dialog module. + * + * License: + * MIT. See LICENSE for full details. + */ +module tkd.window.dialog; + +public import tkd.window.dialog.colordialog; +public import tkd.window.dialog.directorydialog; +public import tkd.window.dialog.fontdialog; +public import tkd.window.dialog.messagedialog; +public import tkd.window.dialog.openfiledialog; +public import tkd.window.dialog.savefiledialog; diff --git a/source/tkd/dialog/savefiledialog.d b/source/tkd/window/dialog/savefiledialog.d similarity index 96% rename from source/tkd/dialog/savefiledialog.d rename to source/tkd/window/dialog/savefiledialog.d index 2db6583..d8065be 100644 --- a/source/tkd/dialog/savefiledialog.d +++ b/source/tkd/window/dialog/savefiledialog.d @@ -4,14 +4,15 @@ * License: * MIT. See LICENSE for full details. */ -module tkd.dialog.savefiledialog; +module tkd.window.dialog.savefiledialog; /** * Imports. */ import std.array; import std.regex; -import tkd.dialog.filedialog; +import tkd.window.dialog.filedialog; +import tkd.window.window; /** * Pops up a dialog box for the user to save a file. diff --git a/source/tkd/window/package.d b/source/tkd/window/package.d new file mode 100644 index 0000000..4c825de --- /dev/null +++ b/source/tkd/window/package.d @@ -0,0 +1,10 @@ +/** + * Window module. + * + * License: + * MIT. See LICENSE for full details. + */ +module tkd.window; + +public import tkd.window.dialog; +public import tkd.window.window; diff --git a/source/tkd/window/window.d b/source/tkd/window/window.d new file mode 100644 index 0000000..3dfed00 --- /dev/null +++ b/source/tkd/window/window.d @@ -0,0 +1,536 @@ +/** + * Window module. + * + * License: + * MIT. See LICENSE for full details. + */ +module tkd.window.window; + +/** + * Private imports. + */ +import std.string; +import tkd.element.uielement; +import tkd.interpreter; + +/** + * The Window class creates a new toplevel window. + * + * A window is similar to a frame except that it is created as a top-level + * widget. The primary purpose of a toplevel is to serve as a container for + * dialog boxes and other collections of widgets. + * + * Example: + * --- + * auto window = new Window("New window") + * .setGeometry(640, 480, 10, 10) + * .setDefaultIcon(new Png!("icon.png")) + * .setMaxSize(1024, 768) + * .addProtocolCommand(WindowProtocol.deleteWindow, delegate(CommandArgs args){ ... }); + * --- + * Additional_Events: + * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. + * $(P + * <<PrevWindow>>, + * <Alt-Key>, + * <Key-Tab>, + * <Key-F10>, + * ) + * + * See_Also: + * $(LINK2 ../element/uielement.html, tkd.element.uielement) + */ +class Window : UiElement +{ + /** + * Constructor. + * + * This constructor is mainly for internal use. When creating a window + * using this constructor what you are really doing is creating a new + * reference to the main application window. + */ + public this() + { + super(); + this.overrideGeneratedId("."); + } + + /** + * Constructor. + * + * It's important to understand that the window will be drawn immediately + * by default. This means that the window will display before any other + * actions take place, including drawing or managing other widgets. This is + * so other methods (such as platformId) that rely on the window being + * drawn don't fail if immediately used afterwards. + * + * This behaviour can be overridden by passing false as the waitForWindow + * argument which is useful if you want the entire UI belonging to the new + * window to be drawn before actaully showing it. + * + * The parent window is responsible for the life of this window. If the + * parent window is destroyed, this one will be too. + * + * Params: + * parent = The window to act as a parent. + * title = The title of the window. + * waitForWindow = Whether to wait for the window to be drawn before continuing. + */ + public this(Window parent, string title, bool waitForWindow = true) + { + super(parent); + this._elementId = "window"; + this._tk.eval("toplevel %s", this.id); + + if (waitForWindow) + { + // This tip was gathered from the following post, if it proves not + // to be cross-platform there are other tips in this post that + // could be used. + // http://stackoverflow.com/questions/8929031/grabbing-a-new-window-in-tcl-tk + this._tk.eval("tkwait visibility %s", this.id); + } + + this.setTitle(title); + } + + /** + * Constructor. + * + * It's important to understand that the window will be drawn immediately + * by default. This means that the window will display before any other + * actions take place, including drawing or managing other widgets. This is + * so other methods (such as platformId) that rely on the window being + * drawn don't fail if immediately used afterwards. + * + * This behaviour can be overridden by passing false as the waitForWindow + * argument which is useful if you want the entire UI belonging to the new + * window to be drawn before actaully showing it. + * + * If no parent is specified the new window with be a child of the main + * window. + * + * Params: + * title = The title of the window. + * waitForWindow = Whether to wait for the window to be drawn before continuing. + */ + public this(string title, bool waitForWindow = true) + { + this(new Window(), title, waitForWindow); + } + + /** + * Set the title of the window. + * + * Params: + * title = The title of the window. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setTitle(this T)(string title) + { + this._tk.eval("wm title %s {%s}", this.id, title); + + return cast(T) this; + } + + /** + * Set the opacity of the window. + * + * Params: + * opacity = A number between 0.0 and 1.0 specifying the transparency. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setOpacity(this T)(double opacity) + { + assert(opacity >= 0 && opacity <= 1, "Opacity must be between 0.0 and 1.0."); + + this._tk.eval("wm attributes %s -alpha %s", this.id, opacity); + + return cast(T) this; + } + + /** + * Handle setting the window to fullscreen. + * + * Params: + * fullscreen = A boolean specifying if the window should be fullscreen or not. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setFullscreen(this T)(bool fullscreen) + { + this._tk.eval("wm attributes %s -fullscreen %s", this.id, fullscreen); + + return cast(T) this; + } + + /** + * Handle setting the window to be the top-most. This makes the window not + * able to be lowered behind any others. + * + * Params: + * topmost = A boolean specifying if the window should be top-most or not. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setTopmost(this T)(bool topmost) + { + this._tk.eval("wm attributes %s -topmost %s", this.id, topmost); + + return cast(T) this; + } + + version (Windows) + { + /** + * Handle disabling the window. Windows only. + * + * Params: + * disabled = A boolean specifying if the window should be disabled or not. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setDisabled(this T)(bool disabled) + { + this._tk.eval("wm attributes %s -disabled %s", this.id, disabled); + + return cast(T) this; + } + + /** + * Handle changing the window to a tool window. Windows only. + * + * Params: + * toolWindow = A boolean specifying if the window should be a tool window or not. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setToolWindow(this T)(bool toolWindow) + { + this._tk.eval("wm attributes %s -toolwindow %s", this.id, toolWindow); + + return cast(T) this; + } + } + + version (OSX) + { + /** + * Set the modified state of the window. Mac OSX only. + * + * Params: + * modified = A boolean specifying if the window should show it's been modified or not. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setModified(this T)(bool modified) + { + this._tk.eval("wm attributes %s -modified %s", this.id, modified); + + return cast(T) this; + } + + /** + * Set the notify state of the window. On Mac OS it usually bounces the + * dock icon. Mac OSX only. + * + * Params: + * modified = A boolean specifying if the window should show a notification or not. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setNotify(this T)(bool modified) + { + this._tk.eval("wm attributes %s -notify %s", this.id, modified); + + return cast(T) this; + } + } + + /** + * Restore the window's state to before it was minimised or withdrawn. + * + * Returns: + * This widget to aid method chaining. + */ + public auto deiconify(this T)() + { + this._tk.eval("wm deiconify %s", this.id); + + return cast(T) this; + } + + /** + * Minimise the window. + * + * Returns: + * This widget to aid method chaining. + */ + public auto iconify(this T)() + { + this._tk.eval("wm iconify %s", this.id); + + return cast(T) this; + } + + /** + * Set the size and postition of the window. + * + * Params: + * width = The width of the window. + * height = The height of the window. + * xPos = The horizontal position of the window. + * yPos = The vertical position of the window. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setGeometry(this T)(int width, int height, int xPos, int yPos) + { + this._tk.eval("wm geometry %s %sx%s+%s+%s", this.id, width, height, xPos, yPos); + + return cast(T) this; + } + + /** + * Set the default icon for this window. This is applied to all future + * child windows as well. + * + * The data in the images is taken as a snapshot at the time of invocation. + * If the images are later changed, this is not reflected to the titlebar + * icons. Multiple images are accepted to allow different images sizes + * (e.g., 16x16 and 32x32) to be provided. The window manager may scale + * provided icons to an appropriate size. + * + * Params: + * images = A variadic list of images. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setDefaultIcon(this T)(Image[] images ...) + { + string defaultImages; + + foreach (image; images) + { + defaultImages ~= format("%s ", image.id); + } + + this._tk.eval("wm iconphoto %s -default %s", this.id, defaultImages); + + return cast(T) this; + } + + /** + * Set the icon for this window, this overrides the default icon. + * + * Params: + * images = A variadic list of images. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setIcon(this T)(Image[] images ...) + { + string defaultImages; + + foreach (image; images) + { + defaultImages ~= format("%s ", image.id); + } + + this._tk.eval("wm iconphoto %s %s", this.id, defaultImages); + + return cast(T) this; + } + + /** + * Set the maximum size of the window. + * + * Params: + * width = The maximum width of the window. + * height = The maximum height of the window. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setMaxSize(this T)(int width, int height) + { + this._tk.eval("wm maxsize %s %s %s", this.id, width, height); + + return cast(T) this; + } + + /** + * Set the minimum size of the window. + * + * Params: + * width = The minimum width of the window. + * height = The minimum height of the window. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setMinSize(this T)(int width, int height) + { + this._tk.eval("wm minsize %s %s %s", this.id, width, height); + + return cast(T) this; + } + + /** + * This command is used to manage window manager protocols such as + * WM_DELETE_WINDOW. Protocol is the name of an atom corresponding to a + * window manager protocol, such as WM_DELETE_WINDOW or WM_SAVE_YOURSELF or + * WM_TAKE_FOCUS. + * + * Params: + * protocol = The protocol to respond to. + * callback = The callback to invoke when the protocol is encountered. + * + * Returns: + * This widget to aid method chaining. + * + * Callback_Arguments: + * These are the fields within the callback's $(LINK2 + * ../element/element.html#CommandArgs, CommandArgs) parameter which + * are populated by this method when the callback is executed. + * $(P + * $(PARAM_TABLE + * $(PARAM_ROW CommandArgs.element, The window that executed the callback.) + * $(PARAM_ROW CommandArgs.uniqueData, The protocol that was responded to.) + * $(PARAM_ROW CommandArgs.callback, The callback which was executed.) + * ) + * ) + * + * See_Also: + * $(LINK2 ../element/element.html#CommandCallback, tkd.element.element.CommandCallback) $(BR) + * $(LINK2 ../tkdapplication.html#WindowProtocol, tkd.tkdapplication.WindowProtocol) $(BR) + */ + public auto addProtocolCommand(this T)(string protocol, CommandCallback callback) + { + string command = this.createCommand(callback, protocol); + this._tk.eval("wm protocol %s %s %s", this.id, protocol, command); + + return cast(T) this; + } + + /** + * Remove a previously set protocol command. + * + * Params: + * protocol = The protocol which will have the command removed. + * + * Returns: + * This widget to aid method chaining. + * + * See_Also: + * $(LINK2 ../tkdapplication.html#WindowProtocol, tkd.tkdapplication.WindowProtocol) + */ + public auto removeProtocolCommand(this T)(string protocol) + { + this._tk.deleteCommand(this.getCommandName(protocol)); + this._tk.eval("wm protocol %s %s {}", this.id, protocol); + + return cast(T) this; + } + + /** + * Set if the width and height can be resized. + * + * Params: + * resizeWidth = True to allow width resizing, false to disable. + * resizeHeight = True to allow height resizing, false to disable. + * + * Returns: + * This widget to aid method chaining. + */ + public auto setResizable(this T)(bool resizeWidth, bool resizeHeight) + { + this._tk.eval("wm resizable %s %s %s", this.id, resizeWidth, resizeHeight); + + return cast(T) this; + } + + /** + * Determine if this window is above another. + * + * Params: + * other = The other window to check this one is above. + * + * Returns: + * true if this window is above other, false if not. + */ + public bool isAbove(Window other) + { + this._tk.eval("wm stackorder %s isabove %s", this.id, other.id); + + return this._tk.getResult!(int) == 1; + } + + /** + * Determine if this window is below another. + * + * Params: + * other = The other window to check this one is below. + * + * Returns: + * true if this window is below other, false if not. + */ + public bool isBelow(Window other) + { + this._tk.eval("wm stackorder %s isbelow %s", this.id, other.id); + + return this._tk.getResult!(int) == 1; + } + + /** + * Withdraw a window from being displayed/mapped by the window manager. + * + * Returns: + * This widget to aid method chaining. + */ + public auto withdraw(this T)() + { + this._tk.eval("wm withdraw %s", this.id); + + return cast(T) this; + } + + /** + * Wait until this window has been destroyed. + * + * Returns: + * This widget to aid method chaining. + */ + public auto wait(this T)() + { + this._tk.eval("tkwait window %s", this.id); + + return cast(T) this; + } +} + +/** + * Window manager protocols. + * + * Bugs: + * This list is incomplete. + */ +enum WindowProtocol : string +{ + deleteWindow = "WM_DELETE_WINDOW", /// Issued when the window is to be deleted. + saveYourself = "WM_SAVE_YOURSELF", /// Issued when the window is required to save itself. + takeFocus = "WM_TAKE_FOCUS", /// Issued then the window is focused. +}