2015-08-28 15:38:04 -05:00
// 28 august 2015
# include "uipriv_unix.h"
// This file contains helpers for managing child controls.
2018-05-12 12:03:55 -05:00
struct uiprivChild {
2015-08-28 15:38:04 -05:00
uiControl * c ;
GtkWidget * widget ;
gboolean oldhexpand ;
GtkAlign oldhalign ;
gboolean oldvexpand ;
GtkAlign oldvalign ;
// Some children can be boxed; that is, they can have an optionally-margined box around them.
// uiGroup, uiTab, and uiWindow all do this.
GtkWidget * box ;
// If the child is not boxed, this is its parent.
// If the child is boxed, this is the box.
GtkContainer * parent ;
// This flag is for users of these functions.
// For uiBox, this is "spaced".
// For uiTab, this is "margined". (uiGroup and uiWindow have to maintain their margined state themselves, since the margined state is independent of whether there is a child for those two.)
int flag ;
} ;
2018-05-12 12:03:55 -05:00
uiprivChild * uiprivNewChild ( uiControl * child , uiControl * parent , GtkContainer * parentContainer )
2015-08-28 15:38:04 -05:00
{
2018-05-12 12:03:55 -05:00
uiprivChild * c ;
2015-08-28 15:38:04 -05:00
if ( child = = NULL )
return NULL ;
2018-05-12 12:03:55 -05:00
c = uiprivNew ( uiprivChild ) ;
2015-08-28 15:38:04 -05:00
c - > c = child ;
c - > widget = GTK_WIDGET ( uiControlHandle ( c - > c ) ) ;
c - > oldhexpand = gtk_widget_get_hexpand ( c - > widget ) ;
c - > oldhalign = gtk_widget_get_halign ( c - > widget ) ;
c - > oldvexpand = gtk_widget_get_vexpand ( c - > widget ) ;
c - > oldvalign = gtk_widget_get_valign ( c - > widget ) ;
uiControlSetParent ( c - > c , parent ) ;
2016-04-25 19:09:20 -05:00
uiUnixControlSetContainer ( uiUnixControl ( c - > c ) , parentContainer , FALSE ) ;
2015-08-28 15:38:04 -05:00
c - > parent = parentContainer ;
return c ;
}
2018-05-12 12:03:55 -05:00
uiprivChild * uiprivNewChildWithBox ( uiControl * child , uiControl * parent , GtkContainer * parentContainer , int margined )
2015-08-28 15:38:04 -05:00
{
2018-05-12 12:03:55 -05:00
uiprivChild * c ;
2015-08-28 15:38:04 -05:00
GtkWidget * box ;
if ( child = = NULL )
return NULL ;
box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
2015-08-28 15:43:41 -05:00
gtk_widget_show ( box ) ;
2018-05-12 12:03:55 -05:00
c = uiprivNewChild ( child , parent , GTK_CONTAINER ( box ) ) ;
2015-08-28 15:50:55 -05:00
gtk_widget_set_hexpand ( c - > widget , TRUE ) ;
gtk_widget_set_halign ( c - > widget , GTK_ALIGN_FILL ) ;
gtk_widget_set_vexpand ( c - > widget , TRUE ) ;
gtk_widget_set_valign ( c - > widget , GTK_ALIGN_FILL ) ;
2015-08-28 15:38:04 -05:00
c - > box = box ;
gtk_container_add ( parentContainer , c - > box ) ;
2018-05-12 12:03:55 -05:00
uiprivChildSetMargined ( c , margined ) ;
2015-08-28 15:38:04 -05:00
return c ;
}
2018-05-12 12:03:55 -05:00
void uiprivChildRemove ( uiprivChild * c )
2015-08-28 15:38:04 -05:00
{
uiControlSetParent ( c - > c , NULL ) ;
2016-04-25 19:34:12 -05:00
uiUnixControlSetContainer ( uiUnixControl ( c - > c ) , c - > parent , TRUE ) ;
2015-08-28 15:38:04 -05:00
gtk_widget_set_hexpand ( c - > widget , c - > oldhexpand ) ;
gtk_widget_set_halign ( c - > widget , c - > oldhalign ) ;
gtk_widget_set_vexpand ( c - > widget , c - > oldvexpand ) ;
gtk_widget_set_valign ( c - > widget , c - > oldvalign ) ;
if ( c - > box ! = NULL )
gtk_widget_destroy ( c - > box ) ;
2018-04-15 15:36:03 -05:00
uiprivFree ( c ) ;
2015-08-28 15:38:04 -05:00
}
2018-05-12 12:03:55 -05:00
void uiprivChildDestroy ( uiprivChild * c )
2015-08-28 15:38:04 -05:00
{
uiControl * child ;
child = c - > c ;
2018-05-12 12:03:55 -05:00
uiprivChildRemove ( c ) ;
2015-08-28 15:38:04 -05:00
uiControlDestroy ( child ) ;
}
2018-05-12 12:03:55 -05:00
GtkWidget * uiprivChildWidget ( uiprivChild * c )
2015-08-28 15:38:04 -05:00
{
return c - > widget ;
}
2018-05-12 12:03:55 -05:00
int uiprivChildFlag ( uiprivChild * c )
2015-08-28 15:38:04 -05:00
{
return c - > flag ;
}
2018-05-12 12:03:55 -05:00
void uiprivChildSetFlag ( uiprivChild * c , int flag )
2015-08-28 15:38:04 -05:00
{
c - > flag = flag ;
}
2018-05-12 12:03:55 -05:00
GtkWidget * uiprivChildBox ( uiprivChild * c )
2015-08-28 15:38:04 -05:00
{
return c - > box ;
}
2018-05-12 12:03:55 -05:00
void uiprivChildSetMargined ( uiprivChild * c , int margined )
2015-08-28 15:38:04 -05:00
{
2018-05-12 11:47:21 -05:00
uiprivSetMargined ( GTK_CONTAINER ( c - > box ) , margined ) ;
2015-08-28 15:38:04 -05:00
}