glom r2011 - trunk/glom/bakery



Author: murrayc
Date: Fri Mar 20 10:12:11 2009
New Revision: 2011
URL: http://svn.gnome.org/viewvc/glom?rev=2011&view=rev

Log:
Really restored files.

Added:
   trunk/glom/bakery/AppInstanceManager.cc
   trunk/glom/bakery/AppInstanceManager.h

Added: trunk/glom/bakery/AppInstanceManager.cc
==============================================================================
--- (empty file)
+++ trunk/glom/bakery/AppInstanceManager.cc	Fri Mar 20 10:12:11 2009
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2000 Murray Cumming
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glom/bakery/AppInstanceManager.h>
+#include <glom/bakery/App.h>
+#include <gtkmm/main.h>
+
+namespace GlomBakery
+{
+
+AppInstanceManager::AppInstanceManager()
+{
+  m_bExiting = false;
+}
+
+AppInstanceManager::~AppInstanceManager()
+{
+}
+
+void AppInstanceManager::on_app_hide(App* pApp)
+{
+  //If pApp is one of the remembered instances (it always should be):
+  type_listAppInstances::iterator iterFind = std::find(m_listAppInstances.begin(), m_listAppInstances.end(), pApp);
+  if(iterFind != m_listAppInstances.end())
+  {
+    m_listAppInstances.erase(iterFind);
+    delete pApp;
+    pApp = 0;
+  }
+
+  //When the last instance goes, the application closes.
+  if(m_listAppInstances.empty())
+  {
+    Gtk::Main::quit();
+  }
+}
+
+void AppInstanceManager::add_app(App* pApp)
+{
+  m_listAppInstances.push_back(pApp);
+
+  //Allow the AppInstanceManager to respond when the Application is hidden (hidden == closed):
+  pApp->ui_signal_hide().connect( sigc::bind<App*>(sigc::mem_fun(*this, &AppInstanceManager::on_app_hide), pApp) );
+}
+
+void AppInstanceManager::close_all()
+{
+  m_bExiting = true; //One of the instances could cancel this loop.
+
+  type_listAppInstances::iterator i = m_listAppInstances.begin();
+  while (m_bExiting && (i != m_listAppInstances.end()))
+  {
+    type_listAppInstances::iterator j = i;
+    i++;
+
+    App* pApp = (*j);
+    if(pApp)
+    {
+      type_listAppInstances::size_type count = m_listAppInstances.size();
+      pApp->on_menu_file_close();
+
+      //The iterator is invalid if an element has been removed:
+      if(count != m_listAppInstances.size())
+      {
+        i = m_listAppInstances.begin(); //There should not be a problem with asking again.
+      }
+    }
+  }
+}
+
+void AppInstanceManager::cancel_close_all()
+{
+  m_bExiting = false;
+}
+
+unsigned int AppInstanceManager::get_app_count() const
+{
+  return m_listAppInstances.size();
+}
+
+AppInstanceManager::type_listAppInstances AppInstanceManager::get_instances() const
+{
+  return m_listAppInstances;
+}
+
+
+
+} //namespace

Added: trunk/glom/bakery/AppInstanceManager.h
==============================================================================
--- (empty file)
+++ trunk/glom/bakery/AppInstanceManager.h	Fri Mar 20 10:12:11 2009
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2002 Murray Cumming
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef GLOM_BAKERY_APPINSTANCEMANAGER_H
+#define GLOM_BAKERY_APPINSTANCEMANAGER_H
+
+#include <sigc++/sigc++.h>
+#include <list>
+
+namespace GlomBakery
+{
+
+class App;
+
+/** Contains a list of App instances.
+ * Each App registers itself with the one AppInstanceManager,
+ * and the AppInstanceManager will then delete the App when
+ * it has been closed, by catching the "hide" signal.
+ * You should not need to use this class directly.
+ */
+class AppInstanceManager : public sigc::trackable
+{
+public:
+  AppInstanceManager();
+  virtual ~AppInstanceManager();
+
+  virtual void add_app(App* pApp);
+  virtual void close_all();
+  virtual void cancel_close_all();
+
+  virtual unsigned int get_app_count() const;
+
+  typedef std::list<App*> type_listAppInstances;
+  virtual type_listAppInstances get_instances() const; //Used by App_WithDoc to get associated Documents.
+
+protected:
+  //Signal handler:
+  virtual void on_app_hide(App* pApp);
+
+  //Instances:
+  type_listAppInstances m_listAppInstances;
+
+  bool m_bExiting;
+};
+
+} //namespace
+
+#endif //BAKERY_APPINSTANCEMANAGER_H



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]