Class: VRVirtualDesktopForm

Inherits:
VRForm
  • Object
show all
Includes:
VRClosingSensitive, VRMenuUseable, VRTimerFeasible, VRTrayiconFeasible
Defined in:
lib/VRVirtualDesktopForm.rb

Overview

To do, add in list box control and send traces to it

Constant Summary collapse

OBJECT_DB_ICON_ID =
1
SCREEN_ICON_ID_BASE =
2
SC_MINIMIZE =
0xF020

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run_gui(restore) ⇒ Object

run this form



32
33
34
35
36
37
38
39
40
# File 'lib/VRVirtualDesktopForm.rb', line 32

def run_gui(restore)
  vrForm = VRLocalScreen.newform(nil, nil, VRVirtualDesktopForm)
  vrForm.exinit(restore).create.goto_tray
  begin
    VRLocalScreen.messageloop
  ensure
    vrForm.handle_exit
  end
end

Instance Method Details

#clean_trayObject

clean the icon out of the tray



171
172
173
174
175
# File 'lib/VRVirtualDesktopForm.rb', line 171

def clean_tray
  $TRACE.debug 5, "cleaning tray"
  delete_trayicon(OBJECT_DB_ICON_ID)
  @virtual_desktops.delete_trayicons
end

#constructObject

construct the form



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
# File 'lib/VRVirtualDesktopForm.rb', line 46

def construct
  self.caption = @caption

  icon_filename = @icon_path + "/" + @icon_file
  $TRACE.debug 5, "icon filename = '#{icon_filename}'"
  @icon = VRLocalScreen.factory.iconfromfile(icon_filename)

  @window_manager = Win32::WindowManager.new
  @virtual_desktops = Win32::VirtualDesktops.new(self, @icon_path, SCREEN_ICON_ID_BASE, 6, @window_manager)
  $TRACE.debug 5, "at start windows = " + @window_manager.get_all_windows.values.map{|w| w.to_s}.join(",")

  # attempt to restore windows

  if @restore then
    begin 
      @virtual_desktops.restore
    rescue Errno::ENOENT
      # ignore this error

    end
  end

  # add any windows that weren't added on restore (if restore happened

  @window_manager.get_all_windows.each_value do |window|
    $TRACE.debug 5, "checking window: #{window}"
    #window.show

    unless @virtual_desktops.contains_window(window)
      $TRACE.debug 5, "adding window: #{window} to active desktop"
      @virtual_desktops.active_desktop.add_window(window)
    end
  end
  @virtual_desktops.save

  # set up menus

  fileMenu = 
      ["&File", 
          [
            ["E&xit","file_exit"]
          ]
        ]
  menus = [fileMenu]
   setMenu newMenu.set(menus)
  
  @tray_menu = newPopupMenu
  @tray_menu.set(@tray_menu_source)

    addTimer 500,"windowUpdate"
    
  # used add handler for minimize

  wm_syscommand = WMsg::WM_COMMAND+1
  addHandler wm_syscommand,"syscommand",MSGTYPE::ARGWINT,nil
  acceptEvents [wm_syscommand]
end

#exinit(restore, caption, icon_file, icon_path, tray_menu_additions = []) ⇒ Object

initialize this form



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/VRVirtualDesktopForm.rb', line 101

def exinit(restore, caption, icon_file, icon_path, tray_menu_additions=[])
  @exited = false
  @restore = restore
  @caption = caption
  @icon_file = icon_file
  @icon_path = icon_path

  @tray_menu_source = [
    ["Set Screen Name...", "set_screen_name"],
    ["Exit", "exit"]
  ]
  @tray_menu_source.insert(0, tray_menu_additions) unless tray_menu_additions.empty?
  self
end

#exit_clickedObject

user clicked tray menu Exit



225
226
227
# File 'lib/VRVirtualDesktopForm.rb', line 225

def exit_clicked
  handle_close
end

#file_exit_clickedObject

user clicked File | Exit



207
208
209
# File 'lib/VRVirtualDesktopForm.rb', line 207

def file_exit_clicked
  handle_close
end

#goto_trayObject

enable the tray icon



147
148
149
150
151
152
153
# File 'lib/VRVirtualDesktopForm.rb', line 147

def goto_tray
  #return unless @displayed

  @virtual_desktops.create_trayicons
  create_trayicon(@icon.hicon, @caption, OBJECT_DB_ICON_ID)
  self.hide
  @displayed = false
end

#handle_closeObject

common handler for exit menu selections



240
241
242
243
244
245
# File 'lib/VRVirtualDesktopForm.rb', line 240

def handle_close
  if user_okays_close then
    handle_exit
    self.close
  end
end

#handle_exitObject

handle exit of program by all methods



249
250
251
252
253
254
255
# File 'lib/VRVirtualDesktopForm.rb', line 249

def handle_exit
  return if @exited

  @exited = true
  @virtual_desktops.handle_exit
  clean_tray
end

#restore_clickedObject

user clicked tray menu show ObjectDatabase



219
220
221
# File 'lib/VRVirtualDesktopForm.rb', line 219

def restore_clicked
  up_from_tray
end

#self_closeObject

user clicked close box



259
260
261
262
263
264
265
266
# File 'lib/VRVirtualDesktopForm.rb', line 259

def self_close
  # handle user clicks close box

  if user_okays_close then
    clean_tray
  else
    SKIP_DEFAULTHANDLER
  end
end

#self_syscommand(message_type) ⇒ Object

Handler for system commands



122
123
124
125
126
127
128
129
# File 'lib/VRVirtualDesktopForm.rb', line 122

def self_syscommand(message_type)
  $TRACE.debug 5, "message_type = #{message_type}"
  if message_type == SC_MINIMIZE then
    $TRACE.debug 5, "going to tray"
    goto_tray
    SKIP_DEFAULTHANDLER
  end
end

#self_traylbuttondown(iconid) ⇒ Object

this is called when left button is clicked on tray icon. we display the tray menu



181
182
183
184
185
186
187
188
# File 'lib/VRVirtualDesktopForm.rb', line 181

def self_traylbuttondown(iconid)
  case iconid
  when OBJECT_DB_ICON_ID
    showPopup @tray_menu
  else
    @virtual_desktops.change_desktop(iconid)
  end
end

#self_trayrbuttonup(iconid) ⇒ Object

this is called when right button is clicked on tray icon



193
194
195
196
197
198
199
200
# File 'lib/VRVirtualDesktopForm.rb', line 193

def self_trayrbuttonup(iconid)
  case iconid
  when OBJECT_DB_ICON_ID
    showPopup @tray_menu
  else
    @virtual_desktops.move_window(iconid)
  end
end

#set_screen_name_clickedObject

allow the user to set screen names



213
214
215
# File 'lib/VRVirtualDesktopForm.rb', line 213

def set_screen_name_clicked
  @virtual_desktops.set_screen_name
end

#tray_clickedObject

this is called when?



140
141
142
# File 'lib/VRVirtualDesktopForm.rb', line 140

def tray_clicked
  goto_tray
end

#up_from_trayObject

show the window from the tray



158
159
160
161
162
163
164
165
166
# File 'lib/VRVirtualDesktopForm.rb', line 158

def up_from_tray
  return if @displayed
  # delete_trayicon(1)

  myexstyle = self.exwinstyle
  myexstyle.ws_ex_toolwindow = false
  myexstyle.ws_ex_appwindow = true
  self.show
  @displayed = true
end

#user_okays_closeObject

ask user if they are sure they want to quit



233
234
235
236
# File 'lib/VRVirtualDesktopForm.rb', line 233

def user_okays_close
  ret = messageBox("Are you sure you want to quit?", "Exit?", VRMessageBoxConst::MB_YESNO)
  ret == VRDialogComponent::IDYES
end

#windowUpdate_timerObject



131
132
133
# File 'lib/VRVirtualDesktopForm.rb', line 131

def windowUpdate_timer
  @virtual_desktops.periodic_timer
end