Class: Gtk2HTML::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/gtk2html.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html, irb: false) ⇒ Main

Returns a new instance of Main.



516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
# File 'lib/gtk2html.rb', line 516

def initialize(html, irb: false)
  
  @html = html
  @doc = Htmle.new(html, callback: self)

  @area = area = Gtk::DrawingArea.new
  @layout = layout = Gtk::Layout.new
  widgets = nil
  
  
  client_code = []
  
  window = Gtk::Window.new
  
  @width = 320
  @height = 240
  @window = window
  window.set_default_size(@width, @height)
  
  @dirty = true


  layout.signal_connect("expose_event") do      
    
    width, height = window.size

    @dirty = true if [@width, @height] != [width, height]

    
    if @dirty then
      
      @layout_instructions = prepare_layout @doc

    end

    drawing = Gtk2HTML::DrawingInstructions.new layout
    drawing.render @layout_instructions

    @dirty = false
    
  end

  area.add_events(Gdk::Event::POINTER_MOTION_MASK) 

  area.signal_connect('motion_notify_event') do |item,  event|

    @doc.root.xpath('//*[@onmousemove]').each do |x|
                
      eval x.onmousemove() if x.hotspot? event.x, event.y
      
    end
  end

  area.add_events(Gdk::Event::BUTTON_PRESS_MASK) 

  area.signal_connect "button_press_event" do |item,event| 

    @doc.root.xpath('//*[@onmousedown]').each do |x|
                
      eval x.onmousedown() if x.hotspot? event.x, event.y
      
    end        
  end     

  layout_instructions = prepare_layout @doc

  widgets = Gtk2HTML::WidgetInstructions.new layout
  widgets.render layout_instructions

  @layout.put area, 0, 0
  
  window.add(@layout).show_all
  window.show_all.signal_connect("destroy"){Gtk.main_quit}

  irb ? Thread.new {Gtk.main  } : Gtk.main
end

Instance Attribute Details

#docObject

Returns the value of attribute doc.



513
514
515
# File 'lib/gtk2html.rb', line 513

def doc
  @doc
end

#heightObject (readonly)

Returns the value of attribute height.



514
515
516
# File 'lib/gtk2html.rb', line 514

def height
  @height
end

#htmlObject

Returns the value of attribute html.



513
514
515
# File 'lib/gtk2html.rb', line 513

def html
  @html
end

#layout_instructionsObject

Returns the value of attribute layout_instructions.



513
514
515
# File 'lib/gtk2html.rb', line 513

def layout_instructions
  @layout_instructions
end

#widthObject (readonly)

Returns the value of attribute width.



514
515
516
# File 'lib/gtk2html.rb', line 514

def width
  @width
end

#windowObject (readonly)

Returns the value of attribute window.



514
515
516
# File 'lib/gtk2html.rb', line 514

def window
  @window
end

Instance Method Details

#onmousemove(x, y) ⇒ Object



593
594
595
# File 'lib/gtk2html.rb', line 593

def onmousemove(x,y)
  
end

#refreshObject



597
598
599
600
# File 'lib/gtk2html.rb', line 597

def refresh()
  @dirty = true
  @area.queue_draw
end