Class: RubyMVC::Toolkit::WxRuby::GridView

Inherits:
Wx::Grid
  • Object
show all
Includes:
SignalHandler, Common
Defined in:
lib/ruby_mvc/toolkit/peers/wxruby/grid_view.rb

Instance Method Summary collapse

Methods included from Common

#title, #title=

Methods included from SignalHandler

#signal_connect, #signal_disconnect, #signal_emit

Constructor Details

#initialize(options = {}) ⇒ GridView

Returns a new instance of GridView.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ruby_mvc/toolkit/peers/wxruby/grid_view.rb', line 34

def initialize(options = {})
#          puts "options: #{options.inspect}"
  super(WxRuby.parent(options), options[:id] || -1)
  if false == options[:show_row_labels]
    set_row_label_size(0)
  end
  @selected_rows = []

  evt_grid_cmd_cell_left_dclick(self.get_id()) do |e|
    if @gm
      col = @gm.get_key(e.get_col)
    else
      col = e.get_col
    end
    signal_emit("row-activated", self, @model, e.get_row, col)
  end

  evt_grid_range_select do |e|
#            puts "Event alt: #{e.alt_down}; ctrl: #{e.control_down}; brc: #{e.get_bottom_right_coords}; bottom: #{e.get_bottom_row}; left: #{e.get_left_col}; right: #{e.get_right_col}; tlc: #{e.get_top_left_coords}; top: #{e.get_top_row}; meta: #{e.meta_down}; selecting: #{e.selecting}; shift: #{e.shift_down}" if !e.selecting
    next if !e.selecting

    # FIXME: this should be a bit more clever in the
    # future, but right now, we're only dealing with
    # row selection
#            puts "Event alt: #{e.alt_down}; ctrl: #{e.control_down}; brc: #{e.get_bottom_right_coords}; bottom: #{e.get_bottom_row}; left: #{e.get_left_col}; right: #{e.get_right_col}; tlc: #{e.get_top_left_coords}; top: #{e.get_top_row}; meta: #{e.meta_down}; selecting: #{e.selecting}; shift: #{e.shift_down}"
    top = e.get_top_row
    bottom = e.get_bottom_row
    if e.meta_down || e.shift_down
      # extending the selection
      sel = @selected_rows.clone
    else
      # reset the selection
      sel = []
    end
    top.upto(bottom) do |i|
      sel << i
    end
    @selected_rows = sel
    signal_emit("row-selection-changed", self, @model, sel)
  end
end

Instance Method Details

#editable=(val) ⇒ Object



113
114
115
# File 'lib/ruby_mvc/toolkit/peers/wxruby/grid_view.rb', line 113

def editable=(val)
  enable_editing(val)
end

#model=(model) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/ruby_mvc/toolkit/peers/wxruby/grid_view.rb', line 76

def model=(model)
  @model = model
  @gm = GridModel.new(model)
  set_table(@gm, Wx::Grid::GridSelectRows)

  # FIXME: this is a bit cheezy and there should be a
  # better way to communicate between the grid table
  # and the view than this...  Apparently, the wxRuby
  # implementation doesn't expose the message
  # dispatching required between GridTableBase and the
  # Grid displaying it.  Kinda defeats the point...

  @model.signal_connect("rows-inserted") do |s, i, r|
#            puts "refresh rows-inserted"
    @gm = GridModel.new(model)
    set_table(@gm, Wx::Grid::GridSelectRows, false)
  end
  @model.signal_connect("rows-removed") do |s, i, r|
#            puts "refresh rows-removed"
    @gm = GridModel.new(model)
    selected_rows.delete(i)
    set_table(@gm, Wx::Grid::GridSelectRows, false)
  end
  @model.signal_connect("row-changed") do |s, i, r|
#            puts "refresh row-changed"
    @gm = GridModel.new(model)
    set_table(@gm, Wx::Grid::GridSelectRows, false)
  end
end

#selected_rowsObject



117
118
119
120
# File 'lib/ruby_mvc/toolkit/peers/wxruby/grid_view.rb', line 117

def selected_rows
  # FIXME: I shouldn't have to maintain this list...
  @selected_rows
end

#set_table(table, flags, clear_selection = true) ⇒ Object



106
107
108
109
110
111
# File 'lib/ruby_mvc/toolkit/peers/wxruby/grid_view.rb', line 106

def set_table(table, flags, clear_selection = true)
  super(table, flags)
  @selected_rows.clear if clear_selection
  auto_size_columns(false)
  signal_emit("row-selection-changed", self, @model, @selected_rows)
end