-
Notifications
You must be signed in to change notification settings - Fork 10
/
GSMarkupTagCappuccinoAdditions.j
582 lines (485 loc) · 16.1 KB
/
GSMarkupTagCappuccinoAdditions.j
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
@import "GSMarkupTagView.j"
@implementation GSMarkupTagFlashView : GSMarkupTagView
+ (CPString) tagName
{
return @"flashView";
}
+ (Class) platformObjectClass
{
return [CPFlashView class];
}
- (id) initPlatformObject: (id)platformObject
{ platformObject = [super initPlatformObject: platformObject];
var name = [_attributes objectForKey: @"ressource"];
if (name != nil)
{ [platformObject setFlashMovie: [CPFlashMovie flashMovieWithFile: [CPString stringWithFormat:@"%@/%@", [[CPBundle mainBundle] resourcePath], name ]] ];
}
return platformObject;
}
@end
@implementation GSMarkupTagLevelIndicator : GSMarkupTagControl
+ (CPString) tagName
{
return @"levelIndicator";
}
+ (Class) platformObjectClass
{
return [CPLevelIndicator class];
}
- (id) initPlatformObject: (id)platformObject
{ platformObject = [super initPlatformObject: platformObject];
var min;
var max;
var warning;
var critical;
var current;
min = [_attributes objectForKey: @"min"];
if (min != nil)
{ [platformObject setMinValue: [min doubleValue]];
}
max = [_attributes objectForKey: @"max"];
if (max != nil)
{ [platformObject setMaxValue: [max doubleValue]];
}
warning = [_attributes objectForKey: @"warning"];
if (warning != nil)
{ [platformObject setWarningValue: [warning doubleValue]];
}
critical = [_attributes objectForKey: @"critical"];
if (critical != nil)
{ [platformObject setCriticalValue: [critical doubleValue]];
}
/* minimum size is 83x17*/
var height;
height = [_attributes objectForKey: @"height"];
if (height == nil)
{
[_attributes setObject: @"25" forKey: @"height"];
}
var width;
width = [_attributes objectForKey: @"width"];
if (width == nil)
{ [_attributes setObject: @"250" forKey: @"width"];
}
return platformObject;
}
@end
@implementation GSMarkupTagStepper : GSMarkupTagLevelIndicator
+ (CPString) tagName
{
return @"stepper";
}
+ (Class) platformObjectClass
{
return [CPStepper class];
}
@end
//<!> fixme: only small spinner is currently supported
@implementation GSMarkupTagProgresIndicator : GSMarkupTagLevelIndicator
+ (CPString) tagName
{
return @"progresIndicator";
}
+ (Class) platformObjectClass
{
return [CPProgressIndicator class];
}
- (id) initPlatformObject: (id)platformObject
{ platformObject = [super initPlatformObject: platformObject];
var current;
if([_attributes objectForKey:"style"] == 'Bar')
{ [platformObject setDisplayedWhenStopped: YES];
[platformObject setStyle: CPProgressIndicatorBarStyle];
[_attributes setObject: @"20" forKey: @"height"];
}
else
{ [platformObject setDisplayedWhenStopped:NO];
[platformObject setStyle:CPProgressIndicatorSpinningStyle];
[platformObject setIndeterminate:YES];
[platformObject setControlSize:CPMiniControlSize];
[_attributes setObject: @"16" forKey: @"height"];
[_attributes setObject: @"16" forKey: @"width"];
}
return platformObject;
}
@end
@implementation GSMarkupTagTabViewItem : GSMarkupTagObject
+ (CPString) tagName
{
return @"tabViewItem";
}
+ (Class) platformObjectClass
{
return nil;
}
-(CPString) title
{ return [_attributes objectForKey:"title"];
}
- (id) initPlatformObject: (id)platformObject
{ platformObject=[[CPTabViewItem alloc] initWithIdentifier: [self title] ];
return platformObject;
}
@end
@import <AppKit/CPTabView.j>
@implementation GSMarkupTagTabView : GSMarkupTagView
+ (CPString) tagName
{
return @"tabView";
}
+ (Class) platformObjectClass
{
return [CPTabView class];
}
-(int) type
{ if([_attributes objectForKey: "type"]=="topBezel") return CPTopTabsBezelBorder;
return CPNoTabsBezelBorder;
}
- (id) initPlatformObject: (id)platformObject
{ platformObject = [super initPlatformObject: platformObject];
[platformObject setTabViewType: [self type]];
[platformObject._box setBorderType:CPLineBorder];
[platformObject._box setBoxType:CPBoxCustom];
var i, count = _content? _content.length:0;
for (i = 0 ; i < count; i++)
{ var item = [_content[i] platformObject];
[item setView: [[_content[i] content][0] platformObject] ];
[item setLabel: [_content[i] title] ];
[platformObject addTabViewItem: item];
}
return platformObject;
}
@end
@implementation CPTabView(AutoLayoutDefaults)
- (GSAutoLayoutAlignment) autolayoutDefaultVerticalAlignment
{ return GSAutoLayoutExpand;
}
- (GSAutoLayoutAlignment) autolayoutDefaultHorizontalAlignment
{ return GSAutoLayoutExpand;
}
@end
@import "GSMarkupTagControl.j"
@implementation GSMarkupTagCheckBox : GSMarkupTagControl
+ (CPString) tagName
{
return @"checkBox";
}
+ (Class) platformObjectClass
{
return [CPCheckBox class];
}
- (id) initPlatformObject: (id)platformObject
{
platformObject = [super initPlatformObject: platformObject];
[platformObject setTitle: [_attributes objectForKey:"title"] ];
[platformObject setHighlightsBy:CPContentsCellMask];
[platformObject setShowsStateBy:CPContentsCellMask];
return platformObject;
}
@end
@import <AppKit/CPCollectionView.j>
@implementation CPCollectionView(KVB)
-(void) setObjectValue: someArray
{ [self setContent: someArray];
}
-(CPArray) value
{ return [self content];
}
-(void) setValue:(CPArray) someArray
{ return [self setObjectValue: someArray];
}
- (GSAutoLayoutAlignment) autolayoutDefaultVerticalAlignment
{ return GSAutoLayoutExpand;
}
- (GSAutoLayoutAlignment) autolayoutDefaultHorizontalAlignment
{ return GSAutoLayoutExpand;
}
@end
@implementation GSMarkupTagCollectionView : GSMarkupTagView
+ (CPString) tagName
{
return @"collectionView";
}
+ (Class) platformObjectClass
{
return [CPCollectionView class];
}
- (id) initPlatformObject: (id)platformObject
{ platformObject = [super initPlatformObject: platformObject];
[platformObject setSelectable: [self boolValueForAttribute:"selectable"]==1 ];
[platformObject setAllowsEmptySelection: [self boolValueForAttribute:"emptySelectionAllowed"]==1 ];
[platformObject setAllowsMultipleSelection: [self boolValueForAttribute:"multipleSelectionAllowed"]!=0 ];
[platformObject setMaxNumberOfRows: [self intValueForAttribute:"maxRows"] ];
[platformObject setMaxNumberOfColumns: [self intValueForAttribute:"maxColumns"] ];
var width=[self intValueForAttribute:"itemWidth"];
var height=[self intValueForAttribute:"itemHeight"];
if(width && height)
{ var mysize=CPMakeSize(width,height);
[platformObject setMinItemSize: mysize ];
[platformObject setMaxItemSize: mysize ];
}
var width=[self intValueForAttribute:"minItemWidth"];
var height=[self intValueForAttribute:"minItemHeight"];
if(width && height)
{ [platformObject setMinItemSize: CPMakeSize(width,height) ];
}
var width=[self intValueForAttribute:"maxItemWidth"];
var height=[self intValueForAttribute:"maxItemHeight"];
if(width && height)
{ [platformObject setMaxItemSize: CPMakeSize(width,height) ];
}
var protoClass=CPClassFromString([self stringValueForAttribute:"itemsClassName"]);
if(!protoClass) protoClass=[CPCollectionViewItem class];
var proto=[protoClass new];
[platformObject setItemPrototype: proto];
return platformObject;
}
- (id) postInitPlatformObject: (id)platformObject
{ platformObject=[super postInitPlatformObject: platformObject];
[platformObject tile];
return platformObject;
}
@end
@import <AppKit/CPButtonBar.j>
@implementation GSMarkupTagButtonBar : GSMarkupTagView
+ (CPString) tagName
{
return @"ButtonBar";
}
+ (Class) platformObjectClass
{
return [CPButtonBar class];
}
- (id) initPlatformObject: (id)platformObject
{ [_attributes setObject: @"24" forKey: @"height"];
platformObject = [super initPlatformObject: platformObject];
[platformObject setHasResizeControl: [self boolValueForAttribute:"resizable"]==1 ];
var buttons=[];
var peek;
if(peek=[self stringValueForAttribute:"plusButtonAction"] )
{ var button=[CPButtonBar plusButton];
[button setAction: CPSelectorFromString (peek)];
[buttons addObject: button];
}
if(peek=[self stringValueForAttribute:"minusButtonAction"] )
{ var button=[CPButtonBar minusButton];
[button setAction: CPSelectorFromString (peek)];
[buttons addObject: button];
}
if([self boolValueForAttribute:"actionsButton"]==1)
{ var actionButton;
[buttons addObject:actionButton=[CPButtonBar actionPopupButton] ];
var i, count = [_content count];
for (i = 0; i < count; i++)
{ var item = [_content objectAtIndex: i];
var title = [item localizedStringValueForAttribute: @"title"];
if (title == nil) title = @"";
[actionButton addItemWithTitle: title];
var platformItem = [actionButton lastItem];
platformItem = [item initPlatformObject: platformItem]; // load additional attributes into the init platform object
[item setPlatformObject:platformItem];
var peek;
if (peek = [[item attributes] objectForKey: "enabledBinding"])
{
debugger
var r = [peek rangeOfString: @"."];
var objectName = [peek substringToIndex:r.location];
var target = [[CPBundle sharedGSMarkupDecoder] _getObjectForIdString:objectName];
var keyValuePath = [peek substringFromIndex:CPMaxRange(r)];
var binding = CPEnabledBinding;
var options = nil;
[platformItem bind:binding toObject:target withKeyPath:keyValuePath options:options];
}
}
}
[platformObject setButtons: buttons ];
return platformObject;
}
@end
@implementation CPButtonBar(RennaissanceAdditions)
-(void) setTarget: someTarget
{ [[self buttons] makeObjectsPerformSelector:@selector(setTarget:) withObject: someTarget];
}
- (GSAutoLayoutAlignment) autolayoutDefaultHorizontalAlignment
{ return GSAutoLayoutExpand;
}
@end
@import <AppKit/CPTokenField.j>
@implementation GSMarkupTagTokenField : GSMarkupTagTextField
+ (CPString) tagName
{
return @"tokenField";
}
+ (Class) platformObjectClass
{ return [CPTokenField class];
}
- (id) initPlatformObject: (id)platformObject
{ platformObject = [super initPlatformObject: platformObject];
[_attributes setObject: @"29" forKey: @"height"];
peek=[self stringValueForAttribute:"tokenSeparators"];
if (!peek) peek=" ";
[platformObject setTokenizingCharacterSet:[CPCharacterSet characterSetWithCharactersInString: peek]];
return platformObject;
}
@end
@implementation GSMarkupTagSwitchButton: GSMarkupTagButton
- (id) initPlatformObject: (id)platformObject
{ platformObject = [super initPlatformObject: platformObject];
[platformObject setHighlightsBy:CPContentsCellMask];
[platformObject setShowsStateBy:CPContentsCellMask];
[platformObject setObjectValue:[self boolValueForAttribute:"selected"]==1 ];
return platformObject;
}
+ (CPString) tagName
{
return @"switchButton";
}
+ (Class) platformObjectClass
{ return [CPCheckBox class];
}
@end
@implementation GSMarkupTagPredicate : GSMarkupTagObject
+ (CPString) tagName
{ return @"predicate";
}
+ (Class) platformObjectClass
{ return nil;
}
- (id) initPlatformObject: (id)platformObject
{ platformObject=[CPPredicate predicateWithFormat: [_attributes objectForKey:"format"] argumentArray: nil ];
return platformObject;
}
@end
@implementation GSMarkupTagDatePicker: GSMarkupTagControl
+ (CPString) tagName
{
return @"datePicker";
}
+ (Class) platformObjectClass
{ return [CPDatePicker class];
}
- (id) initPlatformObject: (id)platformObject
{
platformObject = [super initPlatformObject: platformObject];
[platformObject setLocale:[[CPLocale alloc] initWithLocaleIdentifier:@"de_DE"]]; //<!> fixme
var styleString = [_attributes objectForKey: @"style"];
if(styleString === 'textual')
{ [platformObject setDatePickerStyle: CPTextFieldAndStepperDatePickerStyle];
[_attributes setObject: @"120" forKey: @"width"];
[_attributes setObject: @"29" forKey: @"height"];
var elements = CPYearMonthDayDatePickerElementFlag;
if ([self boolValueForAttribute: @"hm"] == 1)
{ elements |= CPHourMinuteDatePickerElementFlag;
[_attributes setObject: @"160" forKey: @"width"];
}
[platformObject setDatePickerElements:elements];
}
else if(styleString === 'graphical')
{ [platformObject setDatePickerStyle: CPClockAndCalendarDatePickerStyle];
[platformObject setDatePickerElements: CPYearMonthDatePickerElementFlag]
[_attributes setObject: @"150" forKey: @"width"];
[_attributes setObject: @"150" forKey: @"height"];
var c = [self colorValueForAttribute: @"backgroundColor"] || [CPColor whiteColor];
[platformObject setBackgroundColor:c];
}
return platformObject;
}
- (id) postInitPlatformObject: (id)platformObject
{ platformObject=[super postInitPlatformObject: platformObject];
[platformObject _init];
return platformObject;
}
@end
@implementation FSObservableSegmentedControl:CPSegmentedControl
-(void) setSegments:(CPArray) anArray
{ var info=[CPBinder infoForBinding: "segments" forObject: self];
var tagArray;
if(info) // this stuff is to allow row-wise filtered popup-lists in table-views
{ var options= [info objectForKey: CPOptionsKey];
var ac= [info objectForKey: CPObservedObjectKey];
var mykey=[info objectForKey: CPObservedKeyPathKey];
var dotIndex = mykey.lastIndexOf("."),
mykey=[mykey substringFromIndex: dotIndex+1];
var myvalkey=[options objectForKey: "valueFace"];
if(myvalkey)
{ dotIndex = myvalkey.lastIndexOf("."),
myvalkey=[myvalkey substringFromIndex: dotIndex+1];
}
var sourceArray=[ac arrangedObjects];
someArray=[];
tagArray=[];
var i, l = [sourceArray count];
for (i = 0; i < l; i++)
{ var curr_obj= [sourceArray objectAtIndex:i];
someArray.push([curr_obj valueForKey: mykey]);
if(myvalkey) tagArray.push([curr_obj valueForKey: myvalkey]);
}
}
var j, l1 = someArray.length;
[self setSegmentCount: l1];
for (j = 0; j < l1; j++)
{ [self setLabel:someArray[j] forSegment: j];
if(tagArray) [self setTag: tagArray[j] forSegment: j];
}
[self setSelectedSegment:0]; // FIXME
}
- (void)setSelected:(BOOL)isSelected forSegment:(unsigned)aSegment
{
[self willChangeValueForKey:"selectedSegment"];
[super setSelected:isSelected forSegment:aSegment];
[self didChangeValueForKey:"selectedSegment"];
}
@end
@implementation GSMarkupTagSegmentedControl: GSMarkupTagControl
+ (CPString) tagName
{
return @"segmentedControl";
}
+ (Class) platformObjectClass
{ return [FSObservableSegmentedControl class];
}
- (id) initPlatformObject: (id)platformObject
{ [_attributes setObject: @"25" forKey: @"height"];
platformObject = [super initPlatformObject: platformObject];
var i, peek, count = [_content count];
[platformObject setSegmentCount: count];
for (i = 0; i < count; i++)
{ var item = [_content objectAtIndex: i];
var title = [item localizedStringValueForAttribute: @"title"];
if (title == nil) title = @"";
[platformObject setLabel: title forSegment: i];
[platformObject setTag: [item intValueForAttribute: @"tag"] forSegment: i];
if(peek=[self intValueForAttribute:"width"]) [platformObject setWidth: peek forSegment:i];
if([item boolValueForAttribute:"selected"] == 1) [platformObject setSelected:YES forSegment:i];
}
return platformObject;
}
@end
@implementation GSMarkupTagSegmentedControlItem: GSMarkupTagObject
+ (CPString) tagName
{
return @"segmentedControlItem";
}
@end
@implementation GSMarkupTagWebView: GSMarkupTagView
+ (CPString) tagName
{
return @"webView";
}
+ (Class) platformObjectClass
{ return [CPWebView class];
}
- (id) initPlatformObject: (id)platformObject
{
platformObject = [super initPlatformObject: platformObject];
var count = [_content count];
if (count > 0)
{
var s = [_content objectAtIndex: 0];
if (s != nil && [s isKindOfClass: [CPString class]])
{
[platformObject loadHTMLString:s];
}
}
return platformObject;
}
@end