Constantin Kaplinsky | 0a1eca1 | 2006-04-16 07:28:14 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 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 | |
Constantin Kaplinsky | 0a1eca1 | 2006-04-16 07:28:14 +0000 | [diff] [blame] | 32 | rfb::win32::WMCopyRect::WMCopyRect() : ut(0), fg_window(0) { |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | bool |
| 36 | rfb::win32::WMCopyRect::processEvent() { |
Constantin Kaplinsky | 0a1eca1 | 2006-04-16 07:28:14 +0000 | [diff] [blame] | 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)); |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 50 | } |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 51 | } |
Constantin Kaplinsky | 0a1eca1 | 2006-04-16 07:28:14 +0000 | [diff] [blame] | 52 | fg_window = window; |
| 53 | fg_window_rect = winrect; |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 54 | } else { |
| 55 | fg_window = 0; |
| 56 | } |
Constantin Kaplinsky | 0a1eca1 | 2006-04-16 07:28:14 +0000 | [diff] [blame] | 57 | } else { |
| 58 | fg_window = 0; |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 59 | } |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | bool |
Constantin Kaplinsky | 0a1eca1 | 2006-04-16 07:28:14 +0000 | [diff] [blame] | 64 | rfb::win32::WMCopyRect::setUpdateTracker(UpdateTracker* ut_) { |
| 65 | ut = ut_; |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 66 | return true; |
| 67 | } |