Class: CDK::SCREEN

Inherits:
Object
  • Object
show all
Defined in:
lib/cdk/screen.rb

Constant Summary collapse

NOEXIT =
0
EXITOK =
1
EXITCANCEL =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ SCREEN

Returns a new instance of SCREEN.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cdk/screen.rb', line 10

def initialize (window)
  # initialization for the first time
  if CDK::ALL_SCREENS.size == 0
    # Set up basic curses settings.
    # #ifdef HAVE_SETLOCALE
    # setlocale (LC_ALL, "");
    # #endif
    
    Ncurses.noecho
    Ncurses.cbreak
  end

  CDK::ALL_SCREENS << self
  @object_count = 0
  @object_limit = 2
  @object = Array.new(@object_limit, nil)
  @window = window
  @object_focus = 0
end

Instance Attribute Details

#exit_statusObject

Returns the value of attribute exit_status.



4
5
6
# File 'lib/cdk/screen.rb', line 4

def exit_status
  @exit_status
end

#objectObject

Returns the value of attribute object.



3
4
5
# File 'lib/cdk/screen.rb', line 3

def object
  @object
end

#object_countObject

Returns the value of attribute object_count.



3
4
5
# File 'lib/cdk/screen.rb', line 3

def object_count
  @object_count
end

#object_focusObject

Returns the value of attribute object_focus.



3
4
5
# File 'lib/cdk/screen.rb', line 3

def object_focus
  @object_focus
end

#object_limitObject

Returns the value of attribute object_limit.



3
4
5
# File 'lib/cdk/screen.rb', line 3

def object_limit
  @object_limit
end

#windowObject

Returns the value of attribute window.



3
4
5
# File 'lib/cdk/screen.rb', line 3

def window
  @window
end

Class Method Details

.endCDKObject

This is added to remain consistent



298
299
300
301
302
# File 'lib/cdk/screen.rb', line 298

def self.endCDK
  Ncurses.echo
  Ncurses.nocbreak
  Ncurses.endwin
end

.lowerCDKObject(cdktype, object) ⇒ Object

This ‘lowers’ an object.



113
114
115
116
117
# File 'lib/cdk/screen.rb', line 113

def self.lowerCDKObject(cdktype, object)
  if object.validObjType(cdktype)
    object.screen.swapCDKIndices(object.screen_index, 0)
  end
end

.raiseCDKObject(cdktype, object) ⇒ Object

This ‘brings’ a CDK object to the top of the stack.



105
106
107
108
109
110
# File 'lib/cdk/screen.rb', line 105

def self.raiseCDKObject(cdktype, object)
  if object.validObjType(cdktype)
    screen = object.screen
    screen.swapCDKIndices(object.screen_index, screen.object_count - 1)
  end
end

.refresh_output(v = true) ⇒ Object



192
193
194
# File 'lib/cdk/screen.rb', line 192

def self.refresh_output(v=true)
  @refresh_output = v
end

.refresh_output?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/cdk/screen.rb', line 196

def self.refresh_output?
  !defined?(@refresh_output) || !!@refresh_output
end

.refreshCDKWindow(win) ⇒ Object

Refresh one CDK window. FIXME(original): this should be rewritten to use the panel library, so it would not be necessary to touch the window to ensure that it covers other windows.



214
215
216
217
# File 'lib/cdk/screen.rb', line 214

def self.refreshCDKWindow(win)
  win.touchwin
  SCREEN.wrefresh(win)
end

.unregister(cdktype, object) ⇒ Object

This removes an object from the CDK screen.



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
# File 'lib/cdk/screen.rb', line 45

def self.unregister(cdktype, object)
  if object.validObjType(cdktype) && object.screen_index >= 0
    screen = object.screen

    unless screen.nil?
      index = object.screen_index
      object.screen_index = -1

      # Resequence the objects
      (index...screen.object_count - 1).each do |x|
        screen.setScreenIndex(x, screen.object[x+1])
      end

      if screen.object_count <= 1
        # if no more objects, remove the array
        screen.object = []
        screen.object_count = 0
        screen.object_limit = 0
      else
        screen.object[screen.object_count] = nil
        screen.object_count -= 1

        # Update the object-focus
        if screen.object_focus == index
          screen.object_focus -= 1
          Traverse.setCDKFocusNext(screen)
        elsif screen.object_focus > index
          screen.object_focus -= 1
        end
      end
    end
  end
end

.wrefresh(w) ⇒ Object



200
201
202
203
204
205
206
207
208
# File 'lib/cdk/screen.rb', line 200

def self.wrefresh(w)
  if refresh_output?
    w.wrefresh

  else
    w.noutrefresh

  end
end

Instance Method Details

#destroyObject

This destroys a CDK screen.



293
294
295
# File 'lib/cdk/screen.rb', line 293

def destroy
  CDK::ALL_SCREENS.delete(self)
end

#destroyCDKScreenObjectsObject

Destroy all the objects on a screen



279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/cdk/screen.rb', line 279

def destroyCDKScreenObjects
  (0...@object_count).each do |x|
    obj = @object[x]
    before = @object_count

    if obj.validObjType(obj.object_type)
      obj.erase
      obj.destroy
      x -= (@object_count - before)
    end
  end
end

#drawObject

This calls SCREEN.refresh, (made consistent with widgets)



188
189
190
# File 'lib/cdk/screen.rb', line 188

def draw
  self.refresh
end

#eraseObject

This clears all the objects in the screen



265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/cdk/screen.rb', line 265

def erase
  # We just call the object erase function
  (0...@object_count).each do |x|
    obj = @object[x]
    if obj.validObjType(obj.object_type)
      obj.erase
    end
  end

  # Refresh the screen.
  SCREEN.wrefresh(@window)
end

#noutrefreshObject



258
259
260
261
262
# File 'lib/cdk/screen.rb', line 258

def noutrefresh
  SCREEN.refresh_output(false)
  refresh
  SCREEN.refresh_output(true)
end

#popupDialog(mesg, mesg_count, buttons, button_count) ⇒ Object

This pops up a dialog box.



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/cdk/screen.rb', line 165

def popupDialog(mesg, mesg_count, buttons, button_count)
  # Create the dialog box.
  popup = CDK::DIALOG.new(self, CDK::CENTER, CDK::CENTER,
      mesg, mesg_count, buttons, button_count, Ncurses::A_REVERSE,
      true, true, false)

  # Activate the dialog box
  popup.draw(true)

  # Get the choice
  choice = popup.activate('')

  # Destroy the dialog box
  popup.destroy

  # Clean the screen.
  self.erase
  self.refresh

  return choice
end

#popupLabel(mesg, count) ⇒ Object

This pops up a message.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/cdk/screen.rb', line 120

def popupLabel(mesg, count)
  #Create the label.
  popup = CDK::LABEL.new(self, CENTER, CENTER, mesg, count, true, false)

  old_state = Ncurses.curs_set(0)
  #Draw it on the screen
  popup.draw(true)

  # Wait for some input.
  popup.win.keypad(true)
  popup.getch([])

  # Kill it.
  popup.destroy

  # Clean the screen.
  Ncurses.curs_set(old_state)
  self.erase
  self.refresh
end

#popupLabelAttrib(mesg, count, attrib) ⇒ Object

This pops up a message



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/cdk/screen.rb', line 142

def popupLabelAttrib(mesg, count, attrib)
  # Create the label.
  popup = CDK::LABEL.new(self, CENTER, CENTER, mesg, count, true, false)
  popup.setBackgroundAttrib

  old_state = Ncurses.curs_set(0)
  # Draw it on the screen)
  popup.draw(true)

  # Wait for some input
  popup.win.keypad(true)
  popup.getch([])

  # Kill it.
  popup.destroy

  # Clean the screen.
  Ncurses.curs_set(old_state)
  screen.erase
  screen.refresh
end

#refreshObject

This refreshes all the objects in the screen.



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
# File 'lib/cdk/screen.rb', line 220

def refresh
  focused = -1
  visible = -1

  CDK::SCREEN.refreshCDKWindow(@window)

  # We erase all the invisible objects, then only draw it all back, so
  # that the objects can overlap, and the visible ones will always be
  # drawn after all the invisible ones are erased
  (0...@object_count).each do |x|
    obj = @object[x]
    if obj.validObjType(obj.object_type)
      if obj.is_visible
        if visible < 0
          visible = x
        end
        if obj.has_focus && focused < 0
          focused = x
        end
      else
        obj.erase
      end
    end
  end

  (0...@object_count).each do |x|
    obj = @object[x]

    if obj.validObjType(obj.object_type)
      obj.has_focus = (x == focused)

      if obj.is_visible
        obj.draw(obj.box)
      end
    end
  end
end

#register(cdktype, object) ⇒ Object

This registers a CDK object with a screen.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cdk/screen.rb', line 31

def register(cdktype, object)
  if @object_count + 1 >= @object_limit
    @object_limit += 2
    @object_limit *= 2
    @object.concat(Array.new(@object_limit - @object.size, nil))
  end

  if object.validObjType(cdktype)
    self.setScreenIndex(@object_count, object)
    @object_count += 1
  end
end

#setScreenIndex(number, obj) ⇒ Object



79
80
81
82
83
# File 'lib/cdk/screen.rb', line 79

def setScreenIndex(number, obj)
  obj.screen_index = number
  obj.screen = self
  @object[number] = obj
end

#swapCDKIndices(n1, n2) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cdk/screen.rb', line 89

def swapCDKIndices(n1, n2)
  if n1 != n2 && self.validIndex(n1) && self.validIndex(n2)
    o1 = @object[n1]
    o2 = @object[n2]
    self.setScreenIndex(n1, o2)
    self.setScreenIndex(n2, o1)

    if @object_focus == n1
      @object_focus = n2
    elsif @object_focus == n2
      @object_focus = n1
    end
  end
end

#validIndex(n) ⇒ Object



85
86
87
# File 'lib/cdk/screen.rb', line 85

def validIndex(n)
  n >= 0 && n < @object_count
end