ui/cocoa/container.m

changeset 51
42506e19eb6b
parent 13
2dbc56c2323b
--- a/ui/cocoa/container.m	Sat May 31 11:08:34 2014 +0200
+++ b/ui/cocoa/container.m	Fri Jun 13 10:39:54 2014 +0200
@@ -36,17 +36,71 @@
     UiContainer *ct = ucx_mempool_malloc(
                                          obj->ctx->mempool,
                                          sizeof(UiContainer));
-    ct->widget = (NSView*)window;
-    ct->add = ui_window_container_add;
-    ct->getframe = ui_window_container_getframe;
+    ct->widget = [window contentView];
+    ct->add = ui_container_add;
+    ct->getframe = ui_container_getframe;
     return ct;
 }
 
-void ui_window_container_add(UiContainer *ct, NSView *view) {
-    NSWindow *window = (NSWindow*)ct->widget;
-    [window setContentView:view];
+UIWIDGET ui_sidebar(UiObject *obj) {
+    UiContainer *ct = uic_get_current_container(obj);
+    NSRect frame = ct->getframe(ct);
+    
+    // create and add views
+    NSSplitView *splitview = [[NSSplitView alloc] initWithFrame:frame];
+    [splitview setVertical:YES];
+    [splitview setDividerStyle:NSSplitViewDividerStyleThin];
+    ct->add(ct, splitview);
+    
+    NSRect lframe;
+    lframe.origin.x = 0;
+    lframe.origin.y = 0;
+    lframe.size.width = 200;
+    lframe.size.height = frame.size.height;
+    
+    NSRect rframe;
+    rframe.origin.x = 0;
+    rframe.origin.y = 0;
+    rframe.size.width = frame.size.width - 201;
+    rframe.size.height = frame.size.height;
+    
+    NSView *sidebar = [[NSView alloc]initWithFrame:lframe];
+    NSView *contentarea = [[NSView alloc]initWithFrame:rframe];
+    
+    [splitview addSubview:sidebar];
+    [splitview addSubview:contentarea];
+    
+    // add ui objects for the sidebar and contentarea
+    // the sidebar is added last, so that new views are added first to it
+    UiObject *left = uic_object_new(obj, sidebar);
+    UiContainer *ct1 = ucx_mempool_malloc(
+            obj->ctx->mempool,
+            sizeof(UiContainer));
+    ct1->widget = sidebar;
+    ct1->add = ui_container_add;
+    ct1->getframe = ui_container_getframe;
+    left->container = ct1;
+    
+    UiObject *right = uic_object_new(obj, sidebar);
+    UiContainer *ct2 = ucx_mempool_malloc(
+            obj->ctx->mempool,
+            sizeof(UiContainer));
+    ct2->widget = contentarea;
+    ct2->add = ui_container_add;
+    ct2->getframe = ui_container_getframe;
+    right->container = ct2;
+    
+    uic_obj_add(obj, right);
+    uic_obj_add(obj, left);
+    
+    return splitview;
 }
 
-NSRect ui_window_container_getframe(UiContainer *ct) {
+
+NSRect ui_container_getframe(UiContainer *ct) {
     return [ct->widget frame];
 }
+
+void ui_container_add(UiContainer *ct, NSView *view) {
+    [ct->widget addSubview: view];
+}

mercurial