Thu, 11 Dec 2025 20:07:16 +0100
remove window data arg
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
4 | * Copyright 2024 Olaf Wintermann. All rights reserved. |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
29 | #import "window.h" |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
31 | #import "MainWindow.h" |
|
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
32 | #import "WindowManager.h" |
|
864
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
33 | #import "BoxContainer.h" |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
34 | #import "EventData.h" |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
570
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
36 | #import <objc/runtime.h> |
|
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
37 | |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
38 | #include "../ui/window.h" |
|
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
39 | #include "../ui/properties.h" |
|
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
40 | #include "../common/context.h" |
|
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
41 | #include "../common/menu.h" |
|
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
42 | #include "../common/toolbar.h" |
|
851
367b2bbbc07e
add tabview (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
832
diff
changeset
|
43 | #include "../common/object.h" |
|
14
e2fd132ab781
added menu item lists (Cocoa implementation)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
10
diff
changeset
|
44 | |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
45 | #include <cx/mempool.h> |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
|
869
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
47 | static int window_default_width = 650; |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
48 | static int window_default_height = 550; |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
49 | |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
50 | static int splitview_window_default_pos = -1; |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
51 | static UiBool splitview_window_use_prop = TRUE; |
|
570
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
52 | |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
53 | static UiObject* create_window(const char *title, BOOL simple, BOOL sidebar, BOOL splitview) { |
|
851
367b2bbbc07e
add tabview (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
832
diff
changeset
|
54 | UiObject *obj = uic_object_new_toplevel(); |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
56 | MainWindow *window = [[MainWindow alloc] init:obj withSidebar:sidebar withSplitview:splitview]; |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
57 | [[WindowManager sharedWindowManager] addWindow:window]; |
|
832
7adbd6b7bf7c
enable vertical scrollbar in the sourcelist (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
811
diff
changeset
|
58 | window.releasedWhenClosed = false; // TODO: we still need a cleanup strategy |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
60 | obj->wobj = (__bridge void*)window; |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | |
|
570
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
62 | MainWindowController *controller = [[MainWindowController alloc] initWithWindow:obj window:window]; |
|
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
63 | window.windowController = controller; |
|
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
64 | [window setNextResponder:(NSResponder*)controller]; |
|
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
65 | objc_setAssociatedObject(window, "windowcontroller", controller, OBJC_ASSOCIATION_RETAIN); |
|
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
66 | |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | return obj; |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | } |
|
28
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
69 | |
|
986
6f7600c2b9e1
remove window data arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
70 | UiObject* ui_window(const char *title) { |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
71 | UiObject *obj = create_window(title, FALSE, FALSE, FALSE); |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
72 | return obj; |
|
47
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
73 | } |
|
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
74 | |
|
986
6f7600c2b9e1
remove window data arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
75 | UiObject* ui_simple_window(const char *title) { |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
76 | UiObject *obj = create_window(title, TRUE, FALSE, FALSE); |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
77 | return obj; |
|
28
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
78 | } |
|
724
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
79 | |
|
986
6f7600c2b9e1
remove window data arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
870
diff
changeset
|
80 | UiObject* ui_sidebar_window(const char *title) { |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
81 | UiObject *obj = create_window(title, FALSE, TRUE, FALSE); |
|
751
41286f7f8433
implement sidebar window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
750
diff
changeset
|
82 | return obj; |
|
41286f7f8433
implement sidebar window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
750
diff
changeset
|
83 | } |
|
724
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
84 | |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
85 | UiObject* ui_splitview_window(const char *title, UiBool sidebar) { |
| 870 | 86 | sleep(1); |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
87 | return create_window(title, FALSE, sidebar, TRUE); |
|
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
88 | } |
|
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
89 | |
|
869
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
90 | void ui_window_size(UiObject *obj, int width, int height) { |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
91 | // TODO |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
92 | } |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
93 | |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
94 | void ui_window_default_size(int width, int height) { |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
95 | window_default_width = width; |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
96 | window_default_height = height; |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
97 | } |
|
6b7a178cff7c
add some missing functions (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
864
diff
changeset
|
98 | |
|
724
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
99 | /* --------------------------------- File Dialogs --------------------------------- */ |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
100 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
101 | void ui_openfiledialog(UiObject *obj, unsigned int mode, ui_callback file_selected_callback, void *cbdata) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
102 | NSOpenPanel *openPanel = [NSOpenPanel openPanel]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
103 | if((mode & UI_FILEDIALOG_SELECT_MULTI) == UI_FILEDIALOG_SELECT_MULTI) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
104 | openPanel.allowsMultipleSelection = YES; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
105 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
106 | if((mode & UI_FILEDIALOG_SELECT_FOLDER) == UI_FILEDIALOG_SELECT_FOLDER) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
107 | openPanel.canChooseFiles = NO; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
108 | openPanel.canChooseDirectories = YES; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
109 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
110 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
111 | NSWindow *window = (__bridge NSWindow*)obj->wobj; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
112 | [openPanel beginSheetModalForWindow:window completionHandler:^(NSModalResponse result) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
113 | UiEvent event; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
114 | event.obj = obj; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
115 | event.window = obj->window; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
116 | event.document = obj->ctx->document; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
117 | event.intval = 0; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
118 | event.set = 0; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
119 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
120 | UiFileList flist = { NULL, 0 }; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
121 | event.eventdata = &flist; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
122 | event.eventdatatype = UI_EVENT_DATA_FILE_LIST; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
123 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
124 | if(result == NSModalResponseOK) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
125 | NSArray<NSURL *> *urls = [openPanel URLs]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
126 | flist.files = calloc(urls.count, sizeof(char*)); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
127 | for(NSURL *url in urls) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
128 | if([url isFileURL]) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
129 | flist.files[flist.nfiles++] = strdup(url.path.UTF8String); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
130 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
131 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
132 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
133 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
134 | if(file_selected_callback) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
135 | file_selected_callback(&event, cbdata); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
136 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
137 | ui_filelist_free(flist); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
138 | }]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
139 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
140 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
141 | void ui_savefiledialog(UiObject *obj, const char *name, ui_callback file_selected_callback, void *cbdata) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
142 | NSSavePanel *savePanel = [NSSavePanel savePanel]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
143 | if(name) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
144 | NSString *nameStr = [[NSString alloc] initWithUTF8String:name]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
145 | [savePanel setNameFieldStringValue: nameStr]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
146 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
147 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
148 | NSWindow *window = (__bridge NSWindow*)obj->wobj; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
149 | [savePanel beginSheetModalForWindow:window completionHandler:^(NSModalResponse result) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
150 | UiEvent event; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
151 | event.obj = obj; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
152 | event.window = obj->window; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
153 | event.document = obj->ctx->document; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
154 | event.intval = 0; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
155 | event.set = 0; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
156 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
157 | UiFileList flist = { NULL, 0 }; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
158 | event.eventdata = &flist; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
159 | event.eventdatatype = UI_EVENT_DATA_FILE_LIST; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
160 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
161 | if(result == NSModalResponseOK) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
162 | NSURL *url = [savePanel URL]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
163 | if([url isFileURL]) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
164 | NSString *path = url.path; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
165 | flist.files = malloc(sizeof(char*)); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
166 | flist.files[0] = strdup(path.UTF8String); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
167 | flist.nfiles = 1; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
168 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
169 | file_selected_callback(NULL, NULL); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
170 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
171 | if(file_selected_callback) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
172 | file_selected_callback(&event, cbdata); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
173 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
174 | ui_filelist_free(flist); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
175 | }]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
176 | } |
|
750
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
177 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
178 | /* ------------------------------------- Dialog ------------------------------------- */ |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
179 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
180 | void ui_dialog_create(UiObject *parent, UiDialogArgs *args) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
181 | NSAlert *dialog = [[NSAlert alloc] init]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
182 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
183 | if(args->title) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
184 | dialog.messageText = [[NSString alloc]initWithUTF8String:args->title]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
185 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
186 | if(args->content) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
187 | dialog.informativeText = [[NSString alloc]initWithUTF8String:args->content]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
188 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
189 | NSTextField *textfield = nil; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
190 | if(args->input) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
191 | NSRect frame = NSMakeRect(0,0,300,22); |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
192 | textfield = args->password ? [[NSSecureTextField alloc] initWithFrame:frame] : [[NSTextField alloc]initWithFrame:frame]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
193 | if(args->input_value) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
194 | textfield.stringValue = [[NSString alloc]initWithUTF8String:args->input_value]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
195 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
196 | dialog.accessoryView = textfield; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
197 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
198 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
199 | int b = 0; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
200 | int b1 = -1; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
201 | int b2 = -1; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
202 | if(args->button1_label) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
203 | [dialog addButtonWithTitle:[[NSString alloc]initWithUTF8String:args->button1_label]]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
204 | b1 = b++; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
205 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
206 | if(args->button2_label) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
207 | [dialog addButtonWithTitle:[[NSString alloc]initWithUTF8String:args->button2_label]]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
208 | b2 = b; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
209 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
210 | if(args->closebutton_label) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
211 | [dialog addButtonWithTitle:[[NSString alloc]initWithUTF8String:args->closebutton_label]]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
212 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
213 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
214 | ui_callback callback = args->result; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
215 | void *userdata = args->resultdata; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
216 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
217 | NSWindow *window = (__bridge NSWindow*)parent->wobj; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
218 | [dialog beginSheetModalForWindow:window completionHandler:^(NSModalResponse returnCode) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
219 | UiEvent event; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
220 | event.obj = parent; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
221 | event.window = event.obj->window; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
222 | event.document = event.obj->ctx->document; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
223 | event.eventdata = NULL; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
224 | event.eventdatatype = 0; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
225 | event.set = 0; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
226 | event.intval = 0; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
227 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
228 | long ret = returnCode - NSAlertFirstButtonReturn; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
229 | if(ret == b1) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
230 | event.intval = 1; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
231 | } else if(ret == b2) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
232 | event.intval = 2; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
233 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
234 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
235 | NSString *value = nil; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
236 | if(textfield) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
237 | value = textfield.stringValue; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
238 | event.eventdata = (void*)value.UTF8String; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
239 | event.eventdatatype = UI_EVENT_DATA_STRING; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
240 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
241 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
242 | if(callback) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
243 | callback(&event, userdata); |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
244 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
245 | }]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
246 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
247 | } |
|
864
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
248 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
249 | /* ------------------------------------- Dialog Window ------------------------------------- */ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
250 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
251 | @implementation UiDialogWindow |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
252 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
253 | - (BOOL) getIsVisible { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
254 | return self.isVisible; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
255 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
256 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
257 | - (void) setVisible:(BOOL)visible { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
258 | //[self makeKeyAndOrderFront:nil]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
259 | if(visible) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
260 | [_parent beginSheet:self completionHandler:^(NSModalResponse returnCode) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
261 | // TODO: close event |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
262 | }]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
263 | } else { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
264 | [self.sheetParent endSheet:self returnCode:NSModalResponseCancel]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
265 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
266 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
267 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
268 | - (void)cancelOperation:(id)sender { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
269 | [self.sheetParent endSheet:self returnCode:NSModalResponseCancel]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
270 | // TODO: close event |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
271 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
272 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
273 | @end |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
274 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
275 | UiObject *ui_dialog_window_create(UiObject *parent, UiDialogWindowArgs *args) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
276 | UiObject *obj = uic_object_new_toplevel(); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
277 | UiDialogWindow *panel = [[UiDialogWindow alloc] initWithContentRect:NSMakeRect(0, 0, args->width, args->height) |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
278 | styleMask:(NSWindowStyleMaskTitled | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
279 | NSWindowStyleMaskClosable | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
280 | NSWindowStyleMaskResizable | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
281 | NSWindowStyleMaskUtilityWindow) |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
282 | backing:NSBackingStoreBuffered |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
283 | defer:NO]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
284 | panel.parent = (__bridge NSWindow*)parent->wobj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
285 | panel.obj = obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
286 | panel.modal = args->modal; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
287 | panel.onclick = args->onclick; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
288 | panel.onclickdata = args->onclickdata; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
289 | [panel center]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
290 | [[WindowManager sharedWindowManager] addWindow:panel]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
291 | obj->wobj = (__bridge void*)panel; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
292 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
293 | NSView *content = panel.contentView; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
294 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
295 | // Create a view for the dialog window buttons (lbutton1, lbutton2, rbutton3, rbutton4) |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
296 | NSView *buttonArea = [[NSView alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
297 | buttonArea.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
298 | [content addSubview:buttonArea]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
299 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
300 | [buttonArea.bottomAnchor constraintEqualToAnchor:content.bottomAnchor constant:-10], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
301 | [buttonArea.leadingAnchor constraintEqualToAnchor:content.leadingAnchor constant:10], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
302 | [buttonArea.trailingAnchor constraintEqualToAnchor:content.trailingAnchor constant:-10], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
303 | [buttonArea.heightAnchor constraintEqualToConstant:20] |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
304 | ]]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
305 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
306 | NSButton *lbutton1 = nil; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
307 | if(args->lbutton1) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
308 | lbutton1 = [[NSButton alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
309 | lbutton1.title = [[NSString alloc]initWithUTF8String:args->lbutton1]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
310 | lbutton1.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
311 | [buttonArea addSubview:lbutton1]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
312 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
313 | [lbutton1.topAnchor constraintEqualToAnchor:buttonArea.topAnchor constant:0], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
314 | [lbutton1.leadingAnchor constraintEqualToAnchor:buttonArea.leadingAnchor constant:0] |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
315 | ]]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
316 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
317 | EventData *event = [[EventData alloc] init:args->onclick userdata:args->onclickdata]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
318 | event.obj = obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
319 | event.value = 1; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
320 | lbutton1.target = event; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
321 | lbutton1.action = @selector(handleEvent:); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
322 | objc_setAssociatedObject(lbutton1, "eventdata", event, OBJC_ASSOCIATION_RETAIN); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
323 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
324 | NSButton *lbutton2 = nil; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
325 | if(args->lbutton2) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
326 | lbutton2 = [[NSButton alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
327 | lbutton2.title = [[NSString alloc]initWithUTF8String:args->lbutton2]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
328 | lbutton2.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
329 | [buttonArea addSubview:lbutton2]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
330 | NSLayoutXAxisAnchor *anchor = lbutton1 != nil ? lbutton1.trailingAnchor : buttonArea.leadingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
331 | int off = lbutton1 != nil ? 4 : 0; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
332 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
333 | [lbutton2.topAnchor constraintEqualToAnchor:buttonArea.topAnchor constant:0], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
334 | [lbutton2.leadingAnchor constraintEqualToAnchor:anchor constant:off] |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
335 | ]]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
336 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
337 | EventData *event = [[EventData alloc] init:args->onclick userdata:args->onclickdata]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
338 | event.obj = obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
339 | event.value = 2; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
340 | lbutton2.target = event; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
341 | lbutton2.action = @selector(handleEvent:); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
342 | objc_setAssociatedObject(lbutton2, "eventdata", event, OBJC_ASSOCIATION_RETAIN); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
343 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
344 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
345 | NSButton *rbutton4 = nil; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
346 | if(args->rbutton4) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
347 | rbutton4 = [[NSButton alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
348 | rbutton4.title = [[NSString alloc]initWithUTF8String:args->rbutton4]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
349 | rbutton4.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
350 | [buttonArea addSubview:rbutton4]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
351 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
352 | [rbutton4.topAnchor constraintEqualToAnchor:buttonArea.topAnchor constant:0], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
353 | [rbutton4.trailingAnchor constraintEqualToAnchor:buttonArea.trailingAnchor constant:0] |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
354 | ]]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
355 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
356 | EventData *event = [[EventData alloc] init:args->onclick userdata:args->onclickdata]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
357 | event.obj = obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
358 | event.value = 2; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
359 | rbutton4.target = event; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
360 | rbutton4.action = @selector(handleEvent:); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
361 | objc_setAssociatedObject(rbutton4, "eventdata", event, OBJC_ASSOCIATION_RETAIN); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
362 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
363 | NSButton *rbutton3 = nil; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
364 | if(args->rbutton3) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
365 | rbutton3 = [[NSButton alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
366 | rbutton3.title = [[NSString alloc]initWithUTF8String:args->rbutton3]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
367 | rbutton3.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
368 | [buttonArea addSubview:rbutton3]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
369 | NSLayoutXAxisAnchor *anchor = rbutton4 != nil ? rbutton4.leadingAnchor : buttonArea.trailingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
370 | int off = rbutton4 != nil ? -4 : 0; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
371 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
372 | [rbutton3.topAnchor constraintEqualToAnchor:buttonArea.topAnchor constant:0], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
373 | [rbutton3.trailingAnchor constraintEqualToAnchor:anchor constant:off] |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
374 | ]]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
375 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
376 | EventData *event = [[EventData alloc] init:args->onclick userdata:args->onclickdata]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
377 | event.obj = obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
378 | event.value = 2; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
379 | rbutton3.target = event; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
380 | rbutton3.action = @selector(handleEvent:); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
381 | objc_setAssociatedObject(rbutton3, "eventdata", event, OBJC_ASSOCIATION_RETAIN); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
382 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
383 | switch(args->default_button) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
384 | default: break; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
385 | case 1: if(lbutton1 != nil) lbutton1.keyEquivalent = @"\r"; break; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
386 | case 2: if(lbutton2 != nil) lbutton2.keyEquivalent = @"\r"; break; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
387 | case 3: if(rbutton3 != nil) rbutton3.keyEquivalent = @"\r"; break; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
388 | case 4: if(rbutton4 != nil) rbutton4.keyEquivalent = @"\r"; break; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
389 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
390 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
391 | // space between left and right buttons |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
392 | NSView *space = [[NSView alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
393 | space.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
394 | [buttonArea addSubview:space]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
395 | NSLayoutXAxisAnchor *leftAnchor = buttonArea.leadingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
396 | NSLayoutXAxisAnchor *rightAnchor = buttonArea.trailingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
397 | if(lbutton2 != nil) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
398 | leftAnchor = lbutton2.trailingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
399 | } else if(lbutton1 != nil) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
400 | leftAnchor = lbutton1.trailingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
401 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
402 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
403 | if(rbutton3 != nil) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
404 | rightAnchor = rbutton3.leadingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
405 | } else if(rbutton4 != nil) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
406 | rightAnchor = rbutton4.leadingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
407 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
408 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
409 | [space.topAnchor constraintEqualToAnchor:buttonArea.topAnchor], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
410 | [space.leadingAnchor constraintEqualToAnchor:leftAnchor constant:10], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
411 | [space.trailingAnchor constraintEqualToAnchor:rightAnchor constant:-10] |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
412 | ]]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
413 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
414 | // dialog window main content |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
415 | BoxContainer *vbox = [[BoxContainer alloc] init:NSUserInterfaceLayoutOrientationVertical spacing:0]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
416 | vbox.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
417 | [content addSubview:vbox]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
418 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
419 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
420 | [vbox.topAnchor constraintEqualToAnchor:content.topAnchor constant:0], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
421 | [vbox.leadingAnchor constraintEqualToAnchor:content.leadingAnchor], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
422 | [vbox.trailingAnchor constraintEqualToAnchor:content.trailingAnchor], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
423 | [vbox.bottomAnchor constraintEqualToAnchor:buttonArea.topAnchor constant:0] |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
424 | ]]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
425 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
426 | UiContainerX *container = ui_create_container(obj, vbox); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
427 | vbox.container = container; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
428 | uic_object_push_container(obj, container); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
429 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
430 | return obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
431 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
432 |