├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── examples ├── counter-gtk │ ├── build.gradle.kts │ └── src │ │ └── nativeMain │ │ └── kotlin │ │ └── Main.kt ├── demo-adwaita │ ├── build.gradle.kts │ └── src │ │ └── nativeMain │ │ └── kotlin │ │ ├── AboutDemo.kt │ │ ├── ButtonDemo.kt │ │ ├── Main.kt │ │ └── ToastDemo.kt ├── gtk-examples │ ├── build.gradle.kts │ └── src │ │ └── nativeMain │ │ └── kotlin │ │ ├── customwidget │ │ └── CustomWidgetExample.kt │ │ ├── customwidgetbinding │ │ └── CustomWidgetBindingExample.kt │ │ ├── gridview │ │ └── GridViewExample.kt │ │ ├── listmodel │ │ └── ListModelExample.kt │ │ └── treelistmodel │ │ └── TreeListModelExample.kt ├── hello-world-gtk │ ├── build.gradle.kts │ └── src │ │ └── nativeMain │ │ └── kotlin │ │ └── Main.kt ├── sevenguis-1-counter │ ├── build.gradle.kts │ └── src │ │ └── nativeMain │ │ └── kotlin │ │ └── Main.kt ├── sevenguis-2-temperature-converter │ ├── build.gradle.kts │ └── src │ │ └── nativeMain │ │ └── kotlin │ │ └── Main.kt └── sevenguis-3-flight-booker │ ├── build.gradle.kts │ └── src │ └── nativeMain │ └── kotlin │ └── Main.kt ├── gio-bindings ├── build.gradle.kts └── src │ ├── nativeInterop │ └── cinterop │ │ └── gio.def │ ├── nativeMain │ └── kotlin │ │ └── bindings │ │ └── gio │ │ ├── Action.kt │ │ ├── ActionGroup.kt │ │ ├── ActionMap.kt │ │ ├── ActionMapExt.kt │ │ ├── Application.kt │ │ ├── Extensions.kt │ │ ├── ListModel.kt │ │ ├── ListStore.kt │ │ ├── Menu.kt │ │ ├── MenuItem.kt │ │ ├── MenuModel.kt │ │ ├── Permission.kt │ │ ├── SimpleAction.kt │ │ ├── SimplePermission.kt │ │ └── internal │ │ ├── InterfaceWrappers.kt │ │ └── Signals.kt │ └── nativeTest │ └── kotlin │ ├── GApplicationTest.kt │ └── ListStoreTests.kt ├── gobject-bindings ├── build.gradle.kts └── src │ ├── nativeInterop │ └── cinterop │ │ └── gobject.def │ ├── nativeMain │ └── kotlin │ │ ├── bindings │ │ ├── glib │ │ │ ├── Variant.kt │ │ │ └── VariantType.kt │ │ ├── gobject │ │ │ ├── Binding.kt │ │ │ ├── Extensions.kt │ │ │ ├── Object.kt │ │ │ ├── ObjectCompanion.kt │ │ │ ├── ParamSpec.kt │ │ │ └── ParamSpecString.kt │ │ └── util │ │ │ └── Util.kt │ │ ├── internal │ │ ├── KGType.kt │ │ ├── Signals.kt │ │ ├── TypeRegistry.kt │ │ └── objectproperties │ │ │ ├── IntObjectProperty.kt │ │ │ ├── NullableStringObjectProperty.kt │ │ │ ├── ObjectClassProperties.kt │ │ │ ├── ObjectPropertyDelegate.kt │ │ │ └── StringObjectProperty.kt │ │ └── usertypes │ │ ├── KGObjectProperty.kt │ │ └── UserTypes.kt │ └── nativeTest │ └── kotlin │ ├── CustomObjectPropertiesTest.kt │ ├── CustomObjectTest.kt │ └── GObjectTests.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── gtk-bindings ├── build.gradle.kts └── src │ ├── nativeInterop │ └── cinterop │ │ └── gtk.def │ ├── nativeMain │ └── kotlin │ │ └── bindings │ │ └── gtk │ │ ├── AboutDialog.kt │ │ ├── Actionable.kt │ │ ├── Adjustment.kt │ │ ├── Application.kt │ │ ├── ApplicationWindow.kt │ │ ├── AspectFrame.kt │ │ ├── Border.kt │ │ ├── Box.kt │ │ ├── Button.kt │ │ ├── CenterBox.kt │ │ ├── CheckButton.kt │ │ ├── ColumnView.kt │ │ ├── Dialog.kt │ │ ├── DropDown.kt │ │ ├── Editable.kt │ │ ├── Entry.kt │ │ ├── EntryBuffer.kt │ │ ├── Extensions.kt │ │ ├── Grid.kt │ │ ├── GridView.kt │ │ ├── HeaderBar.kt │ │ ├── Image.kt │ │ ├── Label.kt │ │ ├── LevelBar.kt │ │ ├── LinkButton.kt │ │ ├── ListBase.kt │ │ ├── ListBox.kt │ │ ├── ListBoxRow.kt │ │ ├── ListItem.kt │ │ ├── ListItemFactory.kt │ │ ├── ListView.kt │ │ ├── LockButton.kt │ │ ├── MenuButton.kt │ │ ├── MessageDialog.kt │ │ ├── Native.kt │ │ ├── Orientable.kt │ │ ├── Popover.kt │ │ ├── ProgressBar.kt │ │ ├── Root.kt │ │ ├── Scrollable.kt │ │ ├── ScrolledWindow.kt │ │ ├── Searchbar.kt │ │ ├── SelectionModel.kt │ │ ├── Separator.kt │ │ ├── ShortcutManager.kt │ │ ├── ShortcutsWindow.kt │ │ ├── SignalListItemFactory.kt │ │ ├── SingleSelection.kt │ │ ├── Stack.kt │ │ ├── StackPage.kt │ │ ├── StackSidebar.kt │ │ ├── StringList.kt │ │ ├── StringObject.kt │ │ ├── Switch.kt │ │ ├── ToggleButton.kt │ │ ├── TreeExpander.kt │ │ ├── TreeListModel.kt │ │ ├── TreeListRow.kt │ │ ├── Widget.kt │ │ ├── Window.kt │ │ ├── internal │ │ ├── InterfaceWrappers.kt │ │ └── Signals.kt │ │ └── usertypes │ │ └── WidgetCompanion.kt │ └── nativeTest │ └── kotlin │ └── bindings.gtk │ ├── CustomGtkApplicationTest.kt │ ├── CustomWidgetTest.kt │ ├── GtkAboutDialogTest.kt │ ├── GtkApplicationTest.kt │ ├── GtkBoxTest.kt │ ├── GtkButtonTest.kt │ ├── GtkDialogTest.kt │ ├── GtkHeaderBartest.kt │ ├── GtkLabelTests.kt │ ├── GtkListBoxTest.kt │ ├── GtkMenuButtonTest.kt │ ├── SignalListItemFactoryTest.kt │ ├── WindowTests.kt │ └── testutils │ └── GtkTestBase.kt ├── libadwaita-bindings ├── build.gradle.kts └── src │ ├── nativeInterop │ └── cinterop │ │ └── adwaita.def │ ├── nativeMain │ └── kotlin │ │ └── bindings.adw │ │ ├── AboutWindow.kt │ │ ├── ActionRow.kt │ │ ├── Application.kt │ │ ├── ApplicationWindow.kt │ │ ├── Avatar.kt │ │ ├── Bin.kt │ │ ├── ButtonContent.kt │ │ ├── Clamp.kt │ │ ├── ClampScrollable.kt │ │ ├── ComboRow.kt │ │ ├── EntryRow.kt │ │ ├── ExpanderRow.kt │ │ ├── Extensions.kt │ │ ├── Flap.kt │ │ ├── HeaderBar.kt │ │ ├── Leaflet.kt │ │ ├── LeafletPage.kt │ │ ├── MessageDialog.kt │ │ ├── PasswordEntryRow.kt │ │ ├── PreferencesGroup.kt │ │ ├── PreferencesPage.kt │ │ ├── PreferencesRow.kt │ │ ├── PreferencesWindow.kt │ │ ├── SplitButton.kt │ │ ├── StatusPage.kt │ │ ├── TabBar.kt │ │ ├── TabPage.kt │ │ ├── TabView.kt │ │ ├── Toast.kt │ │ ├── ToastOverlay.kt │ │ ├── ViewStack.kt │ │ ├── ViewStackPage.kt │ │ ├── ViewSwitcher.kt │ │ ├── ViewSwitcherBar.kt │ │ ├── ViewSwitcherTitle.kt │ │ ├── Window.kt │ │ ├── WindowTitle.kt │ │ └── internal │ │ └── Signals.kt │ └── nativeTest │ └── kotlin │ ├── AdMessageDialogTest.kt │ ├── AdwAboutWindowTest.kt │ ├── AdwActionRowTest.kt │ ├── AdwApplicationTest.kt │ ├── AdwApplicationWindowTest.kt │ ├── AdwAvatarTest.kt │ ├── AdwButtonContentTest.kt │ ├── AdwClampTest.kt │ ├── AdwHeaderBarTest.kt │ ├── AdwPreferencesTest.kt │ ├── AdwStatusPageTest.kt │ ├── AdwStyleClassesTest.kt │ ├── AdwTabBarTest.kt │ ├── AdwTestBase.kt │ ├── AdwToastTest.kt │ ├── AdwViewSwitcherTest.kt │ ├── AdwWindowTest.kt │ ├── ApplicationUnrefTest.kt │ └── SubclassAdwBinTest.kt └── settings.gradle.kts /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | .idea/ 3 | build/ 4 | .envrc 5 | .env 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Steven Van Bael 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") version "1.7.20" 3 | id("org.jetbrains.dokka") version "1.7.20" 4 | } 5 | 6 | allprojects { 7 | group = "io.quantus.gtk-kotlin-native" 8 | version = "0.0.1-SNAPSHOT" 9 | repositories { 10 | mavenCentral() 11 | } 12 | } 13 | 14 | kotlin { 15 | mingwX64() 16 | macosX64() 17 | linuxX64() 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/counter-gtk/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | } 4 | 5 | kotlin { 6 | val hostOs = System.getProperty("os.name") 7 | val isMingwX64 = hostOs.startsWith("Windows") 8 | val nativeTarget = when { 9 | hostOs == "Mac OS X" -> macosX64("native") 10 | hostOs == "Linux" -> linuxX64("native") 11 | isMingwX64 -> mingwX64("native") 12 | else -> throw GradleException("Host OS is not supported in Kotlin/Native.") 13 | } 14 | sourceSets { 15 | val nativeMain by getting { 16 | dependencies { 17 | implementation(project(":gtk-bindings")) 18 | } 19 | } 20 | } 21 | 22 | nativeTarget.apply { 23 | binaries { 24 | executable { 25 | entryPoint = "main" 26 | if (isMingwX64) { 27 | val userHome = File(System.getenv("USERPROFILE")) 28 | linkerOpts( 29 | "-L${userHome}\\.konan\\dependencies\\msys2-mingw-w64-x86_64-2\\x86_64-w64-mingw32\\lib", 30 | "-LC:\\msys64\\mingw64\\lib", 31 | ) 32 | } 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /examples/counter-gtk/src/nativeMain/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | import bindings.gtk.* 2 | import native.gtk.GtkAlign.GTK_ALIGN_CENTER 3 | import native.gtk.GtkOrientation.GTK_ORIENTATION_VERTICAL 4 | 5 | fun main() { 6 | val app = Application("com.example.counter") 7 | 8 | var counter = 0 9 | 10 | app.onActivate { 11 | // create the window 12 | val window = ApplicationWindow(app) 13 | window.title = "Hello World" 14 | window.defaultSize = Pair(600, 400) 15 | 16 | // create the widgets 17 | val label = Label() 18 | val button = Button("Click me") 19 | 20 | // attach a button click handler 21 | button.onClicked { 22 | label.text = "You clicked ${++counter} times" 23 | } 24 | 25 | // wrap in a box for layout 26 | window.child = Box(GTK_ORIENTATION_VERTICAL, 20).apply { 27 | valign = GTK_ALIGN_CENTER 28 | append(button) 29 | append(label) 30 | } 31 | 32 | // show the window 33 | window.show() 34 | } 35 | 36 | app.runApplication() 37 | app.unref() 38 | } -------------------------------------------------------------------------------- /examples/demo-adwaita/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | } 4 | 5 | kotlin { 6 | val hostOs = System.getProperty("os.name") 7 | val isMingwX64 = hostOs.startsWith("Windows") 8 | val nativeTarget = when { 9 | hostOs == "Mac OS X" -> macosX64("native") 10 | hostOs == "Linux" -> linuxX64("native") 11 | isMingwX64 -> mingwX64("native") 12 | else -> throw GradleException("Host OS is not supported in Kotlin/Native.") 13 | } 14 | sourceSets { 15 | val nativeMain by getting { 16 | dependencies { 17 | implementation(project(":libadwaita-bindings")) 18 | } 19 | } 20 | } 21 | 22 | nativeTarget.apply { 23 | binaries { 24 | executable { 25 | entryPoint = "main" 26 | if (isMingwX64) { 27 | val userHome = File(System.getenv("USERPROFILE")) 28 | linkerOpts( 29 | "-L${userHome}\\.konan\\dependencies\\msys2-mingw-w64-x86_64-2\\x86_64-w64-mingw32\\lib", 30 | "-LC:\\msys64\\mingw64\\lib", 31 | ) 32 | } 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /examples/demo-adwaita/src/nativeMain/kotlin/AboutDemo.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.AboutWindow 2 | import bindings.adw.Clamp 3 | import bindings.adw.StatusPage 4 | import bindings.gtk.Button 5 | import native.gtk.GtkLicense 6 | 7 | fun buildAboutPage() = StatusPage().apply { 8 | title = "About Demo" 9 | child = Clamp().apply { 10 | maximumSize = 400 11 | child = Button("Show About").apply { 12 | onClicked { showAbout() } 13 | addCssClass("pill") 14 | } 15 | } 16 | } 17 | 18 | fun showAbout() { 19 | val about = AboutWindow() 20 | 21 | about.applicationIcon = "folder-music" 22 | about.applicationName = "Adwaita Demo" 23 | about.artists = listOf("Chuck Schuldiner", "Chris Cornell", "Layne Staley") 24 | about.comments = "Sample comments." 25 | about.copyright = "Copyright 2022 - Steven Van Bael" 26 | about.debugInfo = "Sample debug info." 27 | about.debugInfoFilename = "/tmp/debug.txt" 28 | about.designers = listOf("Designer 1", "Designer 2") 29 | about.developerName = "Steven Van Bael" 30 | about.developers = listOf("Steven Van Bael", "Mystery Developer") 31 | about.documenters = listOf("Documenter 1", "Documenter 2") 32 | about.issueUrl = "https://github.com/vbsteven/gtk-kotlin-native/issues" 33 | about.license = "The License Text" 34 | about.licenseType = GtkLicense.GTK_LICENSE_MIT_X11 35 | about.releaseNotes = """ 36 | 41 | """ 42 | about.releaseNotesVersion = "0.0.1" 43 | about.supportUrl = about.issueUrl 44 | about.translatorCredits = "Credit to the translators" 45 | about.version = "0.0.1" 46 | about.website = "https://github.com/vbsteven/gtk-kotlin-native" 47 | about.show() 48 | } -------------------------------------------------------------------------------- /examples/demo-adwaita/src/nativeMain/kotlin/ToastDemo.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.* 2 | import bindings.gtk.Button 3 | import bindings.gtk.Widget 4 | import native.gtk.GtkAlign 5 | 6 | lateinit var overlay: ToastOverlay 7 | 8 | fun buildToastDemoPage(): Widget { 9 | overlay = ToastOverlay() 10 | overlay.vexpand = true 11 | 12 | val page = StatusPage().apply { 13 | vexpand = true 14 | title = "Toasts" 15 | child = buildToastList() 16 | valign = GtkAlign.GTK_ALIGN_START 17 | } 18 | 19 | overlay.child = page 20 | 21 | return overlay 22 | } 23 | 24 | fun buildToastList(): Widget { 25 | 26 | val prefGroup = PreferencesGroup() 27 | 28 | prefGroup.add(demoToastRow("Simple Toast", ::showSimpleToast)) 29 | prefGroup.add(demoToastRow("Toast with button", ::showButtonToast)) 30 | prefGroup.add(demoToastRow("Custom Title", ::showCustomTitleToast)) 31 | 32 | return Clamp().apply { 33 | maximumSize = 400 34 | tighteningThreshold = 300 35 | child = prefGroup 36 | } 37 | } 38 | 39 | private fun demoToastRow(label: String, handler: () -> Unit) = ActionRow().apply { 40 | this.title = label 41 | this.addSuffix( 42 | Button("Show").apply { 43 | valign = GtkAlign.GTK_ALIGN_CENTER 44 | onClicked { handler() } 45 | } 46 | ) 47 | } 48 | 49 | fun showSimpleToast() = overlay.addToast(Toast("A simple toast")) 50 | fun showButtonToast() = overlay.addToast(Toast("A button toast").apply { 51 | buttonLabel = "Click me" 52 | }) 53 | 54 | fun showCustomTitleToast() = overlay.addToast(Toast("Custom Title").apply { 55 | customTitle = Avatar(30, null, false) 56 | }) 57 | -------------------------------------------------------------------------------- /examples/gtk-examples/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | } 4 | 5 | kotlin { 6 | val hostOs = System.getProperty("os.name") 7 | val isMingwX64 = hostOs.startsWith("Windows") 8 | val nativeTarget = when { 9 | hostOs == "Mac OS X" -> macosX64("native") 10 | hostOs == "Linux" -> linuxX64("native") 11 | isMingwX64 -> mingwX64("native") 12 | else -> throw GradleException("Host OS is not supported in Kotlin/Native.") 13 | } 14 | sourceSets { 15 | val nativeMain by getting { 16 | dependencies { 17 | implementation(project(":gtk-bindings")) 18 | } 19 | } 20 | } 21 | 22 | nativeTarget.apply { 23 | // list all packages in the source dir 24 | val packageDirs = 25 | sourceSets["nativeMain"].kotlin.srcDirs 26 | .first() 27 | .listFiles() 28 | ?.filter { it.isDirectory } 29 | ?: emptyList() 30 | 31 | binaries { 32 | // add a binary for each package, using its main() fun as the entrypoint 33 | packageDirs.forEach { pkg -> 34 | executable(pkg.name) { 35 | entryPoint = "${pkg.name}.main" 36 | if (isMingwX64) { 37 | val userHome = File(System.getenv("USERPROFILE")) 38 | linkerOpts( 39 | "-L${userHome}\\.konan\\dependencies\\msys2-mingw-w64-x86_64-2\\x86_64-w64-mingw32\\lib", 40 | "-LC:\\msys64\\mingw64\\lib", 41 | ) 42 | } 43 | } 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /examples/gtk-examples/src/nativeMain/kotlin/customwidget/CustomWidgetExample.kt: -------------------------------------------------------------------------------- 1 | package customwidget 2 | 3 | import bindings.gtk.* 4 | import bindings.gtk.usertypes.WidgetCompanion 5 | import kotlinx.cinterop.CPointer 6 | import native.gtk.GtkAlign.GTK_ALIGN_CENTER 7 | import native.gtk.GtkOrientation.GTK_ORIENTATION_VERTICAL 8 | 9 | /** 10 | * An example showing how to create a Custom Widget. 11 | */ 12 | fun main() { 13 | val app = Application("io.quantus.gtk-kotlin-native.example.customwidget") 14 | app.onActivate { 15 | val window = ApplicationWindow(app) 16 | window.title = "Custom Widget Example" 17 | window.defaultSize = Pair(600, 400) 18 | buildUI(window) 19 | window.show() 20 | } 21 | app.run() 22 | app.unref() 23 | } 24 | 25 | private fun buildUI(window: Window) { 26 | window.child = MyCustomWidget("LabelText", "open-menu") 27 | } 28 | 29 | /** 30 | * A simple custom Widget that extends the [Box] class and contains a [Label] and an [Image]. 31 | */ 32 | private class MyCustomWidget : Box { 33 | 34 | private val label = Label() 35 | private val image = Image() 36 | 37 | constructor(pointer: CPointer<*>) : super(pointer) 38 | 39 | constructor(text: String, iconName: String) : this(newInstancePointer()) { 40 | // configure the box 41 | orientation = GTK_ORIENTATION_VERTICAL 42 | spacing = 10 43 | marginStart = 10 44 | marginEnd = 10 45 | marginTop = 10 46 | marginBottom = 10 47 | 48 | vexpand = true 49 | hexpand = true 50 | valign = GTK_ALIGN_CENTER 51 | halign = GTK_ALIGN_CENTER 52 | 53 | // set values on the child widgets 54 | label.text = text 55 | image.iconName = iconName 56 | 57 | // add the child widgets 58 | append(image) 59 | append(label) 60 | } 61 | 62 | companion object : WidgetCompanion() { 63 | override val typeName = "MyCustomWidget" 64 | override val parentType = Box.Type 65 | } 66 | } -------------------------------------------------------------------------------- /examples/gtk-examples/src/nativeMain/kotlin/gridview/GridViewExample.kt: -------------------------------------------------------------------------------- 1 | package gridview 2 | 3 | import bindings.gobject.asType 4 | import bindings.gtk.* 5 | 6 | /** 7 | * An example showing how to build a GTK4 [ListView] with string items. 8 | */ 9 | fun main() { 10 | val app = Application("io.quantus.gtk-kotlin-native.example.grid") 11 | app.onActivate { 12 | val window = ApplicationWindow(app) 13 | window.title = "GridView Example" 14 | window.defaultSize = Pair(600, 400) 15 | buildUI(window) 16 | window.show() 17 | } 18 | app.run() 19 | app.unref() 20 | } 21 | 22 | private fun buildUI(window: Window) { 23 | 24 | // create a list of String items 25 | val items = List(200) { "Item $it" } 26 | 27 | // wrap in a StingList (ListModel) 28 | val model = StringList(items) 29 | 30 | // setup the item factory 31 | val factory = SignalListItemFactory() 32 | 33 | // prepare the item row 34 | factory.onSetup { listItem -> 35 | listItem.child = Label() 36 | } 37 | 38 | // bind the item row 39 | factory.onBind { listItem -> 40 | // get the label from the listItem 41 | val label = listItem.child!!.asType(Label.Type) 42 | 43 | // get the StringObject from the listItem 44 | val item = listItem.item!!.asType(StringObject.Type) 45 | 46 | // update the label 47 | label.text = item.string 48 | } 49 | 50 | val selectionModel = SingleSelection(model) 51 | val gridView = GridView(selectionModel, factory) 52 | 53 | window.child = ScrolledWindow(gridView) 54 | } -------------------------------------------------------------------------------- /examples/gtk-examples/src/nativeMain/kotlin/listmodel/ListModelExample.kt: -------------------------------------------------------------------------------- 1 | package listmodel 2 | 3 | import bindings.gobject.asType 4 | import bindings.gtk.* 5 | 6 | /** 7 | * An example showing how to build a GTK4 [ListView] with string items. 8 | */ 9 | fun main() { 10 | val app = Application("io.quantus.gtk-kotlin-native.example.listmodel") 11 | app.onActivate { 12 | val window = ApplicationWindow(app) 13 | window.title = "ListModel" 14 | window.defaultSize = Pair(600, 400) 15 | buildUI(window) 16 | window.show() 17 | } 18 | app.run() 19 | app.unref() 20 | } 21 | 22 | private fun buildUI(window: Window) { 23 | 24 | // create a list of String items 25 | val items = List(200) { "Item $it" } 26 | 27 | // wrap in a StingList (ListModel) 28 | val model = StringList(items) 29 | 30 | // setup the item factory 31 | val factory = SignalListItemFactory() 32 | 33 | // prepare the item row 34 | factory.onSetup { listItem -> 35 | listItem.child = Label() 36 | } 37 | 38 | // bind the item row 39 | factory.onBind { listItem -> 40 | // get the label from the listItem 41 | val label = listItem.child!!.asType(Label.Type) 42 | 43 | // get the StringObject from the listItem 44 | val item = listItem.item!!.asType(StringObject.Type) 45 | 46 | // update the label 47 | label.text = item.string 48 | } 49 | 50 | val selectionModel = SingleSelection(model) 51 | val listView = ListView(selectionModel, factory) 52 | 53 | window.child = ScrolledWindow(listView) 54 | } -------------------------------------------------------------------------------- /examples/hello-world-gtk/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | } 4 | 5 | kotlin { 6 | val hostOs = System.getProperty("os.name") 7 | val isMingwX64 = hostOs.startsWith("Windows") 8 | val nativeTarget = when { 9 | hostOs == "Mac OS X" -> macosX64("native") 10 | hostOs == "Linux" -> linuxX64("native") 11 | isMingwX64 -> mingwX64("native") 12 | else -> throw GradleException("Host OS is not supported in Kotlin/Native.") 13 | } 14 | sourceSets { 15 | val nativeMain by getting { 16 | dependencies { 17 | implementation(project(":gtk-bindings")) 18 | } 19 | } 20 | } 21 | 22 | nativeTarget.apply { 23 | binaries { 24 | executable { 25 | entryPoint = "main" 26 | if (isMingwX64) { 27 | val userHome = File(System.getenv("USERPROFILE")) 28 | linkerOpts( 29 | "-L${userHome}\\.konan\\dependencies\\msys2-mingw-w64-x86_64-2\\x86_64-w64-mingw32\\lib", 30 | "-LC:\\msys64\\mingw64\\lib", 31 | ) 32 | } 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /examples/hello-world-gtk/src/nativeMain/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | import bindings.gtk.Application 2 | import bindings.gtk.ApplicationWindow 3 | import bindings.gtk.Label 4 | 5 | fun main() { 6 | val app = Application("com.example.app") 7 | 8 | app.onActivate { 9 | val window = ApplicationWindow(app) 10 | window.title = "Hello World" 11 | window.defaultSize = Pair(600, 400) 12 | window.child = Label("Hello from Kotlin/Native") 13 | window.show() 14 | } 15 | 16 | app.runApplication() 17 | app.unref() 18 | } -------------------------------------------------------------------------------- /examples/sevenguis-1-counter/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | } 4 | 5 | kotlin { 6 | val hostOs = System.getProperty("os.name") 7 | val isMingwX64 = hostOs.startsWith("Windows") 8 | val nativeTarget = when { 9 | hostOs == "Mac OS X" -> macosX64("native") 10 | hostOs == "Linux" -> linuxX64("native") 11 | isMingwX64 -> mingwX64("native") 12 | else -> throw GradleException("Host OS is not supported in Kotlin/Native.") 13 | } 14 | sourceSets { 15 | val nativeMain by getting { 16 | dependencies { 17 | implementation(project(":gtk-bindings")) 18 | } 19 | } 20 | } 21 | 22 | nativeTarget.apply { 23 | binaries { 24 | executable { 25 | entryPoint = "main" 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /examples/sevenguis-1-counter/src/nativeMain/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | import bindings.gtk.* 2 | import native.gtk.GtkAlign.GTK_ALIGN_CENTER 3 | import native.gtk.GtkOrientation.GTK_ORIENTATION_HORIZONTAL 4 | 5 | fun main() { 6 | val app = Application("io.quantus.gtkkn.sevenguis.counter") 7 | app.onActivate { 8 | val window = ApplicationWindow(app).apply { 9 | title = "7GUIs Counter" 10 | } 11 | 12 | var counter = 0 13 | 14 | val textField = Entry() 15 | textField.text = counter.toString() 16 | 17 | val button = Button("Count").apply { 18 | onClicked { 19 | counter++ 20 | textField.text = counter.toString() 21 | } 22 | } 23 | 24 | window.child = Box(GTK_ORIENTATION_HORIZONTAL, 10).apply { 25 | homogeneous = true 26 | valign = GTK_ALIGN_CENTER 27 | marginTop = 10 28 | marginBottom = 10 29 | marginStart = 10 30 | marginEnd = 10 31 | append(textField) 32 | append(button) 33 | } 34 | 35 | window.show() 36 | } 37 | app.run() 38 | app.unref() 39 | } 40 | 41 | -------------------------------------------------------------------------------- /examples/sevenguis-2-temperature-converter/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | } 4 | 5 | kotlin { 6 | val hostOs = System.getProperty("os.name") 7 | val isMingwX64 = hostOs.startsWith("Windows") 8 | val nativeTarget = when { 9 | hostOs == "Mac OS X" -> macosX64("native") 10 | hostOs == "Linux" -> linuxX64("native") 11 | isMingwX64 -> mingwX64("native") 12 | else -> throw GradleException("Host OS is not supported in Kotlin/Native.") 13 | } 14 | sourceSets { 15 | val nativeMain by getting { 16 | dependencies { 17 | implementation(project(":gtk-bindings")) 18 | } 19 | } 20 | } 21 | 22 | nativeTarget.apply { 23 | binaries { 24 | executable { 25 | entryPoint = "main" 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /examples/sevenguis-2-temperature-converter/src/nativeMain/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | import bindings.gtk.* 2 | import native.gtk.GtkAlign.GTK_ALIGN_CENTER 3 | import native.gtk.GtkOrientation.GTK_ORIENTATION_HORIZONTAL 4 | 5 | fun main() { 6 | val app = Application("io.quantus.gtkkn.sevenguis.temperature-converter") 7 | app.onActivate { 8 | val window = ApplicationWindow(app).apply { 9 | title = "7GUIs Temperature Converter" 10 | } 11 | 12 | val celciusField = Entry() 13 | val fahrenheitField = Entry() 14 | 15 | var isEditing = false 16 | 17 | celciusField.onChanged { 18 | if (isEditing) return@onChanged 19 | celciusField.text.toIntOrNull()?.let { c -> 20 | isEditing = true 21 | fahrenheitField.text = (c * (9 / 5.toDouble()) + 32).toInt().toString() 22 | isEditing = false 23 | } 24 | } 25 | 26 | fahrenheitField.onChanged { 27 | if (isEditing) return@onChanged 28 | fahrenheitField.text.toIntOrNull()?.let { f -> 29 | isEditing = true 30 | celciusField.text = ((f - 32) * (5 / 9.toDouble())).toInt().toString() 31 | isEditing = false 32 | } 33 | } 34 | 35 | window.child = Box(GTK_ORIENTATION_HORIZONTAL, 10).apply { 36 | homogeneous = true 37 | valign = GTK_ALIGN_CENTER 38 | marginTop = 10 39 | marginBottom = 10 40 | marginStart = 10 41 | marginEnd = 10 42 | append(celciusField) 43 | append(Label("Celcius =")) 44 | append(fahrenheitField) 45 | append(Label("Fahrenheit")) 46 | } 47 | 48 | window.show() 49 | } 50 | app.run() 51 | app.unref() 52 | } 53 | 54 | -------------------------------------------------------------------------------- /examples/sevenguis-3-flight-booker/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | } 4 | 5 | kotlin { 6 | val hostOs = System.getProperty("os.name") 7 | val isMingwX64 = hostOs.startsWith("Windows") 8 | val nativeTarget = when { 9 | hostOs == "Mac OS X" -> macosX64("native") 10 | hostOs == "Linux" -> linuxX64("native") 11 | isMingwX64 -> mingwX64("native") 12 | else -> throw GradleException("Host OS is not supported in Kotlin/Native.") 13 | } 14 | sourceSets { 15 | val nativeMain by getting { 16 | dependencies { 17 | implementation(project(":gtk-bindings")) 18 | implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0") 19 | } 20 | } 21 | } 22 | 23 | nativeTarget.apply { 24 | binaries { 25 | executable { 26 | entryPoint = "main" 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /gio-bindings/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | id("org.jetbrains.dokka") 4 | `maven-publish` 5 | } 6 | 7 | kotlin { 8 | val hostOs = System.getProperty("os.name") 9 | val isMingwX64 = hostOs.startsWith("Windows") 10 | val nativeTarget = when { 11 | hostOs == "Mac OS X" -> macosX64("native") 12 | hostOs == "Linux" -> linuxX64("native") 13 | isMingwX64 -> mingwX64("native") 14 | else -> throw GradleException("Host OS is not supported in Kotlin/Native.") 15 | } 16 | 17 | sourceSets { 18 | val nativeMain by getting { 19 | dependencies { 20 | api(project(":gobject-bindings")) 21 | } 22 | } 23 | val nativeTest by getting 24 | } 25 | 26 | nativeTarget.apply { 27 | compilations["main"].cinterops { 28 | val gio by creating 29 | } 30 | 31 | binaries { 32 | all { 33 | if (isMingwX64) { 34 | val userHome = File(System.getenv("USERPROFILE")) 35 | linkerOpts( 36 | "-L${userHome}\\.konan\\dependencies\\msys2-mingw-w64-x86_64-2\\x86_64-w64-mingw32\\lib", 37 | "-LC:\\msys64\\mingw64\\lib", 38 | ) 39 | } 40 | } 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /gio-bindings/src/nativeInterop/cinterop/gio.def: -------------------------------------------------------------------------------- 1 | headers = "gio/gio.h" 2 | package = native.gio 3 | headerFilter = "gio/*" 4 | 5 | # compiler opts 6 | 7 | compilerOpts.linux = \ 8 | -I/usr/include/glib-2.0 \ 9 | -I/usr/lib/glib-2.0/include \ 10 | -I/usr/include/sysprof-4 \ 11 | -I/usr/include/libmount \ 12 | -I/usr/include/blkid \ 13 | -pthread 14 | 15 | compilerOpts.linux_x64 = \ 16 | -I/usr/lib64/glib-2.0/include \ 17 | -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 18 | 19 | compilerOpts.mingw_x64 = \ 20 | -IC:/msys64/mingw64/include/glib-2.0 \ 21 | -IC:/msys64/mingw64/lib/glib-2.0/include \ 22 | -IC:/msys64/mingw64/include 23 | 24 | # linker opts 25 | 26 | linkerOpts.linux = \ 27 | -L/usr/local/lib \ 28 | -lgio-2.0 \ 29 | -lgobject-2.0 \ 30 | -lglib-2.0 31 | 32 | linkerOpts.linux_x64 = \ 33 | -L/usr/lib64 \ 34 | -L/usr/lib/x86_64-linux-gnu 35 | 36 | linkerOpts.mingw_x64 = \ 37 | -LC:/msys64/mingw64/lib \ 38 | -lgio-2.0 \ 39 | -lgobject-2.0 \ 40 | -lglib-2.0 \ 41 | -lintl \ 42 | -lstdc++ -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/Action.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.glib.Variant 4 | import bindings.glib.VariantType 5 | import bindings.glib.asVariant 6 | import bindings.glib.asVariantType 7 | import bindings.gobject.boolean 8 | import internal.BuiltinTypeInfo 9 | import kotlinx.cinterop.CPointer 10 | import kotlinx.cinterop.toKString 11 | import native.gio.* 12 | import native.gobject.g_free 13 | 14 | interface Action { 15 | 16 | val gActionPointer: CPointer 17 | 18 | fun activate(parameter: Variant) { 19 | g_action_activate(gActionPointer, parameter.variantPointer) 20 | } 21 | 22 | fun changeState(value: Variant) = g_action_change_state(gActionPointer, value.variantPointer) 23 | 24 | val isEnabled: Boolean 25 | get() = g_action_get_enabled(gActionPointer).boolean 26 | 27 | val name: String 28 | get() = g_action_get_name(gActionPointer)!!.toKString() 29 | 30 | val parameterType: VariantType? 31 | get() = g_action_get_parameter_type(gActionPointer)?.asVariantType() 32 | 33 | val state: Variant? 34 | get() = g_action_get_state(gActionPointer)?.asVariant() 35 | 36 | val stateHint: Variant? 37 | get() = g_action_get_state_hint(gActionPointer)?.asVariant() 38 | 39 | val stateType: VariantType? 40 | get() = g_action_get_state_type(gActionPointer)?.asVariantType() 41 | 42 | companion object { 43 | fun nameIsValid(name: String) = g_action_name_is_valid(name).boolean 44 | // TODO parseDetailedName 45 | fun printDetailedName(actionName: String, targetValue: Variant?): String { 46 | val resultPointer = g_action_print_detailed_name(actionName, targetValue?.variantPointer)!! 47 | val result = resultPointer.toKString() 48 | g_free(resultPointer) 49 | return result 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/ActionGroup.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.gobject.boolean 4 | import bindings.util.toStringList 5 | import kotlinx.cinterop.CPointer 6 | import kotlinx.cinterop.memScoped 7 | import native.gio.GActionGroup 8 | import native.gio.g_action_group_get_action_enabled 9 | import native.gio.g_action_group_has_action 10 | import native.gio.g_action_group_list_actions 11 | import native.gobject.g_strfreev 12 | 13 | interface ActionGroup { 14 | val gActionGroupPointer: CPointer 15 | 16 | fun hasAction(actionName: String): Boolean = g_action_group_has_action(gActionGroupPointer, actionName).boolean 17 | 18 | fun getActionEnabled(actionName: String): Boolean = 19 | g_action_group_get_action_enabled(gActionGroupPointer, actionName).boolean 20 | 21 | val actions: List 22 | get() = memScoped { 23 | val a = g_action_group_list_actions(gActionGroupPointer)!! 24 | val actions = a.toStringList() 25 | g_strfreev(a) 26 | actions 27 | } 28 | } -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/ActionMap.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import kotlinx.cinterop.CPointer 4 | import native.gio.GActionMap 5 | import native.gio.g_action_map_add_action 6 | import native.gio.g_action_map_lookup_action 7 | import native.gio.g_action_map_remove_action 8 | 9 | interface ActionMap { 10 | 11 | val gActionMapPointer: CPointer 12 | 13 | fun addAction(action: Action) = g_action_map_add_action(gActionMapPointer, action.gActionPointer) 14 | 15 | // TODO addActionEntries with varargs or a list 16 | 17 | fun lookupAction(actionName: String) = g_action_map_lookup_action(gActionMapPointer, actionName)?.asAction() 18 | 19 | fun removeAction(actionName: String) = g_action_map_remove_action(gActionMapPointer, actionName) 20 | } 21 | -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/ActionMapExt.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.glib.Variant 4 | 5 | fun ActionMap.addAction(actionName: String, handler: () -> Unit) = addAction(SimpleAction(actionName).apply { 6 | onActivate { handler() } 7 | }) 8 | 9 | fun ActionMap.addAction(actionName: String, handler: (Variant?) -> Unit) = addAction(SimpleAction(actionName).apply { 10 | onActivate(handler) 11 | }) -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/Application.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import bindings.gobject.boolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.sizeOf 9 | import kotlinx.cinterop.toKString 10 | import native.gio.* 11 | 12 | open class Application(pointer: CPointer<*>) : Object(pointer), ActionMap { 13 | 14 | val gApplicationPointer get() = this.gPointer.asTypedPointer() 15 | 16 | override val gActionMapPointer get() = gPointer.asTypedPointer() 17 | 18 | constructor(applicationId: String, flags: GApplicationFlags = G_APPLICATION_FLAGS_NONE) 19 | : this(g_application_new(applicationId, flags)!!) 20 | 21 | var applicationId: String? 22 | get() = g_application_get_application_id(gApplicationPointer)?.toKString() 23 | set(value) = g_application_set_application_id(gApplicationPointer, value) 24 | 25 | var flags: GApplicationFlags 26 | get() = g_application_get_flags(gApplicationPointer) 27 | set(value) = g_application_set_flags(gApplicationPointer, value) 28 | 29 | val isBusy: Boolean get() = g_application_get_is_busy(gApplicationPointer).boolean 30 | 31 | val isRegistered: Boolean get() = g_application_get_is_registered(gApplicationPointer).boolean 32 | 33 | val isRemote: Boolean get() = g_application_get_is_remote(gApplicationPointer).boolean 34 | 35 | fun markBusy() = g_application_mark_busy(gApplicationPointer) 36 | fun unmarkBusy() = g_application_unmark_busy(gApplicationPointer) 37 | 38 | fun hold() = g_application_hold(gApplicationPointer) 39 | fun release() = g_application_release(gApplicationPointer) 40 | 41 | 42 | fun run() { 43 | g_application_run(gApplicationPointer, 0, null) 44 | } 45 | 46 | /** 47 | * Start running the application. 48 | * 49 | * This method will not return until the app has quit. 50 | */ 51 | fun runApplication() { 52 | g_application_run(gApplicationPointer, 0, null) 53 | } 54 | 55 | /** 56 | * Quit the application. 57 | */ 58 | fun quit() { 59 | g_application_quit(gApplicationPointer) 60 | } 61 | 62 | companion object { 63 | val Type = BuiltinTypeInfo( 64 | G_TYPE_APPLICATION, 65 | sizeOf(), 66 | sizeOf(), 67 | ::Application 68 | ) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/Extensions.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.gio.internal.ActionMapWrapper 4 | import bindings.gio.internal.ActionWrapper 5 | import bindings.gio.internal.ListModelWrapper 6 | import kotlinx.cinterop.CPointer 7 | import native.gio.* 8 | 9 | fun CPointer.asAction(): Action = ActionWrapper(this) 10 | fun CPointer.asActionMap(): ActionMap = ActionMapWrapper(this) 11 | fun CPointer.asApplication(): Application = Application(this) 12 | fun CPointer.asListModel(): ListModel = ListModelWrapper(this) 13 | fun CPointer.asListStore(): ListStore = ListStore(this) 14 | fun CPointer.asMenu(): Menu = Menu(this) 15 | fun CPointer.asMenuItem(): MenuItem = MenuItem(this) 16 | fun CPointer.asMenuModel(): MenuModel = MenuModel(this) 17 | fun CPointer.asPermission(): Permission = Permission(this) 18 | fun CPointer.asSimplePermission(): SimplePermission = SimplePermission(this) 19 | 20 | 21 | -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/ListModel.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import kotlinx.cinterop.CPointer 4 | import native.gio.GListModel 5 | import native.gio.g_list_model_get_item_type 6 | import native.gio.g_list_model_get_n_items 7 | import native.gio.g_list_model_get_object 8 | import native.gobject.GType 9 | import native.gobject.gpointer 10 | 11 | interface ListModel { 12 | val gListModelPointer: CPointer 13 | 14 | val itemCount: Int 15 | get() = g_list_model_get_n_items(gListModelPointer).toInt() 16 | 17 | val itemType: GType 18 | get() = g_list_model_get_item_type(gListModelPointer) 19 | 20 | fun getObject(position: UInt): gpointer? { 21 | return g_list_model_get_object(gListModelPointer, position) 22 | } 23 | 24 | fun getObject(position: Int) = getObject(position.toUInt()) 25 | } 26 | -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/ListStore.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import internal.BuiltinTypeInfo 6 | import internal.KGType 7 | import kotlinx.cinterop.CPointer 8 | import native.gio.* 9 | import native.gobject.GType 10 | 11 | class ListStore : Object, ListModel { 12 | override val gListModelPointer get() = gPointer.asTypedPointer() 13 | 14 | val gListStorePointer get() = gPointer.asTypedPointer() 15 | 16 | constructor(pointer: CPointer<*>) : super(pointer) 17 | constructor(itemType: GType) : super(g_list_store_new(itemType)!!) 18 | constructor(itemType: KGType<*>) : this(itemType.gType) 19 | 20 | /** 21 | * Utility constructor for creating a listStore with initial items. 22 | * 23 | * This is the same as creating a new listStore and immediately calling [appendAll] on it. 24 | */ 25 | constructor(itemType: GType, vararg items: Object) : this(itemType) { 26 | this.appendAll(*items) 27 | } 28 | 29 | /** 30 | * Utility constructor for creating a listStore with initial items. 31 | * 32 | * This is the same as creating a new listStore and immediately calling [appendAll] on it. 33 | */ 34 | constructor(itemType: GType, items: List) : this(itemType) { 35 | this.appendAll(items) 36 | } 37 | 38 | constructor(itemType: KGType<*>, vararg items: Object) : this(itemType.gType, *items) 39 | 40 | 41 | 42 | fun append(item: Object) = g_list_store_append(gListStorePointer, item.gPointer) 43 | fun appendAll(vararg items: Object) = items.forEach { append(it) } 44 | fun appendAll(items: List) = items.forEach { append(it) } 45 | 46 | fun insert(position: Int, item: Object) = g_list_store_insert(gListStorePointer, position.toUInt(), item.gPointer) 47 | fun remove(position: Int) = g_list_store_remove(gListStorePointer, position.toUInt()) 48 | fun removeAll() = g_list_store_remove_all(gListStorePointer) 49 | 50 | // TODO insert_sorted 51 | // TODO find 52 | // TODO find_with_equal_func 53 | // TODO find_with_equal_func_full 54 | // TODO sort 55 | // TODO splice 56 | 57 | companion object { 58 | val Type = BuiltinTypeInfo(G_TYPE_LIST_STORE, ::ListStore) 59 | } 60 | } -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/Menu.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.gobject.asTypedPointer 4 | import internal.BuiltinTypeInfo 5 | import kotlinx.cinterop.CPointer 6 | import native.gio.* 7 | 8 | class Menu : MenuModel { 9 | 10 | val gMenuPointer get() = gPointer.asTypedPointer() 11 | 12 | constructor() : super(g_menu_new()!!) 13 | constructor(pointer: CPointer<*>) : super(pointer) 14 | 15 | fun append(label: String? = null, detailedAction: String? = null) = 16 | g_menu_append(gMenuPointer, label, detailedAction) 17 | 18 | fun appendItem(item: MenuItem) = g_menu_append_item(gMenuPointer, item.gMenuItemPointer) 19 | 20 | fun appendSection(label: String? = null, section: MenuModel) = 21 | g_menu_append_section(gMenuPointer, label, section.gMenuModelPointer) 22 | 23 | fun appendSubmenu(label: String? = null, submenu: MenuModel) = 24 | g_menu_append_submenu(gMenuPointer, label, submenu.gMenuModelPointer) 25 | 26 | fun freeze() = g_menu_freeze(gMenuPointer) 27 | 28 | fun insert(position: Int, label: String? = null, detailedAction: String?) = 29 | g_menu_insert(gMenuPointer, position, label, detailedAction) 30 | 31 | fun insertItem(position: Int, item: MenuItem) = g_menu_insert_item(gMenuPointer, position, item.gMenuItemPointer) 32 | 33 | fun insertSection(position: Int, label: String? = null, section: MenuModel) = 34 | g_menu_insert_section(gMenuPointer, position, label, section.gMenuModelPointer) 35 | 36 | fun insertSubmenu(position: Int, label: String? = null, submenu: MenuModel) = 37 | g_menu_insert_submenu(gMenuPointer, position, label, submenu.gMenuModelPointer) 38 | 39 | fun prepend(label: String? = null, detailedAction: String? = null) = 40 | g_menu_prepend(gMenuPointer, label, detailedAction) 41 | 42 | fun prependItem(item: MenuItem) = g_menu_prepend_item(gMenuPointer, item.gMenuItemPointer) 43 | 44 | fun prependSection(label: String? = null, section: MenuModel) = 45 | g_menu_prepend_section(gMenuPointer, label, section.gMenuModelPointer) 46 | 47 | fun prependSubmenu(label: String? = null, submenu: MenuModel) = 48 | g_menu_prepend_submenu(gMenuPointer, label, submenu.gMenuModelPointer) 49 | 50 | fun remove(position: Int) = g_menu_remove(gMenuPointer, position) 51 | fun removeAll() = g_menu_remove_all(gMenuPointer) 52 | 53 | companion object { 54 | val Type = BuiltinTypeInfo(G_TYPE_MENU, ::Menu) 55 | } 56 | } -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/MenuItem.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import internal.BuiltinTypeInfo 6 | import kotlinx.cinterop.CPointer 7 | import native.gio.* 8 | 9 | class MenuItem : Object { 10 | 11 | val gMenuItemPointer get() = gPointer.asTypedPointer() 12 | 13 | constructor(label: String? = null, detailedAction: String? = null) : super(g_menu_item_new(label, detailedAction)!!) 14 | constructor(pointer: CPointer<*>) : super(pointer) 15 | 16 | // TODO attribute property 17 | // TODO attributeValue property 18 | 19 | fun getLink(link: String): MenuModel? = g_menu_item_get_link(gMenuItemPointer, link)?.asMenuModel() 20 | fun setLink(link: String, model: MenuModel?) = 21 | g_menu_item_set_link(gMenuItemPointer, link, model?.gMenuModelPointer) 22 | 23 | // TODO setActionAndTarget with varargs? 24 | 25 | fun setDetailedAction(detailedAction: String) = g_menu_item_set_detailed_action(gMenuItemPointer, detailedAction) 26 | 27 | // TODO setIcon with GIcon 28 | 29 | fun setLabel(label: String?) = g_menu_item_set_label(gMenuItemPointer, label) 30 | 31 | fun setSection(section: MenuModel?) = g_menu_item_set_section(gMenuItemPointer, section?.gMenuModelPointer) 32 | fun setSubmenu(submenu: MenuModel?) = g_menu_item_set_submenu(gMenuItemPointer, submenu?.gMenuModelPointer) 33 | 34 | companion object { 35 | val Type = BuiltinTypeInfo(G_TYPE_MENU_ITEM, ::MenuItem) 36 | } 37 | } -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/MenuModel.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import bindings.gobject.boolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.sizeOf 9 | import native.gio.* 10 | 11 | open class MenuModel : Object { 12 | 13 | val gMenuModelPointer get() = gPointer.asTypedPointer() 14 | 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | 17 | // TODO getItemAttribute 18 | // TODO getItemAttributeValue 19 | 20 | /** 21 | * The count of items in this model. 22 | */ 23 | val itemCount: Int get() = g_menu_model_get_n_items(gMenuModelPointer) 24 | 25 | fun getItemLink(position: Int, link: String): MenuModel? = 26 | g_menu_model_get_item_link(gMenuModelPointer, position, link)?.asMenuModel() 27 | 28 | val isMutable: Boolean get() = g_menu_model_is_mutable(gMenuModelPointer).boolean 29 | 30 | fun itemsChanged(position: Int, removed: Int, added: Int) = 31 | g_menu_model_items_changed(gMenuModelPointer, position, removed, added) 32 | 33 | // TODO iterateItemAttributes 34 | // TODO iterateItemLinks 35 | 36 | 37 | companion object { 38 | val Type = BuiltinTypeInfo( 39 | G_TYPE_MENU_MODEL, 40 | sizeOf(), 41 | sizeOf(), 42 | ::MenuModel 43 | ) 44 | } 45 | } -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/Permission.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import internal.BuiltinTypeInfo 6 | import kotlinx.cinterop.CPointer 7 | import kotlinx.cinterop.sizeOf 8 | import native.gio.GPermission 9 | import native.gio.GPermissionClass 10 | import native.gio.G_TYPE_PERMISSION 11 | 12 | open class Permission : Object { 13 | val gPermissionPointer get() = gPointer.asTypedPointer() 14 | 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | 17 | // TODO implement 18 | 19 | companion object { 20 | val Type = BuiltinTypeInfo( 21 | G_TYPE_PERMISSION, 22 | sizeOf(), 23 | sizeOf(), 24 | ::Permission 25 | ) 26 | } 27 | } -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/SimpleAction.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.gio.internal.staticStableRefDestroy 4 | import bindings.glib.Variant 5 | import bindings.glib.VariantType 6 | import bindings.glib.asVariant 7 | import bindings.gobject.Object 8 | import bindings.gobject.asTypedPointer 9 | import bindings.gobject.gboolean 10 | import internal.BuiltinTypeInfo 11 | import kotlinx.cinterop.* 12 | import native.gio.* 13 | import native.gobject.GCallback 14 | import native.gobject.GVariant 15 | import native.gobject.g_signal_connect_data 16 | import native.gobject.gpointer 17 | 18 | class SimpleAction : Object, Action { 19 | 20 | override val gActionPointer get() = gPointer.asTypedPointer() 21 | val gSimpleActionPointer get() = gPointer.asTypedPointer() 22 | 23 | constructor(name: String, parameterType: VariantType? = null) : this( 24 | g_simple_action_new( 25 | name, 26 | parameterType?.variantTypePointer 27 | )!! 28 | ) 29 | 30 | constructor(name: String, parameterType: VariantType? = null, state: Variant) : this( 31 | g_simple_action_new_stateful( 32 | name, 33 | parameterType?.variantTypePointer, 34 | state.variantPointer 35 | )!! 36 | ) 37 | 38 | constructor(pointer: CPointer<*>) : super(pointer) 39 | 40 | fun setEnabled(enabled: Boolean) = g_simple_action_set_enabled(gSimpleActionPointer, enabled.gboolean) 41 | fun setState(state: Variant?) = g_simple_action_set_state(gSimpleActionPointer, state?.variantPointer) 42 | fun setStateHint(stateHint: Variant?) = g_simple_action_set_state(gSimpleActionPointer, stateHint?.variantPointer) 43 | 44 | fun onActivate(func: (parameter: Variant?) -> Unit) { 45 | g_signal_connect_data( 46 | gPointer, 47 | "activate", 48 | staticActionCallbackFunc, 49 | StableRef.create(func).asCPointer(), 50 | staticStableRefDestroy, 51 | 0 52 | ) 53 | } 54 | 55 | companion object { 56 | val Type = BuiltinTypeInfo(G_TYPE_SIMPLE_ACTION, ::SimpleAction) 57 | } 58 | } 59 | 60 | 61 | private val staticActionCallbackFunc: GCallback = 62 | staticCFunction { action: CPointer, 63 | param: CPointer, 64 | data: gpointer -> 65 | data.asStableRef<(Variant?) -> Unit>() 66 | .get() 67 | .invoke(param?.asVariant()) 68 | // TODO add param to the callback 69 | }.reinterpret() -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/SimplePermission.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.gboolean 5 | import internal.BuiltinTypeInfo 6 | import kotlinx.cinterop.CPointer 7 | import native.gio.GSimplePermission 8 | import native.gio.G_TYPE_SIMPLE_PERMISSION 9 | import native.gio.g_simple_permission_new 10 | 11 | class SimplePermission : Permission { 12 | val gtkSimplePermissionPointer get() = gPermissionPointer.asTypedPointer() 13 | 14 | constructor(pointer: CPointer<*>) : super(pointer) 15 | constructor(allowed: Boolean) : this(g_simple_permission_new(allowed.gboolean)!!) 16 | 17 | companion object { 18 | val Type = BuiltinTypeInfo(G_TYPE_SIMPLE_PERMISSION, ::SimplePermission) 19 | } 20 | } -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/internal/InterfaceWrappers.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio.internal 2 | 3 | import bindings.gio.Action 4 | import bindings.gio.ActionGroup 5 | import bindings.gio.ActionMap 6 | import bindings.gio.ListModel 7 | import bindings.gobject.asTypedPointer 8 | import kotlinx.cinterop.CPointer 9 | import native.gio.GAction 10 | import native.gio.GActionGroup 11 | import native.gio.GActionMap 12 | import native.gio.GListModel 13 | 14 | internal class ActionWrapper( 15 | override val gActionPointer: CPointer 16 | ) : Action 17 | 18 | internal class ActionMapWrapper( 19 | override val gActionMapPointer: CPointer 20 | ) : ActionMap 21 | 22 | internal class ListModelWrapper(pointer: CPointer<*>) : ListModel { 23 | override val gListModelPointer = pointer.asTypedPointer() 24 | } 25 | 26 | internal class ActionGroupWrapper(pointer: CPointer<*>) : ActionGroup { 27 | override val gActionGroupPointer = pointer.asTypedPointer() 28 | } -------------------------------------------------------------------------------- /gio-bindings/src/nativeMain/kotlin/bindings/gio/internal/Signals.kt: -------------------------------------------------------------------------------- 1 | package bindings.gio.internal 2 | 3 | import kotlinx.cinterop.asStableRef 4 | import kotlinx.cinterop.reinterpret 5 | import kotlinx.cinterop.staticCFunction 6 | import native.gobject.GClosureNotify 7 | import native.gobject.gpointer 8 | 9 | /** 10 | * Helper function that can be used as a destroy_data handler 11 | * when connecting to a signal. 12 | * 13 | * This implementation assumes [data] is a pointer to a StableRef 14 | * and calls dispose on it. 15 | */ 16 | internal val staticStableRefDestroy: GClosureNotify = 17 | staticCFunction { data: gpointer?, 18 | _: gpointer? -> 19 | data?.asStableRef()?.dispose() 20 | Unit 21 | }.reinterpret() -------------------------------------------------------------------------------- /gio-bindings/src/nativeTest/kotlin/GApplicationTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.gio.Application 2 | import kotlin.test.Test 3 | 4 | class GApplicationTest { 5 | @Test 6 | fun startApplication() { 7 | println("Starting application") 8 | val application = Application("io.quantus.testapplication") 9 | application.run() 10 | } 11 | } -------------------------------------------------------------------------------- /gio-bindings/src/nativeTest/kotlin/ListStoreTests.kt: -------------------------------------------------------------------------------- 1 | import bindings.gio.ListStore 2 | import bindings.gobject.Object 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.asObject 5 | import native.gobject.GObject 6 | import native.gobject.G_TYPE_OBJECT 7 | import kotlin.test.Test 8 | import kotlin.test.assertEquals 9 | 10 | class ListStoreTests { 11 | 12 | @Test 13 | fun createListStore() { 14 | val listStore = ListStore(G_TYPE_OBJECT) 15 | assertEquals(G_TYPE_OBJECT, listStore.itemType) 16 | 17 | val o1 = Object() 18 | val o2 = Object() 19 | val o3 = Object() 20 | 21 | listStore.appendAll(o1, o2, o3) 22 | assertEquals(3, listStore.itemCount) 23 | } 24 | 25 | @Test 26 | fun testRemove() { 27 | val listStore = ListStore(G_TYPE_OBJECT) 28 | 29 | val o1 = Object() 30 | val o2 = Object() 31 | val o3 = Object() 32 | 33 | listStore.appendAll(o1, o2, o3) 34 | listStore.remove(1) 35 | assertEquals(2, listStore.itemCount) 36 | 37 | val first = listStore.getObject(0)!!.asTypedPointer().asObject() 38 | val last = listStore.getObject(1)!!.asTypedPointer().asObject() 39 | 40 | assertEquals(o1.gPointer, first.gPointer) 41 | assertEquals(o3.gPointer, last.gPointer) 42 | 43 | listStore.removeAll() 44 | assertEquals(0, listStore.itemCount) 45 | } 46 | 47 | @Test 48 | fun testInsert() { 49 | val listStore = ListStore(G_TYPE_OBJECT) 50 | 51 | val o1 = Object() 52 | val o2 = Object() 53 | val o3 = Object() 54 | val o4 = Object() 55 | 56 | listStore.appendAll(o1, o2, o3) 57 | listStore.insert(2, o4) 58 | assertEquals(4, listStore.itemCount) 59 | 60 | val fetched = listStore.getObject(2)!!.asTypedPointer().asObject() 61 | assertEquals(o4.gPointer, fetched.gPointer) 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /gobject-bindings/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | id("org.jetbrains.dokka") 4 | `maven-publish` 5 | } 6 | 7 | kotlin { 8 | val hostOs = System.getProperty("os.name") 9 | val isMingwX64 = hostOs.startsWith("Windows") 10 | val nativeTarget = when { 11 | hostOs == "Mac OS X" -> macosX64("native") 12 | hostOs == "Linux" -> linuxX64("native") 13 | isMingwX64 -> mingwX64("native") 14 | else -> throw GradleException("Host OS is not supported in Kotlin/Native.") 15 | } 16 | 17 | sourceSets { 18 | val nativeMain by getting 19 | val nativeTest by getting 20 | } 21 | 22 | nativeTarget.apply { 23 | compilations["main"].cinterops { 24 | val gobject by creating 25 | } 26 | 27 | binaries { 28 | all { 29 | if (isMingwX64) { 30 | val userHome = File(System.getenv("USERPROFILE")) 31 | linkerOpts( 32 | "-L${userHome}\\.konan\\dependencies\\msys2-mingw-w64-x86_64-2\\x86_64-w64-mingw32\\lib", 33 | "-LC:\\msys64\\mingw64\\lib", 34 | ) 35 | } 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /gobject-bindings/src/nativeInterop/cinterop/gobject.def: -------------------------------------------------------------------------------- 1 | headers = glib-object.h 2 | package = native.gobject 3 | headerFilter = gobject/* glib/* 4 | 5 | # compiler opts 6 | 7 | compilerOpts.linux = \ 8 | -I/usr/include/glib-2.0 \ 9 | -I/usr/include/sysprof-4 \ 10 | -pthread 11 | 12 | compilerOpts.linux_x64 = \ 13 | -I/usr/lib64/glib-2.0/include \ 14 | -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 15 | 16 | compilerOpts.mingw_x64 = \ 17 | -IC:/msys64/mingw64/include \ 18 | -IC:/msys64/mingw64/lib/glib-2.0/include \ 19 | -IC:/msys64/mingw64/include/glib-2.0 \ 20 | 21 | # linker 22 | 23 | linkerOpts.linux = \ 24 | -L/usr/local/lib \ 25 | -lgobject-2.0 \ 26 | -lglib-2.0 27 | 28 | linkerOpts.linux_x64 = \ 29 | -L/usr/lib64 \ 30 | -L/usr/lib/x86_64-linux-gnu 31 | 32 | linkerOpts.mingw_x64 = \ 33 | -lgobject-2.0 \ 34 | -lglib-2.0 \ 35 | -lintl \ 36 | -lstdc++ 37 | 38 | --- 39 | 40 | typedef struct { 41 | int dispose_has_run; 42 | int test_value; 43 | void *internal_obj; 44 | } CustomObjectProperties; 45 | 46 | typedef struct { 47 | GObject parent_instance; 48 | CustomObjectProperties properties; 49 | } CustomObject; 50 | 51 | typedef struct { 52 | void *kg_type_obj; 53 | void *kg_object_class_properties; 54 | } CustomObjectClassProperties; 55 | 56 | typedef struct { 57 | GObjectClass parent_class; 58 | CustomObjectClassProperties properties; 59 | } CustomObjectClass; 60 | -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/bindings/glib/Variant.kt: -------------------------------------------------------------------------------- 1 | package bindings.glib 2 | 3 | import bindings.gobject.gboolean 4 | import kotlinx.cinterop.CPointer 5 | import native.gobject.* 6 | 7 | class Variant( 8 | val variantPointer: CPointer 9 | ) { 10 | constructor(value: Boolean) : this(g_variant_new_boolean(value.gboolean)!!) 11 | constructor(value: Int): this(g_variant_new_int32(value)!!) 12 | constructor(value: UInt) : this(g_variant_new_uint32(value)!!) 13 | constructor(value: Long): this(g_variant_new_int64(value)!!) 14 | constructor(value: ULong): this(g_variant_new_uint64(value)!!) 15 | constructor(value: String) : this(g_variant_new_string(value)!!) 16 | } 17 | 18 | fun CPointer.asVariant(): Variant = Variant(this) -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/bindings/glib/VariantType.kt: -------------------------------------------------------------------------------- 1 | package bindings.glib 2 | 3 | import kotlinx.cinterop.CPointer 4 | import native.gobject.GVariantType 5 | 6 | class VariantType( 7 | val variantTypePointer: CPointer 8 | ) { 9 | // TODO implement 10 | } 11 | 12 | fun CPointer.asVariantType(): VariantType = VariantType(this) 13 | -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/bindings/gobject/Binding.kt: -------------------------------------------------------------------------------- 1 | package bindings.gobject 2 | 3 | import kotlinx.cinterop.CPointer 4 | import kotlinx.cinterop.toKString 5 | import native.gobject.* 6 | 7 | class Binding : Object { 8 | val gBindingPointer get() = gPointer.asTypedPointer() 9 | 10 | constructor(pointer: CPointer<*>) : super(pointer) 11 | 12 | val flags: GBindingFlags 13 | get() = g_binding_get_flags(gBindingPointer) 14 | 15 | val source: Object? 16 | get() = g_binding_get_source(gBindingPointer)?.asObject() 17 | 18 | val sourceProperty: String? 19 | get() = g_binding_get_source_property(gBindingPointer)?.toKString() 20 | 21 | val target: Object? 22 | get() = g_binding_get_source(gBindingPointer)?.asObject() 23 | 24 | val targetProperty: String? 25 | get() = g_binding_get_source_property(gBindingPointer)?.toKString() 26 | 27 | fun unbind() = g_binding_unbind(gBindingPointer) 28 | 29 | } -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/bindings/gobject/Extensions.kt: -------------------------------------------------------------------------------- 1 | package bindings.gobject 2 | 3 | import internal.KGType 4 | import kotlinx.cinterop.CPointed 5 | import kotlinx.cinterop.CPointer 6 | import kotlinx.cinterop.toKString 7 | import native.gobject.* 8 | 9 | /* 10 | * Utility extensions for converting native types to Kotlin types and back. 11 | */ 12 | 13 | inline val gboolean.boolean: Boolean 14 | get() = this > 0 15 | 16 | inline val Boolean.gboolean: gboolean 17 | get() = if (this) 1 else 0 18 | 19 | /** 20 | * Convert a generic [gpointer] into a [CPointer] of the given type. 21 | */ 22 | @Suppress("UNCHECKED_CAST") 23 | inline fun gpointer.asTypedPointer() = this as CPointer 24 | 25 | /** 26 | * Convert a generic [Object] into an instance of the given type class. 27 | * 28 | * @throws Error when the object cannot be converted 29 | */ 30 | inline infix fun Object.asType(typeInfo: KGType): T { 31 | return typeInfo.instanceFromPointer(this.gPointer) 32 | } 33 | 34 | /** 35 | * Convert an [Object] instance to an instance of the given type class. 36 | * @return the converted instance, or null if the instance could not be converted 37 | */ 38 | inline fun Object.asTypeOrNull(typeInfo: KGType): T? { 39 | return typeInfo.instanceFromPointerOrNull(this.gPointer) 40 | } 41 | 42 | 43 | fun gpointer.asObject(): Object = Object(this) 44 | 45 | fun CPointer.asBinding(): Binding = Binding(this) 46 | fun CPointer.asObject(): Object = Object(this) 47 | 48 | fun CPointer.asParamSpec(): ParamSpec = ParamSpec(this) 49 | fun CPointer.asParamSpecString(): ParamSpecString = ParamSpecString(this) 50 | 51 | val GType.typeName: String get() = g_type_name(this)?.toKString() ?: "unknown" 52 | -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/bindings/gobject/ParamSpec.kt: -------------------------------------------------------------------------------- 1 | package bindings.gobject 2 | 3 | import kotlinx.cinterop.CPointer 4 | import kotlinx.cinterop.toKString 5 | import native.gobject.* 6 | 7 | open class ParamSpec : Object { 8 | val gParamSpecPointer get() = gPointer.asTypedPointer() 9 | 10 | constructor(pointer: CPointer<*>) : super(pointer) 11 | 12 | val name: String get() = g_param_spec_get_name(gParamSpecPointer)!!.toKString() 13 | val blurb: String? get() = g_param_spec_get_blurb(gParamSpecPointer)?.toKString() 14 | val nick: String? get() = g_param_spec_get_nick(gParamSpecPointer)?.toKString() 15 | 16 | } -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/bindings/gobject/ParamSpecString.kt: -------------------------------------------------------------------------------- 1 | package bindings.gobject 2 | 3 | import kotlinx.cinterop.CPointer 4 | 5 | class ParamSpecString : ParamSpec { 6 | constructor(pointer: CPointer<*>) : super(pointer) 7 | 8 | 9 | } -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/bindings/util/Util.kt: -------------------------------------------------------------------------------- 1 | package bindings.util 2 | 3 | import kotlinx.cinterop.* 4 | 5 | fun List.toCStringList(scope: MemScope): CArrayPointer>> = with(scope) { 6 | return allocArrayOf(this@toCStringList.map { it?.cstr?.getPointer(this) } + null) 7 | } 8 | 9 | fun CArrayPointer>>.toStringList(): List { 10 | var i = 0 11 | val list = mutableListOf() 12 | while (this[i] != null) { 13 | list.add(this[i]!!.toKString()) 14 | i++ 15 | } 16 | return list 17 | } 18 | -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/internal/Signals.kt: -------------------------------------------------------------------------------- 1 | package internal 2 | 3 | import kotlinx.cinterop.asStableRef 4 | import kotlinx.cinterop.reinterpret 5 | import kotlinx.cinterop.staticCFunction 6 | import native.gobject.GClosureNotify 7 | import native.gobject.gpointer 8 | 9 | /** 10 | * Helper function that can be used as a destroy_data handler 11 | * when connecting to a signal. 12 | * 13 | * This implementation assumes [data] is a pointer to a StableRef 14 | * and calls dispose on it. 15 | */ 16 | internal val staticStableRefDestroy: GClosureNotify = 17 | staticCFunction { data: gpointer?, 18 | _: gpointer? -> 19 | data?.asStableRef()?.dispose() 20 | Unit 21 | }.reinterpret() -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/internal/objectproperties/IntObjectProperty.kt: -------------------------------------------------------------------------------- 1 | package internal.objectproperties 2 | 3 | import bindings.gobject.Object 4 | import kotlinx.cinterop.CPointer 5 | import native.gobject.* 6 | import usertypes.KGObjectProperty 7 | import kotlin.reflect.KMutableProperty1 8 | 9 | class IntObjectProperty( 10 | kProperty: KMutableProperty1, 11 | name: String, 12 | nick: String?, 13 | blurb: String?, 14 | val minimum: Int, 15 | val maximum: Int, 16 | defaultValue: Int, 17 | flags: GParamFlags, 18 | ) : KGObjectProperty(name, nick, blurb, defaultValue, flags, kProperty) { 19 | override val paramSpec: CPointer get() = g_param_spec_int(name, nick, blurb, minimum, maximum, defaultValue, flags)!! 20 | 21 | override fun extractValueFromGValue(gValue: CPointer, paramSpec: CPointer): Int { 22 | return g_value_get_int(gValue) 23 | } 24 | 25 | override fun insertValueIntoGValue(value: Int, gValue: CPointer, paramSpec: CPointer) { 26 | return g_value_set_int(gValue, value) 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/internal/objectproperties/NullableStringObjectProperty.kt: -------------------------------------------------------------------------------- 1 | package internal.objectproperties 2 | 3 | import bindings.gobject.Object 4 | import kotlinx.cinterop.CPointer 5 | import kotlinx.cinterop.toKString 6 | import native.gobject.* 7 | import usertypes.KGObjectProperty 8 | import kotlin.reflect.KMutableProperty1 9 | 10 | internal class NullableStringObjectProperty( 11 | kProperty: KMutableProperty1, 12 | name: String, 13 | nick: String? = null, 14 | blurb: String? = null, 15 | defaultValue: String? = null, 16 | flags: GParamFlags = G_PARAM_READWRITE, 17 | ) : KGObjectProperty(name, nick, blurb, defaultValue, flags, kProperty) { 18 | 19 | override val paramSpec: CPointer 20 | get() = g_param_spec_string(name, nick, blurb, defaultValue, flags)!! 21 | 22 | override fun extractValueFromGValue(gValue: CPointer, paramSpec: CPointer): String? { 23 | return g_value_get_string(gValue)?.toKString() 24 | } 25 | 26 | override fun insertValueIntoGValue(value: String?, gValue: CPointer, paramSpec: CPointer) { 27 | g_value_set_string(gValue, value) 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/internal/objectproperties/ObjectClassProperties.kt: -------------------------------------------------------------------------------- 1 | package internal.objectproperties 2 | 3 | import kotlinx.cinterop.CPointer 4 | import kotlinx.cinterop.CValuesRef 5 | import native.gobject.* 6 | import usertypes.KGObjectProperty 7 | 8 | class ObjectClassProperties( 9 | private val objectClassPointer: CValuesRef 10 | ) { 11 | private var propertyIndex = 0.toUInt() 12 | private val propertyMap: MutableMap> = mutableMapOf() 13 | 14 | fun installProperty( 15 | property: KGObjectProperty<*, *> 16 | ) { 17 | propertyMap[++propertyIndex] = property 18 | 19 | val paramSpec = property.paramSpec 20 | g_object_class_install_property(objectClassPointer, propertyIndex, paramSpec) 21 | g_param_spec_unref(paramSpec) // TODO is this correct? 22 | } 23 | 24 | /** 25 | * Called by gobject when a property needs to be set 26 | */ 27 | fun setPropertyValue(thisRef: Any, propertyId: UInt, gValue: CPointer, paramSpec: CPointer) { 28 | propertyMap[propertyId]?.setPropertyValue(thisRef, gValue, paramSpec) 29 | } 30 | 31 | /** 32 | * Called by gobject when a property needs to be get 33 | */ 34 | fun getPropertyValue(thisRef: Any, propertyId: UInt, gValue: CPointer, paramSpec: CPointer) { 35 | propertyMap[propertyId]?.getPropertyValue(thisRef, gValue, paramSpec) 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/internal/objectproperties/ObjectPropertyDelegate.kt: -------------------------------------------------------------------------------- 1 | package internal.objectproperties 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import native.gobject.g_object_notify 6 | import kotlin.reflect.KProperty 7 | 8 | /** 9 | * A property delegate used for gobject properties. 10 | */ 11 | class ObjectPropertyDelegate( 12 | private val propertyName: String, 13 | defaultValue: T, 14 | ) { 15 | private var internalValue: T = defaultValue 16 | 17 | /** 18 | * Called when the user gets a value in kotlin 19 | */ 20 | operator fun getValue(thisRef: Object, property: KProperty<*>): T { 21 | return internalValue 22 | } 23 | 24 | /** 25 | * Called when the user sets a value in kotlin. 26 | * 27 | * Setting the value will trigger a gobject notify on the property. 28 | */ 29 | operator fun setValue(thisRef: Object, property: KProperty<*>, s: T) { 30 | internalValue = s 31 | g_object_notify(thisRef.gPointer.asTypedPointer(), propertyName) 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/internal/objectproperties/StringObjectProperty.kt: -------------------------------------------------------------------------------- 1 | package internal.objectproperties 2 | 3 | import bindings.gobject.Object 4 | import kotlinx.cinterop.CPointer 5 | import kotlinx.cinterop.toKString 6 | import native.gobject.* 7 | import usertypes.KGObjectProperty 8 | import kotlin.reflect.KMutableProperty1 9 | 10 | internal class StringObjectProperty( 11 | kProperty: KMutableProperty1, 12 | name: String, 13 | nick: String? = null, 14 | blurb: String? = null, 15 | defaultValue: String = "", 16 | flags: GParamFlags = G_PARAM_READWRITE, 17 | ) : KGObjectProperty(name, nick, blurb, defaultValue, flags, kProperty) { 18 | 19 | override val paramSpec: CPointer 20 | get() = g_param_spec_string(name, nick, blurb, defaultValue, flags)!! 21 | 22 | override fun extractValueFromGValue(gValue: CPointer, paramSpec: CPointer): String { 23 | return g_value_get_string(gValue)?.toKString() ?: "" 24 | } 25 | 26 | override fun insertValueIntoGValue(value: String, gValue: CPointer, paramSpec: CPointer) { 27 | g_value_set_string(gValue, value) 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /gobject-bindings/src/nativeMain/kotlin/usertypes/KGObjectProperty.kt: -------------------------------------------------------------------------------- 1 | package usertypes 2 | 3 | import bindings.gobject.Object 4 | import internal.objectproperties.ObjectPropertyDelegate 5 | import kotlinx.cinterop.CPointer 6 | import native.gobject.GParamFlags 7 | import native.gobject.GParamSpec 8 | import native.gobject.GValue 9 | import kotlin.reflect.KMutableProperty1 10 | import kotlin.reflect.KProperty 11 | 12 | abstract class KGObjectProperty( 13 | val name: String, 14 | val nick: String?, 15 | val blurb: String?, 16 | val defaultValue: PARAM_TYPE, 17 | val flags: GParamFlags, 18 | private val kProperty: KMutableProperty1 19 | ) { 20 | 21 | protected val initialValue: PARAM_TYPE = defaultValue 22 | 23 | abstract val paramSpec: CPointer 24 | 25 | abstract fun extractValueFromGValue(gValue: CPointer, paramSpec: CPointer): PARAM_TYPE 26 | abstract fun insertValueIntoGValue(value: PARAM_TYPE, gValue: CPointer, paramSpec: CPointer) 27 | 28 | operator fun provideDelegate(thisRef: Object, property: KProperty<*>): ObjectPropertyDelegate { 29 | return ObjectPropertyDelegate(name, defaultValue) 30 | } 31 | 32 | @Suppress("UNCHECKED_CAST") 33 | fun getPropertyValue(thisRef: Any, gValue: CPointer, paramSpec: CPointer) { 34 | val value = kProperty.getValue(thisRef as OBJECT_TYPE, kProperty) 35 | insertValueIntoGValue(value, gValue, paramSpec) 36 | } 37 | 38 | @Suppress("UNCHECKED_CAST") 39 | fun setPropertyValue(thisRef: Any, gValue: CPointer, paramSpec: CPointer) { 40 | kProperty.setValue(thisRef as OBJECT_TYPE, kProperty, extractValueFromGValue(gValue, paramSpec)) 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /gobject-bindings/src/nativeTest/kotlin/CustomObjectTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.gobject.Object 2 | import bindings.gobject.ObjectCompanion 3 | import bindings.gobject.boolean 4 | import kotlinx.cinterop.CPointer 5 | import kotlinx.cinterop.reinterpret 6 | import native.gobject.g_type_check_instance_is_a 7 | import kotlin.test.Test 8 | import kotlin.test.assertEquals 9 | import kotlin.test.assertFalse 10 | import kotlin.test.assertTrue 11 | 12 | class CustomObjectTest { 13 | 14 | @Test 15 | fun testCustomObjectCreation() { 16 | val o = MyCustomObject() 17 | assertEquals("", o.name) 18 | assertTrue(g_type_check_instance_is_a(o.gPointer.reinterpret(), MyCustomObject.Type.gType).boolean) 19 | assertTrue(g_type_check_instance_is_a(o.gPointer.reinterpret(), Object.Type.gType).boolean) 20 | assertFalse(g_type_check_instance_is_a(o.gPointer.reinterpret(), AnotherClass.Type.gType).boolean) 21 | } 22 | 23 | @Test 24 | fun testCustomObjectCreationWithName() { 25 | val o = MyCustomObject("Steven") 26 | assertEquals("Steven", o.name) 27 | } 28 | 29 | @Test 30 | fun testCustomObjectFromPointer() { 31 | val o = MyCustomObject("Steven") 32 | assertEquals("Steven", o.name) 33 | 34 | val pointer = o.gPointer 35 | 36 | val anotherObject = MyCustomObject.instanceFromPointer(pointer) 37 | assertEquals("Steven", anotherObject.name) 38 | } 39 | 40 | } 41 | 42 | private class MyCustomObject : Object { 43 | var name: String = "" 44 | 45 | constructor(pointer: CPointer<*>) : super(pointer) 46 | 47 | constructor() : this(newInstancePointer()) 48 | 49 | constructor(name: String) : this() { 50 | this.name = name 51 | } 52 | 53 | companion object : ObjectCompanion() { 54 | override val typeName = "MyCustomObject" 55 | override val parentType = Object.Type 56 | } 57 | } 58 | 59 | private class AnotherClass : Object { 60 | constructor(pointer: CPointer<*>) : super(pointer) 61 | 62 | companion object : ObjectCompanion() { 63 | override val typeName = "AnotherClass" 64 | override val parentType = Object.Type 65 | } 66 | } -------------------------------------------------------------------------------- /gobject-bindings/src/nativeTest/kotlin/GObjectTests.kt: -------------------------------------------------------------------------------- 1 | import kotlin.test.Test 2 | 3 | class GObjectTests { 4 | @Test 5 | fun test() { 6 | println("Creating new gobject") 7 | val obj = bindings.gobject.Object() 8 | println(obj) 9 | println(obj.gPointer) 10 | } 11 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | kotlin.mpp.stability.nowarn=true 3 | kotlin.native.ignoreDisabledTargets=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vbsteven/gtk-kotlin-native/af5f6c9d32498b6e791a92503dfb45ebfd1af6c3/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gtk-bindings/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | id("org.jetbrains.dokka") 4 | `maven-publish` 5 | } 6 | 7 | kotlin { 8 | val hostOs = System.getProperty("os.name") 9 | val isMingwX64 = hostOs.startsWith("Windows") 10 | val nativeTarget = when { 11 | hostOs == "Mac OS X" -> macosX64("native") 12 | hostOs == "Linux" -> linuxX64("native") 13 | isMingwX64 -> mingwX64("native") 14 | else -> throw GradleException("Host OS is not supported in Kotlin/Native.") 15 | } 16 | 17 | sourceSets { 18 | val nativeMain by getting { 19 | dependencies { 20 | api(project(":gobject-bindings")) 21 | api(project(":gio-bindings")) 22 | } 23 | } 24 | val nativeTest by getting 25 | } 26 | 27 | // native main for testing 28 | nativeTarget.apply { 29 | compilations["main"].cinterops { 30 | val gtk by creating 31 | } 32 | 33 | binaries { 34 | all { 35 | if (isMingwX64) { 36 | val userHome = File(System.getenv("USERPROFILE")) 37 | linkerOpts( 38 | "-L${userHome}\\.konan\\dependencies\\msys2-mingw-w64-x86_64-2\\x86_64-w64-mingw32\\lib", 39 | "-LC:\\msys64\\mingw64\\lib", 40 | ) 41 | } 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeInterop/cinterop/gtk.def: -------------------------------------------------------------------------------- 1 | headers = gtk/gtk.h 2 | package = native.gtk 3 | headerFilter = gtk/* gdk/* 4 | 5 | # compiler 6 | 7 | compilerOpts.linux = \ 8 | -I/usr/include \ 9 | -I/usr/include/gtk-4.0 \ 10 | -I/usr/include/pango-1.0 \ 11 | -I/usr/include/glib-2.0 \ 12 | -I/usr/lib/glib-2.0/include \ 13 | -I/usr/include/sysprof-4 \ 14 | -I/usr/include/harfbuzz \ 15 | -I/usr/include/freetype2 \ 16 | -I/usr/include/libpng16 \ 17 | -I/usr/include/libmount \ 18 | -I/usr/include/blkid \ 19 | -I/usr/include/fribidi \ 20 | -I/usr/include/cairo \ 21 | -I/usr/include/lzo \ 22 | -I/usr/include/pixman-1 \ 23 | -I/usr/include/gdk-pixbuf-2.0 \ 24 | -I/usr/include/graphene-1.0 \ 25 | -I/usr/lib/graphene-1.0/include \ 26 | -mfpmath=sse \ 27 | -msse \ 28 | -msse2 \ 29 | -pthread 30 | 31 | compilerOpts.linux_x64 = \ 32 | -I/usr/lib64/glib-2.0/include \ 33 | -I/usr/lib64/graphene-1.0/include \ 34 | -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \ 35 | -I/usr/lib/x86_64-linux-gnu/graphene-1.0/include 36 | 37 | compilerOpts.mingw_x64 = \ 38 | -IC:/msys64/mingw64/include \ 39 | -IC:/msys64/mingw64/include/gtk-4.0 \ 40 | -IC:/msys64/mingw64/include/pango-1.0 \ 41 | -IC:/msys64/mingw64/include/glib-2.0 \ 42 | -IC:/msys64/mingw64/lib/glib-2.0/include \ 43 | -IC:/msys64/mingw64/include/harfbuzz \ 44 | -IC:/msys64/mingw64/include/libpng16 \ 45 | -IC:/msys64/mingw64/include/fribidi \ 46 | -IC:/msys64/mingw64/include/cairo \ 47 | -IC:/msys64/mingw64/include/lzo \ 48 | -IC:/msys64/mingw64/include/pixman-1 \ 49 | -IC:/msys64/mingw64/include/gdk-pixbuf-2.0 \ 50 | -DLIBDEFLATE_DLL \ 51 | -IC:/msys64/mingw64/include/graphene-1.0 \ 52 | -IC:/msys64/mingw64/lib/graphene-1.0/include \ 53 | -mfpmath=sse \ 54 | -msse \ 55 | -msse2 \ 56 | 57 | # linker 58 | 59 | linkerOpts.linux = \ 60 | -L/usr/lib \ 61 | -lgtk-4 \ 62 | -lpangocairo-1.0 \ 63 | -lpango-1.0 \ 64 | -lharfbuzz \ 65 | -lgdk_pixbuf-2.0 \ 66 | -lcairo-gobject \ 67 | -lcairo \ 68 | -lgraphene-1.0 \ 69 | -lgio-2.0 \ 70 | -lgobject-2.0 \ 71 | -lglib-2.0 72 | 73 | linkerOpts.linux_x64 = \ 74 | -L/usr/lib64 \ 75 | -L/usr/lib/x86_64-linux-gnu 76 | 77 | linkerOpts.mingw_x64 = \ 78 | -LC:/msys64/mingw64/lib \ 79 | -lgtk-4 \ 80 | -lpangowin32-1.0 \ 81 | -lpangocairo-1.0 \ 82 | -lpango-1.0 \ 83 | -lharfbuzz \ 84 | -lgdk_pixbuf-2.0 \ 85 | -lcairo-gobject \ 86 | -lcairo \ 87 | -lgraphene-1.0 \ 88 | -lgio-2.0 \ 89 | -lgobject-2.0 \ 90 | -lglib-2.0 \ 91 | -lintl \ 92 | -lstdc++ -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Actionable.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.glib.Variant 4 | import bindings.glib.asVariant 5 | import kotlinx.cinterop.CPointer 6 | import kotlinx.cinterop.toKString 7 | import native.gtk.* 8 | 9 | interface Actionable { 10 | 11 | val gtkActionablePointer: CPointer 12 | 13 | var actionName: String? 14 | get() = gtk_actionable_get_action_name(gtkActionablePointer)?.toKString() 15 | set(value) = gtk_actionable_set_action_name(gtkActionablePointer, value) 16 | 17 | var actionTarget: Variant? 18 | get() = gtk_actionable_get_action_target_value(gtkActionablePointer)?.asVariant() 19 | set(value) = gtk_actionable_set_action_target_value(gtkActionablePointer, value?.variantPointer) 20 | 21 | fun setDetailedActionName(detailedActionName: String) { 22 | gtk_actionable_set_detailed_action_name(gtkActionablePointer, detailedActionName) 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Adjustment.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import kotlinx.cinterop.CPointer 6 | import native.gtk.* 7 | 8 | class Adjustment : Object { 9 | val gtkAdjustmentPointer get() = gPointer.asTypedPointer() 10 | 11 | constructor(pointer: CPointer<*>) : super(pointer) 12 | constructor( 13 | value: Double, 14 | lower: Double, 15 | upper: Double, 16 | stepIncrement: Double, 17 | pageIncrement: Double, 18 | pageSize: Double 19 | ) : this(gtk_adjustment_new(value, lower, upper, stepIncrement, pageIncrement, pageSize)!!) 20 | 21 | fun clampPage(lower: Double, upper: Double) = gtk_adjustment_clamp_page(gtkAdjustmentPointer, lower, upper) 22 | 23 | fun configure( 24 | value: Double, 25 | lower: Double, 26 | upper: Double, 27 | stepIncrement: Double, 28 | pageIncrement: Double, 29 | pageSize: Double 30 | ) = gtk_adjustment_configure(gtkAdjustmentPointer, value, lower, upper, stepIncrement, pageIncrement, pageSize) 31 | 32 | var lower: Double 33 | get() = gtk_adjustment_get_lower(gtkAdjustmentPointer) 34 | set(value) = gtk_adjustment_set_lower(gtkAdjustmentPointer, value) 35 | 36 | var upper: Double 37 | get() = gtk_adjustment_get_upper(gtkAdjustmentPointer) 38 | set(value) = gtk_adjustment_set_upper(gtkAdjustmentPointer, value) 39 | 40 | var value: Double 41 | get() = gtk_adjustment_get_value(gtkAdjustmentPointer) 42 | set(value) = gtk_adjustment_set_value(gtkAdjustmentPointer, value) 43 | 44 | var stepIncrement: Double 45 | get() = gtk_adjustment_get_step_increment(gtkAdjustmentPointer) 46 | set(value) = gtk_adjustment_set_step_increment(gtkAdjustmentPointer, value) 47 | 48 | var pageIncrement: Double 49 | get() = gtk_adjustment_get_page_increment(gtkAdjustmentPointer) 50 | set(value) = gtk_adjustment_set_page_increment(gtkAdjustmentPointer, value) 51 | 52 | var pageSize: Double 53 | get() = gtk_adjustment_get_page_size(gtkAdjustmentPointer) 54 | set(value) = gtk_adjustment_set_page_size(gtkAdjustmentPointer, value) 55 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/ApplicationWindow.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gio.ActionMap 4 | import bindings.gobject.asTypedPointer 5 | import bindings.gobject.boolean 6 | import bindings.gobject.gboolean 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.CPointer 9 | import kotlinx.cinterop.sizeOf 10 | import native.gio.GActionMap 11 | import native.gtk.* 12 | 13 | open class ApplicationWindow : Window, ActionMap { 14 | 15 | val gtkApplicationWindowPointer get() = gtkWindowPointer.asTypedPointer() 16 | 17 | override val gActionMapPointer get() = gtkWindowPointer.asTypedPointer() 18 | 19 | constructor(pointer: CPointer<*>) : super(pointer) 20 | constructor(application: Application) : this(gtk_application_window_new(application.gtkApplicationPointer)!!) 21 | 22 | val id: UInt get() = gtk_application_window_get_id(gtkApplicationWindowPointer) 23 | 24 | // TODO helpOverlay property as GtkShortcutsWindow 25 | 26 | var showMenubar: Boolean 27 | get() = gtk_application_window_get_show_menubar(gtkApplicationWindowPointer).boolean 28 | set(value) = gtk_application_window_set_show_menubar(gtkApplicationWindowPointer, value.gboolean) 29 | 30 | companion object { 31 | val Type = BuiltinTypeInfo( 32 | GTK_TYPE_APPLICATION_WINDOW, 33 | sizeOf(), 34 | sizeOf(), 35 | ::ApplicationWindow 36 | ) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/AspectFrame.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import native.gtk.* 9 | 10 | class AspectFrame : Widget { 11 | val gtkAspectFramePointer get() = gtkWidgetPointer.asTypedPointer() 12 | 13 | constructor(pointer: CPointer<*>) : super(pointer) 14 | constructor( 15 | xalign: Float, 16 | yalign: Float, 17 | ratio: Float, 18 | obeyChild: Boolean 19 | ) : this(gtk_aspect_frame_new(xalign, yalign, ratio, obeyChild.gboolean)!!) 20 | 21 | var child: Widget? 22 | get() = gtk_aspect_frame_get_child(gtkAspectFramePointer)?.asWidget() 23 | set(value) = gtk_aspect_frame_set_child(gtkAspectFramePointer, value?.gtkWidgetPointer) 24 | 25 | var obeyChild: Boolean 26 | get() = gtk_aspect_frame_get_obey_child(gtkAspectFramePointer).boolean 27 | set(value) = gtk_aspect_frame_set_obey_child(gtkAspectFramePointer, value.gboolean) 28 | 29 | var ratio: Float 30 | get() = gtk_aspect_frame_get_ratio(gtkAspectFramePointer) 31 | set(value) = gtk_aspect_frame_set_ratio(gtkAspectFramePointer, value) 32 | 33 | var xalign: Float 34 | get() = gtk_aspect_frame_get_xalign(gtkAspectFramePointer) 35 | set(value) = gtk_aspect_frame_set_xalign(gtkAspectFramePointer, value) 36 | 37 | var yalign: Float 38 | get() = gtk_aspect_frame_get_yalign(gtkAspectFramePointer) 39 | set(value) = gtk_aspect_frame_set_yalign(gtkAspectFramePointer, value) 40 | 41 | companion object { 42 | val Type = BuiltinTypeInfo(GTK_TYPE_ASPECT_FRAME, ::AspectFrame) 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Border.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | data class Border( 4 | val left: Short, 5 | val right: Short, 6 | val top: Short, 7 | val bottom: Short 8 | ) -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Box.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.sizeOf 9 | import native.gtk.* 10 | 11 | open class Box : Widget, Orientable { 12 | 13 | val gtkBoxPointer get() = gtkWidgetPointer.asTypedPointer() 14 | 15 | override val gtkOrientablePointer get() = gtkBoxPointer.asTypedPointer() 16 | 17 | constructor(pointer: CPointer<*>) : super(pointer) 18 | 19 | constructor(orientation: GtkOrientation, spacing: Int) : this(gtk_box_new(orientation, spacing)!!) 20 | 21 | fun append(child: Widget) = gtk_box_append(gtkBoxPointer, child.gtkWidgetPointer) 22 | fun appendAll(vararg children: Widget) = children.forEach(::append) 23 | fun appendAll(children: List) = children.forEach(::append) 24 | 25 | fun prepend(child: Widget) = gtk_box_prepend(gtkBoxPointer, child.gtkWidgetPointer) 26 | fun remove(child: Widget) = gtk_box_remove(gtkBoxPointer, child.gtkWidgetPointer) 27 | fun reorderChildAfter(child: Widget, sibling: Widget?) = 28 | gtk_box_reorder_child_after(gtkBoxPointer, child.gtkWidgetPointer, sibling?.gtkWidgetPointer) 29 | 30 | var baselinePosition: GtkBaselinePosition 31 | get() = gtk_box_get_baseline_position(gtkBoxPointer) 32 | set(value) = gtk_box_set_baseline_position(gtkBoxPointer, value) 33 | 34 | var homogeneous: Boolean 35 | get() = gtk_box_get_homogeneous(gtkBoxPointer).boolean 36 | set(value) = gtk_box_set_homogeneous(gtkBoxPointer, value.gboolean) 37 | 38 | var spacing: Int 39 | get() = gtk_box_get_spacing(gtkBoxPointer) 40 | set(value) = gtk_box_set_spacing(gtkBoxPointer, value) 41 | 42 | companion object { 43 | val Type = BuiltinTypeInfo( 44 | GTK_TYPE_BOX, 45 | sizeOf(), 46 | sizeOf(), 47 | ::Box 48 | ) 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/CenterBox.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import internal.BuiltinTypeInfo 5 | import kotlinx.cinterop.CPointer 6 | import native.gtk.* 7 | 8 | class CenterBox : Widget { 9 | val gtkCenterBoxPointer get() = gtkWidgetPointer.asTypedPointer() 10 | 11 | constructor(pointer: CPointer<*>) : super(pointer) 12 | constructor() : this(gtk_center_box_new()!!) 13 | 14 | var baselinePosition: GtkBaselinePosition 15 | get() = gtk_center_box_get_baseline_position(gtkCenterBoxPointer) 16 | set(value) = gtk_center_box_set_baseline_position(gtkCenterBoxPointer, value) 17 | 18 | var centerWidget: Widget? 19 | get() = gtk_center_box_get_center_widget(gtkCenterBoxPointer)?.asWidget() 20 | set(value) = gtk_center_box_set_center_widget(gtkCenterBoxPointer, value?.gtkWidgetPointer) 21 | 22 | var startWidget: Widget? 23 | get() = gtk_center_box_get_start_widget(gtkCenterBoxPointer)?.asWidget() 24 | set(value) = gtk_center_box_set_start_widget(gtkCenterBoxPointer, value?.gtkWidgetPointer) 25 | 26 | var endWidget: Widget? 27 | get() = gtk_center_box_get_end_widget(gtkCenterBoxPointer)?.asWidget() 28 | set(value) = gtk_center_box_set_end_widget(gtkCenterBoxPointer, value?.gtkWidgetPointer) 29 | 30 | companion object { 31 | val Type = BuiltinTypeInfo(GTK_TYPE_CENTER_BOX, ::CenterBox) 32 | } 33 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/EntryBuffer.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import internal.BuiltinTypeInfo 6 | import kotlinx.cinterop.CPointer 7 | import kotlinx.cinterop.sizeOf 8 | import kotlinx.cinterop.toKString 9 | import native.gtk.* 10 | 11 | open class EntryBuffer : Object { 12 | 13 | val gtkEntryBufferPointer get() = gPointer.asTypedPointer() 14 | 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | 17 | constructor(initialText: String? = null) : this(gtk_entry_buffer_new(initialText, initialText?.length ?: -1)!!) 18 | 19 | var text: String 20 | get() = gtk_entry_buffer_get_text(gtkEntryBufferPointer)?.toKString() ?: "" 21 | set(value) = gtk_entry_buffer_set_text(gtkEntryBufferPointer, value, value.length) 22 | 23 | var maxLength: Int 24 | get() = gtk_entry_buffer_get_max_length(gtkEntryBufferPointer) 25 | set(value) = gtk_entry_buffer_set_max_length(gtkEntryBufferPointer, value) 26 | 27 | fun insertText(position: Int, text: String, count: Int = text.length) = 28 | gtk_entry_buffer_insert_text(gtkEntryBufferPointer, position.toUInt(), text, count).toInt() 29 | 30 | fun deleteText(position: Int, count: Int) = 31 | gtk_entry_buffer_delete_text(gtkEntryBufferPointer, position.toUInt(), count).toInt() 32 | 33 | fun emitDeletedText(position: Int, count: Int) = 34 | gtk_entry_buffer_emit_deleted_text(gtkEntryBufferPointer, position.toUInt(), count.toUInt()) 35 | 36 | fun emitInsertedText(position: Int, text: String, count: Int) = 37 | gtk_entry_buffer_emit_inserted_text(gtkEntryBufferPointer, position.toUInt(), text, count.toUInt()) 38 | 39 | val bytes: Long 40 | get() = gtk_entry_buffer_get_bytes(gtkEntryBufferPointer).toLong() 41 | 42 | val length: Int 43 | get() = gtk_entry_buffer_get_length(gtkEntryBufferPointer).toInt() 44 | 45 | companion object { 46 | val Type = BuiltinTypeInfo( 47 | GTK_TYPE_ENTRY_BUFFER, 48 | sizeOf(), 49 | sizeOf(), 50 | ::EntryBuffer 51 | ) 52 | } 53 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/GridView.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import native.gtk.* 9 | 10 | class GridView : ListBase { 11 | 12 | val gtkGridViewPointer get() = gtkWidgetPointer.asTypedPointer() 13 | 14 | constructor(pointer: CPointer<*>) : super(pointer) 15 | constructor( 16 | model: SelectionModel? = null, 17 | factory: ListItemFactory? = null 18 | ) : this(gtk_grid_view_new(model?.gtkSelectionModelPointer, factory?.gtkListItemFactoryPointer)!!) 19 | 20 | 21 | var enableRubberband: Boolean 22 | get() = gtk_grid_view_get_enable_rubberband(gtkGridViewPointer).boolean 23 | set(value) = gtk_grid_view_set_enable_rubberband(gtkGridViewPointer, value.gboolean) 24 | 25 | var factory: ListItemFactory? 26 | get() = gtk_grid_view_get_factory(gtkGridViewPointer)?.asListItemFactory() 27 | set(value) = gtk_grid_view_set_factory(gtkGridViewPointer, value?.gtkListItemFactoryPointer) 28 | 29 | var model: SelectionModel? 30 | get() = gtk_grid_view_get_model(gtkGridViewPointer)?.asSelectionModel() 31 | set(value) = gtk_grid_view_set_model(gtkGridViewPointer, value?.gtkSelectionModelPointer) 32 | 33 | var singleClickActivate: Boolean 34 | get() = gtk_grid_view_get_single_click_activate(gtkGridViewPointer).boolean 35 | set(value) = gtk_grid_view_set_single_click_activate(gtkGridViewPointer, value.gboolean) 36 | 37 | var minColumns: Int 38 | get() = gtk_grid_view_get_min_columns(gtkGridViewPointer).toInt() 39 | set(value) = gtk_grid_view_set_min_columns(gtkGridViewPointer, value.toUInt()) 40 | 41 | var maxColumns: Int 42 | get() = gtk_grid_view_get_max_columns(gtkGridViewPointer).toInt() 43 | set(value) = gtk_grid_view_set_max_columns(gtkGridViewPointer, value.toUInt()) 44 | 45 | companion object { 46 | val Type = BuiltinTypeInfo(GTK_TYPE_GRID_VIEW, ::GridView) 47 | } 48 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/HeaderBar.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.toKString 9 | import native.gtk.* 10 | 11 | class HeaderBar : Widget { 12 | 13 | val gtkHeaderBarPointer get() = gPointer.asTypedPointer() 14 | 15 | constructor() : super(gtk_header_bar_new()!!) 16 | constructor(pointer: CPointer<*>) : super(pointer) 17 | 18 | var titleWidget: Widget? 19 | get() = gtk_header_bar_get_title_widget(gtkHeaderBarPointer)?.asWidget() 20 | set(value) = gtk_header_bar_set_title_widget(gtkHeaderBarPointer, value?.gtkWidgetPointer) 21 | 22 | var decorationLayout: String? 23 | get() = gtk_header_bar_get_decoration_layout(gtkHeaderBarPointer)?.toKString() 24 | set(value) = gtk_header_bar_set_decoration_layout(gtkHeaderBarPointer, value) 25 | 26 | var showTitleButtons: Boolean 27 | get() = gtk_header_bar_get_show_title_buttons(gtkHeaderBarPointer).boolean 28 | set(value) = gtk_header_bar_set_show_title_buttons(gtkHeaderBarPointer, value.gboolean) 29 | 30 | /** 31 | * Add [widget] to the end of the bar. 32 | */ 33 | fun packEnd(widget: Widget) = gtk_header_bar_pack_end(gtkHeaderBarPointer, widget.gtkWidgetPointer) 34 | 35 | /** 36 | * Add [widget] to the start of the bar 37 | */ 38 | fun packStart(widget: Widget) = gtk_header_bar_pack_start(gtkHeaderBarPointer, widget.gtkWidgetPointer) 39 | 40 | /** 41 | * Remove [widget] from the bar 42 | */ 43 | fun remove(widget: Widget) = gtk_header_bar_remove(gtkHeaderBarPointer, widget.gtkWidgetPointer) 44 | 45 | companion object { 46 | val Type = BuiltinTypeInfo(GTK_TYPE_HEADER_BAR, ::HeaderBar) 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Image.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import internal.BuiltinTypeInfo 5 | import kotlinx.cinterop.CPointer 6 | import kotlinx.cinterop.toKString 7 | import native.gtk.* 8 | 9 | class Image : Widget { 10 | val gtkImagePointer get() = gtkWidgetPointer.asTypedPointer() 11 | 12 | constructor(pointer: CPointer<*>) : super(pointer) 13 | constructor() : this(gtk_image_new()!!) 14 | 15 | fun clear() = gtk_image_clear(gtkImagePointer) 16 | 17 | 18 | var iconName: String? 19 | get() = gtk_image_get_icon_name(gtkImagePointer)?.toKString() 20 | set(value) = gtk_image_set_from_icon_name(gtkImagePointer, value) 21 | 22 | fun setResourcePath(resourcePath: String) = gtk_image_set_from_resource(gtkImagePointer, resourcePath) 23 | 24 | var iconSize: GtkIconSize 25 | get() = gtk_image_get_icon_size(gtkImagePointer) 26 | set(value) = gtk_image_set_icon_size(gtkImagePointer, value) 27 | 28 | var pixelSize: Int 29 | get() = gtk_image_get_pixel_size(gtkImagePointer) 30 | set(value) = gtk_image_set_pixel_size(gtkImagePointer, value) 31 | 32 | val storageType: GtkImageType = gtk_image_get_storage_type(gtkImagePointer) 33 | 34 | // TODO add gicon property and constructor 35 | // TODO add paintable property and constructor 36 | // TODO add pixbuf property 37 | 38 | companion object { 39 | fun newFromFile(fileName: String) = Image(gtk_image_new_from_file(fileName)!!) 40 | fun newFromIconName(iconName: String) = Image(gtk_image_new_from_icon_name(iconName)!!) 41 | fun newFromResource(resourcePath: String) = Image(gtk_image_new_from_resource(resourcePath)!!) 42 | 43 | val Type = BuiltinTypeInfo(GTK_TYPE_IMAGE, ::Image) 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/LevelBar.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.* 8 | import native.gtk.* 9 | 10 | class LevelBar : Widget { 11 | val gtkLevelBarPointer get() = gtkWidgetPointer.asTypedPointer() 12 | 13 | constructor(pointer: CPointer<*>) : super(pointer) 14 | constructor() : this(gtk_level_bar_new()!!) 15 | constructor(minValue: Double, maxValue: Double) : this(gtk_level_bar_new_for_interval(minValue, maxValue)!!) 16 | 17 | var inverted: Boolean 18 | get() = gtk_level_bar_get_inverted(gtkLevelBarPointer).boolean 19 | set(value) = gtk_level_bar_set_inverted(gtkLevelBarPointer, value.gboolean) 20 | 21 | var maxValue: Double 22 | get() = gtk_level_bar_get_max_value(gtkLevelBarPointer) 23 | set(value) = gtk_level_bar_set_max_value(gtkLevelBarPointer, value) 24 | 25 | var minValue: Double 26 | get() = gtk_level_bar_get_min_value(gtkLevelBarPointer) 27 | set(value) = gtk_level_bar_set_min_value(gtkLevelBarPointer, value) 28 | 29 | var mode: GtkLevelBarMode 30 | get() = gtk_level_bar_get_mode(gtkLevelBarPointer) 31 | set(value) = gtk_level_bar_set_mode(gtkLevelBarPointer, value) 32 | 33 | var value: Double 34 | get() = gtk_level_bar_get_value(gtkLevelBarPointer) 35 | set(value) = gtk_level_bar_set_value(gtkLevelBarPointer, value) 36 | 37 | fun addOffsetValue(name: String, value: Double) = gtk_level_bar_add_offset_value(gtkLevelBarPointer, name, value) 38 | 39 | fun getOffsetValue(name: String): Double? = memScoped { 40 | val value = alloc() 41 | val success = gtk_level_bar_get_offset_value(gtkLevelBarPointer, name, value.ptr).boolean 42 | return if (success) value.value else null 43 | } 44 | 45 | fun removeOffsetValue(name: String) = gtk_level_bar_remove_offset_value(gtkLevelBarPointer, name) 46 | 47 | // TODO offset-changed signal 48 | 49 | companion object { 50 | val Type = BuiltinTypeInfo(GTK_TYPE_LEVEL_BAR, ::LevelBar) 51 | } 52 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/LinkButton.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.toKString 9 | import native.gtk.* 10 | 11 | class LinkButton : Button { 12 | val gtkLinkButtonPointer get() = gtkWidgetPointer.asTypedPointer() 13 | 14 | constructor(pointer: CPointer<*>) : super(pointer) 15 | constructor(uri: String) : this(gtk_link_button_new(uri)!!) 16 | constructor(uri: String, label: String) : this(gtk_link_button_new_with_label(uri, label)!!) 17 | 18 | var uri: String 19 | get() = gtk_link_button_get_uri(gtkLinkButtonPointer)!!.toKString() 20 | set(value) = gtk_link_button_set_uri(gtkLinkButtonPointer, value) 21 | 22 | var visited: Boolean 23 | get() = gtk_link_button_get_visited(gtkLinkButtonPointer).boolean 24 | set(value) = gtk_link_button_set_visited(gtkLinkButtonPointer, value.gboolean) 25 | 26 | // TODO activate-link signal with ability to return a boolean 27 | 28 | companion object { 29 | val Type = BuiltinTypeInfo(GTK_TYPE_LINK_BUTTON, ::LinkButton) 30 | } 31 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/ListBase.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import kotlinx.cinterop.CPointer 5 | import native.gtk.GtkOrientable 6 | import native.gtk.GtkScrollable 7 | 8 | open class ListBase : Widget, Orientable, Scrollable { 9 | override val gtkOrientablePointer get() = gtkWidgetPointer.asTypedPointer() 10 | override val gtkScrollablePointer get() = gtkWidgetPointer.asTypedPointer() 11 | 12 | constructor(pointer: CPointer<*>) : super(pointer) 13 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/ListBox.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import native.gtk.* 9 | 10 | class ListBox : Widget { 11 | 12 | val gtkListBoxPointer get() = gPointer.asTypedPointer() 13 | 14 | constructor() : super(gtk_list_box_new()!!) 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | 17 | var selectionMode: GtkSelectionMode 18 | get() = gtk_list_box_get_selection_mode(gtkListBoxPointer) 19 | set(value) = gtk_list_box_set_selection_mode(gtkListBoxPointer, value) 20 | 21 | var showSeparators: Boolean 22 | get() = gtk_list_box_get_show_separators(gtkListBoxPointer).boolean 23 | set(value) = gtk_list_box_set_show_separators(gtkListBoxPointer, value.gboolean) 24 | 25 | var activateOnSingleClick: Boolean 26 | get() = gtk_list_box_get_activate_on_single_click(gtkListBoxPointer).boolean 27 | set(value) = gtk_list_box_set_activate_on_single_click(gtkListBoxPointer, value.gboolean) 28 | 29 | // TODO add adjustment :: GtkAdjustment 30 | 31 | fun append(widget: Widget) = gtk_list_box_append(gtkListBoxPointer, widget.gtkWidgetPointer) 32 | fun appendAll(vararg widgets: Widget) = widgets.forEach { append(it) } 33 | 34 | fun prepend(widget: Widget) = gtk_list_box_prepend(gtkListBoxPointer, widget.gtkWidgetPointer) 35 | 36 | fun insert(widget: Widget, pos: Int) = gtk_list_box_insert(gtkListBoxPointer, widget.gtkWidgetPointer, pos) 37 | 38 | fun remove(widget: Widget) = gtk_list_box_remove(gtkListBoxPointer, widget.gtkWidgetPointer) 39 | 40 | fun selectAll() = gtk_list_box_select_all(gtkListBoxPointer) 41 | fun selectRow(row: ListBoxRow) = gtk_list_box_select_row(gtkListBoxPointer, row.gtkListBoxRowPointer) 42 | 43 | fun unselectAll() = gtk_list_box_unselect_all(gtkListBoxPointer) 44 | fun unselectRow(row: ListBoxRow) = gtk_list_box_unselect_row(gtkListBoxPointer, row.gtkListBoxRowPointer) 45 | 46 | fun rowAtIndex(pos: Int): ListBoxRow? = 47 | gtk_list_box_get_row_at_index(gtkListBoxPointer, pos)?.asListBoxRow() 48 | 49 | fun rowAtY(y: Int): ListBoxRow? = gtk_list_box_get_row_at_y(gtkListBoxPointer, y)?.asListBoxRow() 50 | 51 | fun selectedRow(): ListBoxRow? = gtk_list_box_get_selected_row(gtkListBoxPointer)?.asListBoxRow() 52 | 53 | companion object { 54 | val Type = BuiltinTypeInfo(GTK_TYPE_LIST_BOX, ::ListBox) 55 | } 56 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/ListBoxRow.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.sizeOf 9 | import native.gtk.* 10 | 11 | open class ListBoxRow : Widget, Actionable { 12 | 13 | val gtkListBoxRowPointer get() = gPointer.asTypedPointer() 14 | 15 | override val gtkActionablePointer get() = gPointer.asTypedPointer() 16 | 17 | constructor() : super(gtk_list_box_row_new()!!) 18 | constructor(pointer: CPointer<*>) : super(pointer) 19 | 20 | var activatable: Boolean 21 | get() = gtk_list_box_row_get_activatable(gtkListBoxRowPointer).boolean 22 | set(value) = gtk_list_box_row_set_activatable(gtkListBoxRowPointer, value.gboolean) 23 | 24 | var selectable: Boolean 25 | get() = gtk_list_box_row_get_selectable(gtkListBoxRowPointer).boolean 26 | set(value) = gtk_list_box_row_set_selectable(gtkListBoxRowPointer, value.gboolean) 27 | 28 | var child: Widget? 29 | get() = gtk_list_box_row_get_child(gtkListBoxRowPointer)?.asWidget() 30 | set(value) = gtk_list_box_row_set_child(gtkListBoxRowPointer, value?.gtkWidgetPointer) 31 | 32 | var header: Widget? 33 | get() = gtk_list_box_row_get_header(gtkListBoxRowPointer)?.asWidget() 34 | set(value) = gtk_list_box_row_set_header(gtkListBoxRowPointer, value?.gtkWidgetPointer) 35 | 36 | val index: Int get() = gtk_list_box_row_get_index(gtkListBoxRowPointer) 37 | 38 | 39 | /** 40 | * Marks this row as changed. 41 | */ 42 | fun changed() = gtk_list_box_row_changed(gtkListBoxRowPointer) 43 | 44 | companion object { 45 | val Type = BuiltinTypeInfo( 46 | GTK_TYPE_LIST_BOX_ROW, 47 | sizeOf(), 48 | sizeOf(), 49 | ::ListBoxRow 50 | ) 51 | } 52 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/ListItem.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.* 4 | import internal.BuiltinTypeInfo 5 | import kotlinx.cinterop.CPointer 6 | import native.gtk.* 7 | 8 | class ListItem : Object { 9 | 10 | val gtkListItemPointer get() = gPointer.asTypedPointer() 11 | 12 | constructor(pointer: CPointer<*>) : super(pointer) 13 | 14 | var activatable: Boolean 15 | get() = gtk_list_item_get_activatable(gtkListItemPointer).boolean 16 | set(value) = gtk_list_item_set_activatable(gtkListItemPointer, value.gboolean) 17 | 18 | var child: Widget? 19 | get() = gtk_list_item_get_child(gtkListItemPointer)?.asWidget() 20 | set(value) = gtk_list_item_set_child(gtkListItemPointer, value?.gtkWidgetPointer) 21 | 22 | /** 23 | * The position in the model that this item currently displays 24 | * 25 | * Returns null if unbound 26 | */ 27 | val position: Int? 28 | get() { 29 | val i = gtk_list_item_get_position(gtkListItemPointer) 30 | return if (i != GTK_INVALID_LIST_POSITION) i.toInt() else null 31 | } 32 | 33 | var selectable: Boolean 34 | get() = gtk_list_item_get_selectable(gtkListItemPointer).boolean 35 | set(value) = gtk_list_item_set_selectable(gtkListItemPointer, value.gboolean) 36 | 37 | val selected: Boolean 38 | get() = gtk_list_item_get_selected(gtkListItemPointer).boolean 39 | 40 | val item: Object? = gtk_list_item_get_item(gtkListItemPointer)?.asObject() 41 | 42 | companion object { 43 | val Type = BuiltinTypeInfo(GTK_TYPE_LIST_ITEM, ::ListItem) 44 | } 45 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/ListItemFactory.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import kotlinx.cinterop.CPointer 6 | import native.gtk.GtkListItemFactory 7 | 8 | open class ListItemFactory : Object { 9 | val gtkListItemFactoryPointer get() = gPointer.asTypedPointer() 10 | 11 | constructor(pointer: CPointer<*>) : super(pointer) 12 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/ListView.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import native.gtk.* 9 | 10 | class ListView : ListBase { 11 | val gtkListViewPointer get() = gtkWidgetPointer.asTypedPointer() 12 | 13 | constructor(pointer: CPointer<*>) : super(pointer) 14 | constructor(model: SelectionModel?, factory: ListItemFactory?) : this( 15 | gtk_list_view_new( 16 | model?.gtkSelectionModelPointer, 17 | factory?.gtkListItemFactoryPointer 18 | )!! 19 | ) 20 | 21 | var enableRubberband: Boolean 22 | get() = gtk_list_view_get_enable_rubberband(gtkListViewPointer).boolean 23 | set(value) = gtk_list_view_set_enable_rubberband(gtkListViewPointer, value.gboolean) 24 | 25 | var factory: ListItemFactory? 26 | get() = gtk_list_view_get_factory(gtkListViewPointer)?.asListItemFactory() 27 | set(value) = gtk_list_view_set_factory(gtkListViewPointer, value?.gtkListItemFactoryPointer) 28 | 29 | var model: SelectionModel? 30 | get() = gtk_list_view_get_model(gtkListViewPointer)?.asSelectionModel() 31 | set(value) = gtk_list_view_set_model(gtkListViewPointer, value?.gtkSelectionModelPointer) 32 | 33 | var showSeparators: Boolean 34 | get() = gtk_list_view_get_show_separators(gtkListViewPointer).boolean 35 | set(value) = gtk_list_view_set_show_separators(gtkListViewPointer, value.gboolean) 36 | 37 | var singleClickActivate: Boolean 38 | get() = gtk_list_view_get_single_click_activate(gtkListViewPointer).boolean 39 | set(value) = gtk_list_view_set_single_click_activate(gtkListViewPointer, value.gboolean) 40 | 41 | companion object { 42 | val Type = BuiltinTypeInfo(GTK_TYPE_LIST_VIEW, ::ListView) 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/LockButton.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gio.Permission 4 | import bindings.gio.asPermission 5 | import bindings.gobject.asTypedPointer 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import native.gtk.* 9 | 10 | class LockButton : Button { 11 | val gtkLockButtonPointer get() = gtkWidgetPointer.asTypedPointer() 12 | 13 | constructor(pointer: CPointer<*>) : super(pointer) 14 | constructor(permission: Permission?) : this(gtk_lock_button_new(permission?.gPermissionPointer)!!) 15 | 16 | var permission: Permission? 17 | get() = gtk_lock_button_get_permission(gtkLockButtonPointer)?.asPermission() 18 | set(value) = gtk_lock_button_set_permission(gtkLockButtonPointer, value?.gPermissionPointer) 19 | 20 | companion object { 21 | val Type = BuiltinTypeInfo(GTK_TYPE_LOCK_BUTTON, ::LockButton) 22 | } 23 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/MessageDialog.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import internal.BuiltinTypeInfo 5 | import kotlinx.cinterop.CPointer 6 | import native.gtk.* 7 | 8 | class MessageDialog : Dialog { 9 | 10 | val gtkMessageDialogPointer get() = gtkDialogPointer.asTypedPointer() 11 | 12 | constructor( 13 | parent: Window?, 14 | flags: GtkDialogFlags, 15 | type: GtkMessageType, 16 | buttonType: GtkButtonsType, 17 | message: String, 18 | ) : super( 19 | gtk_message_dialog_new( 20 | parent?.gtkWindowPointer, 21 | flags, type, buttonType, message 22 | )!! 23 | ) 24 | 25 | constructor(pointer: CPointer<*>) : super(pointer) 26 | 27 | val messageArea: Box 28 | get() = gtk_message_dialog_get_message_area(gtkMessageDialogPointer)!! 29 | .asTypedPointer() 30 | .asBox() 31 | 32 | fun setMarkup(markup: String) = gtk_message_dialog_set_markup(gtkMessageDialogPointer, markup) 33 | 34 | companion object { 35 | val Type = BuiltinTypeInfo(GTK_TYPE_MESSAGE_DIALOG, ::MessageDialog) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Native.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import kotlinx.cinterop.* 4 | import native.gtk.GtkNative 5 | import native.gtk.gtk_native_get_surface_transform 6 | 7 | interface Native { 8 | val gtkNativePointer: CPointer 9 | 10 | fun getSurfaceTransform(): Coordinate = memScoped { 11 | val x = alloc() 12 | val y = alloc() 13 | gtk_native_get_surface_transform(gtkNativePointer, x.ptr, y.ptr) 14 | return Coordinate(x.value, y.value) 15 | } 16 | 17 | data class Coordinate(val x: Double, val y: Double) 18 | } 19 | 20 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Orientable.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import kotlinx.cinterop.CPointer 4 | import native.gtk.GtkOrientable 5 | import native.gtk.GtkOrientation 6 | import native.gtk.gtk_orientable_get_orientation 7 | import native.gtk.gtk_orientable_set_orientation 8 | 9 | interface Orientable { 10 | 11 | val gtkOrientablePointer: CPointer 12 | 13 | var orientation: GtkOrientation 14 | get() = gtk_orientable_get_orientation(gtkOrientablePointer) 15 | set(value) = gtk_orientable_set_orientation(gtkOrientablePointer, value) 16 | } 17 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/ProgressBar.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.toKString 9 | import native.gtk.* 10 | 11 | class ProgressBar : Widget, Orientable { 12 | val gtkProgressBarPointer get() = gtkWidgetPointer.asTypedPointer() 13 | 14 | override val gtkOrientablePointer get() = gtkWidgetPointer.asTypedPointer() 15 | 16 | constructor(pointer: CPointer<*>) : super(pointer) 17 | constructor() : this(gtk_progress_bar_new()!!) 18 | 19 | var ellipsize: PangoEllipsizeMode 20 | get() = gtk_progress_bar_get_ellipsize(gtkProgressBarPointer) 21 | set(value) = gtk_progress_bar_set_ellipsize(gtkProgressBarPointer, value) 22 | 23 | var fraction: Double 24 | get() = gtk_progress_bar_get_fraction(gtkProgressBarPointer) 25 | set(value) = gtk_progress_bar_set_fraction(gtkProgressBarPointer, value) 26 | 27 | var inverted: Boolean 28 | get() = gtk_progress_bar_get_inverted(gtkProgressBarPointer).boolean 29 | set(value) = gtk_progress_bar_set_inverted(gtkProgressBarPointer, value.gboolean) 30 | 31 | var pulseStep: Double 32 | get() = gtk_progress_bar_get_pulse_step(gtkProgressBarPointer) 33 | set(value) = gtk_progress_bar_set_pulse_step(gtkProgressBarPointer, value) 34 | 35 | var showText: Boolean 36 | get() = gtk_progress_bar_get_show_text(gtkProgressBarPointer).boolean 37 | set(value) = gtk_progress_bar_set_show_text(gtkProgressBarPointer, value.gboolean) 38 | 39 | var text: String? 40 | get() = gtk_progress_bar_get_text(gtkProgressBarPointer)?.toKString() 41 | set(value) = gtk_progress_bar_set_text(gtkProgressBarPointer, value) 42 | 43 | fun pulse() = gtk_progress_bar_pulse(gtkProgressBarPointer) 44 | 45 | companion object { 46 | val Type = BuiltinTypeInfo(GTK_TYPE_PROGRESS_BAR, ::ProgressBar) 47 | } 48 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Root.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import kotlinx.cinterop.CPointer 5 | import native.gtk.GtkRoot 6 | import native.gtk.gtk_root_get_focus 7 | import native.gtk.gtk_root_set_focus 8 | 9 | interface Root : Native { 10 | val gtkRootPointer: CPointer get() = gtkNativePointer.asTypedPointer() 11 | 12 | var focus: Widget? 13 | get() = gtk_root_get_focus(gtkRootPointer)?.asWidget() 14 | set(value) = gtk_root_set_focus(gtkRootPointer, value?.gtkWidgetPointer) 15 | } 16 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Scrollable.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.boolean 4 | import kotlinx.cinterop.CPointer 5 | import kotlinx.cinterop.alloc 6 | import kotlinx.cinterop.memScoped 7 | import kotlinx.cinterop.ptr 8 | import native.gtk.* 9 | 10 | interface Scrollable { 11 | val gtkScrollablePointer: CPointer 12 | 13 | var hadjustment: Adjustment? 14 | get() = gtk_scrollable_get_hadjustment(gtkScrollablePointer)?.asAdjustment() 15 | set(value) = gtk_scrollable_set_hadjustment(gtkScrollablePointer, value?.gtkAdjustmentPointer) 16 | 17 | var vadjustment: Adjustment? 18 | get() = gtk_scrollable_get_vadjustment(gtkScrollablePointer)?.asAdjustment() 19 | set(value) = gtk_scrollable_set_vadjustment(gtkScrollablePointer, value?.gtkAdjustmentPointer) 20 | 21 | var hscrollPolicy: GtkScrollablePolicy 22 | get() = gtk_scrollable_get_hscroll_policy(gtkScrollablePointer) 23 | set(value) = gtk_scrollable_set_hscroll_policy(gtkScrollablePointer, value) 24 | 25 | var vscrollPolicy: GtkScrollablePolicy 26 | get() = gtk_scrollable_get_vscroll_policy(gtkScrollablePointer) 27 | set(value) = gtk_scrollable_set_vscroll_policy(gtkScrollablePointer, value) 28 | 29 | val border: Border? 30 | get() = memScoped { 31 | val gBorder = alloc() 32 | val success = gtk_scrollable_get_border(gtkScrollablePointer, gBorder.ptr).boolean 33 | if (success) Border(gBorder.left, gBorder.right, gBorder.top, gBorder.bottom) 34 | else null 35 | } 36 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Searchbar.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.sizeOf 9 | import native.gtk.* 10 | 11 | class SearchBar : Widget { 12 | val gtkSearchBarPointer get() = gtkWidgetPointer.asTypedPointer() 13 | 14 | constructor(pointer: CPointer<*>) : super(pointer) 15 | constructor() : this(gtk_search_bar_new()!!) 16 | 17 | fun connectEntry(entry: Editable) = gtk_search_bar_connect_entry(gtkSearchBarPointer, entry.gtkEditablePointer) 18 | 19 | var child: Widget? 20 | get() = gtk_search_bar_get_child(gtkSearchBarPointer)?.asWidget() 21 | set(value) = gtk_search_bar_set_child(gtkSearchBarPointer, value?.gtkWidgetPointer) 22 | 23 | var keyCaptureWidget: Widget? 24 | get() = gtk_search_bar_get_key_capture_widget(gtkSearchBarPointer)?.asWidget() 25 | set(value) = gtk_search_bar_set_key_capture_widget(gtkSearchBarPointer, value?.gtkWidgetPointer) 26 | 27 | var searchMode: Boolean 28 | get() = gtk_search_bar_get_search_mode(gtkSearchBarPointer).boolean 29 | set(value) = gtk_search_bar_set_search_mode(gtkSearchBarPointer, value.gboolean) 30 | 31 | var showCloseButton: Boolean 32 | get() = gtk_search_bar_get_show_close_button(gtkSearchBarPointer).boolean 33 | set(value) = gtk_search_bar_set_show_close_button(gtkSearchBarPointer, value.gboolean) 34 | 35 | companion object { 36 | val Type = BuiltinTypeInfo(GTK_TYPE_SEARCH_BAR, ::SearchBar) 37 | } 38 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/SelectionModel.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gio.ListModel 4 | import bindings.gobject.asTypedPointer 5 | import bindings.gtk.internal.staticStableRefDestroy 6 | import kotlinx.cinterop.* 7 | import native.gio.GListModel 8 | import native.gobject.GCallback 9 | import native.gobject.g_signal_connect_data 10 | import native.gobject.gpointer 11 | import native.gtk.GtkSelectionModel 12 | 13 | interface SelectionModel : ListModel { 14 | val gtkSelectionModelPointer: CPointer 15 | override val gListModelPointer get() = gtkSelectionModelPointer.asTypedPointer() 16 | 17 | fun onSelectionChanged(handler: () -> Unit) { 18 | g_signal_connect_data( 19 | gtkSelectionModelPointer, "selection-changed", staticSelectionChangedFunc, 20 | StableRef.create(handler).asCPointer(), staticStableRefDestroy, 0 21 | ) 22 | } 23 | 24 | // TODO implement the rest of the interface 25 | } 26 | 27 | private val staticSelectionChangedFunc: GCallback = 28 | staticCFunction { _: CPointer, 29 | position: UInt, 30 | nItems: UInt, 31 | data: gpointer -> 32 | data.asStableRef<() -> Unit>().get().invoke() 33 | }.reinterpret() 34 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Separator.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import internal.BuiltinTypeInfo 5 | import kotlinx.cinterop.CPointer 6 | import native.gtk.* 7 | 8 | class Separator : Widget, Orientable { 9 | val gtkSeparatorPointer get() = gtkWidgetPointer.asTypedPointer() 10 | 11 | override val gtkOrientablePointer get() = gtkWidgetPointer.asTypedPointer() 12 | 13 | constructor(pointer: CPointer<*>) : super(pointer) 14 | constructor(orientation: GtkOrientation) : this(gtk_separator_new(orientation)!!) 15 | 16 | companion object { 17 | val Type = BuiltinTypeInfo(GTK_TYPE_SEPARATOR, ::Separator) 18 | } 19 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/ShortcutManager.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import kotlinx.cinterop.CPointer 4 | import native.gtk.GtkShortcutManager 5 | 6 | interface ShortcutManager { 7 | val gtkShortcutManagerPointer: CPointer 8 | } 9 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/ShortcutsWindow.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import internal.BuiltinTypeInfo 5 | import kotlinx.cinterop.CPointer 6 | import native.gtk.GTK_TYPE_SHORTCUTS_WINDOW 7 | import native.gtk.GtkShortcutsWindow 8 | 9 | class ShortcutsWindow : Window { 10 | val gtkShortcutsWindowPointer get() = gtkWindowPointer.asTypedPointer() 11 | 12 | constructor(pointer: CPointer<*>) : super(pointer) 13 | 14 | companion object { 15 | val Type = BuiltinTypeInfo(GTK_TYPE_SHORTCUTS_WINDOW, ::ShortcutsWindow) 16 | } 17 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/SingleSelection.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gio.ListModel 4 | import bindings.gio.asListModel 5 | import bindings.gobject.* 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import native.gtk.* 9 | 10 | class SingleSelection : Object, SelectionModel { 11 | 12 | val gtkSingleSelectionPointer get() = gPointer.asTypedPointer() 13 | override val gtkSelectionModelPointer get() = gPointer.asTypedPointer() 14 | 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | constructor(model: ListModel) : this(gtk_single_selection_new(model.gListModelPointer)!!) 17 | 18 | var autoselect: Boolean 19 | get() = gtk_single_selection_get_autoselect(gtkSingleSelectionPointer).boolean 20 | set(value) = gtk_single_selection_set_autoselect(gtkSingleSelectionPointer, value.gboolean) 21 | 22 | var canUnselect: Boolean 23 | get() = gtk_single_selection_get_can_unselect(gtkSingleSelectionPointer).boolean 24 | set(value) = gtk_single_selection_set_can_unselect(gtkSingleSelectionPointer, value.gboolean) 25 | 26 | var model: ListModel? 27 | get() = gtk_single_selection_get_model(gtkSingleSelectionPointer)?.asListModel() 28 | set(value) = gtk_single_selection_set_model(gtkSingleSelectionPointer, value?.gListModelPointer) 29 | 30 | // TODO this may return GTK_INVALID_LIST_POSITION, make the result nullable? 31 | var selected: Int 32 | get() = gtk_single_selection_get_selected(gtkSingleSelectionPointer).toInt() 33 | set(value) = gtk_single_selection_set_selected(gtkSingleSelectionPointer, value.toUInt()) 34 | 35 | val selectedItem: Object? 36 | get() = gtk_single_selection_get_selected_item(gtkSingleSelectionPointer)?.asObject() 37 | 38 | companion object { 39 | val Type = BuiltinTypeInfo(GTK_TYPE_SINGLE_SELECTION, ::SingleSelection) 40 | } 41 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/StackPage.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import bindings.gobject.boolean 6 | import bindings.gobject.gboolean 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.CPointer 9 | import kotlinx.cinterop.toKString 10 | import native.gtk.* 11 | 12 | class StackPage : Object { 13 | val gtkStackPagePointer get() = gPointer.asTypedPointer() 14 | 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | 17 | val child: Widget 18 | get() = gtk_stack_page_get_child(gtkStackPagePointer)!!.asWidget() 19 | 20 | var iconName: String? 21 | get() = gtk_stack_page_get_icon_name(gtkStackPagePointer)?.toKString() 22 | set(value) = gtk_stack_page_set_icon_name(gtkStackPagePointer, value) 23 | 24 | var name: String? 25 | get() = gtk_stack_page_get_name(gtkStackPagePointer)?.toKString() 26 | set(value) = gtk_stack_page_set_name(gtkStackPagePointer, value) 27 | 28 | var needsAttention: Boolean 29 | get() = gtk_stack_page_get_needs_attention(gtkStackPagePointer).boolean 30 | set(value) = gtk_stack_page_set_needs_attention(gtkStackPagePointer, value.gboolean) 31 | 32 | var title: String? 33 | get() = gtk_stack_page_get_title(gtkStackPagePointer)?.toKString() 34 | set(value) = gtk_stack_page_set_title(gtkStackPagePointer, value) 35 | 36 | var useUnderline: Boolean 37 | get() = gtk_stack_page_get_use_underline(gtkStackPagePointer).boolean 38 | set(value) = gtk_stack_page_set_use_underline(gtkStackPagePointer, value.gboolean) 39 | 40 | var visible: Boolean 41 | get() = gtk_stack_page_get_visible(gtkStackPagePointer).boolean 42 | set(value) = gtk_stack_page_set_visible(gtkStackPagePointer, value.gboolean) 43 | 44 | companion object { 45 | val Type = BuiltinTypeInfo(GTK_TYPE_STACK_PAGE, ::StackPage) 46 | } 47 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/StackSidebar.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import internal.BuiltinTypeInfo 5 | import kotlinx.cinterop.CPointer 6 | import native.gtk.* 7 | 8 | class StackSidebar : Widget { 9 | val gtkStackSidebarPointer get() = gtkWidgetPointer.asTypedPointer() 10 | 11 | constructor(pointer: CPointer<*>) : super(pointer) 12 | constructor() : this(gtk_stack_sidebar_new()!!) 13 | 14 | var stack: Stack? 15 | get() = gtk_stack_sidebar_get_stack(gtkStackSidebarPointer)?.asStack() 16 | set(value) = gtk_stack_sidebar_set_stack(gtkStackSidebarPointer, value?.gtkStackPointer) 17 | 18 | companion object { 19 | val Type = BuiltinTypeInfo(GTK_TYPE_STACK_SIDEBAR, ::StackSidebar) 20 | } 21 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/StringList.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gio.ListModel 4 | import bindings.gobject.Object 5 | import bindings.gobject.asTypedPointer 6 | import bindings.util.toCStringList 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.CPointer 9 | import kotlinx.cinterop.memScoped 10 | import native.gio.GListModel 11 | import native.gtk.* 12 | 13 | class StringList : Object, ListModel { 14 | 15 | val gtkStringListPointer get() = gPointer.asTypedPointer() 16 | override val gListModelPointer get() = gPointer.asTypedPointer() 17 | 18 | constructor(pointer: CPointer<*>) : super(pointer) 19 | 20 | constructor(items: List = emptyList()) : this(createStringList(items)) 21 | 22 | constructor(vararg items: String) : this(items.asList()) 23 | 24 | fun append(item: String) = gtk_string_list_append(gtkStringListPointer, item) 25 | 26 | fun getString(position: Int) = gtk_string_list_get_string(gtkStringListPointer, position.toUInt()) 27 | 28 | fun remove(position: Int) = gtk_string_list_remove(gtkStringListPointer, position.toUInt()) 29 | 30 | // TODO add splice 31 | // TODO add take? 32 | 33 | companion object { 34 | val Type = BuiltinTypeInfo(GTK_TYPE_STRING_LIST, ::StringList) 35 | } 36 | } 37 | 38 | private fun createStringList(items: List): CPointer = memScoped { 39 | val s = items.toCStringList(this) 40 | return gtk_string_list_new(s)!! 41 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/StringObject.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import internal.BuiltinTypeInfo 6 | import kotlinx.cinterop.CPointer 7 | import kotlinx.cinterop.toKString 8 | import native.gtk.GTK_TYPE_STRING_OBJECT 9 | import native.gtk.GtkStringObject 10 | import native.gtk.gtk_string_object_get_string 11 | import native.gtk.gtk_string_object_new 12 | 13 | class StringObject : Object { 14 | val gtkStringObjectPointer get() = gPointer.asTypedPointer() 15 | 16 | constructor(pointer: CPointer<*>) : super(pointer) 17 | constructor(str: String) : this(gtk_string_object_new(str)!!) 18 | 19 | val string: String 20 | get() = gtk_string_object_get_string(gtkStringObjectPointer)!!.toKString() 21 | 22 | companion object { 23 | 24 | val Type = BuiltinTypeInfo(GTK_TYPE_STRING_OBJECT, ::StringObject) 25 | } 26 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/Switch.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import native.gtk.* 9 | 10 | class Switch : Widget, Actionable { 11 | val gtkSwitchPointer get() = gtkWidgetPointer.asTypedPointer() 12 | 13 | override val gtkActionablePointer get() = gtkWidgetPointer.asTypedPointer() 14 | 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | constructor() : this(gtk_switch_new()!!) 17 | 18 | var state: Boolean 19 | get() = gtk_switch_get_state(gtkSwitchPointer).boolean 20 | set(value) = gtk_switch_set_state(gtkSwitchPointer, value.gboolean) 21 | 22 | var active: Boolean 23 | get() = gtk_switch_get_active(gtkSwitchPointer).boolean 24 | set(value) = gtk_switch_set_active(gtkSwitchPointer, value.gboolean) 25 | 26 | // TODO activate and state-set signals 27 | 28 | companion object { 29 | val Type = BuiltinTypeInfo(GTK_TYPE_SWITCH, ::Switch) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/ToggleButton.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import bindings.gtk.internal.staticStableRefDestroy 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.* 9 | import native.gobject.GCallback 10 | import native.gobject.g_signal_connect_data 11 | import native.gobject.gpointer 12 | import native.gtk.* 13 | 14 | open class ToggleButton : Button { 15 | val gtkToggleButtonPointer get() = gtkWidgetPointer.asTypedPointer() 16 | 17 | constructor(pointer: CPointer<*>) : super(pointer) 18 | constructor() : this(gtk_toggle_button_new()!!) 19 | constructor(label: String) : this(gtk_toggle_button_new_with_label(label)!!) 20 | 21 | var active: Boolean 22 | get() = gtk_toggle_button_get_active(gtkToggleButtonPointer).boolean 23 | set(value) = gtk_toggle_button_set_active(gtkToggleButtonPointer, value.gboolean) 24 | 25 | fun setGroup(group: ToggleButton) = 26 | gtk_toggle_button_set_group(gtkToggleButtonPointer, group.gtkToggleButtonPointer) 27 | 28 | /** 29 | * Emits the toggled signal on this ToggleButton. 30 | */ 31 | fun toggled() = gtk_toggle_button_toggled(gtkToggleButtonPointer) 32 | 33 | fun onToggled(func: (ToggleButton) -> Unit) { 34 | val handler = { func(this) } 35 | g_signal_connect_data( 36 | gtkToggleButtonPointer, 37 | "toggled", 38 | staticToggleButtonSignalFunc, 39 | StableRef.create(handler).asCPointer(), 40 | staticStableRefDestroy, 41 | 0 42 | ) 43 | } 44 | 45 | companion object { 46 | val Type = BuiltinTypeInfo( 47 | GTK_TYPE_TOGGLE_BUTTON, 48 | sizeOf(), 49 | sizeOf(), 50 | ::ToggleButton 51 | ) 52 | } 53 | 54 | } 55 | 56 | private val staticToggleButtonSignalFunc: GCallback = 57 | staticCFunction { _: gpointer, data: gpointer -> 58 | data.asStableRef<() -> Unit>().get().invoke() 59 | Unit 60 | }.reinterpret() -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/TreeExpander.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.* 4 | import internal.BuiltinTypeInfo 5 | import kotlinx.cinterop.CPointer 6 | import native.gtk.* 7 | 8 | class TreeExpander : Widget { 9 | val gtkTreeExpanderPointer get() = gtkWidgetPointer.asTypedPointer() 10 | 11 | constructor(pointer: CPointer<*>) : super(pointer) 12 | constructor() : this(gtk_tree_expander_new()!!) 13 | 14 | var child: Widget? 15 | get() = gtk_tree_expander_get_child(gtkTreeExpanderPointer)?.asWidget() 16 | set(value) = gtk_tree_expander_set_child(gtkTreeExpanderPointer, value?.gtkWidgetPointer) 17 | 18 | var indentForIcon: Boolean 19 | get() = gtk_tree_expander_get_indent_for_icon(gtkTreeExpanderPointer).boolean 20 | set(value) = gtk_tree_expander_set_indent_for_icon(gtkTreeExpanderPointer, value.gboolean) 21 | 22 | val item: Object? get() = gtk_tree_expander_get_item(gtkTreeExpanderPointer)?.asObject() 23 | 24 | var listRow: TreeListRow? 25 | get() = gtk_tree_expander_get_list_row(gtkTreeExpanderPointer)?.asTreeListRow() 26 | set(value) = gtk_tree_expander_set_list_row(gtkTreeExpanderPointer, value?.gtkTreeListRowPointer) 27 | 28 | companion object { 29 | val Type = BuiltinTypeInfo(GTK_TYPE_TREE_EXPANDER, ::TreeExpander) 30 | } 31 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/TreeListRow.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gio.ListModel 4 | import bindings.gio.asListModel 5 | import bindings.gobject.* 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import native.gtk.* 9 | 10 | class TreeListRow : Object { 11 | val gtkTreeListRowPointer get() = gPointer.asTypedPointer() 12 | 13 | constructor(pointer: CPointer<*>) : super(pointer) 14 | 15 | fun getChildRow(position: Int): TreeListRow? = 16 | gtk_tree_list_row_get_child_row(gtkTreeListRowPointer, position.toUInt())?.asTreeListRow() 17 | 18 | val children: ListModel? get() = gtk_tree_list_row_get_children(gtkTreeListRowPointer)?.asListModel() 19 | 20 | val depth: Int get() = gtk_tree_list_row_get_depth(gtkTreeListRowPointer).toInt() 21 | 22 | var expanded: Boolean 23 | get() = gtk_tree_list_row_get_expanded(gtkTreeListRowPointer).boolean 24 | set(value) = gtk_tree_list_row_set_expanded(gtkTreeListRowPointer, value.gboolean) 25 | 26 | val item: Object? get() = gtk_tree_list_row_get_item(gtkTreeListRowPointer)?.asObject() 27 | 28 | companion object { 29 | val Type = BuiltinTypeInfo(GTK_TYPE_TREE_LIST_ROW, ::TreeListRow) 30 | } 31 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/internal/InterfaceWrappers.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk.internal 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.* 5 | import kotlinx.cinterop.CPointer 6 | import native.gtk.* 7 | 8 | internal class ActionableWrapper( 9 | override val gtkActionablePointer: CPointer 10 | ) : Actionable 11 | 12 | internal class NativeWrapper( 13 | override val gtkNativePointer: CPointer 14 | ) : Native 15 | 16 | internal class OrientableWrapper( 17 | override val gtkOrientablePointer: CPointer 18 | ) : Orientable 19 | 20 | internal class RootWrapper( 21 | override val gtkRootPointer: CPointer 22 | ) : Root { 23 | override val gtkNativePointer: CPointer get() = gtkRootPointer.asTypedPointer() 24 | } 25 | 26 | internal class SelectionModelWrapper( 27 | override val gtkSelectionModelPointer: CPointer 28 | ) : SelectionModel 29 | 30 | internal class EditableWrapper( 31 | override var gtkEditablePointer: CPointer 32 | ) : Editable 33 | 34 | internal class ShortcutManagerWrapper( 35 | override val gtkShortcutManagerPointer: CPointer 36 | ) : ShortcutManager 37 | 38 | internal class ScrollableWrapper( 39 | override val gtkScrollablePointer: CPointer 40 | ) : Scrollable -------------------------------------------------------------------------------- /gtk-bindings/src/nativeMain/kotlin/bindings/gtk/internal/Signals.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk.internal 2 | 3 | import kotlinx.cinterop.asStableRef 4 | import kotlinx.cinterop.reinterpret 5 | import kotlinx.cinterop.staticCFunction 6 | import native.gobject.GClosureNotify 7 | import native.gobject.gpointer 8 | 9 | /** 10 | * Helper function that can be used as a destroy_data handler 11 | * when connecting to a signal. 12 | * 13 | * This implementation assumes [data] is a pointer to a StableRef 14 | * and calls dispose on it. 15 | */ 16 | internal val staticStableRefDestroy: GClosureNotify = 17 | staticCFunction { data: gpointer?, 18 | _: gpointer? -> 19 | data?.asStableRef()?.dispose() 20 | Unit 21 | }.reinterpret() -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/CustomGtkApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.ObjectCompanion 4 | import bindings.gtk.testutils.GtkTestBase 5 | import kotlinx.cinterop.CPointer 6 | import kotlin.test.Test 7 | import kotlin.test.assertTrue 8 | 9 | class CustomGtkApplicationTest : GtkTestBase() { 10 | @Test 11 | fun createCustomGtkApplication() { 12 | val myApplication = MyGtkApplication() 13 | myApplication.runApplication() 14 | assertTrue(myApplication.applicationWasActivated, "Application was not activated") 15 | } 16 | } 17 | 18 | class MyGtkApplication : Application { 19 | 20 | var applicationWasActivated = false 21 | 22 | constructor(pointer: CPointer<*>) : super(pointer) 23 | 24 | constructor() : super("io.quantus.MyTestApplication") { 25 | onActivate { 26 | println("MyGtkApplication was activated") 27 | applicationWasActivated = true 28 | quit() 29 | } 30 | } 31 | 32 | companion object : ObjectCompanion() { 33 | override val typeName = "MyGtkApplication" 34 | override val parentType = Application.Type 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/CustomWidgetTest.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.Object 4 | import bindings.gtk.testutils.GtkTestBase 5 | import usertypes.registerTypeClass 6 | import native.gobject.g_object_new 7 | import native.gobject.g_object_ref_sink 8 | import native.gobject.g_object_unref 9 | import kotlin.test.Test 10 | 11 | class CustomWidgetTest : GtkTestBase() { 12 | 13 | @Test 14 | fun tmpInstantiateCustomWidget() { 15 | val widget = g_object_new(MyCustomWidgetTypeInfo.gType, null) 16 | println("widget: $widget") 17 | } 18 | 19 | @Test 20 | fun testCustomWidgetDispose() { 21 | val widget = g_object_new(MyCustomWidgetTypeInfo.gType, null) 22 | g_object_unref(widget) 23 | 24 | val w2 = AnotherWidget() 25 | g_object_ref_sink(w2.gPointer) 26 | g_object_unref(w2.gPointer) 27 | } 28 | 29 | } 30 | 31 | class MyCustomWidget : Button { 32 | constructor() : super() 33 | } 34 | 35 | val MyCustomWidgetTypeInfo = registerTypeClass( 36 | "MyCustomWidget", Button.Type, 37 | ) 38 | 39 | class AnotherWidget : Object { 40 | constructor() : super(AnotherWidgetTypeInfo.newInstancePointer()) 41 | } 42 | 43 | val AnotherWidgetTypeInfo = registerTypeClass("AnotherWidget", Button.Type) -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/GtkAboutDialogTest.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gtk.testutils.GtkTestBase 4 | import native.gtk.GtkLicense 5 | import kotlin.test.Ignore 6 | import kotlin.test.Test 7 | 8 | @Ignore 9 | class GtkAboutDialogTest : GtkTestBase() { 10 | 11 | @Test 12 | fun testAboutDialog() = runTestApplication { 13 | val dialog = AboutDialog() 14 | 15 | dialog.application = it.app 16 | 17 | dialog.copyright = "Copyright 2022" 18 | dialog.programName = "Test Program" 19 | dialog.license = "LICENSE TEXT" 20 | dialog.licenseType = GtkLicense.GTK_LICENSE_MIT_X11 21 | dialog.version = "0.0.1" 22 | dialog.website = "https://stevenvanbael.com" 23 | dialog.websiteLabel = "Project website" 24 | 25 | dialog.addCreditSection("Credits", "Steven", "Erika", "Lore") 26 | dialog.addCreditSection("Secondary Credits", "Jan", "Piet", "Korneel") 27 | 28 | dialog.artists = listOf("Chuck Schuldiner", "Chris Cornell", "Layne Staley") 29 | println("Artists: ${dialog.artists}") 30 | 31 | dialog.comments = "Some comments" 32 | dialog.documenters = listOf("Documenter 1", "Documenter 2") 33 | dialog.logoIconName = "open-menu" 34 | dialog.systemInformation = "Arch Linux" 35 | dialog.translatorCredits = "A translator" 36 | 37 | dialog.present() 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/GtkApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gio.Menu 4 | import bindings.gio.SimpleAction 5 | import bindings.gtk.testutils.GtkTestBase 6 | import kotlin.test.Ignore 7 | import kotlin.test.Test 8 | import kotlin.test.assertTrue 9 | 10 | @Ignore 11 | class GtkApplicationTest : GtkTestBase() { 12 | @Test 13 | fun startGtkApplication() { 14 | var activated = false 15 | 16 | val application = Application("io.quantus.gtkapplication") 17 | application.onActivate { 18 | activated = true 19 | application.quit() 20 | } 21 | application.runApplication() 22 | assertTrue(activated, "Application was not activated") 23 | } 24 | 25 | @Test 26 | fun startGtkApplicationWithMenu() { 27 | runTestApplication { 28 | val application = it.app 29 | 30 | // setup menu 31 | 32 | val menu = Menu() 33 | 34 | val fileMenu = Menu() 35 | fileMenu.append("New", "app.new") 36 | fileMenu.append("Open", "app.open") 37 | fileMenu.append("Close", "app.close") 38 | menu.appendSubmenu("File", fileMenu) 39 | 40 | val aboutMenu = Menu() 41 | aboutMenu.append("Show About", "app.about") 42 | menu.appendSubmenu("About", aboutMenu) 43 | 44 | application.menuBar = menu 45 | 46 | // setup actions 47 | 48 | val newAction = SimpleAction("new").apply { 49 | onActivate { 50 | println("Action 'New' activated") 51 | } 52 | } 53 | 54 | val closeAction = SimpleAction("close").apply { 55 | onActivate { 56 | application.quit() 57 | } 58 | } 59 | 60 | application.addAction(newAction) 61 | application.addAction(closeAction) 62 | 63 | // setup window 64 | 65 | val window = ApplicationWindow(application) 66 | window.application = application 67 | window.child = Label("Window content") 68 | window.showMenubar = true 69 | window.present() 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/GtkBoxTest.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gtk.testutils.GtkTestBase 4 | import native.gtk.GtkOrientation 5 | import kotlin.test.Ignore 6 | import kotlin.test.Test 7 | 8 | @Ignore 9 | class GtkBoxTest : GtkTestBase() { 10 | 11 | @Test 12 | fun testBox() { 13 | runTestApplicationWindow { window -> 14 | 15 | val box = Box(GtkOrientation.GTK_ORIENTATION_HORIZONTAL, 0) 16 | box.appendAll(Button("Button 1"), Button("Button 2")) 17 | box.homogeneous = true 18 | 19 | window.child = box 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/GtkButtonTest.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gtk.testutils.GtkTestBase 4 | import kotlin.test.Ignore 5 | import kotlin.test.Test 6 | 7 | @Ignore 8 | class GtkButtonTest : GtkTestBase() { 9 | 10 | @Test 11 | fun testButton() { 12 | runTestApplicationWindow { window -> 13 | 14 | val listBox = ListBox() 15 | 16 | listBox.appendAll( 17 | Button.newWithLabel("Button with Label"), 18 | Button.newWithMnemonic("Button with _Mnemonic"), 19 | Button.newFromIconName("open-menu"), 20 | Button().apply { 21 | this.child = Label("Custom Label") 22 | }, 23 | Button("Click me").apply { 24 | onClicked { b -> 25 | b.label = "You clicked!" 26 | } 27 | } 28 | ) 29 | 30 | window.child = listBox 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/GtkDialogTest.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gtk.testutils.GtkTestBase 4 | import native.gtk.* 5 | import kotlin.test.Ignore 6 | import kotlin.test.Test 7 | 8 | @Ignore 9 | class GtkDialogTest : GtkTestBase() { 10 | 11 | @Test 12 | fun testDialogWithButtons() = runTestApplicationWindow { window -> 13 | 14 | val dialog = Dialog.newDialogWithButtons( 15 | "My Dialog", 16 | window, 17 | GTK_DIALOG_DESTROY_WITH_PARENT.and(GTK_DIALOG_USE_HEADER_BAR), 18 | "OK" to GTK_RESPONSE_ACCEPT, 19 | "Cancel" to GTK_RESPONSE_REJECT 20 | ) 21 | 22 | dialog.contentArea.append(Label("Are you sure?")) 23 | 24 | dialog.onResponse { 25 | println("Response received: $it") 26 | dialog.close() 27 | } 28 | 29 | dialog.onClose { 30 | println("Dialog closed") 31 | } 32 | dialog.isModal = true 33 | dialog.show() 34 | } 35 | 36 | @Test 37 | fun testMessageDialog() = runTestApplicationWindow { window -> 38 | val dialog = 39 | MessageDialog( 40 | window, 41 | GTK_DIALOG_MODAL.and(GTK_DIALOG_USE_HEADER_BAR), 42 | GtkMessageType.GTK_MESSAGE_WARNING, 43 | GtkButtonsType.GTK_BUTTONS_OK, 44 | "Are you sure?" 45 | ) 46 | 47 | dialog.addButton("Cancel", GTK_RESPONSE_CANCEL) 48 | 49 | dialog.onResponse { 50 | println("Response received: $it") 51 | dialog.close() 52 | } 53 | dialog.onClose { 54 | println("Dialog closed") 55 | } 56 | 57 | dialog.show() 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/GtkHeaderBartest.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gio.Menu 4 | import bindings.gtk.testutils.GtkTestBase 5 | import kotlin.test.Ignore 6 | import kotlin.test.Test 7 | 8 | @Ignore 9 | class GtkHeaderBartest : GtkTestBase() { 10 | 11 | @Test 12 | fun testHeaderBar() { 13 | runTestApplicationWindow { window -> 14 | val menu = Menu() 15 | menu.append("Some Item") 16 | 17 | val menuButton = MenuButton() 18 | menuButton.iconName = "open-menu" 19 | menuButton.menuModel = menu 20 | 21 | val title = Label("My Custom Title") 22 | 23 | val headerBar = HeaderBar() 24 | headerBar.packEnd(menuButton) 25 | headerBar.titleWidget = title 26 | 27 | window.titleBar = headerBar 28 | window.child = Label("Window content") 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/GtkLabelTests.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gtk.testutils.GtkTestBase 4 | import kotlin.test.Test 5 | import kotlin.test.assertEquals 6 | 7 | class GtkLabelTests : GtkTestBase() { 8 | @Test 9 | fun createLabelWithText() { 10 | val label = Label("My Label") 11 | assertEquals("My Label", label.text) 12 | } 13 | 14 | @Test 15 | fun createEmptyLabel() { 16 | val label = Label() 17 | assertEquals("", label.text) 18 | } 19 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/GtkListBoxTest.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gtk.testutils.GtkTestBase 4 | import kotlin.test.Ignore 5 | import kotlin.test.Test 6 | 7 | @Ignore 8 | class GtkListBoxTest : GtkTestBase() { 9 | 10 | @Test 11 | fun testListBox() { 12 | runTestApplicationWindow { window -> 13 | 14 | val listBox = ListBox() 15 | val button1 = Button("Button 1") 16 | val button2 = Button("Button 2") 17 | val button3 = Button("Button 3") 18 | 19 | listBox.append(button1) 20 | listBox.append(button2) 21 | listBox.append(button3) 22 | 23 | window.child = listBox 24 | } 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/GtkMenuButtonTest.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gio.Menu 4 | import bindings.gtk.testutils.GtkTestBase 5 | import kotlin.test.Ignore 6 | import kotlin.test.Test 7 | 8 | @Ignore 9 | class GtkMenuButtonTest : GtkTestBase() { 10 | 11 | @Test 12 | fun testMenuButton() { 13 | runTestApplicationWindow { window -> 14 | 15 | val menu = Menu() 16 | menu.append("Item 1") 17 | menu.append("Item 2") 18 | menu.append("Item 3") 19 | 20 | val section = Menu() 21 | section.append("Section Item 1") 22 | section.append("Section Item 2") 23 | menu.appendSection("My Section", section) 24 | 25 | val submenu = Menu() 26 | submenu.append("Submenu Item 1") 27 | submenu.append("Submenu Item 2") 28 | submenu.append("Submenu Item 3") 29 | menu.appendSubmenu("My Submenu", submenu) 30 | 31 | val menuButton = MenuButton() 32 | menuButton.label = "My Menu Button" 33 | menuButton.iconName = "open-menu" 34 | menuButton.menuModel = menu 35 | 36 | window.child = menuButton 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/SignalListItemFactoryTest.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gobject.asType 4 | import bindings.gtk.testutils.GtkTestBase 5 | import kotlin.test.Ignore 6 | import kotlin.test.Test 7 | 8 | @Ignore 9 | class SignalListItemFactoryTest : GtkTestBase() { 10 | 11 | @Test 12 | fun testSignalListItemFactory() = runTestApplicationWindow { window -> 13 | val items = List(200) { "Item $it" } 14 | val model = StringList(items) 15 | val factory = SignalListItemFactory() 16 | val selectionModel = SingleSelection(model) 17 | 18 | factory.onSetup { listItem -> 19 | println("setup") 20 | listItem.child = Label() 21 | } 22 | factory.onBind { listItem -> 23 | val label = listItem.child!!.asType(Label.Type) 24 | val item = listItem.item!!.asType(StringObject.Type) 25 | label.text = item.string 26 | } 27 | factory.onUnbind { 28 | println("unbind") 29 | } 30 | factory.onTeardown { 31 | println("teardown") 32 | } 33 | 34 | val listView = ListView(selectionModel, factory) 35 | 36 | window.child = ScrolledWindow(listView) 37 | } 38 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/WindowTests.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk 2 | 3 | import bindings.gtk.testutils.GtkTestBase 4 | import kotlin.test.Ignore 5 | import kotlin.test.Test 6 | import kotlin.test.assertEquals 7 | 8 | @Ignore 9 | class WindowTests : GtkTestBase() { 10 | @Test 11 | fun presentWindow() = runTestApplication { handle -> 12 | val window = Window() 13 | 14 | window.application = handle.app 15 | window.defaultSize = Pair(1280, 720) 16 | window.title = "My Window" 17 | window.child = Button("Click me") 18 | 19 | window.present() 20 | 21 | assertEquals(1, Window.toplevels.itemCount) 22 | } 23 | } -------------------------------------------------------------------------------- /gtk-bindings/src/nativeTest/kotlin/bindings.gtk/testutils/GtkTestBase.kt: -------------------------------------------------------------------------------- 1 | package bindings.gtk.testutils 2 | 3 | import bindings.gtk.Application 4 | import bindings.gtk.ApplicationWindow 5 | import bindings.gtk.Window 6 | import native.gtk.gtk_init 7 | 8 | open class GtkTestBase { 9 | init { 10 | gtk_init() 11 | } 12 | 13 | /** 14 | * Create a GtkApplication and run the given [onActivateFunc] 15 | * when the application activates 16 | */ 17 | fun runTestApplication( 18 | applicationId: String = "io.quantus.gtktestbaseapplication", 19 | onActivateFunc: (TestApplicationHandle) -> Unit 20 | ) { 21 | val application = Application(applicationId) 22 | application.onActivate { onActivateFunc(TestApplicationHandle(application)) } 23 | application.runApplication() 24 | } 25 | 26 | /** 27 | * Create a GTK [Application] and a [Window]. 28 | * When the window is presented, the given [func] will run. 29 | */ 30 | fun runTestApplicationWindow( 31 | func: (ApplicationWindow) -> Unit 32 | ) { 33 | runTestApplication { 34 | val window = ApplicationWindow(it.app) 35 | window.title = this::class.simpleName 36 | window.application = it.app 37 | window.defaultSize = Pair(600, 400) 38 | 39 | func(window) 40 | window.present() 41 | } 42 | } 43 | } 44 | 45 | /** 46 | * A handle for a running test [Application]. 47 | * 48 | * The handle can be used to close the application. 49 | */ 50 | class TestApplicationHandle( 51 | val app: Application 52 | ) 53 | -------------------------------------------------------------------------------- /libadwaita-bindings/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("multiplatform") 3 | id("org.jetbrains.dokka") 4 | `maven-publish` 5 | } 6 | 7 | kotlin { 8 | val hostOs = System.getProperty("os.name") 9 | val isMingwX64 = hostOs.startsWith("Windows") 10 | val nativeTarget = when { 11 | hostOs == "Mac OS X" -> macosX64("native") 12 | hostOs == "Linux" -> linuxX64("native") 13 | isMingwX64 -> mingwX64("native") 14 | else -> throw GradleException("Host OS is not supported in Kotlin/Native.") 15 | } 16 | 17 | sourceSets { 18 | val nativeMain by getting { 19 | dependencies { 20 | api(project(":gobject-bindings")) 21 | api(project(":gio-bindings")) 22 | api(project(":gtk-bindings")) 23 | } 24 | } 25 | val nativeTest by getting 26 | } 27 | 28 | nativeTarget.apply { 29 | compilations["main"].cinterops { 30 | val adwaita by creating 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/ActionRow.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.Widget 5 | import bindings.gtk.asWidget 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.sizeOf 9 | import kotlinx.cinterop.toKString 10 | import native.adwaita.* 11 | 12 | open class ActionRow : PreferencesRow { 13 | val adwActionRowPointer get() = adwPreferencesRowPointer.asTypedPointer() 14 | 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | 17 | constructor() : this(adw_action_row_new()!!) 18 | 19 | // TODO activate signal handler 20 | 21 | override fun activate(): Boolean { 22 | adw_action_row_activate(adwActionRowPointer) 23 | return true 24 | } 25 | 26 | fun addPrefix(widget: Widget) = adw_action_row_add_prefix(adwActionRowPointer, widget.gtkWidgetPointer) 27 | 28 | fun addSuffix(widget: Widget) = adw_action_row_add_suffix(adwActionRowPointer, widget.gtkWidgetPointer) 29 | 30 | fun remove(widget: Widget) = adw_action_row_remove(adwActionRowPointer, widget.gtkWidgetPointer) 31 | 32 | 33 | var activatableWidget: Widget? 34 | get() = adw_action_row_get_activatable_widget(adwActionRowPointer)?.asWidget() 35 | set(value) = adw_action_row_set_activatable_widget(adwActionRowPointer, value?.gtkWidgetPointer) 36 | 37 | var iconName: String? 38 | get() = adw_action_row_get_icon_name(adwActionRowPointer)?.toKString() 39 | set(value) = adw_action_row_set_icon_name(adwActionRowPointer, value) 40 | 41 | var subtitle: String? 42 | get() = adw_action_row_get_subtitle(adwActionRowPointer)?.toKString() 43 | set(value) = adw_action_row_set_subtitle(adwActionRowPointer, value) 44 | 45 | var titleLines: Int 46 | get() = adw_action_row_get_title_lines(adwActionRowPointer) 47 | set(value) = adw_action_row_set_title_lines(adwActionRowPointer, value) 48 | 49 | var subtitleLines: Int 50 | get() = adw_action_row_get_subtitle_lines(adwActionRowPointer) 51 | set(value) = adw_action_row_set_subtitle_lines(adwActionRowPointer, value) 52 | 53 | companion object { 54 | val Type = BuiltinTypeInfo( 55 | ADW_TYPE_ACTION_ROW, 56 | sizeOf(), 57 | sizeOf(), 58 | ::ActionRow 59 | ) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/Application.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import internal.BuiltinTypeInfo 5 | import kotlinx.cinterop.CPointer 6 | import kotlinx.cinterop.sizeOf 7 | import native.adwaita.ADW_TYPE_APPLICATION 8 | import native.adwaita.AdwApplication 9 | import native.adwaita.AdwApplicationClass 10 | import native.adwaita.adw_application_new 11 | import native.gio.GApplicationFlags 12 | import native.gio.G_APPLICATION_FLAGS_NONE 13 | import bindings.gtk.Application as GtkApplication 14 | 15 | open class Application : GtkApplication { 16 | 17 | val adwApplicationPointer get() = gApplicationPointer.asTypedPointer() 18 | 19 | constructor(pointer: CPointer<*>) : super(pointer) 20 | 21 | constructor(applicationId: String, flags: GApplicationFlags = G_APPLICATION_FLAGS_NONE) : this( 22 | adw_application_new(applicationId, flags)!! 23 | ) 24 | 25 | companion object { 26 | val Type = BuiltinTypeInfo( 27 | ADW_TYPE_APPLICATION, 28 | sizeOf(), 29 | sizeOf(), 30 | ::Application 31 | ) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/ApplicationWindow.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.Application 5 | import bindings.gtk.Widget 6 | import bindings.gtk.asWidget 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.CPointer 9 | import kotlinx.cinterop.sizeOf 10 | import native.adwaita.* 11 | import bindings.gtk.ApplicationWindow as GtkApplicationWindow 12 | 13 | open class ApplicationWindow : GtkApplicationWindow { 14 | 15 | val adwApplicationWindowPointer get() = gtkWindowPointer.asTypedPointer() 16 | 17 | constructor(pointer: CPointer<*>) : super(pointer) 18 | constructor(application: Application) : this(adw_application_window_new(application.gtkApplicationPointer)!!) 19 | 20 | var content: Widget? 21 | get() = adw_application_window_get_content(adwApplicationWindowPointer)?.asWidget() 22 | set(value) = adw_application_window_set_content(adwApplicationWindowPointer, value?.gtkWidgetPointer) 23 | 24 | override var child = this.content 25 | 26 | companion object { 27 | val Type = BuiltinTypeInfo( 28 | ADW_TYPE_APPLICATION_WINDOW, 29 | sizeOf(), 30 | sizeOf(), 31 | ::ApplicationWindow 32 | ) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/Avatar.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import bindings.gtk.Widget 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.CPointer 9 | import kotlinx.cinterop.toKString 10 | import native.adwaita.* 11 | 12 | class Avatar : Widget { 13 | 14 | val adwAvatarPointer get() = gtkWidgetPointer.asTypedPointer() 15 | 16 | constructor(pointer: CPointer<*>) : super(pointer) 17 | 18 | constructor( 19 | size: Int, 20 | text: String? = null, 21 | showInitials: Boolean = false, 22 | ) : this(adw_avatar_new(size, text, showInitials.gboolean)!!) 23 | 24 | var iconName: String? 25 | get() = adw_avatar_get_icon_name(adwAvatarPointer)?.toKString() 26 | set(value) = adw_avatar_set_icon_name(adwAvatarPointer, value) 27 | 28 | var showInitials: Boolean 29 | get() = adw_avatar_get_show_initials(adwAvatarPointer).boolean 30 | set(value) = adw_avatar_set_show_initials(adwAvatarPointer, value.gboolean) 31 | 32 | var size: Int 33 | get() = adw_avatar_get_size(adwAvatarPointer) 34 | set(value) = adw_avatar_set_size(adwAvatarPointer, value) 35 | 36 | var text: String? 37 | get() = adw_avatar_get_text(adwAvatarPointer)?.toKString() 38 | set(value) = adw_avatar_set_text(adwAvatarPointer, value) 39 | 40 | companion object { 41 | val Type = BuiltinTypeInfo(ADW_TYPE_AVATAR, ::Avatar) 42 | } 43 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/Bin.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.Widget 5 | import bindings.gtk.asWidget 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.sizeOf 9 | import native.adwaita.* 10 | 11 | open class Bin : Widget { 12 | val adwBinPointer get() = gtkWidgetPointer.asTypedPointer() 13 | 14 | constructor(pointer: CPointer<*>) : super(pointer) 15 | constructor() : this(adw_bin_new()!!) 16 | 17 | var child: Widget? 18 | get() = adw_bin_get_child(adwBinPointer)?.asWidget() 19 | set(value) = adw_bin_set_child(adwBinPointer, value?.gtkWidgetPointer) 20 | 21 | companion object { 22 | val Type = BuiltinTypeInfo( 23 | ADW_TYPE_BIN, 24 | sizeOf(), 25 | sizeOf(), 26 | ::Bin 27 | ) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/ButtonContent.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import bindings.gtk.Widget 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.CPointer 9 | import kotlinx.cinterop.toKString 10 | import native.adwaita.* 11 | 12 | class ButtonContent : Widget { 13 | val adwButtonContentPointer get() = gtkWidgetPointer.asTypedPointer() 14 | 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | constructor() : this(adw_button_content_new()!!) 17 | constructor( 18 | label: String = "", 19 | iconName: String = "", 20 | useUnderline: Boolean = true 21 | ) : this() { // TODO what is the default for useUnderline? 22 | this.label = label 23 | this.iconName = iconName 24 | this.useUnderline = true 25 | } 26 | 27 | var iconName: String? 28 | get() = adw_button_content_get_icon_name(adwButtonContentPointer)?.toKString() 29 | set(value) = adw_button_content_set_icon_name(adwButtonContentPointer, value) 30 | 31 | var label: String? 32 | get() = adw_button_content_get_label(adwButtonContentPointer)?.toKString() 33 | set(value) = adw_button_content_set_label(adwButtonContentPointer, value) 34 | 35 | var useUnderline: Boolean 36 | get() = adw_button_content_get_use_underline(adwButtonContentPointer).boolean 37 | set(value) = adw_button_content_set_use_underline(adwButtonContentPointer, value.gboolean) 38 | 39 | companion object { 40 | val Type = BuiltinTypeInfo(ADW_TYPE_BUTTON_CONTENT, ::ButtonContent) 41 | } 42 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/Clamp.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.Orientable 5 | import bindings.gtk.Widget 6 | import bindings.gtk.asWidget 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.CPointer 9 | import native.adwaita.* 10 | import native.gtk.GtkOrientable 11 | 12 | class Clamp : Widget, Orientable { 13 | val adwClampPointer get() = gtkWidgetPointer.asTypedPointer() 14 | 15 | override val gtkOrientablePointer = gtkWidgetPointer.asTypedPointer() 16 | 17 | constructor(pointer: CPointer<*>) : super(pointer) 18 | 19 | constructor() : this(adw_clamp_new()!!) 20 | 21 | var child: Widget? 22 | get() = adw_clamp_get_child(adwClampPointer)?.asWidget() 23 | set(value) = adw_clamp_set_child(adwClampPointer, value?.gtkWidgetPointer) 24 | 25 | var maximumSize: Int 26 | get() = adw_clamp_get_maximum_size(adwClampPointer) 27 | set(value) = adw_clamp_set_maximum_size(adwClampPointer, value) 28 | 29 | var tighteningThreshold: Int 30 | get() = adw_clamp_get_tightening_threshold(adwClampPointer) 31 | set(value) = adw_clamp_set_tightening_threshold(adwClampPointer, value) 32 | 33 | companion object { 34 | val Type = BuiltinTypeInfo(ADW_TYPE_CLAMP, ::Clamp) 35 | } 36 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/ClampScrollable.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.Orientable 5 | import bindings.gtk.Scrollable 6 | import bindings.gtk.Widget 7 | import bindings.gtk.asWidget 8 | import internal.BuiltinTypeInfo 9 | import kotlinx.cinterop.CPointer 10 | import native.adwaita.* 11 | import native.gtk.GtkOrientable 12 | import native.gtk.GtkScrollable 13 | 14 | open class ClampScrollable : Widget, Scrollable, Orientable { 15 | val adwClampScrollablePointer get() = gtkWidgetPointer.asTypedPointer() 16 | 17 | override val gtkScrollablePointer get() = gtkWidgetPointer.asTypedPointer() 18 | override val gtkOrientablePointer get() = gtkWidgetPointer.asTypedPointer() 19 | 20 | constructor(pointer: CPointer<*>) : super(pointer) 21 | constructor() : this(adw_clamp_scrollable_new()!!) 22 | 23 | var child: Widget? 24 | get() = adw_clamp_scrollable_get_child(adwClampScrollablePointer)?.asWidget() 25 | set(value) = adw_clamp_scrollable_set_child(adwClampScrollablePointer, value?.gtkWidgetPointer) 26 | 27 | var maximumSize: Int 28 | get() = adw_clamp_scrollable_get_maximum_size(adwClampScrollablePointer) 29 | set(value) = adw_clamp_scrollable_set_maximum_size(adwClampScrollablePointer, value) 30 | 31 | var tighteningThreshold: Int 32 | get() = adw_clamp_scrollable_get_tightening_threshold(adwClampScrollablePointer) 33 | set(value) = adw_clamp_scrollable_set_tightening_threshold(adwClampScrollablePointer, value) 34 | 35 | companion object { 36 | val Type = BuiltinTypeInfo(ADW_TYPE_CLAMP_SCROLLABLE, ::ClampScrollable) 37 | } 38 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/ComboRow.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gio.ListModel 4 | import bindings.gio.asListModel 5 | import bindings.gobject.* 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.sizeOf 9 | import native.adwaita.* 10 | 11 | open class ComboRow : ActionRow { 12 | val adwComboRowPointer get() = adwActionRowPointer.asTypedPointer() 13 | 14 | constructor(pointer: CPointer<*>) : super(pointer) 15 | 16 | constructor() : this(adw_combo_row_new()!!) 17 | 18 | // TODO add expression property with GtkExpression 19 | 20 | // TODO add factory property 21 | // TODO add listFactory property 22 | 23 | var model: ListModel? 24 | get() = adw_combo_row_get_model(adwComboRowPointer)?.asListModel() 25 | set(value) = adw_combo_row_set_model(adwComboRowPointer, value?.gListModelPointer) 26 | 27 | var selected: Int 28 | get() = adw_combo_row_get_selected(adwComboRowPointer).toInt() 29 | set(value) = adw_combo_row_set_selected(adwComboRowPointer, value.toUInt()) 30 | 31 | val selectedItem: Object? 32 | get() = adw_combo_row_get_selected_item(adwComboRowPointer)?.asObject() 33 | 34 | var useSubtitle: Boolean 35 | get() = adw_combo_row_get_use_subtitle(adwComboRowPointer).boolean 36 | set(value) = adw_combo_row_set_use_subtitle(adwComboRowPointer, value.gboolean) 37 | 38 | companion object { 39 | val Type = BuiltinTypeInfo( 40 | ADW_TYPE_COMBO_ROW, 41 | sizeOf(), 42 | sizeOf(), 43 | ::ComboRow 44 | ) 45 | } 46 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/ExpanderRow.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import bindings.gtk.Widget 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.CPointer 9 | import kotlinx.cinterop.sizeOf 10 | import kotlinx.cinterop.toKString 11 | import native.adwaita.* 12 | 13 | open class ExpanderRow : PreferencesRow { 14 | 15 | val adwExpanderRowPointer get() = adwPreferencesRowPointer.asTypedPointer() 16 | 17 | constructor(pointer: CPointer<*>) : super(pointer) 18 | constructor() : this(adw_expander_row_new()!!) 19 | 20 | 21 | var expanded: Boolean 22 | get() = adw_expander_row_get_expanded(adwExpanderRowPointer).boolean 23 | set(value) = adw_expander_row_set_expanded(adwExpanderRowPointer, value.gboolean) 24 | 25 | var iconName: String? 26 | get() = adw_expander_row_get_icon_name(adwExpanderRowPointer)?.toKString() 27 | set(value) = adw_expander_row_set_icon_name(adwExpanderRowPointer, value) 28 | 29 | var showEnableSwitch: Boolean 30 | get() = adw_expander_row_get_show_enable_switch(adwExpanderRowPointer).boolean 31 | set(value) = adw_expander_row_set_show_enable_switch(adwExpanderRowPointer, value.gboolean) 32 | 33 | var enableExpansion: Boolean 34 | get() = adw_expander_row_get_enable_expansion(adwExpanderRowPointer).boolean 35 | set(value) = adw_expander_row_set_enable_expansion(adwExpanderRowPointer, value.gboolean) 36 | 37 | var subtitle: String 38 | get() = adw_expander_row_get_subtitle(adwExpanderRowPointer)!!.toKString() 39 | set(value) = adw_expander_row_set_subtitle(adwExpanderRowPointer, value) 40 | 41 | fun addPrefix(widget: Widget) = adw_expander_row_add_prefix(adwExpanderRowPointer, widget.gtkWidgetPointer) 42 | 43 | fun addAction(widget: Widget) = adw_expander_row_add_action(adwExpanderRowPointer, widget.gtkWidgetPointer) 44 | 45 | fun addRow(widget: Widget) = adw_expander_row_add_row(adwExpanderRowPointer, widget.gtkWidgetPointer) 46 | 47 | fun remove(widget: Widget) = adw_expander_row_remove(adwExpanderRowPointer, widget.gtkWidgetPointer) 48 | 49 | companion object { 50 | val Type = BuiltinTypeInfo( 51 | ADW_TYPE_EXPANDER_ROW, 52 | sizeOf(), 53 | sizeOf(), 54 | ::ExpanderRow 55 | ) 56 | } 57 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/HeaderBar.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import bindings.gtk.Widget 7 | import bindings.gtk.asWidget 8 | import internal.BuiltinTypeInfo 9 | import kotlinx.cinterop.CPointer 10 | import kotlinx.cinterop.toKString 11 | import native.adwaita.* 12 | 13 | class HeaderBar : Widget { 14 | 15 | val adwHeaderBarPointer get() = gtkWidgetPointer.asTypedPointer() 16 | 17 | constructor(pointer: CPointer<*>) : super(pointer) 18 | 19 | constructor() : this(adw_header_bar_new()!!) 20 | 21 | var showEndTitleButtons: Boolean 22 | get() = adw_header_bar_get_show_end_title_buttons(adwHeaderBarPointer).boolean 23 | set(value) = adw_header_bar_set_show_end_title_buttons(adwHeaderBarPointer, value.gboolean) 24 | 25 | var showStartTitleButtons: Boolean 26 | get() = adw_header_bar_get_show_start_title_buttons(adwHeaderBarPointer).boolean 27 | set(value) = adw_header_bar_set_show_start_title_buttons(adwHeaderBarPointer, value.gboolean) 28 | 29 | var centerPolicy: AdwCenteringPolicy 30 | get() = adw_header_bar_get_centering_policy(adwHeaderBarPointer) 31 | set(value) = adw_header_bar_set_centering_policy(adwHeaderBarPointer, value) 32 | 33 | var decorationLayout: String? 34 | get() = adw_header_bar_get_decoration_layout(adwHeaderBarPointer)?.toKString() 35 | set(value) = adw_header_bar_set_decoration_layout(adwHeaderBarPointer, value) 36 | 37 | var titleWidget: Widget? 38 | get() = adw_header_bar_get_title_widget(adwHeaderBarPointer)?.asWidget() 39 | set(value) = adw_header_bar_set_title_widget(adwHeaderBarPointer, value?.gtkWidgetPointer) 40 | 41 | fun packStart(widget: Widget) = adw_header_bar_pack_start(adwHeaderBarPointer, widget.gtkWidgetPointer) 42 | 43 | fun packEnd(widget: Widget) = adw_header_bar_pack_end(adwHeaderBarPointer, widget.gtkWidgetPointer) 44 | 45 | fun remove(widget: Widget) = adw_header_bar_remove(adwHeaderBarPointer, widget.gtkWidgetPointer) 46 | 47 | companion object { 48 | val Type = BuiltinTypeInfo(ADW_TYPE_HEADER_BAR, ::HeaderBar) 49 | } 50 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/LeafletPage.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import bindings.gobject.boolean 6 | import bindings.gobject.gboolean 7 | import bindings.gtk.Widget 8 | import bindings.gtk.asWidget 9 | import internal.BuiltinTypeInfo 10 | import kotlinx.cinterop.CPointer 11 | import kotlinx.cinterop.toKString 12 | import native.adwaita.* 13 | 14 | class LeafletPage : Object { 15 | val adwLeafletPagePointer get() = gPointer.asTypedPointer() 16 | 17 | constructor(pointer: CPointer<*>) : super(pointer) 18 | 19 | val child: Widget 20 | get() = adw_leaflet_page_get_child(adwLeafletPagePointer)!!.asWidget() 21 | 22 | var name: String? 23 | get() = adw_leaflet_page_get_name(adwLeafletPagePointer)?.toKString() 24 | set(value) = adw_leaflet_page_set_name(adwLeafletPagePointer, value) 25 | 26 | var navigatable: Boolean 27 | get() = adw_leaflet_page_get_navigatable(adwLeafletPagePointer).boolean 28 | set(value) = adw_leaflet_page_set_navigatable(adwLeafletPagePointer, value.gboolean) 29 | 30 | companion object { 31 | val Type = BuiltinTypeInfo(ADW_TYPE_LEAFLET_PAGE, ::LeafletPage) 32 | } 33 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/PasswordEntryRow.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import internal.BuiltinTypeInfo 5 | import kotlinx.cinterop.CPointer 6 | import native.adwaita.ADW_TYPE_PASSWORD_ENTRY_ROW 7 | import native.adwaita.AdwPasswordEntryRow 8 | import native.adwaita.adw_password_entry_row_new 9 | 10 | class PasswordEntryRow : EntryRow { 11 | val adwPasswordEntryRow get() = adwEntryRowPointer.asTypedPointer() 12 | 13 | constructor(pointer: CPointer<*>) : super(pointer) 14 | constructor() : this(adw_password_entry_row_new()!!) 15 | 16 | companion object { 17 | val Type = BuiltinTypeInfo(ADW_TYPE_PASSWORD_ENTRY_ROW, ::PasswordEntryRow) 18 | } 19 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/PreferencesGroup.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.Widget 5 | import bindings.gtk.asWidget 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.sizeOf 9 | import kotlinx.cinterop.toKString 10 | import native.adwaita.* 11 | 12 | open class PreferencesGroup : Widget { 13 | val adwPreferencesGroupPointer get() = gtkWidgetPointer.asTypedPointer() 14 | 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | constructor() : this(adw_preferences_group_new()!!) 17 | 18 | var title: String 19 | get() = adw_preferences_group_get_title(adwPreferencesGroupPointer)!!.toKString() 20 | set(value) = adw_preferences_group_set_title(adwPreferencesGroupPointer, value) 21 | 22 | var description: String? 23 | get() = adw_preferences_group_get_description(adwPreferencesGroupPointer)?.toKString() 24 | set(value) = adw_preferences_group_set_description(adwPreferencesGroupPointer, value) 25 | 26 | var headerSuffix: Widget? 27 | get() = adw_preferences_group_get_header_suffix(adwPreferencesGroupPointer)?.asWidget() 28 | set(value) = adw_preferences_group_set_header_suffix(adwPreferencesGroupPointer, value?.gtkWidgetPointer) 29 | 30 | fun add(widget: Widget) = adw_preferences_group_add(adwPreferencesGroupPointer, widget.gtkWidgetPointer) 31 | 32 | fun remove(widget: Widget) = adw_preferences_group_remove(adwPreferencesGroupPointer, widget.gtkWidgetPointer) 33 | 34 | companion object { 35 | val Type = BuiltinTypeInfo( 36 | ADW_TYPE_PREFERENCES_GROUP, 37 | sizeOf(), 38 | sizeOf(), 39 | ::PreferencesGroup 40 | ) 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/PreferencesPage.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import bindings.gtk.Widget 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.CPointer 9 | import kotlinx.cinterop.sizeOf 10 | import kotlinx.cinterop.toKString 11 | import native.adwaita.* 12 | 13 | open class PreferencesPage : Widget { 14 | val adwPreferencesPagePointer get() = gtkWidgetPointer.asTypedPointer() 15 | 16 | constructor(pointer: CPointer<*>) : super(pointer) 17 | constructor() : this(adw_preferences_page_new()!!) 18 | 19 | var iconName: String? 20 | get() = adw_preferences_page_get_icon_name(adwPreferencesPagePointer)?.toKString() 21 | set(value) = adw_preferences_page_set_icon_name(adwPreferencesPagePointer, value) 22 | 23 | // TODO check this, widget already has a name property 24 | var name: String? 25 | get() = adw_preferences_page_get_name(adwPreferencesPagePointer)?.toKString() 26 | set(value) = adw_preferences_page_set_name(adwPreferencesPagePointer, value) 27 | 28 | var title: String 29 | get() = adw_preferences_page_get_title(adwPreferencesPagePointer)?.toKString() ?: "" 30 | set(value) = adw_preferences_page_set_title(adwPreferencesPagePointer, value) 31 | 32 | var useUnderline: Boolean 33 | get() = adw_preferences_page_get_use_underline(adwPreferencesPagePointer).boolean 34 | set(value) = adw_preferences_page_set_use_underline(adwPreferencesPagePointer, value.gboolean) 35 | 36 | fun add(group: PreferencesGroup) = 37 | adw_preferences_page_add(adwPreferencesPagePointer, group.adwPreferencesGroupPointer) 38 | 39 | fun remove(group: PreferencesGroup) = 40 | adw_preferences_page_remove(adwPreferencesPagePointer, group.adwPreferencesGroupPointer) 41 | 42 | companion object { 43 | val Type = BuiltinTypeInfo( 44 | ADW_TYPE_PREFERENCES_PAGE, 45 | sizeOf(), 46 | sizeOf(), 47 | ::PreferencesPage 48 | ) 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/PreferencesRow.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import bindings.gtk.Actionable 7 | import bindings.gtk.ListBoxRow 8 | import internal.BuiltinTypeInfo 9 | import kotlinx.cinterop.CPointer 10 | import kotlinx.cinterop.sizeOf 11 | import kotlinx.cinterop.toKString 12 | import native.adwaita.* 13 | import native.gtk.GtkActionable 14 | 15 | open class PreferencesRow : ListBoxRow, Actionable { 16 | 17 | val adwPreferencesRowPointer get() = gtkListBoxRowPointer.asTypedPointer() 18 | 19 | override val gtkActionablePointer get() = adwPreferencesRowPointer.asTypedPointer() 20 | 21 | constructor(pointer: CPointer<*>) : super(pointer) 22 | 23 | constructor() : this(adw_preferences_row_new()!!) 24 | 25 | var title: String 26 | get() = adw_preferences_row_get_title(adwPreferencesRowPointer)!!.toKString() 27 | set(value) = adw_preferences_row_set_title(adwPreferencesRowPointer, value) 28 | 29 | var useUnderline: Boolean 30 | get() = adw_preferences_row_get_use_underline(adwPreferencesRowPointer).boolean 31 | set(value) = adw_preferences_row_set_use_underline(adwPreferencesRowPointer, value.gboolean) 32 | 33 | var useMarkup: Boolean 34 | get() = adw_preferences_row_get_use_markup(adwPreferencesRowPointer).boolean 35 | set(value) = adw_preferences_row_set_use_markup(adwPreferencesRowPointer, value.gboolean) 36 | 37 | var titleSelectable: Boolean 38 | get() = adw_preferences_row_get_title_selectable(adwPreferencesRowPointer).boolean 39 | set(value) = adw_preferences_row_set_title_selectable(adwPreferencesRowPointer, value.gboolean) 40 | 41 | companion object { 42 | val Type = BuiltinTypeInfo( 43 | ADW_TYPE_PREFERENCES_ROW, 44 | sizeOf(), 45 | sizeOf(), 46 | ::PreferencesRow 47 | ) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/StatusPage.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.Widget 5 | import bindings.gtk.asWidget 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.toKString 9 | import native.adwaita.* 10 | 11 | class StatusPage : Widget { 12 | val adwStatusPagePointer get() = gtkWidgetPointer.asTypedPointer() 13 | 14 | constructor(pointer: CPointer<*>) : super(pointer) 15 | 16 | constructor() : this(adw_status_page_new()!!) 17 | 18 | var title: String? 19 | get() = adw_status_page_get_title(adwStatusPagePointer)?.toKString() 20 | set(value) = adw_status_page_set_title(adwStatusPagePointer, value) 21 | 22 | var iconName: String? 23 | get() = adw_status_page_get_icon_name(adwStatusPagePointer)?.toKString() 24 | set(value) = adw_status_page_set_icon_name(adwStatusPagePointer, value) 25 | 26 | var description: String? 27 | get() = adw_status_page_get_description(adwStatusPagePointer)?.toKString() 28 | set(value) = adw_status_page_set_description(adwStatusPagePointer, value) 29 | 30 | var child: Widget? 31 | get() = adw_status_page_get_child(adwStatusPagePointer)?.asWidget() 32 | set(value) = adw_status_page_set_child(adwStatusPagePointer, value?.gtkWidgetPointer) 33 | 34 | // TODO add paintable with GdkPaintable support 35 | 36 | companion object { 37 | val Type = BuiltinTypeInfo(ADW_TYPE_STATUS_PAGE, ::StatusPage) 38 | } 39 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/TabBar.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import bindings.gtk.Widget 7 | import bindings.gtk.asWidget 8 | import internal.BuiltinTypeInfo 9 | import kotlinx.cinterop.CPointer 10 | import native.adwaita.* 11 | 12 | class TabBar : Widget { 13 | val adwTabBarPointer get() = gtkWidgetPointer.asTypedPointer() 14 | 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | constructor() : this(adw_tab_bar_new()!!) 17 | 18 | var autohide: Boolean 19 | get() = adw_tab_bar_get_autohide(adwTabBarPointer).boolean 20 | set(value) = adw_tab_bar_set_autohide(adwTabBarPointer, value.gboolean) 21 | 22 | var endActionWidget: Widget? 23 | get() = adw_tab_bar_get_end_action_widget(adwTabBarPointer)?.asWidget() 24 | set(value) = adw_tab_bar_set_end_action_widget(adwTabBarPointer, value?.gtkWidgetPointer) 25 | 26 | var expandTabs: Boolean 27 | get() = adw_tab_bar_get_expand_tabs(adwTabBarPointer).boolean 28 | set(value) = adw_tab_bar_set_expand_tabs(adwTabBarPointer, value.gboolean) 29 | 30 | var inverted: Boolean 31 | get() = adw_tab_bar_get_inverted(adwTabBarPointer).boolean 32 | set(value) = adw_tab_bar_set_inverted(adwTabBarPointer, value.gboolean) 33 | 34 | val isOverflowing: Boolean get() = adw_tab_bar_get_is_overflowing(adwTabBarPointer).boolean 35 | 36 | var startActionWidget: Widget? 37 | get() = adw_tab_bar_get_start_action_widget(adwTabBarPointer)?.asWidget() 38 | set(value) = adw_tab_bar_set_start_action_widget(adwTabBarPointer, value?.gtkWidgetPointer) 39 | 40 | val tabsRevealed: Boolean get() = adw_tab_bar_get_tabs_revealed(adwTabBarPointer).boolean 41 | 42 | var view: TabView? 43 | get() = adw_tab_bar_get_view(adwTabBarPointer)?.asTabView() 44 | set(value) = adw_tab_bar_set_view(adwTabBarPointer, value?.adwTabViewPointer) 45 | 46 | // TODO setupExtraDropTarget once there is GdkDragAction support 47 | // TODO extra-drag-drop signal 48 | 49 | companion object { 50 | val Type = BuiltinTypeInfo(ADW_TYPE_TAB_BAR, ::TabBar) 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/TabPage.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import bindings.gobject.boolean 6 | import bindings.gobject.gboolean 7 | import bindings.gtk.Widget 8 | import bindings.gtk.asWidget 9 | import internal.BuiltinTypeInfo 10 | import kotlinx.cinterop.CPointer 11 | import kotlinx.cinterop.toKString 12 | import native.adwaita.* 13 | 14 | class TabPage : Object { 15 | val adwTabPagePointer get() = gPointer.asTypedPointer() 16 | 17 | constructor(pointer: CPointer<*>) : super(pointer) 18 | 19 | val child: Widget 20 | get() = adw_tab_page_get_child(adwTabPagePointer)!!.asWidget() 21 | 22 | // TODO icon property with GIcon 23 | 24 | var indicatorActivatable: Boolean 25 | get() = adw_tab_page_get_indicator_activatable(adwTabPagePointer).boolean 26 | set(value) = adw_tab_page_set_indicator_activatable(adwTabPagePointer, value.gboolean) 27 | 28 | // TODO indicator icon propery with GIcon 29 | 30 | var indicatorTooltip: String 31 | get() = adw_tab_page_get_indicator_tooltip(adwTabPagePointer)?.toKString() ?: "" 32 | set(value) = adw_tab_page_set_indicator_tooltip(adwTabPagePointer, value) 33 | 34 | var loading: Boolean 35 | get() = adw_tab_page_get_loading(adwTabPagePointer).boolean 36 | set(value) = adw_tab_page_set_loading(adwTabPagePointer, value.gboolean) 37 | 38 | var needsAttention: Boolean 39 | get() = adw_tab_page_get_needs_attention(adwTabPagePointer).boolean 40 | set(value) = adw_tab_page_set_needs_attention(adwTabPagePointer, value.gboolean) 41 | 42 | val parent: TabPage? 43 | get() = adw_tab_page_get_parent(adwTabPagePointer)?.asTabPage() 44 | 45 | val pinned: Boolean 46 | get() = adw_tab_page_get_pinned(adwTabPagePointer).boolean 47 | 48 | val selected: Boolean 49 | get() = adw_tab_page_get_selected(adwTabPagePointer).boolean 50 | 51 | var title: String 52 | get() = adw_tab_page_get_title(adwTabPagePointer)?.toKString() ?: "" 53 | set(value) = adw_tab_page_set_title(adwTabPagePointer, value) 54 | 55 | var tooltip: String? 56 | get() = adw_tab_page_get_tooltip(adwTabPagePointer)?.toKString() 57 | set(value) = adw_tab_page_set_tooltip(adwTabPagePointer, value) 58 | 59 | companion object { 60 | val Type = BuiltinTypeInfo(ADW_TYPE_TAB_PAGE, ::TabPage) 61 | } 62 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/ToastOverlay.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.Widget 5 | import bindings.gtk.asWidget 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import native.adwaita.* 9 | 10 | class ToastOverlay : Widget { 11 | 12 | val adwToastOverlayPointer get() = gtkWidgetPointer.asTypedPointer() 13 | 14 | constructor(pointer: CPointer<*>) : super(pointer) 15 | 16 | constructor() : this(adw_toast_overlay_new()!!) 17 | 18 | var child: Widget? 19 | get() = adw_toast_overlay_get_child(adwToastOverlayPointer)?.asWidget() 20 | set(value) = adw_toast_overlay_set_child(adwToastOverlayPointer, value?.gtkWidgetPointer) 21 | 22 | fun addToast(toast: Toast) = adw_toast_overlay_add_toast(adwToastOverlayPointer, toast.adwToastPointer) 23 | 24 | companion object { 25 | val Type = BuiltinTypeInfo(ADW_TYPE_TOAST_OVERLAY, ::ToastOverlay) 26 | } 27 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/ViewStackPage.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.Object 4 | import bindings.gobject.asTypedPointer 5 | import bindings.gobject.boolean 6 | import bindings.gobject.gboolean 7 | import bindings.gtk.Widget 8 | import bindings.gtk.asWidget 9 | import internal.BuiltinTypeInfo 10 | import kotlinx.cinterop.CPointer 11 | import kotlinx.cinterop.toKString 12 | import native.adwaita.* 13 | 14 | class ViewStackPage : Object { 15 | 16 | val adwViewStackPagePointer get() = gPointer.asTypedPointer() 17 | 18 | constructor(pointer: CPointer<*>) : super(pointer) 19 | 20 | var badgeNumber: Int 21 | get() = adw_view_stack_page_get_badge_number(adwViewStackPagePointer).toInt() 22 | set(value) = adw_view_stack_page_set_badge_number(adwViewStackPagePointer, value.toUInt()) 23 | 24 | val child: Widget 25 | get() = adw_view_stack_page_get_child(adwViewStackPagePointer)!!.asWidget() 26 | 27 | var iconName: String? 28 | get() = adw_view_stack_page_get_icon_name(adwViewStackPagePointer)?.toKString() 29 | set(value) = adw_view_stack_page_set_icon_name(adwViewStackPagePointer, value) 30 | 31 | var name: String? 32 | get() = adw_view_stack_page_get_name(adwViewStackPagePointer)?.toKString() 33 | set(value) = adw_view_stack_page_set_name(adwViewStackPagePointer, value) 34 | 35 | var needsAttention: Boolean 36 | get() = adw_view_stack_page_get_needs_attention(adwViewStackPagePointer).boolean 37 | set(value) = adw_view_stack_page_set_needs_attention(adwViewStackPagePointer, value.gboolean) 38 | 39 | var title: String? 40 | get() = adw_view_stack_page_get_title(adwViewStackPagePointer)?.toKString() 41 | set(value) = adw_view_stack_page_set_title(adwViewStackPagePointer, value) 42 | 43 | var useUnderline: Boolean 44 | get() = adw_view_stack_page_get_use_underline(adwViewStackPagePointer).boolean 45 | set(value) = adw_view_stack_page_set_use_underline(adwViewStackPagePointer, value.gboolean) 46 | 47 | var visible: Boolean 48 | get() = adw_view_stack_page_get_visible(adwViewStackPagePointer).boolean 49 | set(value) = adw_view_stack_page_set_visible(adwViewStackPagePointer, value.gboolean) 50 | 51 | companion object { 52 | val Type = BuiltinTypeInfo(ADW_TYPE_VIEW_STACK_PAGE, ::ViewStackPage) 53 | } 54 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/ViewSwitcher.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.Widget 5 | import internal.BuiltinTypeInfo 6 | import kotlinx.cinterop.CPointer 7 | import native.adwaita.* 8 | 9 | class ViewSwitcher : Widget { 10 | val adwViewSwitcherPointer get() = gtkWidgetPointer.asTypedPointer() 11 | 12 | constructor(pointer: CPointer<*>) : super(pointer) 13 | constructor() : this(adw_view_switcher_new()!!) 14 | 15 | var policy: AdwViewSwitcherPolicy 16 | get() = adw_view_switcher_get_policy(adwViewSwitcherPointer) 17 | set(value) = adw_view_switcher_set_policy(adwViewSwitcherPointer, value) 18 | 19 | var stack: ViewStack? 20 | get() = adw_view_switcher_get_stack(adwViewSwitcherPointer)?.asViewStack() 21 | set(value) = adw_view_switcher_set_stack(adwViewSwitcherPointer, value?.adwViewStackPointer) 22 | 23 | companion object { 24 | val Type = BuiltinTypeInfo(ADW_TYPE_VIEW_SWITCHER, ::ViewSwitcher) 25 | } 26 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/ViewSwitcherBar.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import bindings.gtk.Widget 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.CPointer 9 | import native.adwaita.* 10 | 11 | class ViewSwitcherBar : Widget { 12 | val adwViewSwitcherBarPointer get() = gtkWidgetPointer.asTypedPointer() 13 | 14 | constructor(pointer: CPointer<*>) : super(pointer) 15 | constructor() : this(adw_view_switcher_bar_new()!!) 16 | 17 | 18 | var reveal: Boolean 19 | get() = adw_view_switcher_bar_get_reveal(adwViewSwitcherBarPointer).boolean 20 | set(value) = adw_view_switcher_bar_set_reveal(adwViewSwitcherBarPointer, value.gboolean) 21 | 22 | var stack: ViewStack? 23 | get() = adw_view_switcher_bar_get_stack(adwViewSwitcherBarPointer)?.asViewStack() 24 | set(value) = adw_view_switcher_bar_set_stack(adwViewSwitcherBarPointer, value?.adwViewStackPointer) 25 | 26 | companion object { 27 | val Type = BuiltinTypeInfo(ADW_TYPE_VIEW_SWITCHER_BAR, ::ViewSwitcherBar) 28 | } 29 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/ViewSwitcherTitle.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gobject.boolean 5 | import bindings.gobject.gboolean 6 | import bindings.gtk.Widget 7 | import internal.BuiltinTypeInfo 8 | import kotlinx.cinterop.CPointer 9 | import kotlinx.cinterop.toKString 10 | import native.adwaita.* 11 | 12 | class ViewSwitcherTitle : Widget { 13 | val adwViewSwitcherTitlePointer get() = gtkWidgetPointer.asTypedPointer() 14 | 15 | constructor(pointer: CPointer<*>) : super(pointer) 16 | constructor() : this(adw_view_switcher_title_new()!!) 17 | 18 | var stack: ViewStack? 19 | get() = adw_view_switcher_title_get_stack(adwViewSwitcherTitlePointer)?.asViewStack() 20 | set(value) = adw_view_switcher_title_set_stack(adwViewSwitcherTitlePointer, value?.adwViewStackPointer) 21 | 22 | var subtitle: String 23 | get() = adw_view_switcher_title_get_subtitle(adwViewSwitcherTitlePointer)?.toKString() ?: "" 24 | set(value) = adw_view_switcher_title_set_subtitle(adwViewSwitcherTitlePointer, value) 25 | 26 | var title: String 27 | get() = adw_view_switcher_title_get_title(adwViewSwitcherTitlePointer)?.toKString() ?: "" 28 | set(value) = adw_view_switcher_title_set_title(adwViewSwitcherTitlePointer, value) 29 | 30 | val titleVisible: Boolean get() = adw_view_switcher_title_get_title_visible(adwViewSwitcherTitlePointer).boolean 31 | 32 | var viewSwitcherEnabled: Boolean 33 | get() = adw_view_switcher_title_get_view_switcher_enabled(adwViewSwitcherTitlePointer).boolean 34 | set(value) = adw_view_switcher_title_set_view_switcher_enabled(adwViewSwitcherTitlePointer, value.gboolean) 35 | 36 | companion object { 37 | val Type = BuiltinTypeInfo(ADW_TYPE_VIEW_SWITCHER_TITLE, ::ViewSwitcherTitle) 38 | } 39 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/Window.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.Widget 5 | import bindings.gtk.asWidget 6 | import internal.BuiltinTypeInfo 7 | import kotlinx.cinterop.CPointer 8 | import kotlinx.cinterop.sizeOf 9 | import native.adwaita.* 10 | import bindings.gtk.Window as GtkWindow 11 | 12 | open class Window : GtkWindow { 13 | 14 | val adwWindowPointer get() = gtkWindowPointer.asTypedPointer() 15 | 16 | constructor(pointer: CPointer<*>) : super(pointer) 17 | 18 | constructor() : this(adw_window_new()!!) 19 | 20 | var content: Widget? 21 | get() = adw_window_get_content(adwWindowPointer)?.asWidget() 22 | set(value) = adw_window_set_content(adwWindowPointer, value?.gtkWidgetPointer) 23 | 24 | override var child = this.content 25 | 26 | companion object { 27 | val Type = BuiltinTypeInfo( 28 | ADW_TYPE_WINDOW, 29 | sizeOf(), 30 | sizeOf(), 31 | ::Window 32 | ) 33 | } 34 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/WindowTitle.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw 2 | 3 | import bindings.gobject.asTypedPointer 4 | import bindings.gtk.Widget 5 | import internal.BuiltinTypeInfo 6 | import kotlinx.cinterop.CPointer 7 | import kotlinx.cinterop.toKString 8 | import native.adwaita.* 9 | 10 | class WindowTitle : Widget { 11 | val adwWindowTitlePointer get() = gtkWidgetPointer.asTypedPointer() 12 | 13 | constructor(pointer: CPointer<*>) : super(pointer) 14 | constructor(title: String = "", subtitle: String = "") : this(adw_window_title_new(title, subtitle)!!) 15 | 16 | var title: String 17 | get() = adw_window_title_get_title(adwWindowTitlePointer)?.toKString() ?: "" 18 | set(value) = adw_window_title_set_title(adwWindowTitlePointer, value) 19 | 20 | var subtitle: String 21 | get() = adw_window_title_get_subtitle(adwWindowTitlePointer)?.toKString() ?: "" 22 | set(value) = adw_window_title_set_subtitle(adwWindowTitlePointer, value) 23 | 24 | companion object { 25 | val Type = BuiltinTypeInfo(ADW_TYPE_WINDOW_TITLE, ::WindowTitle) 26 | } 27 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeMain/kotlin/bindings.adw/internal/Signals.kt: -------------------------------------------------------------------------------- 1 | package bindings.adw.internal 2 | 3 | import kotlinx.cinterop.asStableRef 4 | import kotlinx.cinterop.reinterpret 5 | import kotlinx.cinterop.staticCFunction 6 | import native.gobject.GClosureNotify 7 | import native.gobject.gpointer 8 | 9 | /** 10 | * Helper function that can be used as a destroy_data handler 11 | * when connecting to a signal. 12 | * 13 | * This implementation assumes [data] is a pointer to a StableRef 14 | * and calls dispose on it. 15 | */ 16 | internal val staticStableRefDestroy: GClosureNotify = 17 | staticCFunction { data: gpointer?, 18 | _: gpointer? -> 19 | data?.asStableRef()?.dispose() 20 | Unit 21 | }.reinterpret() -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdMessageDialogTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.Avatar 2 | import bindings.adw.MessageDialog 3 | import bindings.adw.Toast 4 | import bindings.adw.ToastOverlay 5 | import bindings.gtk.ListBox 6 | import native.adwaita.AdwResponseAppearance 7 | import kotlin.test.Ignore 8 | import kotlin.test.Test 9 | 10 | @Ignore 11 | class AdMessageDialogTest : AdwTestBase() { 12 | 13 | @Test 14 | fun testMessageDialogs() = runApplicationWindow { window -> 15 | val toastOverlay = ToastOverlay() 16 | toastOverlay.vexpand = true 17 | val listBox = ListBox() 18 | 19 | listBox.addButton("Simple Message Dialog") { 20 | MessageDialog(window, "Heading", "Body").show() 21 | } 22 | listBox.addButton("Widget Dialog") { 23 | MessageDialog(window, "Heading", "Body").apply { 24 | extraChild = Avatar(30, null, false) 25 | }.show() 26 | } 27 | listBox.addButton("Responses Dialog") { 28 | MessageDialog(window, "Heading", "Body").apply { 29 | addResponse("cancel", "Cancel") 30 | setResponseAppearance("cancel", AdwResponseAppearance.ADW_RESPONSE_DEFAULT) 31 | addResponse("discard", "Discard") 32 | setResponseAppearance("discard", AdwResponseAppearance.ADW_RESPONSE_DESTRUCTIVE) 33 | addResponse("save", "Save") 34 | setResponseAppearance("save", AdwResponseAppearance.ADW_RESPONSE_SUGGESTED) 35 | 36 | onResponse { response -> 37 | toastOverlay.addToast(Toast("You chose : $response")) 38 | } 39 | 40 | }.show() 41 | } 42 | 43 | toastOverlay.child = listBox 44 | 45 | window.setTestContent("Message Dialogs", toastOverlay) 46 | } 47 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwAboutWindowTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.AboutWindow 2 | import native.gtk.GtkLicense 3 | import kotlin.test.Ignore 4 | import kotlin.test.Test 5 | 6 | @Ignore 7 | class AdwAboutWindowTest : AdwTestBase() { 8 | 9 | @Test 10 | fun testAboutWindow() = runApplicationWindow { window -> 11 | val about = AboutWindow() 12 | about.transientFor = window 13 | 14 | about.applicationIcon = "folder-music" 15 | about.applicationName = "Test Application" 16 | about.artists = listOf("Chuck Schuldiner", "Chris Cornell", "Layne Staley") 17 | about.comments = "Sample comments." 18 | about.copyright = "Copyright 2022 - Steven Van Bael" 19 | about.debugInfo = "Sample debug info." 20 | about.debugInfoFilename = "/tmp/debug.txt" 21 | about.designers = listOf("Designer 1", "Designer 2") 22 | about.developerName = "Steven Van Bael" 23 | about.developers = listOf("Steven Van Bael", "Mystery Developer") 24 | about.documenters = listOf("Documenter 1", "Documenter 2") 25 | about.issueUrl = "https://github.com/vbsteven/gtk-kotlin-native/issues" 26 | about.license = "The License Text" 27 | about.licenseType = GtkLicense.GTK_LICENSE_MIT_X11 28 | about.releaseNotes = """ 29 |
    30 |
  • Cool feature
  • 31 |
  • Another cool feature
  • 32 |
  • More cool features
  • 33 |
34 | """ 35 | about.releaseNotesVersion = "0.0.1" 36 | about.supportUrl = about.issueUrl 37 | about.translatorCredits = "Credit to the translators" 38 | about.version = "0.0.1" 39 | about.website = "https://github.com/vbsteven/gtk-kotlin-native" 40 | 41 | about.show() 42 | } 43 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwActionRowTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.ActionRow 2 | import bindings.adw.Avatar 3 | import bindings.adw.HeaderBar 4 | import bindings.gtk.Box 5 | import bindings.gtk.Button 6 | import bindings.gtk.ListBox 7 | import native.gtk.GtkAlign 8 | import native.gtk.GtkOrientation 9 | import kotlin.test.Ignore 10 | import kotlin.test.Test 11 | 12 | @Ignore 13 | class AdwActionRowTest : AdwTestBase() { 14 | 15 | @Test 16 | fun testAdwActionRows() = runApplicationWindow { window -> 17 | val listBox = ListBox() 18 | 19 | listBox.appendAll( 20 | ActionRow().apply { 21 | title = "Action Row 1" 22 | }, 23 | ActionRow().apply { 24 | title = "Action Row 2" 25 | subtitle = "Action Row subtitle" 26 | }, 27 | ActionRow().apply { 28 | title = "Action Row 3" 29 | subtitle = "Action Row subtitle" 30 | iconName = "open-menu" 31 | }, 32 | ActionRow().apply { 33 | title = "Action Row 4" 34 | subtitle = "Action Row subtitle" 35 | addSuffix(Button("Suffix").apply { 36 | valign = GtkAlign.GTK_ALIGN_CENTER 37 | }) 38 | }, 39 | ActionRow().apply { 40 | title = "Action Row 5" 41 | subtitle = "Action Row subtitle" 42 | addPrefix(Avatar(30, null, false)) 43 | }, 44 | ) 45 | 46 | window.content = Box(GtkOrientation.GTK_ORIENTATION_VERTICAL, 0).apply { 47 | append(HeaderBar()) 48 | append(listBox) 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwApplicationTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.Application 2 | import kotlin.test.Ignore 3 | import kotlin.test.Test 4 | import kotlin.test.assertTrue 5 | 6 | @Ignore 7 | class AdwApplicationTest { 8 | @Test 9 | fun testAdwApplication() { 10 | var onActivateCalled = false 11 | 12 | val application = Application("io.quantus.adwtestapplication") 13 | application.onActivate { 14 | onActivateCalled = true 15 | } 16 | application.runApplication() 17 | 18 | assertTrue(onActivateCalled, "Application onActivate was not called") 19 | } 20 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwApplicationWindowTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.Application 2 | import bindings.adw.ApplicationWindow 3 | import bindings.gtk.Button 4 | import kotlin.test.Ignore 5 | import kotlin.test.Test 6 | 7 | @Ignore 8 | class AdwApplicationWindowTest { 9 | @Test 10 | fun testAdwApplicationWindow() { 11 | 12 | val application = Application("io.quantus.adwtestapplication") 13 | application.onActivate { 14 | val window = ApplicationWindow(application) 15 | window.defaultSize = Pair(1280, 720) 16 | 17 | window.content = Button("Hello AdwApplicationWindow") 18 | 19 | window.show() 20 | } 21 | application.runApplication() 22 | } 23 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwAvatarTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.Avatar 2 | import bindings.adw.HeaderBar 3 | import bindings.gtk.Box 4 | import bindings.gtk.ListBox 5 | import native.gtk.GtkOrientation 6 | import kotlin.test.Ignore 7 | import kotlin.test.Test 8 | 9 | @Ignore 10 | class AdwAvatarTest : AdwTestBase() { 11 | @Test 12 | fun testAvatar() = runApplicationWindow { window -> 13 | val listBox = ListBox() 14 | 15 | listBox.appendAll( 16 | Avatar(50, null, false), 17 | Avatar(50, "Steven Van Bael", false), 18 | Avatar(50, "Steven Van Bael", true), 19 | Avatar(100, "Steven Van Bael", true), 20 | Avatar(100, null, false).apply { 21 | iconName = "open-menu" 22 | } 23 | ) 24 | 25 | window.content = Box(GtkOrientation.GTK_ORIENTATION_VERTICAL, 0).apply { 26 | append(HeaderBar()) 27 | append(listBox) 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwButtonContentTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.ButtonContent 2 | import bindings.gtk.Button 3 | import bindings.gtk.ListBox 4 | import kotlin.test.Ignore 5 | import kotlin.test.Test 6 | 7 | @Ignore 8 | class AdwButtonContentTest : AdwTestBase() { 9 | 10 | @Test 11 | fun testButtonContent() = runApplicationWindow { window -> 12 | val listBox = ListBox() 13 | 14 | listBox.appendAll( 15 | Button().apply { 16 | child = ButtonContent("Hello Button", "emblem-music") 17 | }, 18 | Button().apply { 19 | child = ButtonContent(iconName = "emblem-music") 20 | }, 21 | Button().apply { 22 | child = ButtonContent().apply { 23 | label = "Music" 24 | iconName = "emblem-music" 25 | } 26 | }, 27 | ) 28 | 29 | window.content = listBox 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwClampTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.Clamp 2 | import bindings.gtk.Button 3 | import kotlin.test.Ignore 4 | import kotlin.test.Test 5 | 6 | @Ignore 7 | class AdwClampTest : AdwTestBase() { 8 | 9 | @Test 10 | fun testAdwClamp() = runApplicationWindow { window -> 11 | val clamp = Clamp() 12 | 13 | clamp.child = Button("Hello") 14 | clamp.maximumSize = 200 15 | 16 | window.content = clamp 17 | } 18 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwHeaderBarTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.Application 2 | import bindings.adw.ApplicationWindow 3 | import bindings.adw.HeaderBar 4 | import bindings.gtk.Box 5 | import bindings.gtk.Button 6 | import bindings.gtk.Label 7 | import native.gtk.GtkOrientation 8 | import kotlin.test.Ignore 9 | import kotlin.test.Test 10 | 11 | @Ignore 12 | class AdwHeaderBarTest { 13 | @Test 14 | fun testAdwHeaderBar() { 15 | val application = Application("io.quantus.adwheaderbartest") 16 | application.onActivate { 17 | 18 | // build the headerbar 19 | val headerBar = HeaderBar() 20 | headerBar.titleWidget = Label("Custom Title Widget") 21 | headerBar.packStart(Button("Test Start")) 22 | headerBar.packEnd(Button("Test End")) 23 | 24 | val box = Box(GtkOrientation.GTK_ORIENTATION_VERTICAL, 0) 25 | box.append(headerBar) 26 | 27 | val window = ApplicationWindow(application) 28 | window.defaultSize = Pair(1280, 720) 29 | window.content = box 30 | 31 | window.show() 32 | } 33 | application.runApplication() 34 | } 35 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwStatusPageTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.Clamp 2 | import bindings.adw.StatusPage 3 | import bindings.gtk.Button 4 | import kotlin.test.Ignore 5 | import kotlin.test.Test 6 | 7 | @Ignore 8 | class AdwStatusPageTest : AdwTestBase() { 9 | @Test 10 | fun testAdwStatusPage() = runApplicationWindow { window -> 11 | 12 | val statusPage = StatusPage() 13 | 14 | statusPage.title = "My Page Title" 15 | statusPage.iconName = "emblem-music" 16 | statusPage.description = "A short description" 17 | 18 | statusPage.child = Clamp().apply { 19 | maximumSize = 100 20 | child = Button("A button") 21 | } 22 | 23 | window.content = statusPage 24 | } 25 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwTabBarTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.StatusPage 2 | import bindings.adw.TabBar 3 | import bindings.adw.TabView 4 | import bindings.gtk.Box 5 | import bindings.gtk.Button 6 | import bindings.gtk.Widget 7 | import native.gtk.GtkOrientation 8 | import kotlin.test.Ignore 9 | import kotlin.test.Test 10 | 11 | @Ignore 12 | class AdwTabBarTest : AdwTestBase() { 13 | 14 | @Test 15 | fun testTabBar() = runApplicationWindow { window -> 16 | val tabView = TabView() 17 | var tabCount = 0 18 | 19 | fun addTab(pinned: Boolean = false) { 20 | if (pinned) { 21 | tabView.appendPinned(testPageWidget("Tab ${++tabCount}")).apply { 22 | title = "Tab $tabCount" 23 | tooltip = "Tooltip $tabCount" 24 | } 25 | } else { 26 | tabView.append(testPageWidget("Tab ${++tabCount}")).apply { 27 | title = "Tab $tabCount" 28 | tooltip = "Tooltip $tabCount" 29 | } 30 | } 31 | } 32 | 33 | addTab() 34 | addTab() 35 | addTab() 36 | 37 | val tabBar = TabBar() 38 | tabBar.view = tabView 39 | 40 | val buttonBar = Box(GtkOrientation.GTK_ORIENTATION_HORIZONTAL, 10) 41 | buttonBar.append(Button("Add Tab").apply { 42 | onClicked { addTab() } 43 | }) 44 | buttonBar.append(Button("Add Pinned Tab").apply { 45 | onClicked { addTab(true) } 46 | }) 47 | 48 | val box = Box(GtkOrientation.GTK_ORIENTATION_VERTICAL, 0) 49 | box.append(buttonBar) 50 | box.append(tabBar) 51 | box.append(tabView) 52 | 53 | window.setTestContent("TabBar Test", box) 54 | } 55 | } 56 | 57 | private fun testPageWidget(pageTitle: String): Widget { 58 | return StatusPage().apply { 59 | title = pageTitle 60 | iconName = "emblem-music" 61 | } 62 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwTestBase.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.Application 2 | import bindings.adw.ApplicationWindow 3 | import bindings.adw.HeaderBar 4 | import bindings.gtk.* 5 | import native.gtk.GtkOrientation 6 | 7 | open class AdwTestBase { 8 | 9 | fun runApplication( 10 | func: (Application) -> Unit 11 | ) { 12 | val application = Application("io.quantus.AdwTestApplication") 13 | 14 | application.onActivate { 15 | func(application) 16 | } 17 | application.runApplication() 18 | } 19 | 20 | fun runApplicationWindow( 21 | func: (ApplicationWindow) -> Unit 22 | ) = runApplication { app -> 23 | val window = ApplicationWindow(app) 24 | window.defaultSize = Pair(600, 400) 25 | func(window) 26 | window.show() 27 | } 28 | } 29 | 30 | /** 31 | * Helper for setting the content of the window and wrapping it 32 | * with a proper header bar 33 | */ 34 | fun ApplicationWindow.setTestContent(title: String, widget: Widget) { 35 | val headerBar = HeaderBar() 36 | headerBar.titleWidget = Label(title) 37 | val box = Box(GtkOrientation.GTK_ORIENTATION_VERTICAL, 0) 38 | box.append(headerBar) 39 | box.append(widget) 40 | 41 | this.content = box 42 | } 43 | 44 | /** 45 | * Helper for adding a button with a handler to a listbox for testing purposes. 46 | */ 47 | fun ListBox.addButton(buttonLabel: String, func: () -> Unit) { 48 | val button = Button(buttonLabel) 49 | button.onClicked { func() } 50 | this.append(button) 51 | } 52 | -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/AdwWindowTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.Application 2 | import bindings.adw.Window 3 | import bindings.gtk.Button 4 | import kotlin.test.Ignore 5 | import kotlin.test.Test 6 | 7 | @Ignore 8 | class AdwWindowTest { 9 | @Test 10 | fun testAdwWindow() { 11 | val application = Application("io.quantus.adwtestapplication") 12 | application.onActivate { 13 | val window = Window() 14 | window.defaultSize = Pair(1280, 720) 15 | window.application = application 16 | 17 | window.content = Button("Hello") 18 | 19 | window.show() 20 | } 21 | application.runApplication() 22 | } 23 | } -------------------------------------------------------------------------------- /libadwaita-bindings/src/nativeTest/kotlin/SubclassAdwBinTest.kt: -------------------------------------------------------------------------------- 1 | import bindings.adw.Bin 2 | import bindings.gtk.Button 3 | import bindings.gtk.ListBox 4 | import bindings.gtk.usertypes.WidgetClass 5 | import bindings.gtk.usertypes.WidgetCompanion 6 | import kotlinx.cinterop.CPointer 7 | import native.gobject.G_SIGNAL_RUN_FIRST 8 | import kotlin.test.Ignore 9 | import kotlin.test.Test 10 | 11 | @Ignore 12 | class SubclassAdwBinTest : AdwTestBase() { 13 | 14 | @Test 15 | fun testCustomWidget() = runApplicationWindow { window -> 16 | 17 | val widget1 = MyWidget("Widget 1") 18 | val widget2 = MyWidget("Widget 2") 19 | 20 | widget1.connectSignal(MyWidget.TEST_SIGNAL) { 21 | println("### Received TEST_SIGNAL from widget1") 22 | } 23 | widget2.connectSignal(MyWidget.TEST_SIGNAL) { 24 | println("### RECEIVED TEST_SIGNAL from widget2") 25 | } 26 | 27 | val listBox = ListBox() 28 | listBox.append(widget1) 29 | listBox.append(widget2) 30 | 31 | window.setTestContent("Subclass Example", listBox) 32 | } 33 | 34 | } 35 | 36 | /** 37 | * A custom GtkWidget class that extends from the Adwaita Bin widget. 38 | * 39 | * The implementation sets a Button as the Bin child. 40 | * The button activates the "mywidgetbutton-clicked" action. 41 | * The action handler emits the test-signal signal. 42 | */ 43 | class MyWidget : Bin { 44 | 45 | var name: String = "" 46 | 47 | constructor(pointer: CPointer<*>) : super(pointer) 48 | 49 | constructor(name: String) : this(newInstancePointer()) { 50 | this.name = name 51 | 52 | this.child = Button(name).apply { 53 | actionName = "mywidgetbutton-clicked" 54 | } 55 | } 56 | 57 | 58 | private fun myButtonClickedAction() { 59 | emitSignal(TEST_SIGNAL) 60 | } 61 | 62 | companion object : WidgetCompanion() { 63 | override val typeName = "MyWidget" 64 | override val parentType = Bin.Type 65 | 66 | const val TEST_SIGNAL = "test-signal" 67 | 68 | override fun classInit(klass: WidgetClass) { 69 | // install the signal 70 | klass.installSignal(TEST_SIGNAL, G_SIGNAL_RUN_FIRST) 71 | // install the action with the handler 72 | klass.installAction("mywidgetbutton-clicked", MyWidget::myButtonClickedAction) 73 | } 74 | } 75 | 76 | } 77 | 78 | 79 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "gtk-kotlin-native" 2 | 3 | include("gobject-bindings") 4 | include("gio-bindings") 5 | include("gtk-bindings") 6 | include("libadwaita-bindings") 7 | 8 | include("examples:hello-world-gtk") 9 | include("examples:counter-gtk") 10 | include("examples:demo-adwaita") 11 | include("examples:gtk-examples") 12 | include("examples:sevenguis-1-counter") 13 | include("examples:sevenguis-2-temperature-converter") 14 | include("examples:sevenguis-3-flight-booker") 15 | --------------------------------------------------------------------------------