Sun, 19 Oct 2025 12:08:32 +0200
add dialog window (Cocoa)
|
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 | |
|
570
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
47 | |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
48 | 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
|
49 | UiObject *obj = uic_object_new_toplevel(); |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
51 | 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
|
52 | [[WindowManager sharedWindowManager] addWindow:window]; |
|
832
7adbd6b7bf7c
enable vertical scrollbar in the sourcelist (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
811
diff
changeset
|
53 | window.releasedWhenClosed = false; // TODO: we still need a cleanup strategy |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
55 | obj->wobj = (__bridge void*)window; |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
|
570
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
57 | MainWindowController *controller = [[MainWindowController alloc] initWithWindow:obj window:window]; |
|
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
58 | window.windowController = controller; |
|
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
59 | [window setNextResponder:(NSResponder*)controller]; |
|
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
60 | objc_setAssociatedObject(window, "windowcontroller", controller, OBJC_ASSOCIATION_RETAIN); |
|
a2df724b4cb9
implement toggle menu items (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
471
diff
changeset
|
61 | |
|
7
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | return obj; |
|
431dde3c5fbe
added Cocoa implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | } |
|
28
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
64 | |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
65 | UiObject* ui_window(const char *title, void *window_data) { |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
66 | 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
|
67 | obj->window = window_data; |
|
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
68 | return obj; |
|
47
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
69 | } |
|
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
70 | |
|
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
71 | UiObject* ui_simple_window(const char *title, void *window_data) { |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
72 | 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
|
73 | obj->window = window_data; |
|
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
157
diff
changeset
|
74 | return obj; |
|
28
794a5c91c479
added open/save dialogs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
25
diff
changeset
|
75 | } |
|
724
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
76 | |
|
751
41286f7f8433
implement sidebar window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
750
diff
changeset
|
77 | UiObject* ui_sidebar_window(const char *title, void *window_data) { |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
78 | UiObject *obj = create_window(title, FALSE, TRUE, FALSE); |
|
751
41286f7f8433
implement sidebar window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
750
diff
changeset
|
79 | obj->window = window_data; |
|
41286f7f8433
implement sidebar window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
750
diff
changeset
|
80 | return obj; |
|
41286f7f8433
implement sidebar window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
750
diff
changeset
|
81 | } |
|
724
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
82 | |
|
811
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
83 | UiObject* ui_splitview_window(const char *title, UiBool sidebar) { |
|
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
84 | return create_window(title, FALSE, sidebar, TRUE); |
|
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
85 | } |
|
1391ba7e533f
implement splitview window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
751
diff
changeset
|
86 | |
|
724
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
87 | /* --------------------------------- File Dialogs --------------------------------- */ |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
88 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
89 | 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
|
90 | NSOpenPanel *openPanel = [NSOpenPanel openPanel]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
91 | 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
|
92 | openPanel.allowsMultipleSelection = YES; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
93 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
94 | 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
|
95 | openPanel.canChooseFiles = NO; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
96 | openPanel.canChooseDirectories = YES; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
97 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
98 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
99 | NSWindow *window = (__bridge NSWindow*)obj->wobj; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
100 | [openPanel beginSheetModalForWindow:window completionHandler:^(NSModalResponse result) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
101 | UiEvent event; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
102 | event.obj = obj; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
103 | event.window = obj->window; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
104 | event.document = obj->ctx->document; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
105 | event.intval = 0; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
106 | event.set = 0; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
107 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
108 | UiFileList flist = { NULL, 0 }; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
109 | event.eventdata = &flist; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
110 | event.eventdatatype = UI_EVENT_DATA_FILE_LIST; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
111 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
112 | if(result == NSModalResponseOK) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
113 | NSArray<NSURL *> *urls = [openPanel URLs]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
114 | flist.files = calloc(urls.count, sizeof(char*)); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
115 | for(NSURL *url in urls) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
116 | if([url isFileURL]) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
117 | flist.files[flist.nfiles++] = strdup(url.path.UTF8String); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
118 | } |
|
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 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
121 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
122 | if(file_selected_callback) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
123 | file_selected_callback(&event, cbdata); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
124 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
125 | ui_filelist_free(flist); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
126 | }]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
127 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
128 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
129 | 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
|
130 | NSSavePanel *savePanel = [NSSavePanel savePanel]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
131 | if(name) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
132 | NSString *nameStr = [[NSString alloc] initWithUTF8String:name]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
133 | [savePanel setNameFieldStringValue: nameStr]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
134 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
135 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
136 | NSWindow *window = (__bridge NSWindow*)obj->wobj; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
137 | [savePanel beginSheetModalForWindow:window completionHandler:^(NSModalResponse result) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
138 | UiEvent event; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
139 | event.obj = obj; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
140 | event.window = obj->window; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
141 | event.document = obj->ctx->document; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
142 | event.intval = 0; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
143 | event.set = 0; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
144 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
145 | UiFileList flist = { NULL, 0 }; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
146 | event.eventdata = &flist; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
147 | event.eventdatatype = UI_EVENT_DATA_FILE_LIST; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
148 | |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
149 | if(result == NSModalResponseOK) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
150 | NSURL *url = [savePanel URL]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
151 | if([url isFileURL]) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
152 | NSString *path = url.path; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
153 | flist.files = malloc(sizeof(char*)); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
154 | flist.files[0] = strdup(path.UTF8String); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
155 | flist.nfiles = 1; |
|
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 | file_selected_callback(NULL, NULL); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
158 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
159 | if(file_selected_callback) { |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
160 | file_selected_callback(&event, cbdata); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
161 | } |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
162 | ui_filelist_free(flist); |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
163 | }]; |
|
ba7a2f7675b9
add file dialogs (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
164 | } |
|
750
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
165 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
166 | /* ------------------------------------- Dialog ------------------------------------- */ |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
167 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
168 | void ui_dialog_create(UiObject *parent, UiDialogArgs *args) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
169 | NSAlert *dialog = [[NSAlert alloc] init]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
170 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
171 | if(args->title) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
172 | dialog.messageText = [[NSString alloc]initWithUTF8String:args->title]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
173 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
174 | if(args->content) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
175 | dialog.informativeText = [[NSString alloc]initWithUTF8String:args->content]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
176 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
177 | NSTextField *textfield = nil; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
178 | if(args->input) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
179 | NSRect frame = NSMakeRect(0,0,300,22); |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
180 | 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
|
181 | if(args->input_value) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
182 | textfield.stringValue = [[NSString alloc]initWithUTF8String:args->input_value]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
183 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
184 | dialog.accessoryView = textfield; |
|
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 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
187 | int b = 0; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
188 | int b1 = -1; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
189 | int b2 = -1; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
190 | if(args->button1_label) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
191 | [dialog addButtonWithTitle:[[NSString alloc]initWithUTF8String:args->button1_label]]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
192 | b1 = b++; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
193 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
194 | if(args->button2_label) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
195 | [dialog addButtonWithTitle:[[NSString alloc]initWithUTF8String:args->button2_label]]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
196 | b2 = b; |
|
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 | if(args->closebutton_label) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
199 | [dialog addButtonWithTitle:[[NSString alloc]initWithUTF8String:args->closebutton_label]]; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
200 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
201 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
202 | ui_callback callback = args->result; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
203 | void *userdata = args->resultdata; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
204 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
205 | NSWindow *window = (__bridge NSWindow*)parent->wobj; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
206 | [dialog beginSheetModalForWindow:window completionHandler:^(NSModalResponse returnCode) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
207 | UiEvent event; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
208 | event.obj = parent; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
209 | event.window = event.obj->window; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
210 | event.document = event.obj->ctx->document; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
211 | event.eventdata = NULL; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
212 | event.eventdatatype = 0; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
213 | event.set = 0; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
214 | event.intval = 0; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
215 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
216 | long ret = returnCode - NSAlertFirstButtonReturn; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
217 | if(ret == b1) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
218 | event.intval = 1; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
219 | } else if(ret == b2) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
220 | event.intval = 2; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
221 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
222 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
223 | NSString *value = nil; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
224 | if(textfield) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
225 | value = textfield.stringValue; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
226 | event.eventdata = (void*)value.UTF8String; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
227 | event.eventdatatype = UI_EVENT_DATA_STRING; |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
228 | } |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
229 | |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
230 | if(callback) { |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
231 | callback(&event, userdata); |
|
7b627710c155
implement ui_dialog_create (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
232 | } |
|
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 | } |
|
864
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
236 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
237 | /* ------------------------------------- Dialog Window ------------------------------------- */ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
238 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
239 | @implementation UiDialogWindow |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
240 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
241 | - (BOOL) getIsVisible { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
242 | return self.isVisible; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
243 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
244 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
245 | - (void) setVisible:(BOOL)visible { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
246 | //[self makeKeyAndOrderFront:nil]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
247 | if(visible) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
248 | [_parent beginSheet:self completionHandler:^(NSModalResponse returnCode) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
249 | // TODO: close event |
|
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 | } else { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
252 | [self.sheetParent endSheet:self returnCode:NSModalResponseCancel]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
253 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
254 | } |
|
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 | - (void)cancelOperation:(id)sender { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
257 | [self.sheetParent endSheet:self returnCode:NSModalResponseCancel]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
258 | // TODO: close event |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
259 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
260 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
261 | @end |
|
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 | UiObject *ui_dialog_window_create(UiObject *parent, UiDialogWindowArgs *args) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
264 | UiObject *obj = uic_object_new_toplevel(); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
265 | 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
|
266 | styleMask:(NSWindowStyleMaskTitled | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
267 | NSWindowStyleMaskClosable | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
268 | NSWindowStyleMaskResizable | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
269 | NSWindowStyleMaskUtilityWindow) |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
270 | backing:NSBackingStoreBuffered |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
271 | defer:NO]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
272 | panel.parent = (__bridge NSWindow*)parent->wobj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
273 | panel.obj = obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
274 | panel.modal = args->modal; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
275 | panel.onclick = args->onclick; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
276 | panel.onclickdata = args->onclickdata; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
277 | [panel center]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
278 | [[WindowManager sharedWindowManager] addWindow:panel]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
279 | obj->wobj = (__bridge void*)panel; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
280 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
281 | NSView *content = panel.contentView; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
282 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
283 | // 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
|
284 | NSView *buttonArea = [[NSView alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
285 | buttonArea.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
286 | [content addSubview:buttonArea]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
287 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
288 | [buttonArea.bottomAnchor constraintEqualToAnchor:content.bottomAnchor constant:-10], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
289 | [buttonArea.leadingAnchor constraintEqualToAnchor:content.leadingAnchor constant:10], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
290 | [buttonArea.trailingAnchor constraintEqualToAnchor:content.trailingAnchor constant:-10], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
291 | [buttonArea.heightAnchor constraintEqualToConstant:20] |
|
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 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
294 | NSButton *lbutton1 = nil; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
295 | if(args->lbutton1) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
296 | lbutton1 = [[NSButton alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
297 | lbutton1.title = [[NSString alloc]initWithUTF8String:args->lbutton1]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
298 | lbutton1.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
299 | [buttonArea addSubview:lbutton1]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
300 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
301 | [lbutton1.topAnchor constraintEqualToAnchor:buttonArea.topAnchor constant:0], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
302 | [lbutton1.leadingAnchor constraintEqualToAnchor:buttonArea.leadingAnchor constant:0] |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
303 | ]]; |
|
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 | 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
|
306 | event.obj = obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
307 | event.value = 1; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
308 | lbutton1.target = event; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
309 | lbutton1.action = @selector(handleEvent:); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
310 | objc_setAssociatedObject(lbutton1, "eventdata", event, OBJC_ASSOCIATION_RETAIN); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
311 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
312 | NSButton *lbutton2 = nil; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
313 | if(args->lbutton2) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
314 | lbutton2 = [[NSButton alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
315 | lbutton2.title = [[NSString alloc]initWithUTF8String:args->lbutton2]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
316 | lbutton2.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
317 | [buttonArea addSubview:lbutton2]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
318 | NSLayoutXAxisAnchor *anchor = lbutton1 != nil ? lbutton1.trailingAnchor : buttonArea.leadingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
319 | int off = lbutton1 != nil ? 4 : 0; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
320 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
321 | [lbutton2.topAnchor constraintEqualToAnchor:buttonArea.topAnchor constant:0], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
322 | [lbutton2.leadingAnchor constraintEqualToAnchor:anchor constant:off] |
|
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 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
325 | 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
|
326 | event.obj = obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
327 | event.value = 2; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
328 | lbutton2.target = event; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
329 | lbutton2.action = @selector(handleEvent:); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
330 | objc_setAssociatedObject(lbutton2, "eventdata", event, OBJC_ASSOCIATION_RETAIN); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
331 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
332 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
333 | NSButton *rbutton4 = nil; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
334 | if(args->rbutton4) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
335 | rbutton4 = [[NSButton alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
336 | rbutton4.title = [[NSString alloc]initWithUTF8String:args->rbutton4]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
337 | rbutton4.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
338 | [buttonArea addSubview:rbutton4]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
339 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
340 | [rbutton4.topAnchor constraintEqualToAnchor:buttonArea.topAnchor constant:0], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
341 | [rbutton4.trailingAnchor constraintEqualToAnchor:buttonArea.trailingAnchor constant:0] |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
342 | ]]; |
|
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 | 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
|
345 | event.obj = obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
346 | event.value = 2; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
347 | rbutton4.target = event; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
348 | rbutton4.action = @selector(handleEvent:); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
349 | objc_setAssociatedObject(rbutton4, "eventdata", event, OBJC_ASSOCIATION_RETAIN); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
350 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
351 | NSButton *rbutton3 = nil; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
352 | if(args->rbutton3) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
353 | rbutton3 = [[NSButton alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
354 | rbutton3.title = [[NSString alloc]initWithUTF8String:args->rbutton3]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
355 | rbutton3.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
356 | [buttonArea addSubview:rbutton3]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
357 | NSLayoutXAxisAnchor *anchor = rbutton4 != nil ? rbutton4.leadingAnchor : buttonArea.trailingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
358 | int off = rbutton4 != nil ? -4 : 0; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
359 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
360 | [rbutton3.topAnchor constraintEqualToAnchor:buttonArea.topAnchor constant:0], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
361 | [rbutton3.trailingAnchor constraintEqualToAnchor:anchor constant:off] |
|
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 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
364 | 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
|
365 | event.obj = obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
366 | event.value = 2; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
367 | rbutton3.target = event; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
368 | rbutton3.action = @selector(handleEvent:); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
369 | objc_setAssociatedObject(rbutton3, "eventdata", event, OBJC_ASSOCIATION_RETAIN); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
370 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
371 | switch(args->default_button) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
372 | default: break; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
373 | case 1: if(lbutton1 != nil) lbutton1.keyEquivalent = @"\r"; break; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
374 | case 2: if(lbutton2 != nil) lbutton2.keyEquivalent = @"\r"; break; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
375 | case 3: if(rbutton3 != nil) rbutton3.keyEquivalent = @"\r"; break; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
376 | case 4: if(rbutton4 != nil) rbutton4.keyEquivalent = @"\r"; break; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
377 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
378 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
379 | // space between left and right buttons |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
380 | NSView *space = [[NSView alloc]init]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
381 | space.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
382 | [buttonArea addSubview:space]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
383 | NSLayoutXAxisAnchor *leftAnchor = buttonArea.leadingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
384 | NSLayoutXAxisAnchor *rightAnchor = buttonArea.trailingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
385 | if(lbutton2 != nil) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
386 | leftAnchor = lbutton2.trailingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
387 | } else if(lbutton1 != nil) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
388 | leftAnchor = lbutton1.trailingAnchor; |
|
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 | if(rbutton3 != nil) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
392 | rightAnchor = rbutton3.leadingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
393 | } else if(rbutton4 != nil) { |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
394 | rightAnchor = rbutton4.leadingAnchor; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
395 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
396 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
397 | [space.topAnchor constraintEqualToAnchor:buttonArea.topAnchor], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
398 | [space.leadingAnchor constraintEqualToAnchor:leftAnchor constant:10], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
399 | [space.trailingAnchor constraintEqualToAnchor:rightAnchor constant:-10] |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
400 | ]]; |
|
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 | // dialog window main content |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
403 | BoxContainer *vbox = [[BoxContainer alloc] init:NSUserInterfaceLayoutOrientationVertical spacing:0]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
404 | vbox.translatesAutoresizingMaskIntoConstraints = NO; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
405 | [content addSubview:vbox]; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
406 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
407 | [NSLayoutConstraint activateConstraints:@[ |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
408 | [vbox.topAnchor constraintEqualToAnchor:content.topAnchor constant:0], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
409 | [vbox.leadingAnchor constraintEqualToAnchor:content.leadingAnchor], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
410 | [vbox.trailingAnchor constraintEqualToAnchor:content.trailingAnchor], |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
411 | [vbox.bottomAnchor constraintEqualToAnchor:buttonArea.topAnchor constant:0] |
|
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 | UiContainerX *container = ui_create_container(obj, vbox); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
415 | vbox.container = container; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
416 | uic_object_push_container(obj, container); |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
417 | |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
418 | return obj; |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
419 | } |
|
d39301e8f962
add dialog window (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
851
diff
changeset
|
420 |