/[svn]/gigedit/trunk/src/gigedit/ManagedWindow.cpp
ViewVC logotype

Annotation of /gigedit/trunk/src/gigedit/ManagedWindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2894 - (hide annotations) (download)
Sat Apr 30 14:42:14 2016 UTC (7 years, 11 months ago) by schoenebeck
File size: 6104 byte(s)
* Enabled auto save & restore of window size & position of all
  remaining windows.
* Bumped version (1.0.0.svn7).

1 schoenebeck 2893 /*
2     Copyright (c) 2016 Christian Schoenebeck
3    
4     This file is part of "gigedit" and released under the terms of the
5     GNU General Public License version 2.
6     */
7    
8     #include "ManagedWindow.h"
9     #include <typeinfo>
10     #include <glib.h>
11     #include "global.h"
12    
13 schoenebeck 2894 ///////////////////////////////////////////////////////////////////////////
14     // class 'ManagedWindow'
15    
16 schoenebeck 2893 ManagedWindow::ManagedWindow() : m_listenOnConfigureEvents(false)
17     {
18     Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
19     sigc::mem_fun(*this, &ManagedWindow::restoreWindowDimensions),
20     0
21     );
22     //HACK: Gtk does not support to distinguish between user caused window resize/move and programmtical window resize/move, so as a workaround we ignore such events for a certain amount of time while this window is constructing
23     Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
24     sigc::mem_fun(*this, &ManagedWindow::enableListeningConfigureEvents),
25     300
26     );
27     }
28    
29     bool ManagedWindow::on_configure_event(GdkEventConfigure* e) {
30     //printf("on_configure_event x=%d y=%d w=%d h=%d\n", e->x, e->y, e->width, e->height);
31     if (m_listenOnConfigureEvents) {
32     //printf("reset event throttle timer\n");
33     // invalidate timer (so it won't fire)
34     if (m_eventThrottleTimer) m_eventThrottleTimer->destroy();
35     // restart timer
36     m_eventThrottleTimer = Glib::TimeoutSource::create(300);
37     m_eventThrottleTimer->connect(
38     sigc::bind(
39     sigc::bind(
40     sigc::bind(
41     sigc::bind(
42     sigc::mem_fun(*this, &ManagedWindow::saveWindowDimensions),
43     e->height
44     ),
45     e->width
46     ),
47     e->y
48     ),
49     e->x
50     )
51     );
52     m_eventThrottleTimer->attach(Glib::MainContext::get_default());
53     }
54     return Gtk::Window::on_configure_event(e);
55     }
56    
57     bool ManagedWindow::saveWindowDimensions(int x, int y, int w, int h) {
58     printf("saveWindowDimensions(%d,%d,%d,%d)\n",x,y,w,h);
59     if (*windowSettingX() != x) *windowSettingX() = x;
60     if (*windowSettingY() != y) *windowSettingY() = y;
61     if (*windowSettingWidth() != w) *windowSettingWidth() = w;
62     if (*windowSettingHeight() != h) *windowSettingHeight() = h;
63     return false; // kill timeout which called this method
64     }
65    
66     void ManagedWindow::restoreWindowDimensions() {
67     int x = *windowSettingX();
68     int y = *windowSettingY();
69     int w = *windowSettingWidth();
70     int h = *windowSettingHeight();
71     printf("restoreWindowDimensions(%d,%d,%d,%d)\n",x,y,w,h);
72     if (x >= 0 && y >= 0) move(x, y);
73 schoenebeck 2894 if (w > 0 && h > 0) resize(w, h);
74 schoenebeck 2893 }
75 schoenebeck 2894
76     ///////////////////////////////////////////////////////////////////////////
77     // class 'ManagedDialog'
78    
79     ManagedDialog::ManagedDialog()
80     : Gtk::Dialog(), m_listenOnConfigureEvents(false)
81     {
82     initManagedDialog();
83     }
84    
85     ManagedDialog::ManagedDialog(const Glib::ustring& title, bool modal)
86     : Gtk::Dialog(title, modal), m_listenOnConfigureEvents(false)
87     {
88     initManagedDialog();
89     }
90    
91     ManagedDialog::ManagedDialog(const Glib::ustring& title, Gtk::Window& parent, bool modal)
92     : Gtk::Dialog(title, parent, modal), m_listenOnConfigureEvents(false)
93     {
94     initManagedDialog();
95     }
96    
97     // ManagedDialog::ManagedDialog(const Glib::ustring& title, Gtk::DialogFlags flags)
98     // : Gtk::Dialog(title, flags), m_listenOnConfigureEvents(false)
99     // {
100     // initManagedDialog();
101     // }
102    
103     void ManagedDialog::initManagedDialog() {
104     Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
105     sigc::mem_fun(*this, &ManagedDialog::restoreWindowDimensions),
106     0
107     );
108     //HACK: Gtk does not support to distinguish between user caused window resize/move and programmtical window resize/move, so as a workaround we ignore such events for a certain amount of time while this window is constructing
109     Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
110     sigc::mem_fun(*this, &ManagedDialog::enableListeningConfigureEvents),
111     300
112     );
113     }
114    
115     bool ManagedDialog::on_configure_event(GdkEventConfigure* e) {
116     //printf("on_configure_event x=%d y=%d w=%d h=%d\n", e->x, e->y, e->width, e->height);
117     if (m_listenOnConfigureEvents) {
118     //printf("reset event throttle timer\n");
119     // invalidate timer (so it won't fire)
120     if (m_eventThrottleTimer) m_eventThrottleTimer->destroy();
121     // restart timer
122     m_eventThrottleTimer = Glib::TimeoutSource::create(300);
123     m_eventThrottleTimer->connect(
124     sigc::bind(
125     sigc::bind(
126     sigc::bind(
127     sigc::bind(
128     sigc::mem_fun(*this, &ManagedDialog::saveWindowDimensions),
129     e->height
130     ),
131     e->width
132     ),
133     e->y
134     ),
135     e->x
136     )
137     );
138     m_eventThrottleTimer->attach(Glib::MainContext::get_default());
139     }
140     return Gtk::Window::on_configure_event(e);
141     }
142    
143     bool ManagedDialog::saveWindowDimensions(int x, int y, int w, int h) {
144     printf("saveDialogDimensions(%d,%d,%d,%d)\n",x,y,w,h);
145     if (*windowSettingX() != x) *windowSettingX() = x;
146     if (*windowSettingY() != y) *windowSettingY() = y;
147     if (*windowSettingWidth() != w) *windowSettingWidth() = w;
148     if (*windowSettingHeight() != h) *windowSettingHeight() = h;
149     return false; // kill timeout which called this method
150     }
151    
152     void ManagedDialog::restoreWindowDimensions() {
153     int x = *windowSettingX();
154     int y = *windowSettingY();
155     int w = *windowSettingWidth();
156     int h = *windowSettingHeight();
157     printf("restoreDialogDimensions(%d,%d,%d,%d)\n",x,y,w,h);
158     if (x >= 0 && y >= 0) move(x, y);
159     if (w > 0 && h >= 0) resize(w, h);
160     }

  ViewVC Help
Powered by ViewVC