remove unused file
[AROS.git] / workbench / libs / workbench / sendappwindowmessage.c
blob09f2d6c85349e9b26b0b65774340b1f3d1816f5b
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: check if the given window is an app window and send it a list of files
6 Lang: English
7 */
9 #include <exec/types.h>
10 #include <exec/ports.h>
11 #include <dos/dos.h>
12 #include <intuition/intuition.h>
14 #include <proto/utility.h>
16 #include "workbench_intern.h"
17 #include <workbench/workbench.h>
19 #include <string.h>
21 static char *allocPath(char *str, APTR WorkbenchBase);
23 /*****************************************************************************
25 NAME */
26 #include <proto/workbench.h>
28 AROS_LH8(BOOL, SendAppWindowMessage,
29 /* SYNOPSIS */
30 AROS_LHA(struct Window *, win, A0),
31 AROS_LHA(ULONG, numfiles, D0),
32 AROS_LHA(char **, files, A1),
33 AROS_LHA(UWORD, class, D1),
34 AROS_LHA(WORD, mousex, D2),
35 AROS_LHA(WORD, mousey, D3),
36 AROS_LHA(ULONG, seconds, D4),
37 AROS_LHA(ULONG, micros, D5),
39 /* LOCATION */
40 struct WorkbenchBase *, WorkbenchBase, 26, Workbench)
42 /* FUNCTION
43 This function sends the given list of files to a registered
44 AppWindow's application. If the window is not an AppWindow, nothing
45 is done.
47 INPUTS
48 win - window that should be checked
49 numfiles - number of files in the attached array of string pointers
50 files - files "list"
52 RESULT
53 TRUE if action succeeded
55 NOTES
57 EXAMPLE
59 char *FileList[] =
60 {"images:image1.png", "images:image2.png", "images:image3.png"};
62 SendAppWindowMessage(myWindow, 3, FileList);
64 BUGS
66 SEE ALSO
68 INTERNALS
70 ******************************************************************************/
72 AROS_LIBFUNC_INIT
74 struct List *awl = NULL;
76 BOOL success = FALSE;
78 if (numfiles == 0) return FALSE;
80 LockWorkbenchShared();
81 awl = &WorkbenchBase->wb_AppWindows;
82 if (!IsListEmpty(awl))
84 struct Node *succ;
85 struct Node *s = awl->lh_Head;
86 struct AppWindow *aw = NULL;
87 int i;
88 BOOL fail = FALSE;
90 struct AppMessage *am = AllocVec(sizeof (struct AppMessage), MEMF_CLEAR);
91 if (am)
93 while (((succ = ((struct Node*) s)->ln_Succ) != NULL) && (aw == NULL))
95 if ((((struct AppWindow *) s)->aw_Window) == win)
97 aw = (struct AppWindow *) s;
99 s = succ;
101 if (aw)
103 struct WBArg *wbargs = AllocVec(sizeof(struct WBArg) * numfiles, MEMF_CLEAR);
104 if (wbargs)
106 struct WBArg *wb = wbargs;
107 for (i = 0; i < numfiles; i++)
109 wb->wa_Name = FilePart(files[i]);
110 char *path = allocPath(files[i], WorkbenchBase);
111 if (path)
113 wb->wa_Lock = Lock(path, SHARED_LOCK);
114 if (wb->wa_Lock == 0) fail = TRUE;
115 FreeVec(path);
117 wb++;
119 if (!fail)
121 struct MsgPort *port = aw->aw_MsgPort;
122 am->am_NumArgs = numfiles;
123 am->am_ArgList = wbargs;
124 am->am_ID = aw->aw_ID;
125 am->am_UserData = aw->aw_UserData;
126 am->am_Type = AMTYPE_APPWINDOW;
127 am->am_Version = AM_VERSION;
128 am->am_Class = class;
129 am->am_MouseX = mousex;
130 am->am_MouseY = mousey;
131 am->am_Seconds = seconds;
132 am->am_Micros = micros;
133 struct MsgPort *reply = CreateMsgPort();
134 if (reply)
136 am->am_Message.mn_ReplyPort = reply;
137 PutMsg(port, (struct Message *) am);
138 WaitPort(reply);
139 GetMsg(reply);
140 DeleteMsgPort(reply);
141 success = TRUE;
144 wb = wbargs;
145 for (i = 0; i < numfiles; i++)
147 if (wb->wa_Lock) UnLock(wb->wa_Lock);
148 wb++;
150 FreeVec(wbargs);
153 FreeVec(am);
156 UnlockWorkbench();
158 return success;
160 AROS_LIBFUNC_EXIT
161 } /* SendAppWindowMessage() */
163 /*****************************************************************************/
165 static char *allocPath(char *str, APTR WorkbenchBase)
167 char *s0, *s1, *s;
169 s = NULL;
170 s0 = str;
172 s1 = PathPart(str);
173 if (s1)
175 int l;
177 for (l = 0; s0 != s1; s0++,l++);
178 s = AllocVec(l + 1, MEMF_CLEAR);
179 if (s) strncpy(s, str, l);
181 return s;