rbcurse 1.1.5 → 1.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/CHANGELOG +45 -0
  2. data/Makefile +1 -1
  3. data/Manifest.txt +91 -0
  4. data/NOTES +349 -2
  5. data/README.markdown +12 -0
  6. data/VERSION +1 -1
  7. data/examples/abasiclist.rb +25 -0
  8. data/examples/alpmenu.rb +42 -0
  9. data/examples/app.rb +883 -0
  10. data/examples/appcombo.rb +17 -0
  11. data/examples/appdirtree.rb +73 -0
  12. data/examples/appemail.rb +164 -0
  13. data/examples/appemaillb.rb +308 -0
  14. data/examples/appgcompose.rb +303 -0
  15. data/examples/appgmail.rb +951 -0
  16. data/examples/atree.rb +56 -0
  17. data/examples/dirtree.rb +78 -0
  18. data/examples/focusmanager.rb +31 -0
  19. data/examples/imap.rb +48 -0
  20. data/examples/menu1.rb +79 -0
  21. data/examples/multispl.rb +86 -0
  22. data/examples/rfe.rb +3 -4
  23. data/examples/rmail.rb +188 -0
  24. data/examples/s.rb +10 -0
  25. data/examples/scrollbar.rb +104 -0
  26. data/examples/splitp.rb +56 -0
  27. data/examples/table1.rb +30 -0
  28. data/examples/term.rb +48 -0
  29. data/examples/term2.rb +54 -0
  30. data/examples/test1.rb +4 -2
  31. data/examples/test2.rb +9 -9
  32. data/examples/testapp.rb +44 -0
  33. data/examples/testapp2.rb +51 -0
  34. data/examples/testcombo.rb +2 -2
  35. data/examples/testgmail.rb +46 -0
  36. data/examples/testlistbox.rb +0 -1
  37. data/examples/testmultispl.rb +199 -0
  38. data/examples/testree.rb +127 -0
  39. data/examples/testscroller.rb +0 -1
  40. data/examples/testscrolllb.rb +1 -1
  41. data/examples/testscrollp.rb +2 -1
  42. data/examples/testscrollta.rb +1 -1
  43. data/examples/testscrolltable.rb +1 -2
  44. data/examples/testsplit.rb +1 -1
  45. data/examples/testsplit2.rb +1 -1
  46. data/examples/testsplit3.rb +1 -1
  47. data/examples/testsplit3_1.rb +1 -1
  48. data/examples/testsplit3a.rb +1 -1
  49. data/examples/testsplit3b.rb +1 -1
  50. data/examples/testsplitta.rb +1 -1
  51. data/examples/testsplittv.rb +1 -1
  52. data/examples/testsplittvv.rb +1 -1
  53. data/examples/testtodo.rb +491 -488
  54. data/examples/testvimsplit.rb +111 -0
  55. data/examples/todo.db +0 -0
  56. data/examples/todocsv.csv +28 -0
  57. data/examples/viewtodo.rb +408 -403
  58. data/lib/rbcurse/action.rb +1 -0
  59. data/lib/rbcurse/app.rb +1294 -0
  60. data/lib/rbcurse/applicationheader.rb +7 -2
  61. data/lib/rbcurse/checkboxcellrenderer.rb +0 -12
  62. data/lib/rbcurse/colormap.rb +34 -8
  63. data/lib/rbcurse/comboboxcellrenderer.rb +0 -11
  64. data/lib/rbcurse/defaultlistselectionmodel.rb +23 -7
  65. data/lib/rbcurse/extras/bottomline.rb +1681 -0
  66. data/lib/rbcurse/extras/directorylist.rb +445 -0
  67. data/lib/rbcurse/extras/directorytree.rb +69 -0
  68. data/lib/rbcurse/extras/divider.rb +310 -0
  69. data/lib/rbcurse/extras/focusmanager.rb +31 -0
  70. data/lib/rbcurse/extras/listselectable.rb +222 -0
  71. data/lib/rbcurse/extras/masterdetail.rb +164 -0
  72. data/lib/rbcurse/extras/menutree.rb +63 -0
  73. data/lib/rbcurse/extras/rlink.rb +27 -0
  74. data/lib/rbcurse/extras/rmenulink.rb +21 -0
  75. data/lib/rbcurse/extras/scrollbar.rb +134 -0
  76. data/lib/rbcurse/extras/stdscrwindow.rb +247 -0
  77. data/lib/rbcurse/extras/tabular.rb +258 -0
  78. data/lib/rbcurse/extras/tabularwidget.rb +1070 -0
  79. data/lib/rbcurse/extras/viewer.rb +106 -0
  80. data/lib/rbcurse/io.rb +137 -80
  81. data/lib/rbcurse/keylabelprinter.rb +4 -0
  82. data/lib/rbcurse/listcellrenderer.rb +91 -59
  83. data/lib/rbcurse/listscrollable.rb +93 -95
  84. data/lib/rbcurse/listselectable.rb +60 -7
  85. data/lib/rbcurse/ractionevent.rb +67 -0
  86. data/lib/rbcurse/rbasiclistbox.rb +688 -0
  87. data/lib/rbcurse/rcombo.rb +5 -5
  88. data/lib/rbcurse/rcommandwindow.rb +555 -0
  89. data/lib/rbcurse/rinputdataevent.rb +12 -0
  90. data/lib/rbcurse/rlistbox.rb +305 -124
  91. data/lib/rbcurse/rmenu.rb +99 -46
  92. data/lib/rbcurse/rmessagebox.rb +13 -6
  93. data/lib/rbcurse/rmulticontainer.rb +54 -93
  94. data/lib/rbcurse/rmultisplit.rb +731 -0
  95. data/lib/rbcurse/rmultitextview.rb +3 -2
  96. data/lib/rbcurse/rpopupmenu.rb +0 -1
  97. data/lib/rbcurse/rprogress.rb +117 -0
  98. data/lib/rbcurse/rscrollpane.rb +2 -1
  99. data/lib/rbcurse/rsplitpane.rb +94 -20
  100. data/lib/rbcurse/rsplitpane2.rb +1009 -0
  101. data/lib/rbcurse/rtabbedpane.rb +3 -2
  102. data/lib/rbcurse/rtabbedwindow.rb +0 -1
  103. data/lib/rbcurse/rtable.rb +92 -64
  104. data/lib/rbcurse/rtextarea.rb +91 -57
  105. data/lib/rbcurse/rtextview.rb +223 -70
  106. data/lib/rbcurse/rtree.rb +723 -0
  107. data/lib/rbcurse/rviewport.rb +2 -1
  108. data/lib/rbcurse/rvimsplit.rb +768 -0
  109. data/lib/rbcurse/rwidget.rb +524 -325
  110. data/lib/rbcurse/table/tablecellrenderer.rb +1 -1
  111. data/lib/rbcurse/table/tabledatecellrenderer.rb +0 -1
  112. data/lib/rbcurse/tree/treecellrenderer.rb +137 -0
  113. data/lib/rbcurse/tree/treemodel.rb +428 -0
  114. data/lib/rbcurse/vieditable.rb +14 -13
  115. data/lib/ver/ncurses.rb +6 -0
  116. data/lib/ver/window.rb +67 -32
  117. metadata +99 -23
  118. data/bin/rbcurse +0 -0
  119. data/examples/rvimsplit.rb +0 -376
  120. data/examples/todo.rb +0 -1
  121. data/lib/rbcurse/rform.rb +0 -845
  122. data/lib/rbcurse/selectable.rb +0 -94
  123. data/rbcurse.gemspec +0 -188
@@ -49,6 +49,7 @@ module RubyCurses
49
49
  #@row_offset = @col_offset = 1
50
50
  #@orig_col = @col
51
51
  init_vars
52
+ @_events.push :STATE_CHANGE
52
53
  end
53
54
  def init_vars
54
55
  #@curpos = @pcol = @toprow = @current_index = 0
@@ -65,7 +66,7 @@ module RubyCurses
65
66
  height(h)
66
67
  width(w)
67
68
  fire_state_changed
68
- #fire_handler :PROPERTY_CHANGE, self # XXX should it be an event STATE_CHANGED with details
69
+ #fire_handler :PROPERTY_CHANGE, self # XXX should it be an event STATE_CHANGE with details
69
70
  end
70
71
  ##
71
72
  # Set the row and col of the child, that the viewport starts displaying.
@@ -0,0 +1,768 @@
1
+ # This is a new kind of splitpane, inspired by the vim editor.
2
+ # I was deeply frustrated with the Java kind of splitpane,
3
+ # which requires splitpanes within splitpanes to get several split.
4
+ # This is an attempt at getting many splits, keeping them at one level
5
+ # and keeping the interface as simple as possible, with minimal input
6
+ # from user.
7
+ # It usually takes a listbox or textview or textarea.
8
+ # It can also take an array, or string or hash.
9
+ # It supports moving the split, and increasing or decreasing the current box to some extent.
10
+ # Typically if the split is vertical, add stacks the components, one below the other.
11
+ # If horizontal, if will flow the components, to the right of previous. This can be overriden by passing
12
+ # type as :STACK or :FLOW.
13
+ # See examples/testvimsplit.rb
14
+ #
15
+ # This does not support changing the orientation at run time, that's nice for demos, but a pain
16
+ # to get right, and results in a lot of extra code, meaning more bugs.
17
+ # TODO: create a class that contains component array and a pointer so it can give next/prev
18
+ # i am tired of maintaining this everywhere.
19
+ require 'rbcurse'
20
+ require 'rbcurse/rlistbox'
21
+ require 'rbcurse/rtextview'
22
+ require 'rbcurse/extras/divider'
23
+ require 'rbcurse/extras/focusmanager'
24
+
25
+ include RubyCurses
26
+ module RubyCurses
27
+ extend self
28
+ class Coord < Struct.new(:row, :col, :h, :w); end
29
+ # Split contains info for a component added. weight is preferred weight
30
+ # and can contain value :AUTO. act_weight has the weight calculated.
31
+ # Often, last component can be nil, remainder will be assigned to it.
32
+ class Split < Struct.new(:which, :type, :weight, :act_weight); end
33
+ class ResizeEvent < Struct.new(:source, :type); end
34
+
35
+ # A simpler replacement for the java-esque SplitPane. This can take multiple splits
36
+ # and does not require splits within splits as SplitPane does.
37
+ # This is less functional, but should be easier to use, setup and hack.
38
+ class VimSplit < Widget
39
+
40
+ # split orientation :V or :H
41
+ dsl_accessor :orientation
42
+ # min and max weight of main split. do not allow user to exceed these
43
+ dsl_accessor :min_weight, :max_weight
44
+ dsl_accessor :suppress_borders #to_print_borders
45
+ dsl_accessor :border_attrib, :border_color
46
+ attr_reader :current_component
47
+ def initialize form, config={}, &block
48
+ if config[:width] == :EXPAND
49
+ config[:width] = Ncurses.COLS - config[:col]
50
+ end
51
+ if config[:orientation] == nil
52
+ config[:orientation] = :HORIZONTAL_SPLIT
53
+ else
54
+ # if first char is V or H then fill it in.
55
+ char = config[:orientation].to_s[0,1].upcase
56
+ if char == "V"
57
+ config[:orientation] = :VERTICAL_SPLIT
58
+ else
59
+ config[:orientation] = :HORIZONTAL_SPLIT
60
+ end
61
+ end
62
+ @max_weight ||= 0.8
63
+ @min_weight ||= 0.1 # earlier 0.2 but i wanted 0.15, someone may want 0.05 ??
64
+ @suppress_borders = false
65
+ @_use_preferred_sizes = true
66
+ @row_offset = @col_offset = 1
67
+ super
68
+ @focusable = true
69
+ @editable = false
70
+ @components = [] # all components
71
+ @c1 =[] # first split's comps
72
+ @c2 =[] # second split's comps
73
+ # coordinates of a split, i calculate and increment row col as i go.
74
+ @c1rc = nil # TODO create once only
75
+ @c2rc = nil
76
+
77
+ # hash, keyed on component, contains Split (which side, flow or stack, weight)
78
+ @ch = {}
79
+ @weight ||= 0.50
80
+ # type can be :INCREASE, :DECREASE, :EXPAND, :UNEXPAND :EQUAL
81
+ @_events.push :COMPONENT_RESIZE_EVENT
82
+ @_events.push :DRAG_EVENT
83
+
84
+ init_vars
85
+ bind_key([?\C-w,?o], :expand)
86
+ bind_key([?\C-w,?1], :expand)
87
+ bind_key([?\C-w,?2], :unexpand)
88
+ bind_key([?\C-w,?\C-w], :goto_other_split)
89
+ bind_key([?\C-w,?-], :decrease_height)
90
+ bind_key([?\C-w,?+], :increase_height)
91
+ bind_key([?\C-w,?<], :decrease_width)
92
+ bind_key([?\C-w,?>], :increase_width)
93
+ bind_key([?\C-w,?i], :increase_weight)
94
+ bind_key([?\C-w,?d], :decrease_weight)
95
+ bind_key([?\C-w,?6], :increase_current_component)
96
+ bind_key([?\C-w,?5], :decrease_current_component)
97
+ # this needs to be set at application level
98
+ bind_key(KEY_F3) {RubyCurses::FocusManager.toggle_focusable}
99
+ end
100
+ def init_vars
101
+ @repaint_required = true
102
+ @recalculate_splits = true # convert weight to size
103
+ # seems it works with false also, so do we really need it to be true ?
104
+ # whe true was giving a seg fault on increasing child window by 0.05
105
+ @_child_buffering = false # private, internal. not to be changed by callers.
106
+ @row_offset = @col_offset = 0 if @suppress_borders # FIXME supposed to use this !!
107
+
108
+ @internal_width = 2
109
+ @internal_width = 1 if @suppress_borders
110
+
111
+ end
112
+ # uses intelligent default a vertical split would prefer stacks and
113
+ # a horizontal split would go with flows
114
+ # @param [Widget, Array, String, Hash, Variable] to add
115
+ # @param [:FIRST, :SECOND]
116
+ def add c, which, weight=:AUTO, type=:AUTO
117
+ if type == :AUTO
118
+ if v?
119
+ type = :STACK
120
+ else
121
+ type = :FLOW
122
+ end
123
+ end
124
+ _add type, c, which, weight
125
+ #return self # lets return component created for christ's sake and keep it simple
126
+ end
127
+ # set the weight of outer split
128
+ def weight(*val)
129
+ if val.empty?
130
+ return @weight
131
+ else
132
+ # raise ArgumentError
133
+ newval = val[0]
134
+ # this is since, using numeric multipliers he can go beyond, so lets give him the best
135
+ if val[0] < @min_weight
136
+ newval = @min_weight
137
+ elsif val[0] > @max_weight
138
+ newval = @max_weight
139
+ end
140
+ oldvalue = @weight
141
+ @weight = newval
142
+ # orientation can be nil, so we cannot calculate rc here
143
+ #if v?
144
+ #@rc = (@width * @weight).to_i
145
+ #else
146
+ #@rc = (@height * @weight).to_i
147
+ #end
148
+ @rc = nil # so recalculated in repaint
149
+ fire_property_change(:weight, oldvalue, @weight)
150
+ end
151
+ self
152
+ end
153
+ # stack components, one over another, useful in a vertical split
154
+ # @param [Widget] component
155
+ # @param [:FIRST :SECOND] first or second split
156
+ # @param [Float, nil, :AUTO] weight of object, nil for last will expand it to full
157
+ # :AUTO will give equal weight to all
158
+ def stack c, which, weight
159
+ _add :STACK, c, which, weight
160
+ #return self # lets return component created for christ's sake and keep it simple
161
+ end
162
+ # place components on right of previous. Useful in horizontal split
163
+ def flow c, which, weight
164
+ _add :FLOW, c, which, weight
165
+ #return self # lets return component created for christ's sake and keep it simple
166
+ end
167
+ private
168
+ def _add type, c, which, weight
169
+ raise ArgumentError, "Nil component passed to add" unless c
170
+ raise ArgumentError, "which must be :FIRST or :SECOND" if which != :FIRST && which != :SECOND
171
+ # trying out wt of 0 means it will see height of object and use that.
172
+ if weight.nil? || weight == :AUTO || (weight >= 0 && weight <= 1.0)
173
+ else
174
+ raise ArgumentError, "weight must be >0 and <=1.0 or nil or :AUTO"
175
+ end
176
+ if c.is_a? Widget
177
+ if c.form && c.form != @form
178
+ $log.debug " removing widget VIMSPLIT #{c.class} "
179
+ c.form.remove_widget c
180
+ c.form = nil
181
+ end
182
+ #$log.debug " XXXX VIM is a widget"
183
+ else
184
+ case c
185
+ when Array
186
+ lb = Listbox.new nil, :list => c , :name => "list#{@components.size}"
187
+ c = lb
188
+ when String
189
+ lb = TextView.new nil, :name => "text#{@components.size}"
190
+ lb.set_content c
191
+ c = lb
192
+ when Hash
193
+ lb = Listbox.new nil, :list => c.keys , :name => "list#{@components.size}"
194
+ c = lb
195
+ when Variable
196
+ # TODO
197
+ else
198
+ if c == :grabbar || c == :divider
199
+ side = :bottom
200
+ case type
201
+ when :STACK
202
+ side = :bottom
203
+ when :FLOW
204
+ side = :left
205
+ end
206
+ c = Divider.new nil, :parent => @components.last, :side => side
207
+ c.focusable(false)
208
+ RubyCurses::FocusManager.add c
209
+ c.bind :DRAG_EVENT do |ev|
210
+ source = ev.source
211
+ case ev.type
212
+ when KEY_UP
213
+ # CHECK BOUNDS TODO
214
+ # TODO what about KEY_LEFT and RIGHT ?
215
+ if source.next && source.next.row > 1 && source.parent.height > 1
216
+ source.parent.height -= 1
217
+ source.next.height +=1
218
+ source.next.row -= 1
219
+ source.parent.repaint_required
220
+ source.next.repaint_required
221
+ source.parent.repaint
222
+ source.next.repaint
223
+ end
224
+ when KEY_DOWN
225
+ # CHECK BOUNDS TODO check with appemail.rb
226
+ if source.next && source.next.height > 1
227
+ source.parent.height += 1
228
+ source.next.height -=1
229
+ source.next.row += 1
230
+ source.parent.repaint_required
231
+ source.next.repaint_required
232
+ source.parent.repaint
233
+ source.next.repaint
234
+ end
235
+ end
236
+ end
237
+ end
238
+ end
239
+ end
240
+ c.parent_component = self
241
+ c.should_create_buffer = @_child_buffering
242
+ c.ext_row_offset += @ext_row_offset + @row #- @subform1.window.top #0# screen_row
243
+ c.ext_col_offset += @ext_col_offset + @col #-@subform1.window.left # 0# screen_col
244
+
245
+ @components << c
246
+ if which == :FIRST
247
+ @c1 << c
248
+ else
249
+ @c2 << c
250
+ end
251
+ #@ch[c] = [which, type, weight]
252
+ @ch[c] = Split.new(which, type, weight)
253
+ @repaint_required = true
254
+ return c
255
+ end
256
+ public
257
+ def split_info_for(c = @current_component)
258
+ @ch[c]
259
+ end
260
+ # get the current split focus is on
261
+ # @return [:FIRST, :SECOND] which split are we on
262
+ def current_split
263
+ split_info_for(@current_component).which
264
+ end
265
+ # returns the other split.
266
+ def other_split
267
+ which = current_split
268
+ return which == :FIRST ? :SECOND : :FIRST
269
+ end
270
+ # returns list of components for FIRST or SECOND split
271
+ def components_for which
272
+ return which == :FIRST ? @c1 : @c2
273
+ end
274
+
275
+ public
276
+ # repaint object
277
+ # called by Form, and sometimes parent component (if not form).
278
+ def repaint
279
+ safe_create_buffer # 2010-01-04 12:36 BUFFERED moved here 2010-01-05 18:07
280
+ my_win = @form ? @form.window : @target_window
281
+ @graphic = my_win unless @graphic
282
+ raise " #{@name} neither form, nor target window given TV paint " unless my_win
283
+ raise " #{@name} NO GRAPHIC set as yet TV paint " unless @graphic
284
+ @win_left = my_win.left
285
+ @win_top = my_win.top
286
+
287
+ #return unless @repaint_required
288
+ @recalculate_splits = true if @rc.nil?
289
+
290
+ # if some major change has happened then repaint everything
291
+ if @repaint_required
292
+ $log.debug " VIM repaint graphic #{@graphic} "
293
+ print_borders unless @suppress_borders # do this once only, unless everything changes
294
+ r,c = rowcol
295
+
296
+ bordercolor = @border_color || $datacolor
297
+ borderatt = @border_attrib || Ncurses::A_NORMAL
298
+
299
+
300
+ @graphic.attron(Ncurses.COLOR_PAIR(bordercolor) | borderatt)
301
+ @gbwid ||= 0
302
+ roffset = 1
303
+ loffset = 2
304
+ if @suppress_borders
305
+ loffset = roffset = 0
306
+ end
307
+ if v?
308
+ @rc ||= (@width * @weight).to_i
309
+ rc = @rc
310
+ $log.debug "SPLP #{@name} prtingign split vline divider 1, rc: #{rc}, h:#{@height} - 2 "
311
+ unless @vb
312
+ @gbwid = 1
313
+ _create_divider
314
+ else
315
+ @vb.row @row+roffset
316
+ @vb.col rc+@col
317
+ #@vb.repaint
318
+ end
319
+ #@graphic.mvvline(@row+1, rc+@col, 0, @height-2)
320
+ # TODO don;t keep recreating, if present, reset values
321
+ @c1rc = Coord.new(@row,@col, @height -0, rc-@gbwid)
322
+ @c2rc = Coord.new(@row,rc+@col+@gbwid,@height-0, @width - rc-@gbwid)
323
+ else
324
+ @rc ||= (@height * @weight).to_i
325
+ rc = @rc
326
+ $log.debug "SPLP #{@name} prtingign split hline divider rc: #{rc} , 1 , w:#{@width} - 2"
327
+ unless @vb
328
+ @gbwid = 1
329
+ _create_divider
330
+ else
331
+ #@vb = Divider.new nil, :row => @row+rc-1, :col => @col+1, :length => @width-loffset, :side => :bottom
332
+ @vb.row @row+@rc-1
333
+ @vb.col @col+roffset
334
+ #@vb.repaint # getting wiped out by vimsplit ?
335
+ end
336
+ #@graphic.mvhline(rc+@row, @col+1, 0, @width-@internal_width)
337
+ #@neat = true
338
+ if @neat
339
+ a = 1
340
+ @c1rc = Coord.new(@row+a,@col+a, rc-a, @width-@internal_width)
341
+ @c2rc = Coord.new(@row+rc+a,@col+a, @height-rc-2, @width - @internal_width)
342
+ else
343
+ # flush
344
+ #@c1rc = Coord.new(@row,@col, @height -0, rc-@gbwid)
345
+ #@c2rc = Coord.new(@row,rc+@col+@gbwid,@height-0, @width - rc-@gbwid)
346
+ a = 0
347
+ @c1rc = Coord.new(@row,@col, rc-@gbwid, @width)
348
+ @c2rc = Coord.new(@row+rc, @col, @height-rc-@gbwid, @width)
349
+ end
350
+ end
351
+ @graphic.attroff(Ncurses.COLOR_PAIR(bordercolor) | borderatt)
352
+ @components.each { |e| e.repaint_all(true) }
353
+ $log.debug " XXX VIM REPAINT ALL "
354
+ # FIXME do this only once, or when major change happends, otherwise
355
+ # i cannot increase decrease size on user request.
356
+ recalculate_splits @_use_preferred_sizes if @recalculate_splits
357
+ # vimsplit often overwrites this while divider is being moved so we must
358
+ # again call it.
359
+ @vb.repaint if @vb
360
+ else
361
+ # only repaint those that are needing repaint
362
+ # 2010-09-22 18:09 its possible somenoe has updated an internal
363
+ # component, but this container does not know. So we've got to call
364
+ # repaint on all components, only those which are changed will
365
+ # actually be repainted
366
+ @components.each { |e| e.repaint }
367
+ end # if repaint_required
368
+ # NOTE: at present one cannot change from flow to stack inside a pane
369
+
370
+ @repaint_required = false
371
+ @buffer_modified = true # required by form to call buffer_to_screen BUFFERED
372
+ buffer_to_window #
373
+ end
374
+ def v?
375
+ @orientation == :VERTICAL_SPLIT
376
+ end
377
+ def h?
378
+ !@orientation == :VERTICAL_SPLIT
379
+ end
380
+ # convert weight to height and length
381
+ # we should only do this once, or if major change
382
+ # otherwise changes that user may have effected in size will be lost
383
+ # NOTE: this resets all components to preferred weights (given when component was added.
384
+ # If user has resized components
385
+ # then those changes in size will be lost.
386
+ def reset_to_preferred_size
387
+ recalculate_splits use_preferred_sizes=true
388
+ end
389
+ def recalculate_splits use_preferred_sizes=false
390
+ @recalculate_splits = false
391
+ [@c1,@c2].each_with_index do |c,i|
392
+ rca = @c1rc
393
+ if i == 1
394
+ #$log.debug " XXX VIM moving to second"
395
+ rca = @c2rc
396
+ end
397
+ totalw = 0 # accumulative weight
398
+ totalwd = 0 # accumulative weight for width (in case someone switches)
399
+ totalht = 0 # accumulative weight for height (in case someone switches)
400
+ sz = c.size
401
+ auto = 1.0/sz
402
+ c.each do |e|
403
+ r = rca.row
404
+ c = rca.col
405
+ info = @ch[e]
406
+ type = info.type
407
+ wt = info.weight
408
+ wt = auto if wt == :AUTO
409
+ e.row = r
410
+ e.col = c
411
+ if type == :STACK
412
+ # store actual weight that was calculated, so if user reduces or increases
413
+ # we can use this, although ... we have no method that uses actual weights
414
+ # NOTE: If calling program increases one comp's weight, will have to reduce other.
415
+ info.act_weight = wt
416
+
417
+ e.width = (rca.w * (1 - totalwd)).to_i
418
+ # recaclulate height only in this case, otherwise we will overwrite changes
419
+ # made by user
420
+ if use_preferred_sizes
421
+ if wt != 0
422
+ if wt
423
+ e.height = ((rca.h * wt).to_i)
424
+ else
425
+ a = 0
426
+ a = 1 if @suppress_borders
427
+ e.height = rca.h - rca.row + a # take exactly rows left
428
+ end
429
+ # else use its own height
430
+ end
431
+ end
432
+ rca.row += e.height
433
+ totalht += wt if wt
434
+ else
435
+ # TODO THIS PART AS PER ABOVE CASE , TO TEST
436
+ # this is a horizontal split or flow
437
+ info.act_weight = wt
438
+ #e.height = rca.h
439
+ e.height = (rca.h * (1- totalht)).to_i
440
+ if use_preferred_sizes
441
+ if wt != 0
442
+ if wt
443
+ e.width = ((rca.w * wt).to_i)
444
+ else
445
+ a = 0
446
+ a = 1 if @suppress_borders
447
+ e.width = rca.w - rca.col + a # take exactly rows left
448
+ end
449
+ end
450
+ end
451
+ rca.col += e.width
452
+ totalwd += wt if wt
453
+ end
454
+ e.set_buffering(:target_window => @target_window || @form.window, :bottom => e.height-1, :right => e.width-1, :form => @form )
455
+ e.set_buffering(:screen_top => e.row, :screen_left => e.col)
456
+ $log.debug " XXXXX VIMS R #{e.row} C #{e.col} H #{e.height} W #{e.width} "
457
+ e.repaint
458
+ e._object_created = true # added 2010-09-16 13:02 now prop handlers can be fired
459
+ end
460
+ end
461
+ @_use_preferred_sizes = false
462
+ end
463
+
464
+ private
465
+ def print_borders
466
+ width = @width
467
+ height = @height-1 # 2010-01-04 15:30 BUFFERED HEIGHT
468
+ window = @graphic # 2010-01-04 12:37 BUFFERED
469
+ startcol = @col
470
+ startrow = @row
471
+ @color_pair = get_color($datacolor)
472
+ #$log.debug "rlistb #{name}: window.print_border #{startrow}, #{startcol} , h:#{height}, w:#{width} , @color_pair, @attr "
473
+ window.print_border startrow, startcol, height, width, @color_pair, @attr
474
+ print_title
475
+ end
476
+ def print_title
477
+ @graphic.printstring( @row, @col+(@width-@title.length)/2, @title, @color_pair, @title_attrib) unless @title.nil?
478
+ end
479
+
480
+ public
481
+ # called by parent or form, otherwise its private
482
+ def handle_key ch
483
+ $log.debug " VIMSPLIT handle_key #{ch} "
484
+ _multiplier = ($multiplier == 0 ? 1 : $multiplier )
485
+ if ch == KEY_TAB
486
+ $log.debug " GOTO NEXT"
487
+ return goto_next_component
488
+ elsif ch == KEY_BTAB
489
+ return goto_prev_component
490
+ end
491
+ comp = @current_component
492
+ $log.debug " VIMSPL handle_k #{ch}: #{comp}"
493
+ if comp
494
+ ret = comp.handle_key(ch)
495
+ if ret != :UNHANDLED
496
+ comp.repaint # NOTE: if we don;t do this, then it won't get repainted. I will have to repaint ALL
497
+ # in repaint of this.
498
+ return ret
499
+ end
500
+ end
501
+ $log.debug "XXX VIM unahdled by comp #{comp.name} "
502
+ case ch
503
+ when ?\C-c.getbyte(0)
504
+ $multiplier = 0
505
+ return 0
506
+ when ?0.getbyte(0)..?9.getbyte(0)
507
+ $log.debug " VIM coming here to set multiplier #{$multiplier} "
508
+ $multiplier *= 10 ; $multiplier += (ch-48)
509
+ return 0
510
+ end
511
+ ret = process_key ch, self
512
+ # allow user to map left and right if he wants
513
+ if ret == :UNHANDLED
514
+ case ch
515
+ when KEY_UP
516
+ # form will pick this up and do needful
517
+ return goto_prev_component #unless on_first_component?
518
+ when KEY_LEFT
519
+ # if i don't check for first component, key will go back to form,
520
+ # but not be processes. so focussed remain here, but be false.
521
+ # In case of returnign an unhandled TAB, on_leave will happen and cursor will move to
522
+ # previous component outside of this.
523
+ return goto_prev_component unless on_first_component?
524
+ when KEY_RIGHT
525
+ return goto_next_component #unless on_last_component?
526
+ when KEY_DOWN
527
+ return goto_next_component #unless on_last_component?
528
+ else
529
+ return :UNHANDLED
530
+ end
531
+ end
532
+
533
+ $multiplier = 0
534
+ return 0
535
+ end
536
+ # private
537
+ def on_enter
538
+ # TODO if BTAB the last comp
539
+ if $current_key == KEY_BTAB
540
+ # FIXME last is not focusable, then ??
541
+ @current_component = @components.last
542
+ else
543
+ @current_component = @components.first
544
+ end
545
+ $log.debug " VIM came to on_enter #{@current_component} "
546
+ set_form_row
547
+ end
548
+ def on_leave
549
+ super
550
+ end
551
+ def goto_next_component
552
+ if @current_component != nil
553
+ leave_current_component
554
+ if on_last_component?
555
+ return :UNHANDLED
556
+ end
557
+ @current_index = @components.index(@current_component)
558
+ index = @current_index + 1
559
+ index.upto(@components.length-1) do |i|
560
+ f = @components[i]
561
+ if f.focusable
562
+ @current_index = i
563
+ @current_component = f
564
+ return set_form_row
565
+ end
566
+ end
567
+ end
568
+ return :UNHANDLED
569
+ end
570
+ def goto_prev_component
571
+ if @current_component != nil
572
+ leave_current_component
573
+ if on_first_component?
574
+ return :UNHANDLED
575
+ end
576
+ @current_index = @components.index(@current_component)
577
+ index = @current_index -= 1
578
+ index.downto(0) do |i|
579
+ f = @components[i]
580
+ if f.focusable
581
+ @current_index = i
582
+ @current_component = f
583
+ return set_form_row
584
+ end
585
+ end
586
+ end
587
+ return :UNHANDLED
588
+ end
589
+ # private
590
+ def set_form_row
591
+ #return :UNHANDLED if @current_component.nil?
592
+ $log.debug " VIM on enter sfr #{@current_component} "
593
+ @current_component.on_enter
594
+ @current_component.set_form_col # XXX
595
+ @current_component.repaint
596
+ # XXX compo should do set_form_row and col if it has that
597
+ end
598
+ # private
599
+ def set_form_col
600
+ return if @current_component.nil?
601
+ $log.debug " #{@name} set_form_col calling sfc for #{@current_component.name} "
602
+ @current_component.set_form_col
603
+ end
604
+ # leave the component we are on.
605
+ # This should be followed by all containers, so that the on_leave action
606
+ # of earlier comp can be displayed, such as dimming components selections
607
+ def leave_current_component
608
+ @current_component.on_leave
609
+ # NOTE this is required, since repaint will just not happen otherwise
610
+ # Some components are erroneously repainting all, after setting this to true so it is
611
+ # working there.
612
+ @current_component.repaint_required true
613
+ $log.debug " after on_leave VIMS XXX #{@current_component.focussed} #{@current_component.name}"
614
+ @current_component.repaint
615
+ end
616
+
617
+ # is focus on first component
618
+ def on_first_component?
619
+ @current_component == @components.first
620
+ end
621
+ # is focus on last component
622
+ def on_last_component?
623
+ @current_component == @components.last
624
+ end
625
+ def goto_other_split
626
+ c = components_for(other_split)
627
+ leave_current_component
628
+ @current_component = c.first
629
+ set_form_row
630
+ end
631
+ # set focus on given component
632
+ # Sometimes you have the handle to component, and you want to move focus to it
633
+ def goto_component comp
634
+ return if comp == @current_component
635
+ leave_current_component
636
+ @current_component = comp
637
+ set_form_row
638
+ end
639
+ # decrease the weight of the split
640
+ def decrease_weight
641
+ _multiplier = ($multiplier == 0 ? 1 : $multiplier )
642
+ weight(weight - 0.05*_multiplier)
643
+ end
644
+ # increase the weight of the split
645
+ def increase_weight
646
+ _multiplier = ($multiplier == 0 ? 1 : $multiplier )
647
+ weight(weight + 0.05*_multiplier)
648
+ end
649
+ # FIXME - i can only reduce if i've increased
650
+ def decrease_current_component
651
+ info = split_info_for
652
+ #info.add_weight = 0 if info.add_weight.nil?
653
+ #if info.add_weight > 0.0
654
+ #info.add_weight = info.add_weight - 0.05
655
+ #end
656
+ e = ResizeEvent.new @current_component, :DECREASE
657
+ fire_handler :COMPONENT_RESIZE_EVENT, e
658
+ #@repaint_required = true
659
+ end
660
+ # fires handler to request app to resize component
661
+ # @param [:INCREASE, :DECREASE]
662
+ # @param [:HEIGHT, :WIDTH]
663
+ def resize_component incdec, hw #:nodoc:
664
+ type = incdec.to_s + '_' + hw.to_s
665
+ #info = split_info_for
666
+ #info.add_weight = 0 if info.add_weight.nil?
667
+ e = ResizeEvent.new @current_component, type.to_sym
668
+ fire_handler :COMPONENT_RESIZE_EVENT, e
669
+ #@repaint_required = true
670
+ end
671
+ # fires handler to request app to resize current component
672
+ #
673
+ def decrease_height
674
+ resize_component :DECREASE, :HEIGHT
675
+ end
676
+ # fires handler to request app to resize current component
677
+ def decrease_width
678
+ resize_component :DECREASE, :WIDTH
679
+ end
680
+ # fires handler to request app to resize current component
681
+ def increase_width
682
+ resize_component :INCREASE, :WIDTH
683
+ end
684
+ # fires handler to request app to resize current component
685
+ def increase_height
686
+ resize_component :INCREASE, :HEIGHT
687
+ end
688
+ def increase_current_component
689
+ info = split_info_for
690
+ #info.add_weight = 0 if info.add_weight.nil?
691
+ #if info.add_weight < 0.3
692
+ #info.add_weight = info.add_weight + 0.05
693
+ #end
694
+ e = ResizeEvent.new @current_component, :INCREASE
695
+ fire_handler :COMPONENT_RESIZE_EVENT, e
696
+ #@repaint_required = true
697
+ end
698
+ # calling application need to handle this, since it knows
699
+ # how many windows its has and what the user would mean
700
+ def expand # maximize
701
+ e = ResizeEvent.new @current_component, :EXPAND
702
+ fire_handler :COMPONENT_RESIZE_EVENT, e
703
+ end
704
+ # calling application need to handle this, since it knows
705
+ # how many windows its has and what the user would mean
706
+ def unexpand
707
+ e = ResizeEvent.new @current_component, :UNEXPAND
708
+ fire_handler :COMPONENT_RESIZE_EVENT, e
709
+ end
710
+
711
+ private
712
+ def _create_divider
713
+ return if @vb
714
+ roffset = 1
715
+ loffset = 2
716
+ if @suppress_borders
717
+ loffset = roffset = 0
718
+ end
719
+ rc = @rc
720
+ if v?
721
+ @vb = Divider.new nil, :row => @row+roffset, :col => rc+@col-1, :length => @height-loffset, :side => :right
722
+ else
723
+ @vb = Divider.new nil, :row => @row+rc-1, :col => @col+1, :length => @width-loffset, :side => :bottom
724
+ end
725
+ @vb.focusable(false)
726
+ RubyCurses::FocusManager.add @vb
727
+ @vb.parent_component = self
728
+ @components << @vb
729
+ @vb.set_buffering(:target_window => @target_window || @form.window, :form => @form )
730
+ @vb.bind :DRAG_EVENT do |ev|
731
+ if v?
732
+ case ev.type
733
+ when KEY_RIGHT
734
+ if @rc < @width - 3
735
+ @recalculate_splits = true
736
+ @rc += 1
737
+ @repaint_required = true # WHY ! Did prop handler not fire ?
738
+ end
739
+ when KEY_LEFT
740
+ if @rc > 3
741
+ @recalculate_splits = true
742
+ @repaint_required = true
743
+ @rc -= 1
744
+ end
745
+ end
746
+ else
747
+ # horizontal
748
+ case ev.type
749
+ when KEY_DOWN
750
+ if @rc < @height - 3
751
+ @recalculate_splits = true
752
+ @rc += 1
753
+ @repaint_required = true # WHY ! Did prop handler not fire ?
754
+ end
755
+ when KEY_UP
756
+ if @rc > 3
757
+ @recalculate_splits = true
758
+ @repaint_required = true
759
+ @rc -= 1
760
+ end
761
+ end
762
+ end # v?
763
+ end
764
+ end
765
+
766
+ # ADD HERE ABOVe
767
+ end # class
768
+ end # module