45 #include <nsComponentManagerUtils.h>
46 #include <nsServiceManagerUtils.h>
47 #include <nsStringGlue.h>
49 #include "sbIDeviceManager.h"
50 #include <sbIDeviceBase.h>
53 #if defined(SB_ENABLE_CD_DEVICE)
54 #include "sbICDDevice.h"
64 char FirstDriveFromMask (ULONG unitmask)
68 for (i = 0; i < 26; ++
i)
72 unitmask = unitmask >> 1;
79 static LRESULT CALLBACK WindowMinMaxSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
81 if (!IsWindow(hWnd))
return 0;
83 return _this->WndProc(hWnd, uMsg, wParam, lParam);
109 LRESULT CWindowMinMaxSubclass::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
120 if (HIWORD(lParam) == WM_LBUTTONDOWN)
128 case WM_GETMINMAXINFO:
130 MINMAXINFO* mi = (MINMAXINFO *) lParam;
138 mi->ptMaxSize.x = workArea.
right - workArea.
left;
139 mi->ptMaxSize.y = workArea.
bottom - workArea.
top;
140 mi->ptMaxPosition.x = workArea.
left - monitorArea.
left;
141 mi->ptMaxPosition.y = workArea.
top - monitorArea.
top;
145 case WM_WINDOWPOSCHANGING:
147 WINDOWPOS *wp = (WINDOWPOS*)lParam;
148 if (
m_callback && wp && !(wp->flags & SWP_NOSIZE))
152 GetWindowRect(hWnd, &r);
156 _r = r.
right != wp->x + wp->cx;
157 _b = r.
bottom != wp->y + wp->cy;
158 _l = r.
left != wp->x;
162 if (_r && _b && _l && _t)
break;
167 int _minwidth = -1, _minheight = -1, _maxwidth = -1, _maxheight = -1;
169 if (!IsWindow(hWnd))
return 0;
171 if (!IsWindow(hWnd))
return 0;
173 if (!IsWindow(hWnd))
return 0;
175 if (!IsWindow(hWnd))
return 0;
202 if (_r && _minwidth != -1)
205 int v = _minwidth-ocx;
206 if (v > 0)
m_dx += v;
209 if (_r && _maxwidth != -1)
212 int v = ocx-_maxwidth;
213 if (v > 0)
m_ix += v;
216 if (_b && _minheight != -1)
219 int v = _minheight-ocy;
220 if (v > 0)
m_dy += v;
223 if (_b && _maxheight != -1)
226 int v = ocy-_maxheight;
227 if (v > 0)
m_iy += v;
232 if (_minwidth != -1 && wp->cx < _minwidth) wp->cx = _minwidth;
239 if (
m_dx >= v) { wp->cx -= v;
m_dx -= v; }
else { wp->cx -=
m_dx;
m_dx = 0; }
242 if (_maxwidth != -1 && wp->cx > _maxwidth) wp->cx = _maxwidth;
249 if (
m_ix >= v) { wp->cx += v;
m_ix -= v; }
else { wp->cx +=
m_ix;
m_ix = 0; }
255 if (_maxwidth != -1 && wp->cx > _maxwidth)
258 wp->x = r.
right - _maxwidth;
260 if (_minwidth != -1 && wp->cx < _minwidth)
263 wp->x = r.
right - _minwidth;
268 if (_minheight != -1 && wp->cy < _minheight) wp->cy = _minheight;
275 if (
m_dy >= v) { wp->cy -= v;
m_dy -= v; }
else { wp->cy -=
m_dy;
m_dy = 0; }
278 if (_maxheight != -1 && wp->cy > _maxheight) wp->cy = _maxheight;
285 if (
m_iy >= v) { wp->cy += v;
m_iy -= v; }
else { wp->cy +=
m_iy;
m_iy = 0; }
291 if (_maxheight != -1 && wp->cy > _maxheight)
294 wp->y = r.
bottom - _maxheight;
296 if (_minheight != -1 && wp->cy < _minheight)
299 wp->y = r.
bottom - _minheight;
311 case WM_DEVICECHANGE:
314 nsCOMPtr<sbIDeviceManager> deviceManager =
315 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;1", &rv);
318 NS_WARNING(
"Failed to get the DeviceManager!");
324 NS_NAMED_LITERAL_STRING(cdCategory,
"Songbird CD Device");
326 rv = deviceManager->HasDeviceForCategory(cdCategory, &hasCDDevice);
327 if (NS_SUCCEEDED(rv) && hasCDDevice)
329 nsCOMPtr<sbIDeviceBase> baseDevice;
330 rv = deviceManager->GetDeviceByCategory(cdCategory,
331 getter_AddRefs(baseDevice));
332 if (NS_SUCCEEDED(rv))
335 #if defined(SB_ENABLE_CD_DEVICE)
336 nsCOMPtr<sbICDDevice> cdDevice = do_QueryInterface(baseDevice, &rv);
337 if (NS_SUCCEEDED(rv))
340 PRBool mediaInserted = DBT_DEVICEARRIVAL == wParam;
341 rv = cdDevice->OnCDDriveEvent(mediaInserted, &retVal);
362 return CallWindowProc(
m_prevWndProc, hWnd, uMsg, wParam, lParam);
390 SetWindowLong(
m_hwnd, GWL_USERDATA, (
LONG)
this);
391 SetWindowLong(
m_hwnd, GWL_WNDPROC, (
LONG)WindowMinMaxSubclassProc);
394 DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
397 ZeroMemory( &NotificationFilter,
sizeof(NotificationFilter) );
398 NotificationFilter.dbcc_size =
sizeof(DEV_BROADCAST_DEVICEINTERFACE);
399 NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
400 NotificationFilter.dbcc_classguid = GUID_NULL;
402 HDEVNOTIFY hDevNotify = RegisterDeviceNotification(
m_hwnd, &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES );
406 ::wsprintfA(szMsg,
"RegisterDeviceNotification failed: %d\n", ::GetLastError());
407 ::MessageBoxA(
m_hwnd, szMsg,
"Registration", MB_OK);
424 SetWindowLong(
m_hwnd, GWL_USERDATA, 0);
425 m_prevWndProc = NULL;
Service for setting min/max limit callbacks to a window position and size - Prototypes.
virtual ~CWindowMinMaxSubclass()
PRInt32 GetMaxHeight()
Get maximum window height This method is called by the WindowMinMax hook to query the application for...
PRInt32 GetMaxWidth()
Get maximum window width This method is called by the WindowMinMax hook to query the application for ...
Songbird Multiple Monitor Support - Definition.
PRInt32 GetMinWidth()
Get minimum window width This method is called by the WindowMinMax hook to query the application for ...
Window subclasser object for WindowMinMax service - Prototypes.
nsISupports * getWindow()
WindowMinMax callback interface This interface describes a callback for the WindowMinMax service...
sbIWindowMinMaxCallback * m_callback
CWindowMinMaxSubclass(nsISupports *window, sbIWindowMinMaxCallback *cb)
static void * get(nsISupports *window)
sbIWindowMinMaxCallback * getCallback()
void OnWindowClose()
Window closing callback This method is called by the WindowMinMax hook to notify the callback object ...
PRInt32 GetMinHeight()
Get minimum window height This method is called by the WindowMinMax hook to query the application for...
static void GetMonitorFromWindow(RECT *r, void *wnd, bool excludeTaskbar)
_getSelectedPageStyle s i