Skip to content

Commit

Permalink
GtkTextView: use pointer or Ref instead of _GtkTextIter struct (break…
Browse files Browse the repository at this point in the history
…ing) (#62)

* GtkTextView: use pointer or ref instead of _GtkTextIter struct

This is more consistent with everything else in the package

* random stuff

* support adding widgets to gutter

* fix GtkTextIter auto-generated methods, better support methods for all non-opaque structs
  • Loading branch information
jwahlstrand authored Jul 6, 2024
1 parent 3f03536 commit 68ad832
Show file tree
Hide file tree
Showing 39 changed files with 3,055 additions and 2,134 deletions.
6 changes: 6 additions & 0 deletions GI/src/giexport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ function struct_exprs!(exprs,exports,ns,structs=nothing;print_summary=true,exclu
end
push!(exports.args, get_full_name(ssi))
length(fields)>0 && push!(exports.args,get_struct_name(ssi,false))
if length(fields)>0 && !in(name, import_as_opaque)
push!(exports.args, structptrlike(ssi))
end
end

if print_summary
Expand Down Expand Up @@ -168,6 +171,9 @@ function all_struct_exprs!(exprs,exports,ns;print_summary=true,excludelist=[],co

push!(exprs, decl(ssi,in(name,import_as_opaque)))
push!(exports.args, get_full_name(ssi))
if length(fields)>0
push!(exports.args, structptrlike(ssi))
end
push!(loaded, name)
length(fields)>0 && push!(exports.args,get_struct_name(ssi,false))
end
Expand Down
13 changes: 10 additions & 3 deletions GI/src/giimport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function decl(structinfo::GIStructInfo,force_opaque=false)
end
end
conv=nothing
structlike = Symbol(gstructname,:Like)
if !opaque
fieldsexpr=Expr[]
for field in get_fields(structinfo)
Expand All @@ -125,6 +126,11 @@ function decl(structinfo::GIStructInfo,force_opaque=false)
conv = quote
unsafe_convert(::Type{Ptr{$ustructname}}, box::$gstructname) = convert(Ptr{$ustructname}, box.handle)
convert(::Type{$gstructname}, p::Ptr{$ustructname}, owns = false) = $gstructname(p, owns)
const $structlike = Union{Ref{$ustructname},$gstructname}
end
else
conv = quote
const $structlike = $gstructname
end
end
decl = isboxed ? :($gstructname <: GBoxed) : gstructname
Expand Down Expand Up @@ -501,12 +507,13 @@ function typename(info::GIStructInfo)
Symbol(GLib.g_type_name(g_type))
end
end
structptrlike(info::GIStructInfo) = Symbol(get_full_name(info),:Like)
function extract_type(typeinfo::GITypeInfo, info::GIStructInfo)
name = typename(info)
sname = get_struct_name(info)
if is_pointer(typeinfo)
fname = get_full_name(info)
tname = isopaque(info) ? fname : :(Union{$fname,Ref{$sname}})
tname = isopaque(info) ? fname : structptrlike(info)
TypeDesc(info,tname,typename(info),:(Ptr{$sname}))
else
TypeDesc(info,sname,sname,sname)
Expand All @@ -517,7 +524,7 @@ function extract_type(typeinfo::Type{InstanceType}, info::GIStructInfo)
sname = get_struct_name(info)
if is_pointer(typeinfo)
fname = get_full_name(info)
tname = isopaque(info) ? fname : :(Union{$fname,Ref{$sname}})
tname = isopaque(info) ? fname : structptrlike(info)
TypeDesc(info,tname,typename(info),:(Ptr{$sname}))
else
TypeDesc(info,sname,sname,sname)
Expand Down Expand Up @@ -801,7 +808,7 @@ function extract_type(typeinfo::GITypeInfo, basetype::Type{T}) where {T<:GBoxed}
name = get_full_name(interf_info)
sname = get_struct_name(interf_info)
p = is_pointer(typeinfo)
jarg = (name != sname ? :(Union{$name,Ref{$sname}}) : name)
jarg = (name != sname ? structptrlike(interf_info) : name)
ctype = is_pointer(typeinfo) ? :(Ptr{$sname}) : sname
TypeDesc{Type{GBoxed}}(GBoxed, jarg, name, ctype)
end
Expand Down
2 changes: 1 addition & 1 deletion examples/HDF5Viewer/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"

[compat]
Gtk4 = "0.6"
Gtk4 = "0.7"

2 changes: 1 addition & 1 deletion gen/gen_gio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object_method_skiplist=[:new_for_bus,:export,:add_option_group,:make_pollfd,:get
:new_for_bus_sync,:new_sync,:writev,:writev_all,:flatten_tree,:changed_tree,:receive_messages,:send_message,:send_message_with_timeout,:send_messages,
:get_channel_binding_data,:lookup_certificates_issued_by,:get_default,:get_unix_fd_list,:set_unix_fd_list,:get_attribute_file_path,:set_attribute_file_path,:get_timeout,:set_timeout]

object_skiplist=vcat(obj_skiplist,[:AppInfoMonitor,:DBusConnection,:DBusMenuModel,:DBusProxy,:DBusMethodInvocation,:IOModule,:SimpleProxyResolver,:UnixMountMonitor,:Task])
object_skiplist=vcat(obj_skiplist,[:AppInfoMonitor,:DBusConnection,:DBusMenuModel,:DBusProxy,:DBusMethodInvocation,:IOModule,:SimpleProxyResolver,:UnixMountMonitor])

interface_method_skiplist=[:add_action_entries,:get_info,:receive_messages,:send_messages,
:writev_nonblocking,:dup_default,:remove_action_entries,:new_build_filenamev]
Expand Down
2 changes: 1 addition & 1 deletion gen/gen_gtk4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ skiplist=[:create_closure,:activate_cell,:event,:start_editing,:filter_keypress,

object_skiplist=vcat(object_skiplist,[:CellRenderer,:MnemonicAction,:NeverTrigger,:NothingAction,:PrintJob,:PrintSettings,:RecentManager])

GI.export_methods!(ns,path,"gtk4"; exclude_deprecated = false, object_method_skiplist = skiplist, object_skiplist = object_skiplist, interface_method_skiplist = [:start_editing, :install_properties], interface_skiplist = [:PrintOperationPreview], struct_skiplist = vcat(struct_skiplist,[:Bitset,:BitsetIter,:BuildableParseContext,:CssSection,:TextIter]))
GI.export_methods!(ns,path,"gtk4"; exclude_deprecated = false, object_method_skiplist = skiplist, object_skiplist = object_skiplist, interface_method_skiplist = [:start_editing, :install_properties], interface_skiplist = [:PrintOperationPreview], struct_skiplist = vcat(struct_skiplist,[:Bitset,:BitsetIter,:BuildableParseContext,:CssSection]))

skiplist=[:editable_install_properties,:ordering_from_cmpfunc,:value_set_expression,:value_take_expression]

Expand Down
2 changes: 1 addition & 1 deletion src/GLib/GLib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export gtkdoc_const_url, gtkdoc_enum_url, gtkdoc_flags_url, gtkdoc_method_url,
gtkdoc_func_url, gtkdoc_struc_url

export gtype_wrappers, GVariantDict, GBytes, GVariantType
export GValue, GParamSpec, GTypeModule, _GValue
export GValue, GParamSpec, GTypeModule, _GValue, GValueLike

Maybe(T) = Union{T,Nothing}

Expand Down
2 changes: 2 additions & 0 deletions src/GLib/gerror.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ end

GErrorException(err::GError) = GErrorException(err.domain, err.code, message(err))

GError(e::GErrorException) = GError(e.domain, e.code, Base.unsafe_convert(Cstring,e.message))

function check_err(err::Base.RefValue{Ptr{GError}})
if err[] != C_NULL
gerror = GError(err[])
Expand Down
12 changes: 11 additions & 1 deletion src/GLib/gtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ _gc_unref(@nospecialize(x), ::Ptr{Nothing}) = gc_unref(x)
gc_ref_closure(@nospecialize(cb::Function)) = (invoke(gc_ref, Tuple{Any}, cb), @cfunction(_gc_unref, Nothing, (Any, Ptr{Nothing})))
gc_ref_closure(x::T) where {T} = (gc_ref(x), @cfunction(_gc_unref, Nothing, (Any, Ptr{Nothing})))

# GLib ref/unref functions -- generally, you shouldn't be calling these
"""
glib_ref(x::Ptr)
Increments the reference count of a pointer managed by a GLib based library. Generally this function will just call a C function, e.g. `g_object_ref`. Most users will not ever need to use this function.
"""
function glib_ref(x::Ptr{GObject})
ccall((:g_object_ref, libgobject), Nothing, (Ptr{GObject},), x)
end
Expand All @@ -234,6 +238,12 @@ function glib_ref(x::GObject)
end
glib_ref(::Nothing) = nothing
gc_unref(p::Ptr{GObject}) = glib_unref(p)

"""
glib_unref(x::Ptr)
Decrements the reference count of a pointer managed by a GLib based library. Generally this function will just call a C function, e.g. `g_object_unref`. Most users will not ever need to use this function.
"""
function glib_unref(x::Ptr{GObject})
ccall((:g_object_unref, libgobject), Nothing, (Ptr{GObject},), x)
end
Expand Down
1 change: 1 addition & 0 deletions src/GLib/gvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct GValue
field3::UInt64
GValue() = new(0, 0, 0)
end
const GValueLike = Union{Ref{GValue},GValue}
# This should be a subtype of GBoxed and the above struct should be renamed to _GValue to be consistent with other boxed types
const _GValue = GValue
Base.zero(::Type{GValue}) = GValue()
Expand Down
15 changes: 15 additions & 0 deletions src/displays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,22 @@ pulse(progress::GtkProgressBar) = G_.pulse(progress)

## GtkSpinner

"""
start(spinner::GtkSpinner)
Start a GtkSpinner widget spinning. The purpose of this widget is to show that some operation is in process.
Related GTK function: [`gtk_spinner_start`()]($(gtkdoc_method_url("gtk4","Spinner","start")))
"""
start(spinner::GtkSpinner) = G_.start(spinner)

"""
stop(spinner::GtkSpinner)
Stop a GtkSpinner. The purpose of this widget is to show that some operation is in process.
Related GTK function: [`gtk_spinner_stop`()]($(gtkdoc_method_url("gtk4","Spinner","stop")))
"""
stop(spinner::GtkSpinner) = G_.stop(spinner)

## GtkStatusbar
Expand Down
Loading

0 comments on commit 68ad832

Please sign in to comment.