2 Copyright 2004-2009, 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 static STRPTR
ExpandEnvName(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 couldnt expand it so just use as is ..
129 /*** Hook functions *********************************************************/
131 ///panelToolBar__HookFunc_LocationStringFunc()
134 void, panelToolBar__HookFunc_LocationStringFunc
,
135 AROS_UFHA(struct Hook
*, hook
, A0
),
136 AROS_UFHA(APTR
*, obj
, A2
),
137 AROS_UFHA(APTR
, param
, A1
)
141 HOOKPROTO(panelToolBar__HookFunc_LocationStringFunc
, void, APTR
*obj
, APTR param
)
147 Object
*self
= ( Object
*)obj
;
148 Class
*CLASS
= *( Class
**)param
;
150 BPTR fp
= (BPTR
) NULL
;
151 struct FileInfoBlock
*fib
;
152 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
154 #warning "stegerg: doesn't allocate fib with AllocDOSObject"
156 SETUP_ICONWINDOW_INST_DATA
;
158 /* Only change dir if it is a valid directory/volume */
159 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != NULL
)
161 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= extension_Name
)
164 GET(panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIA_String_Contents
, &str
);
166 #warning "TODO: Signal that it is a wrong path"
167 /* so that the user understands (here where we abort with return) */
169 fib
= AllocDosObject(DOS_FIB
, NULL
);
173 if (!(fp
= Lock(str
, ACCESS_READ
)))
175 FreeDosObject(DOS_FIB
, fib
);
179 if (!(Examine(fp
, fib
)))
182 FreeDosObject(DOS_FIB
, fib
);
186 /* Change directory! */
187 if (fib
->fib_DirEntryType
>= 0)
189 SET(self
, MUIA_IconWindow_Location
, (IPTR
)str
);
194 FreeDosObject(DOS_FIB
, fib
);
200 MakeStaticHook(ToolBar_locationstrHook
, panelToolBar__HookFunc_LocationStringFunc
);
203 #define TOOLBAR_PREFSSIZE 1024
204 IPTR
panelToolBar__HandleFSUpdate()
206 if (GetVar(extension_PrefsFile
, extension_PrefsData
, TOOLBAR_PREFSSIZE
, GVF_GLOBAL_ONLY
) != -1)
208 D(bug("[IW.toolbar] %s: Prefs contain '%s'\n", __PRETTY_FUNCTION__
, extension_PrefsData
));
209 if ((strcasecmp(extension_PrefsData
, "True")) == 0)
211 SET(panelToolBar__PrefsNotificationObject
, MUIA_ShowMe
, TRUE
);
215 SET(panelToolBar__PrefsNotificationObject
, MUIA_ShowMe
, FALSE
);
221 /*** Main Functions ****************************************************************/
223 ///panelToolBar__PrefsSetup()
224 IPTR
panelToolBar__PrefsSetup(Class
*CLASS
, Object
*self
, struct opSet
*message
)
226 IPTR panelToolBarFSNotifyPort
= 0;
227 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
228 struct List
*panelToolBarFSNotifyList
= NULL
;
230 SETUP_ICONWINDOW_INST_DATA
;
232 panelToolBarFSNotifyPort
= GetTagData(MUIA_Wanderer_FileSysNotifyPort
, (IPTR
) NULL
, message
->ops_AttrList
);
233 panelToolBarFSNotifyList
= GetTagData(MUIA_Wanderer_FileSysNotifyList
, (IPTR
) NULL
, message
->ops_AttrList
);
235 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
237 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != (IPTR
)NULL
)
239 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= extension_Name
)
242 extension_PrefsData
= AllocVec(TOOLBAR_PREFSSIZE
, MEMF_CLEAR
);
244 /* Setup notification on prefs file --------------------------------*/
245 struct Wanderer_FSHandler
*_prefsNotifyHandler
= NULL
;
247 if ((_prefsNotifyHandler
= AllocMem(sizeof(struct Wanderer_FSHandler
), MEMF_CLEAR
)) != NULL
)
249 _prefsNotifyHandler
->fshn_Node
.ln_Name
= ExpandEnvName(extension_PrefsFile
);
250 panelToolBar__PrefsNotifyRequest
.nr_Name
= _prefsNotifyHandler
->fshn_Node
.ln_Name
;
251 panelToolBar__PrefsNotifyRequest
.nr_Flags
= NRF_SEND_MESSAGE
;
252 panelToolBar__PrefsNotifyRequest
.nr_stuff
.nr_Msg
.nr_Port
= panelToolBarFSNotifyPort
;
253 _prefsNotifyHandler
->HandleFSUpdate
= panelToolBar__HandleFSUpdate
;
255 if (StartNotify(&panelToolBar__PrefsNotifyRequest
))
257 D(bug("[IW.toolbar]%s: Prefs-notification setup on '%s'\n", __PRETTY_FUNCTION__
, panelToolBar__PrefsNotifyRequest
.nr_Name
));
261 D(bug("[IW.toolbar] %s: FAILED to setup Prefs-notification!\n", __PRETTY_FUNCTION__
));
263 AddTail(panelToolBarFSNotifyList
, &_prefsNotifyHandler
->fshn_Node
);
266 panelToolBar__PrefsNotificationObject
= (Object
*)NotifyObject
, End
;
268 panelToolBar__PrefsNotificationObject
= MUI_NewObject(MUIC_Notify
, TAG_DONE
);
270 if (GetVar(extension_PrefsFile
, extension_PrefsData
, TOOLBAR_PREFSSIZE
, GVF_GLOBAL_ONLY
) != -1)
272 D(bug("[IW.toolbar] %s: Prefs contain '%s'\n", __PRETTY_FUNCTION__
, extension_PrefsData
));
278 ///panelToolBar__Setup()
279 IPTR
panelToolBar__Setup(Class
*CLASS
, Object
*self
, struct opSet
*message
)
281 SETUP_ICONWINDOW_INST_DATA
;
283 Object
*panel_ToolBar
;
284 Object
*panelToolBar_ButtonDirUp
= NULL
,
285 *panelToolBar_ButtonSearch
= NULL
,
286 *panelToolBar_StringLocation
= NULL
;
288 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
290 if (!(!(data
->iwd_Flags
& IWDFLAG_ISROOT
) && data
->iwd_TopPanel
.iwp_PanelContainerObj
))
293 #if !defined(ICONWINDOW_OPTION_NOSEARCHBUTTON)
294 panelToolBar_ButtonSearch
= ImageButton("", "THEME:Images/Gadgets/Prefs/Test");
297 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
299 if (data
->iwd_TopPanel
.iwp_PanelPrivate
== (IPTR
)NULL
)
301 if ((data
->iwd_TopPanel
.iwp_PanelPrivate
= (IPTR
)AllocVec(sizeof(struct panel_ToolBar_DATA
), MEMF_CLEAR
)) == (IPTR
)NULL
)
304 panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
;
305 panelToolBarPrivate
->iwp_Node
.ln_Name
= extension_Name
;
307 /* Create the "ToolBar" panel object .. */
308 panel_ToolBar
= MUI_NewObject(MUIC_Group
,
312 MUIA_InnerBottom
,(0),
313 MUIA_Frame
, MUIV_Frame_None
,
314 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
318 MUIA_InnerBottom
,(4),
319 MUIA_Frame
, MUIV_Frame_None
,
321 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
325 MUIA_InnerBottom
,(0),
327 Child
, (IPTR
)( panelToolBar_StringLocation
= MUI_NewObject(MUIC_String
,
328 MUIA_String_Contents
, (IPTR
)"",
330 MUIA_Frame
, MUIV_Frame_String
,
333 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
337 MUIA_InnerBottom
,(0),
339 MUIA_VertWeight
, 100,
340 Child
, (IPTR
) (panelToolBar_ButtonDirUp
= ImageButton("", "THEME:Images/Gadgets/Prefs/Revert")),
341 (panelToolBar_ButtonSearch
? Child
: TAG_IGNORE
), (IPTR
) (panelToolBar_ButtonSearch
),
344 Child
, (IPTR
)MUI_NewObject(MUIC_Group
, MUIA_Group_Horiz
, TRUE
,
348 MUIA_InnerBottom
,(0),
349 MUIA_Group_Spacing
, 0,
351 MUIA_Frame
, MUIV_Frame_None
,
352 MUIA_Background
, MUII_SHADOW
,
353 Child
, (IPTR
)MUI_NewObject(MUIC_Rectangle
,
354 MUIA_Frame
, MUIV_Frame_None
,
359 /* Got a toolbarpanel? setup notifies and other values are
360 copied to the data of the object */
361 if ( panel_ToolBar
!= NULL
)
363 D(bug("[IW.toolbar] %s: ToolBar Obj @ 0x%p\n", __PRETTY_FUNCTION__
, panel_ToolBar
));
365 SET(panelToolBar_ButtonDirUp
, MUIA_Background
, XGET( panel_ToolBar
, MUIA_Background
) );
366 SET(panelToolBar_ButtonDirUp
, MUIA_CycleChain
, 1);
367 SET(panelToolBar_ButtonDirUp
, MUIA_Frame
, MUIV_Frame_None
);
368 #if !defined(ICONWINDOW_OPTION_NOSEARCHBUTTON)
369 SET(panelToolBar_ButtonSearch
, MUIA_Background
, XGET( panel_ToolBar
, MUIA_Background
) );
370 SET(panelToolBar_ButtonSearch
, MUIA_CycleChain
, 1);
371 SET(panelToolBar_ButtonSearch
, MUIA_Frame
, MUIV_Frame_None
);
373 panelToolBarPrivate
->iwp_ToolBar_ToolBarObj
= panel_ToolBar
;
375 if (DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, MUIM_Group_InitChange
))
377 DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, OM_ADDMEMBER
, (IPTR
)panel_ToolBar
);
378 if (data
->iwd_TopPanel
.iwp_PanelGroupSpacerObj
)
380 DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, OM_REMMEMBER
, (IPTR
)data
->iwd_TopPanel
.iwp_PanelGroupSpacerObj
);
381 data
->iwd_TopPanel
.iwp_PanelGroupSpacerObj
= NULL
;
384 DoMethod(data
->iwd_TopPanel
.iwp_PanelGroupObj
, MUIM_Group_ExitChange
);
387 if (panelToolBarPrivate
->iwp_ToolBar_ToolBarObj
)
390 panelToolBar_ButtonDirUp
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
391 (IPTR
)self
, 1, MUIM_IconWindow_DirectoryUp
394 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
= panelToolBar_StringLocation
;
396 panelToolBarPrivate
->iwp_ToolBar_LocationStrHook
.h_Entry
= ( HOOKFUNC
)panelToolBar__HookFunc_LocationStringFunc
;
398 panelToolBarPrivate
->iwp_ToolBar_LocationStrHook
= &ToolBar_locationstrHook
;
402 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIA_String_Contents
,
403 XGET(data
->iwd_IconListObj
, MUIA_IconDrawerList_Drawer
)
406 /* Make changes to string contents change dir on enter */
408 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
409 (IPTR
)self
, 3, MUIM_CallHook
, &panelToolBarPrivate
->iwp_ToolBar_LocationStrHook
, (IPTR
)CLASS
412 if (!(panelToolBar__PrefsNotificationObject
))
413 panelToolBar__PrefsSetup(CLASS
, self
, message
);
417 panelToolBar__PrefsNotificationObject
, MUIM_Notify
, MUIA_ShowMe
, MUIV_EveryTime
,
418 (IPTR
)data
->iwd_TopPanel
.iwp_PanelContainerObj
, 3, MUIM_Set
, MUIA_ShowMe
, MUIV_TriggerValue
421 if ((strcasecmp(extension_PrefsData
, "True")) == 0)
423 SET(data
->iwd_TopPanel
.iwp_PanelContainerObj
, MUIA_ShowMe
, TRUE
);
426 AddTail(&panelToolBar__ToolBars
, &panelToolBarPrivate
->iwp_Node
);
431 panelToolBarPrivate
->iwp_ToolBar_ToolBarObj
= NULL
;
438 IPTR
panelToolBar__Cleanup(Class
*CLASS
, Object
*self
, struct opSet
*message
)
440 SETUP_ICONWINDOW_INST_DATA
;
442 struct panel_ToolBar_DATA
*panelToolBarPrivate
;
444 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
446 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != (IPTR
)NULL
)
448 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= extension_Name
)
451 if (panelToolBar__PrefsNotificationObject
)
455 panelToolBar__PrefsNotificationObject
, MUIM_KillNotifyObj
, MUIA_ShowMe
,
456 (IPTR
)data
->iwd_TopPanel
.iwp_PanelContainerObj
459 if (panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
)
463 panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIM_KillNotifyObj
, MUIA_String_Acknowledge
,
472 IPTR
panelToolBar__OM_GET(Class
*CLASS
, Object
*self
, struct opGet
*message
)
474 SETUP_ICONWINDOW_INST_DATA
;
476 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
477 IPTR
*store
= message
->opg_Storage
;
480 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
482 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != (IPTR
)NULL
)
484 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= extension_Name
)
487 switch (message
->opg_AttrID
)
496 IPTR
panelToolBar__OM_SET(Class
*CLASS
, Object
*self
, struct opSet
*message
)
498 SETUP_ICONWINDOW_INST_DATA
;
500 struct panel_ToolBar_DATA
*panelToolBarPrivate
= NULL
;
501 struct TagItem
*tstate
= message
->ops_AttrList
, *tag
;
502 BOOL UpdateIconlist
= FALSE
;
503 IPTR focusicon
= (IPTR
) NULL
;
506 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
508 if ((panelToolBarPrivate
= (struct panel_ToolBar_DATA
*)data
->iwd_TopPanel
.iwp_PanelPrivate
) != (IPTR
)NULL
)
510 if (panelToolBarPrivate
->iwp_Node
.ln_Name
!= extension_Name
)
513 while ((tag
= NextTagItem((TAGITEM
)&tstate
)) != NULL
)
517 case MUIA_IconWindow_Location
:
518 D(bug("[IW.toolbar] %s: MUIA_IconWindow_Location '%s'\n", __PRETTY_FUNCTION__
, data
->iwd_DirectoryPath
));
520 SET(panelToolBarPrivate
->iwp_ToolBar_LocationStringObj
, MUIA_String_Contents
, (IPTR
)data
->iwd_DirectoryPath
);
530 #define PANELTOOLBAR_PRIORITY 10
532 IPTR
panelToolBar__Init()
534 D(bug("[IW.toolbar]: %s()\n", __PRETTY_FUNCTION__
));
536 panelToolBar__Extension
.iwe_Node
.ln_Pri
= PANELTOOLBAR_PRIORITY
;
537 panelToolBar__Extension
.iwe_Node
.ln_Name
= extension_Name
;
538 panelToolBar__Extension
.iwe_Setup
= panelToolBar__Setup
;
539 panelToolBar__Extension
.iwe_Cleanup
= panelToolBar__Cleanup
;
540 panelToolBar__Extension
.iwe_Set
= panelToolBar__OM_SET
;
541 panelToolBar__Extension
.iwe_Get
= panelToolBar__OM_GET
;
543 NewList(&panelToolBar__ToolBars
);
545 Enqueue(&iconwindow_Extensions
, (struct Node
*)&panelToolBar__Extension
);
547 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
));
552 ADD2INIT(panelToolBar__Init
, PANELTOOLBAR_PRIORITY
);