lib/shoes/swt/app.rb in shoes-swt-4.0.0.pre2 vs lib/shoes/swt/app.rb in shoes-swt-4.0.0.pre3
- old
+ new
@@ -17,14 +17,13 @@
#
class App
include Common::Container
include Common::Clickable
- attr_reader :dsl, :real, :shell, :clickable_elements
+ attr_reader :dsl, :real, :shell, :click_listener
- def initialize dsl
- @clickable_elements = []
+ def initialize(dsl)
@dsl = dsl
::Swt::Widgets::Display.app_name = @dsl.app_title
@background = Color.new(@dsl.opts[:background])
@started = false
initialize_shell
@@ -56,28 +55,24 @@
def app
self
end
def width
- if overlay_scrollbars?
- @shell.client_area.width
- else
- width_adjusted_for_scrollbars
- end
+ shell.client_area.width
end
def height
- @shell.client_area.height
+ shell.client_area.height
end
def disposed?
@shell.disposed? || @real.disposed?
end
- def redraw(left=nil, top=nil, width=nil, height=nil, all=true)
+ def redraw(left = nil, top = nil, width = nil, height = nil, all = true)
unless @real.disposed?
- if (left == nil or top == nil or width == nil or height == nil)
+ if left.nil? || top.nil? || width.nil? || height.nil?
@real.redraw
else
@real.redraw(left, top, width, height, all)
end
end
@@ -92,18 +87,19 @@
@real.layout
end
end
def scroll_top
- @real.getLocation.y
+ @real.location.y
end
def scroll_top=(n)
@real.setLocation 0, -n
- @shell.getVerticalBar.setSelection n
+ @shell.vertical_bar.selection = n
end
+ # Java doesn't like ruby-style accessors here for some reason
def clipboard
::Swt::Clipboard.new(Shoes.display).getContents ::Swt::TextTransfer.getInstance
end
def clipboard=(str)
@@ -119,12 +115,12 @@
def fullscreen
@shell.full_screen
end
- def add_clickable_element(element)
- @clickable_elements << element
+ def clickable_elements
+ @click_listener.clickable_elements
end
def started?
@started
end
@@ -132,37 +128,46 @@
# This represents the space (potentially) occupied by a vertical
# scrollbar. Since the scrollbar may not be visible at the time this
# method is called, we don't rely on its reported value.
def gutter
# 16
- @shell.getVerticalBar.getSize.x
+ @shell.vertical_bar.size.x
end
def add_key_listener(listener)
@key_listeners[listener.class] << listener
end
def remove_key_listener(listener)
@key_listeners[listener.class].delete(listener)
end
+ # For use from modal Shoes windows, keeps pumping UI messages but hangs
+ # on from executing other Shoes code until we're done.
+ def wait_until_closed
+ until @shell.isDisposed
+ ::Swt.display.sleep unless ::Swt.display.readAndDispatch
+ end
+ end
+
private
+
def initialize_scroll_bar
- scroll_bar = @shell.getVerticalBar
- scroll_bar.setIncrement 10
+ scroll_bar = @shell.vertical_bar
+ scroll_bar.increment = 10
selection_listener = SelectionListener.new(scroll_bar) do |vertical_bar, event|
- if self.shell.getVerticalBar.getVisible and event.detail != ::Swt::SWT::DRAG
+ if shell.vertical_bar.visible && event.detail != ::Swt::SWT::DRAG
vertically_scroll_window(vertical_bar)
end
end
scroll_bar.addSelectionListener selection_listener
end
def vertically_scroll_window(vertical_bar)
- location = self.real.getLocation
- location.y = -vertical_bar.getSelection
- self.real.setLocation location
+ location = real.location
+ location.y = -vertical_bar.selection
+ real.location = location
end
def force_shell_size
frame_x_decorations = @shell.size.x - @shell.client_area.width
frame_y_decorations = @shell.size.y - @shell.client_area.height
@@ -170,19 +175,20 @@
new_height = @dsl.height + frame_y_decorations
@shell.setSize(new_width, new_height)
end
def main_window_on_close
- lambda { |event|
+ lambda do |_event|
::Swt.display.dispose
- Dir[File.join(Dir.tmpdir, "__shoes4_*.png")].each{|f| File.delete f}
- }
+ Dir[File.join(Dir.tmpdir, "__shoes4_*.png")].each { |f| File.delete f }
+ end
end
def main_window_style
style = ::Swt::SWT::CLOSE | ::Swt::SWT::MIN | ::Swt::SWT::V_SCROLL
style |= ::Swt::SWT::RESIZE | ::Swt::SWT::MAX if @dsl.opts[:resizable]
+ style |= ::Swt::SWT::APPLICATION_MODAL if @dsl.opts[:modal]
style
end
def initialize_shell
@image = ::Swt::Graphics::Image.new(::Swt.display, ICON)
@@ -194,13 +200,13 @@
@shell.background = @background.real
end
def initialize_real
@real = ::Swt::Widgets::Composite.new(@shell,
- ::Swt::SWT::TRANSPARENT | ::Swt::SWT::NO_RADIO_GROUP)
- @real.setSize(@dsl.width - @shell.getVerticalBar.getSize.x, @dsl.height)
- @real.setLayout init_shoes_layout
+ ::Swt::SWT::TRANSPARENT | ::Swt::SWT::NO_RADIO_GROUP)
+ @real.setSize(@dsl.width - @shell.vertical_bar.size.x, @dsl.height)
+ @real.layout = init_shoes_layout
end
# it seems like the class can not not have a constructor with an argument
# due to its java super class
def init_shoes_layout
@@ -211,20 +217,21 @@
def attach_event_listeners
attach_shell_event_listeners
attach_real_event_listeners
attach_key_event_listeners
+ attach_click_listener
end
def attach_shell_event_listeners
@shell.addControlListener ShellControlListener.new(self)
@shell.addListener(::Swt::SWT::Close, main_window_on_close) if main_app?
@shell.addListener(::Swt::SWT::Close, unregister_app)
end
def unregister_app
- proc do |event|
+ proc do |_event|
::Shoes::Swt.unregister(self)
end
end
def attach_real_event_listeners
@@ -250,50 +257,39 @@
end
end
end
end
+ def attach_click_listener
+ @click_listener = ClickListener.new(self)
+ end
+
def for_this_shell?(evt)
evt.widget.shell == @shell unless evt.widget.disposed?
end
-
- def overlay_scrollbars?
- @shell.scrollbars_mode == ::Swt::SWT::SCROLLBAR_OVERLAY
- end
-
- def width_adjusted_for_scrollbars
- if @shell.getVerticalBar.getVisible
- @shell.client_area.width + @shell.getVerticalBar.getSize.x
- else
- @shell.client_area.width
- end
- end
-
end
class ShellControlListener
def initialize(app)
@app = app
end
def controlResized(event)
shell = event.widget
- width = shell.client_area.width
+ width = shell.client_area.width
height = shell.client_area.height
- @app.dsl.top_slot.width = width
- @app.dsl.top_slot.height = height
@app.real.setSize width, height
@app.real.layout
- @app.dsl.resize_callbacks.each{|blk| blk.call}
+ @app.dsl.resize_callbacks.each(&:call)
end
- def controlMoved(e)
+ def controlMoved(_e)
end
end
class MouseListener
- def initialize app
+ def initialize(app)
@app = app
end
def mouseDown(e)
@app.dsl.mouse_button = e.button
@@ -303,12 +299,11 @@
def mouseUp(e)
@app.dsl.mouse_button = 0
@app.dsl.mouse_pos = [e.x, e.y]
end
- def mouseDoubleClick(e)
+ def mouseDoubleClick(_e)
# do nothing
end
end
-
end
end