util/src/gui/kernel/qt_s60_p.h
changeset 7 f7bc934e204c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QT_S60_P_H
       
    43 #define QT_S60_P_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists purely as an
       
    50 // implementation detail.  This header file may change from version to
       
    51 // version without notice, or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 
       
    56 #include "QtGui/qwindowdefs.h"
       
    57 #include "private/qcore_symbian_p.h"
       
    58 #include "qhash.h"
       
    59 #include "qpoint.h"
       
    60 #include "QtGui/qfont.h"
       
    61 #include "QtGui/qimage.h"
       
    62 #include "QtGui/qevent.h"
       
    63 #include "qpointer.h"
       
    64 #include "qapplication.h"
       
    65 #include <w32std.h>
       
    66 #include <coecntrl.h>
       
    67 #include <eikenv.h>
       
    68 #include <eikappui.h>
       
    69 
       
    70 #ifdef Q_WS_S60
       
    71 #include <AknUtils.h>               // AknLayoutUtils
       
    72 #include <avkon.hrh>                // EEikStatusPaneUidTitle
       
    73 #include <akntitle.h>               // CAknTitlePane
       
    74 #include <akncontext.h>             // CAknContextPane
       
    75 #include <eikspane.h>               // CEikStatusPane
       
    76 #include <AknPopupFader.h>          // MAknFadedComponent and TAknPopupFader
       
    77 #endif
       
    78 
       
    79 QT_BEGIN_NAMESPACE
       
    80 
       
    81 // Application internal HandleResourceChangeL events,
       
    82 // system events seems to start with 0x10
       
    83 const TInt KInternalStatusPaneChange = 0x50000000;
       
    84 
       
    85 //this macro exists because EColor16MAP enum value doesn't exist in Symbian OS 9.2
       
    86 #define Q_SYMBIAN_ECOLOR16MAP TDisplayMode(13)
       
    87 
       
    88 class QS60Data
       
    89 {
       
    90 public:
       
    91     QS60Data();
       
    92     TUid uid;
       
    93     int screenDepth;
       
    94     QPoint lastCursorPos;
       
    95     QPoint lastPointerEventPos;
       
    96     QPointer<QWidget> lastPointerEventTarget;
       
    97     QPointer<QWidget> mousePressTarget;
       
    98     int screenWidthInPixels;
       
    99     int screenHeightInPixels;
       
   100     int screenWidthInTwips;
       
   101     int screenHeightInTwips;
       
   102     int defaultDpiX;
       
   103     int defaultDpiY;
       
   104     WId curWin;
       
   105     int virtualMouseLastKey;
       
   106     enum PressedKeys {
       
   107         Select = 0x1,
       
   108         Right = 0x2,
       
   109         Down = 0x4,
       
   110         Left = 0x8,
       
   111         Up = 0x10
       
   112     };
       
   113     int virtualMousePressedKeys; // of the above type, but avoids casting problems
       
   114     int virtualMouseAccel;
       
   115     int virtualMouseMaxAccel;
       
   116 #ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
       
   117     int brokenPointerCursors : 1;
       
   118 #endif
       
   119     int hasTouchscreen : 1;
       
   120     int mouseInteractionEnabled : 1;
       
   121     int virtualMouseRequired : 1;
       
   122     int qtOwnsS60Environment : 1;
       
   123     int supportsPremultipliedAlpha : 1;
       
   124     int avkonComponentsSupportTransparency : 1;
       
   125     QApplication::QS60MainApplicationFactory s60ApplicationFactory; // typedef'ed pointer type
       
   126     static inline void updateScreenSize();
       
   127     static inline RWsSession& wsSession();
       
   128     static inline RWindowGroup& windowGroup();
       
   129     static inline CWsScreenDevice* screenDevice();
       
   130     static inline CCoeAppUi* appUi();
       
   131     static inline CEikMenuBar* menuBar();
       
   132 #ifdef Q_WS_S60
       
   133     static inline CEikStatusPane* statusPane();
       
   134     static inline CCoeControl* statusPaneSubPane(TInt aPaneId);
       
   135     static inline CAknTitlePane* titlePane();
       
   136     static inline CAknContextPane* contextPane();
       
   137     static inline CEikButtonGroupContainer* buttonGroupContainer();
       
   138 
       
   139     TTrapHandler *s60InstalledTrapHandler;
       
   140 #endif
       
   141 };
       
   142 
       
   143 QS60Data* qGlobalS60Data();
       
   144 #define S60 qGlobalS60Data()
       
   145 
       
   146 class QAbstractLongTapObserver
       
   147 {
       
   148 public:
       
   149     virtual void HandleLongTapEventL( const TPoint& aPenEventLocation,
       
   150                                       const TPoint& aPenEventScreenLocation ) = 0;
       
   151 };
       
   152 class QLongTapTimer;
       
   153 
       
   154 
       
   155 class QSymbianControl : public CCoeControl, public QAbstractLongTapObserver
       
   156 #ifdef Q_WS_S60
       
   157 , public MAknFadedComponent
       
   158 #endif
       
   159 {
       
   160 public:
       
   161     DECLARE_TYPE_ID(0x51740000) // Fun fact: the two first values are "Qt" in ASCII.
       
   162 
       
   163 public:
       
   164     QSymbianControl(QWidget *w);
       
   165     void ConstructL(bool isWindowOwning = false, bool desktop = false);
       
   166     ~QSymbianControl();
       
   167     void HandleResourceChange(int resourceType);
       
   168     void HandlePointerEventL(const TPointerEvent& aPointerEvent);
       
   169     TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
       
   170 #if !defined(QT_NO_IM) && defined(Q_WS_S60)
       
   171     TCoeInputCapabilities InputCapabilities() const;
       
   172 #endif
       
   173     TTypeUid::Ptr MopSupplyObject(TTypeUid id);
       
   174 
       
   175     inline QWidget* widget() const { return qwidget; }
       
   176     void setWidget(QWidget *w);
       
   177     void sendInputEvent(QWidget *widget, QInputEvent *inputEvent);
       
   178     void setIgnoreFocusChanged(bool enabled) { m_ignoreFocusChanged = enabled; }
       
   179     void CancelLongTapTimer();
       
   180 
       
   181     void setFocusSafely(bool focus);
       
   182 
       
   183 #ifdef Q_WS_S60
       
   184     void FadeBehindPopup(bool fade){ popupFader.FadeBehindPopup( this, this, fade); }
       
   185 
       
   186 protected: // from MAknFadedComponent
       
   187     TInt CountFadedComponents() {return 1;}
       
   188     CCoeControl* FadedComponent(TInt /*aIndex*/) {return this;}
       
   189 #else
       
   190     #warning No fallback implementation for QSymbianControl::FadeBehindPopup
       
   191     void FadeBehindPopup(bool /*fade*/){ }
       
   192 #endif
       
   193 
       
   194 protected:
       
   195     void Draw(const TRect& aRect) const;
       
   196     void SizeChanged();
       
   197     void PositionChanged();
       
   198     void FocusChanged(TDrawNow aDrawNow);
       
   199 
       
   200 private:
       
   201     void HandlePointerEvent(const TPointerEvent& aPointerEvent);
       
   202     TKeyResponse OfferKeyEvent(const TKeyEvent& aKeyEvent,TEventCode aType);
       
   203     TKeyResponse sendKeyEvent(QWidget *widget, QKeyEvent *keyEvent);
       
   204     bool sendMouseEvent(QWidget *widget, QMouseEvent *mEvent);
       
   205     void sendMouseEvent(
       
   206             QWidget *receiver,
       
   207             QEvent::Type type,
       
   208             const QPoint &globalPos,
       
   209             Qt::MouseButton button,
       
   210             Qt::KeyboardModifiers modifiers);
       
   211     void HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation );
       
   212 #ifdef QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER
       
   213     void translateAdvancedPointerEvent(const TAdvancedPointerEvent *event);
       
   214 #endif
       
   215     void handleClientAreaChange();
       
   216 
       
   217 private:
       
   218     static QSymbianControl *lastFocusedControl;
       
   219 
       
   220 private:
       
   221     QWidget *qwidget;
       
   222     QLongTapTimer* m_longTapDetector;
       
   223     bool m_ignoreFocusChanged : 1;
       
   224     bool m_symbianPopupIsOpen : 1;
       
   225 
       
   226 #ifdef Q_WS_S60
       
   227     // Fader object used to fade everything except this menu and the CBA.
       
   228     TAknPopupFader popupFader;
       
   229 #endif
       
   230 };
       
   231 
       
   232 inline QS60Data::QS60Data()
       
   233 {
       
   234     memclr(this, sizeof(QS60Data)); //zero init data
       
   235 }
       
   236 
       
   237 inline void QS60Data::updateScreenSize()
       
   238 {
       
   239     TPixelsTwipsAndRotation params;
       
   240     int mode = S60->screenDevice()->CurrentScreenMode();
       
   241     S60->screenDevice()->GetScreenModeSizeAndRotation(mode, params);
       
   242     S60->screenWidthInPixels = params.iPixelSize.iWidth;
       
   243     S60->screenHeightInPixels = params.iPixelSize.iHeight;
       
   244     S60->screenWidthInTwips = params.iTwipsSize.iWidth;
       
   245     S60->screenHeightInTwips = params.iTwipsSize.iHeight;
       
   246 
       
   247     S60->virtualMouseMaxAccel = qMax(S60->screenHeightInPixels, S60->screenWidthInPixels) / 20;
       
   248 
       
   249     TReal inches = S60->screenHeightInTwips / (TReal)KTwipsPerInch;
       
   250     S60->defaultDpiY = S60->screenHeightInPixels / inches;
       
   251     inches = S60->screenWidthInTwips / (TReal)KTwipsPerInch;
       
   252     S60->defaultDpiX = S60->screenWidthInPixels / inches;
       
   253 }
       
   254 
       
   255 inline RWsSession& QS60Data::wsSession()
       
   256 {
       
   257     return CCoeEnv::Static()->WsSession();
       
   258 }
       
   259 
       
   260 inline RWindowGroup& QS60Data::windowGroup()
       
   261 {
       
   262     return CCoeEnv::Static()->RootWin();
       
   263 }
       
   264 
       
   265 inline CWsScreenDevice* QS60Data::screenDevice()
       
   266 {
       
   267     return CCoeEnv::Static()->ScreenDevice();
       
   268 }
       
   269 
       
   270 inline CCoeAppUi* QS60Data::appUi()
       
   271 {
       
   272     return CCoeEnv::Static()-> AppUi();
       
   273 }
       
   274 
       
   275 inline CEikMenuBar* QS60Data::menuBar()
       
   276 {
       
   277     return CEikonEnv::Static()->AppUiFactory()->MenuBar();
       
   278 }
       
   279 
       
   280 #ifdef Q_WS_S60
       
   281 inline CEikStatusPane* QS60Data::statusPane()
       
   282 {
       
   283     return CEikonEnv::Static()->AppUiFactory()->StatusPane();
       
   284 }
       
   285 
       
   286 // Returns the application's status pane control, if not present returns NULL.
       
   287 inline CCoeControl* QS60Data::statusPaneSubPane( TInt aPaneId )
       
   288 {
       
   289     const TUid paneUid = { aPaneId };
       
   290     CEikStatusPane* statusPane = S60->statusPane();
       
   291     if (statusPane && statusPane->PaneCapabilities(paneUid).IsPresent()) {
       
   292         CCoeControl* control = NULL;
       
   293         // ControlL shouldn't leave because the pane is present
       
   294         TRAPD(err, control = statusPane->ControlL(paneUid));
       
   295         return err != KErrNone ? NULL : control;
       
   296     }
       
   297     return NULL;
       
   298 }
       
   299 
       
   300 // Returns the application's title pane, if not present returns NULL.
       
   301 inline CAknTitlePane* QS60Data::titlePane()
       
   302 {
       
   303     return static_cast<CAknTitlePane*>(S60->statusPaneSubPane(EEikStatusPaneUidTitle));
       
   304 }
       
   305 
       
   306 // Returns the application's title pane, if not present returns NULL.
       
   307 inline CAknContextPane* QS60Data::contextPane()
       
   308 {
       
   309     return static_cast<CAknContextPane*>(S60->statusPaneSubPane(EEikStatusPaneUidContext));
       
   310 }
       
   311 
       
   312 inline CEikButtonGroupContainer* QS60Data::buttonGroupContainer()
       
   313 {
       
   314     return CEikonEnv::Static()->AppUiFactory()->Cba();
       
   315 }
       
   316 #endif // Q_WS_S60
       
   317 
       
   318 static inline QFont qt_TFontSpec2QFontL(const TFontSpec &fontSpec)
       
   319 {
       
   320     return QFont(
       
   321         qt_TDesC2QString(fontSpec.iTypeface.iName),
       
   322         fontSpec.iHeight / KTwipsPerPoint,
       
   323         fontSpec.iFontStyle.StrokeWeight() == EStrokeWeightNormal ? QFont::Normal : QFont::Bold,
       
   324         fontSpec.iFontStyle.Posture() == EPostureItalic
       
   325     );
       
   326 }
       
   327 
       
   328 static inline QImage::Format qt_TDisplayMode2Format(TDisplayMode mode)
       
   329 {
       
   330     QImage::Format format;
       
   331     switch(mode) {
       
   332     case EGray2:
       
   333         format = QImage::Format_MonoLSB;
       
   334         break;
       
   335     case EColor256:
       
   336     case EGray256:
       
   337         format = QImage::Format_Indexed8;
       
   338         break;
       
   339     case EColor4K:
       
   340         format = QImage::Format_RGB444;
       
   341         break;
       
   342     case EColor64K:
       
   343         format = QImage::Format_RGB16;
       
   344         break;
       
   345     case EColor16M:
       
   346         format = QImage::Format_RGB888;
       
   347         break;
       
   348     case EColor16MU:
       
   349         format = QImage::Format_RGB32;
       
   350         break;
       
   351     case EColor16MA:
       
   352         format = QImage::Format_ARGB32;
       
   353         break;
       
   354     case Q_SYMBIAN_ECOLOR16MAP:
       
   355         format = QImage::Format_ARGB32_Premultiplied;
       
   356         break;
       
   357     default:
       
   358         format = QImage::Format_Invalid;
       
   359         break;
       
   360     }
       
   361     return format;
       
   362 }
       
   363 
       
   364 #ifndef QT_NO_CURSOR
       
   365 void qt_symbian_setWindowCursor(const QCursor &cursor, const CCoeControl* wid);
       
   366 void qt_symbian_setWindowGroupCursor(const QCursor &cursor, RWindowTreeNode &node);
       
   367 void qt_symbian_setGlobalCursor(const QCursor &cursor);
       
   368 void qt_symbian_set_cursor_visible(bool visible);
       
   369 bool qt_symbian_is_cursor_visible();
       
   370 #endif
       
   371 
       
   372 QT_END_NAMESPACE
       
   373 
       
   374 #endif // QT_S60_P_H