ui/gtk/container.c

Thu, 01 Jan 2015 17:22:55 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 01 Jan 2015 17:22:55 +0100
changeset 61
7ee124a58fe3
parent 59
eb6611be50c7
child 62
70d2aee84432
permissions
-rw-r--r--

improved box (Motif)

4
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39b9b86ec452 added simple container
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
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "container.h"
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "../common/context.h"
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
34 #include "../common/object.h"
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
35
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
36 static UiBool ui_lb2bool(UiLayoutBool b) {
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
37 return b == UI_LAYOUT_TRUE ? TRUE : FALSE;
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
38 }
4
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
40 static UiLayoutBool ui_bool2lb(UiBool b) {
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
41 return b ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE;
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
42 }
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
43
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
44 GtkWidget* ui_gtk_vbox_new() {
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
45 #ifdef UI_GTK3
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
46 return gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
47 #else
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
48 return gtk_vbox_new(FALSE, 0);
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
49 #endif
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
50 }
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
51
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
52 GtkWidget* ui_gtk_hbox_new() {
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
53 #ifdef UI_GTK3
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
54 return gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
55 #else
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
56 return gtk_hbox_new(FALSE, 0);
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
57 #endif
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
58 }
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
60 /* -------------------- Frame Container (deprecated) -------------------- */
4
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame) {
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
62 UiContainer *ct = ucx_mempool_calloc(
4
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 obj->ctx->mempool,
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
64 1,
4
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 sizeof(UiContainer));
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 ct->widget = frame;
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 ct->add = ui_frame_container_add;
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 return ct;
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 }
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
71 void ui_frame_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
4
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 gtk_container_add(GTK_CONTAINER(ct->widget), widget);
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
73 ui_reset_layout(ct->layout);
4
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 }
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
75
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
76
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
77 /* -------------------- Box Container -------------------- */
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
78 UiContainer* ui_box_container(UiObject *obj, GtkWidget *box) {
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
79 UiBoxContainer *ct = ucx_mempool_calloc(
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
80 obj->ctx->mempool,
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
81 1,
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
82 sizeof(UiBoxContainer));
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
83 ct->container.widget = box;
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
84 ct->container.add = ui_box_container_add;
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
85 return (UiContainer*)ct;
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
86 }
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
87
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
88 void ui_box_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
89 UiBoxContainer *bc = (UiBoxContainer*)ct;
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
90 if(ct->layout.fill != UI_LAYOUT_UNDEFINED) {
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
91 fill = ui_lb2bool(ct->layout.fill);
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
92 }
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
93
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
94 if(bc->has_fill && fill) {
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
95 fprintf(stderr, "UiError: container has 2 filled widgets");
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
96 fill = FALSE;
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
97 }
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
98 if(fill) {
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
99 bc->has_fill = TRUE;
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
100 }
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
101
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
102 UiBool expand = fill;
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
103 gtk_box_pack_start(GTK_BOX(ct->widget), widget, expand, fill, 0);
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
104
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
105 ui_reset_layout(ct->layout);
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
106 }
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
107
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
108
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
109 /* -------------------- Sidebar -------------------- */
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
110 UIWIDGET ui_sidebar(UiObject *obj) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
111 #ifdef UI_GTK3
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
112 GtkWidget *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
113 #else
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
114 GtkWidget *paned = gtk_hpaned_new();
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
115 #endif
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
116 gtk_paned_set_position(GTK_PANED(paned), 200);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
117
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
118 GtkWidget *sidebar = ui_gtk_vbox_new();
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
119 gtk_paned_pack1(GTK_PANED(paned), sidebar, TRUE, FALSE);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
120
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
121 UiObject *left = uic_object_new(obj, sidebar);
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
122 UiContainer *ct1 = ui_box_container(obj, sidebar);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
123 left->container = ct1;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
124
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
125 UiObject *right = uic_object_new(obj, sidebar);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
126 UiContainer *ct2 = ucx_mempool_malloc(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
127 obj->ctx->mempool,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
128 sizeof(UiContainer));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
129 ct2->widget = paned;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
130 ct2->add = ui_split_container_add2;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
131 right->container = ct2;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
132
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
133 UiContainer *ct = uic_get_current_container(obj);
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
134 ct->add(ct, paned, TRUE);
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
135
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
136 uic_obj_add(obj, right);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
137 uic_obj_add(obj, left);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
138
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
139 return sidebar;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
140 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
141
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
142 void ui_split_container_add1(UiContainer *ct, GtkWidget *widget, UiBool fill) {
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
143 // TODO: remove
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
144 gtk_paned_pack1(GTK_PANED(ct->widget), widget, TRUE, FALSE);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
145 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
146
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
147 void ui_split_container_add2(UiContainer *ct, GtkWidget *widget, UiBool fill) {
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
148 gtk_paned_pack2(GTK_PANED(ct->widget), widget, TRUE, FALSE);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
149 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
150
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
151
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
152 /* -------------------- Document Tabview -------------------- */
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
153 static void page_change(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer data) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
154 GQuark q = g_quark_from_static_string("ui.tab.object");
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
155 UiObject *tab = g_object_get_qdata(G_OBJECT(page), q);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
156 if(!tab) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
157 return;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
158 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
159
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
160 printf("page_change: %d\n", page_num);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
161 UiContext *ctx = tab->ctx;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
162 ctx->parent->set_document(ctx->parent, ctx->document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
163 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
164
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
165 UiTabbedPane* ui_tabbed_document_view(UiObject *obj) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
166 GtkWidget *tabview = gtk_notebook_new();
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
167 gtk_notebook_set_show_border(GTK_NOTEBOOK(tabview), FALSE);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
168
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
169 g_signal_connect(
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
170 tabview,
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
171 "switch-page",
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
172 G_CALLBACK(page_change),
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
173 NULL);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
174
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
175 UiContainer *ct = uic_get_current_container(obj);
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
176 ct->add(ct, tabview, TRUE);
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
177
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
178 UiTabbedPane *tabbedpane = ui_malloc(obj->ctx, sizeof(UiTabbedPane));
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
179 tabbedpane->ctx = uic_current_obj(obj)->ctx;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
180 tabbedpane->widget = tabview;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
181 tabbedpane->document = NULL;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
182
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
183 return tabbedpane;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
184 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
185
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
186 UiObject* ui_document_tab(UiTabbedPane *view) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
187 GtkWidget *frame = gtk_alignment_new(0.5, 0.5, 1, 1);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
188 // TODO: label
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
189 gtk_notebook_append_page(GTK_NOTEBOOK(view->widget), frame, NULL);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
190
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
191 UiObject *tab = ui_malloc(view->ctx, sizeof(UiObject));
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
192 tab->widget = NULL; // initialization for uic_context()
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
193 tab->ctx = uic_context(tab, view->ctx->mempool);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
194 tab->ctx->parent = view->ctx;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
195 tab->ctx->set_document = ui_tab_set_document;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
196 tab->ctx->detach_document = ui_tab_detach_document;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
197 tab->widget = frame;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
198 tab->window = view->ctx->obj->window;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
199 tab->container = ui_frame_container(tab, frame);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
200 tab->next = NULL;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
201
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
202 GQuark q = g_quark_from_static_string("ui.tab.object");
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
203 g_object_set_qdata(G_OBJECT(frame), q, tab);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
204
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
205 return tab;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
206 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
207
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
208 void ui_tab_set_document(UiContext *ctx, void *document) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
209 if(ctx->parent->document) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
210 //ctx->parent->detach_document(ctx->parent, ctx->parent->document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
211 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
212 uic_context_set_document(ctx, document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
213 //uic_context_set_document(ctx->parent, document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
214 //ctx->parent->document = document;
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
215 }
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
216
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
217 void ui_tab_detach_document(UiContext *ctx, void *document) {
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
218 uic_context_detach_document(ctx->parent, document);
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
219 }
59
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
220
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
221
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
222 /*
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
223 * -------------------- Layout Functions --------------------
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
224 *
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
225 * functions for setting layout attributes for the current container
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
226 *
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
227 */
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
228
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
229 void ui_layout_fill(UiObject *obj, UiBool fill) {
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
230 UiContainer *ct = uic_get_current_container(obj);
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
231 ct->layout.fill = ui_bool2lb(fill);
eb6611be50c7 added box container (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
232 }

mercurial