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 <gadgets/extscroller.h>
28 #include <proto/utility.h>
29 #include <proto/intuition.h>
30 #include <clib/alib_protos.h>
31 #include <SDI_compiler.h>
33 #define GA(o) ((struct Gadget *)(o))
40 static ULONG
EXTSCROLLER_Dispatch (REG(a0
, Class
*cl
), REG(a2
, Object
*o
), REG(a1
, Msg msg
));
42 Class
*ExtScrollerClass
;
44 Class
*InitExtScrollerClass (void) {
45 ExtScrollerClass
= MakeClass("extscroller.gadget", "propgclass", NULL
,
46 sizeof(struct ExtScroller
), 0);
47 if (ExtScrollerClass
) {
48 ExtScrollerClass
->cl_Dispatcher
.h_Entry
= EXTSCROLLER_Dispatch
;
50 return ExtScrollerClass
;
53 static ULONG
EXTSCROLLER_Get (Class
*cl
, Object
*o
, struct opGet
*opg
);
54 static ULONG
EXTSCROLLER_Set (Class
*cl
, Object
*o
, struct opSet
*ops
);
55 static void DoRender (Object
*o
, struct GadgetInfo
*ginfo
, ULONG flags
);
57 static ULONG
EXTSCROLLER_Dispatch (REG(a0
, Class
*cl
), REG(a2
, Object
*o
), REG(a1
, Msg msg
)) {
58 switch (msg
->MethodID
) {
59 case OM_GET
: return EXTSCROLLER_Get(cl
, o
, (struct opGet
*)msg
);
61 case OM_UPDATE
: return EXTSCROLLER_Set(cl
, o
, (struct opSet
*)msg
);
63 return DoSuperMethodA(cl
, o
, msg
);
66 static ULONG
EXTSCROLLER_Get (Class
*cl
, Object
*o
, struct opGet
*opg
) {
67 ULONG attrid
= opg
->opg_AttrID
;
72 case SCROLLER_Visible
:
79 return DoSuperMethodA(cl
, o
, (Msg
)opg
);
81 return DoSuperMethod(cl
, o
, OM_GET
, attrid
, opg
->opg_Storage
);
84 static ULONG
EXTSCROLLER_Set (Class
*cl
, Object
*o
, struct opSet
*ops
) {
85 struct ExtScroller
*extscr
= INST_DATA(cl
, o
);
86 struct TagItem
*tstate
= ops
->ops_AttrList
;
88 while ((tag
= NextTagItem(&tstate
))) {
89 switch (tag
->ti_Tag
) {
91 tag
->ti_Tag
= PGA_Total
;
93 extscr
->total
= tag
->ti_Data
;
95 case SCROLLER_Visible
:
96 tag
->ti_Tag
= PGA_Visible
;
98 extscr
->visible
= tag
->ti_Data
;
101 tag
->ti_Tag
= PGA_Top
;
103 case EXTSCROLLER_GoUp
:
104 case EXTSCROLLER_GoDown
:
105 if (tag
->ti_Data
== 1) {
107 struct TagItem tags
[2];
108 DoSuperMethod(cl
, o
, OM_GET
, PGA_Top
, &top
);
109 if (tag
->ti_Tag
== EXTSCROLLER_GoUp
) {
111 if (top
== min
) break;
113 if (top
< min
) top
= min
;
115 const LONG max
= extscr
->total
- extscr
->visible
;
116 if (top
== max
) break;
118 if (top
> max
) top
= max
;
120 tags
[0].ti_Tag
= PGA_Top
;
121 tags
[0].ti_Data
= top
;
122 tags
[1].ti_Tag
= TAG_END
;
123 DoSuperMethod(cl
, o
, OM_SET
, tags
, ops
->ops_GInfo
, 0);
124 DoSuperMethod(cl
, o
, OM_NOTIFY
, tags
, ops
->ops_GInfo
, 0);
125 DoRender(o
, ops
->ops_GInfo
, GREDRAW_UPDATE
);
130 return DoSuperMethodA(cl
, o
, (Msg
)ops
);
133 static void DoRender (Object
*o
, struct GadgetInfo
*ginfo
, ULONG flags
) {
135 rp
= ObtainGIRPort(ginfo
);
137 DoMethod(o
, GM_RENDER
, ginfo
, rp
, flags
);