1 /* $Id: iconify.c,v 2.1 2000/09/29 17:24:09 amura Exp $ */
2 /*
3 * iconify.c
4 * Leo Schwab's iconify() compatible iconify routine.
5 *
6 * Copyright (C) 2000, MURAMATSU Atsushi All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY "MURAMATSU Atsushi" AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 /*
32 * $Log: iconify.c,v $
33 * Revision 2.1 2000/09/29 17:24:09 amura
34 * rewrite from scratch
35 *
36 */
37
38 #include "config.h"
39 #ifdef DO_ICONIFY
40 #include "def.h"
41
42 #include <exec/types.h>
43 #include <exec/memory.h>
44 #include "iconify.h"
45
46 #ifdef V2
47
48 #include <dos/dosextens.h>
49 #include <workbench/workbench.h>
50 #include <workbench/startup.h>
51 #include <clib/wb_protos.h>
52
53 extern struct Library *WorkbenchBase;
54
55 static struct DiskObject icondef = {
56 WB_DISKMAGIC,WB_DISKVERSION,
57 {NULL, 0, 0, 0/*width*/, 0/*height*/, GFLG_GADGIMAGE|GFLG_GADGHCOMP,
58 GACT_IMMEDIATE, GTYP_BOOLGADGET, NULL/*image*/, NULL, NULL,
59 0, NULL, 0, NULL},
60 0, NULL, NULL, NO_ICON_POSITION, NO_ICON_POSITION,
61 NULL, NULL, 0 };
62
63 int
iconify(x,y,width,height,etcptr,ptr,type)64 iconify(x, y, width, height, etcptr, ptr, type)
65 UWORD *x, *y, width, height;
66 APTR ptr;
67 APTR etcptr;
68 {
69 struct AppIcon *icon;
70 struct MsgPort *myport;
71 struct AppMessage *msg;
72 int done;
73
74 icondef.do_Gadget.Width = width;
75 icondef.do_Gadget.Height = height;
76 icondef.do_Gadget.GadgetRender = ptr;
77 icondef.do_CurrentX = NO_ICON_POSITION;
78 icondef.do_CurrentY = NO_ICON_POSITION;
79
80 if ((myport=(struct MsgPort *)CreateMsgPort()) == NULL)
81 return FALSE;
82 if (type == ICON_WB)
83 icon = AddAppIconA(0, 0, etcptr, myport,
84 NULL, &icondef, NULL);
85 else
86 icon = AddAppIconA(0, 0, NULL, myport,
87 NULL, &icondef, NULL);
88
89 if (icon == NULL)
90 {
91 while (msg=(struct AppMessage *)GetMsg(myport))
92 ReplyMsg((struct Message *)msg);
93 DeleteMsgPort(myport);
94 return FALSE;
95 }
96
97 done = FALSE;
98 while (!done)
99 {
100 WaitPort(myport);
101 while (msg = (struct AppMessage *)GetMsg(myport))
102 {
103 if (msg->am_NumArgs == 0L)
104 done = TRUE;
105 ReplyMsg((struct Message *)msg);
106 }
107 }
108
109 RemoveAppIcon(icon);
110 while (msg=(struct AppMessage *)GetMsg(myport))
111 ReplyMsg((struct Message *)msg);
112 DeleteMsgPort(myport);
113
114 return TRUE;
115 }
116
117 #else /* not V2 */
118
119 #include <graphics/gfxbase.h>
120 #include <intuition/intuition.h>
121 #include <intuition/intuitionbase.h>
122 #include <clib/intuition_protos.h>
123
124 static struct Gadget gadget = {
125 NULL, 0, 0, 0/*width*/, 0/*height*/, GFLG_GADGIMAGE|GFLG_GADGHCOMP,
126 GACT_IMMEDIATE, WDRAGGING, NULL/*image*/, NULL, NULL,
127 0, NULL, 0, NULL};
128
129 static struct NewWindow icondef = {
130 0, 0, /* start position */
131 0, 0, /* width, height */
132 0, 1, /* detail pen, block pen */
133 GADGETDOWN, /* mouse is used */
134 BORDERLESS|SMART_REFRESH|NOCAREREFRESH,
135 /* window flags */
136 &gadget, /* pointer to first user gadget */
137 NULL, /* pointer to user checkmark */
138 NULL, /* title (filled in later) */
139 NULL, /* pointer to screen (none) */
140 NULL, /* pointer to superbitmap */
141 0, 0, /* minimum size (small!) */
142 0, 0, /* maximum size (set by ttopen) */
143 WBENCHSCREEN /* screen in which to open */
144 };
145
146 int
iconify(x,y,width,height,etcptr,ptr,type)147 iconify(x, y, width, height, etcptr, ptr, type)
148 UWORD *x, *y, width, height;
149 APTR etcptr;
150 APTR ptr;
151 {
152 int done;
153 unsigned long secs,secs1,micros,micros1;
154 struct IntuiMessage *msg;
155 struct Window *icon;
156
157 icondef.Width = width;
158 icondef.Height = height;
159 icondef.LeftEdge = *x;
160 icondef.TopEdge = *y;
161
162 if (type==ICON_WB || etcptr==NULL)
163 icondef.Screen = (struct Screen *)WBENCHSCREEN;
164 else
165 icondef.Screen = (struct Screen *)etcptr;
166
167 gadget.Width = width;
168 gadget.Height = height;
169 gadget.GadgetRender = ptr;
170
171 if ((icon=OpenWindow(&icondef)) == NULL)
172 return FALSE;
173
174 micros1 = secs1 = 0;
175 done = FALSE;
176 while (!done)
177 {
178 Wait((long)(1L << icon->UserPort->mp_SigBit));
179 while (msg = (struct IntuiMessage *)GetMsg(icon->UserPort))
180 {
181 if (msg->Class == IDCMP_GADGETDOWN)
182 {
183 CurrentTime(&secs, µs);
184 if (DoubleClick(secs1, micros1, secs, micros))
185 done = TRUE;
186 secs1 = secs;
187 micros1 = micros;
188 }
189 ReplyMsg((struct Message *)msg);
190 }
191 }
192
193 CloseWindow(icon);
194 return TRUE;
195 }
196 #endif /* V2 */
197
198 #endif /* DO_ICONIFY */
199