This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathdesktop-ans.cpp
More file actions
332 lines (253 loc) · 8.96 KB
/
desktop-ans.cpp
File metadata and controls
332 lines (253 loc) · 8.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/* Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
#include "platform.h"
#include "globdefs.h"
#include "filedefs.h"
#include "osspec.h"
#include "typedefs.h"
#include "parsedef.h"
#include "objdefs.h"
#include "globals.h"
#include "exec.h"
#include "stack.h"
#include "ans.h"
#include "variable.h"
////////////////////////////////////////////////////////////////////////////////
// MW-2014-06-25: [[ Bug 12686 ]] Make sure we first try the defaultStack, then
// the topStack.
static MCPlatformWindowRef compute_sheet_owner(unsigned int p_options)
{
if ((p_options & MCA_OPTION_SHEET) == 0)
return nil;
MCPlatformWindowRef t_window;
t_window = MCdefaultstackptr -> getwindow();
if (t_window != nil && MCPlatformIsWindowVisible(t_window))
return t_window;
t_window = MCtopstackptr -> getwindow();
if (t_window != nil && MCPlatformIsWindowVisible(t_window))
return t_window;
return nil;
}
////////////////////////////////////////////////////////////////////////////////
// MM-2012-02-13: Updated to use Cocoa APIs. Code mostly cribbed from plugin dialog stuff
int MCA_folder(MCStringRef p_title, MCStringRef p_prompt, MCStringRef p_initial, unsigned int p_options, MCStringRef &r_value, MCStringRef &r_result)
{
MCPlatformWindowRef t_owner;
t_owner = compute_sheet_owner(p_options);
MCPlatformBeginFolderOrFileDialog(kMCPlatformFileDialogKindFolder, t_owner, p_title, p_prompt, p_initial);
MCPlatformDialogResult t_result;
MCAutoStringRef t_folder;
for(;;)
{
t_result = MCPlatformEndFolderDialog(&t_folder);
if (t_result != kMCPlatformDialogResultContinue)
break;
MCscreen -> wait(REFRESH_INTERVAL, True, True);
}
if (t_result == kMCPlatformDialogResultSuccess)
r_value = MCValueRetain(*t_folder);
return 0;
}
////////////////////////////////////////////////////////////////////////////////
static bool filter_to_type_list(MCStringRef p_filter, MCStringRef *&r_types, uint32_t &r_type_count)
{
bool t_success;
t_success = true;
if (t_success)
t_success = p_filter != nil;
uint32_t t_filter_length;
if (t_success)
{
t_filter_length = MCStringGetLength(p_filter);
t_success = t_filter_length >= 4;
}
if (!t_success)
{
r_type_count = 0;
return true;
}
MCStringRef t_types;
if (t_success)
t_success = MCStringCreateMutable(0, t_types);
if (t_success)
t_success = MCStringAppendFormat(t_types, "||", strlen("||"));
if (t_success)
{
uint32_t t_current_pos;
t_current_pos = 0;
for (uint32_t i = 0; t_success && i < t_filter_length / 4; i++)
{
if (i > 0)
t_success = MCStringAppendNativeChar(t_types, ',');
if (t_success)
{
t_success = MCStringAppendSubstring(t_types, p_filter, MCRangeMake(t_current_pos, 4));
t_current_pos += 4;
}
}
}
if (t_success)
t_success = MCMemoryNewArray(1, r_types);
if (t_success)
{
r_types[0] = t_types;
r_type_count = 1;
}
else
{
r_type_count = 0;
MCValueRelease(t_types);
}
return t_success;
}
int MCA_file(MCStringRef p_title, MCStringRef p_prompt, MCStringRef p_filter, MCStringRef p_initial, unsigned int p_options, MCStringRef &r_value, MCStringRef &r_result)
{
MCAutoStringRefArray t_types;
filter_to_type_list(p_filter, t_types.PtrRef(), t_types.CountRef());
MCPlatformWindowRef t_owner;
t_owner = compute_sheet_owner(p_options);
MCPlatformFileDialogKind t_kind;
if ((p_options & MCA_OPTION_PLURAL) != 0)
t_kind = kMCPlatformFileDialogKindOpenMultiple;
else
t_kind = kMCPlatformFileDialogKindOpen;
MCPlatformBeginFolderOrFileDialog(t_kind, t_owner, p_title, p_prompt, p_initial, *t_types, t_types . Count());
MCPlatformDialogResult t_result;
MCAutoStringRef t_file, t_type;
for(;;)
{
MCValueRelease(*t_file);
MCValueRelease(*t_type);
t_result = MCPlatformEndFileDialog(t_kind, &t_file, &t_type);
if (t_result != kMCPlatformDialogResultContinue)
break;
MCscreen -> wait(REFRESH_INTERVAL, True, True);
}
if (t_result == kMCPlatformDialogResultSuccess)
r_value = MCValueRetain(*t_file);
return 0;
}
int MCA_file_with_types(MCStringRef p_title, MCStringRef p_prompt, MCStringRef *p_types, uint4 p_type_count, MCStringRef p_initial, unsigned int p_options, MCStringRef &r_value, MCStringRef &r_result)
{
MCPlatformWindowRef t_owner;
t_owner = compute_sheet_owner(p_options);
MCPlatformFileDialogKind t_kind;
if ((p_options & MCA_OPTION_PLURAL) != 0)
t_kind = kMCPlatformFileDialogKindOpenMultiple;
else
t_kind = kMCPlatformFileDialogKindOpen;
MCPlatformBeginFolderOrFileDialog(t_kind, t_owner, p_title, p_prompt, p_initial, p_types, p_type_count);
MCPlatformDialogResult t_result;
MCAutoStringRef t_file, t_type;
for(;;)
{
MCValueRelease(*t_file);
MCValueRelease(*t_type);
t_result = MCPlatformEndFileDialog(t_kind, &t_file, &t_type);
if (t_result != kMCPlatformDialogResultContinue)
break;
MCscreen -> wait(REFRESH_INTERVAL, True, True);
}
if (t_result == kMCPlatformDialogResultSuccess)
{
r_value = MCValueRetain(*t_file);
if (*t_type != nil)
r_result = MCValueRetain(*t_type);
}
return 0;
}
int MCA_ask_file(MCStringRef p_title, MCStringRef p_prompt, MCStringRef p_filter, MCStringRef p_initial, unsigned int p_options, MCStringRef &r_value, MCStringRef &r_result)
{
MCAutoStringRefArray t_types;
filter_to_type_list(p_filter, t_types.PtrRef(), t_types.CountRef());
MCPlatformWindowRef t_owner;
t_owner = compute_sheet_owner(p_options);
MCPlatformBeginFolderOrFileDialog(kMCPlatformFileDialogKindSave, t_owner, p_title, p_prompt, p_initial, *t_types, t_types . Count());
MCPlatformDialogResult t_result;
MCAutoStringRef t_file, t_type;
for(;;)
{
MCValueRelease(*t_file);
MCValueRelease(*t_type);
t_result = MCPlatformEndFileDialog(kMCPlatformFileDialogKindSave, &t_file, &t_type);
if (t_result != kMCPlatformDialogResultContinue)
break;
MCscreen -> wait(REFRESH_INTERVAL, True, True);
}
if (t_result == kMCPlatformDialogResultSuccess)
r_value = MCValueRetain(*t_file);
return 0;
}
int MCA_ask_file_with_types(MCStringRef p_title, MCStringRef p_prompt, MCStringRef *p_types, uint4 p_type_count, MCStringRef p_initial, unsigned int p_options, MCStringRef &r_value, MCStringRef &r_result)
{
MCPlatformWindowRef t_owner;
t_owner = compute_sheet_owner(p_options);
MCPlatformBeginFolderOrFileDialog(kMCPlatformFileDialogKindSave, t_owner, p_title, p_prompt, p_initial, p_types, p_type_count);
MCPlatformDialogResult t_result;
MCAutoStringRef t_file, t_type;
for(;;)
{
MCValueRelease(*t_file);
MCValueRelease(*t_type);
t_result = MCPlatformEndFileDialog(kMCPlatformFileDialogKindSave, &t_file, &t_type);
if (t_result != kMCPlatformDialogResultContinue)
break;
MCscreen -> wait(REFRESH_INTERVAL, True, True);
}
if (t_result == kMCPlatformDialogResultSuccess)
{
r_value = MCValueRetain(*t_file);
// SN-2014-10-31: [[ Bug 13893 ]] MCPlatformEndFileDialog might return a nil value
if (*t_type != nil)
r_result = MCValueRetain(*t_type);
else
r_result = nil;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
bool MCA_color(MCStringRef p_title, MCColor p_initial, bool as_sheet, bool& r_chosen, MCColor& r_chosen_color)
{
MCPlatformBeginColorDialog(p_title, p_initial);
MCPlatformDialogResult t_result;
MCColor t_new_color;
for(;;)
{
t_result = MCPlatformEndColorDialog(t_new_color);
if (t_result != kMCPlatformDialogResultContinue)
break;
MCscreen -> wait(REFRESH_INTERVAL, True, True);
}
if (t_result == kMCPlatformDialogResultSuccess)
{
r_chosen_color = t_new_color;
r_chosen = true;
MCresult->clear(False);
}
else
{
MCresult->sets(MCcancelstring);
r_chosen = false;
}
// SN-2014-07-23: [[ Bug 12901 ]] Object colors not selectable in inspector
// A bool is expected from MCS_color, not an int defaulting to 0.
return true;
}
// MERG-2013-08-18: Stubs for colorDialogColors. Possibly implement when color dialog moves to Cocoa
void MCA_getcolordialogcolors(MCColor*& r_list, uindex_t& r_count)
{
r_count = 0;
}
void MCA_setcolordialogcolors(MCColor* p_list, uindex_t p_count)
{
}
////////////////////////////////////////////////////////////////////////////////