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.



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/gtk2html.rb', line 407

def initialize(html, irb: false)
  
  @html = html
  @doc = Htmle.new(html, callback: self)
  
  @area = area = Gtk::DrawingArea.new
  client_code = []
  
  window = Gtk::Window.new
  
  @width = 320
  @height = 240
  @window = window
  window.set_default_size(@width, @height)
  
  @dirty = true
  
  
  area.signal_connect("expose_event") do      
    
    width, height = window.size

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

    
    if @dirty then

      Thread.new { @doc.root.xpath('//script').each {|x| eval x.text.unescape } }
      
      @width, @height = window.size
      instructions = Gtk2HTML::Render.new(@doc, @width, @height).to_a

      @layout_instructions = Gtk2HTML::Layout.new(instructions).to_a

    end

    drawing = Gtk2HTML::DrawingInstructions.new area
    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     
  
  window.add(area).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.



404
405
406
# File 'lib/gtk2html.rb', line 404

def doc
  @doc
end

#heightObject (readonly)

Returns the value of attribute height.



405
406
407
# File 'lib/gtk2html.rb', line 405

def height
  @height
end

#htmlObject

Returns the value of attribute html.



404
405
406
# File 'lib/gtk2html.rb', line 404

def html
  @html
end

#widthObject (readonly)

Returns the value of attribute width.



405
406
407
# File 'lib/gtk2html.rb', line 405

def width
  @width
end

#windowObject (readonly)

Returns the value of attribute window.



405
406
407
# File 'lib/gtk2html.rb', line 405

def window
  @window
end

Instance Method Details

#onmousemove(x, y) ⇒ Object



477
478
479
# File 'lib/gtk2html.rb', line 477

def onmousemove(x,y)
  
end

#refreshObject



481
482
483
484
# File 'lib/gtk2html.rb', line 481

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