1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
4 * Copyright (C) 2014 - Scilab Enterprises - Cedric Delamarre
5 *
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 *
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
14 *
15 */
16
17 /*------------------------------------------------------------------------*/
18 /* file: get_figure_name_property.c */
19 /* desc : function to retrieve in Scilab the figure_name field of a */
20 /* handle */
21 /*------------------------------------------------------------------------*/
22
23 #include "internal.hxx"
24 #include "list.hxx"
25 #include "tlist.hxx"
26 #include "double.hxx"
27 #include "string.hxx"
28 #include "bool.hxx"
29
30 extern "C"
31 {
32 #include "Scierror.h"
33 #include "localization.h"
34 #include "SetPropertyStatus.h"
35 #include "getGraphicObjectProperty.h"
36 #include "graphicObjectProperties.h"
37 #include "FrameBorderType.h"
38 }
39
40 /*------------------------------------------------------------------------*/
41 void* getBorder (types::InternalType* _pITParent, int _iPos, int _iObjUID);
42 void* getNoBorder (types::InternalType* _pITParent, int _iPos, int _iObjUID);
43 void* getLineBorder (types::InternalType* _pITParent, int _iPos, int _iObjUID);
44 void* getBevelBorder (types::InternalType* _pITParent, int _iPos, int _iObjUID);
45 void* getSoftBevelBorder (types::InternalType* _pITParent, int _iPos, int _iObjUID);
46 void* getCommonBevelBorder (types::InternalType* _pITParent, int _iPos, int _iObjUID, int _iBevel);
47 void* getEtchedBorder (types::InternalType* _pITParent, int _iPos, int _iObjUID);
48 void* getTitledBorder (types::InternalType* _pITParent, int _iPos, int _iObjUID);
49 void* getEmptyBorder (types::InternalType* _pITParent, int _iPos, int _iObjUID);
50 void* getCompoundBorder (types::InternalType* _pITParent, int _iPos, int _iObjUID);
51 void* getMatteBorder (types::InternalType* _pITParent, int _iPos, int _iObjUID);
52 /*------------------------------------------------------------------------*/
53 extern "C"
54 {
get_border_property(void * _pvCtx,int iObjUID)55 void* get_border_property(void* _pvCtx, int iObjUID)
56 {
57 int iBorder = 0;
58 int* piBorder = &iBorder;
59
60 getGraphicObjectProperty(iObjUID, __GO_UI_FRAME_BORDER__, jni_int, (void **)&piBorder);
61 if (piBorder == NULL)
62 {
63 Scierror(999, _("'%s' property does not exist for this handle.\n"), "border");
64 return NULL;
65 }
66
67 return getBorder(NULL, 0, iBorder);
68 }
69 }
70 /*------------------------------------------------------------------------*/
getBorder(types::InternalType * _pITParent,int _iPos,int _iObjUID)71 void* getBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID)
72 {
73 int iStyle = 0;
74 int* piStyle = &iStyle;
75
76 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_STYLE__, jni_int, (void **)&piStyle);
77 if (piStyle == NULL)
78 {
79 Scierror(999, _("'%s' property does not exist for this handle.\n"), "border");
80 return NULL;
81 }
82
83 switch (iStyle)
84 {
85 default:
86 {
87 return getNoBorder(_pITParent, _iPos, _iObjUID);
88 }
89 break;
90 case LINE :
91 {
92 return getLineBorder(_pITParent, _iPos, _iObjUID);
93 }
94 break;
95 case BEVEL :
96 {
97 return getBevelBorder(_pITParent, _iPos, _iObjUID);
98 }
99 break;
100 case SOFTBEVEL :
101 {
102 return getSoftBevelBorder(_pITParent, _iPos, _iObjUID);
103 }
104 break;
105 case ETCHED :
106 {
107 return getEtchedBorder(_pITParent, _iPos, _iObjUID);
108 }
109 break;
110 case TITLED :
111 {
112 return getTitledBorder(_pITParent, _iPos, _iObjUID);
113 }
114 break;
115 case EMPTY :
116 {
117 return getEmptyBorder(_pITParent, _iPos, _iObjUID);
118 }
119 break;
120 case COMPOUND :
121 {
122 return getCompoundBorder(_pITParent, _iPos, _iObjUID);
123 }
124 break;
125 case MATTE :
126 {
127 return getMatteBorder(_pITParent, _iPos, _iObjUID);
128 }
129 break;
130 }
131
132 return 0;
133 }
134 /*------------------------------------------------------------------------*/
getNoBorder(types::InternalType * _pITParent,int _iPos,int _iObjUID)135 void* getNoBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID)
136 {
137 types::TList* pTL = new types::TList();
138 pTL->append(new types::String("NoBorder"));
139
140 if (_pITParent)
141 {
142 types::List* pL = _pITParent->getAs<types::List>();
143 pL->set(_iPos - 1, pTL);
144 }
145
146 return pTL;
147 }
148 /*------------------------------------------------------------------------*/
getLineBorder(types::InternalType * _pITParent,int _iPos,int _iObjUID)149 void* getLineBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID)
150 {
151 // properties
152 char* pstColor = NULL;
153 int iThickness = 0;
154 int* piThickness = &iThickness;
155 int iRounded = 0;
156 int* piRounded = &iRounded;
157 int iListSize = 4;
158
159 const wchar_t * pstFieldList[] = {L"LineBorder", L"color", L"thickness", L"rounded"};
160
161 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_COLOR__, jni_string, (void **)&pstColor);
162 if (pstColor == NULL)
163 {
164 Scierror(999, _("'%s' property does not exist for this handle.\n"), "border");
165 return NULL;
166 }
167
168 getGraphicObjectProperty(_iObjUID, __GO_LINE_THICKNESS__, jni_int, (void **)&piThickness);
169 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_ROUNDED__, jni_bool, (void **)&piRounded);
170
171 if (piRounded == NULL)
172 {
173 iListSize = 3;
174 }
175
176 if (piThickness == NULL)
177 {
178 iListSize = 2;
179 }
180
181 types::TList* pTL = new types::TList();
182 types::String* pStr = new types::String(1, iListSize, pstFieldList);
183
184 pTL->append(pStr);
185 pTL->append(new types::String(pstColor));
186
187 if (iListSize > 2)
188 {
189 pTL->append(new types::Double((double)iThickness));
190 }
191
192 if (iListSize > 3)
193 {
194 pTL->append(new types::Bool(iRounded));
195 }
196
197 if (_pITParent)
198 {
199 types::List* pL = _pITParent->getAs<types::List>();
200 pL->set(_iPos - 1, pTL);
201 }
202
203 return pTL;
204 }
205 /*------------------------------------------------------------------------*/
getBevelBorder(types::InternalType * _pITParent,int _iPos,int _iObjUID)206 void* getBevelBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID)
207 {
208 return getCommonBevelBorder(_pITParent, _iPos, _iObjUID, 1);
209 }
210 /*------------------------------------------------------------------------*/
getSoftBevelBorder(types::InternalType * _pITParent,int _iPos,int _iObjUID)211 void* getSoftBevelBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID)
212 {
213 return getCommonBevelBorder(_pITParent, _iPos, _iObjUID, 2);
214 }
215 /*------------------------------------------------------------------------*/
getCommonBevelBorder(types::InternalType * _pITParent,int _iPos,int _iObjUID,int _iBevel)216 void* getCommonBevelBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID, int _iBevel)
217 {
218 const wchar_t * pstFieldList1[] = {L"BevelBorder", L"type", L"hlouter", L"hlinner", L"shadowouter", L"shadowinner"};
219 const wchar_t * pstFieldList2[] = {L"BevelBorder", L"type", L"hlouter", L"shadowouter"};
220 wchar_t const* const* pstFieldList = pstFieldList1;
221
222 const wchar_t * pstSoftFieldList1[] = {L"SoftBevelBorder", L"type", L"hlouter", L"hlinner", L"shadowouter", L"shadowinner"};
223 const wchar_t * pstSoftFieldList2[] = {L"SoftBevelBorder", L"type", L"hlouter", L"shadowouter"};
224 wchar_t const* const* pstSoftFieldList = pstSoftFieldList1;
225
226 int iListSize = 6;
227
228 // properties
229 int iType = 0;
230 int* piType = &iType;
231 const wchar_t * pstType[] = {L"raised", L"lowered"};
232 char* pstHlOutColor = NULL;
233 char* pstHlInColor = NULL;
234 char* pstShadowOutColor = NULL;
235 char* pstShadowInColor = NULL;
236
237 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_TYPE__, jni_int, (void **)&piType);
238 if (piType == NULL)
239 {
240 Scierror(999, _("'%s' property does not exist for this handle.\n"), "border");
241 return NULL;
242 }
243
244 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, jni_string, (void **)&pstHlOutColor);
245 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_HIGHLIGHT_IN__, jni_string, (void **)&pstHlInColor);
246 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_SHADOW_OUT__, jni_string, (void **)&pstShadowOutColor);
247 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_SHADOW_IN__, jni_string, (void **)&pstShadowInColor);
248
249 if (pstHlInColor == NULL || pstShadowInColor == NULL)
250 {
251 iListSize = 4;
252 pstFieldList = pstFieldList2;
253 pstSoftFieldList = pstSoftFieldList2;
254 }
255
256 if (pstHlOutColor == NULL || pstShadowOutColor == NULL)
257 {
258 iListSize = 2;
259 pstFieldList = pstFieldList2;
260 pstSoftFieldList = pstSoftFieldList2;
261 }
262
263 types::TList* pTL = new types::TList();
264 types::String* pStr = NULL;
265
266 if (_iBevel == 1)
267 {
268 pStr = new types::String(1, iListSize, pstFieldList);
269 }
270 else
271 {
272 pStr = new types::String(1, iListSize, pstSoftFieldList);
273 }
274
275 pTL->append(pStr);
276 pTL->append(new types::String(pstType[iType]));
277
278 if (iListSize == 4)
279 {
280 pTL->append(new types::String(pstHlOutColor));
281 pTL->append(new types::String(pstShadowOutColor));
282 }
283 else if (iListSize == 6)
284 {
285 pTL->append(new types::String(pstHlOutColor));
286 pTL->append(new types::String(pstHlInColor));
287 pTL->append(new types::String(pstShadowOutColor));
288 pTL->append(new types::String(pstShadowInColor));
289 }
290
291 if (_pITParent)
292 {
293 types::List* pL = _pITParent->getAs<types::List>();
294 pL->set(_iPos - 1, pTL);
295 }
296
297 return pTL;
298 }
299 /*------------------------------------------------------------------------*/
getEtchedBorder(types::InternalType * _pITParent,int _iPos,int _iObjUID)300 void* getEtchedBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID)
301 {
302 const wchar_t * pstFieldList1[] = {L"EtchedBorder", L"type", L"hl", L"shadow"};
303 const wchar_t * pstFieldList2[] = {L"EtchedBorder", L"hl", L"shadow"};
304 wchar_t const* const* pstFieldList = pstFieldList1;
305 int iListSize = 4;
306
307 // properties
308 int iType = 0;
309 int* piType = &iType;
310 const wchar_t * pstType[] = {L"raised", L"lowered"};
311 char* pstHlOutColor = NULL;
312 char* pstShadowOutColor = NULL;
313
314 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_TYPE__, jni_int, (void **)&piType);
315 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_HIGHLIGHT_OUT__, jni_string, (void **)&pstHlOutColor);
316 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_SHADOW_OUT__, jni_string, (void **)&pstShadowOutColor);
317
318 if (piType == NULL)
319 {
320 if (pstHlOutColor == NULL || pstShadowOutColor == NULL)
321 {
322 iListSize = 1;
323 }
324 else
325 {
326 iListSize = 3;
327 pstFieldList = pstFieldList2;
328 }
329 }
330 else
331 {
332 if (pstHlOutColor == NULL || pstShadowOutColor == NULL)
333 {
334 iListSize = 2;
335 }
336 else
337 {
338 iListSize = 4;
339 }
340 }
341
342 types::TList* pTL = new types::TList();
343 types::String* pStr = new types::String(1, iListSize, pstFieldList);
344
345 pTL->append(pStr);
346
347 if (iListSize == 2 || iListSize == 4)
348 {
349 pTL->append(new types::String(pstType[iType]));
350 }
351
352 if (iListSize == 3 || iListSize == 4)
353 {
354 pTL->append(new types::String(pstHlOutColor));
355 pTL->append(new types::String(pstShadowOutColor));
356 }
357
358 if (_pITParent)
359 {
360 types::List* pL = _pITParent->getAs<types::List>();
361 pL->set(_iPos - 1, pTL);
362 }
363
364 return pTL;
365 }
366 /*------------------------------------------------------------------------*/
getTitledBorder(types::InternalType * _pITParent,int _iPos,int _iObjUID)367 void* getTitledBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID)
368 {
369 const wchar_t * pstFieldList1[] = {L"TitledBorder", L"border", L"title", L"justification", L"position", L"font", L"color"};
370 const wchar_t * pstFieldList2[] = {L"TitledBorder", L"title"};
371 wchar_t const* const* pstFieldList = pstFieldList1;
372 const wchar_t * pstJustification[] = {L"leading" , L"left" , L"center" , L"right" , L"trailing"};
373 const wchar_t * pstPosition[] = {L"top" , L"above_top" , L"below_top" , L"bottom" , L"above_bottom", L"below_bottom"};
374
375 int iListSize = 7;
376
377 // properties
378 int iChildBorder = 0;
379 int* piChildBorder = &iChildBorder;
380 char* pstTitle = NULL;
381 int iJustification = 0;
382 int* piJustification = &iJustification;
383 char* pstFontName = NULL;
384 char* pstFontAngle = NULL;
385 int iFontSize = 0;
386 int* piFontSize = &iFontSize;
387 char* pstFontWeight = NULL;
388 int iPosition = 0;
389 int* piPosition = &iPosition;
390 char* pstColor = NULL;
391
392 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_TITLE__, jni_int, (void **)&piChildBorder);
393 getGraphicObjectProperty(_iObjUID, __GO_TITLE__, jni_string, (void **)&pstTitle);
394 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_JUSTIFICATION__, jni_int, (void **)&piJustification);
395 getGraphicObjectProperty(_iObjUID, __GO_UI_FONTNAME__, jni_string, (void **)&pstFontName);
396 getGraphicObjectProperty(_iObjUID, __GO_UI_FONTANGLE__, jni_string, (void **)&pstFontAngle);
397 getGraphicObjectProperty(_iObjUID, __GO_UI_FONTSIZE__, jni_int, (void **)&piFontSize);
398 getGraphicObjectProperty(_iObjUID, __GO_UI_FONTWEIGHT__, jni_string, (void **)&pstFontWeight);
399 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_POSITION__, jni_int, (void **)&piPosition);
400 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_COLOR__, jni_string, (void **)&pstColor);
401
402 //2 3 5 6 7
403 if (pstColor == NULL)
404 {
405 iListSize = 6;
406 }
407
408 if (pstFontName == NULL || pstFontAngle == NULL || piFontSize == NULL || pstFontWeight == NULL)
409 {
410 iListSize = 5;
411 }
412
413 if (piJustification == NULL)
414 {
415 iListSize = 3;
416 }
417
418 if (pstTitle == NULL)
419 {
420 iListSize = 2;
421 }
422
423 if (piChildBorder == NULL)
424 {
425 iListSize = 2;
426 pstFieldList = pstFieldList2;
427 }
428
429 types::TList* pTL = new types::TList();
430 types::String* pStr = new types::String(1, iListSize, pstFieldList);
431
432 pTL->append(pStr);
433
434 if (piChildBorder)
435 {
436 //get child information and fill current list
437 if (getBorder(pTL, 2, iChildBorder) == NULL)
438 {
439 return NULL;
440 }
441 }
442
443 if (pstTitle)
444 {
445 //pos 2 or 3
446 pTL->append(new types::String(pstTitle));
447 }
448
449 if (iListSize > 3)
450 {
451 pTL->set(3, new types::String(pstJustification[iJustification]));
452 pTL->set(4, new types::String(pstPosition[iPosition]));
453 }
454
455 if (iListSize > 5)
456 {
457 //create a Font Border
458 types::TList* pTLBorder = new types::TList();
459
460 types::String* pStrBorder = new types::String(1, 5);
461 pStrBorder->set(0, "BorderFont");
462 pStrBorder->set(1, "name");
463 pStrBorder->set(2, "size");
464 pStrBorder->set(3, "angle");
465 pStrBorder->set(4, "weight");
466
467 pTLBorder->append(pStrBorder);
468 pTLBorder->append(new types::String(pstFontName));
469 pTLBorder->append(new types::Double((double)iFontSize));
470 pTLBorder->append(new types::String(pstFontAngle));
471 pTLBorder->append(new types::String(pstFontWeight));
472
473 pTL->set(5, pTLBorder);
474 }
475
476 if (iListSize > 6)
477 {
478 pTL->set(6, new types::String(pstColor));
479 }
480
481 if (_pITParent)
482 {
483 types::List* pL = _pITParent->getAs<types::List>();
484 pL->set(_iPos - 1, pTL);
485 }
486
487 return pTL;
488 }
489 /*------------------------------------------------------------------------*/
getEmptyBorder(types::InternalType * _pITParent,int _iPos,int _iObjUID)490 void* getEmptyBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID)
491 {
492 const wchar_t * pstFieldList[] = {L"EmptyBorder", L"top", L"left", L"bottom", L"right"};
493 int iListSize = 5;
494 double* pdblPosition = NULL;
495
496 getGraphicObjectProperty(_iObjUID, __GO_POSITION__, jni_double_vector, (void **)&pdblPosition);
497
498 if (pdblPosition == NULL)
499 {
500 iListSize = 1;
501 }
502
503 types::TList* pTL = new types::TList();
504 types::String* pStr = new types::String(1, iListSize, pstFieldList);
505
506 pTL->append(pStr);
507
508 if (iListSize > 1)
509 {
510 pTL->append(new types::Double(pdblPosition[0]));
511 pTL->append(new types::Double(pdblPosition[1]));
512 pTL->append(new types::Double(pdblPosition[2]));
513 pTL->append(new types::Double(pdblPosition[3]));
514 }
515
516 if (_pITParent)
517 {
518 types::List* pL = _pITParent->getAs<types::List>();
519 pL->set(_iPos - 1, pTL);
520 }
521
522 return pTL;
523 }
524 /*------------------------------------------------------------------------*/
getCompoundBorder(types::InternalType * _pITParent,int _iPos,int _iObjUID)525 void* getCompoundBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID)
526 {
527 const wchar_t * pstFieldList[] = {L"CompoundBorder", L"outer", L"inner"};
528 int iListSize = 3;
529
530 // properties
531 int iChildBorderOut = 0;
532 int* piChildBorderOut = &iChildBorderOut;
533 int iChildBorderIn = 0;
534 int* piChildBorderIn = &iChildBorderIn;
535
536 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_OUT_BORDER__, jni_int, (void **)&piChildBorderOut);
537 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_IN_BORDER__, jni_int, (void **)&piChildBorderIn);
538
539 if (piChildBorderOut == NULL || piChildBorderIn == NULL)
540 {
541 iListSize = 1;
542 }
543
544 types::TList* pTL = new types::TList();
545 types::String* pStr = new types::String(1, iListSize, pstFieldList);
546
547 pTL->append(pStr);
548
549 if (iListSize > 1)
550 {
551 //get child information and fill current list
552 if (getBorder(pTL, 2, iChildBorderOut) == NULL)
553 {
554 return NULL;
555 }
556
557 if (getBorder(pTL, 3, iChildBorderIn) == NULL)
558 {
559 return NULL;
560 }
561 }
562
563 if (_pITParent)
564 {
565 types::List* pL = _pITParent->getAs<types::List>();
566 pL->set(_iPos - 1, pTL);
567 }
568
569 return pTL;
570 }
571 /*------------------------------------------------------------------------*/
getMatteBorder(types::InternalType * _pITParent,int _iPos,int _iObjUID)572 void* getMatteBorder(types::InternalType* _pITParent, int _iPos, int _iObjUID)
573 {
574 const wchar_t * pstFieldList[] = {L"MatteBorder", L"top", L"left", L"bottom", L"right", L"color"};
575 int iListSize = 6;
576
577 // properties
578 double* pdblPosition = NULL;
579 char* pstColor = NULL;
580
581 getGraphicObjectProperty(_iObjUID, __GO_POSITION__, jni_double_vector, (void **)&pdblPosition);
582 getGraphicObjectProperty(_iObjUID, __GO_UI_FRAME_BORDER_COLOR__, jni_string, (void **)&pstColor);
583
584 types::TList* pTL = new types::TList();
585 types::String* pStr = new types::String(1, iListSize, pstFieldList);
586
587 pTL->append(pStr);
588 pTL->append(new types::Double(pdblPosition[0]));
589 pTL->append(new types::Double(pdblPosition[1]));
590 pTL->append(new types::Double(pdblPosition[2]));
591 pTL->append(new types::Double(pdblPosition[3]));
592 pTL->append(new types::String(pstColor));
593
594 if (_pITParent)
595 {
596 types::List* pL = _pITParent->getAs<types::List>();
597 pL->set(_iPos - 1, pTL);
598 }
599
600 return pTL;
601 }
602 /*------------------------------------------------------------------------*/
603