uifw/EikStd/coctlsrc/EIKLBBUT.CPP
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 1997-1999 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 
       
    18 
       
    19 #include <barsread.h>
       
    20 #include <eiklbbut.h>
       
    21 #include <eikcmbut.h>
       
    22 #include <eikmnbut.h>
       
    23 #include <eiklabel.h>
       
    24 #include <eikenv.h>
       
    25 #include <eikpanic.h>
       
    26 #include <uikon.hrh>
       
    27 #include "laflbbut.h"
       
    28 
       
    29 /**
       
    30  * Writes the internal state of the control and its components to aStream.
       
    31  * Does nothing in release mode.
       
    32  * Designed to be overidden and base called by subclasses.
       
    33  *
       
    34  * @internal
       
    35  * @since App-Framework_6.1
       
    36  */
       
    37 #ifndef _DEBUG
       
    38 EXPORT_C void CEikLabeledButton::WriteInternalStateL(RWriteStream&) const
       
    39 	{}
       
    40 #else
       
    41 EXPORT_C void CEikLabeledButton::WriteInternalStateL(RWriteStream& aWriteStream) const
       
    42 	{
       
    43 	_LIT(KEikLitLbButCtlSt,"<CEikLabeledButton>");
       
    44 	_LIT(KEikLitLbButCtlEnd,"<\\CEikLabeledButton>");
       
    45 	_LIT(KEikLitLbButCtlHkey, "<iHotKeyCode>");
       
    46 	_LIT(KEikLitLbButCtlHkeyEnd, "<\\iHotKeyCode>");
       
    47 	_LIT(KEikLitLbButCtlFlags, "<iLButFlags>");
       
    48 	_LIT(KEikLitLbButCtlFlagsEnd, "<\\iLButFlags>");
       
    49 
       
    50 	aWriteStream << KEikLitLbButCtlSt;
       
    51 	aWriteStream << KEikLitLbButCtlHkey;
       
    52 	aWriteStream.WriteInt32L(iHotKeyCode);
       
    53 	aWriteStream << KEikLitLbButCtlHkeyEnd;
       
    54 	aWriteStream << KEikLitLbButCtlFlags;
       
    55 	aWriteStream.WriteInt32L(iLButFlags);
       
    56 	aWriteStream << KEikLitLbButCtlFlagsEnd;
       
    57 	CCoeControl::WriteInternalStateL(aWriteStream);
       
    58 	aWriteStream << KEikLitLbButCtlEnd;
       
    59 	}
       
    60 #endif
       
    61 
       
    62 EXPORT_C CEikLabeledButton::CEikLabeledButton()
       
    63 	{
       
    64 	SetComponentsToInheritVisibility(ETrue);
       
    65 	}
       
    66 
       
    67 EXPORT_C CEikLabeledButton::~CEikLabeledButton()
       
    68 	{
       
    69 	delete iButton;
       
    70 	delete iLabel;
       
    71 	}
       
    72 
       
    73 EXPORT_C void CEikLabeledButton::ConstructL(CEikCommandButtonBase* aButton,TInt aHotKeyCode,TInt aFlags)
       
    74 	{
       
    75 	__ASSERT_DEBUG(aButton,Panic(EEikPanicNullPointer));
       
    76 	iButton=aButton;
       
    77 	iButton->SetObserver(this);
       
    78 	iHotKeyCode=aHotKeyCode;
       
    79 	iLButFlags=aFlags;
       
    80 	CreateLabelL();
       
    81 	if(iLButFlags&EEikLabeledButtonIsDefault)
       
    82 		iButton->SetDefault(ETrue);
       
    83 	}
       
    84 
       
    85 EXPORT_C void CEikLabeledButton::ConstructFromResourceL(TResourceReader& aReader)
       
    86 	{
       
    87 	const TInt type=aReader.ReadInt16();
       
    88 	switch (type)
       
    89 		{
       
    90 	case EEikCtCommandButton:
       
    91 		iButton=new(ELeave) CEikCommandButton;
       
    92 		break;
       
    93 	case EEikCtMenuButton:
       
    94 		iButton=new(ELeave) CEikMenuButton;
       
    95 		break;
       
    96 	case EEikCtTextButton:
       
    97 		iButton=new(ELeave) CEikTextButton;
       
    98 		break;
       
    99 	case EEikCtBitmapButton:
       
   100 		iButton=new(ELeave) CEikBitmapButton;
       
   101 		break;
       
   102 	default:
       
   103 		Panic(EEikPanicLabeledButtonInvalidButtonType);
       
   104 		}
       
   105 	iButton->SetContainerWindowL(*this);
       
   106 	iButton->ConstructFromResourceL(aReader);
       
   107 	iButton->SetObserver(this);
       
   108 	iHotKeyCode=aReader.ReadInt32();
       
   109 	iLButFlags=aReader.ReadInt8();
       
   110 	CreateLabelL();
       
   111 	if(iLButFlags&EEikLabeledButtonIsDefault)
       
   112 		iButton->SetDefault(ETrue);
       
   113 	}
       
   114 
       
   115 EXPORT_C CEikCommandButtonBase* CEikLabeledButton::Button() const
       
   116 	{
       
   117 	return iButton;
       
   118 	}
       
   119 
       
   120 EXPORT_C CEikLabel* CEikLabeledButton::Label() const
       
   121 	{
       
   122 	return iLabel;
       
   123 	}
       
   124 
       
   125 EXPORT_C TInt CEikLabeledButton::HotKeyCode() const
       
   126 	{
       
   127 	return iHotKeyCode;
       
   128 	}
       
   129 
       
   130 EXPORT_C TBool CEikLabeledButton::ShowsHotKey() const
       
   131 	{
       
   132 	return (LafLabeledButton::ShowHotKey() ? iLButFlags&EShowHotKey: EFalse);
       
   133 	}
       
   134 
       
   135 EXPORT_C TBool CEikLabeledButton::PlainHotKey() const
       
   136 	{
       
   137 	return iLButFlags&EPlainHotKey;
       
   138 	}
       
   139 
       
   140 EXPORT_C TKeyResponse CEikLabeledButton::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   141 	{
       
   142 	if (!IsDimmed() && aType==EEventKey)
       
   143 		{
       
   144 		TBool consumed=EFalse;
       
   145 		if ((aKeyEvent.iModifiers & EAllStdModifiers) == EModifierCtrl)
       
   146 			consumed=(aKeyEvent.iCode==(TUint)iHotKeyCode && !(aKeyEvent.iModifiers&EModifierPureKeycode));
       
   147 		else
       
   148 			{
       
   149 			switch (iHotKeyCode)
       
   150 				{
       
   151 			case EEikBidCancel:
       
   152 				consumed=(aKeyEvent.iCode==EKeyEscape);
       
   153 				break;
       
   154 			case EEikBidOk:
       
   155 				consumed=(aKeyEvent.iCode==EKeyEnter);
       
   156 				break;
       
   157 // AKNLAF start
       
   158 			case EEikBidSelect:
       
   159 				consumed=(aKeyEvent.iCode==EKeyEnter);
       
   160 				break;
       
   161 // AKNLAF end
       
   162 			case EEikBidTab:
       
   163 				consumed=(aKeyEvent.iCode==EKeyTab);
       
   164 				break;
       
   165 			case EEikBidDelete:
       
   166 				consumed=(aKeyEvent.iCode==EKeyBackspace);
       
   167 				break;
       
   168 			case EEikBidSpace:
       
   169 				consumed=(aKeyEvent.iCode==EKeySpace);
       
   170 				break;
       
   171 			default:
       
   172 				{
       
   173 				consumed=(iLButFlags&EPlainHotKey && TCharF(aKeyEvent.iCode)==TCharF((TUint)iHotKeyCode));
       
   174 				break;
       
   175 				}
       
   176 				}
       
   177 			}
       
   178 		if (consumed)
       
   179 			{
       
   180 			iButton->Animate();
       
   181 			ReportEventL(MCoeControlObserver::EEventStateChanged);
       
   182 			return EKeyWasConsumed;
       
   183 			}
       
   184 		}
       
   185 	return EKeyWasNotConsumed;
       
   186 	}
       
   187 
       
   188 EXPORT_C TSize CEikLabeledButton::MinimumSize()
       
   189 	{
       
   190 	TSize size=iButton->MinimumSize();
       
   191 	//size.iHeight=Max(KMinButtonHeight,size.iHeight);
       
   192 	size.iHeight=Max(LafLabeledButton::MinimumButtonHeight(),size.iHeight);
       
   193 	const TSize labelSize=(ShowsHotKey()? iLabel->MinimumSize()+TSize(LafLabeledButton::HorizontalLabelMargin(),LafLabeledButton::VerticalLabelMargin()) : TSize());
       
   194 	size.iWidth=Max(size.iWidth,labelSize.iWidth);
       
   195 	size.iHeight+=labelSize.iHeight;
       
   196 	return size;
       
   197 	}
       
   198 
       
   199 EXPORT_C void CEikLabeledButton::SetContainerWindowL(const CCoeControl& aContainer)
       
   200 	{
       
   201 	CCoeControl::SetContainerWindowL(aContainer);
       
   202 	if (iButton)
       
   203 		iButton->SetContainerWindowL(aContainer);
       
   204 	if (iLabel)
       
   205 		iLabel->SetContainerWindowL(aContainer);
       
   206 	CopyControlContextFrom(&aContainer);
       
   207 	}
       
   208 
       
   209 EXPORT_C void CEikLabeledButton::SetDimmed(TBool aDimmed)
       
   210 	{
       
   211 	CCoeControl::SetDimmed(aDimmed);
       
   212 	if (iButton)
       
   213 		iButton->SetDimmed(aDimmed);
       
   214 	if (iLabel)
       
   215 		iLabel->SetDimmed(aDimmed);
       
   216 	}
       
   217 
       
   218 EXPORT_C TCoeInputCapabilities CEikLabeledButton::InputCapabilities() const
       
   219 	{
       
   220 	return TCoeInputCapabilities(LafLabeledButton::InputCapabilities());
       
   221 	}
       
   222 
       
   223 EXPORT_C void CEikLabeledButton::Animate()
       
   224 	{
       
   225 	if (iButton)
       
   226 		iButton->Animate();
       
   227 	}
       
   228 
       
   229 EXPORT_C void CEikLabeledButton::UpdateHotKey(TInt aKeyCode,TFlags aFlags)
       
   230 	{
       
   231 	iHotKeyCode=aKeyCode;
       
   232 	iLButFlags=aFlags;
       
   233 	TRAPD(err,UpdateHotKeyL());
       
   234 	if (err)
       
   235 		{
       
   236 		TPtrC text(KNullDesC);
       
   237 		__ASSERT_DEBUG_NO_LEAVE(iLabel->SetTextL(text)); // won't leave as we've already called SetBufferReserveLength during construction
       
   238 		}
       
   239 	}
       
   240 
       
   241 TInt CEikLabeledButton::CountComponentControls() const
       
   242 	{
       
   243 	return 2;
       
   244 	}
       
   245 
       
   246 CCoeControl* CEikLabeledButton::ComponentControl(TInt aIndex) const
       
   247 	{
       
   248 	if (aIndex==0)
       
   249 		return iButton;
       
   250 	else if (aIndex==1)
       
   251 		return iLabel;
       
   252 	return NULL;
       
   253 	}
       
   254 
       
   255 void CEikLabeledButton::SizeChanged()
       
   256 	{
       
   257 	//const TSize butSize(iSize.iWidth,Max(KMinButtonHeight,iButton->MinimumSize().iHeight));
       
   258 	const TSize butSize(iSize.iWidth,Max(LafLabeledButton::MinimumButtonHeight(),iButton->MinimumSize().iHeight));
       
   259 	iButton->SetExtent(iPosition,butSize);
       
   260 	iLabel->SetExtent(TPoint(iPosition.iX,iPosition.iY+butSize.iHeight),
       
   261 						TSize(iSize.iWidth,iSize.iHeight-butSize.iHeight));
       
   262 	}
       
   263 
       
   264 void CEikLabeledButton::HandleControlEventL(CCoeControl* /*aControl*/,TCoeEvent aEventType)
       
   265 	{
       
   266 	ReportEventL(aEventType);
       
   267 	}
       
   268 
       
   269 void CEikLabeledButton::CreateLabelL()
       
   270 	{
       
   271 	iLabel=new(ELeave) CEikLabel;
       
   272 	iLabel->SetContainerWindowL(*this);
       
   273 	iLabel->CopyControlContextFrom(this);
       
   274 	iLabel->SetBufferReserveLengthL(LafLabeledButton::MaxLabelTextLengthInChars());
       
   275 	UpdateHotKeyL();
       
   276 	iLabel->SetFont(iEikonEnv->AnnotationFont());
       
   277 	iLabel->SetAlignment(LafLabeledButton::LabelAlignment());
       
   278 	}
       
   279 
       
   280 void CEikLabeledButton::UpdateHotKeyL()
       
   281 	{
       
   282 	TPtrC text;
       
   283 	if (iHotKeyCode<=EEikBidCancel && iHotKeyCode>=EEikBidSpace)
       
   284 		{
       
   285 		if (ShowsHotKey())
       
   286 			text.Set(iEikonEnv->KeyPressLabel(EEikBidCancel-iHotKeyCode));
       
   287 		}
       
   288 	else
       
   289 		{
       
   290 		if (/*iHotKeyCode && */ShowsHotKey())
       
   291 			{
       
   292 			if (PlainHotKey())
       
   293 				{
       
   294 				TBuf<1> buf;
       
   295 				buf.Append(TChar(iHotKeyCode));
       
   296 				text.Set(buf);
       
   297 				}
       
   298 			else
       
   299 				{
       
   300 				TBuf<10> defaultText = iEikonEnv->KeyPressLabel((EEikBidCancel)-(EEikBidSpace)+1);
       
   301 				const TInt len=defaultText.Length();
       
   302 				defaultText[len-1]=(TInt8)iHotKeyCode;
       
   303 				text.Set(defaultText);
       
   304 				}
       
   305 			}
       
   306 		if (!PlainHotKey())
       
   307 			{
       
   308 			if (iHotKeyCode>='A' && iHotKeyCode<='Z')
       
   309 				iHotKeyCode-='A'-1;
       
   310 			else
       
   311 				iHotKeyCode-='a'-1;
       
   312 			}
       
   313 		}
       
   314 	iLabel->SetTextL(text);
       
   315 	}
       
   316 
       
   317 /**
       
   318  * Gets the list of logical colors employed in the drawing of the control,
       
   319  * paired with an explanation of how they are used. Appends the list to aColorUseList.
       
   320  *
       
   321  * @since ER5U 
       
   322  */
       
   323 EXPORT_C void CEikLabeledButton::GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList) const
       
   324 	{
       
   325 	CCoeControl::GetColorUseListL(aColorUseList);	
       
   326 	}
       
   327 
       
   328 /**
       
   329  * Handles a change to the control's resources of type aType
       
   330  * which are shared across the environment, e.g. colors or fonts.
       
   331  *
       
   332  * @since ER5U 
       
   333  */
       
   334 EXPORT_C void CEikLabeledButton::HandleResourceChange(TInt aType)
       
   335 	{
       
   336 	CCoeControl::HandleResourceChange(aType);
       
   337 	}
       
   338 
       
   339 EXPORT_C void CEikLabeledButton::HandlePointerEventL(const TPointerEvent& aPointerEvent) 
       
   340     { 
       
   341     CAknControl::HandlePointerEventL(aPointerEvent); 
       
   342     }
       
   343 
       
   344 EXPORT_C void* CEikLabeledButton::ExtensionInterface( TUid /*aInterface*/ )
       
   345     {
       
   346     return NULL;
       
   347     }
       
   348 
       
   349 void CEikLabeledButton::Reserved_2()
       
   350 	{}