ui/gtk/container.c

Thu, 15 May 2014 21:48:53 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 15 May 2014 21:48:53 +0200
changeset 40
caa0df8ed095
parent 33
458831c574f4
child 52
25e5390cce41
permissions
-rw-r--r--

added table view (GTK)

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
4
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame) {
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 UiContainer *ct = ucx_mempool_malloc(
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 obj->ctx->mempool,
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 sizeof(UiContainer));
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 ct->widget = frame;
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 ct->add = ui_frame_container_add;
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 return ct;
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 }
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 void ui_frame_container_add(UiContainer *ct, GtkWidget *widget) {
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 gtk_container_add(GTK_CONTAINER(ct->widget), widget);
39b9b86ec452 added simple container
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 }
33
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
49
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
50
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
51 UIWIDGET ui_sidebar(UiObject *obj) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
52 #ifdef UI_GTK3
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
53 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
54 #else
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
55 GtkWidget *paned = gtk_hpaned_new();
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
56 #endif
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
57 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
58
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
59 GtkWidget *sidebar;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
60 #ifdef UI_GTK3
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
61 sidebar = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
62 #else
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
63 sidebar = gtk_vbox_new(FALSE, 0);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
64 #endif
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
65 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
66
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
67 UiObject *left = uic_object_new(obj, sidebar);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
68 UiContainer *ct1 = ucx_mempool_malloc(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
69 obj->ctx->mempool,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
70 sizeof(UiContainer));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
71 ct1->widget = sidebar;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
72 ct1->add = ui_box_add;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
73 left->container = ct1;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
74
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
75 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
76 UiContainer *ct2 = ucx_mempool_malloc(
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
77 obj->ctx->mempool,
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
78 sizeof(UiContainer));
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
79 ct2->widget = paned;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
80 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
81 right->container = ct2;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
82
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
83 UiContainer *ct = uic_get_current_container(obj);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
84 ct->add(ct, paned);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
85
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
86 uic_obj_add(obj, right);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
87 uic_obj_add(obj, left);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
88
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
89 return sidebar;
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
90 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
91
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
92 void ui_split_container_add1(UiContainer *ct, GtkWidget *widget) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
93 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
94 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
95
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
96 void ui_split_container_add2(UiContainer *ct, GtkWidget *widget) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
97 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
98 }
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
99
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
100
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
101 void ui_box_add(UiContainer *ct, GtkWidget *widget) {
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
102 gtk_box_pack_start(GTK_BOX(ct->widget), widget, TRUE, TRUE, 0);
458831c574f4 added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 4
diff changeset
103 }

mercurial