diff Framework/Viewport/WidgetViewport.cpp @ 61:ca644004d2ee wasm

MAJOR - removal of Start/Stop and observers in IWidget
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 May 2017 17:55:13 +0200
parents f0f354a97581
children 298f375dcb68
line wrap: on
line diff
--- a/Framework/Viewport/WidgetViewport.cpp	Wed May 10 16:10:47 2017 +0200
+++ b/Framework/Viewport/WidgetViewport.cpp	Wed May 10 17:55:13 2017 +0200
@@ -26,28 +26,25 @@
 
 namespace OrthancStone
 {
-  void WidgetViewport::UnregisterCentralWidget()
-  {
-    mouseTracker_.reset(NULL);
-
-    if (centralWidget_.get() != NULL)
-    {
-      centralWidget_->Unregister(*this);
-    }
-  }
-
-
   WidgetViewport::WidgetViewport() :
     statusBar_(NULL),
     isMouseOver_(false),
     lastMouseX_(0),
     lastMouseY_(0),
-    backgroundChanged_(false),
-    started_(false)
+    backgroundChanged_(false)
   {
   }
 
 
+  void WidgetViewport::SetDefaultView()
+  {
+    if (centralWidget_.get() != NULL)
+    {
+      centralWidget_->SetDefaultView();
+    }
+  }
+
+
   void WidgetViewport::SetStatusBar(IStatusBar& statusBar)
   {
     statusBar_ = &statusBar;
@@ -59,39 +56,19 @@
   }
 
 
-  void WidgetViewport::ResetStatusBar()
-  {
-    statusBar_ = NULL;
-
-    if (centralWidget_.get() != NULL)
-    {
-      centralWidget_->ResetStatusBar();
-    }
-  }
-
-
   IWidget& WidgetViewport::SetCentralWidget(IWidget* widget)
   {
-    if (started_)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
-    }
-
     if (widget == NULL)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
 
-    UnregisterCentralWidget();
+    mouseTracker_.reset(NULL);
       
     centralWidget_.reset(widget);
-    centralWidget_->Register(*this);
+    centralWidget_->SetViewport(*this);
 
-    if (statusBar_ == NULL)
-    {
-      centralWidget_->ResetStatusBar();
-    }
-    else
+    if (statusBar_ != NULL)
     {
       centralWidget_->SetStatusBar(*statusBar_);
     }
@@ -109,28 +86,6 @@
   }
 
 
-  void WidgetViewport::Start()
-  {
-    if (centralWidget_.get() != NULL)
-    {
-      centralWidget_->Start();
-    }
-
-    started_ = true;
-  }
-
-
-  void WidgetViewport::Stop()
-  {
-    started_ = false;
-
-    if (centralWidget_.get() != NULL)
-    {
-      centralWidget_->Stop();
-    }
-  }
-
-
   void WidgetViewport::SetSize(unsigned int width,
                                unsigned int height)
   {
@@ -147,8 +102,7 @@
 
   bool WidgetViewport::Render(Orthanc::ImageAccessor& surface)
   {
-    if (!started_ ||
-        centralWidget_.get() == NULL)
+    if (centralWidget_.get() == NULL)
     {
       return false;
     }
@@ -187,11 +141,6 @@
                                  int y,
                                  KeyboardModifiers modifiers)
   {
-    if (!started_)
-    {
-      return;
-    }
-
     lastMouseX_ = x;
     lastMouseY_ = y;
 
@@ -210,11 +159,6 @@
 
   void WidgetViewport::MouseUp()
   {
-    if (!started_)
-    {
-      return;
-    }
-
     if (mouseTracker_.get() != NULL)
     {
       mouseTracker_->MouseUp();
@@ -227,7 +171,7 @@
   void WidgetViewport::MouseMove(int x, 
                                  int y) 
   {
-    if (!started_)
+    if (centralWidget_.get() == NULL)
     {
       return;
     }
@@ -266,8 +210,7 @@
   {
     isMouseOver_ = false;
 
-    if (started_ &&
-        mouseTracker_.get() != NULL)
+    if (mouseTracker_.get() != NULL)
     {
       mouseTracker_->MouseUp();
       mouseTracker_.reset(NULL);
@@ -282,11 +225,6 @@
                                   int y,
                                   KeyboardModifiers modifiers)
   {
-    if (!started_)
-    {
-      return;
-    }
-
     if (centralWidget_.get() != NULL &&
         mouseTracker_.get() == NULL)
     {