javauis/lcdui_akn/lcdui/src/CMIDComponentFactory.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2003-2006 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 // Using debug macros.
       
    19 #include <j2me/jdebug.h>
       
    20 
       
    21 #include <coecntrl.h>
       
    22 #include <lcdui.h>
       
    23 //
       
    24 #include "CMIDDisplayable.h"
       
    25 #include "CMIDTicker.h"
       
    26 #include "CMIDForm.h"
       
    27 // needed for creating alert
       
    28 #include "CMIDAlert.h"
       
    29 #include "CMIDCanvas.h"
       
    30 // needed for creating font
       
    31 #include "CMIDFont.h"
       
    32 #include "CMIDItem.h"
       
    33 #include "CMIDControlItem.h"
       
    34 // needed for creating image item
       
    35 #include "CMIDImageItem.h"
       
    36 // needed for creating string item
       
    37 #include "CMIDStringItem.h"
       
    38 // needed for creating date field item
       
    39 #include "CMIDDateFieldItem.h"
       
    40 // needed for creating gauge
       
    41 #include "CMIDGaugeItem.h"
       
    42 // needed for creating text box control
       
    43 #include "CMIDTextBoxControl.h"
       
    44 // needed for creating popup text box control
       
    45 #include "CMIDTextBoxDialogControl.h"
       
    46 // needed for creating text field item
       
    47 #include "CMIDTextFieldItem.h"
       
    48 // needed for creating utils
       
    49 #include "CMIDUtils.h"
       
    50 // for iUIManager member
       
    51 #include "CMIDUIManager.h"
       
    52 #include "CMIDCommand.h"
       
    53 // needed for creating spacer
       
    54 #include "CMIDSpacer.h"
       
    55 // needed for creating custom item
       
    56 #include "CMIDCustomItem.h"
       
    57 #include "CMIDComponentFactory.h"
       
    58 // needed for creating list
       
    59 #include "CMIDList.h"
       
    60 // needed for creating choice group
       
    61 #include "CMIDChoiceGroupItem.h"
       
    62 // needed for creating text editor
       
    63 #include "CMIDTextEditor.h"
       
    64 // needed for creating canvas graphics item
       
    65 #include "CMIDCanvasGraphicsItem.h"
       
    66 #include "CMIDCanvasGraphicsItemPainter.h"
       
    67 
       
    68 CMIDComponentFactory::CMIDComponentFactory() : iUtils(NULL)
       
    69 {
       
    70 }
       
    71 
       
    72 CMIDComponentFactory::~CMIDComponentFactory()
       
    73 {
       
    74     displayableCreated = EFalse;
       
    75     delete iUIManager;
       
    76     if (iUtils)
       
    77     {
       
    78         iUtils->Dispose();
       
    79         iUtils = NULL;
       
    80     }
       
    81 }
       
    82 
       
    83 /**
       
    84  *
       
    85  * ComponentFactory implementation
       
    86  *
       
    87  */
       
    88 void CMIDComponentFactory::ConstructL(MMIDEnv& aEnv)
       
    89 {
       
    90     iEnv = &aEnv;
       
    91     displayableCreated = EFalse;
       
    92     iUIManager = CMIDUIManager::NewL(aEnv);
       
    93 }
       
    94 
       
    95 MMIDDisplayable* CMIDComponentFactory::CreateDisplayableL()
       
    96 {
       
    97     return CMIDDisplayable::NewL(*iEnv,*iUIManager);
       
    98 }
       
    99 
       
   100 MMIDCanvas* CMIDComponentFactory::CreateCanvasL(
       
   101     MMIDDisplayable& aDisplayable,MMIDComponent::TType aCanvasType)
       
   102 {
       
   103     CCoeControl& window = static_cast< CMIDDisplayable& >(aDisplayable).ContentWindow();
       
   104     displayableCreated = ETrue;
       
   105     return CMIDCanvas::NewL(*iEnv, window, aCanvasType);
       
   106 }
       
   107 
       
   108 MMIDAlert* CMIDComponentFactory::CreateAlertL(MMIDDisplayable& aDisplayable,MMIDAlert::TAlertType aType,const TDesC& aString,MMIDImage* aImage)
       
   109 {
       
   110     if (!iUIManager->OpenMenuHandlerL()->GetDisplayable() && !displayableCreated)
       
   111     {
       
   112         iUIManager->OpenDefaultDisplayableL(ETrue);
       
   113     }
       
   114     return CMIDAlert::NewL(
       
   115                *iEnv, aType, aDisplayable, aString, aImage, GetUtils());
       
   116 }
       
   117 
       
   118 MMIDForm* CMIDComponentFactory::CreateFormL(MMIDDisplayable& aDisplayable)
       
   119 {
       
   120     displayableCreated = ETrue;
       
   121     return CMIDForm::NewL(*iEnv,aDisplayable);
       
   122 }
       
   123 
       
   124 MMIDList* CMIDComponentFactory::CreateListL(TInt aType,MMIDDisplayable& aDisplayable,RArray<TPtrC>& aStringArray, RArray<MMIDImage*>& aImageArray)
       
   125 {
       
   126     displayableCreated = ETrue;
       
   127     return CMIDList::NewL(*iEnv,aDisplayable,aType,aStringArray,aImageArray);
       
   128 }
       
   129 
       
   130 MMIDTextBox* CMIDComponentFactory::CreateTextBoxL(TInt aConstraints, TInt aMaxSize, const TDesC& aText, MMIDDisplayable& aDisplayable)
       
   131 {
       
   132     if (iEnv->MidletAttributeContainsVal(LcduiMidletAttributes::KAttribUIEnhancement, LcduiMidletAttributeValues::KUIEnhFullScreenTextBox))
       
   133     {
       
   134         return CMIDTextBoxControl::NewL(aConstraints, aText, aMaxSize, &aDisplayable);
       
   135     }
       
   136     else
       
   137     {
       
   138         if (!iUIManager->OpenMenuHandlerL()->GetDisplayable() && !displayableCreated)
       
   139         {
       
   140             iUIManager->OpenDefaultDisplayableL(ETrue);
       
   141         }
       
   142         return CMIDTextBoxDialogControl::NewL(aConstraints, aText, aMaxSize, &aDisplayable);
       
   143     }
       
   144 }
       
   145 
       
   146 MMIDImageItem* CMIDComponentFactory::CreateImageItemL(
       
   147     const TDesC& aLabel, MMIDImage* aImage, MMIDItem::TLayout aLayout,
       
   148     MMIDItem::TAppearance aAppearance, const TDesC& aAltText)
       
   149 {
       
   150     return CMIDImageItem::NewL(aLabel, aImage, aLayout, aAppearance, aAltText, iUIManager);
       
   151 }
       
   152 
       
   153 MMIDCustomItem* CMIDComponentFactory::CreateCustomItemL(const TDesC& aLabel)
       
   154 {
       
   155     return CMIDCustomItem::NewL(*iEnv, aLabel, iUIManager);
       
   156 }
       
   157 
       
   158 MMIDStringItem* CMIDComponentFactory::CreateStringItemL(const TDesC& aLabel,const TDesC& aText,MMIDItem::TAppearance aAppearance)
       
   159 {
       
   160     return CMIDStringItem::NewL(aLabel, aText, aAppearance, iUIManager);
       
   161 }
       
   162 
       
   163 MMIDDateField* CMIDComponentFactory::CreateDateFieldL(
       
   164     const TDesC& aLabel, MMIDDateField::TFieldType aFieldType)
       
   165 {
       
   166     return CMIDDateFieldItem::NewL(aLabel, aFieldType, iUIManager);
       
   167 }
       
   168 
       
   169 MMIDGauge* CMIDComponentFactory::CreateGaugeL(
       
   170     const TDesC& aLabel, TBool aInteractive, TInt aMaxValue, TInt aInitialValue)
       
   171 {
       
   172     if (aInteractive)
       
   173     {
       
   174         return CMIDInteractiveGauge::NewL(aLabel, aMaxValue, aInitialValue, iUIManager);
       
   175     }
       
   176     else
       
   177     {
       
   178         return CMIDNonInteractiveGauge::NewL(aLabel, aMaxValue, aInitialValue , iUIManager);
       
   179     }
       
   180 }
       
   181 
       
   182 MMIDTextField* CMIDComponentFactory::CreateTextFieldL(
       
   183     const TDesC& aLabel, const TDesC& aText, TInt aConstraints, TInt aMaxSize)
       
   184 {
       
   185     if (!iUIManager->OpenMenuHandlerL()->GetDisplayable())
       
   186     {
       
   187         iUIManager->OpenDefaultDisplayableL(EFalse);
       
   188     }
       
   189     return CMIDTextFieldItem::NewL(aLabel, aText, aConstraints, aMaxSize, iUIManager);
       
   190 }
       
   191 
       
   192 MMIDChoiceGroup* CMIDComponentFactory::CreateChoiceGroupL(
       
   193     const TDesC& aLabel, TInt aType, RArray<TPtrC>& aStringArray, RArray<MMIDImage*>& aImageArray)
       
   194 {
       
   195     return CMIDChoiceGroupItem::NewL(
       
   196                *iEnv, aLabel, aType, aStringArray, aImageArray, iUIManager);
       
   197 }
       
   198 
       
   199 MMIDSpacer* CMIDComponentFactory::CreateSpacerL(const TSize& aMinimumSize)
       
   200 {
       
   201     return CMIDSpacer::NewL(aMinimumSize, iUIManager);
       
   202 }
       
   203 
       
   204 MMIDFont* CMIDComponentFactory::CreateFontL(
       
   205     TUint aStyle, TUint aSize, TInt aFace, TBool aIsFreeSizeFont)
       
   206 {
       
   207     return CMIDFont::NewL(aStyle, aSize, aFace, iUIManager, aIsFreeSizeFont);
       
   208 }
       
   209 
       
   210 MMIDTicker* CMIDComponentFactory::CreateTickerL(const TDesC& aText)
       
   211 {
       
   212     return CMIDTicker::NewL(aText);
       
   213 }
       
   214 
       
   215 MMIDCommand* CMIDComponentFactory::CreateCommandL(
       
   216     const TDesC& aShortLabel, const TDesC& aLongLabel,
       
   217     MMIDCommand::TCommandType aCommandType, TInt aPriority, TInt aCommandID)
       
   218 {
       
   219     return CMIDCommand::NewL(aShortLabel,aLongLabel,aCommandType,aPriority,aCommandID);
       
   220 }
       
   221 
       
   222 MMIDUtils* CMIDComponentFactory::CreateUtilsL()
       
   223 {
       
   224     return CMIDUtils::NewL(*iEnv, iUIManager);
       
   225 }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // CMIDComponentFactory::CreateTextEditorL
       
   229 // (other items are commented in the header file)
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 MMIDTextEditor* CMIDComponentFactory::CreateTextEditorL(
       
   233     TInt aMaxSize,
       
   234     TInt aWidth,
       
   235     TInt aHeight,
       
   236     TBool aHeightInRows)
       
   237 {
       
   238     DEBUG("CMIDComponentFactory::CreateTextEditorL +");
       
   239 
       
   240     CMIDTextEditor::TCtorParams params;
       
   241 
       
   242     params.iMaxSize = aMaxSize;
       
   243     params.iWidth = aWidth;
       
   244     params.iHeight = aHeight;
       
   245     params.iHeightInRows = aHeightInRows;
       
   246     params.iUtils = GetUtils();
       
   247 
       
   248     MMIDTextEditor* editor = CMIDTextEditor::NewL(params);
       
   249 
       
   250     DEBUG("CMIDComponentFactory::CreateTextEditorL -");
       
   251 
       
   252     return editor;
       
   253 }
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // CMIDComponentFactory::CreateCanvasGraphicsItemL
       
   257 // (other items are commented in the header file)
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 MMIDCanvasGraphicsItem* CMIDComponentFactory::CreateCanvasGraphicsItemL(
       
   261     MMIDCanvasGraphicsItemPainter* aItemPainter)
       
   262 {
       
   263     DEBUG("CMIDComponentFactory::CreateCanvasGraphicsItemL +");
       
   264 
       
   265     CMIDCanvasGraphicsItem::TCtorParams params;
       
   266 
       
   267     params.iPainterHandle =
       
   268         static_cast<CMIDCanvasGraphicsItemPainter*>(aItemPainter);
       
   269     params.iUtils = GetUtils();
       
   270 
       
   271     MMIDCanvasGraphicsItem* item = CMIDCanvasGraphicsItem::NewL(params);
       
   272 
       
   273     DEBUG("CMIDComponentFactory::CreateCanvasGraphicsItemL -");
       
   274 
       
   275     return item;
       
   276 }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CMIDComponentFactory::CreateCanvasGraphicsItemPainterL
       
   280 // (other items are commented in the header file)
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 MMIDCanvasGraphicsItemPainter*
       
   284 CMIDComponentFactory::CreateCanvasGraphicsItemPainterL(
       
   285     TInt aWidth,
       
   286     TInt aHeight)
       
   287 {
       
   288     DEBUG("CMIDComponentFactory::CreateCanvasGraphicsItemPainterL +");
       
   289 
       
   290     CMIDCanvasGraphicsItemPainter::TCtorParams params;
       
   291 
       
   292     params.iWidth = aWidth;
       
   293     params.iHeight = aHeight;
       
   294     params.iEnv = iEnv;
       
   295 
       
   296     MMIDCanvasGraphicsItemPainter* itemPainter =
       
   297         CMIDCanvasGraphicsItemPainter::NewL(params);
       
   298 
       
   299     DEBUG("CMIDComponentFactory::CreateCanvasGraphicsItemPainterL -");
       
   300 
       
   301     return itemPainter;
       
   302 }
       
   303 
       
   304 void CMIDComponentFactory::Dispose()
       
   305 {
       
   306     delete this;
       
   307 }
       
   308 
       
   309 CMIDUtils* CMIDComponentFactory::GetUtils()
       
   310 {
       
   311     // If iUtils is not initialized, this method will initialized it.
       
   312     if (!iUtils)
       
   313     {
       
   314 
       
   315         TRAPD(err, iUtils = static_cast<CMIDUtils*>(CreateUtilsL()));
       
   316         if (err != KErrNone)
       
   317         {
       
   318             DEBUG_INT("CMIDComponentFactory::GetUtils - error %d", err);
       
   319             iUtils = NULL;
       
   320         }
       
   321 
       
   322     }
       
   323     // Return shared instance of CMIDUtils: iUtils.
       
   324     return iUtils;
       
   325 }
       
   326 
       
   327 // End of File