revert between 56095 -> 55830 in arch
[AROS.git] / workbench / system / Wanderer / panel_toolbar.c
blobfbd54ba059cfad5a48a9f92e73aab6814b5bccc0
1 /*
2 Copyright 2004-2010, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "portable_macros.h"
7 #ifdef __AROS__
8 #define MUIMASTER_YES_INLINE_STDARG
9 #endif
11 #define ICONWINDOW_OPTION_NOSEARCHBUTTON
13 #ifdef __AROS__
14 #define DEBUG 0
15 #include <aros/debug.h>
16 #endif
18 #include <exec/types.h>
19 #include <libraries/mui.h>
21 #ifdef __AROS__
22 #include <zune/customclasses.h>
23 #else
24 #include <zune_AROS/customclasses.h>
25 #endif
27 #include <proto/utility.h>
29 #include <proto/graphics.h>
31 #include <proto/exec.h>
32 #include <proto/datatypes.h>
34 #include <dos/dos.h>
35 #include <proto/dos.h>
37 #include <proto/icon.h>
39 #include <stdio.h>
40 #include <string.h>
42 #include <intuition/screens.h>
43 #include <datatypes/pictureclass.h>
44 #include <clib/macros.h>
46 #ifdef __AROS__
47 #include <clib/alib_protos.h>
49 #include <prefs/wanderer.h>
50 #else
51 #include <prefs_AROS/wanderer.h>
52 #endif
54 #if defined(__AMIGA__) && !defined(__PPC__)
55 #define NO_INLINE_STDARG
56 #endif
57 #ifndef _PROTO_INTUITION_H
58 #include <proto/intuition.h>
59 #endif
60 #include <proto/muimaster.h>
62 #include "Classes/iconlist.h"
63 #include "Classes/iconlistview.h"
64 #include "Classes/iconlist_attributes.h"
65 #include "wanderer.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
86 struct Node iwp_Node;
88 Object *iwp_ToolBar_ToolBarObj;
89 Object *iwp_ToolBar_LocationStringObj;
90 #ifdef __AROS__
91 struct Hook iwp_ToolBar_LocationStrHook;
92 #else
93 struct Hook *iwp_ToolBar_LocationStrHook;
94 #endif
97 ///ExpandEnvName()
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)
103 BOOL ok = FALSE;
104 char tmp_envbuff[1024];
105 STRPTR fullpath = NULL;
106 BPTR env_lock = (BPTR) NULL;
108 env_lock = Lock("ENV:", SHARED_LOCK);
109 if (env_lock)
111 if (NameFromLock(env_lock, tmp_envbuff, 256)) ok = TRUE;
112 UnLock(env_lock);
115 if (ok)
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);
121 return fullpath;
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);
130 return fullpath;
134 /*** Hook functions *********************************************************/
136 ///panelToolBar__HookFunc_LocationStringFunc()
137 #ifdef __AROS__
138 AROS_UFH3(
139 void, panelToolBar__HookFunc_LocationStringFunc,
140 AROS_UFHA(struct Hook *, hook, A0),
141 AROS_UFHA(APTR *, obj, A2),
142 AROS_UFHA(APTR, param, A1)
145 #else
146 HOOKPROTO(panelToolBar__HookFunc_LocationStringFunc, void, APTR *obj, APTR param)
148 #endif
149 AROS_USERFUNC_INIT
151 /* Get data */
152 Object *self = ( Object *)obj;
153 Class *CLASS = *( Class **)param;
154 STRPTR str = NULL;
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)
165 return;
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);
173 if (!fib)
174 return;
176 if (!(fp = Lock(str, ACCESS_READ)))
178 FreeDosObject(DOS_FIB, fib);
179 return;
182 if (!(Examine(fp, fib)))
184 UnLock (fp );
185 FreeDosObject(DOS_FIB, fib);
186 return;
189 /* Change directory! */
190 if (fib->fib_DirEntryType >= 0)
192 SET(self, MUIA_IconWindow_Location, (IPTR)str);
195 UnLock(fp);
197 FreeDosObject(DOS_FIB, fib);
200 AROS_USERFUNC_EXIT
202 #ifndef __AROS__
203 MakeStaticHook(ToolBar_locationstrHook, panelToolBar__HookFunc_LocationStringFunc);
204 #endif
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);
216 else
218 SET(panelToolBar__PrefsNotificationObject, MUIA_ShowMe, FALSE);
221 return 0;
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)
245 return 0;
247 extension_PrefsData = (STRPTR)AllocVec(TOOLBAR_PREFSSIZE, MEMF_CLEAR);
248 if (extension_PrefsData == NULL)
250 extension_PrefsData = (STRPTR)strTrue;
251 return 0;
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));
269 else
271 D(bug("[IW.toolbar] %s: FAILED to setup Prefs-notification!\n", __PRETTY_FUNCTION__));
273 AddTail(panelToolBarFSNotifyList, &_prefsNotifyHandler->fshn_Node);
275 #ifdef __AROS__
276 panelToolBar__PrefsNotificationObject = (Object *)NotifyObject, End;
277 #else
278 panelToolBar__PrefsNotificationObject = MUI_NewObject(MUIC_Notify, TAG_DONE);
279 #endif
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));
285 return 0;
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))
302 return (IPTR)NULL;
304 #if !defined(ICONWINDOW_OPTION_NOSEARCHBUTTON)
305 panelToolBar_ButtonSearch = ImageButton("", "THEME:Images/Gadgets/Search");
306 #endif
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)
313 return 0;
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,
320 MUIA_InnerLeft,(0),
321 MUIA_InnerRight,(0),
322 MUIA_InnerTop,(0),
323 MUIA_InnerBottom,(0),
324 MUIA_Frame, MUIV_Frame_None,
325 Child, (IPTR)MUI_NewObject(MUIC_Group, MUIA_Group_Horiz, TRUE ,
326 MUIA_InnerLeft,(4),
327 MUIA_InnerRight,(4),
328 MUIA_InnerTop,(4),
329 MUIA_InnerBottom,(4),
330 MUIA_Frame, MUIV_Frame_None,
331 MUIA_Weight, 100,
332 Child, (IPTR)MUI_NewObject(MUIC_Group, MUIA_Group_Horiz, TRUE ,
333 MUIA_InnerLeft,(0),
334 MUIA_InnerRight,(0),
335 MUIA_InnerTop,(0),
336 MUIA_InnerBottom,(0),
337 MUIA_Weight, 100,
338 Child, (IPTR)( panelToolBar_StringLocation = MUI_NewObject(MUIC_String,
339 MUIA_String_Contents, (IPTR)"",
340 MUIA_CycleChain, 1,
341 MUIA_Frame, MUIV_Frame_String,
342 TAG_DONE) ),
343 TAG_DONE),
344 Child, (IPTR)MUI_NewObject(MUIC_Group, MUIA_Group_Horiz, TRUE ,
345 MUIA_InnerLeft,(0),
346 MUIA_InnerRight,(0),
347 MUIA_InnerTop,(0),
348 MUIA_InnerBottom,(0),
349 MUIA_HorizWeight, 0,
350 MUIA_VertWeight, 100,
351 Child, (IPTR) (panelToolBar_ButtonDirUp = ImageButton("", "THEME:Images/Gadgets/DirUp")),
352 (panelToolBar_ButtonSearch ? Child : TAG_IGNORE), (IPTR) (panelToolBar_ButtonSearch),
353 TAG_DONE),
354 TAG_DONE),
355 Child, (IPTR)MUI_NewObject(MUIC_Group, MUIA_Group_Horiz, TRUE ,
356 MUIA_InnerLeft,(0),
357 MUIA_InnerRight,(0),
358 MUIA_InnerTop,(0),
359 MUIA_InnerBottom,(0),
360 MUIA_Group_Spacing, 0,
361 MUIA_FixHeight, 1,
362 MUIA_Frame, MUIV_Frame_None,
363 MUIA_Background, MUII_SHADOW,
364 Child, (IPTR)MUI_NewObject(MUIC_Rectangle,
365 MUIA_Frame, MUIV_Frame_None,
366 TAG_DONE),
367 TAG_DONE),
368 TAG_DONE);
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 );
383 #endif
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)
400 DoMethod(
401 panelToolBar_ButtonDirUp, MUIM_Notify, MUIA_Pressed, FALSE,
402 (IPTR)self, 1, MUIM_IconWindow_DirectoryUp
405 panelToolBarPrivate->iwp_ToolBar_LocationStringObj = panelToolBar_StringLocation;
406 #ifdef __AROS__
407 panelToolBarPrivate->iwp_ToolBar_LocationStrHook.h_Entry = ( HOOKFUNC )panelToolBar__HookFunc_LocationStringFunc;
408 #else
409 panelToolBarPrivate->iwp_ToolBar_LocationStrHook= &ToolBar_locationstrHook;
410 #endif
412 NNSET(
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 */
418 DoMethod (
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);
426 DoMethod
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);
440 else
442 panelToolBarPrivate->iwp_ToolBar_ToolBarObj = NULL;
445 return 0;
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__));
457 #if (0)
458 // we cant free this here since it will be used again!
459 if (extension_PrefsData && (extension_PrefsData != strTrue))
460 FreeVec(extension_PrefsData);
461 #endif
463 if ((panelToolBarPrivate = (struct panel_ToolBar_DATA *)data->iwd_TopPanel.iwp_PanelPrivate) != NULL)
465 if (panelToolBarPrivate->iwp_Node.ln_Name != (char *)extension_Name)
466 return 0;
468 if (panelToolBar__PrefsNotificationObject)
470 DoMethod
472 panelToolBar__PrefsNotificationObject, MUIM_KillNotifyObj, MUIA_ShowMe,
473 (IPTR)data->iwd_TopPanel.iwp_PanelContainerObj
476 if (panelToolBarPrivate->iwp_ToolBar_LocationStringObj)
478 DoMethod
480 panelToolBarPrivate->iwp_ToolBar_LocationStringObj, MUIM_KillNotifyObj, MUIA_String_Acknowledge,
481 (IPTR)self
485 return 0;
488 ///OM_GET()
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;
495 IPTR rv = FALSE;
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)
502 return rv;
504 switch (message->opg_AttrID)
509 return rv;
512 ///OM_SET()
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;
521 IPTR rv = FALSE;
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)
528 return rv;
530 while ((tag = NextTagItem((TAGITEM)&tstate)) != NULL)
532 switch (tag->ti_Tag)
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);
539 break;
544 return rv;
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));
566 return TRUE;
569 ADD2INIT(panelToolBar__Init, PANELTOOLBAR_PRIORITY);