Class: VRMenu

Inherits:
Object show all
Defined in:
lib/vr/vrcontrol.rb

Overview

Menu

Constant Summary collapse

SEPARATOR =
["sep","_vrmenusep",0x800]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(menu, parent) ⇒ VRMenu

Returns a new instance of VRMenu.



867
868
869
870
# File 'lib/vr/vrcontrol.rb', line 867

def initialize(menu,parent)
  @menu=menu
  @parent=parent
end

Instance Attribute Details

VRMenu

Menu.

Methods

— append(caption,state)

Adds a new menu item at the last with the caption of ((|caption|)) and 
the state of ((|state|)). See ((<state=>)) about ((|state|)).

— insert(ptr,caption,name,state)

Inserts new item at ((|ptr|)).

— delete(id)

Deletes menu. ((|id|)) can be a instance of VRMenuItem or a menu-id integer.

— count

Counts the menu items.

— set(sarr)

Sets the menu according to the ((|sarr|)) which is a structured array 
of strings such like
(({  [ ["&File", [["&Open","open"],["E&xit","exit"]],  }))
(({       ["&Edit",["&Copy","copy]]    }))
(({    ] ]  }))
  Caption : TEXT
  Name : TEXT
  Menu : [Caption, Name|Menu]

When a menu is clicked, ((|Name|))_clicked method is fired.


862
863
864
# File 'lib/vr/vrcontrol.rb', line 862

def menu
  @menu
end

#parentObject (readonly)

Returns the value of attribute parent.



863
864
865
# File 'lib/vr/vrcontrol.rb', line 863

def parent
  @parent
end

Instance Method Details

#append(*arg) ⇒ Object



872
873
874
875
876
877
878
879
880
881
882
# File 'lib/vr/vrcontrol.rb', line 872

def append (*arg)
  m=VRMenuItem.new(@menu)
  id=@parent.newControlID
  if arg[2] then
    @menu.append arg[0],id,arg[2]
  else
    @menu.append arg[0],id
  end
  @parent.registerMenu(m,arg[1],id,arg[0])
  m
end

#count(*arg) ⇒ Object



901
902
903
# File 'lib/vr/vrcontrol.rb', line 901

def count (*arg)
  @menu.count(*arg)
end

#delete(id) ⇒ Object



894
895
896
897
898
899
900
# File 'lib/vr/vrcontrol.rb', line 894

def delete (id)
  if id.is_a?(VRMenuItem) then
    @menu.delete id.etc
  else
    @menu.delete id
  end
end

#insert(ptr, *arg) ⇒ Object



883
884
885
886
887
888
889
890
891
892
893
# File 'lib/vr/vrcontrol.rb', line 883

def insert (ptr,*arg)
  m=VRMenuItem.new(@menu)
  id=@parent.newControlID
  if arg.size>2 then
    @menu.insert arg[0],id,ptr,arg[2]
  else
    @menu.insert arg[0],id,ptr
  end
  @parent.registerMenu(m,arg[1],id,arg[0])
  m
end

#set(sarr) ⇒ Object



905
906
907
908
909
910
911
912
913
914
915
916
917
918
# File 'lib/vr/vrcontrol.rb', line 905

def set(sarr)
  sarr.each do |item|
    if item[1].is_a?(Array) then
      m=@parent.newMenu(true)
      m.set(item[1])
      @menu.append item[0],m.menu,item[2]
    elsif item[1].is_a?(VRMenu) then
      @menu.append item[0],item[1].menu,item[2]
    else
      append(*item)
    end
  end
  self
end