]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/ogl/src/basic.cpp
Added wxWindow::Center
[wxWidgets.git] / utils / ogl / src / basic.cpp
index 12867bd404be03aea0f80a4a2607327a68409a43..8919f9b08dbd47de2a7abaf00aea7c31165a7b76 100644 (file)
@@ -81,6 +81,22 @@ wxShapeEvtHandler::~wxShapeEvtHandler()
 {
 }
 
+// Creates a copy of this event handler.
+wxShapeEvtHandler* wxShapeEvtHandler::CreateNewCopy()
+{
+  wxShapeEvtHandler* newObject = (wxShapeEvtHandler*) GetClassInfo()->CreateObject();
+
+  wxASSERT( (newObject != NULL) );
+  wxASSERT( (newObject->IsKindOf(CLASSINFO(wxShapeEvtHandler))) );
+
+  newObject->m_previousHandler = newObject;
+
+  CopyData(*newObject);
+
+  return newObject;
+}
+
+
 void wxShapeEvtHandler::OnDelete()
 {
   if (this != GetShape())
@@ -197,6 +213,26 @@ void wxShapeEvtHandler::OnEndDragRight(float x, float y, int keys, int attachmen
     m_previousHandler->OnEndDragRight(x, y, keys, attachment);
 }
 
+// Control points ('handles') redirect control to the actual shape, to make it easier
+// to override sizing behaviour.
+void wxShapeEvtHandler::OnSizingDragLeft(wxControlPoint* pt, bool draw, float x, float y, int keys, int attachment)
+{
+  if (m_previousHandler)
+    m_previousHandler->OnSizingDragLeft(pt, draw, x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnSizingBeginDragLeft(wxControlPoint* pt, float x, float y, int keys, int attachment)
+{
+  if (m_previousHandler)
+    m_previousHandler->OnSizingBeginDragLeft(pt, x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnSizingEndDragLeft(wxControlPoint* pt, float x, float y, int keys, int attachment)
+{
+  if (m_previousHandler)
+    m_previousHandler->OnSizingEndDragLeft(pt, x, y, keys, attachment);
+}
+
 void wxShapeEvtHandler::OnDrawOutline(wxDC& dc, float x, float y, float w, float h)
 {
   if (m_previousHandler)
@@ -220,7 +256,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxShape, wxShapeEvtHandler)
 wxShape::wxShape(wxShapeCanvas *can)
 {
   m_eventHandler = this;
-  SetHandlerShape(this);
+  SetShape(this);
   m_id = 0;
   m_formatted = FALSE;
   m_canvas = can;
@@ -824,8 +860,8 @@ void wxShape::FindRegionNames(wxStringList& list)
 
 void wxShape::AssignNewIds()
 {
-  if (m_id == 0)
-    m_id = NewId();
+//  if (m_id == 0)
+  m_id = NewId();
   wxNode *node = m_children.First();
   while (node)
   {
@@ -1499,7 +1535,13 @@ void wxShape::WritePrologAttributes(wxExpr *clause)
       clause->AddAttributeValue("pen_style", (long)penStyle);
 
     wxString penColour = wxTheColourDatabase->FindName(m_pen->GetColour());
-    if ((penColour != "") && (penColour != "BLACK"))
+    if (penColour == "")
+    {
+      wxString hex(oglColourToHex(m_pen->GetColour()));
+      hex = wxString("#") + hex;
+      clause->AddAttributeValueString("pen_colour", hex);
+    }
+    else if (penColour != "BLACK")
       clause->AddAttributeValueString("pen_colour", penColour);
   }
 
@@ -1507,7 +1549,13 @@ void wxShape::WritePrologAttributes(wxExpr *clause)
   {
     wxString brushColour = wxTheColourDatabase->FindName(m_brush->GetColour());
 
-    if ((brushColour != "") && (brushColour != "WHITE"))
+    if (brushColour == "")
+    {
+      wxString hex(oglColourToHex(m_brush->GetColour()));
+      hex = wxString("#") + hex;
+      clause->AddAttributeValueString("brush_colour", hex);
+    }
+    else if (brushColour != "WHITE")
       clause->AddAttributeValueString("brush_colour", brushColour);
     
     if (m_brush->GetStyle() != wxSOLID)
@@ -1759,11 +1807,25 @@ void wxShape::ReadPrologAttributes(wxExpr *clause)
   if (brush_string == "")
     brush_string = "WHITE";
 
-  m_pen = wxThePenList->FindOrCreatePen(pen_string, pen_width, pen_style);
+  if (pen_string[0] == '#')
+  {
+    wxColour col(oglHexToColour(pen_string.After('#')));
+    m_pen = wxThePenList->FindOrCreatePen(col, pen_width, pen_style);
+  }
+  else
+    m_pen = wxThePenList->FindOrCreatePen(pen_string, pen_width, pen_style);
+
   if (!m_pen)
     m_pen = wxBLACK_PEN;
 
-  m_brush = wxTheBrushList->FindOrCreateBrush(brush_string, brush_style);
+  if (brush_string[0] == '#')
+  {
+    wxColour col(oglHexToColour(brush_string.After('#')));
+    m_brush = wxTheBrushList->FindOrCreateBrush(col, brush_style);
+  }
+  else
+    m_brush = wxTheBrushList->FindOrCreateBrush(brush_string, brush_style);
+
   if (!m_brush)
     m_brush = wxWHITE_BRUSH;
 
@@ -1876,7 +1938,7 @@ void wxShape::ReadRegions(wxExpr *clause)
       m_regionProportionX = propXExpr->RealValue();
       m_regionProportionY = propYExpr->RealValue();
 
-      formatMode = (formatExpr->IntegerValue() != 0);
+      formatMode = (int) formatExpr->IntegerValue();
       fontSize = (int)sizeExpr->IntegerValue();
       fontFamily = (int)familyExpr->IntegerValue();
       fontStyle = (int)styleExpr->IntegerValue();
@@ -2002,6 +2064,7 @@ void wxShape::ReadRegions(wxExpr *clause)
 
 void wxShape::Copy(wxShape& copy)
 {
+  copy.m_id = m_id;
   copy.m_xpos = m_xpos;
   copy.m_ypos = m_ypos;
   copy.m_pen = m_pen;
@@ -2055,16 +2118,48 @@ void wxShape::Copy(wxShape& copy)
 }
 
 // Create and return a new, fully copied object.
-wxShape *wxShape::CreateNewCopy(wxShapeCanvas *theCanvas)
+wxShape *wxShape::CreateNewCopy(bool resetMapping, bool recompute)
 {
-  wxObjectCopyMapping.Clear();
-  wxShape *newObject = PrivateCopy();
-  if (theCanvas)
-    newObject->AddToCanvas(theCanvas);
-  newObject->Recompute();
+  if (resetMapping)
+    wxObjectCopyMapping.Clear();
+
+  wxShape* newObject = (wxShape*) GetClassInfo()->CreateObject();
+
+  wxASSERT( (newObject != NULL) );
+  wxASSERT( (newObject->IsKindOf(CLASSINFO(wxShape))) );
+
+  Copy(*newObject);
+
+  if (GetEventHandler() != this)
+  {
+    wxShapeEvtHandler* newHandler = GetEventHandler()->CreateNewCopy();
+    newObject->SetEventHandler(newHandler);
+    newObject->SetPreviousHandler(NULL);
+    newHandler->SetPreviousHandler(newObject);
+    newHandler->SetShape(newObject);
+  }
+
+  if (recompute)
+    newObject->Recompute();
   return newObject;
 }
 
+// Does the copying for this object, including copying event
+// handler data if any. Calls the virtual Copy function.
+void wxShape::CopyWithHandler(wxShape& copy)
+{
+    Copy(copy);
+
+    if (GetEventHandler() != this)
+    {
+        wxASSERT( copy.GetEventHandler() != NULL );
+        wxASSERT( copy.GetEventHandler() != (&copy) );
+        wxASSERT( GetEventHandler()->GetClassInfo() == copy.GetEventHandler()->GetClassInfo() );
+        GetEventHandler()->CopyData(* (copy.GetEventHandler()));
+    }
+}
+
+
 // Default - make 6 control points
 void wxShape::MakeControlPoints()
 {