2 Copyright 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: check if the given window is an app window and send a list of files to it
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 /*****************************************************************************
24 #include <proto/workbench.h>
26 char *allocPath(char *str
) {
35 for (l
=0; s0
!= s1
; s0
++,l
++);
36 s
= AllocVec(l
+1, MEMF_CLEAR
);
37 if (s
) strncpy(s
, str
, l
);
41 AROS_LH8(BOOL
, SendAppWindowMessage
,
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
),
53 struct WorkbenchBase
*, WorkbenchBase
, 26, Workbench
)
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.
62 win -- window which should be checked
63 numfiles -- number of files in the attached array of pointers to an array of chars
68 TRUE if action succeeded
74 char *FileList[] = {"images:image1.png", "images:image2.png", "images:image3.png", };
76 SendAppWindowMessage(myWindow, 3, FilesList);
84 ******************************************************************************/
87 struct List
*awl
= NULL
;
91 if (numfiles
== 0) return FALSE
;
93 LockWorkbenchShared();
94 awl
= &WorkbenchBase
->wb_AppWindows
;
95 if (!IsListEmpty(awl
))
98 struct Node
*s
= awl
->lh_Head
;
99 struct AppWindow
*aw
= NULL
;
103 struct AppMessage
*am
= AllocVec(sizeof (struct AppMessage
), MEMF_CLEAR
);
106 while (((succ
= ((struct Node
*) s
)->ln_Succ
) != NULL
) && (aw
== NULL
))
108 if ((((struct AppWindow
*) s
)->aw_Window
) == win
)
110 aw
= (struct AppWindow
*) s
;
116 struct WBArg
*wbargs
= AllocVec(sizeof(struct WBArg
) * numfiles
, MEMF_CLEAR
);
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
]);
126 wb
->wa_Lock
= Lock(path
, SHARED_LOCK
);
127 if (wb
->wa_Lock
== 0) fail
= TRUE
;
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();
149 am
->am_Message
.mn_ReplyPort
= reply
;
150 PutMsg(port
, (struct Message
*) am
);
153 DeleteMsgPort(reply
);
158 for (i
= 0; i
< numfiles
; i
++)
160 if (wb
->wa_Lock
) UnLock(wb
->wa_Lock
);
174 } /* SendAppWindowMessage() */