dhtmlxWindows Guide and Samples

Main features

  • Multibrowser/Multiplatform support
  • Full controll with JavaScript API
  • Modal dialog mode
  • Alwaya-on-top mode
  • Skinable
  • Resizable
  • Supported browsers

  • IE 5.5 and above
  • Mac OS X Safari
  • Mozilla 1.4 and above
  • FireFox 0.9 and above
  • Opera
  • Introduction

    Scope of the document

    This document describes dhtmlxWindows system, defines its methods and global parameters.

    Target readers

    Target readers are project architects, development and QA staff.

    What is dhtmlxWindows

    dhtmlxWindows is a windowing system that enables user to work with several windows and their content at the same time.

    This system allows windows to overlap, and provides means for the user to perform standard operations such as moving/resizing a window, sending a window to the foreground/background, minimizing/maximizing a window, changing window’s position, making a window modal and sticking a window.

    Work with this system involves:

    Working with dhtmlxWindows

    Initializing dhtmlxWindows

    What files you need
    Before writing any script commands related to window creation on page, you need to add some js and css files to your page. Exactly: <link rel="stylesheet" type="text/css" href="codebase/dhtmlxwindows.css"> <link rel="stylesheet" type="text/css" href="codebase/skins/dhtmlxwindows_[skin name].css"> <script src="codebase/dhtmlxcommon.js"></script> <script src="codebase/dhtmlxwindows.js"></script> If you need more then one skin to use, then add related css files also (in most cases one skin requires one css file).
    Minimal initialization

    A base for set of new windows can be created in the following way:

    dhxWins= new dhtmlXWindows();
    imagePath

    Sets the full path to directory where necessary image files are located. Method setImagePath() should be used here:

    dhxWins.setImagePath(String);
    New window creation

    While creating a new window with minimal initialization, a user should use createWindow() method and pass the following values:

    dhxWins.createWindow(String id,int x,int y,int width,int height);

    User can set the header text to the newly created window using the command setText:

    dhxWins.window(String id).setText(String text);

    Default values

    Default values in dhtmlxWindows are:

    Extended initialization

    When creating a new window with extended initialization, a user should call the same commands described in Minimal initialization.

    Additional parameters which can be defined are:

    Header icon

    There is also the opportunity to specify any header icon if default icon is not suitable for user. This can be done in the following way:

    dhxWins.window(id).setIcon(String iconEnabled, String iconDisabled)

    Along with setting header icon user can choose to clear/remove it. In this case there will be just empty space instead of any header icon. To do this user should do the following:

    dhxWins.window(id).clearIcon();

    It is also possible to restore default window icon according the loaded skin:

    dhxWins.window(id).restoreIcon();

    Enable/Disable Resizing

    By default window resizing is allowed.

    Extended initialization allows user to deny window resizing by calling method denyResize():

    dhxWins.window(id).denyResize();

    Resizing of a window can be allowed again with the help of the following method:

    dhxWins.window(id).allowResize();

    Enable/Disable Moving

    By default window moving is allowed.

    User can deny window moving by calling the following method:

    dhxWins.window(id).denyMove();

    Window moving can be allowed again if user calls method allowMove():

    dhxWins.window(id).allowMove();

    Enable/Disable Parking

    By default window parking is allowed.

    User can choose to deny window parking using the following method:

    dhxWins.window(id).denyPark();

    Window parking can be allowed again with the help of the following method:

    dhxWins.window(id).allowPark();

    Hide/disable buttons

    All default buttons are enabled. User can hide some of/all these buttons or disable them.

    In order to hide/disable these buttons use the following methods:

    dhxWins.window(id).button(“close”).hide();
    dhxWins.window(id).button(“park”).disable();

    Attach object

    dhtmlxWindows allows users to attach objects to any window by method attachObject():

    dhxWins.window(id).attachObject = function(objId, changeDisp);

    Besides, user can set “display” property to “none” and pass changeDisp=true to attached element before attaching it to window.

    In this case “display: none;” will be removed and the object will be shown immediately after attaching.

    Attach url

    There is the possibility to attach any external page to window with the help of method attachURL():

    dhxWins.window(id).attachURL = function(url);

    Global dhtmlxWindows parameters

    Global parameters affect the entire system. Global parameters enable features, control information displayed in the graphical user interface.

    Viewport (working area)

    This parameter sets the invisible area that limits windows movements. Windows can’t be completely moved outside the viewport.

    Users can specify the size of the viewport. By default the size of the viewport occupies the document.body and automatically changes its size when document.body’s size changes.

    To enable user-defined viewport evoke the following code:

    dhxWins.enableAutoViewport(false);
    dhxWins.setViewport(10, 10, 1260, 500);

    keepInViewport() method, when is set to “true”, permanently locates a window within the viewport (the window can’t be moved outside the viewport).

    window(id).keepInViewport(true/false);

    By default this method is set to “false”. Thus, all windows can be moved outside the vieport in such a way that only a tiny part of window’s header will be seen.

    Skins

    This parameter allows users to change dhtmlxWindows skins. There is a set of default skins among which user can choose one with the help of method setSkin():

    dhxWins.setSkin(String skin);

    Skins are able to be changed “on the fly”, i.e. user can change them very easily in the process of work. There is no need of any other actions except calling of setSkin() method.

    There is also the possibility for users to create their own skins.

    The following built-in skins are available in dhtmlxWindows:

    Accessing single window

    User can access window in the two following ways:

    var dhxWins = new dhtmlXWindows();
    var win = dhxWins.createWindow(id,…);

    var dhxWins = new dhtmlXWindows();
    dhxWins.window(id);

    Thus, user can access this window using “win” variable or by calling window() function.

    Regardless of the way the window is accessed, the content of “win” variable and windows.window(id) will be equal.

    Window iterator

    Method forEachWindow() calls user-defined function for every existing window passing window handler into it.

    forEachWindow(function(winHandler){winHandler.show();})

    Changing window dimension

    Default min- and max Dimensions are set in dhtmlxWindows.

    The user has the possibility to set his own min and max Dimension parameters to a window by calling methods setMaxDimension() and setMinDimension():

    dhxWins.window(id).setMaxDimension(int width, int height);
    dhxWins.window(id).setMinDimension(int width
    , int height);

    Also if the user wants to change window dimension, he/she should use the command setDimension() and pass width & height values:

    dhxWins.window(id).setDimension(int width, int height);

    There is also a method to get window dimension (will return array (width, height)):

    dhxWins.window(id).getDimension();

    The following methods can also be used to get min and max Dimensions:

    dhxWins.window(id).getMaxDimension();
    dhxWins.window(id).getMinDimension();

    Notice: window will be able to occupy the whole viewport after minimizing if user sets maxDimension to “auto”:

    dhxWins.window(id).setMaxDimension(“auto”, “auto”);

    In this case the window becomes not resizable (only in maximized state).

    Notice: if user changes window dimension in such a way that it cannot display the whole title text, the text will be cut.

    Changing window position

    As with window Dimension, it is available to change window Position. In order to do this method setPosition() must be called with values x and y:

    dhxWins.window(id).setPosition(int x, int y);

    There is also a command to get window position (will return Array(x, y)):

    dhxWins.window(id).getPosition();

    Window parking

    If user wants to park window, he/she should use the command park().

    If the window was parked up, this command makes it park down and vice versa:

    dhxWins.window(id).park();

    Window minimizing/maximizing

    To minimize/maximize a window user should call the following methods:

    dhxWins.window(id).maximize();
    dhxWins.window(id).minimize()
    ;

    Bringing window to top/bottom

    User can bring any window to top with the help of method bringToTop():

    dhxWins.window(id). bringToTop ();

    In this case the window will be automatically focused.

    Method bringToBottom() brings any window to bottom:

    dhxWins.window(id). bringToBottom ();

    In the situation when this method was applied to the top window, the window that lies right after the top one occupies its position and becomes the top window.

    Some peculiarities of these two methods are revealed dealing with sticked/unsticked windows.

    Window sticking/unsticking

    The user has the opportunity to stick/unstick window - to place it always on top. To do this a user should use methods stick() or unstick().

    dhxWins.window(id).stick();
    dhxWins.window(id).unstick()
    ;

    If there is any window that was made “sticked” in the system, global window behavior will be the following:

    Modal/modeless window

    There is the possibility to make window modal calling method setModal():

    dhxWins.window(id).setModal(Boolean state);

    Any modal window has the following features:

    The value “true” in method setModal() makes a window modal while the value “false” makes it modeless.

    Topmost/Bottommost Window

    User is able to get handler of the topmost window with the help of the following method:

    dhxWins.window(id).getTopmostWindow();

    To get handler of the bottommost window user should call the following method:

    dhxWins.window(id).getBottommostWindow();

    Buttons settings manipulating

    Accessing the button

    Button can be accessed in the following way:

    var btn = dhxWins.window(id).button(id);

    Default buttons ids are:

    Showing/hiding buttons

    There is the possibility to show/hide a button by calling the following methods:

    dhxWins.window(id).button(id).show();
    dhxWins.window(id).button(id).hide()
    ;

    User buttons also inherit these methods.

    Button enabling/disabling

    The button can be enabled/disabled by user:

    dhxWins.window(id).button(id).enable();
    dhxWins.window(id).button(id).disable()
    ;

    User buttons also inherit these methods.

    Notice: in some cases button enabling/disabling is determined by Object.

    For example, when the window is Parked Up, resize buttons are inactive/disabled. But they become active/enabled when the window is Parked Down. Thus resize buttons are disabled by the Object.

    Creating user buttons

    Making set of button images

    This example will show user how to create their own buttons for a window.

    1. To get started user should decide for which skin the button will be created. Take, for example, the skin “Web”.

    2. Then user should get to know the dimension of buttons for the chosen skin.

    3. Each button can be divided into “active” & “inactive”. Besides, all buttons have the following states: “default”, “over_default”, “over_pressed”, “disabled”.

    Thus, there must be 8 skins for each single user button:

    1. Next user should name the newly created button. For example, the name of the button can be “tray”.

    2. The next step is to create the main folder for the new button (for example, “tray_button”) and 2 subfolders in it called “active” and “inactive”.

    3. Then user is to create 4 subfolders in both “active” and “inactive” folders:

    As a result there will be the following tree:

    tray/

    active/

    btns_default/

    btns_disabled/

    btns_over_default/

    btns_over_pressed/

    inactive/

    btns_default/

    btns_disabled/

    btns_over_default/

    btns_over_pressed/

    1. Now user should create 8 GIF files with button skins for each button state. Then each GIF file should be placed to each folder according to state. Single file name should be used for each skin, for example: “btn_tray.gif”.

    2. After this the tree will be presented in the following way:

    tray/

    active/

    btns_default/

    btn_tray.gif

    btns_disabled/

    btn_tray.gif

    btns_over_default/

    btn_tray.gif

    btns_over_pressed/

    btn_tray.gif

    inactive/

    btns_default/

    btn_tray.gif

    btns_disabled/

    btn_tray.gif

    btns_over_default/

    btn_tray.gif

    btns_over_pressed/

    btn_tray.gif

    1. Now when button skins are created, user should proceed to CSS file creation.

    CSS file creation

    This example is going to show user how to create CSS file for buttons.

    1. User should find template CSS file dhtmlxwindows_user_button_template.css and save it with a different name. For example, it can be “user_button_tray.css”.

    2. Then user should modify this CSS file in the following way:



    Adding User Button

    To add this newly created button to a window user should use the following method:

    dhxWins.window(id).addUserButton(id, position, tooltip, name);

    This method takes the following parameters:

    Adding event to button

    User can attach an event to the newly created button in the following way:

    dhxWins.window(id).button(id).attachEvent(“onClick”, handler);

    User can also remove an event from any user-created button:

    dhxWins.window(id).button(id).detachEvent(“onClick”);

    Any user-created button can be removed in the following way:

    dhxWins.window(id).button(id).removeUserButton(id);

    Besides, all default buttons methods will be available for user-created buttons as well:

    dhxWins.window(id).button(id).show();
    dhxWins.window(id).button(id).hide();
    dhxWins.window(id).button(id).isHidden();
    dhxWins.window(id).button(id).enable();
    dhxWins.window(id).button(id).disable();
    dhxWins.window(id).button(id).isEnabled();

    Removing User Button

    To remove any user button from the window user should call the following method:

    dhxWins.window(id).removeUserButton(id);

    Event handling

    Default events

    Default events signal various actions, such as the user clicking a button to Park window or a window being closed. Default events are usually button events.

    Button events can be as follows:

    Default events can be redefined by user, who can choose to assign other user-defined events instead. In this case, default events will be ignored until they are restored by user.

    Redefine default button event

    User can choose to redefine default button event adding any user’s event instead.

    To redefine button default event user can use attachEvent() method:

    dhxWins.window(id).button(id).attachEvent(eventName, handler);

    Adding window events handlers

    The entire point of an event is to inform a handler that something has happened to a component in the GUI.

    A handler can figure out what exactly happened and respond in a meaningful way.

    The list of events to which user-defined handlers can be attached is given below:

    Adding global event handlers for windows

    User can add global event handlers for windows. This can be done in the following way:

    dhxWins.attachEvent(eventName, handler);

    Adding personal window event handler

    If there is a window to which user wants to assign a special handler, this can be done by adding the handler to the window directly.

    While other windows will be calling global handlers, this window with personal handler will call this personal handler:

    dhxWins.window(id).attachEvent(eventName, handler);

    Restore global event handlers

    User can detach personal event from window.

    In this case global event handler will be restored for this window, i.e. when personal handler is removed from the window, the widow will call global handler.

    dhxWins.window(id).detachEvent(eventName);

    Remove global handlers

    Global handlers can be easily removed with the help of the following method:

    dhxWins.detachEvent(eventName);

    Understanding events handlers priority

    In the situation described above windows w2 and w3 will call “globalHandler” when they are focused.

    Window w1 will call personal “w1Handler” when it is focused.

    © DHTMLX LTD.