javauis/lcdui_qt/src/javax/microedition/lcdui/LCDUIInvokerImpl.java
changeset 21 2a9601315dfc
child 23 98ccebc37403
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 package javax.microedition.lcdui;
       
    18 
       
    19 import org.eclipse.swt.graphics.Internal_GfxPackageSupport;
       
    20 import org.eclipse.swt.internal.qt.graphics.GraphicsContext;
       
    21 import org.eclipse.swt.widgets.Control;
       
    22 import org.eclipse.swt.widgets.Display;
       
    23 import org.eclipse.swt.widgets.Button;
       
    24 import com.nokia.mid.ui.DirectGraphics;
       
    25 import com.nokia.mj.impl.nokialcdui.LCDUIInvoker;
       
    26 
       
    27 final class LCDUIInvokerImpl extends LCDUIInvoker {
       
    28 
       
    29     private boolean eswtReturn;
       
    30 
       
    31    /**
       
    32      * Constant for Soft Key Label Height
       
    33      */
       
    34     public static final int LABEL_HEIGHT = 30;
       
    35     
       
    36     static void createInvoker() {
       
    37         LCDUIInvoker.setInvoker(
       
    38                 new javax.microedition.lcdui.LCDUIInvokerImpl());
       
    39     }
       
    40     
       
    41     
       
    42     protected void doESWTUIThreadRunnerSyncExec(Runnable runnable) {
       
    43         ESWTUIThreadRunner.syncExec(runnable);
       
    44     }
       
    45 
       
    46     /**
       
    47      * Returns main eSWT Control that is used by LCDUI Displayable or Item.
       
    48      *
       
    49      * @param lcduiObject - LCDUI Displayable or Item.
       
    50      * @return eSWT Control that is used by Displayable/Item or null if no
       
    51      *         Control is available.
       
    52      */
       
    53     protected Control doGetEswtControl(Object lcduiObject) {
       
    54         Logger.method(this, "doGetEswtControl", lcduiObject);
       
    55         if (lcduiObject instanceof Displayable) {
       
    56             return ((Displayable) lcduiObject).getShell();
       
    57         }
       
    58         else if (lcduiObject instanceof Item) {
       
    59             Item item = (Item) lcduiObject;
       
    60             if (item.isContainedInForm()) {
       
    61                 Form parentForm = (Form) item.getParent();
       
    62                 return parentForm.getLayoutPolicy().getItemControl(item);
       
    63             }
       
    64         }
       
    65         return null;
       
    66     }
       
    67 
       
    68     /*
       
    69     * This method checks if the current Displayable exists
       
    70     * If yes, then the current Displayable is asked for the property
       
    71     * If no, the null is returned
       
    72     */
       
    73     protected String getSoftKeyLabelLocationImpl(String softKeyId)
       
    74     {
       
    75         String SoftKeyLabelLocation = null;
       
    76 
       
    77         Displayable disp = javax.microedition.lcdui.Display.getDisplay().getCurrent();
       
    78 
       
    79             if( ( disp != null) && (disp instanceof Canvas))
       
    80             {
       
    81                   if( ( (Canvas) disp).IsFullScreenMode()) {
       
    82 
       
    83                       if("com.nokia.softkey1.label.location".equals(softKeyId))
       
    84                       {
       
    85                           SoftKeyLabelLocation = "0," + String.valueOf(( (Canvas) disp).getHeight()) + ","
       
    86                                                  + String.valueOf( (((Canvas) disp).getWidth())/2 ) + ","
       
    87                                                  + String.valueOf(LABEL_HEIGHT);
       
    88                       }
       
    89                       else if("com.nokia.softkey2.label.location".equals(softKeyId))
       
    90                       {
       
    91                           SoftKeyLabelLocation = String.valueOf( (((Canvas) disp).getWidth())/2 ) + "," 
       
    92                                                  + String.valueOf(( (Canvas) disp).getHeight()) + ","
       
    93                                                  + String.valueOf( (((Canvas) disp).getWidth())/2 ) + ","
       
    94                                                  + String.valueOf(LABEL_HEIGHT);
       
    95                       }
       
    96                   }
       
    97             }
       
    98 
       
    99         return SoftKeyLabelLocation;
       
   100     }
       
   101 
       
   102     /*
       
   103     * This method checks if the current Displayable exists
       
   104     * If yes, then the current Displayable is asked for the property
       
   105     * If no, the null is returned
       
   106     */
       
   107     protected String getSoftKeyLabelAnchorImpl(String softKeyId)
       
   108     {
       
   109         String SoftKeyLabelAnchor = null;
       
   110 
       
   111         Displayable disp = javax.microedition.lcdui.Display.getDisplay().getCurrent();
       
   112 
       
   113             if( ( disp != null) && (disp instanceof Canvas))
       
   114             {
       
   115                  if( null == ((Canvas) disp).getCanvasKeypad())
       
   116                  {
       
   117                      SoftKeyLabelAnchor = String.valueOf(Graphics.TOP | Graphics.HCENTER);
       
   118                  }
       
   119                  else
       
   120                  {
       
   121                      if("com.nokia.softkey1.label.anchor".equals(softKeyId))
       
   122                      {
       
   123                          SoftKeyLabelAnchor = String.valueOf(Graphics.TOP | Graphics.LEFT);
       
   124                      }
       
   125                      else if("com.nokia.softkey2.label.anchor".equals(softKeyId))
       
   126                      {
       
   127                          SoftKeyLabelAnchor = String.valueOf(Graphics.TOP | Graphics.RIGHT);
       
   128                      }
       
   129                  }
       
   130             }
       
   131 
       
   132         return SoftKeyLabelAnchor;
       
   133     }
       
   134 
       
   135     protected Display doGetEswtDisplay() {
       
   136         Logger.method(this, "doGetEswtDisplay");
       
   137         return ESWTUIThreadRunner.getInstance().getDisplay();
       
   138     }
       
   139 
       
   140     protected org.eclipse.swt.graphics.Image doGetEswtImage(Image img) {
       
   141         Logger.method(this, "doGetEswtImage", img);
       
   142         return Image.getESWTImage(img);
       
   143     }
       
   144 
       
   145     protected DirectGraphics doGetDirectGraphics(Graphics g) {
       
   146         Logger.method(this, "doGetDirectGraphics", g);
       
   147         if (g != null) {
       
   148             return g.getDirectGraphics();
       
   149         }
       
   150         return null;
       
   151     }
       
   152 
       
   153     protected GraphicsContext doGetGc(Graphics g) {
       
   154         Logger.method(this, "doGetGc", g);
       
   155         if (g != null) {
       
   156             return g.getGc();
       
   157         }
       
   158         return null;
       
   159     }
       
   160 
       
   161     protected Font doGetFreeSizedFont(int face, int style, int height) {
       
   162         Logger.method(this, "doGetFreeSizedFont");
       
   163         return Font.getFreeSizedFont(face, style, height);
       
   164     }
       
   165 
       
   166 
       
   167     protected void doInitGameCanvas(Object canvas, boolean suppressKeys) {
       
   168         Logger.method(canvas, "doInitGameCanvas", String.valueOf(suppressKeys));
       
   169         ((Canvas) canvas).initGameCanvas(suppressKeys);
       
   170     }
       
   171 
       
   172     protected Object doGetGraphics(Object canvas) {
       
   173         return ((Canvas) canvas).getGameBufferGraphics();
       
   174     }
       
   175 
       
   176     protected Object doGetFlushLock(Object graphics) {
       
   177     	return ((Graphics) graphics).getLock();
       
   178     }
       
   179     
       
   180     protected int doGetKeyStates(Object canvas) {
       
   181         return ((Canvas) canvas).getGameKeyStates();
       
   182     }
       
   183 
       
   184     protected void doRenderGraphics(Object canvas, Object graphics) {
       
   185         ((Canvas) canvas).renderGraphics((Graphics) graphics);
       
   186     }
       
   187 
       
   188     protected void doFlushGraphics(Object canvas,
       
   189             int x, int y, int width, int height) {
       
   190         ((Canvas) canvas).flushGameBuffer(x, y, width, height);
       
   191     }
       
   192 
       
   193     protected String doGetDynamicProperty(String key) {
       
   194         if ("com.nokia.key.scancode".equals(key)) {
       
   195             return String.valueOf(ESWTUIThreadRunner.getLastKeyScancode());
       
   196         }
       
   197         else if ("com.nokia.key.modifier".equals(key)) {
       
   198             return String.valueOf(ESWTUIThreadRunner.getLastKeyModifier());
       
   199         }
       
   200         else if ("com.nokia.keyboard.type".equals(key)) {
       
   201             // TODO: eSWT support required
       
   202             /*
       
   203             No keypad (for example a touch device without keypad)   - None
       
   204             Standard ITU-T keypad (Phone keypad with 12 keys)       - PhoneKeypad
       
   205             QWERTY (4x12 layout)                                    - FullKeyboard
       
   206             QWERTY (limited, 4x10 layout)                           - LimitedKeyboard4x10
       
   207             QWERTY (limited, 3x11 layout)                           - LimitedKeyboard3x11
       
   208             Half QWERTY layout (aka Compact QWERTY keyboard).       - HalfKeyboard
       
   209             Custom QWERTY layout                                    - Custom
       
   210             Unknown layout                                          - Unknown
       
   211             */
       
   212             return "Unknown";
       
   213         }
       
   214         else if("com.nokia.softkey1.label.location".equals(key))
       
   215         {
       
   216         	  return getSoftKeyLabelLocationImpl(key);
       
   217         }
       
   218         else if("com.nokia.softkey1.label.anchor".equals(key))
       
   219         {
       
   220         	  return getSoftKeyLabelAnchorImpl(key);
       
   221         }
       
   222         else if("com.nokia.softkey2.label.location".equals(key))
       
   223         {
       
   224         	  return getSoftKeyLabelLocationImpl(key);
       
   225         }
       
   226         else if("com.nokia.softkey2.label.anchor".equals(key))
       
   227         {
       
   228         	  return getSoftKeyLabelAnchorImpl(key);
       
   229         }
       
   230         return "key not supported";
       
   231     }
       
   232 
       
   233     protected boolean doDetectCollision(Image image1, int transform1, int p1x, int p1y,
       
   234                                         int r1x1, int r1y1, int r1x2, int r1y2,
       
   235                                         Image image2, int transform2, int p2x, int p2y,
       
   236                                         int r2x1, int r2y1, int r2x2, int r2y2) {
       
   237 
       
   238         final org.eclipse.swt.graphics.Image eswtImg1 = Image.getESWTImage(image1);;
       
   239         final int ftransform1 = transform1;
       
   240         final int fp1x = p1x;
       
   241         final int fp1y = p1y;
       
   242         final int fr1x1 = r1x1;
       
   243         final int fr1y1 = r1y1;
       
   244         final int fr1x2 = r1x2;
       
   245         final int fr1y2 = r1y2;
       
   246 
       
   247         final org.eclipse.swt.graphics.Image eswtImg2 = Image.getESWTImage(image2);
       
   248         final int ftransform2 = transform2;
       
   249         final int fp2x = p2x;
       
   250         final int fp2y = p2y;
       
   251         final int fr2x1 = r2x1;
       
   252         final int fr2y1 = r2y1;
       
   253         final int fr2x2 = r2x2;
       
   254         final int fr2y2 = r2y2;
       
   255 
       
   256         eswtReturn = false;
       
   257         ESWTUIThreadRunner.safeSyncExec(new Runnable() {
       
   258             public void run() {
       
   259                 eswtReturn = org.eclipse.swt.internal.qt.graphics.Image.detectCollision(
       
   260                         Internal_GfxPackageSupport.getImage(eswtImg1), ftransform1, fp1x, fp1y,
       
   261                         fr1x1, fr1y1, fr1x2, fr1y2,
       
   262                         Internal_GfxPackageSupport.getImage(eswtImg2), ftransform2, fp2x, fp2y,
       
   263                         fr2x1, fr2y1, fr2x2, fr2y2);
       
   264             }
       
   265         });
       
   266         return eswtReturn;
       
   267     }
       
   268 
       
   269 }