Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #558 from JuliaGraphics/text_window_bindings
Browse files Browse the repository at this point in the history
Added miscellaneous text and window related bindings
  • Loading branch information
jonathanBieler authored Jun 24, 2021
2 parents 62d3e73 + 40565e3 commit 4a24142
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/gdk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,13 @@ function screen_size(screen::Ptr{Nothing})
return (ccall((:gdk_screen_get_width, libgdk), Cint, (Ptr{Nothing},), screen),
ccall((:gdk_screen_get_height, libgdk), Cint, (Ptr{Nothing},), screen))
end

function get_origin(window)
window_x, window_y = mutable(Cint), mutable(Cint)
ccall(
(:gdk_window_get_origin, libgdk), Cint,
(Ptr{GObject}, Ptr{Cint}, Ptr{Cint}),
window, window_x, window_y
)
return (window_x[], window_y[])
end
36 changes: 32 additions & 4 deletions src/lists.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,14 @@ function iter_n_children(treeModel::GtkTreeModel, iter::TRI)
ret
end


## update iter pointing to nth child n in 1:nchildren)
## As a special case, if parent is NULL, then the n-th root node is set
## return boolean
function iter_nth_child(treeModel::GtkTreeModel, iter::Mutable{GtkTreeIter}, piter::TRI, n::Int)
function iter_nth_child(treeModel::GtkTreeModel, iter::Mutable{GtkTreeIter}, parent_iter::Union{TRI, Nothing}, n::Int)
parent_iter = isnothing(parent_iter) ? C_NULL : mutable(parent_iter)
ret = ccall((:gtk_tree_model_iter_nth_child, libgtk), Cint,
(Ptr{GObject}, Ptr{GtkTreeIter}, Ptr{GtkTreeIter}, Cint),
treeModel, iter, mutable(piter), n - 1) # 0-based
treeModel, iter, parent_iter, n - 1) # 0-based
ret != 0
end

Expand Down Expand Up @@ -699,17 +700,44 @@ function push!(treeView::GtkTreeView, treeColumns::GtkTreeViewColumn...)
end
treeView
end

function insert!(treeView::GtkTreeView, index::Integer, treeColumn::GtkTreeViewColumn)
ccall((:gtk_tree_view_insert_column, libgtk), Nothing, (Ptr{GObject}, Ptr{GObject}, Cint), treeView, treeColumn, index - 1)
treeView
end

function delete!(treeView::GtkTreeView, treeColumns::GtkTreeViewColumn...)
for col in treeColumns
ccall((:gtk_tree_view_remove_column, libgtk), Nothing, (Ptr{GObject}, Ptr{GObject}), treeView, col)
end
treeView
end

function expand_to_path(tree_view::GtkTreeView, path::GtkTreePath)
return ccall(
(:gtk_tree_view_expand_to_path, libgtk), Cvoid,
(Ptr{GObject}, Ptr{GtkTreePath}), tree_view, path
)
end

function treepath(path::AbstractString)
ptr = ccall(
(:gtk_tree_path_new_from_string, libgtk), Ptr{GtkTreePath},
(Ptr{UInt8},), bytestring(path)
)
return ptr == C_NULL ? GtkTreePath() : convert(GtkTreePath, ptr)
end

# There's a method wrapped in GAccessor but tries to convert to a GtkTreeModel, which
# is an interface in Gtk
function model(tree_view::GtkTreeView)
return convert(GtkTreeStore, ccall(
(:gtk_tree_view_get_model, Gtk.libgtk),
Ptr{Gtk.GObject},
(Ptr{Gtk.GObject},),
tree_view)
)
end

# TODO Use internal accessor with default values?
function path_at_pos(treeView::GtkTreeView, x::Integer, y::Integer)
Expand All @@ -721,7 +749,7 @@ function path_at_pos(treeView::GtkTreeView, x::Integer, y::Integer)
if ret
path = GtkTreePath(pathPtr[], true)
else
path = GtkTreePath()
path = GtkTreePath()
end
ret, path
end
Expand Down
63 changes: 63 additions & 0 deletions src/text.jl
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,69 @@ function scroll_to(view::GtkTextView, iter::TI, within_margin::Real,
view, iter, within_margin, use_align, xalign, yalign)
end


"""
buffer_to_window_coords(view::GtkTextView, buffer_x::Integer, buffer_y::Integer, wintype::Integer = 0)
Implements `gtk_text_view_buffer_to_window_coords`.
"""
function buffer_to_window_coords(view::GtkTextView, buffer_x::Integer, buffer_y::Integer, wintype::Integer = 0)
window_x, window_y = Gtk.mutable(Cint), Gtk.mutable(Cint)
ccall(
(:gtk_text_view_buffer_to_window_coords, libgtk), Cvoid,
(Ptr{Gtk.GObject}, Cint, Cint, Cint, Ptr{Cint}, Ptr{Cint}),
view, Int32(wintype), buffer_x, buffer_y, window_x, window_y
)
return (window_x[], window_y[])
end

"""
window_to_buffer_coords(view::Gtk.GtkTextView, window_x::Integer, window_y::Integer, wintype::Integer = 2)
Implements `gtk_text_view_window_to_buffer_coords`.
"""
function window_to_buffer_coords(view::GtkTextView, window_x::Integer, window_y::Integer, wintype::Integer = 2)
buffer_x, buffer_y = Gtk.mutable(Cint), Gtk.mutable(Cint)
ccall(
(:gtk_text_view_window_to_buffer_coords, libgtk), Cvoid,
(Ptr{GObject}, Cint, Cint, Cint, Ptr{Cint}, Ptr{Cint}),
view, Int32(wintype), window_x, window_y, buffer_x, buffer_y
)
return (buffer_x[],buffer_y[])
end

"""
text_iter_at_position(view::GtkTextView, x::Integer, y::Integer)
Implements `gtk_text_view_get_iter_at_position`.
"""
function text_iter_at_position(view::GtkTextView, x::Integer, y::Integer)
buffer = view.buffer[GtkTextBuffer]
iter = mutable(GtkTextIter(buffer))
text_iter_at_position(view, iter, C_NULL, Int32(x), Int32(y))
return GtkTextIter(buffer, char_offset(iter))
end

text_iter_at_position(view::GtkTextView, iter::Mutable{GtkTextIter}, trailing, x::Int32, y::Int32) = ccall(
(:gtk_text_view_get_iter_at_position, libgtk), Cvoid,
(Ptr{GObject}, Ptr{GtkTextIter}, Ptr{Cint}, Cint, Cint),
view, iter, trailing, x, y
)

function cursor_locations(view::GtkTextView)
weak = Gtk.mutable(GdkRectangle)
strong = Gtk.mutable(GdkRectangle)
buffer = view.buffer[GtkTextBuffer]
iter = mutable(GtkTextIter(buffer, buffer.cursor_position[Int]))

ccall(
(:gtk_text_view_get_cursor_locations, libgtk), Cvoid,
(Ptr{GObject}, Ptr{GtkTextIter}, Ptr{Gtk.GdkRectangle}, Ptr{GdkRectangle}),
view, iter, strong, weak
)
return (iter, strong[], weak[])
end

#### GtkTextMark ####

visible(w::GtkTextMark) =
Expand Down
32 changes: 27 additions & 5 deletions src/theme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ function GtkCssProviderLeaf(; data = nothing, filename = nothing)
provider = GtkCssProviderLeaf(ccall((:gtk_css_provider_new, libgtk), Ptr{GObject}, ()))
if data !== nothing
GError() do error_check
ccall((:gtk_css_provider_load_from_data, libgtk), Bool,
ccall((:gtk_css_provider_load_from_data, libgtk), Bool,
(Ptr{GObject}, Ptr{UInt8}, Clong, Ptr{Ptr{GError}}),
provider, bytestring(data), -1, error_check)
end
elseif filename !== nothing
GError() do error_check
ccall((:gtk_css_provider_load_from_path, libgtk), Bool,
ccall((:gtk_css_provider_load_from_path, libgtk), Bool,
(Ptr{GObject}, Ptr{UInt8}, Ptr{Ptr{GError}}),
provider, bytestring(filename), error_check)
end
Expand All @@ -22,6 +22,28 @@ end

GtkStyleContextLeaf() = GtkStyleContextLeaf(ccall((:gtk_style_context_new, libgtk), Ptr{GObject}, ()))

push!(context::GtkStyleContext, provider::GObject, priority::Integer) =
ccall((:gtk_style_context_add_provider, libgtk), Nothing, (Ptr{GObject}, Ptr{GObject}, Cuint),
context, provider, priority)
push!(context::GtkStyleContext, provider::GObject, priority::Integer) = ccall(
(:gtk_style_context_add_provider, libgtk), Nothing, (Ptr{GObject}, Ptr{GObject}, Cuint),
context, provider, priority
)

icon_theme_get_default() = ccall((:gtk_icon_theme_get_default, Gtk.libgtk), Ptr{GObject}, ())

icon_theme_append_search_path(icon_theme, path::AbstractString) = ccall(
(:gtk_icon_theme_append_search_path, libgtk), Cvoid, (Ptr{GObject}, Ptr{UInt8}),
icon_theme, path
)

function icon_theme_load_icon_for_scale(icon_theme, icon_name::AbstractString, size::Integer, scale::Integer, flags::Integer)
local pixbuf::Ptr{GObject}
Gtk.GError() do error_check
pixbuf = ccall(
(:gtk_icon_theme_load_icon_for_scale, libgtk),
Ptr{GObject},
(Ptr{GObject}, Ptr{UInt8}, Cint, Cint, Cint, Ptr{Ptr{GError}}),
icon_theme, bytestring(icon_name), size, scale, flags, error_check
)
return pixbuf !== C_NULL
end
return convert(GdkPixbuf, pixbuf)
end

0 comments on commit 4a24142

Please sign in to comment.