r10212: An IE fix. Must set initial values in the onload function.
[mat/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
12 /* Qooxdoo's browser sniffer doesn't distinguish IE version.
13 We'll cover IE 6 for now, but these checks need to be
14 revisited for fuller browser coverage. */
15 var browser = QxClient().engine;
16
17 // DocX/Y returns the width/height of the page in browser
18 function docX()
19 {
20         var x;
21         if (browser != "mshtml") {
22                 x = window.innerWidth;
23         } else {
24                 x = document.documentElement.clientWidth;
25         }
26         return x;
27 }
28
29 function docY()
30 {
31         var y;
32         if (browser != "mshtml") {
33                 y = window.innerHeight;
34         } else {
35                 y = document.documentElement.clientHeight;
36         }
37         return y;
38 }
39
40 //  If given a number, sizeX/Y returns in pixels a percentage of the browser
41 //  window. If given a Window object, sizeX/Y returns the size of that object. 
42 function sizeX(s)
43 {
44         var sX;
45
46         if (typeof(s) == 'number') {
47                 sX = Math.floor(docX() * s);
48         } else {
49                 sX = s.getMinWidth();
50         }
51
52         return sX;
53 }
54
55 function sizeY(s)
56 {
57         var sY;
58         if (typeof(s) == 'number') {
59                 sY = Math.floor(docY() * s);
60         } else {
61                 sY = s.getMinHeight();
62         }
63
64         return sY;
65 }
66
67 function getPosX(win)
68 {
69         var y = Math.floor( (docY() - sizeY(win)) * Math.random() );
70         return y;
71 }
72
73 function getPosY(win)
74 {
75         var x = Math.floor( (docX() - sizeX(win)) * Math.random() );
76         return x;
77 }
78
79 function openIn(e)
80 {
81         var blank = new Window("New Menu");
82         e.add(blank);
83         blank.setVisible(true);
84 }
85         
86 function Window(h, src, s)
87 {
88         this.self = new QxWindow(h);
89
90         // Settings for all windows
91         if (s) {
92                 this.self.setMinWidth(sizeX(s));
93                 this.self.setMinHeight(sizeY(s));
94         }
95         this.self.setTop(getPosX(this.self));
96         this.self.setLeft(getPosY(this.self));
97
98         this.self.addEventListener("contextmenu", contextMenu);
99
100         return this.self;
101 }
102
103 function SmallWindow(h, src)
104 {
105         this.self = new Window(h, src, .20);
106         return this.self;
107 }
108
109 function StandardWindow(h, src)
110 {
111         this.self = new Window(h, src, .45);
112         return this.self;
113 }
114
115 function LargeWindow(h, src)
116 {
117         this.self = new Window(h, src, .70);
118         return this.self;
119 }
120
121 Window.small = SmallWindow;
122 Window.standard = StandardWindow;
123 Window.large = LargeWindow;
124
125 function contextMenu(e)
126 {       
127         var t = e.getTarget()
128         var tObj = t.getHtmlAttribute("class")
129
130         if (tObj == 'QxWidget') {
131                 clientContextMenu(e);
132         } else if (tObj == 'QxWindowPane') {
133                 windowContextMenu(t, e);
134         }
135 }
136
137
138 window.application.main = function()
139 {
140         with(w) {
141                 setTop(0);
142                 setLeft(0);
143                 setWidth(docX());
144                 setHeight(docY());
145         }
146
147         var doc = this.getClientWindow().getClientDocument();
148         doc.addEventListener("contextmenu", contextMenu);
149         doc.add(w);
150
151         var bar = new QxMenuBar;
152         with (bar) {
153                 setBottom(0);
154                 setLeft(0);
155                 setWidth("100%");
156                 setHeight(25);
157                 setBackgroundColor("ThreeDFace");
158         }
159
160         var start = new QxMenuButton("START");
161         start.addEventListener("click", function() {
162                 startMenu();
163         });
164         bar.add(start);
165
166         w.add(bar);
167 }
168
169 window.onresize = function() 
170 {
171         w.setWidth(docX());
172         w.setHeight(docY());
173 }
174