2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 Desc: check if the given window is an app window and send it a list of files
9 #include <exec/types.h>
10 #include <exec/ports.h>
12 #include <intuition/intuition.h>
14 #include <proto/utility.h>
16 #include "workbench_intern.h"
17 #include <workbench/workbench.h>
21 static char *allocPath(char *str
, APTR WorkbenchBase
);
23 /*****************************************************************************
26 #include <proto/workbench.h>
28 AROS_LH8(BOOL
, SendAppWindowMessage
,
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
),
40 struct WorkbenchBase
*, WorkbenchBase
, 26, Workbench
)
43 This function sends the given list of files to a registered
44 AppWindow's application. If the window is not an AppWindow, nothing
48 win - window that should be checked
49 numfiles - number of files in the attached array of string pointers
53 TRUE if action succeeded
60 {"images:image1.png", "images:image2.png", "images:image3.png"};
62 SendAppWindowMessage(myWindow, 3, FileList);
70 ******************************************************************************/
74 struct List
*awl
= NULL
;
78 if (numfiles
== 0) return FALSE
;
80 LockWorkbenchShared();
81 awl
= &WorkbenchBase
->wb_AppWindows
;
82 if (!IsListEmpty(awl
))
85 struct Node
*s
= awl
->lh_Head
;
86 struct AppWindow
*aw
= NULL
;
90 struct AppMessage
*am
= AllocVec(sizeof (struct AppMessage
), MEMF_CLEAR
);
93 while (((succ
= ((struct Node
*) s
)->ln_Succ
) != NULL
) && (aw
== NULL
))
95 if ((((struct AppWindow
*) s
)->aw_Window
) == win
)
97 aw
= (struct AppWindow
*) s
;
103 struct WBArg
*wbargs
= AllocVec(sizeof(struct WBArg
) * numfiles
, MEMF_CLEAR
);
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
);
113 wb
->wa_Lock
= Lock(path
, SHARED_LOCK
);
114 if (wb
->wa_Lock
== 0) fail
= TRUE
;
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();
136 am
->am_Message
.mn_ReplyPort
= reply
;
137 PutMsg(port
, (struct Message
*) am
);
140 DeleteMsgPort(reply
);
145 for (i
= 0; i
< numfiles
; i
++)
147 if (wb
->wa_Lock
) UnLock(wb
->wa_Lock
);
161 } /* SendAppWindowMessage() */
163 /*****************************************************************************/
165 static char *allocPath(char *str
, APTR WorkbenchBase
)
177 for (l
= 0; s0
!= s1
; s0
++,l
++);
178 s
= AllocVec(l
+ 1, MEMF_CLEAR
);
179 if (s
) strncpy(s
, str
, l
);