[gnote] Adjust window size according to child



commit d45df63c972f26b40b1251392176d2c465ec0144
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Tue Sep 25 22:21:52 2012 +0300

    Adjust window size according to child

 src/note.cpp              |   36 +++---------------------------------
 src/note.hpp              |    1 -
 src/notewindow.cpp        |   28 +++++++++++++++++++++++-----
 src/notewindow.hpp        |    9 ++++++++-
 src/searchnoteswidget.cpp |    3 +++
 5 files changed, 37 insertions(+), 40 deletions(-)
---
diff --git a/src/note.cpp b/src/note.cpp
index 1630343..d8bdc62 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -468,33 +468,6 @@ namespace gnote {
   }
 
 
-  bool Note::on_window_configure(GdkEventConfigure * /*ev*/)
-  {
-#if 0
-    int cur_x, cur_y, cur_width, cur_height;
-
-    // Ignore events when maximized.  We don't want notes
-    // popping up maximized the next run.
-    if ((m_window->get_window()->get_state() & Gdk::WINDOW_STATE_MAXIMIZED) != 0)
-      return false;
-
-    m_window->get_position(cur_x, cur_y);
-    m_window->get_size(cur_width, cur_height);
-
-    if (m_data.data().x() == cur_x &&
-        m_data.data().y() == cur_y &&
-        m_data.data().width() == cur_width &&
-        m_data.data().height() == cur_height)
-      return false;
-
-    m_data.data().set_position_extent(cur_x, cur_y, cur_width, cur_height);
-
-    DBG_OUT("WindowConfigureEvent queueing save");
-    queue_save(NO_CHANGE);
-#endif
-    return false;
-  }
-
   bool Note::on_window_destroyed(GdkEventAny * /*ev*/)
   {
     m_window = NULL;
@@ -1031,15 +1004,12 @@ namespace gnote {
       m_window = new NoteWindow(*this);
       m_window->signal_delete_event().connect(
         sigc::mem_fun(*this, &Note::on_window_destroyed));
-      m_window->signal_configure_event().connect(
-        sigc::mem_fun(*this, &Note::on_window_configure), false);
 
       m_window->editor()->set_sensitive(enabled());
+      if(m_data.data().has_extent()) {
+        m_window->set_size(m_data.data().width(), m_data.data().height());
+      }
 #if 0
-      if (m_data.data().has_extent())
-        m_window->set_default_size(m_data.data().width(),
-                                   m_data.data().height());
-
       if (m_data.data().has_position())
         m_window->move(m_data.data().x(), m_data.data().y());
 #endif
diff --git a/src/note.hpp b/src/note.hpp
index 00a4a4c..c0ac867 100644
--- a/src/note.hpp
+++ b/src/note.hpp
@@ -376,7 +376,6 @@ private:
                              const Gtk::TextBuffer::iterator &);
   void on_buffer_mark_set(const Gtk::TextBuffer::iterator & iter,
                           const Glib::RefPtr<Gtk::TextBuffer::Mark> & insert);
-  bool on_window_configure(GdkEventConfigure *ev);
   bool on_window_destroyed(GdkEventAny *ev);
   void on_save_timeout();
   void process_child_widget_queue();
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 368a0f7..93407f9 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -55,6 +55,8 @@ namespace gnote {
     : Gtk::VBox(false, 2)
     , m_note(note)
     , m_name(note.get_title())
+    , m_height(360)
+    , m_width(450)
     , m_global_keys(NULL)
   {
     m_template_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
@@ -62,11 +64,6 @@ namespace gnote {
     m_template_save_selection_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG);
     m_template_save_title_tag = TagManager::obj().get_or_create_system_tag(TagManager::TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG);
 
-#if 0
-    set_default_size(450, 360);
-    set_resizable(true);
-#endif
-
     m_text_menu = Gtk::manage(new NoteTextMenu(note.get_buffer(), note.get_buffer()->undoer()));
 
     // Add the Find menu item to the toolbar Text menu.  It
@@ -152,6 +149,11 @@ namespace gnote {
     }
 
     utils::EmbedableWidget::foreground();
+    parent->set_default_size(m_width, m_height);
+    if((parent->get_window()->get_state() & Gdk::WINDOW_STATE_MAXIMIZED) == 0 && parent->get_visible()) {
+      parent->get_window()->resize(m_width, m_height);
+    }
+    parent->set_focus(*m_editor);
     m_editor->scroll_to(m_editor->get_buffer()->get_insert());
   }
 
@@ -163,6 +165,22 @@ namespace gnote {
       return;
     }
     remove_accel_group(*parent);
+    if((parent->get_window()->get_state() & Gdk::WINDOW_STATE_MAXIMIZED) == 0) {
+      int cur_x, cur_y, cur_width, cur_height;
+      parent->get_position(cur_x, cur_y);
+      parent->get_size(cur_width, cur_height);
+
+      if(!(m_note.data().x() == cur_x && m_note.data().y() == cur_y
+           && m_note.data().width() == cur_width
+           && m_note.data().height() == cur_height)) {
+        m_note.data().set_position_extent(cur_x, cur_y, cur_width, cur_height);
+        m_width = cur_width;
+        m_height = cur_height;
+
+        DBG_OUT("WindowConfigureEvent queueing save");
+        m_note.queue_save(NO_CHANGE);
+      }
+    }
   }
 
   void NoteWindow::add_accel_group(Gtk::Window & window)
diff --git a/src/notewindow.hpp b/src/notewindow.hpp
index 0e1d110..821335c 100644
--- a/src/notewindow.hpp
+++ b/src/notewindow.hpp
@@ -114,6 +114,11 @@ public:
   virtual void foreground();
   virtual void background();
 
+  void set_size(int width, int height)
+    {
+      m_width = width;
+      m_height = height;
+    }
   Gtk::TextView * editor() const
     {
       return m_editor;
@@ -171,7 +176,9 @@ private:
   void remove_accel_group(Gtk::Window &);
 
   Note                        & m_note;
-  std::string                  m_name;
+  std::string                   m_name;
+  int                           m_height;
+  int                           m_width;
   Glib::RefPtr<Gtk::AccelGroup> m_accel_group;
   Gtk::Toolbar                 *m_toolbar;
   Gtk::ToolButton              *m_link_button;
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index 6321b8c..6e4bd23 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -405,6 +405,9 @@ void SearchNotesWidget::restore_position()
   }
 
   window->set_default_size(width, height);
+  if(window->get_visible()) {
+    window->get_window()->resize(width, height);
+  }
   if(!m_initial_position_restored) {
     window->move(x, y);
     m_initial_position_restored = true;



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