+# * BOOH *
+#
+# A.k.a `Best web-album Of the world, Or your money back, Humerus'.
+#
+# The acronyn sucks, however this is a tribute to Dragon Ball by
+# Akira Toriyama, where the last enemy beaten by heroes of Dragon
+# Ball is named "Boo". But there was already a free software project
+# called Boo, so this one will be it "Booh". Or whatever.
+#
+#
+# Copyright (c) 2004 Guillaume Cottenceau <gc3 at bluewin.ch>
+#
+# This software may be freely redistributed under the terms of the GNU
+# public license version 2.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
require 'gtk2'
require 'booh/booh-lib'
end
end
-class Gtk::AutoTable < Gtk::VBox
+class Gtk::AutoTable < Gtk::EventBox
+
+ attr_accessor :queue_draws
def initialize(row_spacings)
@children = []
@containers = []
@width = -1
@old_widths = []
+ @queue_draws = []
@row_spacings = row_spacings
@table = nil
- super
+ super()
recreate_table
signal_connect('size-allocate') { |w, allocation|
msg 3, "got self allocation: #{allocation}"
end
}
@timeout = Gtk.timeout_add(100) {
- if @queue_draw
- queue_draw
- @queue_draw = false
+ if @queue_draws.size > 0
+ @queue_draws.each { |elem| elem.call }
+ @queue_draws.clear
end
true
}
warn "Critical: child not found!"
end
}
-
- #- handle reordering with drag and drop
- Gtk::Drag.source_set(widget, Gdk::Window::BUTTON1_MASK, [['reorder-elements', Gtk::Drag::TARGET_SAME_APP, 1]], Gdk::DragContext::ACTION_MOVE)
- Gtk::Drag.dest_set(widget, Gtk::Drag::DEST_DEFAULT_ALL, [['reorder-elements', Gtk::Drag::TARGET_SAME_APP, 1]], Gdk::DragContext::ACTION_MOVE)
- widget.signal_connect('drag-data-get') { |w, ctxt, selection_data, info, time|
- selection_data.set(Gdk::Selection::TYPE_STRING, get_current_number(widget).to_s)
- }
- widget.signal_connect('drag-data-received') { |w, ctxt, x, y, selection_data, info, time|
- ctxt.targets.each { |target|
- if target.name == 'reorder-elements'
- insert(selection_data.data.to_i, get_current_number(widget))
- end
- }
- }
end
#- remove a widget from the list of automatically handled widgets
- def remove(widget)
+ def remove_widget(widget)
@children.each_with_index { |chld, index|
if chld[:widget] == widget
@children.delete_at(index)
return false
end
+ #- re-insert a widget at a given pos
+ def reinsert(pos, widget, name)
+ child = { :widget => widget, :name => name }
+ @children[pos, 0] = child
+ redistribute(true)
+ end
+
#- remove all widgets
def clear
@children = []
return -1
end
- #- insert a widget before another by numbers
- def insert(src, dst)
+ #- move widgets by numbers
+ def move(src, dst)
if src != dst
chld = @children.delete_at(src)
@children[dst > src ? dst - 1 : dst, 0] = chld
@containers = []
if @table
remove(@table)
- @table.destroy
+ @table.hide #- should be #destroy, but that triggers an Abort in booh, and I cannot really understand why and fix
+ #- this is a memory leak, so ideally it should be either fixed in ruby-gtk2 0.16.0, or at least checked if
+ #- it's not fixed from a side effect of another fix in the future
end
add(@table = Gtk::Table.new(0, 0, true))
@table.set_row_spacings(@row_spacings)
if unallocated = @children.find { |e| !e[:allocation] }
#- waiting for allocations. replace last displayed widget with first unallocated.
last_container = @containers[-1]
- put(unallocated, last_container[:x], last_container[:y])
+ put(unallocated, last_container ? last_container[:x] : 0, last_container ? last_container[:y]: 0)
else
if @children.size == 0
put(e, e[:xnew], e[:ynew])
}
show_all
- @queue_draw = true
+ @queue_draws << proc { queue_draw }
end
end
end