Codebase list ruby-fxruby / 9b4196b lib / fox16 / iterators.rb
9b4196b

Tree @9b4196b (Download .tar.gz)

iterators.rb @9b4196braw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 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
 75
 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
module Fox

  class FXComboBox

    include Enumerable

    #
    # Override Enumerable#first with FXWindow#first for backwards compatibility.
    #
    def first
      getFirst
    end

    #
    # Calls block once for each item in the list, passing the item's text and
    # user data as parameters.
    #
    def each # :yields: itemText, itemData
      0.upto(numItems - 1) do |i|
        yield getItemText(i), getItemData(i)
      end
      self
    end
  end

  class FXFoldingList

    include Enumerable

    #
    # Calls block once for each root-level folding list item, passing a
    # reference to that item as a parameter.
    #
    def each # :yields: aFoldingItem
      current = firstItem
      while current != nil
        next_current = current.next
        yield current
        current = next_current
      end
      self
    end
  end

  class FXFoldingItem

    include Enumerable

    #
    # Calls block once for each child of this folding list item, passing a
    # reference to that child item as a parameter.
    #
    def each # :yields: aFoldingItem
      current = first
      while current != nil
        next_current = current.next
        yield current
        current = next_current
      end
      self
    end
  end

  class FXHeader

    include Enumerable

    #
    # Override Enumerable#first with FXWindow#first for backwards compatibility.
    #
    def first
      getFirst
    end

    #
    # Calls block once for each item in the list, passing a reference to that
    # item as a parameter.
    #
    def each # :yields: aHeaderItem
      0.upto(numItems - 1) do |i|
        yield getItem(i)
      end
      self
    end
  end

  class FXIconList

    include Enumerable

    #
    # Calls block once for each item in the list, passing a reference to that
    # item as a parameter.
    #
    def each # :yields: anIconItem
      0.upto(numItems - 1) do |i|
        yield getItem(i)
      end
      self
    end
  end

  class FXList

    include Enumerable

    #
    # Override Enumerable#first with FXWindow#first for backwards compatibility.
    #
    def first
      getFirst
    end

    #
    # Calls block once for each item in the list, passing a reference to that
    # item as a parameter.
    #
    def each # :yields: aListItem
      0.upto(numItems - 1) do |i|
        yield getItem(i)
      end
      self
    end
  end

  class FXListBox

    include Enumerable

    #
    # Override Enumerable#first with FXWindow#first for backwards compatibility.
    #
    def first
      getFirst
    end

    #
    # Calls block once for each item in the list, passing the item's text,
    # icon and user data as parameters.
    #
    def each
      0.upto(numItems - 1) do |i|
        yield getItemText(i), getItemIcon(i), getItemData(i)
      end
      self
    end
  end

  class FXTable

    include Enumerable

    #
    # Override Enumerable#first with FXWindow#first for backwards compatibility.
    #
    def first
      getFirst
    end

    #
    # Calls block once for each row in the table, passing an array of
    # references (one element per column) as a parameter.
    #
    def each_row # :yields: itemArray
      0.upto(numRows - 1) do |i|
        tableRow = []
        0.upto(numColumns - 1) do |j|
          tableRow << getItem(i, j)
        end
        yield tableRow
      end
      self
    end

    #
    # Calls block once for each column in the table, passing an array of
    # references (one element per row) as a parameter.
    #
    def each_column # :yields: itemArray
      0.upto(numColumns - 1) do |j|
        tableCol = []
        0.upto(numRows - 1) do |i|
          tableCol << getItem(i, j)
        end
        yield tableCol
      end
      self
    end

    alias each each_row
  end

  class FXTreeItem

    include Enumerable

    #
    # Calls block once for each child of this tree item, passing a
    # reference to that child item as a parameter.
    #
    def each # :yields: aTreeItem
      current = first
      while current != nil
        next_current = current.next
        yield current
        current = next_current
      end
      self
    end
  end

  class FXTreeList

    include Enumerable

    #
    # Override Enumerable#first with FXWindow#first for backwards compatibility.
    #
    def first
      getFirst
    end

    #
    # Calls block once for each root-level tree item, passing a
    # reference to that item as a parameter.
    #
    def each # :yields: aTreeItem
      current = firstItem
      while current != nil
        next_current = current.next
        yield current
        current = next_current
      end
      self
    end
  end

  class FXTreeListBox

    include Enumerable

    #
    # Override Enumerable#first with FXWindow#first for backwards compatibility.
    #
    def first
      getFirst
    end

    #
    # Calls block once for each root-level tree item, passing a
    # reference to that item as a parameter.
    #
    def each # :yields: aTreeItem
      current = firstItem
      while current != nil
        next_current = current.next
        yield current
        current = next_current
      end
      self
    end
  end

  class FXStream
  end

  class FXFileStream
    #
    # Construct a new FXFileStream object with the specified data flow
    # direction (<em>save_or_load</em>) and _container_ object.
    # If an optional code block is given, it will be passed this file
    # stream as an argument, and the file stream will automatically be
    # closed when the block terminates.
    # If no code block is provided, this method just returns the
    # new file stream in an opened state.
    #
    # Raises FXStreamNoWriteError if <em>save_or_load</em> is +FXStreamSave+
    # but the file cannot be opened for writing. Raises FXStreamNoReadError
    # if <em>save_or_load</em> is +FXStreamLoad+ but the file cannot be opened
    # for reading.
    #

    def FXFileStream.open(filename, save_or_load, size=8192, container=nil) # :yields: theFileStream
      fstream = FXFileStream.new(container)
      if fstream.open(filename, save_or_load, size)
      	if block_given?
      	  begin
      	    yield fstream
      	  ensure
      	    fstream.close
      	  end
      	else
      	  fstream
      	end
      else
        # FXFileStream#open returned false, so report error
      	raise FXStreamError.makeStreamError(fstream.status)
      end
    end
  end

  class FXMemoryStream
    #
    # Construct a new FXMemoryStream object with the specified data flow
    # direction, data and container object.
    # If an optional code block is given, it will be passed this memory
    # stream as an argument, and the memory stream will automatically be
    # closed when the block terminates.
    # If no code block is provided, this method just returns the
    # new memory stream in an opened state.
    #
    # Raises FXStreamAllocError if some kind of memory allocation failed
    # while initializing the stream.
    #
    # ==== Parameters:
    #
    # +save_or_load+::	access mode, either +FXStreamSave+ or +FXStreamLoad+ [Integer]
    # +data+::		memory buffer used for the stream, or +nil+ if the buffer is to be initially empty [String].
    # +cont+::		the container object, or +nil+ if there is none [FXObject]
    #
    def FXMemoryStream.open(save_or_load, data, cont=nil) # :yields: theMemoryStream
      stream = FXMemoryStream.new(cont)
      if stream.open(save_or_load, data)
      	if block_given?
      	  begin
      	    yield stream
      	  ensure
      	    stream.close
      	  end
      	else
      	  stream
      	end
      else
        # FXFileStream#open returned false, so report error
      	raise FXStreamError.makeStreamError(stream.status)
      end
    end
  end

  class FXApp

    alias beginWaitCursor0 beginWaitCursor # :nodoc:

    #
    # Changes the default application cursor to an hourglass shape,
    # to provide a visual cue to the user that it's time to wait.
    # To revert the default application cursor to its normal shape,
    # call the #endWaitCursor method. For example,
    #
    #    getApp().beginWaitCursor()
    #      ... time-consuming operation ...
    #    getApp().endWaitCursor()
    #
    # Invocations of #beginWaitCursor may be nested, and if so, the
    # call to #endWaitCursor is matched with the most recent call to
    # #beginWaitCursor.
    #
    # If an optional code block is provided, #endWaitCursor is
    # automatically called after the block terminates, e.g.
    #
    #    getApp().beginWaitCursor() {
    #              ... time-consuming operation ...
    #      ... endWaitCursor() is called automatically ...
    #    }
    #
    def beginWaitCursor
      beginWaitCursor0
      if block_given?
        begin
      	  yield
      	ensure
      	  endWaitCursor
      	end
      end
    end
  end

  class FXDCPrint

    alias beginPrint0 beginPrint # :nodoc:

    #
    # Begin print session described by _job_ (an FXPrinter instance).
    # If an optional code block is provided, #endPrint is automatically
    # called after the block terminates.
    #
    def beginPrint(job) # :yields: theDC
      result = beginPrint0(job)
      if block_given?
        begin
      	  yield self
      	ensure
      	  endPrint
      	end
      else
        result
      end
    end

    alias beginPage0 beginPage # :nodoc:

    #
    # Generate beginning of _page_ (the page number).
    # If an optional code block is provided, #endPage is automatically
    # called after the block terminates.
    #
    def beginPage(page=1) # :yields: theDC
      result = beginPage0(page)
      if block_given?
        begin
      	  yield self
      	ensure
      	  endPage
      	end
      else
        result
      end
    end
  end
end