classicui_pub/misc_controls_api/inc/eiktbar.h
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Class declaration for EIKON toolbar control.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __EIKTBAR_H__
       
    20 #define __EIKTBAR_H__
       
    21 
       
    22 #include <eikctgrp.h>
       
    23 #include <coecobs.h>
       
    24 #include <eikbtgrp.h>
       
    25 #include <eikbtgpc.h>
       
    26 
       
    27 // Forward declarations
       
    28 
       
    29 class MEikCommandObserver;
       
    30 class TEikButtonCoordinator;
       
    31 class CEikCommandButton;
       
    32 class CCoeBrushAndPenContext;
       
    33 
       
    34 /**
       
    35  * A vertical group of controls displayed down the right-hand side of the
       
    36  * screen in an application.
       
    37  *
       
    38  * It contains buttons which are used to issue application commands,
       
    39  * and other controls. A toolband may also be created using this class,
       
    40  * by setting the @c EEikToolBarHorizontal flag and initialising from a
       
    41  * @c TOOLBAND resource.
       
    42  *
       
    43  * @lib eikcoctl.lib
       
    44  * @since S60 0.9
       
    45  */
       
    46 class CEikToolBar : public CEikControlGroup,
       
    47                     public MCoeControlObserver,
       
    48                     public MEikButtonGroup
       
    49 	{
       
    50 public:
       
    51 
       
    52     /**
       
    53      * Destructor.
       
    54      * Deletes the toolbar's brush and pen context and control types.
       
    55      */
       
    56 	IMPORT_C ~CEikToolBar();
       
    57 	
       
    58 	/**
       
    59      * Default C++ constructor.
       
    60      * Creates a new toolbar object, but does not initialise any of
       
    61      * its heap-stored members.
       
    62      */
       
    63 	IMPORT_C CEikToolBar();
       
    64 	
       
    65 	/**
       
    66 	 * Completes construction of a default-constructed toolbar.
       
    67 	 *
       
    68      * The command observer interface defines a method for creating custom
       
    69      * controls on the toolbar from user-defined IDs specified in the
       
    70      * resource @c aResourceId.
       
    71      *
       
    72      * IDs for controls which cannot be constructed using
       
    73      * @c EikControlFactory::CreateByTypeL() are passed to this object's
       
    74      * command observer for construction.
       
    75      *
       
    76      * Applications requiring custom controls in their toolbars should
       
    77      * override their AppUI's @c CreateCustomCommandControlL() method,
       
    78      * inherited from @c MEikCommandObserver.
       
    79      *
       
    80      * @param aCommandObserver Sets the command observer for this toolbar.
       
    81      *                         The observer's @c ProcessCommandL()
       
    82      *                         function is invoked when a toolbar command
       
    83      *                         is invoked by the user.
       
    84      *                         @see MEikCommandObserver::ProcessCommandL().
       
    85      *                         Typically the observer is the
       
    86      *                         application's AppUI.
       
    87      *
       
    88      * @param aResourceId      The ID of a @c TOOLBAR or @c TOOLBAND
       
    89      *                         resource structure.
       
    90      *
       
    91      * @param aBoundingRect    Defines the rectangle to which the toolbar's
       
    92      *                         extent must be limited. This is typically given
       
    93      *                         by @c CEikAppUi::ClientRect(), which returns
       
    94      *                         the extent of the whole application window,
       
    95      *                         less the extent of any toolbars that already
       
    96      *                         exist and are owned by the AppUI.
       
    97      *
       
    98      * @panic EIKCOCTL-36      If the control on the toolbar cannot be
       
    99      *                         constructed.
       
   100      */
       
   101 	IMPORT_C void ConstructL( MEikCommandObserver* aCommandObserver,
       
   102 	                          TInt aResourceId,
       
   103 	                          const TRect& aBoundingRect );
       
   104 	
       
   105 	/**
       
   106 	 * Creates a toolbar from a resource definition,
       
   107 	 * but does not set its extent or activate it.
       
   108 	 *
       
   109 	 * This function is used by @c ConstructL(), applications will
       
   110 	 * not typically need to use it.
       
   111 	 *
       
   112 	 * @param aCommandObserver Specifies the object in which
       
   113 	 *                         @c HandleCommandL() is called when a toolbar
       
   114 	 *                         command is invoked, typically the application's
       
   115 	 *                         AppUI.
       
   116 	 *
       
   117 	 * @param aResourceId      The resource that defines the toolbar.
       
   118 	 *
       
   119 	 * @panic EIKCOCTL-36      If the control on the toolbar cannot be
       
   120 	 *                         constructed.
       
   121 	 */
       
   122 	IMPORT_C void StaticConstructL( MEikCommandObserver* aCommandObserver,
       
   123 	                                TInt aResourceId );
       
   124 	
       
   125 	/**
       
   126 	 * Sets the toolbar's command observer.
       
   127 	 * Applications will not typically need to use this function.
       
   128 	 *
       
   129 	 * @param aCommandObserver The command observer for this toolbar.
       
   130 	 *                         When a command is invoked in the toolbar,
       
   131 	 *                         @c HandleCommandL() is called in the observer.
       
   132 	 */
       
   133 	IMPORT_C void SetCommandObserver(MEikCommandObserver* aCommandObserver);
       
   134 	
       
   135 	/**
       
   136 	 * Sets the button co-ordinator for a group of buttons in a toolbar.
       
   137 	 *
       
   138 	 * @param aId           Command identifying a toolbar button. 
       
   139 	 * @param aCount        The number of buttons in the group. 
       
   140 	 * @param aCoordinator  The button coordinator. 
       
   141 	 */
       
   142 	IMPORT_C void CoordinateButtons( TInt aId,
       
   143 	                                 TInt aCount,
       
   144 	                                 TEikButtonCoordinator* aCoordinator );
       
   145 	
       
   146 	/**
       
   147 	 * Sets the state of the specified button and draws the button
       
   148 	 * to show the new state.
       
   149 	 *
       
   150 	 * @param aId    The command that identifies the button.
       
   151 	 * @param aState @c ETrue to set the button, @c EFalse to clear the button.
       
   152 	 */
       
   153 	IMPORT_C void SetButtonStateOn(TInt aId,TBool aState);
       
   154 	
       
   155 	/**
       
   156 	 * Delays activation of the toolbar when constructed.
       
   157 	 *
       
   158 	 * This function sets the toolbar flag @c EEikToolBarDelayActivation.
       
   159 	 * If this flag is set when @c ConstructL() is called on the toolbar,
       
   160 	 * the toolbar will be constructed but not activated.
       
   161 	 *
       
   162 	 * The application can subsequently activate the toolbar by calling
       
   163 	 * @c CCoeControl::ActivateL().
       
   164 	 *
       
   165 	 * @return @c ETrue to delay activation of the toolbar.
       
   166 	 */
       
   167 	IMPORT_C TBool DelayActivation() const;
       
   168 	
       
   169 public: /** From @c CCoeControl. */
       
   170 
       
   171     /**
       
   172 	 * Second-phase construction from a resource.
       
   173 	 * This is called by @c StaticConstructL() with an appropriate reader.
       
   174 	 *
       
   175 	 * From @c CCoeControl
       
   176 	 *
       
   177 	 * @param aReader     A resource reader pointing at a @c TOOLBAR or
       
   178 	 *                    @c TOOLBAND resource defining the toolbar.
       
   179 	 * @panic EIKCOCTL-36 If the control on the toolbar cannot be constructed.
       
   180 	 */
       
   181 	IMPORT_C void ConstructFromResourceL(TResourceReader& aReader);
       
   182 	
       
   183 	/**
       
   184 	 * Sets the toolbar dimmed or not dimmed.
       
   185 	 * Dimming usually indicates that user input is not accepted.
       
   186 	 *
       
   187 	 * From @c CCoeControl
       
   188 	 *
       
   189 	 * @param aDimmed @c ETrue to set as dimmed ,
       
   190 	 *                @c EFalse to set as not dimmed.
       
   191 	 */
       
   192 	IMPORT_C void SetDimmed(TBool aDimmed);
       
   193 	
       
   194 	/**
       
   195 	 * Gets the list of logical colours used to draw the control.
       
   196 	 * Appends the list to @c aColorUseList paired with an explanation
       
   197 	 * of how the colours are used.
       
   198      *
       
   199 	 * From @c CCoeControl
       
   200 	 *
       
   201 	 * @param[in,out] aColorUseList The list of logical colours. 
       
   202 	 */
       
   203 	IMPORT_C void GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList) const;
       
   204 	
       
   205 	/**
       
   206      * Handles a change to the control's resources.
       
   207      *
       
   208      * The types of resources handled are those which are shared across
       
   209      * the environment, e.g. colours or fonts. For colour scheme changes,
       
   210      * @c DrawDeferred() is called in order to redraw the control.
       
   211      *
       
   212      * If overriding this method, the implementation must
       
   213      * include a base call to this method.
       
   214      *
       
   215      * From @c CCoeControl.
       
   216 	 *
       
   217      * @param aType The type of resource that has changed.
       
   218      */
       
   219 	IMPORT_C void HandleResourceChange(TInt aType);
       
   220 	
       
   221 	/**
       
   222      * Handles pointer events.
       
   223      *
       
   224      * This function gets called whenever a pointer event occurs in the 
       
   225      * control, i.e. when the pointer is within the control's extent, or when 
       
   226      * the control has grabbed the pointer.
       
   227      * 
       
   228      * If overriding this method, the implementation must 
       
   229      * include a base call to this method.
       
   230      *
       
   231      * From @c CCoeControl.
       
   232      *
       
   233      * @param aPointerEvent The pointer event.
       
   234      */
       
   235 	IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
       
   236 	
       
   237 public: /** From @c CEikControlGroup. */
       
   238 
       
   239     /**
       
   240      * Adds a control to the control group.
       
   241      *
       
   242 	 * From @c CEikControlGroup
       
   243 	 *
       
   244 	 * @param aControl    The control to add to the control group
       
   245 	 * @param aId         The control's ID.
       
   246 	 * @panic EIKCOCTL-26 If the control does not exist.
       
   247 	 */
       
   248 	IMPORT_C void AddControlL(CCoeControl* aControl,TInt aId);
       
   249 	
       
   250 	/**
       
   251 	 * Adds a control wrapped with its ID and length to the control group.
       
   252 	 *
       
   253 	 * From @c CEikControlGroup
       
   254 	 *
       
   255 	 * @param aGroupControl The wrapped control to add.
       
   256 	 * @panic EIKCOCTL-26   If the control does not exist.
       
   257 	 */
       
   258 	IMPORT_C void AddControlL(TEikGroupControl& aGroupControl);
       
   259 	
       
   260 public: // but not exported
       
   261 
       
   262     /**
       
   263 	 * Adds a control type to the control type array.
       
   264 	 *
       
   265 	 * @internal
       
   266 	 *
       
   267 	 * @param aType The control type to be added.
       
   268 	 */
       
   269 	void AddControlTypeL(TInt aType);
       
   270 	
       
   271 	/**
       
   272 	 * Removes a control type from the control type array.
       
   273 	 *
       
   274 	 * @internal
       
   275 	 *
       
   276 	 * @param aIndex Index of the control type to be removed
       
   277 	 *               in the control type array.
       
   278 	 */
       
   279 	void RemoveControlType(TInt aIndex);
       
   280 	
       
   281 	/**
       
   282 	 * Used to check if a control is a button type control or not.
       
   283 	 *
       
   284 	 * @internal
       
   285 	 *
       
   286 	 * @param  aIndex Index of the control.
       
   287 	 * @return @c ETrue, if the control is a button type control.
       
   288 	 */
       
   289 	TBool ControlIsButton(TInt aIndex) const;
       
   290 	
       
   291 public: /** From @c MEikButtonGroup. */
       
   292 
       
   293     /**
       
   294      * Sets the toolbar's bounding rectangle.
       
   295      * This function has a different effect on the toolbar's extent,
       
   296      * depending on whether the toolbar is vertical or horizontal.
       
   297      *
       
   298      * For a vertical toolbar, sets the toolbar height to equal the
       
   299      * height of the bounding rectangle.
       
   300      *
       
   301      * For a horizontal toolbar (toolband), sets the toolband width
       
   302      * to equal the width of the bounding rectangle.
       
   303      *
       
   304 	 * From @c MEikButtonGroup
       
   305 	 *
       
   306 	 * @param aBoundingRect The toolbar's bounding rectangle.
       
   307 	 */
       
   308 	IMPORT_C void SetBoundingRect(const TRect& aBoundingRect);
       
   309 	
       
   310 	/**
       
   311 	 * Shrinks a rectangle to exclude the toolbar area.
       
   312      * This function reduces the size of the rectangle passed into the
       
   313      * function so that on return, the area occupied by the toolbar or toolband
       
   314      * is removed from the rectangle. It is provided to prevent drawing
       
   315      * over an existing toolbar or toolband.
       
   316      *
       
   317 	 * From @c MEikButtonGroup
       
   318 	 *
       
   319 	 * @param[in,out] aBoundingRect Specifies a rectangle which, on return,
       
   320 	 *                              is shrunk to exclude the toolbar’s extent.
       
   321 	 */
       
   322 	IMPORT_C void ReduceRect(TRect& aBoundingRect) const;
       
   323 	
       
   324 protected:
       
   325 
       
   326     /**
       
   327      * Writes the internal state of the control and its
       
   328      * components to @c aWriteStream.
       
   329      * Does nothing in release mode.
       
   330      *
       
   331      * Designed to be overridden and base called from subclasses.
       
   332      *
       
   333      * From @c CCoeControl
       
   334      *
       
   335      * @param[in,out] aWriteStream A connected write stream.
       
   336      */
       
   337 	IMPORT_C void WriteInternalStateL(RWriteStream& aWriteStream) const;
       
   338 	
       
   339 private:
       
   340 
       
   341 	CEikCommandButton* ButtonByIndex(TInt aIndex) const;	
       
   342 	void SetCurrentId(TInt aPosition,TInt aId);	
       
   343 	TInt CurrentId(TInt aPosition) const;	
       
   344 	TEikGroupControl& GroupControlByIndex(TInt aIndex) const;	
       
   345 	TInt IndexFromPosition(TInt aPos) const;
       
   346 	
       
   347 private: /** From @c MEikButtonGroup */
       
   348 
       
   349 	void SetCommandL( TInt aPosition,
       
   350 	                  TInt aCommandId,
       
   351 	                  const TDesC* aText,
       
   352 	                  const CFbsBitmap* aBitmap,
       
   353 	                  const CFbsBitmap* aMask );
       
   354 	                  
       
   355 	void SetCommandL(TInt aPosition,TInt aResourceId);
       
   356 	void SetCommandSetL(TInt aResourceId);
       
   357 	void AddCommandL( TInt aPosition,
       
   358 	                  TInt aCommandId,
       
   359 	                  const TDesC* aText,
       
   360 	                  const CFbsBitmap* aBitmap,
       
   361 	                  const CFbsBitmap* aMask );
       
   362 	void AddCommandToStackL( TInt aPosition,
       
   363 	                         TInt aCommandId,
       
   364 	                         const TDesC* aText,
       
   365 	                         const CFbsBitmap* aBitmap,
       
   366 	                         const CFbsBitmap* aMask );
       
   367 	void AddCommandToStackL(TInt aPosition,TInt aResourceId);
       
   368 	void AddCommandSetToStackL(TInt aResourceId);
       
   369 	void SetDefaultCommand(TInt aCommandId);
       
   370 	TSize CalcMinimumSizeL(TInt aResourceId);
       
   371 	void RemoveCommandFromStack(TInt aPosition,TInt aCommandId);
       
   372 	TInt CommandPos(TInt aCommandId) const;
       
   373 	void DimCommand(TInt aCommandId,TBool aDimmed);
       
   374 	TBool IsCommandDimmed(TInt aCommandId) const;
       
   375 	void MakeCommandVisible(TInt aCommandId,TBool aVisible);
       
   376 	TBool IsCommandVisible(TInt aCommandId) const;
       
   377 	CCoeControl* AsControl();
       
   378 	const CCoeControl* AsControl() const;
       
   379 	CCoeControl* GroupControlById(TInt aCommandId) const;
       
   380 	CEikCommandButton* GroupControlAsButton(TInt aCommandId) const;
       
   381 	TInt CommandId(TInt aCommandPos) const;
       
   382 	TInt ButtonCount() const;
       
   383 	TUint ButtonGroupFlags() const;
       
   384 
       
   385     void SetMSKCommandObserver(MEikCommandObserver* aCommandObserver);
       
   386     void DimCommandByPosition(TInt aPosition,TBool aDimmed);
       
   387     TBool IsCommandDimmedByPosition(TInt aPosition) const;
       
   388     void MakeCommandVisibleByPosition(TInt aPosition,TBool aVisible);
       
   389     TBool IsCommandVisibleByPosition(TInt aPosition) const;
       
   390     void AnimateCommandByPosition(TInt aPosition);
       
   391 
       
   392 private: /** From @c MCoeControlObserver */
       
   393 	IMPORT_C void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEvent);
       
   394 	
       
   395 private:
       
   396 	IMPORT_C void Reserved_2();
       
   397 	
       
   398 private: /** From @c CAknControl */
       
   399 
       
   400     IMPORT_C void* ExtensionInterface( TUid aInterface );
       
   401 private:
       
   402 	void BaseConstructL();
       
   403 	TInt ControlCount() const;
       
   404 private:
       
   405 	TInt                    iToolBarFlags;
       
   406 	MEikCommandObserver*    iCommandObserver;
       
   407 	CCoeBrushAndPenContext* iBrushAndPenContext;
       
   408 	CArrayFix<TInt>*        iControlTypes; 
       
   409 	};
       
   410 
       
   411 #endif // __EIKTBAR_H__