r9762: Add support for reading good old smbpasswd files
[kai/samba.git] / swat / scripting / client / desktop.js
1 /*
2    Windows, tabs, and general widgetry for SWAT.
3
4    Copyright (C) Deryck Hodge 2005
5    released under the GNU GPL Version 2 or later
6 */
7
8
9 // The global widget we attach everything to
10 var w = new QxWidget();
11 with(w) {
12         setTop(0);
13         setLeft(0);
14         setWidth(docX());
15         setHeight(docY());
16 }
17
18 /* Qooxdoo's browser sniffer doesn't distinguish IE version.
19 We'll cover IE 6 for now, but these checks need to be
20 revisited for fuller browser coverage. */
21 var browser = QxClient().engine;
22
23 // DocX/Y returns the width/height of the page in browser
24 function docX()
25 {
26         var x;
27         if (browser != "mshtml") {
28                 x = window.innerWidth;
29         } else {
30                 x = document.documentElement.clientWidth;
31         }
32         return x;
33 }
34
35 function docY()
36 {
37         var y;
38         // Less 25px to not cover the toolbar
39         if (browser != "mshtml") {
40                 y = window.innerHeight - 25;
41         } else {
42                 y = document.documentElement.clientHeight;
43         }
44         return y;
45 }
46
47 //  If given a number, sizeX/Y returns in pixels a percentage of the browser
48 //  window. If given a Window object, sizeX/Y returns the size of that object. 
49 function sizeX(s)
50 {
51         var sX;
52
53         if (typeof(s) == 'number') {
54                 sX = Math.floor(docX() * s);
55         } else {
56                 sX = s.getMinWidth();
57         }
58
59         return sX;
60 }
61
62 function sizeY(s)
63 {
64         var sY;
65         if (typeof(s) == 'number') {
66                 sY = Math.floor(docY() * s);
67         } else {
68                 sY = s.getMinHeight();
69         }
70
71         return sY;
72 }
73
74 function getPosX(win)
75 {
76         var y = Math.floor( (docY() - sizeY(win)) * Math.random() );
77         return y;
78 }
79
80 function getPosY(win)
81 {
82         var x = Math.floor( (docX() - sizeX(win)) * Math.random() );
83         return x;
84 }
85
86 function openIn(e)
87 {
88         var blank = new Window("New Menu");
89         e.add(blank);
90         blank.setVisible(true);
91 }
92         
93 function winMenu(e)
94 {
95         var self = this;
96         var WinWin = new QxCommand();
97         WinWin.addEventListener("execute", function() {
98                 var blank = new QxWindow();
99                 self.add(blank);
100                 blank.setVisible(true);
101         }); 
102
103         var inset = new QxMenu;
104         var sub1 = new QxMenuButton("Open window in a window", null, WinWin);
105
106         inset.add(sub1);
107         self.add(inset)
108
109         cmenu.setVisible(false);
110         inset.setVisible(true);
111 }
112
113 function Window(h, src, s)
114 {
115         this.self = new QxWindow(h);
116
117         // Settings for all windows
118         if (s) {
119                 this.self.setMinWidth(sizeX(s));
120                 this.self.setMinHeight(sizeY(s));
121         }
122         this.self.setTop(getPosX(this.self));
123         this.self.setLeft(getPosY(this.self));
124
125         this.self.addEventListener("contextmenu", winMenu);
126
127         return this.self;
128 }
129
130 function SmallWindow(h, src)
131 {
132         this.self = new Window(h, src, .20);
133         return this.self;
134 }
135
136 function StandardWindow(h, src)
137 {
138         this.self = new Window(h, src, .45);
139         return this.self;
140 }
141
142 function LargeWindow(h, src)
143 {
144         this.self = new Window(h, src, .70);
145         return this.self;
146 }
147
148 Window.small = SmallWindow;
149 Window.standard = StandardWindow;
150 Window.large = LargeWindow;
151
152 window.application.main = function()
153 {
154         var doc = this.getClientWindow().getClientDocument();
155         doc.addEventListener("contextmenu", showContextMenu);
156         doc.add(w);
157 }
158
159 window.onresize = function() 
160 {
161         w.setWidth(docX());
162         w.setHeight(docY());
163 }
164