gtk3 3.0.9-x64-mingw32 → 3.1.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/ext/gtk3/rb-gtk3-private.h +1 -0
  3. data/ext/gtk3/rb-gtk3-spin-button.c +85 -0
  4. data/ext/gtk3/rb-gtk3.c +3 -0
  5. data/lib/2.2/gtk3.so +0 -0
  6. data/lib/2.3/gtk3.so +0 -0
  7. data/lib/gtk3/deprecated.rb +0 -8
  8. data/lib/gtk3/loader.rb +1 -7
  9. data/lib/gtk3/tree-model.rb +2 -0
  10. data/sample/gtk-demo/TODO +10 -10
  11. data/sample/gtk-demo/assistant.rb +44 -39
  12. data/sample/gtk-demo/builder.rb +71 -50
  13. data/sample/gtk-demo/button_box.rb +39 -28
  14. data/sample/gtk-demo/clipboard.rb +139 -46
  15. data/sample/gtk-demo/colorsel.rb +50 -36
  16. data/sample/gtk-demo/css_accordion.rb +18 -17
  17. data/sample/gtk-demo/css_basics.rb +60 -47
  18. data/sample/gtk-demo/css_multiplebgs.rb +92 -71
  19. data/sample/gtk-demo/css_pixbufs.rb +61 -48
  20. data/sample/gtk-demo/css_shadows.rb +63 -50
  21. data/sample/gtk-demo/cursors.rb +95 -64
  22. data/sample/gtk-demo/dialog.rb +95 -78
  23. data/sample/gtk-demo/drawingarea.rb +138 -171
  24. data/sample/gtk-demo/editable_cells.rb +169 -130
  25. data/sample/gtk-demo/entry_buffer.rb +15 -13
  26. data/sample/gtk-demo/entry_completion.rb +22 -17
  27. data/sample/gtk-demo/expander.rb +39 -31
  28. data/sample/gtk-demo/filtermodel.rb +67 -63
  29. data/sample/gtk-demo/font_features.rb +91 -60
  30. data/sample/gtk-demo/glarea.rb +277 -0
  31. data/sample/gtk-demo/headerbar.rb +17 -15
  32. data/sample/gtk-demo/hypertext.rb +146 -167
  33. data/sample/gtk-demo/iconview.rb +132 -91
  34. data/sample/gtk-demo/iconview_edit.rb +49 -38
  35. data/sample/gtk-demo/infobar.rb +81 -62
  36. data/sample/gtk-demo/links.rb +35 -30
  37. data/sample/gtk-demo/list_store.rb +169 -114
  38. data/sample/gtk-demo/listbox.rb +183 -0
  39. data/sample/gtk-demo/main.rb +32 -21
  40. data/sample/gtk-demo/markup.rb +65 -52
  41. data/sample/gtk-demo/menus.rb +57 -58
  42. data/sample/gtk-demo/modelbutton.rb +11 -9
  43. data/sample/gtk-demo/modelbutton.ui +3 -0
  44. data/sample/gtk-demo/overlay.rb +39 -32
  45. data/sample/gtk-demo/overlay2.rb +68 -54
  46. data/sample/gtk-demo/panes.rb +56 -68
  47. data/sample/gtk-demo/pickers.rb +46 -45
  48. data/sample/gtk-demo/pixbufs.rb +27 -25
  49. data/sample/gtk-demo/popover.rb +70 -63
  50. data/sample/gtk-demo/printing.rb +94 -69
  51. data/sample/gtk-demo/revealer.rb +46 -38
  52. data/sample/gtk-demo/rotated_text.rb +75 -54
  53. data/sample/gtk-demo/scale.rb +10 -8
  54. data/sample/gtk-demo/search_entry.rb +195 -0
  55. data/sample/gtk-demo/search_entry2.rb +71 -59
  56. data/sample/gtk-demo/sidebar.rb +20 -19
  57. data/sample/gtk-demo/sizegroup.rb +36 -35
  58. data/sample/gtk-demo/spinbutton.rb +128 -0
  59. data/sample/gtk-demo/spinner.rb +55 -40
  60. data/sample/gtk-demo/stack.rb +11 -8
  61. data/sample/gtk-demo/textmask.rb +14 -13
  62. data/sample/gtk-demo/textscroll.rb +16 -12
  63. data/sample/gtk-demo/theming_style_classes.rb +14 -12
  64. data/sample/gtk-demo/transparent.rb +17 -13
  65. data/sample/misc/treemodelfilter.rb +1 -1
  66. metadata +24 -19
@@ -1,205 +1,172 @@
1
- # Copyright (c) 2003-2014 Ruby-GNOME2 Project Team
1
+ # Copyright (c) 2016 Ruby-GNOME2 Project Team
2
2
  # This program is licenced under the same licence as Ruby-GNOME2.
3
3
  #
4
- # $Id: drawingarea.rb,v 1.5 2005/02/12 23:02:43 kzys Exp $
5
4
  =begin
6
- = Drawing Area
5
+ = Drawing Area
7
6
 
8
- Gtk::DrawingArea is a blank area where you can draw custom displays
9
- of various kinds.
7
+ GtkDrawingArea is a blank area where you can draw custom displays
8
+ of various kinds.
10
9
 
11
- This demo has two drawing areas. The checkerboard area shows
12
- how you can just draw something; all you have to do is write
13
- a signal handler for expose_event, as shown here.
10
+ This demo has two drawing areas. The checkerboard area shows
11
+ how you can just draw something; all you have to do is write
12
+ a signal handler for expose_event, as shown here.
14
13
 
15
- The 'scribble' area is a bit more advanced, and shows how to handle
16
- events such as button presses and mouse motion. Click the mouse
17
- and drag in the scribble area to draw squiggles. Resize the window
18
- to clear the area.
14
+ The "scribble" area is a bit more advanced, and shows how to handle
15
+ events such as button presses and mouse motion. Click the mouse
16
+ and drag in the scribble area to draw squiggles. Resize the window
17
+ to clear the area.
19
18
  =end
19
+ class DrawingareaDemo
20
+ def initialize(main_window)
21
+ @window = Gtk::Window.new(:toplevel)
22
+ @window.screen = main_window.screen
23
+ @window.title = "Drawing Area"
24
+ @window.border_width = 8
25
+
26
+ initialize_vbox
27
+ create_the_checkerboard_area
28
+ create_the_scribble_area
29
+ end
20
30
 
21
- require "common"
22
-
23
- module Demo
24
- class DrawingArea < BasicWindow
25
- def initialize
26
- # Pixmap for scribble area, to store current scribbles
27
- @cairo_context = nil
28
- super("Drawing Area")
29
-
30
- self.border_width = 8
31
+ def run
32
+ if !@window.visible?
33
+ @window.show_all
34
+ else
35
+ @window.destroy
36
+ end
37
+ @window
38
+ end
31
39
 
32
- vbox = Gtk::Box.new(:vertical, 8)
33
- vbox.border_width = 8
34
- add(vbox)
40
+ private
35
41
 
36
- ## Create the checkerboard area
37
- label = Gtk::Label.new
38
- label.set_markup("<u>Checkerboard pattern</u>")
39
- vbox.pack_start(label, :expand => false, :fill => false, :padding => 0)
42
+ def initialize_vbox
43
+ @vbox = Gtk::Box.new(:vertical, 8)
44
+ @vbox.border_width = 8
45
+ @window.add(@vbox)
46
+ end
40
47
 
41
- frame = Gtk::Frame.new
42
- frame.shadow_type = :in
43
- vbox.pack_start(frame, :expand => true, :fill => true, :padding => 0)
48
+ def create_da_in_frame(text)
49
+ label = Gtk::Label.new
50
+ label.set_markup(text, :use_underline => true)
51
+ @vbox.pack_start(label, :expand => false, :fill => false, :padding => 0)
44
52
 
45
- da = Gtk::DrawingArea.new
46
- # set a minimum size
47
- da.set_size_request(100, 100)
53
+ frame = Gtk::Frame.new
54
+ frame.shadow_type = :in
55
+ @vbox.pack_start(frame, :expand => true, :fill => true, :padding => 0)
48
56
 
49
- frame.add(da)
57
+ da = Gtk::DrawingArea.new
58
+ da.set_size_request(100, 100)
59
+ frame.add(da)
60
+ da
61
+ end
50
62
 
51
- da.signal_connect("draw") do |widget, event|
52
- checkerboard_draw(widget, event)
63
+ def checkerboard_draw(da, cr)
64
+ check_size = 10
65
+ spacing = 2
66
+ # At the start of a draw handler, a clip region has been set on
67
+ # the Cairo context, and the contents have been cleared to the
68
+ # widget's background color. The docs for
69
+ # gdk_window_begin_paint_region() give more details on how this
70
+ # works.
71
+ ycount = 0
72
+ xcount = 0
73
+ i = spacing
74
+ while i < da.allocated_width
75
+ j = spacing
76
+ ycount = xcount % 2 # start with even/odd depending on row
77
+ while j < da.allocated_height
78
+ if ycount % 2
79
+ cr.set_source_rgb(0.45777, 0, 0.45777)
80
+ else
81
+ cr.set_source_rgb(1, 1, 1)
82
+ end
83
+ # if we are outside the clip, this will do nothing
84
+ cr.rectangle(i, j, check_size, check_size)
85
+ cr.fill
86
+ j += check_size + spacing
87
+ ++ycount
53
88
  end
89
+ i += check_size + spacing
90
+ ++xcount
91
+ end
92
+ end
54
93
 
55
- ## Create the scribble area
56
- label = Gtk::Label.new
57
- label.set_markup("<u>Scribble area</u>")
58
- vbox.pack_start(label, :expand => false, :fill => false, :padding => 0)
59
-
60
- frame = Gtk::Frame.new
61
- frame.shadow_type = :in
62
- vbox.pack_start(frame, :expand => true, :fill => true, :padding => 0)
94
+ def create_the_checkerboard_area
95
+ da = create_da_in_frame("<u>Checkerboard pattern</u>")
96
+ da.signal_connect "draw" do |widget, cr|
97
+ checkerboard_draw(widget, cr)
98
+ end
99
+ end
63
100
 
64
- da = Gtk::DrawingArea.new
65
- # set a minimum size
66
- da.set_size_request(100, 100)
101
+ def scribble_configure_event(da)
102
+ @surface.destroy if @surface
103
+
104
+ @surface = da.window.create_similar_surface(Cairo::CONTENT_COLOR,
105
+ da.allocated_width,
106
+ da.allocated_height)
107
+ # initialize the surface to white
108
+ cr = Cairo::Context.new(@surface)
109
+ cr.set_source_rgb(1, 1, 1)
110
+ cr.paint
111
+ cr.destroy
112
+ # we have handled the configure event, no need to further processing
113
+ true
114
+ end
67
115
 
68
- frame.add(da)
116
+ def scribble_draw(cr)
117
+ # Redraw the screen from the surface
118
+ cr.set_source(@surface, 0, 0)
119
+ cr.paint
120
+ false
121
+ end
69
122
 
70
- # Signals used to handle backing pixmap
71
- da.signal_connect("draw") do |*args|
72
- scribble_draw(*args)
73
- end
74
- da.signal_connect("configure-event") do |widget, event|
75
- scribble_configure_event(widget)
76
- end
123
+ def draw_brush(widget, x, y)
124
+ cr = Cairo::Context.new(@surface)
125
+ cr.rectangle(x - 3, y - 3, 6, 6)
126
+ cr.fill
127
+ cr.destroy
128
+ widget.queue_draw_area(x - 3, y - 3, 6, 6)
129
+ end
77
130
 
78
- # Event signals
79
- da.signal_connect("motion-notify-event") do |*args|
80
- scribble_motion_notify_event(*args)
81
- end
82
- da.signal_connect("button-press-event") do |*args|
83
- scribble_button_press_event(*args)
84
- end
131
+ def scribble_button_press_event(da, event)
132
+ return false unless @surface
133
+ draw_brush(da, event.x, event.y) if event.button == Gdk::BUTTON_PRIMARY
134
+ true
135
+ end
85
136
 
86
- # Ask to receive events the drawing area doesn't normally
87
- # subscribe to
88
- da.events |= (Gdk::Event::LEAVE_NOTIFY_MASK |
89
- Gdk::Event::BUTTON_PRESS_MASK |
90
- Gdk::Event::POINTER_MOTION_MASK |
91
- Gdk::Event::POINTER_MOTION_HINT_MASK)
137
+ def scribble_motion_notify_event(da, event)
138
+ return false unless @surface
139
+ _window, x, y, state = event.window.get_device_position(event.device)
140
+ if (state & Gdk::EventMask::BUTTON_PRESS_MASK.to_i).nonzero?
141
+ draw_brush(da, x, y)
92
142
  end
143
+ true
144
+ end
93
145
 
94
- # Create a new surface of the appropriate size to store our scribbles
95
- def scribble_configure_event(widget)
96
- allocation = widget.allocation
97
- surface = widget.window.create_similar_surface(:color,
98
- allocation.width,
99
- allocation.height)
100
- @cairo_context = Cairo::Context.new(surface)
101
- @cairo_context.set_source_rgb(1, 1, 1)
102
- @cairo_context.paint
103
-
104
- # We've handled the configure event, no need for further processing.
105
- return true
106
- end
146
+ def create_the_scribble_area
147
+ da = create_da_in_frame("<u>Scribble area</u>")
107
148
 
108
- CHECK_SIZE = 10
109
- SPACING = 2
110
- def checkerboard_draw(da, cairo_context)
111
- # At the start of a draw handler, a clip region of event.area
112
- # is set on the window, and event.area has been cleared to the
113
- # widget's background color. The docs for
114
- # gdk_window_begin_paint_region give more details on how this
115
- # works.
116
-
117
- xcount = 0
118
- width = da.allocated_width
119
- height = da.allocated_height
120
- SPACING.step(da.allocation.width, CHECK_SIZE + SPACING) do |i|
121
- ycount = xcount % 2; # start with even/odd depending on row
122
- SPACING.step(da.allocation.height, CHECK_SIZE + SPACING) do |j|
123
- if ycount % 2 == 1
124
- cairo_context.set_source_rgb(0.45777, 0, 0.45777)
125
- else
126
- cairo_context.set_source_rgb(1, 1, 1)
127
- end
128
-
129
- # If we're outside the clip, this will do nothing.
130
- cairo_context.fill do
131
- cairo_context.rectangle(i, j, CHECK_SIZE, CHECK_SIZE)
132
- end
133
- ycount += 1
134
- end
135
- xcount += 1
136
- end
137
- # return true because we've handled this event, so no
138
- # further processing is required.
139
- #
140
- return true
149
+ da.signal_connect "draw" do |_widget, cr|
150
+ scribble_draw(cr)
141
151
  end
142
152
 
143
- # Redraw the screen from the surface
144
- def scribble_draw(widget, event)
145
- event.set_source(@cairo_context.target)
146
- event.paint
147
- return false
153
+ da.signal_connect "configure-event" do |widget|
154
+ scribble_configure_event(widget)
148
155
  end
149
156
 
150
- # Draw a rectangle on the screen
151
- def draw_brush(widget, x, y)
152
- update_rect = Gdk::Rectangle.new(x - 3, y - 3, 6, 6)
153
-
154
- # Paint to the surface, where we store our state
155
- @cairo_context.fill do
156
- @cairo_context.set_source_rgb(0, 0, 0)
157
- @cairo_context.rectangle(update_rect.x,
158
- update_rect.y,
159
- update_rect.width,
160
- update_rect.height)
161
- end
162
-
163
- # Now invalidate the affected region of the drawing area.
164
- widget.window.invalidate(update_rect, false)
157
+ da.signal_connect "motion-notify-event" do |widget, event|
158
+ scribble_motion_notify_event(widget, event)
165
159
  end
166
160
 
167
- def scribble_button_press_event(widget, event)
168
- # paranoia check, in case we haven't gotten a configure event
169
- return false unless @cairo_context
170
-
171
- if event.button == 1
172
- draw_brush(widget, event.x, event.y)
173
- end
174
-
175
- # We've handled the event, stop processing
176
- return true
161
+ da.signal_connect "button-press-event" do |widget, event|
162
+ scribble_button_press_event(widget, event)
177
163
  end
178
164
 
179
- def scribble_motion_notify_event(widget, event)
180
- # paranoia check, in case we haven't gotten a configure event
181
- return false unless @cairo_context
182
-
183
- # This call is very important; it requests the next motion event.
184
- # If you don't call Gdk::Window#pointer you'll only get
185
- # a single motion event. The reason is that we specified
186
- # Gdk::POINTER_MOTION_HINT_MASK to Gtk::Widget#set_events.
187
- # If we hadn't specified that, we could just use event.x, event.y
188
- # as the pointer location. But we'd also get deluged in events.
189
- # By requesting the next event as we handle the current one,
190
- # we avoid getting a huge number of events faster than we
191
- # can cope.
192
-
193
- # NOTE: Gdk::EventMotion#window will be restored from Ruby/GDK3 2.1.1.
194
- # win, x, y, state = event.window.get_device_position(event.device)
195
- win, x, y, state = widget.window.get_device_position(event.device)
196
-
197
- if (state & :button1_mask) != 0
198
- draw_brush(widget, x, y)
199
- end
200
-
201
- # We've handled it, stop processing
202
- return true
203
- end
165
+ # da.events |= (Gdk::EventMask::LEAVE_NOTIFY_MASK |
166
+ # Gdk::EventMask::BUTTON_PRESS_MASK |
167
+ # Gdk::EventMask::POINTER_MOTION_MASK |
168
+ # Gdk::EventMask::POINTER_MOTION_HINT_MASK)
169
+ da.add_events([:leave_notify_mask, :button_press_mask,
170
+ :pointer_motion_mask, :pointer_motion_hint_mask])
204
171
  end
205
172
  end
@@ -1,173 +1,212 @@
1
- # Copyright (c) 2003-2005 Ruby-GNOME2 Project Team
1
+ # Copyright (c) 2016 Ruby-GNOME2 Project Team
2
2
  # This program is licenced under the same licence as Ruby-GNOME2.
3
3
  #
4
- # $Id: editable_cells.rb,v 1.7 2005/02/06 18:25:13 kzys Exp $
5
4
  =begin
6
- = Tree View/Editable Cells
5
+ = Tree View/Editable Cells
7
6
 
8
- This demo demonstrates the use of editable cells in a Gtk::TreeView. If
9
- you're new to the Gtk::TreeView widgets and associates, look into
10
- the Gtk::ListStore example first.
11
- =end
12
- require 'common'
7
+ This demo demonstrates the use of editable cells in a GtkTreeView. If
8
+ you're new to the GtkTreeView widgets and associates, look into
9
+ the GtkListStore example first. It also shows how to use the
10
+ GtkCellRenderer::editing-started signal to do custom setup of the
11
+ editable widget.
13
12
 
14
- module Demo
15
- class EditableCells < BasicWindow
16
- Item = Struct.new('Item', :number, :product, :editable)
17
- COLUMN_NUMBER, COLUMN_PRODUCT, COLUMN_EDITABLE, NUM_COLUMNS = *(0..4).to_a
13
+ The cell renderers used in this demo are GtkCellRendererText,
14
+ GtkCellRendererCombo and GtkCellRendererProgress.
15
+ =end
16
+ class EditableCellsDemo
17
+ Item = Struct.new("Item", :number, :product, :yummy)
18
+ COL_ITEM_NUM, COL_ITEM_PROD, COL_ITEM_YUMMY = *(0..3).to_a
19
+ COL_NUM_TEXT = 0
18
20
 
19
- def initialize
20
- super('Shopping list')
21
- self.border_width = 5
21
+ def initialize(main_window)
22
+ @window = Gtk::Window.new(:toplevel)
23
+ @window.screen = main_window.screen
24
+ @window.title = "Editable Cells"
25
+ @window.border_width = 5
22
26
 
23
- vbox = Gtk::VBox.new(false, 5)
24
- add(vbox)
27
+ vbox = Gtk::Box.new(:vertical, 5)
28
+ @window.add(vbox)
29
+ label = Gtk::Label.new("Shopping list (you can edit the cells)")
30
+ vbox.pack_start(label, :expand => false, :fill => true, :padding => 0)
25
31
 
26
- vbox.pack_start(Gtk::Label.new('Shopping list (you can edit the cells!)'),
27
- :expand => false, :fill => false, :padding => 0)
32
+ sw = Gtk::ScrolledWindow.new
33
+ sw.shadow_type = :etched_in
34
+ sw.set_policy(:automatic, :automatic)
35
+ vbox.pack_start(sw, :expand => true, :fill => true, :padding => 0)
28
36
 
29
- sw = Gtk::ScrolledWindow.new
30
- sw.shadow_type = Gtk::SHADOW_ETCHED_IN
31
- sw.set_policy(:automatic, :automatic)
32
- vbox.pack_start(sw, :expand => true, :fill => true, :padding => 0)
37
+ # create models
38
+ create_items_model
39
+ create_numbers_model
33
40
 
34
- # create model
35
- model = create_model
41
+ # create tree view
42
+ @treeview = Gtk::TreeView.new(@items_model)
43
+ @treeview.selection.mode = :single
36
44
 
37
- # create tree view
38
- treeview = Gtk::TreeView.new(model)
39
- treeview.rules_hint = true
40
- treeview.selection.mode = Gtk::SELECTION_SINGLE
45
+ add_columns
41
46
 
42
- add_columns(treeview)
47
+ sw.add(@treeview)
43
48
 
44
- sw.add(treeview)
49
+ # Some buttons
50
+ hbox = Gtk::Box.new(:horizontal, 4)
51
+ hbox.homogeneous = true
52
+ vbox.pack_start(hbox, :expand => false, :fill => false, :padding => 0)
45
53
 
46
- # some buttons
47
- hbox = Gtk::Box.new(:horizontal, 4)
48
- hbox.homogeneous = true
49
- vbox.pack_start(hbox, :expand => false, :fill => false, :padding => 0)
54
+ button = Gtk::Button.new(:label => "Add item")
55
+ button.signal_connect("clicked") { add_item }
56
+ hbox.pack_start(button, :expand => true, :fill => true, :padding => 0)
50
57
 
51
- button = Gtk::Button.new('Add item')
52
- button.signal_connect('clicked') do
53
- add_item(model)
54
- end
55
- hbox.pack_start(button, :expand => true, :fill => true, :padding => 0)
58
+ button = Gtk::Button.new(:label => "Remove item")
59
+ button.signal_connect("clicked") { remove_item }
56
60
 
57
- button = Gtk::Button.new('Remove item')
58
- button.signal_connect('clicked') do
59
- remove_item(treeview)
60
- end
61
- hbox.pack_start(button, :expand => true, :fill => true, :padding => 0)
61
+ hbox.pack_start(button, :expand => true, :fill => true, :padding => 0)
62
+ @window.set_default_size(320, 200)
63
+ end
62
64
 
63
- set_default_size(320, 200)
65
+ def run
66
+ if !@window.visible?
67
+ @window.show_all
68
+ else
69
+ @window.destroy
64
70
  end
71
+ @window
72
+ end
65
73
 
66
- def create_model
67
- # create array
68
- @articles = []
74
+ private
75
+
76
+ def add_item
77
+ return if @items.nil?
78
+ item = Item.new(0, "Description here", 50)
79
+ @items << item
80
+
81
+ # Insert a row below the current one
82
+ path = @treeview.cursor[0]
83
+ iter = if path
84
+ current = @items_model.get_iter(path)
85
+ @items_model.insert_after(current)
86
+ else
87
+ @items_model.insert(-1)
88
+ end
89
+
90
+ # set the data for the new row
91
+ item.each_with_index do |value, index|
92
+ iter[index] = value
93
+ end
69
94
 
70
- add_items
95
+ # Move focus to the new row
96
+ path = @items_model.get_path(iter)
97
+ column = @treeview.get_column(0)
98
+ @treeview.set_cursor(path, column, false)
99
+ end
71
100
 
72
- # create list store
73
- model = Gtk::ListStore.new(Integer, String, TrueClass)
101
+ def remove_item
102
+ selection = @treeview.selection
103
+ iter = selection.selected
104
+ if iter
105
+ path = @items_model.get_path(iter)
106
+ i = path.indices[0]
107
+ @items_model.remove(iter)
108
+ @items.delete_at(i)
109
+ end
110
+ end
74
111
 
75
- # add items
76
- @articles.each do |article|
77
- iter = model.append
112
+ def add_items
113
+ @items << Item.new(3, "bottles of coke", 20)
114
+ @items << Item.new(5, "packages of noodles", 50)
115
+ @items << Item.new(2, "packages of chocolate chip cookies", 90)
116
+ @items << Item.new(1, "can vanilla ice cream", 60)
117
+ @items << Item.new(6, "eggs", 10)
118
+ end
78
119
 
79
- article.each_with_index do |value, index|
80
- iter.set_value(index, value)
81
- end
82
- end
83
- return model
120
+ def create_items_model
121
+ @items = []
122
+ add_items
123
+
124
+ # Create list store
125
+ @items_model = Gtk::ListStore.new(Integer, String, Integer, TrueClass)
126
+ @items.each do |item|
127
+ iter = @items_model.append
128
+ iter[COL_ITEM_NUM] = item.number
129
+ iter[COL_ITEM_PROD] = item.product
130
+ iter[COL_ITEM_YUMMY] = item.yummy
84
131
  end
132
+ end
85
133
 
86
- def add_items
87
- item = Item.new(3, 'bottles of coke', true)
88
- @articles.push(item)
134
+ def create_numbers_model
135
+ @numbers_model = Gtk::ListStore.new(String, Integer)
136
+ (1..10).each do |n|
137
+ iter = @numbers_model.append
138
+ iter[COL_NUM_TEXT] = n.to_s
139
+ end
140
+ end
89
141
 
90
- item = Item.new(5, 'packages of noodles', true)
91
- @articles.push(item)
142
+ def add_columns
143
+ add_number_column
144
+ add_product_column
145
+ add_yummy_column
146
+ end
92
147
 
93
- item = Item.new(2, 'packages of chocolate chip cookies', true)
94
- @articles.push(item)
148
+ def add_number_column
149
+ renderer = Gtk::CellRendererCombo.new
150
+ renderer.model = @numbers_model
151
+ renderer.text_column = COL_NUM_TEXT
152
+ renderer.has_entry = false
153
+ renderer.editable = true
95
154
 
96
- item = Item.new(1, 'can vanilla ice cream', true)
97
- @articles.push(item)
155
+ renderer.signal_connect "edited" do |cell, path, new_text|
156
+ cell_edited(cell, path, new_text)
157
+ end
98
158
 
99
- item = Item.new(6, 'eggs', true)
100
- @articles.push(item)
159
+ renderer.signal_connect "editing-started" do |_cell, editable, path|
160
+ editable.set_row_separator_func do |model, iter|
161
+ path = model.get_path(iter)
162
+ idx = path.indices[0]
163
+ idx == 5
164
+ end
101
165
  end
102
166
 
103
- def add_columns(treeview)
104
- model = treeview.model
167
+ def renderer.column
168
+ COL_ITEM_NUM
169
+ end
105
170
 
106
- # number column
107
- renderer = Gtk::CellRendererText.new
108
- renderer.signal_connect('edited') do |*args|
109
- cell_edited(*args.push(model))
110
- end
111
- treeview.insert_column(-1, 'Number', renderer,
112
- {
113
- :text => COLUMN_NUMBER,
114
- :editable => COLUMN_EDITABLE,
115
- })
116
- def renderer.column
117
- COLUMN_NUMBER
118
- end
171
+ @treeview.insert_column(-1, "Number", renderer, :text => COL_ITEM_NUM)
172
+ end
119
173
 
120
- # product column
121
- renderer = Gtk::CellRendererText.new
122
- renderer.signal_connect('edited') do |*args|
123
- cell_edited(*args.push(model))
124
- end
125
- def renderer.column
126
- COLUMN_PRODUCT
127
- end
128
- treeview.insert_column(-1, 'Product', renderer,
129
- {
130
- :text => COLUMN_PRODUCT,
131
- :editable => COLUMN_EDITABLE,
132
- })
174
+ def add_product_column
175
+ renderer = Gtk::CellRendererText.new
176
+ renderer.editable = true
177
+ renderer.signal_connect "edited" do |cell, path, new_text|
178
+ cell_edited(cell, path, new_text)
133
179
  end
134
180
 
135
- def cell_edited(cell, path_string, new_text, model)
136
- path = Gtk::TreePath.new(path_string)
137
-
138
- column = cell.column
139
-
140
- iter = model.get_iter(path)
141
- case column
142
- when COLUMN_NUMBER
143
- i = iter.path.indices[0]
144
- @articles[i].number = new_text.to_i
145
- iter.set_value(column, @articles[i].number)
146
- when COLUMN_PRODUCT
147
- i = iter.path.indices[0]
148
- @articles[i].product = new_text
149
- iter.set_value(column, @articles[i].product)
150
- end
181
+ def renderer.column
182
+ COL_ITEM_PROD
151
183
  end
152
184
 
153
- def add_item(model)
154
- foo = Item.new(0, 'Description here', true)
155
- @articles.concat([foo])
185
+ @treeview.insert_column(-1, "Product", renderer, :text => COL_ITEM_PROD)
186
+ end
156
187
 
157
- iter = model.append
158
- foo.each_with_index do |value, index|
159
- iter.set_value(index, value)
160
- end
188
+ def add_yummy_column
189
+ renderer = Gtk::CellRendererProgress.new
190
+ def renderer.column
191
+ COL_ITEM_YUMMY
161
192
  end
193
+ @treeview.insert_column(-1, "Yummy", renderer, :value => COL_ITEM_YUMMY)
194
+ end
162
195
 
163
- def remove_item(treeview)
164
- model = treeview.model
165
- selection = treeview.selection
166
-
167
- if iter = selection.selected
168
- @articles.delete_at(iter.path.indices[0])
169
- model.remove(iter)
170
- end
196
+ def cell_edited(cell, path_string, new_text)
197
+ path = Gtk::TreePath.new(path_string)
198
+ column = cell.column
199
+ iter = @items_model.get_iter(path)
200
+
201
+ case column
202
+ when COL_ITEM_NUM
203
+ i = path.indices[0]
204
+ @items[i].number = new_text.to_i
205
+ iter.set_value(column, @items[i].number)
206
+ when COL_ITEM_PROD
207
+ i = path.indices[0]
208
+ @items[i].product = new_text
209
+ iter.set_value(column, @items[i].product)
171
210
  end
172
211
  end
173
212
  end