| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package gtk |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
import "C" |
| 10 |
|
| 11 |
import ( |
| 12 |
"unsafe" |
| 13 |
|
| 14 |
"github.com/gotk3/gotk3/glib" |
| 15 |
) |
| 16 |
|
| 17 |
func init() { |
| 18 |
tm := []glib.TypeMarshaler{ |
| 19 |
|
| 20 |
{glib.Type(C.gtk_popover_constraint_get_type()), marshalPopoverConstraint}, |
| 21 |
} |
| 22 |
glib.RegisterGValueMarshalers(tm) |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
type PopoverConstraint int |
| 31 |
|
| 32 |
const ( |
| 33 |
POPOVER_CONSTRAINT_NONE PopoverConstraint = C.GTK_POPOVER_CONSTRAINT_NONE |
| 34 |
POPOVER_CONSTRAINT_WINDOW PopoverConstraint = C.GTK_POPOVER_CONSTRAINT_WINDOW |
| 35 |
) |
| 36 |
|
| 37 |
func marshalPopoverConstraint(p uintptr) (interface{}, error) { |
| 38 |
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) |
| 39 |
return PopoverConstraint(c), nil |
| 40 |
} |
| 41 |
|
| 42 |
const ( |
| 43 |
STATE_FLAG_DROP_ACTIVE StateFlags = C.GTK_STATE_FLAG_DROP_ACTIVE |
| 44 |
) |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
type NativeDialog struct { |
| 52 |
glib.InitiallyUnowned |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
func (v *NativeDialog) native() *C.GtkNativeDialog { |
| 57 |
if v == nil || v.GObject == nil { |
| 58 |
return nil |
| 59 |
} |
| 60 |
p := unsafe.Pointer(v.GObject) |
| 61 |
return C.toGtkNativeDialog(p) |
| 62 |
} |
| 63 |
|
| 64 |
func wrapNativeDialog(obj *glib.Object) *NativeDialog { |
| 65 |
if obj == nil { |
| 66 |
return nil |
| 67 |
} |
| 68 |
|
| 69 |
return &NativeDialog{glib.InitiallyUnowned{obj}} |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
func (v *NativeDialog) Run() int { |
| 74 |
c := C.gtk_native_dialog_run(v.native()) |
| 75 |
return int(c) |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
func (v *NativeDialog) Destroy() { |
| 80 |
C.gtk_native_dialog_destroy(v.native()) |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
func (v *NativeDialog) SetModal(modal bool) { |
| 85 |
C.gtk_native_dialog_set_modal(v.native(), gbool(modal)) |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
func (v *NativeDialog) GetModal() bool { |
| 90 |
c := C.gtk_native_dialog_get_modal(v.native()) |
| 91 |
return gobool(c) |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
func (v *NativeDialog) SetTitle(title string) { |
| 96 |
cstr := C.CString(title) |
| 97 |
defer C.free(unsafe.Pointer(cstr)) |
| 98 |
C.gtk_native_dialog_set_title(v.native(), (*C.char)(cstr)) |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
func (v *NativeDialog) GetTitle() (string, error) { |
| 103 |
return stringReturn((*C.gchar)(C.gtk_native_dialog_get_title(v.native()))) |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
func (v *NativeDialog) SetTransientFor(parent IWindow) { |
| 108 |
var pw *C.GtkWindow = nil |
| 109 |
if parent != nil { |
| 110 |
pw = parent.toWindow() |
| 111 |
} |
| 112 |
C.gtk_native_dialog_set_transient_for(v.native(), pw) |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
func (v *NativeDialog) GetTransientFor() (*Window, error) { |
| 117 |
c := C.gtk_native_dialog_get_transient_for(v.native()) |
| 118 |
if c == nil { |
| 119 |
return nil, nilPtrErr |
| 120 |
} |
| 121 |
return wrapWindow(glib.Take(unsafe.Pointer(c))), nil |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
func (v *NativeDialog) GetVisible() bool { |
| 126 |
c := C.gtk_native_dialog_get_visible(v.native()) |
| 127 |
return gobool(c) |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
func (v *NativeDialog) Show() { |
| 132 |
C.gtk_native_dialog_show(v.native()) |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
func (v *NativeDialog) Hide() { |
| 137 |
C.gtk_native_dialog_hide(v.native()) |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
type FileChooserNativeDialog struct { |
| 146 |
NativeDialog |
| 147 |
|
| 148 |
|
| 149 |
FileChooser |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
func (v *FileChooserNativeDialog) native() *C.GtkFileChooserNative { |
| 154 |
if v == nil || v.GObject == nil { |
| 155 |
return nil |
| 156 |
} |
| 157 |
p := unsafe.Pointer(v.GObject) |
| 158 |
return C.toGtkFileChooserNative(p) |
| 159 |
} |
| 160 |
|
| 161 |
func wrapFileChooserNativeDialog(obj *glib.Object) *FileChooserNativeDialog { |
| 162 |
if obj == nil { |
| 163 |
return nil |
| 164 |
} |
| 165 |
|
| 166 |
fc := wrapFileChooser(obj) |
| 167 |
return &FileChooserNativeDialog{NativeDialog{glib.InitiallyUnowned{obj}}, *fc} |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
func FileChooserNativeDialogNew(title string, parent IWindow, action FileChooserAction, |
| 172 |
accept_label string, cancel_label string) (*FileChooserNativeDialog, error) { |
| 173 |
|
| 174 |
c_title := C.CString(title) |
| 175 |
defer C.free(unsafe.Pointer(c_title)) |
| 176 |
|
| 177 |
c_accept_label := C.CString(accept_label) |
| 178 |
defer C.free(unsafe.Pointer(c_accept_label)) |
| 179 |
|
| 180 |
c_cancel_label := C.CString(cancel_label) |
| 181 |
defer C.free(unsafe.Pointer(c_cancel_label)) |
| 182 |
|
| 183 |
var w *C.GtkWindow = nil |
| 184 |
if parent != nil { |
| 185 |
w = parent.toWindow() |
| 186 |
} |
| 187 |
|
| 188 |
c := C.gtk_file_chooser_native_new( |
| 189 |
(*C.gchar)(c_title), w, C.GtkFileChooserAction(action), |
| 190 |
(*C.gchar)(c_accept_label), (*C.gchar)(c_cancel_label)) |
| 191 |
if c == nil { |
| 192 |
return nil, nilPtrErr |
| 193 |
} |
| 194 |
obj := glib.Take(unsafe.Pointer(c)) |
| 195 |
return wrapFileChooserNativeDialog(obj), nil |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
func OpenFileChooserNative(title string, parent IWindow) *string { |
| 202 |
c_title := C.CString(title) |
| 203 |
|
| 204 |
var native *C.GtkFileChooserNative |
| 205 |
|
| 206 |
var w *C.GtkWindow = nil |
| 207 |
if parent != nil { |
| 208 |
w = parent.toWindow() |
| 209 |
} |
| 210 |
|
| 211 |
native = C.gtk_file_chooser_native_new((*C.gchar)(c_title), |
| 212 |
w, |
| 213 |
C.GtkFileChooserAction(FILE_CHOOSER_ACTION_OPEN), |
| 214 |
(*C.gchar)(C.CString("_Open")), |
| 215 |
(*C.gchar)(C.CString("_Cancel"))) |
| 216 |
|
| 217 |
p := unsafe.Pointer(unsafe.Pointer(native)) |
| 218 |
dlg := C.toGtkNativeDialog(p) |
| 219 |
res := C.gtk_native_dialog_run(dlg) |
| 220 |
|
| 221 |
if res == C.GTK_RESPONSE_ACCEPT { |
| 222 |
c := C.gtk_file_chooser_get_filename(C.toGtkFileChooser(p)) |
| 223 |
s := goString(c) |
| 224 |
defer C.g_free((C.gpointer)(c)) |
| 225 |
|
| 226 |
return &s |
| 227 |
} |
| 228 |
|
| 229 |
return nil |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
func (v *FileChooserNativeDialog) SetAcceptLabel(accept_label string) { |
| 234 |
cstr := C.CString(accept_label) |
| 235 |
defer C.free(unsafe.Pointer(cstr)) |
| 236 |
C.gtk_file_chooser_native_set_accept_label(v.native(), (*C.char)(cstr)) |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
func (v *FileChooserNativeDialog) GetAcceptLabel() (string, error) { |
| 241 |
return stringReturn((*C.gchar)(C.gtk_file_chooser_native_get_accept_label(v.native()))) |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
func (v *FileChooserNativeDialog) SetCancelLabel(cancel_label string) { |
| 246 |
cstr := C.CString(cancel_label) |
| 247 |
defer C.free(unsafe.Pointer(cstr)) |
| 248 |
C.gtk_file_chooser_native_set_cancel_label(v.native(), (*C.char)(cstr)) |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
func (v *FileChooserNativeDialog) GetCancelLabel() (string, error) { |
| 253 |
return stringReturn((*C.gchar)(C.gtk_file_chooser_native_get_cancel_label(v.native()))) |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
func (v *Popover) SetConstrainTo(constrain PopoverConstraint) { |
| 277 |
C.gtk_popover_set_constrain_to(v.native(), C.GtkPopoverConstraint(constrain)) |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
func (v *Popover) GetConstrainTo() PopoverConstraint { |
| 282 |
return PopoverConstraint(C.gtk_popover_get_constrain_to(v.native())) |
| 283 |
} |