2015-08-27 11:29:19 -05:00
// 7 april 2015
/*
This file assumes that you have included < gtk / gtk . h > and " ui.h " beforehand . It provides API - specific functions for interfacing with foreign controls on Unix systems that use GTK + to provide their UI ( currently all except Mac OS X ) .
*/
# ifndef __LIBUI_UI_UNIX_H__
# define __LIBUI_UI_UNIX_H__
2015-11-16 09:55:44 -06:00
# ifdef __cplusplus
extern " C " {
# endif
2015-08-27 11:29:19 -05:00
typedef struct uiUnixControl uiUnixControl ;
struct uiUnixControl {
uiControl c ;
2016-04-25 18:16:48 -05:00
uiControl * parent ;
gboolean addedBefore ;
2017-06-06 15:19:08 -05:00
gboolean explicitlyHidden ;
2016-04-25 15:45:49 -05:00
void ( * SetContainer ) ( uiUnixControl * , GtkContainer * , gboolean ) ;
2015-08-27 11:29:19 -05:00
} ;
2016-04-24 13:15:56 -05:00
# define uiUnixControl(this) ((uiUnixControl *) (this))
2015-08-27 11:29:19 -05:00
// TODO document
2016-04-25 15:45:49 -05:00
_UI_EXTERN void uiUnixControlSetContainer ( uiUnixControl * , GtkContainer * , gboolean ) ;
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultDestroy(type) \
2016-04-25 15:45:49 -05:00
static void type # # Destroy ( uiControl * c ) \
{ \
2016-04-25 18:16:48 -05:00
/* TODO is this safe on floating refs? */ \
2016-04-25 18:45:05 -05:00
g_object_unref ( type ( c ) - > widget ) ; \
2016-04-25 15:45:49 -05:00
uiFreeControl ( c ) ; \
}
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultHandle(type) \
2016-04-25 15:45:49 -05:00
static uintptr_t type # # Handle ( uiControl * c ) \
{ \
2016-04-25 18:45:05 -05:00
return ( uintptr_t ) ( type ( c ) - > widget ) ; \
2016-04-25 15:45:49 -05:00
}
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultParent(type) \
2016-04-25 15:45:49 -05:00
static uiControl * type # # Parent ( uiControl * c ) \
{ \
return uiUnixControl ( c ) - > parent ; \
}
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultSetParent(type) \
2016-04-25 15:45:49 -05:00
static void type # # SetParent ( uiControl * c , uiControl * parent ) \
{ \
uiControlVerifySetParent ( c , parent ) ; \
uiUnixControl ( c ) - > parent = parent ; \
}
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultToplevel(type) \
2016-04-25 15:45:49 -05:00
static int type # # Toplevel ( uiControl * c ) \
{ \
return 0 ; \
}
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultVisible(type) \
2016-04-25 15:45:49 -05:00
static int type # # Visible ( uiControl * c ) \
{ \
2016-04-25 18:45:05 -05:00
return gtk_widget_get_visible ( type ( c ) - > widget ) ; \
2016-04-25 15:45:49 -05:00
}
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultShow(type) \
2016-04-25 15:45:49 -05:00
static void type # # Show ( uiControl * c ) \
{ \
2017-06-06 15:19:08 -05:00
/*TODO part of massive hack about hidden before*/ uiUnixControl ( c ) - > explicitlyHidden = FALSE ; \
2016-04-25 18:45:05 -05:00
gtk_widget_show ( type ( c ) - > widget ) ; \
2016-04-25 15:45:49 -05:00
}
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultHide(type) \
2016-04-25 15:45:49 -05:00
static void type # # Hide ( uiControl * c ) \
2015-08-27 11:29:19 -05:00
{ \
2017-06-06 15:19:08 -05:00
/*TODO part of massive hack about hidden before*/ uiUnixControl ( c ) - > explicitlyHidden = TRUE ; \
2016-04-25 18:45:05 -05:00
gtk_widget_hide ( type ( c ) - > widget ) ; \
2016-04-25 15:45:49 -05:00
}
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultEnabled(type) \
2016-04-25 15:45:49 -05:00
static int type # # Enabled ( uiControl * c ) \
2015-08-27 11:29:19 -05:00
{ \
2016-04-25 18:45:05 -05:00
return gtk_widget_get_sensitive ( type ( c ) - > widget ) ; \
2016-04-25 15:45:49 -05:00
}
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultEnable(type) \
2016-04-25 15:45:49 -05:00
static void type # # Enable ( uiControl * c ) \
{ \
2016-04-25 18:45:05 -05:00
gtk_widget_set_sensitive ( type ( c ) - > widget , TRUE ) ; \
2016-04-25 15:45:49 -05:00
}
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultDisable(type) \
2016-04-25 15:45:49 -05:00
static void type # # Disable ( uiControl * c ) \
2015-08-27 11:29:19 -05:00
{ \
2016-04-25 18:45:05 -05:00
gtk_widget_set_sensitive ( type ( c ) - > widget , FALSE ) ; \
2015-08-27 11:29:19 -05:00
}
2016-06-09 17:57:58 -05:00
// TODO this whole addedBefore stuff is a MASSIVE HACK.
2016-04-25 18:45:05 -05:00
# define uiUnixControlDefaultSetContainer(type) \
2016-04-25 18:16:48 -05:00
static void type # # SetContainer ( uiUnixControl * c , GtkContainer * container , gboolean remove ) \
2016-04-25 15:45:49 -05:00
{ \
2016-04-25 18:16:48 -05:00
if ( ! uiUnixControl ( c ) - > addedBefore ) { \
2016-04-25 18:45:05 -05:00
g_object_ref_sink ( type ( c ) - > widget ) ; /* our own reference, which we release in Destroy() */ \
2017-06-06 15:20:58 -05:00
/* massive hack notes: without any of this, nothing gets shown when we show a window; without the if, all things get shown even if some were explicitly hidden (TODO why don't we just show everything except windows on create? */ \
2017-06-06 15:19:08 -05:00
/*TODO*/ if ( ! uiUnixControl ( c ) - > explicitlyHidden ) gtk_widget_show ( type ( c ) - > widget ) ; \
2016-04-25 18:16:48 -05:00
uiUnixControl ( c ) - > addedBefore = TRUE ; \
} \
if ( remove ) \
2016-04-25 18:45:05 -05:00
gtk_container_remove ( container , type ( c ) - > widget ) ; \
2016-04-25 15:45:49 -05:00
else \
2016-04-25 18:45:05 -05:00
gtk_container_add ( container , type ( c ) - > widget ) ; \
2016-04-25 15:45:49 -05:00
}
2016-04-25 18:45:05 -05:00
# define uiUnixControlAllDefaultsExceptDestroy(type) \
uiUnixControlDefaultHandle ( type ) \
uiUnixControlDefaultParent ( type ) \
uiUnixControlDefaultSetParent ( type ) \
uiUnixControlDefaultToplevel ( type ) \
uiUnixControlDefaultVisible ( type ) \
uiUnixControlDefaultShow ( type ) \
uiUnixControlDefaultHide ( type ) \
uiUnixControlDefaultEnabled ( type ) \
uiUnixControlDefaultEnable ( type ) \
uiUnixControlDefaultDisable ( type ) \
uiUnixControlDefaultSetContainer ( type )
2015-08-27 11:29:19 -05:00
2016-04-25 18:45:05 -05:00
# define uiUnixControlAllDefaults(type) \
uiUnixControlDefaultDestroy ( type ) \
uiUnixControlAllDefaultsExceptDestroy ( type )
2015-08-27 11:29:19 -05:00
2016-04-24 15:59:46 -05:00
// TODO document
2016-04-25 15:45:49 -05:00
# define uiUnixNewControl(type, var) \
var = type ( uiUnixAllocControl ( sizeof ( type ) , type # # Signature , # type ) ) ; \
uiControl ( var ) - > Destroy = type # # Destroy ; \
uiControl ( var ) - > Handle = type # # Handle ; \
uiControl ( var ) - > Parent = type # # Parent ; \
uiControl ( var ) - > SetParent = type # # SetParent ; \
uiControl ( var ) - > Toplevel = type # # Toplevel ; \
uiControl ( var ) - > Visible = type # # Visible ; \
uiControl ( var ) - > Show = type # # Show ; \
uiControl ( var ) - > Hide = type # # Hide ; \
uiControl ( var ) - > Enabled = type # # Enabled ; \
uiControl ( var ) - > Enable = type # # Enable ; \
uiControl ( var ) - > Disable = type # # Disable ; \
2016-04-25 18:16:48 -05:00
uiUnixControl ( var ) - > SetContainer = type # # SetContainer ;
2016-04-25 15:45:49 -05:00
// TODO document
_UI_EXTERN uiUnixControl * uiUnixAllocControl ( size_t n , uint32_t typesig , const char * typenamestr ) ;
2015-08-27 11:29:19 -05:00
// uiUnixStrdupText() takes the given string and produces a copy of it suitable for being freed by uiFreeText().
2015-11-17 09:46:58 -06:00
_UI_EXTERN char * uiUnixStrdupText ( const char * ) ;
2015-08-27 11:29:19 -05:00
2015-11-16 09:55:44 -06:00
# ifdef __cplusplus
}
# endif
2015-08-27 11:29:19 -05:00
# endif