10 |
#include <glib.h> |
#include <glib.h> |
11 |
#include "global.h" |
#include "global.h" |
12 |
|
|
13 |
|
/////////////////////////////////////////////////////////////////////////// |
14 |
|
// class 'ManagedWindow' |
15 |
|
|
16 |
ManagedWindow::ManagedWindow() : m_listenOnConfigureEvents(false) |
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 ... |
Glib::signal_idle().connect_once( // timeout starts given amount of ms after the main loop became idle again ... |
70 |
int h = *windowSettingHeight(); |
int h = *windowSettingHeight(); |
71 |
printf("restoreWindowDimensions(%d,%d,%d,%d)\n",x,y,w,h); |
printf("restoreWindowDimensions(%d,%d,%d,%d)\n",x,y,w,h); |
72 |
if (x >= 0 && y >= 0) move(x, y); |
if (x >= 0 && y >= 0) move(x, y); |
73 |
if (w >= 0 && h >= 0) resize(w, h); |
if (w > 0 && h > 0) resize(w, h); |
74 |
|
} |
75 |
|
|
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 |
} |
} |