/[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 3364 - (hide annotations) (download)
Tue Nov 14 18:07:25 2017 UTC (6 years, 5 months ago) by schoenebeck
File size: 7376 byte(s)
* Added experimental support for upcoming GTK(MM)4
  (for now up to GTKMM 3.91.2 while still preserving backward compatibility
  down to GTKMM 2).
* Re-merged r2845 to compile now with and without Gtk "Stock ID" API
  (see also r3158).

1 schoenebeck 2893 /*
2 schoenebeck 3364 Copyright (c) 2016 - 2017 Christian Schoenebeck
3 schoenebeck 2893
4     This file is part of "gigedit" and released under the terms of the
5     GNU General Public License version 2.
6     */
7    
8 persson 3202 #include "global.h"
9 schoenebeck 2893 #include "ManagedWindow.h"
10     #include <typeinfo>
11 schoenebeck 3364 #ifdef GLIB_HEADER_FILE
12     # include GLIB_HEADER_FILE(glib.h)
13     #else
14     # include <glib.h>
15     #endif
16 schoenebeck 2893
17 schoenebeck 2894 ///////////////////////////////////////////////////////////////////////////
18     // class 'ManagedWindow'
19    
20 schoenebeck 2893 ManagedWindow::ManagedWindow() : m_listenOnConfigureEvents(false)
21     {
22 schoenebeck 2918 if (!Settings::singleton()->autoRestoreWindowDimension)
23     return;
24    
25 schoenebeck 2893 Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
26     sigc::mem_fun(*this, &ManagedWindow::restoreWindowDimensions),
27     0
28     );
29     //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
30     Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
31     sigc::mem_fun(*this, &ManagedWindow::enableListeningConfigureEvents),
32     300
33     );
34     }
35    
36 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
37     bool ManagedWindow::on_configure_event(Gdk::EventConfigure& event) {
38     GdkEventConfigure* e = event.gobj();
39     #else
40 schoenebeck 2893 bool ManagedWindow::on_configure_event(GdkEventConfigure* e) {
41 schoenebeck 3364 #endif
42 schoenebeck 2893 //printf("on_configure_event x=%d y=%d w=%d h=%d\n", e->x, e->y, e->width, e->height);
43     if (m_listenOnConfigureEvents) {
44     //printf("reset event throttle timer\n");
45     // invalidate timer (so it won't fire)
46     if (m_eventThrottleTimer) m_eventThrottleTimer->destroy();
47     // restart timer
48     m_eventThrottleTimer = Glib::TimeoutSource::create(300);
49     m_eventThrottleTimer->connect(
50     sigc::bind(
51     sigc::bind(
52     sigc::bind(
53     sigc::bind(
54     sigc::mem_fun(*this, &ManagedWindow::saveWindowDimensions),
55     e->height
56     ),
57     e->width
58     ),
59     e->y
60     ),
61     e->x
62     )
63     );
64     m_eventThrottleTimer->attach(Glib::MainContext::get_default());
65     }
66 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
67     return Gtk::Window::on_configure_event(event);
68     #else
69 schoenebeck 2893 return Gtk::Window::on_configure_event(e);
70 schoenebeck 3364 #endif
71 schoenebeck 2893 }
72    
73     bool ManagedWindow::saveWindowDimensions(int x, int y, int w, int h) {
74     printf("saveWindowDimensions(%d,%d,%d,%d)\n",x,y,w,h);
75     if (*windowSettingX() != x) *windowSettingX() = x;
76     if (*windowSettingY() != y) *windowSettingY() = y;
77     if (*windowSettingWidth() != w) *windowSettingWidth() = w;
78     if (*windowSettingHeight() != h) *windowSettingHeight() = h;
79     return false; // kill timeout which called this method
80     }
81    
82     void ManagedWindow::restoreWindowDimensions() {
83     int x = *windowSettingX();
84     int y = *windowSettingY();
85     int w = *windowSettingWidth();
86     int h = *windowSettingHeight();
87     printf("restoreWindowDimensions(%d,%d,%d,%d)\n",x,y,w,h);
88     if (x >= 0 && y >= 0) move(x, y);
89 schoenebeck 2894 if (w > 0 && h > 0) resize(w, h);
90 schoenebeck 2893 }
91 schoenebeck 2894
92     ///////////////////////////////////////////////////////////////////////////
93     // class 'ManagedDialog'
94    
95     ManagedDialog::ManagedDialog()
96     : Gtk::Dialog(), m_listenOnConfigureEvents(false)
97     {
98     initManagedDialog();
99     }
100    
101     ManagedDialog::ManagedDialog(const Glib::ustring& title, bool modal)
102     : Gtk::Dialog(title, modal), m_listenOnConfigureEvents(false)
103     {
104     initManagedDialog();
105     }
106    
107     ManagedDialog::ManagedDialog(const Glib::ustring& title, Gtk::Window& parent, bool modal)
108     : Gtk::Dialog(title, parent, modal), m_listenOnConfigureEvents(false)
109     {
110     initManagedDialog();
111     }
112    
113     // ManagedDialog::ManagedDialog(const Glib::ustring& title, Gtk::DialogFlags flags)
114     // : Gtk::Dialog(title, flags), m_listenOnConfigureEvents(false)
115     // {
116     // initManagedDialog();
117     // }
118    
119     void ManagedDialog::initManagedDialog() {
120 schoenebeck 2918 if (!Settings::singleton()->autoRestoreWindowDimension)
121     return;
122    
123 schoenebeck 2894 Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
124     sigc::mem_fun(*this, &ManagedDialog::restoreWindowDimensions),
125     0
126     );
127     //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
128     Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ...
129     sigc::mem_fun(*this, &ManagedDialog::enableListeningConfigureEvents),
130     300
131     );
132     }
133    
134 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
135     bool ManagedDialog::on_configure_event(Gdk::EventConfigure& event) {
136     GdkEventConfigure* e = event.gobj();
137     #else
138 schoenebeck 2894 bool ManagedDialog::on_configure_event(GdkEventConfigure* e) {
139 schoenebeck 3364 #endif
140 schoenebeck 2894 //printf("on_configure_event x=%d y=%d w=%d h=%d\n", e->x, e->y, e->width, e->height);
141     if (m_listenOnConfigureEvents) {
142     //printf("reset event throttle timer\n");
143     // invalidate timer (so it won't fire)
144     if (m_eventThrottleTimer) m_eventThrottleTimer->destroy();
145     // restart timer
146     m_eventThrottleTimer = Glib::TimeoutSource::create(300);
147     m_eventThrottleTimer->connect(
148     sigc::bind(
149     sigc::bind(
150     sigc::bind(
151     sigc::bind(
152     sigc::mem_fun(*this, &ManagedDialog::saveWindowDimensions),
153     e->height
154     ),
155     e->width
156     ),
157     e->y
158     ),
159     e->x
160     )
161     );
162     m_eventThrottleTimer->attach(Glib::MainContext::get_default());
163     }
164 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
165     return Gtk::Dialog::on_configure_event(event);
166     #else
167 schoenebeck 2918 return Gtk::Dialog::on_configure_event(e);
168 schoenebeck 3364 #endif
169 schoenebeck 2894 }
170    
171     bool ManagedDialog::saveWindowDimensions(int x, int y, int w, int h) {
172     printf("saveDialogDimensions(%d,%d,%d,%d)\n",x,y,w,h);
173     if (*windowSettingX() != x) *windowSettingX() = x;
174     if (*windowSettingY() != y) *windowSettingY() = y;
175     if (*windowSettingWidth() != w) *windowSettingWidth() = w;
176     if (*windowSettingHeight() != h) *windowSettingHeight() = h;
177     return false; // kill timeout which called this method
178     }
179    
180     void ManagedDialog::restoreWindowDimensions() {
181     int x = *windowSettingX();
182     int y = *windowSettingY();
183     int w = *windowSettingWidth();
184     int h = *windowSettingHeight();
185     printf("restoreDialogDimensions(%d,%d,%d,%d)\n",x,y,w,h);
186     if (x >= 0 && y >= 0) move(x, y);
187     if (w > 0 && h >= 0) resize(w, h);
188     }

  ViewVC Help
Powered by ViewVC