Class: WR::Controls

Inherits:
Collection show all
Includes:
ModAccessor
Defined in:
lib/wrb/base.rb

Instance Attribute Summary collapse

Attributes included from ModAccessor

#_accessors

Instance Method Summary collapse

Methods included from ModAccessor

#_add_accessor, #_check_name, #_define_access_method, #_delete_accessor, #_delete_accessor_by_obj

Constructor Details

#initialize(parent, receiver = parent, sendto = nil) ⇒ Controls

; dpp self, parent, receiver, caller



481
482
483
484
485
486
487
# File 'lib/wrb/base.rb', line 481

def initialize(parent, receiver=parent, sendto=nil) #; dpp self, parent, receiver, caller
  raise "parent must be RWin::Window" if parent && !parent.is_a?(RWin::Window) && 
                                         !parent.is_a?(RWin::Dialog)
  @parent = parent
  @receiver = receiver
  @sendto = sendto
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



478
479
480
# File 'lib/wrb/base.rb', line 478

def parent
  @parent
end

#receiverObject (readonly)

Returns the value of attribute receiver.



478
479
480
# File 'lib/wrb/base.rb', line 478

def receiver
  @receiver
end

Instance Method Details

#<<(*args) ⇒ Object



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/wrb/base.rb', line 489

def <<(*args)
  args = args[0] if args[0].is_a?(Array)
  if args[0].respond_to?(:create)
    ret = args[0]
    ret.parent ||= @parent
  elsif args[0].is_a?(Class)
    klass = args.shift
    ret = klass.new(@parent, *args)
  elsif args[0].is_a?(Controls)
    ret = args[0]
  else
   ret = args[0]
  end
  
  if  @parent && @parent.controls.equal?(self) # is root?
    _add_accessor(ret, ret.name) 
#      super(ret)
  end
  
  ret.idcmd = @receiver.new_control_id if ret.respond_to?(:idcmd=) && !ret.idcmd
  ret.class::DefaultEvents.each{|i|
    msg, submsg, template, klass = ret.acceptable_events[i]
    handlername = "#{ret.name}_#{i.to_s}"
    @receiver.set_msgtranslator(msg) unless @receiver.get_msgtranslator(msg)
    @receiver.register_event(ret.idcmd, msg, submsg, handlername, template, klass, @sendto)
  } if defined? ret.class::DefaultEvents
  
  if ret.respond_to?(:create) && @parent.alive?
    ret.create
    if f=parent.inheritfont && ret.is_a?(RWin::Window)
      if (hf=ret.SendMessage(RC::WM_GETFONT, 0, 0))==0 || hf==Font::SystemFontHandle
        ret.font = @parent.SendMessage(RC::WM_GETFONT, 0, 0)
      elsif f==:force
        ret.font = @parent.SendMessage(RC::WM_GETFONT, 0, 0)
      end
    end
  end
  super(ret)
  ret
end

#[](arg) ⇒ Object



530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/wrb/base.rb', line 530

def [](arg)
  if arg.is_a?(Integer)
    arg > ModParent::ItemBaseID ? self.find{|i| i.idcmd == arg} : super(arg)
  elsif arg.is_a?(String) || arg.is_a?(Symbol)
    sym = arg.intern
    self.find{|i| i.name == sym}
  elsif arg.is_a?(WinControl)
    self._index(arg)
  else
    raise "Type #{arg.class} is not allowed"
  end
end

#__move(x, y, w, h) ⇒ Object



584
585
586
# File 'lib/wrb/base.rb', line 584

def __move(x, y, w, h) 
  self._each{|i| i.__move(x, y, w, h) if respond_to?(:__move)}
end

#_createObject



572
573
574
575
576
577
578
579
580
581
582
# File 'lib/wrb/base.rb', line 572

def _create()
  self._each{|i|
    if i.is_a?(WinControl) && !i.alive? #; dp "@i=%p, parent=%p", i, i.parent
      i.create
    elsif i.is_a?(Controls)
      i._create
    elsif !i.is_a?(RWin::Window) && i.respond_to?(:create)
      i.create
    end
  }
end

#_delete(ctl) ⇒ Object Also known as: delete



543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/wrb/base.rb', line 543

def _delete(ctl)
  if @_accessors && (ar=@_accessors[ctl.name]).is_a?(Array)
    ar.delete(ctl)
    @_accessors[ctl.name] = ar[0] if ar.size == 1
  else
    self._delete_accessor(ctl.name)
    if @parent && ctl.respond_to?(:idcmd)
      @parent.registered_messages.each{|msg| @parent.unregister_event(ctl.idcmd, msg)}
    end
  end
  if ctl.respond_to?(:alive?) && ctl.alive?
    if ctl.respond_to?(:close)
      ctl.close
    elsif ctl.respond_to?(:destroy) # for Menu
      ctl.destroy
    end
  end
  super
end

#_hideObject



568
569
570
# File 'lib/wrb/base.rb', line 568

def _hide()
  self._each{|i| i.visible = false}
end

#_showObject



564
565
566
# File 'lib/wrb/base.rb', line 564

def _show()
  self._each{|i| i.visible = true}
end