| 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
| 27 */ |
27 */ |
| 28 |
28 |
| 29 #import "MainWindow.h" |
29 #import "MainWindow.h" |
| |
30 #import "WindowManager.h" |
| 30 #import "container.h" |
31 #import "container.h" |
| 31 #import "GridLayout.h" |
32 #import "GridLayout.h" |
| 32 #import "BoxContainer.h" |
33 #import "BoxContainer.h" |
| 33 #import "../common/object.h" |
34 #import "../common/object.h" |
| 34 #import "../ui/properties.h" |
35 #import "../ui/properties.h" |
| 35 #import <objc/runtime.h> |
36 #import <objc/runtime.h> |
| 36 |
37 |
| 37 #import "EventData.h" |
38 #import "EventData.h" |
| 38 #import "menu.h" |
39 #import "menu.h" |
| 39 #import "Toolbar.h" |
40 #import "Toolbar.h" |
| |
41 |
| |
42 |
| 40 |
43 |
| 41 @implementation MainWindow |
44 @implementation MainWindow |
| 42 |
45 |
| 43 - (MainWindow*)init:(UiObject*)obj withSidebar:(BOOL)hasSidebar withSplitview:(BOOL)hasSplitview{ |
46 - (MainWindow*)init:(UiObject*)obj withSidebar:(BOOL)hasSidebar withSplitview:(BOOL)hasSplitview{ |
| 44 NSRect frame = NSMakeRect(300, 200, 600, 500); |
47 NSRect frame = NSMakeRect(300, 200, 600, 500); |
| 49 NSWindowStyleMaskClosable | |
52 NSWindowStyleMaskClosable | |
| 50 NSWindowStyleMaskMiniaturizable |
53 NSWindowStyleMaskMiniaturizable |
| 51 backing:NSBackingStoreBuffered |
54 backing:NSBackingStoreBuffered |
| 52 defer:false]; |
55 defer:false]; |
| 53 _obj = obj; |
56 _obj = obj; |
| 54 |
57 self.delegate = self; |
| 55 |
58 |
| 56 int top = 4; |
59 int top = 4; |
| 57 NSView *content = self.contentView; |
60 NSView *content = self.contentView; |
| 58 |
61 |
| 59 // A sidebar or splitview window need a NSSplitView |
62 // A sidebar or splitview window need a NSSplitView |
| 135 if(uic_toolbar_isenabled()) { |
138 if(uic_toolbar_isenabled()) { |
| 136 UiToolbar *toolbar = [[UiToolbar alloc]initWithWindow:self]; |
139 UiToolbar *toolbar = [[UiToolbar alloc]initWithWindow:self]; |
| 137 [self setToolbar:toolbar]; |
140 [self setToolbar:toolbar]; |
| 138 } |
141 } |
| 139 |
142 |
| 140 |
|
| 141 return self; |
143 return self; |
| 142 } |
144 } |
| 143 |
145 |
| 144 - (BOOL) getIsVisible { |
146 - (BOOL) getIsVisible { |
| 145 return [self isVisible]; |
147 return [self isVisible]; |
| 151 } else { |
153 } else { |
| 152 [self close]; |
154 [self close]; |
| 153 } |
155 } |
| 154 } |
156 } |
| 155 |
157 |
| 156 |
158 - (void) windowWillClose:(NSNotification *) notification { |
| |
159 UiObject *obj = _obj; |
| |
160 |
| |
161 if(obj->onclose) { |
| |
162 UiEvent event; |
| |
163 memset(&event, 0, sizeof(UiEvent)); |
| |
164 event.obj = obj; |
| |
165 event.window = obj->window; |
| |
166 event.document = obj->ctx->document; |
| |
167 obj->onclose(&event, obj->onclosedata); |
| |
168 } |
| |
169 |
| |
170 if(obj->ref > 0) { |
| |
171 obj->ref--; |
| |
172 } else { |
| |
173 // warn about invalid reference counting |
| |
174 NSLog(@"Error: UiObject %p ref == 0\n", obj); |
| |
175 } |
| |
176 |
| |
177 if(obj->ref == 0) { |
| |
178 // this cleans up any widget references from the context |
| |
179 uic_context_prepare_close(obj->ctx); |
| |
180 |
| |
181 [[WindowManager sharedWindowManager] closeWindow:self]; |
| |
182 } |
| |
183 } |
| |
184 |
| |
185 - (void) dealloc { |
| |
186 uic_object_destroy(_obj); |
| |
187 NSLog(@"MainWindow dealloc"); |
| |
188 } |
| 157 @end |
189 @end |
| 158 |
190 |
| 159 |
191 |
| 160 @implementation MainWindowController |
192 @implementation MainWindowController |
| 161 |
193 |