shows a window with a list of items the list is an array of arrays, displayed as String the first array is the column names each item clicked yields the block with the selected iterator, double-click also close the popup
# File metasm/gui/gtk.rb, line 706 def initialize(owner, title, list, h={}) owner ||= Gtk::Window.toplevels.first super(title, owner, Gtk::Dialog::DESTROY_WITH_PARENT) cols = list.shift treeview = Gtk::TreeView.new treeview.model = Gtk::ListStore.new(*[String]*cols.length) treeview.selection.mode = Gtk::SELECTION_NONE if @color_callback = h[:color_callback] @drawable = DrawableWidget.new # needed for color()... @drawable.signal_emit('realize') end cols.each_with_index { |col, i| crt = Gtk::CellRendererText.new tvc = Gtk::TreeViewColumn.new(col, crt) tvc.sort_column_id = i tvc.set_cell_data_func(crt) { |_tvc, _crt, model, iter| _crt.text = iter[i] if @color_callback fu = (0...cols.length).map { |ii| iter[ii] } fg, bg = @color_callback[fu] fg ||= :black bg ||= :white _crt.foreground = @drawable.color(fg).to_s _crt.cell_background = @drawable.color(bg).to_s end } treeview.append_column tvc } list.each { |e| iter = treeview.model.append e.each_with_index { |v, i| iter[i] = v.to_s } } treeview.model.set_sort_column_id(0) treeview.signal_connect('cursor_changed') { |x| if iter = treeview.selection.selected yield iter end } treeview.signal_connect('row_activated') { destroy } signal_connect('destroy') { h[:ondestroy].call } if h[:ondestroy] remove vbox add Gtk::ScrolledWindow.new.add(treeview) toplevel.set_default_size cols.length*240, 400 show if not h[:noshow] # so that the 1st line is not selected by default treeview.selection.mode = Gtk::SELECTION_SINGLE end
# File metasm/gui/win32.rb, line 3058 def destroy_window @ondestroy.call if @ondestroy super() end
# File metasm/gui/win32.rb, line 3052 def initialize_window(title, list, opts={}, &b) @ondestroy = opts[:ondestroy] self.title = title self.widget = LBoxWidget.new(list, opts, &b) end
# File metasm/gui/gtk.rb, line 764 def show show_all present end
# File metasm/gui/win32.rb, line 3063 def windowproc(hwnd, msg, wparam, lparam) case msg when Win32Gui::WM_HSCROLL sif = Win32Gui.alloc_c_struct('SCROLLINFO', :cbsize => :size, :fmask => Win32Gui::SIF_ALL) Win32Gui.getscrollinfo(@hwnd, Win32Gui::SB_HORZ, sif) case wparam & 0xffff when Win32Gui::SB_THUMBPOSITION; val = sif.ntrackpos when Win32Gui::SB_THUMBTRACK; val = sif.ntrackpos when Win32Gui::SB_LINELEFT; val = sif.npos - 1 when Win32Gui::SB_LINERIGHT; val = sif.npos + 1 when Win32Gui::SB_PAGELEFT; val = sif.npos - sif.npage when Win32Gui::SB_PAGERIGHT; val = sif.npos + sif.npage else return 0 end @widget.hscroll val when Win32Gui::WM_VSCROLL sif = Win32Gui.alloc_c_struct('SCROLLINFO', :cbsize => :size, :fmask => Win32Gui::SIF_ALL) Win32Gui.getscrollinfo(@hwnd, Win32Gui::SB_VERT, sif) case wparam & 0xffff when Win32Gui::SB_THUMBPOSITION; val = sif.ntrackpos when Win32Gui::SB_THUMBTRACK; val = sif.ntrackpos #; nopos = true when Win32Gui::SB_LINEDOWN; val = sif.npos + 1 when Win32Gui::SB_LINEUP; val = sif.npos - 1 when Win32Gui::SB_PAGEDOWN; val = sif.npos + sif.npage when Win32Gui::SB_PAGEUP; val = sif.npos - sif.npage else return 0 end @widget.vscroll val else return super(hwnd, msg, wparam, lparam) end 0 end