class Rabbit::Frame

Attributes

force_keep_above[RW]
geometry[RW]
logger[R]
window[R]

Public Class Methods

new(logger, canvas) click to toggle source
# File lib/rabbit/frame.rb, line 30
def initialize(logger, canvas)
  @logger = logger
  @canvas = canvas
  @geometry = nil
  @force_keep_above = nil
end

Public Instance Methods

destroyed?() click to toggle source
# File lib/rabbit/frame.rb, line 37
def destroyed?
  @window.nil? or @window.destroyed?
end
fullscreen() click to toggle source
# File lib/rabbit/frame.rb, line 59
def fullscreen
  @fullscreen_toggled = false
  @fullscreen = true
  @window.fullscreen
end
fullscreen?() click to toggle source
# File lib/rabbit/frame.rb, line 79
def fullscreen?
  if @window.respond_to?(:fullscreen?)
    @window.fullscreen?
  else
    @fullscreen
  end
end
fullscreen_available?() click to toggle source
# File lib/rabbit/frame.rb, line 110
def fullscreen_available?
  true
end
height() click to toggle source
# File lib/rabbit/frame.rb, line 51
def height
  @window.size[1]
end
iconify_available?() click to toggle source
# File lib/rabbit/frame.rb, line 114
def iconify_available?
  true
end
init_gui(width, height, main_window, window_type=nil) click to toggle source
# File lib/rabbit/frame.rb, line 95
def init_gui(width, height, main_window, window_type=nil)
  init_window(width, height, window_type)
  @fullscreen_toggled = false
  @fullscreen = false
  @iconify = false
  @main_window = main_window
  if @main_window
    @window.keep_above = @force_keep_above unless @force_keep_above.nil?
  else
    @window.keep_above = true
  end
  @window.show
  @canvas.post_init_gui
end
main_window?() click to toggle source
# File lib/rabbit/frame.rb, line 87
def main_window?
  @main_window
end
parse(source, callback=nil, &block) click to toggle source
# File lib/rabbit/frame.rb, line 55
def parse(source, callback=nil, &block)
  @canvas.parse(source, callback, &block)
end
quit() click to toggle source
# File lib/rabbit/frame.rb, line 41
def quit
  @window.destroy unless destroyed?
  @window = nil
  true
end
toggle_fullscreen() click to toggle source
# File lib/rabbit/frame.rb, line 71
def toggle_fullscreen
  if fullscreen?
    unfullscreen
  else
    fullscreen
  end
end
unfullscreen() click to toggle source
# File lib/rabbit/frame.rb, line 65
def unfullscreen
  @fullscreen_toggled = false
  @fullscreen = false
  @window.unfullscreen
end
update_title(new_title) click to toggle source
# File lib/rabbit/frame.rb, line 91
def update_title(new_title)
  @window.title = Utils.unescape_title(new_title)
end
width() click to toggle source
# File lib/rabbit/frame.rb, line 47
def width
  @window.size[0]
end

Private Instance Methods

init_window(width, height, window_type=nil) click to toggle source
# File lib/rabbit/frame.rb, line 119
def init_window(width, height, window_type=nil)
  window_type ||= Gtk::Window::TOPLEVEL
  @window = Gtk::Window.new(window_type)
  @window.set_default_size(width, height)
  @window.parse_geometry(@geometry) if @geometry
  @window.set_app_paintable(true)
  set_window_signal
  setup_dnd
  @canvas.attach_to(self, @window)
end
set_window_signal() click to toggle source
# File lib/rabbit/frame.rb, line 130
def set_window_signal
  set_window_signal_window_state_event
  set_window_signal_destroy
end
set_window_signal_destroy() click to toggle source
# File lib/rabbit/frame.rb, line 167
def set_window_signal_destroy
  @window.signal_connect("destroy") do
    @canvas.detach
    if main_window? and Gtk.main_level > 0
      Gtk.main_quit
    end
  end
end
set_window_signal_window_state_event() click to toggle source
# File lib/rabbit/frame.rb, line 144
def set_window_signal_window_state_event
  @window.signal_connect("window_state_event") do |widget, event|
    if event.changed_mask.fullscreen?
      @fullscreen_toggled = true
      if fullscreen?
        @window.keep_above = true
        @canvas.fullscreened
      else
        update_keep_above(false)
        @canvas.unfullscreened
      end
      @window.present
    elsif event.changed_mask.iconified?
      if @iconify
        @iconify = false
      else
        @canvas.iconified
        @iconify = true
      end
    end
  end
end
setup_dnd() click to toggle source
# File lib/rabbit/frame.rb, line 176
def setup_dnd
  Gtk::Drag.dest_set(@window,
                     Gtk::Drag::DEST_DEFAULT_ALL,
                     [["text/uri-list", 0, 0],
                      ["_NETSCAPE_URL", 0, 0]],
                     Gdk::DragContext::ACTION_COPY)
  @window.signal_connect("drag-data-received") do |*args|
    widget, context, x, y, selection_data, info, time = args
    uri = selection_data.data.chomp
    Gtk.idle_add do
      parse(Source::URI.new(nil, logger, uri))
      false
    end
    Gtk::Drag.finish(context, true, false, time)
  end

  @window.signal_connect("drag-drop") do |widget, context, x, y, time|
    true
  end
end
update_keep_above(keep_above=nil) click to toggle source
# File lib/rabbit/frame.rb, line 135
def update_keep_above(keep_above=nil)
  if @main_window
    keep_above = @force_keep_above unless @force_keep_above.nil?
    @window.keep_above = keep_above unless keep_above.nil?
  else
    @window.keep_above = true
  end
end