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 "diskimage_device.h"
29 #include "device_locale.h"
30 #include <SDI_stdarg.h>
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
);
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
60 WA_IDCMP
, stop
? (IDCMP_CLOSEWINDOW
|IDCMP_GADGETUP
) : 0,
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
,
68 FUELGAUGE_ShortTicks
, TRUE
,
72 LAYOUT_AddChild
, ButtonObject
,
73 GA_ID
, GID_PROGRESS_CANCEL
,
75 GA_Text
, GetString(li
, MSG_CANCEL_GAD
),
78 CHILD_WeightedWidth
, 0,
82 if (pb
->pb_Window
&& RA_OpenWindow(pb
->pb_Window
)) {
87 DeleteProgressBar(Self
, pb
);
92 void DeleteProgressBar (APTR Self
, struct ProgressBar
*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
) {
111 struct DiskImageBase
*libBase
= pb
->pb_LibBase
;
112 struct Library
*IntuitionBase
= libBase
->IntuitionBase
;
115 while (WMHI_LASTMSG
!= (res
= RA_HandleInput(pb
->pb_Window
, &code
))) {
116 switch (res
& WMHI_CLASSMASK
) {
117 case WMHI_CLOSEWINDOW
:
121 switch (res
& WMHI_GADGETMASK
) {
122 case GID_PROGRESS_CANCEL
:
133 void SetProgressBarAttrsA (APTR Self
, struct ProgressBar
*pb
, const struct TagItem
*tags
) {
135 struct Library
*IntuitionBase
= pb
->pb_LibBase
->IntuitionBase
;
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
, ...) {
145 SetProgressBarAttrsA(Self
, pb
, (const struct TagItem
*)VA_ARG(tags
, const struct TagItem
*));
151 struct ProgressBar
*CreateProgressBar (APTR Self
, struct DiskImageUnit
*unit
, BOOL stop
) {
155 void DeleteProgressBar (APTR Self
, struct ProgressBar
*pb
) {
158 BOOL
ProgressBarInput (APTR Self
, struct ProgressBar
*pb
) {
162 void SetProgressBarAttrsA (APTR Self
, struct ProgressBar
*pb
, const struct TagItem
*tags
) {
165 VARARGS68K
void SetProgressBarAttrs (APTR Self
, struct ProgressBar
*pb
, ...) {