summaryrefslogtreecommitdiffstats
path: root/src/gui/s60framework/qs60mainappui.cpp
blob: 0c99f80886e062e947d2150ea456d3a5b9728cf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Symbian application wrapper of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

// INCLUDE FILES
#include <exception>
#include <qglobal.h>
#ifdef Q_WS_S60
#include <avkon.hrh>
#include <eikmenub.h>
#include <eikmenup.h>
#include <avkon.rsg>
#endif
#include <barsread.h>
#include <coeutils.h>
#include <qconfig.h>

#include "qs60mainappui.h"
#include <QtGui/qapplication.h>
#include <QtGui/qsymbianevent.h>
#include <QtGui/qmenu.h>
#include <private/qmenu_p.h>
#include <private/qt_s60_p.h>
#include <qdebug.h>

//Animated wallpapers in Qt applications are not supported.
const TInt KAknDisableAnimationBackground = 0x02000000;

QT_BEGIN_NAMESPACE

/*!
  \class QS60MainAppUi
  \since 4.6
  \brief The QS60MainAppUi class is a helper class for S60 migration.

  \warning This class is provided only to get access to S60 specific
  functionality in the application framework classes. It is not
  portable. We strongly recommend against using it in new applications.

  The QS60MainAppUi provides a helper class for use in migrating from
  existing S60 based applications to Qt based applications. It is used
  in the exact same way as the \c CAknAppUi class from Symbian, but
  internally provides extensions used by Qt.

  When modifying old S60 applications that rely on implementing
  functions in \c CAknAppUi, the class should be modified to inherit
  from this class instead of \c CAknAppUi. Then the application can
  choose to override only certain functions.

  For more information on \c CAknAppUi, please see the S60
  documentation.

  Unlike other Qt classes, QS60MainAppUi behaves like an S60 class,
  and can throw Symbian leaves.

  \sa QS60MainDocument, QS60MainApplication
 */

/*!
 * \brief Second phase Symbian constructor.
 *
 * Constructs all the elements of the class that can cause a leave to happen.
 *
 * If you override this function, you should call the base class implementation as well.
 */
void QS60MainAppUi::ConstructL()
{
    // Cone's heap and handle checks on app destruction are not suitable for Qt apps, as many
    // objects can still exist in static data at that point. Instead we will print relevant information
    // so that comparative checks may be made for memory leaks, using ~SPrintExitInfo in corelib.
    iEikonEnv->DisableExitChecks(ETrue);

    // Initialise app UI with standard value.
    // ENoAppResourceFile and ENonStandardResourceFile makes UI to work without
    // resource files in most SDKs. S60 3rd FP1 public seems to require resource file
    // even these flags are defined
    TInt flags = CEikAppUi::ENoScreenFurniture
               | CEikAppUi::ENonStandardResourceFile;
#ifdef Q_WS_S60
    flags |= CAknAppUi::EAknEnableSkin;
    // After 5th Edition S60, native side supports animated wallpapers.
    // However, there is no support for that feature on Qt side, so indicate to
    // native UI framework that this application will not support background animations.
    if (QSysInfo::s60Version() > QSysInfo::SV_S60_5_0)
        flags |= KAknDisableAnimationBackground;
#endif
    BaseConstructL(flags);
}

/*!
 * \brief Contructs an instance of QS60MainAppUi.
 */
QS60MainAppUi::QS60MainAppUi()
{
    // No implementation required
}

/*!
 * \brief Destroys the QS60MainAppUi.
 */
QS60MainAppUi::~QS60MainAppUi()
{
}

/*!
 * \brief Handles commands produced by the S60 framework.
 *
 * \a command holds the ID of the command to handle, and is S60 specific.
 *
 * If you override this function, you should call the base class implementation if you do not
 * handle the command.
 */
void QS60MainAppUi::HandleCommandL(TInt command)
{
    if (qApp) {
        QSymbianEvent event(QSymbianEvent::CommandEvent, command);
        QT_TRYCATCH_LEAVING(qApp->symbianProcessEvent(&event));
    }
}

/*!
 * \brief Handles a resource change in the S60 framework.
 *
 * Resource changes include layout switches. \a type holds the type of resource change that
 * occurred.
 *
 * If you override this function, you should call the base class implementation if you do not
 * handle the resource change.
 */
void QS60MainAppUi::HandleResourceChangeL(TInt type)
{
    QS60MainAppUiBase::HandleResourceChangeL(type);

    if (qApp) {
        QSymbianEvent event(QSymbianEvent::ResourceChangeEvent, type);
        QT_TRYCATCH_LEAVING(qApp->symbianProcessEvent(&event));
    }
}

/*!
 * \brief Handles raw window server events.
 *
 * The event type and information is passed in \a wsEvent, while the receiving control is passed in
 * \a destination.
 *
 * If you override this function, you should call the base class implementation if you do not
 * handle the event.
 */
void QS60MainAppUi::HandleWsEventL(const TWsEvent &wsEvent, CCoeControl *destination)
{
    int result = 0;
    if (qApp) {
        QSymbianEvent event(&wsEvent);
        QT_TRYCATCH_LEAVING(
            result = qApp->symbianProcessEvent(&event)
        );
    }

    if (result <= 0)
        QS60MainAppUiBase::HandleWsEventL(wsEvent, destination);
}


/*!
 * \brief Handles changes to the status pane size.
 *
 * Called by the framework when the application status pane size is changed.
 *
 * If you override this function, you should call the base class implementation if you do not
 * handle the size change.
 */
void QS60MainAppUi::HandleStatusPaneSizeChange()
{
    TRAP_IGNORE(HandleResourceChangeL(KInternalStatusPaneChange));
    HandleStackedControlsResourceChange(KInternalStatusPaneChange);
}

/*!
 * \brief Dynamically initializes a menu bar.
 *
 * The resource associated with the menu is given in \a resourceId, and the actual menu bar is
 * passed in \a menuBar.
 *
 * If you override this function, you should call the base class implementation as well.
 */
void QS60MainAppUi::DynInitMenuBarL(TInt /* resourceId */, CEikMenuBar * /* menuBar */)
{
}

/*!
 * \brief Dynamically initializes a menu pane.
 *
 * The resource associated with the menu is given in \a resourceId, and the actual menu pane is
 * passed in \a menuPane.
 *
 * If you override this function, you should call the base class implementation as well.
 */
void QS60MainAppUi::DynInitMenuPaneL(TInt resourceId, CEikMenuPane *menuPane)
{
#ifdef Q_WS_S60
    if (resourceId == R_AVKON_MENUPANE_EMPTY) {
        if (menuPane->NumberOfItemsInPane() <= 1)
            QT_TRYCATCH_LEAVING(qt_symbian_show_toplevel(menuPane));

    } else if (resourceId != R_AVKON_MENUPANE_FEP_DEFAULT
            && resourceId != R_AVKON_MENUPANE_EDITTEXT_DEFAULT
            && resourceId != R_AVKON_MENUPANE_LANGUAGE_DEFAULT) {
        QT_TRYCATCH_LEAVING(qt_symbian_show_submenu(menuPane, resourceId));
    }
#else
    QS60MainAppUiBase::DynInitMenuPaneL(resourceId, menuPane);
#endif
}

/*!
 * \brief Restores a menu window.
 *
 * The menu window to restore is given in \a menuWindow. The resource ID and type of menu is given
 * in \a resourceId and \a menuType, respectively.
 *
 * If you override this function, you should call the base class implementation as well.
 */
void QS60MainAppUi::RestoreMenuL(CCoeControl *menuWindow, TInt resourceId, TMenuType menuType)
{
#ifdef Q_WS_S60
    if (resourceId >= QT_SYMBIAN_FIRST_MENU_ITEM && resourceId <= QT_SYMBIAN_LAST_MENU_ITEM) {
        if (menuType == EMenuPane)
            DynInitMenuPaneL(resourceId, (CEikMenuPane*)menuWindow);
        else
            DynInitMenuBarL(resourceId, (CEikMenuBar*)menuWindow);
    } else if(resourceId == R_AVKON_MENUPANE_EMPTY) {
        CEikMenuBarTitle *title = new(ELeave) CEikMenuBarTitle;
        CleanupStack::PushL(title);

        title->iData.iMenuPaneResourceId = R_AVKON_MENUPANE_EMPTY;
        title->iTitleFlags = 0;

        S60->menuBar()->TitleArray()->AddTitleL(title);
        CleanupStack::Pop( title );
    }
    else
#endif
    {
        QS60MainAppUiBase::RestoreMenuL(menuWindow, resourceId, menuType);
    }
}

/*!
  \internal
*/
void QS60MainAppUi::Exit()
{
    QS60MainAppUiBase::Exit();
}

/*!
  \internal
*/
void QS60MainAppUi::SetFadedL(TBool aFaded)
{
    QS60MainAppUiBase::SetFadedL(aFaded);
}

/*!
  \internal
*/
TRect QS60MainAppUi::ApplicationRect() const
{
    return QS60MainAppUiBase::ApplicationRect();
}

/*!
  \internal
*/
void QS60MainAppUi::HandleScreenDeviceChangedL()
{
    QS60MainAppUiBase::HandleScreenDeviceChangedL();
}

/*!
  \internal
*/
void QS60MainAppUi::HandleApplicationSpecificEventL(TInt aType, const TWsEvent &aEvent)
{
    QS60MainAppUiBase::HandleApplicationSpecificEventL(aType, aEvent);
}

/*!
  \internal
*/
TTypeUid::Ptr QS60MainAppUi::MopSupplyObject(TTypeUid aId)
{
    return QS60MainAppUiBase::MopSupplyObject(aId);
}

/*!
  \internal
*/
void QS60MainAppUi::ProcessCommandL(TInt aCommand)
{
    QS60MainAppUiBase::ProcessCommandL(aCommand);
}

/*!
  \internal
*/
TErrorHandlerResponse QS60MainAppUi::HandleError (TInt aError, const SExtendedError &aExtErr, TDes &aErrorText, TDes &aContextText)
{
    return QS60MainAppUiBase::HandleError(aError, aExtErr, aErrorText, aContextText);
}

/*!
  \internal
*/
void QS60MainAppUi::HandleViewDeactivation(const TVwsViewId &aViewIdToBeDeactivated, const TVwsViewId &aNewlyActivatedViewId)
{
    QS60MainAppUiBase::HandleViewDeactivation(aViewIdToBeDeactivated, aNewlyActivatedViewId);
}

/*!
  \internal
*/
void QS60MainAppUi::PrepareToExit()
{
    QS60MainAppUiBase::PrepareToExit();
}

/*!
  \internal
*/
void QS60MainAppUi::HandleTouchPaneSizeChange()
{
    QS60MainAppUiBase::HandleTouchPaneSizeChange();
}

/*!
  \internal
*/
void QS60MainAppUi::HandleSystemEventL(const TWsEvent &aEvent)
{
    QS60MainAppUiBase::HandleSystemEventL(aEvent);
}

/*!
  \internal
*/
void QS60MainAppUi::Reserved_MtsmPosition()
{
    QS60MainAppUiBase::Reserved_MtsmPosition();
}

/*!
  \internal
*/
void QS60MainAppUi::Reserved_MtsmObject()
{
    QS60MainAppUiBase::Reserved_MtsmObject();
}

/*!
  \internal
*/
void QS60MainAppUi::HandleForegroundEventL(TBool aForeground)
{
    QS60MainAppUiBase::HandleForegroundEventL(aForeground);
}

/*!
  \internal
*/
TBool QS60MainAppUi::ProcessCommandParametersL(TApaCommand /*aCommand*/, TFileName &/*aDocumentName*/, const TDesC8 &/*aTail*/)
{
    // bypass CEikAppUi::ProcessCommandParametersL(..) which modifies aDocumentName, preventing apparc document opening from working.
    // The return value is effectively unused in Qt apps (see QS60MainDocument::OpenFileL)
    return EFalse;
}

#ifndef Q_WS_S60

void QS60StubAknAppUi::HandleViewDeactivation(const TVwsViewId &, const TVwsViewId &) {}
void QS60StubAknAppUi::HandleTouchPaneSizeChange() {}
void QS60StubAknAppUi::HandleStatusPaneSizeChange() {}
void QS60StubAknAppUi::Reserved_MtsmPosition() {}
void QS60StubAknAppUi::Reserved_MtsmObject() {}

#endif

QT_END_NAMESPACE