summaryrefslogtreecommitdiffstats
path: root/src/modules/objects/class_workspace.cpp
blob: 98f0a2fbc2b27a038ef80b26ac0d3a4d050cd322 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
//mdm:
//   File : class_workspace.cpp
//   Creation date : Sat Feb 12 23:01:48 CEST 2005
//   by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor).
//   Thanks to Lucia Papini (^ashura^) for English help.
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 1999-2005 Szymon Stefanek (pragma at kvirc dot net)
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//



#include <tqworkspace.h>
#include "class_workspace.h"
#include "kvi_error.h"
#include "kvi_debug.h"

#include "kvi_locale.h"
#include "kvi_iconmanager.h"

/*
	@doc:	workspace
	@keyterms:
		workspace object class,
	@title:
		workspace class
	@type:
		class
	@short:
		Provides a MDI workspace object
	@inherits:
		[class]object[/class]
		[class]widget[/class]
	@description:
		This widget provides a workspace window that can contain decorated window.
	@functions:
		!fn: <object> $activeWindow()
		Returns the active window, or 0 if no window is active.
		!fn: <boolean> $scrollBarsEnabled()
		Returns TRUE if the workspace provides scrollbars; otherwise returns FALSE.
		!fn: $setscrollBarsEnabled(<bEnabled:boolean>)
		Sets whether the workspace provides scrollbars to enable. (bEnabled 1 or 0)
		!fn: $cascade()
		Arranges all the child windows in a cascade pattern.
		!fn: $tile()
		Arranges all child windows in a tile pattern.
		!fn: $closeActiveWindow()
		Closes the child window that is currently active.
		!fn: $closeAllWindows()
		Closes all child windows.
		!fn: $activateNextWindow()
		Activates the next window in the child window chain.
		!fn: $activatePrevWindow()
		Activates the prev window in the child window chain.[br]

		|----CLASS EXAMPLE----|[br]
		|-Start:[br]
		#Let's start.[br]
		#We start the main class creation, in the constructor we do the[br]
		#widget's  showing, to give a particular pop-up[br]
		#creation  appearance.[br]
		class (ws,widget)[br]
		{[br]
			constructor[br]
			{[br]
				$$->$setGeometry(%X,%Y,100,100)[br]
				$$->%label=$new(label,$$)[br]
				$$->%label->$settext("Another class by N\&G")[br]
				$$->%label->$setautoresize(1)[br]
				$$->$show()[br]
			}[br]
		}[br]
		#We create the new workspace, and we set a 640x480 size with widget $resize[br]
		#command.[br]
		%Workspace=$new(workspace)[br]
		%Workspace->$resize(640,480)[br]
		#Now we make a cycling costruction of the widgets(look at the class),[br]
		#and give to the widgets a random X and Y coordinates.[br]
		#It takes few seconds to show the effects, be patient.[br]
		%I=0[br]
		while (%I<100)[br]
		{[br]
			%X=$rand(500)[br]
			%Y=$rand(480)[br]
			%Widget=$new(ws,%Workspace)[br]
			%I++[br]
		}[br]
		#Let's show the fireworks! EnJoY![br]
		%Workspace->$show()[br]
		|-Start:[br]
		|-|EXAMPLE n2:[br]
		#This is like the first example but it has a particular animation effect.[br]
		%Hex[]=$array(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)[br]
		class (ws,widget)[br]
		{[br]
			constructor[br]
			{[br]
			       $$->$setGeometry(%X,%Y,100,100)[br]
			       $$->%lay=$new(layout,$$)[br]
			       %i=0[br]
			       while (%i<10)[br]
				{[br]
					$$->%label=$new(label,$$)[br]
					$$->%label->$settext("Another class by N\&G")[br]
					%color=%Hex[$rand(15)]%Hex[$rand(15)]%Hex[$rand(15)]%Hex[$rand(15)]%Hex[$rand(15)]%Hex[$rand(15)][br]
					$$->%label->$setforegroundcolor(%color)[br]
					$$->%label->$setautoresize(1)[br]
					$$->%lay->$addwidget($$->%label,%i,0)[br]
					%i++;[br]
				}[br]
				$$->$show()[br]
			}[br]
			mousepressevent[br]
			{[br]
				if ($istimer(cycle) == 1) killtimer cycle[br]
			}[br]
		}[br]
		%Workspace=$new(workspace)[br]
		%Workspace->$resize(640,480)[br]
		%Workspace->$setCaption("Hit the mouse to stop cycling windows....")[br]
		%I=0[br]
		%Cicle=1[br]
		while (%I<20)[br]
		{[br]
			%X=$rand(500)[br]
			%Y=$rand(480)[br]
			%Widget=$new(ws,%Workspace)[br]
			%I++[br]
		}[br]
		%Workspace->$show[br]
		timer (cycle,3000)[br]
		{[br]
			if (%Cicle==1) %Workspace->$tile()[br]
			if (%Cicle==2)[br]
			{[br]
				%Workspace->$cascade()[br]
				%Cicle=1[br]
				return[br]
			}[br]
			%Cicle++[br]
		}[br]
		privateimpl(%Workspace,mousepressevent)[br]
		{[br]
			if ($istimer(cycle) == 1) killtimer cycle[br]
		}[br]
		#-|End.[br]

*/

KVSO_BEGIN_REGISTERCLASS(KviKvsObject_workspace,"workspace","widget")
	KVSO_REGISTER_HANDLER(KviKvsObject_workspace,"activeWindow", functionactiveWindow);
	KVSO_REGISTER_HANDLER(KviKvsObject_workspace,"scrollBarsEnabled", functionscrollBarsEnabled);
	KVSO_REGISTER_HANDLER(KviKvsObject_workspace,"setscrollBarsEnabled", functionsetscrollBarsEnabled);
	KVSO_REGISTER_HANDLER(KviKvsObject_workspace,"cascade", functioncascade);
	KVSO_REGISTER_HANDLER(KviKvsObject_workspace,"tile", functiontile);
	KVSO_REGISTER_HANDLER(KviKvsObject_workspace,"closeActiveWindow", functioncloseActiveWindow);
	KVSO_REGISTER_HANDLER(KviKvsObject_workspace,"closeAllWindows", functioncloseAllWindows);
	KVSO_REGISTER_HANDLER(KviKvsObject_workspace,"activateNextWindow", functionactivateNextWindow);
	KVSO_REGISTER_HANDLER(KviKvsObject_workspace,"activatePrevWindow", functionactivatePrevWindow);
KVSO_END_REGISTERCLASS(KviKvsObject_workspace)

KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_workspace,KviKvsObject_widget)

KVSO_END_CONSTRUCTOR(KviKvsObject_workspace)


KVSO_BEGIN_DESTRUCTOR(KviKvsObject_workspace)

KVSO_END_CONSTRUCTOR(KviKvsObject_workspace)

bool KviKvsObject_workspace::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams)
{
	setObject(new TQWorkspace(parentScriptWidget(), name()), true);
	return true;
}

bool KviKvsObject_workspace::functionactiveWindow(KviKvsObjectFunctionCall *c)
{
	//if(widget()) c->returnValue()->setHObject((unsigned long)(((TQWorkspace *)widget())->activeWindow()));
	// FIXME!
	c->returnValue()->setHObject(0);
	return true; //?pFIX ME?
}

bool KviKvsObject_workspace::functionscrollBarsEnabled(KviKvsObjectFunctionCall *c)
{
	if(widget())
	c->returnValue()->setBoolean(((TQWorkspace *)widget())->scrollBarsEnabled());
	return true;
}

bool KviKvsObject_workspace::functionsetscrollBarsEnabled(KviKvsObjectFunctionCall *c)
{
	bool bEnabled;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
	KVSO_PARAMETERS_END(c)
	if(widget())
		((TQWorkspace *)widget())->setScrollBarsEnabled(bEnabled);
	return true;
}

bool KviKvsObject_workspace::functioncascade(KviKvsObjectFunctionCall *c)
{
	if(widget())
		((TQWorkspace *)widget())->cascade();
	return true;
}

bool KviKvsObject_workspace::functiontile(KviKvsObjectFunctionCall *c)
{
	if(widget())
		((TQWorkspace *)widget())->tile();
	return true;
}

bool KviKvsObject_workspace::functioncloseActiveWindow(KviKvsObjectFunctionCall *c)
{
	if(widget())
		((TQWorkspace *)widget())->closeActiveWindow();
	return true;
}

bool KviKvsObject_workspace::functioncloseAllWindows(KviKvsObjectFunctionCall *c)
{
	if(widget())
		((TQWorkspace *)widget())->closeAllWindows();
	return true;
}

bool KviKvsObject_workspace::functionactivateNextWindow(KviKvsObjectFunctionCall *c)
{
	if(widget())
		((TQWorkspace *)widget())->activateNextWindow();
	return true;
}

bool KviKvsObject_workspace::functionactivatePrevWindow(KviKvsObjectFunctionCall *c)
{
	if(widget()){
		((TQWorkspace *)widget())->activatePrevWindow();
	}
		return true;
}