sbNativeWindowManager.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 
33 #include "sbNativeWindowManager.h"
34 #include "../NativeWindowFromNode.h"
35 
36 #include <windows.h>
37 #include <dwmapi.h>
38 
40 
41 typedef HRESULT (STDAPICALLTYPE* DwmSetWindowAttributeProc_t)(HWND,
42  DWORD,
43  LPCVOID,
44  DWORD);
45 
46 typedef HRESULT (STDAPICALLTYPE* DwmExtendFrameIntoClientArea_t)(HWND,
47  const MARGINS *);
48 
49 NS_IMETHODIMP sbNativeWindowManager::BeginResizeDrag(nsISupports *aWindow, nsIDOMMouseEvent* aEvent, PRInt32 aDirection)
50 {
51  return NS_ERROR_NOT_IMPLEMENTED;
52 }
53 
54 
55 NS_IMETHODIMP sbNativeWindowManager::GetSupportsResizeDrag(PRBool *aSupportsResizeDrag)
56 {
57  NS_ENSURE_ARG_POINTER(aSupportsResizeDrag);
58  *aSupportsResizeDrag = PR_FALSE;
59  return NS_OK;
60 }
61 
62 
63 NS_IMETHODIMP sbNativeWindowManager::SetMinimumWindowSize(nsISupports *aWindow, PRInt32 aMinimumWidth, PRInt32 aMinimumHeight)
64 {
65  return NS_ERROR_NOT_IMPLEMENTED;
66 }
67 
68 
69 NS_IMETHODIMP sbNativeWindowManager::SetMaximumWindowSize(nsISupports *aWindow, PRInt32 aMaximumWidth, PRInt32 aMaximumHeight)
70 {
71  return NS_ERROR_NOT_IMPLEMENTED;
72 }
73 
74 
75 NS_IMETHODIMP sbNativeWindowManager::GetSupportsMinimumWindowSize(PRBool *aSupportsMinimumWindowSize)
76 {
77  NS_ENSURE_ARG_POINTER(aSupportsMinimumWindowSize);
78  *aSupportsMinimumWindowSize = PR_FALSE;
79  return NS_OK;
80 }
81 
82 
83 NS_IMETHODIMP sbNativeWindowManager::GetSupportsMaximumWindowSize(PRBool *aSupportsMaximumWindowSize)
84 {
85  NS_ENSURE_ARG_POINTER(aSupportsMaximumWindowSize);
86  *aSupportsMaximumWindowSize = PR_FALSE;
87  return NS_OK;
88 }
89 
90 
91 NS_IMETHODIMP sbNativeWindowManager::SetOnTop(nsISupports *aWindow, PRBool aOnTop)
92 {
93  NS_ENSURE_ARG_POINTER(aWindow);
94 
95  HWND window = NativeWindowFromNode::get(aWindow);
96  SetWindowPos(window, aOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0,
97  SWP_NOSIZE | SWP_NOMOVE);
98 
99  return NS_OK;
100 }
101 
102 NS_IMETHODIMP sbNativeWindowManager::SetShadowing(nsISupports *aWindow, PRBool aShadowing)
103 {
104  NS_ENSURE_ARG_POINTER(aWindow);
105 
106  HWND window = NativeWindowFromNode::get(aWindow);
107  HMODULE hDll = LoadLibraryW(L"dwmapi");
108 
109  // failure is not an error.
110  if(!hDll) {
111  return NS_OK;
112  }
113 
114  DwmSetWindowAttributeProc_t setWindowAttribute =
115  (DwmSetWindowAttributeProc_t) GetProcAddress(hDll, "DwmSetWindowAttribute");
116 
117  DwmExtendFrameIntoClientArea_t extendFrameIntoClientArea =
118  (DwmExtendFrameIntoClientArea_t) GetProcAddress(hDll, "DwmExtendFrameIntoClientArea");
119 
120  if(!setWindowAttribute || !extendFrameIntoClientArea) {
121  return NS_ERROR_UNEXPECTED;
122  }
123 
124  DWMNCRENDERINGPOLICY ncrp = aShadowing ? DWMNCRP_ENABLED : DWMNCRP_DISABLED;
125 
126  // enable non-client area rendering on window
127  HRESULT hr = setWindowAttribute(window, DWMWA_NCRENDERING_POLICY, &ncrp, sizeof(ncrp));
128  NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_UNEXPECTED);
129 
130  //set margins
131  MARGINS margins = {1, 0, 0, 0};
132 
133  //extend frame
134  hr = extendFrameIntoClientArea(window, &margins);
135  NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_UNEXPECTED);
136 
137  FreeLibrary(hDll);
138 
139  return NS_OK;
140 }
141 
142 NS_IMETHODIMP sbNativeWindowManager::GetSupportsOnTop(PRBool *aSupportsOnTop)
143 {
144  NS_ENSURE_ARG_POINTER(aSupportsOnTop);
145 
146  *aSupportsOnTop = PR_TRUE;
147 
148  return NS_OK;
149 }
150 
151 NS_IMETHODIMP sbNativeWindowManager::GetSupportsShadowing(PRBool *aSupportsShadowing)
152 {
153  NS_ENSURE_ARG_POINTER(aSupportsShadowing);
154 
155  *aSupportsShadowing = PR_TRUE;
156 
157  return NS_OK;
158 }
return NS_OK
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
HRESULT(STDAPICALLTYPE * DwmExtendFrameIntoClientArea_t)(HWND, const MARGINS *)
interface to the operating system's window manager This Interfaces to allows JavaScript to talk to th...
let window
static void * get(nsISupports *window)
HRESULT(STDAPICALLTYPE * DwmSetWindowAttributeProc_t)(HWND, DWORD, LPCVOID, DWORD)