1
/*********************************************************
2
* Copyright (C) 2009 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License as published
6
* by the Free Software Foundation version 2.1 and no later version.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
11
* License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
*********************************************************/
20
* @file dragDetWnd.cpp
22
* Detection window code for Linux/X11, based on Gtkmm. Includes unit test
26
#include "dragDetWnd.h"
45
DragDetWnd::DragDetWnd() :
48
#if defined(DETWNDDEBUG)
59
DragDetWnd::~DragDetWnd()
65
* Flush the X connection.
71
Glib::RefPtr<Gdk::Display> gdkdisplay = Gdk::Display::get_default();
85
DragDetWnd::Show(void)
98
DragDetWnd::Hide(void)
111
DragDetWnd::Raise(void)
113
Glib::RefPtr<Gdk::Window> gdkwin = get_window();
127
DragDetWnd::Lower(void)
129
Glib::RefPtr<Gdk::Window> gdkwin = get_window();
139
* Get the width of the screen associated with this window.
141
* @return width of screen, in pixels.
145
DragDetWnd::GetScreenWidth(void)
147
Glib::RefPtr<Gdk::Screen> gdkscreen = get_screen();
148
return gdkscreen->get_width();
154
* Get the height of the screen associated with this window.
156
* @return height of screen, in pixels.
160
DragDetWnd::GetScreenHeight(void)
162
Glib::RefPtr<Gdk::Screen> gdkscreen = get_screen();
163
return gdkscreen->get_height();
167
#if defined(DETWNDDEBUG)
170
* Set default window attributes appropriate for debugging detection windows.
172
* @note This only applies to instances of DragDetWnd that are derived from
177
DragDetWnd::DebugSetAttributes(void)
179
set_default_size(1, 1);
181
set_decorated(false);
182
set_type_hint(Gdk::WINDOW_TYPE_HINT_DOCK);
189
* Set the geometry of the window.
191
* @param[in] x desired x-coordinate of the window.
192
* @param[in] y desired y-coordinate of the window.
193
* @param[in] width desired width of the window.
194
* @param[in] height desired height of the window.
198
DragDetWnd::SetGeometry(const int x,
203
Glib::RefPtr<Gdk::Window> gdkwin = get_window();
206
gdkwin->move_resize(x, y, width, height);
214
* Get the current geometry of the window.
216
* @param[out] x current x-coordinate of the window.
217
* @param[out] y current y-coordinate of the window.
218
* @param[out] width current width of the window.
219
* @param[out] height current height of the window.
221
* @note The current geometry may be inaccurate if retrieved too quickly
222
* after a change made by SetGeometry(). This is due to the realities of
223
* X and window managers. Some of this is mitigated by the use of flush()
224
* and sync() calls in SetGeometry(), but these are no guarantee.
228
DragDetWnd::GetGeometry(int &x, int &y, int &width, int &height)
232
Glib::RefPtr<Gdk::Window> gdkwin = get_window();
234
gdkwin->get_geometry(x, y, width, height, dummy);
235
#if defined(DETWNDTEST)
242
* Code below here is for unit tests.
245
#if defined(DETWNDTEST)
249
* Add a button to launch unit tests to the drag detection window.
253
DragDetWndTest::CreateTestUI()
255
m_button.set_label("Start Unit Tests");
257
m_button.signal_clicked().connect(sigc::mem_fun(*this, &DragDetWndTest::RunUnitTests));
264
* Run some unit tests, then exit. Requires a main program, refer to
265
* bora-vmsoft/toolbox/linux/vmwareuser/detWndTest/main.cpp for an
270
DragDetWndTest::RunUnitTests()
276
#if defined(DETWNDDEBUG)
277
testWnd.SetAttributes();
280
int x, y, width, height;
281
testWnd.GetGeometry(x, y, width, height);
282
printf("Geometry is x %d y %d width %d height %d\n", x, y, width, height);
284
for (int i = 10; i < 50; Gtk::Main::iteration(), i++) {
286
printf("Setting geometry to x %d y %d w %d h %d\n", i * 10, i * 10, i * 10, i * 10);
287
testWnd.SetGeometry(i * 10, i * 10, i * 10, i * 10);
289
testWnd.GetGeometry(x, y, width, height);
290
printf("Geometry is x %d y %d width %d height %d\n", x, y, width, height);
291
if (x != i * 10 || y != i * 10 || width != i * 10) {
292
printf("FAIL x or y not correct\n");
297
for (int i = 49; i > 0; Gtk::Main::iteration(), i--) {
299
printf("Setting geometry to x %d y %d w %d h %d\n", i * 10, i * 10, i * 10, i * 10);
300
testWnd.SetGeometry(i * 10, i * 10, i * 10, i * 10);
302
testWnd.GetGeometry(x, y, width, height);
303
printf("Geometry is x %d y %d width %d height %d\n", x, y, width, height);
304
if (x != i * 10 || y != i * 10 || width != i * 10) {
305
printf("FAIL width or height not correct\n");
310
testWnd.SetGeometry(500, 500, 300, 300);
312
for (int i = 0; i < 60; Gtk::Main::iteration(), i++) {
324
printf("Done fail count %d (%.2f%%)\n", failCount, 100.0 * failCount/testCount);