1 /*
2  * GNT - The GLib Ncurses Toolkit
3  *
4  * GNT is the legal property of its developers, whose names are too numerous
5  * to list here.  Please refer to the COPYRIGHT file distributed with this
6  * source distribution.
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
21  */
22 
23 #ifndef GNT_BOX_H
24 #define GNT_BOX_H
25 /**
26  * SECTION:gntbox
27  * @section_id: libgnt-gntbox
28  * @title: GntBox
29  * @short_description: A box for packing widgets in a single row or column
30  */
31 
32 #include "gnt.h"
33 #include "gntwidget.h"
34 
35 #define GNT_TYPE_BOX				(gnt_box_get_gtype())
36 #define GNT_BOX(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_BOX, GntBox))
37 #define GNT_BOX_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_BOX, GntBoxClass))
38 #define GNT_IS_BOX(obj)			(G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_BOX))
39 #define GNT_IS_BOX_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_BOX))
40 #define GNT_BOX_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_BOX, GntBoxClass))
41 
42 typedef struct _GntBox			GntBox;
43 typedef struct _GntBoxClass		GntBoxClass;
44 
45 typedef enum
46 {
47 	/* These for vertical boxes */
48 	GNT_ALIGN_LEFT,
49 	GNT_ALIGN_RIGHT,
50 
51 	GNT_ALIGN_MID,
52 
53 	/* These for horizontal boxes */
54 	GNT_ALIGN_TOP,
55 	GNT_ALIGN_BOTTOM
56 } GntAlignment;
57 
58 /**
59  * GntBox:
60  *
61  * Access to any fields is deprecated. See inline comments for replacements.
62  */
63 struct _GntBox
64 {
65 	GntWidget parent;
66 
67 	gboolean GNTSEAL(vertical);
68 	gboolean GNTSEAL(homogeneous);
69 	gboolean GNTSEAL(fill);
70 	GList *GNTSEAL(list);		/* Deprecated. Use gnt_box_get_children. */
71 
72 	GntWidget *GNTSEAL(active);
73 	int GNTSEAL(pad);			/* Number of spaces to use between widgets */
74 	GntAlignment GNTSEAL(alignment);  /* How are the widgets going to be aligned? */
75 
76 	char *GNTSEAL(title);
77 	GList *GNTSEAL(focus);		/* List of widgets to cycle focus (only valid for parent boxes) */
78 
79 	/*< private >*/
80     void (*gnt_reserved1)(void);
81     void (*gnt_reserved2)(void);
82     void (*gnt_reserved3)(void);
83     void (*gnt_reserved4)(void);
84 };
85 
86 struct _GntBoxClass
87 {
88 	GntWidgetClass parent;
89 
90 	/*< private >*/
91 	void (*gnt_reserved1)(void);
92 	void (*gnt_reserved2)(void);
93 	void (*gnt_reserved3)(void);
94 	void (*gnt_reserved4)(void);
95 };
96 
97 G_BEGIN_DECLS
98 
99 /**
100  * gnt_box_get_gtype:
101  *
102  * The GType for GntBox.
103  *
104  * Returns: The GType.
105  */
106 GType gnt_box_get_gtype(void);
107 
108 #define gnt_vbox_new(homo) gnt_box_new(homo, TRUE)
109 #define gnt_hbox_new(homo) gnt_box_new(homo, FALSE)
110 
111 /**
112  * gnt_box_new:
113  * @homo:  If %TRUE, all the widgets in it will have the same width (or height)
114  * @vert:  Whether the widgets in it should be stacked vertically (if %TRUE)
115  *              or horizontally (if %FALSE).
116  *
117  * Create a new GntBox.
118  *
119  * Returns: The new GntBox.
120  */
121 GntWidget * gnt_box_new(gboolean homo, gboolean vert);
122 
123 /**
124  * gnt_box_get_children:
125  * @box: The box
126  *
127  * Returns a list of the children of the widget.
128  *
129  * Returns: (element-type GntWidget) (transfer container): A new list
130  *          containing the children of the box.
131  *
132  * Since: 2.14.0
133  */
134 GList *gnt_box_get_children(GntBox *box);
135 
136 /**
137  * gnt_box_add_widget:
138  * @box:     The box
139  * @widget:  The widget to add
140  *
141  * Add a widget in the box.
142  */
143 void gnt_box_add_widget(GntBox *box, GntWidget *widget);
144 
145 /**
146  * gnt_box_set_title:
147  * @box:    The box
148  * @title:	 The title to set
149  *
150  * Set a title for the box.
151  */
152 void gnt_box_set_title(GntBox *box, const char *title);
153 
154 /**
155  * gnt_box_set_pad:
156  * @box: The box
157  * @pad: The padding to use
158  *
159  * Set the padding to use between the widgets in the box.
160  */
161 void gnt_box_set_pad(GntBox *box, int pad);
162 
163 /**
164  * gnt_box_set_toplevel:
165  * @box: The box
166  * @set: %TRUE if it's a toplevel box, %FALSE otherwise.
167  *
168  * Set whether it's a toplevel box (ie, a window) or not. If a box is toplevel,
169  * then it will show borders, the title (if set) and shadow (if enabled in
170  * <filename>.gntrc</filename>)
171  */
172 void gnt_box_set_toplevel(GntBox *box, gboolean set);
173 
174 /**
175  * gnt_box_sync_children:
176  * @box: The box
177  *
178  * Reposition and refresh the widgets in the box.
179  */
180 void gnt_box_sync_children(GntBox *box);
181 
182 /**
183  * gnt_box_set_alignment:
184  * @box:       The box
185  * @alignment: The alignment to use
186  *
187  * Set the alignment for the widgets in the box.
188  */
189 void gnt_box_set_alignment(GntBox *box, GntAlignment alignment);
190 
191 /**
192  * gnt_box_remove:
193  * @box:       The box
194  * @widget:    The widget to remove
195  *
196  * Remove a widget from the box. Calling this does NOT destroy the removed widget.
197  */
198 void gnt_box_remove(GntBox *box, GntWidget *widget);
199 
200 /**
201  * gnt_box_remove_all:
202  * @box: The box
203  *
204  * Remove all widgets from the box. This DOES destroy all widgets in the box.
205  */
206 void gnt_box_remove_all(GntBox *box);
207 
208 /**
209  * gnt_box_readjust:
210  * @box:  The box
211  *
212  * Readjust the size of each child widget, reposition the child widgets and
213  * recalculate the size of the box.
214  */
215 void gnt_box_readjust(GntBox *box);
216 
217 /**
218  * gnt_box_set_fill:
219  * @box:   The box
220  * @fill:  Whether the child widgets should fill the empty space
221  *
222  * Set whether the widgets in the box should fill the empty spaces.
223  */
224 void gnt_box_set_fill(GntBox *box, gboolean fill);
225 
226 /**
227  * gnt_box_move_focus:
228  * @box: The box
229  * @dir: The direction. If it's 1, then the focus is moved forwards, if it's
230  *            -1, the focus is moved backwards.
231  *
232  * Move the focus from one widget to the other.
233  */
234 void gnt_box_move_focus(GntBox *box, int dir);
235 
236 /**
237  * gnt_box_give_focus_to_child:
238  * @box:       The box
239  * @widget:    The child widget to give focus
240  *
241  * Give focus to a specific child widget.
242  */
243 void gnt_box_give_focus_to_child(GntBox *box, GntWidget *widget);
244 
245 G_END_DECLS
246 
247 #endif /* GNT_BOX_H */
248 
249