Module: TkAutoPostMenu

Defined in:
lib/a-tkcommons.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(_widget) ⇒ Object



1483
1484
1485
# File 'lib/a-tkcommons.rb', line 1483

def self.extended(_widget)
  _widget.__initialize_posting(_widget)
end

.included(_widget) ⇒ Object



1487
1488
1489
# File 'lib/a-tkcommons.rb', line 1487

def self.included(_widget)
  _widget.__initialize_posting(_widget)
end

Instance Method Details

#__initialize_posting(_widget = self) ⇒ Object



1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
# File 'lib/a-tkcommons.rb', line 1502

def __initialize_posting(_widget=self)
  #    parent = TkWinfo.parent(_widget)
  #    parent.bind_append("Enter", proc{p "Enter parent"})
  #    parent.bind_append("Leave", proc{p "Leave parent"})

  chs = TkWinfo.children(_widget)
  hh = 22
  @last_post = nil
  @posting_on = true
  @event_posting_on = false
  @m_show = Hash.new
  chs.each{|ch|
    ch.menu.bind_append("Map", proc{ @m_show[ch.menu] = true })
    ch.menu.bind_append("Unmap", proc{ @m_show[ch.menu] = false })
    ch.bind_append("Enter", proc{|x,y,rx,ry|
      if @posting_on
        if @last_post && @last_post != ch.menu
          @last_post.unpost
          @last_post=nil
        end
        if @last_clicked && @last_clicked != ch.menu
          @last_clicked.unpost
          @last_clicked = nil
        end
        
        ch.menu.post(x-rx,y-ry+hh)
        #just_posted = TkWinfo.containing(x, y+hh)

        chmenus = TkWinfo.children(ch)
        @last_menu_posted = chmenus[0]
        @last_menu_posted.set_focus

        @last_menu_posted.bind("Enter", proc{
          @last_menu_posted.bind("Leave", proc{
            if @posting_on
              @last_post.unpost if @last_post
              @last_post = nil
              @last_menu_posted.bind("Enter", proc{})
              @last_menu_posted.bind("Leave", proc{})
            end
          })
        })
        #@last_post = just_posted
      end

      #@last_post=ch.menu
    }, "%X %Y %x %y")
    ch.bind_append("Leave", proc{
      ch.configure("state"=>:normal, "relief"=>:flat)
      if @posting_on
        if @last_post
          _x = TkWinfo.x(@last_post)
          _y = TkWinfo.y(@last_post)
          ch.event_generate("KeyPress", :keysym=>"Escape")  if Tk.focus.kind_of?(TkMenu) &&  Tk.focus != ch.menu
          @last_post.post(_x,_y) if @last_clicked && @last_clicked == ch.menu
        end
        if @last_post!=ch.menu
          @last_post=ch.menu
        else
          @last_post=nil
        end
        if !Tk.focus.kind_of?(TkMenu)
          @last_post.unpost if @last_post
          @last_post=nil
        end
      end
    })
    ch.bind_append("1", proc{|x,y,rx,ry|
      @posting_on=true if @event_posting_on
      if @last_post && @last_post != ch.menu
        @last_post.unpost
        @last_post = nil
      end
      @last_post=ch.menu #if ch.state == 'active'
      ch.configure('state'=>'normal')
      @last_clicked = ch.menu
      #@last_post.unpost
      #@last_post.post(0,0)
      #@last_post.set_focus

    }, "%X %Y %x %y")

  }
  _widget.bind_append("Leave", proc{
    if @posting_on  && Tk.focus != @last_menu_posted
      @last_post.unpost if @last_post
      @last_post=nil
      @posting_on = false if @event_posting_on
    end
    TkAfter.new(1000,1, proc{
      one_post = false
      @m_show.each{|m,v|
        one_post = v
        break if v
      }
      @posting_on = one_post if @event_posting_on
    }).start
  })


  _widget.bind_append("1", proc{
    @posting_on=true  if @event_posting_on
  })

end

#event_posting_offObject



1496
1497
1498
1499
# File 'lib/a-tkcommons.rb', line 1496

def event_posting_off
  @event_posting_on = false
  @posting_on = true
end

#event_posting_onObject



1491
1492
1493
1494
# File 'lib/a-tkcommons.rb', line 1491

def event_posting_on
  @event_posting_on = true
  @posting_on = false
end