1 | /* OBox Copyright (C) 2002 Red Hat Inc. based on GtkHBox */ |
---|
2 | /* GTK - The GIMP Toolkit |
---|
3 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
---|
4 | * |
---|
5 | * This library is free software; you can redistribute it and/or |
---|
6 | * modify it under the terms of the GNU Lesser General Public |
---|
7 | * License as published by the Free Software Foundation; either |
---|
8 | * version 2 of the License, or (at your option) any later version. |
---|
9 | * |
---|
10 | * This library is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | * Lesser General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU Lesser General Public |
---|
16 | * License along with this library; if not, write to the |
---|
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
18 | * Boston, MA 02111-1307, USA. |
---|
19 | */ |
---|
20 | |
---|
21 | /* |
---|
22 | * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS |
---|
23 | * file for a list of people on the GTK+ Team. See the ChangeLog |
---|
24 | * files for a list of changes. These files are distributed with |
---|
25 | * GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
---|
26 | */ |
---|
27 | |
---|
28 | #include "obox.h" |
---|
29 | |
---|
30 | #include <gtk/gtk.h> |
---|
31 | |
---|
32 | static void na_obox_size_request (GtkWidget *widget, |
---|
33 | GtkRequisition *requisition); |
---|
34 | static void na_obox_size_allocate (GtkWidget *widget, |
---|
35 | GtkAllocation *allocation); |
---|
36 | |
---|
37 | |
---|
38 | G_DEFINE_TYPE (NaOBox, na_obox, GTK_TYPE_BOX) |
---|
39 | |
---|
40 | static void |
---|
41 | na_obox_class_init (NaOBoxClass *class) |
---|
42 | { |
---|
43 | GtkWidgetClass *widget_class; |
---|
44 | |
---|
45 | widget_class = (GtkWidgetClass*) class; |
---|
46 | |
---|
47 | widget_class->size_request = na_obox_size_request; |
---|
48 | widget_class->size_allocate = na_obox_size_allocate; |
---|
49 | } |
---|
50 | |
---|
51 | static void |
---|
52 | na_obox_init (NaOBox *obox) |
---|
53 | { |
---|
54 | obox->orientation = GTK_ORIENTATION_HORIZONTAL; |
---|
55 | } |
---|
56 | |
---|
57 | GtkWidget* |
---|
58 | na_obox_new (void) |
---|
59 | { |
---|
60 | NaOBox *obox; |
---|
61 | |
---|
62 | obox = g_object_new (NA_TYPE_OBOX, NULL); |
---|
63 | |
---|
64 | return GTK_WIDGET (obox); |
---|
65 | } |
---|
66 | |
---|
67 | static GtkWidgetClass* |
---|
68 | get_class (NaOBox *obox) |
---|
69 | { |
---|
70 | GtkWidgetClass *klass; |
---|
71 | |
---|
72 | switch (obox->orientation) |
---|
73 | { |
---|
74 | case GTK_ORIENTATION_HORIZONTAL: |
---|
75 | klass = GTK_WIDGET_CLASS (g_type_class_peek (GTK_TYPE_HBOX)); |
---|
76 | break; |
---|
77 | case GTK_ORIENTATION_VERTICAL: |
---|
78 | klass = GTK_WIDGET_CLASS (g_type_class_peek (GTK_TYPE_VBOX)); |
---|
79 | break; |
---|
80 | default: |
---|
81 | g_assert_not_reached (); |
---|
82 | klass = NULL; |
---|
83 | break; |
---|
84 | } |
---|
85 | |
---|
86 | return klass; |
---|
87 | } |
---|
88 | |
---|
89 | static void |
---|
90 | na_obox_size_request (GtkWidget *widget, |
---|
91 | GtkRequisition *requisition) |
---|
92 | { |
---|
93 | GtkWidgetClass *klass; |
---|
94 | NaOBox *obox; |
---|
95 | |
---|
96 | obox = NA_OBOX (widget); |
---|
97 | |
---|
98 | klass = get_class (obox); |
---|
99 | |
---|
100 | klass->size_request (widget, requisition); |
---|
101 | } |
---|
102 | |
---|
103 | static void |
---|
104 | na_obox_size_allocate (GtkWidget *widget, |
---|
105 | GtkAllocation *allocation) |
---|
106 | { |
---|
107 | GtkWidgetClass *klass; |
---|
108 | NaOBox *obox; |
---|
109 | |
---|
110 | obox = NA_OBOX (widget); |
---|
111 | |
---|
112 | klass = get_class (obox); |
---|
113 | |
---|
114 | klass->size_allocate (widget, allocation); |
---|
115 | } |
---|
116 | |
---|
117 | void |
---|
118 | na_obox_set_orientation (NaOBox *obox, |
---|
119 | GtkOrientation orientation) |
---|
120 | { |
---|
121 | g_return_if_fail (NA_IS_OBOX (obox)); |
---|
122 | |
---|
123 | if (obox->orientation == orientation) |
---|
124 | return; |
---|
125 | |
---|
126 | obox->orientation = orientation; |
---|
127 | |
---|
128 | gtk_widget_queue_resize (GTK_WIDGET (obox)); |
---|
129 | } |
---|