Commit 1ccdd320 authored by Sascha Steinbiss's avatar Sascha Steinbiss

New upstream version 0.0~git20160819.0.3499960

parents
This diff is collapsed.
# gotk3adapter
Contains adapters and interfaces for gotk3 in order to make testing possible.
package gdk_mock
import "github.com/twstrike/gotk3adapter/gdki"
type Mock struct{}
func (*Mock) EventButtonFrom(ev gdki.Event) gdki.EventButton {
return nil
}
func (*Mock) EventKeyFrom(ev gdki.Event) gdki.EventKey {
return nil
}
func (*Mock) PixbufLoaderNew() (gdki.PixbufLoader, error) {
return &MockPixbufLoader{}, nil
}
func (*Mock) ScreenGetDefault() (gdki.Screen, error) {
return &MockScreen{}, nil
}
func (*Mock) WorkspaceControlSupported() bool {
return false
}
package gdk_mock
type MockEvent struct {
}
package gdk_mock
type MockEventButton struct {
MockEvent
}
func (*MockEventButton) Button() uint {
return 0
}
func (*MockEventButton) Time() uint32 {
return 0
}
func (*MockEventButton) X() float64 {
return 0
}
func (*MockEventButton) Y() float64 {
return 0
}
package gdk_mock
type MockEventKey struct {
MockEvent
}
func (*MockEventKey) KeyVal() uint {
return 0
}
func (*MockEventKey) State() uint {
return 0
}
package gdk_mock
import "github.com/twstrike/gotk3adapter/gdki"
func init() {
gdki.AssertGdk(&Mock{})
gdki.AssertEvent(&MockEvent{})
gdki.AssertEventButton(&MockEventButton{})
gdki.AssertEventKey(&MockEventKey{})
gdki.AssertPixbuf(&MockPixbuf{})
gdki.AssertPixbufLoader(&MockPixbufLoader{})
gdki.AssertScreen(&MockScreen{})
gdki.AssertWindow(&MockWindow{})
}
package gdk_mock
type MockPixbuf struct {
}
package gdk_mock
import (
"github.com/twstrike/gotk3adapter/gdki"
"github.com/twstrike/gotk3adapter/glib_mock"
)
type MockPixbufLoader struct {
glib_mock.MockObject
}
func (*MockPixbufLoader) Close() error {
return nil
}
func (*MockPixbufLoader) GetPixbuf() (gdki.Pixbuf, error) {
return nil, nil
}
func (*MockPixbufLoader) Write(b []byte) (int, error) {
return 0, nil
}
package gdk_mock
type MockScreen struct {
}
package gdk_mock
import "github.com/twstrike/gotk3adapter/glib_mock"
type MockWindow struct {
glib_mock.MockObject
}
func (*MockWindow) GetDesktop() uint32 {
return 0
}
func (*MockWindow) MoveToDesktop(uint32) {
}
This diff is collapsed.
package gdka
import (
"github.com/gotk3/gotk3/gdk"
"github.com/twstrike/gotk3adapter/gdki"
)
type event struct {
*gdk.Event
}
func wrapEventSimple(v *gdk.Event) *event {
if v == nil {
return nil
}
return &event{v}
}
func wrapEvent(v *gdk.Event, e error) (*event, error) {
return wrapEventSimple(v), e
}
func unwrapEvent(v gdki.Event) *gdk.Event {
if v == nil {
return nil
}
return v.(*event).Event
}
package gdka
import (
"github.com/gotk3/gotk3/gdk"
"github.com/twstrike/gotk3adapter/gdki"
)
type eventButton struct {
*gdk.EventButton
}
func wrapEventButtonSimple(v *gdk.EventButton) *eventButton {
if v == nil {
return nil
}
return &eventButton{v}
}
func wrapEventButton(v *gdk.EventButton, e error) (*eventButton, error) {
return wrapEventButtonSimple(v), e
}
func unwrapEventButton(v gdki.EventButton) *gdk.EventButton {
if v == nil {
return nil
}
return v.(*eventButton).EventButton
}
package gdka
import "github.com/gotk3/gotk3/gdk"
func wrapEventAsEventButton(v *event) *eventButton {
wrapped, _ := wrapEventButton(&gdk.EventButton{v.Event}, nil)
return wrapped
}
package gdka
import "github.com/twstrike/gotk3adapter/gdki"
func eventCast(e gdki.Event) *event {
if e == nil {
return nil
}
return e.(*event)
}
package gdka
import (
"github.com/gotk3/gotk3/gdk"
"github.com/twstrike/gotk3adapter/gdki"
)
type eventKey struct {
*gdk.EventKey
}
func wrapEventKeySimple(v *gdk.EventKey) *eventKey {
if v == nil {
return nil
}
return &eventKey{v}
}
func wrapEventKey(v *gdk.EventKey, e error) (*eventKey, error) {
return wrapEventKeySimple(v), e
}
func unwrapEventKey(v gdki.EventKey) *gdk.EventKey {
if v == nil {
return nil
}
return v.(*eventKey).EventKey
}
package gdka
import "github.com/gotk3/gotk3/gdk"
func wrapEventAsEventKey(v *event) *eventKey {
wrapped, _ := wrapEventKey(&gdk.EventKey{v.Event}, nil)
return wrapped
}
package gdka
import "github.com/twstrike/gotk3adapter/gdki"
func init() {
gdki.AssertGdk(&RealGdk{})
gdki.AssertEvent(&event{})
gdki.AssertEventButton(&eventButton{})
gdki.AssertEventKey(&eventKey{})
gdki.AssertPixbuf(&pixbuf{})
gdki.AssertPixbufLoader(&pixbufLoader{})
gdki.AssertScreen(&screen{})
gdki.AssertWindow(&window{})
}
#!/usr/bin/env ruby
types = %w[
Event
EventButton
Pixbuf
PixbufLoader
Screen
]
exportedWrap = {}
exportedUnwrap = {
"Screen" => true,
"Pixbuf" => true
}
class String
def underscore
self.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
end
end
types.each do |tp|
lower = tp[0].downcase + tp[1..-1]
fname = "#{tp.underscore}.go"
prefix1 = if exportedWrap[tp]
"W"
else
"w"
end
prefix2 = if exportedUnwrap[tp]
"U"
else
"u"
end
File.open(fname, "w") do |ff|
ff.puts <<METH
package gdka
import (
"github.com/gotk3/gotk3/gdk"
"github.com/twstrike/gotk3adapter/gdki"
)
type #{ lower } struct {
*gdk.#{ tp }
}
func #{prefix1}rap#{ tp }(v *gdk.#{ tp }, e error) (*#{ lower }, error) {
if v == nil {
return nil, e
}
return &#{ lower }{v}, e
}
func #{prefix2}nwrap#{ tp }(v gdki.#{ tp }) *gdk.#{ tp } {
if v == nil {
return nil
}
return v.(*#{ lower }).#{ tp }
}
METH
end
end
package gdka
import (
"github.com/gotk3/gotk3/gdk"
"github.com/twstrike/gotk3adapter/gdki"
)
type pixbuf struct {
*gdk.Pixbuf
}
func wrapPixbufSimple(v *gdk.Pixbuf) *pixbuf {
if v == nil {
return nil
}
return &pixbuf{v}
}
func wrapPixbuf(v *gdk.Pixbuf, e error) (*pixbuf, error) {
return wrapPixbufSimple(v), e
}
func UnwrapPixbuf(v gdki.Pixbuf) *gdk.Pixbuf {
if v == nil {
return nil
}
return v.(*pixbuf).Pixbuf
}
package gdka
import (
"github.com/gotk3/gotk3/gdk"
"github.com/twstrike/gotk3adapter/gdki"
"github.com/twstrike/gotk3adapter/gliba"
)
type pixbufLoader struct {
*gliba.Object
internal *gdk.PixbufLoader
}
func wrapPixbufLoaderSimple(v *gdk.PixbufLoader) *pixbufLoader {
if v == nil {
return nil
}
return &pixbufLoader{gliba.WrapObjectSimple(v.Object), v}
}
func wrapPixbufLoader(v *gdk.PixbufLoader, e error) (*pixbufLoader, error) {
return wrapPixbufLoaderSimple(v), e
}
func unwrapPixbufLoader(v gdki.PixbufLoader) *gdk.PixbufLoader {
if v == nil {
return nil
}
return v.(*pixbufLoader).internal
}
func (v *pixbufLoader) Close() error {
return v.internal.Close()
}
func (v *pixbufLoader) GetPixbuf() (gdki.Pixbuf, error) {
return wrapPixbuf(v.internal.GetPixbuf())
}
func (v *pixbufLoader) Write(b []byte) (int, error) {
return v.internal.Write(b)
}
package gdka
import (
"github.com/gotk3/gotk3/gdk"
"github.com/twstrike/gotk3adapter/gdki"
)
type RealGdk struct{}
var Real = &RealGdk{}
func (*RealGdk) EventButtonFrom(ev gdki.Event) gdki.EventButton {
return wrapEventAsEventButton(eventCast(ev))
}
func (*RealGdk) EventKeyFrom(ev gdki.Event) gdki.EventKey {
return wrapEventAsEventKey(eventCast(ev))
}
func (*RealGdk) PixbufLoaderNew() (gdki.PixbufLoader, error) {
return wrapPixbufLoader(gdk.PixbufLoaderNew())
}
func (*RealGdk) ScreenGetDefault() (gdki.Screen, error) {
return wrapScreen(gdk.ScreenGetDefault())
}
func (*RealGdk) WorkspaceControlSupported() bool {
return gdk.WorkspaceControlSupported()
}
package gdka
import (
"github.com/gotk3/gotk3/gdk"
"github.com/twstrike/gotk3adapter/gdki"
)
type screen struct {
*gdk.Screen
}
func wrapScreenSimple(v *gdk.Screen) *screen {
if v == nil {
return nil
}
return &screen{v}
}
func wrapScreen(v *gdk.Screen, e error) (*screen, error) {
return wrapScreenSimple(v), e
}
func UnwrapScreen(v gdki.Screen) *gdk.Screen {
if v == nil {
return nil
}
return v.(*screen).Screen
}
package gdka
import (
"github.com/gotk3/gotk3/gdk"
"github.com/twstrike/gotk3adapter/gdki"
"github.com/twstrike/gotk3adapter/gliba"
)
type window struct {
*gliba.Object
internal *gdk.Window
}
func WrapWindowSimple(v *gdk.Window) *window {
if v == nil {
return nil
}
return &window{gliba.WrapObjectSimple(v.Object), v}
}
func WrapWindow(v *gdk.Window, e error) (*window, error) {
return WrapWindowSimple(v), e
}
func UnwrapWindow(v gdki.Window) *gdk.Window {
if v == nil {
return nil
}
return v.(*window).internal
}
func (v *window) GetDesktop() uint32 {
return v.internal.GetDesktop()
}
func (v *window) MoveToDesktop(v1 uint32) {
v.internal.MoveToDesktop(v1)
}
package gdka
import (
"github.com/gotk3/gotk3/gdk"
"github.com/twstrike/gotk3adapter/gliba"
)
func init() {
gliba.AddWrapper(WrapLocal)
gliba.AddUnwrapper(UnwrapLocal)
}
func WrapLocal(o interface{}) (interface{}, bool) {
switch oo := o.(type) {
case *gdk.EventButton:
val := wrapEventButtonSimple(oo)
if val == nil {
return nil, true
}
return val, true
case *gdk.Event:
val := wrapEventSimple(oo)
if val == nil {
return nil, true
}
return val, true
case *gdk.Pixbuf:
val := wrapPixbufSimple(oo)
if val == nil {
return nil, true
}
return val, true
case *gdk.PixbufLoader:
val := wrapPixbufLoaderSimple(oo)
if val == nil {
return nil, true
}
return val, true
case *gdk.Screen:
val := wrapScreenSimple(oo)
if val == nil {
return nil, true
}
return val, true
case *gdk.Window:
val := WrapWindowSimple(oo)
if val == nil {
return nil, true
}
return val, true
default:
return nil, false
}
}
func UnwrapLocal(o interface{}) (interface{}, bool) {
switch oo := o.(type) {
case *eventButton:
val := unwrapEventButton(oo)
if val == nil {
return nil, true
}
return val, true
case *event:
val := unwrapEvent(oo)
if val == nil {
return nil, true
}
return val, true
case *pixbuf:
val := UnwrapPixbuf(oo)
if val == nil {
return nil, true
}
return val, true
case *pixbufLoader:
val := unwrapPixbufLoader(oo)
if val == nil {
return nil, true
}
return val, true
case *screen:
val := UnwrapScreen(oo)
if val == nil {
return nil, true
}
return val, true
case *window:
val := UnwrapWindow(oo)
if val == nil {
return nil, true
}
return val, true
default:
return nil, false
}
}
This diff is collapsed.
package gdki
type Event interface{}
func AssertEvent(_ Event) {}