Module: RNDK::Traverse
- Defined in:
- lib/rndk/core/traverse.rb
Class Method Summary collapse
- .exit_cancel(screen) ⇒ Object
- .exit_cancel_of(obj) ⇒ Object
- .exit_ok(screen) ⇒ Object
- .exit_ok_of(obj) ⇒ Object
-
.get_current_focus(screen) ⇒ Object
Returns the widget on which the focus lies.
-
.once(screen, curobj, key_code, function_key, func_menu_key) ⇒ Object
Traverse the screen just one time.
-
.over(screen) ⇒ Object
Traverse continuously the widgets on a screen.
- .reset(screen) ⇒ Object
- .reset_of(obj) ⇒ Object
-
.set_current_focus(screen, newobj) ⇒ Object
Set focus to a specific widget, returning it.
-
.set_first_focus(screen) ⇒ Object
Set focus to the first widget in the screen.
-
.set_last_focus(screen) ⇒ Object
Set focus to the last widget in the screen.
-
.set_next_focus(screen) ⇒ Object
Set focus to the next widget, returning it.
-
.set_previous_focus(screen) ⇒ Object
Set focus to the previous widget, returning it.
Class Method Details
.exit_cancel(screen) ⇒ Object
96 97 98 |
# File 'lib/rndk/core/traverse.rb', line 96 def Traverse.exit_cancel screen screen.exit_status = RNDK::Screen::EXITCANCEL end |
.exit_cancel_of(obj) ⇒ Object
104 105 106 |
# File 'lib/rndk/core/traverse.rb', line 104 def Traverse.exit_cancel_of(obj) exit_cancel obj.screen end |
.exit_ok(screen) ⇒ Object
92 93 94 |
# File 'lib/rndk/core/traverse.rb', line 92 def Traverse.exit_ok screen screen.exit_status = RNDK::Screen::EXITOK end |
.exit_ok_of(obj) ⇒ Object
100 101 102 |
# File 'lib/rndk/core/traverse.rb', line 100 def Traverse.exit_ok_of(obj) exit_ok obj.screen end |
.get_current_focus(screen) ⇒ Object
Returns the widget on which the focus lies.
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rndk/core/traverse.rb', line 113 def Traverse.get_current_focus(screen) result = nil n = screen. if n >= 0 && n < screen. result = screen.[n] end return result end |
.once(screen, curobj, key_code, function_key, func_menu_key) ⇒ Object
Traverse the screen just one time.
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 |
# File 'lib/rndk/core/traverse.rb', line 8 def Traverse.once(screen, curobj, key_code, function_key, ) case key_code when Ncurses::KEY_BTAB switch_focus(set_previous_focus(screen), curobj) when RNDK::KEY_TAB switch_focus(set_next_focus(screen), curobj) when RNDK.KEY_F(10) # save data and exit exit_ok(screen) when RNDK.CTRL('X') exit_cancel screen when RNDK.CTRL('R') # reset data to defaults reset(screen) set_focus(curobj) when RNDK::REFRESH # redraw screen screen.refresh set_focus(curobj) else # not everyone wants menus, so we make them optional here if !(.nil?) && (.call(key_code, function_key)) # find and enable drop down menu screen..each do || if !(.nil?) && . == :MENU Traverse.handleMenu(screen, , curobj) end end else curobj.inject(key_code) end end end |
.over(screen) ⇒ Object
Traverse continuously the widgets on a screen.
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 |
# File 'lib/rndk/core/traverse.rb', line 56 def Traverse.over screen result = 0 curobj = set_first_focus(screen) unless curobj.nil? refresh_data(screen) screen.exit_status = RNDK::Screen::NOEXIT while !((curobj = get_current_focus(screen)).nil?) && screen.exit_status == RNDK::Screen::NOEXIT function = [] key = curobj.getch(function) # TODO look at more direct way to do this = lambda do |key_code, function_key| Traverse.checkMenuKey(key_code, function_key) end Traverse.once(screen, curobj, key, function[0], ) end if screen.exit_status == RNDK::Screen::EXITOK save_data(screen) result = 1 end end return result end |
.reset(screen) ⇒ Object
88 89 90 |
# File 'lib/rndk/core/traverse.rb', line 88 def Traverse.reset screen refresh_data(screen) end |
.reset_of(obj) ⇒ Object
108 109 110 |
# File 'lib/rndk/core/traverse.rb', line 108 def Traverse.reset_of(obj) reset(obj.screen) end |
.set_current_focus(screen, newobj) ⇒ Object
Set focus to a specific widget, returning it. If the widget cannot be found, return nil.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/rndk/core/traverse.rb', line 178 def Traverse.set_current_focus(screen, newobj) result = nil curobj = nil n = getFocusIndex(screen) first = n while true n += 1 if n >= screen. n = 0 end curobj = screen.[n] if curobj == newobj result = curobj break elsif n == first break end end set_focusIndex(screen, if !(result.nil?) then n else -1 end) return result end |
.set_first_focus(screen) ⇒ Object
Set focus to the first widget in the screen.
204 205 206 207 |
# File 'lib/rndk/core/traverse.rb', line 204 def Traverse.set_first_focus(screen) set_focusIndex(screen, screen. - 1) return switch_focus(set_next_focus(screen), nil) end |
.set_last_focus(screen) ⇒ Object
Set focus to the last widget in the screen.
210 211 212 213 |
# File 'lib/rndk/core/traverse.rb', line 210 def Traverse.set_last_focus(screen) set_focusIndex(screen, 0) return switch_focus(set_previous_focus(screen), nil) end |
.set_next_focus(screen) ⇒ Object
Set focus to the next widget, returning it.
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 |
# File 'lib/rndk/core/traverse.rb', line 125 def Traverse.set_next_focus(screen) result = nil curobj = nil n = getFocusIndex(screen) first = n while true n+= 1 if n >= screen. n = 0 end curobj = screen.[n] if !(curobj.nil?) && curobj.accepts_focus result = curobj break else if n == first break end end end set_focusIndex(screen, if !(result.nil?) then n else -1 end) return result end |
.set_previous_focus(screen) ⇒ Object
Set focus to the previous widget, returning it.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/rndk/core/traverse.rb', line 152 def Traverse.set_previous_focus(screen) result = nil curobj = nil n = getFocusIndex(screen) first = n while true n -= 1 if n < 0 n = screen. - 1 end curobj = screen.[n] if !(curobj.nil?) && curobj.accepts_focus result = curobj break elsif n == first break end end set_focusIndex(screen, if !(result.nil?) then n else -1 end) return result end |