bddd38b60c8bfea88eae1faa030edd9284bababf
[jelmer/samba4-debian.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         if (browser != "mshtml") {
39                 y = window.innerHeight;
40         } else {
41                 y = document.documentElement.clientHeight;
42         }
43         return y;
44 }
45
46 //  If given a number, sizeX/Y returns in pixels a percentage of the browser
47 //  window. If given a Window object, sizeX/Y returns the size of that object. 
48 function sizeX(s)
49 {
50         var sX;
51
52         if (typeof(s) == 'number') {
53                 sX = Math.floor(docX() * s);
54         } else {
55                 sX = s.getMinWidth();
56         }
57
58         return sX;
59 }
60
61 function sizeY(s)
62 {
63         var sY;
64         if (typeof(s) == 'number') {
65                 sY = Math.floor(docY() * s);
66         } else {
67                 sY = s.getMinHeight();
68         }
69
70         return sY;
71 }
72
73 function getPosX(win)
74 {
75         var y = Math.floor( (docY() - sizeY(win)) * Math.random() );
76         return y;
77 }
78
79 function getPosY(win)
80 {
81         var x = Math.floor( (docX() - sizeX(win)) * Math.random() );
82         return x;
83 }
84
85 function openIn(e)
86 {
87         var blank = new Window("New Menu");
88         e.add(blank);
89         blank.setVisible(true);
90 }
91         
92 function Window(h, src, s)
93 {
94         this.self = new QxWindow(h);
95
96         // Settings for all windows
97         if (s) {
98                 this.self.setMinWidth(sizeX(s));
99                 this.self.setMinHeight(sizeY(s));
100         }
101         this.self.setTop(getPosX(this.self));
102         this.self.setLeft(getPosY(this.self));
103
104         this.self.addEventListener("contextmenu", contextMenu);
105
106         return this.self;
107 }
108
109 function SmallWindow(h, src)
110 {
111         this.self = new Window(h, src, .20);
112         return this.self;
113 }
114
115 function StandardWindow(h, src)
116 {
117         this.self = new Window(h, src, .45);
118         return this.self;
119 }
120
121 function LargeWindow(h, src)
122 {
123         this.self = new Window(h, src, .70);
124         return this.self;
125 }
126
127 Window.small = SmallWindow;
128 Window.standard = StandardWindow;
129 Window.large = LargeWindow;
130
131 function contextMenu(e)
132 {       
133         var t = e.getTarget()
134         var tObj = t.getHtmlAttribute("class")
135
136         if (tObj == 'QxWidget') {
137                 clientContextMenu(e);
138         } else if (tObj == 'QxWindowPane') {
139                 windowContextMenu(t, e);
140         }
141 }
142
143
144 window.application.main = function()
145 {
146         var doc = this.getClientWindow().getClientDocument();
147         doc.addEventListener("contextmenu", contextMenu);
148         doc.add(w);
149
150         var bar = new QxMenuBar;
151         with (bar) {
152                 setBottom(0);
153                 setLeft(0);
154                 setWidth("100%");
155                 setHeight(25);
156                 setBackgroundColor("ThreeDFace");
157         }
158
159         var start = new QxMenuButton("START");
160         start.addEventListener("click", function() {
161                 startMenu();
162         });
163         bar.add(start);
164
165         w.add(bar);
166 }
167
168 window.onresize = function() 
169 {
170         w.setWidth(docX());
171         w.setHeight(docY());
172 }
173