Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / diskimage / device / progress.c
blob70e385126eba56c5177760365ef84a6f27d96e4c
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 "diskimage_device.h"
28 #include "progress.h"
29 #include "device_locale.h"
30 #include <SDI_stdarg.h>
32 #ifndef __AROS__
33 #include <reaction/reaction_macros.h>
35 struct ProgressBar *CreateProgressBar (APTR Self, struct DiskImageUnit *unit, BOOL stop) {
36 struct DiskImageBase *libBase = unit->LibBase;
37 struct Screen *scr = unit->Screen;
38 struct Library *SysBase = libBase->SysBase;
39 struct ProgressBar *pb;
40 pb = AllocMem(sizeof(struct ProgressBar), MEMF_CLEAR);
41 if (pb) {
42 pb->pb_Screen = scr;
43 pb->pb_LibBase = libBase;
45 pb->pb_WindowBase = OpenLibrary("window.class", MIN_OS_VERSION);
46 pb->pb_LayoutBase = OpenLibrary("gadgets/layout.gadget", MIN_OS_VERSION);
47 pb->pb_FuelGaugeBase = OpenLibrary("gadgets/fuelgauge.gadget", MIN_OS_VERSION);
49 if (pb->pb_WindowBase && pb->pb_LayoutBase && pb->pb_FuelGaugeBase) {
50 struct Library *IntuitionBase = libBase->IntuitionBase;
51 struct Library *WindowBase = pb->pb_WindowBase;
52 struct Library *LayoutBase = pb->pb_LayoutBase;
53 struct Library *FuelGaugeBase = pb->pb_FuelGaugeBase;
54 struct LocaleInfo *li = &libBase->LocaleInfo;
56 pb->pb_Window = WindowObject,
57 WA_Title, unit->Node.ln_Name,
58 WA_Flags, (stop ? WFLG_CLOSEGADGET : 0)|WFLG_DRAGBAR|WFLG_DEPTHGADGET
59 |WFLG_NOCAREREFRESH,
60 WA_IDCMP, stop ? (IDCMP_CLOSEWINDOW|IDCMP_GADGETUP) : 0,
61 WA_PubScreen, scr,
62 WINDOW_Position, WPOS_CENTERSCREEN,
63 WINDOW_Layout, VLayoutObject,
64 LAYOUT_HorizAlignment, LALIGN_CENTER,
65 LAYOUT_AddChild, pb->pb_ProgressBar = FuelGaugeObject,
66 FUELGAUGE_Justification, FGJ_CENTER,
67 FUELGAUGE_Ticks, 5,
68 FUELGAUGE_ShortTicks, TRUE,
69 End,
70 CHILD_MinWidth, 300,
71 CHILD_MinHeight, 40,
72 LAYOUT_AddChild, ButtonObject,
73 GA_ID, GID_PROGRESS_CANCEL,
74 GA_RelVerify, stop,
75 GA_Text, GetString(li, MSG_CANCEL_GAD),
76 GA_Disabled, !stop,
77 End,
78 CHILD_WeightedWidth, 0,
79 End,
80 End;
82 if (pb->pb_Window && RA_OpenWindow(pb->pb_Window)) {
83 return pb;
87 DeleteProgressBar(Self, pb);
89 return NULL;
92 void DeleteProgressBar (APTR Self, struct ProgressBar *pb) {
93 if (pb) {
94 struct DiskImageBase *libBase = pb->pb_LibBase;
95 struct Library *SysBase = libBase->SysBase;
96 struct Library *IntuitionBase = libBase->IntuitionBase;
98 DisposeObject(pb->pb_Window);
100 CloseLibrary(pb->pb_FuelGaugeBase);
101 CloseLibrary(pb->pb_LayoutBase);
102 CloseLibrary(pb->pb_WindowBase);
104 FreeMem(pb, sizeof(struct ProgressBar));
108 BOOL ProgressBarInput (APTR Self, struct ProgressBar *pb) {
109 BOOL quit = FALSE;
110 if (pb) {
111 struct DiskImageBase *libBase = pb->pb_LibBase;
112 struct Library *IntuitionBase = libBase->IntuitionBase;
113 ULONG res;
114 UWORD code;
115 while (WMHI_LASTMSG != (res = RA_HandleInput(pb->pb_Window, &code))) {
116 switch (res & WMHI_CLASSMASK) {
117 case WMHI_CLOSEWINDOW:
118 quit = TRUE;
119 break;
120 case WMHI_GADGETUP:
121 switch (res & WMHI_GADGETMASK) {
122 case GID_PROGRESS_CANCEL:
123 quit = TRUE;
124 break;
126 break;
130 return quit;
133 void SetProgressBarAttrsA (APTR Self, struct ProgressBar *pb, const struct TagItem *tags) {
134 if (pb) {
135 struct Library *IntuitionBase = pb->pb_LibBase->IntuitionBase;
136 struct Window *win;
137 GetAttr(WINDOW_Window, pb->pb_Window, (IPTR *)&win);
138 SetGadgetAttrsA((struct Gadget *)pb->pb_ProgressBar, win, NULL, tags);
142 VARARGS68K void SetProgressBarAttrs (APTR Self, struct ProgressBar *pb, ...) {
143 VA_LIST tags;
144 VA_START(tags, pb);
145 SetProgressBarAttrsA(Self, pb, (const struct TagItem *)VA_ARG(tags, const struct TagItem *));
146 VA_END(tags);
149 #else
151 struct ProgressBar *CreateProgressBar (APTR Self, struct DiskImageUnit *unit, BOOL stop) {
152 return NULL;
155 void DeleteProgressBar (APTR Self, struct ProgressBar *pb) {
158 BOOL ProgressBarInput (APTR Self, struct ProgressBar *pb) {
159 return FALSE;
162 void SetProgressBarAttrsA (APTR Self, struct ProgressBar *pb, const struct TagItem *tags) {
165 VARARGS68K void SetProgressBarAttrs (APTR Self, struct ProgressBar *pb, ...) {
168 #endif