Class: VRScreen

Inherits:
Object show all
Defined in:
lib/vr/vruby.rb,
lib/vr/vrdialog.rb

Constant Summary collapse

WINDOWCHECK_INTERVAL =
3
PlaneDialogTemplate =

VRScreen

A method is added to VRScreen by loading this file.

Method

— openModalDialog(parent,style=nil,mod=VRDialogComponent,template=PlaneDialogTemplate,options={})

Creates and opens a modal dialog box. 
This method is blocked until the dialog box closed. 
GUI definition can be specified by ((|template|)) or mod#construct.
When mod==nil, then this method use VRDialogComponent instead of nil.
The return value is dialog's return value set by SWin::Dialog#close.
((|options|)) specifies the focused control, ok button, cancel button, etc.

— openModelessDialog(parent,style=nil,mod=VRDialogComponent,template=PlaneDialogTemplate,options={})

Creates and opens a modeless dialog box.
GUI definition can be specified by ((|template|)) or mod#construct.
When mod==nil, then this method use VRDialogComponent instead of nil.
The return value is false and this method returns immediately.(non-blocking)
((|options|)) specifies the focused control, ok button, cancel button, etc.
(see VRInputbox)

— newdialog(parent,style=nil,mod=VRDialogComponent,template=PlaneDialogTemplate,options={})

Creates a dialogbox whose parent is ((|parent|)), and returns it.
To open that dialogbox, call "open" method. 
This method is called by openModalDialog() and openModelessDialog() .
((|mod|)) may be a module or a class which is a descendant of 
VRDialogComponent.
VRDialogTemplate.new.to_template

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frame, factory) ⇒ VRScreen

Returns a new instance of VRScreen.



926
927
928
929
930
931
932
# File 'lib/vr/vruby.rb', line 926

def initialize(frame,factory)
  @application=frame
  @factory=factory
  @desktop=@application.getDesktop
  @idle_sleep_timer = 0.01
  @_vr_box=[]    # pushed windows for avoiding destruction by GC
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



919
920
921
# File 'lib/vr/vruby.rb', line 919

def application
  @application
end

#desktopObject (readonly)

Returns the value of attribute desktop.



921
922
923
# File 'lib/vr/vruby.rb', line 921

def desktop
  @desktop
end

#factoryObject (readonly)

Returns the value of attribute factory.



920
921
922
# File 'lib/vr/vruby.rb', line 920

def factory
  @factory
end

#idle_sleep_timerObject (readonly)

Returns the value of attribute idle_sleep_timer.



922
923
924
# File 'lib/vr/vruby.rb', line 922

def idle_sleep_timer
  @idle_sleep_timer
end

#screenObject (readonly)

VRScreen

This class expresses the desktop screen. Currently only ((<VRLocalScreen>)) defined in vruby, the instance of this class, is available.

Class Method

— new(app,factory)

((|app|)) as SWin::Application and ((|factory|)) as SWin::Factory.

Methods

— newform(parent=nil,style=nil,mod=VRForm)

Creates and initializes the top-level window which is the instance of
((<VRForm>)) or its descendant.
The parent window is specified by ((|parent|)) and parent==nil means
that it has no parent window.
The window style is specified by ((|style|)) which can be ((|nil|)) for
default style.
((|mod|)) can be a module which is to be added to ((<VRForm>)) or a class
which is a descendant of ((<VRForm>)).

— showForm(mod,x,y,w,h)

Creates and shows the new top-level window using ((<newform>)).
The arguments ((|x|)),((|y|)),((|w|)),((|h|)) is omittable.
((|mod|)) is the argument for ((<newform>))'s argument.

— addIdleproc(f)

Adds a idling process executed while message loop runs.
((|f|)) is an instance of Proc class.

— messageloop(wflag=false)

Get into the system message loop. You need to call this method to
process windows messages.
While wflag is true, messageloop waits a message by WaitMessage() API.
This waiting will prevent other threads' processes and can suppress CPU load
average.
If wflag==false and your ruby's version is so high that Thread has 'list' 
class-method, WaitMessage() API is used automatically by the case.

— idling_messageloop

((*obsolete*))
Almost same as ((<messageloop>)). The difference is that this method
yields when the messageloop is in idle state. You need to use this 
method in iterator's style.

— width

Width of the desktop.

— height

Height of the desktop.

— newFormClass(name,brush=nil,style=nil,icon=nil,cursor=nil)

Register a new window class to the system.
This method returns a form class with specified icon, color, cursor
and default window style.


918
919
920
# File 'lib/vr/vruby.rb', line 918

def screen
  @screen
end

Instance Method Details

#addIdleproc(f) ⇒ Object



971
972
973
974
# File 'lib/vr/vruby.rb', line 971

def addIdleproc(f)
  @idleprocs=[] unless defined?(@idleprocs)
  @idleprocs.push f
end

#heightObject Also known as: h



1034
1035
1036
# File 'lib/vr/vruby.rb', line 1034

def height
  @desktop.h
end

#idling_messageloopObject

obsolete



1005
1006
1007
1008
1009
# File 'lib/vr/vruby.rb', line 1005

def idling_messageloop # obsolete
  @application.messageloop do |q|
    yield q
  end
end

#messageloop(waitflag = false) ⇒ Object



976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
# File 'lib/vr/vruby.rb', line 976

def messageloop(waitflag=false)
  @idleprocs=[] unless defined?(@idleprocs)

=begin commented out for activex support
  cth =Thread.new do 
    while true do
      @_vr_box.reject! do |w| (! w.alive?);  end
      sleep WINDOWCHECK_INTERVAL
    end
  end
=end

  @application.messageloop do
    n=@idleprocs.shift
    if n then
      Thread.new do
        n.call
      end
    else
      if waitflag then
        @application.waitmessage
      else
#          Thread.pass
         sleep(@idle_sleep_timer)
      end
    end
  end
end

#newdialog(parent, style = nil, mod = VRDialogComponent, *template_arg) ⇒ Object



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/vr/vrdialog.rb', line 326

def newdialog(parent,style=nil,mod=VRDialogComponent,*template_arg)
  template,options = *template_arg
  template = PlaneDialogTemplate unless template
  options = {} unless options
  if mod.is_a?(Class) and mod.ancestors.index(VRDialogComponent) then
    frm=@factory.newdialog(template,mod)
  elsif mod.is_a?(Class) then
    raise "#{mod.class} is not a descendant of VRDialogComponent"
  elsif mod.is_a?(Module) then
    frm=@factory.newdialog(template,VRDialogComponent)
    frm.extend VRParent
    frm.extend mod
  else
    raise ArgError,"a Class/Module of VRDialogComponent required"
  end
  frm.parentinit(self)
  frm.addEvent WMsg::WM_INITDIALOG
  frm.extend(VRStdControlContainer)
  frm.style=style if style
  frm.extend(VRDialogComponent::VRInitDialogHandler)
  frm.options.update(options)
  frm.instance_eval("@parent=parent")
  frm
end

#newform(parent = nil, style = nil, mod = VRForm) ⇒ Object

create top-level window



934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
# File 'lib/vr/vruby.rb', line 934

def newform(parent=nil,style=nil,mod=VRForm)   # create top-level window
  if mod.is_a?(Class) then
    if mod.ancestors.index(VRForm) then
      frm=@factory.newwindow(parent,mod)
    else
      raise "#{mod} is not a window class"
    end
  elsif  mod.is_a?(Module) then
    frm=@factory.newwindow(parent,VRForm)
    frm.extend mod
  else
    raise ArgumentError,"required a child class of VRForm or a Module extending VRForm"
  end
  frm.style= style if style
  frm.classname = frm.class.winclass if frm.class.winclass
  frm.extend VRContainersSet
  frm.forminit(self,parent)
  frm
end

#newFormClass(name, brush = nil, style = nil, icon = nil, cursor = nil) ⇒ Object



1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
# File 'lib/vr/vruby.rb', line 1011

def newFormClass(name,brush=nil,style=nil,icon=nil,cursor=nil)
  hicon = case(icon) 
          when Integer 
            icon 
          when SWin::Icon 
            icon.hicon 
          else
            nil
          end

  sw = factory.registerWinClass(name.to_s,brush,style,hicon,cursor)
  raise "register class failed" unless sw
  a = Class.new(VRForm)
  a.class_eval(<<EEOOFF)
    VR_WINCLASS="#{sw}"
    def self.winclass() VR_WINCLASS end
EEOOFF
  a
end

#openModalDialog(parent, style = nil, mod = VRModalDialog, *template_arg) ⇒ Object Also known as: modalform



351
352
353
354
355
# File 'lib/vr/vrdialog.rb', line 351

def openModalDialog(parent,style=nil,mod=VRModalDialog,*template_arg)
  mod = VRModalDialog unless mod
  frm = newdialog(parent,style,mod,*template_arg)
  a = frm.open(parent,true)
end

#openModelessDialog(parent, style = nil, mod = VRModelessDialog, *template_arg) ⇒ Object Also known as: modelessform



357
358
359
360
361
362
363
# File 'lib/vr/vrdialog.rb', line 357

def openModelessDialog(parent,style=nil,mod=VRModelessDialog,*template_arg)
  mod = VRModelessDialog unless mod
  frm = newdialog(parent,style,mod,*template_arg)
  frm.open parent,false
  @_vr_box.push frm
  frm
end

#showForm(formmodule, *rect) ⇒ Object



954
955
956
957
958
959
960
961
962
963
964
# File 'lib/vr/vruby.rb', line 954

def showForm(formmodule,*rect)
  if rect.is_a?(Array) and rect.size>3 then
    x,y,w,h = *rect
  end

  frm=newform(nil,nil,formmodule)
  frm.move x,y,w,h if x
  frm.create.show
  @_vr_box.push frm
  frm
end

#start(*args) ⇒ Object



966
967
968
969
# File 'lib/vr/vruby.rb', line 966

def start(*args)
  showForm(*args)
  messageloop
end

#widthObject Also known as: w



1031
1032
1033
# File 'lib/vr/vruby.rb', line 1031

def width
  @desktop.w
end

#xObject



1039
# File 'lib/vr/vruby.rb', line 1039

def x() @desktop.x; end

#yObject



1040
# File 'lib/vr/vruby.rb', line 1040

def y() @desktop.y; end