1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
27 #include <intuition/icclass.h>
28 #include <classes/extwindow.h>
29 #include <gadgets/extscroller.h>
30 #include <images/titlebar.h>
31 #include <proto/utility.h>
32 #include <proto/intuition.h>
33 #include <proto/window.h>
34 #include <clib/alib_protos.h>
35 #include <SDI_compiler.h>
37 #define GA(o) ((struct Gadget *)(o))
40 struct Window
*window
;
52 #define GID_SNAPSHOT 0x7FFE
53 #define GID_VERTPROP 0x7FFD
54 #define GID_HORIZPROP 0x7FFC
55 #define EWFLG_SNAPSHOTGADGET 0x00000001
56 #define EWFLG_VERTPROPGADGET 0x00000002
58 static ULONG
EXTWINDOW_Dispatch (REG(a0
, Class
*cl
), REG(a2
, Object
*o
), REG(a1
, Msg msg
));
60 Class
*ExtWindowClass
;
62 Class
*InitExtWindowClass (void) {
63 ExtWindowClass
= MakeClass("extwindow.class", NULL
, WINDOW_GetClass(),
64 sizeof(struct ExtWindow
), 0);
66 ExtWindowClass
->cl_Dispatcher
.h_Entry
= EXTWINDOW_Dispatch
;
68 return ExtWindowClass
;
71 static ULONG
EXTWINDOW_New (Class
*cl
, Object
*o
, struct opSet
*ops
);
72 static ULONG
EXTWINDOW_Get (Class
*cl
, Object
*o
, struct opGet
*opg
);
73 static ULONG
EXTWINDOW_Open (Class
*cl
, Object
*o
, Msg msg
);
74 static ULONG
EXTWINDOW_Close (Class
*cl
, Object
*o
, Msg msg
);
75 static ULONG
EXTWINDOW_Dispose (Class
*cl
, Object
*o
, Msg msg
);
76 static ULONG
EXTWINDOW_HandleInput (Class
*cl
, Object
*o
, Msg msg
);
77 static void ParseTagList (const struct TagItem
*src_tags
,
78 struct TagItem
*win_tags
, struct TagItem
*extwin_tags
);
79 static struct Gadget
*FindSysGadget (struct Window
*window
, ULONG type
);
80 static BOOL
AddSnapshotGadget (struct ExtWindow
*extwin
);
81 static void RemSnapshotGadget (struct ExtWindow
*extwin
);
82 static BOOL
AddVertPropGadget (struct ExtWindow
*extwin
);
83 static void RemVertPropGadget (struct ExtWindow
*extwin
);
85 static ULONG
EXTWINDOW_Dispatch (REG(a0
, Class
*cl
), REG(a2
, Object
*o
), REG(a1
, Msg msg
)) {
86 switch (msg
->MethodID
) {
87 case OM_NEW
: return EXTWINDOW_New(cl
, o
, (struct opSet
*)msg
);
88 case OM_GET
: return EXTWINDOW_Get(cl
, o
, (struct opGet
*)msg
);
89 case WM_OPEN
: return EXTWINDOW_Open(cl
, o
, msg
);
91 case WM_ICONIFY
: return EXTWINDOW_Close(cl
, o
, msg
);
92 case OM_DISPOSE
: return EXTWINDOW_Dispose(cl
, o
, msg
);
93 case WM_HANDLEINPUT
: return EXTWINDOW_HandleInput(cl
, o
, msg
);
95 return DoSuperMethodA(cl
, o
, msg
);
98 static const struct TagItem up2vprop_map
[] = {
99 { GA_ID
, EXTSCROLLER_GoUp
},
102 static const struct TagItem down2vprop_map
[] = {
103 { GA_ID
, EXTSCROLLER_GoDown
},
107 static ULONG
EXTWINDOW_New (Class
*cl
, Object
*o
, struct opSet
*ops
) {
109 res
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)ops
);
111 struct TagItem
*tags
= ops
->ops_AttrList
;
112 struct ExtWindow
*extwin
= INST_DATA(cl
, res
);
113 LONG error_count
= 0;
114 if (GetTagData(EXTWINDOW_VertProp
, FALSE
, tags
)) {
115 extwin
->flags
|= EWFLG_VERTPROPGADGET
;
116 extwin
->vertpropgad
= ExtScrollerObject
,
118 PGA_Borderless
, TRUE
,
121 if (!extwin
->vertpropgad
) error_count
++;
122 extwin
->uparrowgad
= NewObject(NULL
, "buttongclass",
125 ICA_MAP
, up2vprop_map
,
126 ICA_TARGET
, extwin
->vertpropgad
,
128 if (!extwin
->uparrowgad
) error_count
++;
129 extwin
->downarrowgad
= NewObject(NULL
, "buttongclass",
132 ICA_MAP
, down2vprop_map
,
133 ICA_TARGET
, extwin
->vertpropgad
,
135 if (!extwin
->downarrowgad
) error_count
++;
137 if (GetTagData(EXTWINDOW_SnapshotGadget
, FALSE
, tags
)) {
138 extwin
->flags
|= EWFLG_SNAPSHOTGADGET
;
139 extwin
->snapshotgad
= NewObject(NULL
, "buttongclass",
143 if (!extwin
->snapshotgad
) error_count
++;
146 CoerceMethod(cl
, res
, OM_DISPOSE
);
153 static ULONG
EXTWINDOW_Get (Class
*cl
, Object
*o
, struct opGet
*opg
) {
154 struct ExtWindow
*extwin
= INST_DATA(cl
, o
);
155 switch (opg
->opg_AttrID
) {
156 case EXTWINDOW_VertObject
:
157 *opg
->opg_Storage
= (ULONG
)extwin
->vertpropgad
;
160 return DoSuperMethodA(cl
, o
, (Msg
)opg
);
165 static ULONG
EXTWINDOW_Open (Class
*cl
, Object
*o
, Msg msg
) {
166 struct ExtWindow
*extwin
= INST_DATA(cl
, o
);
168 res
= (struct Window
*)DoSuperMethodA(cl
, o
, msg
);
169 if (!extwin
->window
&& res
) {
170 extwin
->window
= res
;
171 extwin
->drawinfo
= GetScreenDrawInfo(res
->WScreen
);
172 if (extwin
->flags
& EWFLG_VERTPROPGADGET
) {
173 AddVertPropGadget(extwin
);
175 if (extwin
->flags
& EWFLG_SNAPSHOTGADGET
) {
176 AddSnapshotGadget(extwin
);
182 static ULONG
EXTWINDOW_Close (Class
*cl
, Object
*o
, Msg msg
) {
183 struct ExtWindow
*extwin
= INST_DATA(cl
, o
);
184 if (extwin
->window
) {
185 RemSnapshotGadget(extwin
);
186 RemVertPropGadget(extwin
);
187 FreeScreenDrawInfo(extwin
->window
->WScreen
, extwin
->drawinfo
);
188 extwin
->drawinfo
= NULL
;
189 extwin
->window
= NULL
;
191 return DoSuperMethodA(cl
, o
, msg
);
194 static ULONG
EXTWINDOW_Dispose (Class
*cl
, Object
*o
, Msg msg
) {
195 struct ExtWindow
*extwin
= INST_DATA(cl
, o
);
196 if (extwin
->window
) {
197 RemSnapshotGadget(extwin
);
198 RemVertPropGadget(extwin
);
199 FreeScreenDrawInfo(extwin
->window
->WScreen
, extwin
->drawinfo
);
200 extwin
->drawinfo
= NULL
;
201 extwin
->window
= NULL
;
203 DisposeObject(extwin
->snapshotgad
);
204 extwin
->snapshotgad
= NULL
;
205 DisposeObject(extwin
->downarrowgad
);
206 extwin
->downarrowgad
= NULL
;
207 DisposeObject(extwin
->uparrowgad
);
208 extwin
->uparrowgad
= NULL
;
209 DisposeObject(extwin
->vertpropgad
);
210 extwin
->vertpropgad
= NULL
;
211 return DoSuperMethodA(cl
, o
, msg
);
214 static ULONG
EXTWINDOW_HandleInput (Class
*cl
, Object
*o
, Msg msg
) {
216 res
= DoSuperMethodA(cl
, o
, msg
);
217 if ((res
& WMHI_CLASSMASK
) == WMHI_GADGETUP
) {
218 switch (res
& WMHI_GADGETMASK
) {
227 static struct Gadget
*FindSysGadget (struct Window
*window
, ULONG type
) {
230 gad
= window
->FirstGadget
;
232 if ((gad
->GadgetType
& (GTYP_SYSGADGET
|GTYP_SYSTYPEMASK
)) == (GTYP_SYSGADGET
|type
)) {
235 gad
= gad
->NextGadget
;
241 static BOOL
AddSnapshotGadget (struct ExtWindow
*extwin
) {
242 struct Window
*window
= extwin
->window
;
243 struct Gadget
*zoomgad
;
244 zoomgad
= FindSysGadget(window
, GTYP_WZOOM
);
248 extwin
->snapshotimg
= NewObject(NULL
, "tbiclass",
249 SYSIA_DrawInfo
, extwin
->drawinfo
,
250 SYSIA_Which
, SNAPSHOTIMAGE
,
252 if (!extwin
->snapshotimg
) {
255 SetAttrs(extwin
->snapshotgad
,
256 GA_Image
, extwin
->snapshotimg
,
257 GA_RelRight
, TBI_RELPOS(zoomgad
, 3),
259 GA_Width
, zoomgad
->Width
,
260 GA_Height
, zoomgad
->Height
,
263 AddGadget(window
, GA(extwin
->snapshotgad
), 0);
264 RefreshGList(GA(extwin
->snapshotgad
), window
, NULL
, 1);
268 static void RemSnapshotGadget (struct ExtWindow
*extwin
) {
269 if (extwin
->snapshotgad
) {
270 RemoveGadget(extwin
->window
, GA(extwin
->snapshotgad
));
271 SetAttrs(extwin
->snapshotgad
,
274 DisposeObject(extwin
->snapshotimg
);
275 extwin
->snapshotimg
= NULL
;
279 static BOOL
AddVertPropGadget (struct ExtWindow
*extwin
) {
280 struct Window
*window
= extwin
->window
;
281 struct Gadget
*sizegad
;
282 sizegad
= FindSysGadget(window
, GTYP_SIZING
);
286 extwin
->uparrowimg
= NewObject(NULL
, "sysiclass",
287 SYSIA_DrawInfo
, extwin
->drawinfo
,
288 SYSIA_Which
, UPIMAGE
,
290 if (!extwin
->uparrowimg
) {
293 extwin
->downarrowimg
= NewObject(NULL
, "sysiclass",
294 SYSIA_DrawInfo
, extwin
->drawinfo
,
295 SYSIA_Which
, DOWNIMAGE
,
297 if (!extwin
->downarrowimg
) {
298 DisposeObject(extwin
->uparrowimg
);
299 extwin
->uparrowimg
= NULL
;
302 SetAttrs(extwin
->vertpropgad
,
303 GA_RelRight
, -(window
->BorderRight
- 5),
304 GA_Top
, window
->BorderTop
+ 1,
305 GA_Width
, window
->BorderRight
- 8,
306 GA_RelHeight
, -(window
->BorderTop
+ sizegad
->Height
+ 4 + 2*sizegad
->Height
),
307 GA_RightBorder
, TRUE
,
309 SetAttrs(extwin
->uparrowgad
,
310 GA_Image
, extwin
->uparrowimg
,
311 GA_RelRight
, -(window
->BorderRight
- 1),
312 GA_RelBottom
, -(3*sizegad
->Height
+ 1),
313 GA_Width
, window
->BorderRight
,
314 GA_Height
, sizegad
->Height
,
316 SetAttrs(extwin
->downarrowgad
,
317 GA_Image
, extwin
->downarrowimg
,
318 GA_RelRight
, -(window
->BorderRight
- 1),
319 GA_RelBottom
, -(2*sizegad
->Height
),
320 GA_Width
, window
->BorderRight
,
321 GA_Height
, sizegad
->Height
,
323 AddGadget(window
, GA(extwin
->vertpropgad
), 0);
324 AddGadget(window
, GA(extwin
->uparrowgad
), 0);
325 AddGadget(window
, GA(extwin
->downarrowgad
), 0);
326 RefreshGList(GA(extwin
->vertpropgad
), window
, NULL
, 1);
327 RefreshGList(GA(extwin
->uparrowgad
), window
, NULL
, 1);
328 RefreshGList(GA(extwin
->downarrowgad
), window
, NULL
, 1);
332 static void RemVertPropGadget (struct ExtWindow
*extwin
) {
333 if (extwin
->vertpropgad
) {
334 RemoveGadget(extwin
->window
, GA(extwin
->vertpropgad
));
335 RemoveGadget(extwin
->window
, GA(extwin
->uparrowgad
));
336 RemoveGadget(extwin
->window
, GA(extwin
->downarrowgad
));
337 SetAttrs(extwin
->uparrowgad
,
340 SetAttrs(extwin
->downarrowgad
,
343 DisposeObject(extwin
->uparrowimg
);
344 extwin
->uparrowimg
= NULL
;
345 DisposeObject(extwin
->downarrowimg
);
346 extwin
->downarrowimg
= NULL
;