Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame^] | 1 | /* 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 | |
| 25 | using namespace rfb; |
| 26 | using namespace rfb::win32; |
| 27 | |
| 28 | static LogWriter vlog("WMCopyRect"); |
| 29 | |
| 30 | // -=- WMHooks class |
| 31 | |
| 32 | rfb::win32::WMCopyRect::WMCopyRect() : clipper(0), fg_window(0) { |
| 33 | } |
| 34 | |
| 35 | rfb::win32::WMCopyRect::~WMCopyRect() { |
| 36 | if (clipper) delete clipper; |
| 37 | } |
| 38 | |
| 39 | bool |
| 40 | rfb::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 | |
| 70 | bool |
| 71 | rfb::win32::WMCopyRect::setClipRect(const Rect& r) { |
| 72 | clip_region = r; |
| 73 | if (clipper) clipper->set_clip_region(clip_region); |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | bool |
| 78 | rfb::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 | } |