adds vendor directory
vendors dependencies in standard `vendor` directory, managed by glide
This commit is contained in:
32
vendor/github.com/mattn/go-gtk/.gitignore
generated
vendored
Normal file
32
vendor/github.com/mattn/go-gtk/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
*~
|
||||
_obj
|
||||
*.cgo?.*
|
||||
_cgo_*
|
||||
main
|
||||
*.exe
|
||||
tags
|
||||
|
||||
# example binaries
|
||||
example/action/action
|
||||
example/alignment/alignment
|
||||
example/arrow/arrow
|
||||
example/builder/builder
|
||||
example/clipboard/clipboard
|
||||
example/demo/demo
|
||||
example/dnd/dnd
|
||||
example/drawable/drawable
|
||||
example/event/event
|
||||
example/expander/expander
|
||||
example/iconview/iconview
|
||||
example/listview/listview
|
||||
example/locale/locale
|
||||
example/notebook/notebook
|
||||
example/number/number
|
||||
example/sourceview/sourceview
|
||||
example/spinbutton/spinbutton
|
||||
example/statusicon/statusicon
|
||||
example/table/table
|
||||
example/thread/thread
|
||||
example/toolbar/toolbar
|
||||
example/treeview/treeview
|
||||
example/twitterstream/twitterstream
|
4
vendor/github.com/mattn/go-gtk/.gitmodules
generated
vendored
Normal file
4
vendor/github.com/mattn/go-gtk/.gitmodules
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[submodule "docs"]
|
||||
path = docs
|
||||
url = git@github.com:mattn/go-gtk.git
|
||||
branch = gh-pages
|
1
vendor/github.com/mattn/go-gtk/.test
generated
vendored
Executable file
1
vendor/github.com/mattn/go-gtk/.test
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
make example
|
28
vendor/github.com/mattn/go-gtk/Makefile
generated
vendored
Normal file
28
vendor/github.com/mattn/go-gtk/Makefile
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
include example/example.mk
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
.PHONY: all
|
||||
all:
|
||||
cd pango && go get -x
|
||||
cd glib && go get -x
|
||||
cd gdk && go get -x
|
||||
cd gdkpixbuf && go get -x
|
||||
cd gtk && go get -x
|
||||
cd gtksourceview && go get -x
|
||||
#cd gtkgl && go get -x .
|
||||
#cd gtkspell && go get -x .
|
||||
|
||||
.PHONY: all
|
||||
fmt:
|
||||
cd pango && go fmt .
|
||||
cd glib && go fmt .
|
||||
cd gdk && go fmt .
|
||||
cd gdkpixbuf && go fmt .
|
||||
cd gtk && go fmt .
|
||||
cd gtksourceview && go fmt .
|
||||
#cd gtkgl && go fmt .
|
||||
#cd gtkspell && go fmt .
|
||||
|
||||
.PHONY: clean
|
||||
clean: clean-example
|
||||
@true
|
259
vendor/github.com/mattn/go-gtk/README.md
generated
vendored
Normal file
259
vendor/github.com/mattn/go-gtk/README.md
generated
vendored
Normal file
@@ -0,0 +1,259 @@
|
||||
# go-gtk
|
||||
|
||||
## WHATS
|
||||
|
||||
Go bindings for GTK
|
||||
|
||||
## SCREENSHOT
|
||||
|
||||

|
||||
|
||||
## INSTALL
|
||||
|
||||
You can experiment with go-gtk
|
||||
by running the various example programs:
|
||||
|
||||
git clone https://github.com/mattn/go-gtk
|
||||
cd go-gtk
|
||||
make example
|
||||
./example/demo/demo
|
||||
|
||||
Or
|
||||
|
||||
go get github.com/mattn/go-gtk/gtk
|
||||
|
||||
Don't forget, that you need the GTK-Development-Packages.
|
||||
|
||||
If you use linux, you should install `libgtk+-2.0` and packages that depend on gtk.
|
||||
|
||||
On Debian and Debian derived distributions you can run (as root):
|
||||
|
||||
apt-get install libgtk2.0-dev libglib2.0-dev libgtksourceview2.0-dev
|
||||
|
||||
If you use windows, find gtk binary packages from here:
|
||||
|
||||
* http://www.gtk.org/download/windows.php
|
||||
|
||||
## LICENSE
|
||||
|
||||
The library is available under the same terms and conditions as the Go, the BSD style license, and the LGPL (GNU Lesser General Public License). The idea is that if you can use Go (and Gtk) in a project, you should also be able to use go-gtk.
|
||||
|
||||
## AUTHOR
|
||||
|
||||
* Yasuhiro Matsumoto
|
||||
|
||||
## CONTRIBUTE AUTHORS
|
||||
|
||||
* David Roundy
|
||||
* Mark Andrew Gerads
|
||||
* Tobias Kortkamp
|
||||
* Mikhail Trushnikov
|
||||
* Federico Sogaro
|
||||
* Crazy2be
|
||||
* Daniël de Kok
|
||||
* Erik Lissel
|
||||
* Jeffrey Bolle
|
||||
* Leonhard Küper
|
||||
* Matt Joiner
|
||||
* SQP
|
||||
* Steven T
|
||||
* Taru Karttunen
|
||||
* Utkan Güngördü
|
||||
* matiaslina
|
||||
* Dag Robøle
|
||||
* Denis Dyakov
|
||||
|
||||
## GOAL
|
||||
|
||||
Hopefully support following widgets and methods enough to run general application.
|
||||
|
||||
(output of tools/gogtkinfo)
|
||||
|
||||
Main Loop and Events : 30% ( 8/ 26)
|
||||
GtkAccelGroup : 15% ( 3/ 19)
|
||||
GtkAccelMap : 0% ( 0/ 14)
|
||||
GtkClipboard : 25% ( 8/ 31)
|
||||
Drag and Drop : 11% ( 4/ 35)
|
||||
GtkIconTheme : 0% ( 0/ 31)
|
||||
GtkStockItem : 66% ( 4/ 6)
|
||||
Themeable Stock Images : 0% ( 0/ 41)
|
||||
Resource Files : 14% ( 4/ 28)
|
||||
GtkSettings : 40% ( 6/ 15)
|
||||
GtkBinding : 0% ( 0/ 14)
|
||||
Graphics Contexts : 0% ( 0/ 2)
|
||||
GtkStyle : 9% ( 6/ 64)
|
||||
Selections : 8% ( 4/ 47)
|
||||
Version Information : 0% ( 0/ 6)
|
||||
Testing : 0% ( 0/ 16)
|
||||
Filesystem Utilities : 0% ( 0/ 7)
|
||||
GtkDialog : 45% ( 9/ 20)
|
||||
GtkMessageDialog : 62% ( 5/ 8)
|
||||
GtkWindow : 49% ( 50/102)
|
||||
GtkWindowGroup : 0% ( 0/ 5)
|
||||
GtkAboutDialog : 90% ( 29/ 32)
|
||||
GtkAssistant : 91% ( 21/ 23)
|
||||
GtkOffscreenWindow : 0% ( 0/ 3)
|
||||
GtkAccelLabel : 83% ( 5/ 6)
|
||||
GtkImage : 32% ( 10/ 31)
|
||||
GtkLabel : 86% ( 39/ 45)
|
||||
GtkProgressBar : 100% ( 12/ 12)
|
||||
GtkStatusbar : 77% ( 7/ 9)
|
||||
GtkInfoBar : 100% ( 12/ 12)
|
||||
GtkStatusIcon : 68% ( 26/ 38)
|
||||
GtkSpinner : 100% ( 3/ 3)
|
||||
GtkButton : 100% ( 28/ 28)
|
||||
GtkCheckButton : 100% ( 3/ 3)
|
||||
GtkRadioButton : 100% ( 8/ 8)
|
||||
GtkToggleButton : 100% ( 9/ 9)
|
||||
GtkLinkButton : 75% ( 6/ 8)
|
||||
GtkScaleButton : 100% ( 9/ 9)
|
||||
GtkVolumeButton : 100% ( 1/ 1)
|
||||
GtkEntry : 41% ( 26/ 63)
|
||||
GtkEntryBuffer : 72% ( 8/ 11)
|
||||
GtkEntryCompletion : 96% ( 25/ 26)
|
||||
GtkHScale : 100% ( 2/ 2)
|
||||
GtkVScale : 100% ( 2/ 2)
|
||||
GtkSpinButton : 100% ( 30/ 30)
|
||||
GtkEditable : 100% ( 13/ 13)
|
||||
GtkTextIter : 25% ( 23/ 91)
|
||||
GtkTextMark : 0% ( 0/ 7)
|
||||
GtkTextBuffer : 67% ( 52/ 77)
|
||||
GtkTextTag : 83% ( 5/ 6)
|
||||
GtkTextAttributes : 100% ( 5/ 5)
|
||||
GtkTextTagTable : 83% ( 5/ 6)
|
||||
GtkTextView : 29% ( 19/ 64)
|
||||
GtkTreePath : 90% ( 18/ 20)
|
||||
GtkTreeRowReference : 60% ( 6/ 10)
|
||||
GtkTreeIter : 100% ( 2/ 2)
|
||||
GtkTreeModel : 57% ( 15/ 26)
|
||||
GtkTreeSelection : 78% ( 18/ 23)
|
||||
GtkTreeViewColumn : 61% ( 34/ 55)
|
||||
GtkTreeView : 18% ( 18/ 98)
|
||||
GtkTreeView drag-and-drop : 0% ( 0/ 7)
|
||||
GtkCellView : 0% ( 0/ 11)
|
||||
GtkIconView : 17% ( 11/ 62)
|
||||
GtkTreeSortable : 62% ( 5/ 8)
|
||||
GtkTreeModelSort : 0% ( 0/ 9)
|
||||
GtkTreeModelFilter : 0% ( 0/ 11)
|
||||
GtkCellLayout : 0% ( 0/ 9)
|
||||
GtkCellRenderer : 100% ( 2/ 2)
|
||||
GtkCellEditable : 0% ( 0/ 3)
|
||||
GtkCellRendererAccel : 100% ( 1/ 1)
|
||||
GtkCellRendererCombo : 100% ( 1/ 1)
|
||||
GtkCellRendererPixbuf : 100% ( 1/ 1)
|
||||
GtkCellRendererProgress : 100% ( 1/ 1)
|
||||
GtkCellRendererSpin : 100% ( 1/ 1)
|
||||
GtkCellRendererText : 100% ( 2/ 2)
|
||||
GtkCellRendererToggle : 100% ( 7/ 7)
|
||||
GtkCellRendererSpinner : 100% ( 1/ 1)
|
||||
GtkListStore : 84% ( 16/ 19)
|
||||
GtkTreeStore : 80% ( 17/ 21)
|
||||
GtkComboBox : 78% ( 30/ 38)
|
||||
GtkComboBoxText : 100% ( 7/ 7)
|
||||
GtkComboBoxEntry : 80% ( 4/ 5)
|
||||
GtkMenu : 50% ( 15/ 30)
|
||||
GtkMenuBar : 100% ( 8/ 8)
|
||||
GtkMenuItem : 90% ( 18/ 20)
|
||||
GtkImageMenuItem : 54% ( 6/ 11)
|
||||
GtkRadioMenuItem : 44% ( 4/ 9)
|
||||
GtkCheckMenuItem : 100% ( 10/ 10)
|
||||
GtkSeparatorMenuItem : 100% ( 1/ 1)
|
||||
GtkTearoffMenuItem : 100% ( 1/ 1)
|
||||
GtkToolShell : 0% ( 0/ 9)
|
||||
GtkToolbar : 63% ( 24/ 38)
|
||||
GtkToolItem : 76% ( 19/ 25)
|
||||
GtkToolPalette : 59% ( 13/ 22)
|
||||
GtkToolItemGroup : 47% ( 8/ 17)
|
||||
GtkSeparatorToolItem : 100% ( 3/ 3)
|
||||
GtkToolButton : 100% ( 15/ 15)
|
||||
GtkMenuToolButton : 85% ( 6/ 7)
|
||||
GtkToggleToolButton : 100% ( 5/ 5)
|
||||
GtkRadioToolButton : 33% ( 2/ 6)
|
||||
GtkUIManager : 29% ( 5/ 17)
|
||||
GtkActionGroup : 55% ( 11/ 20)
|
||||
GtkAction : 93% ( 44/ 47)
|
||||
GtkToggleAction : 100% ( 6/ 6)
|
||||
GtkRadioAction : 100% ( 5/ 5)
|
||||
GtkRecentAction : 75% ( 3/ 4)
|
||||
GtkActivatable : 66% ( 4/ 6)
|
||||
GtkColorButton : 100% ( 10/ 10)
|
||||
GtkColorSelectionDialog : 0% ( 0/ 2)
|
||||
GtkColorSelection : 0% ( 0/ 21)
|
||||
GtkHSV : 0% ( 0/ 8)
|
||||
GtkFileChooser : 22% ( 13/ 58)
|
||||
GtkFileChooserButton : 18% ( 2/ 11)
|
||||
GtkFileChooserDialog : 100% ( 1/ 1)
|
||||
GtkFileChooserWidget : 50% ( 1/ 2)
|
||||
GtkFileFilter : 55% ( 5/ 9)
|
||||
GtkFontButton : 100% ( 14/ 14)
|
||||
GtkFontSelection : 28% ( 4/ 14)
|
||||
GtkFontSelectionDialog : 100% ( 8/ 8)
|
||||
GtkInputDialog : 0% ( 0/ 1)
|
||||
GtkAlignment : 100% ( 4/ 4)
|
||||
GtkAspectFrame : 0% ( 0/ 2)
|
||||
GtkHBox : 100% ( 1/ 1)
|
||||
GtkVBox : 100% ( 1/ 1)
|
||||
GtkHButtonBox : 0% ( 0/ 5)
|
||||
GtkVButtonBox : 0% ( 0/ 5)
|
||||
GtkFixed : 100% ( 5/ 5)
|
||||
GtkHPaned : 100% ( 1/ 1)
|
||||
GtkVPaned : 100% ( 1/ 1)
|
||||
GtkLayout : 100% ( 12/ 12)
|
||||
GtkNotebook : 90% ( 50/ 55)
|
||||
GtkTable : 93% ( 14/ 15)
|
||||
GtkExpander : 87% ( 14/ 16)
|
||||
GtkOrientable : 0% ( 0/ 2)
|
||||
GtkFrame : 100% ( 9/ 9)
|
||||
GtkHSeparator : 100% ( 1/ 1)
|
||||
GtkVSeparator : 100% ( 1/ 1)
|
||||
GtkScrollbar : 100% ( 0/ 0)
|
||||
GtkHScrollbar : 100% ( 1/ 1)
|
||||
GtkVScrollbar : 100% ( 1/ 1)
|
||||
GtkScrolledWindow : 86% ( 13/ 15)
|
||||
GtkPrintOperation : 13% ( 5/ 36)
|
||||
GtkPrintContext : 18% ( 2/ 11)
|
||||
GtkPrintSettings : 0% ( 0/ 74)
|
||||
GtkPageSetup : 0% ( 0/ 25)
|
||||
GtkPaperSize : 0% ( 0/ 21)
|
||||
GtkPrinter : 0% ( 0/ 23)
|
||||
GtkPrintJob : 0% ( 0/ 10)
|
||||
GtkPrintUnixDialog : 0% ( 0/ 18)
|
||||
GtkPageSetupUnixDialog : 0% ( 0/ 5)
|
||||
GtkAdjustment : 83% ( 15/ 18)
|
||||
GtkArrow : 100% ( 2/ 2)
|
||||
GtkCalendar : 0% ( 0/ 17)
|
||||
GtkDrawingArea : 100% ( 2/ 2)
|
||||
GtkEventBox : 20% ( 1/ 5)
|
||||
GtkHandleBox : 0% ( 0/ 8)
|
||||
GtkIMContextSimple : 0% ( 0/ 2)
|
||||
GtkIMMulticontext : 0% ( 0/ 4)
|
||||
GtkSizeGroup : 100% ( 8/ 8)
|
||||
GtkTooltip : 60% ( 6/ 10)
|
||||
GtkViewport : 100% ( 9/ 9)
|
||||
GtkAccessible : 100% ( 3/ 3)
|
||||
GtkBin : 100% ( 1/ 1)
|
||||
GtkBox : 100% ( 11/ 11)
|
||||
GtkButtonBox : 0% ( 0/ 10)
|
||||
GtkContainer : 48% ( 16/ 33)
|
||||
GtkItem : 100% ( 3/ 3)
|
||||
GtkMenuShell : 0% ( 0/ 11)
|
||||
GtkMisc : 100% ( 4/ 4)
|
||||
GtkObject : 100% ( 2/ 2)
|
||||
GtkPaned : 88% ( 8/ 9)
|
||||
GtkRange : 53% ( 16/ 30)
|
||||
GtkScale : 90% ( 9/ 10)
|
||||
GtkSeparator : 100% ( 0/ 0)
|
||||
GtkWidget : 54% (101/187)
|
||||
GtkIMContext : 0% ( 0/ 11)
|
||||
GtkPlug : 0% ( 0/ 7)
|
||||
GtkSocket : 0% ( 0/ 5)
|
||||
GtkRecentManager : 0% ( 0/ 37)
|
||||
GtkRecentChooser : 0% ( 0/ 33)
|
||||
GtkRecentChooserDialog : 0% ( 0/ 2)
|
||||
GtkRecentChooserMenu : 0% ( 0/ 4)
|
||||
GtkRecentChooserWidget : 0% ( 0/ 2)
|
||||
GtkRecentFilter : 0% ( 0/ 12)
|
||||
GtkBuildable : 0% ( 0/ 10)
|
||||
|
||||
Total progress : 47% (1519/3180)
|
||||
|
4
vendor/github.com/mattn/go-gtk/TODO
generated
vendored
Normal file
4
vendor/github.com/mattn/go-gtk/TODO
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
* more widgets.
|
||||
* main loop handling (using goroutine) (done)
|
||||
* split gtksourceview from gtk package (done)
|
||||
* copyright header in sources
|
BIN
vendor/github.com/mattn/go-gtk/data/go-gtk-logo.png
generated
vendored
Normal file
BIN
vendor/github.com/mattn/go-gtk/data/go-gtk-logo.png
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
vendor/github.com/mattn/go-gtk/data/mattn-logo.png
generated
vendored
Normal file
BIN
vendor/github.com/mattn/go-gtk/data/mattn-logo.png
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
BIN
vendor/github.com/mattn/go-gtk/data/win32-demo.png
generated
vendored
Normal file
BIN
vendor/github.com/mattn/go-gtk/data/win32-demo.png
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
BIN
vendor/github.com/mattn/go-gtk/data/win32-twitter.png
generated
vendored
Normal file
BIN
vendor/github.com/mattn/go-gtk/data/win32-twitter.png
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
222
vendor/github.com/mattn/go-gtk/example/action/action.go
generated
vendored
Normal file
222
vendor/github.com/mattn/go-gtk/example/action/action.go
generated
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func CreateWindow() *gtk.Window {
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetDefaultSize(700, 300)
|
||||
vbox := gtk.NewVBox(false, 1)
|
||||
CreateMenuAndToolbar(window, vbox)
|
||||
CreateActivatableDemo(vbox)
|
||||
window.Add(vbox)
|
||||
return window
|
||||
}
|
||||
|
||||
func CreateMenuAndToolbar(w *gtk.Window, vbox *gtk.VBox) {
|
||||
action_group := gtk.NewActionGroup("my_group")
|
||||
ui_manager := CreateUIManager()
|
||||
accel_group := ui_manager.GetAccelGroup()
|
||||
w.AddAccelGroup(accel_group)
|
||||
AddFileMenuActions(action_group)
|
||||
AddEditMenuActions(action_group)
|
||||
AddChoicesMenuActions(action_group)
|
||||
ui_manager.InsertActionGroup(action_group, 0)
|
||||
menubar := ui_manager.GetWidget("/MenuBar")
|
||||
vbox.PackStart(menubar, false, false, 0)
|
||||
toolbar := ui_manager.GetWidget("/ToolBar")
|
||||
vbox.PackStart(toolbar, false, false, 0)
|
||||
eventbox := gtk.NewEventBox()
|
||||
vbox.PackStart(eventbox, false, false, 0)
|
||||
// label := gtk.NewLabel("Right-click to see the popup menu.")
|
||||
// vbox.PackStart(label, false, false, 0)
|
||||
}
|
||||
|
||||
func CreateActivatableDemo(vbox *gtk.VBox) {
|
||||
action_entry := gtk.NewAction("ActionEntry",
|
||||
"Button attached to Action", "", gtk.STOCK_INFO)
|
||||
action_entry.Connect("activate", func() {
|
||||
fmt.Println("Action clicked")
|
||||
})
|
||||
frame1 := gtk.NewFrame("GtkActivatable interface demonstration")
|
||||
frame1.SetBorderWidth(5)
|
||||
hbox2 := gtk.NewHBox(false, 5)
|
||||
hbox2.SetSizeRequest(400, 50)
|
||||
hbox2.SetBorderWidth(5)
|
||||
button1 := gtk.NewButton()
|
||||
button1.SetSizeRequest(250, 0)
|
||||
button1.SetRelatedAction(action_entry)
|
||||
hbox2.PackStart(button1, false, false, 0)
|
||||
hbox2.PackStart(gtk.NewVSeparator(), false, false, 0)
|
||||
button2 := gtk.NewButtonWithLabel("Hide Action")
|
||||
button2.SetSizeRequest(150, 0)
|
||||
button2.Connect("clicked", func() {
|
||||
action_entry.SetVisible(false)
|
||||
fmt.Println("Hide Action")
|
||||
})
|
||||
hbox2.PackStart(button2, false, false, 0)
|
||||
button3 := gtk.NewButtonWithLabel("Unhide Action")
|
||||
button3.SetSizeRequest(150, 0)
|
||||
button3.Connect("clicked", func() {
|
||||
action_entry.SetVisible(true)
|
||||
fmt.Println("Show Action")
|
||||
})
|
||||
hbox2.PackStart(button3, false, false, 0)
|
||||
frame1.Add(hbox2)
|
||||
vbox.PackStart(frame1, false, true, 0)
|
||||
}
|
||||
|
||||
func CreateUIManager() *gtk.UIManager {
|
||||
UI_INFO := `
|
||||
<ui>
|
||||
<menubar name='MenuBar'>
|
||||
<menu action='FileMenu'>
|
||||
<menu action='FileNew'>
|
||||
<menuitem action='FileNewStandard' />
|
||||
<menuitem action='FileNewFoo' />
|
||||
<menuitem action='FileNewGoo' />
|
||||
</menu>
|
||||
<separator />
|
||||
<menuitem action='FileQuit' />
|
||||
</menu>
|
||||
<menu action='EditMenu'>
|
||||
<menuitem action='EditCopy' />
|
||||
<menuitem action='EditPaste' />
|
||||
<menuitem action='EditSomething' />
|
||||
</menu>
|
||||
<menu action='ChoicesMenu'>
|
||||
<menuitem action='ChoiceOne'/>
|
||||
<menuitem action='ChoiceTwo'/>
|
||||
<menuitem action='ChoiceThree'/>
|
||||
<separator />
|
||||
<menuitem action='ChoiceToggle'/>
|
||||
</menu>
|
||||
</menubar>
|
||||
<toolbar name='ToolBar'>
|
||||
<toolitem action='FileNewStandard' />
|
||||
<toolitem action='FileQuit' />
|
||||
</toolbar>
|
||||
<popup name='PopupMenu'>
|
||||
<menuitem action='EditCopy' />
|
||||
<menuitem action='EditPaste' />
|
||||
<menuitem action='EditSomething' />
|
||||
</popup>
|
||||
</ui>
|
||||
`
|
||||
ui_manager := gtk.NewUIManager()
|
||||
ui_manager.AddUIFromString(UI_INFO)
|
||||
return ui_manager
|
||||
}
|
||||
|
||||
func OnMenuFileNewGeneric() {
|
||||
fmt.Println("A File|New menu item was selected.")
|
||||
}
|
||||
|
||||
func OnMenuFileQuit() {
|
||||
fmt.Println("quit app...")
|
||||
gtk.MainQuit()
|
||||
}
|
||||
|
||||
func OnMenuOther(ctx *glib.CallbackContext) {
|
||||
v := reflect.ValueOf(ctx.Target())
|
||||
if v.Kind() == reflect.Ptr {
|
||||
fmt.Printf("Item %s(%p) was selected", v.Elem(), v.Interface())
|
||||
fmt.Println()
|
||||
if w, ok := v.Elem().Interface().(gtk.IWidget); ok {
|
||||
v := reflect.ValueOf(ctx.Target())
|
||||
v2 := v.Elem()
|
||||
fmt.Println(v.Kind(), v2.Kind())
|
||||
fmt.Println("Menu item ", w.GetName(), " was selected")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func OnMenuOther2(widget unsafe.Pointer, event unsafe.Pointer,
|
||||
data unsafe.Pointer) {
|
||||
fmt.Println("Menu item ", "", " was selected")
|
||||
}
|
||||
|
||||
func AddFileMenuActions(action_group *gtk.ActionGroup) {
|
||||
action_group.AddAction(gtk.NewAction("FileMenu", "File", "", ""))
|
||||
|
||||
action_filenewmenu := gtk.NewAction("FileNew", "", "", gtk.STOCK_NEW)
|
||||
action_group.AddAction(action_filenewmenu)
|
||||
|
||||
action_new := gtk.NewAction("FileNewStandard", "_New",
|
||||
"Create a new file", gtk.STOCK_NEW)
|
||||
action_new.Connect("activate", OnMenuFileNewGeneric)
|
||||
action_group.AddActionWithAccel(action_new, "")
|
||||
|
||||
action_new_foo := gtk.NewAction("FileNewFoo", "New Foo",
|
||||
"Create new foo", gtk.STOCK_NEW)
|
||||
action_new_foo.Connect("activate", OnMenuFileNewGeneric)
|
||||
action_group.AddAction(action_new_foo)
|
||||
|
||||
action_new_goo := gtk.NewAction("FileNewGoo", "_New Goo",
|
||||
"Create new goo", gtk.STOCK_NEW)
|
||||
action_new_goo.Connect("activate", OnMenuFileNewGeneric)
|
||||
action_group.AddAction(action_new_goo)
|
||||
|
||||
action_filequit := gtk.NewAction("FileQuit", "", "", gtk.STOCK_QUIT)
|
||||
action_filequit.Connect("activate", OnMenuFileQuit)
|
||||
action_group.AddActionWithAccel(action_filequit, "")
|
||||
}
|
||||
|
||||
func AddEditMenuActions(action_group *gtk.ActionGroup) {
|
||||
action_group.AddAction(gtk.NewAction("EditMenu", "Edit", "", ""))
|
||||
|
||||
action_editcopy := gtk.NewAction("EditCopy", "", "", gtk.STOCK_COPY)
|
||||
action_editcopy.Connect("activate", OnMenuOther)
|
||||
action_group.AddActionWithAccel(action_editcopy, "")
|
||||
|
||||
action_editpaste := gtk.NewAction("EditPaste", "", "", gtk.STOCK_PASTE)
|
||||
action_editpaste.Connect("activate", OnMenuOther)
|
||||
action_group.AddActionWithAccel(action_editpaste, "")
|
||||
|
||||
action_editsomething := gtk.NewAction("EditSomething", "Something", "", "")
|
||||
action_editsomething.Connect("activate", OnMenuOther)
|
||||
action_group.AddActionWithAccel(action_editsomething, "<control><alt>S")
|
||||
}
|
||||
|
||||
func AddChoicesMenuActions(action_group *gtk.ActionGroup) {
|
||||
action_group.AddAction(gtk.NewAction("ChoicesMenu", "Choices", "", ""))
|
||||
|
||||
var ra_list []*gtk.RadioAction
|
||||
ra_one := gtk.NewRadioAction("ChoiceOne", "One", "", "", 1)
|
||||
ra_list = append(ra_list, ra_one)
|
||||
|
||||
ra_two := gtk.NewRadioAction("ChoiceTwo", "Two", "", "", 2)
|
||||
ra_list = append(ra_list, ra_two)
|
||||
|
||||
ra_three := gtk.NewRadioAction("ChoiceThree", "Three", "", "", 2)
|
||||
ra_list = append(ra_list, ra_three)
|
||||
|
||||
var sl *glib.SList
|
||||
for _, ra := range ra_list {
|
||||
ra.SetGroup(sl)
|
||||
sl = ra.GetGroup()
|
||||
action_group.AddAction(ra)
|
||||
}
|
||||
|
||||
ra_last := gtk.NewToggleAction("ChoiceToggle", "Toggle", "", "")
|
||||
ra_last.SetActive(true)
|
||||
action_group.AddAction(ra_last)
|
||||
}
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
window := CreateWindow()
|
||||
window.SetPosition(gtk.WIN_POS_CENTER)
|
||||
window.Connect("destroy", func(ctx *glib.CallbackContext) {
|
||||
fmt.Println("destroy pending...")
|
||||
gtk.MainQuit()
|
||||
}, "foo")
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
43
vendor/github.com/mattn/go-gtk/example/alignment/alignment.go
generated
vendored
Normal file
43
vendor/github.com/mattn/go-gtk/example/alignment/alignment.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("Alignment")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
notebook := gtk.NewNotebook()
|
||||
window.Add(notebook)
|
||||
|
||||
align := gtk.NewAlignment(0.5, 0.5, 0.5, 0.5)
|
||||
notebook.AppendPage(align, gtk.NewLabel("Alignment"))
|
||||
|
||||
button := gtk.NewButtonWithLabel("Hello World!")
|
||||
align.Add(button)
|
||||
|
||||
fixed := gtk.NewFixed()
|
||||
notebook.AppendPage(fixed, gtk.NewLabel("Fixed"))
|
||||
|
||||
button2 := gtk.NewButtonWithLabel("Pulse")
|
||||
fixed.Put(button2, 30, 30)
|
||||
|
||||
progress := gtk.NewProgressBar()
|
||||
fixed.Put(progress, 30, 70)
|
||||
|
||||
button.Connect("clicked", func() {
|
||||
progress.SetFraction(0.1 + 0.9*progress.GetFraction()) //easter egg
|
||||
})
|
||||
button2.Connect("clicked", func() {
|
||||
progress.Pulse()
|
||||
})
|
||||
|
||||
window.ShowAll()
|
||||
window.SetSizeRequest(200, 200)
|
||||
|
||||
gtk.Main()
|
||||
}
|
48
vendor/github.com/mattn/go-gtk/example/arrow/arrow.go
generated
vendored
Normal file
48
vendor/github.com/mattn/go-gtk/example/arrow/arrow.go
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
)
|
||||
|
||||
func createArrowButton(at gtk.ArrowType, st gtk.ShadowType) *gtk.Button {
|
||||
b := gtk.NewButton()
|
||||
a := gtk.NewArrow(at, st)
|
||||
|
||||
b.Add(a)
|
||||
|
||||
b.Show()
|
||||
a.Show()
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("Arrow Buttons")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
box := gtk.NewHBox(false, 0)
|
||||
box.Show()
|
||||
window.Add(box)
|
||||
|
||||
up := createArrowButton(gtk.ARROW_UP, gtk.SHADOW_IN)
|
||||
down := createArrowButton(gtk.ARROW_DOWN, gtk.SHADOW_OUT)
|
||||
left := createArrowButton(gtk.ARROW_LEFT, gtk.SHADOW_ETCHED_IN)
|
||||
right := createArrowButton(gtk.ARROW_RIGHT, gtk.SHADOW_ETCHED_OUT)
|
||||
|
||||
box.PackStart(up, false, false, 3)
|
||||
box.PackStart(down, false, false, 3)
|
||||
box.PackStart(left, false, false, 3)
|
||||
box.PackStart(right, false, false, 3)
|
||||
|
||||
up.Clicked(func() { println("↑") })
|
||||
down.Clicked(func() { println("↓") })
|
||||
left.Clicked(func() { println("←") })
|
||||
right.Clicked(func() { println("→") })
|
||||
|
||||
window.Show()
|
||||
gtk.Main()
|
||||
}
|
26
vendor/github.com/mattn/go-gtk/example/builder/builder.go
generated
vendored
Normal file
26
vendor/github.com/mattn/go-gtk/example/builder/builder.go
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/mattn/go-gtk/example/builder/callback"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
//"github.com/mattn/go-gtk/example/builder/callback"
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
|
||||
builder := gtk.NewBuilder()
|
||||
|
||||
builder.AddFromFile("hello.ui")
|
||||
obj := builder.GetObject("window1")
|
||||
|
||||
window := gtk.WidgetFromObject(obj)
|
||||
window.Show()
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
callback.Init(builder)
|
||||
|
||||
gtk.Main()
|
||||
}
|
37
vendor/github.com/mattn/go-gtk/example/builder/callback/callback.go
generated
vendored
Normal file
37
vendor/github.com/mattn/go-gtk/example/builder/callback/callback.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
package callback
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
var aboutdialog *gtk.AboutDialog
|
||||
|
||||
func Init(builder *gtk.Builder) {
|
||||
aboutdialog = >k.AboutDialog{
|
||||
*(*gtk.Dialog)(unsafe.Pointer(&builder.GetObject("aboutdialog1").Object))}
|
||||
builder.ConnectSignalsFull(func(builder *gtk.Builder, obj *glib.GObject, sig, handler string, conn *glib.GObject, flags glib.ConnectFlags, user_data interface{}) {
|
||||
switch handler {
|
||||
case "on_imagemenuitem1_activate":
|
||||
obj.SignalConnect(sig, on_imagemenuitem1_activate, user_data, flags)
|
||||
case "on_show_aboutdialog_activate":
|
||||
obj.SignalConnect(sig, on_show_aboutdialog_activate, user_data, flags)
|
||||
case "gtk_widget_hide":
|
||||
obj.SignalConnect(sig, func(c *glib.CallbackContext) {
|
||||
gtk.WidgetFromObject(c.Target().(*glib.GObject)).Hide()
|
||||
}, nil, flags)
|
||||
}
|
||||
}, nil)
|
||||
}
|
||||
|
||||
//export on_imagemenuitem1_activate
|
||||
func on_imagemenuitem1_activate() {
|
||||
gtk.MainQuit()
|
||||
}
|
||||
|
||||
//export on_show_aboutdialog_activate
|
||||
func on_show_aboutdialog_activate() {
|
||||
aboutdialog.Run()
|
||||
}
|
139
vendor/github.com/mattn/go-gtk/example/builder/hello.ui
generated
vendored
Normal file
139
vendor/github.com/mattn/go-gtk/example/builder/hello.ui
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk+" version="2.16"/>
|
||||
<!-- interface-naming-policy toplevel-contextual -->
|
||||
<object class="GtkAboutDialog" id="aboutdialog1">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">5</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<property name="program_name">go-gtk builder</property>
|
||||
<property name="version">0.1</property>
|
||||
<property name="copyright">The library is available under the same terms and conditions as the Go,
|
||||
the BSD style license, and the LGPL (Lesser GNU Public License).
|
||||
The idea is that if you can use Go (and Gtk) in a project, you should also be able to use go-gtk.</property>
|
||||
<property name="comments" translatable="yes">example program for go-gtk</property>
|
||||
<property name="website">https://github.com/mattn/go-gtk</property>
|
||||
<property name="authors">Yasuhiro Matsumoto</property>
|
||||
<signal name="response" handler="gtk_widget_hide" swapped="no"/>
|
||||
<child internal-child="vbox">
|
||||
<object class="GtkVBox" id="dialog-vbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">2</property>
|
||||
<child internal-child="action_area">
|
||||
<object class="GtkHButtonBox" id="dialog-action_area1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">end</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="pixbuf">../../data/mattn-logo.png</property>
|
||||
</object>
|
||||
<object class="GtkWindow" id="window1">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">builder</property>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkMenuBar" id="menubar1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="file">
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">_File</property>
|
||||
<property name="use_underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkMenu" id="exit">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem" id="do_exit">
|
||||
<property name="label">gtk-quit</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="activate" handler="on_imagemenuitem1_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="help">
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="right_justified">True</property>
|
||||
<property name="label" translatable="yes">_Help</property>
|
||||
<property name="use_underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkMenu" id="about">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem" id="show_aboutdialog">
|
||||
<property name="label">gtk-about</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="activate" handler="on_show_aboutdialog_activate" after="yes" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLinkButton" id="linkbutton1">
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="has_tooltip">True</property>
|
||||
<property name="tooltip_markup"><b>http://mattn.kaoriya.net/</b></property>
|
||||
<property name="image">image1</property>
|
||||
<property name="relief">none</property>
|
||||
<property name="uri">http://mattn.kaoriya.net/</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
19
vendor/github.com/mattn/go-gtk/example/clipboard/clipboard.go
generated
vendored
Normal file
19
vendor/github.com/mattn/go-gtk/example/clipboard/clipboard.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
clipboard := gtk.NewClipboardGetForDisplay(
|
||||
gdk.DisplayGetDefault(),
|
||||
gdk.SELECTION_CLIPBOARD)
|
||||
fmt.Println(clipboard.WaitForText())
|
||||
clipboard.SetText("helloworld")
|
||||
gtk.MainIterationDo(true)
|
||||
clipboard.Store()
|
||||
gtk.MainIterationDo(true)
|
||||
}
|
355
vendor/github.com/mattn/go-gtk/example/demo/demo.go
generated
vendored
Normal file
355
vendor/github.com/mattn/go-gtk/example/demo/demo.go
generated
vendored
Normal file
@@ -0,0 +1,355 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/gdkpixbuf"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func uniq(strings []string) (ret []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func authors() []string {
|
||||
if b, err := exec.Command("git", "log").Output(); err == nil {
|
||||
lines := strings.Split(string(b), "\n")
|
||||
|
||||
var a []string
|
||||
r := regexp.MustCompile(`^Author:\s*([^ <]+).*$`)
|
||||
for _, e := range lines {
|
||||
ms := r.FindStringSubmatch(e)
|
||||
if ms == nil {
|
||||
continue
|
||||
}
|
||||
a = append(a, ms[1])
|
||||
}
|
||||
sort.Strings(a)
|
||||
var p string
|
||||
lines = []string{}
|
||||
for _, e := range a {
|
||||
if p == e {
|
||||
continue
|
||||
}
|
||||
lines = append(lines, e)
|
||||
p = e
|
||||
}
|
||||
return lines
|
||||
}
|
||||
return []string{"Yasuhiro Matsumoto <mattn.jp@gmail.com>"}
|
||||
}
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetPosition(gtk.WIN_POS_CENTER)
|
||||
window.SetTitle("GTK Go!")
|
||||
window.SetIconName("gtk-dialog-info")
|
||||
window.Connect("destroy", func(ctx *glib.CallbackContext) {
|
||||
fmt.Println("got destroy!", ctx.Data().(string))
|
||||
gtk.MainQuit()
|
||||
}, "foo")
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkVBox
|
||||
//--------------------------------------------------------
|
||||
vbox := gtk.NewVBox(false, 1)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkMenuBar
|
||||
//--------------------------------------------------------
|
||||
menubar := gtk.NewMenuBar()
|
||||
vbox.PackStart(menubar, false, false, 0)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkVPaned
|
||||
//--------------------------------------------------------
|
||||
vpaned := gtk.NewVPaned()
|
||||
vbox.Add(vpaned)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkFrame
|
||||
//--------------------------------------------------------
|
||||
frame1 := gtk.NewFrame("Demo")
|
||||
framebox1 := gtk.NewVBox(false, 1)
|
||||
frame1.Add(framebox1)
|
||||
|
||||
frame2 := gtk.NewFrame("Demo")
|
||||
framebox2 := gtk.NewVBox(false, 1)
|
||||
frame2.Add(framebox2)
|
||||
|
||||
vpaned.Pack1(frame1, false, false)
|
||||
vpaned.Pack2(frame2, false, false)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkImage
|
||||
//--------------------------------------------------------
|
||||
dir, _ := filepath.Split(os.Args[0])
|
||||
imagefile := filepath.Join(dir, "../../data/go-gtk-logo.png")
|
||||
|
||||
label := gtk.NewLabel("Go Binding for GTK")
|
||||
label.ModifyFontEasy("DejaVu Serif 15")
|
||||
framebox1.PackStart(label, false, true, 0)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkEntry
|
||||
//--------------------------------------------------------
|
||||
entry := gtk.NewEntry()
|
||||
entry.SetText("Hello world")
|
||||
framebox1.Add(entry)
|
||||
|
||||
image := gtk.NewImageFromFile(imagefile)
|
||||
framebox1.Add(image)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkScale
|
||||
//--------------------------------------------------------
|
||||
scale := gtk.NewHScaleWithRange(0, 100, 1)
|
||||
scale.Connect("value-changed", func() {
|
||||
fmt.Println("scale:", int(scale.GetValue()))
|
||||
})
|
||||
framebox2.Add(scale)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkHBox
|
||||
//--------------------------------------------------------
|
||||
buttons := gtk.NewHBox(false, 1)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkButton
|
||||
//--------------------------------------------------------
|
||||
button := gtk.NewButtonWithLabel("Button with label")
|
||||
button.Clicked(func() {
|
||||
fmt.Println("button clicked:", button.GetLabel())
|
||||
messagedialog := gtk.NewMessageDialog(
|
||||
button.GetTopLevelAsWindow(),
|
||||
gtk.DIALOG_MODAL,
|
||||
gtk.MESSAGE_INFO,
|
||||
gtk.BUTTONS_OK,
|
||||
entry.GetText())
|
||||
messagedialog.Response(func() {
|
||||
fmt.Println("Dialog OK!")
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkFileChooserDialog
|
||||
//--------------------------------------------------------
|
||||
filechooserdialog := gtk.NewFileChooserDialog(
|
||||
"Choose File...",
|
||||
button.GetTopLevelAsWindow(),
|
||||
gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
gtk.STOCK_OK,
|
||||
gtk.RESPONSE_ACCEPT)
|
||||
filter := gtk.NewFileFilter()
|
||||
filter.AddPattern("*.go")
|
||||
filechooserdialog.AddFilter(filter)
|
||||
filechooserdialog.Response(func() {
|
||||
fmt.Println(filechooserdialog.GetFilename())
|
||||
filechooserdialog.Destroy()
|
||||
})
|
||||
filechooserdialog.Run()
|
||||
messagedialog.Destroy()
|
||||
})
|
||||
messagedialog.Run()
|
||||
})
|
||||
buttons.Add(button)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkFontButton
|
||||
//--------------------------------------------------------
|
||||
fontbutton := gtk.NewFontButton()
|
||||
fontbutton.Connect("font-set", func() {
|
||||
fmt.Println("title:", fontbutton.GetTitle())
|
||||
fmt.Println("fontname:", fontbutton.GetFontName())
|
||||
fmt.Println("use_size:", fontbutton.GetUseSize())
|
||||
fmt.Println("show_size:", fontbutton.GetShowSize())
|
||||
})
|
||||
buttons.Add(fontbutton)
|
||||
framebox2.PackStart(buttons, false, false, 0)
|
||||
|
||||
buttons = gtk.NewHBox(false, 1)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkToggleButton
|
||||
//--------------------------------------------------------
|
||||
togglebutton := gtk.NewToggleButtonWithLabel("ToggleButton with label")
|
||||
togglebutton.Connect("toggled", func() {
|
||||
if togglebutton.GetActive() {
|
||||
togglebutton.SetLabel("ToggleButton ON!")
|
||||
} else {
|
||||
togglebutton.SetLabel("ToggleButton OFF!")
|
||||
}
|
||||
})
|
||||
buttons.Add(togglebutton)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkCheckButton
|
||||
//--------------------------------------------------------
|
||||
checkbutton := gtk.NewCheckButtonWithLabel("CheckButton with label")
|
||||
checkbutton.Connect("toggled", func() {
|
||||
if checkbutton.GetActive() {
|
||||
checkbutton.SetLabel("CheckButton CHECKED!")
|
||||
} else {
|
||||
checkbutton.SetLabel("CheckButton UNCHECKED!")
|
||||
}
|
||||
})
|
||||
buttons.Add(checkbutton)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkRadioButton
|
||||
//--------------------------------------------------------
|
||||
buttonbox := gtk.NewVBox(false, 1)
|
||||
radiofirst := gtk.NewRadioButtonWithLabel(nil, "Radio1")
|
||||
buttonbox.Add(radiofirst)
|
||||
buttonbox.Add(gtk.NewRadioButtonWithLabel(radiofirst.GetGroup(), "Radio2"))
|
||||
buttonbox.Add(gtk.NewRadioButtonWithLabel(radiofirst.GetGroup(), "Radio3"))
|
||||
buttons.Add(buttonbox)
|
||||
//radiobutton.SetMode(false);
|
||||
radiofirst.SetActive(true)
|
||||
|
||||
framebox2.PackStart(buttons, false, false, 0)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkVSeparator
|
||||
//--------------------------------------------------------
|
||||
vsep := gtk.NewVSeparator()
|
||||
framebox2.PackStart(vsep, false, false, 0)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkComboBoxEntry
|
||||
//--------------------------------------------------------
|
||||
combos := gtk.NewHBox(false, 1)
|
||||
comboboxentry := gtk.NewComboBoxText()
|
||||
comboboxentry.AppendText("Monkey")
|
||||
comboboxentry.AppendText("Tiger")
|
||||
comboboxentry.AppendText("Elephant")
|
||||
comboboxentry.Connect("changed", func() {
|
||||
fmt.Println("value:", comboboxentry.GetActiveText())
|
||||
})
|
||||
combos.Add(comboboxentry)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkComboBox
|
||||
//--------------------------------------------------------
|
||||
combobox := gtk.NewComboBoxText()
|
||||
combobox.AppendText("Peach")
|
||||
combobox.AppendText("Banana")
|
||||
combobox.AppendText("Apple")
|
||||
combobox.SetActive(1)
|
||||
combobox.Connect("changed", func() {
|
||||
fmt.Println("value:", combobox.GetActiveText())
|
||||
})
|
||||
combos.Add(combobox)
|
||||
|
||||
framebox2.PackStart(combos, false, false, 0)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkTextView
|
||||
//--------------------------------------------------------
|
||||
swin := gtk.NewScrolledWindow(nil, nil)
|
||||
swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||
swin.SetShadowType(gtk.SHADOW_IN)
|
||||
textview := gtk.NewTextView()
|
||||
var start, end gtk.TextIter
|
||||
buffer := textview.GetBuffer()
|
||||
buffer.GetStartIter(&start)
|
||||
buffer.Insert(&start, "Hello ")
|
||||
buffer.GetEndIter(&end)
|
||||
buffer.Insert(&end, "World!")
|
||||
tag := buffer.CreateTag("bold", map[string]string{
|
||||
"background": "#FF0000", "weight": "700"})
|
||||
buffer.GetStartIter(&start)
|
||||
buffer.GetEndIter(&end)
|
||||
buffer.ApplyTag(tag, &start, &end)
|
||||
swin.Add(textview)
|
||||
framebox2.Add(swin)
|
||||
|
||||
buffer.Connect("changed", func() {
|
||||
fmt.Println("changed")
|
||||
})
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkMenuItem
|
||||
//--------------------------------------------------------
|
||||
cascademenu := gtk.NewMenuItemWithMnemonic("_File")
|
||||
menubar.Append(cascademenu)
|
||||
submenu := gtk.NewMenu()
|
||||
cascademenu.SetSubmenu(submenu)
|
||||
|
||||
var menuitem *gtk.MenuItem
|
||||
menuitem = gtk.NewMenuItemWithMnemonic("E_xit")
|
||||
menuitem.Connect("activate", func() {
|
||||
gtk.MainQuit()
|
||||
})
|
||||
submenu.Append(menuitem)
|
||||
|
||||
cascademenu = gtk.NewMenuItemWithMnemonic("_View")
|
||||
menubar.Append(cascademenu)
|
||||
submenu = gtk.NewMenu()
|
||||
cascademenu.SetSubmenu(submenu)
|
||||
|
||||
checkmenuitem := gtk.NewCheckMenuItemWithMnemonic("_Disable")
|
||||
checkmenuitem.Connect("activate", func() {
|
||||
vpaned.SetSensitive(!checkmenuitem.GetActive())
|
||||
})
|
||||
submenu.Append(checkmenuitem)
|
||||
|
||||
menuitem = gtk.NewMenuItemWithMnemonic("_Font")
|
||||
menuitem.Connect("activate", func() {
|
||||
fsd := gtk.NewFontSelectionDialog("Font")
|
||||
fsd.SetFontName(fontbutton.GetFontName())
|
||||
fsd.Response(func() {
|
||||
fmt.Println(fsd.GetFontName())
|
||||
fontbutton.SetFontName(fsd.GetFontName())
|
||||
fsd.Destroy()
|
||||
})
|
||||
fsd.SetTransientFor(window)
|
||||
fsd.Run()
|
||||
})
|
||||
submenu.Append(menuitem)
|
||||
|
||||
cascademenu = gtk.NewMenuItemWithMnemonic("_Help")
|
||||
menubar.Append(cascademenu)
|
||||
submenu = gtk.NewMenu()
|
||||
cascademenu.SetSubmenu(submenu)
|
||||
|
||||
menuitem = gtk.NewMenuItemWithMnemonic("_About")
|
||||
menuitem.Connect("activate", func() {
|
||||
dialog := gtk.NewAboutDialog()
|
||||
dialog.SetName("Go-Gtk Demo!")
|
||||
dialog.SetProgramName("demo")
|
||||
dialog.SetAuthors(authors())
|
||||
dir, _ := filepath.Split(os.Args[0])
|
||||
imagefile := filepath.Join(dir, "../../data/mattn-logo.png")
|
||||
pixbuf, _ := gdkpixbuf.NewPixbufFromFile(imagefile)
|
||||
dialog.SetLogo(pixbuf)
|
||||
dialog.SetLicense("The library is available under the same terms and conditions as the Go, the BSD style license, and the LGPL (Lesser GNU Public License). The idea is that if you can use Go (and Gtk) in a project, you should also be able to use go-gtk.")
|
||||
dialog.SetWrapLicense(true)
|
||||
dialog.Run()
|
||||
dialog.Destroy()
|
||||
})
|
||||
submenu.Append(menuitem)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkStatusbar
|
||||
//--------------------------------------------------------
|
||||
statusbar := gtk.NewStatusbar()
|
||||
context_id := statusbar.GetContextId("go-gtk")
|
||||
statusbar.Push(context_id, "GTK binding for Go!")
|
||||
|
||||
framebox2.PackStart(statusbar, false, false, 0)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Event
|
||||
//--------------------------------------------------------
|
||||
window.Add(vbox)
|
||||
window.SetSizeRequest(600, 600)
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
64
vendor/github.com/mattn/go-gtk/example/dnd/dnd.go
generated
vendored
Normal file
64
vendor/github.com/mattn/go-gtk/example/dnd/dnd.go
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK DND")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
vbox := gtk.NewVBox(true, 0)
|
||||
vbox.SetBorderWidth(5)
|
||||
|
||||
targets := []gtk.TargetEntry{
|
||||
{"text/uri-list", 0, 0},
|
||||
{"STRING", 0, 1},
|
||||
{"text/plain", 0, 2},
|
||||
}
|
||||
dest := gtk.NewLabel("drop me file")
|
||||
dest.DragDestSet(
|
||||
gtk.DEST_DEFAULT_MOTION|
|
||||
gtk.DEST_DEFAULT_HIGHLIGHT|
|
||||
gtk.DEST_DEFAULT_DROP,
|
||||
targets,
|
||||
gdk.ACTION_COPY)
|
||||
dest.DragDestAddUriTargets()
|
||||
dest.Connect("drag-data-received", func(ctx *glib.CallbackContext) {
|
||||
sdata := gtk.NewSelectionDataFromNative(unsafe.Pointer(ctx.Args(3)))
|
||||
if sdata != nil {
|
||||
a := (*[2000]uint8)(sdata.GetData())
|
||||
files := strings.Split(string(a[0:sdata.GetLength()-1]), "\n")
|
||||
for i := range files {
|
||||
filename, _, _ := glib.FilenameFromUri(files[i])
|
||||
files[i] = filename
|
||||
}
|
||||
dialog := gtk.NewMessageDialog(
|
||||
window,
|
||||
gtk.DIALOG_MODAL,
|
||||
gtk.MESSAGE_INFO,
|
||||
gtk.BUTTONS_OK,
|
||||
strings.Join(files, "\n"))
|
||||
dialog.SetTitle("D&D")
|
||||
dialog.Response(func() {
|
||||
dialog.Destroy()
|
||||
})
|
||||
dialog.Run()
|
||||
}
|
||||
})
|
||||
vbox.Add(dest)
|
||||
|
||||
window.Add(vbox)
|
||||
|
||||
window.SetSizeRequest(300, 100)
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
92
vendor/github.com/mattn/go-gtk/example/drawable/drawable.go
generated
vendored
Normal file
92
vendor/github.com/mattn/go-gtk/example/drawable/drawable.go
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type point struct {
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK DrawingArea")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
vbox := gtk.NewVBox(true, 0)
|
||||
vbox.SetBorderWidth(5)
|
||||
drawingarea := gtk.NewDrawingArea()
|
||||
|
||||
var p1, p2 point
|
||||
var gdkwin *gdk.Window
|
||||
var pixmap *gdk.Pixmap
|
||||
var gc *gdk.GC
|
||||
p1.x = -1
|
||||
p1.y = -1
|
||||
colors := []string{
|
||||
"black",
|
||||
"gray",
|
||||
"blue",
|
||||
"purple",
|
||||
"red",
|
||||
"orange",
|
||||
"yellow",
|
||||
"green",
|
||||
"darkgreen",
|
||||
}
|
||||
|
||||
drawingarea.Connect("configure-event", func() {
|
||||
if pixmap != nil {
|
||||
pixmap.Unref()
|
||||
}
|
||||
allocation := drawingarea.GetAllocation()
|
||||
pixmap = gdk.NewPixmap(drawingarea.GetWindow().GetDrawable(), allocation.Width, allocation.Height, 24)
|
||||
gc = gdk.NewGC(pixmap.GetDrawable())
|
||||
gc.SetRgbFgColor(gdk.NewColor("white"))
|
||||
pixmap.GetDrawable().DrawRectangle(gc, true, 0, 0, -1, -1)
|
||||
gc.SetRgbFgColor(gdk.NewColor(colors[0]))
|
||||
gc.SetRgbBgColor(gdk.NewColor("white"))
|
||||
})
|
||||
|
||||
drawingarea.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
|
||||
arg := ctx.Args(0)
|
||||
mev := *(**gdk.EventMotion)(unsafe.Pointer(&arg))
|
||||
var mt gdk.ModifierType
|
||||
if mev.IsHint != 0 {
|
||||
gdkwin.GetPointer(&p2.x, &p2.y, &mt)
|
||||
} else {
|
||||
p2.x, p2.y = int(mev.X), int(mev.Y)
|
||||
}
|
||||
if p1.x != -1 && p2.x != -1 && (gdk.EventMask(mt)&gdk.BUTTON_PRESS_MASK) != 0 {
|
||||
pixmap.GetDrawable().DrawLine(gc, p1.x, p1.y, p2.x, p2.y)
|
||||
gdkwin.Invalidate(nil, false)
|
||||
}
|
||||
colors = append(colors[1:], colors[0])
|
||||
gc.SetRgbFgColor(gdk.NewColor(colors[0]))
|
||||
p1 = p2
|
||||
})
|
||||
|
||||
drawingarea.Connect("expose-event", func() {
|
||||
if pixmap == nil {
|
||||
return
|
||||
}
|
||||
gdkwin.GetDrawable().DrawDrawable(gc, pixmap.GetDrawable(), 0, 0, 0, 0, -1, -1)
|
||||
})
|
||||
|
||||
drawingarea.SetEvents(int(gdk.POINTER_MOTION_MASK | gdk.POINTER_MOTION_HINT_MASK | gdk.BUTTON_PRESS_MASK))
|
||||
vbox.Add(drawingarea)
|
||||
|
||||
window.Add(vbox)
|
||||
window.SetSizeRequest(400, 400)
|
||||
window.ShowAll()
|
||||
|
||||
gdkwin = drawingarea.GetWindow()
|
||||
|
||||
gtk.Main()
|
||||
}
|
48
vendor/github.com/mattn/go-gtk/example/event/event.go
generated
vendored
Normal file
48
vendor/github.com/mattn/go-gtk/example/event/event.go
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Events")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
event := make(chan interface{})
|
||||
|
||||
window.Connect("key-press-event", func(ctx *glib.CallbackContext) {
|
||||
arg := ctx.Args(0)
|
||||
event <- *(**gdk.EventKey)(unsafe.Pointer(&arg))
|
||||
})
|
||||
window.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
|
||||
arg := ctx.Args(0)
|
||||
event <- *(**gdk.EventMotion)(unsafe.Pointer(&arg))
|
||||
})
|
||||
|
||||
go func() {
|
||||
for {
|
||||
e := <-event
|
||||
switch ev := e.(type) {
|
||||
case *gdk.EventKey:
|
||||
fmt.Println("key-press-event:", ev.Keyval)
|
||||
break
|
||||
case *gdk.EventMotion:
|
||||
fmt.Println("motion-notify-event:", int(ev.X), int(ev.Y))
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
window.SetEvents(int(gdk.POINTER_MOTION_MASK | gdk.POINTER_MOTION_HINT_MASK | gdk.BUTTON_PRESS_MASK))
|
||||
window.SetSizeRequest(400, 400)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
59
vendor/github.com/mattn/go-gtk/example/example.mk
generated
vendored
Normal file
59
vendor/github.com/mattn/go-gtk/example/example.mk
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
EXAMPLES := \
|
||||
example/action/action \
|
||||
example/alignment/alignment \
|
||||
example/builder/builder \
|
||||
example/clipboard/clipboard \
|
||||
example/demo/demo \
|
||||
example/arrow/arrow \
|
||||
example/dnd/dnd \
|
||||
example/drawable/drawable \
|
||||
example/event/event \
|
||||
example/expander/expander \
|
||||
example/iconview/iconview \
|
||||
example/listview/listview \
|
||||
example/locale/locale \
|
||||
example/notebook/notebook \
|
||||
example/number/number \
|
||||
example/sourceview/sourceview \
|
||||
example/spinbutton/spinbutton \
|
||||
example/statusicon/statusicon \
|
||||
example/table/table \
|
||||
example/thread/thread \
|
||||
example/toolbar/toolbar \
|
||||
example/treeview/treeview \
|
||||
example/twitterstream/twitterstream
|
||||
|
||||
.PHONY: example
|
||||
example: $(EXAMPLES)
|
||||
@true
|
||||
|
||||
.PHONY: clean-example
|
||||
clean-example:
|
||||
rm -f $(EXAMPLES)
|
||||
|
||||
%: %.go
|
||||
cd $(@D) && go build -x
|
||||
|
||||
example/action/action: example/action/action.go
|
||||
example/alignment/alignment: example/alignment/alignment.go
|
||||
example/builder/builder: example/builder/builder.go
|
||||
example/clipboard/clipboard: example/clipboard/clipboard.go
|
||||
example/demo/demo: example/demo/demo.go
|
||||
example/arrow/arrow: example/arrow/arrow.go
|
||||
example/dnd/dnd: example/dnd/dnd.go
|
||||
example/drawable/drawable: example/drawable/drawable.go
|
||||
example/event/event: example/event/event.go
|
||||
example/expander/expander: example/expander/expander.go
|
||||
example/iconview/iconview: example/iconview/iconview.go
|
||||
example/listview/listview: example/listview/listview.go
|
||||
example/locale/locale: example/locale/locale.go
|
||||
example/notebook/notebook: example/notebook/notebook.go
|
||||
example/number/number: example/number/number.go
|
||||
example/sourceview/sourceview: example/sourceview/sourceview.go
|
||||
example/spinbutton/spinbutton: example/spinbutton/spinbutton.go
|
||||
example/statusicon/statusicon: example/statusicon/statusicon.go
|
||||
example/table/table: example/table/table.go
|
||||
example/thread/thread: example/thread/thread.go
|
||||
example/toolbar/toolbar: example/toolbar/toolbar.go
|
||||
example/treeview/treeview: example/treeview/treeview.go
|
||||
example/twitterstream/twitterstream: example/twitterstream/twitterstream.go
|
24
vendor/github.com/mattn/go-gtk/example/expander/expander.go
generated
vendored
Normal file
24
vendor/github.com/mattn/go-gtk/example/expander/expander.go
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("We love Expander")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
vbox := gtk.NewVBox(true, 0)
|
||||
vbox.SetBorderWidth(5)
|
||||
expander := gtk.NewExpander("dan the ...")
|
||||
expander.Add(gtk.NewLabel("404 contents not found"))
|
||||
vbox.PackStart(expander, false, false, 0)
|
||||
|
||||
window.Add(vbox)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
40
vendor/github.com/mattn/go-gtk/example/iconview/iconview.go
generated
vendored
Normal file
40
vendor/github.com/mattn/go-gtk/example/iconview/iconview.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/gdkpixbuf"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Icon View")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
swin := gtk.NewScrolledWindow(nil, nil)
|
||||
|
||||
store := gtk.NewListStore(gdkpixbuf.GetType(), glib.G_TYPE_STRING)
|
||||
iconview := gtk.NewIconViewWithModel(store)
|
||||
iconview.SetPixbufColumn(0)
|
||||
iconview.SetTextColumn(1)
|
||||
swin.Add(iconview)
|
||||
|
||||
gtk.StockListIDs().ForEach(func(d unsafe.Pointer, v interface{}) {
|
||||
id := glib.GPtrToString(d)
|
||||
var iter gtk.TreeIter
|
||||
store.Append(&iter)
|
||||
store.Set(&iter,
|
||||
0, gtk.NewImage().RenderIcon(id, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf,
|
||||
1, id)
|
||||
})
|
||||
|
||||
window.Add(swin)
|
||||
window.SetSizeRequest(500, 200)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
21
vendor/github.com/mattn/go-gtk/example/idle/idle.go
generated
vendored
Normal file
21
vendor/github.com/mattn/go-gtk/example/idle/idle.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
glib.IdleAdd(func() bool {
|
||||
fmt.Println("start")
|
||||
return false
|
||||
})
|
||||
glib.TimeoutAdd(1000, func() bool {
|
||||
fmt.Println(fmt.Sprintf("%v", time.Now()))
|
||||
return true
|
||||
})
|
||||
|
||||
glib.NewMainLoop(nil, false).Run()
|
||||
}
|
46
vendor/github.com/mattn/go-gtk/example/listview/listview.go
generated
vendored
Normal file
46
vendor/github.com/mattn/go-gtk/example/listview/listview.go
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/gdkpixbuf"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Stock Icons")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
swin := gtk.NewScrolledWindow(nil, nil)
|
||||
|
||||
store := gtk.NewListStore(glib.G_TYPE_STRING, glib.G_TYPE_BOOL, gdkpixbuf.GetType())
|
||||
treeview := gtk.NewTreeView()
|
||||
swin.Add(treeview)
|
||||
|
||||
treeview.SetModel(store)
|
||||
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("name", gtk.NewCellRendererText(), "text", 0))
|
||||
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("check", gtk.NewCellRendererToggle(), "active", 1))
|
||||
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("icon", gtk.NewCellRendererPixbuf(), "pixbuf", 2))
|
||||
n := 0
|
||||
gtk.StockListIDs().ForEach(func(d unsafe.Pointer, v interface{}) {
|
||||
id := glib.GPtrToString(d)
|
||||
var iter gtk.TreeIter
|
||||
store.Append(&iter)
|
||||
store.Set(&iter,
|
||||
0, id,
|
||||
1, (n == 1),
|
||||
2, gtk.NewImage().RenderIcon(id, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf,
|
||||
)
|
||||
n = 1 - n
|
||||
})
|
||||
|
||||
window.Add(swin)
|
||||
window.SetSizeRequest(400, 200)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
17
vendor/github.com/mattn/go-gtk/example/locale/locale.go
generated
vendored
Normal file
17
vendor/github.com/mattn/go-gtk/example/locale/locale.go
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import "github.com/mattn/go-gtk/gtk"
|
||||
import "github.com/mattn/go-gtk/glib"
|
||||
import "fmt"
|
||||
import "syscall"
|
||||
|
||||
func main() {
|
||||
gtk.SetLocale()
|
||||
|
||||
bs, _, _, err := glib.LocaleFromUtf8("こんにちわ世界\n")
|
||||
if err == nil {
|
||||
syscall.Write(syscall.Stdout, bs)
|
||||
} else {
|
||||
fmt.Println(err.Message())
|
||||
}
|
||||
}
|
42
vendor/github.com/mattn/go-gtk/example/notebook/notebook.go
generated
vendored
Normal file
42
vendor/github.com/mattn/go-gtk/example/notebook/notebook.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Notebook")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
notebook := gtk.NewNotebook()
|
||||
for n := 1; n <= 10; n++ {
|
||||
page := gtk.NewFrame("demo" + strconv.Itoa(n))
|
||||
notebook.AppendPage(page, gtk.NewLabel("demo"+strconv.Itoa(n)))
|
||||
|
||||
vbox := gtk.NewHBox(false, 1)
|
||||
|
||||
prev := gtk.NewButtonWithLabel("go prev")
|
||||
prev.Clicked(func() {
|
||||
notebook.PrevPage()
|
||||
})
|
||||
vbox.Add(prev)
|
||||
|
||||
next := gtk.NewButtonWithLabel("go next")
|
||||
next.Clicked(func() {
|
||||
notebook.NextPage()
|
||||
})
|
||||
vbox.Add(next)
|
||||
|
||||
page.Add(vbox)
|
||||
}
|
||||
|
||||
window.Add(notebook)
|
||||
window.SetSizeRequest(400, 200)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
56
vendor/github.com/mattn/go-gtk/example/number/number.go
generated
vendored
Normal file
56
vendor/github.com/mattn/go-gtk/example/number/number.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"strconv"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
|
||||
dialog := gtk.NewDialog()
|
||||
dialog.SetTitle("number input")
|
||||
|
||||
vbox := dialog.GetVBox()
|
||||
|
||||
label := gtk.NewLabel("Numnber:")
|
||||
vbox.Add(label)
|
||||
|
||||
input := gtk.NewEntry()
|
||||
input.SetEditable(true)
|
||||
vbox.Add(input)
|
||||
|
||||
input.Connect("insert-text", func(ctx *glib.CallbackContext) {
|
||||
a := (*[2000]uint8)(unsafe.Pointer(ctx.Args(0)))
|
||||
p := (*int)(unsafe.Pointer(ctx.Args(2)))
|
||||
i := 0
|
||||
for a[i] != 0 {
|
||||
i++
|
||||
}
|
||||
s := string(a[0:i])
|
||||
if s == "." {
|
||||
if *p == 0 {
|
||||
input.StopEmission("insert-text")
|
||||
}
|
||||
} else {
|
||||
_, err := strconv.ParseFloat(s, 64)
|
||||
if err != nil {
|
||||
input.StopEmission("insert-text")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
button := gtk.NewButtonWithLabel("OK")
|
||||
button.Connect("clicked", func() {
|
||||
fmt.Println(input.GetText())
|
||||
gtk.MainQuit()
|
||||
})
|
||||
vbox.Add(button)
|
||||
|
||||
dialog.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
61
vendor/github.com/mattn/go-gtk/example/sourceview/sourceview.go
generated
vendored
Normal file
61
vendor/github.com/mattn/go-gtk/example/sourceview/sourceview.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
gsv "github.com/mattn/go-gtk/gtksourceview"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("SourceView")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
swin := gtk.NewScrolledWindow(nil, nil)
|
||||
swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||
swin.SetShadowType(gtk.SHADOW_IN)
|
||||
sourcebuffer := gsv.NewSourceBufferWithLanguage(gsv.SourceLanguageManagerGetDefault().GetLanguage("cpp"))
|
||||
sourceview := gsv.NewSourceViewWithBuffer(sourcebuffer)
|
||||
|
||||
var start gtk.TextIter
|
||||
sourcebuffer.GetStartIter(&start)
|
||||
sourcebuffer.BeginNotUndoableAction()
|
||||
sourcebuffer.Insert(&start, `#include <iostream>
|
||||
template<class T>
|
||||
struct foo_base {
|
||||
T operator+(T const &rhs) const {
|
||||
T tmp(static_cast<T const &>(*this));
|
||||
tmp += rhs;
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
|
||||
class foo : public foo_base<foo> {
|
||||
private:
|
||||
int v;
|
||||
public:
|
||||
foo(int v) : v(v) {}
|
||||
foo &operator+=(foo const &rhs){
|
||||
this->v += rhs.v;
|
||||
return *this;
|
||||
}
|
||||
operator int() { return v; }
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
foo a(1), b(2);
|
||||
a += b;
|
||||
std::cout << (int)a << std::endl;
|
||||
}
|
||||
`)
|
||||
sourcebuffer.EndNotUndoableAction()
|
||||
|
||||
swin.Add(sourceview)
|
||||
|
||||
window.Add(swin)
|
||||
window.SetSizeRequest(400, 300)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
56
vendor/github.com/mattn/go-gtk/example/spinbutton/spinbutton.go
generated
vendored
Normal file
56
vendor/github.com/mattn/go-gtk/example/spinbutton/spinbutton.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetPosition(gtk.WIN_POS_CENTER)
|
||||
window.SetTitle("GTK Go!")
|
||||
window.Connect("destroy", func(ctx *glib.CallbackContext) {
|
||||
fmt.Println("got destroy!", ctx.Data().(string))
|
||||
gtk.MainQuit()
|
||||
}, "foo")
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkHBox
|
||||
//--------------------------------------------------------
|
||||
fixed := gtk.NewFixed()
|
||||
|
||||
//--------------------------------------------------------
|
||||
// GtkSpinButton
|
||||
//--------------------------------------------------------
|
||||
spinbutton1 := gtk.NewSpinButtonWithRange(1.0, 10.0, 1.0)
|
||||
spinbutton1.SetDigits(3)
|
||||
spinbutton1.Spin(gtk.SPIN_STEP_FORWARD, 7.0)
|
||||
fixed.Put(spinbutton1, 40, 50)
|
||||
|
||||
spinbutton1.OnValueChanged(func() {
|
||||
val := spinbutton1.GetValueAsInt()
|
||||
fval := spinbutton1.GetValue()
|
||||
fmt.Println("SpinButton changed, new value: " + strconv.Itoa(val) + " | " + strconv.FormatFloat(fval, 'f', 2, 64))
|
||||
min, max := spinbutton1.GetRange()
|
||||
fmt.Println("Range: " + strconv.FormatFloat(min, 'f', 2, 64) + " " + strconv.FormatFloat(max, 'f', 2, 64))
|
||||
fmt.Println("Digits: " + strconv.Itoa(int(spinbutton1.GetDigits())))
|
||||
})
|
||||
|
||||
adjustment := gtk.NewAdjustment(2.0, 1.0, 8.0, 2.0, 0.0, 0.0)
|
||||
spinbutton2 := gtk.NewSpinButton(adjustment, 1.0, 1)
|
||||
spinbutton2.SetRange(0.0, 20.0)
|
||||
spinbutton2.SetValue(18.0)
|
||||
spinbutton2.SetIncrements(2.0, 4.0)
|
||||
fixed.Put(spinbutton2, 150, 50)
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Event
|
||||
//--------------------------------------------------------
|
||||
window.Add(fixed)
|
||||
window.SetSizeRequest(600, 600)
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
40
vendor/github.com/mattn/go-gtk/example/statusicon/statusicon.go
generated
vendored
Normal file
40
vendor/github.com/mattn/go-gtk/example/statusicon/statusicon.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
|
||||
glib.SetApplicationName("go-gtk-statusicon-example")
|
||||
|
||||
mi := gtk.NewMenuItemWithLabel("Popup!")
|
||||
mi.Connect("activate", func() {
|
||||
gtk.MainQuit()
|
||||
})
|
||||
nm := gtk.NewMenu()
|
||||
nm.Append(mi)
|
||||
nm.ShowAll()
|
||||
|
||||
si := gtk.NewStatusIconFromStock(gtk.STOCK_FILE)
|
||||
si.SetTitle("StatusIcon Example")
|
||||
si.SetTooltipMarkup("StatusIcon Example")
|
||||
si.Connect("popup-menu", func(cbx *glib.CallbackContext) {
|
||||
nm.Popup(nil, nil, gtk.StatusIconPositionMenu, si, uint(cbx.Args(0)), uint32(cbx.Args(1)))
|
||||
})
|
||||
|
||||
fmt.Println(`
|
||||
Can you see statusicon in systray?
|
||||
If you don't see it and if you use 'unity', try following.
|
||||
|
||||
# gsettings set com.canonical.Unity.Panel systray-whitelist \
|
||||
"$(gsettings get com.canonical.Unity.Panel systray-whitelist \|
|
||||
sed -e "s/]$/, 'go-gtk-statusicon-example']/")"
|
||||
`)
|
||||
|
||||
gtk.Main()
|
||||
}
|
31
vendor/github.com/mattn/go-gtk/example/table/table.go
generated
vendored
Normal file
31
vendor/github.com/mattn/go-gtk/example/table/table.go
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Table")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
swin := gtk.NewScrolledWindow(nil, nil)
|
||||
swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||
|
||||
table := gtk.NewTable(5, 5, false)
|
||||
for y := uint(0); y < 5; y++ {
|
||||
for x := uint(0); x < 5; x++ {
|
||||
table.Attach(gtk.NewButtonWithLabel(fmt.Sprintf("%02d:%02d", x, y)), x, x+1, y, y+1, gtk.FILL, gtk.FILL, 5, 5)
|
||||
}
|
||||
}
|
||||
swin.AddWithViewPort(table)
|
||||
|
||||
window.Add(swin)
|
||||
window.SetDefaultSize(200, 200)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
55
vendor/github.com/mattn/go-gtk/example/textview/textview.go
generated
vendored
Normal file
55
vendor/github.com/mattn/go-gtk/example/textview/textview.go
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetPosition(gtk.WIN_POS_CENTER)
|
||||
window.SetTitle("GTK Go!")
|
||||
window.SetIconName("textview")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
textview := gtk.NewTextView()
|
||||
textview.SetEditable(true)
|
||||
textview.SetCursorVisible(true)
|
||||
var iter gtk.TextIter
|
||||
buffer := textview.GetBuffer()
|
||||
|
||||
buffer.GetStartIter(&iter)
|
||||
buffer.Insert(&iter, "Hello ")
|
||||
|
||||
tag := buffer.CreateTag("bold", map[string]string{"background": "#FF0000", "weight": "700"})
|
||||
buffer.InsertWithTag(&iter, "Google!", tag)
|
||||
|
||||
u := "http://www.google.com"
|
||||
tag.SetData("tag-name", unsafe.Pointer(&u))
|
||||
textview.Connect("event-after", func(ctx *glib.CallbackContext) {
|
||||
arg := ctx.Args(0)
|
||||
if ev := *(**gdk.EventAny)(unsafe.Pointer(&arg)); ev.Type != gdk.BUTTON_RELEASE {
|
||||
return
|
||||
}
|
||||
ev := *(**gdk.EventButton)(unsafe.Pointer(&arg))
|
||||
var iter gtk.TextIter
|
||||
textview.GetIterAtLocation(&iter, int(ev.X), int(ev.Y))
|
||||
tags := iter.GetTags()
|
||||
for n := uint(0); n < tags.Length(); n++ {
|
||||
vv := tags.NthData(n)
|
||||
tag := gtk.NewTextTagFromPointer(vv)
|
||||
u := *(*string)(tag.GetData("tag-name"))
|
||||
fmt.Println(u)
|
||||
}
|
||||
})
|
||||
|
||||
window.Add(textview)
|
||||
window.SetSizeRequest(600, 600)
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
51
vendor/github.com/mattn/go-gtk/example/thread/thread.go
generated
vendored
Normal file
51
vendor/github.com/mattn/go-gtk/example/thread/thread.go
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(10)
|
||||
glib.ThreadInit(nil)
|
||||
gdk.ThreadsInit()
|
||||
gdk.ThreadsEnter()
|
||||
gtk.Init(nil)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
vbox := gtk.NewVBox(false, 1)
|
||||
|
||||
label1 := gtk.NewLabel("")
|
||||
vbox.Add(label1)
|
||||
label2 := gtk.NewLabel("")
|
||||
vbox.Add(label2)
|
||||
|
||||
window.Add(vbox)
|
||||
|
||||
window.SetSizeRequest(100, 100)
|
||||
window.ShowAll()
|
||||
time.Sleep(1000 * 1000 * 100)
|
||||
go (func() {
|
||||
for i := 0; i < 300000; i++ {
|
||||
gdk.ThreadsEnter()
|
||||
label1.SetLabel(strconv.Itoa(i))
|
||||
gdk.ThreadsLeave()
|
||||
}
|
||||
gtk.MainQuit()
|
||||
})()
|
||||
go (func() {
|
||||
for i := 300000; i >= 0; i-- {
|
||||
gdk.ThreadsEnter()
|
||||
label2.SetLabel(strconv.Itoa(i))
|
||||
gdk.ThreadsLeave()
|
||||
}
|
||||
gtk.MainQuit()
|
||||
})()
|
||||
gtk.Main()
|
||||
}
|
108
vendor/github.com/mattn/go-gtk/example/toolbar/toolbar.go
generated
vendored
Normal file
108
vendor/github.com/mattn/go-gtk/example/toolbar/toolbar.go
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetPosition(gtk.WIN_POS_CENTER)
|
||||
window.SetTitle("GTK Go!")
|
||||
window.Connect("destroy", func(ctx *glib.CallbackContext) {
|
||||
gtk.MainQuit()
|
||||
}, "")
|
||||
|
||||
vbox := gtk.NewVBox(false, 0)
|
||||
|
||||
toolbar := gtk.NewToolbar()
|
||||
toolbar.SetStyle(gtk.TOOLBAR_ICONS)
|
||||
vbox.PackStart(toolbar, false, false, 5)
|
||||
|
||||
btnnew := gtk.NewToolButtonFromStock(gtk.STOCK_NEW)
|
||||
btnclose := gtk.NewToolButtonFromStock(gtk.STOCK_CLOSE)
|
||||
separator := gtk.NewSeparatorToolItem()
|
||||
btncustom := gtk.NewToolButton(nil, "Custom")
|
||||
btnmenu := gtk.NewMenuToolButtonFromStock("gtk.STOCK_CLOSE")
|
||||
btnmenu.SetArrowTooltipText("This is a tool tip")
|
||||
|
||||
btnnew.OnClicked(onToolButtonClicked)
|
||||
btnclose.OnClicked(onToolButtonClicked)
|
||||
btncustom.OnClicked(onToolButtonClicked)
|
||||
|
||||
toolmenu := gtk.NewMenu()
|
||||
menuitem := gtk.NewMenuItemWithMnemonic("8")
|
||||
menuitem.Show()
|
||||
toolmenu.Append(menuitem)
|
||||
menuitem = gtk.NewMenuItemWithMnemonic("16")
|
||||
menuitem.Show()
|
||||
toolmenu.Append(menuitem)
|
||||
menuitem = gtk.NewMenuItemWithMnemonic("32")
|
||||
menuitem.Show()
|
||||
toolmenu.Append(menuitem)
|
||||
btnmenu.SetMenu(toolmenu)
|
||||
|
||||
toolbar.Insert(btnnew, -1)
|
||||
toolbar.Insert(btnclose, -1)
|
||||
toolbar.Insert(separator, -1)
|
||||
toolbar.Insert(btncustom, -1)
|
||||
toolbar.Insert(btnmenu, -1)
|
||||
|
||||
hbox := gtk.NewHBox(false, 0)
|
||||
vbox.PackStart(hbox, true, true, 0)
|
||||
|
||||
toolbar2 := gtk.NewToolbar()
|
||||
toolbar2.SetOrientation(gtk.ORIENTATION_VERTICAL)
|
||||
hbox.PackStart(toolbar2, false, false, 5)
|
||||
btnhelp := gtk.NewToolButtonFromStock(gtk.STOCK_HELP)
|
||||
btnhelp.OnClicked(onToolButtonClicked)
|
||||
toolbar2.Insert(btnhelp, -1)
|
||||
|
||||
btntoggle := gtk.NewToggleToolButton()
|
||||
btntoggle2 := gtk.NewToggleToolButtonFromStock(gtk.STOCK_ITALIC)
|
||||
toolbar2.Insert(btntoggle, -1)
|
||||
toolbar2.Insert(btntoggle2, -1)
|
||||
|
||||
for i := 0; i < toolbar.GetNItems(); i++ {
|
||||
gti := toolbar.GetNthItem(i)
|
||||
switch gti.(type) {
|
||||
case *gtk.ToolButton:
|
||||
fmt.Printf("toolbar[%d] is a *gtk.ToolButton\n", i)
|
||||
w := gti.(*gtk.ToolButton).GetIconWidget()
|
||||
gti.(*gtk.ToolButton).SetIconWidget(w)
|
||||
case *gtk.ToggleToolButton:
|
||||
fmt.Printf("toolbar[%d] is a *gtk.ToggleToolButton\n", i)
|
||||
gti.(*gtk.ToggleToolButton).SetActive(true)
|
||||
case *gtk.SeparatorToolItem:
|
||||
fmt.Printf("toolbar[%d] is a *gtk.SeparatorToolItem\n", i)
|
||||
default:
|
||||
fmt.Printf("toolbar: Item is of unknown type\n")
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < toolbar2.GetNItems(); i++ {
|
||||
gti := toolbar2.GetNthItem(i)
|
||||
switch gti.(type) {
|
||||
case *gtk.ToolButton:
|
||||
fmt.Printf("toolbar2[%d] is a *gtk.ToolButton\n", i)
|
||||
case *gtk.ToggleToolButton:
|
||||
fmt.Printf("toolbar2[%d] is a *gtk.ToggleToolButton\n", i)
|
||||
gti.(*gtk.ToggleToolButton).SetActive(true)
|
||||
case *gtk.SeparatorToolItem:
|
||||
fmt.Printf("toolbar2[%d] is a *gtk.SeparatorToolItem\n", i)
|
||||
default:
|
||||
fmt.Printf("toolbar2: Item is of unknown type\n")
|
||||
}
|
||||
}
|
||||
|
||||
window.Add(vbox)
|
||||
window.SetSizeRequest(600, 600)
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
||||
|
||||
func onToolButtonClicked() {
|
||||
fmt.Println("ToolButton clicked")
|
||||
}
|
78
vendor/github.com/mattn/go-gtk/example/toolpalette/toolpalette.go
generated
vendored
Normal file
78
vendor/github.com/mattn/go-gtk/example/toolpalette/toolpalette.go
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(nil)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetPosition(gtk.WIN_POS_CENTER)
|
||||
window.SetTitle("GTK Go!")
|
||||
window.Connect("destroy", func(ctx *glib.CallbackContext) {
|
||||
gtk.MainQuit()
|
||||
}, "")
|
||||
|
||||
box := gtk.NewHPaned()
|
||||
|
||||
palette := gtk.NewToolPalette()
|
||||
group := gtk.NewToolItemGroup("Tools")
|
||||
b := gtk.NewToolButtonFromStock(gtk.STOCK_NEW)
|
||||
b.OnClicked(func() { fmt.Println("You clicked new!") })
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_CLOSE)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_REDO)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_REFRESH)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_QUIT)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_YES)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_NO)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_PRINT)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_NETWORK)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_INFO)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_HOME)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_INDEX)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_FIND)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_FILE)
|
||||
group.Insert(b, -1)
|
||||
b = gtk.NewToolButtonFromStock(gtk.STOCK_EXECUTE)
|
||||
group.Insert(b, -1)
|
||||
palette.Add(group)
|
||||
|
||||
bcopy := gtk.NewToolButtonFromStock(gtk.STOCK_COPY)
|
||||
bcut := gtk.NewToolButtonFromStock(gtk.STOCK_CUT)
|
||||
bdelete := gtk.NewToolButtonFromStock(gtk.STOCK_DELETE)
|
||||
|
||||
group = gtk.NewToolItemGroup("Stuff")
|
||||
group.Insert(bcopy, -1)
|
||||
group.Insert(bcut, -1)
|
||||
group.Insert(bdelete, -1)
|
||||
palette.Add(group)
|
||||
|
||||
frame := gtk.NewVBox(false, 1)
|
||||
align := gtk.NewAlignment(0, 0, 0, 0)
|
||||
image := gtk.NewImageFromFile("./turkey.jpg")
|
||||
align.Add(image)
|
||||
frame.Add(align)
|
||||
|
||||
box.Pack1(palette, true, false)
|
||||
box.Pack2(frame, false, false)
|
||||
|
||||
window.Add(box)
|
||||
window.SetSizeRequest(600, 600)
|
||||
window.ShowAll()
|
||||
gtk.Main()
|
||||
}
|
BIN
vendor/github.com/mattn/go-gtk/example/toolpalette/turkey.jpg
generated
vendored
Normal file
BIN
vendor/github.com/mattn/go-gtk/example/toolpalette/turkey.jpg
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
60
vendor/github.com/mattn/go-gtk/example/treeview/treeview.go
generated
vendored
Normal file
60
vendor/github.com/mattn/go-gtk/example/treeview/treeview.go
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattn/go-gtk/gdkpixbuf"
|
||||
"github.com/mattn/go-gtk/glib"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("GTK Folder View")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
swin := gtk.NewScrolledWindow(nil, nil)
|
||||
|
||||
store := gtk.NewTreeStore(gdkpixbuf.GetType(), glib.G_TYPE_STRING)
|
||||
treeview := gtk.NewTreeView()
|
||||
swin.Add(treeview)
|
||||
|
||||
treeview.SetModel(store.ToTreeModel())
|
||||
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("pixbuf", gtk.NewCellRendererPixbuf(), "pixbuf", 0))
|
||||
treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("text", gtk.NewCellRendererText(), "text", 1))
|
||||
|
||||
for n := 1; n <= 10; n++ {
|
||||
var iter1, iter2, iter3 gtk.TreeIter
|
||||
store.Append(&iter1, nil)
|
||||
store.Set(&iter1, gtk.NewImage().RenderIcon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf, "Folder"+strconv.Itoa(n))
|
||||
store.Append(&iter2, &iter1)
|
||||
store.Set(&iter2, gtk.NewImage().RenderIcon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf, "SubFolder"+strconv.Itoa(n))
|
||||
store.Append(&iter3, &iter2)
|
||||
store.Set(&iter3, gtk.NewImage().RenderIcon(gtk.STOCK_FILE, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf, "File"+strconv.Itoa(n))
|
||||
}
|
||||
|
||||
treeview.Connect("row_activated", func() {
|
||||
var path *gtk.TreePath
|
||||
var column *gtk.TreeViewColumn
|
||||
treeview.GetCursor(&path, &column)
|
||||
mes := "TreePath is: " + path.String()
|
||||
dialog := gtk.NewMessageDialog(
|
||||
treeview.GetTopLevelAsWindow(),
|
||||
gtk.DIALOG_MODAL,
|
||||
gtk.MESSAGE_INFO,
|
||||
gtk.BUTTONS_OK,
|
||||
mes)
|
||||
dialog.SetTitle("TreePath")
|
||||
dialog.Response(func() {
|
||||
dialog.Destroy()
|
||||
})
|
||||
dialog.Run()
|
||||
})
|
||||
|
||||
window.Add(swin)
|
||||
window.SetSizeRequest(400, 200)
|
||||
window.ShowAll()
|
||||
|
||||
gtk.Main()
|
||||
}
|
6
vendor/github.com/mattn/go-gtk/example/twitterstream/settings.json.example
generated
vendored
Normal file
6
vendor/github.com/mattn/go-gtk/example/twitterstream/settings.json.example
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"AccessSecret": "ACCCESS_TOKEN_SECRET",
|
||||
"AccessToken": "ACCESS_TOKEN",
|
||||
"ClientSecret": "CLIENT_SECRET",
|
||||
"ClientToken": "CLIENT_TOKEN"
|
||||
}
|
249
vendor/github.com/mattn/go-gtk/example/twitterstream/twitterstream.go
generated
vendored
Normal file
249
vendor/github.com/mattn/go-gtk/example/twitterstream/twitterstream.go
generated
vendored
Normal file
@@ -0,0 +1,249 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/garyburd/go-oauth/oauth"
|
||||
"github.com/mattn/go-gtk/gdkpixbuf"
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
var (
|
||||
alive = true
|
||||
)
|
||||
|
||||
func readURL(url string) ([]byte, *http.Response) {
|
||||
r, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
var b []byte
|
||||
if b, err = ioutil.ReadAll(r.Body); err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
return b, r
|
||||
}
|
||||
|
||||
func bytes2pixbuf(data []byte, typ string) *gdkpixbuf.Pixbuf {
|
||||
var loader *gdkpixbuf.Loader
|
||||
if strings.Index(typ, "jpeg") >= 0 {
|
||||
loader, _ = gdkpixbuf.NewLoaderWithMimeType("image/jpeg")
|
||||
} else {
|
||||
loader, _ = gdkpixbuf.NewLoaderWithMimeType("image/png")
|
||||
}
|
||||
loader.SetSize(24, 24)
|
||||
loader.Write(data)
|
||||
loader.Close()
|
||||
return loader.GetPixbuf()
|
||||
}
|
||||
|
||||
type tweet struct {
|
||||
Text string
|
||||
Identifier string `json:"id_str"`
|
||||
Source string
|
||||
User struct {
|
||||
Name string
|
||||
ScreenName string `json:"screen_name"`
|
||||
FollowersCount int `json:"followers_count"`
|
||||
ProfileImageUrl string `json:"profile_image_url"`
|
||||
}
|
||||
Place *struct {
|
||||
Id string
|
||||
FullName string `json:"full_name"`
|
||||
}
|
||||
Entities struct {
|
||||
HashTags []struct {
|
||||
Indices [2]int
|
||||
Text string
|
||||
}
|
||||
UserMentions []struct {
|
||||
Indices [2]int
|
||||
ScreenName string `json:"screen_name"`
|
||||
} `json:"user_mentions"`
|
||||
Urls []struct {
|
||||
Indices [2]int
|
||||
Url string
|
||||
DisplayUrl string `json:"display_url"`
|
||||
ExpandedUrl *string `json:"expanded_url"`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func stream(client *oauth.Client, cred *oauth.Credentials, f func(*tweet)) {
|
||||
param := make(url.Values)
|
||||
uri := "https://userstream.twitter.com/1.1/user.json"
|
||||
client.SignParam(cred, "GET", uri, param)
|
||||
uri = uri + "?" + param.Encode()
|
||||
res, err := http.Get(uri)
|
||||
if err != nil {
|
||||
log.Fatal("failed to get tweets:", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
log.Fatal("failed to get tweets:", err)
|
||||
}
|
||||
var buf *bufio.Reader
|
||||
if res.Header.Get("Content-Encoding") == "gzip" {
|
||||
gr, err := gzip.NewReader(res.Body)
|
||||
if err != nil {
|
||||
log.Fatal("failed to make gzip decoder:", err)
|
||||
}
|
||||
buf = bufio.NewReader(gr)
|
||||
} else {
|
||||
buf = bufio.NewReader(res.Body)
|
||||
}
|
||||
var last []byte
|
||||
for alive {
|
||||
b, _, err := buf.ReadLine()
|
||||
last = append(last, b...)
|
||||
var t tweet
|
||||
err = json.Unmarshal(last, &t)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
last = []byte{}
|
||||
if t.Text == "" {
|
||||
continue
|
||||
}
|
||||
f(&t)
|
||||
}
|
||||
}
|
||||
|
||||
func post(client *oauth.Client, cred *oauth.Credentials, s string) {
|
||||
param := make(url.Values)
|
||||
param.Set("status", s)
|
||||
uri := "https://api.twitter.com/1.1/statuses/update.json"
|
||||
client.SignParam(cred, "POST", uri, param)
|
||||
res, err := http.PostForm(uri, url.Values(param))
|
||||
if err != nil {
|
||||
log.Println("failed to post tweet:", err)
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
log.Println("failed to get timeline:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func display(t *tweet, buffer *gtk.TextBuffer, tag *gtk.TextTag) {
|
||||
var iter gtk.TextIter
|
||||
pixbufbytes, resp := readURL(t.User.ProfileImageUrl)
|
||||
buffer.GetStartIter(&iter)
|
||||
if resp != nil {
|
||||
buffer.InsertPixbuf(&iter, bytes2pixbuf(pixbufbytes, resp.Header.Get("Content-Type")))
|
||||
}
|
||||
buffer.Insert(&iter, " ")
|
||||
buffer.InsertWithTag(&iter, t.User.ScreenName, tag)
|
||||
buffer.Insert(&iter, ":"+t.Text+"\n")
|
||||
gtk.MainIterationDo(false)
|
||||
}
|
||||
|
||||
func show(client *oauth.Client, cred *oauth.Credentials, f func(t *tweet)) {
|
||||
param := make(url.Values)
|
||||
uri := "https://api.twitter.com/1.1/statuses/home_timeline.json"
|
||||
client.SignParam(cred, "GET", uri, param)
|
||||
uri = uri + "?" + param.Encode()
|
||||
res, err := http.Get(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
return
|
||||
}
|
||||
var tweets []tweet
|
||||
json.NewDecoder(res.Body).Decode(&tweets)
|
||||
for _, t := range tweets {
|
||||
f(&t)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
b, err := ioutil.ReadFile("settings.json")
|
||||
if err != nil {
|
||||
fmt.Println(`"settings.json" not found: `, err)
|
||||
return
|
||||
}
|
||||
var config map[string]string
|
||||
err = json.Unmarshal(b, &config)
|
||||
if err != nil {
|
||||
fmt.Println(`can't read "settings.json": `, err)
|
||||
return
|
||||
}
|
||||
client := &oauth.Client{Credentials: oauth.Credentials{config["ClientToken"], config["ClientSecret"]}}
|
||||
cred := &oauth.Credentials{config["AccessToken"], config["AccessSecret"]}
|
||||
|
||||
runtime.LockOSThread()
|
||||
gtk.Init(&os.Args)
|
||||
window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||
window.SetTitle("Twitter!")
|
||||
window.Connect("destroy", gtk.MainQuit)
|
||||
|
||||
vbox := gtk.NewVBox(false, 1)
|
||||
|
||||
scrolledwin := gtk.NewScrolledWindow(nil, nil)
|
||||
textview := gtk.NewTextView()
|
||||
textview.SetEditable(false)
|
||||
textview.SetCursorVisible(false)
|
||||
scrolledwin.Add(textview)
|
||||
vbox.Add(scrolledwin)
|
||||
|
||||
buffer := textview.GetBuffer()
|
||||
tag := buffer.CreateTag("blue", map[string]string{"foreground": "#0000FF", "weight": "700"})
|
||||
|
||||
hbox := gtk.NewHBox(false, 1)
|
||||
vbox.PackEnd(hbox, false, true, 5)
|
||||
|
||||
label := gtk.NewLabel("Tweet")
|
||||
hbox.PackStart(label, false, false, 5)
|
||||
text := gtk.NewEntry()
|
||||
hbox.PackEnd(text, true, true, 5)
|
||||
|
||||
text.Connect("activate", func() {
|
||||
t := text.GetText()
|
||||
text.SetText("")
|
||||
post(client, cred, t)
|
||||
})
|
||||
|
||||
window.Add(vbox)
|
||||
window.SetSizeRequest(800, 500)
|
||||
window.ShowAll()
|
||||
|
||||
var mutex sync.Mutex
|
||||
|
||||
go func() {
|
||||
show(client, cred, func(t *tweet) {
|
||||
mutex.Lock()
|
||||
display(t, buffer, tag)
|
||||
mutex.Unlock()
|
||||
})
|
||||
|
||||
stream(client, cred, func(t *tweet) {
|
||||
mutex.Lock()
|
||||
display(t, buffer, tag)
|
||||
var start, end gtk.TextIter
|
||||
buffer.GetIterAtLine(&start, buffer.GetLineCount()-2)
|
||||
buffer.GetEndIter(&end)
|
||||
buffer.Delete(&start, &end)
|
||||
mutex.Unlock()
|
||||
})
|
||||
}()
|
||||
|
||||
for alive {
|
||||
mutex.Lock()
|
||||
alive = gtk.MainIterationDo(false)
|
||||
mutex.Unlock()
|
||||
}
|
||||
}
|
3008
vendor/github.com/mattn/go-gtk/gdk/gdk.go
generated
vendored
Normal file
3008
vendor/github.com/mattn/go-gtk/gdk/gdk.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
23
vendor/github.com/mattn/go-gtk/gdk/gdk.go.h
generated
vendored
Normal file
23
vendor/github.com/mattn/go-gtk/gdk/gdk.go.h
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef GO_GDK_H
|
||||
#define GO_GDK_H
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
static gchar* toGstr(char* s) { return (gchar*)s; }
|
||||
|
||||
static void freeCstr(char* s) { free(s); }
|
||||
|
||||
static GdkWindow* toGdkWindow(void* w) { return GDK_WINDOW(w); }
|
||||
static GdkDragContext* toGdkDragContext(void* l) { return (GdkDragContext*)l; }
|
||||
static GdkFont* toGdkFont(void* l) { return (GdkFont*)l; }
|
||||
|
||||
static void* _gdk_display_get_default() {
|
||||
return (void*) gdk_display_get_default();
|
||||
}
|
||||
|
||||
#endif
|
1
vendor/github.com/mattn/go-gtk/gdk/gdk_freebsd.go
generated
vendored
Symbolic link
1
vendor/github.com/mattn/go-gtk/gdk/gdk_freebsd.go
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
gdk_linux.go
|
15
vendor/github.com/mattn/go-gtk/gdk/gdk_linux.go
generated
vendored
Normal file
15
vendor/github.com/mattn/go-gtk/gdk/gdk_linux.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// +build !cgocheck
|
||||
|
||||
package gdk
|
||||
|
||||
/*
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
// #cgo pkg-config: gdk-2.0 gthread-2.0
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
func (v *Window) GetNativeWindowID() int32 {
|
||||
return int32(C.gdk_x11_drawable_get_xid((*C.GdkDrawable)(unsafe.Pointer(v.GWindow))))
|
||||
}
|
33
vendor/github.com/mattn/go-gtk/gdk/gdk_quartz_darwin.go
generated
vendored
Normal file
33
vendor/github.com/mattn/go-gtk/gdk/gdk_quartz_darwin.go
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
// +build !with-x11
|
||||
|
||||
package gdk
|
||||
|
||||
/*
|
||||
#cgo pkg-config: gdk-2.0 gthread-2.0
|
||||
#cgo CFLAGS: -x objective-c
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkquartz.h>
|
||||
|
||||
// Must return void* to avoid "struct size calculation error off=8 bytesize=0"
|
||||
// See:
|
||||
// - https://github.com/golang/go/issues/12065
|
||||
// - http://thread0.me/2015/07/gogoa-cocoa-bindings-for-go/
|
||||
void* getNsWindow(GdkWindow *w) {
|
||||
return (void*) gdk_quartz_window_get_nswindow(w);
|
||||
}
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type NSWindow struct {
|
||||
ID unsafe.Pointer
|
||||
}
|
||||
|
||||
func (v *Window) GetNativeWindow() *NSWindow {
|
||||
return &NSWindow{
|
||||
unsafe.Pointer(C.getNsWindow(v.GWindow)),
|
||||
}
|
||||
}
|
15
vendor/github.com/mattn/go-gtk/gdk/gdk_windows.go
generated
vendored
Normal file
15
vendor/github.com/mattn/go-gtk/gdk/gdk_windows.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// +build !cgocheck
|
||||
|
||||
package gdk
|
||||
|
||||
/*
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkwin32.h>
|
||||
// #cgo pkg-config: gdk-2.0 gthread-2.0
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
func (v *Window) GetNativeWindowID() int32 {
|
||||
return int32(uintptr(unsafe.Pointer(C.gdk_win32_drawable_get_handle((*C.GdkDrawable)(unsafe.Pointer(v.GWindow))))))
|
||||
}
|
16
vendor/github.com/mattn/go-gtk/gdk/gdk_x11_darwin.go
generated
vendored
Normal file
16
vendor/github.com/mattn/go-gtk/gdk/gdk_x11_darwin.go
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
// +build with-x11
|
||||
|
||||
package gdk
|
||||
|
||||
/*
|
||||
#cgo pkg-config: gdk-2.0 gthread-2.0
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
func (v *Window) GetNativeWindowID() int32 {
|
||||
return int32(C.gdk_x11_drawable_get_xid((*C.GdkDrawable)(unsafe.Pointer(v.GWindow))))
|
||||
}
|
520
vendor/github.com/mattn/go-gtk/gdkpixbuf/gdkpixbuf.go
generated
vendored
Normal file
520
vendor/github.com/mattn/go-gtk/gdkpixbuf/gdkpixbuf.go
generated
vendored
Normal file
@@ -0,0 +1,520 @@
|
||||
// +build !cgocheck
|
||||
|
||||
package gdkpixbuf
|
||||
|
||||
// #include "gdkpixbuf.go.h"
|
||||
// #cgo pkg-config: gdk-pixbuf-2.0
|
||||
import "C"
|
||||
import "github.com/mattn/go-gtk/glib"
|
||||
import (
|
||||
"log"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func gstring(s *C.char) *C.gchar { return C.toGstr(s) }
|
||||
func cstring(s *C.gchar) *C.char { return C.toCstr(s) }
|
||||
func gostring(s *C.gchar) string { return C.GoString(cstring(s)) }
|
||||
|
||||
func gbool(b bool) C.gboolean {
|
||||
if b {
|
||||
return C.gboolean(1)
|
||||
}
|
||||
return C.gboolean(0)
|
||||
}
|
||||
|
||||
func gobool(b C.gboolean) bool {
|
||||
if b != 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func cfree(s *C.char) { C.freeCstr(s) }
|
||||
|
||||
func panic_if_version_older(major int, minor int, micro int, function string) {
|
||||
if C._check_version(C.int(major), C.int(minor), C.int(micro)) == 0 {
|
||||
log.Panicf("%s is not provided on your Glib, version %d.%d is required\n", function, major, minor)
|
||||
}
|
||||
}
|
||||
|
||||
func panic_if_version_older_auto(major, minor, micro int) {
|
||||
if C._check_version(C.int(major), C.int(minor), C.int(micro)) != 0 {
|
||||
return
|
||||
}
|
||||
formatStr := "%s is not provided on your Glib, version %d.%d is required\n"
|
||||
if pc, _, _, ok := runtime.Caller(1); ok {
|
||||
log.Panicf(formatStr, runtime.FuncForPC(pc).Name(), major, minor)
|
||||
} else {
|
||||
log.Panicf("Glib version %d.%d is required (unknown caller, see stack)\n",
|
||||
major, minor)
|
||||
}
|
||||
}
|
||||
|
||||
func deprecated_since(major int, minor int, micro int, function string) {
|
||||
if C._check_version(C.int(major), C.int(minor), C.int(micro)) != 0 {
|
||||
log.Printf("\nWarning: %s is deprecated since glib %d.%d\n", function, major, minor)
|
||||
}
|
||||
}
|
||||
|
||||
func argumentPanic(message string) {
|
||||
if pc, _, _, ok := runtime.Caller(2); ok {
|
||||
log.Panicf("Arguments error: %s : %s\n",
|
||||
runtime.FuncForPC(pc).Name(), message)
|
||||
} else {
|
||||
log.Panicln("Arguments error: (unknown caller, see stack):", message)
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Pixbuf
|
||||
//-----------------------------------------------------------------------
|
||||
type Pixbuf struct {
|
||||
*GdkPixbuf
|
||||
*glib.GObject
|
||||
}
|
||||
|
||||
type GdkPixbuf struct {
|
||||
GPixbuf *C.GdkPixbuf
|
||||
}
|
||||
|
||||
func NewGdkPixbuf(p unsafe.Pointer) *GdkPixbuf {
|
||||
return &GdkPixbuf{(*C.GdkPixbuf)(p)}
|
||||
}
|
||||
|
||||
// File Loading
|
||||
// GdkPixbuf * gdk_pixbuf_new (GdkColorspace colorspace, gboolean has_alpha, int bits_per_sample, int width, int height);
|
||||
func NewPixbuf(colorspace Colorspace, hasAlpha bool, bitsPerSample, width, height int) *Pixbuf {
|
||||
gpixbuf := C.gdk_pixbuf_new(
|
||||
C.GdkColorspace(colorspace),
|
||||
gbool(hasAlpha),
|
||||
C.int(bitsPerSample),
|
||||
C.int(width),
|
||||
C.int(height),
|
||||
)
|
||||
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}
|
||||
}
|
||||
|
||||
func NewPixbufFromFile(filename string) (*Pixbuf, *glib.Error) {
|
||||
var err *C.GError
|
||||
ptr := C.CString(filename)
|
||||
defer cfree(ptr)
|
||||
gpixbuf := C.gdk_pixbuf_new_from_file(ptr, &err)
|
||||
if err != nil {
|
||||
return nil, glib.ErrorFromNative(unsafe.Pointer(err))
|
||||
}
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewPixbufFromFileAtSize(filename string, width, heigth int) (*Pixbuf, *glib.Error) {
|
||||
var err *C.GError
|
||||
ptr := C.CString(filename)
|
||||
defer cfree(ptr)
|
||||
gpixbuf := C.gdk_pixbuf_new_from_file_at_size(ptr, C.int(width), C.int(heigth), &err)
|
||||
if err != nil {
|
||||
return nil, glib.ErrorFromNative(unsafe.Pointer(err))
|
||||
}
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewPixbufFromFileAtScale(filename string, width, height int, preserve_aspect_ratio bool) (*Pixbuf, *glib.Error) {
|
||||
var err *C.GError
|
||||
ptr := C.CString(filename)
|
||||
defer cfree(ptr)
|
||||
gpixbuf := C.gdk_pixbuf_new_from_file_at_scale(ptr, C.int(width), C.int(height), gbool(preserve_aspect_ratio), &err)
|
||||
if err != nil {
|
||||
return nil, glib.ErrorFromNative(unsafe.Pointer(err))
|
||||
}
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewPixbufFromData creates a Pixbuf from image data in a byte array
|
||||
//
|
||||
// Can be used for reading Base64 encoded images easily with the output from base64.StdEncoding.DecodeString("...")
|
||||
func NewPixbufFromData(buffer []byte) (*Pixbuf, *glib.Error) {
|
||||
var err *C.GError
|
||||
loader := C.gdk_pixbuf_loader_new()
|
||||
C.gdk_pixbuf_loader_write(loader, C.to_gucharptr(unsafe.Pointer(&buffer[0])), C.gsize(len(buffer)), &err)
|
||||
gpixbuf := C.gdk_pixbuf_loader_get_pixbuf(loader)
|
||||
|
||||
if err != nil {
|
||||
return nil, glib.ErrorFromNative(unsafe.Pointer(err))
|
||||
}
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewPixbufFromBytes creates a Pixbuf from image data in a byte array
|
||||
//
|
||||
// Can be used for reading Base64 encoded images easily with the output from base64.StdEncoding.DecodeString("...")
|
||||
func NewPixbufFromBytes(buffer []byte) (*Pixbuf, *glib.Error) {
|
||||
var err *C.GError
|
||||
loader := C.gdk_pixbuf_loader_new()
|
||||
C.gdk_pixbuf_loader_write(loader, C.to_gucharptr(unsafe.Pointer(&buffer[0])), C.gsize(len(buffer)), &err)
|
||||
gpixbuf := C.gdk_pixbuf_loader_get_pixbuf(loader)
|
||||
|
||||
if err != nil {
|
||||
return nil, glib.ErrorFromNative(unsafe.Pointer(err))
|
||||
}
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewPixbufFromXpmData(data **byte) (*Pixbuf, *glib.Error) {
|
||||
var err *C.GError
|
||||
gpixbuf := C.gdk_pixbuf_new_from_xpm_data(
|
||||
(**C.char)(unsafe.Pointer(data)),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, glib.ErrorFromNative(unsafe.Pointer(err))
|
||||
}
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func GetType() int {
|
||||
return int(C.gdk_pixbuf_get_type())
|
||||
}
|
||||
|
||||
func GetFileInfo(filename string, width, height *int) *Format {
|
||||
ptr := C.CString(filename)
|
||||
defer cfree(ptr)
|
||||
|
||||
var w, h C.gint
|
||||
format := &Format{C.gdk_pixbuf_get_file_info(gstring(ptr), &w, &h)}
|
||||
*width = int(w)
|
||||
*height = int(h)
|
||||
return format
|
||||
}
|
||||
|
||||
// Scaling
|
||||
|
||||
type InterpType int
|
||||
|
||||
const (
|
||||
INTERP_NEAREST InterpType = iota
|
||||
INTERP_TILES
|
||||
INTERP_BILINEAR
|
||||
INTERP_HYPER
|
||||
)
|
||||
|
||||
func (p *Pixbuf) ScaleSimple(width, height int, interp InterpType) *Pixbuf {
|
||||
gpixbuf := C.gdk_pixbuf_scale_simple(p.GPixbuf, C.int(width), C.int(height), C.GdkInterpType(interp))
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pixbuf) Scale(x, y, width, height int, offsetX, offsetY, scaleX, scaleY float64, interp InterpType) *Pixbuf {
|
||||
var gpixbuf *C.GdkPixbuf
|
||||
C.gdk_pixbuf_scale(
|
||||
p.GPixbuf,
|
||||
gpixbuf,
|
||||
C.int(x), C.int(y),
|
||||
C.int(width), C.int(height),
|
||||
C.double(offsetX), C.double(offsetY),
|
||||
C.double(scaleX), C.double(scaleY),
|
||||
C.GdkInterpType(interp))
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}
|
||||
}
|
||||
|
||||
// gdk_pixbuf_composite_color_simple
|
||||
// gdk_pixbuf_composite
|
||||
// gdk_pixbuf_composite_color
|
||||
|
||||
type PixbufRotation int
|
||||
|
||||
const (
|
||||
PIXBUF_ROTATE_NONE PixbufRotation = 0
|
||||
PIXBUF_ROTATE_COUNTERCLOCKWISE PixbufRotation = 90
|
||||
PIXBUF_ROTATE_UPSIDEDOWN PixbufRotation = 180
|
||||
PIXBUF_ROTATE_CLOCKWISE PixbufRotation = 270
|
||||
)
|
||||
|
||||
func (p *Pixbuf) RotateSimple(angle PixbufRotation) *Pixbuf {
|
||||
gpixbuf := C.gdk_pixbuf_rotate_simple(p.GPixbuf, C.GdkPixbufRotation(angle))
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pixbuf) Flip(horizontal bool) *Pixbuf {
|
||||
gpixbuf := C.gdk_pixbuf_flip(p.GPixbuf, gbool(horizontal))
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pixbuf) Fill(pixel uint32) {
|
||||
C.gdk_pixbuf_fill(p.GPixbuf, C.guint32(pixel))
|
||||
}
|
||||
|
||||
// The GdkPixbuf Structure
|
||||
|
||||
type Colorspace int
|
||||
|
||||
const (
|
||||
GDK_COLORSPACE_RGB Colorspace = iota
|
||||
)
|
||||
|
||||
type PixbufAlphaMode int
|
||||
|
||||
const (
|
||||
GDK_PIXBUF_ALPHA_BILEVEL PixbufAlphaMode = iota
|
||||
GDK_PIXBUF_ALPHA_FULL
|
||||
)
|
||||
|
||||
func (p *Pixbuf) GetColorspace() Colorspace {
|
||||
return Colorspace(C.gdk_pixbuf_get_colorspace(p.GPixbuf))
|
||||
}
|
||||
|
||||
func (p *Pixbuf) GetNChannels() int {
|
||||
return int(C.gdk_pixbuf_get_n_channels(p.GPixbuf))
|
||||
}
|
||||
|
||||
func (p *Pixbuf) GetHasAlpha() bool {
|
||||
return gobool(C.gdk_pixbuf_get_has_alpha(p.GPixbuf))
|
||||
}
|
||||
|
||||
func (p *Pixbuf) GetBitsPerSample() int {
|
||||
return int(C.gdk_pixbuf_get_bits_per_sample(p.GPixbuf))
|
||||
}
|
||||
|
||||
func (p *Pixbuf) GetPixels() []byte {
|
||||
ptr := C.gdk_pixbuf_get_pixels(
|
||||
p.GPixbuf,
|
||||
)
|
||||
return (*[1 << 30]byte)(unsafe.Pointer(ptr))[:]
|
||||
}
|
||||
|
||||
// guchar * gdk_pixbuf_get_pixels_with_length (const GdkPixbuf *pixbuf, guint *length);
|
||||
//
|
||||
// Retuns a slice of byte backed by a C array of pixbuf data.
|
||||
func (p *Pixbuf) GetPixelsWithLength() []byte {
|
||||
panic_if_version_older(2, 26, 0, "gdk_pixbuf_get_pixels_with_length()")
|
||||
length := C.guint(0)
|
||||
ptr := C._gdk_pixbuf_get_pixels_with_length(
|
||||
p.GPixbuf,
|
||||
&length,
|
||||
)
|
||||
return (*[1 << 30]byte)(unsafe.Pointer(ptr))[:length]
|
||||
}
|
||||
|
||||
func (p *Pixbuf) GetWidth() int {
|
||||
return int(C.gdk_pixbuf_get_width(p.GPixbuf))
|
||||
}
|
||||
|
||||
func (p *Pixbuf) GetHeight() int {
|
||||
return int(C.gdk_pixbuf_get_height(p.GPixbuf))
|
||||
}
|
||||
|
||||
func (p *Pixbuf) GetRowstride() int {
|
||||
return int(C.gdk_pixbuf_get_rowstride(p.GPixbuf))
|
||||
}
|
||||
|
||||
// gdk_pixbuf_get_byte_length
|
||||
// gdk_pixbuf_get_option
|
||||
|
||||
// File saving
|
||||
|
||||
func (p *Pixbuf) Save(filename, savetype string, options ...string) *glib.Error {
|
||||
if len(options)%2 != 0 {
|
||||
argumentPanic("Save options must be even (key and value)")
|
||||
}
|
||||
|
||||
pfilename := C.CString(filename)
|
||||
defer cfree(pfilename)
|
||||
psavetype := C.CString(savetype)
|
||||
defer cfree(psavetype)
|
||||
|
||||
klen := len(options) / 2
|
||||
keys := C.makeCstrv(C.int(klen + 1))
|
||||
vals := C.makeCstrv(C.int(klen + 1))
|
||||
for i := 0; i < klen; i++ {
|
||||
C.setCstr(keys, C.int(i), C.CString(options[2*i]))
|
||||
C.setCstr(vals, C.int(i), C.CString(options[2*i+1]))
|
||||
}
|
||||
C.setCstr(keys, C.int(klen), nil)
|
||||
C.setCstr(vals, C.int(klen), nil)
|
||||
defer func() {
|
||||
for i := 0; i < klen; i++ {
|
||||
cfree(C.getCstr(keys, C.int(i)))
|
||||
cfree(C.getCstr(vals, C.int(i)))
|
||||
}
|
||||
C.freeCstrv(keys)
|
||||
C.freeCstrv(vals)
|
||||
}()
|
||||
|
||||
var err *C.GError
|
||||
C.gdk_pixbuf_savev(p.GPixbuf, pfilename, psavetype, keys, vals, &err)
|
||||
if err != nil {
|
||||
return glib.ErrorFromNative(unsafe.Pointer(err))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Animation
|
||||
//-----------------------------------------------------------------------
|
||||
type Animation struct {
|
||||
GPixbufAnimation *C.GdkPixbufAnimation
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Format
|
||||
//-----------------------------------------------------------------------
|
||||
type Format struct {
|
||||
GPixbufFormat *C.GdkPixbufFormat
|
||||
}
|
||||
|
||||
// gdk_pixbuf_get_formats
|
||||
|
||||
func (v *Format) GetName() string {
|
||||
return gostring(C.gdk_pixbuf_format_get_name(v.GPixbufFormat))
|
||||
}
|
||||
|
||||
func (v *Format) GetDescription() string {
|
||||
return gostring(C.gdk_pixbuf_format_get_description(v.GPixbufFormat))
|
||||
}
|
||||
|
||||
func (v *Format) GetMimeTypes() []string {
|
||||
gstrv := C.gdk_pixbuf_format_get_mime_types(v.GPixbufFormat)
|
||||
defer C.g_strfreev(gstrv)
|
||||
s := make([]string, 0)
|
||||
for i := 0; C.getGstr(gstrv, C.int(i)) != nil; i++ {
|
||||
s = append(s, gostring(C.getGstr(gstrv, C.int(i))))
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (v *Format) GetExtensions() []string {
|
||||
gstrv := C.gdk_pixbuf_format_get_extensions(v.GPixbufFormat)
|
||||
defer C.g_strfreev(gstrv)
|
||||
s := make([]string, 0)
|
||||
for i := 0; C.getGstr(gstrv, C.int(i)) != nil; i++ {
|
||||
s = append(s, gostring(C.getGstr(gstrv, C.int(i))))
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (v *Format) IsWritable() bool {
|
||||
return gobool(C.gdk_pixbuf_format_is_writable(v.GPixbufFormat))
|
||||
}
|
||||
|
||||
func (v *Format) IsScalable() bool {
|
||||
return gobool(C.gdk_pixbuf_format_is_scalable(v.GPixbufFormat))
|
||||
}
|
||||
|
||||
func (v *Format) IsDisabled() bool {
|
||||
return gobool(C.gdk_pixbuf_format_is_disabled(v.GPixbufFormat))
|
||||
}
|
||||
|
||||
func (v *Format) SetDisabled(disabled bool) {
|
||||
C.gdk_pixbuf_format_set_disabled(v.GPixbufFormat, gbool(disabled))
|
||||
}
|
||||
|
||||
func (v *Format) GetLicense() string {
|
||||
return gostring(C.gdk_pixbuf_format_get_license(v.GPixbufFormat))
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Loader
|
||||
//-----------------------------------------------------------------------
|
||||
type Loader struct {
|
||||
GPixbufLoader *C.GdkPixbufLoader
|
||||
}
|
||||
|
||||
func NewLoader() *Loader {
|
||||
return &Loader{
|
||||
C.gdk_pixbuf_loader_new()}
|
||||
}
|
||||
|
||||
func NewLoaderWithType(image_type string) (loader *Loader, err *glib.Error) {
|
||||
var gerr *C.GError
|
||||
ptr := C.CString(image_type)
|
||||
defer cfree(ptr)
|
||||
loader = &Loader{
|
||||
C.gdk_pixbuf_loader_new_with_type(ptr, &gerr)}
|
||||
if gerr != nil {
|
||||
err = glib.ErrorFromNative(unsafe.Pointer(gerr))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewLoaderWithMimeType(mime_type string) (loader *Loader, err *glib.Error) {
|
||||
var error *C.GError
|
||||
ptr := C.CString(mime_type)
|
||||
defer cfree(ptr)
|
||||
loader = &Loader{
|
||||
C.gdk_pixbuf_loader_new_with_mime_type(ptr, &error)}
|
||||
err = glib.ErrorFromNative(unsafe.Pointer(error))
|
||||
return
|
||||
}
|
||||
|
||||
func (v Loader) GetPixbuf() *Pixbuf {
|
||||
gpixbuf := C.gdk_pixbuf_loader_get_pixbuf(v.GPixbufLoader)
|
||||
return &Pixbuf{
|
||||
GdkPixbuf: &GdkPixbuf{gpixbuf},
|
||||
GObject: glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
|
||||
}
|
||||
}
|
||||
|
||||
func (v Loader) Write(buf []byte) (bool, *glib.Error) {
|
||||
var err *C.GError
|
||||
var pbuf *byte
|
||||
pbuf = &buf[0]
|
||||
ret := gobool(C.gdk_pixbuf_loader_write(v.GPixbufLoader, C.to_gucharptr(unsafe.Pointer(pbuf)), C.gsize(len(buf)), &err))
|
||||
if err != nil {
|
||||
return ret, glib.ErrorFromNative(unsafe.Pointer(err))
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (v Loader) Close() (bool, *glib.Error) {
|
||||
var err *C.GError
|
||||
ret := gobool(C.gdk_pixbuf_loader_close(v.GPixbufLoader, &err))
|
||||
if err != nil {
|
||||
return ret, glib.ErrorFromNative(unsafe.Pointer(err))
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
//func (v Loader) GetPixbufAnimation() *Animation {
|
||||
// return &Animation {
|
||||
// C.gdk_pixbuf_loader_get_animation(v.GPixbufLoader) };
|
||||
//}
|
||||
func (v Loader) SetSize(width int, height int) {
|
||||
C.gdk_pixbuf_loader_set_size(v.GPixbufLoader, C.int(width), C.int(height))
|
||||
}
|
||||
|
||||
func (v Loader) GetFormat() *Format {
|
||||
return &Format{
|
||||
C.gdk_pixbuf_loader_get_format(v.GPixbufLoader)}
|
||||
}
|
||||
|
||||
// FINISH
|
48
vendor/github.com/mattn/go-gtk/gdkpixbuf/gdkpixbuf.go.h
generated
vendored
Normal file
48
vendor/github.com/mattn/go-gtk/gdkpixbuf/gdkpixbuf.go.h
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef GO_GDK_PIXBUF_H
|
||||
#define GO_GDK_PIXBUF_H
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
//static const gchar* to_gcharptr(const char* s) { return (const gchar*)s; }
|
||||
static guchar* to_gucharptr(void* s) { return (guchar*)s; }
|
||||
|
||||
static inline GdkPixbuf* toGdkPixbuf(void* p) { return GDK_PIXBUF(p); }
|
||||
|
||||
static inline gchar* toGstr(const char* s) { return (gchar*)s; }
|
||||
static inline char* toCstr(const gchar* s) { return (char*)s; }
|
||||
|
||||
static inline void freeCstr(char* s) { free(s); }
|
||||
|
||||
static inline char** makeCstrv(int count) {
|
||||
return (char**)malloc(sizeof(char*) * count);
|
||||
}
|
||||
|
||||
static guchar* _gdk_pixbuf_get_pixels_with_length(const GdkPixbuf *pixbuf, guint *length) {
|
||||
#if GDK_PIXBUF_MAJOR >= 2 && GDK_PIXBUF_MINOR >= 26
|
||||
return gdk_pixbuf_get_pixels_with_length(pixbuf, length);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
static inline void freeCstrv(char** cstrv) { free(cstrv); }
|
||||
static inline char* getCstr(char** cstrv, int n) { return cstrv[n]; }
|
||||
static inline void setCstr(char** cstrv, int n, char* str) { cstrv[n] = str; }
|
||||
static inline gchar* getGstr(gchar** gstrv, int n) { return gstrv[n]; }
|
||||
|
||||
static int _check_version(int major, int minor, int micro) {
|
||||
if (GDK_PIXBUF_MAJOR > major) return 1;
|
||||
if (GDK_PIXBUF_MAJOR < major) return 0;
|
||||
if (GDK_PIXBUF_MINOR > minor) return 1;
|
||||
if (GDK_PIXBUF_MINOR < minor) return 0;
|
||||
if (GDK_PIXBUF_MICRO > micro) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
1052
vendor/github.com/mattn/go-gtk/glib/glib.go
generated
vendored
Normal file
1052
vendor/github.com/mattn/go-gtk/glib/glib.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
218
vendor/github.com/mattn/go-gtk/glib/glib.go.h
generated
vendored
Normal file
218
vendor/github.com/mattn/go-gtk/glib/glib.go.h
generated
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
#ifndef GO_GLIB_H
|
||||
#define GO_GLIB_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
static GList* to_list(void* l) {
|
||||
return (GList*)l;
|
||||
}
|
||||
static GSList* to_slist(void* sl) {
|
||||
return (GSList*)sl;
|
||||
}
|
||||
static GError* to_error(void* err) {
|
||||
return (GError*)err;
|
||||
}
|
||||
static inline GObject* to_GObject(void* o) { return G_OBJECT(o); }
|
||||
|
||||
static inline gchar* to_gcharptr(const char* s) { return (gchar*)s; }
|
||||
|
||||
static inline char* to_charptr(const gchar* s) { return (char*)s; }
|
||||
|
||||
static inline char* to_charptr_from_gpointer(gpointer s) { return (char*)s; }
|
||||
|
||||
static inline char* to_charptr_voidp(const void* s) { return (char*)s; }
|
||||
|
||||
static inline void free_string(char* s) { free(s); }
|
||||
|
||||
static inline gchar* next_string(gchar* s) { return (gchar*)(s + strlen(s) + 1); }
|
||||
|
||||
static gboolean _g_utf8_validate(void* str, int len, void* ppbar) {
|
||||
return g_utf8_validate((const gchar*)str, (gssize)len, (const gchar**)ppbar);
|
||||
}
|
||||
|
||||
static gchar* _g_locale_to_utf8(void* opsysstring, int len, int* bytes_read, int* bytes_written, GError** error) {
|
||||
return g_locale_from_utf8((const gchar*)opsysstring, (gssize)len, (gsize*)bytes_read, (gsize*)bytes_written, error);
|
||||
}
|
||||
|
||||
static gchar* _g_locale_from_utf8(char* utf8string, int len, int* bytes_read, int* bytes_written, GError** error) {
|
||||
return g_locale_from_utf8((const gchar*)utf8string, (gssize)len, (gsize*)bytes_read, (gsize*)bytes_written, error);
|
||||
}
|
||||
static void _g_object_set_ptr(gpointer object, const gchar *property_name, void* value) {
|
||||
g_object_set(object, property_name, value, NULL);
|
||||
}
|
||||
static void _g_object_set_addr(gpointer object, const gchar *property_name, void* value) {
|
||||
g_object_set(object, property_name, *(gpointer**)value, NULL);
|
||||
}
|
||||
//static void _g_object_get(gpointer object, const gchar *property_name, void* value) {
|
||||
// g_object_get(object, property_name, value, NULL);
|
||||
//}
|
||||
|
||||
static void g_value_init_int(GValue* gv) { g_value_init(gv, G_TYPE_INT); }
|
||||
static void g_value_init_string(GValue* gv) { g_value_init(gv, G_TYPE_STRING); }
|
||||
|
||||
static GValue* init_gvalue_string_type() {
|
||||
GValue* gv = g_new0(GValue, 1);
|
||||
g_value_init(gv, G_TYPE_STRING);
|
||||
return gv;
|
||||
}
|
||||
static GValue* init_gvalue_string(gchar* val) {
|
||||
GValue* gv = init_gvalue_string_type();
|
||||
g_value_set_string(gv, val);
|
||||
return gv;
|
||||
}
|
||||
|
||||
static GValue* init_gvalue_int_type() {
|
||||
GValue* gv = g_new0(GValue, 1);
|
||||
g_value_init(gv, G_TYPE_INT);
|
||||
return gv;
|
||||
}
|
||||
static GValue* init_gvalue_int(gint val) {
|
||||
GValue* gv = init_gvalue_int_type();
|
||||
g_value_set_int(gv, val);
|
||||
return gv;
|
||||
}
|
||||
|
||||
static GValue* init_gvalue_uint(guint val) { GValue* gv = g_new0(GValue, 1); g_value_init(gv, G_TYPE_UINT); g_value_set_uint(gv, val); return gv; }
|
||||
static GValue* init_gvalue_int64(gint64 val) { GValue* gv = g_new0(GValue, 1); g_value_init(gv, G_TYPE_INT64); g_value_set_int64(gv, val); return gv; }
|
||||
static GValue* init_gvalue_double(gdouble val) { GValue* gv = g_new0(GValue, 1); g_value_init(gv, G_TYPE_DOUBLE); g_value_set_double(gv, val); return gv; }
|
||||
static GValue* init_gvalue_byte(guchar val) { GValue* gv = g_new0(GValue, 1); g_value_init(gv, G_TYPE_UCHAR); g_value_set_uchar(gv, val); return gv; }
|
||||
static GValue* init_gvalue_bool(gboolean val) { GValue* gv = g_new0(GValue, 1); g_value_init(gv, G_TYPE_BOOLEAN); g_value_set_boolean(gv, val); return gv; }
|
||||
//static GValue* init_gvalue_pointer(gpointer val) { GValue* gv = g_new0(GValue, 1); g_value_init(gv, G_TYPE_POINTER); g_value_set_pointer(gv, val); return gv; }
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
int func_no;
|
||||
void* target;
|
||||
uintptr_t* args;
|
||||
int args_no;
|
||||
void* ret;
|
||||
gulong id;
|
||||
} callback_info;
|
||||
|
||||
static uintptr_t callback_info_get_arg(callback_info* cbi, int idx) {
|
||||
return cbi->args[idx];
|
||||
}
|
||||
extern void _go_glib_callback(callback_info* cbi);
|
||||
static uintptr_t _glib_callback(void *data, ...) {
|
||||
va_list ap;
|
||||
callback_info *cbi = (callback_info*) data;
|
||||
|
||||
int i;
|
||||
cbi->args = (uintptr_t*)malloc(sizeof(uintptr_t)*cbi->args_no);
|
||||
va_start(ap, data);
|
||||
for (i = 0; i < cbi->args_no; i++) {
|
||||
cbi->args[i] = va_arg(ap, uintptr_t);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
_go_glib_callback(cbi);
|
||||
|
||||
free(cbi->args);
|
||||
|
||||
return *(uintptr_t*)(&cbi->ret);
|
||||
}
|
||||
|
||||
static void free_callback_info(gpointer data, GClosure *closure) {
|
||||
g_slice_free(callback_info, data);
|
||||
}
|
||||
|
||||
static callback_info* _g_signal_connect(void* obj, gchar* name, int func_no, int flags) {
|
||||
GSignalQuery query;
|
||||
callback_info* cbi;
|
||||
guint signal_id = g_signal_lookup(name, G_OBJECT_TYPE(obj));
|
||||
g_signal_query(signal_id, &query);
|
||||
cbi = g_slice_new0(callback_info);
|
||||
cbi->name = g_strdup(name);
|
||||
cbi->func_no = func_no;
|
||||
cbi->args = NULL;
|
||||
cbi->target = obj;
|
||||
cbi->args_no = query.n_params;
|
||||
if (((GConnectFlags)flags) == G_CONNECT_AFTER)
|
||||
cbi->id = g_signal_connect_data((gpointer)obj, name, G_CALLBACK(_glib_callback), (gpointer)cbi, free_callback_info, G_CONNECT_AFTER);
|
||||
else
|
||||
cbi->id = g_signal_connect_data((gpointer)obj, name, G_CALLBACK(_glib_callback), (gpointer)cbi, free_callback_info, G_CONNECT_SWAPPED);
|
||||
return cbi;
|
||||
}
|
||||
|
||||
static void _g_signal_emit_by_name(gpointer instance, const gchar *detailed_signal) {
|
||||
g_signal_emit_by_name(instance, detailed_signal);
|
||||
}
|
||||
|
||||
static gulong _g_signal_callback_id(callback_info* cbi) {
|
||||
return cbi->id;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int func_no;
|
||||
gboolean ret;
|
||||
guint id;
|
||||
} sourcefunc_info;
|
||||
|
||||
extern void _go_glib_sourcefunc(sourcefunc_info* sfi);
|
||||
static gboolean _go_sourcefunc(void *data) {
|
||||
sourcefunc_info *sfi = (sourcefunc_info*) data;
|
||||
|
||||
_go_glib_sourcefunc(sfi);
|
||||
|
||||
return sfi->ret;
|
||||
}
|
||||
|
||||
static void free_sourcefunc_info(gpointer data) {
|
||||
g_slice_free(sourcefunc_info, data);
|
||||
}
|
||||
|
||||
static sourcefunc_info* _g_idle_add(int func_no) {
|
||||
sourcefunc_info* sfi;
|
||||
sfi = g_slice_new0(sourcefunc_info);
|
||||
sfi->func_no = func_no;
|
||||
sfi->id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, _go_sourcefunc, sfi, free_sourcefunc_info);
|
||||
return sfi;
|
||||
}
|
||||
|
||||
static sourcefunc_info* _g_timeout_add(guint interval, int func_no) {
|
||||
sourcefunc_info* sfi;
|
||||
sfi = g_slice_new0(sourcefunc_info);
|
||||
sfi->func_no = func_no;
|
||||
sfi->id = g_timeout_add_full(G_PRIORITY_DEFAULT, interval, _go_sourcefunc, sfi, free_sourcefunc_info);
|
||||
return sfi;
|
||||
}
|
||||
|
||||
static void _g_thread_init(GThreadFunctions *vtable) {
|
||||
#if !GLIB_CHECK_VERSION(2,32,0)
|
||||
#ifdef G_THREADS_ENABLED
|
||||
g_thread_init(vtable);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2,28,0)
|
||||
static const gchar *
|
||||
g_get_user_runtime_dir (void)
|
||||
{
|
||||
#ifndef G_OS_WIN32
|
||||
static const gchar *runtime_dir;
|
||||
static gsize initialised;
|
||||
|
||||
if (g_once_init_enter (&initialised)) {
|
||||
runtime_dir = g_strdup (getenv ("XDG_RUNTIME_DIR"));
|
||||
if (runtime_dir == NULL)
|
||||
g_warning ("XDG_RUNTIME_DIR variable not set. Falling back to XDG cache dir.");
|
||||
g_once_init_leave (&initialised, 1);
|
||||
}
|
||||
|
||||
if (runtime_dir)
|
||||
return runtime_dir;
|
||||
|
||||
/* Both fallback for UNIX and the default
|
||||
* in Windows: use the user cache directory.
|
||||
*/
|
||||
#endif
|
||||
|
||||
return g_get_user_cache_dir ();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
11272
vendor/github.com/mattn/go-gtk/gtk/gtk.go
generated
vendored
Normal file
11272
vendor/github.com/mattn/go-gtk/gtk/gtk.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
873
vendor/github.com/mattn/go-gtk/gtk/gtk.go.h
generated
vendored
Normal file
873
vendor/github.com/mattn/go-gtk/gtk/gtk.go.h
generated
vendored
Normal file
@@ -0,0 +1,873 @@
|
||||
#ifndef GO_GTK_H
|
||||
#define GO_GTK_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
//Why is this necessary?
|
||||
//#include <gdk/gdkx.h>
|
||||
//#include <gdk/gdkquartz.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static void _gtk_init(int* argc, char*** argv) {
|
||||
gtk_init((int*)argc, (char***)argv);
|
||||
}
|
||||
|
||||
static GtkClipboard* _gtk_clipboard_get_for_display(void* display, void* selection) {
|
||||
return gtk_clipboard_get_for_display((GdkDisplay*)display, (GdkAtom)selection);
|
||||
}
|
||||
|
||||
static int _gtk_selection_data_get_length(void* selection_data) {
|
||||
return (int) gtk_selection_data_get_length((GtkSelectionData*)selection_data);
|
||||
}
|
||||
|
||||
static void* _gtk_selection_data_get_data(void* selection_data) {
|
||||
return (char*) gtk_selection_data_get_data((GtkSelectionData*)selection_data);
|
||||
}
|
||||
|
||||
static char* _gtk_selection_data_get_text(void* selection_data) {
|
||||
return (char*) gtk_selection_data_get_text((GtkSelectionData*)selection_data);
|
||||
}
|
||||
|
||||
static void _gtk_drag_finish(void *context, gboolean success, gboolean del, guint32 time_) {
|
||||
gtk_drag_finish((GdkDragContext*) context, success, del, time_);
|
||||
}
|
||||
|
||||
static GtkWidget* _gtk_message_dialog_new(GtkWidget* parent, GtkDialogFlags flags, GtkMessageType type, GtkButtonsType buttons, gchar *message) {
|
||||
return gtk_message_dialog_new(
|
||||
GTK_WINDOW(parent),
|
||||
flags,
|
||||
type,
|
||||
buttons,
|
||||
message, NULL);
|
||||
}
|
||||
|
||||
static GtkWidget* _gtk_message_dialog_new_with_markup(GtkWidget* parent, GtkDialogFlags flags, GtkMessageType type, GtkButtonsType buttons, gchar *message) {
|
||||
return gtk_message_dialog_new_with_markup(
|
||||
GTK_WINDOW(parent),
|
||||
flags,
|
||||
type,
|
||||
buttons,
|
||||
message, NULL);
|
||||
}
|
||||
|
||||
static GtkWidget* _gtk_file_chooser_dialog_new(const gchar* title,
|
||||
GtkWidget* parent, int file_chooser_action, int action, const gchar* button) {
|
||||
return gtk_file_chooser_dialog_new(
|
||||
title,
|
||||
GTK_WINDOW(parent),
|
||||
file_chooser_action,
|
||||
button,
|
||||
action,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static GtkWidget* _gtk_file_chooser_widget_new(int file_chooser_action) {
|
||||
return gtk_file_chooser_widget_new(file_chooser_action);
|
||||
}
|
||||
|
||||
static GtkTreePath* _gtk_tree_model_get_path(GtkTreeModel* tree_model, GtkTreeIter* iter) {
|
||||
return gtk_tree_model_get_path(tree_model, iter);
|
||||
}
|
||||
|
||||
static void _gtk_text_buffer_insert_with_tag(GtkTextBuffer* buffer, GtkTextIter* iter, const gchar* text, gint len, GtkTextTag* tag) {
|
||||
gtk_text_buffer_insert_with_tags(buffer, iter, text, len, tag, NULL);
|
||||
}
|
||||
|
||||
//static void _gtk_text_buffer_insert_with_tags_by_name(GtkTextBuffer* buffer, GtkTextIter* iter, const gchar* text, gint len, const gchar* first_tag_name, ...);
|
||||
|
||||
static GtkTextTag* _gtk_text_buffer_create_tag(GtkTextBuffer* buffer, const gchar* tag_name) {
|
||||
return gtk_text_buffer_create_tag(buffer, tag_name, NULL);
|
||||
}
|
||||
|
||||
static void _gtk_widget_hide_on_delete(GtkWidget* w) {
|
||||
g_signal_connect(GTK_WIDGET(w), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
|
||||
}
|
||||
|
||||
static void _gtk_text_iter_assign(GtkTextIter* one, GtkTextIter* two) {
|
||||
*one = *two;
|
||||
}
|
||||
|
||||
static void _apply_property(void* obj, const gchar* prop, const gchar* val) {
|
||||
GParamSpec *pspec;
|
||||
GValue fromvalue = { 0, };
|
||||
GValue tovalue = { 0, };
|
||||
pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(obj), prop);
|
||||
if (!pspec) return;
|
||||
g_value_init(&fromvalue, G_TYPE_STRING);
|
||||
g_value_set_string(&fromvalue, val);
|
||||
g_value_init(&tovalue, G_PARAM_SPEC_VALUE_TYPE(pspec));
|
||||
g_value_transform(&fromvalue, &tovalue);
|
||||
g_object_set_property((GObject *)obj, prop, &tovalue);
|
||||
g_value_unset(&fromvalue);
|
||||
g_value_unset(&tovalue);
|
||||
}
|
||||
|
||||
static GtkTreeViewColumn* _gtk_tree_view_column_new_with_attribute(gchar* title, GtkCellRenderer* cell) {
|
||||
return gtk_tree_view_column_new_with_attributes(title, cell, NULL);
|
||||
}
|
||||
|
||||
static GtkTreeViewColumn* _gtk_tree_view_column_new_with_attributes(gchar* title, GtkCellRenderer* cell, gchar* prop, gint column) {
|
||||
return gtk_tree_view_column_new_with_attributes(title, cell, prop, column, NULL);
|
||||
}
|
||||
|
||||
static void _gtk_list_store_set_ptr(GtkListStore* list_store, GtkTreeIter* iter, gint column, void* data) {
|
||||
gtk_list_store_set(list_store, iter, column, data, -1);
|
||||
}
|
||||
|
||||
static void _gtk_list_store_set_addr(GtkListStore* list_store, GtkTreeIter* iter, gint column, void* data) {
|
||||
gtk_list_store_set(list_store, iter, column, *(gpointer*)data, -1);
|
||||
}
|
||||
|
||||
static void _gtk_tree_store_set_ptr(GtkTreeStore* tree_store, GtkTreeIter* iter, gint column, void* data) {
|
||||
gtk_tree_store_set(tree_store, iter, column, data, -1);
|
||||
}
|
||||
|
||||
static void _gtk_tree_store_set_addr(GtkTreeStore* tree_store, GtkTreeIter* iter, gint column, void* data) {
|
||||
gtk_tree_store_set(tree_store, iter, column, *(gpointer*)data, -1);
|
||||
}
|
||||
|
||||
//static void _gtk_range_get_value(GtkRange* range, gdouble* value) {
|
||||
// *value = gtk_range_get_value(range);
|
||||
//}
|
||||
|
||||
static GtkTreeIter* _gtk_tree_iter_new() {
|
||||
return (GtkTreeIter*)malloc(sizeof(GtkTreeIter));
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GtkTreeModel* model;
|
||||
GtkTreeIter* a;
|
||||
GtkTreeIter* b;
|
||||
gint columnNum;
|
||||
void* gots;
|
||||
int ret;
|
||||
} _gtk_sort_func_info;
|
||||
|
||||
extern void _go_call_sort_func(_gtk_sort_func_info* gsfi);
|
||||
static gint sortable_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer gsfi) {
|
||||
gint gret = 0;
|
||||
_gtk_sort_func_info* gsfil = (_gtk_sort_func_info*) gsfi;
|
||||
gsfil->model = model;
|
||||
gsfil->a = a;
|
||||
gsfil->b = b;
|
||||
_go_call_sort_func(gsfil);
|
||||
gret = gsfil->ret;
|
||||
return gret;
|
||||
}
|
||||
|
||||
static void free_sort_func(gpointer gsfi) {
|
||||
free(gsfi);
|
||||
}
|
||||
|
||||
static void _gtk_tree_sortable_set_sort_func(GtkTreeSortable* ts, gint col, void* gots) {
|
||||
_gtk_sort_func_info* gsfi = malloc(sizeof(_gtk_sort_func_info));
|
||||
gsfi->columnNum = col;
|
||||
gsfi->gots = gots;
|
||||
gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(ts), col, sortable_sort_func, (gpointer) gsfi, free_sort_func);
|
||||
}
|
||||
|
||||
extern void _go_gtk_builder_connect_signals_full_cb(void* builder, void* object, gchar *signal_name, gchar *handler_name, void* connect_object, int flags, void* user_data);
|
||||
static void _gtk_builder_connect_signals_full(GtkBuilder *builder, void* user_data) {
|
||||
gtk_builder_connect_signals_full(builder, (GtkBuilderConnectFunc)_go_gtk_builder_connect_signals_full_cb, user_data);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GtkMenu *menu;
|
||||
gint x;
|
||||
gint y;
|
||||
gboolean push_in;
|
||||
gpointer data;
|
||||
} _gtk_menu_position_func_info;
|
||||
|
||||
extern void _go_gtk_menu_position_func(_gtk_menu_position_func_info* gmpfi);
|
||||
static void _c_gtk_menu_position_func(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data) {
|
||||
_gtk_menu_position_func_info gmpfi;
|
||||
gmpfi.menu = menu;
|
||||
gmpfi.x = *x;
|
||||
gmpfi.y = *y;
|
||||
gmpfi.push_in = *push_in;
|
||||
gmpfi.data = user_data;
|
||||
_go_gtk_menu_position_func(&gmpfi);
|
||||
*x = gmpfi.x;
|
||||
*y = gmpfi.y;
|
||||
*push_in = gmpfi.push_in;
|
||||
#ifdef _WIN32
|
||||
RECT rect;
|
||||
SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
|
||||
gint h = GTK_WIDGET(menu)->requisition.height;
|
||||
if (*y + h > rect.bottom) *y -= h;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void _gtk_menu_popup(GtkWidget *menu, GtkWidget *parent_menu_shell, GtkWidget *parent_menu_item, void* data, guint button, guint32 activate_time) {
|
||||
gtk_menu_popup(GTK_MENU(menu), parent_menu_shell, parent_menu_item, _c_gtk_menu_position_func, (gpointer) data, button, activate_time);
|
||||
}
|
||||
|
||||
extern gboolean _go_gtk_tree_selection_select_func(gpointer sel, gpointer model, gpointer path, gboolean selected, gpointer payload);
|
||||
|
||||
static gboolean _c_gtk_tree_selection_select_func(GtkTreeSelection *sel, GtkTreeModel *model, GtkTreePath *path, gboolean selected, gpointer payload) {
|
||||
return _go_gtk_tree_selection_select_func(sel, model, path, selected, payload);
|
||||
}
|
||||
|
||||
static void _go_gtk_tree_selection_set_select_function(GtkTreeSelection *sel, void * payload) {
|
||||
gtk_tree_selection_set_select_function(sel, _c_gtk_tree_selection_select_func, payload, NULL);
|
||||
}
|
||||
|
||||
static void _gtk_container_child_set_bool(GtkContainer* container, GtkWidget* child, const gchar* propname, gboolean value) {
|
||||
gtk_container_child_set(container, child, propname, value, NULL);
|
||||
}
|
||||
|
||||
static void _gtk_container_child_set_int(GtkContainer* container, GtkWidget* child, const gchar* propname, gint value) {
|
||||
gtk_container_child_set(container, child, propname, value, NULL);
|
||||
}
|
||||
|
||||
static inline GType* make_gtypes(int count) {
|
||||
return g_new0(GType, count);
|
||||
}
|
||||
|
||||
static inline void destroy_gtypes(GType* types) {
|
||||
g_free(types);
|
||||
}
|
||||
|
||||
static inline void set_gtype(GType* types, int n, int type) {
|
||||
types[n] = (GType) type;
|
||||
}
|
||||
|
||||
static inline gchar** make_strings(int count) {
|
||||
return (gchar**)malloc(sizeof(gchar*) * count);
|
||||
}
|
||||
|
||||
static inline void destroy_strings(gchar** strings) {
|
||||
free(strings);
|
||||
}
|
||||
|
||||
static inline gchar* get_string(gchar** strings, int n) {
|
||||
return strings[n];
|
||||
}
|
||||
|
||||
static inline void set_string(gchar** strings, int n, gchar* str) {
|
||||
strings[n] = str;
|
||||
}
|
||||
|
||||
static GSList* to_gslist(void* gs) {
|
||||
return (GSList*)gs;
|
||||
}
|
||||
|
||||
static int _check_version(int major, int minor, int micro) {
|
||||
return GTK_CHECK_VERSION(major, minor, micro);
|
||||
}
|
||||
|
||||
static void _gtk_tree_iter_assign(void* iter, void* to) {
|
||||
*(GtkTreeIter*)iter = *(GtkTreeIter*)to;
|
||||
}
|
||||
|
||||
static GtkWidget* _gtk_dialog_get_vbox(GtkWidget* w) {
|
||||
return GTK_DIALOG(w)->vbox;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// ############# Version Control #############
|
||||
//////////////////////////////////////////////
|
||||
|
||||
#if GTK_CHECK_VERSION(2,14,0)
|
||||
static gdouble _gtk_adjustment_get_lower(GtkAdjustment* adjustment) {
|
||||
return gtk_adjustment_get_lower(adjustment);
|
||||
}
|
||||
static void _gtk_adjustment_set_lower(GtkAdjustment* adjustment, gdouble lower) {
|
||||
gtk_adjustment_set_lower(adjustment, lower);
|
||||
}
|
||||
static gdouble _gtk_adjustment_get_upper(GtkAdjustment* adjustment) {
|
||||
return gtk_adjustment_get_upper(adjustment);
|
||||
}
|
||||
static void _gtk_adjustment_set_upper(GtkAdjustment* adjustment, gdouble upper) {
|
||||
gtk_adjustment_set_upper(adjustment, upper);
|
||||
}
|
||||
static gdouble _gtk_adjustment_get_step_increment(GtkAdjustment* adjustment) {
|
||||
return gtk_adjustment_get_step_increment(adjustment);
|
||||
}
|
||||
static void _gtk_adjustment_set_step_increment(GtkAdjustment* adjustment, gdouble step_increment) {
|
||||
gtk_adjustment_set_step_increment(adjustment, step_increment);
|
||||
}
|
||||
static gdouble _gtk_adjustment_get_page_increment(GtkAdjustment* adjustment) {
|
||||
return gtk_adjustment_get_page_increment(adjustment);
|
||||
}
|
||||
static void _gtk_adjustment_set_page_increment(GtkAdjustment* adjustment, gdouble page_increment) {
|
||||
gtk_adjustment_set_page_increment(adjustment, page_increment);
|
||||
}
|
||||
static gdouble _gtk_adjustment_get_page_size(GtkAdjustment* adjustment) {
|
||||
return gtk_adjustment_get_page_size(adjustment);
|
||||
}
|
||||
static void _gtk_adjustment_set_page_size(GtkAdjustment* adjustment, gdouble page_size) {
|
||||
gtk_adjustment_set_page_size(adjustment, page_size);
|
||||
}
|
||||
static void _gtk_adjustment_configure(GtkAdjustment* adjustment, gdouble value, gdouble lower, gdouble upper, gdouble step_increment, gdouble page_increment, gdouble page_size) {
|
||||
gtk_adjustment_configure(adjustment, value, lower, upper, step_increment, page_increment, page_size);
|
||||
}
|
||||
#else //GTK_CHECK_VERSION(2,14,0)
|
||||
static gdouble _gtk_adjustment_get_lower(GtkAdjustment* adjustment) {
|
||||
return 0f;
|
||||
}
|
||||
static void _gtk_adjustment_set_lower(GtkAdjustment* adjustment, gdouble lower) {
|
||||
}
|
||||
static gdouble _gtk_adjustment_get_upper(GtkAdjustment* adjustment) {
|
||||
return 0f;
|
||||
}
|
||||
static void _gtk_adjustment_set_upper(GtkAdjustment* adjustment, gdouble upper) {
|
||||
}
|
||||
static gdouble _gtk_adjustment_get_step_increment(GtkAdjustment* adjustment) {
|
||||
return 0f;
|
||||
}
|
||||
static void _gtk_adjustment_set_step_increment(GtkAdjustment* adjustment, gdouble step_increment) {
|
||||
}
|
||||
static gdouble _gtk_adjustment_get_page_increment(GtkAdjustment* adjustment) {
|
||||
return 0f;
|
||||
}
|
||||
static void _gtk_adjustment_set_page_increment(GtkAdjustment* adjustment, gdouble page_increment) {
|
||||
}
|
||||
static gdouble _gtk_adjustment_get_page_size(GtkAdjustment* adjustment) {
|
||||
return 0f;
|
||||
}
|
||||
static void _gtk_adjustment_set_page_size(GtkAdjustment* adjustment, gdouble page_size) {
|
||||
}
|
||||
static void _gtk_adjustment_configure(GtkAdjustment* adjustment, gdouble value, gdouble lower, gdouble upper, gdouble step_increment, gdouble page_increment, gdouble page_size) {
|
||||
}
|
||||
#endif //GTK_CHECK_VERSION(2,14,0)
|
||||
|
||||
#if GTK_CHECK_VERSION(2,18,0)
|
||||
static gboolean _gtk_cell_renderer_toggle_get_activatable(GtkCellRendererToggle *toggle) {
|
||||
return gtk_cell_renderer_toggle_get_activatable(toggle);
|
||||
}
|
||||
static void _gtk_cell_renderer_toggle_set_activatable(GtkCellRendererToggle *toggle, gboolean setting) {
|
||||
gtk_cell_renderer_toggle_set_activatable(toggle, setting);
|
||||
}
|
||||
static void _gtk_menu_set_reserve_toggle_size(GtkMenu *menu, gboolean reserve_toggle_size) {
|
||||
gtk_menu_set_reserve_toggle_size(menu, reserve_toggle_size);
|
||||
}
|
||||
static gboolean _gtk_menu_get_reserve_toggle_size(GtkMenu *menu) {
|
||||
return gtk_menu_get_reserve_toggle_size(menu);
|
||||
}
|
||||
static gboolean _gtk_range_get_flippable(GtkRange *range) {
|
||||
return gtk_range_get_flippable(range);
|
||||
}
|
||||
static void _gtk_range_set_flippable(GtkRange *range, gboolean flippable) {
|
||||
gtk_range_set_flippable(range, flippable);
|
||||
}
|
||||
static void _gtk_widget_get_allocation(GtkWidget *widget, GtkAllocation *allocation) {
|
||||
gtk_widget_get_allocation(widget, allocation);
|
||||
}
|
||||
static void _gtk_widget_set_allocation(GtkWidget *widget, const GtkAllocation *allocation) {
|
||||
gtk_widget_set_allocation(widget, allocation);
|
||||
}
|
||||
static gboolean _gtk_widget_get_app_paintable(GtkWidget *widget) {
|
||||
return gtk_widget_get_app_paintable(widget);
|
||||
}
|
||||
static gboolean _gtk_widget_get_can_default(GtkWidget *widget) {
|
||||
return gtk_widget_get_can_default(widget);
|
||||
}
|
||||
static void _gtk_widget_set_can_default(GtkWidget *widget, gboolean can_default) {
|
||||
gtk_widget_set_can_default(widget, can_default);
|
||||
}
|
||||
static gboolean _gtk_widget_get_can_focus(GtkWidget *widget) {
|
||||
return gtk_widget_get_can_focus(widget);
|
||||
}
|
||||
static void _gtk_widget_set_can_focus(GtkWidget *widget, gboolean can_focus) {
|
||||
gtk_widget_set_can_focus(widget, can_focus);
|
||||
}
|
||||
static gboolean _gtk_widget_get_double_buffered(GtkWidget *widget) {
|
||||
return gtk_widget_get_double_buffered(widget);
|
||||
}
|
||||
static gboolean _gtk_widget_get_has_window(GtkWidget *widget) {
|
||||
return gtk_widget_get_has_window(widget);
|
||||
}
|
||||
static void _gtk_widget_set_has_window(GtkWidget *widget, gboolean has_window) {
|
||||
gtk_widget_set_has_window(widget, has_window);
|
||||
}
|
||||
static gboolean _gtk_widget_get_sensitive(GtkWidget *widget) {
|
||||
return gtk_widget_get_sensitive(widget);
|
||||
}
|
||||
static gboolean _gtk_widget_is_sensitive(GtkWidget *widget) {
|
||||
return gtk_widget_is_sensitive(widget);
|
||||
}
|
||||
static GtkStateType _gtk_widget_get_state(GtkWidget *widget) {
|
||||
return gtk_widget_get_state(widget);
|
||||
}
|
||||
static gboolean _gtk_widget_get_visible(GtkWidget *widget) {
|
||||
return gtk_widget_get_visible(widget);
|
||||
}
|
||||
static void _gtk_widget_set_visible(GtkWidget *widget, gboolean visible) {
|
||||
gtk_widget_set_visible(widget, visible);
|
||||
}
|
||||
static gboolean _gtk_widget_has_default(GtkWidget *widget) {
|
||||
return gtk_widget_has_default(widget);
|
||||
}
|
||||
static gboolean _gtk_widget_has_focus(GtkWidget *widget) {
|
||||
return gtk_widget_has_focus(widget);
|
||||
}
|
||||
static gboolean _gtk_widget_has_grab(GtkWidget *widget) {
|
||||
return gtk_widget_has_grab(widget);
|
||||
}
|
||||
static gboolean _gtk_widget_is_drawable(GtkWidget *widget) {
|
||||
return gtk_widget_is_drawable(widget);
|
||||
}
|
||||
static gboolean _gtk_widget_is_toplevel(GtkWidget *widget) {
|
||||
return gtk_widget_is_toplevel(widget);
|
||||
}
|
||||
static void _gtk_widget_set_window(GtkWidget *widget, GdkWindow *window) {
|
||||
gtk_widget_set_window(widget, window);
|
||||
}
|
||||
static void _gtk_widget_set_receives_default(GtkWidget *widget, gboolean receives_default) {
|
||||
gtk_widget_set_receives_default(widget, receives_default);
|
||||
}
|
||||
static gboolean _gtk_widget_get_receives_default(GtkWidget *widget) {
|
||||
return gtk_widget_get_receives_default(widget);
|
||||
}
|
||||
static GtkWidget* _gtk_info_bar_new() {
|
||||
return gtk_info_bar_new();
|
||||
}
|
||||
static void _gtk_info_bar_add_action_widget(GtkInfoBar *info_bar, GtkWidget *child, gint response_id) {
|
||||
gtk_info_bar_add_action_widget(info_bar, child, response_id);
|
||||
}
|
||||
static GtkWidget* _gtk_info_bar_add_button(GtkInfoBar *info_bar, const gchar *button_text, gint response_id) {
|
||||
return gtk_info_bar_add_button(info_bar, button_text, response_id);
|
||||
}
|
||||
static void _gtk_info_bar_set_response_sensitive(GtkInfoBar *info_bar, gint response_id, gboolean setting) {
|
||||
gtk_info_bar_set_response_sensitive(info_bar, response_id, setting);
|
||||
}
|
||||
static void _gtk_info_bar_set_default_response(GtkInfoBar *info_bar, gint response_id) {
|
||||
gtk_info_bar_set_default_response(info_bar, response_id);
|
||||
}
|
||||
static void _gtk_info_bar_response(GtkInfoBar *info_bar, gint response_id) {
|
||||
gtk_info_bar_response(info_bar, response_id);
|
||||
}
|
||||
static void _gtk_info_bar_set_message_type(GtkInfoBar *info_bar, GtkMessageType message_type) {
|
||||
gtk_info_bar_set_message_type(info_bar, message_type);
|
||||
}
|
||||
static GtkMessageType _gtk_info_bar_get_message_type(GtkInfoBar *info_bar) {
|
||||
return gtk_info_bar_get_message_type(info_bar);
|
||||
}
|
||||
static GtkWidget* _gtk_info_bar_get_action_area(GtkInfoBar *info_bar) {
|
||||
return gtk_info_bar_get_action_area(info_bar);
|
||||
}
|
||||
static GtkWidget* _gtk_info_bar_get_content_area(GtkInfoBar *info_bar) {
|
||||
return gtk_info_bar_get_content_area(info_bar);
|
||||
}
|
||||
static GtkWidget* _gtk_entry_new_with_buffer(GtkEntryBuffer *buffer) {
|
||||
return gtk_entry_new_with_buffer(buffer);
|
||||
}
|
||||
static GtkEntryBuffer* _gtk_entry_get_buffer(GtkEntry *entry) {
|
||||
return gtk_entry_get_buffer(entry);
|
||||
}
|
||||
static void _gtk_entry_set_buffer(GtkEntry *entry, GtkEntryBuffer *buffer) {
|
||||
gtk_entry_set_buffer(entry, buffer);
|
||||
}
|
||||
static GtkEntryBuffer* _gtk_entry_buffer_new(const gchar *initial_chars, gint n_initial_chars) {
|
||||
return gtk_entry_buffer_new(initial_chars, n_initial_chars);
|
||||
}
|
||||
static const gchar* _gtk_entry_buffer_get_text(GtkEntryBuffer *buffer) {
|
||||
return gtk_entry_buffer_get_text(buffer);
|
||||
}
|
||||
static void _gtk_entry_buffer_set_text(GtkEntryBuffer *buffer, const gchar *chars, gint n_chars) {
|
||||
gtk_entry_buffer_set_text(buffer, chars, n_chars);
|
||||
}
|
||||
//static gsize _gtk_entry_buffer_get_bytes(GtkEntryBuffer *buffer) {
|
||||
// return gtk_entry_buffer_get_bytes(buffer);
|
||||
//}
|
||||
static guint _gtk_entry_buffer_get_length(GtkEntryBuffer *buffer) {
|
||||
return gtk_entry_buffer_get_length(buffer);
|
||||
}
|
||||
static gint _gtk_entry_buffer_get_max_length(GtkEntryBuffer *buffer) {
|
||||
return gtk_entry_buffer_get_max_length(buffer);
|
||||
}
|
||||
static void _gtk_entry_buffer_set_max_length(GtkEntryBuffer *buffer, gint max_length) {
|
||||
gtk_entry_buffer_set_max_length(buffer, max_length);
|
||||
}
|
||||
static guint _gtk_entry_buffer_insert_text(GtkEntryBuffer *buffer, guint position, const gchar *chars, gint n_chars) {
|
||||
return gtk_entry_buffer_insert_text(buffer, position, chars, n_chars);
|
||||
}
|
||||
static guint _gtk_entry_buffer_delete_text(GtkEntryBuffer *buffer, guint position, gint n_chars) {
|
||||
return gtk_entry_buffer_delete_text(buffer, position, n_chars);
|
||||
}
|
||||
static void _gtk_status_icon_set_title(GtkStatusIcon *status_icon, const gchar *title) {
|
||||
gtk_status_icon_set_title(status_icon, title);
|
||||
}
|
||||
static const gchar* _gtk_status_icon_get_title(GtkStatusIcon *status_icon) {
|
||||
return gtk_status_icon_get_title(status_icon);
|
||||
}
|
||||
#else //!GTK_CHECK_VERSION(2,18,0)
|
||||
static gboolean _gtk_cell_renderer_toggle_get_activatable(GtkCellRendererToggle *toggle) {
|
||||
return 0;
|
||||
}
|
||||
static void _gtk_cell_renderer_toggle_set_activatable(GtkCellRendererToggle *toggle, gboolean setting) {
|
||||
}
|
||||
static void _gtk_menu_set_reserve_toggle_size(GtkMenu *menu, gboolean reserve_toggle_size) {
|
||||
}
|
||||
static gboolean _gtk_menu_get_reserve_toggle_size(GtkMenu *menu) {
|
||||
return 0;
|
||||
}
|
||||
static gboolean _gtk_range_get_flippable(GtkRange *range) {
|
||||
return 0;
|
||||
}
|
||||
static void _gtk_range_set_flippable(GtkRange *range, gboolean flippable) {
|
||||
}
|
||||
static void _gtk_widget_get_allocation(GtkWidget *widget, GtkAllocation *allocation) {
|
||||
}
|
||||
static void _gtk_widget_set_allocation(GtkWidget *widget, const GtkAllocation *allocation) {
|
||||
}
|
||||
static gboolean _gtk_widget_get_app_paintable(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static gboolean _gtk_widget_get_can_default(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static void _gtk_widget_set_can_default(GtkWidget *widget, gboolean can_default) {
|
||||
}
|
||||
static gboolean _gtk_widget_get_can_focus(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static void _gtk_widget_set_can_focus(GtkWidget *widget, gboolean can_focus) {
|
||||
}
|
||||
static gboolean _gtk_widget_get_double_buffered(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static gboolean _gtk_widget_get_has_window(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static void _gtk_widget_set_has_window(GtkWidget *widget, gboolean has_window) {
|
||||
}
|
||||
static gboolean _gtk_widget_get_sensitive(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static gboolean _gtk_widget_is_sensitive(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static GtkStateType _gtk_widget_get_state(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static gboolean _gtk_widget_get_visible(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static void _gtk_widget_set_visible(GtkWidget *widget, gboolean visible) {
|
||||
}
|
||||
static gboolean _gtk_widget_has_default(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static gboolean _gtk_widget_has_focus(GtkWidget *widget) {
|
||||
return 0:
|
||||
}
|
||||
static gboolean _gtk_widget_has_grab(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static gboolean _gtk_widget_is_drawable(GtkWidget *widget) {
|
||||
return 0:
|
||||
}
|
||||
static gboolean _gtk_widget_is_toplevel(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static void _gtk_widget_set_window(GtkWidget *widget, GdkWindow *window) {
|
||||
}
|
||||
static void _gtk_widget_set_receives_default(GtkWidget *widget, gboolean receives_default) {
|
||||
}
|
||||
static gboolean _gtk_widget_get_receives_default(GtkWidget *widget) {
|
||||
return 0;
|
||||
}
|
||||
static GtkWidget* _gtk_info_bar_new() {
|
||||
return NULL;
|
||||
}
|
||||
static void _gtk_info_bar_add_action_widget(GtkInfoBar *info_bar, GtkWidget *child, gint response_id) {
|
||||
}
|
||||
static GtkWidget* _gtk_info_bar_add_button(GtkInfoBar *info_bar, const gchar *button_text, gint response_id) {
|
||||
return NULL;
|
||||
}
|
||||
static void _gtk_info_bar_set_response_sensitive(GtkInfoBar *info_bar, gint response_id, gboolean setting) {
|
||||
}
|
||||
static void _gtk_info_bar_set_default_response(GtkInfoBar *info_bar, gint response_id) {
|
||||
}
|
||||
static void _gtk_info_bar_response(GtkInfoBar *info_bar, gint response_id) {
|
||||
}
|
||||
static void _gtk_info_bar_set_message_type(GtkInfoBar *info_bar, GtkMessageType message_type) {
|
||||
}
|
||||
static GtkMessageType _gtk_info_bar_get_message_type(GtkInfoBar *info_bar) {
|
||||
return 0;
|
||||
}
|
||||
static GtkWidget* _gtk_info_bar_get_action_area(GtkInfoBar *info_bar) {
|
||||
return NULL;
|
||||
}
|
||||
static GtkWidget* _gtk_info_bar_get_content_area(GtkInfoBar *info_bar) {
|
||||
return NULL;
|
||||
}
|
||||
static GtkWidget* _gtk_entry_new_with_buffer(GtkEntryBuffer *buffer) {
|
||||
return NULL;
|
||||
}
|
||||
static GtkEntryBuffer* _gtk_entry_get_buffer(GtkEntry *entry) {
|
||||
return NULL;
|
||||
}
|
||||
static void _gtk_entry_set_buffer(GtkEntry *entry, GtkEntryBuffer *buffer) {
|
||||
}
|
||||
static GtkEntryBuffer* _gtk_entry_buffer_new(const gchar *initial_chars, gint n_initial_chars) {
|
||||
return NULL;
|
||||
}
|
||||
static const gchar* _gtk_entry_buffer_get_text(GtkEntryBuffer *buffer) {
|
||||
return NULL;
|
||||
}
|
||||
static void _gtk_entry_buffer_set_text(GtkEntryBuffer *buffer, const gchar *chars, gint n_chars) {
|
||||
}
|
||||
//static gsize _gtk_entry_buffer_get_bytes(GtkEntryBuffer *buffer) {
|
||||
// return 0;
|
||||
//}
|
||||
static guint _gtk_entry_buffer_get_length(GtkEntryBuffer *buffer) {
|
||||
return 0;
|
||||
}
|
||||
static gint _gtk_entry_buffer_get_max_length(GtkEntryBuffer *buffer) {
|
||||
return 0;
|
||||
}
|
||||
static void _gtk_entry_buffer_set_max_length(GtkEntryBuffer *buffer, gint max_length) {
|
||||
}
|
||||
static guint _gtk_entry_buffer_insert_text(GtkEntryBuffer *buffer, guint position, const gchar *chars, gint n_chars) {
|
||||
return 0;
|
||||
}
|
||||
static guint _gtk_entry_buffer_delete_text(GtkEntryBuffer *buffer, guint position, gint n_chars) {
|
||||
return 0;
|
||||
}
|
||||
static void _gtk_status_icon_set_title(GtkStatusIcon *status_icon, const gchar *title) {
|
||||
}
|
||||
static const gchar* _gtk_status_icon_get_title(GtkStatusIcon *status_icon) {
|
||||
return NULL;
|
||||
}
|
||||
#endif //GTK_CHECK_VERSION(2,18,0)
|
||||
|
||||
#if GTK_CHECK_VERSION(2,20,0)
|
||||
static GtkWidget* _gtk_dialog_get_widget_for_response(GtkDialog* dialog, gint id) {
|
||||
return gtk_dialog_get_widget_for_response(dialog, id);
|
||||
}
|
||||
static GdkWindow* _gtk_viewport_get_bin_window(GtkViewport *viewport) {
|
||||
return gtk_viewport_get_bin_window(viewport);
|
||||
}
|
||||
static void _gtk_status_icon_set_name(GtkStatusIcon *status_icon, const gchar *name) {
|
||||
gtk_status_icon_set_name(status_icon, name);
|
||||
}
|
||||
#else //GTK_CHECK_VERSION(2,20,0)
|
||||
static GtkWidget* _gtk_dialog_get_widget_for_response(GtkDialog* dialog, gint id) {
|
||||
return NULL;
|
||||
}
|
||||
static GdkWindow* _gtk_viewport_get_bin_window(GtkViewport *viewport) {
|
||||
return NULL;
|
||||
}
|
||||
static void _gtk_status_icon_set_name(GtkStatusIcon *status_icon, const gchar *name) {
|
||||
}
|
||||
#endif //GTK_CHECK_VERSION(2,20,0)
|
||||
|
||||
#if GTK_CHECK_VERSION(2,22,0)
|
||||
static GtkWidget* _gtk_accessible_get_widget(GtkAccessible *accessible) {
|
||||
return gtk_accessible_get_widget(accessible);
|
||||
}
|
||||
static void _gtk_accessible_set_widget(GtkAccessible *accessible, GtkWidget *widget) {
|
||||
gtk_accessible_set_widget(accessible, widget);
|
||||
}
|
||||
static GdkWindow* _gtk_viewport_get_view_window(GtkViewport *viewport) {
|
||||
return gtk_viewport_get_view_window(viewport);
|
||||
}
|
||||
#else //GTK_CHECK_VERSION(2,22,0)
|
||||
static GtkWidget* _gtk_accessible_get_widget(GtkAccessible *accessible) {
|
||||
return NULL;
|
||||
}
|
||||
static void _gtk_accessible_set_widget(GtkAccessible *accessible, GtkWidget *widget) {
|
||||
}
|
||||
static GdkWindow* _gtk_viewport_get_view_window(GtkViewport *viewport) {
|
||||
return NULL;
|
||||
}
|
||||
#endif //GTK_CHECK_VERSION(2,22,0)
|
||||
|
||||
#if GTK_CHECK_VERSION(2,24,0)
|
||||
static GtkWidget* _gtk_combo_box_new_with_entry(void) {
|
||||
return gtk_combo_box_new_with_entry();
|
||||
}
|
||||
static GtkWidget* _gtk_combo_box_new_with_model_and_entry(GtkTreeModel *model) {
|
||||
return gtk_combo_box_new_with_model_and_entry(model);
|
||||
}
|
||||
static GtkWidget* _gtk_combo_box_text_new(void) {
|
||||
return gtk_combo_box_text_new();
|
||||
}
|
||||
static GtkWidget* _gtk_combo_box_text_new_with_entry(void) {
|
||||
return gtk_combo_box_text_new_with_entry();
|
||||
}
|
||||
static void _gtk_combo_box_text_append_text(GtkComboBoxText *combo_box, const gchar *text) {
|
||||
gtk_combo_box_text_append_text(combo_box, text);
|
||||
}
|
||||
static void _gtk_combo_box_text_insert_text(GtkComboBoxText *combo_box, gint position, const gchar *text) {
|
||||
gtk_combo_box_text_insert_text(combo_box, position, text);
|
||||
}
|
||||
static void _gtk_combo_box_text_prepend_text(GtkComboBoxText *combo_box, const gchar *text) {
|
||||
gtk_combo_box_text_prepend_text(combo_box, text);
|
||||
}
|
||||
static void _gtk_combo_box_text_remove(GtkComboBoxText *combo_box, gint position) {
|
||||
gtk_combo_box_text_remove(combo_box, position);
|
||||
}
|
||||
static gchar* _gtk_combo_box_text_get_active_text(GtkComboBoxText *combo_box) {
|
||||
return gtk_combo_box_text_get_active_text(combo_box);
|
||||
}
|
||||
static void _gtk_notebook_set_group_name(GtkNotebook* notebook, const gchar* group_name) {
|
||||
gtk_notebook_set_group_name(notebook, group_name);
|
||||
}
|
||||
static const gchar* _gtk_notebook_get_group_name(GtkNotebook* notebook) {
|
||||
return gtk_notebook_get_group_name(notebook);
|
||||
}
|
||||
#else //GTK_CHECK_VERSION(2,24,0)
|
||||
typedef GtkComboBox GtkComboBoxText;
|
||||
|
||||
static GtkWidget* _gtk_combo_box_new_with_entry(void) {
|
||||
return NULL;
|
||||
}
|
||||
static GtkWidget* _gtk_combo_box_new_with_model_and_entry(GtkTreeModel *model) {
|
||||
return NULL;
|
||||
}
|
||||
static GtkWidget* _gtk_combo_box_text_new(void) {
|
||||
return NULL;
|
||||
}
|
||||
static GtkWidget* _gtk_combo_box_text_new_with_entry(void) {
|
||||
return NULL;
|
||||
}
|
||||
static void _gtk_combo_box_text_append_text(GtkComboBoxText *combo_box, const gchar *text) {
|
||||
}
|
||||
static void _gtk_combo_box_text_insert_text(GtkComboBoxText *combo_box, gint position, const gchar *text) {
|
||||
}
|
||||
static void _gtk_combo_box_text_prepend_text(GtkComboBoxText *combo_box, const gchar *text) {
|
||||
}
|
||||
static void _gtk_combo_box_text_remove(GtkComboBoxText *combo_box, gint position) {
|
||||
}
|
||||
static gchar* _gtk_combo_box_text_get_active_text(GtkComboBoxText *combo_box) {
|
||||
return NULL;
|
||||
}
|
||||
static void _gtk_notebook_set_group_name(GtkNotebook* notebook, const gchar* group_name) {
|
||||
}
|
||||
static const gchar* _gtk_notebook_get_group_name(GtkNotebook* notebook) {
|
||||
return NULL;
|
||||
}
|
||||
#endif //GTK_CHECK_VERSION(2,24,0)
|
||||
|
||||
static GtkCellRenderer* _gtk_cell_renderer_spinner_new(void) {
|
||||
#ifdef GTK_CELL_RENDERER_SPINNER //2.20
|
||||
return gtk_cell_renderer_spinner_new();
|
||||
#else
|
||||
return gtk_cell_renderer_spin_new();
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// ################# Casting #################
|
||||
//////////////////////////////////////////////
|
||||
|
||||
static inline void freeCstr(char* s) { free(s); }
|
||||
static inline gchar** nextGstr(gchar** s) { return (s+1); }
|
||||
|
||||
static inline gchar* toGstr(const char* s) { return (gchar*)s; }
|
||||
static inline char* toCstr(const gchar* s) { return (char*)s; }
|
||||
//static inline char* toCstrU(const guchar* s) { return (char*)s; }
|
||||
//static inline char* toCstrV(const void* s) { return (char*)s; }
|
||||
|
||||
static inline GObject* toGObject(void* o) { return G_OBJECT(o); }
|
||||
static inline GValue* toGValue(void* s) { return (GValue*)s; }
|
||||
static inline GtkWindow* toGWindow(GtkWidget* w) { return GTK_WINDOW(w); }
|
||||
static inline GtkDialog* toGDialog(GtkWidget* w) { return GTK_DIALOG(w); }
|
||||
static inline GtkAboutDialog* toGAboutDialog(GtkWidget* w) { return GTK_ABOUT_DIALOG(w); }
|
||||
static inline GtkContainer* toGContainer(GtkWidget* w) { return GTK_CONTAINER(w); }
|
||||
static inline GtkFileChooser* toGFileChooser(GtkWidget* w) { return GTK_FILE_CHOOSER(w); }
|
||||
static inline GtkFontSelection* toGFontSelection(GtkWidget* w) { return GTK_FONT_SELECTION(w); }
|
||||
static inline GtkFontSelectionDialog* toGFontSelectionDialog(GtkWidget* w) { return GTK_FONT_SELECTION_DIALOG(w); }
|
||||
static inline GtkMisc* toGMisc(GtkWidget* w) { return GTK_MISC(w); }
|
||||
static inline GtkLabel* toGLabel(GtkWidget* w) { return GTK_LABEL(w); }
|
||||
static inline GtkButton* toGButton(GtkWidget* w) { return GTK_BUTTON(w); }
|
||||
static inline GtkSpinButton* toGSpinButton(GtkWidget* w) { return GTK_SPIN_BUTTON(w); }
|
||||
static inline GtkRadioButton* toGRadioButton(GtkWidget* w) { return GTK_RADIO_BUTTON(w); }
|
||||
static inline GtkFontButton* toGFontButton(GtkWidget* w) { return GTK_FONT_BUTTON(w); }
|
||||
static inline GtkLinkButton* toGLinkButton(GtkWidget* w) { return GTK_LINK_BUTTON(w); }
|
||||
static inline GtkComboBox* toGComboBox(GtkWidget* w) { return GTK_COMBO_BOX(w); }
|
||||
static inline GtkComboBoxEntry* toGComboBoxEntry(GtkWidget* w) { return GTK_COMBO_BOX_ENTRY(w); }
|
||||
static inline GtkMessageDialog* toGMessageDialog(GtkWidget* w) { return GTK_MESSAGE_DIALOG(w); }
|
||||
#if GTK_CHECK_VERSION(2,24,0)
|
||||
static inline GtkComboBoxText* toGComboBoxText(GtkWidget* w) { return GTK_COMBO_BOX_TEXT(w); }
|
||||
#else
|
||||
static inline GtkComboBoxText* toGComboBoxText(GtkWidget* w) { return w; }
|
||||
#endif
|
||||
static inline GtkAccessible* toGAccessible(void* w) { return GTK_ACCESSIBLE(w); }
|
||||
static inline GtkBin* toGBin(GtkWidget* w) { return GTK_BIN(w); }
|
||||
static inline GtkStatusbar* toGStatusbar(GtkWidget* w) { return GTK_STATUSBAR(w); }
|
||||
static inline GtkInfoBar* toGInfoBar(GtkWidget* w) { return GTK_INFO_BAR(w); }
|
||||
static inline GtkFrame* toGFrame(GtkWidget* w) { return GTK_FRAME(w); }
|
||||
static inline GtkBox* toGBox(GtkWidget* w) { return GTK_BOX(w); }
|
||||
static inline GtkPaned* toGPaned(GtkWidget* w) { return GTK_PANED(w); }
|
||||
static inline GtkToggleButton* toGToggleButton(GtkWidget* w) { return GTK_TOGGLE_BUTTON(w); }
|
||||
static inline GtkAccelLabel* toGAccelLabel(GtkWidget* w) { return GTK_ACCEL_LABEL(w); }
|
||||
static inline GtkEntry* toGEntry(GtkWidget* w) { return GTK_ENTRY(w); }
|
||||
static inline GtkScaleButton* toGScaleButton(GtkWidget* w) { return GTK_SCALE_BUTTON(w); }
|
||||
static inline GtkStyle* toGStyle(GtkObject* o) { return GTK_STYLE(o); }
|
||||
static inline GtkAdjustment* toGAdjustment(GtkObject* o) { return GTK_ADJUSTMENT(o); }
|
||||
static inline GtkArrow* toGArrow(GtkWidget* w) { return GTK_ARROW(w); }
|
||||
static inline GtkTextView* toGTextView(GtkWidget* w) { return GTK_TEXT_VIEW(w); }
|
||||
static inline GtkTextBuffer* toGTextBuffer(void* w) { return GTK_TEXT_BUFFER(w); }
|
||||
static inline GtkTextTag* toGTextTag(void* o) { return GTK_TEXT_TAG(o); }
|
||||
static inline GtkMenu* toGMenu(GtkWidget* w) { return GTK_MENU(w); }
|
||||
static inline GtkMenuBar* toGMenuBar(GtkWidget* w) { return GTK_MENU_BAR(w); }
|
||||
static inline GtkMenuShell* toGMenuShell(GtkWidget* w) { return GTK_MENU_SHELL(w); }
|
||||
static inline GtkMenuItem* toGMenuItem(GtkWidget* w) { return GTK_MENU_ITEM(w); }
|
||||
static inline GtkItem* toGItem(GtkWidget* w) { return GTK_ITEM(w); }
|
||||
static inline GtkToolbar* toGToolbar(GtkWidget* w) { return GTK_TOOLBAR(w); }
|
||||
static inline GtkToolItem* toGToolItem(GtkWidget* w) { return GTK_TOOL_ITEM(w); }
|
||||
static inline GtkSeparatorToolItem* toGSeparatorToolItem(GtkWidget* w) { return GTK_SEPARATOR_TOOL_ITEM(w); }
|
||||
static inline GtkToolButton* toGToolButton(GtkWidget* w) { return GTK_TOOL_BUTTON(w); }
|
||||
static inline GtkToolPalette* toGToolPalette(GtkWidget* w) { return GTK_TOOL_PALETTE(w); }
|
||||
static inline GtkToolItemGroup* toGToolItemGroup(GtkWidget* w) { return GTK_TOOL_ITEM_GROUP(w); }
|
||||
static inline GtkMenuToolButton* toGMenuToolButton(GtkWidget* w) { return GTK_MENU_TOOL_BUTTON(w); }
|
||||
static inline GtkToggleToolButton* toGToggleToolButton(GtkWidget* w) { return GTK_TOGGLE_TOOL_BUTTON(w); }
|
||||
static inline GtkScrolledWindow* toGScrolledWindow(GtkWidget* w) { return GTK_SCROLLED_WINDOW(w); }
|
||||
static inline GtkViewport* toGViewport(GtkWidget* w) { return GTK_VIEWPORT(w); }
|
||||
static inline GtkWidget* toGWidget(void* w) { return GTK_WIDGET(w); }
|
||||
static inline GdkWindow* toGdkWindow(void* w) { return GDK_WINDOW(w); }
|
||||
static inline GdkScreen* toGdkScreen(void* s) { return GDK_SCREEN(s); }
|
||||
static inline GtkTreeView* toGTreeView(GtkWidget* w) { return GTK_TREE_VIEW(w); }
|
||||
static inline GtkIconView* toGIconView(GtkWidget* w) { return GTK_ICON_VIEW(w); }
|
||||
static inline GtkTreeSortable* toGTreeSortable(GtkTreeModel* m) { return GTK_TREE_SORTABLE(m); }
|
||||
static inline GtkEditable* toGEditable(GtkWidget* w) { return GTK_EDITABLE(w); }
|
||||
static inline GtkCellRendererText* toGCellRendererText(GtkCellRenderer* w) { return GTK_CELL_RENDERER_TEXT(w); }
|
||||
static inline GtkCellRendererToggle* toGCellRendererToggle(GtkCellRenderer* w) { return GTK_CELL_RENDERER_TOGGLE(w); }
|
||||
static inline GtkScale* toGScale(GtkWidget* w) { return GTK_SCALE(w); }
|
||||
static inline GtkRange* toGRange(GtkWidget* w) { return GTK_RANGE(w); }
|
||||
static inline GtkTreeModel* toGTreeModelFromListStore(GtkListStore* w) { return GTK_TREE_MODEL(w); }
|
||||
static inline GtkTreeModel* toGTreeModelFromTreeStore(GtkTreeStore* w) { return GTK_TREE_MODEL(w); }
|
||||
static inline GtkListStore* toGListStore(void* w) { return GTK_LIST_STORE(w); }
|
||||
static inline GtkImage* toGImage(GtkWidget* w) { return GTK_IMAGE(w); }
|
||||
static inline GtkNotebook* toGNotebook(GtkWidget* w) { return GTK_NOTEBOOK(w); }
|
||||
static inline GtkTable* toGTable(GtkWidget* w) { return GTK_TABLE(w); }
|
||||
static inline GtkDrawingArea* toGDrawingArea(GtkWidget* w) { return GTK_DRAWING_AREA(w); }
|
||||
static inline GtkSpinner* toGSpinner(GtkWidget* w) { return GTK_SPINNER(w); }
|
||||
static inline GtkAssistant* toGAssistant(GtkWidget* w) { return GTK_ASSISTANT(w); }
|
||||
static inline GtkExpander* toGExpander(GtkWidget* w) { return GTK_EXPANDER(w); }
|
||||
static inline GtkAlignment* toGAlignment(GtkWidget* w) { return GTK_ALIGNMENT(w); }
|
||||
static inline GtkProgressBar* toGProgressBar(GtkWidget* w) { return GTK_PROGRESS_BAR(w); }
|
||||
static inline GtkFixed* toGFixed(GtkWidget* w) { return GTK_FIXED(w); }
|
||||
static inline GtkCheckMenuItem* toGCheckMenuItem(GtkWidget* w) { return GTK_CHECK_MENU_ITEM(w); }
|
||||
static inline GtkRadioMenuItem* toGRadioMenuItem(GtkWidget* w) { return GTK_RADIO_MENU_ITEM(w); }
|
||||
static inline GtkFileFilter* toGFileFilter(gpointer p) { return GTK_FILE_FILTER(p); }
|
||||
static inline GtkTreePath* to_GTreePath(gpointer p) { return (GtkTreePath *)p; }
|
||||
static inline GtkTreeSelection* to_GTreeSelection(void *p) { return GTK_TREE_SELECTION(p); }
|
||||
static inline GtkTreeModel* to_GTreeModel(void *p) { return GTK_TREE_MODEL(p); }
|
||||
static inline GtkLayout* toGLayout(GtkWidget* w) { return GTK_LAYOUT(w); }
|
||||
static inline GtkColorButton* toGColorButton(GtkWidget* w) { return GTK_COLOR_BUTTON(w); }
|
||||
static inline GtkImageMenuItem* toGImageMenuItem(GtkWidget* w) { return GTK_IMAGE_MENU_ITEM(w); }
|
||||
static inline GtkAction* toGAction(void* o) { return GTK_ACTION(o); }
|
||||
static inline GtkToggleAction* toGToggleAction(void* o) { return GTK_TOGGLE_ACTION(o); }
|
||||
static inline GtkRadioAction* toGRadioAction(void* o) { return GTK_RADIO_ACTION(o); }
|
||||
static inline GtkRecentAction* toGRecentAction(void* o) { return GTK_RECENT_ACTION(o); }
|
||||
static inline GtkActionGroup* toGActionGroup(void* o) { return GTK_ACTION_GROUP(o); }
|
||||
static inline GtkActivatable* toGActivatable(GtkWidget* w) { return GTK_ACTIVATABLE(w); }
|
||||
static inline GtkUIManager* toGUIManager(void* o) { return GTK_UI_MANAGER(o); }
|
||||
#endif
|
58
vendor/github.com/mattn/go-gtk/gtk/gtk_test.go
generated
vendored
Normal file
58
vendor/github.com/mattn/go-gtk/gtk/gtk_test.go
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
package gtk
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUpdateTreeViewColumns(t *testing.T) {
|
||||
Init(nil)
|
||||
|
||||
columnsDesc := []struct {
|
||||
Title string
|
||||
Type string
|
||||
GTKType ICellRenderer
|
||||
}{
|
||||
{"Col_1", "text", NewCellRendererText()},
|
||||
{"Col_2", "text", NewCellRendererText()},
|
||||
}
|
||||
|
||||
tw := NewTreeView()
|
||||
for i, c := range columnsDesc {
|
||||
tw.AppendColumn(NewTreeViewColumnWithAttributes(c.Title, c.GTKType, c.Type, i))
|
||||
}
|
||||
|
||||
columns := tw.GetColumns()
|
||||
|
||||
if len(columns) != len(columnsDesc) {
|
||||
t.Error("Wrong number of the columns:", len(columns), len(columnsDesc))
|
||||
} else {
|
||||
|
||||
for i, _ := range columnsDesc {
|
||||
if columns[i].GetTitle() != columnsDesc[i].Title {
|
||||
t.Error("Wrong column title:", columns[i].GetTitle(), columnsDesc[i].Title)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for lastIndex := len(columns) - 1; lastIndex >= 0; {
|
||||
c := columns[lastIndex]
|
||||
|
||||
after := tw.RemoveColumn(c)
|
||||
|
||||
numbersColumns := lastIndex
|
||||
if numbersColumns != after {
|
||||
t.Error("Failed remove column:", numbersColumns, after)
|
||||
}
|
||||
|
||||
lastIndex -= 1
|
||||
if lastIndex >= 0 {
|
||||
if title := tw.GetColumns()[lastIndex].GetTitle(); title != columnsDesc[lastIndex].Title {
|
||||
t.Error("Wrong column title:", title, columnsDesc[lastIndex].Title)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if count := len(tw.GetColumns()); count != 0 {
|
||||
t.Error("Wrong number of the columns:", count)
|
||||
}
|
||||
}
|
13
vendor/github.com/mattn/go-gtk/gtk/gtk_x11.go
generated
vendored
Normal file
13
vendor/github.com/mattn/go-gtk/gtk/gtk_x11.go
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
// +build with-x11
|
||||
|
||||
package gtk
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/gdk"
|
||||
)
|
||||
|
||||
func (v *Window) XID() int32 {
|
||||
return gdk.WindowFromUnsafe(unsafe.Pointer(v.GWidget.window)).GetNativeWindowID()
|
||||
}
|
34
vendor/github.com/mattn/go-gtk/gtkgl/gdkgl.go
generated
vendored
Normal file
34
vendor/github.com/mattn/go-gtk/gtkgl/gdkgl.go
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
// +build !cgocheck
|
||||
|
||||
package gtkgl
|
||||
|
||||
const (
|
||||
ATTR_NONE = 0
|
||||
ATTR_USE_GL = 1
|
||||
ATTR_BUFFER_SIZE = 2
|
||||
ATTR_LEVEL = 3
|
||||
ATTR_RGBA = 4
|
||||
ATTR_DOUBLEBUFFER = 5
|
||||
ATTR_STEREO = 6
|
||||
ATTR_AUX_BUFFERS = 7
|
||||
ATTR_RED_SIZE = 8
|
||||
ATTR_GREEN_SIZE = 9
|
||||
ATTR_BLUE_SIZE = 10
|
||||
ATTR_ALPGHA_SIZE = 11
|
||||
ATTR_DEPTH_SIZE = 12
|
||||
ATTR_STENCIL_SIZE = 13
|
||||
ATTR_ACCUM_RED_SIZE = 14
|
||||
ATTR_ACCUM_GREEN_SIZE = 15
|
||||
ATTR_ACCUM_BLUE_SIZE = 16
|
||||
ATTR_ACCUM_ALPHA_SIZE = 17
|
||||
)
|
||||
|
||||
const (
|
||||
ATTR_X_VISUAL_TYPE_EXT = 0x22
|
||||
ATTR_TRANSPARENT_TYPE_EXT = 0x23
|
||||
ATTR_TRANSPARENT_INDEX_VALUE_EXT = 0x24
|
||||
ATTR_TRANSPARENT_RED_VALUE_EXT = 0x25
|
||||
ATTR_TRANSPARENT_GREEN_VALUE_EXT = 0x26
|
||||
ATTR_TRANSPARENT_BLUE_VALUE_EXT = 0x27
|
||||
ATTR_TRANSPARENT_ALPHA_VALUE_EXT = 0x28
|
||||
)
|
28
vendor/github.com/mattn/go-gtk/gtkgl/gtkgl.go.h
generated
vendored
Normal file
28
vendor/github.com/mattn/go-gtk/gtkgl/gtkgl.go.h
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef GO_GTKGL_H
|
||||
#define GO_GTKGL_H
|
||||
|
||||
#include <gtkgl/gdkgl.h>
|
||||
#include <gtkgl/gtkglarea.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void *make_area(int attr_count, int *attrs) {
|
||||
if (attr_count > 0 && attrs[attr_count-1] == 0) {
|
||||
// already null terminated; use the pointer directly
|
||||
return gtk_gl_area_new(attrs);
|
||||
} else {
|
||||
// make a null terminated copy of the attribute list
|
||||
GtkWidget *area = NULL;
|
||||
int *zattrs = malloc((attr_count+1)*sizeof(int));
|
||||
if (!zattrs) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(zattrs, attrs, attr_count * sizeof(attrs));
|
||||
zattrs[attr_count] = 0;
|
||||
area = gtk_gl_area_new(zattrs);
|
||||
free(zattrs);
|
||||
return area;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
27
vendor/github.com/mattn/go-gtk/gtkgl/gtkglarea.go
generated
vendored
Normal file
27
vendor/github.com/mattn/go-gtk/gtkgl/gtkglarea.go
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// +build !cgocheck
|
||||
|
||||
package gtkgl
|
||||
|
||||
// #include "gtkgl.go.h"
|
||||
// #cgo pkg-config: gtkgl-2.0
|
||||
import "C"
|
||||
|
||||
import "github.com/mattn/go-gtk/gtk"
|
||||
import "unsafe"
|
||||
|
||||
type GLArea struct {
|
||||
gtk.DrawingArea
|
||||
}
|
||||
|
||||
func NewGLArea(attrList []int) *GLArea {
|
||||
return &GLArea{gtk.DrawingArea{
|
||||
*gtk.WidgetFromNative(C.make_area(C.int(len(attrList)), (*C.int)(unsafe.Pointer(&attrList[0]))))}}
|
||||
}
|
||||
|
||||
func (v *GLArea) MakeCurrent() {
|
||||
C.gtk_gl_area_make_current((*C.GtkGLArea)(unsafe.Pointer(v.GWidget)))
|
||||
}
|
||||
|
||||
func (v *GLArea) SwapBuffers() {
|
||||
C.gtk_gl_area_swap_buffers((*C.GtkGLArea)(unsafe.Pointer(v.GWidget)))
|
||||
}
|
405
vendor/github.com/mattn/go-gtk/gtksourceview/gtksourceview.go
generated
vendored
Normal file
405
vendor/github.com/mattn/go-gtk/gtksourceview/gtksourceview.go
generated
vendored
Normal file
@@ -0,0 +1,405 @@
|
||||
// +build !cgocheck
|
||||
|
||||
package gtksourceview
|
||||
|
||||
// #include "gtksourceview.go.h"
|
||||
// #cgo pkg-config: gtksourceview-2.0
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-gtk/gtk"
|
||||
)
|
||||
|
||||
func gstring(s *C.char) *C.gchar { return C.toGstr(s) }
|
||||
func cstring(s *C.gchar) *C.char { return C.toCstr(s) }
|
||||
func gostring(s *C.gchar) string { return C.GoString(cstring(s)) }
|
||||
|
||||
func gbool(b bool) C.gboolean {
|
||||
if b {
|
||||
return C.gboolean(1)
|
||||
}
|
||||
return C.gboolean(0)
|
||||
}
|
||||
|
||||
func gobool(b C.gboolean) bool {
|
||||
if b != 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func cfree(s *C.char) { C.freeCstr(s) }
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// GtkSourceBuffer
|
||||
//-----------------------------------------------------------------------
|
||||
type SourceBuffer struct {
|
||||
GSourceBuffer *C.GtkSourceBuffer
|
||||
*gtk.TextBuffer
|
||||
}
|
||||
|
||||
func NewSourceBuffer() *SourceBuffer {
|
||||
v := C.gtk_source_buffer_new(nil)
|
||||
return &SourceBuffer{v, gtk.NewTextBufferFromPointer(unsafe.Pointer(v))}
|
||||
}
|
||||
|
||||
func NewSourceBufferWithLanguage(lang *SourceLanguage) *SourceBuffer {
|
||||
v := C.gtk_source_buffer_new_with_language(lang.GSourceLanguage)
|
||||
return &SourceBuffer{v, gtk.NewTextBufferFromPointer(unsafe.Pointer(v))}
|
||||
}
|
||||
|
||||
func (v *SourceBuffer) GetNativeBuffer() unsafe.Pointer {
|
||||
return unsafe.Pointer(v.GSourceBuffer)
|
||||
}
|
||||
|
||||
func (v *SourceBuffer) SetHighlightSyntax(highlight bool) {
|
||||
C.gtk_source_buffer_set_highlight_syntax(v.GSourceBuffer, gbool(highlight))
|
||||
}
|
||||
|
||||
func (v *SourceBuffer) GetHighlightSyntax() bool {
|
||||
return gobool(C.gtk_source_buffer_get_highlight_syntax(v.GSourceBuffer))
|
||||
}
|
||||
|
||||
func (v *SourceBuffer) SetHighlightMatchingBrackets(hl bool) {
|
||||
C.gtk_source_buffer_set_highlight_matching_brackets(v.GSourceBuffer, gbool(hl))
|
||||
}
|
||||
|
||||
func (v *SourceBuffer) SetLanguage(lang *SourceLanguage) {
|
||||
C.gtk_source_buffer_set_language(v.GSourceBuffer, lang.GSourceLanguage)
|
||||
}
|
||||
|
||||
func (v *SourceBuffer) GetLanguage() *SourceLanguage {
|
||||
return &SourceLanguage{C.gtk_source_buffer_get_language(v.GSourceBuffer)}
|
||||
}
|
||||
|
||||
func (v *SourceBuffer) BeginNotUndoableAction() {
|
||||
C.gtk_source_buffer_begin_not_undoable_action(v.GSourceBuffer)
|
||||
}
|
||||
|
||||
func (v *SourceBuffer) EndNotUndoableAction() {
|
||||
C.gtk_source_buffer_end_not_undoable_action(v.GSourceBuffer)
|
||||
}
|
||||
|
||||
func (v *SourceBuffer) SetStyleScheme(scheme *SourceStyleScheme) {
|
||||
C.gtk_source_buffer_set_style_scheme(v.GSourceBuffer, scheme.GSourceStyleScheme)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// GtkSourceView
|
||||
//-----------------------------------------------------------------------
|
||||
type SourceView struct {
|
||||
gtk.TextView
|
||||
}
|
||||
|
||||
func NewSourceView() *SourceView {
|
||||
return &SourceView{gtk.TextView{gtk.Container{
|
||||
*gtk.WidgetFromNative(unsafe.Pointer(C.gtk_source_view_new()))}}}
|
||||
}
|
||||
|
||||
func NewSourceViewWithBuffer(buf *SourceBuffer) *SourceView {
|
||||
return &SourceView{gtk.TextView{gtk.Container{
|
||||
*gtk.WidgetFromNative(unsafe.Pointer(C.gtk_source_view_new_with_buffer(buf.GSourceBuffer)))}}}
|
||||
}
|
||||
|
||||
func (v *SourceView) ToNativeSourceView() *C.GtkSourceView {
|
||||
return C.toGtkSourceView(unsafe.Pointer(v.GWidget))
|
||||
}
|
||||
|
||||
func (v *SourceView) SetAutoIndent(enable bool) {
|
||||
C.gtk_source_view_set_auto_indent(v.ToNativeSourceView(), gbool(enable))
|
||||
}
|
||||
|
||||
func (v *SourceView) GetAutoIndent() bool {
|
||||
return gobool(C.gtk_source_view_get_auto_indent(v.ToNativeSourceView()))
|
||||
}
|
||||
|
||||
func (v *SourceView) SetHighlightCurrentLine(enable bool) {
|
||||
C.gtk_source_view_set_highlight_current_line(v.ToNativeSourceView(), gbool(enable))
|
||||
}
|
||||
|
||||
func (v *SourceView) GetHighlightCurrentLine() bool {
|
||||
return gobool(C.gtk_source_view_get_highlight_current_line(v.ToNativeSourceView()))
|
||||
}
|
||||
|
||||
func (v *SourceView) SetShowLineNumbers(enable bool) {
|
||||
C.gtk_source_view_set_show_line_numbers(v.ToNativeSourceView(), gbool(enable))
|
||||
}
|
||||
|
||||
func (v *SourceView) GetShowLineNumbers() bool {
|
||||
return gobool(C.gtk_source_view_get_show_line_numbers(v.ToNativeSourceView()))
|
||||
}
|
||||
|
||||
func (v *SourceView) SetRightMarginPosition(pos uint) {
|
||||
C.gtk_source_view_set_right_margin_position(v.ToNativeSourceView(), C.guint(pos))
|
||||
}
|
||||
|
||||
func (v *SourceView) GetRightMarginPosition() uint {
|
||||
return uint(C.gtk_source_view_get_right_margin_position(v.ToNativeSourceView()))
|
||||
}
|
||||
|
||||
func (v *SourceView) SetIndentWidth(width int) {
|
||||
C.gtk_source_view_set_indent_width(v.ToNativeSourceView(), C.gint(width))
|
||||
}
|
||||
|
||||
func (v *SourceView) GetIndentWidth() int {
|
||||
return int(C.gtk_source_view_get_indent_width(v.ToNativeSourceView()))
|
||||
}
|
||||
|
||||
func (v *SourceView) SetShowRightMargin(enable bool) {
|
||||
C.gtk_source_view_set_show_right_margin(v.ToNativeSourceView(), gbool(enable))
|
||||
}
|
||||
|
||||
func (v *SourceView) GetShowRightMargin() bool {
|
||||
return gobool(C.gtk_source_view_get_show_right_margin(v.ToNativeSourceView()))
|
||||
}
|
||||
|
||||
func (v *SourceView) SetInsertSpacesInsteadOfTabs(enable bool) {
|
||||
C.gtk_source_view_set_insert_spaces_instead_of_tabs(v.ToNativeSourceView(), gbool(enable))
|
||||
}
|
||||
|
||||
func (v *SourceView) GetInsertSpacesInsteadOfTabs() bool {
|
||||
return gobool(C.gtk_source_view_get_insert_spaces_instead_of_tabs(v.ToNativeSourceView()))
|
||||
}
|
||||
|
||||
type SourceDrawSpacesFlags int
|
||||
|
||||
const (
|
||||
SOURCE_DRAW_SPACES_SPACE SourceDrawSpacesFlags = 1 << 0
|
||||
SOURCE_DRAW_SPACES_TAB SourceDrawSpacesFlags = 1 << 1
|
||||
SOURCE_DRAW_SPACES_NEWLINE SourceDrawSpacesFlags = 1 << 2
|
||||
SOURCE_DRAW_SPACES_NBSP SourceDrawSpacesFlags = 1 << 3
|
||||
SOURCE_DRAW_SPACES_LEADING SourceDrawSpacesFlags = 1 << 4
|
||||
SOURCE_DRAW_SPACES_TEXT SourceDrawSpacesFlags = 1 << 5
|
||||
SOURCE_DRAW_SPACES_TRAILING SourceDrawSpacesFlags = 1 << 6
|
||||
SOURCE_DRAW_SPACES_ALL SourceDrawSpacesFlags = (SOURCE_DRAW_SPACES_SPACE |
|
||||
SOURCE_DRAW_SPACES_TAB |
|
||||
SOURCE_DRAW_SPACES_NEWLINE |
|
||||
SOURCE_DRAW_SPACES_NBSP |
|
||||
SOURCE_DRAW_SPACES_LEADING |
|
||||
SOURCE_DRAW_SPACES_TEXT |
|
||||
SOURCE_DRAW_SPACES_TRAILING)
|
||||
)
|
||||
|
||||
func (v *SourceView) SetDrawSpaces(flags SourceDrawSpacesFlags) {
|
||||
C.gtk_source_view_set_draw_spaces(v.ToNativeSourceView(),
|
||||
C.GtkSourceDrawSpacesFlags(flags))
|
||||
}
|
||||
|
||||
func (v *SourceView) GetDrawSpaces() SourceDrawSpacesFlags {
|
||||
return SourceDrawSpacesFlags(C.gtk_source_view_get_draw_spaces(v.ToNativeSourceView()))
|
||||
}
|
||||
|
||||
func (v *SourceView) SetTabWidth(width uint) {
|
||||
C.gtk_source_view_set_tab_width(v.ToNativeSourceView(),
|
||||
C.guint(width))
|
||||
}
|
||||
|
||||
func (v *SourceView) GetTabWidth() uint {
|
||||
return uint(C.gtk_source_view_get_tab_width(v.ToNativeSourceView()))
|
||||
}
|
||||
|
||||
type SourceSmartHomeEndType int
|
||||
|
||||
const (
|
||||
SOURCE_SMART_HOME_END_DISABLED SourceSmartHomeEndType = 0
|
||||
SOURCE_SMART_HOME_END_BEFORE SourceSmartHomeEndType = 1
|
||||
SOURCE_SMART_HOME_END_AFTER SourceSmartHomeEndType = 2
|
||||
SOURCE_SMART_HOME_END_ALWAYS SourceSmartHomeEndType = 3
|
||||
)
|
||||
|
||||
func (v *SourceView) SetSmartHomeEnd(flags SourceSmartHomeEndType) {
|
||||
C.gtk_source_view_set_smart_home_end(v.ToNativeSourceView(),
|
||||
C.GtkSourceSmartHomeEndType(flags))
|
||||
}
|
||||
|
||||
func (v *SourceView) GetSmartHomeEnd() SourceSmartHomeEndType {
|
||||
return SourceSmartHomeEndType(C.gtk_source_view_get_smart_home_end(v.ToNativeSourceView()))
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// GtkSourceLanguage
|
||||
//-----------------------------------------------------------------------
|
||||
type SourceLanguage struct {
|
||||
GSourceLanguage *C.GtkSourceLanguage
|
||||
}
|
||||
|
||||
func (v *SourceLanguage) GetId() string {
|
||||
return gostring(C.gtk_source_language_get_id(v.GSourceLanguage))
|
||||
}
|
||||
|
||||
func (v *SourceLanguage) GetName() string {
|
||||
return gostring(C.gtk_source_language_get_name(v.GSourceLanguage))
|
||||
}
|
||||
|
||||
func (v *SourceLanguage) GetSection() string {
|
||||
return gostring(C.gtk_source_language_get_section(v.GSourceLanguage))
|
||||
}
|
||||
|
||||
func (v *SourceLanguage) GetHidden() bool {
|
||||
return gobool(C.gtk_source_language_get_hidden(v.GSourceLanguage))
|
||||
}
|
||||
|
||||
func (v *SourceLanguage) GetMetadata(name string) string {
|
||||
cname := C.CString(name)
|
||||
defer cfree(cname)
|
||||
return gostring(C.gtk_source_language_get_metadata(v.GSourceLanguage, gstring(cname)))
|
||||
}
|
||||
|
||||
func (v *SourceLanguage) GetMimeTypes() []string {
|
||||
var types []string
|
||||
ctypes := C.gtk_source_language_get_mime_types(v.GSourceLanguage)
|
||||
for {
|
||||
types = append(types, gostring(*ctypes))
|
||||
ctypes = C.nextGstr(ctypes)
|
||||
if *ctypes == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return types
|
||||
}
|
||||
|
||||
func (v *SourceLanguage) GetGlobs() []string {
|
||||
var globs []string
|
||||
cglobs := C.gtk_source_language_get_globs(v.GSourceLanguage)
|
||||
for {
|
||||
globs = append(globs, gostring(*cglobs))
|
||||
cglobs = C.nextGstr(cglobs)
|
||||
if *cglobs == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return globs
|
||||
}
|
||||
|
||||
func (v *SourceLanguage) GetStyleName(styleId string) string {
|
||||
cstyleId := C.CString(styleId)
|
||||
defer cfree(cstyleId)
|
||||
return gostring(C.gtk_source_language_get_metadata(v.GSourceLanguage, gstring(cstyleId)))
|
||||
}
|
||||
|
||||
func (v *SourceLanguage) GetStyleIds() []string {
|
||||
var ids []string
|
||||
cids := C.gtk_source_language_get_globs(v.GSourceLanguage)
|
||||
for {
|
||||
ids = append(ids, gostring(*cids))
|
||||
cids = C.nextGstr(cids)
|
||||
if *cids == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
//FINISH
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// GtkSourceLanguageManager
|
||||
//-----------------------------------------------------------------------
|
||||
type SourceLanguageManager struct {
|
||||
GSourceLanguageManager *C.GtkSourceLanguageManager
|
||||
}
|
||||
|
||||
func NewSourceLanguageManager() *SourceLanguageManager {
|
||||
return &SourceLanguageManager{C.gtk_source_language_manager_new()}
|
||||
}
|
||||
|
||||
func SourceLanguageManagerGetDefault() *SourceLanguageManager {
|
||||
return &SourceLanguageManager{C.gtk_source_language_manager_get_default()}
|
||||
}
|
||||
|
||||
func (v *SourceLanguageManager) SetSearchPath(paths []string) {
|
||||
cpaths := C.make_strings(C.int(len(paths) + 1))
|
||||
for i, path := range paths {
|
||||
ptr := C.CString(path)
|
||||
defer cfree(ptr)
|
||||
C.set_string(cpaths, C.int(i), gstring(ptr))
|
||||
}
|
||||
C.set_string(cpaths, C.int(len(paths)), nil)
|
||||
C.gtk_source_language_manager_set_search_path(v.GSourceLanguageManager, cpaths)
|
||||
C.destroy_strings(cpaths)
|
||||
}
|
||||
|
||||
func (v *SourceLanguageManager) GetSearchPath() []string {
|
||||
var dirs []string
|
||||
cdirs := C.gtk_source_language_manager_get_search_path(v.GSourceLanguageManager)
|
||||
for {
|
||||
dirs = append(dirs, gostring(*cdirs))
|
||||
cdirs = C.nextGstr(cdirs)
|
||||
if *cdirs == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return dirs
|
||||
}
|
||||
|
||||
func (v *SourceLanguageManager) GetLanguageIds() []string {
|
||||
var ids []string
|
||||
cids := C.gtk_source_language_manager_get_language_ids(v.GSourceLanguageManager)
|
||||
for {
|
||||
ids = append(ids, gostring(*cids))
|
||||
cids = C.nextGstr(cids)
|
||||
if *cids == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
func (v *SourceLanguageManager) GetLanguage(id string) *SourceLanguage {
|
||||
cid := C.CString(id)
|
||||
defer cfree(cid)
|
||||
return &SourceLanguage{C.gtk_source_language_manager_get_language(v.GSourceLanguageManager, gstring(cid))}
|
||||
}
|
||||
|
||||
func (v *SourceLanguageManager) GuessLanguage(filename string, contentType string) *SourceLanguage {
|
||||
if filename == "" {
|
||||
cct := C.CString(contentType)
|
||||
defer cfree(cct)
|
||||
return &SourceLanguage{C.gtk_source_language_manager_guess_language(v.GSourceLanguageManager, nil, gstring(cct))}
|
||||
}
|
||||
cfn := C.CString(filename)
|
||||
defer cfree(cfn)
|
||||
return &SourceLanguage{C.gtk_source_language_manager_guess_language(v.GSourceLanguageManager, gstring(cfn), nil)}
|
||||
}
|
||||
|
||||
//FINISH
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// GtkSourceStyle
|
||||
//-----------------------------------------------------------------------
|
||||
type SourceStyleScheme struct {
|
||||
GSourceStyleScheme *C.GtkSourceStyleScheme
|
||||
}
|
||||
|
||||
// gtk_source_style_scheme_get_id
|
||||
// gtk_source_style_scheme_get_name
|
||||
// gtk_source_style_scheme_get_description
|
||||
// gtk_source_style_scheme_get_authors
|
||||
// gtk_source_style_scheme_get_filename
|
||||
// gtk_source_style_scheme_get_style
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// GtkSourceStyleSchemeManager
|
||||
//-----------------------------------------------------------------------
|
||||
type SourceStyleSchemeManager struct {
|
||||
GSourceStyleSchemeManager *C.GtkSourceStyleSchemeManager
|
||||
}
|
||||
|
||||
func NewSourceStyleSchemeManager() *SourceStyleSchemeManager {
|
||||
return &SourceStyleSchemeManager{C.gtk_source_style_scheme_manager_new()}
|
||||
}
|
||||
|
||||
func (v *SourceStyleSchemeManager) GetScheme(scheme_id string) *SourceStyleScheme {
|
||||
cscheme_id := C.CString(scheme_id)
|
||||
defer cfree(cscheme_id)
|
||||
return &SourceStyleScheme{C.gtk_source_style_scheme_manager_get_scheme(v.GSourceStyleSchemeManager, gstring(cscheme_id))}
|
||||
}
|
||||
|
||||
// gtk_source_style_scheme_manager_get_default
|
||||
// gtk_source_style_scheme_manager_set_search_path
|
||||
// gtk_source_style_scheme_manager_append_search_path
|
||||
// gtk_source_style_scheme_manager_prepend_search_path
|
||||
// gtk_source_style_scheme_manager_get_search_path
|
||||
// gtk_source_style_scheme_manager_get_scheme_ids
|
||||
// gtk_source_style_scheme_manager_force_rescan
|
30
vendor/github.com/mattn/go-gtk/gtksourceview/gtksourceview.go.h
generated
vendored
Normal file
30
vendor/github.com/mattn/go-gtk/gtksourceview/gtksourceview.go.h
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef GO_GTKSOURCEVIEW_H
|
||||
#define GO_GTKSOURCEVIEW_H
|
||||
|
||||
#include <gtksourceview/gtksourceview.h>
|
||||
#include <gtksourceview/gtksourcebuffer.h>
|
||||
#include <gtksourceview/gtksourcelanguage.h>
|
||||
#include <gtksourceview/gtksourcelanguagemanager.h>
|
||||
#include <gtksourceview/gtksourcestyleschememanager.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static inline gchar** make_strings(int count) {
|
||||
return (gchar**)malloc(sizeof(gchar*) * count);
|
||||
}
|
||||
|
||||
static inline void destroy_strings(gchar** strings) {
|
||||
free(strings);
|
||||
}
|
||||
|
||||
static inline void set_string(gchar** strings, int n, gchar* str) {
|
||||
strings[n] = str;
|
||||
}
|
||||
|
||||
static inline GObject* toGObject(void* o) { return G_OBJECT(o); }
|
||||
static inline gchar* toGstr(const char* s) { return (gchar*)s; }
|
||||
static inline char* toCstr(const gchar* s) { return (char*)s; }
|
||||
static inline gchar** nextGstr(gchar** s) { return (s+1); }
|
||||
static inline void freeCstr(char* s) { free(s); }
|
||||
static GtkSourceView* toGtkSourceView(void* w) { return GTK_SOURCE_VIEW(w); }
|
||||
|
||||
#endif
|
56
vendor/github.com/mattn/go-gtk/gtkspell/gtkspell.go
generated
vendored
Normal file
56
vendor/github.com/mattn/go-gtk/gtkspell/gtkspell.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
// +build !cgocheck
|
||||
|
||||
package gtkspell
|
||||
|
||||
/*
|
||||
#include <gtk/gtk.h>
|
||||
#include <gtkspell/gtkspell.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static GtkTextView* to_GtkTextView(void* w) { return GTK_TEXT_VIEW(w); }
|
||||
static inline gchar* to_gcharptr(const char* s) { return (gchar*)s; }
|
||||
*/
|
||||
// #cgo pkg-config: gtkspell-2.0
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
import "github.com/mattn/go-gtk/glib"
|
||||
import "github.com/mattn/go-gtk/gtk"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// GtkSpell
|
||||
//-----------------------------------------------------------------------
|
||||
type GtkSpell struct {
|
||||
Spell *C.GtkSpell
|
||||
}
|
||||
|
||||
func New(textview *gtk.TextView, 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
|
||||
}
|
||||
|
||||
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 (spell *GtkSpell) Recheck() {
|
||||
C.gtkspell_recheck_all(spell.Spell)
|
||||
}
|
101
vendor/github.com/mattn/go-gtk/pango/pango.go
generated
vendored
Normal file
101
vendor/github.com/mattn/go-gtk/pango/pango.go
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
// +build !cgocheck
|
||||
|
||||
package pango
|
||||
|
||||
// #include "pango.go.h"
|
||||
// #cgo pkg-config: pango
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
const (
|
||||
SCALE = C.PANGO_SCALE
|
||||
)
|
||||
|
||||
func bool2gboolean(b bool) C.gboolean {
|
||||
if b {
|
||||
return C.gboolean(1)
|
||||
}
|
||||
return C.gboolean(0)
|
||||
}
|
||||
|
||||
func gboolean2bool(b C.gboolean) bool {
|
||||
if b != 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type WrapMode int
|
||||
|
||||
const (
|
||||
WRAP_WORD WrapMode = 0
|
||||
WRAP_CHAR WrapMode = 1
|
||||
WRAP_WORD_CHAR WrapMode = 2
|
||||
)
|
||||
|
||||
type EllipsizeMode int
|
||||
|
||||
const (
|
||||
ELLIPSIZE_NONE EllipsizeMode = 0
|
||||
ELLIPSIZE_START EllipsizeMode = 1
|
||||
ELLIPSIZE_MIDDLE EllipsizeMode = 2
|
||||
ELLIPSIZE_END EllipsizeMode = 3
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
GContext *C.PangoContext
|
||||
}
|
||||
|
||||
type Layout struct {
|
||||
GLayout *C.PangoLayout
|
||||
}
|
||||
|
||||
type FontDescription struct {
|
||||
GFontDescription *C.PangoFontDescription
|
||||
}
|
||||
|
||||
func ContextFromUnsafe(context unsafe.Pointer) *Context {
|
||||
return &Context{(*C.PangoContext)(context)}
|
||||
}
|
||||
|
||||
func (v *Layout) Unref() {
|
||||
C.g_object_unref(C.gpointer(v.GLayout))
|
||||
}
|
||||
|
||||
func (v *Layout) SetWidth(width int) {
|
||||
C.pango_layout_set_width(v.GLayout, C.int(width))
|
||||
}
|
||||
|
||||
func (v *Layout) SetFontDescription(d *FontDescription) {
|
||||
C.pango_layout_set_font_description(v.GLayout, d.GFontDescription)
|
||||
}
|
||||
|
||||
func (v *Layout) SetText(s string) {
|
||||
cs := C.CString(s)
|
||||
C.pango_layout_set_text(v.GLayout, cs, -1)
|
||||
C.free(unsafe.Pointer(cs))
|
||||
}
|
||||
|
||||
func NewLayout(ctx *Context) *Layout {
|
||||
return &Layout{C.pango_layout_new(ctx.GContext)}
|
||||
}
|
||||
|
||||
func NewFontDescription() *FontDescription {
|
||||
return &FontDescription{C.pango_font_description_new()}
|
||||
}
|
||||
|
||||
func (v *FontDescription) Free() {
|
||||
C.pango_font_description_free(v.GFontDescription)
|
||||
}
|
||||
|
||||
func (v *FontDescription) SetSize(size int) {
|
||||
C.pango_font_description_set_size(v.GFontDescription, C.gint(size))
|
||||
}
|
||||
|
||||
func (v *FontDescription) Copy() *FontDescription {
|
||||
return &FontDescription{C.pango_font_description_copy(v.GFontDescription)}
|
||||
}
|
||||
|
||||
func (f *FontDescription) GetSize() int {
|
||||
return int(C.pango_font_description_get_size(f.GFontDescription))
|
||||
}
|
23
vendor/github.com/mattn/go-gtk/pango/pango.go.h
generated
vendored
Normal file
23
vendor/github.com/mattn/go-gtk/pango/pango.go.h
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef GO_PANGO_H
|
||||
#define GO_PANGO_H
|
||||
|
||||
#ifndef uintptr
|
||||
#define uintptr unsigned int*
|
||||
#endif
|
||||
#include <pango/pango.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
//static const gchar* to_gcharptr(const char* s) { return (const gchar*)s; }
|
||||
//static guchar* to_gucharptr(void* s) { return (guchar*)s; }
|
||||
|
||||
//static void free_string(char* s) { free(s); }
|
||||
|
||||
//static gchar* to_gcharptr(char* s) { return (gchar*)s; }
|
||||
|
||||
//static void free_string(char* s) { free(s); }
|
||||
|
||||
#endif
|
106
vendor/github.com/mattn/go-gtk/tools/gogtkinfo/gogtkinfo.go
generated
vendored
Normal file
106
vendor/github.com/mattn/go-gtk/tools/gogtkinfo/gogtkinfo.go
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
Simple tool to approximatively count the progress of go-gtk library.
|
||||
Counts line starting by "func" (binding done) or starting by "//" and containing "gtk_" (binding to do) for each section (starting by a "// text" comment preceded by a "//------------")
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
list := make([]string, 0, 100)
|
||||
alphabeticalOrder := flag.Bool("a", false, "alphabetical order")
|
||||
githubCode := flag.Bool("g", false, "prepend spaces to each line so github will format them as code")
|
||||
flag.Parse()
|
||||
fname := flag.Arg(0)
|
||||
if fname == "" {
|
||||
fmt.Println("Usage: gogtkinfo [-ag] file")
|
||||
return
|
||||
}
|
||||
file, err := os.Open(fname)
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
rd := bufio.NewReader(file)
|
||||
var currentSection, sectionAlertName string
|
||||
var cDone, cTodo, p, tDone, tTodo int
|
||||
var sectionAlert, falseAlarm bool
|
||||
for {
|
||||
var l string
|
||||
if falseAlarm {
|
||||
falseAlarm = false
|
||||
} else {
|
||||
line, isPrefix, err := rd.ReadLine()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if isPrefix {
|
||||
return
|
||||
}
|
||||
l = string(line)
|
||||
}
|
||||
if strings.HasPrefix(l, "//---------------") {
|
||||
if sectionAlertName == "" {
|
||||
sectionAlert = true
|
||||
} else {
|
||||
if currentSection != "" {
|
||||
cTot := cDone + cTodo
|
||||
if cTot == 0 {
|
||||
p = 100
|
||||
} else {
|
||||
p = 100 * cDone / cTot
|
||||
}
|
||||
s := fmt.Sprintf("%-30s: %3d%% (%3d/%3d)\n", currentSection, p, cDone, cTot)
|
||||
list = append(list, s)
|
||||
}
|
||||
currentSection = sectionAlertName
|
||||
tDone += cDone
|
||||
tTodo += cTodo
|
||||
cDone = 0
|
||||
cTodo = 0
|
||||
sectionAlertName = ""
|
||||
}
|
||||
} else if sectionAlert {
|
||||
if strings.HasPrefix(l, "//") && len(l) > 3 && !strings.Contains(l, "gtk_") {
|
||||
sectionAlertName = strings.TrimSpace(l[2:len(l)])
|
||||
} else {
|
||||
falseAlarm = true
|
||||
}
|
||||
sectionAlert = false
|
||||
} else if strings.HasPrefix(l, "func") {
|
||||
cDone++
|
||||
} else if strings.HasPrefix(l, "//") && strings.Contains(l, "gtk_") {
|
||||
cTodo++
|
||||
}
|
||||
}
|
||||
if *alphabeticalOrder {
|
||||
sort.StringSlice(list).Sort()
|
||||
}
|
||||
for _, s := range list {
|
||||
if *githubCode {
|
||||
fmt.Print(" ")
|
||||
}
|
||||
fmt.Print(s)
|
||||
}
|
||||
tTot := tDone + tTodo
|
||||
if tTot == 0 {
|
||||
p = 0
|
||||
} else {
|
||||
p = 100 * tDone / tTot
|
||||
}
|
||||
if *githubCode {
|
||||
fmt.Print("\n ")
|
||||
} else {
|
||||
fmt.Print("\n")
|
||||
}
|
||||
fmt.Printf("Total progress : %18d%% (%d/%d)\n", p, tDone, tTot)
|
||||
}
|
29
vendor/github.com/mattn/go-pointer/README.md
generated
vendored
Normal file
29
vendor/github.com/mattn/go-pointer/README.md
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# go-pointer
|
||||
|
||||
Utility for cgo
|
||||
|
||||
## Usage
|
||||
|
||||
https://github.com/golang/proposal/blob/master/design/12416-cgo-pointers.md
|
||||
|
||||
In go 1.6, cgo argument can't be passed Go pointer.
|
||||
|
||||
```
|
||||
var s string
|
||||
C.pass_pointer(pointer.Save(&s))
|
||||
v := *(pointer.Restore(C.get_from_pointer()).(*string))
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
go get github.com/mattn/go-pointer
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Author
|
||||
|
||||
Yasuhiro Matsumoto (a.k.a mattn)
|
9
vendor/github.com/mattn/go-pointer/_example/callback.h
generated
vendored
Normal file
9
vendor/github.com/mattn/go-pointer/_example/callback.h
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <unistd.h>
|
||||
|
||||
typedef void (*callback)(void*);
|
||||
|
||||
static void call_later(int delay, callback cb, void* data) {
|
||||
sleep(delay);
|
||||
cb(data);
|
||||
}
|
||||
|
29
vendor/github.com/mattn/go-pointer/_example/main.go
generated
vendored
Normal file
29
vendor/github.com/mattn/go-pointer/_example/main.go
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
#include "callback.h"
|
||||
|
||||
void call_later_go_cb(void*);
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-pointer"
|
||||
)
|
||||
|
||||
type Foo struct {
|
||||
v int
|
||||
}
|
||||
|
||||
func main() {
|
||||
f := &Foo{123}
|
||||
C.call_later(3, C.callback(C.call_later_go_cb), pointer.Save(f))
|
||||
}
|
||||
|
||||
//export call_later_go_cb
|
||||
func call_later_go_cb(data unsafe.Pointer) {
|
||||
f := pointer.Restore(data).(*Foo)
|
||||
fmt.Println(f.v)
|
||||
}
|
13
vendor/github.com/mattn/go-pointer/example/example.go
generated
vendored
Normal file
13
vendor/github.com/mattn/go-pointer/example/example.go
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
package example
|
||||
|
||||
/*
|
||||
void *pass_pointer(void* p) {
|
||||
return p;
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
func PassPointer(ptr unsafe.Pointer) unsafe.Pointer {
|
||||
return C.pass_pointer(ptr)
|
||||
}
|
59
vendor/github.com/mattn/go-pointer/pointer.go
generated
vendored
Normal file
59
vendor/github.com/mattn/go-pointer/pointer.go
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
package pointer
|
||||
|
||||
// #include <stdlib.h>
|
||||
import "C"
|
||||
import (
|
||||
"sync"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
mutex sync.Mutex
|
||||
store = map[unsafe.Pointer]interface{}{}
|
||||
)
|
||||
|
||||
func Save(v interface{}) unsafe.Pointer {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Generate real fake C pointer.
|
||||
// This pointer will not store any data, but will bi used for indexing purposes.
|
||||
// Since Go doest allow to cast dangling pointer to unsafe.Pointer, we do rally allocate one byte.
|
||||
// Why we need indexing, because Go doest allow C code to store pointers to Go data.
|
||||
var ptr unsafe.Pointer = C.malloc(C.size_t(1))
|
||||
if ptr == nil {
|
||||
panic("can't allocate 'cgo-pointer hack index pointer': ptr == nil")
|
||||
}
|
||||
|
||||
mutex.Lock()
|
||||
store[ptr] = v
|
||||
mutex.Unlock()
|
||||
|
||||
return ptr
|
||||
}
|
||||
|
||||
func Restore(ptr unsafe.Pointer) interface{} {
|
||||
if ptr == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
if v, ok := store[ptr]; ok {
|
||||
return v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Unref(ptr unsafe.Pointer) {
|
||||
if ptr == nil {
|
||||
return
|
||||
}
|
||||
|
||||
mutex.Lock()
|
||||
delete(store, ptr)
|
||||
mutex.Unlock()
|
||||
|
||||
C.free(ptr)
|
||||
}
|
4
vendor/github.com/mattn/go-sqlite3/.gitignore
generated
vendored
Normal file
4
vendor/github.com/mattn/go-sqlite3/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
*.db
|
||||
*.exe
|
||||
*.dll
|
||||
*.o
|
18
vendor/github.com/mattn/go-sqlite3/.travis.yml
generated
vendored
Normal file
18
vendor/github.com/mattn/go-sqlite3/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
language: go
|
||||
sudo: required
|
||||
dist: trusty
|
||||
env:
|
||||
- GOTAGS=
|
||||
- GOTAGS=libsqlite3
|
||||
- GOTAGS=trace
|
||||
- GOTAGS=vtable
|
||||
go:
|
||||
- 1.7
|
||||
- 1.8
|
||||
- tip
|
||||
before_install:
|
||||
- go get github.com/mattn/goveralls
|
||||
- go get golang.org/x/tools/cmd/cover
|
||||
script:
|
||||
- $HOME/gopath/bin/goveralls -repotoken 3qJVUE0iQwqnCbmNcDsjYu1nh4J4KIFXx
|
||||
- go test -race -v . -tags "$GOTAGS"
|
21
vendor/github.com/mattn/go-sqlite3/LICENSE
generated
vendored
Normal file
21
vendor/github.com/mattn/go-sqlite3/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Yasuhiro Matsumoto
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
97
vendor/github.com/mattn/go-sqlite3/README.md
generated
vendored
Normal file
97
vendor/github.com/mattn/go-sqlite3/README.md
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
go-sqlite3
|
||||
==========
|
||||
|
||||
[](http://godoc.org/github.com/mattn/go-sqlite3)
|
||||
[](https://travis-ci.org/mattn/go-sqlite3)
|
||||
[](https://coveralls.io/r/mattn/go-sqlite3?branch=master)
|
||||
[](https://goreportcard.com/report/github.com/mattn/go-sqlite3)
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
sqlite3 driver conforming to the built-in database/sql interface
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
This package can be installed with the go get command:
|
||||
|
||||
go get github.com/mattn/go-sqlite3
|
||||
|
||||
_go-sqlite3_ is *cgo* package.
|
||||
If you want to build your app using go-sqlite3, you need gcc.
|
||||
However, if you install _go-sqlite3_ with `go install github.com/mattn/go-sqlite3`, you don't need gcc to build your app anymore.
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
API documentation can be found here: http://godoc.org/github.com/mattn/go-sqlite3
|
||||
|
||||
Examples can be found under the `./_example` directory
|
||||
|
||||
FAQ
|
||||
---
|
||||
|
||||
* Want to build go-sqlite3 with libsqlite3 on my linux.
|
||||
|
||||
Use `go build --tags "libsqlite3 linux"`
|
||||
|
||||
* Want to build go-sqlite3 with libsqlite3 on OS X.
|
||||
|
||||
Install sqlite3 from homebrew: `brew install sqlite3`
|
||||
|
||||
Use `go build --tags "libsqlite3 darwin"`
|
||||
|
||||
* Want to build go-sqlite3 with icu extension.
|
||||
|
||||
Use `go build --tags "icu"`
|
||||
|
||||
Available extensions: `json1`, `fts5`, `icu`
|
||||
|
||||
* Can't build go-sqlite3 on windows 64bit.
|
||||
|
||||
> Probably, you are using go 1.0, go1.0 has a problem when it comes to compiling/linking on windows 64bit.
|
||||
> See: [#27](https://github.com/mattn/go-sqlite3/issues/27)
|
||||
|
||||
* Getting insert error while query is opened.
|
||||
|
||||
> You can pass some arguments into the connection string, for example, a URI.
|
||||
> See: [#39](https://github.com/mattn/go-sqlite3/issues/39)
|
||||
|
||||
* Do you want to cross compile? mingw on Linux or Mac?
|
||||
|
||||
> See: [#106](https://github.com/mattn/go-sqlite3/issues/106)
|
||||
> See also: http://www.limitlessfx.com/cross-compile-golang-app-for-windows-from-linux.html
|
||||
|
||||
* Want to get time.Time with current locale
|
||||
|
||||
Use `loc=auto` in SQLite3 filename schema like `file:foo.db?loc=auto`.
|
||||
|
||||
* Can use this in multiple routines concurrently?
|
||||
|
||||
Yes for readonly. But, No for writable. See [#50](https://github.com/mattn/go-sqlite3/issues/50), [#51](https://github.com/mattn/go-sqlite3/issues/51), [#209](https://github.com/mattn/go-sqlite3/issues/209).
|
||||
|
||||
* Why is it racy if I use a `sql.Open("sqlite", ":memory:")` database?
|
||||
|
||||
Each connection to :memory: opens a brand new in-memory sql database, so if
|
||||
the stdlib's sql engine happens to open another connection and you've only
|
||||
specified ":memory:", that connection will see a brand new database. A
|
||||
workaround is to use "file::memory:?mode=memory&cache=shared". Every
|
||||
connection to this string will point to the same in-memory database. See
|
||||
[#204](https://github.com/mattn/go-sqlite3/issues/204) for more info.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
MIT: http://mattn.mit-license.org/2012
|
||||
|
||||
sqlite3-binding.c, sqlite3-binding.h, sqlite3ext.h
|
||||
|
||||
The -binding suffix was added to avoid build failures under gccgo.
|
||||
|
||||
In this repository, those files are an amalgamation of code that was copied from SQLite3. The license of that code is the same as the license of SQLite3.
|
||||
|
||||
Author
|
||||
------
|
||||
|
||||
Yasuhiro Matsumoto (a.k.a mattn)
|
133
vendor/github.com/mattn/go-sqlite3/_example/custom_func/main.go
generated
vendored
Normal file
133
vendor/github.com/mattn/go-sqlite3/_example/custom_func/main.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
|
||||
sqlite "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
// Computes x^y
|
||||
func pow(x, y int64) int64 {
|
||||
return int64(math.Pow(float64(x), float64(y)))
|
||||
}
|
||||
|
||||
// Computes the bitwise exclusive-or of all its arguments
|
||||
func xor(xs ...int64) int64 {
|
||||
var ret int64
|
||||
for _, x := range xs {
|
||||
ret ^= x
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Returns a random number. It's actually deterministic here because
|
||||
// we don't seed the RNG, but it's an example of a non-pure function
|
||||
// from SQLite's POV.
|
||||
func getrand() int64 {
|
||||
return rand.Int63()
|
||||
}
|
||||
|
||||
// Computes the standard deviation of a GROUPed BY set of values
|
||||
type stddev struct {
|
||||
xs []int64
|
||||
// Running average calculation
|
||||
sum int64
|
||||
n int64
|
||||
}
|
||||
|
||||
func newStddev() *stddev { return &stddev{} }
|
||||
|
||||
func (s *stddev) Step(x int64) {
|
||||
s.xs = append(s.xs, x)
|
||||
s.sum += x
|
||||
s.n++
|
||||
}
|
||||
|
||||
func (s *stddev) Done() float64 {
|
||||
mean := float64(s.sum) / float64(s.n)
|
||||
var sqDiff []float64
|
||||
for _, x := range s.xs {
|
||||
sqDiff = append(sqDiff, math.Pow(float64(x)-mean, 2))
|
||||
}
|
||||
var dev float64
|
||||
for _, x := range sqDiff {
|
||||
dev += x
|
||||
}
|
||||
dev /= float64(len(sqDiff))
|
||||
return math.Sqrt(dev)
|
||||
}
|
||||
|
||||
func main() {
|
||||
sql.Register("sqlite3_custom", &sqlite.SQLiteDriver{
|
||||
ConnectHook: func(conn *sqlite.SQLiteConn) error {
|
||||
if err := conn.RegisterFunc("pow", pow, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := conn.RegisterFunc("xor", xor, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := conn.RegisterFunc("rand", getrand, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := conn.RegisterAggregator("stddev", newStddev, true); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
db, err := sql.Open("sqlite3_custom", ":memory:")
|
||||
if err != nil {
|
||||
log.Fatal("Failed to open database:", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
var i int64
|
||||
err = db.QueryRow("SELECT pow(2,3)").Scan(&i)
|
||||
if err != nil {
|
||||
log.Fatal("POW query error:", err)
|
||||
}
|
||||
fmt.Println("pow(2,3) =", i) // 8
|
||||
|
||||
err = db.QueryRow("SELECT xor(1,2,3,4,5,6)").Scan(&i)
|
||||
if err != nil {
|
||||
log.Fatal("XOR query error:", err)
|
||||
}
|
||||
fmt.Println("xor(1,2,3,4,5) =", i) // 7
|
||||
|
||||
err = db.QueryRow("SELECT rand()").Scan(&i)
|
||||
if err != nil {
|
||||
log.Fatal("RAND query error:", err)
|
||||
}
|
||||
fmt.Println("rand() =", i) // pseudorandom
|
||||
|
||||
_, err = db.Exec("create table foo (department integer, profits integer)")
|
||||
if err != nil {
|
||||
log.Fatal("Failed to create table:", err)
|
||||
}
|
||||
_, err = db.Exec("insert into foo values (1, 10), (1, 20), (1, 45), (2, 42), (2, 115)")
|
||||
if err != nil {
|
||||
log.Fatal("Failed to insert records:", err)
|
||||
}
|
||||
|
||||
rows, err := db.Query("select department, stddev(profits) from foo group by department")
|
||||
if err != nil {
|
||||
log.Fatal("STDDEV query error:", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var dept int64
|
||||
var dev float64
|
||||
if err := rows.Scan(&dept, &dev); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("dept=%d stddev=%f\n", dept, dev)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
72
vendor/github.com/mattn/go-sqlite3/_example/hook/hook.go
generated
vendored
Normal file
72
vendor/github.com/mattn/go-sqlite3/_example/hook/hook.go
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
sqlite3conn := []*sqlite3.SQLiteConn{}
|
||||
sql.Register("sqlite3_with_hook_example",
|
||||
&sqlite3.SQLiteDriver{
|
||||
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
|
||||
sqlite3conn = append(sqlite3conn, conn)
|
||||
return nil
|
||||
},
|
||||
})
|
||||
os.Remove("./foo.db")
|
||||
os.Remove("./bar.db")
|
||||
|
||||
srcDb, err := sql.Open("sqlite3_with_hook_example", "./foo.db")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer srcDb.Close()
|
||||
srcDb.Ping()
|
||||
|
||||
_, err = srcDb.Exec("create table foo(id int, value text)")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, err = srcDb.Exec("insert into foo values(1, 'foo')")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, err = srcDb.Exec("insert into foo values(2, 'bar')")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, err = srcDb.Query("select * from foo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
destDb, err := sql.Open("sqlite3_with_hook_example", "./bar.db")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer destDb.Close()
|
||||
destDb.Ping()
|
||||
|
||||
bk, err := sqlite3conn[1].Backup("main", sqlite3conn[0], "main")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = bk.Step(-1)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, err = destDb.Query("select * from foo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, err = destDb.Exec("insert into foo values(3, 'bar')")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
bk.Finish()
|
||||
}
|
22
vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/Makefile
generated
vendored
Normal file
22
vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/Makefile
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
ifeq ($(OS),Windows_NT)
|
||||
EXE=extension.exe
|
||||
EXT=sqlite3_mod_regexp.dll
|
||||
RM=cmd /c del
|
||||
LDFLAG=
|
||||
else
|
||||
EXE=extension
|
||||
EXT=sqlite3_mod_regexp.so
|
||||
RM=rm
|
||||
LDFLAG=-fPIC
|
||||
endif
|
||||
|
||||
all : $(EXE) $(EXT)
|
||||
|
||||
$(EXE) : extension.go
|
||||
go build $<
|
||||
|
||||
$(EXT) : sqlite3_mod_regexp.c
|
||||
gcc $(LDFLAG) -shared -o $@ $< -lsqlite3 -lpcre
|
||||
|
||||
clean :
|
||||
@-$(RM) $(EXE) $(EXT)
|
43
vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/extension.go
generated
vendored
Normal file
43
vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/extension.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/mattn/go-sqlite3"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
sql.Register("sqlite3_with_extensions",
|
||||
&sqlite3.SQLiteDriver{
|
||||
Extensions: []string{
|
||||
"sqlite3_mod_regexp",
|
||||
},
|
||||
})
|
||||
|
||||
db, err := sql.Open("sqlite3_with_extensions", ":memory:")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
// Force db to make a new connection in pool
|
||||
// by putting the original in a transaction
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer tx.Commit()
|
||||
|
||||
// New connection works (hopefully!)
|
||||
rows, err := db.Query("select 'hello world' where 'hello world' regexp '^hello.*d$'")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var helloworld string
|
||||
rows.Scan(&helloworld)
|
||||
fmt.Println(helloworld)
|
||||
}
|
||||
}
|
31
vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/sqlite3_mod_regexp.c
generated
vendored
Normal file
31
vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/sqlite3_mod_regexp.c
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <pcre.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sqlite3ext.h>
|
||||
|
||||
SQLITE_EXTENSION_INIT1
|
||||
static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) {
|
||||
if (argc >= 2) {
|
||||
const char *target = (const char *)sqlite3_value_text(argv[1]);
|
||||
const char *pattern = (const char *)sqlite3_value_text(argv[0]);
|
||||
const char* errstr = NULL;
|
||||
int erroff = 0;
|
||||
int vec[500];
|
||||
int n, rc;
|
||||
pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL);
|
||||
rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
|
||||
if (rc <= 0) {
|
||||
sqlite3_result_error(context, errstr, 0);
|
||||
return;
|
||||
}
|
||||
sqlite3_result_int(context, 1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_extension_init(sqlite3 *db, char **errmsg, const sqlite3_api_routines *api) {
|
||||
SQLITE_EXTENSION_INIT2(api);
|
||||
return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, (void*)db, regexp_func, NULL, NULL);
|
||||
}
|
24
vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/Makefile
generated
vendored
Normal file
24
vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/Makefile
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
ifeq ($(OS),Windows_NT)
|
||||
EXE=extension.exe
|
||||
EXT=sqlite3_mod_vtable.dll
|
||||
RM=cmd /c del
|
||||
LIBCURL=-lcurldll
|
||||
LDFLAG=
|
||||
else
|
||||
EXE=extension
|
||||
EXT=sqlite3_mod_vtable.so
|
||||
RM=rm
|
||||
LDFLAG=-fPIC
|
||||
LIBCURL=-lcurl
|
||||
endif
|
||||
|
||||
all : $(EXE) $(EXT)
|
||||
|
||||
$(EXE) : extension.go
|
||||
go build $<
|
||||
|
||||
$(EXT) : sqlite3_mod_vtable.cc
|
||||
g++ $(LDFLAG) -shared -o $@ $< -lsqlite3 $(LIBCURL)
|
||||
|
||||
clean :
|
||||
@-$(RM) $(EXE) $(EXT)
|
37
vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/extension.go
generated
vendored
Normal file
37
vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/extension.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
sql.Register("sqlite3_with_extensions",
|
||||
&sqlite3.SQLiteDriver{
|
||||
Extensions: []string{
|
||||
"sqlite3_mod_vtable",
|
||||
},
|
||||
})
|
||||
|
||||
db, err := sql.Open("sqlite3_with_extensions", ":memory:")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
db.Exec("create virtual table repo using github(id, full_name, description, html_url)")
|
||||
|
||||
rows, err := db.Query("select id, full_name, description, html_url from repo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var id, fullName, description, htmlURL string
|
||||
rows.Scan(&id, &fullName, &description, &htmlURL)
|
||||
fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, fullName, description, htmlURL)
|
||||
}
|
||||
}
|
1040
vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/picojson.h
generated
vendored
Normal file
1040
vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/picojson.h
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
238
vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/sqlite3_mod_vtable.cc
generated
vendored
Normal file
238
vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/sqlite3_mod_vtable.cc
generated
vendored
Normal file
@@ -0,0 +1,238 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <sqlite3-binding.h>
|
||||
#include <sqlite3ext.h>
|
||||
#include <curl/curl.h>
|
||||
#include "picojson.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
# define EXPORT
|
||||
#endif
|
||||
|
||||
SQLITE_EXTENSION_INIT1;
|
||||
|
||||
typedef struct {
|
||||
char* data; // response data from server
|
||||
size_t size; // response size of data
|
||||
} MEMFILE;
|
||||
|
||||
MEMFILE*
|
||||
memfopen() {
|
||||
MEMFILE* mf = (MEMFILE*) malloc(sizeof(MEMFILE));
|
||||
if (mf) {
|
||||
mf->data = NULL;
|
||||
mf->size = 0;
|
||||
}
|
||||
return mf;
|
||||
}
|
||||
|
||||
void
|
||||
memfclose(MEMFILE* mf) {
|
||||
if (mf->data) free(mf->data);
|
||||
free(mf);
|
||||
}
|
||||
|
||||
size_t
|
||||
memfwrite(char* ptr, size_t size, size_t nmemb, void* stream) {
|
||||
MEMFILE* mf = (MEMFILE*) stream;
|
||||
int block = size * nmemb;
|
||||
if (!mf) return block; // through
|
||||
if (!mf->data)
|
||||
mf->data = (char*) malloc(block);
|
||||
else
|
||||
mf->data = (char*) realloc(mf->data, mf->size + block);
|
||||
if (mf->data) {
|
||||
memcpy(mf->data + mf->size, ptr, block);
|
||||
mf->size += block;
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
char*
|
||||
memfstrdup(MEMFILE* mf) {
|
||||
char* buf;
|
||||
if (mf->size == 0) return NULL;
|
||||
buf = (char*) malloc(mf->size + 1);
|
||||
memcpy(buf, mf->data, mf->size);
|
||||
buf[mf->size] = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
static int
|
||||
my_connect(sqlite3 *db, void *pAux, int argc, const char * const *argv, sqlite3_vtab **ppVTab, char **c) {
|
||||
std::stringstream ss;
|
||||
ss << "CREATE TABLE " << argv[0]
|
||||
<< "(id int, full_name text, description text, html_url text)";
|
||||
int rc = sqlite3_declare_vtab(db, ss.str().c_str());
|
||||
*ppVTab = (sqlite3_vtab *) sqlite3_malloc(sizeof(sqlite3_vtab));
|
||||
memset(*ppVTab, 0, sizeof(sqlite3_vtab));
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int
|
||||
my_create(sqlite3 *db, void *pAux, int argc, const char * const * argv, sqlite3_vtab **ppVTab, char **c) {
|
||||
return my_connect(db, pAux, argc, argv, ppVTab, c);
|
||||
}
|
||||
|
||||
static int my_disconnect(sqlite3_vtab *pVTab) {
|
||||
sqlite3_free(pVTab);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
my_destroy(sqlite3_vtab *pVTab) {
|
||||
sqlite3_free(pVTab);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
sqlite3_vtab_cursor base;
|
||||
int index;
|
||||
picojson::value* rows;
|
||||
} cursor;
|
||||
|
||||
static int
|
||||
my_open(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor) {
|
||||
MEMFILE* mf;
|
||||
CURL* curl;
|
||||
char* json;
|
||||
CURLcode res = CURLE_OK;
|
||||
char error[CURL_ERROR_SIZE] = {0};
|
||||
char* cert_file = getenv("SSL_CERT_FILE");
|
||||
|
||||
mf = memfopen();
|
||||
curl = curl_easy_init();
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/7.29.0");
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://api.github.com/repositories");
|
||||
if (cert_file)
|
||||
curl_easy_setopt(curl, CURLOPT_CAINFO, cert_file);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, mf);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, memfwrite);
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
if (res != CURLE_OK) {
|
||||
std::cerr << error << std::endl;
|
||||
return SQLITE_FAIL;
|
||||
}
|
||||
|
||||
picojson::value* v = new picojson::value;
|
||||
std::string err;
|
||||
picojson::parse(*v, mf->data, mf->data + mf->size, &err);
|
||||
memfclose(mf);
|
||||
|
||||
if (!err.empty()) {
|
||||
delete v;
|
||||
std::cerr << err << std::endl;
|
||||
return SQLITE_FAIL;
|
||||
}
|
||||
|
||||
cursor *c = (cursor *)sqlite3_malloc(sizeof(cursor));
|
||||
c->rows = v;
|
||||
c->index = 0;
|
||||
*ppCursor = &c->base;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
my_close(cursor *c) {
|
||||
delete c->rows;
|
||||
sqlite3_free(c);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
my_filter(cursor *c, int idxNum, const char *idxStr, int argc, sqlite3_value **argv) {
|
||||
c->index = 0;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
my_next(cursor *c) {
|
||||
c->index++;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
my_eof(cursor *c) {
|
||||
return c->index >= c->rows->get<picojson::array>().size() ? 1 : 0;
|
||||
}
|
||||
|
||||
static int
|
||||
my_column(cursor *c, sqlite3_context *ctxt, int i) {
|
||||
picojson::value v = c->rows->get<picojson::array>()[c->index];
|
||||
picojson::object row = v.get<picojson::object>();
|
||||
const char* p = NULL;
|
||||
switch (i) {
|
||||
case 0:
|
||||
p = row["id"].to_str().c_str();
|
||||
break;
|
||||
case 1:
|
||||
p = row["full_name"].to_str().c_str();
|
||||
break;
|
||||
case 2:
|
||||
p = row["description"].to_str().c_str();
|
||||
break;
|
||||
case 3:
|
||||
p = row["html_url"].to_str().c_str();
|
||||
break;
|
||||
}
|
||||
sqlite3_result_text(ctxt, strdup(p), strlen(p), free);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
my_rowid(cursor *c, sqlite3_int64 *pRowid) {
|
||||
*pRowid = c->index;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
my_bestindex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo) {
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
static const sqlite3_module module = {
|
||||
0,
|
||||
my_create,
|
||||
my_connect,
|
||||
my_bestindex,
|
||||
my_disconnect,
|
||||
my_destroy,
|
||||
my_open,
|
||||
(int (*)(sqlite3_vtab_cursor *)) my_close,
|
||||
(int (*)(sqlite3_vtab_cursor *, int, char const *, int, sqlite3_value **)) my_filter,
|
||||
(int (*)(sqlite3_vtab_cursor *)) my_next,
|
||||
(int (*)(sqlite3_vtab_cursor *)) my_eof,
|
||||
(int (*)(sqlite3_vtab_cursor *, sqlite3_context *, int)) my_column,
|
||||
(int (*)(sqlite3_vtab_cursor *, sqlite3_int64 *)) my_rowid,
|
||||
NULL, // my_update
|
||||
NULL, // my_begin
|
||||
NULL, // my_sync
|
||||
NULL, // my_commit
|
||||
NULL, // my_rollback
|
||||
NULL, // my_findfunction
|
||||
NULL, // my_rename
|
||||
};
|
||||
|
||||
static void
|
||||
destructor(void *arg) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
EXPORT int
|
||||
sqlite3_extension_init(sqlite3 *db, char **errmsg, const sqlite3_api_routines *api) {
|
||||
SQLITE_EXTENSION_INIT2(api);
|
||||
sqlite3_create_module_v2(db, "github", &module, NULL, destructor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
106
vendor/github.com/mattn/go-sqlite3/_example/simple/simple.go
generated
vendored
Normal file
106
vendor/github.com/mattn/go-sqlite3/_example/simple/simple.go
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Remove("./foo.db")
|
||||
|
||||
db, err := sql.Open("sqlite3", "./foo.db")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
sqlStmt := `
|
||||
create table foo (id integer not null primary key, name text);
|
||||
delete from foo;
|
||||
`
|
||||
_, err = db.Exec(sqlStmt)
|
||||
if err != nil {
|
||||
log.Printf("%q: %s\n", err, sqlStmt)
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
stmt, err := tx.Prepare("insert into foo(id, name) values(?, ?)")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer stmt.Close()
|
||||
for i := 0; i < 100; i++ {
|
||||
_, err = stmt.Exec(i, fmt.Sprintf("こんにちわ世界%03d", i))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
tx.Commit()
|
||||
|
||||
rows, err := db.Query("select id, name from foo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var id int
|
||||
var name string
|
||||
err = rows.Scan(&id, &name)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(id, name)
|
||||
}
|
||||
err = rows.Err()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
stmt, err = db.Prepare("select name from foo where id = ?")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer stmt.Close()
|
||||
var name string
|
||||
err = stmt.QueryRow("3").Scan(&name)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(name)
|
||||
|
||||
_, err = db.Exec("delete from foo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("insert into foo(id, name) values(1, 'foo'), (2, 'bar'), (3, 'baz')")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
rows, err = db.Query("select id, name from foo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var id int
|
||||
var name string
|
||||
err = rows.Scan(&id, &name)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(id, name)
|
||||
}
|
||||
err = rows.Err()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
264
vendor/github.com/mattn/go-sqlite3/_example/trace/main.go
generated
vendored
Normal file
264
vendor/github.com/mattn/go-sqlite3/_example/trace/main.go
generated
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
sqlite3 "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func traceCallback(info sqlite3.TraceInfo) int {
|
||||
// Not very readable but may be useful; uncomment next line in case of doubt:
|
||||
//fmt.Printf("Trace: %#v\n", info)
|
||||
|
||||
var dbErrText string
|
||||
if info.DBError.Code != 0 || info.DBError.ExtendedCode != 0 {
|
||||
dbErrText = fmt.Sprintf("; DB error: %#v", info.DBError)
|
||||
} else {
|
||||
dbErrText = "."
|
||||
}
|
||||
|
||||
// Show the Statement-or-Trigger text in curly braces ('{', '}')
|
||||
// since from the *paired* ASCII characters they are
|
||||
// the least used in SQL syntax, therefore better visual delimiters.
|
||||
// Maybe show 'ExpandedSQL' the same way as 'StmtOrTrigger'.
|
||||
//
|
||||
// A known use of curly braces (outside strings) is
|
||||
// for ODBC escape sequences. Not likely to appear here.
|
||||
//
|
||||
// Template languages, etc. don't matter, we should see their *result*
|
||||
// at *this* level.
|
||||
// Strange curly braces in SQL code that reached the database driver
|
||||
// suggest that there is a bug in the application.
|
||||
// The braces are likely to be either template syntax or
|
||||
// a programming language's string interpolation syntax.
|
||||
|
||||
var expandedText string
|
||||
if info.ExpandedSQL != "" {
|
||||
if info.ExpandedSQL == info.StmtOrTrigger {
|
||||
expandedText = " = exp"
|
||||
} else {
|
||||
expandedText = fmt.Sprintf(" expanded {%q}", info.ExpandedSQL)
|
||||
}
|
||||
} else {
|
||||
expandedText = ""
|
||||
}
|
||||
|
||||
// SQLite docs as of September 6, 2016: Tracing and Profiling Functions
|
||||
// https://www.sqlite.org/c3ref/profile.html
|
||||
//
|
||||
// The profile callback time is in units of nanoseconds, however
|
||||
// the current implementation is only capable of millisecond resolution
|
||||
// so the six least significant digits in the time are meaningless.
|
||||
// Future versions of SQLite might provide greater resolution on the profiler callback.
|
||||
|
||||
var runTimeText string
|
||||
if info.RunTimeNanosec == 0 {
|
||||
if info.EventCode == sqlite3.TraceProfile {
|
||||
//runTimeText = "; no time" // seems confusing
|
||||
runTimeText = "; time 0" // no measurement unit
|
||||
} else {
|
||||
//runTimeText = "; no time" // seems useless and confusing
|
||||
}
|
||||
} else {
|
||||
const nanosPerMillisec = 1000000
|
||||
if info.RunTimeNanosec%nanosPerMillisec == 0 {
|
||||
runTimeText = fmt.Sprintf("; time %d ms", info.RunTimeNanosec/nanosPerMillisec)
|
||||
} else {
|
||||
// unexpected: better than millisecond resolution
|
||||
runTimeText = fmt.Sprintf("; time %d ns!!!", info.RunTimeNanosec)
|
||||
}
|
||||
}
|
||||
|
||||
var modeText string
|
||||
if info.AutoCommit {
|
||||
modeText = "-AC-"
|
||||
} else {
|
||||
modeText = "+Tx+"
|
||||
}
|
||||
|
||||
fmt.Printf("Trace: ev %d %s conn 0x%x, stmt 0x%x {%q}%s%s%s\n",
|
||||
info.EventCode, modeText, info.ConnHandle, info.StmtHandle,
|
||||
info.StmtOrTrigger, expandedText,
|
||||
runTimeText,
|
||||
dbErrText)
|
||||
return 0
|
||||
}
|
||||
|
||||
func main() {
|
||||
eventMask := sqlite3.TraceStmt | sqlite3.TraceProfile | sqlite3.TraceRow | sqlite3.TraceClose
|
||||
|
||||
sql.Register("sqlite3_tracing",
|
||||
&sqlite3.SQLiteDriver{
|
||||
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
|
||||
err := conn.SetTrace(&sqlite3.TraceConfig{
|
||||
Callback: traceCallback,
|
||||
EventMask: uint(eventMask),
|
||||
WantExpandedSQL: true,
|
||||
})
|
||||
return err
|
||||
},
|
||||
})
|
||||
|
||||
os.Exit(dbMain())
|
||||
}
|
||||
|
||||
// Harder to do DB work in main().
|
||||
// It's better with a separate function because
|
||||
// 'defer' and 'os.Exit' don't go well together.
|
||||
//
|
||||
// DO NOT use 'log.Fatal...' below: remember that it's equivalent to
|
||||
// Print() followed by a call to os.Exit(1) --- and
|
||||
// we want to avoid Exit() so 'defer' can do cleanup.
|
||||
// Use 'log.Panic...' instead.
|
||||
|
||||
func dbMain() int {
|
||||
db, err := sql.Open("sqlite3_tracing", ":memory:")
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to open database: %#+v\n", err)
|
||||
return 1
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
err = db.Ping()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
dbSetup(db)
|
||||
|
||||
dbDoInsert(db)
|
||||
dbDoInsertPrepared(db)
|
||||
dbDoSelect(db)
|
||||
dbDoSelectPrepared(db)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// 'DDL' stands for "Data Definition Language":
|
||||
|
||||
// Note: "INTEGER PRIMARY KEY NOT NULL AUTOINCREMENT" causes the error
|
||||
// 'near "AUTOINCREMENT": syntax error'; without "NOT NULL" it works.
|
||||
const tableDDL = `CREATE TABLE t1 (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
note VARCHAR NOT NULL
|
||||
)`
|
||||
|
||||
// 'DML' stands for "Data Manipulation Language":
|
||||
|
||||
const insertDML = "INSERT INTO t1 (note) VALUES (?)"
|
||||
const selectDML = "SELECT id, note FROM t1 WHERE note LIKE ?"
|
||||
|
||||
const textPrefix = "bla-1234567890-"
|
||||
const noteTextPattern = "%Prep%"
|
||||
|
||||
const nGenRows = 4 // Number of Rows to Generate (for *each* approach tested)
|
||||
|
||||
func dbSetup(db *sql.DB) {
|
||||
var err error
|
||||
|
||||
_, err = db.Exec("DROP TABLE IF EXISTS t1")
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
_, err = db.Exec(tableDDL)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func dbDoInsert(db *sql.DB) {
|
||||
const Descr = "DB-Exec"
|
||||
for i := 0; i < nGenRows; i++ {
|
||||
result, err := db.Exec(insertDML, textPrefix+Descr)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
resultDoCheck(result, Descr, i)
|
||||
}
|
||||
}
|
||||
|
||||
func dbDoInsertPrepared(db *sql.DB) {
|
||||
const Descr = "DB-Prepare"
|
||||
|
||||
stmt, err := db.Prepare(insertDML)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
for i := 0; i < nGenRows; i++ {
|
||||
result, err := stmt.Exec(textPrefix + Descr)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
resultDoCheck(result, Descr, i)
|
||||
}
|
||||
}
|
||||
|
||||
func resultDoCheck(result sql.Result, callerDescr string, callIndex int) {
|
||||
lastID, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
nAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
log.Printf("Exec result for %s (%d): ID = %d, affected = %d\n", callerDescr, callIndex, lastID, nAffected)
|
||||
}
|
||||
|
||||
func dbDoSelect(db *sql.DB) {
|
||||
const Descr = "DB-Query"
|
||||
|
||||
rows, err := db.Query(selectDML, noteTextPattern)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
rowsDoFetch(rows, Descr)
|
||||
}
|
||||
|
||||
func dbDoSelectPrepared(db *sql.DB) {
|
||||
const Descr = "DB-Prepare"
|
||||
|
||||
stmt, err := db.Prepare(selectDML)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
rows, err := stmt.Query(noteTextPattern)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
rowsDoFetch(rows, Descr)
|
||||
}
|
||||
|
||||
func rowsDoFetch(rows *sql.Rows, callerDescr string) {
|
||||
var nRows int
|
||||
var id int64
|
||||
var note string
|
||||
|
||||
for rows.Next() {
|
||||
err := rows.Scan(&id, ¬e)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
log.Printf("Row for %s (%d): id=%d, note=%q\n",
|
||||
callerDescr, nRows, id, note)
|
||||
nRows++
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
log.Printf("Total %d rows for %s.\n", nRows, callerDescr)
|
||||
}
|
38
vendor/github.com/mattn/go-sqlite3/_example/vtable/main.go
generated
vendored
Normal file
38
vendor/github.com/mattn/go-sqlite3/_example/vtable/main.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
sql.Register("sqlite3_with_extensions", &sqlite3.SQLiteDriver{
|
||||
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
|
||||
return conn.CreateModule("github", &githubModule{})
|
||||
},
|
||||
})
|
||||
db, err := sql.Open("sqlite3_with_extensions", ":memory:")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
_, err = db.Exec("create virtual table repo using github(id, full_name, description, html_url)")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
rows, err := db.Query("select id, full_name, description, html_url from repo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var id, fullName, description, htmlURL string
|
||||
rows.Scan(&id, &fullName, &description, &htmlURL)
|
||||
fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, fullName, description, htmlURL)
|
||||
}
|
||||
}
|
111
vendor/github.com/mattn/go-sqlite3/_example/vtable/vtable.go
generated
vendored
Normal file
111
vendor/github.com/mattn/go-sqlite3/_example/vtable/vtable.go
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
type githubRepo struct {
|
||||
ID int `json:"id"`
|
||||
FullName string `json:"full_name"`
|
||||
Description string `json:"description"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
}
|
||||
|
||||
type githubModule struct {
|
||||
}
|
||||
|
||||
func (m *githubModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
|
||||
err := c.DeclareVTab(fmt.Sprintf(`
|
||||
CREATE TABLE %s (
|
||||
id INT,
|
||||
full_name TEXT,
|
||||
description TEXT,
|
||||
html_url TEXT
|
||||
)`, args[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ghRepoTable{}, nil
|
||||
}
|
||||
|
||||
func (m *githubModule) Connect(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
|
||||
return m.Create(c, args)
|
||||
}
|
||||
|
||||
func (m *githubModule) DestroyModule() {}
|
||||
|
||||
type ghRepoTable struct {
|
||||
repos []githubRepo
|
||||
}
|
||||
|
||||
func (v *ghRepoTable) Open() (sqlite3.VTabCursor, error) {
|
||||
resp, err := http.Get("https://api.github.com/repositories")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var repos []githubRepo
|
||||
if err := json.Unmarshal(body, &repos); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ghRepoCursor{0, repos}, nil
|
||||
}
|
||||
|
||||
func (v *ghRepoTable) BestIndex(cst []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
|
||||
return &sqlite3.IndexResult{}, nil
|
||||
}
|
||||
|
||||
func (v *ghRepoTable) Disconnect() error { return nil }
|
||||
func (v *ghRepoTable) Destroy() error { return nil }
|
||||
|
||||
type ghRepoCursor struct {
|
||||
index int
|
||||
repos []githubRepo
|
||||
}
|
||||
|
||||
func (vc *ghRepoCursor) Column(c *sqlite3.SQLiteContext, col int) error {
|
||||
switch col {
|
||||
case 0:
|
||||
c.ResultInt(vc.repos[vc.index].ID)
|
||||
case 1:
|
||||
c.ResultText(vc.repos[vc.index].FullName)
|
||||
case 2:
|
||||
c.ResultText(vc.repos[vc.index].Description)
|
||||
case 3:
|
||||
c.ResultText(vc.repos[vc.index].HTMLURL)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vc *ghRepoCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
|
||||
vc.index = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vc *ghRepoCursor) Next() error {
|
||||
vc.index++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vc *ghRepoCursor) EOF() bool {
|
||||
return vc.index >= len(vc.repos)
|
||||
}
|
||||
|
||||
func (vc *ghRepoCursor) Rowid() (int64, error) {
|
||||
return int64(vc.index), nil
|
||||
}
|
||||
|
||||
func (vc *ghRepoCursor) Close() error {
|
||||
return nil
|
||||
}
|
85
vendor/github.com/mattn/go-sqlite3/backup.go
generated
vendored
Normal file
85
vendor/github.com/mattn/go-sqlite3/backup.go
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
// Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sqlite3
|
||||
|
||||
/*
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// SQLiteBackup implement interface of Backup.
|
||||
type SQLiteBackup struct {
|
||||
b *C.sqlite3_backup
|
||||
}
|
||||
|
||||
// Backup make backup from src to dest.
|
||||
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*SQLiteBackup, error) {
|
||||
destptr := C.CString(dest)
|
||||
defer C.free(unsafe.Pointer(destptr))
|
||||
srcptr := C.CString(src)
|
||||
defer C.free(unsafe.Pointer(srcptr))
|
||||
|
||||
if b := C.sqlite3_backup_init(c.db, destptr, conn.db, srcptr); b != nil {
|
||||
bb := &SQLiteBackup{b: b}
|
||||
runtime.SetFinalizer(bb, (*SQLiteBackup).Finish)
|
||||
return bb, nil
|
||||
}
|
||||
return nil, c.lastError()
|
||||
}
|
||||
|
||||
// Step to backs up for one step. Calls the underlying `sqlite3_backup_step`
|
||||
// function. This function returns a boolean indicating if the backup is done
|
||||
// and an error signalling any other error. Done is returned if the underlying
|
||||
// C function returns SQLITE_DONE (Code 101)
|
||||
func (b *SQLiteBackup) Step(p int) (bool, error) {
|
||||
ret := C.sqlite3_backup_step(b.b, C.int(p))
|
||||
if ret == C.SQLITE_DONE {
|
||||
return true, nil
|
||||
} else if ret != 0 && ret != C.SQLITE_LOCKED && ret != C.SQLITE_BUSY {
|
||||
return false, Error{Code: ErrNo(ret)}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// Remaining return whether have the rest for backup.
|
||||
func (b *SQLiteBackup) Remaining() int {
|
||||
return int(C.sqlite3_backup_remaining(b.b))
|
||||
}
|
||||
|
||||
// PageCount return count of pages.
|
||||
func (b *SQLiteBackup) PageCount() int {
|
||||
return int(C.sqlite3_backup_pagecount(b.b))
|
||||
}
|
||||
|
||||
// Finish close backup.
|
||||
func (b *SQLiteBackup) Finish() error {
|
||||
return b.Close()
|
||||
}
|
||||
|
||||
// Close close backup.
|
||||
func (b *SQLiteBackup) Close() error {
|
||||
ret := C.sqlite3_backup_finish(b.b)
|
||||
|
||||
// sqlite3_backup_finish() never fails, it just returns the
|
||||
// error code from previous operations, so clean up before
|
||||
// checking and returning an error
|
||||
b.b = nil
|
||||
runtime.SetFinalizer(b, nil)
|
||||
|
||||
if ret != 0 {
|
||||
return Error{Code: ErrNo(ret)}
|
||||
}
|
||||
return nil
|
||||
}
|
290
vendor/github.com/mattn/go-sqlite3/backup_test.go
generated
vendored
Normal file
290
vendor/github.com/mattn/go-sqlite3/backup_test.go
generated
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The number of rows of test data to create in the source database.
|
||||
// Can be used to control how many pages are available to be backed up.
|
||||
const testRowCount = 100
|
||||
|
||||
// The maximum number of seconds after which the page-by-page backup is considered to have taken too long.
|
||||
const usePagePerStepsTimeoutSeconds = 30
|
||||
|
||||
// Test the backup functionality.
|
||||
func testBackup(t *testing.T, testRowCount int, usePerPageSteps bool) {
|
||||
// This function will be called multiple times.
|
||||
// It uses sql.Register(), which requires the name parameter value to be unique.
|
||||
// There does not currently appear to be a way to unregister a registered driver, however.
|
||||
// So generate a database driver name that will likely be unique.
|
||||
var driverName = fmt.Sprintf("sqlite3_testBackup_%v_%v_%v", testRowCount, usePerPageSteps, time.Now().UnixNano())
|
||||
|
||||
// The driver's connection will be needed in order to perform the backup.
|
||||
driverConns := []*SQLiteConn{}
|
||||
sql.Register(driverName, &SQLiteDriver{
|
||||
ConnectHook: func(conn *SQLiteConn) error {
|
||||
driverConns = append(driverConns, conn)
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
// Connect to the source database.
|
||||
srcTempFilename := TempFilename(t)
|
||||
defer os.Remove(srcTempFilename)
|
||||
srcDb, err := sql.Open(driverName, srcTempFilename)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to open the source database:", err)
|
||||
}
|
||||
defer srcDb.Close()
|
||||
err = srcDb.Ping()
|
||||
if err != nil {
|
||||
t.Fatal("Failed to connect to the source database:", err)
|
||||
}
|
||||
|
||||
// Connect to the destination database.
|
||||
destTempFilename := TempFilename(t)
|
||||
defer os.Remove(destTempFilename)
|
||||
destDb, err := sql.Open(driverName, destTempFilename)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to open the destination database:", err)
|
||||
}
|
||||
defer destDb.Close()
|
||||
err = destDb.Ping()
|
||||
if err != nil {
|
||||
t.Fatal("Failed to connect to the destination database:", err)
|
||||
}
|
||||
|
||||
// Check the driver connections.
|
||||
if len(driverConns) != 2 {
|
||||
t.Fatalf("Expected 2 driver connections, but found %v.", len(driverConns))
|
||||
}
|
||||
srcDbDriverConn := driverConns[0]
|
||||
if srcDbDriverConn == nil {
|
||||
t.Fatal("The source database driver connection is nil.")
|
||||
}
|
||||
destDbDriverConn := driverConns[1]
|
||||
if destDbDriverConn == nil {
|
||||
t.Fatal("The destination database driver connection is nil.")
|
||||
}
|
||||
|
||||
// Generate some test data for the given ID.
|
||||
var generateTestData = func(id int) string {
|
||||
return fmt.Sprintf("test-%v", id)
|
||||
}
|
||||
|
||||
// Populate the source database with a test table containing some test data.
|
||||
tx, err := srcDb.Begin()
|
||||
if err != nil {
|
||||
t.Fatal("Failed to begin a transaction when populating the source database:", err)
|
||||
}
|
||||
_, err = srcDb.Exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)")
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
t.Fatal("Failed to create the source database \"test\" table:", err)
|
||||
}
|
||||
for id := 0; id < testRowCount; id++ {
|
||||
_, err = srcDb.Exec("INSERT INTO test (id, value) VALUES (?, ?)", id, generateTestData(id))
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
t.Fatal("Failed to insert a row into the source database \"test\" table:", err)
|
||||
}
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
t.Fatal("Failed to populate the source database:", err)
|
||||
}
|
||||
|
||||
// Confirm that the destination database is initially empty.
|
||||
var destTableCount int
|
||||
err = destDb.QueryRow("SELECT COUNT(*) FROM sqlite_master WHERE type = 'table'").Scan(&destTableCount)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to check the destination table count:", err)
|
||||
}
|
||||
if destTableCount != 0 {
|
||||
t.Fatalf("The destination database is not empty; %v table(s) found.", destTableCount)
|
||||
}
|
||||
|
||||
// Prepare to perform the backup.
|
||||
backup, err := destDbDriverConn.Backup("main", srcDbDriverConn, "main")
|
||||
if err != nil {
|
||||
t.Fatal("Failed to initialize the backup:", err)
|
||||
}
|
||||
|
||||
// Allow the initial page count and remaining values to be retrieved.
|
||||
// According to <https://www.sqlite.org/c3ref/backup_finish.html>, the page count and remaining values are "... only updated by sqlite3_backup_step()."
|
||||
isDone, err := backup.Step(0)
|
||||
if err != nil {
|
||||
t.Fatal("Unable to perform an initial 0-page backup step:", err)
|
||||
}
|
||||
if isDone {
|
||||
t.Fatal("Backup is unexpectedly done.")
|
||||
}
|
||||
|
||||
// Check that the page count and remaining values are reasonable.
|
||||
initialPageCount := backup.PageCount()
|
||||
if initialPageCount <= 0 {
|
||||
t.Fatalf("Unexpected initial page count value: %v", initialPageCount)
|
||||
}
|
||||
initialRemaining := backup.Remaining()
|
||||
if initialRemaining <= 0 {
|
||||
t.Fatalf("Unexpected initial remaining value: %v", initialRemaining)
|
||||
}
|
||||
if initialRemaining != initialPageCount {
|
||||
t.Fatalf("Initial remaining value differs from the initial page count value; remaining: %v; page count: %v", initialRemaining, initialPageCount)
|
||||
}
|
||||
|
||||
// Perform the backup.
|
||||
if usePerPageSteps {
|
||||
var startTime = time.Now().Unix()
|
||||
|
||||
// Test backing-up using a page-by-page approach.
|
||||
var latestRemaining = initialRemaining
|
||||
for {
|
||||
// Perform the backup step.
|
||||
isDone, err = backup.Step(1)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to perform a backup step:", err)
|
||||
}
|
||||
|
||||
// The page count should remain unchanged from its initial value.
|
||||
currentPageCount := backup.PageCount()
|
||||
if currentPageCount != initialPageCount {
|
||||
t.Fatalf("Current page count differs from the initial page count; initial page count: %v; current page count: %v", initialPageCount, currentPageCount)
|
||||
}
|
||||
|
||||
// There should now be one less page remaining.
|
||||
currentRemaining := backup.Remaining()
|
||||
expectedRemaining := latestRemaining - 1
|
||||
if currentRemaining != expectedRemaining {
|
||||
t.Fatalf("Unexpected remaining value; expected remaining value: %v; actual remaining value: %v", expectedRemaining, currentRemaining)
|
||||
}
|
||||
latestRemaining = currentRemaining
|
||||
|
||||
if isDone {
|
||||
break
|
||||
}
|
||||
|
||||
// Limit the runtime of the backup attempt.
|
||||
if (time.Now().Unix() - startTime) > usePagePerStepsTimeoutSeconds {
|
||||
t.Fatal("Backup is taking longer than expected.")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Test the copying of all remaining pages.
|
||||
isDone, err = backup.Step(-1)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to perform a backup step:", err)
|
||||
}
|
||||
if !isDone {
|
||||
t.Fatal("Backup is unexpectedly not done.")
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the page count and remaining values are reasonable.
|
||||
finalPageCount := backup.PageCount()
|
||||
if finalPageCount != initialPageCount {
|
||||
t.Fatalf("Final page count differs from the initial page count; initial page count: %v; final page count: %v", initialPageCount, finalPageCount)
|
||||
}
|
||||
finalRemaining := backup.Remaining()
|
||||
if finalRemaining != 0 {
|
||||
t.Fatalf("Unexpected remaining value: %v", finalRemaining)
|
||||
}
|
||||
|
||||
// Finish the backup.
|
||||
err = backup.Finish()
|
||||
if err != nil {
|
||||
t.Fatal("Failed to finish backup:", err)
|
||||
}
|
||||
|
||||
// Confirm that the "test" table now exists in the destination database.
|
||||
var doesTestTableExist bool
|
||||
err = destDb.QueryRow("SELECT EXISTS (SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'test' LIMIT 1) AS test_table_exists").Scan(&doesTestTableExist)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to check if the \"test\" table exists in the destination database:", err)
|
||||
}
|
||||
if !doesTestTableExist {
|
||||
t.Fatal("The \"test\" table could not be found in the destination database.")
|
||||
}
|
||||
|
||||
// Confirm that the number of rows in the destination database's "test" table matches that of the source table.
|
||||
var actualTestTableRowCount int
|
||||
err = destDb.QueryRow("SELECT COUNT(*) FROM test").Scan(&actualTestTableRowCount)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to determine the rowcount of the \"test\" table in the destination database:", err)
|
||||
}
|
||||
if testRowCount != actualTestTableRowCount {
|
||||
t.Fatalf("Unexpected destination \"test\" table row count; expected: %v; found: %v", testRowCount, actualTestTableRowCount)
|
||||
}
|
||||
|
||||
// Check each of the rows in the destination database.
|
||||
for id := 0; id < testRowCount; id++ {
|
||||
var checkedValue string
|
||||
err = destDb.QueryRow("SELECT value FROM test WHERE id = ?", id).Scan(&checkedValue)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to query the \"test\" table in the destination database:", err)
|
||||
}
|
||||
|
||||
var expectedValue = generateTestData(id)
|
||||
if checkedValue != expectedValue {
|
||||
t.Fatalf("Unexpected value in the \"test\" table in the destination database; expected value: %v; actual value: %v", expectedValue, checkedValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackupStepByStep(t *testing.T) {
|
||||
testBackup(t, testRowCount, true)
|
||||
}
|
||||
|
||||
func TestBackupAllRemainingPages(t *testing.T) {
|
||||
testBackup(t, testRowCount, false)
|
||||
}
|
||||
|
||||
// Test the error reporting when preparing to perform a backup.
|
||||
func TestBackupError(t *testing.T) {
|
||||
const driverName = "sqlite3_TestBackupError"
|
||||
|
||||
// The driver's connection will be needed in order to perform the backup.
|
||||
var dbDriverConn *SQLiteConn
|
||||
sql.Register(driverName, &SQLiteDriver{
|
||||
ConnectHook: func(conn *SQLiteConn) error {
|
||||
dbDriverConn = conn
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
// Connect to the database.
|
||||
dbTempFilename := TempFilename(t)
|
||||
defer os.Remove(dbTempFilename)
|
||||
db, err := sql.Open(driverName, dbTempFilename)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to open the database:", err)
|
||||
}
|
||||
defer db.Close()
|
||||
db.Ping()
|
||||
|
||||
// Need the driver connection in order to perform the backup.
|
||||
if dbDriverConn == nil {
|
||||
t.Fatal("Failed to get the driver connection.")
|
||||
}
|
||||
|
||||
// Prepare to perform the backup.
|
||||
// Intentionally using the same connection for both the source and destination databases, to trigger an error result.
|
||||
backup, err := dbDriverConn.Backup("main", dbDriverConn, "main")
|
||||
if err == nil {
|
||||
t.Fatal("Failed to get the expected error result.")
|
||||
}
|
||||
const expectedError = "source and destination must be distinct"
|
||||
if err.Error() != expectedError {
|
||||
t.Fatalf("Unexpected error message; expected value: \"%v\"; actual value: \"%v\"", expectedError, err.Error())
|
||||
}
|
||||
if backup != nil {
|
||||
t.Fatal("Failed to get the expected nil backup result.")
|
||||
}
|
||||
}
|
340
vendor/github.com/mattn/go-sqlite3/callback.go
generated
vendored
Normal file
340
vendor/github.com/mattn/go-sqlite3/callback.go
generated
vendored
Normal file
@@ -0,0 +1,340 @@
|
||||
// Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sqlite3
|
||||
|
||||
// You can't export a Go function to C and have definitions in the C
|
||||
// preamble in the same file, so we have to have callbackTrampoline in
|
||||
// its own file. Because we need a separate file anyway, the support
|
||||
// code for SQLite custom functions is in here.
|
||||
|
||||
/*
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
void _sqlite3_result_text(sqlite3_context* ctx, const char* s);
|
||||
void _sqlite3_result_blob(sqlite3_context* ctx, const void* b, int l);
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"sync"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
//export callbackTrampoline
|
||||
func callbackTrampoline(ctx *C.sqlite3_context, argc int, argv **C.sqlite3_value) {
|
||||
args := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.sqlite3_value)(nil))]*C.sqlite3_value)(unsafe.Pointer(argv))[:argc:argc]
|
||||
fi := lookupHandle(uintptr(C.sqlite3_user_data(ctx))).(*functionInfo)
|
||||
fi.Call(ctx, args)
|
||||
}
|
||||
|
||||
//export stepTrampoline
|
||||
func stepTrampoline(ctx *C.sqlite3_context, argc C.int, argv **C.sqlite3_value) {
|
||||
args := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.sqlite3_value)(nil))]*C.sqlite3_value)(unsafe.Pointer(argv))[:int(argc):int(argc)]
|
||||
ai := lookupHandle(uintptr(C.sqlite3_user_data(ctx))).(*aggInfo)
|
||||
ai.Step(ctx, args)
|
||||
}
|
||||
|
||||
//export doneTrampoline
|
||||
func doneTrampoline(ctx *C.sqlite3_context) {
|
||||
handle := uintptr(C.sqlite3_user_data(ctx))
|
||||
ai := lookupHandle(handle).(*aggInfo)
|
||||
ai.Done(ctx)
|
||||
}
|
||||
|
||||
// Use handles to avoid passing Go pointers to C.
|
||||
|
||||
type handleVal struct {
|
||||
db *SQLiteConn
|
||||
val interface{}
|
||||
}
|
||||
|
||||
var handleLock sync.Mutex
|
||||
var handleVals = make(map[uintptr]handleVal)
|
||||
var handleIndex uintptr = 100
|
||||
|
||||
func newHandle(db *SQLiteConn, v interface{}) uintptr {
|
||||
handleLock.Lock()
|
||||
defer handleLock.Unlock()
|
||||
i := handleIndex
|
||||
handleIndex++
|
||||
handleVals[i] = handleVal{db, v}
|
||||
return i
|
||||
}
|
||||
|
||||
func lookupHandle(handle uintptr) interface{} {
|
||||
handleLock.Lock()
|
||||
defer handleLock.Unlock()
|
||||
r, ok := handleVals[handle]
|
||||
if !ok {
|
||||
if handle >= 100 && handle < handleIndex {
|
||||
panic("deleted handle")
|
||||
} else {
|
||||
panic("invalid handle")
|
||||
}
|
||||
}
|
||||
return r.val
|
||||
}
|
||||
|
||||
func deleteHandles(db *SQLiteConn) {
|
||||
handleLock.Lock()
|
||||
defer handleLock.Unlock()
|
||||
for handle, val := range handleVals {
|
||||
if val.db == db {
|
||||
delete(handleVals, handle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is only here so that tests can refer to it.
|
||||
type callbackArgRaw C.sqlite3_value
|
||||
|
||||
type callbackArgConverter func(*C.sqlite3_value) (reflect.Value, error)
|
||||
|
||||
type callbackArgCast struct {
|
||||
f callbackArgConverter
|
||||
typ reflect.Type
|
||||
}
|
||||
|
||||
func (c callbackArgCast) Run(v *C.sqlite3_value) (reflect.Value, error) {
|
||||
val, err := c.f(v)
|
||||
if err != nil {
|
||||
return reflect.Value{}, err
|
||||
}
|
||||
if !val.Type().ConvertibleTo(c.typ) {
|
||||
return reflect.Value{}, fmt.Errorf("cannot convert %s to %s", val.Type(), c.typ)
|
||||
}
|
||||
return val.Convert(c.typ), nil
|
||||
}
|
||||
|
||||
func callbackArgInt64(v *C.sqlite3_value) (reflect.Value, error) {
|
||||
if C.sqlite3_value_type(v) != C.SQLITE_INTEGER {
|
||||
return reflect.Value{}, fmt.Errorf("argument must be an INTEGER")
|
||||
}
|
||||
return reflect.ValueOf(int64(C.sqlite3_value_int64(v))), nil
|
||||
}
|
||||
|
||||
func callbackArgBool(v *C.sqlite3_value) (reflect.Value, error) {
|
||||
if C.sqlite3_value_type(v) != C.SQLITE_INTEGER {
|
||||
return reflect.Value{}, fmt.Errorf("argument must be an INTEGER")
|
||||
}
|
||||
i := int64(C.sqlite3_value_int64(v))
|
||||
val := false
|
||||
if i != 0 {
|
||||
val = true
|
||||
}
|
||||
return reflect.ValueOf(val), nil
|
||||
}
|
||||
|
||||
func callbackArgFloat64(v *C.sqlite3_value) (reflect.Value, error) {
|
||||
if C.sqlite3_value_type(v) != C.SQLITE_FLOAT {
|
||||
return reflect.Value{}, fmt.Errorf("argument must be a FLOAT")
|
||||
}
|
||||
return reflect.ValueOf(float64(C.sqlite3_value_double(v))), nil
|
||||
}
|
||||
|
||||
func callbackArgBytes(v *C.sqlite3_value) (reflect.Value, error) {
|
||||
switch C.sqlite3_value_type(v) {
|
||||
case C.SQLITE_BLOB:
|
||||
l := C.sqlite3_value_bytes(v)
|
||||
p := C.sqlite3_value_blob(v)
|
||||
return reflect.ValueOf(C.GoBytes(p, l)), nil
|
||||
case C.SQLITE_TEXT:
|
||||
l := C.sqlite3_value_bytes(v)
|
||||
c := unsafe.Pointer(C.sqlite3_value_text(v))
|
||||
return reflect.ValueOf(C.GoBytes(c, l)), nil
|
||||
default:
|
||||
return reflect.Value{}, fmt.Errorf("argument must be BLOB or TEXT")
|
||||
}
|
||||
}
|
||||
|
||||
func callbackArgString(v *C.sqlite3_value) (reflect.Value, error) {
|
||||
switch C.sqlite3_value_type(v) {
|
||||
case C.SQLITE_BLOB:
|
||||
l := C.sqlite3_value_bytes(v)
|
||||
p := (*C.char)(C.sqlite3_value_blob(v))
|
||||
return reflect.ValueOf(C.GoStringN(p, l)), nil
|
||||
case C.SQLITE_TEXT:
|
||||
c := (*C.char)(unsafe.Pointer(C.sqlite3_value_text(v)))
|
||||
return reflect.ValueOf(C.GoString(c)), nil
|
||||
default:
|
||||
return reflect.Value{}, fmt.Errorf("argument must be BLOB or TEXT")
|
||||
}
|
||||
}
|
||||
|
||||
func callbackArgGeneric(v *C.sqlite3_value) (reflect.Value, error) {
|
||||
switch C.sqlite3_value_type(v) {
|
||||
case C.SQLITE_INTEGER:
|
||||
return callbackArgInt64(v)
|
||||
case C.SQLITE_FLOAT:
|
||||
return callbackArgFloat64(v)
|
||||
case C.SQLITE_TEXT:
|
||||
return callbackArgString(v)
|
||||
case C.SQLITE_BLOB:
|
||||
return callbackArgBytes(v)
|
||||
case C.SQLITE_NULL:
|
||||
// Interpret NULL as a nil byte slice.
|
||||
var ret []byte
|
||||
return reflect.ValueOf(ret), nil
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
}
|
||||
|
||||
func callbackArg(typ reflect.Type) (callbackArgConverter, error) {
|
||||
switch typ.Kind() {
|
||||
case reflect.Interface:
|
||||
if typ.NumMethod() != 0 {
|
||||
return nil, errors.New("the only supported interface type is interface{}")
|
||||
}
|
||||
return callbackArgGeneric, nil
|
||||
case reflect.Slice:
|
||||
if typ.Elem().Kind() != reflect.Uint8 {
|
||||
return nil, errors.New("the only supported slice type is []byte")
|
||||
}
|
||||
return callbackArgBytes, nil
|
||||
case reflect.String:
|
||||
return callbackArgString, nil
|
||||
case reflect.Bool:
|
||||
return callbackArgBool, nil
|
||||
case reflect.Int64:
|
||||
return callbackArgInt64, nil
|
||||
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Int, reflect.Uint:
|
||||
c := callbackArgCast{callbackArgInt64, typ}
|
||||
return c.Run, nil
|
||||
case reflect.Float64:
|
||||
return callbackArgFloat64, nil
|
||||
case reflect.Float32:
|
||||
c := callbackArgCast{callbackArgFloat64, typ}
|
||||
return c.Run, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("don't know how to convert to %s", typ)
|
||||
}
|
||||
}
|
||||
|
||||
func callbackConvertArgs(argv []*C.sqlite3_value, converters []callbackArgConverter, variadic callbackArgConverter) ([]reflect.Value, error) {
|
||||
var args []reflect.Value
|
||||
|
||||
if len(argv) < len(converters) {
|
||||
return nil, fmt.Errorf("function requires at least %d arguments", len(converters))
|
||||
}
|
||||
|
||||
for i, arg := range argv[:len(converters)] {
|
||||
v, err := converters[i](arg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args = append(args, v)
|
||||
}
|
||||
|
||||
if variadic != nil {
|
||||
for _, arg := range argv[len(converters):] {
|
||||
v, err := variadic(arg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args = append(args, v)
|
||||
}
|
||||
}
|
||||
return args, nil
|
||||
}
|
||||
|
||||
type callbackRetConverter func(*C.sqlite3_context, reflect.Value) error
|
||||
|
||||
func callbackRetInteger(ctx *C.sqlite3_context, v reflect.Value) error {
|
||||
switch v.Type().Kind() {
|
||||
case reflect.Int64:
|
||||
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Int, reflect.Uint:
|
||||
v = v.Convert(reflect.TypeOf(int64(0)))
|
||||
case reflect.Bool:
|
||||
b := v.Interface().(bool)
|
||||
if b {
|
||||
v = reflect.ValueOf(int64(1))
|
||||
} else {
|
||||
v = reflect.ValueOf(int64(0))
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("cannot convert %s to INTEGER", v.Type())
|
||||
}
|
||||
|
||||
C.sqlite3_result_int64(ctx, C.sqlite3_int64(v.Interface().(int64)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func callbackRetFloat(ctx *C.sqlite3_context, v reflect.Value) error {
|
||||
switch v.Type().Kind() {
|
||||
case reflect.Float64:
|
||||
case reflect.Float32:
|
||||
v = v.Convert(reflect.TypeOf(float64(0)))
|
||||
default:
|
||||
return fmt.Errorf("cannot convert %s to FLOAT", v.Type())
|
||||
}
|
||||
|
||||
C.sqlite3_result_double(ctx, C.double(v.Interface().(float64)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func callbackRetBlob(ctx *C.sqlite3_context, v reflect.Value) error {
|
||||
if v.Type().Kind() != reflect.Slice || v.Type().Elem().Kind() != reflect.Uint8 {
|
||||
return fmt.Errorf("cannot convert %s to BLOB", v.Type())
|
||||
}
|
||||
i := v.Interface()
|
||||
if i == nil || len(i.([]byte)) == 0 {
|
||||
C.sqlite3_result_null(ctx)
|
||||
} else {
|
||||
bs := i.([]byte)
|
||||
C._sqlite3_result_blob(ctx, unsafe.Pointer(&bs[0]), C.int(len(bs)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func callbackRetText(ctx *C.sqlite3_context, v reflect.Value) error {
|
||||
if v.Type().Kind() != reflect.String {
|
||||
return fmt.Errorf("cannot convert %s to TEXT", v.Type())
|
||||
}
|
||||
C._sqlite3_result_text(ctx, C.CString(v.Interface().(string)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func callbackRet(typ reflect.Type) (callbackRetConverter, error) {
|
||||
switch typ.Kind() {
|
||||
case reflect.Slice:
|
||||
if typ.Elem().Kind() != reflect.Uint8 {
|
||||
return nil, errors.New("the only supported slice type is []byte")
|
||||
}
|
||||
return callbackRetBlob, nil
|
||||
case reflect.String:
|
||||
return callbackRetText, nil
|
||||
case reflect.Bool, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Int, reflect.Uint:
|
||||
return callbackRetInteger, nil
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return callbackRetFloat, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("don't know how to convert to %s", typ)
|
||||
}
|
||||
}
|
||||
|
||||
func callbackError(ctx *C.sqlite3_context, err error) {
|
||||
cstr := C.CString(err.Error())
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
C.sqlite3_result_error(ctx, cstr, -1)
|
||||
}
|
||||
|
||||
// Test support code. Tests are not allowed to import "C", so we can't
|
||||
// declare any functions that use C.sqlite3_value.
|
||||
func callbackSyntheticForTests(v reflect.Value, err error) callbackArgConverter {
|
||||
return func(*C.sqlite3_value) (reflect.Value, error) {
|
||||
return v, err
|
||||
}
|
||||
}
|
97
vendor/github.com/mattn/go-sqlite3/callback_test.go
generated
vendored
Normal file
97
vendor/github.com/mattn/go-sqlite3/callback_test.go
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCallbackArgCast(t *testing.T) {
|
||||
intConv := callbackSyntheticForTests(reflect.ValueOf(int64(math.MaxInt64)), nil)
|
||||
floatConv := callbackSyntheticForTests(reflect.ValueOf(float64(math.MaxFloat64)), nil)
|
||||
errConv := callbackSyntheticForTests(reflect.Value{}, errors.New("test"))
|
||||
|
||||
tests := []struct {
|
||||
f callbackArgConverter
|
||||
o reflect.Value
|
||||
}{
|
||||
{intConv, reflect.ValueOf(int8(-1))},
|
||||
{intConv, reflect.ValueOf(int16(-1))},
|
||||
{intConv, reflect.ValueOf(int32(-1))},
|
||||
{intConv, reflect.ValueOf(uint8(math.MaxUint8))},
|
||||
{intConv, reflect.ValueOf(uint16(math.MaxUint16))},
|
||||
{intConv, reflect.ValueOf(uint32(math.MaxUint32))},
|
||||
// Special case, int64->uint64 is only 1<<63 - 1, not 1<<64 - 1
|
||||
{intConv, reflect.ValueOf(uint64(math.MaxInt64))},
|
||||
{floatConv, reflect.ValueOf(float32(math.Inf(1)))},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
conv := callbackArgCast{test.f, test.o.Type()}
|
||||
val, err := conv.Run(nil)
|
||||
if err != nil {
|
||||
t.Errorf("Couldn't convert to %s: %s", test.o.Type(), err)
|
||||
} else if !reflect.DeepEqual(val.Interface(), test.o.Interface()) {
|
||||
t.Errorf("Unexpected result from converting to %s: got %v, want %v", test.o.Type(), val.Interface(), test.o.Interface())
|
||||
}
|
||||
}
|
||||
|
||||
conv := callbackArgCast{errConv, reflect.TypeOf(int8(0))}
|
||||
_, err := conv.Run(nil)
|
||||
if err == nil {
|
||||
t.Errorf("Expected error during callbackArgCast, but got none")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallbackConverters(t *testing.T) {
|
||||
tests := []struct {
|
||||
v interface{}
|
||||
err bool
|
||||
}{
|
||||
// Unfortunately, we can't tell which converter was returned,
|
||||
// but we can at least check which types can be converted.
|
||||
{[]byte{0}, false},
|
||||
{"text", false},
|
||||
{true, false},
|
||||
{int8(0), false},
|
||||
{int16(0), false},
|
||||
{int32(0), false},
|
||||
{int64(0), false},
|
||||
{uint8(0), false},
|
||||
{uint16(0), false},
|
||||
{uint32(0), false},
|
||||
{uint64(0), false},
|
||||
{int(0), false},
|
||||
{uint(0), false},
|
||||
{float64(0), false},
|
||||
{float32(0), false},
|
||||
|
||||
{func() {}, true},
|
||||
{complex64(complex(0, 0)), true},
|
||||
{complex128(complex(0, 0)), true},
|
||||
{struct{}{}, true},
|
||||
{map[string]string{}, true},
|
||||
{[]string{}, true},
|
||||
{(*int8)(nil), true},
|
||||
{make(chan int), true},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
_, err := callbackArg(reflect.TypeOf(test.v))
|
||||
if test.err && err == nil {
|
||||
t.Errorf("Expected an error when converting %s, got no error", reflect.TypeOf(test.v))
|
||||
} else if !test.err && err != nil {
|
||||
t.Errorf("Expected converter when converting %s, got error: %s", reflect.TypeOf(test.v), err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
_, err := callbackRet(reflect.TypeOf(test.v))
|
||||
if test.err && err == nil {
|
||||
t.Errorf("Expected an error when converting %s, got no error", reflect.TypeOf(test.v))
|
||||
} else if !test.err && err != nil {
|
||||
t.Errorf("Expected converter when converting %s, got error: %s", reflect.TypeOf(test.v), err)
|
||||
}
|
||||
}
|
||||
}
|
112
vendor/github.com/mattn/go-sqlite3/doc.go
generated
vendored
Normal file
112
vendor/github.com/mattn/go-sqlite3/doc.go
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
Package sqlite3 provides interface to SQLite3 databases.
|
||||
|
||||
This works as a driver for database/sql.
|
||||
|
||||
Installation
|
||||
|
||||
go get github.com/mattn/go-sqlite3
|
||||
|
||||
Supported Types
|
||||
|
||||
Currently, go-sqlite3 supports the following data types.
|
||||
|
||||
+------------------------------+
|
||||
|go | sqlite3 |
|
||||
|----------|-------------------|
|
||||
|nil | null |
|
||||
|int | integer |
|
||||
|int64 | integer |
|
||||
|float64 | float |
|
||||
|bool | integer |
|
||||
|[]byte | blob |
|
||||
|string | text |
|
||||
|time.Time | timestamp/datetime|
|
||||
+------------------------------+
|
||||
|
||||
SQLite3 Extension
|
||||
|
||||
You can write your own extension module for sqlite3. For example, below is an
|
||||
extension for a Regexp matcher operation.
|
||||
|
||||
#include <pcre.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sqlite3ext.h>
|
||||
|
||||
SQLITE_EXTENSION_INIT1
|
||||
static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) {
|
||||
if (argc >= 2) {
|
||||
const char *target = (const char *)sqlite3_value_text(argv[1]);
|
||||
const char *pattern = (const char *)sqlite3_value_text(argv[0]);
|
||||
const char* errstr = NULL;
|
||||
int erroff = 0;
|
||||
int vec[500];
|
||||
int n, rc;
|
||||
pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL);
|
||||
rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
|
||||
if (rc <= 0) {
|
||||
sqlite3_result_error(context, errstr, 0);
|
||||
return;
|
||||
}
|
||||
sqlite3_result_int(context, 1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_extension_init(sqlite3 *db, char **errmsg,
|
||||
const sqlite3_api_routines *api) {
|
||||
SQLITE_EXTENSION_INIT2(api);
|
||||
return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8,
|
||||
(void*)db, regexp_func, NULL, NULL);
|
||||
}
|
||||
|
||||
It needs to be built as a so/dll shared library. And you need to register
|
||||
the extension module like below.
|
||||
|
||||
sql.Register("sqlite3_with_extensions",
|
||||
&sqlite3.SQLiteDriver{
|
||||
Extensions: []string{
|
||||
"sqlite3_mod_regexp",
|
||||
},
|
||||
})
|
||||
|
||||
Then, you can use this extension.
|
||||
|
||||
rows, err := db.Query("select text from mytable where name regexp '^golang'")
|
||||
|
||||
Connection Hook
|
||||
|
||||
You can hook and inject your code when the connection is established. database/sql
|
||||
doesn't provide a way to get native go-sqlite3 interfaces. So if you want,
|
||||
you need to set ConnectHook and get the SQLiteConn.
|
||||
|
||||
sql.Register("sqlite3_with_hook_example",
|
||||
&sqlite3.SQLiteDriver{
|
||||
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
|
||||
sqlite3conn = append(sqlite3conn, conn)
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
Go SQlite3 Extensions
|
||||
|
||||
If you want to register Go functions as SQLite extension functions,
|
||||
call RegisterFunction from ConnectHook.
|
||||
|
||||
regex = func(re, s string) (bool, error) {
|
||||
return regexp.MatchString(re, s)
|
||||
}
|
||||
sql.Register("sqlite3_with_go_func",
|
||||
&sqlite3.SQLiteDriver{
|
||||
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
|
||||
return conn.RegisterFunc("regexp", regex, true)
|
||||
},
|
||||
})
|
||||
|
||||
See the documentation of RegisterFunc for more details.
|
||||
|
||||
*/
|
||||
package sqlite3
|
135
vendor/github.com/mattn/go-sqlite3/error.go
generated
vendored
Normal file
135
vendor/github.com/mattn/go-sqlite3/error.go
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
// Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import "C"
|
||||
|
||||
// ErrNo inherit errno.
|
||||
type ErrNo int
|
||||
|
||||
// ErrNoMask is mask code.
|
||||
const ErrNoMask C.int = 0xff
|
||||
|
||||
// ErrNoExtended is extended errno.
|
||||
type ErrNoExtended int
|
||||
|
||||
// Error implement sqlite error code.
|
||||
type Error struct {
|
||||
Code ErrNo /* The error code returned by SQLite */
|
||||
ExtendedCode ErrNoExtended /* The extended error code returned by SQLite */
|
||||
err string /* The error string returned by sqlite3_errmsg(),
|
||||
this usually contains more specific details. */
|
||||
}
|
||||
|
||||
// result codes from http://www.sqlite.org/c3ref/c_abort.html
|
||||
var (
|
||||
ErrError = ErrNo(1) /* SQL error or missing database */
|
||||
ErrInternal = ErrNo(2) /* Internal logic error in SQLite */
|
||||
ErrPerm = ErrNo(3) /* Access permission denied */
|
||||
ErrAbort = ErrNo(4) /* Callback routine requested an abort */
|
||||
ErrBusy = ErrNo(5) /* The database file is locked */
|
||||
ErrLocked = ErrNo(6) /* A table in the database is locked */
|
||||
ErrNomem = ErrNo(7) /* A malloc() failed */
|
||||
ErrReadonly = ErrNo(8) /* Attempt to write a readonly database */
|
||||
ErrInterrupt = ErrNo(9) /* Operation terminated by sqlite3_interrupt() */
|
||||
ErrIoErr = ErrNo(10) /* Some kind of disk I/O error occurred */
|
||||
ErrCorrupt = ErrNo(11) /* The database disk image is malformed */
|
||||
ErrNotFound = ErrNo(12) /* Unknown opcode in sqlite3_file_control() */
|
||||
ErrFull = ErrNo(13) /* Insertion failed because database is full */
|
||||
ErrCantOpen = ErrNo(14) /* Unable to open the database file */
|
||||
ErrProtocol = ErrNo(15) /* Database lock protocol error */
|
||||
ErrEmpty = ErrNo(16) /* Database is empty */
|
||||
ErrSchema = ErrNo(17) /* The database schema changed */
|
||||
ErrTooBig = ErrNo(18) /* String or BLOB exceeds size limit */
|
||||
ErrConstraint = ErrNo(19) /* Abort due to constraint violation */
|
||||
ErrMismatch = ErrNo(20) /* Data type mismatch */
|
||||
ErrMisuse = ErrNo(21) /* Library used incorrectly */
|
||||
ErrNoLFS = ErrNo(22) /* Uses OS features not supported on host */
|
||||
ErrAuth = ErrNo(23) /* Authorization denied */
|
||||
ErrFormat = ErrNo(24) /* Auxiliary database format error */
|
||||
ErrRange = ErrNo(25) /* 2nd parameter to sqlite3_bind out of range */
|
||||
ErrNotADB = ErrNo(26) /* File opened that is not a database file */
|
||||
ErrNotice = ErrNo(27) /* Notifications from sqlite3_log() */
|
||||
ErrWarning = ErrNo(28) /* Warnings from sqlite3_log() */
|
||||
)
|
||||
|
||||
// Error return error message from errno.
|
||||
func (err ErrNo) Error() string {
|
||||
return Error{Code: err}.Error()
|
||||
}
|
||||
|
||||
// Extend return extended errno.
|
||||
func (err ErrNo) Extend(by int) ErrNoExtended {
|
||||
return ErrNoExtended(int(err) | (by << 8))
|
||||
}
|
||||
|
||||
// Error return error message that is extended code.
|
||||
func (err ErrNoExtended) Error() string {
|
||||
return Error{Code: ErrNo(C.int(err) & ErrNoMask), ExtendedCode: err}.Error()
|
||||
}
|
||||
|
||||
func (err Error) Error() string {
|
||||
if err.err != "" {
|
||||
return err.err
|
||||
}
|
||||
return errorString(err)
|
||||
}
|
||||
|
||||
// result codes from http://www.sqlite.org/c3ref/c_abort_rollback.html
|
||||
var (
|
||||
ErrIoErrRead = ErrIoErr.Extend(1)
|
||||
ErrIoErrShortRead = ErrIoErr.Extend(2)
|
||||
ErrIoErrWrite = ErrIoErr.Extend(3)
|
||||
ErrIoErrFsync = ErrIoErr.Extend(4)
|
||||
ErrIoErrDirFsync = ErrIoErr.Extend(5)
|
||||
ErrIoErrTruncate = ErrIoErr.Extend(6)
|
||||
ErrIoErrFstat = ErrIoErr.Extend(7)
|
||||
ErrIoErrUnlock = ErrIoErr.Extend(8)
|
||||
ErrIoErrRDlock = ErrIoErr.Extend(9)
|
||||
ErrIoErrDelete = ErrIoErr.Extend(10)
|
||||
ErrIoErrBlocked = ErrIoErr.Extend(11)
|
||||
ErrIoErrNoMem = ErrIoErr.Extend(12)
|
||||
ErrIoErrAccess = ErrIoErr.Extend(13)
|
||||
ErrIoErrCheckReservedLock = ErrIoErr.Extend(14)
|
||||
ErrIoErrLock = ErrIoErr.Extend(15)
|
||||
ErrIoErrClose = ErrIoErr.Extend(16)
|
||||
ErrIoErrDirClose = ErrIoErr.Extend(17)
|
||||
ErrIoErrSHMOpen = ErrIoErr.Extend(18)
|
||||
ErrIoErrSHMSize = ErrIoErr.Extend(19)
|
||||
ErrIoErrSHMLock = ErrIoErr.Extend(20)
|
||||
ErrIoErrSHMMap = ErrIoErr.Extend(21)
|
||||
ErrIoErrSeek = ErrIoErr.Extend(22)
|
||||
ErrIoErrDeleteNoent = ErrIoErr.Extend(23)
|
||||
ErrIoErrMMap = ErrIoErr.Extend(24)
|
||||
ErrIoErrGetTempPath = ErrIoErr.Extend(25)
|
||||
ErrIoErrConvPath = ErrIoErr.Extend(26)
|
||||
ErrLockedSharedCache = ErrLocked.Extend(1)
|
||||
ErrBusyRecovery = ErrBusy.Extend(1)
|
||||
ErrBusySnapshot = ErrBusy.Extend(2)
|
||||
ErrCantOpenNoTempDir = ErrCantOpen.Extend(1)
|
||||
ErrCantOpenIsDir = ErrCantOpen.Extend(2)
|
||||
ErrCantOpenFullPath = ErrCantOpen.Extend(3)
|
||||
ErrCantOpenConvPath = ErrCantOpen.Extend(4)
|
||||
ErrCorruptVTab = ErrCorrupt.Extend(1)
|
||||
ErrReadonlyRecovery = ErrReadonly.Extend(1)
|
||||
ErrReadonlyCantLock = ErrReadonly.Extend(2)
|
||||
ErrReadonlyRollback = ErrReadonly.Extend(3)
|
||||
ErrReadonlyDbMoved = ErrReadonly.Extend(4)
|
||||
ErrAbortRollback = ErrAbort.Extend(2)
|
||||
ErrConstraintCheck = ErrConstraint.Extend(1)
|
||||
ErrConstraintCommitHook = ErrConstraint.Extend(2)
|
||||
ErrConstraintForeignKey = ErrConstraint.Extend(3)
|
||||
ErrConstraintFunction = ErrConstraint.Extend(4)
|
||||
ErrConstraintNotNull = ErrConstraint.Extend(5)
|
||||
ErrConstraintPrimaryKey = ErrConstraint.Extend(6)
|
||||
ErrConstraintTrigger = ErrConstraint.Extend(7)
|
||||
ErrConstraintUnique = ErrConstraint.Extend(8)
|
||||
ErrConstraintVTab = ErrConstraint.Extend(9)
|
||||
ErrConstraintRowID = ErrConstraint.Extend(10)
|
||||
ErrNoticeRecoverWAL = ErrNotice.Extend(1)
|
||||
ErrNoticeRecoverRollback = ErrNotice.Extend(2)
|
||||
ErrWarningAutoIndex = ErrWarning.Extend(1)
|
||||
)
|
242
vendor/github.com/mattn/go-sqlite3/error_test.go
generated
vendored
Normal file
242
vendor/github.com/mattn/go-sqlite3/error_test.go
generated
vendored
Normal file
@@ -0,0 +1,242 @@
|
||||
// Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSimpleError(t *testing.T) {
|
||||
e := ErrError.Error()
|
||||
if e != "SQL logic error or missing database" {
|
||||
t.Error("wrong error code:" + e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCorruptDbErrors(t *testing.T) {
|
||||
dirName, err := ioutil.TempDir("", "sqlite3")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dirName)
|
||||
|
||||
dbFileName := path.Join(dirName, "test.db")
|
||||
f, err := os.Create(dbFileName)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
f.Write([]byte{1, 2, 3, 4, 5})
|
||||
f.Close()
|
||||
|
||||
db, err := sql.Open("sqlite3", dbFileName)
|
||||
if err == nil {
|
||||
_, err = db.Exec("drop table foo")
|
||||
}
|
||||
|
||||
sqliteErr := err.(Error)
|
||||
if sqliteErr.Code != ErrNotADB {
|
||||
t.Error("wrong error code for corrupted DB")
|
||||
}
|
||||
if err.Error() == "" {
|
||||
t.Error("wrong error string for corrupted DB")
|
||||
}
|
||||
db.Close()
|
||||
}
|
||||
|
||||
func TestSqlLogicErrors(t *testing.T) {
|
||||
dirName, err := ioutil.TempDir("", "sqlite3")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dirName)
|
||||
|
||||
dbFileName := path.Join(dirName, "test.db")
|
||||
db, err := sql.Open("sqlite3", dbFileName)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
_, err = db.Exec("CREATE TABLE Foo (id INTEGER PRIMARY KEY)")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
const expectedErr = "table Foo already exists"
|
||||
_, err = db.Exec("CREATE TABLE Foo (id INTEGER PRIMARY KEY)")
|
||||
if err.Error() != expectedErr {
|
||||
t.Errorf("Unexpected error: %s, expected %s", err.Error(), expectedErr)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestExtendedErrorCodes_ForeignKey(t *testing.T) {
|
||||
dirName, err := ioutil.TempDir("", "sqlite3-err")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dirName)
|
||||
|
||||
dbFileName := path.Join(dirName, "test.db")
|
||||
db, err := sql.Open("sqlite3", dbFileName)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
_, err = db.Exec("PRAGMA foreign_keys=ON;")
|
||||
if err != nil {
|
||||
t.Errorf("PRAGMA foreign_keys=ON: %v", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec(`CREATE TABLE Foo (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
value INTEGER NOT NULL,
|
||||
ref INTEGER NULL REFERENCES Foo (id),
|
||||
UNIQUE(value)
|
||||
);`)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("INSERT INTO Foo (ref, value) VALUES (100, 100);")
|
||||
if err == nil {
|
||||
t.Error("No error!")
|
||||
} else {
|
||||
sqliteErr := err.(Error)
|
||||
if sqliteErr.Code != ErrConstraint {
|
||||
t.Errorf("Wrong basic error code: %d != %d",
|
||||
sqliteErr.Code, ErrConstraint)
|
||||
}
|
||||
if sqliteErr.ExtendedCode != ErrConstraintForeignKey {
|
||||
t.Errorf("Wrong extended error code: %d != %d",
|
||||
sqliteErr.ExtendedCode, ErrConstraintForeignKey)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestExtendedErrorCodes_NotNull(t *testing.T) {
|
||||
dirName, err := ioutil.TempDir("", "sqlite3-err")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dirName)
|
||||
|
||||
dbFileName := path.Join(dirName, "test.db")
|
||||
db, err := sql.Open("sqlite3", dbFileName)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
_, err = db.Exec("PRAGMA foreign_keys=ON;")
|
||||
if err != nil {
|
||||
t.Errorf("PRAGMA foreign_keys=ON: %v", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec(`CREATE TABLE Foo (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
value INTEGER NOT NULL,
|
||||
ref INTEGER NULL REFERENCES Foo (id),
|
||||
UNIQUE(value)
|
||||
);`)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
res, err := db.Exec("INSERT INTO Foo (value) VALUES (100);")
|
||||
if err != nil {
|
||||
t.Fatalf("Creating first row: %v", err)
|
||||
}
|
||||
|
||||
id, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving last insert id: %v", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("INSERT INTO Foo (ref) VALUES (?);", id)
|
||||
if err == nil {
|
||||
t.Error("No error!")
|
||||
} else {
|
||||
sqliteErr := err.(Error)
|
||||
if sqliteErr.Code != ErrConstraint {
|
||||
t.Errorf("Wrong basic error code: %d != %d",
|
||||
sqliteErr.Code, ErrConstraint)
|
||||
}
|
||||
if sqliteErr.ExtendedCode != ErrConstraintNotNull {
|
||||
t.Errorf("Wrong extended error code: %d != %d",
|
||||
sqliteErr.ExtendedCode, ErrConstraintNotNull)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestExtendedErrorCodes_Unique(t *testing.T) {
|
||||
dirName, err := ioutil.TempDir("", "sqlite3-err")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dirName)
|
||||
|
||||
dbFileName := path.Join(dirName, "test.db")
|
||||
db, err := sql.Open("sqlite3", dbFileName)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
_, err = db.Exec("PRAGMA foreign_keys=ON;")
|
||||
if err != nil {
|
||||
t.Errorf("PRAGMA foreign_keys=ON: %v", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec(`CREATE TABLE Foo (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
value INTEGER NOT NULL,
|
||||
ref INTEGER NULL REFERENCES Foo (id),
|
||||
UNIQUE(value)
|
||||
);`)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
res, err := db.Exec("INSERT INTO Foo (value) VALUES (100);")
|
||||
if err != nil {
|
||||
t.Fatalf("Creating first row: %v", err)
|
||||
}
|
||||
|
||||
id, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
t.Fatalf("Retrieving last insert id: %v", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("INSERT INTO Foo (ref, value) VALUES (?, 100);", id)
|
||||
if err == nil {
|
||||
t.Error("No error!")
|
||||
} else {
|
||||
sqliteErr := err.(Error)
|
||||
if sqliteErr.Code != ErrConstraint {
|
||||
t.Errorf("Wrong basic error code: %d != %d",
|
||||
sqliteErr.Code, ErrConstraint)
|
||||
}
|
||||
if sqliteErr.ExtendedCode != ErrConstraintUnique {
|
||||
t.Errorf("Wrong extended error code: %d != %d",
|
||||
sqliteErr.ExtendedCode, ErrConstraintUnique)
|
||||
}
|
||||
extended := sqliteErr.Code.Extend(3).Error()
|
||||
expected := "constraint failed"
|
||||
if extended != expected {
|
||||
t.Errorf("Wrong basic error code: %q != %q",
|
||||
extended, expected)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
201408
vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c
generated
vendored
Normal file
201408
vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
10475
vendor/github.com/mattn/go-sqlite3/sqlite3-binding.h
generated
vendored
Normal file
10475
vendor/github.com/mattn/go-sqlite3/sqlite3-binding.h
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1015
vendor/github.com/mattn/go-sqlite3/sqlite3.go
generated
vendored
Normal file
1015
vendor/github.com/mattn/go-sqlite3/sqlite3.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
103
vendor/github.com/mattn/go-sqlite3/sqlite3_context.go
generated
vendored
Normal file
103
vendor/github.com/mattn/go-sqlite3/sqlite3_context.go
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
// Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sqlite3
|
||||
|
||||
/*
|
||||
|
||||
#ifndef USE_LIBSQLITE3
|
||||
#include <sqlite3-binding.h>
|
||||
#else
|
||||
#include <sqlite3.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
// These wrappers are necessary because SQLITE_TRANSIENT
|
||||
// is a pointer constant, and cgo doesn't translate them correctly.
|
||||
|
||||
static inline void my_result_text(sqlite3_context *ctx, char *p, int np) {
|
||||
sqlite3_result_text(ctx, p, np, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
static inline void my_result_blob(sqlite3_context *ctx, void *p, int np) {
|
||||
sqlite3_result_blob(ctx, p, np, SQLITE_TRANSIENT);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"math"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const i64 = unsafe.Sizeof(int(0)) > 4
|
||||
|
||||
// SQLiteContext behave sqlite3_context
|
||||
type SQLiteContext C.sqlite3_context
|
||||
|
||||
// ResultBool sets the result of an SQL function.
|
||||
func (c *SQLiteContext) ResultBool(b bool) {
|
||||
if b {
|
||||
c.ResultInt(1)
|
||||
} else {
|
||||
c.ResultInt(0)
|
||||
}
|
||||
}
|
||||
|
||||
// ResultBlob sets the result of an SQL function.
|
||||
// See: sqlite3_result_blob, http://sqlite.org/c3ref/result_blob.html
|
||||
func (c *SQLiteContext) ResultBlob(b []byte) {
|
||||
if i64 && len(b) > math.MaxInt32 {
|
||||
C.sqlite3_result_error_toobig((*C.sqlite3_context)(c))
|
||||
return
|
||||
}
|
||||
var p *byte
|
||||
if len(b) > 0 {
|
||||
p = &b[0]
|
||||
}
|
||||
C.my_result_blob((*C.sqlite3_context)(c), unsafe.Pointer(p), C.int(len(b)))
|
||||
}
|
||||
|
||||
// ResultDouble sets the result of an SQL function.
|
||||
// See: sqlite3_result_double, http://sqlite.org/c3ref/result_blob.html
|
||||
func (c *SQLiteContext) ResultDouble(d float64) {
|
||||
C.sqlite3_result_double((*C.sqlite3_context)(c), C.double(d))
|
||||
}
|
||||
|
||||
// ResultInt sets the result of an SQL function.
|
||||
// See: sqlite3_result_int, http://sqlite.org/c3ref/result_blob.html
|
||||
func (c *SQLiteContext) ResultInt(i int) {
|
||||
if i64 && (i > math.MaxInt32 || i < math.MinInt32) {
|
||||
C.sqlite3_result_int64((*C.sqlite3_context)(c), C.sqlite3_int64(i))
|
||||
} else {
|
||||
C.sqlite3_result_int((*C.sqlite3_context)(c), C.int(i))
|
||||
}
|
||||
}
|
||||
|
||||
// ResultInt64 sets the result of an SQL function.
|
||||
// See: sqlite3_result_int64, http://sqlite.org/c3ref/result_blob.html
|
||||
func (c *SQLiteContext) ResultInt64(i int64) {
|
||||
C.sqlite3_result_int64((*C.sqlite3_context)(c), C.sqlite3_int64(i))
|
||||
}
|
||||
|
||||
// ResultNull sets the result of an SQL function.
|
||||
// See: sqlite3_result_null, http://sqlite.org/c3ref/result_blob.html
|
||||
func (c *SQLiteContext) ResultNull() {
|
||||
C.sqlite3_result_null((*C.sqlite3_context)(c))
|
||||
}
|
||||
|
||||
// ResultText sets the result of an SQL function.
|
||||
// See: sqlite3_result_text, http://sqlite.org/c3ref/result_blob.html
|
||||
func (c *SQLiteContext) ResultText(s string) {
|
||||
h := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
||||
cs, l := (*C.char)(unsafe.Pointer(h.Data)), C.int(h.Len)
|
||||
C.my_result_text((*C.sqlite3_context)(c), cs, l)
|
||||
}
|
||||
|
||||
// ResultZeroblob sets the result of an SQL function.
|
||||
// See: sqlite3_result_zeroblob, http://sqlite.org/c3ref/result_blob.html
|
||||
func (c *SQLiteContext) ResultZeroblob(n int) {
|
||||
C.sqlite3_result_zeroblob((*C.sqlite3_context)(c), C.int(n))
|
||||
}
|
130
vendor/github.com/mattn/go-sqlite3/sqlite3_fts3_test.go
generated
vendored
Normal file
130
vendor/github.com/mattn/go-sqlite3/sqlite3_fts3_test.go
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
// Copyright (C) 2015 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFTS3(t *testing.T) {
|
||||
tempFilename := TempFilename(t)
|
||||
defer os.Remove(tempFilename)
|
||||
db, err := sql.Open("sqlite3", tempFilename)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to open database:", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
_, err = db.Exec("DROP TABLE foo")
|
||||
_, err = db.Exec("CREATE VIRTUAL TABLE foo USING fts3(id INTEGER PRIMARY KEY, value TEXT)")
|
||||
if err != nil {
|
||||
t.Fatal("Failed to create table:", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("INSERT INTO foo(id, value) VALUES(?, ?)", 1, `今日の 晩御飯は 天麩羅よ`)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to insert value:", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("INSERT INTO foo(id, value) VALUES(?, ?)", 2, `今日は いい 天気だ`)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to insert value:", err)
|
||||
}
|
||||
|
||||
rows, err := db.Query("SELECT id, value FROM foo WHERE value MATCH '今日* 天*'")
|
||||
if err != nil {
|
||||
t.Fatal("Unable to query foo table:", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var id int
|
||||
var value string
|
||||
|
||||
if err := rows.Scan(&id, &value); err != nil {
|
||||
t.Error("Unable to scan results:", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if id == 1 && value != `今日の 晩御飯は 天麩羅よ` {
|
||||
t.Error("Value for id 1 should be `今日の 晩御飯は 天麩羅よ`, but:", value)
|
||||
} else if id == 2 && value != `今日は いい 天気だ` {
|
||||
t.Error("Value for id 2 should be `今日は いい 天気だ`, but:", value)
|
||||
}
|
||||
}
|
||||
|
||||
rows, err = db.Query("SELECT value FROM foo WHERE value MATCH '今日* 天麩羅*'")
|
||||
if err != nil {
|
||||
t.Fatal("Unable to query foo table:", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var value string
|
||||
if !rows.Next() {
|
||||
t.Fatal("Result should be only one")
|
||||
}
|
||||
|
||||
if err := rows.Scan(&value); err != nil {
|
||||
t.Fatal("Unable to scan results:", err)
|
||||
}
|
||||
|
||||
if value != `今日の 晩御飯は 天麩羅よ` {
|
||||
t.Fatal("Value should be `今日の 晩御飯は 天麩羅よ`, but:", value)
|
||||
}
|
||||
|
||||
if rows.Next() {
|
||||
t.Fatal("Result should be only one")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFTS4(t *testing.T) {
|
||||
tempFilename := TempFilename(t)
|
||||
defer os.Remove(tempFilename)
|
||||
db, err := sql.Open("sqlite3", tempFilename)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to open database:", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
_, err = db.Exec("DROP TABLE foo")
|
||||
_, err = db.Exec("CREATE VIRTUAL TABLE foo USING fts4(tokenize=unicode61, id INTEGER PRIMARY KEY, value TEXT)")
|
||||
switch {
|
||||
case err != nil && err.Error() == "unknown tokenizer: unicode61":
|
||||
t.Skip("FTS4 not supported")
|
||||
case err != nil:
|
||||
t.Fatal("Failed to create table:", err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("INSERT INTO foo(id, value) VALUES(?, ?)", 1, `février`)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to insert value:", err)
|
||||
}
|
||||
|
||||
rows, err := db.Query("SELECT value FROM foo WHERE value MATCH 'fevrier'")
|
||||
if err != nil {
|
||||
t.Fatal("Unable to query foo table:", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var value string
|
||||
if !rows.Next() {
|
||||
t.Fatal("Result should be only one")
|
||||
}
|
||||
|
||||
if err := rows.Scan(&value); err != nil {
|
||||
t.Fatal("Unable to scan results:", err)
|
||||
}
|
||||
|
||||
if value != `février` {
|
||||
t.Fatal("Value should be `février`, but:", value)
|
||||
}
|
||||
|
||||
if rows.Next() {
|
||||
t.Fatal("Result should be only one")
|
||||
}
|
||||
}
|
13
vendor/github.com/mattn/go-sqlite3/sqlite3_fts5.go
generated
vendored
Normal file
13
vendor/github.com/mattn/go-sqlite3/sqlite3_fts5.go
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
// +build fts5
|
||||
|
||||
package sqlite3
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -DSQLITE_ENABLE_FTS5
|
||||
#cgo LDFLAGS: -lm
|
||||
*/
|
||||
import "C"
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user