2 Copyright © 2011, The AROS Development Team. All rights reserved.
5 Desc: Workbook Window Class
10 #include <aros/debug.h>
14 #include <intuition/icclass.h>
16 #include <proto/dos.h>
17 #include <proto/exec.h>
18 #include <proto/intuition.h>
19 #include <proto/utility.h>
20 #include <proto/gadtools.h>
21 #include <proto/workbench.h>
22 #include <proto/graphics.h>
23 #include <proto/layers.h>
24 #include <proto/icon.h>
26 #include <intuition/classusr.h>
27 #include <libraries/gadtools.h>
28 #include <exec/rawfmt.h>
30 #include "workbook_intern.h"
31 #include "workbook_menu.h"
34 #include <clib/boopsistubs.h>
36 static inline WORD
max(WORD a
, WORD b
)
38 return (a
> b
) ? a
: b
;
41 struct wbWindow_Icon
{
42 struct MinNode wbwiNode
;
49 struct Window
*Window
;
53 Object
*Area
; /* Virual area of icons */
54 Object
*Set
; /* Set of icons */
60 /* Temporary path buffer */
61 TEXT PathBuffer
[PATH_MAX
];
62 TEXT ScreenTitle
[256];
64 /* List of icons in this window */
65 struct MinList IconList
;
68 #define WBWF_USERPORT (1 << 0) /* Window has a custom port */
70 #define Broken NM_ITEMDISABLED |
72 static const struct NewMenu WBWindow_menu
[] = {
73 WBMENU_TITLE(WBMENU_WB
),
74 WBMENU_ITEM(WBMENU_WB_BACKDROP
),
75 WBMENU_ITEM(WBMENU_WB_EXECUTE
),
76 WBMENU_ITEM(WBMENU_WB_SHELL
),
77 WBMENU_ITEM(WBMENU_WB_ABOUT
),
79 WBMENU_ITEM(WBMENU_WB_QUIT
),
80 WBMENU_ITEM(WBMENU_WB_SHUTDOWN
),
81 WBMENU_TITLE(WBMENU_WN
),
82 WBMENU_ITEM(WBMENU_WN_NEW_DRAWER
),
83 WBMENU_ITEM(WBMENU_WN_OPEN_PARENT
),
84 WBMENU_ITEM(WBMENU_WN_UPDATE
),
85 WBMENU_ITEM(WBMENU_WN_SELECT_ALL
),
86 WBMENU_ITEM(WBMENU_WN_SELECT_NONE
),
87 WBMENU_SUBTITLE(WBMENU_WN__SNAP
),
88 WBMENU_SUBITEM(WBMENU_WN__SNAP_WINDOW
),
89 WBMENU_SUBITEM(WBMENU_WN__SNAP_ALL
),
90 WBMENU_SUBTITLE(WBMENU_WN__SHOW
),
91 WBMENU_SUBITEM(WBMENU_WN__SHOW_ICONS
),
92 WBMENU_SUBITEM(WBMENU_WN__SHOW_ALL
),
93 WBMENU_SUBTITLE(WBMENU_WN__VIEW
),
94 WBMENU_SUBITEM(WBMENU_WN__VIEW_ICON
),
95 WBMENU_SUBITEM(WBMENU_WN__VIEW_DETAILS
),
96 WBMENU_TITLE(WBMENU_IC
),
97 WBMENU_ITEM(WBMENU_IC_OPEN
),
98 WBMENU_ITEM(WBMENU_IC_COPY
),
99 WBMENU_ITEM(WBMENU_IC_RENAME
),
100 WBMENU_ITEM(WBMENU_IC_INFO
),
102 WBMENU_ITEM(WBMENU_IC_SNAPSHOT
),
103 WBMENU_ITEM(WBMENU_IC_UNSNAPSHOT
),
104 WBMENU_ITEM(WBMENU_IC_LEAVE_OUT
),
105 WBMENU_ITEM(WBMENU_IC_PUT_AWAY
),
107 WBMENU_ITEM(WBMENU_IC_DELETE
),
108 WBMENU_ITEM(WBMENU_IC_FORMAT
),
109 WBMENU_ITEM(WBMENU_IC_EMPTY_TRASH
),
113 static BOOL
wbMenuEnable(Class
*cl
, Object
*obj
, int id
, BOOL onoff
)
115 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
116 struct wbWindow
*my
= INST_DATA(cl
, obj
);
117 int i
, menu
= -1, item
= -1, sub
= -1;
118 UWORD MenuNumber
= MENUNULL
;
121 for (i
= 0; WBWindow_menu
[i
].nm_Type
!= NM_END
; i
++) {
122 const struct NewMenu
*nm
= &WBWindow_menu
[i
];
124 switch (nm
->nm_Type
) {
141 if (nm
->nm_UserData
== (APTR
)(IPTR
)id
) {
142 MenuNumber
= FULLMENUNUM(menu
, item
, sub
);
147 if (MenuNumber
!= MENUNULL
) {
149 OnMenu(my
->Window
, MenuNumber
);
151 OffMenu(my
->Window
, MenuNumber
);
159 AROS_UFH3(ULONG
, wbFilterIcons_Hook
,
160 AROS_UFHA(struct Hook
*, hook
, A0
),
161 AROS_UFHA(struct ExAllData
*, ead
, A2
),
162 AROS_UFHA(LONG
*, type
, A1
))
167 if (stricmp(ead
->ed_Name
, "disk.info") == 0)
170 i
= strlen(ead
->ed_Name
);
171 if (i
>= 5 && stricmp(&ead
->ed_Name
[i
-5], ".info") == 0) {
172 ead
->ed_Name
[i
-5] = 0;
176 if (stricmp(ead
->ed_Name
, ".backdrop") == 0)
184 AROS_UFH3(ULONG
, wbFilterAll_Hook
,
185 AROS_UFHA(struct Hook
*, hook
, A0
),
186 AROS_UFHA(struct ExAllData
*, ead
, A2
),
187 AROS_UFHA(LONG
*, type
, A1
))
193 if (stricmp(ead
->ed_Name
, "disk.info") == 0)
196 i
= strlen(ead
->ed_Name
);
197 if (i
>= 5 && stricmp(&ead
->ed_Name
[i
-5], ".info") == 0) {
198 ead
->ed_Name
[i
-5] = 0;
202 if (stricmp(ead
->ed_Name
, ".backdrop") == 0)
210 static int wbwiIconCmp(Class
*cl
, Object
*obj
, Object
*a
, Object
*b
)
212 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
214 CONST_STRPTR al
= NULL
, bl
= NULL
;
216 GetAttr(WBIA_Label
, a
, (IPTR
*)&al
);
217 GetAttr(WBIA_Label
, b
, (IPTR
*)&bl
);
228 return Stricmp(al
, bl
);
231 static void wbwiAppend(Class
*cl
, Object
*obj
, Object
*iobj
)
233 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
234 struct wbWindow
*my
= INST_DATA(cl
, obj
);
235 struct wbWindow_Icon
*wbwi
;
237 wbwi
= AllocMem(sizeof(*wbwi
), MEMF_ANY
);
241 struct wbWindow_Icon
*tmp
, *pred
= NULL
;
242 wbwi
->wbwiObject
= iobj
;
244 /* Insert in Alpha order */
245 ForeachNode(&my
->IconList
, tmp
) {
246 if (wbwiIconCmp(cl
, obj
, tmp
->wbwiObject
, wbwi
->wbwiObject
) == 0) {
250 if (wbwiIconCmp(cl
, obj
, tmp
->wbwiObject
, wbwi
->wbwiObject
) < 0)
255 Insert((struct List
*)&my
->IconList
, (struct Node
*)wbwi
, (struct Node
*)pred
);
259 static void wbAddFiles(Class
*cl
, Object
*obj
)
261 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
262 struct wbWindow
*my
= INST_DATA(cl
, obj
);
263 struct ExAllControl
*eac
;
264 struct ExAllData
*ead
;
265 const ULONG eadSize
= sizeof(struct ExAllData
) + 1024;
269 path
= AllocVec(1024, MEMF_ANY
);
273 if (!NameFromLock(my
->Lock
, path
, 1024)) {
276 file_part
= strlen(path
);
278 ead
= AllocVec(eadSize
, MEMF_CLEAR
);
280 eac
= AllocDosObject(DOS_EXALLCONTROL
, NULL
);
285 hook
.h_Entry
= my
->FilterHook
;
286 hook
.h_SubEntry
= NULL
;
289 eac
->eac_MatchFunc
= &hook
;
291 struct ExAllData
*tmp
= ead
;
294 more
= ExAll(my
->Lock
, ead
, eadSize
, ED_NAME
, eac
);
295 for (i
= 0; i
< eac
->eac_Entries
; i
++, tmp
=tmp
->ed_Next
) {
298 if (AddPart(path
, tmp
->ed_Name
, 1024)) {
299 iobj
= NewObject(WBIcon
, NULL
,
301 WBIA_Label
, tmp
->ed_Name
,
302 WBIA_Screen
, my
->Window
->WScreen
,
305 wbwiAppend(cl
, obj
, iobj
);
309 FreeDosObject(DOS_EXALLCONTROL
, eac
);
317 static void wbAddVolumeIcons(Class
*cl
, Object
*obj
)
319 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
320 struct wbWindow
*my
= INST_DATA(cl
, obj
);
324 /* Add all the DOS disks */
325 dl
= LockDosList(LDF_VOLUMES
| LDF_READ
);
331 while ((tdl
= NextDosEntry(tdl
, LDF_VOLUMES
))) {
334 CopyMem(AROS_BSTR_ADDR(tdl
->dol_Name
), text
, AROS_BSTR_strlen(tdl
->dol_Name
));
335 CopyMem(":",&text
[AROS_BSTR_strlen(tdl
->dol_Name
)],2);
337 iobj
= NewObject(WBIcon
, NULL
,
339 WBIA_Label
, AROS_BSTR_ADDR(tdl
->dol_Name
),
340 WBIA_Screen
, my
->Window
->WScreen
,
342 D(bug("Volume: %s => %p\n", text
, iobj
));
344 wbwiAppend(cl
, obj
, iobj
);
346 UnLockDosList(LDF_VOLUMES
| LDF_READ
);
350 static void wbAddAppIcons(Class
*cl
, Object
*obj
)
352 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
353 struct wbWindow
*my
= INST_DATA(cl
, obj
);
354 struct DiskObject
*icon
;
357 /* Add all the AppIcons */
359 while ((icon
= GetNextAppIcon(icon
, &text
[0]))) {
360 Object
*iobj
= NewObject(WBIcon
, NULL
,
362 WBIA_Screen
, my
->Window
->WScreen
,
365 wbwiAppend(cl
, obj
, iobj
);
369 static void wbRedimension(Class
*cl
, Object
*obj
)
371 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
372 struct wbWindow
*my
= INST_DATA(cl
, obj
);
373 struct Window
*win
= my
->Window
;
374 struct IBox real
; /* pos & size of the inner window area */
375 IPTR setWidth
= 0, setHeight
= 0;
377 real
.Left
= win
->BorderLeft
;
378 real
.Top
= win
->BorderTop
;
379 real
.Width
= win
->Width
- (win
->BorderLeft
+ win
->BorderRight
);
380 real
.Height
= win
->Height
- (win
->BorderTop
+ win
->BorderBottom
);
382 D(bug("%s: Real (%d,%d) %dx%d\n", __func__
,
383 real
.Left
, real
.Top
, real
.Width
, real
.Height
));
384 D(bug("%s: Border (%d,%d) %dx%d\n", __func__
,
385 my
->Window
->BorderLeft
, my
->Window
->BorderTop
,
386 my
->Window
->BorderRight
, my
->Window
->BorderBottom
));
388 SetAttrs(my
->Area
, GA_Top
, real
.Top
,
390 GA_Width
, real
.Width
,
391 GA_Height
, real
.Height
,
394 SetAttrs(my
->ScrollH
, PGA_Visible
, real
.Width
,
396 GA_RelBottom
, -(my
->Window
->BorderBottom
- 2),
397 GA_Width
, real
.Width
,
398 GA_Height
, my
->Window
->BorderBottom
- 3,
401 SetAttrs(my
->ScrollV
, PGA_Visible
, real
.Height
,
402 GA_RelRight
, -(my
->Window
->BorderRight
- 2),
404 GA_Width
, my
->Window
->BorderRight
- 3,
405 GA_Height
, real
.Height
,
408 GetAttr(GA_Width
, my
->Set
, &setWidth
);
409 GetAttr(GA_Height
, my
->Set
, &setHeight
);
410 UpdateAttrs(obj
, NULL
, 0,
411 WBVA_VirtWidth
, setWidth
,
412 WBVA_VirtHeight
, setHeight
,
415 /* Clear the background to the right of the icons*/
416 if (setWidth
< real
.Width
) {
417 SetAPen(win
->RPort
,0);
418 RectFill(win
->RPort
, win
->BorderLeft
+ setWidth
, win
->BorderTop
,
419 win
->Width
- win
->BorderRight
- 1,
420 win
->Height
- win
->BorderBottom
- 1);
422 setWidth
= real
.Width
;
425 /* Clear the background beneath the icons*/
426 if (setHeight
< real
.Height
) {
427 SetAPen(win
->RPort
,0);
428 RectFill(win
->RPort
, win
->BorderLeft
, win
->BorderTop
+ setHeight
,
429 setWidth
- win
->BorderRight
- 1,
430 win
->Height
- win
->BorderBottom
- 1);
435 /* Rescan the Lock for new entries */
436 static void wbRescan(Class
*cl
, Object
*obj
)
438 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
439 struct wbWindow
*my
= INST_DATA(cl
, obj
);
440 struct wbWindow_Icon
*wbwi
;
442 /* We're going to busy for a while */
443 D(bug("BUSY....\n"));
444 SetWindowPointer(my
->Window
, WA_BusyPointer
, TRUE
, TAG_END
);
446 /* Remove and undisplay any existing icons */
447 while ((wbwi
= (struct wbWindow_Icon
*)REMHEAD(&my
->IconList
)) != NULL
) {
448 DoMethod(my
->Set
, OM_REMMEMBER
, wbwi
->wbwiObject
);
449 DisposeObject(wbwi
->wbwiObject
);
450 FreeMem(wbwi
, sizeof(*wbwi
));
453 /* Scan for new icons, and add them to the list
455 if (my
->Lock
== BNULL
) {
457 wbAddVolumeIcons(cl
, obj
);
458 wbAddAppIcons(cl
, obj
);
460 /* Directory window */
464 /* Display the new icons */
465 ForeachNode(&my
->IconList
, wbwi
)
466 DoMethod(my
->Set
, OM_ADDMEMBER
, wbwi
->wbwiObject
);
468 /* Adjust the scrolling regions */
469 wbRedimension(cl
, obj
);
471 /* Return the point back to normal */
472 SetWindowPointer(my
->Window
, WA_BusyPointer
, FALSE
, TAG_END
);
473 D(bug("Not BUSY....\n"));
477 const struct TagItem scrollv2window
[] = {
478 { PGA_Top
, WBVA_VirtTop
},
481 const struct TagItem scrollh2window
[] = {
482 { PGA_Top
, WBVA_VirtLeft
},
486 static void wbFixBorders(struct Window
*win
)
490 bb
= 16 - win
->BorderBottom
;
491 br
= 16 - win
->BorderRight
;
493 win
->BorderBottom
+= bb
;
494 win
->BorderRight
+= br
;
497 static IPTR
WBWindowNew(Class
*cl
, Object
*obj
, struct opSet
*ops
)
499 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
501 struct MsgPort
*userport
;
506 struct wbWindow_Icon
*wbwi
;
508 rc
= DoSuperMethodA(cl
, obj
, (Msg
)ops
);
513 my
= INST_DATA(cl
, obj
);
515 NEWLIST(&my
->IconList
);
516 my
->FilterHook
= wbFilterIcons_Hook
;
518 path
= (CONST_STRPTR
)GetTagData(WBWA_Path
, (IPTR
)NULL
, ops
->ops_AttrList
);
523 my
->Lock
= Lock(path
, SHARED_LOCK
);
524 if (my
->Lock
== BNULL
)
527 my
->Path
= AllocVec(strlen(path
)+1, MEMF_ANY
);
528 if (my
->Path
== NULL
)
531 strcpy(my
->Path
, path
);
534 /* Create icon set */
535 my
->Set
= NewObject(WBSet
, NULL
,
538 idcmp
= IDCMP_MENUPICK
| IDCMP_INTUITICKS
;
539 if (my
->Path
== NULL
) {
540 my
->Window
= OpenWindowTags(NULL
,
543 WA_WBenchWindow
, TRUE
,
546 WA_SmartRefresh
, TRUE
,
547 WA_NewLookMenus
, TRUE
,
549 TAG_MORE
, ops
->ops_AttrList
);
550 my
->Window
->BorderTop
= my
->Window
->WScreen
->BarHeight
+1;
552 struct DiskObject
*icon
;
553 struct NewWindow
*nwin
= NULL
;
554 struct TagItem extra
[] = {
559 { TAG_MORE
, (IPTR
)ops
->ops_AttrList
},
562 icon
= GetDiskObjectNew(my
->Path
);
566 if (icon
->do_DrawerData
) {
567 nwin
= &icon
->do_DrawerData
->dd_NewWindow
;
568 D(bug("%s: NewWindow %p\n", __func__
, nwin
));
569 extra
[0].ti_Tag
= TAG_MORE
;
570 extra
[0].ti_Data
= (IPTR
)ops
->ops_AttrList
;
573 idcmp
|= IDCMP_NEWSIZE
| IDCMP_CLOSEWINDOW
;
574 my
->Window
= OpenWindowTags(nwin
,
581 WA_WBenchWindow
, TRUE
,
583 WA_SmartRefresh
, TRUE
,
586 WA_DepthGadget
, TRUE
,
587 WA_CloseGadget
, TRUE
,
589 WA_NewLookMenus
, TRUE
,
592 TAG_MORE
, (IPTR
)&extra
[0] );
595 wbFixBorders(my
->Window
);
597 FreeDiskObject(icon
);
603 /* If we want a shared port, do it. */
604 userport
= (struct MsgPort
*)GetTagData(WBWA_UserPort
, (IPTR
)NULL
, ops
->ops_AttrList
);
606 my
->Flags
|= WBWF_USERPORT
;
607 my
->Window
->UserPort
= userport
;
609 ModifyIDCMP(my
->Window
, idcmp
);
611 /* The gadgets' layout will be performed during wbRedimension
613 AddGadget(my
->Window
, (struct Gadget
*)(my
->Area
= NewObject(WBVirtual
, NULL
,
614 WBVA_Gadget
, (IPTR
)my
->Set
,
617 /* Add the verical scrollbar */
618 AddGadget(my
->Window
, (struct Gadget
*)(my
->ScrollV
= NewObject(NULL
, "propgclass",
619 GA_RightBorder
, TRUE
,
621 ICA_TARGET
, (IPTR
)obj
,
622 ICA_MAP
, (IPTR
)scrollv2window
,
623 PGA_Freedom
, FREEVERT
,
625 PGA_Borderless
, TRUE
,
631 /* Add the horizontal scrollbar */
632 AddGadget(my
->Window
, (struct Gadget
*)(my
->ScrollH
= NewObject(NULL
, "propgclass",
633 ICA_TARGET
, (IPTR
)obj
,
634 ICA_MAP
, (IPTR
)scrollh2window
,
635 PGA_Freedom
, FREEHORIZ
,
637 PGA_Borderless
, TRUE
,
643 /* Send first intuitick */
644 DoMethod(obj
, WBWM_INTUITICK
);
646 my
->Menu
= CreateMenusA((struct NewMenu
*)WBWindow_menu
, NULL
);
647 if (my
->Menu
== NULL
)
650 vis
= GetVisualInfo(my
->Window
->WScreen
, TAG_END
);
651 LayoutMenus(my
->Menu
, vis
, TAG_END
);
654 SetMenuStrip(my
->Window
, my
->Menu
);
656 /* Disable opening the parent for root window
659 if (my
->Lock
== BNULL
) {
660 wbMenuEnable(cl
, obj
, WBMENU_ID(WBMENU_WN_OPEN_PARENT
), FALSE
);
662 BPTR lock
= ParentDir(my
->Lock
);
664 wbMenuEnable(cl
, obj
, WBMENU_ID(WBMENU_WN_OPEN_PARENT
), FALSE
);
670 SetAttrs(my
->Set
, WBSA_MaxWidth
, my
->Window
->Width
- (my
->Window
->BorderLeft
+ my
->Window
->BorderRight
));
671 RefreshGadgets(my
->Window
->FirstGadget
, my
->Window
, NULL
);
678 while ((wbwi
= (APTR
)GetHead(&my
->IconList
))) {
679 Remove((struct Node
*)wbwi
);
680 FreeMem(wbwi
, sizeof(*wbwi
));
684 DisposeObject(my
->Set
);
687 CloseWindow(my
->Window
);
692 if (my
->Lock
!= BNULL
)
695 DoSuperMethod(cl
, obj
, OM_DISPOSE
, 0);
699 static IPTR
WBWindowDispose(Class
*cl
, Object
*obj
, Msg msg
)
701 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
702 struct wbWindow
*my
= INST_DATA(cl
, obj
);
703 struct wbWindow_Icon
*wbwi
;
705 ClearMenuStrip(my
->Window
);
708 /* If we have a custom user port, be paranoid.
709 * See the Autodocs for CloseWindow().
711 if (my
->Flags
& WBWF_USERPORT
) {
712 struct IntuiMessage
*msg
;
716 msg
= (APTR
)my
->Window
->UserPort
->mp_MsgList
.lh_Head
;
717 while ((succ
= msg
->ExecMessage
.mn_Node
.ln_Succ
)) {
718 if (msg
->IDCMPWindow
== my
->Window
) {
720 ReplyMsg((struct Message
*)msg
);
723 msg
= (struct IntuiMessage
*) succ
;
726 my
->Window
->UserPort
= NULL
;
727 ModifyIDCMP(my
->Window
, 0);
732 /* We won't need our list of icons anymore */
733 while ((wbwi
= (APTR
)GetHead(&my
->IconList
))) {
734 Remove((struct Node
*)wbwi
);
735 FreeMem(wbwi
, sizeof(*wbwi
));
738 /* As a side effect, this will close all the
739 * gadgets attached to it.
741 CloseWindow(my
->Window
);
743 /* .. except for my->Set */
744 DisposeObject(my
->Set
);
749 if (my
->Lock
!= BNULL
)
752 return DoSuperMethodA(cl
, obj
, msg
);
756 static IPTR
WBWindowGet(Class
*cl
, Object
*obj
, struct opGet
*opg
)
758 struct wbWindow
*my
= INST_DATA(cl
, obj
);
761 switch (opg
->opg_AttrID
) {
763 *(opg
->opg_Storage
) = (IPTR
)my
->Path
;
766 *(opg
->opg_Storage
) = (IPTR
)my
->Window
;
769 rc
= DoSuperMethodA(cl
, obj
, (Msg
)opg
);
777 static IPTR
WBWindowUpdate(Class
*cl
, Object
*obj
, struct opUpdate
*opu
)
779 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
780 struct wbWindow
*my
= INST_DATA(cl
, obj
);
781 struct TagItem
*tstate
;
785 rc
= DoSuperMethodA(cl
, obj
, (Msg
)opu
);
787 /* Also send these to the Area */
788 rc
|= DoMethodA(my
->Area
, (Msg
)opu
);
790 /* Update scrollbars if needed */
791 tstate
= opu
->opu_AttrList
;
792 while ((tag
= NextTagItem(&tstate
))) {
793 switch (tag
->ti_Tag
) {
801 SetAttrs(my
->ScrollH
, PGA_Total
, tag
->ti_Data
, TAG_END
);
804 case WBVA_VirtHeight
:
805 SetAttrs(my
->ScrollV
, PGA_Total
, tag
->ti_Data
, TAG_END
);
811 if (rc
&& !(opu
->opu_Flags
& OPUF_INTERIM
))
812 RefreshGadgets(my
->Window
->FirstGadget
, my
->Window
, NULL
);
818 static IPTR
WBWindowNewSize(Class
*cl
, Object
*obj
, Msg msg
)
820 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
821 struct wbWindow
*my
= INST_DATA(cl
, obj
);
822 struct Window
*win
= my
->Window
;
825 SetAttrs(my
->Set
, WBSA_MaxWidth
, win
->Width
- (win
->BorderLeft
+ win
->BorderRight
));
827 /* Clip to the window for drawing */
828 clip
= wbClipWindow(wb
, win
);
829 wbRedimension(cl
, obj
);
830 wbUnclipWindow(wb
, win
, clip
);
835 static IPTR
WBWindowRefresh(Class
*cl
, Object
*obj
, Msg msg
)
837 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
838 struct wbWindow
*my
= INST_DATA(cl
, obj
);
839 struct Window
*win
= my
->Window
;
842 EndRefresh(win
, TRUE
);
847 static void NewCLI(Class
*cl
, Object
*obj
)
849 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
850 struct wbWindow
*my
= INST_DATA(cl
, obj
);
854 SetWindowPointer(my
->Window
, WA_BusyPointer
, TRUE
, TAG_END
);
855 dir
= CurrentDir(my
->Lock
);
856 Execute("", BNULL
, BNULL
);
858 SetWindowPointer(my
->Window
, WA_BusyPointer
, FALSE
, TAG_END
);
861 static IPTR
WBWindowForSelectedIcons(Class
*cl
, Object
*obj
, IPTR MethodID
)
863 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
864 struct wbWindow
*my
= INST_DATA(cl
, obj
);
865 struct wbWindow_Icon
*wbwi
;
868 ForeachNode(&my
->IconList
, wbwi
) {
869 IPTR selected
= FALSE
;
871 GetAttr(GA_Selected
, wbwi
->wbwiObject
, &selected
);
873 rc
|= DoMethodA(wbwi
->wbwiObject
, (Msg
)&MethodID
);
880 static IPTR
WBWindowMenuPick(Class
*cl
, Object
*obj
, struct wbwm_MenuPick
*wbwmp
)
882 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
883 struct wbWindow
*my
= INST_DATA(cl
, obj
);
884 struct MenuItem
*item
= wbwmp
->wbwmp_MenuItem
;
888 switch (WBMENU_ITEM_ID(item
)) {
889 case WBMENU_ID(WBMENU_WN_OPEN_PARENT
):
890 if (my
->Lock
!= BNULL
) {
891 lock
= ParentDir(my
->Lock
);
892 if (NameFromLock(lock
, my
->PathBuffer
, sizeof(my
->PathBuffer
))) {
893 OpenWorkbenchObject(my
->PathBuffer
, TAG_END
);
898 case WBMENU_ID(WBMENU_WN__SHOW_ICONS
):
899 my
->FilterHook
= wbFilterIcons_Hook
;
902 case WBMENU_ID(WBMENU_WN__SHOW_ALL
):
903 my
->FilterHook
= wbFilterAll_Hook
;
906 case WBMENU_ID(WBMENU_WB_SHELL
):
909 case WBMENU_ID(WBMENU_IC_OPEN
):
910 rc
= WBWindowForSelectedIcons(cl
, obj
, WBIM_Open
);
912 case WBMENU_ID(WBMENU_IC_COPY
):
913 rc
= WBWindowForSelectedIcons(cl
, obj
, WBIM_Copy
);
915 case WBMENU_ID(WBMENU_IC_RENAME
):
916 rc
= WBWindowForSelectedIcons(cl
, obj
, WBIM_Rename
);
918 case WBMENU_ID(WBMENU_IC_INFO
):
919 rc
= WBWindowForSelectedIcons(cl
, obj
, WBIM_Info
);
921 case WBMENU_ID(WBMENU_IC_SNAPSHOT
):
922 rc
= WBWindowForSelectedIcons(cl
, obj
, WBIM_Snapshot
);
924 case WBMENU_ID(WBMENU_IC_UNSNAPSHOT
):
925 rc
= WBWindowForSelectedIcons(cl
, obj
, WBIM_Unsnapshot
);
927 case WBMENU_ID(WBMENU_IC_LEAVE_OUT
):
928 rc
= WBWindowForSelectedIcons(cl
, obj
, WBIM_Leave_Out
);
930 case WBMENU_ID(WBMENU_IC_PUT_AWAY
):
931 rc
= WBWindowForSelectedIcons(cl
, obj
, WBIM_Put_Away
);
933 case WBMENU_ID(WBMENU_IC_DELETE
):
934 rc
= WBWindowForSelectedIcons(cl
, obj
, WBIM_Delete
);
936 case WBMENU_ID(WBMENU_IC_FORMAT
):
937 rc
= WBWindowForSelectedIcons(cl
, obj
, WBIM_Format
);
939 case WBMENU_ID(WBMENU_IC_EMPTY_TRASH
):
940 rc
= WBWindowForSelectedIcons(cl
, obj
, WBIM_Empty_Trash
);
951 static IPTR
WBWindowIntuiTick(Class
*cl
, Object
*obj
, Msg msg
)
953 struct WorkbookBase
*wb
= (APTR
)cl
->cl_UserData
;
954 struct wbWindow
*my
= INST_DATA(cl
, obj
);
961 val
[1] = WB_REVISION
;
962 val
[2] = AvailMem(MEMF_CHIP
) / 1024;
963 val
[3] = AvailMem(MEMF_FAST
) / 1024;
964 val
[4] = AvailMem(MEMF_ANY
) / 1024;
966 /* Update the window's title */
967 RawDoFmt("Workbook %ld.%ld Chip: %ldk, Fast: %ldk, Any: %ldk", (RAWARG
)val
,
968 RAWFMTFUNC_STRING
, my
->ScreenTitle
);
970 SetWindowTitles(my
->Window
, (CONST_STRPTR
)-1, my
->ScreenTitle
);
974 /* Approx 10 IntuiTicks per second */
975 my
->Tick
= (my
->Tick
+ 1) % 10;
980 static IPTR
dispatcher(Class
*cl
, Object
*obj
, Msg msg
)
984 switch (msg
->MethodID
) {
985 case OM_NEW
: rc
= WBWindowNew(cl
, obj
, (APTR
)msg
); break;
986 case OM_DISPOSE
: rc
= WBWindowDispose(cl
, obj
, (APTR
)msg
); break;
987 case OM_GET
: rc
= WBWindowGet(cl
, obj
, (APTR
)msg
); break;
988 case OM_UPDATE
: rc
= WBWindowUpdate(cl
, obj
, (APTR
)msg
); break;
989 case WBWM_NEWSIZE
: rc
= WBWindowNewSize(cl
, obj
, (APTR
)msg
); break;
990 case WBWM_MENUPICK
: rc
= WBWindowMenuPick(cl
, obj
, (APTR
)msg
); break;
991 case WBWM_INTUITICK
: rc
= WBWindowIntuiTick(cl
, obj
, (APTR
)msg
); break;
992 case WBWM_REFRESH
: rc
= WBWindowRefresh(cl
, obj
, (APTR
)msg
); break;
993 default: rc
= DoSuperMethodA(cl
, obj
, msg
); break;
999 Class
*WBWindow_MakeClass(struct WorkbookBase
*wb
)
1003 cl
= MakeClass( NULL
, "rootclass", NULL
,
1004 sizeof(struct wbWindow
),
1007 cl
->cl_Dispatcher
.h_Entry
= HookEntry
;
1008 cl
->cl_Dispatcher
.h_SubEntry
= dispatcher
;
1009 cl
->cl_Dispatcher
.h_Data
= NULL
;
1010 cl
->cl_UserData
= (IPTR
)wb
;