blob: 46d85eac08dd7ae27d29bed4653aa60bcc7c1924 [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// -=- WMCopyRect.cxx
20
21#include <rfb_win32/WMWindowCopyRect.h>
22#include <rfb/LogWriter.h>
23#include <windows.h>
24
25using namespace rfb;
26using namespace rfb::win32;
27
28static LogWriter vlog("WMCopyRect");
29
30// -=- WMHooks class
31
32rfb::win32::WMCopyRect::WMCopyRect() : clipper(0), fg_window(0) {
33}
34
35rfb::win32::WMCopyRect::~WMCopyRect() {
36 if (clipper) delete clipper;
37}
38
39bool
40rfb::win32::WMCopyRect::processEvent() {
41 if (clipper) {
42 // See if the foreground window has moved
43 HWND window = GetForegroundWindow();
44 if (window) {
45 RECT wrect;
46 if (IsWindow(window) && IsWindowVisible(window) && GetWindowRect(window, &wrect)) {
47 Rect winrect(wrect.left, wrect.top, wrect.right, wrect.bottom);
48 if (fg_window == window) {
49
50 if (!fg_window_rect.tl.equals(winrect.tl)) {
51 // Window has moved - send a copyrect event to the client
52 Point delta = Point(winrect.tl.x-fg_window_rect.tl.x, winrect.tl.y-fg_window_rect.tl.y);
53 Region copy_dest = winrect;
54 clipper->add_copied(copy_dest, delta);
55 clipper->add_changed(Region(fg_window_rect).subtract(copy_dest));
56 }
57 }
58 fg_window = window;
59 fg_window_rect = winrect;
60 } else {
61 fg_window = 0;
62 }
63 } else {
64 fg_window = 0;
65 }
66 }
67 return false;
68}
69
70bool
71rfb::win32::WMCopyRect::setClipRect(const Rect& r) {
72 clip_region = r;
73 if (clipper) clipper->set_clip_region(clip_region);
74 return true;
75}
76
77bool
78rfb::win32::WMCopyRect::setUpdateTracker(UpdateTracker* ut) {
79 if (clipper) delete clipper;
80 clipper = new ClippedUpdateTracker(*ut);
81 clipper->set_clip_region(clip_region);
82 return true;
83}