| |
1 /* |
| |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| |
3 * |
| |
4 * Copyright 2025 Olaf Wintermann. All rights reserved. |
| |
5 * |
| |
6 * Redistribution and use in source and binary forms, with or without |
| |
7 * modification, are permitted provided that the following conditions are met: |
| |
8 * |
| |
9 * 1. Redistributions of source code must retain the above copyright |
| |
10 * notice, this list of conditions and the following disclaimer. |
| |
11 * |
| |
12 * 2. Redistributions in binary form must reproduce the above copyright |
| |
13 * notice, this list of conditions and the following disclaimer in the |
| |
14 * documentation and/or other materials provided with the distribution. |
| |
15 * |
| |
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| |
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| |
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| |
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| |
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| |
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| |
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| |
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| |
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| |
26 * POSSIBILITY OF SUCH DAMAGE. |
| |
27 */ |
| |
28 |
| |
29 #import "Toolbar.h" |
| |
30 |
| |
31 #include "../common/toolbar.h" |
| |
32 |
| |
33 void ui_toolbar_init(void) { |
| |
34 |
| |
35 } |
| |
36 |
| |
37 |
| |
38 |
| |
39 /* --------------------- UiToolbar --------------------- */ |
| |
40 |
| |
41 @implementation UiToolbar |
| |
42 |
| |
43 - (UiToolbar*) initWithObject:(UiObject*)object { |
| |
44 self = [super initWithIdentifier:@"UiToolbar"]; |
| |
45 _obj = object; |
| |
46 |
| |
47 allowedItems = [[NSMutableArray alloc]initWithCapacity:16]; |
| |
48 defaultItems = [[NSMutableArray alloc]initWithCapacity:16]; |
| |
49 |
| |
50 CxMap *toolbarItems = uic_get_toolbar_items(); |
| |
51 CxMapIterator i = cxMapIteratorKeys(toolbarItems); |
| |
52 cx_foreach(CxHashKey *, key, i) { |
| |
53 NSString *s = [[NSString alloc]initWithBytes:key->data length:key->len encoding:NSUTF8StringEncoding]; |
| |
54 [allowedItems addObject:s]; |
| |
55 } |
| |
56 [allowedItems addObject: NSToolbarFlexibleSpaceItemIdentifier]; |
| |
57 [allowedItems addObject: NSToolbarSpaceItemIdentifier]; |
| |
58 |
| |
59 CxList *tbitems[3]; |
| |
60 tbitems[0] = uic_get_toolbar_defaults(UI_TOOLBAR_LEFT); |
| |
61 tbitems[1] = uic_get_toolbar_defaults(UI_TOOLBAR_CENTER); |
| |
62 tbitems[2] = uic_get_toolbar_defaults(UI_TOOLBAR_RIGHT); |
| |
63 for(int t=0;t<3;t++) { |
| |
64 CxIterator iter = cxListIterator(tbitems[t]); |
| |
65 cx_foreach(char *, name, iter) { |
| |
66 NSString *s = [[NSString alloc] initWithUTF8String:name]; |
| |
67 [defaultItems addObject:s]; |
| |
68 } |
| |
69 } |
| |
70 |
| |
71 [self setDelegate:self]; |
| |
72 [self setAllowsUserCustomization:YES]; |
| |
73 return self; |
| |
74 } |
| |
75 |
| |
76 // implementation of NSToolbarDelegate methods |
| |
77 |
| |
78 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar { |
| |
79 return allowedItems; |
| |
80 } |
| |
81 |
| |
82 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar { |
| |
83 return defaultItems; |
| |
84 } |
| |
85 |
| |
86 - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar |
| |
87 itemForItemIdentifier:(NSString *)itemIdentifier |
| |
88 willBeInsertedIntoToolbar:(BOOL)flag { |
| |
89 CxMap *items = uic_get_toolbar_items(); |
| |
90 UiToolbarItemI *item = cxMapGet(items, itemIdentifier.UTF8String); |
| |
91 if(!item) { |
| |
92 return nil; |
| |
93 } |
| |
94 |
| |
95 switch(item->type) { |
| |
96 default: return nil; |
| |
97 case UI_TOOLBAR_ITEM: { |
| |
98 NSToolbarItem *tbItem = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier]; |
| |
99 [tbItem setLabel: @"Test"]; |
| |
100 return tbItem; |
| |
101 break; |
| |
102 } |
| |
103 } |
| |
104 |
| |
105 return nil; |
| |
106 } |
| |
107 |
| |
108 @end |