]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/samples/ogl/studio/shapes.cpp
no changes; just added some comments
[wxWidgets.git] / contrib / samples / ogl / studio / shapes.cpp
index 272b887ba299298fbdc6af09ed3068e8f2e02815..e7125a4a24f3f0d72f6e6a55711dd2517fa22925 100644 (file)
@@ -1,18 +1,14 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        shapes.cpp
+// Name:        contrib/samples/ogl/studio/shapes.cpp
 // Purpose:     Implements Studio shapes
 // Author:      Julian Smart
 // Modified by:
 // Created:     12/07/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:    wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-// #pragma implementation
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 #endif
 
 #ifndef WX_PRECOMP
-#include <wx/wx.h>
+#include "wx/wx.h"
 #endif
 
 #if !wxUSE_DOC_VIEW_ARCHITECTURE
 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h!
 #endif
 
-#include <wx/deprecated/setup.h>
-#include <wx/deprecated/wxexpr.h>
+#include "wx/ogl/ogl.h" // base header of OGL, includes and adjusts wx/deprecated/setup.h
 
 #include "studio.h"
 #include "doc.h"
 #include "shapes.h"
 #include "view.h"
-#include <wx/ogl/basicp.h>
-#include <wx/ogl/linesp.h>
 #include "cspalette.h"
 #include "dialogs.h"
 
@@ -83,7 +76,7 @@ void csEvtHandler::CopyData(wxShapeEvtHandler& copy)
     csEvtHandler& csCopy = (csEvtHandler&) copy;
     csCopy.m_label = m_label;
 }
+
 void csEvtHandler::OnLeftClick(double WXUNUSED(x), double WXUNUSED(y), int keys, int WXUNUSED(attachment))
 {
   wxClientDC dc(GetShape()->GetCanvas());
@@ -130,7 +123,7 @@ void csEvtHandler::OnLeftClick(double WXUNUSED(x), double WXUNUSED(y), int keys,
     // If the shape was selected, deselect it and vice versa.
     bool selected = GetShape()->Selected();
 
-    view->SelectAll(FALSE);
+    view->SelectAll(false);
 
     selected = !selected;
 
@@ -143,13 +136,13 @@ void csEvtHandler::OnLeftClick(double WXUNUSED(x), double WXUNUSED(y), int keys,
   {
     if (GetShape()->Selected())
     {
-        GetShape()->Select(FALSE, &dc);
-        view->SelectShape(GetShape(), FALSE);
+        GetShape()->Select(false, &dc);
+        view->SelectShape(GetShape(), false);
     }
     else
     {
-        GetShape()->Select(TRUE, &dc);
-        view->SelectShape(GetShape(), TRUE);
+        GetShape()->Select(true, &dc);
+        view->SelectShape(GetShape(), true);
     }
     GetShape()->GetCanvas()->Redraw(dc); // Redraw because bits of objects will be missing
   }
@@ -159,7 +152,9 @@ void csEvtHandler::OnLeftClick(double WXUNUSED(x), double WXUNUSED(y), int keys,
   }
   else
   {
+#if wxUSE_STATUSBAR
     ((wxFrame*)wxGetApp().GetTopWindow())->SetStatusText(m_label);
+#endif // wxUSE_STATUSBAR
   }
 }
 
@@ -194,7 +189,7 @@ void csEvtHandler::OnBeginDragRight(double x, double y, int WXUNUSED(keys), int
   wxClientDC dc(GetShape()->GetCanvas());
   GetShape()->GetCanvas()->PrepareDC(dc);
 
-  wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+  wxPen dottedPen(*wxBLACK, 1, wxDOT);
   dc.SetLogicalFunction(OGLRBLF);
   dc.SetPen(dottedPen);
   double xp, yp;
@@ -208,7 +203,7 @@ void csEvtHandler::OnDragRight(bool WXUNUSED(draw), double x, double y, int WXUN
   wxClientDC dc(GetShape()->GetCanvas());
   GetShape()->GetCanvas()->PrepareDC(dc);
 
-  wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+  wxPen dottedPen(*wxBLACK, 1, wxDOT);
   dc.SetLogicalFunction(OGLRBLF);
   dc.SetPen(dottedPen);
   double xp, yp;
@@ -224,7 +219,7 @@ void csEvtHandler::OnEndDragRight(double x, double y, int WXUNUSED(keys), int at
   // Check if we're on an object
   int new_attachment;
   wxShape *otherShape = canvas->FindFirstSensitiveShape(x, y, &new_attachment, OP_DRAG_RIGHT);
-  
+
   if (otherShape && !otherShape->IsKindOf(CLASSINFO(wxLineShape)))
   {
         wxLineShape* theShape = new csLineShape;
@@ -280,7 +275,7 @@ void csEvtHandler::OnDragLeft(bool draw, double x, double y, int keys, int attac
 
   dc.SetLogicalFunction(OGLRBLF);
 
-  wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+  wxPen dottedPen(*wxBLACK, 1, wxDOT);
   dc.SetPen(dottedPen);
   dc.SetBrush(* wxTRANSPARENT_BRUSH);
 
@@ -299,7 +294,7 @@ void csEvtHandler::OnDragLeft(bool draw, double x, double y, int keys, int attac
   GetShape()->GetEventHandler()->OnDrawOutline(dc, xx, yy, w, h);
 
   // Draw bounding box for other selected shapes
-  wxNode* node = GetShape()->GetCanvas()->GetDiagram()->GetShapeList()->GetFirst();
+  wxObjectList::compatibility_iterator node = GetShape()->GetCanvas()->GetDiagram()->GetShapeList()->GetFirst();
   while (node)
   {
      wxShape* shape = (wxShape*) node->GetData();
@@ -349,7 +344,7 @@ void csEvtHandler::OnBeginDragLeft(double x, double y, int keys, int attachment)
 
   dc.SetLogicalFunction(OGLRBLF);
 
-  wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+  wxPen dottedPen(*wxBLACK, 1, wxDOT);
   dc.SetPen(dottedPen);
   dc.SetBrush((* wxTRANSPARENT_BRUSH));
 
@@ -358,7 +353,7 @@ void csEvtHandler::OnBeginDragLeft(double x, double y, int keys, int attachment)
   GetShape()->GetEventHandler()->OnDrawOutline(dc, xx, yy, w, h);
 
   // Draw bounding box for other selected shapes
-  wxNode* node = GetShape()->GetCanvas()->GetDiagram()->GetShapeList()->GetFirst();
+  wxObjectList::compatibility_iterator node = GetShape()->GetCanvas()->GetDiagram()->GetShapeList()->GetFirst();
   while (node)
   {
      wxShape* shape = (wxShape*) node->GetData();
@@ -413,7 +408,7 @@ void csEvtHandler::OnEndDragLeft(double x, double y, int keys, int attachment)
                 new csCommandState(ID_CS_MOVE, newShape, GetShape()));
 
   // Move line points
-  wxNode* node = GetShape()->GetCanvas()->GetDiagram()->GetShapeList()->GetFirst();
+  wxObjectList::compatibility_iterator node = GetShape()->GetCanvas()->GetDiagram()->GetShapeList()->GetFirst();
   while (node)
   {
      wxShape* shape = (wxShape*) node->GetData();
@@ -427,7 +422,7 @@ void csEvtHandler::OnEndDragLeft(double x, double y, int keys, int attachment)
         {
             wxLineShape* newLineShape = (wxLineShape*) lineShape->CreateNewCopy();
 
-            wxNode *node1 = newLineShape->GetLineControlPoints()->GetFirst();
+            wxObjectList::compatibility_iterator node1 = newLineShape->GetLineControlPoints()->GetFirst();
             while (node1)
             {
                 wxRealPoint *point = (wxRealPoint *)node1->GetData();
@@ -477,7 +472,7 @@ void csEvtHandler::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, i
         wxClientDC dc(canvas);
         canvas->PrepareDC(dc);
 
-        shape->SetDisableLabel(FALSE);
+        shape->SetDisableLabel(false);
 
         if (lpt->m_type == CONTROL_POINT_LINE)
         {
@@ -529,7 +524,7 @@ void csEvtHandler::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, i
   shape->Recompute();
   shape->ResetControlPoints();
   if (!pt->m_eraseObject)
-    shape->Show(FALSE);
+    shape->Show(false);
 */
 
   wxShape* newShape = shape->CreateNewCopy();
@@ -612,7 +607,7 @@ bool csEvtHandler::EditProperties()
 
     // For now, no line property editing
     if (shape->IsKindOf(CLASSINFO(wxLineShape)))
-        return FALSE;
+        return false;
 
     csDiagramView* view = ((csCanvas*)shape->GetCanvas())->GetView();
 
@@ -677,19 +672,25 @@ bool csEvtHandler::EditProperties()
     else
     {
         wxMessageBox(_T("Unrecognised shape."), _T("Studio"), wxICON_EXCLAMATION);
-        return FALSE;
+        return false;
     }
 
+    wxString newLabel(m_label);
+
+#if wxUSE_WX_RESOURCES
     csShapePropertiesDialog* dialog = new csShapePropertiesDialog(shape->GetCanvas()->GetParent(), title, attributeDialog, attributeDialogName);
     dialog->GetGeneralPropertiesDialog()->SetShapeLabel(m_label);
     if (dialog->ShowModal() == wxID_CANCEL)
     {
         dialog->Destroy();
-        return FALSE;
+        return false;
     }
 
-    wxString newLabel = dialog->GetGeneralPropertiesDialog()->GetShapeLabel();
+    newLabel = dialog->GetGeneralPropertiesDialog()->GetShapeLabel();
     dialog->Destroy();
+#else
+    wxUnusedVar(attributeDialog);
+#endif // wxUSE_WX_RESOURCES
 
     wxShape* newShape = shape->CreateNewCopy();
 
@@ -699,19 +700,20 @@ bool csEvtHandler::EditProperties()
     view->GetDocument()->GetCommandProcessor()->Submit(new csDiagramCommand(_T("Edit properties"), (csDiagramDocument*) view->GetDocument(),
                 new csCommandState(ID_CS_EDIT_PROPERTIES, newShape, shape)));
 
-    return TRUE;
+    return true;
 }
 
 /*
  * Diagram
  */
+
+#if wxUSE_PROLOGIO
 bool csDiagram::OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr)
 {
   wxDiagram::OnShapeSave(db, shape, expr);
   csEvtHandler *handler = (csEvtHandler *)shape.GetEventHandler();
   expr.AddAttributeValueString(_T("label"), handler->m_label);
-  return TRUE;
+  return true;
 }
 
 bool csDiagram::OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr)
@@ -721,9 +723,10 @@ bool csDiagram::OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr)
   expr.GetAttributeValue(_T("label"), label);
   csEvtHandler *handler = new csEvtHandler(&shape, &shape, label);
   shape.SetEventHandler(handler);
-  
-  return TRUE;
+
+  return true;
 }
+#endif // wxUSE_PROLOGIO
 
 IMPLEMENT_DYNAMIC_CLASS(csThinRectangleShape, wxDrawnShape)
 
@@ -741,7 +744,7 @@ csThinRectangleShape::csThinRectangleShape()
 
     SetAttachmentMode(ATTACHMENT_MODE_BRANCHING);
     SetBranchStyle(BRANCHING_ATTACHMENT_NORMAL|BRANCHING_ATTACHMENT_BLOB);
-    SetCentreResize(FALSE);
+    SetCentreResize(false);
 }
 
 IMPLEMENT_DYNAMIC_CLASS(csWideRectangleShape, wxDrawnShape)
@@ -760,7 +763,7 @@ csWideRectangleShape::csWideRectangleShape()
 
     SetAttachmentMode(ATTACHMENT_MODE_BRANCHING);
     SetBranchStyle(BRANCHING_ATTACHMENT_NORMAL|BRANCHING_ATTACHMENT_BLOB);
-    SetCentreResize(FALSE);
+    SetCentreResize(false);
 }
 
 IMPLEMENT_DYNAMIC_CLASS(csTriangleShape, wxDrawnShape)
@@ -814,7 +817,7 @@ csTriangleShape::csTriangleShape()
 
     SetAttachmentMode(ATTACHMENT_MODE_BRANCHING);
     SetBranchStyle(BRANCHING_ATTACHMENT_NORMAL|BRANCHING_ATTACHMENT_BLOB);
-    SetCentreResize(FALSE);
+    SetCentreResize(false);
 }
 
 IMPLEMENT_DYNAMIC_CLASS(csSemiCircleShape, wxDrawnShape)
@@ -911,7 +914,7 @@ csSemiCircleShape::csSemiCircleShape()
 
     SetAttachmentMode(ATTACHMENT_MODE_BRANCHING);
     SetBranchStyle(BRANCHING_ATTACHMENT_NORMAL|BRANCHING_ATTACHMENT_BLOB);
-    SetCentreResize(FALSE);
+    SetCentreResize(false);
 }
 
 IMPLEMENT_DYNAMIC_CLASS(csCircleShape, wxCircleShape)
@@ -926,7 +929,7 @@ csCircleShape::csCircleShape()
 
     SetAttachmentMode(ATTACHMENT_MODE_BRANCHING);
     SetBranchStyle(BRANCHING_ATTACHMENT_NORMAL|BRANCHING_ATTACHMENT_BLOB);
-    SetCentreResize(FALSE);
+    SetCentreResize(false);
 }
 
 IMPLEMENT_DYNAMIC_CLASS(csCircleShadowShape, wxCircleShape)
@@ -941,7 +944,7 @@ csCircleShadowShape::csCircleShadowShape()
 
     SetAttachmentMode(ATTACHMENT_MODE_BRANCHING);
     SetBranchStyle(BRANCHING_ATTACHMENT_NORMAL|BRANCHING_ATTACHMENT_BLOB);
-    SetCentreResize(FALSE);
+    SetCentreResize(false);
     SetShadowMode(SHADOW_RIGHT);
 }
 
@@ -971,7 +974,7 @@ csOctagonShape::csOctagonShape()
 
     SetAttachmentMode(ATTACHMENT_MODE_BRANCHING);
     SetBranchStyle(BRANCHING_ATTACHMENT_NORMAL|BRANCHING_ATTACHMENT_BLOB);
-    SetCentreResize(FALSE);
+    SetCentreResize(false);
 }
 
 // This is a transparent shape for drawing around other shapes.
@@ -983,7 +986,7 @@ csGroupShape::csGroupShape()
     SetBrush(wxTRANSPARENT_BRUSH);
 
     SetSize(csSTANDARD_SHAPE_WIDTH, csSTANDARD_SHAPE_WIDTH);
-    SetCentreResize(FALSE);
+    SetCentreResize(false);
 }
 
 void csGroupShape::OnDraw(wxDC& dc)
@@ -1013,20 +1016,20 @@ bool csGroupShape::HitTest(double x, double y, int* attachment, double* distance
     if (x >= x1 && x <= x2)
     {
         if ((y >= y1 - edgeTolerance) && (y <= y1 + edgeTolerance))
-            return TRUE;
+            return true;
         if ((y <= y2 + edgeTolerance) && (y >= y2 - edgeTolerance))
-            return TRUE;
+            return true;
     }
     // Left/right edges
     if (y >= y1 && y <= y2)
     {
         if ((x >= x1 - edgeTolerance) && (x <= x1 + edgeTolerance))
-            return TRUE;
+            return true;
         if ((x <= x2 + edgeTolerance) && (x >= x2 - edgeTolerance))
-            return TRUE;
+            return true;
     }
 
-    return FALSE;
+    return false;
 }
 
 IMPLEMENT_DYNAMIC_CLASS(csTextBoxShape, wxRectangleShape)
@@ -1040,7 +1043,7 @@ csTextBoxShape::csTextBoxShape()
 
     SetAttachmentMode(ATTACHMENT_MODE_NONE);
     SetBranchStyle(BRANCHING_ATTACHMENT_NORMAL|BRANCHING_ATTACHMENT_BLOB);
-    SetCentreResize(FALSE);
+    SetCentreResize(false);
 }
 
 IMPLEMENT_DYNAMIC_CLASS(csLineShape, wxLineShape)
@@ -1066,7 +1069,7 @@ bool csLineShape::OnMoveMiddleControlPoint(wxDC& WXUNUSED(dc), wxLineControlPoin
     view->GetDocument()->GetCommandProcessor()->Submit(new csDiagramCommand(_T("Move line point"), (csDiagramDocument*) view->GetDocument(),
                 new csCommandState(ID_CS_MOVE_LINE_POINT, newShape, this)));
 
-    return TRUE;
+    return true;
 }
 
 wxLabelShape* csLineShape::OnCreateLabelShape(wxLineShape *parent, wxShapeRegion *region, double w, double h)
@@ -1085,7 +1088,7 @@ bool csLineShape::OnLabelMovePre(wxDC& dc, wxLabelShape* labelShape, double x, d
 
     view->GetDocument()->GetCommandProcessor()->Submit(new csDiagramCommand("Move label", (csDiagramDocument*) view->GetDocument(),
                 new csCommandState(ID_CS_MOVE_LABEL, newShape, this)));
-  return TRUE;
+  return true;
 }
 #endif
 
@@ -1153,7 +1156,7 @@ void studioShapeEditProc(wxMenu& menu, wxCommandEvent& event)
                 break;
 
             double theta = shape->GetRotation();
-            const double myPi = 3.1415926535897932384626433832795 ;
+            const double myPi = M_PI;
             double ninetyDegrees = myPi/2.0;
 
             wxString opStr;
@@ -1192,4 +1195,3 @@ void ShapeEditMenu::OnCommand(wxCommandEvent& event)
 {
     studioShapeEditProc(*this, event);
 }
-