2015-06-11 18:07:06 -05:00
// 11 june 2015
# include "uipriv_unix.h"
2015-08-27 17:40:00 -05:00
struct uiGroup {
uiUnixControl c ;
2015-06-11 18:07:06 -05:00
GtkWidget * widget ;
2015-06-26 20:52:42 -05:00
GtkContainer * container ;
GtkFrame * frame ;
2015-07-01 07:07:53 -05:00
// unfortunately, even though a GtkFrame is a GtkBin, calling gtk_container_set_border_width() on it /includes/ the GtkFrame's label; we don't want tht
2015-08-27 17:40:00 -05:00
GtkWidget * box ;
2015-06-11 18:07:06 -05:00
uiControl * child ;
2015-07-01 07:07:53 -05:00
2015-08-27 17:40:00 -05:00
int margined ;
2015-06-11 18:07:06 -05:00
} ;
2015-08-27 17:40:00 -05:00
static void onDestroy ( uiGroup * ) ;
2015-06-11 18:07:06 -05:00
2015-08-27 17:40:00 -05:00
uiUnixDefineControlWithOnDestroy (
uiGroup , // type name
uiGroupType , // type function
onDestroy ( this ) ; // on destroy
)
2015-07-01 07:07:53 -05:00
2015-08-27 17:40:00 -05:00
static void onDestroy ( uiGroup * g )
{
2015-07-01 07:07:53 -05:00
if ( g - > child ! = NULL ) {
2015-08-27 17:40:00 -05:00
uiControlSetParent ( g - > child , NULL ) ;
2015-07-01 07:07:53 -05:00
uiControlDestroy ( g - > child ) ;
}
2015-08-27 17:40:00 -05:00
gtk_widget_destroy ( g - > box ) ;
2015-06-11 18:07:06 -05:00
}
static void groupContainerUpdateState ( uiControl * c )
{
2015-08-27 17:40:00 -05:00
uiGroup * g = uiGroup ( c ) ;
2015-06-11 18:07:06 -05:00
if ( g - > child ! = NULL )
2015-08-28 09:10:52 -05:00
controlUpdateState ( g - > child ) ;
2015-06-11 18:07:06 -05:00
}
2015-08-27 17:40:00 -05:00
char * uiGroupTitle ( uiGroup * g )
2015-06-11 18:07:06 -05:00
{
2015-07-01 07:07:53 -05:00
return uiUnixStrdupText ( gtk_frame_get_label ( g - > frame ) ) ;
2015-06-11 18:07:06 -05:00
}
2015-08-27 17:40:00 -05:00
void uiGroupSetTitle ( uiGroup * g , const char * text )
2015-06-11 18:07:06 -05:00
{
2015-07-01 07:07:53 -05:00
gtk_frame_set_label ( g - > frame , text ) ;
2015-06-11 18:07:06 -05:00
// changing the text might necessitate a change in the groupbox's size
uiControlQueueResize ( uiControl ( g ) ) ;
}
2015-08-27 17:40:00 -05:00
void uiGroupSetChild ( uiGroup * g , uiControl * child )
2015-06-11 18:07:06 -05:00
{
2015-08-27 17:40:00 -05:00
if ( g - > child ! = NULL ) {
2015-08-28 09:10:52 -05:00
gtk_container_remove ( GTK_CONTAINER ( g - > box ) ,
2015-08-27 17:40:00 -05:00
GTK_WIDGET ( uiControlHandle ( g - > child ) ) ) ;
uiControlSetParent ( g - > child , NULL ) ;
}
2015-06-11 18:07:06 -05:00
g - > child = child ;
if ( g - > child ! = NULL ) {
2015-08-27 17:40:00 -05:00
uiControlSetParent ( g - > child , uiControl ( g ) ) ;
2015-08-28 09:10:52 -05:00
gtk_container_add ( GTK_CONTAINER ( g - > box ) ,
2015-08-27 17:40:00 -05:00
GTK_WIDGET ( uiControlHandle ( g - > child ) ) ) ;
2015-06-11 18:07:06 -05:00
uiControlQueueResize ( g - > child ) ;
}
}
2015-08-27 17:40:00 -05:00
int uiGroupMargined ( uiGroup * g )
2015-06-11 18:07:06 -05:00
{
2015-08-27 17:40:00 -05:00
return g - > margined ;
2015-06-11 18:07:06 -05:00
}
2015-08-27 17:40:00 -05:00
void uiGroupSetMargined ( uiGroup * g , int margined )
2015-06-11 18:07:06 -05:00
{
2015-08-27 17:40:00 -05:00
g - > margined = margined ;
setMargined ( GTK_CONTAINER ( g - > box ) , g - > margined ) ;
2015-06-11 18:07:06 -05:00
uiControlQueueResize ( uiControl ( g ) ) ;
}
uiGroup * uiNewGroup ( const char * text )
{
2015-08-27 17:40:00 -05:00
uiGroup * g ;
2015-06-26 20:52:42 -05:00
gfloat yalign ;
GtkLabel * label ;
PangoAttribute * bold ;
PangoAttrList * boldlist ;
2015-06-11 18:07:06 -05:00
2015-08-28 09:10:52 -05:00
g = ( uiGroup * ) uiNewControl ( uiGroupType ( ) ) ;
2015-06-11 18:07:06 -05:00
2015-06-26 20:52:42 -05:00
g - > widget = gtk_frame_new ( text ) ;
g - > container = GTK_CONTAINER ( g - > widget ) ;
g - > frame = GTK_FRAME ( g - > widget ) ;
// with GTK+, groupboxes by default have frames and slightly x-offset regular text
// they should have no frame and fully left-justified, bold text
// preserve default y-alignment
gtk_frame_get_label_align ( g - > frame , NULL , & yalign ) ;
gtk_frame_set_label_align ( g - > frame , 0 , yalign ) ;
gtk_frame_set_shadow_type ( g - > frame , GTK_SHADOW_NONE ) ;
label = GTK_LABEL ( gtk_frame_get_label_widget ( g - > frame ) ) ;
// this is the boldness level used by GtkPrintUnixDialog
// (it technically uses "bold" but see pango's pango-enum-types.c for the name conversion; GType is weird)
bold = pango_attr_weight_new ( PANGO_WEIGHT_BOLD ) ;
boldlist = pango_attr_list_new ( ) ;
pango_attr_list_insert ( boldlist , bold ) ;
gtk_label_set_attributes ( label , boldlist ) ;
pango_attr_list_unref ( boldlist ) ; // thanks baedert in irc.gimp.net/#gtk+
2015-06-11 18:07:06 -05:00
2015-08-27 17:40:00 -05:00
g - > box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 0 ) ;
gtk_container_add ( g - > container , g - > box ) ;
gtk_widget_show ( g - > box ) ;
2015-07-01 07:07:53 -05:00
2015-08-27 17:40:00 -05:00
uiUnixFinishNewControl ( g , uiGroup ) ;
2015-06-11 18:07:06 -05:00
uiControl ( g ) - > ContainerUpdateState = groupContainerUpdateState ;
2015-08-27 17:40:00 -05:00
return g ;
2015-06-11 18:07:06 -05:00
}