2 Copyright © 2011, The AROS Development Team. All rights reserved.
5 Desc: Workbook Icon Class
12 #include <aros/debug.h>
14 #include <proto/icon.h>
15 #include <proto/intuition.h>
16 #include <proto/gadtools.h>
17 #include <proto/utility.h>
18 #include <proto/exec.h>
19 #include <proto/dos.h>
20 #include <proto/icon.h>
21 #include <proto/graphics.h>
22 #include <proto/workbench.h>
24 #include <intuition/cghooks.h>
26 #include "workbook_intern.h"
31 struct DiskObject
*Icon
;
33 struct Screen
*Screen
;
35 struct timeval LastActive
;
38 const struct TagItem wbIcon_DrawTags
[] = {
39 { ICONDRAWA_Frameless
, TRUE
, },
40 { ICONDRAWA_Borderless
, TRUE
, },
41 { ICONDRAWA_EraseBackground
, FALSE
, },
45 void wbIcon_Update(Class
*cl
, Object
*obj
)
47 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
48 struct wbIcon
*my
= INST_DATA(cl
, obj
);
49 struct Rectangle rect
;
52 /* Update the parent's idea of how big we are
54 GetIconRectangleA(&my
->Screen
->RastPort
, my
->Icon
, (STRPTR
)my
->Label
, &rect
, (struct TagItem
*)wbIcon_DrawTags
);
56 w
= (rect
.MaxX
- rect
.MinX
) + 1;
57 h
= (rect
.MaxY
- rect
.MinY
) + 1;
59 /* If the icon is outside of the bounds for this
60 * screen, ignore the position information
62 if ((my
->Icon
->do_CurrentX
!= NO_ICON_POSITION
||
63 my
->Icon
->do_CurrentY
!= NO_ICON_POSITION
) && my
->Screen
) {
64 if ((my
->Icon
->do_CurrentX
!= NO_ICON_POSITION
&&
65 (my
->Icon
->do_CurrentX
< my
->Screen
->LeftEdge
||
66 (my
->Icon
->do_CurrentX
> (my
->Screen
->LeftEdge
+ my
->Screen
->Width
- w
)))) ||
67 (my
->Icon
->do_CurrentY
!= NO_ICON_POSITION
&&
68 (my
->Icon
->do_CurrentY
< my
->Screen
->TopEdge
||
69 (my
->Icon
->do_CurrentY
> (my
->Screen
->TopEdge
+ my
->Screen
->Height
- h
))))) {
70 my
->Icon
->do_CurrentY
= NO_ICON_POSITION
;
71 my
->Icon
->do_CurrentX
= NO_ICON_POSITION
;
75 D(bug("%s: %dx%d @%d,%d (%s)\n", my
->File
, (int)w
, (int)h
, (WORD
)my
->Icon
->do_CurrentX
, (WORD
)my
->Icon
->do_CurrentY
, my
->Label
));
77 GA_Left
, (my
->Icon
->do_CurrentX
== NO_ICON_POSITION
) ? ~0 : my
->Icon
->do_CurrentX
,
78 GA_Top
, (my
->Icon
->do_CurrentY
== NO_ICON_POSITION
) ? ~0 : my
->Icon
->do_CurrentY
,
85 static IPTR
wbIconNew(Class
*cl
, Object
*obj
, struct opSet
*ops
)
87 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
89 CONST_STRPTR file
, label
= "???";
91 obj
= (Object
*)DoSuperMethodA(cl
, obj
, (Msg
)ops
);
95 my
= INST_DATA(cl
, obj
);
98 my
->Icon
= (struct DiskObject
*)GetTagData(WBIA_Icon
, (IPTR
)NULL
, ops
->ops_AttrList
);
99 my
->Screen
= (struct Screen
*)GetTagData(WBIA_Screen
, (IPTR
)NULL
, ops
->ops_AttrList
);
100 if (my
->Icon
!= NULL
) {
101 if (my
->Icon
->do_Gadget
.GadgetText
!= NULL
&&
102 my
->Icon
->do_Gadget
.GadgetText
->IText
!= NULL
)
103 label
= my
->Icon
->do_Gadget
.GadgetText
->IText
;
105 file
= (CONST_STRPTR
)GetTagData(WBIA_File
, (IPTR
)NULL
, ops
->ops_AttrList
);
109 my
->File
= StrDup(file
);
110 if (my
->File
== NULL
)
113 strcpy(my
->File
, file
);
115 label
= FilePart(my
->File
);
117 my
->Icon
= GetIconTags(my
->File
,
118 ICONGETA_Screen
, my
->Screen
,
119 ICONGETA_FailIfUnavailable
, FALSE
,
121 if (my
->Icon
== NULL
)
126 my
->Label
= StrDup((CONST_STRPTR
)GetTagData(WBIA_Label
, (IPTR
)label
, ops
->ops_AttrList
));
127 if (my
->Label
== NULL
)
130 wbIcon_Update(cl
, obj
);
137 DoSuperMethod(cl
, obj
, OM_DISPOSE
);
142 static IPTR
wbIconDispose(Class
*cl
, Object
*obj
, Msg msg
)
144 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
145 struct wbIcon
*my
= INST_DATA(cl
, obj
);
147 struct TagItem tags
[] = {
148 { ICONPUTA_OnlyUpdatePosition
, TRUE
},
151 /* If need be, update the on-disk Icon's position information */
152 PutIconTagList(my
->File
, my
->Icon
, tags
);
155 /* If my->File is set, then we allocated it
156 * and my->Icon. Otherwise, Icon was passed in
157 * via WBIA_Icon, and its the caller's responsibility.
162 FreeDiskObject(my
->Icon
);
168 return DoSuperMethodA(cl
, obj
, msg
);
172 static IPTR
wbIconGet(Class
*cl
, Object
*obj
, struct opGet
*opg
)
174 struct wbIcon
*my
= INST_DATA(cl
, obj
);
177 switch (opg
->opg_AttrID
) {
179 *(opg
->opg_Storage
) = (IPTR
)my
->File
;
182 *(opg
->opg_Storage
) = (IPTR
)my
->Label
;
185 rc
= DoSuperMethodA(cl
, obj
, (Msg
)opg
);
193 static IPTR
wbIconRender(Class
*cl
, Object
*obj
, struct gpRender
*gpr
)
195 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
196 struct wbIcon
*my
= INST_DATA(cl
, obj
);
197 struct RastPort
*rp
= gpr
->gpr_RPort
;
198 struct Window
*win
= gpr
->gpr_GInfo
->gi_Window
;
200 struct Gadget
*gadget
= (struct Gadget
*)obj
; /* Legal for 'gadgetclass' */
203 x
= gadget
->LeftEdge
;
206 /* Clip to the window for drawing */
207 clip
= wbClipWindow(wb
, win
);
208 DrawIconStateA(rp
, my
->Icon
, (STRPTR
)my
->Label
, x
, y
,
209 (gadget
->Flags
& GFLG_SELECTED
) ? TRUE
: FALSE
, (struct TagItem
*)wbIcon_DrawTags
);
210 wbUnclipWindow(wb
, win
, clip
);
216 static IPTR
wbIconGoActive(Class
*cl
, Object
*obj
, struct gpInput
*gpi
)
218 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
219 struct wbIcon
*my
= INST_DATA(cl
, obj
);
220 struct Gadget
*gadget
= (struct Gadget
*)obj
;
225 if ((rp
= ObtainGIRPort(gpi
->gpi_GInfo
))) {
226 gadget
->Flags
^= GFLG_SELECTED
;
227 /* Clip to the window for drawing */
228 clip
= wbClipWindow(wb
, gpi
->gpi_GInfo
->gi_Window
);
229 DoMethod(obj
, GM_RENDER
, gpi
->gpi_GInfo
, rp
, GREDRAW_TOGGLE
);
230 wbUnclipWindow(wb
, gpi
->gpi_GInfo
->gi_Window
, clip
);
234 /* On a double-click, don't go 'active', just
237 dclicked
= DoubleClick(my
->LastActive
.tv_secs
,
238 my
->LastActive
.tv_micro
,
239 gpi
->gpi_IEvent
->ie_TimeStamp
.tv_secs
,
240 gpi
->gpi_IEvent
->ie_TimeStamp
.tv_micro
);
242 my
->LastActive
= gpi
->gpi_IEvent
->ie_TimeStamp
;
245 DoMethod(obj
, WBIM_Open
);
251 static IPTR
wbIconGoInactive(Class
*cl
, Object
*obj
, struct gpGoInactive
*gpgi
)
257 static IPTR
wbIconHandleInput(Class
*cl
, Object
*obj
, struct gpInput
*gpi
)
259 struct InputEvent
*iev
= gpi
->gpi_IEvent
;
261 if ((iev
->ie_Class
== IECLASS_RAWMOUSE
) &&
262 (iev
->ie_Code
== SELECTUP
))
269 static IPTR
wbIconOpen(Class
*cl
, Object
*obj
, Msg msg
)
271 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
272 struct wbIcon
*my
= INST_DATA(cl
, obj
);
274 struct TagItem tags
[] = {
275 { NP_Seglist
, (IPTR
)wb
->wb_OpenerSegList
},
276 { NP_Arguments
, (IPTR
)my
->File
},
277 { NP_FreeSeglist
, FALSE
},
286 static IPTR
wbIconCopy(Class
*cl
, Object
*obj
, Msg msg
)
292 static IPTR
wbIconRename(Class
*cl
, Object
*obj
, Msg msg
)
298 static IPTR
wbIconInfo(Class
*cl
, Object
*obj
, Msg msg
)
300 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
301 struct wbIcon
*my
= INST_DATA(cl
, obj
);
303 return WBInfo(BNULL
, my
->File
, NULL
);
307 static IPTR
wbIconSnapshot(Class
*cl
, Object
*obj
, Msg msg
)
313 static IPTR
wbIconUnsnapshot(Class
*cl
, Object
*obj
, Msg msg
)
319 static IPTR
wbIconLeaveOut(Class
*cl
, Object
*obj
, Msg msg
)
325 static IPTR
wbIconPutAway(Class
*cl
, Object
*obj
, Msg msg
)
331 static IPTR
wbIconDelete(Class
*cl
, Object
*obj
, Msg msg
)
337 static IPTR
wbIconFormat(Class
*cl
, Object
*obj
, Msg msg
)
343 static IPTR
wbIconEmptyTrash(Class
*cl
, Object
*obj
, Msg msg
)
348 static IPTR
dispatcher(Class
*cl
, Object
*obj
, Msg msg
)
352 switch (msg
->MethodID
) {
353 case OM_NEW
: rc
= wbIconNew(cl
, obj
, (APTR
)msg
); break;
354 case OM_DISPOSE
: rc
= wbIconDispose(cl
, obj
, (APTR
)msg
); break;
355 case OM_GET
: rc
= wbIconGet(cl
, obj
, (APTR
)msg
); break;
356 case GM_RENDER
: rc
= wbIconRender(cl
, obj
, (APTR
)msg
); break;
357 case GM_GOACTIVE
: rc
= wbIconGoActive(cl
, obj
, (APTR
)msg
); break;
358 case GM_GOINACTIVE
: rc
= wbIconGoInactive(cl
, obj
, (APTR
)msg
); break;
359 case GM_HANDLEINPUT
: rc
= wbIconHandleInput(cl
, obj
, (APTR
)msg
); break;
360 case WBIM_Open
: rc
= wbIconOpen(cl
, obj
, msg
); break;
361 case WBIM_Copy
: rc
= wbIconCopy(cl
, obj
, msg
); break;
362 case WBIM_Rename
: rc
= wbIconRename(cl
, obj
, msg
); break;
363 case WBIM_Info
: rc
= wbIconInfo(cl
, obj
, msg
); break;
364 case WBIM_Snapshot
: rc
= wbIconSnapshot(cl
, obj
, msg
); break;
365 case WBIM_Unsnapshot
: rc
= wbIconUnsnapshot(cl
, obj
, msg
); break;
366 case WBIM_Leave_Out
: rc
= wbIconLeaveOut(cl
, obj
, msg
); break;
367 case WBIM_Put_Away
: rc
= wbIconPutAway(cl
, obj
, msg
); break;
368 case WBIM_Delete
: rc
= wbIconDelete(cl
, obj
, msg
); break;
369 case WBIM_Format
: rc
= wbIconFormat(cl
, obj
, msg
); break;
370 case WBIM_Empty_Trash
: rc
= wbIconEmptyTrash(cl
, obj
, msg
); break;
371 default: rc
= DoSuperMethodA(cl
, obj
, msg
); break;
377 Class
*WBIcon_MakeClass(struct WorkbookBase
*wb
)
381 cl
= MakeClass( NULL
, "gadgetclass", NULL
,
382 sizeof(struct wbIcon
),
385 cl
->cl_Dispatcher
.h_Entry
= HookEntry
;
386 cl
->cl_Dispatcher
.h_SubEntry
= dispatcher
;
387 cl
->cl_Dispatcher
.h_Data
= NULL
;
388 cl
->cl_UserData
= (IPTR
)wb
;