require 'observable'

module Fox

unless defined? FXMenuBar
  FXMenuBar   = FXMenubar # this was just driving me crazy
  FXScrollBar = FXScrollbar
end

class FXObject
  extend Observable
  include Observable::Match
end


# All the basic properties of widgets should have reader/writer pairs that
# take boolean or other values. This will let them be easily used as
# targets of check buttons/menus etc. FXRuby already does this in most cases.

class FXTextField
  alias :editable :editable? unless instance_methods.include?("editable")
  observable :editable    # make the reader and writer methods observable


end

class FXWindow
  alias :enabled :enabled? unless instance_methods.include?("enabled")
  unless instance_methods.include?("enabled=")
    def enabled=(x); x ? enable : disable; end
  end
  observable :enabled

  unless instance_methods.include?("shown=")
    def shown=(x); x ? show : hide; end
  end
  observable :shown

  ## drop_enabled

  observable :height, :width ## doesn't really work yet -- see simple.rb
end

end

class Integer

def to_bool
  self != 0
end

end

class TrueClass

def to_bool; self; end

end

class FalseClass

def to_bool; self; end

end

module FoxTails

# Functions for storing simple objects as human-readable strings.

# extracts consecutive decimal digits and returns the corresponding
# integers in an array--safer than eval!
def FoxTails.string_to_int_array(str)
  str.scan(/-?\d+/).map{|s|s.to_i}
end

# parses as "...", "...", ... and returns the corresponding
# strings in an array--safer than eval!
def FoxTails.string_to_string_array(str)
end

end