├── .editorconfig ├── .gitignore ├── .swiftlint.yml ├── LICENSE.md ├── Package.swift ├── README.md ├── Screenshots └── Demo_macOS.png └── Sources ├── CGtk ├── Linux+Windows │ ├── header.h │ └── module.modulemap └── MacOS │ ├── header.h │ └── module.modulemap ├── Demo ├── GTK.png └── main.swift └── SwiftGtk ├── Application.swift ├── ApplicationWindow.swift ├── Bin.swift ├── Box.swift ├── Button.swift ├── ButtonBox.swift ├── Calendar.swift ├── Color.swift ├── Common.swift ├── Container.swift ├── CssProvider.swift ├── Entry.swift ├── Enums ├── Align.swift ├── ArrowPlacement.swift ├── ArrowType.swift ├── AssistantPageType.swift ├── BaselinePosition.swift ├── BorderStyle.swift ├── ButtonBoxStyle.swift ├── ButtonRole.swift ├── ButtonsType.swift ├── CellRendererAccelMode.swift ├── CellRendererMode.swift ├── CornerType.swift ├── CssSectionType.swift ├── DeleteType.swift ├── DirectionType.swift ├── DragResult.swift ├── EntryIconPosition.swift ├── EventSequenceState.swift ├── ExpanderStyle.swift ├── FileChooserAction.swift ├── FileChooserConfirmation.swift ├── IconSize.swift ├── IconViewDropPosition.swift ├── ImageType.swift ├── InputPurpose.swift ├── Justification.swift ├── LevelBarMode.swift ├── MenuDirectionType.swift ├── MessageType.swift ├── MovementStep.swift ├── NotebookTab.swift ├── NumberUpLayout.swift ├── Orientation.swift ├── PackDirection.swift ├── PackType.swift ├── PadActionType.swift ├── PageOrientation.swift ├── PageSet.swift ├── PanDirection.swift ├── PolicyType.swift ├── PopoverConstraint.swift ├── PositionType.swift ├── PrintDuplex.swift ├── PrintOperationAction.swift ├── PrintOperationResult.swift ├── PrintPages.swift ├── PrintQuality.swift ├── PrintStatus.swift ├── PropagationPhase.swift ├── RecentSortType.swift ├── ReliefStyle.swift ├── ResizeMode.swift ├── ResponseType.swift ├── RevealerTransitionType.swift ├── ScrollStep.swift ├── ScrollType.swift ├── ScrollablePolicy.swift ├── SelectionMode.swift ├── SensitivityType.swift ├── ShadowType.swift ├── ShortcutType.swift ├── SizeGroupMode.swift ├── SizeRequestMode.swift ├── SortType.swift ├── SpinButtonUpdatePolicy.swift ├── SpinType.swift ├── StackTransitionType.swift ├── StateType.swift ├── TextBufferTargetInfo.swift ├── TextDirection.swift ├── TextExtendSelection.swift ├── TextViewLayer.swift ├── TextWindowType.swift ├── ToolbarStyle.swift ├── TreeViewColumnSizing.swift ├── TreeViewDropPosition.swift ├── TreeViewGridLines.swift ├── Unit.swift ├── WidgetHelpType.swift ├── WindowPosition.swift ├── WindowType.swift └── WrapMode.swift ├── FileChooser.swift ├── Grid.swift ├── GtkError.swift ├── HeaderBar.swift ├── Image.swift ├── Label.swift ├── Scale.swift ├── ScrolledWindow.swift ├── SignalBox.swift ├── Signals.swift ├── Size.swift ├── TextView.swift ├── ToggleButton.swift ├── UnsafePointerGChar+ToString.swift ├── Value.swift ├── Viewport.swift ├── Widget+CastedPointer.swift ├── Widget.swift └── Window.swift /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 4 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .build/ 2 | .swiftpm/ 3 | *.xcodeproj 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /.swiftlint.yml: -------------------------------------------------------------------------------- 1 | disabled_rules: 2 | - line_length 3 | swiftlint_version: 0.21.0 4 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2016 Tomáš Linhart 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.5 2 | 3 | import PackageDescription 4 | 5 | #if os(macOS) 6 | let cGtkSources = "Sources/CGtk/MacOS" 7 | #elseif os(Linux) || os(Windows) 8 | let cGtkSources = "Sources/CGtk/Linux+Windows" 9 | #else 10 | fatalError("Unsupported platform.") 11 | #endif 12 | 13 | let package = Package( 14 | name: "SwiftGtk", 15 | products: [ 16 | .executable(name: "Demo", targets: ["Demo"]), 17 | .library(name: "SwiftGtk", targets: ["SwiftGtk"]), 18 | .library(name: "CGtk", targets: ["CGtk"]) 19 | ], 20 | targets: [ 21 | .systemLibrary( 22 | name: "CGtk", 23 | path: cGtkSources, 24 | pkgConfig: "gtk+-3.0", 25 | providers: [ 26 | .brew(["gtk+3"]), 27 | .apt(["libgtk-3-dev clang"]) 28 | ] 29 | ), 30 | .target( 31 | name: "SwiftGtk", 32 | dependencies: ["CGtk"] 33 | ), 34 | .executableTarget( 35 | name: "Demo", 36 | dependencies: ["SwiftGtk"], 37 | resources: [.copy("GTK.png")] 38 | ) 39 | ] 40 | ) 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **ARCHIVED**: This Gtk wrapper is developed in tandem with 2 | [SwiftCrossUI](https://github.com/stackotter/swift-cross-ui), and hence its API is a 3 | higgledy-piggledy mess of random Gtk APIs that SwiftCrossUI needs to access. Thus, for someone 4 | wanting to actually just use regular old Gtk in a Swift project (and not SwiftCrossUI), this project 5 | was never really very useful. Hence I have moved this wrapper into the SwiftCrossUI repository to 6 | simplify the development and the contributing process of SwiftCrossUI. I advise that you have a look at 7 | [rhx's great Gtk wrapper](https://github.com/rhx/SwiftGtk) which uses automatic code generation to 8 | always stay up-to-date with the latest features and have complete coverage of the Gtk API. 9 | 10 | If you still want to continue using this wrapper after reading what I have to say, include 11 | [SwiftCrossUI](https://github.com/stackotter/swift-cross-ui) as a dependency in your project and add 12 | the `Gtk` product as a dependency of your target or app. The wrapper has merely been moved to a new 13 | more fitting home. 14 | 15 | # SwiftGtk 16 | 17 | SwiftGtk provides Swift bindings for Gtk+ 3. It currently supports both macOS and Linux (with Windows support planned). 18 | 19 | ## Dependencies 20 | 21 | 1. Swift 5.5 or higher 22 | 2. Gtk+ 3 23 | 3. clang (only required on Linux) 24 | 25 | ### macOS: Installing Gtk+ 3 26 | 27 | Install Gtk+ 3 using [homebrew](http://brew.sh/) or the package manager of your choice. 28 | 29 | ```bash 30 | brew install gtk+3 31 | ``` 32 | 33 | ### Linux: Installing Gtk+ 3 and clang 34 | 35 | Install Gtk+3 and Clang using `apt` or the package manager of your choice. 36 | 37 | ```bash 38 | sudo apt install libgtk-3-dev clang 39 | ``` 40 | 41 | ## Usage 42 | 43 | Add SwiftGtk as a dependency of your project using Swift Package Manager. Below is an example package manifest that has SwiftGtk as a dependency. 44 | 45 | ```swift 46 | import PackageDescription 47 | 48 | let package = Package( 49 | name: "GtkHelloWorld", 50 | dependencies: [ 51 | .package(url: "https://github.com/stackotter/SwiftGtk", .branch("main")) 52 | ], 53 | targets: [ 54 | .executableTarget(name: "GtkHelloWorld", dependencies: ["SwiftGtk"]) 55 | ] 56 | ) 57 | ``` 58 | 59 | ## Demo 60 | 61 | First install the required dependencies as listed above. And then run the following commands: 62 | 63 | ```bash 64 | git clone https://github.com/stackotter/SwiftGtk 65 | cd SwiftGtk 66 | swift run Demo 67 | ``` 68 | 69 | ### macOS 70 | 71 | ![macOS](https://github.com/stackotter/SwiftGtk/blob/main/Screenshots/Demo_macOS.png?raw=true) 72 | 73 | ## License 74 | 75 | All code is licensed under MIT license. 76 | -------------------------------------------------------------------------------- /Screenshots/Demo_macOS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stackotter/SwiftGtk/aa259668fe446600a80851587db5243cd2a6348a/Screenshots/Demo_macOS.png -------------------------------------------------------------------------------- /Sources/CGtk/Linux+Windows/header.h: -------------------------------------------------------------------------------- 1 | #include -------------------------------------------------------------------------------- /Sources/CGtk/Linux+Windows/module.modulemap: -------------------------------------------------------------------------------- 1 | module CGtk [system] { 2 | header "header.h" 3 | link "gtk-3" 4 | 5 | export * 6 | } 7 | -------------------------------------------------------------------------------- /Sources/CGtk/MacOS/header.h: -------------------------------------------------------------------------------- 1 | #include -------------------------------------------------------------------------------- /Sources/CGtk/MacOS/module.modulemap: -------------------------------------------------------------------------------- 1 | module CGtk [system] { 2 | header "header.h" 3 | link "gtk-3.0" 4 | 5 | export * 6 | } 7 | -------------------------------------------------------------------------------- /Sources/Demo/GTK.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stackotter/SwiftGtk/aa259668fe446600a80851587db5243cd2a6348a/Sources/Demo/GTK.png -------------------------------------------------------------------------------- /Sources/Demo/main.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import SwiftGtk 6 | import Foundation 7 | 8 | let app = Application(applicationId: "com.tomaslinhart.swiftgtk.example") 9 | app.run { window in 10 | window.title = "Hello World" 11 | window.defaultSize = Size(width: 400, height: 400) 12 | window.resizable = true 13 | 14 | let buttonBox = ButtonBox(orientation: .vertical) 15 | 16 | let label = Label() 17 | label.selectable = true 18 | buttonBox.add(label) 19 | 20 | let slider = Scale() 21 | slider.minimum = 5 22 | slider.maximum = 10.5 23 | slider.value = 5.7 24 | buttonBox.add(slider) 25 | 26 | let entry = Entry(placeholder: "Test input") 27 | entry.changed = { entry in 28 | let text = entry.text 29 | print(text) 30 | entry.text = text 31 | } 32 | buttonBox.add(entry) 33 | 34 | let scrollable = ScrolledWindow() 35 | scrollable.maximumContentHeight = 100 36 | scrollable.minimumContentHeight = 100 37 | let viewport = Viewport() 38 | let content = Box(orientation: .vertical, spacing: 0) 39 | for i in 0..<20 { 40 | content.add(Label(text: "This is line number \(i)")) 41 | } 42 | viewport.add(content) 43 | scrollable.add(viewport) 44 | buttonBox.add(scrollable) 45 | 46 | let button = Button(label: "Press") 47 | button.label = "Press Me" 48 | button.clicked = { [weak label] _ in 49 | label?.text = "Oh, you pressed the button." 50 | 51 | let newWindow = Window(windowType: .topLevel) 52 | newWindow.title = "Just a window" 53 | newWindow.defaultSize = Size(width: 200, height: 200) 54 | 55 | let labelPressed = Label(text: "Oh, you pressed the button.") 56 | newWindow.add(labelPressed) 57 | 58 | newWindow.showAll() 59 | } 60 | 61 | buttonBox.add(button) 62 | 63 | let calendarButton = Button(label: "Calendar") 64 | calendarButton.clicked = { _ in 65 | let newWindow = Window(windowType: .topLevel) 66 | newWindow.title = "Just a window" 67 | newWindow.defaultSize = Size(width: 200, height: 200) 68 | 69 | let calendar = Calendar() 70 | calendar.year = 2000 71 | calendar.showHeading = true 72 | 73 | newWindow.add(calendar) 74 | 75 | newWindow.showAll() 76 | } 77 | 78 | buttonBox.add(calendarButton) 79 | 80 | let imageButton = Button(label: "Image") 81 | imageButton.clicked = { _ in 82 | let newWindow = Window(windowType: .topLevel) 83 | newWindow.title = "Just a window" 84 | newWindow.defaultSize = Size(width: 200, height: 200) 85 | 86 | let image = Image(path: Bundle.module.bundleURL.appendingPathComponent("GTK.png").path) 87 | 88 | newWindow.add(image) 89 | 90 | newWindow.showAll() 91 | } 92 | 93 | buttonBox.add(imageButton) 94 | 95 | let textView = TextView() 96 | textView.backspace = { _ in 97 | print("backspace") 98 | } 99 | textView.copyClipboard = { _ in 100 | print("copyClipboard") 101 | } 102 | textView.cutClipboard = { _ in 103 | print("cutClipboard") 104 | } 105 | textView.pasteClipboard = { _ in 106 | print("pasteClipboard") 107 | } 108 | textView.selectAll = { _, select in 109 | print(select ? "everything is selected" : "everything is unselected") 110 | } 111 | 112 | buttonBox.add(textView) 113 | 114 | window.add(buttonBox) 115 | } 116 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Application.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | public class Application { 8 | let applicationPointer: UnsafeMutablePointer 9 | private(set) var applicationWindow: ApplicationWindow? 10 | private var windowCallback: ((ApplicationWindow) -> Void)? 11 | 12 | public init(applicationId: String) { 13 | // Ignore the deprecation warning, making the change breaks support for platforms such as 14 | // Ubuntu (before Lunar). This is due to Ubuntu coming with an older version of Gtk in apt. 15 | applicationPointer = gtk_application_new(applicationId, G_APPLICATION_FLAGS_NONE) 16 | } 17 | 18 | @discardableResult 19 | public func run(_ windowCallback: @escaping (ApplicationWindow) -> Void) -> Int { 20 | self.windowCallback = windowCallback 21 | 22 | let handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void = { sender, data in 23 | let app = unsafeBitCast(data, to: Application.self) 24 | app.activate() 25 | } 26 | 27 | connectSignal(applicationPointer, name: "activate", data: Unmanaged.passUnretained(self).toOpaque(), handler: unsafeBitCast(handler, to: GCallback.self)) 28 | let status = g_application_run(applicationPointer.cast(), 0, nil) 29 | g_object_unref(applicationPointer) 30 | return Int(status) 31 | } 32 | 33 | private func activate() { 34 | let window = ApplicationWindow(application: self) 35 | windowCallback?(window) 36 | window.showAll() 37 | 38 | self.applicationWindow = window 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/ApplicationWindow.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | public class ApplicationWindow: Window { 8 | public init(application: Application) { 9 | super.init() 10 | widgetPointer = gtk_application_window_new(application.applicationPointer) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Bin.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | open class Bin: Container { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Box.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | open class Box: Container { 8 | public init(orientation: Orientation, spacing: Int) { 9 | super.init() 10 | 11 | widgetPointer = gtk_box_new(orientation.toGtkOrientation(), gint(spacing)) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Button.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | open class Button: Bin { 8 | public override init() { 9 | super.init() 10 | widgetPointer = gtk_button_new() 11 | } 12 | 13 | public init(label: String) { 14 | super.init() 15 | widgetPointer = gtk_button_new_with_label(label) 16 | } 17 | 18 | override func didMoveToParent() { 19 | super.didMoveToParent() 20 | 21 | addSignal(name: "clicked") { [weak self] in 22 | guard let self = self else { return } 23 | self.clicked?(self) 24 | } 25 | } 26 | 27 | public var label: String? { 28 | get { 29 | return String(cString: gtk_button_get_label(castedPointer())) 30 | } 31 | set { 32 | if let title = newValue { 33 | gtk_button_set_label(castedPointer(), title) 34 | } else { 35 | gtk_button_set_label(castedPointer(), nil) 36 | } 37 | } 38 | } 39 | 40 | public var clicked: ((Button) -> Void)? 41 | } 42 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/ButtonBox.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | public class ButtonBox: Box { 8 | public init(orientation: Orientation = .horizontal) { 9 | super.init(orientation: orientation, spacing: 0) 10 | 11 | widgetPointer = gtk_button_box_new(orientation.toGtkOrientation()) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Calendar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2016 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | public class Calendar: Widget { 8 | public override init() { 9 | super.init() 10 | 11 | widgetPointer = gtk_calendar_new() 12 | } 13 | 14 | public var year: Int { 15 | get { 16 | return getProperty(castedPointer(), name: "year") 17 | } 18 | set { 19 | setProperty(castedPointer(), name: "year", newValue: newValue) 20 | } 21 | } 22 | 23 | public var showHeading: Bool { 24 | get { 25 | return getProperty(castedPointer(), name: "show-heading") 26 | } 27 | set { 28 | setProperty(castedPointer(), name: "show-heading", newValue: newValue) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Color.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | public struct Color { 4 | public var red: Double 5 | public var green: Double 6 | public var blue: Double 7 | public var alpha: Double 8 | 9 | public init( 10 | _ red: Double, 11 | _ green: Double, 12 | _ blue: Double, 13 | _ alpha: Double = 1 14 | ) { 15 | self.red = red 16 | self.green = green 17 | self.blue = blue 18 | self.alpha = alpha 19 | } 20 | 21 | public var gdkColor: GdkRGBA { 22 | return GdkRGBA(red: red, green: green, blue: blue, alpha: alpha) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Common.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2016 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | extension gboolean { 8 | func toBool() -> Bool { 9 | return self >= 1 10 | } 11 | } 12 | 13 | extension Bool { 14 | func toGBoolean() -> gboolean { 15 | return self ? 1 : 0 16 | } 17 | } 18 | 19 | extension Int { 20 | func toBool() -> Bool { 21 | return self >= 1 22 | } 23 | } 24 | 25 | extension UnsafeMutablePointer { 26 | func cast() -> UnsafeMutablePointer { 27 | let pointer = UnsafeRawPointer(self).bindMemory(to: T.self, capacity: 1) 28 | return UnsafeMutablePointer(mutating: pointer) 29 | } 30 | } 31 | 32 | extension UnsafeRawPointer { 33 | func cast() -> UnsafeMutablePointer { 34 | let pointer = UnsafeRawPointer(self).bindMemory(to: T.self, capacity: 1) 35 | return UnsafeMutablePointer(mutating: pointer) 36 | } 37 | } 38 | 39 | extension UnsafeMutableRawPointer { 40 | func cast() -> UnsafeMutablePointer { 41 | let pointer = UnsafeRawPointer(self).bindMemory(to: T.self, capacity: 1) 42 | return UnsafeMutablePointer(mutating: pointer) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Container.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | open class Container: Widget { 8 | var widgets: [Widget] = [] 9 | 10 | public func add(_ widget: Widget) { 11 | widgets.append(widget) 12 | widget.parentWidget = self 13 | gtk_container_add(castedPointer(), widget.widgetPointer) 14 | } 15 | 16 | public func remove(_ widget: Widget) { 17 | if let index = widgets.firstIndex(where: { $0 === widget }) { 18 | gtk_container_remove(castedPointer(), widget.widgetPointer) 19 | widgets.remove(at: index) 20 | widget.parentWidget = nil 21 | } 22 | } 23 | 24 | public func removeAll() { 25 | var list = gtk_container_get_children(castedPointer()) 26 | 27 | while let node = list { 28 | let widget = node.pointee.data.assumingMemoryBound(to: GtkWidget.self) 29 | gtk_container_remove(castedPointer(), widget) 30 | list = node.pointee.next 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/CssProvider.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | public class CssProvider { 4 | var pointer: UnsafeMutablePointer 5 | 6 | init() { 7 | pointer = gtk_css_provider_new() 8 | } 9 | 10 | public func loadFromData(_ data: String) throws { 11 | try withGtkError { error in 12 | data.withCString { cString in 13 | gtk_css_provider_load_from_data(pointer, cString, data.count, error) 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Entry.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Essentially just a one-line text input. No clue why Gtk calls it an entry. 4 | public class Entry: Widget { 5 | public override init() { 6 | super.init() 7 | 8 | widgetPointer = gtk_entry_new() 9 | } 10 | 11 | public convenience init(placeholder: String) { 12 | self.init() 13 | gtk_entry_set_placeholder_text(castedPointer(), placeholder) 14 | } 15 | 16 | override func didMoveToParent() { 17 | super.didMoveToParent() 18 | 19 | addSignal(name: "changed") { [weak self] in 20 | guard let self = self else { return } 21 | self.changed?(self) 22 | } 23 | } 24 | 25 | public var text: String { 26 | get { 27 | String(cString: gtk_entry_get_text(castedPointer())) 28 | } 29 | set { 30 | gtk_entry_set_text(castedPointer(), newValue) 31 | } 32 | } 33 | 34 | public var placeholder: String { 35 | get { 36 | String(cString: gtk_entry_get_placeholder_text(castedPointer())) 37 | } 38 | set { 39 | gtk_entry_set_placeholder_text(castedPointer(), newValue) 40 | } 41 | } 42 | 43 | public var changed: ((Entry) -> Void)? 44 | } 45 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/Align.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Controls how a widget deals with extra space in a single (x or y) dimension. 4 | /// 5 | /// Alignment only matters if the widget receives a “too large” allocation, for example if you packed the widget with the `GtkWidget:expand` flag inside a `GtkBox`, then the widget might get extra space. If you have for example a 16x16 icon inside a 32x32 space, the icon could be scaled and stretched, it could be centered, or it could be positioned to one side of the space. 6 | /// 7 | /// Note that in horizontal context `GTK_ALIGN_START` and `GTK_ALIGN_END` are interpreted relative to text direction. 8 | /// 9 | /// `GTK_ALIGN_BASELINE` support for it is optional for containers and widgets, and it is only supported for vertical alignment. When its not supported by a child or a container it is treated as `GTK_ALIGN_FILL`. 10 | /// 11 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.Align.html) 12 | public enum Align { 13 | /// Stretch to fill all space if possible, center if no meaningful way to stretch. 14 | case fill 15 | /// Snap to left or top side, leaving space on right or bottom. 16 | case start 17 | /// Snap to right or bottom side, leaving space on left or top. 18 | case end 19 | /// Center natural width of widget inside the allocation. 20 | case center 21 | /// Align the widget according to the baseline. Since 3.10. 22 | case baseline 23 | 24 | func toGtkAlign() -> GtkAlign { 25 | switch self { 26 | case .fill: 27 | return GTK_ALIGN_FILL 28 | case .start: 29 | return GTK_ALIGN_START 30 | case .end: 31 | return GTK_ALIGN_END 32 | case .center: 33 | return GTK_ALIGN_CENTER 34 | case .baseline: 35 | return GTK_ALIGN_BASELINE 36 | } 37 | } 38 | } 39 | 40 | extension GtkAlign { 41 | func toAlign() -> Align { 42 | switch self { 43 | case GTK_ALIGN_FILL: 44 | return .fill 45 | case GTK_ALIGN_START: 46 | return .start 47 | case GTK_ALIGN_END: 48 | return .end 49 | case GTK_ALIGN_CENTER: 50 | return .center 51 | case GTK_ALIGN_BASELINE: 52 | return .baseline 53 | default: 54 | fatalError("Unsupported GtkAlign enum value: \(self.rawValue)") 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ArrowPlacement.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to specify the placement of scroll arrows in scrolling menus. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ArrowPlacement.html) 6 | public enum ArrowPlacement { 7 | /// Place one arrow on each end of the menu. 8 | case both 9 | /// Place both arrows at the top of the menu. 10 | case start 11 | /// Place both arrows at the bottom of the menu. 12 | case end 13 | 14 | func toGtkArrowPlacement() -> GtkArrowPlacement { 15 | switch self { 16 | case .both: 17 | return GTK_ARROWS_BOTH 18 | case .start: 19 | return GTK_ARROWS_START 20 | case .end: 21 | return GTK_ARROWS_END 22 | } 23 | } 24 | } 25 | 26 | extension GtkArrowPlacement { 27 | func toArrowPlacement() -> ArrowPlacement { 28 | switch self { 29 | case GTK_ARROWS_BOTH: 30 | return .both 31 | case GTK_ARROWS_START: 32 | return .start 33 | case GTK_ARROWS_END: 34 | return .end 35 | default: 36 | fatalError("Unsupported GtkArrowPlacement enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ArrowType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to indicate the direction in which an arrow should point. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ArrowType.html) 6 | public enum ArrowType { 7 | /// Represents an upward pointing arrow. 8 | case up 9 | /// Represents a downward pointing arrow. 10 | case down 11 | /// Represents a left pointing arrow. 12 | case left 13 | /// Represents a right pointing arrow. 14 | case right 15 | /// No arrow. Since 2.10. 16 | case none 17 | 18 | func toGtkArrowType() -> GtkArrowType { 19 | switch self { 20 | case .up: 21 | return GTK_ARROW_UP 22 | case .down: 23 | return GTK_ARROW_DOWN 24 | case .left: 25 | return GTK_ARROW_LEFT 26 | case .right: 27 | return GTK_ARROW_RIGHT 28 | case .none: 29 | return GTK_ARROW_NONE 30 | } 31 | } 32 | } 33 | 34 | extension GtkArrowType { 35 | func toArrowType() -> ArrowType { 36 | switch self { 37 | case GTK_ARROW_UP: 38 | return .up 39 | case GTK_ARROW_DOWN: 40 | return .down 41 | case GTK_ARROW_LEFT: 42 | return .left 43 | case GTK_ARROW_RIGHT: 44 | return .right 45 | case GTK_ARROW_NONE: 46 | return ArrowType.none 47 | default: 48 | fatalError("Unsupported GtkArrowType enum value: \(self.rawValue)") 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/AssistantPageType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// An enum for determining the page role inside the `GtkAssistant`. It’s used to handle buttons sensitivity and visibility. 4 | /// 5 | /// Note that an assistant needs to end its page flow with a page of type `GTK_ASSISTANT_PAGE_CONFIRM`, `GTK_ASSISTANT_PAGE_SUMMARY` or `GTK_ASSISTANT_PAGE_PROGRESS` to be correct. 6 | /// 7 | /// The Cancel button will only be shown if the page isn’t “committed”. See `gtk_assistant_commit()` for details. 8 | /// 9 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.AssistantPageType.html) 10 | public enum AssistantPageType { 11 | /// The page has regular contents. Both the Back and forward buttons will be shown. 12 | case content 13 | /// The page contains an introduction to the assistant task. Only the Forward button will be shown if there is a next page. 14 | case intro 15 | /// The page lets the user confirm or deny the changes. The Back and Apply buttons will be shown. 16 | case confirm 17 | /// The page informs the user of the changes done. Only the Close button will be shown. 18 | case summary 19 | /// Used for tasks that take a long time to complete, blocks the assistant until the page is marked as complete. Only the back button will be shown. 20 | case progress 21 | /// Used for when other page types are not appropriate. No buttons will be shown, and the application must add its own buttons through gtk_assistant_add_action_widget(). 22 | case custom 23 | 24 | func toGtkAssistantPageType() -> GtkAssistantPageType { 25 | switch self { 26 | case .content: 27 | return GTK_ASSISTANT_PAGE_CONTENT 28 | case .intro: 29 | return GTK_ASSISTANT_PAGE_INTRO 30 | case .confirm: 31 | return GTK_ASSISTANT_PAGE_CONFIRM 32 | case .summary: 33 | return GTK_ASSISTANT_PAGE_SUMMARY 34 | case .progress: 35 | return GTK_ASSISTANT_PAGE_PROGRESS 36 | case .custom: 37 | return GTK_ASSISTANT_PAGE_CUSTOM 38 | } 39 | } 40 | } 41 | 42 | extension GtkAssistantPageType { 43 | func toAssistantPageType() -> AssistantPageType { 44 | switch self { 45 | case GTK_ASSISTANT_PAGE_CONTENT: 46 | return .content 47 | case GTK_ASSISTANT_PAGE_INTRO: 48 | return .intro 49 | case GTK_ASSISTANT_PAGE_CONFIRM: 50 | return .confirm 51 | case GTK_ASSISTANT_PAGE_SUMMARY: 52 | return .summary 53 | case GTK_ASSISTANT_PAGE_PROGRESS: 54 | return .progress 55 | case GTK_ASSISTANT_PAGE_CUSTOM: 56 | return .custom 57 | default: 58 | fatalError("Unsupported GtkAssistantPageType enum value: \(self.rawValue)") 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/BaselinePosition.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Whenever a container has some form of natural row it may align children in that row along a common typographical baseline. If the amount of verical space in the row is taller than the total requested height of the baseline-aligned children then it can use a `GtkBaselinePosition` to select where to put the baseline inside the extra availible space. 4 | /// 5 | /// Available since: 3.10 6 | /// 7 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.BaselinePosition.html) 8 | public enum BaselinePosition { 9 | /// Align the baseline at the top. 10 | case top 11 | /// Center the baseline. 12 | case center 13 | /// Align the baseline at the bottom. 14 | case bottom 15 | 16 | func toGtkBaselinePosition() -> GtkBaselinePosition { 17 | switch self { 18 | case .top: 19 | return GTK_BASELINE_POSITION_TOP 20 | case .center: 21 | return GTK_BASELINE_POSITION_CENTER 22 | case .bottom: 23 | return GTK_BASELINE_POSITION_BOTTOM 24 | } 25 | } 26 | } 27 | 28 | extension GtkBaselinePosition { 29 | func toBaselinePosition() -> BaselinePosition { 30 | switch self { 31 | case GTK_BASELINE_POSITION_TOP: 32 | return .top 33 | case GTK_BASELINE_POSITION_CENTER: 34 | return .center 35 | case GTK_BASELINE_POSITION_BOTTOM: 36 | return .bottom 37 | default: 38 | fatalError("Unsupported GtkBaselinePosition enum value: \(self.rawValue)") 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/BorderStyle.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Describes how the border of a UI element should be rendered. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.BorderStyle.html) 6 | public enum BorderStyle { 7 | /// No visible border. 8 | case none 9 | /// A single line segment. 10 | case solid 11 | /// Looks as if the content is sunken into the canvas. 12 | case inset 13 | /// Looks as if the content is coming out of the canvas. 14 | case outset 15 | /// Same as GTK_BORDER_STYLE_NONE. 16 | case hidden 17 | /// A series of round dots. 18 | case dotted 19 | /// A series of square-ended dashes. 20 | case dashed 21 | /// Two parallel lines with some space between them. 22 | case double 23 | /// Looks as if it were carved in the canvas. 24 | case groove 25 | /// Looks as if it were coming out of the canvas. 26 | case ridge 27 | 28 | func toGtkBorderStyle() -> GtkBorderStyle { 29 | switch self { 30 | case .none: 31 | return GTK_BORDER_STYLE_NONE 32 | case .solid: 33 | return GTK_BORDER_STYLE_SOLID 34 | case .inset: 35 | return GTK_BORDER_STYLE_INSET 36 | case .outset: 37 | return GTK_BORDER_STYLE_OUTSET 38 | case .hidden: 39 | return GTK_BORDER_STYLE_HIDDEN 40 | case .dotted: 41 | return GTK_BORDER_STYLE_DOTTED 42 | case .dashed: 43 | return GTK_BORDER_STYLE_DASHED 44 | case .double: 45 | return GTK_BORDER_STYLE_DOUBLE 46 | case .groove: 47 | return GTK_BORDER_STYLE_GROOVE 48 | case .ridge: 49 | return GTK_BORDER_STYLE_RIDGE 50 | } 51 | } 52 | } 53 | 54 | extension GtkBorderStyle { 55 | func toBorderStyle() -> BorderStyle { 56 | switch self { 57 | case GTK_BORDER_STYLE_NONE: 58 | return BorderStyle.none 59 | case GTK_BORDER_STYLE_SOLID: 60 | return .solid 61 | case GTK_BORDER_STYLE_INSET: 62 | return .inset 63 | case GTK_BORDER_STYLE_OUTSET: 64 | return .outset 65 | case GTK_BORDER_STYLE_HIDDEN: 66 | return .hidden 67 | case GTK_BORDER_STYLE_DOTTED: 68 | return .dotted 69 | case GTK_BORDER_STYLE_DASHED: 70 | return .dashed 71 | case GTK_BORDER_STYLE_DOUBLE: 72 | return .double 73 | case GTK_BORDER_STYLE_GROOVE: 74 | return .groove 75 | case GTK_BORDER_STYLE_RIDGE: 76 | return .ridge 77 | default: 78 | fatalError("Unsupported GtkBorderStyle enum value: \(self.rawValue)") 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ButtonBoxStyle.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to dictate the style that a `GtkButtonBox` uses to layout the buttons it contains. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ButtonBoxStyle.html) 6 | public enum ButtonBoxStyle { 7 | /// Buttons are evenly spread across the box. 8 | case spread 9 | /// Buttons are placed at the edges of the box. 10 | case edge 11 | /// Buttons are grouped towards the start of the box, (on the left for a HBox, or the top for a VBox). 12 | case start 13 | /// Buttons are grouped towards the end of the box, (on the right for a HBox, or the bottom for a VBox). 14 | case end 15 | /// Buttons are centered in the box. Since 2.12. 16 | case center 17 | /// Buttons expand to fill the box. This entails giving buttons a “linked” appearance, making button sizes homogeneous, and setting spacing to 0 (same as calling gtk_box_set_homogeneous() and gtk_box_set_spacing() manually). Since 3.12. 18 | case expand 19 | 20 | func toGtkButtonBoxStyle() -> GtkButtonBoxStyle { 21 | switch self { 22 | case .spread: 23 | return GTK_BUTTONBOX_SPREAD 24 | case .edge: 25 | return GTK_BUTTONBOX_EDGE 26 | case .start: 27 | return GTK_BUTTONBOX_START 28 | case .end: 29 | return GTK_BUTTONBOX_END 30 | case .center: 31 | return GTK_BUTTONBOX_CENTER 32 | case .expand: 33 | return GTK_BUTTONBOX_EXPAND 34 | } 35 | } 36 | } 37 | 38 | extension GtkButtonBoxStyle { 39 | func toButtonBoxStyle() -> ButtonBoxStyle { 40 | switch self { 41 | case GTK_BUTTONBOX_SPREAD: 42 | return .spread 43 | case GTK_BUTTONBOX_EDGE: 44 | return .edge 45 | case GTK_BUTTONBOX_START: 46 | return .start 47 | case GTK_BUTTONBOX_END: 48 | return .end 49 | case GTK_BUTTONBOX_CENTER: 50 | return .center 51 | case GTK_BUTTONBOX_EXPAND: 52 | return .expand 53 | default: 54 | fatalError("Unsupported GtkButtonBoxStyle enum value: \(self.rawValue)") 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ButtonRole.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// The role specifies the desired appearance of a `GtkModelButton`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ButtonRole.html) 6 | public enum ButtonRole { 7 | /// A plain button. 8 | case normal 9 | /// A check button. 10 | case check 11 | /// A radio button. 12 | case radio 13 | 14 | func toGtkAlign() -> GtkButtonRole { 15 | switch self { 16 | case .normal: 17 | return GTK_BUTTON_ROLE_NORMAL 18 | case .check: 19 | return GTK_BUTTON_ROLE_CHECK 20 | case .radio: 21 | return GTK_BUTTON_ROLE_RADIO 22 | } 23 | } 24 | } 25 | 26 | extension GtkButtonRole { 27 | func toButtonRole() -> ButtonRole { 28 | switch self { 29 | case GTK_BUTTON_ROLE_NORMAL: 30 | return .normal 31 | case GTK_BUTTON_ROLE_CHECK: 32 | return .check 33 | case GTK_BUTTON_ROLE_RADIO: 34 | return .radio 35 | default: 36 | fatalError("Unsupported GtkButtonRole enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ButtonsType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Prebuilt sets of buttons for the dialog. If none of these choices are appropriate, simply use `GTK_BUTTONS_NONE` then call `gtk_dialog_add_buttons()`. 4 | /// 5 | /// Please note that GTK_BUTTONS_OK, GTK_BUTTONS_YES_NO and GTK_BUTTONS_OK_CANCEL are discouraged by the [GNOME Human Interface Guidelines](http://library.gnome.org/devel/hig-book/stable/). 6 | /// 7 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ButtonsType.html) 8 | public enum ButtonsType { 9 | /// No buttons at all. 10 | case none 11 | /// An OK button. 12 | case ok 13 | /// A Close button. 14 | case close 15 | /// A Cancel button. 16 | case cancel 17 | /// Yes and No buttons. 18 | case yesAndNo 19 | /// OK and Cancel buttons. 20 | case okAndCancel 21 | 22 | func toGtkButtonsType() -> GtkButtonsType { 23 | switch self { 24 | case .none: 25 | return GTK_BUTTONS_NONE 26 | case .ok: 27 | return GTK_BUTTONS_OK 28 | case .close: 29 | return GTK_BUTTONS_CLOSE 30 | case .cancel: 31 | return GTK_BUTTONS_CANCEL 32 | case .yesAndNo: 33 | return GTK_BUTTONS_YES_NO 34 | case .okAndCancel: 35 | return GTK_BUTTONS_OK_CANCEL 36 | } 37 | } 38 | } 39 | 40 | extension GtkButtonsType { 41 | func toButtonsType() -> ButtonsType { 42 | switch self { 43 | case GTK_BUTTONS_NONE: 44 | return ButtonsType.none 45 | case GTK_BUTTONS_OK: 46 | return .ok 47 | case GTK_BUTTONS_CLOSE: 48 | return .close 49 | case GTK_BUTTONS_CANCEL: 50 | return .cancel 51 | case GTK_BUTTONS_YES_NO: 52 | return .yesAndNo 53 | case GTK_BUTTONS_OK_CANCEL: 54 | return .okAndCancel 55 | default: 56 | fatalError("Unsupported GtkButtonsType enum value: \(self.rawValue)") 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/CellRendererAccelMode.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Determines if the edited accelerators are GTK+ accelerators. If they are, consumed modifiers are suppressed, only accelerators accepted by GTK+ are allowed, and the accelerators are rendered in the same way as they are in menus. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.CellRendererAccelMode.html) 6 | public enum CellRendererAccelMode { 7 | /// GTK+ accelerators mode. 8 | case gtk 9 | /// Other accelerator mode. 10 | case other 11 | 12 | func toGtkCellRendererAccelMode() -> GtkCellRendererAccelMode { 13 | switch self { 14 | case .gtk: 15 | return GTK_CELL_RENDERER_ACCEL_MODE_GTK 16 | case .other: 17 | return GTK_CELL_RENDERER_ACCEL_MODE_OTHER 18 | } 19 | } 20 | } 21 | 22 | extension GtkCellRendererAccelMode { 23 | func toCellRendererAccelMode() -> CellRendererAccelMode { 24 | switch self { 25 | case GTK_CELL_RENDERER_ACCEL_MODE_GTK: 26 | return .gtk 27 | case GTK_CELL_RENDERER_ACCEL_MODE_OTHER: 28 | return .other 29 | default: 30 | fatalError("Unsupported GtkCellRendererAccelMode enum value: \(self.rawValue)") 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/CellRendererMode.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Identifies how the user can interact with a particular cell. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.CellRendererMode.html) 6 | public enum CellRendererMode { 7 | /// The cell is just for display and cannot be interacted with. Note that this doesn’t mean that eg. the row being drawn can’t be selected — just that a particular element of it cannot be individually modified. 8 | case inert 9 | /// The cell can be clicked. 10 | case activatable 11 | /// The cell can be edited or otherwise modified. 12 | case editable 13 | 14 | func toGtkCellRendererMode() -> GtkCellRendererMode { 15 | switch self { 16 | case .inert: 17 | return GTK_CELL_RENDERER_MODE_INERT 18 | case .activatable: 19 | return GTK_CELL_RENDERER_MODE_ACTIVATABLE 20 | case .editable: 21 | return GTK_CELL_RENDERER_MODE_EDITABLE 22 | } 23 | } 24 | } 25 | 26 | extension GtkCellRendererMode { 27 | func toCellRendererMode() -> CellRendererMode { 28 | switch self { 29 | case GTK_CELL_RENDERER_MODE_INERT: 30 | return .inert 31 | case GTK_CELL_RENDERER_MODE_ACTIVATABLE: 32 | return .activatable 33 | case GTK_CELL_RENDERER_MODE_EDITABLE: 34 | return .editable 35 | default: 36 | fatalError("Unsupported GtkCellRendererMode enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/CornerType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Specifies which corner a child widget should be placed in when packed into a `GtkScrolledWindow`. This is effectively the opposite of where the scroll bars are placed. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.CornerType.html) 6 | public enum CornerType { 7 | /// Place the scrollbars on the right and bottom of the widget (default behaviour). 8 | case topLeft 9 | /// Place the scrollbars on the top and right of the widget. 10 | case bottomLeft 11 | /// Place the scrollbars on the left and bottom of the widget. 12 | case topRight 13 | /// Place the scrollbars on the top and left of the widget. 14 | case bottomRight 15 | 16 | func toGtkCornerType() -> GtkCornerType { 17 | switch self { 18 | case .topLeft: 19 | return GTK_CORNER_TOP_LEFT 20 | case .bottomLeft: 21 | return GTK_CORNER_BOTTOM_LEFT 22 | case .topRight: 23 | return GTK_CORNER_TOP_RIGHT 24 | case .bottomRight: 25 | return GTK_CORNER_BOTTOM_RIGHT 26 | } 27 | } 28 | } 29 | 30 | extension GtkCornerType { 31 | func toCornerType() -> CornerType { 32 | switch self { 33 | case GTK_CORNER_TOP_LEFT: 34 | return .topLeft 35 | case GTK_CORNER_BOTTOM_LEFT: 36 | return .bottomLeft 37 | case GTK_CORNER_TOP_RIGHT: 38 | return .topRight 39 | case GTK_CORNER_BOTTOM_RIGHT: 40 | return .bottomRight 41 | default: 42 | fatalError("Unsupported GtkCornerType enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/CssSectionType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// The different types of sections indicate parts of a CSS document as parsed by GTK’s CSS parser. They are oriented towards the [CSS Grammar](http://www.w3.org/TR/CSS21/grammar.html), but may contain extensions. 4 | /// 5 | /// More types might be added in the future as the parser incorporates more features. 6 | /// 7 | /// Available since: 3.2 8 | /// 9 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.CssSectionType.html) 10 | public enum CssSectionType { 11 | /// The section describes a complete document. This section time is the only one where `gtk_css_section_get_parent()` might return `NULL`. 12 | case document 13 | /// The section defines an import rule. 14 | case `import` 15 | /// The section defines a color. This is a GTK extension to CSS. 16 | case colorDefinition 17 | /// The section defines a binding set. This is a GTK extension to CSS. 18 | case bindingSet 19 | /// The section defines a CSS ruleset. 20 | case ruleSet 21 | /// The section defines a CSS selector. 22 | case selector 23 | /// The section defines the declaration of a CSS variable. 24 | case declaration 25 | /// The section defines the value of a CSS declaration. 26 | case value 27 | /// The section defines keyframes. See [CSS Animations](http://dev.w3.org/csswg/css3-animations/#keyframes) for details. Since 3.6 28 | case keyFrames 29 | 30 | func toGtkCssSectionType() -> GtkCssSectionType { 31 | switch self { 32 | case .document: 33 | return GTK_CSS_SECTION_DOCUMENT 34 | case .import: 35 | return GTK_CSS_SECTION_IMPORT 36 | case .colorDefinition: 37 | return GTK_CSS_SECTION_COLOR_DEFINITION 38 | case .bindingSet: 39 | return GTK_CSS_SECTION_BINDING_SET 40 | case .ruleSet: 41 | return GTK_CSS_SECTION_RULESET 42 | case .selector: 43 | return GTK_CSS_SECTION_SELECTOR 44 | case .declaration: 45 | return GTK_CSS_SECTION_DECLARATION 46 | case .value: 47 | return GTK_CSS_SECTION_VALUE 48 | case .keyFrames: 49 | return GTK_CSS_SECTION_KEYFRAMES 50 | } 51 | } 52 | } 53 | 54 | extension GtkCssSectionType { 55 | func toCssSectionType() -> CssSectionType { 56 | switch self { 57 | case GTK_CSS_SECTION_DOCUMENT: 58 | return .document 59 | case GTK_CSS_SECTION_IMPORT: 60 | return .import 61 | case GTK_CSS_SECTION_COLOR_DEFINITION: 62 | return .colorDefinition 63 | case GTK_CSS_SECTION_BINDING_SET: 64 | return .bindingSet 65 | case GTK_CSS_SECTION_RULESET: 66 | return .ruleSet 67 | case GTK_CSS_SECTION_SELECTOR: 68 | return .selector 69 | case GTK_CSS_SECTION_DECLARATION: 70 | return .declaration 71 | case GTK_CSS_SECTION_VALUE: 72 | return .value 73 | case GTK_CSS_SECTION_KEYFRAMES: 74 | return .keyFrames 75 | default: 76 | fatalError("Unsupported GtkCssSectionType enum value: \(self.rawValue)") 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/DeleteType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// See also: `GtkEntry::delete-from-cursor`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.DeleteType.html) 6 | public enum DeleteType { 7 | /// Delete characters. 8 | case characters 9 | /// Delete only the portion of the word to the left/right of cursor if we’re in the middle of a word. 10 | case wordEnds 11 | /// Delete words. 12 | case words 13 | /// Delete display-lines. Display-lines refers to the visible lines, with respect to to the current line breaks. As opposed to paragraphs, which are defined by line breaks in the input. 14 | case displayLines 15 | /// Delete only the portion of the display-line to the left/right of cursor. 16 | case displayLineEnds 17 | /// Delete to the end of the paragraph. Like C-k in Emacs (or its reverse). 18 | case paragraphEnds 19 | /// Delete entire line. Like C-k in pico. 20 | case paragraphs 21 | /// Delete only whitespace. Like M-\ in Emacs. 22 | case whitespace 23 | 24 | func toGtkDeleteType() -> GtkDeleteType { 25 | switch self { 26 | case .characters: 27 | return GTK_DELETE_CHARS 28 | case .wordEnds: 29 | return GTK_DELETE_WORD_ENDS 30 | case .words: 31 | return GTK_DELETE_WORDS 32 | case .displayLines: 33 | return GTK_DELETE_DISPLAY_LINES 34 | case .displayLineEnds: 35 | return GTK_DELETE_DISPLAY_LINE_ENDS 36 | case .paragraphEnds: 37 | return GTK_DELETE_PARAGRAPH_ENDS 38 | case .paragraphs: 39 | return GTK_DELETE_PARAGRAPHS 40 | case .whitespace: 41 | return GTK_DELETE_WHITESPACE 42 | } 43 | } 44 | } 45 | 46 | extension GtkDeleteType { 47 | func toDeleteType() -> DeleteType { 48 | switch self { 49 | case GTK_DELETE_CHARS: 50 | return .characters 51 | case GTK_DELETE_WORD_ENDS: 52 | return .wordEnds 53 | case GTK_DELETE_WORDS: 54 | return .words 55 | case GTK_DELETE_DISPLAY_LINES: 56 | return .displayLines 57 | case GTK_DELETE_DISPLAY_LINE_ENDS: 58 | return .displayLineEnds 59 | case GTK_DELETE_PARAGRAPH_ENDS: 60 | return .paragraphEnds 61 | case GTK_DELETE_PARAGRAPHS: 62 | return .paragraphs 63 | case GTK_DELETE_WHITESPACE: 64 | return .whitespace 65 | default: 66 | fatalError("Unsupported GtkDeleteType enum value: \(self.rawValue)") 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/DirectionType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Focus movement types. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.DirectionType.html) 6 | public enum DirectionType { 7 | /// Move forward. 8 | case tabForward 9 | /// Move backward. 10 | case tabBackward 11 | /// Move up. 12 | case up 13 | /// Move down. 14 | case down 15 | /// Move left. 16 | case left 17 | /// Move right. 18 | case right 19 | 20 | func toGtkDirectionType() -> GtkDirectionType { 21 | switch self { 22 | case .tabForward: 23 | return GTK_DIR_TAB_FORWARD 24 | case .tabBackward: 25 | return GTK_DIR_TAB_BACKWARD 26 | case .up: 27 | return GTK_DIR_UP 28 | case .down: 29 | return GTK_DIR_DOWN 30 | case .left: 31 | return GTK_DIR_LEFT 32 | case .right: 33 | return GTK_DIR_RIGHT 34 | } 35 | } 36 | } 37 | 38 | extension GtkDirectionType { 39 | func toDirectionType() -> DirectionType { 40 | switch self { 41 | case GTK_DIR_TAB_FORWARD: 42 | return .tabForward 43 | case GTK_DIR_TAB_BACKWARD: 44 | return .tabBackward 45 | case GTK_DIR_UP: 46 | return .up 47 | case GTK_DIR_DOWN: 48 | return .down 49 | case GTK_DIR_LEFT: 50 | return .left 51 | case GTK_DIR_RIGHT: 52 | return .right 53 | default: 54 | fatalError("Unsupported GtkDirectionType enum value: \(self.rawValue)") 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/DragResult.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Gives an indication why a drag operation failed. The value can by obtained by connecting to the `GtkWidget::drag-failed` signal. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.DragResult.html) 6 | public enum DragResult { 7 | /// The drag operation was successful. 8 | case success 9 | /// No suitable drag target. 10 | case noTarget 11 | /// The user cancelled the drag operation. 12 | case userCancelled 13 | /// The drag operation timed out. 14 | case timeoutExpired 15 | /// The pointer or keyboard grab used for the drag operation was broken. 16 | case grabBroken 17 | /// The drag operation failed due to some unspecified error. 18 | case error 19 | 20 | func toGtkDragResult() -> GtkDragResult { 21 | switch self { 22 | case .success: 23 | return GTK_DRAG_RESULT_SUCCESS 24 | case .noTarget: 25 | return GTK_DRAG_RESULT_NO_TARGET 26 | case .userCancelled: 27 | return GTK_DRAG_RESULT_USER_CANCELLED 28 | case .timeoutExpired: 29 | return GTK_DRAG_RESULT_TIMEOUT_EXPIRED 30 | case .grabBroken: 31 | return GTK_DRAG_RESULT_GRAB_BROKEN 32 | case .error: 33 | return GTK_DRAG_RESULT_ERROR 34 | } 35 | } 36 | } 37 | 38 | extension GtkDragResult { 39 | func toDragResult() -> DragResult { 40 | switch self { 41 | case GTK_DRAG_RESULT_SUCCESS: 42 | return .success 43 | case GTK_DRAG_RESULT_NO_TARGET: 44 | return .noTarget 45 | case GTK_DRAG_RESULT_USER_CANCELLED: 46 | return .userCancelled 47 | case GTK_DRAG_RESULT_TIMEOUT_EXPIRED: 48 | return .timeoutExpired 49 | case GTK_DRAG_RESULT_GRAB_BROKEN: 50 | return .grabBroken 51 | case GTK_DRAG_RESULT_ERROR: 52 | return .error 53 | default: 54 | fatalError("Unsupported GtkDragResult enum value: \(self.rawValue)") 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/EntryIconPosition.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Specifies the side of the entry at which an icon is placed. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.EntryIconPosition.html) 6 | public enum EntryIconPosition { 7 | /// At the beginning of the entry (depending on the text direction). 8 | case primary 9 | /// At the end of the entry (depending on the text direction). 10 | case secondary 11 | 12 | func toGtkEntryIconPosition() -> GtkEntryIconPosition { 13 | switch self { 14 | case .primary: 15 | return GTK_ENTRY_ICON_PRIMARY 16 | case .secondary: 17 | return GTK_ENTRY_ICON_SECONDARY 18 | } 19 | } 20 | } 21 | 22 | extension GtkEntryIconPosition { 23 | func toEntryIconPosition() -> EntryIconPosition { 24 | switch self { 25 | case GTK_ENTRY_ICON_PRIMARY: 26 | return .primary 27 | case GTK_ENTRY_ICON_SECONDARY: 28 | return .secondary 29 | default: 30 | fatalError("Unsupported GtkEntryIconPosition enum value: \(self.rawValue)") 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/EventSequenceState.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Describes the state of a `GdkEventSequence` in a `GtkGesture`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.EventSequenceState.html) 6 | public enum EventSequenceState { 7 | /// The sequence is handled, but not grabbed. 8 | case none 9 | /// The sequence is handled and grabbed. 10 | case claimed 11 | /// The sequence is denied. 12 | case denied 13 | 14 | func toGtkEventSequenceState() -> GtkEventSequenceState { 15 | switch self { 16 | case .none: 17 | return GTK_EVENT_SEQUENCE_NONE 18 | case .claimed: 19 | return GTK_EVENT_SEQUENCE_CLAIMED 20 | case .denied: 21 | return GTK_EVENT_SEQUENCE_DENIED 22 | } 23 | } 24 | } 25 | 26 | extension GtkEventSequenceState { 27 | func toEventSequenceState() -> EventSequenceState { 28 | switch self { 29 | case GTK_EVENT_SEQUENCE_NONE: 30 | return EventSequenceState.none 31 | case GTK_EVENT_SEQUENCE_CLAIMED: 32 | return .claimed 33 | case GTK_EVENT_SEQUENCE_DENIED: 34 | return .denied 35 | default: 36 | fatalError("Unsupported GtkEventSequenceState enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ExpanderStyle.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to specify the style of the expanders drawn by a `GtkTreeView`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ExpanderStyle.html) 6 | public enum ExpanderStyle { 7 | /// The style used for a collapsed subtree. 8 | case collapsed 9 | /// The style used for a collapsed subtree. 10 | case semiCollapsed 11 | /// Intermediate style used during animation. 12 | case semiExpanded 13 | /// The style used for an expanded subtree. 14 | case expanded 15 | 16 | func toGtkExpanderStyle() -> GtkExpanderStyle { 17 | switch self { 18 | case .collapsed: 19 | return GTK_EXPANDER_COLLAPSED 20 | case .semiCollapsed: 21 | return GTK_EXPANDER_SEMI_COLLAPSED 22 | case .semiExpanded: 23 | return GTK_EXPANDER_SEMI_EXPANDED 24 | case .expanded: 25 | return GTK_EXPANDER_EXPANDED 26 | } 27 | } 28 | } 29 | 30 | extension GtkExpanderStyle { 31 | func toExpanderStyle() -> ExpanderStyle { 32 | switch self { 33 | case GTK_EXPANDER_COLLAPSED: 34 | return .collapsed 35 | case GTK_EXPANDER_SEMI_COLLAPSED: 36 | return .semiCollapsed 37 | case GTK_EXPANDER_SEMI_EXPANDED: 38 | return .semiExpanded 39 | case GTK_EXPANDER_EXPANDED: 40 | return .expanded 41 | default: 42 | fatalError("Unsupported GtkExpanderStyle enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/FileChooserAction.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Describes whether a `GtkFileChooser` is being used to open existing files or to save to a possibly new file. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.FileChooserAction.html) 6 | public enum FileChooserAction { 7 | /// Indicates open mode. The file chooser will only let the user pick an existing file. 8 | case `open` 9 | /// Indicates save mode. The file chooser will let the user pick an existing file, or type in a new filename. 10 | case save 11 | /// Indicates an Open mode for selecting folders. The file chooser will let the user pick an existing folder. 12 | case selectFolder 13 | /// Indicates a mode for creating a new folder. The file chooser will let the user name an existing or new folder. 14 | case createFolder 15 | 16 | func toGtkFileChooserAction() -> GtkFileChooserAction { 17 | switch self { 18 | case .open: 19 | return GTK_FILE_CHOOSER_ACTION_OPEN 20 | case .save: 21 | return GTK_FILE_CHOOSER_ACTION_SAVE 22 | case .selectFolder: 23 | return GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER 24 | case .createFolder: 25 | return GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER 26 | } 27 | } 28 | } 29 | 30 | extension GtkFileChooserAction { 31 | func toFileChooserAction() -> FileChooserAction { 32 | switch self { 33 | case GTK_FILE_CHOOSER_ACTION_OPEN: 34 | return .open 35 | case GTK_FILE_CHOOSER_ACTION_SAVE: 36 | return .save 37 | case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: 38 | return .selectFolder 39 | case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: 40 | return .createFolder 41 | default: 42 | fatalError("Unsupported GtkFileChooserAction enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/FileChooserConfirmation.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used as a return value of handlers for the `GtkFileChooser::confirm-overwrite` signal of a `GtkFileChooser`. This value determines whether the file chooser will present the stock confirmation dialog, accept the user’s choice of a filename, or let the user choose another filename. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.FileChooserConfirmation.html) 6 | public enum FileChooserConfirmation { 7 | /// The file chooser will present its stock dialog to confirm about overwriting an existing file. 8 | case confirm 9 | /// The file chooser will terminate and accept the user’s choice of a file name. 10 | case acceptFileName 11 | /// The file chooser will continue running, so as to let the user select another file name. 12 | case selectAgain 13 | 14 | func toGtkFileChooserConfirmation() -> GtkFileChooserConfirmation { 15 | switch self { 16 | case .confirm: 17 | return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM 18 | case .acceptFileName: 19 | return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME 20 | case .selectAgain: 21 | return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN 22 | } 23 | } 24 | } 25 | 26 | extension GtkFileChooserConfirmation { 27 | func toFileChooserConfirmation() -> FileChooserConfirmation { 28 | switch self { 29 | case GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM: 30 | return .confirm 31 | case GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME: 32 | return .acceptFileName 33 | case GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN: 34 | return .selectAgain 35 | default: 36 | fatalError("Unsupported GtkFileChooserConfirmation enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/IconSize.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Built-in stock icon sizes. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.IconSize.html) 6 | public enum IconSize { 7 | /// Invalid size. 8 | case invalid 9 | /// Size appropriate for menus (16px). 10 | case menu 11 | /// Size appropriate for small toolbars (16px). 12 | case smallToolbar 13 | /// Size appropriate for large toolbars (24px). 14 | case largeToolbar 15 | /// Size appropriate for buttons (16px) 16 | case button 17 | /// Size appropriate for drag and drop (32px). 18 | case dragAndDrop 19 | /// Size appropriate for dialogs (48px). 20 | case dialog 21 | 22 | func toGtkIconSize() -> GtkIconSize { 23 | switch self { 24 | case .invalid: 25 | return GTK_ICON_SIZE_INVALID 26 | case .menu: 27 | return GTK_ICON_SIZE_MENU 28 | case .smallToolbar: 29 | return GTK_ICON_SIZE_SMALL_TOOLBAR 30 | case .largeToolbar: 31 | return GTK_ICON_SIZE_LARGE_TOOLBAR 32 | case .button: 33 | return GTK_ICON_SIZE_BUTTON 34 | case .dragAndDrop: 35 | return GTK_ICON_SIZE_DND 36 | case .dialog: 37 | return GTK_ICON_SIZE_DIALOG 38 | } 39 | } 40 | } 41 | 42 | extension GtkIconSize { 43 | func toIconSize() -> IconSize { 44 | switch self { 45 | case GTK_ICON_SIZE_INVALID: 46 | return .invalid 47 | case GTK_ICON_SIZE_MENU: 48 | return .menu 49 | case GTK_ICON_SIZE_SMALL_TOOLBAR: 50 | return .smallToolbar 51 | case GTK_ICON_SIZE_LARGE_TOOLBAR: 52 | return .largeToolbar 53 | case GTK_ICON_SIZE_BUTTON: 54 | return .button 55 | case GTK_ICON_SIZE_DND: 56 | return .dragAndDrop 57 | case GTK_ICON_SIZE_DIALOG: 58 | return .dialog 59 | default: 60 | fatalError("Unsupported GtkIconSize enum value: \(self.rawValue)") 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/IconViewDropPosition.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// An enum for determining where a dropped item goes. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.IconViewDropPosition.html) 6 | public enum IconViewDropPosition { 7 | /// No drop possible. 8 | case noDrop 9 | /// Dropped item replaces the item. 10 | case dropInto 11 | /// Droppped item is inserted to the left. 12 | case dropLeft 13 | /// Dropped item is inserted to the right. 14 | case dropRight 15 | /// Dropped item is inserted above. 16 | case dropAbove 17 | /// Dropped item is inserted below. 18 | case dropBelow 19 | 20 | func toGtkIconViewDropPosition() -> GtkIconViewDropPosition { 21 | switch self { 22 | case .noDrop: 23 | return GTK_ICON_VIEW_NO_DROP 24 | case .dropInto: 25 | return GTK_ICON_VIEW_DROP_INTO 26 | case .dropLeft: 27 | return GTK_ICON_VIEW_DROP_LEFT 28 | case .dropRight: 29 | return GTK_ICON_VIEW_DROP_RIGHT 30 | case .dropAbove: 31 | return GTK_ICON_VIEW_DROP_ABOVE 32 | case .dropBelow: 33 | return GTK_ICON_VIEW_DROP_BELOW 34 | } 35 | } 36 | } 37 | 38 | extension GtkIconViewDropPosition { 39 | func toIconViewDropPosition() -> IconViewDropPosition { 40 | switch self { 41 | case GTK_ICON_VIEW_NO_DROP: 42 | return .noDrop 43 | case GTK_ICON_VIEW_DROP_INTO: 44 | return .dropInto 45 | case GTK_ICON_VIEW_DROP_LEFT: 46 | return .dropLeft 47 | case GTK_ICON_VIEW_DROP_RIGHT: 48 | return .dropRight 49 | case GTK_ICON_VIEW_DROP_ABOVE: 50 | return .dropAbove 51 | case GTK_ICON_VIEW_DROP_BELOW: 52 | return .dropBelow 53 | default: 54 | fatalError("Unsupported GtkIconViewDropPosition enum value: \(self.rawValue)") 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ImageType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Describes the image data representation used by a `GtkImage`. If you want to get the image from the widget, you can only get the currently-stored representation. e.g. if the `gtk_image_get_storage_type()` returns #GTK_IMAGE_PIXBUF, then you can call `gtk_image_get_pixbuf()` but not `gtk_image_get_stock()`. For empty images, you can request any storage type (call any of the “get” functions), but they will all return `NULL` values. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ImageType.html) 6 | public enum ImageType { 7 | /// There is no image displayed by the widget. 8 | case empty 9 | /// The widget contains a `GdkPixbuf`. 10 | case pixbuf 11 | /// The widget contains a [stock item name][gtkstock] 12 | case stock 13 | /// The widget contains a `GtkIconSet`. 14 | case iconSet 15 | /// The widget contains a `GdkPixbufAnimation`. 16 | case animation 17 | /// The widget contains a named icon. This image type was added in GTK+ 2.6. 18 | case iconName 19 | /// The widget contains a GIcon. This image type was added in GTK+ 2.14. 20 | case gIcon 21 | /// The widget contains a #cairo_surface_t. This image type was added in GTK+ 3.10. 22 | case surface 23 | 24 | func toGtkImageType() -> GtkImageType { 25 | switch self { 26 | case .empty: 27 | return GTK_IMAGE_EMPTY 28 | case .pixbuf: 29 | return GTK_IMAGE_PIXBUF 30 | case .stock: 31 | return GTK_IMAGE_STOCK 32 | case .iconSet: 33 | return GTK_IMAGE_ICON_SET 34 | case .animation: 35 | return GTK_IMAGE_ANIMATION 36 | case .iconName: 37 | return GTK_IMAGE_ICON_NAME 38 | case .gIcon: 39 | return GTK_IMAGE_GICON 40 | case .surface: 41 | return GTK_IMAGE_SURFACE 42 | } 43 | } 44 | } 45 | 46 | extension GtkImageType { 47 | func toImageType() -> ImageType { 48 | switch self { 49 | case GTK_IMAGE_EMPTY: 50 | return .empty 51 | case GTK_IMAGE_PIXBUF: 52 | return .pixbuf 53 | case GTK_IMAGE_STOCK: 54 | return .stock 55 | case GTK_IMAGE_ICON_SET: 56 | return .iconSet 57 | case GTK_IMAGE_ANIMATION: 58 | return .animation 59 | case GTK_IMAGE_ICON_NAME: 60 | return .iconName 61 | case GTK_IMAGE_GICON: 62 | return .gIcon 63 | case GTK_IMAGE_SURFACE: 64 | return .surface 65 | default: 66 | fatalError("Unsupported GtkImageType enum value: \(self.rawValue)") 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/InputPurpose.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Describes primary purpose of the input widget. This information is useful for on-screen keyboards and similar input methods to decide which keys should be presented to the user. 4 | /// 5 | /// Note that the purpose is not meant to impose a totally strict rule about allowed characters, and does not replace input validation. It is fine for an on-screen keyboard to let the user override the character set restriction that is expressed by the purpose. The application is expected to validate the entry contents, even if it specified a purpose. 6 | /// 7 | /// The difference between `GTK_INPUT_PURPOSE_DIGITS` and `GTK_INPUT_PURPOSE_NUMBER` is that the former accepts only digits while the latter also some punctuation (like commas or points, plus, minus) and “e” or “E” as in 3.14E+000. 8 | /// 9 | /// This enumeration may be extended in the future; input methods should interpret unknown values as “free form”. 10 | /// 11 | /// Available since: 3.6 12 | /// 13 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.InputPurpose.html) 14 | public enum InputPurpose { 15 | /// Allow any character. 16 | case freeForm 17 | /// Allow only alphabetic characters. 18 | case alpha 19 | /// Allow only digits. 20 | case digits 21 | /// Edited field expects numbers. 22 | case number 23 | /// Edited field expects phone number. 24 | case phone 25 | /// Edited field expects URL. 26 | case url 27 | /// Edited field expects email address. 28 | case email 29 | /// Edited field expects the name of a person. 30 | case name 31 | /// Like `GTK_INPUT_PURPOSE_FREE_FORM`, but characters are hidden. 32 | case password 33 | /// Like `GTK_INPUT_PURPOSE_DIGITS`, but characters are hidden. 34 | case pin 35 | /// Allow any character, in addition to control codes. 36 | case terminal 37 | 38 | func toGtkInputPurpose() -> GtkInputPurpose { 39 | switch self { 40 | case .freeForm: 41 | return GTK_INPUT_PURPOSE_FREE_FORM 42 | case .alpha: 43 | return GTK_INPUT_PURPOSE_ALPHA 44 | case .digits: 45 | return GTK_INPUT_PURPOSE_DIGITS 46 | case .number: 47 | return GTK_INPUT_PURPOSE_NUMBER 48 | case .phone: 49 | return GTK_INPUT_PURPOSE_PHONE 50 | case .url: 51 | return GTK_INPUT_PURPOSE_URL 52 | case .email: 53 | return GTK_INPUT_PURPOSE_EMAIL 54 | case .name: 55 | return GTK_INPUT_PURPOSE_NAME 56 | case .password: 57 | return GTK_INPUT_PURPOSE_PASSWORD 58 | case .pin: 59 | return GTK_INPUT_PURPOSE_PIN 60 | case .terminal: 61 | return GTK_INPUT_PURPOSE_TERMINAL 62 | } 63 | } 64 | } 65 | 66 | extension GtkInputPurpose { 67 | func toInputPurpose() -> InputPurpose { 68 | switch self { 69 | case GTK_INPUT_PURPOSE_FREE_FORM: 70 | return .freeForm 71 | case GTK_INPUT_PURPOSE_ALPHA: 72 | return .alpha 73 | case GTK_INPUT_PURPOSE_DIGITS: 74 | return .digits 75 | case GTK_INPUT_PURPOSE_NUMBER: 76 | return .number 77 | case GTK_INPUT_PURPOSE_PHONE: 78 | return .phone 79 | case GTK_INPUT_PURPOSE_URL: 80 | return .url 81 | case GTK_INPUT_PURPOSE_EMAIL: 82 | return .email 83 | case GTK_INPUT_PURPOSE_NAME: 84 | return .name 85 | case GTK_INPUT_PURPOSE_PASSWORD: 86 | return .password 87 | case GTK_INPUT_PURPOSE_PIN: 88 | return .pin 89 | case GTK_INPUT_PURPOSE_TERMINAL: 90 | return .terminal 91 | default: 92 | fatalError("Unsupported GtkInputPurpose enum value: \(self.rawValue)") 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/Justification.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used for justifying the text inside a GtkLabel widget. (See also GtkAlignment). 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.Justification.html) 6 | public enum Justification { 7 | /// The text is placed at the left edge of the label. 8 | case left 9 | /// The text is placed at the right edge of the label. 10 | case right 11 | /// The text is placed in the center of the label. 12 | case center 13 | /// The text is placed is distributed across the label. 14 | case fill 15 | 16 | func toGtkJustification() -> GtkJustification { 17 | switch self { 18 | case .left: 19 | return GTK_JUSTIFY_LEFT 20 | case .right: 21 | return GTK_JUSTIFY_RIGHT 22 | case .center: 23 | return GTK_JUSTIFY_CENTER 24 | case .fill: 25 | return GTK_JUSTIFY_FILL 26 | } 27 | } 28 | } 29 | 30 | extension GtkJustification { 31 | func toJustification() -> Justification { 32 | switch self { 33 | case GTK_JUSTIFY_LEFT: 34 | return .left 35 | case GTK_JUSTIFY_RIGHT: 36 | return .right 37 | case GTK_JUSTIFY_CENTER: 38 | return .center 39 | case GTK_JUSTIFY_FILL: 40 | return .fill 41 | default: 42 | fatalError("Unsupported GtkJustification enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/LevelBarMode.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Describes how GtkLevelBar contents should be rendered. Note that this enumeration could be extended with additional modes in the future. 4 | /// 5 | /// Available since: 3.6 6 | /// 7 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.LevelBarMode.html) 8 | public enum LevelBarMode { 9 | /// The bar has a continuous mode. 10 | case continuous 11 | /// The bar has a discrete mode. 12 | case discrete 13 | 14 | func toGtkLevelBarMode() -> GtkLevelBarMode { 15 | switch self { 16 | case .continuous: 17 | return GTK_LEVEL_BAR_MODE_CONTINUOUS 18 | case .discrete: 19 | return GTK_LEVEL_BAR_MODE_DISCRETE 20 | } 21 | } 22 | } 23 | 24 | extension GtkLevelBarMode { 25 | func toLevelBarMode() -> LevelBarMode { 26 | switch self { 27 | case GTK_LEVEL_BAR_MODE_CONTINUOUS: 28 | return .continuous 29 | case GTK_LEVEL_BAR_MODE_DISCRETE: 30 | return .discrete 31 | default: 32 | fatalError("Unsupported GtkLevelBarMode enum value: \(self.rawValue)") 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/MenuDirectionType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// An enumeration representing directional movements within a menu. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.MenuDirectionType.html) 6 | public enum MenuDirectionType { 7 | /// To the parent menu shell. 8 | case parent 9 | /// To the submenu, if any, associated with the item. 10 | case child 11 | /// To the next menu item. 12 | case next 13 | /// To the previous menu item. 14 | case previous 15 | 16 | func toGtkMenuDirectionType() -> GtkMenuDirectionType { 17 | switch self { 18 | case .parent: 19 | return GTK_MENU_DIR_PARENT 20 | case .child: 21 | return GTK_MENU_DIR_CHILD 22 | case .next: 23 | return GTK_MENU_DIR_NEXT 24 | case .previous: 25 | return GTK_MENU_DIR_PREV 26 | } 27 | } 28 | } 29 | 30 | extension GtkMenuDirectionType { 31 | func toMenuDirectionType() -> MenuDirectionType { 32 | switch self { 33 | case GTK_MENU_DIR_PARENT: 34 | return .parent 35 | case GTK_MENU_DIR_CHILD: 36 | return .child 37 | case GTK_MENU_DIR_NEXT: 38 | return .next 39 | case GTK_MENU_DIR_PREV: 40 | return .previous 41 | default: 42 | fatalError("Unsupported GtkMenuDirectionType enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/MessageType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// The type of message being displayed in the dialog. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.MessageType.html) 6 | public enum MessageType { 7 | /// Informational message. 8 | case info 9 | /// Non-fatal warning message. 10 | case warning 11 | /// Question requiring a choice. 12 | case question 13 | /// Fatal error message. 14 | case error 15 | /// None of the above. 16 | case other 17 | 18 | func toGtkMessageType() -> GtkMessageType { 19 | switch self { 20 | case .info: 21 | return GTK_MESSAGE_INFO 22 | case .warning: 23 | return GTK_MESSAGE_WARNING 24 | case .question: 25 | return GTK_MESSAGE_QUESTION 26 | case .error: 27 | return GTK_MESSAGE_ERROR 28 | case .other: 29 | return GTK_MESSAGE_OTHER 30 | } 31 | } 32 | } 33 | 34 | extension GtkMessageType { 35 | func toMessageType() -> MessageType { 36 | switch self { 37 | case GTK_MESSAGE_INFO: 38 | return .info 39 | case GTK_MESSAGE_WARNING: 40 | return .warning 41 | case GTK_MESSAGE_QUESTION: 42 | return .question 43 | case GTK_MESSAGE_ERROR: 44 | return .error 45 | case GTK_MESSAGE_OTHER: 46 | return .other 47 | default: 48 | fatalError("Unsupported GtkMessageType enum value: \(self.rawValue)") 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/MovementStep.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.MovementStep.html) 4 | public enum MovementStep { 5 | /// Move forward or back by graphemes. 6 | case logicalPositions 7 | /// Move left or right by graphemes. 8 | case visualPositions 9 | /// Move forward or back by words. 10 | case words 11 | /// Move up or down lines (wrapped lines) 12 | case displayLines 13 | /// Move to either end of a line. 14 | case displayLineEnds 15 | /// Move up or down paragraphs (newline-ended lines) 16 | case paragraphs 17 | /// Move to either end of a paragraph. 18 | case paragraphEnds 19 | /// Move by pages. 20 | case pages 21 | /// Move to ends of the buffer. 22 | case bufferEnds 23 | /// Move horizontally by pages. 24 | case horizontalPages 25 | 26 | func toGtkMovementStep() -> GtkMovementStep { 27 | switch self { 28 | case .logicalPositions: 29 | return GTK_MOVEMENT_LOGICAL_POSITIONS 30 | case .visualPositions: 31 | return GTK_MOVEMENT_VISUAL_POSITIONS 32 | case .words: 33 | return GTK_MOVEMENT_WORDS 34 | case .displayLines: 35 | return GTK_MOVEMENT_DISPLAY_LINES 36 | case .displayLineEnds: 37 | return GTK_MOVEMENT_DISPLAY_LINE_ENDS 38 | case .paragraphs: 39 | return GTK_MOVEMENT_PARAGRAPHS 40 | case .paragraphEnds: 41 | return GTK_MOVEMENT_PARAGRAPH_ENDS 42 | case .pages: 43 | return GTK_MOVEMENT_PAGES 44 | case .bufferEnds: 45 | return GTK_MOVEMENT_BUFFER_ENDS 46 | case .horizontalPages: 47 | return GTK_MOVEMENT_HORIZONTAL_PAGES 48 | } 49 | } 50 | } 51 | 52 | extension GtkMovementStep { 53 | func toMovementStep() -> MovementStep { 54 | switch self { 55 | case GTK_MOVEMENT_LOGICAL_POSITIONS: 56 | return .logicalPositions 57 | case GTK_MOVEMENT_VISUAL_POSITIONS: 58 | return .visualPositions 59 | case GTK_MOVEMENT_WORDS: 60 | return .words 61 | case GTK_MOVEMENT_DISPLAY_LINES: 62 | return .displayLines 63 | case GTK_MOVEMENT_DISPLAY_LINE_ENDS: 64 | return .displayLineEnds 65 | case GTK_MOVEMENT_PARAGRAPHS: 66 | return .paragraphs 67 | case GTK_MOVEMENT_PARAGRAPH_ENDS: 68 | return .paragraphEnds 69 | case GTK_MOVEMENT_PAGES: 70 | return .pages 71 | case GTK_MOVEMENT_BUFFER_ENDS: 72 | return .bufferEnds 73 | case GTK_MOVEMENT_HORIZONTAL_PAGES: 74 | return .horizontalPages 75 | default: 76 | fatalError("Unsupported GtkMovementStep enum value: \(self.rawValue)") 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/NotebookTab.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.NotebookTab.html) 4 | public enum NotebookTab { 5 | case first 6 | case last 7 | 8 | func toGtkNotebookTab() -> GtkNotebookTab { 9 | switch self { 10 | case .first: 11 | return GTK_NOTEBOOK_TAB_FIRST 12 | case .last: 13 | return GTK_NOTEBOOK_TAB_LAST 14 | } 15 | } 16 | } 17 | 18 | extension GtkNotebookTab { 19 | func toNotebookTab() -> NotebookTab { 20 | switch self { 21 | case GTK_NOTEBOOK_TAB_FIRST: 22 | return .first 23 | case GTK_NOTEBOOK_TAB_LAST: 24 | return .last 25 | default: 26 | fatalError("Unsupported GtkNotebookTab enum value: \(self.rawValue)") 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/NumberUpLayout.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to determine the layout of pages on a sheet when printing multiple pages per sheet. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.NumberUpLayout.html) 6 | public enum NumberUpLayout { 7 | case leftToRightTopToBottom 8 | case leftToRightBottomToTop 9 | case rightToLeftTopToBottom 10 | case rightToLeftBottomToTop 11 | case topToBottomLeftToRight 12 | case topToBottomRightToLeft 13 | case bottomToTopLeftToRight 14 | case bottomToTopRightToLeft 15 | 16 | func toGtkNumberUpLayout() -> GtkNumberUpLayout { 17 | switch self { 18 | case .leftToRightTopToBottom: 19 | return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM 20 | case .leftToRightBottomToTop: 21 | return GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP 22 | case .rightToLeftTopToBottom: 23 | return GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM 24 | case .rightToLeftBottomToTop: 25 | return GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP 26 | case .topToBottomLeftToRight: 27 | return GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT 28 | case .topToBottomRightToLeft: 29 | return GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT 30 | case .bottomToTopLeftToRight: 31 | return GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT 32 | case .bottomToTopRightToLeft: 33 | return GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT 34 | } 35 | } 36 | } 37 | 38 | extension GtkNumberUpLayout { 39 | func toNumberUpLayout() -> NumberUpLayout { 40 | switch self { 41 | case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM: 42 | return .leftToRightTopToBottom 43 | case GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_BOTTOM_TO_TOP: 44 | return .leftToRightBottomToTop 45 | case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM: 46 | return .rightToLeftTopToBottom 47 | case GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_BOTTOM_TO_TOP: 48 | return .rightToLeftBottomToTop 49 | case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_LEFT_TO_RIGHT: 50 | return .topToBottomLeftToRight 51 | case GTK_NUMBER_UP_LAYOUT_TOP_TO_BOTTOM_RIGHT_TO_LEFT: 52 | return .topToBottomRightToLeft 53 | case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_LEFT_TO_RIGHT: 54 | return .bottomToTopLeftToRight 55 | case GTK_NUMBER_UP_LAYOUT_BOTTOM_TO_TOP_RIGHT_TO_LEFT: 56 | return .bottomToTopRightToLeft 57 | default: 58 | fatalError("Unsupported GtkNumberUpLayout enum value: \(self.rawValue)") 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/Orientation.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Represents the orientation of widgets and other objects which can be switched between horizontal and vertical orientation on the fly, like `GtkToolbar` or `GtkGesturePan`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.Orientation.html) 6 | public enum Orientation { 7 | /// The element is in horizontal orientation. 8 | case horizontal 9 | /// The element is in vertical orientation. 10 | case vertical 11 | 12 | func toGtkOrientation() -> GtkOrientation { 13 | switch self { 14 | case .horizontal: 15 | return GTK_ORIENTATION_HORIZONTAL 16 | case .vertical: 17 | return GTK_ORIENTATION_VERTICAL 18 | } 19 | } 20 | } 21 | 22 | extension GtkOrientation { 23 | func toOrientation() -> Orientation { 24 | switch self { 25 | case GTK_ORIENTATION_HORIZONTAL: 26 | return .horizontal 27 | case GTK_ORIENTATION_VERTICAL: 28 | return .vertical 29 | default: 30 | fatalError("Unsupported GtkOrientation enum value: \(self.rawValue)") 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PackDirection.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Determines how widgets should be packed inside menubars and menuitems contained in menubars. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PackDirection.html) 6 | public enum PackDirection { 7 | /// Widgets are packed left-to-right. 8 | case leftToRight 9 | /// Widgets are packed right-to-left. 10 | case rightToLeft 11 | /// Widgets are packed top-to-bottom. 12 | case topToBottom 13 | /// Widgets are packed bottom-to-top. 14 | case bottomToTop 15 | 16 | func toGtkPackDirection() -> GtkPackDirection { 17 | switch self { 18 | case .leftToRight: 19 | return GTK_PACK_DIRECTION_LTR 20 | case .rightToLeft: 21 | return GTK_PACK_DIRECTION_RTL 22 | case .topToBottom: 23 | return GTK_PACK_DIRECTION_TTB 24 | case .bottomToTop: 25 | return GTK_PACK_DIRECTION_BTT 26 | } 27 | } 28 | } 29 | 30 | extension GtkPackDirection { 31 | func toPackDirection() -> PackDirection { 32 | switch self { 33 | case GTK_PACK_DIRECTION_LTR: 34 | return .leftToRight 35 | case GTK_PACK_DIRECTION_RTL: 36 | return .rightToLeft 37 | case GTK_PACK_DIRECTION_TTB: 38 | return .topToBottom 39 | case GTK_PACK_DIRECTION_BTT: 40 | return .bottomToTop 41 | default: 42 | fatalError("Unsupported GtkPackDirection enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PackType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Represents the packing location GtkBox children. (See: `GtkVBox`, `GtkHBox`, and `GtkButtonBox`). 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PackType.html) 6 | public enum PackType { 7 | /// The child is packed into the start of the box. 8 | case start 9 | /// The child is packed into the end of the box. 10 | case end 11 | 12 | func toGtkPackType() -> GtkPackType { 13 | switch self { 14 | case .start: 15 | return GTK_PACK_START 16 | case .end: 17 | return GTK_PACK_END 18 | } 19 | } 20 | } 21 | 22 | extension GtkPackType { 23 | func toPackType() -> PackType { 24 | switch self { 25 | case GTK_PACK_START: 26 | return .start 27 | case GTK_PACK_END: 28 | return .end 29 | default: 30 | fatalError("Unsupported GtkPackType enum value: \(self.rawValue)") 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PadActionType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// The type of a pad action. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PadActionType.html) 6 | public enum PadActionType { 7 | /// Action is triggered by a pad button. 8 | case button 9 | /// Action is triggered by a pad ring. 10 | case ring 11 | /// Action is triggered by a pad strip. 12 | case strip 13 | 14 | func toGtkPadActionType() -> GtkPadActionType { 15 | switch self { 16 | case .button: 17 | return GTK_PAD_ACTION_BUTTON 18 | case .ring: 19 | return GTK_PAD_ACTION_RING 20 | case .strip: 21 | return GTK_PAD_ACTION_STRIP 22 | } 23 | } 24 | } 25 | 26 | extension GtkPadActionType { 27 | func toPadActionType() -> PadActionType { 28 | switch self { 29 | case GTK_PAD_ACTION_BUTTON: 30 | return .button 31 | case GTK_PAD_ACTION_RING: 32 | return .ring 33 | case GTK_PAD_ACTION_STRIP: 34 | return .strip 35 | default: 36 | fatalError("Unsupported GtkPadActionType enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PageOrientation.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// See also gtk_print_settings_set_orientation(). 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PageOrientation.html) 6 | public enum PageOrientation { 7 | /// Portrait mode. 8 | case portrait 9 | /// Landscape mode. 10 | case landscape 11 | /// Reverse portrait mode. 12 | case reversePortrait 13 | /// Reverse landscape mode. 14 | case reverseLandscape 15 | 16 | func toGtkPageOrientation() -> GtkPageOrientation { 17 | switch self { 18 | case .portrait: 19 | return GTK_PAGE_ORIENTATION_PORTRAIT 20 | case .landscape: 21 | return GTK_PAGE_ORIENTATION_LANDSCAPE 22 | case .reversePortrait: 23 | return GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT 24 | case .reverseLandscape: 25 | return GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE 26 | } 27 | } 28 | } 29 | 30 | extension GtkPageOrientation { 31 | func toPageOrientation() -> PageOrientation { 32 | switch self { 33 | case GTK_PAGE_ORIENTATION_PORTRAIT: 34 | return .portrait 35 | case GTK_PAGE_ORIENTATION_LANDSCAPE: 36 | return .landscape 37 | case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT: 38 | return .reversePortrait 39 | case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE: 40 | return .reverseLandscape 41 | default: 42 | fatalError("Unsupported GtkPageOrientation enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PageSet.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// See also gtk_print_job_set_page_set(). 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PageSet.html) 6 | public enum PageSet { 7 | /// All pages. 8 | case all 9 | /// Even pages. 10 | case even 11 | /// Odd pages. 12 | case odd 13 | 14 | func toGtkPageSet() -> GtkPageSet { 15 | switch self { 16 | case .all: 17 | return GTK_PAGE_SET_ALL 18 | case .even: 19 | return GTK_PAGE_SET_EVEN 20 | case .odd: 21 | return GTK_PAGE_SET_ODD 22 | } 23 | } 24 | } 25 | 26 | extension GtkPageSet { 27 | func toPageSet() -> PageSet { 28 | switch self { 29 | case GTK_PAGE_SET_ALL: 30 | return .all 31 | case GTK_PAGE_SET_EVEN: 32 | return .even 33 | case GTK_PAGE_SET_ODD: 34 | return .odd 35 | default: 36 | fatalError("Unsupported GtkPageSet enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PanDirection.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Describes the panning direction of a `GtkGesturePan`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PanDirection.html) 6 | public enum PanDirection { 7 | /// Panned towards the left. 8 | case left 9 | /// Panned towards the right. 10 | case right 11 | /// Panned upwards. 12 | case up 13 | /// Panned downwards. 14 | case down 15 | 16 | func toGtkPanDirection() -> GtkPanDirection { 17 | switch self { 18 | case .left: 19 | return GTK_PAN_DIRECTION_LEFT 20 | case .right: 21 | return GTK_PAN_DIRECTION_RIGHT 22 | case .up: 23 | return GTK_PAN_DIRECTION_UP 24 | case .down: 25 | return GTK_PAN_DIRECTION_DOWN 26 | } 27 | } 28 | } 29 | 30 | extension GtkPanDirection { 31 | func toPanDirection() -> PanDirection { 32 | switch self { 33 | case GTK_PAN_DIRECTION_LEFT: 34 | return .left 35 | case GTK_PAN_DIRECTION_RIGHT: 36 | return .right 37 | case GTK_PAN_DIRECTION_UP: 38 | return .up 39 | case GTK_PAN_DIRECTION_DOWN: 40 | return .down 41 | default: 42 | fatalError("Unsupported GtkPanDirection enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PolicyType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Determines how the size should be computed to achieve the one of the visibility mode for the scrollbars. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PolicyType.html) 6 | public enum PolicyType { 7 | /// The scrollbar is always visible. The view size is independent of the content. 8 | case always 9 | /// The scrollbar will appear and disappear as necessary. For example, when all of a `GtkTreeView` can not be seen. 10 | case automatic 11 | /// The scrollbar should never appear. In this mode the content determines the size. 12 | case never 13 | /// Don’t show a scrollbar, but don’t force the size to follow the content. This can be used e.g. to make multiple scrolled windows share a scrollbar. Since: 3.16. 14 | case external 15 | 16 | func toGtkPolicyType() -> GtkPolicyType { 17 | switch self { 18 | case .always: 19 | return GTK_POLICY_ALWAYS 20 | case .automatic: 21 | return GTK_POLICY_AUTOMATIC 22 | case .never: 23 | return GTK_POLICY_NEVER 24 | case .external: 25 | return GTK_POLICY_EXTERNAL 26 | } 27 | } 28 | } 29 | 30 | extension GtkPolicyType { 31 | func toPolicyType() -> PolicyType { 32 | switch self { 33 | case GTK_POLICY_ALWAYS: 34 | return .always 35 | case GTK_POLICY_AUTOMATIC: 36 | return .automatic 37 | case GTK_POLICY_NEVER: 38 | return .never 39 | case GTK_POLICY_EXTERNAL: 40 | return .external 41 | default: 42 | fatalError("Unsupported GtkPolicyType enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PopoverConstraint.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Describes constraints to positioning of popovers. More values may be added to this enumeration in the future. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PopoverConstraint.html) 6 | public enum PopoverConstraint { 7 | /// Don’t constrain the popover position beyond what is imposed by the implementation. 8 | case none 9 | /// Constrain the popover to the boundaries of the window that it is attached to. 10 | case window 11 | 12 | func toGtkPopoverConstraint() -> GtkPopoverConstraint { 13 | switch self { 14 | case .none: 15 | return GTK_POPOVER_CONSTRAINT_NONE 16 | case .window: 17 | return GTK_POPOVER_CONSTRAINT_WINDOW 18 | } 19 | } 20 | } 21 | 22 | extension GtkPopoverConstraint { 23 | func toPopoverConstraint() -> PopoverConstraint { 24 | switch self { 25 | case GTK_POPOVER_CONSTRAINT_NONE: 26 | return PopoverConstraint.none 27 | case GTK_POPOVER_CONSTRAINT_WINDOW: 28 | return .window 29 | default: 30 | fatalError("Unsupported GtkPopoverConstraint enum value: \(self.rawValue)") 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PositionType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Describes which edge of a widget a certain feature is positioned at, e.g. the tabs of a `GtkNotebook`, the handle of a `GtkHandleBox` or the label of a `GtkScale`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PositionType.html) 6 | public enum PositionType { 7 | /// The feature is at the left edge. 8 | case left 9 | /// The feature is at the right edge. 10 | case right 11 | /// The feature is at the top edge. 12 | case top 13 | /// The feature is at the bottom edge. 14 | case bottom 15 | 16 | func toGtkPositionType() -> GtkPositionType { 17 | switch self { 18 | case .left: 19 | return GTK_POS_LEFT 20 | case .right: 21 | return GTK_POS_RIGHT 22 | case .top: 23 | return GTK_POS_TOP 24 | case .bottom: 25 | return GTK_POS_BOTTOM 26 | } 27 | } 28 | } 29 | 30 | extension GtkPositionType { 31 | func toPositionType() -> PositionType { 32 | switch self { 33 | case GTK_POS_LEFT: 34 | return .left 35 | case GTK_POS_RIGHT: 36 | return .right 37 | case GTK_POS_TOP: 38 | return .top 39 | case GTK_POS_BOTTOM: 40 | return .bottom 41 | default: 42 | fatalError("Unsupported GtkPositionType enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PrintDuplex.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// See also gtk_print_settings_set_duplex(). 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PrintDuplex.html) 6 | public enum PrintDuplex { 7 | /// No duplex. 8 | case simplex 9 | /// Horizontal duplex. 10 | case horizontal 11 | /// Vertical duplex. 12 | case vertical 13 | 14 | func toGtkPrintDuplex() -> GtkPrintDuplex { 15 | switch self { 16 | case .simplex: 17 | return GTK_PRINT_DUPLEX_SIMPLEX 18 | case .horizontal: 19 | return GTK_PRINT_DUPLEX_HORIZONTAL 20 | case .vertical: 21 | return GTK_PRINT_DUPLEX_VERTICAL 22 | } 23 | } 24 | } 25 | 26 | extension GtkPrintDuplex { 27 | func toPrintDuplex() -> PrintDuplex { 28 | switch self { 29 | case GTK_PRINT_DUPLEX_SIMPLEX: 30 | return .simplex 31 | case GTK_PRINT_DUPLEX_HORIZONTAL: 32 | return .horizontal 33 | case GTK_PRINT_DUPLEX_VERTICAL: 34 | return .vertical 35 | default: 36 | fatalError("Unsupported GtkPrintDuplex enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PrintOperationAction.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// The action parameter to `gtk_print_operation_run()` determines what action the print operation should perform. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PrintOperationAction.html) 6 | public enum PrintOperationAction { 7 | /// Show the print dialog. 8 | case printDialog 9 | /// Start to print without showing the print dialog, based on the current print settings. 10 | case print 11 | /// Show the print preview. 12 | case preview 13 | /// Export to a file. This requires the export-filename property to be set. 14 | case export 15 | 16 | func toGtkPrintOperationAction() -> GtkPrintOperationAction { 17 | switch self { 18 | case .printDialog: 19 | return GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG 20 | case .print: 21 | return GTK_PRINT_OPERATION_ACTION_PRINT 22 | case .preview: 23 | return GTK_PRINT_OPERATION_ACTION_PREVIEW 24 | case .export: 25 | return GTK_PRINT_OPERATION_ACTION_EXPORT 26 | } 27 | } 28 | } 29 | 30 | extension GtkPrintOperationAction { 31 | func toPrintOperationAction() -> PrintOperationAction { 32 | switch self { 33 | case GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG: 34 | return .printDialog 35 | case GTK_PRINT_OPERATION_ACTION_PRINT: 36 | return .print 37 | case GTK_PRINT_OPERATION_ACTION_PREVIEW: 38 | return .preview 39 | case GTK_PRINT_OPERATION_ACTION_EXPORT: 40 | return .export 41 | default: 42 | fatalError("Unsupported GtkPrintOperationAction enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PrintOperationResult.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// A value of this type is returned by gtk_print_operation_run(). 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PrintOperationResult.html) 6 | public enum PrintOperationResult { 7 | /// An error has occurred. 8 | case error 9 | /// The print settings should be stored. 10 | case apply 11 | /// The print operation has been canceled, the print settings should not be stored. 12 | case cancel 13 | /// The print operation is not complete yet. This value will only be returned when running asynchronously. 14 | case inProgress 15 | 16 | func toGtkPrintOperationResult() -> GtkPrintOperationResult { 17 | switch self { 18 | case .error: 19 | return GTK_PRINT_OPERATION_RESULT_ERROR 20 | case .apply: 21 | return GTK_PRINT_OPERATION_RESULT_APPLY 22 | case .cancel: 23 | return GTK_PRINT_OPERATION_RESULT_CANCEL 24 | case .inProgress: 25 | return GTK_PRINT_OPERATION_RESULT_IN_PROGRESS 26 | } 27 | } 28 | } 29 | 30 | extension GtkPrintOperationResult { 31 | func toPrintOperationResult() -> PrintOperationResult { 32 | switch self { 33 | case GTK_PRINT_OPERATION_RESULT_ERROR: 34 | return .error 35 | case GTK_PRINT_OPERATION_RESULT_APPLY: 36 | return .apply 37 | case GTK_PRINT_OPERATION_RESULT_CANCEL: 38 | return .cancel 39 | case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS: 40 | return .inProgress 41 | default: 42 | fatalError("Unsupported GtkPrintOperationResult enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PrintPages.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// See also `gtk_print_job_set_pages()` 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PrintPages.html) 6 | public enum PrintPages { 7 | /// All pages. 8 | case all 9 | /// Current page. 10 | case current 11 | /// Range of pages. 12 | case ranges 13 | /// Selected pages. 14 | case selection 15 | 16 | func toGtkPrintPages() -> GtkPrintPages { 17 | switch self { 18 | case .all: 19 | return GTK_PRINT_PAGES_ALL 20 | case .current: 21 | return GTK_PRINT_PAGES_CURRENT 22 | case .ranges: 23 | return GTK_PRINT_PAGES_RANGES 24 | case .selection: 25 | return GTK_PRINT_PAGES_SELECTION 26 | } 27 | } 28 | } 29 | 30 | extension GtkPrintPages { 31 | func toPrintPages() -> PrintPages { 32 | switch self { 33 | case GTK_PRINT_PAGES_ALL: 34 | return .all 35 | case GTK_PRINT_PAGES_CURRENT: 36 | return .current 37 | case GTK_PRINT_PAGES_RANGES: 38 | return .ranges 39 | case GTK_PRINT_PAGES_SELECTION: 40 | return .selection 41 | default: 42 | fatalError("Unsupported GtkPrintPages enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PrintQuality.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// See also `gtk_print_settings_set_quality()`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PrintQuality.html) 6 | public enum PrintQuality { 7 | /// Low quality. 8 | case low 9 | /// Normal quality. 10 | case normal 11 | /// High quality. 12 | case high 13 | /// Draft quality. 14 | case draft 15 | 16 | func toGtkPrintQuality() -> GtkPrintQuality { 17 | switch self { 18 | case .low: 19 | return GTK_PRINT_QUALITY_LOW 20 | case .normal: 21 | return GTK_PRINT_QUALITY_NORMAL 22 | case .high: 23 | return GTK_PRINT_QUALITY_HIGH 24 | case .draft: 25 | return GTK_PRINT_QUALITY_DRAFT 26 | } 27 | } 28 | } 29 | 30 | extension GtkPrintQuality { 31 | func toPrintQuality() -> PrintQuality { 32 | switch self { 33 | case GTK_PRINT_QUALITY_LOW: 34 | return .low 35 | case GTK_PRINT_QUALITY_NORMAL: 36 | return .normal 37 | case GTK_PRINT_QUALITY_HIGH: 38 | return .high 39 | case GTK_PRINT_QUALITY_DRAFT: 40 | return .draft 41 | default: 42 | fatalError("Unsupported GtkPrintQuality enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PrintStatus.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// The status gives a rough indication of the completion of a running print operation. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PrintStatus.html) 6 | public enum PrintStatus { 7 | /// The printing has not started yet; this status is set initially, and while the print dialog is shown. 8 | case initial 9 | /// This status is set while the begin-print signal is emitted and during pagination. 10 | case preparing 11 | /// This status is set while the pages are being rendered. 12 | case generatingData 13 | /// The print job is being sent off to the printer. 14 | case sendingData 15 | /// The print job has been sent to the printer, but is not printed for some reason, e.g. the printer may be stopped. 16 | case pending 17 | /// Some problem has occurred during printing, e.g. a paper jam. 18 | case pendingIssue 19 | /// The printer is processing the print job. 20 | case printing 21 | /// The printing has been completed successfully. 22 | case finished 23 | /// The printing has been aborted. 24 | case finishedAborted 25 | 26 | func toGtkPrintStatus() -> GtkPrintStatus { 27 | switch self { 28 | case .initial: 29 | return GTK_PRINT_STATUS_INITIAL 30 | case .preparing: 31 | return GTK_PRINT_STATUS_PREPARING 32 | case .generatingData: 33 | return GTK_PRINT_STATUS_GENERATING_DATA 34 | case .sendingData: 35 | return GTK_PRINT_STATUS_SENDING_DATA 36 | case .pending: 37 | return GTK_PRINT_STATUS_PENDING 38 | case .pendingIssue: 39 | return GTK_PRINT_STATUS_PENDING_ISSUE 40 | case .printing: 41 | return GTK_PRINT_STATUS_PRINTING 42 | case .finished: 43 | return GTK_PRINT_STATUS_FINISHED 44 | case .finishedAborted: 45 | return GTK_PRINT_STATUS_FINISHED_ABORTED 46 | } 47 | } 48 | } 49 | 50 | extension GtkPrintStatus { 51 | func toPrintStatus() -> PrintStatus { 52 | switch self { 53 | case GTK_PRINT_STATUS_INITIAL: 54 | return .initial 55 | case GTK_PRINT_STATUS_PREPARING: 56 | return .preparing 57 | case GTK_PRINT_STATUS_GENERATING_DATA: 58 | return .generatingData 59 | case GTK_PRINT_STATUS_SENDING_DATA: 60 | return .sendingData 61 | case GTK_PRINT_STATUS_PENDING: 62 | return .pending 63 | case GTK_PRINT_STATUS_PENDING_ISSUE: 64 | return .pendingIssue 65 | case GTK_PRINT_STATUS_PRINTING: 66 | return .printing 67 | case GTK_PRINT_STATUS_FINISHED: 68 | return .finished 69 | case GTK_PRINT_STATUS_FINISHED_ABORTED: 70 | return .finishedAborted 71 | default: 72 | fatalError("Unsupported GtkPrintStatus enum value: \(self.rawValue)") 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/PropagationPhase.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Describes the stage at which events are fed into a `GtkEventController`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.PropagationPhase.html) 6 | public enum PropagationPhase { 7 | /// Events are not delivered automatically. Those can be manually fed through gtk_event_controller_handle_event(). This should only be used when full control about when, or whether the controller handles the event is needed. 8 | case none 9 | /// Events are delivered in the capture phase. The capture phase happens before the bubble phase, runs from the toplevel down to the event widget. This option should only be used on containers that might possibly handle events before their children do. 10 | case capture 11 | /// Events are delivered in the bubble phase. The bubble phase happens after the capture phase, and before the default handlers are run. This phase runs from the event widget, up to the toplevel. 12 | case bubble 13 | /// Events are delivered in the default widget event handlers, note that widget implementations must chain up on button, motion, touch and grab broken handlers for controllers in this phase to be run. 14 | case target 15 | 16 | func toGtkPropagationPhase() -> GtkPropagationPhase { 17 | switch self { 18 | case .none: 19 | return GTK_PHASE_NONE 20 | case .capture: 21 | return GTK_PHASE_CAPTURE 22 | case .bubble: 23 | return GTK_PHASE_BUBBLE 24 | case .target: 25 | return GTK_PHASE_TARGET 26 | } 27 | } 28 | } 29 | 30 | extension GtkPropagationPhase { 31 | func toPropagationPhase() -> PropagationPhase { 32 | switch self { 33 | case GTK_PHASE_NONE: 34 | return PropagationPhase.none 35 | case GTK_PHASE_CAPTURE: 36 | return .capture 37 | case GTK_PHASE_BUBBLE: 38 | return .bubble 39 | case GTK_PHASE_TARGET: 40 | return .target 41 | default: 42 | fatalError("Unsupported GtkPropagationPhase enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/RecentSortType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to specify the sorting method to be applyed to the recently used resource list. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.RecentSortType.html) 6 | public enum RecentSortType { 7 | /// Do not sort the returned list of recently used resources. 8 | case none 9 | /// Sort the returned list with the most recently used items first. 10 | case mostRecentlyUsed 11 | /// Sort the returned list with the least recently used items first. 12 | case leastRecentlyUsed 13 | /// Sort the returned list using a custom sorting function passed using `gtk_recent_chooser_set_sort_func()`. 14 | case custom 15 | 16 | func toGtkRecentSortType() -> GtkRecentSortType { 17 | switch self { 18 | case .none: 19 | return GTK_RECENT_SORT_NONE 20 | case .mostRecentlyUsed: 21 | return GTK_RECENT_SORT_MRU 22 | case .leastRecentlyUsed: 23 | return GTK_RECENT_SORT_LRU 24 | case .custom: 25 | return GTK_RECENT_SORT_CUSTOM 26 | } 27 | } 28 | } 29 | 30 | extension GtkRecentSortType { 31 | func toRecentSortType() -> RecentSortType { 32 | switch self { 33 | case GTK_RECENT_SORT_NONE: 34 | return RecentSortType.none 35 | case GTK_RECENT_SORT_MRU: 36 | return .mostRecentlyUsed 37 | case GTK_RECENT_SORT_LRU: 38 | return .leastRecentlyUsed 39 | case GTK_RECENT_SORT_CUSTOM: 40 | return .custom 41 | default: 42 | fatalError("Unsupported GtkRecentSortType enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ReliefStyle.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Indicated the relief to be drawn around a `GtkButton`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ReliefStyle.html) 6 | public enum ReliefStyle { 7 | /// Draw a normal relief. 8 | case normal 9 | /// A half relief. Deprecated in 3.14, does the same as GTK_RELIEF_NORMAL. 10 | case half 11 | /// No relief. 12 | case none 13 | 14 | func toGtkReliefStyle() -> GtkReliefStyle { 15 | switch self { 16 | case .normal: 17 | return GTK_RELIEF_NORMAL 18 | case .half: 19 | return GTK_RELIEF_HALF 20 | case .none: 21 | return GTK_RELIEF_NONE 22 | } 23 | } 24 | } 25 | 26 | extension GtkReliefStyle { 27 | func toReliefStyle() -> ReliefStyle { 28 | switch self { 29 | case GTK_RELIEF_NORMAL: 30 | return .normal 31 | case GTK_RELIEF_HALF: 32 | return .half 33 | case GTK_RELIEF_NONE: 34 | return ReliefStyle.none 35 | default: 36 | fatalError("Unsupported GtkReliefStyle enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ResizeMode.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ResizeMode.html) 4 | public enum ResizeMode { 5 | /// Pass resize request to the parent. 6 | case parent 7 | /// Queue resizes on this widget. 8 | case queue 9 | /// Resize immediately. Deprecated. 10 | case immediate 11 | 12 | func toGtkResizeMode() -> GtkResizeMode { 13 | switch self { 14 | case .parent: 15 | return GTK_RESIZE_PARENT 16 | case .queue: 17 | return GTK_RESIZE_QUEUE 18 | case .immediate: 19 | return GTK_RESIZE_IMMEDIATE 20 | } 21 | } 22 | } 23 | 24 | extension GtkResizeMode { 25 | func toResizeMode() -> ResizeMode { 26 | switch self { 27 | case GTK_RESIZE_PARENT: 28 | return .parent 29 | case GTK_RESIZE_QUEUE: 30 | return .queue 31 | case GTK_RESIZE_IMMEDIATE: 32 | return .immediate 33 | default: 34 | fatalError("Unsupported GtkResizeMode enum value: \(self.rawValue)") 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ResponseType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Predefined values for use as response ids in `gtk_dialog_add_button()`. All predefined values are negative; GTK+ leaves values of 0 or greater for application-defined response ids. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ResponseType.html) 6 | public enum ResponseType { 7 | /// Returned if an action widget has no response id, or if the dialog gets programmatically hidden or destroyed. 8 | case none 9 | /// Generic response id, not used by GTK+ dialogs. 10 | case reject 11 | /// Generic response id, not used by GTK+ dialogs. 12 | case accept 13 | /// Returned if the dialog is deleted. 14 | case deleteEvent 15 | /// Returned by OK buttons in GTK+ dialogs. 16 | case ok 17 | /// Returned by Cancel buttons in GTK+ dialogs. 18 | case cancel 19 | /// Returned by Close buttons in GTK+ dialogs. 20 | case close 21 | /// Returned by Yes buttons in GTK+ dialogs. 22 | case yes 23 | /// Returned by No buttons in GTK+ dialogs. 24 | case no 25 | /// Returned by Apply buttons in GTK+ dialogs. 26 | case apply 27 | /// Returned by Help buttons in GTK+ dialogs. 28 | case help 29 | 30 | func toGtkResponseType() -> GtkResponseType { 31 | switch self { 32 | case .none: 33 | return GTK_RESPONSE_NONE 34 | case .reject: 35 | return GTK_RESPONSE_REJECT 36 | case .accept: 37 | return GTK_RESPONSE_ACCEPT 38 | case .deleteEvent: 39 | return GTK_RESPONSE_DELETE_EVENT 40 | case .ok: 41 | return GTK_RESPONSE_OK 42 | case .cancel: 43 | return GTK_RESPONSE_CANCEL 44 | case .close: 45 | return GTK_RESPONSE_CLOSE 46 | case .yes: 47 | return GTK_RESPONSE_YES 48 | case .no: 49 | return GTK_RESPONSE_NO 50 | case .apply: 51 | return GTK_RESPONSE_APPLY 52 | case .help: 53 | return GTK_RESPONSE_HELP 54 | } 55 | } 56 | } 57 | 58 | extension GtkResponseType { 59 | func toResponseType() -> ResponseType { 60 | switch self { 61 | case GTK_RESPONSE_NONE: 62 | return ResponseType.none 63 | case GTK_RESPONSE_REJECT: 64 | return .reject 65 | case GTK_RESPONSE_ACCEPT: 66 | return .accept 67 | case GTK_RESPONSE_DELETE_EVENT: 68 | return .deleteEvent 69 | case GTK_RESPONSE_OK: 70 | return .ok 71 | case GTK_RESPONSE_CANCEL: 72 | return .cancel 73 | case GTK_RESPONSE_CLOSE: 74 | return .close 75 | case GTK_RESPONSE_YES: 76 | return .yes 77 | case GTK_RESPONSE_NO: 78 | return .no 79 | case GTK_RESPONSE_APPLY: 80 | return .apply 81 | case GTK_RESPONSE_HELP: 82 | return .help 83 | default: 84 | fatalError("Unsupported GtkResponseType enum value: \(self.rawValue)") 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/RevealerTransitionType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// These enumeration values describe the possible transitions when the child of a GtkRevealer widget is shown or hidden. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.RevealerTransitionType.html) 6 | public enum RevealerTransitionType { 7 | /// No transition. 8 | case none 9 | /// Fade in. 10 | case crossFade 11 | /// Slide in from the left. 12 | case slideRight 13 | /// Slide in from the right. 14 | case slideLeft 15 | /// Slide in from the bottom. 16 | case slideUp 17 | /// Slide in from the top. 18 | case slideDown 19 | 20 | func toGtkRevealerTransitionType() -> GtkRevealerTransitionType { 21 | switch self { 22 | case .none: 23 | return GTK_REVEALER_TRANSITION_TYPE_NONE 24 | case .crossFade: 25 | return GTK_REVEALER_TRANSITION_TYPE_CROSSFADE 26 | case .slideRight: 27 | return GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT 28 | case .slideLeft: 29 | return GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT 30 | case .slideUp: 31 | return GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP 32 | case .slideDown: 33 | return GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN 34 | } 35 | } 36 | } 37 | 38 | extension GtkRevealerTransitionType { 39 | func toRevealerTransitionType() -> RevealerTransitionType { 40 | switch self { 41 | case GTK_REVEALER_TRANSITION_TYPE_NONE: 42 | return RevealerTransitionType.none 43 | case GTK_REVEALER_TRANSITION_TYPE_CROSSFADE: 44 | return .crossFade 45 | case GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT: 46 | return .slideRight 47 | case GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT: 48 | return .slideLeft 49 | case GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP: 50 | return .slideUp 51 | case GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN: 52 | return .slideDown 53 | default: 54 | fatalError("Unsupported GtkRevealerTransitionType enum value: \(self.rawValue)") 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ScrollStep.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ScrollStep.html) 4 | public enum ScrollStep { 5 | /// Scroll in steps. 6 | case steps 7 | /// Scroll by pages. 8 | case pages 9 | /// Scroll to ends. 10 | case ends 11 | /// Scroll in horizontal steps. 12 | case horizontalSteps 13 | /// Scroll by horizontal pages. 14 | case horizontalPages 15 | /// Scroll to the horizontal ends. 16 | case horizontalEnds 17 | 18 | func toGtkScrollStep() -> GtkScrollStep { 19 | switch self { 20 | case .steps: 21 | return GTK_SCROLL_STEPS 22 | case .pages: 23 | return GTK_SCROLL_PAGES 24 | case .ends: 25 | return GTK_SCROLL_ENDS 26 | case .horizontalSteps: 27 | return GTK_SCROLL_HORIZONTAL_STEPS 28 | case .horizontalPages: 29 | return GTK_SCROLL_HORIZONTAL_PAGES 30 | case .horizontalEnds: 31 | return GTK_SCROLL_HORIZONTAL_ENDS 32 | } 33 | } 34 | } 35 | 36 | extension GtkScrollStep { 37 | func toScrollStep() -> ScrollStep { 38 | switch self { 39 | case GTK_SCROLL_STEPS: 40 | return .steps 41 | case GTK_SCROLL_PAGES: 42 | return .pages 43 | case GTK_SCROLL_ENDS: 44 | return .ends 45 | case GTK_SCROLL_HORIZONTAL_STEPS: 46 | return .horizontalSteps 47 | case GTK_SCROLL_HORIZONTAL_PAGES: 48 | return .horizontalPages 49 | case GTK_SCROLL_HORIZONTAL_ENDS: 50 | return .horizontalEnds 51 | default: 52 | fatalError("Unsupported GtkScrollStep enum value: \(self.rawValue)") 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ScrollType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Scrolling types. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ScrollType.html) 6 | public enum ScrollType { 7 | /// No scrolling. 8 | case none 9 | /// Jump to new location. 10 | case jump 11 | /// Step backward. 12 | case stepBackward 13 | /// Step forward. 14 | case stepForward 15 | /// Page backward. 16 | case pageBackward 17 | /// Page forward. 18 | case pageForward 19 | /// Step up. 20 | case stepUp 21 | /// Step down. 22 | case stepDown 23 | /// Page up. 24 | case pageUp 25 | /// Page down. 26 | case pageDown 27 | /// Step to the left. 28 | case stepLeft 29 | /// Step to the right. 30 | case stepRight 31 | /// Page to the left. 32 | case pageLeft 33 | /// Page to the right. 34 | case pageRight 35 | /// Scroll to start. 36 | case start 37 | /// Scroll to end. 38 | case end 39 | 40 | func toGtkScrollType() -> GtkScrollType { 41 | switch self { 42 | case .none: 43 | return GTK_SCROLL_NONE 44 | case .jump: 45 | return GTK_SCROLL_JUMP 46 | case .stepBackward: 47 | return GTK_SCROLL_STEP_BACKWARD 48 | case .stepForward: 49 | return GTK_SCROLL_STEP_FORWARD 50 | case .pageBackward: 51 | return GTK_SCROLL_PAGE_BACKWARD 52 | case .pageForward: 53 | return GTK_SCROLL_PAGE_FORWARD 54 | case .stepUp: 55 | return GTK_SCROLL_STEP_UP 56 | case .stepDown: 57 | return GTK_SCROLL_STEP_DOWN 58 | case .pageUp: 59 | return GTK_SCROLL_PAGE_UP 60 | case .pageDown: 61 | return GTK_SCROLL_PAGE_DOWN 62 | case .stepLeft: 63 | return GTK_SCROLL_STEP_LEFT 64 | case .stepRight: 65 | return GTK_SCROLL_STEP_RIGHT 66 | case .pageLeft: 67 | return GTK_SCROLL_PAGE_LEFT 68 | case .pageRight: 69 | return GTK_SCROLL_PAGE_RIGHT 70 | case .start: 71 | return GTK_SCROLL_START 72 | case .end: 73 | return GTK_SCROLL_END 74 | } 75 | } 76 | } 77 | 78 | extension GtkScrollType { 79 | func toScrollType() -> ScrollType { 80 | switch self { 81 | case GTK_SCROLL_NONE: 82 | return ScrollType.none 83 | case GTK_SCROLL_JUMP: 84 | return .jump 85 | case GTK_SCROLL_STEP_BACKWARD: 86 | return .stepBackward 87 | case GTK_SCROLL_STEP_FORWARD: 88 | return .stepForward 89 | case GTK_SCROLL_PAGE_BACKWARD: 90 | return .pageBackward 91 | case GTK_SCROLL_PAGE_FORWARD: 92 | return .pageForward 93 | case GTK_SCROLL_STEP_UP: 94 | return .stepUp 95 | case GTK_SCROLL_STEP_DOWN: 96 | return .stepDown 97 | case GTK_SCROLL_PAGE_UP: 98 | return .pageUp 99 | case GTK_SCROLL_PAGE_DOWN: 100 | return .pageDown 101 | case GTK_SCROLL_STEP_LEFT: 102 | return .stepLeft 103 | case GTK_SCROLL_STEP_RIGHT: 104 | return .stepRight 105 | case GTK_SCROLL_PAGE_LEFT: 106 | return .pageLeft 107 | case GTK_SCROLL_PAGE_RIGHT: 108 | return .pageRight 109 | case GTK_SCROLL_START: 110 | return .start 111 | case GTK_SCROLL_END: 112 | return .end 113 | default: 114 | fatalError("Unsupported GtkScrollType enum value: \(self.rawValue)") 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ScrollablePolicy.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Defines the policy to be used in a scrollable widget when updating the scrolled window adjustments in a given orientation. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ScrollablePolicy.html) 6 | public enum ScrollablePolicy { 7 | /// Scrollable adjustments are based on the minimum size. 8 | case minimum 9 | /// Scrollable adjustments are based on the natural size. 10 | case natural 11 | 12 | func toGtkScrollablePolicy() -> GtkScrollablePolicy { 13 | switch self { 14 | case .minimum: 15 | return GTK_SCROLL_MINIMUM 16 | case .natural: 17 | return GTK_SCROLL_NATURAL 18 | } 19 | } 20 | } 21 | 22 | extension GtkScrollablePolicy { 23 | func toScrollablePolicy() -> ScrollablePolicy { 24 | switch self { 25 | case GTK_SCROLL_MINIMUM: 26 | return .minimum 27 | case GTK_SCROLL_NATURAL: 28 | return .natural 29 | default: 30 | fatalError("Unsupported GtkScrollablePolicy enum value: \(self.rawValue)") 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/SelectionMode.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to control what selections users are allowed to make. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.SelectionMode.html) 6 | public enum SelectionMode { 7 | /// No selection is possible. 8 | case none 9 | /// Zero or one element may be selected. 10 | case single 11 | /// Exactly one element is selected. In some circumstances, such as initially or during a search operation, it’s possible for no element to be selected with GTK_SELECTION_BROWSE. What is really enforced is that the user can’t deselect a currently selected element except by selecting another element. 12 | case browse 13 | /// Any number of elements may be selected. The Ctrl key may be used to enlarge the selection, and Shift key to select between the focus and the child pointed to. Some widgets may also allow Click-drag to select a range of elements. 14 | case multiple 15 | 16 | func toGtkSelectionMode() -> GtkSelectionMode { 17 | switch self { 18 | case .none: 19 | return GTK_SELECTION_NONE 20 | case .single: 21 | return GTK_SELECTION_SINGLE 22 | case .browse: 23 | return GTK_SELECTION_BROWSE 24 | case .multiple: 25 | return GTK_SELECTION_MULTIPLE 26 | } 27 | } 28 | } 29 | 30 | extension GtkSelectionMode { 31 | func toSelectionMode() -> SelectionMode { 32 | switch self { 33 | case GTK_SELECTION_NONE: 34 | return SelectionMode.none 35 | case GTK_SELECTION_SINGLE: 36 | return .single 37 | case GTK_SELECTION_BROWSE: 38 | return .browse 39 | case GTK_SELECTION_MULTIPLE: 40 | return .multiple 41 | default: 42 | fatalError("Unsupported GtkSelectionMode enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/SensitivityType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Determines how GTK+ handles the sensitivity of stepper arrows at the end of range widgets. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.SensitivityType.html) 6 | public enum SensitivityType { 7 | /// The arrow is made insensitive if the thumb is at the end. 8 | case auto 9 | /// The arrow is always sensitive. 10 | case on 11 | /// The arrow is always insensitive. 12 | case off 13 | 14 | func toGtkSensitivityType() -> GtkSensitivityType { 15 | switch self { 16 | case .auto: 17 | return GTK_SENSITIVITY_AUTO 18 | case .on: 19 | return GTK_SENSITIVITY_ON 20 | case .off: 21 | return GTK_SENSITIVITY_OFF 22 | } 23 | } 24 | } 25 | 26 | extension GtkSensitivityType { 27 | func toSensitivityType() -> SensitivityType { 28 | switch self { 29 | case GTK_SENSITIVITY_AUTO: 30 | return .auto 31 | case GTK_SENSITIVITY_ON: 32 | return .on 33 | case GTK_SENSITIVITY_OFF: 34 | return .off 35 | default: 36 | fatalError("Unsupported GtkSensitivityType enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ShadowType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to change the appearance of an outline typically provided by a `GtkFrame`. 4 | /// 5 | /// Note that many themes do not differentiate the appearance of the various shadow types: Either their is no visible shadow (`GTK_SHADOW_NONE`), or there is (any other value). 6 | /// 7 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ShadowType.html) 8 | public enum ShadowType { 9 | /// No outline. 10 | case none 11 | /// The outline is bevelled inwards. 12 | case `in` 13 | /// The outline is bevelled outwards like a button. 14 | case out 15 | /// The outline has a sunken 3d appearance. 16 | case etchedIn 17 | /// The outline has a raised 3d appearance. 18 | case etchedOut 19 | 20 | func toGtkShadowType() -> GtkShadowType { 21 | switch self { 22 | case .none: 23 | return GTK_SHADOW_NONE 24 | case .in: 25 | return GTK_SHADOW_IN 26 | case .out: 27 | return GTK_SHADOW_OUT 28 | case .etchedIn: 29 | return GTK_SHADOW_ETCHED_IN 30 | case .etchedOut: 31 | return GTK_SHADOW_ETCHED_OUT 32 | } 33 | } 34 | } 35 | 36 | extension GtkShadowType { 37 | func toShadowType() -> ShadowType { 38 | switch self { 39 | case GTK_SHADOW_NONE: 40 | return ShadowType.none 41 | case GTK_SHADOW_IN: 42 | return .in 43 | case GTK_SHADOW_OUT: 44 | return .out 45 | case GTK_SHADOW_ETCHED_IN: 46 | return .etchedIn 47 | case GTK_SHADOW_ETCHED_OUT: 48 | return .etchedOut 49 | default: 50 | fatalError("Unsupported GtkShadowType enum value: \(self.rawValue)") 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ShortcutType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// GtkShortcutType specifies the kind of shortcut that is being described. More values may be added to this enumeration over time. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ShortcutType.html) 6 | public enum ShortcutType { 7 | /// The shortcut is a keyboard accelerator. The `GtkShortcutsShortcut:accelerator` property will be used. 8 | case accelerator 9 | /// The shortcut is a pinch gesture. GTK+ provides an icon and subtitle. 10 | case gesturePinch 11 | /// The shortcut is a stretch gesture. GTK+ provides an icon and subtitle. 12 | case gestureStretch 13 | /// The shortcut is a clockwise rotation gesture. GTK+ provides an icon and subtitle. 14 | case gestureRotateClockwise 15 | /// The shortcut is a counterclockwise rotation gesture. GTK+ provides an icon and subtitle. 16 | case gestureRotateCounterClockwise 17 | /// The shortcut is a two-finger swipe gesture. GTK+ provides an icon and subtitle. 18 | case gestureTwoFingerSwipeLeft 19 | /// The shortcut is a two-finger swipe gesture. GTK+ provides an icon and subtitle. 20 | case gestureTwoFingerSwipeRight 21 | /// The shortcut is a gesture. The GtkShortcutsShortcut:icon property will be used. 22 | case gesture 23 | 24 | func toGtkShortcutType() -> GtkShortcutType { 25 | switch self { 26 | case .accelerator: 27 | return GTK_SHORTCUT_ACCELERATOR 28 | case .gesturePinch: 29 | return GTK_SHORTCUT_GESTURE_PINCH 30 | case .gestureStretch: 31 | return GTK_SHORTCUT_GESTURE_STRETCH 32 | case .gestureRotateClockwise: 33 | return GTK_SHORTCUT_GESTURE_ROTATE_CLOCKWISE 34 | case .gestureRotateCounterClockwise: 35 | return GTK_SHORTCUT_GESTURE_ROTATE_COUNTERCLOCKWISE 36 | case .gestureTwoFingerSwipeLeft: 37 | return GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_LEFT 38 | case .gestureTwoFingerSwipeRight: 39 | return GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_RIGHT 40 | case .gesture: 41 | return GTK_SHORTCUT_GESTURE 42 | } 43 | } 44 | } 45 | 46 | extension GtkShortcutType { 47 | func toShortcutType() -> ShortcutType { 48 | switch self { 49 | case GTK_SHORTCUT_ACCELERATOR: 50 | return .accelerator 51 | case GTK_SHORTCUT_GESTURE_PINCH: 52 | return .gesturePinch 53 | case GTK_SHORTCUT_GESTURE_STRETCH: 54 | return .gestureStretch 55 | case GTK_SHORTCUT_GESTURE_ROTATE_CLOCKWISE: 56 | return .gestureRotateClockwise 57 | case GTK_SHORTCUT_GESTURE_ROTATE_COUNTERCLOCKWISE: 58 | return .gestureRotateCounterClockwise 59 | case GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_LEFT: 60 | return .gestureTwoFingerSwipeLeft 61 | case GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_RIGHT: 62 | return .gestureTwoFingerSwipeRight 63 | case GTK_SHORTCUT_GESTURE: 64 | return .gesture 65 | default: 66 | fatalError("Unsupported GtkShortcutType enum value: \(self.rawValue)") 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/SizeGroupMode.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// The mode of the size group determines the directions in which the size group affects the requested sizes of its component widgets. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.SizeGroupMode.html) 6 | public enum SizeGroupMode { 7 | /// Group has no effect. 8 | case none 9 | /// Group affects horizontal requisition. 10 | case horizontal 11 | /// Group affects vertical requisition. 12 | case vertical 13 | /// Group affects both horizontal and vertical requisition. 14 | case both 15 | 16 | func toGtkSizeGroupMode() -> GtkSizeGroupMode { 17 | switch self { 18 | case .none: 19 | return GTK_SIZE_GROUP_NONE 20 | case .horizontal: 21 | return GTK_SIZE_GROUP_HORIZONTAL 22 | case .vertical: 23 | return GTK_SIZE_GROUP_VERTICAL 24 | case .both: 25 | return GTK_SIZE_GROUP_BOTH 26 | } 27 | } 28 | } 29 | 30 | extension GtkSizeGroupMode { 31 | func toSizeGroupMode() -> SizeGroupMode { 32 | switch self { 33 | case GTK_SIZE_GROUP_NONE: 34 | return SizeGroupMode.none 35 | case GTK_SIZE_GROUP_HORIZONTAL: 36 | return .horizontal 37 | case GTK_SIZE_GROUP_VERTICAL: 38 | return .vertical 39 | case GTK_SIZE_GROUP_BOTH: 40 | return .both 41 | default: 42 | fatalError("Unsupported GtkSizeGroupMode enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/SizeRequestMode.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Specifies a preference for height-for-width or width-for-height geometry management. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.SizeRequestMode.html) 6 | public enum SizeRequestMode { 7 | /// Prefer height-for-width geometry management. 8 | case heightForWidth 9 | /// Prefer width-for-height geometry management. 10 | case widthForHeight 11 | /// Don’t trade height-for-width or width-for-height. 12 | case constantSize 13 | 14 | func toGtkSizeRequestMode() -> GtkSizeRequestMode { 15 | switch self { 16 | case .heightForWidth: 17 | return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH 18 | case .widthForHeight: 19 | return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT 20 | case .constantSize: 21 | return GTK_SIZE_REQUEST_CONSTANT_SIZE 22 | } 23 | } 24 | } 25 | 26 | extension GtkSizeRequestMode { 27 | func toSizeRequestMode() -> SizeRequestMode { 28 | switch self { 29 | case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH: 30 | return .heightForWidth 31 | case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT: 32 | return .widthForHeight 33 | case GTK_SIZE_REQUEST_CONSTANT_SIZE: 34 | return .constantSize 35 | default: 36 | fatalError("Unsupported GtkSizeRequestMode enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/SortType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Determines the direction of a sort. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.SortType.html) 6 | public enum SortType { 7 | /// Sorting is in ascending order. 8 | case ascending 9 | /// Sorting is in descending order. 10 | case descending 11 | 12 | func toGtkSortType() -> GtkSortType { 13 | switch self { 14 | case .ascending: 15 | return GTK_SORT_ASCENDING 16 | case .descending: 17 | return GTK_SORT_DESCENDING 18 | } 19 | } 20 | } 21 | 22 | extension GtkSortType { 23 | func toSortType() -> SortType { 24 | switch self { 25 | case GTK_SORT_ASCENDING: 26 | return .ascending 27 | case GTK_SORT_DESCENDING: 28 | return .descending 29 | default: 30 | fatalError("Unsupported GtkSortType enum value: \(self.rawValue)") 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/SpinButtonUpdatePolicy.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// The spin button update policy determines whether the spin button displays values even if they are outside the bounds of its adjustment. See `gtk_spin_button_set_update_policy()`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.SpinButtonUpdatePolicy.html) 6 | public enum SpinButtonUpdatePolicy { 7 | /// When refreshing your GtkSpinButton, the value is always displayed. 8 | case always 9 | /// When refreshing your GtkSpinButton, the value is only displayed if it is valid within the bounds of the spin button’s adjustment. 10 | case ifValid 11 | 12 | func toGtkSpinButtonUpdatePolicy() -> GtkSpinButtonUpdatePolicy { 13 | switch self { 14 | case .always: 15 | return GTK_UPDATE_ALWAYS 16 | case .ifValid: 17 | return GTK_UPDATE_IF_VALID 18 | } 19 | } 20 | } 21 | 22 | extension GtkSpinButtonUpdatePolicy { 23 | func toSpinButtonUpdatePolicy() -> SpinButtonUpdatePolicy { 24 | switch self { 25 | case GTK_UPDATE_ALWAYS: 26 | return .always 27 | case GTK_UPDATE_IF_VALID: 28 | return .ifValid 29 | default: 30 | fatalError("Unsupported GtkSpinButtonUpdatePolicy enum value: \(self.rawValue)") 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/SpinType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// The values of the GtkSpinType enumeration are used to specify the change to make in gtk_spin_button_spin(). 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.SpinType.html) 6 | public enum SpinType { 7 | /// Increment by the adjustments step increment. 8 | case stepForward 9 | /// Decrement by the adjustments step increment. 10 | case stepBackward 11 | /// Increment by the adjustments page increment. 12 | case pageForward 13 | /// Decrement by the adjustments page increment. 14 | case pageBackward 15 | /// Go to the adjustments lower bound. 16 | case home 17 | /// Go to the adjustments upper bound. 18 | case end 19 | /// Change by a specified amount. 20 | case userDefined 21 | 22 | func toGtkSpinType() -> GtkSpinType { 23 | switch self { 24 | case .stepForward: 25 | return GTK_SPIN_STEP_FORWARD 26 | case .stepBackward: 27 | return GTK_SPIN_STEP_BACKWARD 28 | case .pageForward: 29 | return GTK_SPIN_PAGE_FORWARD 30 | case .pageBackward: 31 | return GTK_SPIN_PAGE_BACKWARD 32 | case .home: 33 | return GTK_SPIN_HOME 34 | case .end: 35 | return GTK_SPIN_END 36 | case .userDefined: 37 | return GTK_SPIN_USER_DEFINED 38 | } 39 | } 40 | } 41 | 42 | extension GtkSpinType { 43 | func toSpinType() -> SpinType { 44 | switch self { 45 | case GTK_SPIN_STEP_FORWARD: 46 | return .stepForward 47 | case GTK_SPIN_STEP_BACKWARD: 48 | return .stepBackward 49 | case GTK_SPIN_PAGE_FORWARD: 50 | return .pageForward 51 | case GTK_SPIN_PAGE_BACKWARD: 52 | return .pageBackward 53 | case GTK_SPIN_HOME: 54 | return .home 55 | case GTK_SPIN_END: 56 | return .end 57 | case GTK_SPIN_USER_DEFINED: 58 | return .userDefined 59 | default: 60 | fatalError("Unsupported GtkSpinType enum value: \(self.rawValue)") 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/StackTransitionType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// These enumeration values describe the possible transitions between pages in a `GtkStack` widget. 4 | /// 5 | /// New values may be added to this enumeration over time. 6 | /// 7 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.StackTransitionType.html) 8 | public enum StackTransitionType { 9 | /// No transition. 10 | case none 11 | /// A cross-fade. 12 | case crossfade 13 | /// Slide from left to right. 14 | case slideRight 15 | /// Slide from right to left. 16 | case slideLeft 17 | /// Slide from bottom up. 18 | case slideUp 19 | /// Slide from top down. 20 | case slideDown 21 | /// Slide from left or right according to the children order. 22 | case slideLeftRight 23 | /// Slide from top down or bottom up according to the order. 24 | case slideUpDown 25 | /// Cover the old page by sliding up. Since 3.12 26 | case overUp 27 | /// Cover the old page by sliding down. Since: 3.12 28 | case overDown 29 | /// Cover the old page by sliding to the left. Since: 3.12 30 | case overLeft 31 | /// Cover the old page by sliding to the right. Since: 3.12 32 | case overRight 33 | /// Uncover the new page by sliding up. Since 3.12 34 | case underUp 35 | /// Uncover the new page by sliding down. Since: 3.12 36 | case underDown 37 | /// Uncover the new page by sliding to the left. Since: 3.12 38 | case underLeft 39 | /// Uncover the new page by sliding to the right. Since: 3.12 40 | case underRight 41 | /// Cover the old page sliding up or uncover the new page sliding down, according to order. Since: 3.12 42 | case overUpDown 43 | /// Cover the old page sliding down or uncover the new page sliding up, according to order. Since: 3.14 44 | case overDownUp 45 | /// Cover the old page sliding left or uncover the new page sliding right, according to order. Since: 3.14 46 | case overLeftRight 47 | /// Cover the old page sliding right or uncover the new page sliding left, according to order. Since: 3.14 48 | case overRightLeft 49 | 50 | func toGtkStackTransitionType() -> GtkStackTransitionType { 51 | switch self { 52 | case .none: 53 | return GTK_STACK_TRANSITION_TYPE_NONE 54 | case .crossfade: 55 | return GTK_STACK_TRANSITION_TYPE_CROSSFADE 56 | case .slideRight: 57 | return GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT 58 | case .slideLeft: 59 | return GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT 60 | case .slideUp: 61 | return GTK_STACK_TRANSITION_TYPE_SLIDE_UP 62 | case .slideDown: 63 | return GTK_STACK_TRANSITION_TYPE_SLIDE_DOWN 64 | case .slideLeftRight: 65 | return GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT 66 | case .slideUpDown: 67 | return GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN 68 | case .overUp: 69 | return GTK_STACK_TRANSITION_TYPE_OVER_UP 70 | case .overDown: 71 | return GTK_STACK_TRANSITION_TYPE_OVER_DOWN 72 | case .overLeft: 73 | return GTK_STACK_TRANSITION_TYPE_OVER_LEFT 74 | case .overRight: 75 | return GTK_STACK_TRANSITION_TYPE_OVER_RIGHT 76 | case .underUp: 77 | return GTK_STACK_TRANSITION_TYPE_UNDER_UP 78 | case .underDown: 79 | return GTK_STACK_TRANSITION_TYPE_UNDER_DOWN 80 | case .underLeft: 81 | return GTK_STACK_TRANSITION_TYPE_UNDER_LEFT 82 | case .underRight: 83 | return GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT 84 | case .overUpDown: 85 | return GTK_STACK_TRANSITION_TYPE_OVER_UP_DOWN 86 | case .overDownUp: 87 | return GTK_STACK_TRANSITION_TYPE_OVER_DOWN_UP 88 | case .overLeftRight: 89 | return GTK_STACK_TRANSITION_TYPE_OVER_LEFT_RIGHT 90 | case .overRightLeft: 91 | return GTK_STACK_TRANSITION_TYPE_OVER_RIGHT_LEFT 92 | } 93 | } 94 | } 95 | 96 | extension GtkStackTransitionType { 97 | func toStackTransitionType() -> StackTransitionType { 98 | switch self { 99 | case GTK_STACK_TRANSITION_TYPE_NONE: 100 | return StackTransitionType.none 101 | case GTK_STACK_TRANSITION_TYPE_CROSSFADE: 102 | return .crossfade 103 | case GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT: 104 | return .slideRight 105 | case GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT: 106 | return .slideLeft 107 | case GTK_STACK_TRANSITION_TYPE_SLIDE_UP: 108 | return .slideUp 109 | case GTK_STACK_TRANSITION_TYPE_SLIDE_DOWN: 110 | return .slideDown 111 | case GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT: 112 | return .slideLeftRight 113 | case GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN: 114 | return .slideUpDown 115 | case GTK_STACK_TRANSITION_TYPE_OVER_UP: 116 | return .overUp 117 | case GTK_STACK_TRANSITION_TYPE_OVER_DOWN: 118 | return .overDown 119 | case GTK_STACK_TRANSITION_TYPE_OVER_LEFT: 120 | return .overLeft 121 | case GTK_STACK_TRANSITION_TYPE_OVER_RIGHT: 122 | return .overRight 123 | case GTK_STACK_TRANSITION_TYPE_UNDER_UP: 124 | return .underUp 125 | case GTK_STACK_TRANSITION_TYPE_UNDER_DOWN: 126 | return .underDown 127 | case GTK_STACK_TRANSITION_TYPE_UNDER_LEFT: 128 | return .underLeft 129 | case GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT: 130 | return .underRight 131 | case GTK_STACK_TRANSITION_TYPE_OVER_UP_DOWN: 132 | return .overUpDown 133 | case GTK_STACK_TRANSITION_TYPE_OVER_DOWN_UP: 134 | return .overDownUp 135 | case GTK_STACK_TRANSITION_TYPE_OVER_LEFT_RIGHT: 136 | return .overLeftRight 137 | case GTK_STACK_TRANSITION_TYPE_OVER_RIGHT_LEFT: 138 | return .overRightLeft 139 | default: 140 | fatalError("Unsupported GtkStackTransitionType enum value: \(self.rawValue)") 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/StateType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | public enum StateType { 4 | case normal 5 | case active 6 | case prelight 7 | case selected 8 | case insensitive 9 | case inconsistent 10 | case focused 11 | 12 | public init?(rawValue: GtkStateType) { 13 | switch rawValue { 14 | case GTK_STATE_NORMAL: 15 | self = .normal 16 | case GTK_STATE_ACTIVE: 17 | self = .active 18 | case GTK_STATE_PRELIGHT: 19 | self = .prelight 20 | case GTK_STATE_SELECTED: 21 | self = .selected 22 | case GTK_STATE_INSENSITIVE: 23 | self = .insensitive 24 | case GTK_STATE_INCONSISTENT: 25 | self = .inconsistent 26 | case GTK_STATE_FOCUSED: 27 | self = .focused 28 | default: 29 | return nil 30 | } 31 | } 32 | 33 | public var rawValue: GtkStateType { 34 | switch self { 35 | case .normal: 36 | return GTK_STATE_NORMAL 37 | case .active: 38 | return GTK_STATE_ACTIVE 39 | case .prelight: 40 | return GTK_STATE_PRELIGHT 41 | case .selected: 42 | return GTK_STATE_SELECTED 43 | case .insensitive: 44 | return GTK_STATE_INSENSITIVE 45 | case .inconsistent: 46 | return GTK_STATE_INCONSISTENT 47 | case .focused: 48 | return GTK_STATE_FOCUSED 49 | } 50 | } 51 | 52 | public var rawFlagValue: GtkStateFlags { 53 | switch self { 54 | case .normal: 55 | return GTK_STATE_FLAG_NORMAL 56 | case .active: 57 | return GTK_STATE_FLAG_ACTIVE 58 | case .prelight: 59 | return GTK_STATE_FLAG_PRELIGHT 60 | case .selected: 61 | return GTK_STATE_FLAG_SELECTED 62 | case .insensitive: 63 | return GTK_STATE_FLAG_INSENSITIVE 64 | case .inconsistent: 65 | return GTK_STATE_FLAG_INCONSISTENT 66 | case .focused: 67 | return GTK_STATE_FLAG_FOCUSED 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/TextBufferTargetInfo.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// These values are used as “info” for the targets contained in the lists returned by `gtk_text_buffer_get_copy_target_list()` and `gtk_text_buffer_get_paste_target_list()`. 4 | /// 5 | /// The values counts down from -1 to avoid clashes with application added drag destinations which usually start at 0. 6 | /// 7 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.TextBufferTargetInfo.html) 8 | public enum TextBufferTargetInfo { 9 | /// Buffer contents. 10 | case bufferContents 11 | /// Rich text. 12 | case richText 13 | /// Text. 14 | case text 15 | 16 | func toGtkTextBufferTargetInfo() -> GtkTextBufferTargetInfo { 17 | switch self { 18 | case .bufferContents: 19 | return GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS 20 | case .richText: 21 | return GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT 22 | case .text: 23 | return GTK_TEXT_BUFFER_TARGET_INFO_TEXT 24 | } 25 | } 26 | } 27 | 28 | extension GtkTextBufferTargetInfo { 29 | func toTextBufferTargetInfo() -> TextBufferTargetInfo { 30 | switch self { 31 | case GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS: 32 | return .bufferContents 33 | case GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT: 34 | return .richText 35 | case GTK_TEXT_BUFFER_TARGET_INFO_TEXT: 36 | return .text 37 | default: 38 | fatalError("Unsupported GtkTextBufferTargetInfo enum value: \(self.rawValue)") 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/TextDirection.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Reading directions for text. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.TextDirection.html) 6 | public enum TextDirection { 7 | /// No direction. 8 | case none 9 | /// Left to right text direction. 10 | case leftToRight 11 | /// Right to left text direction. 12 | case rightToLeft 13 | 14 | func toGtkTextDirection() -> GtkTextDirection { 15 | switch self { 16 | case .none: 17 | return GTK_TEXT_DIR_NONE 18 | case .leftToRight: 19 | return GTK_TEXT_DIR_LTR 20 | case .rightToLeft: 21 | return GTK_TEXT_DIR_RTL 22 | } 23 | } 24 | } 25 | 26 | extension GtkTextDirection { 27 | func toTextDirection() -> TextDirection { 28 | switch self { 29 | case GTK_TEXT_DIR_NONE: 30 | return TextDirection.none 31 | case GTK_TEXT_DIR_LTR: 32 | return .leftToRight 33 | case GTK_TEXT_DIR_RTL: 34 | return .rightToLeft 35 | default: 36 | fatalError("Unsupported GtkTextDirection enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/TextExtendSelection.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Granularity types that extend the text selection. Use the `GtkTextView::extend-selection` signal to customize the selection. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.TextExtendSelection.html) 6 | public enum TextExtendSelection { 7 | /// Selects the current word. It is triggered by a double-click for example. 8 | case word 9 | /// Selects the current line. It is triggered by a triple-click for example. 10 | case line 11 | 12 | func toGtkTextExtendSelection() -> GtkTextExtendSelection { 13 | switch self { 14 | case .word: 15 | return GTK_TEXT_EXTEND_SELECTION_WORD 16 | case .line: 17 | return GTK_TEXT_EXTEND_SELECTION_LINE 18 | } 19 | } 20 | } 21 | 22 | extension GtkTextExtendSelection { 23 | func toTextExtendSelection() -> TextExtendSelection { 24 | switch self { 25 | case GTK_TEXT_EXTEND_SELECTION_WORD: 26 | return .word 27 | case GTK_TEXT_EXTEND_SELECTION_LINE: 28 | return .line 29 | default: 30 | fatalError("Unsupported GtkTextExtendSelection enum value: \(self.rawValue)") 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/TextViewLayer.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to reference the layers of `GtkTextView` for the purpose of customized drawing with the ::draw_layer vfunc. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.TextViewLayer.html) 6 | public enum TextViewLayer { 7 | /// Old deprecated layer, use GTK_TEXT_VIEW_LAYER_BELOW_TEXT instead. 8 | case below 9 | /// Old deprecated layer, use GTK_TEXT_VIEW_LAYER_ABOVE_TEXT instead. 10 | case above 11 | /// The layer rendered below the text (but above the background). Since: 3.20 12 | case belowText 13 | /// The layer rendered above the text. Since: 3.20 14 | case aboveText 15 | 16 | func toGtkTextViewLayer() -> GtkTextViewLayer { 17 | switch self { 18 | case .below: 19 | return GTK_TEXT_VIEW_LAYER_BELOW 20 | case .above: 21 | return GTK_TEXT_VIEW_LAYER_ABOVE 22 | case .belowText: 23 | return GTK_TEXT_VIEW_LAYER_BELOW_TEXT 24 | case .aboveText: 25 | return GTK_TEXT_VIEW_LAYER_ABOVE_TEXT 26 | } 27 | } 28 | } 29 | 30 | extension GtkTextViewLayer { 31 | func toTextViewLayer() -> TextViewLayer { 32 | switch self { 33 | case GTK_TEXT_VIEW_LAYER_BELOW: 34 | return .below 35 | case GTK_TEXT_VIEW_LAYER_ABOVE: 36 | return .above 37 | case GTK_TEXT_VIEW_LAYER_BELOW_TEXT: 38 | return .belowText 39 | case GTK_TEXT_VIEW_LAYER_ABOVE_TEXT: 40 | return .aboveText 41 | default: 42 | fatalError("Unsupported GtkTextViewLayer enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/TextWindowType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to reference the parts of `GtkTextView`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.TextWindowType.html) 6 | public enum TextWindowType { 7 | /// Invalid value, used as a marker. 8 | case `private` 9 | /// Window that floats over scrolling areas. 10 | case widget 11 | /// Scrollable text window. 12 | case text 13 | /// Left side border window. 14 | case left 15 | /// Right side border window. 16 | case right 17 | /// Top border window. 18 | case top 19 | /// Bottom border window. 20 | case bottom 21 | 22 | func toGtkTextWindowType() -> GtkTextWindowType { 23 | switch self { 24 | case .private: 25 | return GTK_TEXT_WINDOW_PRIVATE 26 | case .widget: 27 | return GTK_TEXT_WINDOW_WIDGET 28 | case .text: 29 | return GTK_TEXT_WINDOW_TEXT 30 | case .left: 31 | return GTK_TEXT_WINDOW_LEFT 32 | case .right: 33 | return GTK_TEXT_WINDOW_RIGHT 34 | case .top: 35 | return GTK_TEXT_WINDOW_TOP 36 | case .bottom: 37 | return GTK_TEXT_WINDOW_BOTTOM 38 | } 39 | } 40 | } 41 | 42 | extension GtkTextWindowType { 43 | func toTextWindowType() -> TextWindowType { 44 | switch self { 45 | case GTK_TEXT_WINDOW_PRIVATE: 46 | return .private 47 | case GTK_TEXT_WINDOW_WIDGET: 48 | return .widget 49 | case GTK_TEXT_WINDOW_TEXT: 50 | return .text 51 | case GTK_TEXT_WINDOW_LEFT: 52 | return .left 53 | case GTK_TEXT_WINDOW_RIGHT: 54 | return .right 55 | case GTK_TEXT_WINDOW_TOP: 56 | return .top 57 | case GTK_TEXT_WINDOW_BOTTOM: 58 | return .bottom 59 | default: 60 | fatalError("Unsupported GtkTextWindowType enum value: \(self.rawValue)") 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/ToolbarStyle.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to customize the appearance of a `GtkToolbar`. Note that setting the toolbar style overrides the user’s preferences for the default toolbar style. Note that if the button has only a label set and `GTK_TOOLBAR_ICONS` is used, the label will be visible, and vice versa. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.ToolbarStyle.html) 6 | public enum ToolbarStyle { 7 | /// Buttons display only icons in the toolbar. 8 | case icons 9 | /// Buttons display only text labels in the toolbar. 10 | case text 11 | /// Buttons display text and icons in the toolbar. 12 | case both 13 | /// Buttons display icons and text alongside each other, rather than vertically stacked. 14 | case bothHorizontal 15 | 16 | func toGtkToolbarStyle() -> GtkToolbarStyle { 17 | switch self { 18 | case .icons: 19 | return GTK_TOOLBAR_ICONS 20 | case .text: 21 | return GTK_TOOLBAR_TEXT 22 | case .both: 23 | return GTK_TOOLBAR_BOTH 24 | case .bothHorizontal: 25 | return GTK_TOOLBAR_BOTH_HORIZ 26 | } 27 | } 28 | } 29 | 30 | extension GtkToolbarStyle { 31 | func toToolbarStyle() -> ToolbarStyle { 32 | switch self { 33 | case GTK_TOOLBAR_ICONS: 34 | return .icons 35 | case GTK_TOOLBAR_TEXT: 36 | return .text 37 | case GTK_TOOLBAR_BOTH: 38 | return .both 39 | case GTK_TOOLBAR_BOTH_HORIZ: 40 | return .bothHorizontal 41 | default: 42 | fatalError("Unsupported GtkToolbarStyle enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/TreeViewColumnSizing.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// The sizing method the column uses to determine its width. Please note that `GTK_TREE_VIEW_COLUMN_AUTOSIZE` are inefficient for large views, and can make columns appear choppy. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.TreeViewColumnSizing.html) 6 | public enum TreeViewColumnSizing { 7 | /// Columns only get bigger in reaction to changes in the model. 8 | case growOnly 9 | /// Columns resize to be the optimal size everytime the model changes. 10 | case auto 11 | /// Columns are a fixed numbers of pixels wide. 12 | case fixed 13 | 14 | func toGtkTreeViewColumnSizing() -> GtkTreeViewColumnSizing { 15 | switch self { 16 | case .growOnly: 17 | return GTK_TREE_VIEW_COLUMN_GROW_ONLY 18 | case .auto: 19 | return GTK_TREE_VIEW_COLUMN_AUTOSIZE 20 | case .fixed: 21 | return GTK_TREE_VIEW_COLUMN_FIXED 22 | } 23 | } 24 | } 25 | 26 | extension GtkTreeViewColumnSizing { 27 | func toTreeViewColumnSizing() -> TreeViewColumnSizing { 28 | switch self { 29 | case GTK_TREE_VIEW_COLUMN_GROW_ONLY: 30 | return .growOnly 31 | case GTK_TREE_VIEW_COLUMN_AUTOSIZE: 32 | return .auto 33 | case GTK_TREE_VIEW_COLUMN_FIXED: 34 | return .fixed 35 | default: 36 | fatalError("Unsupported GtkTreeViewColumnSizing enum value: \(self.rawValue)") 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/TreeViewDropPosition.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// An enum for determining where a dropped row goes. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.TreeViewDropPosition.html) 6 | public enum TreeViewDropPosition { 7 | /// Dropped row is inserted before. 8 | case before 9 | /// Dropped row is inserted after. 10 | case after 11 | /// Dropped row becomes a child or is inserted before. 12 | case intoOrBefore 13 | /// Dropped row becomes a child or is inserted after. 14 | case intoOrAfter 15 | 16 | func toGtkTreeViewDropPosition() -> GtkTreeViewDropPosition { 17 | switch self { 18 | case .before: 19 | return GTK_TREE_VIEW_DROP_BEFORE 20 | case .after: 21 | return GTK_TREE_VIEW_DROP_AFTER 22 | case .intoOrBefore: 23 | return GTK_TREE_VIEW_DROP_INTO_OR_BEFORE 24 | case .intoOrAfter: 25 | return GTK_TREE_VIEW_DROP_INTO_OR_AFTER 26 | } 27 | } 28 | } 29 | 30 | extension GtkTreeViewDropPosition { 31 | func toTreeViewDropPosition() -> TreeViewDropPosition { 32 | switch self { 33 | case GTK_TREE_VIEW_DROP_BEFORE: 34 | return .before 35 | case GTK_TREE_VIEW_DROP_AFTER: 36 | return .after 37 | case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: 38 | return .intoOrBefore 39 | case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: 40 | return .intoOrAfter 41 | default: 42 | fatalError("Unsupported GtkTreeViewDropPosition enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/TreeViewGridLines.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Used to indicate which grid lines to draw in a tree view. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.TreeViewGridLines.html) 6 | public enum TreeViewGridLines { 7 | /// No grid lines. 8 | case none 9 | /// Horizontal grid lines. 10 | case horizontal 11 | /// Vertical grid lines. 12 | case vertical 13 | /// Horizontal and vertical grid lines. 14 | case both 15 | 16 | func toGtkTreeViewGridLines() -> GtkTreeViewGridLines { 17 | switch self { 18 | case .none: 19 | return GTK_TREE_VIEW_GRID_LINES_NONE 20 | case .horizontal: 21 | return GTK_TREE_VIEW_GRID_LINES_HORIZONTAL 22 | case .vertical: 23 | return GTK_TREE_VIEW_GRID_LINES_VERTICAL 24 | case .both: 25 | return GTK_TREE_VIEW_GRID_LINES_BOTH 26 | } 27 | } 28 | } 29 | 30 | extension GtkTreeViewGridLines { 31 | func toTreeViewGridLines() -> TreeViewGridLines { 32 | switch self { 33 | case GTK_TREE_VIEW_GRID_LINES_NONE: 34 | return TreeViewGridLines.none 35 | case GTK_TREE_VIEW_GRID_LINES_HORIZONTAL: 36 | return .horizontal 37 | case GTK_TREE_VIEW_GRID_LINES_VERTICAL: 38 | return .vertical 39 | case GTK_TREE_VIEW_GRID_LINES_BOTH: 40 | return .both 41 | default: 42 | fatalError("Unsupported GtkTreeViewGridLines enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/Unit.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// See also `gtk_print_settings_set_paper_width()`. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.Unit.html) 6 | public enum Unit { 7 | /// No units. 8 | case none 9 | /// Dimensions in points. 10 | case points 11 | /// Dimensions in inches. 12 | case inches 13 | /// Dimensions in millimeters. 14 | case millimeters 15 | 16 | func toGtkUnit() -> GtkUnit { 17 | switch self { 18 | case .none: 19 | return GTK_UNIT_NONE 20 | case .points: 21 | return GTK_UNIT_POINTS 22 | case .inches: 23 | return GTK_UNIT_INCH 24 | case .millimeters: 25 | return GTK_UNIT_MM 26 | } 27 | } 28 | } 29 | 30 | extension GtkUnit { 31 | func toUnit() -> Unit { 32 | switch self { 33 | case GTK_UNIT_NONE: 34 | return Unit.none 35 | case GTK_UNIT_POINTS: 36 | return .points 37 | case GTK_UNIT_INCH: 38 | return .inches 39 | case GTK_UNIT_MM: 40 | return .millimeters 41 | default: 42 | fatalError("Unsupported GtkUnit enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/WidgetHelpType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Kinds of widget-specific help. Used by the ::show-help signal. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.WidgetHelpType.html) 6 | public enum WidgetHelpType { 7 | /// Tooltip. 8 | case tooltip 9 | /// What’s this. 10 | case whatsThis 11 | 12 | func toGtkWidgetHelpType() -> GtkWidgetHelpType { 13 | switch self { 14 | case .tooltip: 15 | return GTK_WIDGET_HELP_TOOLTIP 16 | case .whatsThis: 17 | return GTK_WIDGET_HELP_WHATS_THIS 18 | } 19 | } 20 | } 21 | 22 | extension GtkWidgetHelpType { 23 | func toWidgetHelpType() -> WidgetHelpType { 24 | switch self { 25 | case GTK_WIDGET_HELP_TOOLTIP: 26 | return .tooltip 27 | case GTK_WIDGET_HELP_WHATS_THIS: 28 | return .whatsThis 29 | default: 30 | fatalError("Unsupported GtkWidgetHelpType enum value: \(self.rawValue)") 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/WindowPosition.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Window placement can be influenced using this enumeration. Note that using #GTK_WIN_POS_CENTER_ALWAYS is almost always a bad idea. It won’t necessarily work well with all window managers or on all windowing systems. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.WindowPosition.html) 6 | public enum WindowPosition { 7 | /// No influence is made on placement. 8 | case none 9 | /// Windows should be placed in the center of the screen. 10 | case center 11 | /// Windows should be placed at the current mouse position. 12 | case mouse 13 | /// Keep window centered as it changes size, etc. 14 | case centerAlways 15 | /// Center the window on its transient parent (see gtk_window_set_transient_for()) 16 | case centerOnParent 17 | 18 | func toGtkWindowPosition() -> GtkWindowPosition { 19 | switch self { 20 | case .none: 21 | return GTK_WIN_POS_NONE 22 | case .center: 23 | return GTK_WIN_POS_CENTER 24 | case .mouse: 25 | return GTK_WIN_POS_MOUSE 26 | case .centerAlways: 27 | return GTK_WIN_POS_CENTER_ALWAYS 28 | case .centerOnParent: 29 | return GTK_WIN_POS_CENTER_ON_PARENT 30 | } 31 | } 32 | } 33 | 34 | extension GtkWindowPosition { 35 | func toWindowPosition() -> WindowPosition { 36 | switch self { 37 | case GTK_WIN_POS_NONE: 38 | return WindowPosition.none 39 | case GTK_WIN_POS_CENTER: 40 | return .center 41 | case GTK_WIN_POS_MOUSE: 42 | return .mouse 43 | case GTK_WIN_POS_CENTER_ALWAYS: 44 | return .centerAlways 45 | case GTK_WIN_POS_CENTER_ON_PARENT: 46 | return .centerOnParent 47 | default: 48 | fatalError("Unsupported GtkWindowPosition enum value: \(self.rawValue)") 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/WindowType.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// A GtkWindow can be one of these types. Most things you’d consider a “window” should have type #GTK_WINDOW_TOPLEVEL; windows with this type are managed by the window manager and have a frame by default (call gtk_window_set_decorated() to toggle the frame). Windows with type 4 | /// 5 | /// GTK_WINDOW_POPUP are ignored by the window manager; window manager 6 | /// 7 | /// keybindings won’t work on them, the window manager won’t decorate the window with a frame, many GTK+ features that rely on the window manager will not work (e.g. resize grips and maximization/minimization). #GTK_WINDOW_POPUP is used to implement widgets such as GtkMenu or tooltips that you normally don’t think of as windows per se. Nearly all windows should be #GTK_WINDOW_TOPLEVEL. In particular, do not use #GTK_WINDOW_POPUP just to turn off the window borders; use gtk_window_set_decorated() for that. 8 | /// 9 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.WindowType.html) 10 | public enum WindowType { 11 | /// A regular window, such as a dialog. 12 | case topLevel 13 | /// A special window such as a tooltip. 14 | case popUp 15 | 16 | func toGtkWindowType() -> GtkWindowType { 17 | switch self { 18 | case .topLevel: 19 | return GTK_WINDOW_TOPLEVEL 20 | case .popUp: 21 | return GTK_WINDOW_POPUP 22 | } 23 | } 24 | } 25 | 26 | extension GtkWindowType { 27 | func toWindowType() -> WindowType { 28 | switch self { 29 | case GTK_WINDOW_TOPLEVEL: 30 | return .topLevel 31 | case GTK_WINDOW_POPUP: 32 | return .popUp 33 | default: 34 | fatalError("Unsupported GtkWindowType enum value: \(self.rawValue)") 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Enums/WrapMode.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | /// Describes a type of line wrapping. 4 | /// 5 | /// [Gtk docs](https://docs.gtk.org/gtk3/enum.WrapMode.html) 6 | public enum WrapMode { 7 | /// Do not wrap lines; just make the text area wider. 8 | case none 9 | /// Wrap text, breaking lines anywhere the cursor can appear (between characters, usually - if you want to be technical, between graphemes, see pango_get_log_attrs()) 10 | case character 11 | /// Wrap text, breaking lines in between words. 12 | case word 13 | /// Wrap text, breaking lines in between words, or if that is not enough, also between graphemes. 14 | case wordCharacter 15 | 16 | func toGtkWrapMode() -> GtkWrapMode { 17 | switch self { 18 | case .none: 19 | return GTK_WRAP_NONE 20 | case .character: 21 | return GTK_WRAP_CHAR 22 | case .word: 23 | return GTK_WRAP_WORD 24 | case .wordCharacter: 25 | return GTK_WRAP_WORD_CHAR 26 | } 27 | } 28 | } 29 | 30 | extension GtkWrapMode { 31 | func toWrapMode() -> WrapMode { 32 | switch self { 33 | case GTK_WRAP_NONE: 34 | return WrapMode.none 35 | case GTK_WRAP_CHAR: 36 | return .character 37 | case GTK_WRAP_WORD: 38 | return .word 39 | case GTK_WRAP_WORD_CHAR: 40 | return .wordCharacter 41 | default: 42 | fatalError("Unsupported GtkWrapMode enum value: \(self.rawValue)") 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/FileChooser.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import CGtk 3 | 4 | /// A wrapper for Gtk's native file chooser. 5 | public struct FileChooser { 6 | /// Presents a file chooser dialog in the given window, and gets the chosen files (if any). 7 | public static func present(_ window: Window) -> URL? { 8 | let native = gtk_file_chooser_native_new("Open file", window.castedPointer(), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open", "_Cancel") 9 | let result = gtk_native_dialog_run(UnsafeMutablePointer(native)) 10 | if GtkResponseType(rawValue: result) == GTK_RESPONSE_ACCEPT { 11 | guard let filename = gtk_file_chooser_get_filename(native) else { 12 | return nil 13 | } 14 | return URL(fileURLWithPath: String(cString: filename)) 15 | } else { 16 | return nil 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Grid.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2017 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | /// Grid is a container which arranges its child widgets in rows and columns. It is a very similar to Table and Box, but it consistently uses Widget’s "margin" and "expand" properties instead of custom child properties, and it fully supports height-for-width geometry management. 8 | /// Children are added using `attach(child:left:top:width:height:)`. They can span multiple rows or columns. It is also possible to add a child next to an existing child, using `attach(nextTo:sibling:side:width:height:)`. The behaviour of Grid when several children occupy the same grid cell is undefined. 9 | /// Grid can be used like a Box by just using `add(_:)`, which will place children next to each other in the direction determined by the "orientation" property. 10 | public class Grid: Container { 11 | override init() { 12 | super.init() 13 | 14 | widgetPointer = gtk_grid_new() 15 | } 16 | 17 | public func attach(child: Widget, left: Int, top: Int, width: Int, height: Int) { 18 | widgets.append(child) 19 | child.parentWidget = self 20 | 21 | gtk_grid_attach(castedPointer(), child.widgetPointer, gint(left), gint(top), gint(width), gint(height)) 22 | } 23 | 24 | public func attach(nextTo child: Widget, sibling: Widget, side: PositionType, width: Int, height: Int) { 25 | widgets.append(child) 26 | child.parentWidget = self 27 | 28 | gtk_grid_attach_next_to(castedPointer(), child.widgetPointer, sibling.widgetPointer, side.toGtkPositionType(), gint(width), gint(height)) 29 | } 30 | 31 | func getChildAt(left: Int, top: Int) -> Widget? { 32 | let widget = gtk_grid_get_child_at(castedPointer(), gint(left), gint(top)) 33 | return widgets.first(where: { $0.widgetPointer == widget }) 34 | } 35 | 36 | public func insertRow(position: Int) { 37 | gtk_grid_insert_row(castedPointer(), gint(position)) 38 | } 39 | 40 | public func removeRow(position: Int) { 41 | gtk_grid_remove_row(castedPointer(), gint(position)) 42 | } 43 | 44 | public func insertColumn(position: Int) { 45 | gtk_grid_insert_column(castedPointer(), gint(position)) 46 | } 47 | 48 | public func removeColumn(position: Int) { 49 | gtk_grid_remove_column(castedPointer(), gint(position)) 50 | } 51 | 52 | /// Inserts a row or column at the specified position. 53 | /// The new row or column is placed next to `sibling`, on the side determined by `side`. If `side` is `.top` or `.bottom`, a row is inserted. If side is `.left` or `.right`, a column is inserted. 54 | /// - Parameter sibling: The child of `grid` that the new row or column will be placed next to. 55 | /// - Parameter side: The side of `sibling` that `child` is positioned next to. 56 | public func insert(nextTo sibling: Widget, side: PositionType) { 57 | gtk_grid_insert_next_to(castedPointer(), sibling.widgetPointer, side.toGtkPositionType()) 58 | } 59 | 60 | /// Whether all rows of `grid` will have the same height. 61 | public var rowHomogeneous: Bool { 62 | get { 63 | return gtk_grid_get_row_homogeneous(castedPointer()).toBool() 64 | } 65 | set { 66 | gtk_grid_set_row_homogeneous(castedPointer(), newValue.toGBoolean()) 67 | } 68 | } 69 | 70 | /// The amount of space between rows of `grid`. 71 | public var rowSpacing: Int { 72 | get { 73 | return Int(gtk_grid_get_row_spacing(castedPointer())) 74 | } 75 | set { 76 | gtk_grid_set_row_spacing(castedPointer(), guint(newValue)) 77 | } 78 | } 79 | 80 | public var columnHomogeneous: Bool { 81 | get { 82 | return gtk_grid_get_column_homogeneous(castedPointer()).toBool() 83 | } 84 | set { 85 | gtk_grid_set_column_homogeneous(castedPointer(), newValue.toGBoolean()) 86 | } 87 | } 88 | 89 | public var columnSpacing: Int { 90 | get { 91 | return Int(gtk_grid_get_column_spacing(castedPointer())) 92 | } 93 | set { 94 | gtk_grid_set_column_spacing(castedPointer(), guint(newValue)) 95 | } 96 | } 97 | 98 | public var baselineRow: Int { 99 | get { 100 | return Int(gtk_grid_get_baseline_row(castedPointer())) 101 | } 102 | set { 103 | gtk_grid_set_baseline_row(castedPointer(), gint(newValue)) 104 | } 105 | } 106 | 107 | public func getRowBaselinePosition(forRow row: Int) -> BaselinePosition { 108 | return gtk_grid_get_row_baseline_position(castedPointer(), gint(row)).toBaselinePosition() 109 | } 110 | 111 | public func setRowBaselinePosition(forRow row: Int, position: BaselinePosition) { 112 | gtk_grid_set_row_baseline_position(castedPointer(), gint(row), position.toGtkBaselinePosition()) 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/GtkError.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import CGtk 3 | 4 | public struct GtkError: LocalizedError { 5 | public var code: Int 6 | public var domain: Int 7 | public var message: String 8 | 9 | public init(from error: GError) { 10 | message = String(cString: error.message) 11 | code = Int(error.code) 12 | domain = Int(error.domain) 13 | } 14 | 15 | public var errorDescription: String? { 16 | return message 17 | } 18 | } 19 | 20 | /// An easy way to wrap Gtk code that uses error pointers for handling. Passes an error pointer to 21 | /// your code, which is then checked for an error which is thrown if present. 22 | @discardableResult 23 | public func withGtkError(_ action: (UnsafeMutablePointer?>) -> R) throws -> R { 24 | var errorPointer: UnsafeMutablePointer? = nil 25 | let result = action(&errorPointer) 26 | 27 | if let errorPointer = errorPointer { 28 | throw GtkError(from: errorPointer.pointee) 29 | } else { 30 | return result 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/HeaderBar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2017 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | public class HeaderBar: Container { 8 | public override init() { 9 | super.init() 10 | 11 | widgetPointer = gtk_header_bar_new() 12 | } 13 | 14 | public var title: String? { 15 | get { return gtk_header_bar_get_title(castedPointer())?.toString() } 16 | set { gtk_header_bar_set_title(castedPointer(), newValue) } 17 | } 18 | 19 | public var subtitle: String? { 20 | get { return gtk_header_bar_get_subtitle(castedPointer())?.toString() } 21 | set { gtk_header_bar_set_subtitle(castedPointer(), newValue) } 22 | } 23 | 24 | public var hasSubtitle: Bool { 25 | get { return gtk_header_bar_get_has_subtitle(castedPointer()).toBool() } 26 | set { gtk_header_bar_set_has_subtitle(castedPointer(), newValue.toGBoolean()) } 27 | } 28 | 29 | private var _customTitle: Widget? 30 | public var customTitle: Widget? { 31 | get { return _customTitle } 32 | set { gtk_header_bar_set_custom_title(castedPointer(), newValue?.widgetPointer) } 33 | } 34 | 35 | public var showCloseButton: Bool { 36 | get { return gtk_header_bar_get_show_close_button(castedPointer()).toBool() } 37 | set { gtk_header_bar_set_show_close_button(castedPointer(), newValue.toGBoolean()) } 38 | } 39 | 40 | public var decorationLayout: String? { 41 | get { return gtk_header_bar_get_decoration_layout(castedPointer())?.toString() } 42 | set { gtk_header_bar_set_decoration_layout(castedPointer(), newValue) } 43 | } 44 | 45 | public var spacing: Int { 46 | get { return getProperty(castedPointer(), name: "spacing") } 47 | set { setProperty(castedPointer(), name: "spacing", newValue: newValue) } 48 | } 49 | 50 | public func packStart(child: Widget) { 51 | widgets.append(child) 52 | gtk_header_bar_pack_start(castedPointer(), child.widgetPointer) 53 | } 54 | 55 | public func packEnd(child: Widget) { 56 | widgets.append(child) 57 | gtk_header_bar_pack_end(castedPointer(), child.widgetPointer) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Image.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2016 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | public class Image: Widget { 8 | public init(path: String) { 9 | super.init() 10 | 11 | widgetPointer = gtk_image_new_from_file(path) 12 | } 13 | 14 | public func setPath(_ path: String) { 15 | gtk_image_set_from_file(castedPointer(), path) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Label.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | public class Label: Widget { 8 | public init(text: String? = nil) { 9 | super.init() 10 | if let text = text { 11 | widgetPointer = gtk_label_new(text) 12 | } else { 13 | widgetPointer = gtk_label_new(nil) 14 | } 15 | horizontalAlignment = .start 16 | } 17 | 18 | public var text: String? { 19 | get { 20 | return String(cString: gtk_label_get_text(castedPointer())) 21 | } 22 | set { 23 | if let text = newValue { 24 | gtk_label_set_text(castedPointer(), text) 25 | } else { 26 | gtk_label_set_text(castedPointer(), nil) 27 | } 28 | } 29 | } 30 | 31 | public var selectable: Bool { 32 | get { 33 | return gtk_label_get_selectable(castedPointer()) == 1 34 | } 35 | set { 36 | gtk_label_set_selectable(castedPointer(), newValue ? 1 : 0) 37 | } 38 | } 39 | 40 | public var justification: Justification { 41 | get { 42 | return gtk_label_get_justify(castedPointer()).toJustification() 43 | } 44 | set { 45 | gtk_label_set_justify(castedPointer(), newValue.toGtkJustification()) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Scale.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | public class Scale: Widget { 4 | public override init() { 5 | super.init() 6 | widgetPointer = gtk_scale_new(Orientation.horizontal.toGtkOrientation(), nil) 7 | } 8 | 9 | override func didMoveToParent() { 10 | super.didMoveToParent() 11 | 12 | addSignal(name: "value-changed") { [weak self] in 13 | guard let self = self else { return } 14 | self.changed?(self) 15 | } 16 | 17 | addSignal(name: "button-release-event") { [weak self] _ in 18 | guard let self = self else { return } 19 | self.doneEditing?(self) 20 | } 21 | } 22 | 23 | public var value: Double { 24 | get { 25 | return gtk_range_get_value(castedPointer()) 26 | } 27 | set { 28 | gtk_range_set_value(castedPointer(), newValue) 29 | } 30 | } 31 | 32 | public var minimum: Double { 33 | get { 34 | let adjustment = gtk_range_get_adjustment(castedPointer()) 35 | return gtk_adjustment_get_lower(adjustment) 36 | } 37 | set { 38 | let adjustment = gtk_range_get_adjustment(castedPointer()) 39 | gtk_adjustment_set_lower(adjustment, newValue) 40 | } 41 | } 42 | 43 | public var maximum: Double { 44 | get { 45 | let adjustment = gtk_range_get_adjustment(castedPointer()) 46 | return gtk_adjustment_get_upper(adjustment) 47 | } 48 | set { 49 | let adjustment = gtk_range_get_adjustment(castedPointer()) 50 | gtk_adjustment_set_upper(adjustment, newValue) 51 | } 52 | } 53 | 54 | public var decimalPlaces: Int { 55 | get { 56 | return Int(gtk_scale_get_digits(castedPointer())) 57 | } 58 | set { 59 | gtk_scale_set_digits(castedPointer(), gint(newValue)) 60 | } 61 | } 62 | 63 | public var changed: ((Scale) -> Void)? 64 | public var doneEditing: ((Scale) -> Void)? 65 | } 66 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/ScrolledWindow.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | public class ScrolledWindow: Bin { 4 | public override init() { 5 | super.init() 6 | widgetPointer = gtk_scrolled_window_new(nil, nil) 7 | } 8 | 9 | override func didMoveToParent() { 10 | super.didMoveToParent() 11 | } 12 | 13 | public var minimumContentWidth: Int { 14 | get { 15 | return Int(gtk_scrolled_window_get_min_content_width(castedPointer())) 16 | } 17 | set { 18 | gtk_scrolled_window_set_min_content_width(castedPointer(), gint(newValue)) 19 | } 20 | } 21 | 22 | public var maximumContentWidth: Int { 23 | get { 24 | return Int(gtk_scrolled_window_get_max_content_width(castedPointer())) 25 | } 26 | set { 27 | gtk_scrolled_window_set_max_content_width(castedPointer(), gint(newValue)) 28 | } 29 | } 30 | 31 | public var minimumContentHeight: Int { 32 | get { 33 | return Int(gtk_scrolled_window_get_min_content_height(castedPointer())) 34 | } 35 | set { 36 | gtk_scrolled_window_set_min_content_height(castedPointer(), gint(newValue)) 37 | } 38 | } 39 | 40 | public var maximumContentHeight: Int { 41 | get { 42 | return Int(gtk_scrolled_window_get_max_content_height(castedPointer())) 43 | } 44 | set { 45 | gtk_scrolled_window_set_max_content_height(castedPointer(), gint(newValue)) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/SignalBox.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2016 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | protocol SignalBox { 6 | associatedtype CallbackType 7 | 8 | var callback: CallbackType { get } 9 | 10 | init(callback: CallbackType) 11 | } 12 | 13 | typealias SignalCallbackZero = () -> Void 14 | typealias SignalCallbackOne = (UnsafeMutableRawPointer) -> Void 15 | typealias SignalCallbackTwo = (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void 16 | typealias SignalCallbackThree = (UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void 17 | typealias SignalCallbackFour = (UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void 18 | typealias SignalCallbackFive = (UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void 19 | typealias SignalCallbackSix = (UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void 20 | 21 | /// Provides a box that captures a callback for a signal so it makes easier to add signals. 22 | class SignalBoxZero: SignalBox { 23 | typealias CallbackType = SignalCallbackZero 24 | 25 | let callback: CallbackType 26 | 27 | required init(callback: @escaping CallbackType) { 28 | self.callback = callback 29 | } 30 | } 31 | 32 | class SignalBoxOne: SignalBox { 33 | typealias CallbackType = SignalCallbackOne 34 | 35 | let callback: CallbackType 36 | 37 | required init(callback: @escaping CallbackType) { 38 | self.callback = callback 39 | } 40 | } 41 | 42 | class SignalBoxTwo: SignalBox { 43 | typealias CallbackType = SignalCallbackTwo 44 | 45 | let callback: CallbackType 46 | 47 | required init(callback: @escaping CallbackType) { 48 | self.callback = callback 49 | } 50 | } 51 | 52 | class SignalBoxThree: SignalBox { 53 | typealias CallbackType = SignalCallbackThree 54 | 55 | let callback: CallbackType 56 | 57 | required init(callback: @escaping CallbackType) { 58 | self.callback = callback 59 | } 60 | } 61 | 62 | class SignalBoxFour: SignalBox { 63 | typealias CallbackType = SignalCallbackFour 64 | 65 | let callback: CallbackType 66 | 67 | required init(callback: @escaping CallbackType) { 68 | self.callback = callback 69 | } 70 | } 71 | 72 | class SignalBoxFive: SignalBox { 73 | typealias CallbackType = SignalCallbackFive 74 | 75 | let callback: CallbackType 76 | 77 | required init(callback: @escaping CallbackType) { 78 | self.callback = callback 79 | } 80 | } 81 | 82 | class SignalBoxSix: SignalBox { 83 | typealias CallbackType = SignalCallbackSix 84 | 85 | let callback: CallbackType 86 | 87 | required init(callback: @escaping CallbackType) { 88 | self.callback = callback 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Signals.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | enum ConnectFlags { 8 | case after 9 | case swapped 10 | 11 | fileprivate func toGConnectFlags() -> GConnectFlags { 12 | switch self { 13 | case .after: 14 | return G_CONNECT_AFTER 15 | case .swapped: 16 | return G_CONNECT_SWAPPED 17 | } 18 | } 19 | } 20 | 21 | @discardableResult 22 | func connectSignal(_ instance: UnsafeMutablePointer?, name: String, data: UnsafeRawPointer, connectFlags: ConnectFlags = .after, handler: @escaping GCallback) -> UInt { 23 | return .init(g_signal_connect_data(instance, name, handler, data.cast(), nil, connectFlags.toGConnectFlags())) 24 | } 25 | 26 | @discardableResult 27 | func connectSignal(_ instance: UnsafeMutablePointer?, name: String, connectFlags: ConnectFlags = .after, handler: @escaping GCallback) -> UInt { 28 | return .init(g_signal_connect_data(instance, name, handler, nil, nil, connectFlags.toGConnectFlags())) 29 | } 30 | 31 | func disconnectSignal(_ instance: UnsafeMutablePointer?, handlerId: UInt) { 32 | g_signal_handler_disconnect(instance, .init(handlerId)) 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Size.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2016 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | public struct Size { 6 | static let zero = Size(width: 0, height: 0) 7 | 8 | public var width: Int 9 | public var height: Int 10 | 11 | public init(width: Int = 0, height: Int = 0) { 12 | self.width = width 13 | self.height = height 14 | } 15 | } 16 | 17 | extension Size: CustomStringConvertible { 18 | public var description: String { 19 | return "(\(width), \(height))" 20 | } 21 | } 22 | 23 | extension Size: CustomDebugStringConvertible { 24 | public var debugDescription: String { 25 | return description 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/TextView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2016 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | public class TextView: Container { 8 | public override init() { 9 | super.init() 10 | 11 | widgetPointer = gtk_text_view_new() 12 | } 13 | 14 | override func didMoveToParent() { 15 | super.didMoveToParent() 16 | 17 | addSignal(name: "backspace") { [weak self] in 18 | guard let self = self else { return } 19 | self.backspace?(self) 20 | } 21 | addSignal(name: "copy-clipboard") { [weak self] in 22 | guard let self = self else { return } 23 | self.copyClipboard?(self) 24 | } 25 | addSignal(name: "cut-clipboard") { [weak self] in 26 | guard let self = self else { return } 27 | self.cutClipboard?(self) 28 | } 29 | addSignal(name: "paste-clipboard") { [weak self] in 30 | guard let self = self else { return } 31 | self.pasteClipboard?(self) 32 | } 33 | 34 | addSignal(name: "insert-at-cursor") { [weak self] (pointer: UnsafeMutableRawPointer) in 35 | guard let self = self else { return } 36 | let pointer = UnsafeRawPointer(pointer).bindMemory(to: CChar.self, capacity: 1) 37 | let string = String(cString: pointer) 38 | self.insertAtCursor?(self, string) 39 | } 40 | 41 | addSignal(name: "preedit-changed") { [weak self] (pointer: UnsafeMutableRawPointer) in 42 | guard let self = self else { return } 43 | let pointer = UnsafeRawPointer(pointer).bindMemory(to: CChar.self, capacity: 1) 44 | let string = String(cString: pointer) 45 | self.preeditChanged?(self, string) 46 | } 47 | 48 | addSignal(name: "select-all") { [weak self] (pointer: UnsafeMutableRawPointer) in 49 | guard let self = self else { return } 50 | // We need to get actual value of the pointer because it is not pointer but only integer. 51 | let select = Int(bitPattern: pointer).toBool() 52 | self.selectAll?(self, select) 53 | } 54 | } 55 | 56 | public var editable: Bool { 57 | get { 58 | return gtk_text_view_get_editable(castedPointer()).toBool() 59 | } 60 | set { 61 | gtk_text_view_set_editable(castedPointer(), newValue.toGBoolean()) 62 | } 63 | } 64 | 65 | // MARK: - Signals 66 | 67 | public var backspace: ((TextView) -> Void)? 68 | public var pasteClipboard: ((TextView) -> Void)? 69 | public var cutClipboard: ((TextView) -> Void)? 70 | public var copyClipboard: ((TextView) -> Void)? 71 | public var selectAll: ((TextView, Bool) -> Void)? 72 | public var preeditChanged: ((TextView, String) -> Void)? 73 | public var insertAtCursor: ((TextView, String) -> Void)? 74 | } 75 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/ToggleButton.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2017 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | public class ToggleButton: Button { 8 | public override init() { 9 | super.init() 10 | 11 | widgetPointer = gtk_toggle_button_new() 12 | } 13 | 14 | public override init(label: String) { 15 | super.init() 16 | 17 | widgetPointer = gtk_toggle_button_new_with_label(label) 18 | } 19 | 20 | public init(mnemonicLabel label: String) { 21 | super.init() 22 | 23 | widgetPointer = gtk_toggle_button_new_with_mnemonic(label) 24 | } 25 | 26 | override func didMoveToParent() { 27 | super.didMoveToParent() 28 | 29 | addSignal(name: "toggled") { [weak self] in 30 | guard let self = self else { return } 31 | self.toggled?(self) 32 | } 33 | } 34 | 35 | public var mode: Bool { 36 | get { 37 | return gtk_toggle_button_get_mode(castedPointer()).toBool() 38 | } 39 | set { 40 | gtk_toggle_button_set_mode(castedPointer(), newValue.toGBoolean()) 41 | } 42 | } 43 | 44 | public var active: Bool { 45 | get { 46 | return gtk_toggle_button_get_active(castedPointer()).toBool() 47 | } 48 | set { 49 | gtk_toggle_button_set_active(castedPointer(), newValue.toGBoolean()) 50 | } 51 | } 52 | 53 | public var inconsistent: Bool { 54 | get { 55 | return gtk_toggle_button_get_inconsistent(castedPointer()).toBool() 56 | } 57 | set { 58 | gtk_toggle_button_set_inconsistent(castedPointer(), newValue.toGBoolean()) 59 | } 60 | } 61 | 62 | public var toggled: ((ToggleButton) -> Void)? 63 | } 64 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/UnsafePointerGChar+ToString.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2017 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | extension UnsafePointer where Pointee == gchar { 8 | func toString() -> String { 9 | return String(cString: self) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Value.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2016 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | // This is from GLib and one day could be moved to GLib binding. It also not very perfect because original GValue heavily depends on macros that are not available in Swift. It might be best to introduce Object superclass and define these methods on it. 8 | 9 | func getProperty(_ pointer: UnsafeMutablePointer?, name: String) -> Bool { 10 | var v = GValue() 11 | let type = GType(5 << G_TYPE_FUNDAMENTAL_SHIFT) 12 | let value = g_value_init(&v, type) 13 | g_object_get_property(UnsafeMutablePointer(pointer), name, value) 14 | return g_value_get_boolean(value).toBool() 15 | } 16 | 17 | func setProperty(_ pointer: UnsafeMutablePointer?, name: String, newValue: Bool) { 18 | var v = GValue() 19 | let type = GType(5 << G_TYPE_FUNDAMENTAL_SHIFT) 20 | let value = g_value_init(&v, type) 21 | g_value_set_boolean(value, newValue.toGBoolean()) 22 | g_object_set_property(UnsafeMutablePointer(pointer), name, value) 23 | } 24 | 25 | func getProperty(_ pointer: UnsafeMutablePointer?, name: String) -> Int { 26 | var v = GValue() 27 | let type = GType(6 << G_TYPE_FUNDAMENTAL_SHIFT) 28 | let value = g_value_init(&v, type) 29 | g_object_get_property(UnsafeMutablePointer(pointer), name, value) 30 | return Int(g_value_get_int(value)) 31 | } 32 | 33 | func setProperty(_ pointer: UnsafeMutablePointer?, name: String, newValue: Int) { 34 | var v = GValue() 35 | let type = GType(6 << G_TYPE_FUNDAMENTAL_SHIFT) 36 | let value = g_value_init(&v, type) 37 | g_value_set_int(value, gint(newValue)) 38 | g_object_set_property(UnsafeMutablePointer(pointer), name, value) 39 | } 40 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Viewport.swift: -------------------------------------------------------------------------------- 1 | import CGtk 2 | 3 | public class Viewport: Bin { 4 | public override init() { 5 | super.init() 6 | widgetPointer = gtk_viewport_new(nil, nil) 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Widget+CastedPointer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2017 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import Foundation 6 | 7 | extension Widget { 8 | func castedPointer() -> UnsafeMutablePointer? { 9 | return widgetPointer?.cast() 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Widget.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import Foundation 6 | import CGtk 7 | 8 | open class Widget { 9 | private var signals: [(UInt, Any)] = [] 10 | var widgetPointer: UnsafeMutablePointer? 11 | 12 | public weak var parentWidget: Widget? { 13 | willSet { 14 | 15 | } 16 | didSet { 17 | if parentWidget != nil { 18 | didMoveToParent() 19 | } else { 20 | didMoveFromParent() 21 | removeSignals() 22 | } 23 | } 24 | } 25 | 26 | init() { 27 | widgetPointer = nil 28 | } 29 | 30 | private func removeSignals() { 31 | for (handlerId, _) in signals { 32 | disconnectSignal(widgetPointer, handlerId: handlerId) 33 | } 34 | 35 | signals = [] 36 | } 37 | 38 | func didMoveToParent() { 39 | 40 | } 41 | 42 | func didMoveFromParent() { 43 | 44 | } 45 | 46 | /// Adds a signal that is not carrying any additional information. 47 | func addSignal(name: String, callback: @escaping SignalCallbackZero) { 48 | let box = SignalBoxZero(callback: callback) 49 | let handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void = { sender, data in 50 | let box = unsafeBitCast(data, to: SignalBoxZero.self) 51 | box.callback() 52 | } 53 | 54 | let handlerId = connectSignal(widgetPointer, name: name, data: Unmanaged.passUnretained(box).toOpaque(), handler: unsafeBitCast(handler, to: GCallback.self)) 55 | 56 | signals.append((handlerId, box)) 57 | } 58 | 59 | func addSignal(name: String, callback: @escaping SignalCallbackOne) { 60 | let box = SignalBoxOne(callback: callback) 61 | let handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void = { sender, pointer, data in 62 | let box = unsafeBitCast(data, to: SignalBoxOne.self) 63 | box.callback(pointer) 64 | } 65 | 66 | let handlerId = connectSignal(widgetPointer, name: name, data: Unmanaged.passUnretained(box).toOpaque(), handler: unsafeBitCast(handler, to: GCallback.self)) 67 | 68 | signals.append((handlerId, box)) 69 | } 70 | 71 | func addSignal(name: String, callback: @escaping SignalCallbackTwo) { 72 | let box = SignalBoxTwo(callback: callback) 73 | let handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void = { sender, pointer1, pointer2, data in 74 | let box = unsafeBitCast(data, to: SignalBoxTwo.self) 75 | box.callback(pointer1, pointer2) 76 | } 77 | 78 | let handlerId = connectSignal(widgetPointer, name: name, data: Unmanaged.passUnretained(box).toOpaque(), handler: unsafeBitCast(handler, to: GCallback.self)) 79 | 80 | signals.append((handlerId, box)) 81 | } 82 | 83 | func addSignal(name: String, callback: @escaping SignalCallbackThree) { 84 | let box = SignalBoxThree(callback: callback) 85 | let handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void = { sender, pointer1, pointer2, pointer3, data in 86 | let box = unsafeBitCast(data, to: SignalBoxThree.self) 87 | box.callback(pointer1, pointer2, pointer3) 88 | } 89 | 90 | let handlerId = connectSignal(widgetPointer, name: name, data: Unmanaged.passUnretained(box).toOpaque(), handler: unsafeBitCast(handler, to: GCallback.self)) 91 | 92 | signals.append((handlerId, box)) 93 | } 94 | 95 | func addSignal(name: String, callback: @escaping SignalCallbackFour) { 96 | let box = SignalBoxFour(callback: callback) 97 | let handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void = { sender, pointer1, pointer2, pointer3, pointer4, data in 98 | let box = unsafeBitCast(data, to: SignalBoxFour.self) 99 | box.callback(pointer1, pointer2, pointer3, pointer4) 100 | } 101 | 102 | let handlerId = connectSignal(widgetPointer, name: name, data: Unmanaged.passUnretained(box).toOpaque(), handler: unsafeBitCast(handler, to: GCallback.self)) 103 | 104 | signals.append((handlerId, box)) 105 | } 106 | 107 | func addSignal(name: String, callback: @escaping SignalCallbackFive) { 108 | let box = SignalBoxFive(callback: callback) 109 | let handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void = { sender, pointer1, pointer2, pointer3, pointer4, pointer5, data in 110 | let box = unsafeBitCast(data, to: SignalBoxFive.self) 111 | box.callback(pointer1, pointer2, pointer3, pointer4, pointer5) 112 | } 113 | 114 | let handlerId = connectSignal(widgetPointer, name: name, data: Unmanaged.passUnretained(box).toOpaque(), handler: unsafeBitCast(handler, to: GCallback.self)) 115 | 116 | signals.append((handlerId, box)) 117 | } 118 | 119 | func addSignal(name: String, callback: @escaping SignalCallbackSix) { 120 | let box = SignalBoxSix(callback: callback) 121 | let handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void = { sender, pointer1, pointer2, pointer3, pointer4, pointer5, pointer6, data in 122 | let box = unsafeBitCast(data, to: SignalBoxSix.self) 123 | box.callback(pointer1, pointer2, pointer3, pointer4, pointer5, pointer6) 124 | } 125 | 126 | let handlerId = connectSignal(widgetPointer, name: name, data: Unmanaged.passUnretained(box).toOpaque(), handler: unsafeBitCast(handler, to: GCallback.self)) 127 | 128 | signals.append((handlerId, box)) 129 | } 130 | 131 | public func setForegroundColor(color: Color) { 132 | let className = String("class-\(UUID().uuidString)").replacingOccurrences(of: "-", with: "_") 133 | gtk_style_context_add_class( 134 | gtk_widget_get_style_context(widgetPointer), 135 | className 136 | ) 137 | 138 | let css = ".\(className){color:rgba(\(color.red*255),\(color.green*255),\(color.blue*255),\(color.alpha*255));}" 139 | let provider = CssProvider() 140 | try! provider.loadFromData(css) 141 | addCssProvider(provider) 142 | } 143 | 144 | public func addCssProvider(_ provider: CssProvider) { 145 | gtk_style_context_add_provider( 146 | gtk_widget_get_style_context(widgetPointer), 147 | OpaquePointer(provider.pointer), 148 | UInt32(GTK_STYLE_PROVIDER_PRIORITY_APPLICATION) 149 | ) 150 | } 151 | 152 | public func showAll() { 153 | gtk_widget_show_all(widgetPointer) 154 | } 155 | 156 | public func showNow() { 157 | gtk_widget_show_now(widgetPointer) 158 | } 159 | 160 | public func show() { 161 | gtk_widget_show(widgetPointer) 162 | } 163 | 164 | public func hide() { 165 | gtk_widget_hide(widgetPointer) 166 | } 167 | 168 | public var opacity: Double { 169 | get { 170 | return gtk_widget_get_opacity(widgetPointer) 171 | } 172 | set { 173 | gtk_widget_set_opacity(widgetPointer, newValue) 174 | } 175 | } 176 | 177 | public var topMargin: Int { 178 | get { 179 | return Int(gtk_widget_get_margin_top(widgetPointer)) 180 | } 181 | set { 182 | gtk_widget_set_margin_top(widgetPointer, gint(newValue)) 183 | } 184 | } 185 | 186 | public var bottomMargin: Int { 187 | get { 188 | return Int(gtk_widget_get_margin_bottom(widgetPointer)) 189 | } 190 | set { 191 | gtk_widget_set_margin_bottom(widgetPointer, gint(newValue)) 192 | } 193 | } 194 | 195 | public var leftMargin: Int { 196 | get { 197 | return Int(gtk_widget_get_margin_start(widgetPointer)) 198 | } 199 | set { 200 | gtk_widget_set_margin_start(widgetPointer, gint(newValue)) 201 | } 202 | } 203 | 204 | public var rightMargin: Int { 205 | get { 206 | return Int(gtk_widget_get_margin_end(widgetPointer)) 207 | } 208 | set { 209 | gtk_widget_set_margin_end(widgetPointer, gint(newValue)) 210 | } 211 | } 212 | 213 | public var horizontalAlignment: Align { 214 | get { 215 | return gtk_widget_get_halign(castedPointer()).toAlign() 216 | } 217 | set { 218 | gtk_widget_set_halign(castedPointer(), newValue.toGtkAlign()) 219 | } 220 | } 221 | 222 | public var verticalAlignment: Align { 223 | get { 224 | return gtk_widget_get_valign(castedPointer()).toAlign() 225 | } 226 | set { 227 | gtk_widget_set_valign(castedPointer(), newValue.toGtkAlign()) 228 | } 229 | } 230 | 231 | public var expandHorizontally: Bool { 232 | get { 233 | return gtk_widget_get_hexpand(castedPointer()) != 0 234 | } 235 | set { 236 | gtk_widget_set_hexpand(castedPointer(), newValue ? 1 : 0) 237 | } 238 | } 239 | 240 | public var expandVertically: Bool { 241 | get { 242 | return gtk_widget_get_vexpand(castedPointer()) != 0 243 | } 244 | set { 245 | gtk_widget_set_vexpand(castedPointer(), newValue ? 1 : 0) 246 | } 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /Sources/SwiftGtk/Window.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2015 Tomas Linhart. All rights reserved. 3 | // 4 | 5 | import CGtk 6 | 7 | public class Window: Bin { 8 | public enum WindowType { 9 | case topLevel 10 | case popUp 11 | 12 | fileprivate func toGtkWindowType() -> GtkWindowType { 13 | switch self { 14 | case .topLevel: 15 | return GTK_WINDOW_TOPLEVEL 16 | case .popUp: 17 | return GTK_WINDOW_POPUP 18 | } 19 | } 20 | } 21 | 22 | public init(windowType: WindowType = .topLevel) { 23 | super.init() 24 | widgetPointer = gtk_window_new(windowType.toGtkWindowType()) 25 | } 26 | 27 | private init(pointer: UnsafeMutablePointer) { 28 | super.init() 29 | self.widgetPointer = pointer 30 | } 31 | 32 | public static var rootWindow: Window { 33 | return Window(pointer: UnsafeMutablePointer(gdk_screen_get_root_window(gdk_screen_get_default()))) 34 | } 35 | 36 | public var title: String? { 37 | get { 38 | return String(cString: gtk_window_get_title(castedPointer())) 39 | } 40 | set { 41 | if let title = newValue { 42 | gtk_window_set_title(castedPointer(), title) 43 | } else { 44 | gtk_window_set_title(castedPointer(), nil) 45 | } 46 | } 47 | } 48 | 49 | public var defaultSize: Size { 50 | get { 51 | var width: gint = 0 52 | var height: gint = 0 53 | gtk_window_get_default_size(castedPointer(), &width, &height) 54 | 55 | return Size(width: Int(width), height: Int(height)) 56 | } 57 | set (size) { 58 | gtk_window_set_default_size(castedPointer(), gint(size.width), gint(size.height)) 59 | } 60 | } 61 | 62 | public var resizable: Bool { 63 | get { 64 | return gtk_window_get_resizable(castedPointer()).toBool() 65 | } 66 | set { 67 | gtk_window_set_resizable(castedPointer(), newValue.toGBoolean()) 68 | } 69 | } 70 | 71 | public var hideTitlebarWhenMaximized: Bool { 72 | get { return gtk_window_get_hide_titlebar_when_maximized(castedPointer()).toBool() } 73 | set { gtk_window_set_hide_titlebar_when_maximized(castedPointer(), newValue.toGBoolean()) } 74 | } 75 | 76 | private var _titleBar: Widget? 77 | public var titlebar: Widget? { 78 | get { return _titleBar } 79 | set { gtk_window_set_titlebar(castedPointer(), newValue?.widgetPointer) } 80 | } 81 | } 82 | --------------------------------------------------------------------------------