WindowResizeHook.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25  */
26 
32  // Yet another shameful hack from lone
33 #include "WindowResizeHook.h"
34 
35 // CLASSES ====================================================================
36 //=============================================================================
37 // CWindowResizeHook Class
38 //=============================================================================
39 
40 // This implements a callback into js so that script code may dynamically limit
41 // the position and size of a window
42 
43 //-----------------------------------------------------------------------------
44 /* Implementation file */
46 
47 //-----------------------------------------------------------------------------
49 {
50 #ifdef XP_WIN
51  m_hookid = SetWindowsHookEx(WH_CALLWNDPROCRET, ResizeHook, GetModuleHandle(NULL), GetCurrentThreadId());
52 #endif
53 } // ctor
54 
55 //-----------------------------------------------------------------------------
57 {
58 #ifdef XP_WIN
59  UnhookWindowsHookEx(m_hookid);
60  m_hookid = 0;
61 #endif
62 } // dtor
63 
64 //-----------------------------------------------------------------------------
65 NS_IMETHODIMP CWindowResizeHook::SetCallback(nsISupports *window, sbIWindowResizeHookCallback *cb)
66 {
68  if (wnd == NULL) return NS_ERROR_FAILURE;
69  if (findItemByCallback(cb)) return NS_ERROR_FAILURE;
70  NS_ADDREF(cb);
72  wrhi->m_callback = cb;
73  wrhi->m_window = wnd;
74  m_items.push_back(wrhi);
75  return NS_OK;
76 } // SetCallback
77 
78 //-----------------------------------------------------------------------------
79 NS_IMETHODIMP CWindowResizeHook::ResetCallback(sbIWindowResizeHookCallback *cb)
80 {
82  if (!wrhi) return NS_ERROR_FAILURE;
83  m_items.remove(wrhi);
84  delete wrhi;
85  NS_RELEASE(cb);
86  return NS_OK;
87 } // ResetCallback
88 
89 //-----------------------------------------------------------------------------
91 {
92  std::list<CWindowResizeHookItem*>::iterator iter;
93  for (iter = m_items.begin(); iter != m_items.end(); iter++)
94  {
95  CWindowResizeHookItem *wrhi= *iter;
96  if (wrhi->m_callback == cb) return wrhi;
97  }
98  return NULL;
99 } // findItemByInterface
100 
101 //-----------------------------------------------------------------------------
103 {
104  std::list<CWindowResizeHookItem*>::iterator iter;
105  for (iter = m_items.begin(); iter != m_items.end(); iter++)
106  {
107  CWindowResizeHookItem *wrhi= *iter;
108  if (wrhi->m_window == wnd) return wrhi;
109  }
110  return NULL;
111 } // findItemByInterface
112 
113 //-----------------------------------------------------------------------------
114 
115 std::list<CWindowResizeHookItem *> CWindowResizeHook::m_items;
116 #ifdef XP_WIN
117 HHOOK CWindowResizeHook::m_hookid = 0;
118 #endif
119 
120 #ifdef XP_WIN
121 //-----------------------------------------------------------------------------
122 LRESULT CALLBACK ResizeHook(int code, WPARAM wParam, LPARAM lParam)
123 {
124  static int inhere = 0;
125  if (code >= 0 && inhere == 0)
126  {
127  inhere = 1;
128  CWPRETSTRUCT *rs = (CWPRETSTRUCT *)lParam;
129  if (rs->message == WM_WINDOWPOSCHANGED)
130  {
132  if (wrhi)
133  {
134  RECT r;
135  GetWindowRect(rs->hwnd, &r);
136  wrhi->m_callback->OnResize(r.left, r.top, r.right-r.left, r.bottom-r.top);
137  }
138  }
139  inhere = 0;
140  }
141  return ::CallNextHookEx(CWindowResizeHook::m_hookid, code, wParam, lParam);
142 } // ResizeHook
143 #endif
static CWindowResizeHookItem * findItemByWindow(void *wnd)
return NS_OK
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
LRESULT CALLBACK ResizeHook(int code, WPARAM wParam, LPARAM lParam)
LONG left
Definition: MultiMonitor.h:48
static CWindowResizeHookItem * findItemByCallback(sbIWindowResizeHookCallback *cb)
LONG bottom
Definition: MultiMonitor.h:51
let window
virtual ~CWindowResizeHook()
sbIWindowResizeHookCallback * m_callback
static std::list< CWindowResizeHookItem * > m_items
LONG top
Definition: MultiMonitor.h:49
static void * get(nsISupports *window)
Service for setting min/max limit callbacks to a window position and size - Prototypes.
LONG right
Definition: MultiMonitor.h:50
#define NATIVEWINDOW
WindowResizeHook callback interface This interface describes a callback for the WindowResizeHook serv...
WindowResizeHook service interface This is an interface to the WindowResizeHook service, used to used to register callback notifications of window resizing events.