func loadHtmlString(webview *C.GtkWidget, content, base_uri string) { pcontent := C.CString(content) defer C.free_string(pcontent) pbase_uri := C.CString(base_uri) defer C.free_string(pbase_uri) C.loadHtmlString(webview, C.to_gcharptr(pcontent), C.to_gcharptr(pbase_uri)) }
func (v *WebKitWebView) LoadHtmlString(content, base_uri string) { pcontent := C.CString(content) defer C.free_string(pcontent) pbase_uri := C.CString(base_uri) defer C.free_string(pbase_uri) C.webkit_web_view_load_html_string(v.getWebView(), C.to_gcharptr(pcontent), C.to_gcharptr(pbase_uri)) }
func startGui(width, height int, title string, port int) { C.gtk_init(nil, nil) //gtk.Init(nil) window := C.window window = C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL) C.gtk_window_set_title(C.to_GtkWindow(window), C.to_gcharptr(C.CString(title))) C.connect_destroy(window) vbox := C.gtk_hbox_new(0, 1) C.webview = C._new_webkit() C.gtk_container_add(C.to_GtkContainer(vbox), C.webview) C.loadUri(C.webview, C.to_gcharptr(C.CString(fmt.Sprintf("http://127.0.0.1:%d", port)))) C.gtk_container_add(C.to_GtkContainer(window), vbox) C.gtk_widget_set_size_request(window, C.gint(width), C.gint(height)) C.gtk_widget_show(vbox) C.gtk_widget_show(window) //Window.ShowAll() C.gtk_widget_show(C.webview) /* This only matters if proxy is stupid! proxy := os.Getenv("HTTP_PROXY") if len(proxy) > 0 { ptr := C.CString(uri) C.proxyshit(ptr) C.free(ptr) } */ C.gtk_main() //gtk.GtkMain() }
// void webkit_web_frame_load_alternate_string(WebKitWebFrame *frame, const gchar *content, const gchar *base_url, const gchar *unreachable_url); // void webkit_web_frame_load_request(WebKitWebFrame *frame, WebKitNetworkRequest *request); func (v *WebKitWebFrame) LoadString(content, mime_type, encoding, base_uri string) { pcontent := C.CString(content) defer C.free_string(pcontent) pmime_type := C.CString(mime_type) defer C.free_string(pmime_type) pencoding := C.CString(encoding) defer C.free_string(pencoding) pbase_uri := C.CString(base_uri) defer C.free_string(pbase_uri) C.webkit_web_frame_load_string(v.getWebFrame(), C.to_gcharptr(pcontent), C.to_gcharptr(pmime_type), C.to_gcharptr(pencoding), C.to_gcharptr(pbase_uri)) }
func (v *GObject) Set(name string, value interface{}) { ptr := C.CString(name) defer C.free_string(ptr) if _, ok := value.(WrappedObject); ok { value = value.(WrappedObject).GetInternalValue() } if _, ok := value.(GObject); ok { value = value.(GObject).Object } if _, ok := value.(GValue); ok { value = value.(GValue).Value } switch value.(type) { case bool: bval := bool2gboolean(value.(bool)) C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&bval)) case byte: bval := C.gchar(value.(byte)) C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&bval)) //C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.gchar(value.(byte))).UnsafeAddr())) case int: ival := C.int(value.(int)) C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&ival)) case uint: uval := C.guint(value.(uint)) C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&uval)) //C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.guint(value.(uint))).UnsafeAddr())) case float32: f32val := C.gfloat(value.(float32)) C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&f32val)) //C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.gfloat(value.(float64))).UnsafeAddr())) case float64: f64val := C.gfloat(value.(float64)) C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&f64val)) //C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.gfloat(value.(float64))).UnsafeAddr())) case string: pval := C.CString(value.(string)) defer C.free_string(pval) C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&pval)) default: if pv, ok := value.(*[0]uint8); ok { C._g_object_set_ptr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(pv)) } else { av := reflect.ValueOf(value) if av.CanAddr() { C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(value).UnsafeAddr())) } else { C._g_object_set_ptr(C.gpointer(v.Object), C.to_gcharptr(ptr), value.(unsafe.Pointer)) } } } }
func FilenameToUri(filename string, hostname string) (uri string, err error) { pfilename := C.CString(filename) defer C.free_string(pfilename) phostname := C.CString(hostname) defer C.free_string(phostname) var gerror *C.GError uri = C.GoString(C.to_charptr(C.g_filename_to_uri(C.to_gcharptr(pfilename), C.to_gcharptr(phostname), &gerror))) if unsafe.Pointer(gerror) != nil { err = ErrorFromNative(unsafe.Pointer(gerror)) } else { err = nil } return }
func Color(name string) *GdkColor { var color C.GdkColor ptr := C.CString(name) defer C.free_string(ptr) C.gdk_color_parse(C.to_gcharptr(ptr), &color) return &GdkColor{color} }
func (v *WebView) LoadUri(uri string) { ptr := C.CString(uri) defer C.free_string(ptr) C.webkit_web_view_load_uri( v.getWebView(), C.to_gcharptr(ptr)) }
func (v *WebFrame) LoadUri(uri string) { ptr := C.CString(uri) defer C.free_string(ptr) C.webkit_web_frame_load_uri( v.getWebFrame(), C.to_gcharptr(ptr)) }
func (nr *WebKitNetworkRequest) SetURL(url string) { ptr := C.CString(url) defer C.free_string(ptr) C.webkit_network_request_set_uri( (*C.WebKitNetworkRequest)(nr.GObject.Object), C.to_gcharptr(ptr)) }
func (v *WebView) SetCustomEncoding(encoding string) { pencoding := C.CString(encoding) defer C.free_string(pencoding) C.webkit_web_view_set_custom_encoding( v.getWebView(), C.to_gcharptr(pencoding)) }
func (v *WebView) ExecuteScript(script string) { pscript := C.CString(script) defer C.free_string(pscript) C.webkit_web_view_execute_script( v.getWebView(), C.to_gcharptr(pscript)) }
func (v *WebView) Open(uri string) { ptr := C.CString(uri) defer C.free_string(ptr) C.webkit_web_view_open( v.getWebView(), C.to_gcharptr(ptr)) }
func (v *GObject) SignalConnect(s string, f interface{}, data interface{}, flags ConnectFlags) int { ctx := &CallbackContext{reflect.ValueOf(f), nil, reflect.ValueOf(v), reflect.ValueOf(data)} ptr := C.CString(s) defer C.free_string(ptr) id := callback_contexts.Add(ctx) ctx.cbi = unsafe.Pointer(C._g_signal_connect(unsafe.Pointer(v.Object), C.to_gcharptr(ptr), C.int(id), C.int(flags))) return id }
func GetFileInfo(path string, imgW *int, imgH *int) *GdkPixbufFormat { ptr := C.CString(path) defer C.free_string(ptr) var w, h C.gint format := &GdkPixbufFormat{C.gdk_pixbuf_get_file_info(C.to_gcharptr(ptr), &w, &h)} *imgW = int(w) *imgH = int(h) return format }
func (spell *GtkSpellChecker) SetLanguage(language string) *glib.Error { lang := C.CString(language) defer C.free(unsafe.Pointer(lang)) var gerror *C.GError if C.gtk_spell_checker_set_language(spell.Spell, C.to_gcharptr(lang), &gerror) == 0 { return glib.ErrorFromNative(unsafe.Pointer(gerror)) } return nil }
func (v *GtkSourceLanguageManager) SetSearchPath(paths []string) { cpaths := C.make_strings(C.int(len(paths) + 1)) for i, path := range paths { ptr := C.CString(path) defer C.free_string(ptr) C.set_string(cpaths, C.int(i), C.to_gcharptr(ptr)) } C.set_string(cpaths, C.int(len(paths)), nil) C.gtk_source_language_manager_set_search_path(v.LanguageManager, cpaths) C.destroy_strings(cpaths) }
func (spell *GtkSpell) SetLanguage(language string) *glib.Error { lang := C.CString(language) defer C.free(unsafe.Pointer(lang)) var gerror *C.GError C.gtkspell_set_language(spell.Spell, C.to_gcharptr(lang), &gerror) if gerror != nil { return glib.ErrorFromNative(unsafe.Pointer(gerror)) } return nil }
func (v *GObject) Connect(s string, f interface{}, datas ...interface{}) { var data interface{} if len(datas) > 0 { data = datas[0] } ctx := &CallbackContext{f, nil, reflect.ValueOf(v), reflect.ValueOf(data)} ptr := C.CString(s) defer C.free_string(ptr) ctx.cbi = unsafe.Pointer(C._g_signal_connect(unsafe.Pointer(v.Object), C.to_gcharptr(ptr), C.int(len(callback_contexts)))) callback_contexts = append(callback_contexts, ctx) }
// Return the handler call_id to use with HandlerBlock, HandlerUnblock and // HandlerDisconnect. // func (v *GObject) Connect(s string, f interface{}, datas ...interface{}) int { var data interface{} if len(datas) > 0 { data = datas[0] } ctx := &CallbackContext{reflect.ValueOf(f), nil, reflect.ValueOf(v), reflect.ValueOf(data)} ptr := C.CString(s) defer C.free_string(ptr) id := callback_contexts.Add(ctx) ctx.cbi = unsafe.Pointer(C._g_signal_connect(unsafe.Pointer(v.Object), C.to_gcharptr(ptr), C.int(id))) return id }
func New(textview *gtk.GtkTextView, language string) (*GtkSpell, *glib.Error) { var lang *C.char if len(language) > 0 { lang = C.CString(language) defer C.free(unsafe.Pointer(lang)) } var gerror *C.GError v := C.gtkspell_new_attach(C.to_GtkTextView(unsafe.Pointer(textview.Widget)), C.to_gcharptr(lang), &gerror) if gerror != nil { return nil, glib.ErrorFromNative(unsafe.Pointer(gerror)) } return &GtkSpell{v}, nil }
//----------------------------------------------------------------------- // GValue //----------------------------------------------------------------------- func GValueFromNative(value interface{}) *C.GValue { var gv *C.GValue if _, ok := value.(WrappedObject); ok { value = value.(WrappedObject).GetInternalValue() } if _, ok := value.(GObject); ok { value = value.(GObject).Object } if _, ok := value.(GValue); ok { value = value.(GValue).Value } switch value.(type) { case bool: gv = C.init_gvalue_bool(gbool(value.(bool))) break case byte: gv = C.init_gvalue_byte(C.guchar(value.(byte))) break case int: gv = C.init_gvalue_int(C.gint(value.(int))) break case uint: gv = C.init_gvalue_uint(C.guint(value.(uint))) break case int64: gv = C.init_gvalue_int64(C.gint64(value.(int64))) break case float32: gv = C.init_gvalue_double(C.gdouble(value.(float32))) break case float64: gv = C.init_gvalue_double(C.gdouble(value.(float64))) break case string: { pval := C.CString(value.(string)) defer C.free_string(pval) gv = C.init_gvalue_string(C.to_gcharptr(pval)) } break default: //gv = C.init_gvalue_pointer(C.gpointer(unsafe.Pointer(&value))); break } return gv }
func (v *DOMDocument) GetElementsByTagName(tagName string) []*DOMNode { CtagName := C.CString(tagName) defer C.free_string(CtagName) GtagName := C.to_gcharptr(CtagName) list := C.webkit_dom_document_get_elements_by_tag_name(v.getDOMDocument(), GtagName) length := C.webkit_dom_node_list_get_length(list) //log.Fatal(length) nodes := []*DOMNode{} for i := C.gulong(0); i < length; i++ { domNode := &DOMNode{glib.GObject{unsafe.Pointer(C.webkit_dom_node_list_item(list, C.gulong(i)))}} nodes = append(nodes, domNode) } return nodes }
func FilenameFromUri(uri string) (filename string, hostname string, err error) { str := C.CString(uri) defer C.free_string(str) var gerror *C.GError var ptr *C.gchar filename = C.GoString(C.to_charptr(C.g_filename_from_uri(C.to_gcharptr(str), &ptr, &gerror))) if unsafe.Pointer(gerror) != nil { err = ErrorFromNative(unsafe.Pointer(gerror)) } else { err = nil } hostname = "" if ptr != nil { hostname = C.GoString(C.to_charptr(ptr)) } return }
func (v *GObject) Set(name string, value interface{}) { ptr := C.CString(name) defer C.free_string(ptr) if _, ok := value.(WrappedObject); ok { value = value.(WrappedObject).GetInternalValue() } if _, ok := value.(GObject); ok { value = value.(GObject).Object } if _, ok := value.(GValue); ok { value = value.(GValue).Value } switch value.(type) { case bool: C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.NewValue(bool2gboolean(value.(bool))).Addr())) break case byte: C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.NewValue(C.gchar(value.(byte))).Addr())) break case int: C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.NewValue(C.gint(value.(int))).Addr())) break case uint: C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.NewValue(C.guint(value.(uint))).Addr())) break case float: C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.NewValue(C.gfloat(value.(float))).Addr())) break case string: { pval := C.CString(value.(string)) defer C.free_string(pval) C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.NewValue(pval).Addr())) } break default: C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.NewValue(value).Addr())) break } }
//WEBKIT_API void webkit_web_view_load_request (WebKitWebView *web_view, WebKitNetworkRequest *request); func (v *WebKitWebView) SearchText(text string, case_sensitive bool, forward bool, wrap bool) bool { ptext := C.CString(text) defer C.free_string(ptext) return gboolean2bool(C.webkit_web_view_search_text(v.getWebView(), C.to_gcharptr(ptext), bool2gboolean(case_sensitive), bool2gboolean(forward), bool2gboolean(wrap))) }
func (v *GObject) Emit(s string) { ptr := C.CString(s) defer C.free_string(ptr) C._g_signal_emit_by_name((C.gpointer)(v.Object), C.to_gcharptr(ptr)) }
func (v *GObject) StopEmission(s string) { ptr := C.CString(s) defer C.free_string(ptr) C.g_signal_stop_emission_by_name((C.gpointer)(v.Object), C.to_gcharptr(ptr)) }
func (v *GObject) SetProperty(name string, val *GValue) { str := C.CString(name) defer C.free_string(str) C.g_object_set_property(C.to_GObject(v.Object), C.to_gcharptr(str), &val.Value) }
//----------------------------------------------------------------------- // Application //----------------------------------------------------------------------- func SetApplicationName(name string) { str := C.CString(name) defer C.free_string(str) C.g_set_application_name(C.to_gcharptr(str)) }