javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/inc/swtdisplay.h
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - S60 implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 
       
    13 #ifndef SWTDISPLAY_H
       
    14 #define SWTDISPLAY_H
       
    15 
       
    16 
       
    17 // In emulator debug builds, uncomment the following line to compile eSWT with
       
    18 // memory leak checking enabled. Besides checks for leaked Java objects, this will
       
    19 // cause eSWT to create a separate heap for its native UI thread. In this heap it
       
    20 // will be checked when the Display object is disposed that all the allocated
       
    21 // heap cells have been freed. Failing the check will cause the thread to panic.
       
    22 // Note: Browser widget has problems when this flag is enabled.
       
    23 // Pay attention when using in other files! Include "swtdisplay.h"!!!
       
    24 //#define ESWT_NATIVE_UITHREAD_OWN_HEAP
       
    25 
       
    26 // In emulator debug builds, uncomment the following line to compile eSWT with
       
    27 // checking for situations where Java application is disposing native resources
       
    28 // ( e.g. Images, Fonts ) too soon while they are still being used by the widgets.
       
    29 //#define ESWT_EARLY_DISPOSAL_CHECKING_ENABLED
       
    30 
       
    31 
       
    32 #include <aknapp.h>
       
    33 #include <AknDoc.h>
       
    34 #include <aknappui.h>
       
    35 
       
    36 #include <coreuiappui.h>
       
    37 #include <coreuiavkoneswt.h>
       
    38 #include <coreuiappuichild.h>
       
    39 
       
    40 #include "swtdisplaybase.h"
       
    41 #include "swtclient.h"
       
    42 #include "swteventqueue.h"
       
    43 
       
    44 class CEikonEnv;
       
    45 class CApaWindowGroupName;
       
    46 class CSwtServer;
       
    47 class CSwtDialogBroker;
       
    48 
       
    49 
       
    50 /**
       
    51  * C++ counterpart to the org.eclipse.swt.widgets.Display Java class.
       
    52  *
       
    53  * Additionally to implementing Display's features, this class
       
    54  * also serves as the hub for all communications between the main thread and
       
    55  * the UI thread. Actually, it is it that creates the AppUi's thread.
       
    56  *
       
    57  * If the macro ESWT_OWN_APPUI macro is defined, the AppUi will be
       
    58  * created by the Display ( instead of the launcher ). This must not be used for
       
    59  * release builds as it yields a broken behaviour, but it enables memory leaks
       
    60  * detection by allocating a separate heap for the UI.
       
    61  *
       
    62  * @lib eswt
       
    63  */
       
    64 NONSHARABLE_CLASS(CSwtDisplay)
       
    65         : public CBase
       
    66         , public ASwtDisplayBase
       
    67         , public java::ui::CoreAppUiChild
       
    68 {
       
    69 // Any thread
       
    70 public:
       
    71     static inline CSwtDisplay* CurrentOrNull();
       
    72     static inline CSwtDisplay& Current();
       
    73 
       
    74 // Java Ui Thread
       
    75 public:
       
    76     static CSwtDisplay* NewL(JNIEnv& aJniEnv, jobject aPeer, TInt aDisplayParameter);
       
    77     void Dispose(JNIEnv& aJniEnv);
       
    78     void RequestRunDialogL(TSwtPeer aPeer, TInt aDialogType, TInt aStyle, const TDesC& aTitle,
       
    79                            const TDesC& aText1 = KNullDesC(), const TDesC& aText2 = KNullDesC(),
       
    80                            const TInt aInt1 = 0, const TInt aInt2 = 0, const TInt aInt3 = 0);
       
    81     inline TInt ExecuteInNativeUiThread(const MSwtFunctor& aFunctor);
       
    82 
       
    83 // Native Ui Thread
       
    84 public:
       
    85     void OfferWsEventL(const TSwtWsEvent& aEvent, CCoeControl* aDestination = NULL);
       
    86     void RemoveDialogBroker(CSwtDialogBroker* aBroker);
       
    87 
       
    88 // From java::ui::CoreAppUiChild
       
    89 // Native Ui Thread
       
    90 public:
       
    91     void HandleForegroundEventL(TBool aForeground);
       
    92     void HandleSwitchOnEventL(CCoeControl* aDestination);
       
    93     void HandleApplicationSpecificEventL(TInt aType,const TWsEvent& aEvent);
       
    94     void HandleCommandL(TInt aCommand);
       
    95     void HandleResourceChangeL(TInt aType);
       
    96     TBool HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination);
       
    97 
       
    98 // From MSwtDisplay
       
    99 // Any thread
       
   100 public:
       
   101 #ifdef _DEBUG
       
   102     TBool IsCurrentThreadNativeUi() const;
       
   103 #endif
       
   104     TSwtPeer JavaPeer();
       
   105 
       
   106 // From MSwtDisplay
       
   107 // Native UI Thread
       
   108 public:
       
   109     void SetNameInTaskListL(const TDesC* aNewName);
       
   110     void SetUIDInTaskList(TInt aNewUID);
       
   111     void SetAppVisible(TBool aVisible);
       
   112     void SetUiReady(TBool aFullScreenUi);
       
   113     TBool IsUiReady() const;
       
   114 
       
   115 // Java Ui Thread
       
   116 private:
       
   117     static CSwtDisplay* DoNewL(JNIEnv& aJniEnv, TSwtPeer aPeer, TInt aApplicationUid);
       
   118     inline CSwtDisplay(TSwtPeer aPeer);
       
   119     void ConstructInJavaUiThreadL(JNIEnv& aJniEnv);
       
   120 
       
   121 // Native Ui Thread
       
   122 private:
       
   123     static void DoExecuteInNativeUiThreadL(const MSwtFunctor* aFunctor);
       
   124     static TInt CloseEventDispatchTimerCallback(TAny* aThis);
       
   125     ~CSwtDisplay();
       
   126     void ConstructInNativeUiThreadL();
       
   127     void DestroyInNativeUiThread();
       
   128     CSwtDialogBroker* CreateDialogBrokerL();
       
   129     void HandleCloseEventDispatchTimerCallbackL();
       
   130     void DialogAboutToOpen();
       
   131 
       
   132 // Any thread data
       
   133 private:
       
   134     TSwtPeer iPeer;
       
   135     RThread iNativeUiThread;
       
   136 
       
   137 // Java Ui Thread data
       
   138 private:
       
   139     RSwtClient iClient; // own
       
   140 
       
   141 // Native Ui Thread data
       
   142 private:
       
   143     TBool iCloseEventDispatched;
       
   144     CPeriodic* iCloseEventDispatchTimer; // own
       
   145     RPointerArray<CSwtDialogBroker> iDialogBrokers; // own
       
   146     TBool iUiReady;
       
   147     JavaVM* iVM;
       
   148     TBool iDisposing;
       
   149 };
       
   150 
       
   151 /**
       
   152  * Returns the current Display or NULL if there is none.
       
   153  */
       
   154 inline CSwtDisplay* CSwtDisplay::CurrentOrNull()
       
   155 {
       
   156     if (java::ui::CoreUiAvkonEswt::isCoreUiCreated())
       
   157     {
       
   158         java::ui::CoreUiAvkonEswt& ui = java::ui::CoreUiAvkonEswt::getInstance();
       
   159         return ui.getEswtSupport().display();
       
   160     }
       
   161     else
       
   162     {
       
   163         return 0;
       
   164     }
       
   165 }
       
   166 
       
   167 /**
       
   168  * Returns the current Display.
       
   169  * Can only be called after a Display has been created
       
   170  */
       
   171 inline CSwtDisplay& CSwtDisplay::Current()
       
   172 {
       
   173     CSwtDisplay* display = CurrentOrNull();
       
   174     ASSERT(display);
       
   175     return *display;
       
   176 }
       
   177 
       
   178 /**
       
   179  * Executes a wrapped function in the UI's thread
       
   180  */
       
   181 inline TInt CSwtDisplay::ExecuteInNativeUiThread(const MSwtFunctor& aFunctor)
       
   182 {
       
   183     ASSERT(iClient.Handle()!=0);
       
   184     return iClient.Execute(aFunctor);
       
   185 }
       
   186 
       
   187 /**
       
   188  * C'tor
       
   189  */
       
   190 inline CSwtDisplay::CSwtDisplay(TSwtPeer aPeer)
       
   191         : ASwtDisplayBase()
       
   192         , iPeer(aPeer)
       
   193 {
       
   194 }
       
   195 
       
   196 #endif // SWTDISPLAY_H