imageeditor/plugins/TextPlugin/src/ImageEditorTextPlugin.cpp
changeset 1 edfc90759b9f
equal deleted inserted replaced
0:57d4cdd99204 1:edfc90759b9f
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description: 
       
    16 * Text plugin class.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #include <aknquerydialog.h> 
       
    23 
       
    24 #include "ImageEditorTextPlugin.h"
       
    25 #include "ImageEditorTextControl.h"
       
    26 #include "ImageEditorPluginBaseDefs.h"
       
    27 #include "DrawUtils.h"
       
    28 #include "SystemParameters.h"
       
    29 
       
    30 #ifdef TEXT_INSERTION_IN_PORTRAIT_ONLY
       
    31 #include <aknappui.h>
       
    32 #endif
       
    33 
       
    34 //	CONSTANTS
       
    35 _LIT (KPgnResourceFile, "text.rsc");
       
    36 
       
    37 
       
    38 //=============================================================================
       
    39 EXPORT_C CImageEditorPluginBase * CreateImageEditorPlugin ()
       
    40 {
       
    41 	CImageEditorTextPlugin * plugin = new (ELeave) CImageEditorTextPlugin;
       
    42 	CleanupStack::PushL(plugin);
       
    43 	plugin->ConstructL();
       
    44 	CleanupStack::Pop(); // plugin
       
    45     return plugin;
       
    46 }
       
    47 
       
    48 //=============================================================================
       
    49 CImageEditorTextPlugin::CImageEditorTextPlugin () : iLandscapeEnabled(EFalse)
       
    50 {
       
    51 
       
    52 }
       
    53 
       
    54 //=============================================================================
       
    55 void CImageEditorTextPlugin::ConstructL ()
       
    56 {
       
    57     CImageEditorPluginBase::ConstructL (KPgnResourcePath, KPgnResourceFile);
       
    58 }
       
    59 
       
    60 //=============================================================================
       
    61 CImageEditorTextPlugin::~CImageEditorTextPlugin ()
       
    62 {
       
    63     ReleasePlugin();
       
    64     iSysPars = NULL;
       
    65 }
       
    66 
       
    67 //=============================================================================
       
    68 TInt CImageEditorTextPlugin::SetProperty (
       
    69 	TInt		aPropertyId, 
       
    70 	TDesC &		aPropertyValue
       
    71 	)
       
    72 {
       
    73 
       
    74     TInt err = KErrNone;
       
    75     TLex parser;
       
    76 
       
    77 	//	Copy data
       
    78 	switch (aPropertyId) 
       
    79 	{
       
    80 		case KCapSystemParameters:
       
    81 		{
       
    82 			parser.Assign (aPropertyValue);
       
    83             TInt tempval = 0;
       
    84             parser.Val (tempval);
       
    85             iSysPars = (const CSystemParameters *)tempval;
       
    86 			err = KErrNone;
       
    87             break;
       
    88 		}
       
    89 		default:
       
    90 		{
       
    91 			err = CImageEditorPluginBase::SetProperty (aPropertyId, aPropertyValue);
       
    92             break;
       
    93 		}
       
    94 	}
       
    95     return err;
       
    96 }
       
    97 
       
    98 //=============================================================================
       
    99 TInt CImageEditorTextPlugin::GetProperty (
       
   100 	TInt		aPropertyId, 
       
   101 	TDes &		aPropertyValue
       
   102 	)
       
   103 {
       
   104 	//	Clean buffer
       
   105 	aPropertyValue.Zero();
       
   106 
       
   107 	//	Copy data
       
   108 	switch (aPropertyId) 
       
   109 	{
       
   110 		case KCapParamStruct:
       
   111 		{
       
   112 			// Control found
       
   113 			if (iControl)
       
   114 			{
       
   115 				aPropertyValue.Copy ( ((CImageEditorTextControl *)iControl)->GetParam() );
       
   116 				return KErrNone;
       
   117 			}
       
   118 
       
   119 			//	Control not found, return KErrNotReady
       
   120 			else
       
   121 			{
       
   122 				return KErrNotReady;
       
   123 			}
       
   124 		}
       
   125         case KCapReadyToRender:
       
   126 		{
       
   127             TBool readytorender = ETrue;
       
   128             if (iControl)
       
   129                 {
       
   130                 readytorender = ((CImageEditorTextControl *)iControl)->IsReadyToRender();
       
   131                 }
       
   132 			aPropertyValue.AppendNum ((TInt)readytorender);
       
   133 			return KErrNone;
       
   134 		}
       
   135         case KCapIsLandscapeEnabled:
       
   136 		{
       
   137 			aPropertyValue.AppendNum ((TInt)iLandscapeEnabled);
       
   138 			return KErrNone;
       
   139 		}
       
   140         case KCapIsSlowPlugin:
       
   141 		{
       
   142 			aPropertyValue.AppendNum ((TInt)ETrue);
       
   143 			return KErrNone;
       
   144 		}
       
   145 		default:
       
   146 		{
       
   147 			return CImageEditorPluginBase::GetProperty (aPropertyId, aPropertyValue);
       
   148 		}
       
   149 	}
       
   150 }
       
   151 
       
   152 //=============================================================================
       
   153 TInt CImageEditorTextPlugin::InitPluginL (
       
   154 	const TRect &		aRect,
       
   155 	CCoeControl *		aParent,
       
   156 	CCoeControl *&		aPluginControl
       
   157 	)
       
   158 {
       
   159     //  Delete previous control
       
   160 	ReleasePlugin();
       
   161 
       
   162     TInt ret = KErrNone;
       
   163 
       
   164 	//	Get pointer to the parameter descriptor array
       
   165 	TBuf<256>  readbuf;  
       
   166 	TLex       parser;
       
   167 	User::LeaveIfError ( CImageEditorPluginBase::GetProperty (KCapPluginParamNames, readbuf) );
       
   168 	parser.Assign (readbuf);
       
   169 	TInt tempval = 0;
       
   170 	parser.Val ( tempval );
       
   171 	CDesCArray * pars = (CDesCArray *)tempval;
       
   172 
       
   173 	CEikonEnv* env = CEikonEnv::Static();
       
   174 
       
   175 #ifdef TEXT_INSERTION_IN_PORTRAIT_ONLY
       
   176     // Text input is always insterted in portrait mode.
       
   177 	// Store the original orientation before forcing to portrait.
       
   178     CAknAppUiBase* appUi = static_cast<CAknAppUiBase *>( env->EikAppUi() );
       
   179 	CAknAppUiBase::TAppUiOrientation originalOrientation = appUi->Orientation();
       
   180     appUi->SetOrientationL(CAknAppUiBase::EAppUiOrientationPortrait);
       
   181 #endif
       
   182 
       
   183     TRAPD(err,
       
   184 
       
   185     TBuf<256> text;
       
   186     TBuf<64> prompt;
       
   187     prompt.Copy ( (*pars)[0] );
       
   188 
       
   189     TInt ok = SDrawUtils::LaunchMultiLineTextQueryDialogL ( text, prompt );
       
   190 
       
   191     //  Create new control
       
   192     if (ok)
       
   193     {
       
   194         iControl = CImageEditorTextControl::NewL (aRect, aParent);
       
   195         aPluginControl = iControl;
       
   196         
       
   197         //  Set system parameters
       
   198         ((CImageEditorTextControl*)iControl)->SetSystemParameters (iSysPars);
       
   199 
       
   200         //  Set the text
       
   201         ((CImageEditorTextControl*)iControl)->SetTextL  ( text );
       
   202 
       
   203         iLandscapeEnabled = ETrue;
       
   204         
       
   205         ret = KErrNone;
       
   206     }
       
   207     else
       
   208     {
       
   209         aPluginControl = 0;
       
   210         ret = KErrNotSupported;
       
   211     }
       
   212 
       
   213     ) // TRAP
       
   214 
       
   215 
       
   216 #ifdef TEXT_INSERTION_IN_PORTRAIT_ONLY
       
   217     // Set always back to original orientation, even if leaves
       
   218 	CAknAppUiBase::TAppUiOrientation orientation = appUi->Orientation();
       
   219 
       
   220 	if (orientation != originalOrientation)
       
   221 		{
       
   222 		appUi->SetOrientationL(originalOrientation);
       
   223 
       
   224 		// Send screen device change event to validate screen
       
   225 		TWsEvent event;
       
   226 
       
   227 		RWsSession& rws = env->WsSession();
       
   228 		event.SetType( EEventScreenDeviceChanged );
       
   229 		event.SetTimeNow(); 
       
   230 		event.SetHandle( rws.WsHandle() ); 
       
   231 
       
   232 		User::LeaveIfError( rws.SendEventToAllWindowGroups(event) );
       
   233 		}
       
   234 #else
       
   235 #ifdef LANDSCAPE_ONLY
       
   236 
       
   237 	appUi->SetOrientationL(CAknAppUiBase::EAppUiOrientationLandscape);
       
   238 
       
   239 	// Send screen device change event to validate screen
       
   240 	TWsEvent event;
       
   241 
       
   242 	RWsSession& rws = env->WsSession();
       
   243 	event.SetType( EEventScreenDeviceChanged );
       
   244 	event.SetTimeNow(); 
       
   245 	event.SetHandle( rws.WsHandle() ); 
       
   246 
       
   247 	User::LeaveIfError( rws.SendEventToAllWindowGroups(event) );
       
   248 	
       
   249 #endif
       
   250 #endif
       
   251 
       
   252 
       
   253     if (err)
       
   254         {
       
   255         User::Leave(err);
       
   256         }
       
   257 
       
   258     return ret;
       
   259 }
       
   260 
       
   261 //=============================================================================
       
   262 void CImageEditorTextPlugin::ProcessImageL (CEditorImage * /*aImage*/ )
       
   263 {
       
   264 
       
   265 }
       
   266 
       
   267 //=============================================================================
       
   268 void CImageEditorTextPlugin::ReleasePlugin ()
       
   269 {
       
   270 	delete iControl;
       
   271 	iControl = NULL;
       
   272 }
       
   273 
       
   274 // End of File