+//----------------------------------------------------------------------------
+// wxCanvasObjectGroupRef
+//----------------------------------------------------------------------------
+
+wxCanvasObjectGroupRef::wxCanvasObjectGroupRef(double x, double y, wxCanvasObjectGroup* group)
+ : wxCanvasObject()
+{
+ m_x = x;
+ m_y = y;
+ m_validbounds=false;
+ m_group=group;
+}
+
+void wxCanvasObjectGroupRef::SetOwner(wxCanvas* canvas)
+{
+ m_owner=canvas;
+ m_group->SetOwner(canvas);
+}
+
+void wxCanvasObjectGroupRef::ExtendArea(int x, int y)
+{
+ if (m_validbounds)
+ {
+ if ( x < m_minx ) m_minx = x;
+ if ( y < m_miny ) m_miny = y;
+ if ( x > m_maxx ) m_maxx = x;
+ if ( y > m_maxy ) m_maxy = y;
+ }
+ else
+ {
+ m_validbounds = true;
+
+ m_minx = x;
+ m_miny = y;
+ m_maxx = x;
+ m_maxy = y;
+ }
+
+}
+
+void wxCanvasObjectGroupRef::Recreate()
+{
+ m_validbounds=false;
+ m_group->Recreate();
+ ExtendArea(m_group->GetXMin(),m_group->GetYMin());
+ ExtendArea(m_group->GetXMax(),m_group->GetYMax());
+
+ //set the area in pixels relative to the parent
+ SetArea( m_owner->GetDeviceX( m_x + m_minx ),
+ m_owner->GetDeviceY( m_y + m_miny ),
+ m_owner->GetDeviceWidth( m_maxx-m_minx ),
+ m_owner->GetDeviceHeight( m_maxy-m_miny ) );
+}
+
+void wxCanvasObjectGroupRef::Render(int xabs, int yabs, int x, int y, int width, int height )
+{
+ wxImage *image = m_owner->GetBuffer();
+ xabs+=m_owner->GetDeviceX(GetPosX());
+ yabs+=m_owner->GetDeviceY(GetPosY());
+
+ int clip_x = xabs + m_group->GetXMin();
+ int clip_width = m_group->GetXMax()-m_group->GetXMin();
+ if (clip_x < x)
+ {
+ clip_width -= x-clip_x;
+ clip_x = x;
+ }
+ if (clip_width > 0)
+ {
+ if (clip_x + clip_width > x + width)
+ clip_width = x+width-clip_x;
+
+ if (clip_width > 0)
+ {
+ int clip_y = yabs + m_group->GetYMin();
+ int clip_height = m_group->GetYMax()-m_group->GetYMin();
+ if (clip_y < y)
+ {
+ clip_height -= y-clip_y;
+ clip_y = y;
+ }
+ if (clip_height > 0)
+ {
+ if (clip_y + clip_height > y + height)
+ clip_height = y+height-clip_y;
+
+ if (clip_height > 0)
+ m_group->Render(xabs,yabs, clip_x, clip_y, clip_width, clip_height );
+ }
+ }
+ }
+}
+
+void wxCanvasObjectGroupRef::WriteSVG( wxTextOutputStream &stream )
+{
+}
+
+bool wxCanvasObjectGroupRef::IsHit( int x, int y, int margin )
+{
+ return m_group->IsHit(x-GetPosX(),y-GetPosY(),margin);
+}
+
+wxCanvasObject* wxCanvasObjectGroupRef::IsHitObject( int x, int y, int margin )
+{
+ return m_group->IsHitObject(x-GetPosX(),y-GetPosY(),margin);
+}
+
+void wxCanvasObjectGroupRef::Move( int x, int y )
+{
+ int old_x = m_x;
+ int old_y = m_y;
+
+ m_x = x;
+ m_y = y;
+
+ if (!m_isControl)
+ {
+ // TODO: sometimes faster to merge into 1 Update or
+ // to break up into four
+ m_owner->Update(m_area.x, m_area.y, m_area.width, m_area.height );
+ //calculate the new area in pixels relative to the parent
+ SetArea( m_owner->GetDeviceX( m_x + m_minx ),
+ m_owner->GetDeviceY( m_y + m_miny ),
+ m_owner->GetDeviceWidth( m_maxx-m_minx ),
+ m_owner->GetDeviceHeight( m_maxy-m_miny ) );
+ m_owner->Update( m_area.x, m_area.y, m_area.width, m_area.height );
+ }
+}
+
+