Skip to content

Commit

Permalink
Merge pull request #226 from mcorino/develop
Browse files Browse the repository at this point in the history
Widgets sample
  • Loading branch information
mcorino committed Dec 13, 2023
2 parents 9d7f89b + 104d64c commit 21fd9c3
Show file tree
Hide file tree
Showing 278 changed files with 26,989 additions and 21,834 deletions.
18 changes: 18 additions & 0 deletions ext/wxruby3/include/wxruby-ClientData.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,22 @@ class WXRUBY_EXPORT wxRubyClientData : public wxClientData
VALUE rb_data;
};

class WXRUBY_EXPORT wxRubyUserData;

WXRUBY_EXPORT void wxRuby_RegisterUserData(wxRubyUserData* pud);
WXRUBY_EXPORT void wxRuby_UnregisterUserData(wxRubyUserData* pud);

class WXRUBY_EXPORT wxRubyUserData : public wxObject
{
public:
wxRubyUserData() : rb_data(Qnil) { }
wxRubyUserData (VALUE data) : rb_data(data) { wxRuby_RegisterUserData(this); }
virtual ~wxRubyUserData () { wxRuby_UnregisterUserData(this); }
VALUE GetData() const { return rb_data; }
private:
VALUE rb_data;

wxDECLARE_NO_COPY_CLASS(wxRubyUserData);
};

#endif /* _WXRUBY_CLIENT_DATA_H */
9 changes: 9 additions & 0 deletions lib/wx/core/controlwithitems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ class ControlWithItems
end
end

# define these aliases so controls like ComboBox and OwnerDrawnComboBox and the like all end up with
# similar methods

alias :get_list_selection :get_selection
alias :set_list_selection :set_selection

alias :get_list_string_selection :get_string_selection
alias :set_list_string_selection :set_string_selection

end

end
File renamed without changes.
3 changes: 1 addition & 2 deletions lib/wx/core/sizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class Wx::Sizer
ADD_ITEM_PARAMS = [ Wx::Parameter[ :index, -1 ],
Wx::Parameter[ :proportion, 0 ],
Wx::Parameter[ :flag, 0 ],
Wx::Parameter[ :border, 0 ],
Wx::Parameter[ :user_data, nil ] ]
Wx::Parameter[ :border, 0 ] ]

def add_item(item, *mixed_args)

Expand Down
22 changes: 22 additions & 0 deletions lib/wx/core/standard_paths.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2023 M.J.N. Corino, The Netherlands
#
# This software is released under the MIT license.


module Wx

class StandardPaths

class << self

wx_get = instance_method :get
define_method :get do
# cache the global singleton
@instance ||= wx_get.bind(self).call
end

end

end

end
5 changes: 4 additions & 1 deletion lib/wx/core/text_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ module TextEntry
wx_auto_complete = instance_method :auto_complete
define_method :auto_complete do |completer|
if wx_auto_complete.bind(self).call(completer)
@completer = completer # keep the Ruby object alive
@completer = completer.is_a?(Wx::TextCompleter) ? completer : nil # keep the Ruby object alive or cleanup
true
else
false
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/wx/doc/art_locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def add_search_path(*names) end
# @param [String,nil] art_path base path to look up the art file
# @param [String,nil] art_section optional owner folder name for art files
# @param [Wx::BitmapType,nil] bmp_type bitmap type of art file
# @return [String,nil] full path of art file or nil if not found
def find_art(art_name, art_type: nil, art_path: nil, art_section: nil, bmp_type: nil) end

end
Expand Down
8 changes: 8 additions & 0 deletions lib/wx/doc/controlwithitems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def each_string; end
def is_sorted; end
alias :sorted? :is_sorted

alias :get_list_selection :get_selection

alias :set_list_selection :set_selection

alias :get_list_string_selection :get_string_selection

alias :set_list_string_selection :set_string_selection

end

end
23 changes: 23 additions & 0 deletions lib/wx/doc/date_picker_ctrl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# :stopdoc:
# Copyright (c) 2023 M.J.N. Corino, The Netherlands
#
# This software is released under the MIT license.
# :startdoc:


module Wx

class DatePickerCtrl < Control

# If the control had been previously limited to a range of dates using #set_range, returns the lower and upper bounds of this range.
#
# If no range is set (or only one of the bounds is set), dt1 and/or dt2 are set to be invalid.
#
# Notice that when using a native MSW implementation of this control the lower range is always set, even
# if #set_range hadn't been called explicitly, as the native control only supports dates later than year 1601.
# @return [Array(Time, Time),nil] a set with the lower and upper range limit or nil if no range previously set
def get_range; end

end

end
44 changes: 44 additions & 0 deletions lib/wx/doc/editable_listbox.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# :stopdoc:
# Copyright (c) 2023 M.J.N. Corino, The Netherlands
#
# This software is released under the MIT license.
# :startdoc:


module Wx

class EditableListBox < Panel

# Returns list control of composite.
# @return [Wx::ListCtrl]
def get_list_ctrl; end
alias :list_ctrl :get_list_ctrl

# Returns button of composite.
# @return [Wx::BitmapButton]
def get_del_button; end
alias :del_button :get_del_button

# Returns button of composite.
# @return [Wx::BitmapButton]
def get_new_button; end
alias :new_button :get_new_button

# Returns button of composite.
# @return [Wx::BitmapButton]
def get_up_button; end
alias :up_button :get_up_button

# Returns button of composite.
# @return [Wx::BitmapButton]
def get_down_button; end
alias :down_button :get_down_button

# Returns button of composite.
# @return [Wx::BitmapButton]
def get_edit_button; end
alias :edit_button :get_edit_button

end

end
96 changes: 96 additions & 0 deletions lib/wx/doc/owner_drawn_combobox.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# :stopdoc:
# Copyright (c) 2023 M.J.N. Corino, The Netherlands
#
# This software is released under the MIT license.
# :startdoc:


module Wx

class OwnerDrawnComboBox

# Returns the label of the selected item or an empty string if no item is selected.
#
# @see Wx::OwnerDrawnComboBox#get_selection
# @return [String]
def get_list_string_selection; end
alias :list_string_selection :get_list_string_selection

# Selects the item with the specified string in the control.
#
# This method doesn't cause any command events to be emitted.
# Notice that this method is case-insensitive, i.e. the string is compared with all the elements of the control
# case-insensitively and the first matching entry is selected, even if it doesn't have exactly the same case as
# this string and there is an exact match afterwards.
#
# true if the specified string has been selected, false if it wasn't found in the control.
# @param string [String] The string to select.
# @return [Boolean]
def set_list_string_selection(string) end
alias :list_string_selection= :set_list_string_selection

# Returns the index of the selected item or {Wx::NOT_FOUND} if no item is selected.
#
# The position of the current selection.
# @see Wx::OwnerDrawnComboBox#set_list_selection
# @see Wx::OwnerDrawnComboBox#get_list_string_selection
# @return [Integer]
def get_list_selection; end
alias :list_selection :get_list_selection

# Sets the selection to the given item n or removes the selection entirely if n == {Wx::NOT_FOUND}.
#
# Note that this does not cause any command events to be emitted nor does it deselect any other items in the controls which support multiple selections.
# @see Wx::OwnerDrawnComboBox#set_string
# @see Wx::OwnerDrawnComboBox#set_list_string_selection
# @param n [Integer] The string position to select, starting from zero.
# @return [void]
def set_list_selection(n) end
alias :list_selection= :set_list_selection

# Returns the number of items in the control.
#
# @see Wx::OwnerDrawnComboBox#is_list_empty
# @return [Integer]
def get_count; end
alias_method :count, :get_count

# Returns the label of the item with the given index.
#
# The index must be valid, i.e. less than the value returned by {Wx::OwnerDrawnComboBox#get_count},
# otherwise an assert is triggered. Notably, this function can't be called if the control is empty.
#
# The label of the item.
# @param n [Integer] The zero-based index.
# @return [String]
def get_string(n) end
alias_method :string, :get_string

# Returns the array of the labels of all items in the control.
# @return [Array<String>]
def get_strings; end
alias_method :strings, :get_strings

# Sets the label for the given item.
# @param n [Integer] The zero-based item index.
# @param string [String] The label to set.
# @return [void]
def set_string(n, string) end

# Finds an item whose label matches the given string.
#
# The zero-based position of the item, or {Wx::NOT_FOUND} if the string was not found.
# @param string [String] String to find.
# @param caseSensitive [Boolean] Whether search is case sensitive (default is not).
# @return [Integer]
def find_string(string, caseSensitive=false) end

# This is the same as {Wx::OwnerDrawnComboBox#set_list_selection} and exists only because it is slightly
# more natural for controls which support multiple selection.
# @param n [Integer]
# @return [void]
def select(n) end

end

end
25 changes: 25 additions & 0 deletions lib/wx/doc/static_bitmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# :stopdoc:
# Copyright (c) 2023 M.J.N. Corino, The Netherlands
#
# This software is released under the MIT license.
# :startdoc:


module Wx

# A generic (non-native) static bitmap control to display bitmap.
#
# Unlike the native control implemented by {Wx::StaticBitmap}, which on some platforms is only meant for display of
# the small icons in the dialog boxes, you may use this implementation to display larger images portably.
# Notice that for the best results, the size of the control should be the same as the size of the image displayed in
# it, as happens by default if it's not resized explicitly. Otherwise, behaviour depends on the platform: under MSW,
# the bitmap is drawn centred inside the control, while elsewhere it is drawn at the origin of the control. You can
# use {Wx::GenericStaticBitmap#set_scale_mode} to control how the image is scaled inside the control.
#
# @see Wx::Bitmap
# @see Wx::StaticBitmap
class GenericStaticBitmap < Control

end

end
29 changes: 28 additions & 1 deletion lib/wx/keyword_defs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@
wx_ctor_params :validator, :name => 'listBox'
end

# wxEditableListBox - an editable listbox is composite control that lets the user easily enter, delete and reorder a list of strings.
Wx::define_keyword_ctors(Wx::EditableListBox) do
wx_ctor_params :id, :label, :pos, :size, :style => Wx::EL_DEFAULT_STYLE
wx_ctor_params :name => 'editableListBox'
end

# wxChoice Choice control (a combobox without the editable area)
Wx::define_keyword_ctors(Wx::Choice) do
wx_ctor_params :id, :pos, :size, :choices, :style
Expand Down Expand Up @@ -354,6 +360,14 @@
wx_ctor_params :validator, :name => 'comboCtrl'
end

# wxOwnerDrawnComboBox
Wx::define_keyword_ctors(Wx::OwnerDrawnComboBox) do
wx_ctor_params :id, :value => ''
wx_ctor_params :pos, :size, :choices => []
wx_ctor_params :style
wx_ctor_params :validator, :name => 'ownerDrawnComboBox'
end

# wxGauge A control to represent a varying quantity, such as time
# remaining
Wx::define_keyword_ctors(Wx::Gauge) do
Expand Down Expand Up @@ -426,9 +440,16 @@
wx_ctor_params :id
# autoconvert Bitmaps to BitmapBundles for downward compatibility
wx_ctor_params :label
wx_ctor_params :pos, :size, :style, :name => Wx::StaticBitmapNameStr
wx_ctor_params :pos, :size, :style, :name => Wx::STATIC_BITMAP_NAME_STR
end

# wxGenericStaticBitmap A control to display a bitmap
Wx::define_keyword_ctors(Wx::GenericStaticBitmap) do
wx_ctor_params :id
# autoconvert Bitmaps to BitmapBundles for downward compatibility
wx_ctor_params :label
wx_ctor_params :pos, :size, :style, :name => Wx::STATIC_BITMAP_NAME_STR
end

# wxRadioBox A group of radio buttons
Wx::define_keyword_ctors(Wx::RadioBox) do
Expand Down Expand Up @@ -587,3 +608,9 @@
wx_ctor_params :id, :pos, :size, :order, :items, :style
wx_ctor_params :validator, :name => 'rearrangeCtrl'
end

Wx::define_keyword_ctors(Wx::HeaderCtrlSimple) do
wx_ctor_params :winid => Wx::ID_ANY
wx_ctor_params :pos, :size, :style => Wx::HD_DEFAULT_STYLE
wx_ctor_params :name => 'headerCtrlSimple'
end
18 changes: 18 additions & 0 deletions rakelib/lib/core/include/client_data.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
#include <set>

static std::set<wxRubyClientData*> __s_WxRubyClientDataSet;
static std::set<wxRubyUserData*> __s_WxRubyUserDataSet;

WXRB_EXPORT_FLAG void wxRuby_RegisterClientData(wxRubyClientData* pcd)
{
__s_WxRubyClientDataSet.insert(pcd);
}

WXRB_EXPORT_FLAG void wxRuby_RegisterUserData(wxRubyUserData* pud)
{
__s_WxRubyUserDataSet.insert(pud);
}

static ID client_data_unlinked_id()
{
static ID __s_client_data_unlinked_id {};
Expand All @@ -37,10 +43,22 @@ WXRB_EXPORT_FLAG void wxRuby_UnregisterClientData(wxRubyClientData* pcd)
}
}

WXRB_EXPORT_FLAG void wxRuby_UnregisterUserData(wxRubyUserData* pud)
{
VALUE rbud = pud->GetData();
__s_WxRubyUserDataSet.erase(pud);
if (!NIL_P(rbud) && rb_respond_to(rbud, client_data_unlinked_id()))
{
wxRuby_Funcall(rbud, client_data_unlinked_id(), 0);
}
}

static void wxRuby_GC_mark_ClientData()
{
for (wxRubyClientData* pcd : __s_WxRubyClientDataSet)
rb_gc_mark(pcd->GetData());
for (wxRubyUserData* pud : __s_WxRubyUserDataSet)
rb_gc_mark(pud->GetData());
}

typedef void (*WXRBMarkFunction)();
Expand Down
Loading

0 comments on commit 21fd9c3

Please sign in to comment.