define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / rom / workbench / sendappwindowmessage.c
blob1567541d109b3b58a7b104107c931313f2c7afb8
1 /*
2 Copyright 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: check if the given window is an app window and send a list of files to it
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 /*****************************************************************************
23 NAME */
24 #include <proto/workbench.h>
26 char *allocPath(char *str) {
27 char *s0, *s1, *s;
28 int l;
30 s = NULL;
31 s0 = str;
33 s1 = PathPart(str);
34 if (s1) {
35 for (l=0; s0 != s1; s0++,l++);
36 s = AllocVec(l+1, MEMF_CLEAR);
37 if (s) strncpy(s, str, l);
39 return s;
41 AROS_LH8(BOOL, SendAppWindowMessage,
42 /* SYNOPSIS */
43 AROS_LHA(struct Window *, win, A0),
44 AROS_LHA(ULONG, numfiles, D0),
45 AROS_LHA(char **, files, A1),
46 AROS_LHA(UWORD, class, D1),
47 AROS_LHA(WORD, mousex, D2),
48 AROS_LHA(WORD, mousey, D3),
49 AROS_LHA(ULONG, seconds, D4),
50 AROS_LHA(ULONG, micros, D5),
52 /* LOCATION */
53 struct WorkbenchBase *, WorkbenchBase, 26, Workbench)
55 /* FUNCTION
57 This function checks if the provided window is a registred AppWindow, if this is true the
58 list of given files will be send to the Application of the window.
60 INPUTS
62 win -- window which should be checked
63 numfiles -- number of files in the attached array of pointers to an array of chars
64 files -- files "list"
66 RESULT
68 TRUE if action succeeded
70 NOTES
72 EXAMPLE
74 char *FileList[] = {"images:image1.png", "images:image2.png", "images:image3.png", };
76 SendAppWindowMessage(myWindow, 3, FilesList);
78 BUGS
80 SEE ALSO
82 INTERNALS
84 ******************************************************************************/
86 AROS_LIBFUNC_INIT
87 struct List *awl = NULL;
89 BOOL success = FALSE;
91 if (numfiles == 0) return FALSE;
93 LockWorkbenchShared();
94 awl = &WorkbenchBase->wb_AppWindows;
95 if (!IsListEmpty(awl))
97 struct Node *succ;
98 struct Node *s = awl->lh_Head;
99 struct AppWindow *aw = NULL;
100 int i;
101 BOOL fail = FALSE;
103 struct AppMessage *am = AllocVec(sizeof (struct AppMessage), MEMF_CLEAR);
104 if (am)
106 while (((succ = ((struct Node*) s)->ln_Succ) != NULL) && (aw == NULL))
108 if ((((struct AppWindow *) s)->aw_Window) == win)
110 aw = (struct AppWindow *) s;
112 s = succ;
114 if (aw)
116 struct WBArg *wbargs = AllocVec(sizeof(struct WBArg) * numfiles, MEMF_CLEAR);
117 if (wbargs)
119 struct WBArg *wb = wbargs;
120 for (i = 0; i < numfiles; i++)
122 wb->wa_Name = FilePart(files[i]);
123 char *path = allocPath(files[i]);
124 if (path)
126 wb->wa_Lock = Lock(path, SHARED_LOCK);
127 if (wb->wa_Lock == 0) fail = TRUE;
128 FreeVec(path);
130 wb++;
132 if (!fail)
134 struct MsgPort *port = aw->aw_MsgPort;
135 am->am_NumArgs = numfiles;
136 am->am_ArgList = wbargs;
137 am->am_ID = aw->aw_ID;
138 am->am_UserData = aw->aw_UserData;
139 am->am_Type = AMTYPE_APPWINDOW;
140 am->am_Version = AM_VERSION;
141 am->am_Class = class;
142 am->am_MouseX = mousex;
143 am->am_MouseY = mousey;
144 am->am_Seconds = seconds;
145 am->am_Micros = micros;
146 struct MsgPort *reply = CreateMsgPort();
147 if (reply)
149 am->am_Message.mn_ReplyPort = reply;
150 PutMsg(port, (struct Message *) am);
151 WaitPort(reply);
152 GetMsg(reply);
153 DeleteMsgPort(reply);
154 success = TRUE;
157 wb = wbargs;
158 for (i = 0; i < numfiles; i++)
160 if (wb->wa_Lock) UnLock(wb->wa_Lock);
161 wb++;
163 FreeVec(wbargs);
166 FreeVec(am);
169 UnlockWorkbench();
171 return success;
173 AROS_LIBFUNC_EXIT
174 } /* SendAppWindowMessage() */