source: trunk/src/gui/kernel/qt_s60_p.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 14.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
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 "qelapsedtimer.h"
66#include "QtCore/qthreadstorage.h"
67#include <w32std.h>
68#include <coecntrl.h>
69#include <eikenv.h>
70#include <eikappui.h>
71
72#ifdef Q_WS_S60
73#include <AknUtils.h> // AknLayoutUtils
74#include <avkon.hrh> // EEikStatusPaneUidTitle
75#include <akntitle.h> // CAknTitlePane
76#include <akncontext.h> // CAknContextPane
77#include <eikspane.h> // CEikStatusPane
78#include <AknPopupFader.h> // MAknFadedComponent and TAknPopupFader
79#endif
80
81QT_BEGIN_NAMESPACE
82
83// Application internal HandleResourceChangeL events,
84// system events seems to start with 0x10
85const TInt KInternalStatusPaneChange = 0x50000000;
86
87//this macro exists because EColor16MAP enum value doesn't exist in Symbian OS 9.2
88#define Q_SYMBIAN_ECOLOR16MAP TDisplayMode(13)
89
90class Q_AUTOTEST_EXPORT QS60ThreadLocalData
91{
92public:
93 QS60ThreadLocalData();
94 ~QS60ThreadLocalData();
95 bool usingCONEinstances;
96 RWsSession wsSession;
97 CWsScreenDevice *screenDevice;
98};
99
100class QS60Data
101{
102public:
103 QS60Data();
104 QThreadStorage<QS60ThreadLocalData *> tls;
105 TUid uid;
106 int screenDepth;
107 QPoint lastCursorPos;
108 QPoint lastPointerEventPos;
109 QPointer<QWidget> lastPointerEventTarget;
110 QPointer<QWidget> mousePressTarget;
111 int screenWidthInPixels;
112 int screenHeightInPixels;
113 int screenWidthInTwips;
114 int screenHeightInTwips;
115 int defaultDpiX;
116 int defaultDpiY;
117 WId curWin;
118 enum PressedKeys {
119 Select = 0x1,
120 Right = 0x2,
121 Down = 0x4,
122 Left = 0x8,
123 Up = 0x10,
124 LeftUp = 0x20,
125 RightUp = 0x40,
126 RightDown = 0x80,
127 LeftDown = 0x100
128 };
129 int virtualMousePressedKeys; // of the above type, but avoids casting problems
130 int virtualMouseAccelDX;
131 int virtualMouseAccelDY;
132 QElapsedTimer virtualMouseAccelTimeout;
133 int virtualMouseMaxAccel;
134#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
135 int brokenPointerCursors : 1;
136#endif
137 int hasTouchscreen : 1;
138 int mouseInteractionEnabled : 1;
139 int virtualMouseRequired : 1;
140 int qtOwnsS60Environment : 1;
141 int supportsPremultipliedAlpha : 1;
142 int avkonComponentsSupportTransparency : 1;
143 int menuBeingConstructed : 1;
144 int orientationSet : 1;
145 QApplication::QS60MainApplicationFactory s60ApplicationFactory; // typedef'ed pointer type
146 static CEikButtonGroupContainer *cba;
147
148 enum ScanCodeState {
149 Unpressed,
150 KeyDown,
151 KeyDownAndKey
152 };
153 QHash<TInt, ScanCodeState> scanCodeStates;
154
155 static inline void updateScreenSize();
156 inline RWsSession& wsSession();
157 static inline RWindowGroup& windowGroup();
158 inline CWsScreenDevice* screenDevice();
159 static inline CCoeAppUi* appUi();
160 static inline CEikMenuBar* menuBar();
161#ifdef Q_WS_S60
162 static inline CEikStatusPane* statusPane();
163 static inline CCoeControl* statusPaneSubPane(TInt aPaneId);
164 static inline CAknTitlePane* titlePane();
165 static inline CAknContextPane* contextPane();
166 static inline CEikButtonGroupContainer* buttonGroupContainer();
167 static inline void setButtonGroupContainer(CEikButtonGroupContainer* newCba);
168 static void setStatusPaneAndButtonGroupVisibility(bool statusPaneVisible, bool buttonGroupVisible);
169#endif
170 static void controlVisibilityChanged(CCoeControl *control, bool visible);
171
172#ifdef Q_OS_SYMBIAN
173 TTrapHandler *s60InstalledTrapHandler;
174#endif
175};
176
177Q_AUTOTEST_EXPORT QS60Data* qGlobalS60Data();
178#define S60 qGlobalS60Data()
179
180class QAbstractLongTapObserver
181{
182public:
183 virtual void HandleLongTapEventL( const TPoint& aPenEventLocation,
184 const TPoint& aPenEventScreenLocation ) = 0;
185};
186class QLongTapTimer;
187
188
189class QSymbianControl : public CCoeControl, public QAbstractLongTapObserver
190#ifdef Q_WS_S60
191, public MAknFadedComponent, public MEikStatusPaneObserver
192#endif
193{
194public:
195 DECLARE_TYPE_ID(0x51740000) // Fun fact: the two first values are "Qt" in ASCII.
196
197public:
198 QSymbianControl(QWidget *w);
199 void ConstructL(bool isWindowOwning = false, bool desktop = false);
200 ~QSymbianControl();
201 void HandleResourceChange(int resourceType);
202 void HandlePointerEventL(const TPointerEvent& aPointerEvent);
203 TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
204#if !defined(QT_NO_IM) && defined(Q_WS_S60)
205 TCoeInputCapabilities InputCapabilities() const;
206#endif
207 TTypeUid::Ptr MopSupplyObject(TTypeUid id);
208
209 inline QWidget* widget() const { return qwidget; }
210 void setWidget(QWidget *w);
211 void sendInputEvent(QWidget *widget, QInputEvent *inputEvent);
212 void setIgnoreFocusChanged(bool enabled) { m_ignoreFocusChanged = enabled; }
213 void CancelLongTapTimer();
214
215 void setFocusSafely(bool focus);
216
217 bool isControlActive();
218
219#ifdef Q_WS_S60
220 void FadeBehindPopup(bool fade){ popupFader.FadeBehindPopup( this, this, fade); }
221 void HandleStatusPaneSizeChange();
222
223protected: // from MAknFadedComponent
224 TInt CountFadedComponents() {return 1;}
225 CCoeControl* FadedComponent(TInt /*aIndex*/) {return this;}
226#else
227 // #warning No fallback implementation for QSymbianControl::FadeBehindPopup
228 void FadeBehindPopup(bool /*fade*/){ }
229#endif
230
231protected:
232 void Draw(const TRect& aRect) const;
233 void SizeChanged();
234 void PositionChanged();
235 void FocusChanged(TDrawNow aDrawNow);
236
237private:
238 void HandlePointerEvent(const TPointerEvent& aPointerEvent);
239 TKeyResponse OfferKeyEvent(const TKeyEvent& aKeyEvent,TEventCode aType);
240 TKeyResponse sendSymbianKeyEvent(const TKeyEvent &keyEvent, QEvent::Type type);
241 TKeyResponse sendKeyEvent(QWidget *widget, QKeyEvent *keyEvent);
242 TKeyResponse handleVirtualMouse(const TKeyEvent& keyEvent,TEventCode type);
243 bool sendMouseEvent(QWidget *widget, QMouseEvent *mEvent);
244 void sendMouseEvent(
245 QWidget *receiver,
246 QEvent::Type type,
247 const QPoint &globalPos,
248 Qt::MouseButton button,
249 Qt::KeyboardModifiers modifiers);
250 void processTouchEvent(int pointerNumber, TPointerEvent::TType type, QPointF screenPos, qreal pressure);
251 void HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation );
252#ifdef QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER
253 void translateAdvancedPointerEvent(const TAdvancedPointerEvent *event);
254#endif
255
256public:
257 void handleClientAreaChange();
258
259private:
260 static QSymbianControl *lastFocusedControl;
261
262private:
263 QWidget *qwidget;
264 QLongTapTimer* m_longTapDetector;
265 QElapsedTimer m_doubleClickTimer;
266 bool m_ignoreFocusChanged : 1;
267 bool m_symbianPopupIsOpen : 1;
268
269#ifdef Q_WS_S60
270 // Fader object used to fade everything except this menu and the CBA.
271 TAknPopupFader popupFader;
272#endif
273};
274
275inline QS60Data::QS60Data()
276: uid(TUid::Null()),
277 screenDepth(0),
278 screenWidthInPixels(0),
279 screenHeightInPixels(0),
280 screenWidthInTwips(0),
281 screenHeightInTwips(0),
282 defaultDpiX(0),
283 defaultDpiY(0),
284 curWin(0),
285 virtualMousePressedKeys(0),
286 virtualMouseAccelDX(0),
287 virtualMouseAccelDY(0),
288 virtualMouseMaxAccel(0),
289#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
290 brokenPointerCursors(0),
291#endif
292 hasTouchscreen(0),
293 mouseInteractionEnabled(0),
294 virtualMouseRequired(0),
295 qtOwnsS60Environment(0),
296 supportsPremultipliedAlpha(0),
297 avkonComponentsSupportTransparency(0),
298 menuBeingConstructed(0),
299 orientationSet(0),
300 s60ApplicationFactory(0)
301#ifdef Q_OS_SYMBIAN
302 ,s60InstalledTrapHandler(0)
303#endif
304{
305}
306
307inline void QS60Data::updateScreenSize()
308{
309 TPixelsTwipsAndRotation params;
310 int mode = S60->screenDevice()->CurrentScreenMode();
311 S60->screenDevice()->GetScreenModeSizeAndRotation(mode, params);
312 S60->screenWidthInPixels = params.iPixelSize.iWidth;
313 S60->screenHeightInPixels = params.iPixelSize.iHeight;
314 S60->screenWidthInTwips = params.iTwipsSize.iWidth;
315 S60->screenHeightInTwips = params.iTwipsSize.iHeight;
316
317 S60->virtualMouseMaxAccel = qMax(S60->screenHeightInPixels, S60->screenWidthInPixels) / 10;
318
319 TReal inches = S60->screenHeightInTwips / (TReal)KTwipsPerInch;
320 S60->defaultDpiY = S60->screenHeightInPixels / inches;
321 inches = S60->screenWidthInTwips / (TReal)KTwipsPerInch;
322 S60->defaultDpiX = S60->screenWidthInPixels / inches;
323}
324
325inline RWsSession& QS60Data::wsSession()
326{
327 if(!tls.hasLocalData()) {
328 tls.setLocalData(new QS60ThreadLocalData);
329 }
330 return tls.localData()->wsSession;
331}
332
333inline RWindowGroup& QS60Data::windowGroup()
334{
335 return CCoeEnv::Static()->RootWin();
336}
337
338inline CWsScreenDevice* QS60Data::screenDevice()
339{
340 if(!tls.hasLocalData()) {
341 tls.setLocalData(new QS60ThreadLocalData);
342 }
343 return tls.localData()->screenDevice;
344}
345
346inline CCoeAppUi* QS60Data::appUi()
347{
348 return CCoeEnv::Static()-> AppUi();
349}
350
351inline CEikMenuBar* QS60Data::menuBar()
352{
353 return CEikonEnv::Static()->AppUiFactory()->MenuBar();
354}
355
356#ifdef Q_WS_S60
357inline CEikStatusPane* QS60Data::statusPane()
358{
359 return CEikonEnv::Static()->AppUiFactory()->StatusPane();
360}
361
362// Returns the application's status pane control, if not present returns NULL.
363inline CCoeControl* QS60Data::statusPaneSubPane( TInt aPaneId )
364{
365 const TUid paneUid = { aPaneId };
366 CEikStatusPane* statusPane = S60->statusPane();
367 if (statusPane && statusPane->PaneCapabilities(paneUid).IsPresent()) {
368 CCoeControl* control = NULL;
369 // ControlL shouldn't leave because the pane is present
370 TRAPD(err, control = statusPane->ControlL(paneUid));
371 return err != KErrNone ? NULL : control;
372 }
373 return NULL;
374}
375
376// Returns the application's title pane, if not present returns NULL.
377inline CAknTitlePane* QS60Data::titlePane()
378{
379 return static_cast<CAknTitlePane*>(S60->statusPaneSubPane(EEikStatusPaneUidTitle));
380}
381
382// Returns the application's title pane, if not present returns NULL.
383inline CAknContextPane* QS60Data::contextPane()
384{
385 return static_cast<CAknContextPane*>(S60->statusPaneSubPane(EEikStatusPaneUidContext));
386}
387
388inline CEikButtonGroupContainer* QS60Data::buttonGroupContainer()
389{
390 return QS60Data::cba;
391}
392
393inline void QS60Data::setButtonGroupContainer(CEikButtonGroupContainer *newCba)
394{
395 QS60Data::cba = newCba;
396}
397#endif // Q_WS_S60
398
399static inline QFont qt_TFontSpec2QFontL(const TFontSpec &fontSpec)
400{
401 return QFont(
402 qt_TDesC2QString(fontSpec.iTypeface.iName),
403 fontSpec.iHeight / KTwipsPerPoint,
404 fontSpec.iFontStyle.StrokeWeight() == EStrokeWeightNormal ? QFont::Normal : QFont::Bold,
405 fontSpec.iFontStyle.Posture() == EPostureItalic
406 );
407}
408
409static inline QImage::Format qt_TDisplayMode2Format(TDisplayMode mode)
410{
411 QImage::Format format;
412 switch(mode) {
413 case EGray2:
414 format = QImage::Format_MonoLSB;
415 break;
416 case EColor256:
417 case EGray256:
418 format = QImage::Format_Indexed8;
419 break;
420 case EColor4K:
421 format = QImage::Format_RGB444;
422 break;
423 case EColor64K:
424 format = QImage::Format_RGB16;
425 break;
426 case EColor16M:
427 format = QImage::Format_RGB888;
428 break;
429 case EColor16MU:
430 format = QImage::Format_RGB32;
431 break;
432 case EColor16MA:
433 format = QImage::Format_ARGB32;
434 break;
435 case Q_SYMBIAN_ECOLOR16MAP:
436 format = QImage::Format_ARGB32_Premultiplied;
437 break;
438 default:
439 format = QImage::Format_Invalid;
440 break;
441 }
442 return format;
443}
444
445#ifndef QT_NO_CURSOR
446void qt_symbian_setWindowCursor(const QCursor &cursor, const CCoeControl* wid);
447void qt_symbian_setWindowGroupCursor(const QCursor &cursor, RWindowTreeNode &node);
448void qt_symbian_setGlobalCursor(const QCursor &cursor);
449void qt_symbian_set_cursor_visible(bool visible);
450bool qt_symbian_is_cursor_visible();
451#endif
452
453QT_END_NAMESPACE
454
455#endif // QT_S60_P_H
Note: See TracBrowser for help on using the repository browser.