Codebase list golang-github-mattn-go-gtk / e89904c
Import upstream version 0.1+git20191030.af2e013 Debian Janitor 2 years ago
3 changed file(s) with 147 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
1717
1818 git clone https://github.com/mattn/go-gtk
1919 cd go-gtk
20 go get ...
2021 make example
2122 ./example/demo/demo
2223
174174 func AS_GWIDGET(p unsafe.Pointer) *C.GtkWidget { return C.toGWidget(p) }
175175 func UI_MANAGER(p *UIManager) *C.GtkUIManager { return C.toGUIManager(p.Object) }
176176 func FONT_SELECTION(p *FontSelection) *C.GtkFontSelection { return C.toGFontSelection(p.GWidget) }
177
178 func CALENDAR(p *Calendar) *C.GtkCalendar { return C.toGCalendar(p.GWidget) }
177179
178180 //static inline GtkFileFilter* toGFileFilter(gpointer p) { return GTK_FILE_FILTER(p); }
179181
11471149 //-----------------------------------------------------------------------
11481150 // Version Information
11491151 //-----------------------------------------------------------------------
1150
1151 // gtk_major_version
1152 // gtk_minor_version
1153 // gtk_micro_version
1154 // gtk_binary_age
1155 // gtk_interface_age
1156 // gtk_check_version
1152 func MajorVersion() uint {
1153 return uint(C.gtk_major_version)
1154 }
1155
1156 func MinorVersion() uint {
1157 return uint(C.gtk_minor_version)
1158 }
1159
1160 func MicroVersion() uint {
1161 return uint(C.gtk_micro_version)
1162 }
1163
1164 func BinaryAge() uint {
1165 return uint(C.gtk_binary_age)
1166 }
1167
1168 func InterfaceAge() uint {
1169 return uint(C.gtk_interface_age)
1170 }
1171
1172 func CheckVersion(major uint, minor uint, micro uint) string {
1173 return gostring(C.gtk_check_version(guint(major), guint(minor), guint(micro)))
1174 }
11571175
11581176 //-----------------------------------------------------------------------
11591177 // Testing
42064224 C.gtk_text_buffer_remove_all_tags(v.GTextBuffer, &start.GTextIter, &end.GTextIter)
42074225 }
42084226
4209 func (v *TextBuffer) CreateTag(tag_name string, props map[string]string) *TextTag {
4227 func (v *TextBuffer) CreateTag(tag_name string, props map[string]interface{}) *TextTag {
4228 toInt := func(val interface{}) int {
4229 switch v := val.(type) {
4230 case uint:
4231 return int(v)
4232 case uintptr:
4233 return int(v)
4234 case uint8:
4235 return int(v)
4236 case uint16:
4237 return int(v)
4238 case uint32:
4239 return int(v)
4240 case uint64:
4241 return int(v)
4242 case int:
4243 return int(v)
4244 case int8:
4245 return int(v)
4246 case int16:
4247 return int(v)
4248 case int32:
4249 return int(v)
4250 case int64:
4251 return int(v)
4252 }
4253 return 0
4254 }
4255 toFloat := func(val interface{}) float64 {
4256 switch v := val.(type) {
4257 case float32:
4258 return float64(v)
4259 case float64:
4260 return float64(v)
4261 }
4262 return 0
4263 }
42104264 ptr := C.CString(tag_name)
42114265 defer cfree(ptr)
42124266 tag := C._gtk_text_buffer_create_tag(v.GTextBuffer, gstring(ptr))
42134267 for prop, val := range props {
42144268 pprop := C.CString(prop)
4215 pval := C.CString(val)
4216 C._apply_property(unsafe.Pointer(tag), gstring(pprop), gstring(pval))
4269 switch v := val.(type) {
4270 case bool:
4271 C._apply_property_bool(unsafe.Pointer(tag), gstring(pprop), gbool(v))
4272 case uint, uintptr, uint8, uint16, uint32, uint64, int, int8, int16, int32, int64:
4273 C._apply_property_int(unsafe.Pointer(tag), gstring(pprop), gint(toInt(v)))
4274 case float32, float64:
4275 C._apply_property_float(unsafe.Pointer(tag), gstring(pprop), gdouble(toFloat(v)))
4276 case string:
4277 pval := C.CString(v)
4278 C._apply_property_string(unsafe.Pointer(tag), gstring(pprop), gstring(pval))
4279 cfree(pval)
4280 }
42174281 cfree(pprop)
4218 cfree(pval)
42194282 }
42204283 return newTextTag(tag)
42214284 }
97769839 // GtkCalendar
97779840 //-----------------------------------------------------------------------
97789841
9779 // gtk_calendar_new
9842 type Calendar struct {
9843 Container
9844 }
9845
9846 func NewCalendar() *Calendar {
9847 return &Calendar{Container{Widget{C.gtk_calendar_new()}}}
9848 }
9849
97809850 // gtk_calendar_select_month
97819851 // gtk_calendar_select_day
97829852 // gtk_calendar_mark_day
97849854 // gtk_calendar_clear_marks
97859855 // gtk_calendar_get_display_options
97869856 // gtk_calendar_set_display_options
9787 // gtk_calendar_get_date
9857
9858 func (c *Calendar) GetDate() (year, month, date uint) {
9859 var y, m, d C.guint
9860 C.gtk_calendar_get_date(CALENDAR(c), &y, &m, &d)
9861 return uint(y), uint(m), uint(d)
9862 }
9863
97889864 // gtk_calendar_set_detail_func
97899865 // gtk_calendar_get_detail_width_chars
97909866 // gtk_calendar_set_detail_width_chars
1020510281
1020610282 // gtk_container_resize_children
1020710283 // gtk_container_child_type
10208 // gtk_container_child_get
10284
10285 // value must be pointer to int or bool
10286 func (v *Container) ChildGet(w IWidget, propName string, value interface{}) {
10287
10288 ptr := C.CString(propName)
10289 defer cfree(ptr)
10290
10291 switch value.(type) {
10292 case *bool:
10293 *(value.(*bool)) = int(C._gtk_container_child_get_bool(CONTAINER(v), ToNative(w), gstring(ptr))) != 0
10294 case *int:
10295 *(value.(*int)) = int(C._gtk_container_child_get_int(CONTAINER(v), ToNative(w), gstring(ptr)))
10296 }
10297 }
1020910298
1021010299 func (v *Container) ChildSet(w IWidget, propName string, value interface{}) {
1021110300
9696 *one = *two;
9797 }
9898
99 static void _apply_property(void* obj, const gchar* prop, const gchar* val) {
100 GParamSpec *pspec;
101 GValue fromvalue = { 0, };
102 GValue tovalue = { 0, };
103 pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(obj), prop);
104 if (!pspec) return;
105 g_value_init(&fromvalue, G_TYPE_STRING);
106 g_value_set_string(&fromvalue, val);
107 g_value_init(&tovalue, G_PARAM_SPEC_VALUE_TYPE(pspec));
108 g_value_transform(&fromvalue, &tovalue);
109 g_object_set_property((GObject *)obj, prop, &tovalue);
110 g_value_unset(&fromvalue);
111 g_value_unset(&tovalue);
99 static void _apply_property_bool(void* obj, const gchar* prop, const gboolean val) {
100 GValue value = { 0, };
101 g_value_init(&value, G_TYPE_BOOLEAN);
102 g_value_set_boolean(&value, val);
103 g_object_set_property((GObject *)obj, prop, &value);
104 g_value_unset(&value);
105 }
106
107 static void _apply_property_int(void* obj, const gchar* prop, const gint val) {
108 GValue value = { 0, };
109 g_value_init(&value, G_TYPE_INT);
110 g_value_set_int(&value, val);
111 g_object_set_property((GObject *)obj, prop, &value);
112 g_value_unset(&value);
113 }
114
115 static void _apply_property_float(void* obj, const gchar* prop, const gdouble val) {
116 GValue value = { 0, };
117 g_value_init(&value, G_TYPE_DOUBLE);
118 g_value_set_double(&value, val);
119 g_object_set_property((GObject *)obj, prop, &value);
120 g_value_unset(&value);
121 }
122
123 static void _apply_property_string(void* obj, const gchar* prop, const gchar* val) {
124 GValue value = { 0, };
125 g_value_init(&value, G_TYPE_STRING);
126 g_value_set_string(&value, val);
127 g_object_set_property((GObject *)obj, prop, &value);
128 g_value_unset(&value);
112129 }
113130
114131 static GtkTreeViewColumn* _gtk_tree_view_column_new_with_attribute(gchar* title, GtkCellRenderer* cell) {
229246 gtk_tree_selection_set_select_function(sel, _c_gtk_tree_selection_select_func, payload, NULL);
230247 }
231248
249 static gint _gtk_container_child_get_int(GtkContainer* container, GtkWidget* child, const gchar* propname) {
250 gint value;
251 gtk_container_child_get(container, child, propname, &value, NULL);
252 return value;
253 }
254
255 static gboolean _gtk_container_child_get_bool(GtkContainer* container, GtkWidget* child, const gchar* propname) {
256 gboolean value;
257 gtk_container_child_get(container, child, propname, &value, NULL);
258 return value;
259 }
260
232261 static void _gtk_container_child_set_bool(GtkContainer* container, GtkWidget* child, const gchar* propname, gboolean value) {
233262 gtk_container_child_set(container, child, propname, value, NULL);
234263 }
789818 //static inline char* toCstrU(const guchar* s) { return (char*)s; }
790819 //static inline char* toCstrV(const void* s) { return (char*)s; }
791820
821 static inline GtkCalendar* toGCalendar(GtkWidget* w) { return GTK_CALENDAR(w); }
792822 static inline GObject* toGObject(void* o) { return G_OBJECT(o); }
793823 static inline GValue* toGValue(void* s) { return (GValue*)s; }
794824 static inline GtkWindow* toGWindow(GtkWidget* w) { return GTK_WINDOW(w); }