uifw/EikStd/coctlsrc/EIKBUTB.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 <eikbutb.h>
       
    20 #include <coemain.h>
       
    21 #include "LAFBUTB.H"
       
    22 
       
    23 const TInt KButtonStateMask             =0x000f;
       
    24 const TInt KButtonPressedMask           =0x0010;
       
    25 const TInt KButtonDrawStateMask         =0x001f;
       
    26 const TInt KButtonReportOnPointerDown	=0x0020;
       
    27 const TInt KButtonTristate	            =0x0040;
       
    28 const TInt KButtonAllowTristate	        =0x0080;
       
    29 const TInt KButtonBehaviorMask			=0x0f00;
       
    30 
       
    31 const TInt KAnimationDelayInMicroSeconds=50000;
       
    32 
       
    33 /**
       
    34  * Gets the list of logical colors employed in the drawing of the control,
       
    35  * paired with an explanation of how they are used. Appends the list to aColorUseList.
       
    36  *
       
    37  * @since ER5U 
       
    38  */
       
    39 EXPORT_C void CEikButtonBase::GetColorUseListL(CArrayFix<TCoeColorUse>& /*aColorUseList*/) const
       
    40 	{
       
    41 	}
       
    42 
       
    43 /**
       
    44  * Handles a change to the control's resources of type aType
       
    45  * which are shared across the environment, e.g. colors or fonts.
       
    46  *
       
    47  * @since ER5U 
       
    48  */
       
    49 EXPORT_C void CEikButtonBase::HandleResourceChange(TInt aType)
       
    50 	{
       
    51 	CCoeControl::HandleResourceChange(aType);
       
    52 	}
       
    53 
       
    54 EXPORT_C CEikButtonBase::~CEikButtonBase()
       
    55     {
       
    56 	}
       
    57 
       
    58 EXPORT_C CEikButtonBase::CEikButtonBase()
       
    59     {
       
    60 	__DECLARE_NAME(_S("CEikButtonBase"));
       
    61     }
       
    62 
       
    63 EXPORT_C void CEikButtonBase::SetCoordinator(TEikButtonCoordinator* aButCoord)
       
    64 	{
       
    65 	iButCoord=aButCoord;
       
    66 	}
       
    67 
       
    68 EXPORT_C CEikButtonBase::TState CEikButtonBase::State() const
       
    69     {
       
    70     return((TState)(iButFlags&KButtonStateMask));
       
    71     }
       
    72 
       
    73 EXPORT_C void CEikButtonBase::SetState(TState aState)
       
    74     {
       
    75     iButFlags&=(~KButtonStateMask);
       
    76     iButFlags|=aState;
       
    77     if (aState==EIndeterminate && iButFlags&KButtonAllowTristate)
       
    78         iButFlags|=KButtonTristate;
       
    79 	if (aState==ESet && iButCoord)
       
    80 		iButCoord->SetChosenButton(this);
       
    81     StateChanged();
       
    82     }
       
    83 
       
    84 EXPORT_C void CEikButtonBase::StateChanged()
       
    85 	{
       
    86 	}
       
    87 
       
    88 EXPORT_C TBool CEikButtonBase::IsPressed() const
       
    89     {
       
    90     return(iButFlags&KButtonPressedMask);
       
    91     }
       
    92 
       
    93 EXPORT_C CEikButtonBase::TDrawState CEikButtonBase::DrawState() const
       
    94     {
       
    95     return((TDrawState)(iButFlags&KButtonDrawStateMask));
       
    96     }
       
    97 
       
    98 EXPORT_C void CEikButtonBase::CopyDrawStateTo(CEikButtonBase* aTargetButton) const
       
    99     { // intended to be called from inside the StateChanged() function of a container button
       
   100     aTargetButton->iButFlags&=(~KButtonDrawStateMask);
       
   101     aTargetButton->iButFlags|=DrawState();
       
   102     }
       
   103 
       
   104 EXPORT_C void CEikButtonBase::SetReportOnPointerDown()
       
   105     {
       
   106     iButFlags|=KButtonReportOnPointerDown;
       
   107     }
       
   108 
       
   109 EXPORT_C void CEikButtonBase::SetBehavior(TButtonBehavior aType)
       
   110     {
       
   111     if (aType&EEikButtonReportsOnPointerDown)
       
   112 		SetReportOnPointerDown();
       
   113 	iButFlags&=(~KButtonBehaviorMask);
       
   114     iButFlags|=(aType&(~EEikButtonReportsOnPointerDown));
       
   115     }
       
   116 
       
   117 EXPORT_C TKeyResponse CEikButtonBase::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   118     {
       
   119 	const TInt code=aKeyEvent.iCode;
       
   120 	if (code==EKeyDownArrow || code ==EKeyUpArrow)
       
   121 		return(EKeyWasNotConsumed);
       
   122     if (aType!=EEventKey)
       
   123         return(EKeyWasConsumed);
       
   124 	CEikButtonBase::TState oldState=State();
       
   125    	switch (code)
       
   126         {
       
   127 	case EKeyLeftArrow:
       
   128 	case EKeyTab:
       
   129     case EKeyRightArrow:
       
   130 		Animate();
       
   131 	default:
       
   132 		;
       
   133 		}
       
   134 	TKeyResponse ret=EKeyWasNotConsumed;
       
   135 	if (State()!=oldState)
       
   136 		{
       
   137 		ReportEventL(MCoeControlObserver::EEventStateChanged);
       
   138 		ret=EKeyWasConsumed;
       
   139 		}
       
   140     return ret;
       
   141 	}
       
   142 
       
   143 EXPORT_C void CEikButtonBase::HandlePointerEventL(const TPointerEvent& /*aPointerEvent*/)
       
   144     {
       
   145     }
       
   146 
       
   147 EXPORT_C void* CEikButtonBase::ExtensionInterface( TUid /*aInterface*/ )
       
   148     {
       
   149     return NULL;
       
   150     }
       
   151 
       
   152 EXPORT_C TCoeInputCapabilities CEikButtonBase::InputCapabilities() const
       
   153 	{
       
   154 	return LafButtonBase::InputCapabilities();
       
   155 	}
       
   156 
       
   157 TBool CEikButtonBase::ClickCompleted()
       
   158     {
       
   159     TButtonBehavior behav=(TButtonBehavior)(iButFlags&KButtonBehaviorMask);
       
   160     switch (State())
       
   161         {
       
   162     case EClear:
       
   163         if (behav==EEikButtonStaysClear)
       
   164             return(EFalse);
       
   165         SetState(iButFlags&KButtonTristate? EIndeterminate: ESet);
       
   166         break;
       
   167     case ESet:
       
   168 		if (iButCoord || behav==EEikButtonStaysSet)
       
   169             return(EFalse);
       
   170         SetState(EClear);
       
   171         break;
       
   172     case EIndeterminate:
       
   173         SetState(ESet);
       
   174         break;
       
   175         }
       
   176     return(ETrue); // means SetState() was called
       
   177     }
       
   178 
       
   179 EXPORT_C void CEikButtonBase::Animate()
       
   180     {
       
   181     iButFlags|=KButtonPressedMask;
       
   182     StateChanged();
       
   183     DrawNow();
       
   184     iCoeEnv->Flush(KAnimationDelayInMicroSeconds);
       
   185     iButFlags&=(~KButtonPressedMask);
       
   186     if (!ClickCompleted())
       
   187         StateChanged();
       
   188     DrawNow();
       
   189 	iCoeEnv->WsSession().Flush();
       
   190     }
       
   191 
       
   192 EXPORT_C void CEikButtonBase::SetAllowTristate()
       
   193     {
       
   194     iButFlags|=KButtonAllowTristate;
       
   195     }
       
   196 
       
   197 EXPORT_C void CEikButtonBase::SetIgnoreNextPointerUp()
       
   198 	{
       
   199 	iButFlags|=EIgnoreNextPointerUp;
       
   200 	}
       
   201 
       
   202 /**
       
   203  * Writes the internal state of the control and its components to aStream.
       
   204  * Does nothing in release mode.
       
   205  * Designed to be overidden and base called by subclasses.
       
   206  *
       
   207  * @internal
       
   208  * @since App-Framework_6.1
       
   209  */
       
   210 #ifndef _DEBUG
       
   211 EXPORT_C void CEikButtonBase::WriteInternalStateL(RWriteStream&) const
       
   212 	{}
       
   213 #else
       
   214 EXPORT_C void CEikButtonBase::WriteInternalStateL(RWriteStream& aWriteStream) const
       
   215 	{
       
   216 	_LIT(KEikLitCmdButBaseCtlStart,"<CEikButtonBase>");
       
   217 	_LIT(KEikLitCmdButBaseCtlEnd,"<\\CEikButtonBase>");
       
   218 	_LIT(KEikLitCmdButBaseFlags,"<iButFlags>");
       
   219 	_LIT(KEikLitCmdButBaseFlagsEnd,"<\\iButFlags>");
       
   220 	
       
   221 	aWriteStream << KEikLitCmdButBaseCtlStart;
       
   222 	aWriteStream << KEikLitCmdButBaseFlags;
       
   223 	aWriteStream.WriteInt32L(iButFlags);
       
   224 	aWriteStream << KEikLitCmdButBaseFlagsEnd;
       
   225 	CEikBorderedControl::WriteInternalStateL(aWriteStream);
       
   226 	aWriteStream << KEikLitCmdButBaseCtlEnd;
       
   227 	}
       
   228 #endif
       
   229 
       
   230 EXPORT_C void CEikButtonBase::Reserved_2()
       
   231 	{}
       
   232 EXPORT_C void CEikButtonBase::Reserved_3()
       
   233 	{}
       
   234 
       
   235 //
       
   236 // class TEikButtonCoordinator
       
   237 //
       
   238 
       
   239 EXPORT_C TEikButtonCoordinator::TEikButtonCoordinator()
       
   240 	: iChosenButton(NULL)
       
   241 	{}
       
   242 
       
   243 EXPORT_C void TEikButtonCoordinator::SetChosenButton(CEikButtonBase* aChosenButton)
       
   244 	{
       
   245 	if (iChosenButton==aChosenButton)
       
   246 		return;
       
   247 	if (iChosenButton)
       
   248 		{
       
   249 		iChosenButton->SetState(CEikButtonBase::EClear);
       
   250 		iChosenButton->DrawNow();
       
   251 		}
       
   252 	iChosenButton=aChosenButton;
       
   253 	}