2 Copyright 2004-2010, The AROS Development Team. All rights reserved.
6 #include "portable_macros.h"
8 #define MUIMASTER_YES_INLINE_STDARG
11 #define ICONWINDOW_OPTION_NOSEARCHBUTTON
15 #include <aros/debug.h>
18 #include <exec/types.h>
19 #include <libraries/mui.h>
22 #include <zune/customclasses.h>
24 #include <zune_AROS/customclasses.h>
27 #include <proto/utility.h>
29 #include <proto/graphics.h>
31 #include <proto/exec.h>
32 #include <proto/datatypes.h>
35 #include <proto/dos.h>
37 #include <proto/icon.h>
42 #include <intuition/screens.h>
43 #include <datatypes/pictureclass.h>
44 #include <clib/macros.h>
47 #include <clib/alib_protos.h>
49 #include <prefs/wanderer.h>
51 #include <prefs_AROS/wanderer.h>
54 #if defined(__AMIGA__) && !defined(__PPC__)
55 #define NO_INLINE_STDARG
57 #ifndef _PROTO_INTUITION_H
58 #include <proto/intuition.h>
60 #include <proto/muimaster.h>
62 #include "Classes/iconlist.h"
63 #include "Classes/iconlistview.h"
64 #include "Classes/iconlist_attributes.h"
66 #include "wandererprefs.h"
68 #include "iconwindow.h"
69 #include "iconwindow_attributes.h"
71 extern struct List iconwindow_Extensions
;
73 /*** Private Data *********************************************************/
75 static CONST_STRPTR extension_Name
= "IconWindow ToolBar Extension";
76 static CONST_STRPTR extension_PrefsFile
= "ENV:SYS/Wanderer/toolbar.prefs";
77 static CONST_STRPTR strTrue
= "True";
78 static STRPTR extension_PrefsData
;
79 static struct iconWindow_Extension panelToolBar__Extension
;
80 struct List panelToolBar__ToolBars
;
81 struct NotifyRequest panelToolBar__PrefsNotifyRequest
;
82 Object
*panelToolBar__PrefsNotificationObject
;
84 struct panel_ToolBar_DATA
88 Object
*iwp_ToolBar_ToolBarObj
;
89 Object
*iwp_ToolBar_LocationStringObj
;
91 struct Hook iwp_ToolBar_LocationStrHook
;
93 struct Hook
*iwp_ToolBar_LocationStrHook
;
98 /* Expand a passed in env: string to its full location */
99 /* Wanderer doesnt free this mem at the moment but should
100 incase it is every closed */
101 STRPTR
ExpandEnvName(CONST_STRPTR env_path
)
104 char tmp_envbuff
[1024];
105 STRPTR fullpath
= NULL
;
106 BPTR env_lock
= (BPTR
) NULL
;
108 env_lock
= Lock("ENV:", SHARED_LOCK
);
111 if (NameFromLock(env_lock
, tmp_envbuff
, 256)) ok
= TRUE
;
117 if ((fullpath
= AllocVec(strlen(tmp_envbuff
) + strlen(env_path
) + 1 + 1 - 4, MEMF_CLEAR
| MEMF_PUBLIC
)) != NULL
)
119 strcpy(fullpath
, tmp_envbuff
);
120 AddPart(fullpath
, env_path
+ 4, 1019);
125 // We couldn't expand it so just use as is, but the
126 // caller is expecting a newly allocated string...
127 fullpath
= AllocVec(strlen(env_path
) + 1, MEMF_PUBLIC
);
128 CopyMem(env_path
, fullpath
, strlen(env_path
) + 1);
134 /*** Hook functions *********************************************************/
136 ///panelToolBar__HookFunc_LocationStringFunc()
139 void, panelToolBar__HookFunc_LocationStringFunc
,
140 AROS_UFHA(struct Hook
*, hook
, A0
),
141 AROS_UFHA(APTR
*, obj
, A2
),
142 AROS_UFHA(APTR
, param
, A1
)
146 HOOKPROTO(panelToolBar__HookFunc_LocationStringFunc
, void, APTR
*obj
, APTR param
)
152 Object
*self
= ( Object
*)obj
;
153 Class
*CLASS
= *( Class
**)param
;
155 BPTR fp
= (BPTR
) NULL
;
156 struct FileInfoBlock
*fib
;
157 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
159 SETUP_ICONWINDOW_INST_DATA
;
161 /* Only change dir if it is a valid directory/volume */
162 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
164 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
167 GET(panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIA_String_Contents
, &str
);
169 /* TODO: Signal that it is a wrong path */
170 /* so that the user understands (here where we abort with return) */
172 fib
= AllocDosObject(DOS_FIB
, NULL
);
176 if (!(fp
= Lock(str
, ACCESS_READ
)))
178 FreeDosObject(DOS_FIB
, fib
);
182 if (!(Examine(fp
, fib
)))
185 FreeDosObject(DOS_FIB
, fib
);
189 /* Change directory! */
190 if (fib
->fib_DirEntryType
>= 0)
192 SET(self
, MUIA_IconWindow_Location
, (IPTR
)str
);
197 FreeDosObject(DOS_FIB
, fib
);
203 MakeStaticHook(ToolBar_locationstrHook
, panelToolBar__HookFunc_LocationStringFunc
);
206 #define TOOLBAR_PREFSSIZE 1024
207 IPTR
panelToolBar__HandleFSUpdate(Object
*WandererObj
, struct NotifyMessage
*msg
)
209 if (GetVar(extension_PrefsFile
, extension_PrefsData
, TOOLBAR_PREFSSIZE
, GVF_GLOBAL_ONLY
) != -1)
211 D(bug("[IW.toolbar] %s: Prefs contain '%s'\n", __PRETTY_FUNCTION__
, extension_PrefsData
));
212 if ((strcasecmp(extension_PrefsData
, strTrue
)) == 0)
214 SET(panelToolBar__PrefsNotificationObject
, MUIA_ShowMe
, TRUE
);
218 SET(panelToolBar__PrefsNotificationObject
, MUIA_ShowMe
, FALSE
);
224 /*** Main Functions ****************************************************************/
226 ///panelToolBar__PrefsSetup()
227 IPTR
panelToolBar__PrefsSetup(Class
*CLASS
, Object
*self
, struct opSet
*message
)
229 IPTR panelToolBarFSNotifyPort
= 0;
230 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
231 struct List
*panelToolBarFSNotifyList
= NULL
;
233 SETUP_ICONWINDOW_INST_DATA
;
235 panelToolBarFSNotifyPort
= GetTagData(MUIA_Wanderer_FileSysNotifyPort
, (IPTR
) NULL
, message
->ops_AttrList
);
236 panelToolBarFSNotifyList
= (APTR
)GetTagData(MUIA_Wanderer_FileSysNotifyList
, (IPTR
) NULL
, message
->ops_AttrList
);
238 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
240 extension_PrefsData
= (STRPTR
)strTrue
;
242 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
244 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
247 extension_PrefsData
= (STRPTR
)AllocVec(TOOLBAR_PREFSSIZE
, MEMF_CLEAR
);
248 if (extension_PrefsData
== NULL
)
250 extension_PrefsData
= (STRPTR
)strTrue
;
254 /* Setup notification on prefs file --------------------------------*/
255 struct Wanderer_FSHandler
*_prefsNotifyHandler
= NULL
;
257 if ((_prefsNotifyHandler
= AllocMem(sizeof(struct Wanderer_FSHandler
), MEMF_CLEAR
)) != NULL
)
259 _prefsNotifyHandler
->fshn_Node
.ln_Name
= ExpandEnvName(extension_PrefsFile
);
260 panelToolBar__PrefsNotifyRequest
.nr_Name
= _prefsNotifyHandler
->fshn_Node
.ln_Name
;
261 panelToolBar__PrefsNotifyRequest
.nr_Flags
= NRF_SEND_MESSAGE
;
262 panelToolBar__PrefsNotifyRequest
.nr_stuff
.nr_Msg
.nr_Port
= (struct MsgPort
*)panelToolBarFSNotifyPort
;
263 _prefsNotifyHandler
->HandleFSUpdate
= panelToolBar__HandleFSUpdate
;
265 if (StartNotify(&panelToolBar__PrefsNotifyRequest
))
267 D(bug("[IW.toolbar]%s: Prefs-notification setup on '%s'\n", __PRETTY_FUNCTION__
, panelToolBar__PrefsNotifyRequest
.nr_Name
));
271 D(bug("[IW.toolbar] %s: FAILED to setup Prefs-notification!\n", __PRETTY_FUNCTION__
));
273 AddTail(panelToolBarFSNotifyList
, &_prefsNotifyHandler
->fshn_Node
);
276 panelToolBar__PrefsNotificationObject
= (Object
*)NotifyObject
, End
;
278 panelToolBar__PrefsNotificationObject
= MUI_NewObject(MUIC_Notify
, TAG_DONE
);
280 if (GetVar(extension_PrefsFile
, extension_PrefsData
, TOOLBAR_PREFSSIZE
, GVF_GLOBAL_ONLY
) != -1)
282 D(bug("[IW.toolbar] %s: Prefs contain '%s'\n", __PRETTY_FUNCTION__
, extension_PrefsData
));
289 ///panelToolBar__Setup()
290 IPTR
panelToolBar__Setup(Class
*CLASS
, Object
*self
, struct opSet
*message
)
292 SETUP_ICONWINDOW_INST_DATA
;
294 Object
*panel_ToolBar
;
295 Object
*panelToolBar_ButtonDirUp
= NULL
,
296 *panelToolBar_ButtonSearch
= NULL
,
297 *panelToolBar_StringLocation
= NULL
;
299 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
301 if (!(!(data
->iwd_Flags
& IWDFLAG_ISROOT
) && data
->iwd_TopPanel
.iwp_PanelContainerObj
))
304 #if !defined(ICONWINDOW_OPTION_NOSEARCHBUTTON)
305 panelToolBar_ButtonSearch
= ImageButton("", "THEME:Images/Gadgets/Search");
308 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
310 if (data
->iwd_TopPanel
.iwp_PanelPrivate
== (IPTR
)NULL
)
312 if ((data
->iwd_TopPanel
.iwp_PanelPrivate
= (IPTR
)AllocVec(sizeof(struct panel_ToolBar_DATA
), MEMF_CLEAR
)) == (IPTR
)NULL
)
315 panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
;
316 panelToolBarPrivate
->iwp_Node
.ln_Name
= (char *)extension_Name
;
318 /* Create the "ToolBar" panel object .. */
319 panel_ToolBar
= MUI_NewObject(MUIC_Group
,
323 MUIA_InnerBottom
,(0),
324 MUIA_Frame
, MUIV_Frame_None
,
325 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
329 MUIA_InnerBottom
,(4),
330 MUIA_Frame
, MUIV_Frame_None
,
332 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
336 MUIA_InnerBottom
,(0),
338 Child
, (IPTR
)( panelToolBar_StringLocation
= MUI_NewObject(MUIC_String
,
339 MUIA_String_Contents
, (IPTR
)"",
341 MUIA_Frame
, MUIV_Frame_String
,
344 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
348 MUIA_InnerBottom
,(0),
350 MUIA_VertWeight
, 100,
351 Child
, (IPTR
) (panelToolBar_ButtonDirUp
= ImageButton("", "THEME:Images/Gadgets/DirUp")),
352 (panelToolBar_ButtonSearch
? Child
: TAG_IGNORE
), (IPTR
) (panelToolBar_ButtonSearch
),
355 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
359 MUIA_InnerBottom
,(0),
360 MUIA_Group_Spacing
, 0,
362 MUIA_Frame
, MUIV_Frame_None
,
363 MUIA_Background
, MUII_SHADOW
,
364 Child
, (IPTR
)MUI_NewObject(MUIC_Rectangle
,
365 MUIA_Frame
, MUIV_Frame_None
,
370 /* Got a toolbarpanel? setup notifies and other values are
371 copied to the data of the object */
372 if ( panel_ToolBar
!= NULL
)
374 D(bug("[IW.toolbar] %s: ToolBar Obj @ 0x%p\n", __PRETTY_FUNCTION__
, panel_ToolBar
));
376 SET(panelToolBar_ButtonDirUp
, MUIA_Background
, XGET( panel_ToolBar
, MUIA_Background
) );
377 SET(panelToolBar_ButtonDirUp
, MUIA_CycleChain
, 1);
378 SET(panelToolBar_ButtonDirUp
, MUIA_Frame
, MUIV_Frame_None
);
379 #if !defined(ICONWINDOW_OPTION_NOSEARCHBUTTON)
380 SET(panelToolBar_ButtonSearch
, MUIA_Background
, XGET( panel_ToolBar
, MUIA_Background
) );
381 SET(panelToolBar_ButtonSearch
, MUIA_CycleChain
, 1);
382 SET(panelToolBar_ButtonSearch
, MUIA_Frame
, MUIV_Frame_None
);
384 panelToolBarPrivate
->iwp_ToolBar_ToolBarObj
= panel_ToolBar
;
386 if (DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, MUIM_Group_InitChange
))
388 DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, OM_ADDMEMBER
, (IPTR
)panel_ToolBar
);
389 if (data
->iwd_TopPanel
.iwp_PanelGroupSpacerObj
)
391 DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, OM_REMMEMBER
, (IPTR
)data
->iwd_TopPanel
.iwp_PanelGroupSpacerObj
);
392 data
->iwd_TopPanel
.iwp_PanelGroupSpacerObj
= NULL
;
395 DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, MUIM_Group_ExitChange
);
398 if (panelToolBarPrivate
->iwp_ToolBar_ToolBarObj
)
401 panelToolBar_ButtonDirUp
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
402 (IPTR
)self
, 1, MUIM_IconWindow_DirectoryUp
405 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
= panelToolBar_StringLocation
;
407 panelToolBarPrivate
->iwp_ToolBar_LocationStrHook
.h_Entry
= ( HOOKFUNC
)panelToolBar__HookFunc_LocationStringFunc
;
409 panelToolBarPrivate
->iwp_ToolBar_LocationStrHook
= &ToolBar_locationstrHook
;
413 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIA_String_Contents
,
414 XGET(data
->iwd_IconListObj
, MUIA_IconDrawerList_Drawer
)
417 /* Make changes to string contents change dir on enter */
419 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
420 (IPTR
)self
, 3, MUIM_CallHook
, &panelToolBarPrivate
->iwp_ToolBar_LocationStrHook
, (IPTR
)CLASS
423 if (!(panelToolBar__PrefsNotificationObject
))
424 panelToolBar__PrefsSetup(CLASS
, self
, message
);
428 panelToolBar__PrefsNotificationObject
, MUIM_Notify
, MUIA_ShowMe
, MUIV_EveryTime
,
429 (IPTR
)data
->iwd_TopPanel
.iwp_PanelContainerObj
, 3, MUIM_Set
, MUIA_ShowMe
, MUIV_TriggerValue
432 if ((strcasecmp(extension_PrefsData
, strTrue
)) == 0)
434 SET(data
->iwd_TopPanel
.iwp_PanelContainerObj
, MUIA_ShowMe
, TRUE
);
437 AddTail(&panelToolBar__ToolBars
, &panelToolBarPrivate
->iwp_Node
);
442 panelToolBarPrivate
->iwp_ToolBar_ToolBarObj
= NULL
;
449 IPTR
panelToolBar__Cleanup(Class
*CLASS
, Object
*self
, Msg msg
)
451 SETUP_ICONWINDOW_INST_DATA
;
453 struct panel_ToolBar_DATA
*panelToolBarPrivate
;
455 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
458 // we cant free this here since it will be used again!
459 if (extension_PrefsData
&& (extension_PrefsData
!= strTrue
))
460 FreeVec(extension_PrefsData
);
463 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
465 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
468 if (panelToolBar__PrefsNotificationObject
)
472 panelToolBar__PrefsNotificationObject
, MUIM_KillNotifyObj
, MUIA_ShowMe
,
473 (IPTR
)data
->iwd_TopPanel
.iwp_PanelContainerObj
476 if (panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
)
480 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIM_KillNotifyObj
, MUIA_String_Acknowledge
,
489 IPTR
panelToolBar__OM_GET(Class
*CLASS
, Object
*self
, struct opGet
*message
)
491 SETUP_ICONWINDOW_INST_DATA
;
493 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
494 // IPTR *store = message->opg_Storage;
497 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
499 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
501 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
504 switch (message
->opg_AttrID
)
513 IPTR
panelToolBar__OM_SET(Class
*CLASS
, Object
*self
, struct opSet
*message
)
515 SETUP_ICONWINDOW_INST_DATA
;
517 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
518 struct TagItem
*tstate
= message
->ops_AttrList
, *tag
;
519 // BOOL UpdateIconlist = FALSE;
520 // IPTR focusicon = (IPTR) NULL;
523 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
525 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
527 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
530 while ((tag
= NextTagItem((TAGITEM
)&tstate
)) != NULL
)
534 case MUIA_IconWindow_Location
:
535 D(bug("[IW.toolbar] %s: MUIA_IconWindow_Location '%s'\n", __PRETTY_FUNCTION__
, data
->iwd_DirectoryPath
));
537 SET(panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIA_String_Contents
, (IPTR
)data
->iwd_DirectoryPath
);
547 #define PANELTOOLBAR_PRIORITY 10
549 IPTR
panelToolBar__Init()
551 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
553 panelToolBar__Extension
.iwe_Node
.ln_Pri
= PANELTOOLBAR_PRIORITY
;
554 panelToolBar__Extension
.iwe_Node
.ln_Name
= (char *)extension_Name
;
555 panelToolBar__Extension
.iwe_Setup
= panelToolBar__Setup
;
556 panelToolBar__Extension
.iwe_Cleanup
= panelToolBar__Cleanup
;
557 panelToolBar__Extension
.iwe_Set
= panelToolBar__OM_SET
;
558 panelToolBar__Extension
.iwe_Get
= panelToolBar__OM_GET
;
560 NewList(&panelToolBar__ToolBars
);
562 Enqueue(&iconwindow_Extensions
, (struct Node
*)&panelToolBar__Extension
);
564 D(bug("[IconWindow] %s: Added Extension '%s' @ %p to list @ %p\n", __PRETTY_FUNCTION__
, panelToolBar__Extension
.iwe_Node
.ln_Name
, &panelToolBar__Extension
.iwe_Node
, &iconwindow_Extensions
));
569 ADD2INIT(panelToolBar__Init
, PANELTOOLBAR_PRIORITY
);