Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / diskimage / ra_gui / extscrollerclass.c
blob103ab605db56ede2dac9bb52a9a4fb171dcd0135
1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 **
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
9 **
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))
35 struct ExtScroller {
36 LONG total;
37 LONG visible;
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);
60 case OM_SET:
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;
68 switch (attrid) {
69 case SCROLLER_Total:
70 attrid = PGA_Total;
71 break;
72 case SCROLLER_Visible:
73 attrid = PGA_Visible;
74 break;
75 case SCROLLER_Top:
76 attrid = PGA_Top;
77 break;
78 default:
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;
87 struct TagItem *tag;
88 while ((tag = NextTagItem(&tstate))) {
89 switch (tag->ti_Tag) {
90 case SCROLLER_Total:
91 tag->ti_Tag = PGA_Total;
92 case PGA_Total:
93 extscr->total = tag->ti_Data;
94 break;
95 case SCROLLER_Visible:
96 tag->ti_Tag = PGA_Visible;
97 case PGA_Visible:
98 extscr->visible = tag->ti_Data;
99 break;
100 case SCROLLER_Top:
101 tag->ti_Tag = PGA_Top;
102 break;
103 case EXTSCROLLER_GoUp:
104 case EXTSCROLLER_GoDown:
105 if (tag->ti_Data == 1) {
106 LONG top;
107 struct TagItem tags[2];
108 DoSuperMethod(cl, o, OM_GET, PGA_Top, &top);
109 if (tag->ti_Tag == EXTSCROLLER_GoUp) {
110 const LONG min = 0;
111 if (top == min) break;
112 top -= 5;
113 if (top < min) top = min;
114 } else {
115 const LONG max = extscr->total - extscr->visible;
116 if (top == max) break;
117 top += 5;
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);
127 break;
130 return DoSuperMethodA(cl, o, (Msg)ops);
133 static void DoRender (Object *o, struct GadgetInfo *ginfo, ULONG flags) {
134 struct RastPort *rp;
135 rp = ObtainGIRPort(ginfo);
136 if (rp) {
137 DoMethod(o, GM_RENDER, ginfo, rp, flags);
138 ReleaseGIRPort(rp);