Back to index

lightning-sunbird  0.9+nobinonly
nsScreenManagerQt.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Lars Knoll <knoll@kde.org>
00023  *   Zack Rusin <zack@kde.org>
00024  *   John C. Griggs <johng@corel.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsScreenManagerQt.h"
00041 #include "nsScreenQt.h"
00042 
00043 #include "qdesktopwidget.h"
00044 #include "qapplication.h"
00045 #include "qtlog.h"
00046 
00047 nsScreenManagerQt::nsScreenManagerQt()
00048 {
00049     desktop = 0;
00050 }
00051 
00052 
00053 nsScreenManagerQt::~nsScreenManagerQt()
00054 {
00055     // nothing to see here.
00056 }
00057 
00058 // addref, release, QI
00059 NS_IMPL_ISUPPORTS1(nsScreenManagerQt, nsIScreenManager)
00060 
00061 void nsScreenManagerQt::init()
00062 {
00063     if (desktop)
00064         return;
00065 
00066     desktop = QApplication::desktop();
00067     nScreens = desktop->numScreens();
00068     screens = new nsCOMPtr<nsIScreen>[nScreens];
00069 
00070     for (int i = 0; i < nScreens; ++i)
00071         screens[i] = new nsScreenQt(i);
00072 }
00073 
00074 //
00075 // ScreenForRect
00076 //
00077 // Returns the screen that contains the rectangle. If the rect overlaps
00078 // multiple screens, it picks the screen with the greatest area of intersection.
00079 //
00080 // The coordinates are in pixels (not twips) and in screen coordinates.
00081 //
00082 NS_IMETHODIMP
00083 nsScreenManagerQt::ScreenForRect(PRInt32 inLeft, PRInt32 inTop,
00084                              PRInt32 inWidth, PRInt32 inHeight,
00085                              nsIScreen **outScreen)
00086 {
00087     if (!desktop)
00088         init();
00089 
00090     QRect r(inLeft, inTop, inWidth, inHeight);
00091     int best = 0;
00092     int area = 0;
00093     for (int i = 0; i < nScreens; ++i) {
00094         const QRect& rect = desktop->screenGeometry(i);
00095         QRect intersection = r&rect;
00096         int a = intersection.width()*intersection.height();
00097         if (a > area) {
00098             best = i;
00099             area = a;
00100         }
00101     }
00102     NS_IF_ADDREF(*outScreen = screens[best]);
00103     return NS_OK;
00104 }
00105 
00106 //
00107 // GetPrimaryScreen
00108 //
00109 // The screen with the menubar/taskbar. This shouldn't be needed very
00110 // often.
00111 //
00112 NS_IMETHODIMP
00113 nsScreenManagerQt::GetPrimaryScreen(nsIScreen **aPrimaryScreen)
00114 {
00115     if (!desktop)
00116         init();
00117 
00118     NS_IF_ADDREF(*aPrimaryScreen = screens[0]);
00119     return NS_OK;
00120 }
00121 
00122 //
00123 // GetNumberOfScreens
00124 //
00125 // Returns how many physical screens are available.
00126 //
00127 NS_IMETHODIMP
00128 nsScreenManagerQt::GetNumberOfScreens(PRUint32 *aNumberOfScreens)
00129 {
00130     if (!desktop)
00131         init();
00132 
00133     *aNumberOfScreens = desktop->numScreens();
00134     return NS_OK;
00135 }