summaryrefslogtreecommitdiff
path: root/swat/scripting/client/desktop.js
blob: bddd38b60c8bfea88eae1faa030edd9284bababf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
   Windows, tabs, and general widgetry for SWAT.

   Copyright (C) Deryck Hodge 2005
   released under the GNU GPL Version 2 or later
*/


// The global widget we attach everything to
var w = new QxWidget();
with(w) {
	setTop(0);
	setLeft(0);
	setWidth(docX());
	setHeight(docY());
}

/* Qooxdoo's browser sniffer doesn't distinguish IE version.
We'll cover IE 6 for now, but these checks need to be
revisited for fuller browser coverage. */
var browser = QxClient().engine;

// DocX/Y returns the width/height of the page in browser
function docX()
{
	var x;
	if (browser != "mshtml") {
		x = window.innerWidth;
	} else {
		x = document.documentElement.clientWidth;
	}
	return x;
}

function docY()
{
	var y;
	if (browser != "mshtml") {
		y = window.innerHeight;
	} else {
		y = document.documentElement.clientHeight;
	}
	return y;
}

//  If given a number, sizeX/Y returns in pixels a percentage of the browser
//  window. If given a Window object, sizeX/Y returns the size of that object. 
function sizeX(s)
{
	var sX;

	if (typeof(s) == 'number') {
		sX = Math.floor(docX() * s);
	} else {
		sX = s.getMinWidth();
	}

	return sX;
}

function sizeY(s)
{
	var sY;
	if (typeof(s) == 'number') {
		sY = Math.floor(docY() * s);
	} else {
		sY = s.getMinHeight();
	}

	return sY;
}

function getPosX(win)
{
	var y = Math.floor( (docY() - sizeY(win)) * Math.random() );
	return y;
}

function getPosY(win)
{
	var x = Math.floor( (docX() - sizeX(win)) * Math.random() );
	return x;
}

function openIn(e)
{
	var blank = new Window("New Menu");
	e.add(blank);
	blank.setVisible(true);
}
	
function Window(h, src, s)
{
	this.self = new QxWindow(h);

	// Settings for all windows
	if (s) {
		this.self.setMinWidth(sizeX(s));
		this.self.setMinHeight(sizeY(s));
	}
	this.self.setTop(getPosX(this.self));
	this.self.setLeft(getPosY(this.self));

	this.self.addEventListener("contextmenu", contextMenu);

	return this.self;
}

function SmallWindow(h, src)
{
	this.self = new Window(h, src, .20);
	return this.self;
}

function StandardWindow(h, src)
{
	this.self = new Window(h, src, .45);
	return this.self;
}

function LargeWindow(h, src)
{
	this.self = new Window(h, src, .70);
	return this.self;
}

Window.small = SmallWindow;
Window.standard = StandardWindow;
Window.large = LargeWindow;

function contextMenu(e)
{	
	var t = e.getTarget()
	var tObj = t.getHtmlAttribute("class")

	if (tObj == 'QxWidget') {
		clientContextMenu(e);
	} else if (tObj == 'QxWindowPane') {
		windowContextMenu(t, e);
	}
}


window.application.main = function()
{
	var doc = this.getClientWindow().getClientDocument();
	doc.addEventListener("contextmenu", contextMenu);
	doc.add(w);

	var bar = new QxMenuBar;
	with (bar) {
		setBottom(0);
		setLeft(0);
		setWidth("100%");
		setHeight(25);
		setBackgroundColor("ThreeDFace");
	}

	var start = new QxMenuButton("START");
	start.addEventListener("click", function() {
		startMenu();
	});
	bar.add(start);

	w.add(bar);
}

window.onresize = function() 
{
	w.setWidth(docX());
	w.setHeight(docY());
}