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 STRPTR extension_PrefsData
;
78 static struct iconWindow_Extension panelToolBar__Extension
;
79 struct List panelToolBar__ToolBars
;
80 struct NotifyRequest panelToolBar__PrefsNotifyRequest
;
81 Object
*panelToolBar__PrefsNotificationObject
;
83 struct panel_ToolBar_DATA
87 Object
*iwp_ToolBar_ToolBarObj
;
88 Object
*iwp_ToolBar_LocationStringObj
;
90 struct Hook iwp_ToolBar_LocationStrHook
;
92 struct Hook
*iwp_ToolBar_LocationStrHook
;
97 /* Expand a passed in env: string to its full location */
98 /* Wanderer doesnt free this mem at the moment but should
99 incase it is every closed */
100 STRPTR
ExpandEnvName(CONST_STRPTR env_path
)
103 char tmp_envbuff
[1024];
104 STRPTR fullpath
= NULL
;
105 BPTR env_lock
= (BPTR
) NULL
;
107 env_lock
= Lock("ENV:", SHARED_LOCK
);
110 if (NameFromLock(env_lock
, tmp_envbuff
, 256)) ok
= TRUE
;
116 if ((fullpath
= AllocVec(strlen(tmp_envbuff
) + strlen(env_path
) + 1 + 1 - 4, MEMF_CLEAR
| MEMF_PUBLIC
)) != NULL
)
118 strcpy(fullpath
, tmp_envbuff
);
119 AddPart(fullpath
, env_path
+ 4, 1019);
124 // We couldn't expand it so just use as is, but the
125 // caller is expecting a newly allocated string...
126 fullpath
= AllocVec(strlen(env_path
) + 1, MEMF_PUBLIC
);
127 CopyMem(env_path
, fullpath
, strlen(env_path
) + 1);
133 /*** Hook functions *********************************************************/
135 ///panelToolBar__HookFunc_LocationStringFunc()
138 void, panelToolBar__HookFunc_LocationStringFunc
,
139 AROS_UFHA(struct Hook
*, hook
, A0
),
140 AROS_UFHA(APTR
*, obj
, A2
),
141 AROS_UFHA(APTR
, param
, A1
)
145 HOOKPROTO(panelToolBar__HookFunc_LocationStringFunc
, void, APTR
*obj
, APTR param
)
151 Object
*self
= ( Object
*)obj
;
152 Class
*CLASS
= *( Class
**)param
;
154 BPTR fp
= (BPTR
) NULL
;
155 struct FileInfoBlock
*fib
;
156 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
158 SETUP_ICONWINDOW_INST_DATA
;
160 /* Only change dir if it is a valid directory/volume */
161 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
163 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
166 GET(panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIA_String_Contents
, &str
);
168 /* TODO: Signal that it is a wrong path */
169 /* so that the user understands (here where we abort with return) */
171 fib
= AllocDosObject(DOS_FIB
, NULL
);
175 if (!(fp
= Lock(str
, ACCESS_READ
)))
177 FreeDosObject(DOS_FIB
, fib
);
181 if (!(Examine(fp
, fib
)))
184 FreeDosObject(DOS_FIB
, fib
);
188 /* Change directory! */
189 if (fib
->fib_DirEntryType
>= 0)
191 SET(self
, MUIA_IconWindow_Location
, (IPTR
)str
);
196 FreeDosObject(DOS_FIB
, fib
);
202 MakeStaticHook(ToolBar_locationstrHook
, panelToolBar__HookFunc_LocationStringFunc
);
205 #define TOOLBAR_PREFSSIZE 1024
206 IPTR
panelToolBar__HandleFSUpdate(Object
*WandererObj
, struct NotifyMessage
*msg
)
208 if (GetVar(extension_PrefsFile
, extension_PrefsData
, TOOLBAR_PREFSSIZE
, GVF_GLOBAL_ONLY
) != -1)
210 D(bug("[IW.toolbar] %s: Prefs contain '%s'\n", __PRETTY_FUNCTION__
, extension_PrefsData
));
211 if ((strcasecmp(extension_PrefsData
, "True")) == 0)
213 SET(panelToolBar__PrefsNotificationObject
, MUIA_ShowMe
, TRUE
);
217 SET(panelToolBar__PrefsNotificationObject
, MUIA_ShowMe
, FALSE
);
223 /*** Main Functions ****************************************************************/
225 ///panelToolBar__PrefsSetup()
226 IPTR
panelToolBar__PrefsSetup(Class
*CLASS
, Object
*self
, struct opSet
*message
)
228 IPTR panelToolBarFSNotifyPort
= 0;
229 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
230 struct List
*panelToolBarFSNotifyList
= NULL
;
232 SETUP_ICONWINDOW_INST_DATA
;
234 panelToolBarFSNotifyPort
= GetTagData(MUIA_Wanderer_FileSysNotifyPort
, (IPTR
) NULL
, message
->ops_AttrList
);
235 panelToolBarFSNotifyList
= (APTR
)GetTagData(MUIA_Wanderer_FileSysNotifyList
, (IPTR
) NULL
, message
->ops_AttrList
);
237 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
239 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
241 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
244 // FIXME: this is never freed
245 extension_PrefsData
= AllocVec(TOOLBAR_PREFSSIZE
, MEMF_CLEAR
);
246 if (extension_PrefsData
== NULL
)
249 /* Setup notification on prefs file --------------------------------*/
250 struct Wanderer_FSHandler
*_prefsNotifyHandler
= NULL
;
252 if ((_prefsNotifyHandler
= AllocMem(sizeof(struct Wanderer_FSHandler
), MEMF_CLEAR
)) != NULL
)
254 _prefsNotifyHandler
->fshn_Node
.ln_Name
= ExpandEnvName(extension_PrefsFile
);
255 panelToolBar__PrefsNotifyRequest
.nr_Name
= _prefsNotifyHandler
->fshn_Node
.ln_Name
;
256 panelToolBar__PrefsNotifyRequest
.nr_Flags
= NRF_SEND_MESSAGE
;
257 panelToolBar__PrefsNotifyRequest
.nr_stuff
.nr_Msg
.nr_Port
= (struct MsgPort
*)panelToolBarFSNotifyPort
;
258 _prefsNotifyHandler
->HandleFSUpdate
= panelToolBar__HandleFSUpdate
;
260 if (StartNotify(&panelToolBar__PrefsNotifyRequest
))
262 D(bug("[IW.toolbar]%s: Prefs-notification setup on '%s'\n", __PRETTY_FUNCTION__
, panelToolBar__PrefsNotifyRequest
.nr_Name
));
266 D(bug("[IW.toolbar] %s: FAILED to setup Prefs-notification!\n", __PRETTY_FUNCTION__
));
268 AddTail(panelToolBarFSNotifyList
, &_prefsNotifyHandler
->fshn_Node
);
271 panelToolBar__PrefsNotificationObject
= (Object
*)NotifyObject
, End
;
273 panelToolBar__PrefsNotificationObject
= MUI_NewObject(MUIC_Notify
, TAG_DONE
);
275 if (GetVar(extension_PrefsFile
, extension_PrefsData
, TOOLBAR_PREFSSIZE
, GVF_GLOBAL_ONLY
) != -1)
277 D(bug("[IW.toolbar] %s: Prefs contain '%s'\n", __PRETTY_FUNCTION__
, extension_PrefsData
));
284 ///panelToolBar__Setup()
285 IPTR
panelToolBar__Setup(Class
*CLASS
, Object
*self
, struct opSet
*message
)
287 SETUP_ICONWINDOW_INST_DATA
;
289 Object
*panel_ToolBar
;
290 Object
*panelToolBar_ButtonDirUp
= NULL
,
291 *panelToolBar_ButtonSearch
= NULL
,
292 *panelToolBar_StringLocation
= NULL
;
294 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
296 if (!(!(data
->iwd_Flags
& IWDFLAG_ISROOT
) && data
->iwd_TopPanel
.iwp_PanelContainerObj
))
299 #if !defined(ICONWINDOW_OPTION_NOSEARCHBUTTON)
300 panelToolBar_ButtonSearch
= ImageButton("", "THEME:Images/Gadgets/Search");
303 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
305 if (data
->iwd_TopPanel
.iwp_PanelPrivate
== (IPTR
)NULL
)
307 if ((data
->iwd_TopPanel
.iwp_PanelPrivate
= (IPTR
)AllocVec(sizeof(struct panel_ToolBar_DATA
), MEMF_CLEAR
)) == (IPTR
)NULL
)
310 panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
;
311 panelToolBarPrivate
->iwp_Node
.ln_Name
= (char *)extension_Name
;
313 /* Create the "ToolBar" panel object .. */
314 panel_ToolBar
= MUI_NewObject(MUIC_Group
,
318 MUIA_InnerBottom
,(0),
319 MUIA_Frame
, MUIV_Frame_None
,
320 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
324 MUIA_InnerBottom
,(4),
325 MUIA_Frame
, MUIV_Frame_None
,
327 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
331 MUIA_InnerBottom
,(0),
333 Child
, (IPTR
)( panelToolBar_StringLocation
= MUI_NewObject(MUIC_String
,
334 MUIA_String_Contents
, (IPTR
)"",
336 MUIA_Frame
, MUIV_Frame_String
,
339 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
343 MUIA_InnerBottom
,(0),
345 MUIA_VertWeight
, 100,
346 Child
, (IPTR
) (panelToolBar_ButtonDirUp
= ImageButton("", "THEME:Images/Gadgets/DirUp")),
347 (panelToolBar_ButtonSearch
? Child
: TAG_IGNORE
), (IPTR
) (panelToolBar_ButtonSearch
),
350 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
354 MUIA_InnerBottom
,(0),
355 MUIA_Group_Spacing
, 0,
357 MUIA_Frame
, MUIV_Frame_None
,
358 MUIA_Background
, MUII_SHADOW
,
359 Child
, (IPTR
)MUI_NewObject(MUIC_Rectangle
,
360 MUIA_Frame
, MUIV_Frame_None
,
365 /* Got a toolbarpanel? setup notifies and other values are
366 copied to the data of the object */
367 if ( panel_ToolBar
!= NULL
)
369 D(bug("[IW.toolbar] %s: ToolBar Obj @ 0x%p\n", __PRETTY_FUNCTION__
, panel_ToolBar
));
371 SET(panelToolBar_ButtonDirUp
, MUIA_Background
, XGET( panel_ToolBar
, MUIA_Background
) );
372 SET(panelToolBar_ButtonDirUp
, MUIA_CycleChain
, 1);
373 SET(panelToolBar_ButtonDirUp
, MUIA_Frame
, MUIV_Frame_None
);
374 #if !defined(ICONWINDOW_OPTION_NOSEARCHBUTTON)
375 SET(panelToolBar_ButtonSearch
, MUIA_Background
, XGET( panel_ToolBar
, MUIA_Background
) );
376 SET(panelToolBar_ButtonSearch
, MUIA_CycleChain
, 1);
377 SET(panelToolBar_ButtonSearch
, MUIA_Frame
, MUIV_Frame_None
);
379 panelToolBarPrivate
->iwp_ToolBar_ToolBarObj
= panel_ToolBar
;
381 if (DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, MUIM_Group_InitChange
))
383 DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, OM_ADDMEMBER
, (IPTR
)panel_ToolBar
);
384 if (data
->iwd_TopPanel
.iwp_PanelGroupSpacerObj
)
386 DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, OM_REMMEMBER
, (IPTR
)data
->iwd_TopPanel
.iwp_PanelGroupSpacerObj
);
387 data
->iwd_TopPanel
.iwp_PanelGroupSpacerObj
= NULL
;
390 DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, MUIM_Group_ExitChange
);
393 if (panelToolBarPrivate
->iwp_ToolBar_ToolBarObj
)
396 panelToolBar_ButtonDirUp
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
397 (IPTR
)self
, 1, MUIM_IconWindow_DirectoryUp
400 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
= panelToolBar_StringLocation
;
402 panelToolBarPrivate
->iwp_ToolBar_LocationStrHook
.h_Entry
= ( HOOKFUNC
)panelToolBar__HookFunc_LocationStringFunc
;
404 panelToolBarPrivate
->iwp_ToolBar_LocationStrHook
= &ToolBar_locationstrHook
;
408 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIA_String_Contents
,
409 XGET(data
->iwd_IconListObj
, MUIA_IconDrawerList_Drawer
)
412 /* Make changes to string contents change dir on enter */
414 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
415 (IPTR
)self
, 3, MUIM_CallHook
, &panelToolBarPrivate
->iwp_ToolBar_LocationStrHook
, (IPTR
)CLASS
418 if (!(panelToolBar__PrefsNotificationObject
))
419 panelToolBar__PrefsSetup(CLASS
, self
, message
);
423 panelToolBar__PrefsNotificationObject
, MUIM_Notify
, MUIA_ShowMe
, MUIV_EveryTime
,
424 (IPTR
)data
->iwd_TopPanel
.iwp_PanelContainerObj
, 3, MUIM_Set
, MUIA_ShowMe
, MUIV_TriggerValue
427 if ((strcasecmp(extension_PrefsData
, "True")) == 0)
429 SET(data
->iwd_TopPanel
.iwp_PanelContainerObj
, MUIA_ShowMe
, TRUE
);
432 AddTail(&panelToolBar__ToolBars
, &panelToolBarPrivate
->iwp_Node
);
437 panelToolBarPrivate
->iwp_ToolBar_ToolBarObj
= NULL
;
444 IPTR
panelToolBar__Cleanup(Class
*CLASS
, Object
*self
, Msg msg
)
446 SETUP_ICONWINDOW_INST_DATA
;
448 struct panel_ToolBar_DATA
*panelToolBarPrivate
;
450 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
452 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
454 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
457 if (panelToolBar__PrefsNotificationObject
)
461 panelToolBar__PrefsNotificationObject
, MUIM_KillNotifyObj
, MUIA_ShowMe
,
462 (IPTR
)data
->iwd_TopPanel
.iwp_PanelContainerObj
465 if (panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
)
469 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIM_KillNotifyObj
, MUIA_String_Acknowledge
,
478 IPTR
panelToolBar__OM_GET(Class
*CLASS
, Object
*self
, struct opGet
*message
)
480 SETUP_ICONWINDOW_INST_DATA
;
482 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
483 // IPTR *store = message->opg_Storage;
486 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
488 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
490 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
493 switch (message
->opg_AttrID
)
502 IPTR
panelToolBar__OM_SET(Class
*CLASS
, Object
*self
, struct opSet
*message
)
504 SETUP_ICONWINDOW_INST_DATA
;
506 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
507 struct TagItem
*tstate
= message
->ops_AttrList
, *tag
;
508 // BOOL UpdateIconlist = FALSE;
509 // IPTR focusicon = (IPTR) NULL;
512 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
514 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
516 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= (char *)extension_Name
)
519 while ((tag
= NextTagItem((TAGITEM
)&tstate
)) != NULL
)
523 case MUIA_IconWindow_Location
:
524 D(bug("[IW.toolbar] %s: MUIA_IconWindow_Location '%s'\n", __PRETTY_FUNCTION__
, data
->iwd_DirectoryPath
));
526 SET(panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIA_String_Contents
, (IPTR
)data
->iwd_DirectoryPath
);
536 #define PANELTOOLBAR_PRIORITY 10
538 IPTR
panelToolBar__Init()
540 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
542 panelToolBar__Extension
.iwe_Node
.ln_Pri
= PANELTOOLBAR_PRIORITY
;
543 panelToolBar__Extension
.iwe_Node
.ln_Name
= (char *)extension_Name
;
544 panelToolBar__Extension
.iwe_Setup
= panelToolBar__Setup
;
545 panelToolBar__Extension
.iwe_Cleanup
= panelToolBar__Cleanup
;
546 panelToolBar__Extension
.iwe_Set
= panelToolBar__OM_SET
;
547 panelToolBar__Extension
.iwe_Get
= panelToolBar__OM_GET
;
549 NewList(&panelToolBar__ToolBars
);
551 Enqueue(&iconwindow_Extensions
, (struct Node
*)&panelToolBar__Extension
);
553 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
));
558 ADD2INIT(panelToolBar__Init
, PANELTOOLBAR_PRIORITY
);