Class: Wx::SF::ControlShape::EventSink

Inherits:
EvtHandler
  • Object
show all
Defined in:
lib/wx/shapes/shapes/control_shape.rb

Overview

Auxiliary class used by Wx::SF::ControlShape. All events generated by a GUI control (widget) managed by parent control shape are redirected to this event sink which invokes a default event handler or send a copy of the event to shape canvas if requested.

Instance Method Summary collapse

Constructor Details

#initializeEventSink #initialize(parent) ⇒ EventSink

Returns a new instance of EventSink.

Overloads:

  • #initializeEventSink

    Default constructor.

  • #initialize(parent) ⇒ EventSink

    User constructor.

    Parameters:



30
31
32
# File 'lib/wx/shapes/shapes/control_shape.rb', line 30

def initialize(parent = nil)
  @parent_shape = parent
end

Instance Method Details

#_on_key_down(event) ⇒ Object

Parameters:

  • event (Wx::KeyEvent)

    Keyboard event



67
68
69
70
71
72
# File 'lib/wx/shapes/shapes/control_shape.rb', line 67

def _on_key_down(event)
  send_event(event) if (@parent_shape.get_event_processing & EVTPROCESSING::KEY2CANVAS) !=0

  # process the event also by an original handler if requested
  event.skip if (@parent_shape.get_event_processing & EVTPROCESSING::KEY2GUI) != 0
end

#_on_mouse_button(event) ⇒ Object

Parameters:

  • event (Wx::MouseEvent)

    Mouse event



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/wx/shapes/shapes/control_shape.rb', line 37

def _on_mouse_button(event)
  if (@parent_shape.get_event_processing & EVTPROCESSING::MOUSE2CANVAS) != 0
      updated_event = event.clone

      update_mouse_event(updated_event)
      send_event(updated_event)
  end

  # process the event also by an original handler if requested
  event.skip if (@parent_shape.get_event_processing & EVTPROCESSING::MOUSE2GUI) != 0
end

#_on_mouse_move(event) ⇒ Object

Event handler used for delayed processing of a mouse event (mouse movement). The handler creates new key event instance and sends it to a shape canvas for further processing.

Parameters:

  • event (Wx::MouseEvent)

    Mouse event



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/wx/shapes/shapes/control_shape.rb', line 52

def _on_mouse_move(event)
  if (@parent_shape.get_event_processing & EVTPROCESSING::MOUSE2CANVAS) != 0
    updated_event = event.clone

    update_mouse_event(updated_event)
    send_event(updated_event)
  end

  # process the event also by an original handler if requested
  event.skip if (@parent_shape.get_event_processing & EVTPROCESSING::MOUSE2GUI) != 0
end

#_on_size(event) ⇒ Object

Event handler used for adjusting the parent shape’s size in accordance to size of managed GUI control.

Parameters:

  • event (Wx::SizeEvent)

    Size event



76
77
78
79
80
# File 'lib/wx/shapes/shapes/control_shape.rb', line 76

def _on_size(event)
  event.skip

  @parent_shape.update_shape
end

#send_event(event) ⇒ Object (protected)

Send copy of incoming event to a shape canvas.

Parameters:

  • event (Wx::Event)

    Event to be send



86
87
88
89
90
91
92
# File 'lib/wx/shapes/shapes/control_shape.rb', line 86

def send_event(event)
  if @parent_shape && @parent_shape.get_diagram
      canvas = @parent_shape.get_diagram.get_shape_canvas
      # send copy of the event to the shape canvas
      Wx.post_event(canvas, event) if canvas
  end
end

#update_mouse_event(event) ⇒ Object (protected)

Modify given mouse event (recalculate the event’s position in accordance to parent control shape’s position.

Parameters:

  • event (Wx::MouseEvent)

    Mouse event to be updated



97
98
99
100
101
102
103
104
# File 'lib/wx/shapes/shapes/control_shape.rb', line 97

def update_mouse_event(event)
  abs_pos = @parent_shape.get_absolute_position

  x, y = @parent_shape.get_parent_canvas.calc_unscrolled_position(0, 0)

  event.x += (abs_pos.x.to_i + @parent_shape.get_control_offset - x)
  event.y += (abs_pos.y.to_i + @parent_shape.get_control_offset - y)
end