Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 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() : ut(0), fg_window(0) { |
| 33 | } |
| 34 | |
| 35 | bool |
| 36 | rfb::win32::WMCopyRect::processEvent() { |
| 37 | // See if the foreground window has moved |
| 38 | HWND window = GetForegroundWindow(); |
| 39 | if (window) { |
| 40 | RECT wrect; |
| 41 | if (IsWindow(window) && IsWindowVisible(window) && GetWindowRect(window, &wrect)) { |
| 42 | Rect winrect(wrect.left, wrect.top, wrect.right, wrect.bottom); |
| 43 | if (fg_window == window) { |
| 44 | if (!fg_window_rect.tl.equals(winrect.tl) && ut) { |
| 45 | // Window has moved - send a copyrect event to the client |
| 46 | Point delta = Point(winrect.tl.x-fg_window_rect.tl.x, winrect.tl.y-fg_window_rect.tl.y); |
| 47 | Region copy_dest = winrect; |
| 48 | ut->add_copied(copy_dest, delta); |
| 49 | ut->add_changed(Region(fg_window_rect).subtract(copy_dest)); |
| 50 | } |
| 51 | } |
| 52 | fg_window = window; |
| 53 | fg_window_rect = winrect; |
| 54 | } else { |
| 55 | fg_window = 0; |
| 56 | } |
| 57 | } else { |
| 58 | fg_window = 0; |
| 59 | } |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | bool |
| 64 | rfb::win32::WMCopyRect::setUpdateTracker(UpdateTracker* ut_) { |
| 65 | ut = ut_; |
| 66 | return true; |
| 67 | } |