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