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.



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/gtk2html.rb', line 270

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 = 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.



267
268
269
# File 'lib/gtk2html.rb', line 267

def doc
  @doc
end

#heightObject (readonly)

Returns the value of attribute height.



268
269
270
# File 'lib/gtk2html.rb', line 268

def height
  @height
end

#htmlObject

Returns the value of attribute html.



267
268
269
# File 'lib/gtk2html.rb', line 267

def html
  @html
end

#widthObject (readonly)

Returns the value of attribute width.



268
269
270
# File 'lib/gtk2html.rb', line 268

def width
  @width
end

#windowObject (readonly)

Returns the value of attribute window.



268
269
270
# File 'lib/gtk2html.rb', line 268

def window
  @window
end

Instance Method Details

#onmousemove(x, y) ⇒ Object



339
340
341
# File 'lib/gtk2html.rb', line 339

def onmousemove(x,y)
  
end

#refreshObject



343
344
345
346
# File 'lib/gtk2html.rb', line 343

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