AbstractThis use case explains how to create a specialized command header. This command header has a customized graphic representation. In place of a push item into a menu, the graphic representation is a dynamic list of push items. |
This use case illustrates the creation of a customized command header. In a menu, its graphic representation is a dynamic list of push items in place of a push item, the default representation. You will learn how to create a command header such as those which displays the most recent used document in the File menu. There are three steps:
It is a component which must derive from the CATAfrDialogCommandHeader class.
It is a component which must derive from the CATAfrCommandHeaderRep class and which instantiates one or more CATDlgPushItem class instances.
The data is a list of strings. This list is independent of an instance of a V5 document. It means that whatever the current document, or even if any document is opened, the list of strings is the same.
You can also read the CAAAfrComboColorHeader use case [1] which presents another customized command header. In this case, the graphic representation is a combo in a toolbar. Contrarily to the current use case, the data (the current color) is dependent of the document.
To take full advantage of this article, you can first read "The Command Headers" technical article [2], and precisely the "Creating Customized Command Headers" section.
[Top]
CAAAfrMRUHeader is a use case of the CAAApplicationFrame.edu framework that illustrates ApplicationFrame framework capabilities
[Top]
CAAAfrMRUHeader creates a command header whose the graphic representation is a list of push items in the File menu. Before to explain the construction of such a command header, see the following scenario which shows the end user view.
Above Exit, you have a separator, and just above it the "standard" most recent used documents. |
This toolbar comes from an Add-in of the General workshop. Refer to
the referenced use case to display this toolbar [3].
The Add Item in MRU command is a CATDlgDialog command. |
In the editor, enter Item 1, then click OK |
Now, after Exit, you have a new push item, Item 1 |
In the editor, enter Item 2, then click OK |
Now, after Exit, you have two push items:
|
The Selected item dialog box appears. It displays the selected item (Item 1). Close the dialog box. |
Now, after Exit, you always have two push items, but observe
the new order:
|
In this scenario, you can see that there is a list of strings (or item). About this list :
This list (named MRU list) is kept by a component called CAAAfrMRUManager. It controls data (list of strings) which are displayed in the push items of a menu through the CAAIAfrMRUManagement interface. Since, the MRU list is unique, this component is unique during the session.
The MRU header is an instance of a class deriving from the CATAfrDialogCommandHeader class, like any command header whose the graphic representation is customized. The following UML diagram describes in detail the schema of classes:
CAAAfrMRUHeader is a component which must implement the CATIAfrCommandHeaderRep interface to provide the customized graphic representation. This interface contains three methods:
CreateCtxMenuRep
and CreateToolbarRep
which
return nothing
CreateMenuRep
:
It instantiates an instance of the CAAAfrMRURep class describes just below.
The CAAAfrMRURep class creates one or more CATDlgPushItem [4] class instance according to the contents of the list managed by the CAAAfrMRUManager component. The CAAAfrMRURep class also sets a callback method to be informed when this list changes.
The MRU header is instantiated in an Add-in of the General workshop [3]. The last step of the Step by Step section explains this instantiation.
[Top]
To launch CAAAfrMRUHeader, you will need to set up the build time environment, then compile CAAAfrMRUHeader and CAAAfrGeneralWksAddin[3] along with their prerequisites, set up the run time environment, and then execute the use case [5].
But just before launching the execution, edit the CAAApplicationFrame.edu.dico interface dictionary file located in the dictionary directory of the CAAApplicationFrame.edu framework:
Windows | InstallRootDirectory\CAAApplicationFrame.edu\CNext\code\dictionary\ |
UNIX | InstallRootDirectory/CAAApplicationFrame.edu/CNext/code/dictionary/ |
In this file, remove the "#" character before the two following lines:
... #CAAAfrGeneralWksAddin CATIWorkbenchAddin libCAAAfrGeneralWksAddin #CAAAfrGeneralWksAddin CATIAfrGeneralWksAddin libCAAAfrGeneralWksAddin ... |
and then run mkCreateRuntimeView.
[Top]
The CAAAfrMRUHeader use case is made of several classes located in four modules of the CAAApplicationFrame.edu framework:
Windows | InstallRootDirectory\CAAApplicationFrame.edu |
Unix | InstallRootDirectory/CAAApplicationFrame.edu |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
The CAAAfrCustCommandHdrModel.m
module contains classes to
define the CAAAfrMRUManager component and the notification sent by
this component.
The notification sent when an element is added in the list, or when an element is selected (to become the first in the list)
Interface to add an element, select one, retrieve the list.
The CAAAfrMRUManager component itself which implements the CAAIAfrMRUManagement interface.
The global function to retrieve the unique CAAAfrMRUManager component during the session.
The CAAAfrCustomizedCommandHeader.m
module contains classes to
define the MRU header:
The CAAfrGeoCommands.m
module contains CATCommand
classes
It is a CATDlgDialog class (see image) executed when the end user clicks the "Add Item in MRU" command in the General toolbar.
It is a CATDlgDialog class (see image) executed when the end user selects an item among the MRU list.
The CAAAfrGeneralWksAddin.m
module contains an Add-in of the
General workshop
[Top]
There are four logical steps in CAAAfrMRUHeader:
[Top]
The CAAAfrMRUManager component controls the MRU list to display in a menu. This list is managed through the CAAIAfrMRUManagement interface. The explanations about the creation of this interface are not given in this article, refer to the Creating Interfaces use case for more details [6].
... #define MRU_MAX_SIZE 5 class CAAAfrMRUManager : public CATBaseUnknown { CATDeclareClass; public: CAAAfrMRUManager(); virtual ~CAAAfrMRUManager(); static HRESULT GetMRUManager(CAAAfrMRUManager ** oManager); virtual HRESULT AddElement(CATUnicodeString &iNewElement) ; virtual HRESULT GetElementList(CATListOfCATUnicodeString &ElementList) const ; virtual HRESULT SelectElement(int iPosition) ; private: CAAAfrMRUManager(const CAAAfrMRUManager &iObjectToCopy); CAAAfrMRUManager & operator = (const CAAAfrMRUManager &iObjectToCopy); private: static CATIniCleanerSettingCtrl _Cleaner ; CATListOfCATUnicodeString _NameList; }; |
CATDeclareClass
macro declares that it belongs to a CAA
component.GetMRUManager
is a static method to have only one
CAAAfrMRUManager component during the session. The list is unique whatever
the opened document, or even if no document is opened.AddElement
, GetElementList
and SelectElement
are methods of the CAAIAfrMRUManagement interfaceCopy constructor
and the assignment operator
are
not implemented in the source file. This prevents the compiler from creating
them as public without you know._Cleaner
keeps the pointer on the unique CAAAfrMRUManager
component instance. When the session is killed, the _Cleaner
instance is removed, and the CAAAfrMRUManager class pointer is
released. It avoids to have "MLK". In your own code, the static
data can be directly the pointer on the CAAAfrMRUManager class
instance. _NameList
is a list of CATUnicodeString. This list is
limited to five elements (MRU_MAX_SIZE = 5
)The source file of the CAAAfrMRUManager class is as follows:
... CATIniCleanerSettingCtrl CAAAfrMRUManager::_Cleaner ; CATImplementClass(CAAAfrMRUManager, Implementation, CATBaseUnknown , CATNull); #include <TIE_CAAIAfrMRUManagement.h> TIE_CAAIAfrMRUManagement(CAAAfrMRUManager); CAAAfrMRUManager::CAAAfrMRUManager() {} CAAAfrMRUManager::~CAAAfrMRUManager(){} ... |
_Cleaner
is initializedCATImplementClass
macro makes the class CAAAfrMRUManager
a component main class (Implementation
) that OM-derives [11]
from CATBaseUnknown.TIE_CAAIAfrMRUManagement
macro.
... HRESULT CAAAfrMRUManager::GetMRUManager(CAAAfrMRUManager ** oManager) { ... CATBaseUnknown * pManager = _Cleaner.GetController(); if ( NULL == pManager ) { CAAAfrMRUManager * Obj = NULL; Obj = new CAAAfrMRUManager(); if ( NULL == Obj ) { rc = E_OUTOFMEMORY ; }else { *oManager = Obj ; _Cleaner.SetController(Obj); } }else { *oManager = (CAAAfrMRUManager *) pManager ; } ... |
The GetMRUManager
method creates the only one instance of the CAAAfrMRUManager
class or retrieves the existing one. _Cleaner
is a static data
member, a CATIniCleanerSettingCtrl class instance. If the GetController
method of the CATIniCleanerSettingCtrl class returns a null pointer, a CAAAfrMRUManager
class instance is created, and kept by _Cleaner
through the SetController
method. Otherwise the GetMRUManager
method returns the pointer kept
by _Cleaner
and retrieved thanks to the GetController
method.
Now, lets us see the three methods of the CAAIAfrMRUManagement interface.
... HRESULT CAAAfrMRUManager::AddElement(CATUnicodeString &iNewElement) { if ( MRU_MAX_SIZE == _NameList.Size() ) { // The list is full, the last element is removed _NameList.RemovePosition(MRU_MAX_SIZE); } // At the first position _NameList.InsertBefore(1,iNewElement); CATCallbackManager * pCBManager = ::GetDefaultCallbackManager(this) ; if ( NULL != pCBManager ) { CAAAfrMRUManagerNotification * pNotification = new CAAAfrMRUManagerNotification(); pCBManager->DispatchCallbacks(pNotification,this); pNotification->Release(); } return S_OK ; } ... |
While there are less than MRU_MAX_SIZE
elements in the list,
represented by _NameList
the data member, the AddElement
method just adds the new element (iNewElement
) at the first
position (InsertBefore(1,...)
). But when there are already MRU_MAX_SIZE
elements in the list, before adding the new element at the first position, the
last element of the list is removed.
The second part of the AddElement
method consists in to send a
notification thanks to the callback manager [7]. So,
all objects which will subscribe for this event, published by the MRU manager,
will be informed and awaked. Refer to the callback use case [8],
for explanations about the creation of a notification such as the CAAAfrMRUManagerNotification
class, and how to send a notification using the default callback manager.
... HRESULT CAAAfrMRUManager::GetElementList(CATListOfCATUnicodeString & oElementList) const { for ( int i = 1 ; i <= _NameList.Size() ; i++) { oElementList.Append(_NameList[i]); } return S_OK ; } ... |
The GetElementList
method returns the contents of the list of
item kept by _NameList
the data member. This method will be called
by the MRU header to build its graphic representation. See the Creating
the Class Instantiating the Graphic Representation step.
... HRESULT CAAAfrMRUManager::SelectElement(int iPosition) { HRESULT rc = E_FAIL ; if ( (iPosition >= 1) && (iPosition <= MRU_MAX_SIZE) ) { CATUnicodeString Sel = _NameList[iPosition] ; _NameList.RemovePosition(iPosition); _NameList.InsertBefore(1,Sel); CATCallbackManager * pCBManager = ::GetDefaultCallbackManager(this) ; ... CAAAfrMRUManagerNotification * pNotification = new CAAAfrMRUManagerNotification(); pCBManager->DispatchCallbacks(pNotification,this); pNotification->Release(); pNotification = NULL ; ... |
The SelectElement
method consists in to set at the first
position the iPosition
element of the list. So the element is first
removed from the list (RemovePosition
), and then reinserted
at the first position (InsertBefore
)
.
[Top]
The MRU header is a component which must Object Modeler and C++ derive from CATAfrDialogCommandHeader and must implement the CATIAfrCommandHeaderRep interface (Fig.2).
Here the CAAAfrMRUHeader header file:
//ApplicationFrame framework #include "CATAfrDialogCommandHeader.h" class ExportedByCAAAfrCustomizedCommandHeader CAAAfrMRUHeader: public CATAfrDialogCommandHeader { CATDeclareClass ; public: CAAAfrMRUHeader(const CATString & iHeaderName); virtual ~CAAAfrMRUHeader(); CATCommandHeader * Clone() ; private: CAAAfrMRUHeader(CATCommandHeader *iHeaderToCopy); CAAAfrMRUHeader(const CAAAfrMRUHeader & iObjectToCopy); CAAAfrMRUHeader& operator = (const CAAAfrMRUHeader & iObjectToCopy); }; |
CAAAfrMRUHeader derives from CATAfrDialogCommandHeader. It is
mandatory for a command header whose the graphic representation is customized.
The CATDeclareClass
macro declares that it belongs to a CAA
component. The CATDeclareHeaderResources
macro inserts the methods
to manage the command header resources.
About the mandatory public methods:
constructor
with a reference to a const
CATString
destructor
,
Clone
method inherited from CATCommandHeader and
used to duplicate the command header instance. Refer to the "Customized
Command Header Class Structure" section of the technical article about
the command headers [2]. You will have all the
details about the Clone
method. About the mandatory private methods:
constructor
taking a pointer to a CATCommandHeader
is dedicated to the Clone
method.
constructor
are declared in the private part, and
are not implemented in the source file. This prevents the compiler from
creating them as public without you know.Here the CAAAfrMRUHeader header file:
#include "CAAAfrMRUHeader.h" CATImplementClass(CAAAfrMRUHeader, Implementation, CATAfrDialogCommandHeader, CATNull); CAAAfrMRUHeader::CAAAfrMRUHeader(const CATString & iHeaderName) : CATAfrDialogCommandHeader(iHeaderName){} CAAAfrMRUHeader::CAAAfrMRUHeader(){} CATCommandHeader * CAAAfrMRUHeader::Clone () { return new CAAAfrMRUHeader(this); } CAAAfrMRUHeader::CAAAfrMRUHeader(CATCommandHeader * iHeaderToCopy): CATAfrDialogCommandHeader(iHeaderToCopy) {} |
CATImplementClass
macro makes the class CAAAfrMRUHeader a component main class (Implementation
)
that OM-derives [11] from CATAfrDialogCommandHeader.
Clone
method returns a copy construction instance of
this.CATDeclareHeaderResources
macro in the header
file, and neither CATImplementHeaderResources
macro in the source
file. There is no NLS resources for this header [10].
CATIAfrCommandHeaderRep implementation
This interface of the ApplicationFrame framework must be implemented by all command header whose the graphic representation is customized. On Fig.2, you see that the CAAEAfrCommandHeaderRepForMRU class is the implementation of this interface for the CAAAfrMRUHeader component.
Here the CAAEAfrCommandHeaderRepForMRU header file
... class CAAEAfrCommandHeaderRepForMRU : public CATBaseUnknown { CATDeclareClass; public: CAAEAfrCommandHeaderRepForMRU (); virtual ~CAAEAfrCommandHeaderRepForMRU(); virtual HRESULT CreateToolbarRep (const CATDialog * iParent, CATAfrCommandHeaderRep ** oHdrRep) ; virtual HRESULT CreateMenuRep (const CATDialog * iParent, CATAfrCommandHeaderRep ** oHdrRep) ; virtual HRESULT CreateCtxMenuRep (const CATDialog * iParent, CATAfrCommandHeaderRep ** oHdrRep) ; private: CAAEAfrCommandHeaderRepForMRU (const CAAEAfrCommandHeaderRepForMRU &iObjectToCopy); CAAEAfrCommandHeaderRepForMRU & operator = (const CAAEAfrCommandHeaderRepForMRU &iObjectToCopy); }; |
The CATDeclareClass
macro declares that CAAEAfrCommandHeaderRepForMRU
belongs to a component. CreateToolbarRep
, CreateMenuRep
,
and CreateCtxMenuRep
are methods of the CATIAfrCommandHeaderRep
interface.
Here the CAAEAfrCommandHeaderRepForMRU source file
... #include <TIE_CATIAfrCommandHeaderRep.h> TIE_CATIAfrCommandHeaderRep(CAAEAfrCommandHeaderRepForMRU); CATImplementClass(CAAEAfrCommandHeaderRepForMRU, DataExtension, CATBaseUnknown, CAAAfrMRUHeader); }; CAAEAfrCommandHeaderRepForMRU:: CAAEAfrCommandHeaderRepForMRU():CATBaseUnknown(){} CAAEAfrCommandHeaderRepForMRU::~CAAEAfrCommandHeaderRepForMRU){} ... |
The CAAEAfrCommandHeaderRepForMRU class states that it implements the CATIAfrCommandHeaderRep
interface thanks to the TIE_CATIAfrCommandHeaderRep
macro. The CATImplementClass
macro declares that the CAAEAfrCommandHeaderRepForMRU class is a data
extension, thanks to the DataExtension
keyword, that extends
CAAAfrMRUHeader. The third argument must always be set as CATBaseUnknown
or CATNull for any kind of extension. The class constructor and the
class destructor are empty.
... HRESULT CAAEAfrCommandHeaderRepForMRU::CreateMenuRep (const CATDialog * iParent,CATAfrCommandHeaderRep ** oHdrRep) { HRESULT rc = E_FAIL ; if ( oHdrRep != NULL ) { CATString Name = "CAAAfrMRURepId" ; CAAAfrMRURep * pMRURep = new CAAAfrMRURep(iParent,Name); *oHdrRep = (CATAfrCommandHeaderRep *) pMRURep ; rc = S_OK ; } return rc ; } ... |
The CreateMenuRep
method provides the class instantiating the
graphic representation of the MRU header. This method is called each time the
header command must be represented in a menu.
The CAAAfrMRURep class is a CATCommand class [Fig.3], which instantiates the graphic representation of the MRU header (CATDlgPushItem instances). It is detailed in the Creating the Class Instantiating the Graphic Representation section, just below.
iParent
is a CATDialog component. It will be the dialog
parent of all CATDlgPushItem instances. Name
is the command
name of the CAAAfrMRURep class instance. You can set the same identifier
for all CAAAfrMRURep class instances.
You do not have to take care of the CAAAfrMRURep class instance
destruction, the returned value, oHdrRep
is kept by the frame
application, and the deletion of this pointer is automatically done.
... HRESULT CAAEAfrCommandHeaderRepForMRU:: CreateToolbarRep(const CATDialog * iParent,CATAfrCommandHeaderRep ** oHdrRep) { return E_FAIL ; } HRESULT CAAEAfrCommandHeaderRepForMRU:: CreateCtxMenuRep (const CATDialog * iParent,CATAfrCommandHeaderRep ** oHdrRep) { return E_FAIL; } |
The MRU header has no representation in the menu bar or in a contextual menu,
so CreateToolbarRep
and CreateCtxMenuRep
return
E_FAIL.
[Top]
This class is the CAAAfrMRURep class. Its main roles are:
Set a callback to be informed when the contents or the order of the MRU list change
Create CATDlgPushItem instances depending on the MRU list
Launch a command to display in a Dialog box (see picture) the selected item.
Here the CAAAfrMRURep header file:
... #define MRU_MAX_SIZE 5 class CAAAfrMRURep : public CATAfrCommandHeaderRep { public: CAAAfrMRURep (const CATDialog * iParent, CATString & iCommandName); virtual ~CAAAfrMRURep(); HRESULT Build(); private: void SelectCB(CATCommand * iPublishingCommand, CATNotification * iNotification, CATCommandClientData iData); void ModifiedCB(CATCallback iEvent, void * , CATNotification * iNotification, CATCallbackEvent iData, CATSubscriberData iCallBack); HRESULT ModifyListItem() ; CAAAfrMRURep (const CAAAfrMRURep &iObjectToCopy); CAAAfrMRURep & operator = (const CAAAfrMRURep &iObjectToCopy); private: CATDlgPushItem * _pItemList[MRU_MAX_SIZE]; CAAIAfrMRUManagement * _pIAfrMRUManagement ; }; |
The CAAAfrMRURep class derives from the CATAfrCommandHeaderRep class. Fig.3
The Build
method is a method of the CATAfrCommandHeaderRep
class. You must overwrite this method. In the CATAfrCommandHeaderRep
class it is a pure virtual method. This method is called by the frame
application just after the CAAAfrMRURep class instantiation, in other
words just after the CreateMenuRep
method call.
In private part:
SelectCB
method is a callback method when the end
user selects an item in the dynamic list.ModifiedCB
method is a callback method called when
the data model sent a CAAAfrMRUNotification notification. see the
first step. ModifyListItem
is called by Build
and ModifiedCB
methods to create or update the list of CATDlgPushItem
instances. In data member
_pItemList
a list of CATDlgPushItem class
instances created in the ModifyListItem
method._pIAfrMRUManagement
is a CAAIAfrMRUManagement
interface pointer on the CAAAfrMRUManager component. Here the CAAAfrMRURep source file:
First _pItemList,
the data member which holds all pointers
on CATDlgPushItem class instances, is initialized.
... CAAAfrMRURep::CAAAfrMRURep(const CATDialog * iParent,CATString & iCommandName): CATAfrCommandHeaderRep(iParent,iCommandName) ,_pIAfrMRUManagement(NULL) { for ( int i = 0 ; i < MRU_MAX_SIZE ; i++ ) { _pItemList[i] = NULL ; } ... |
The second step consists in to retrieve the component which holds the MRU list. In the use case, it is the unique CAAAfrMRUManager component that you retrieve with the CAAAfrGetMRUManager global function. The second argument of this method is a pointer on an interface implemented by the CAAAfrMRUManager component.
... HRESULT rc = ::CAAAfrGetMRUManager(IID_CAAIAfrMRUManagement, (void**)&_pIAfrMRUManagement); ... |
The last step consists in to set a callback method to be informed when the CAAAfrMRUManager component will send a CAAAfrMRUManagerNotification notification, in other words when an element will be added in the list or an element will be selected.
... if ( SUCCEEDED(rc) ) { ::AddCallback(this, _pIAfrMRUManagement, "CAAAfrMRUManagerNotification", (CATSubscriberMethod)&CAAAfrMRURep::ModifiedCB, NULL); } } |
AddCallback
is a static global function whose the
parameters are:
this:
The subscriber
_pIAfrMRUManagement
: The publisher
CAAAfrMRUManagerNotification:
The notification class sent
by the publisher
ModifiedCB:
The method of this which is called when a CAAAfrMRUManagerNotification
notification is sent
NULL:
No parameters for the callback methodThe destructor class
... CAAAfrMRURep::~CAAAfrMRURep() { if ( NULL != _pIAfrMRUManagement ) { ::RemoveSubscriberCallbacks(this, _pIAfrMRUManagement); _pIAfrMRUManagement->Release(); _pIAfrMRUManagement = NULL ; } for ( int i=0 ; i < MRU_MAX_SIZE ; i++) { if ( NULL != _pItemList[i] ) { _pItemList[i]->RequestDelayedDestruction(); _pItemList[i] = NULL ; ... |
At the end, the callback set in the constructor must be removed from the callback manager [7], and all the CATDlgPushItem instances must be released.
You must overwrite this method. The goal of this method is to create the
graphic representation and to initialize it. The ModifyListItem
method does the work.
... HRESULT CAAAfrMRUoRep::Build() { ModifyListItem() ; } ... |
The ModifyCB
method is called when the CAAAfrMRUManager
component sends the CAAAfrMRUManagerNotification notification. It
informs the CAAAfrMRURep class instance, that either a new item has
been added, or an element has been selected. In both cases, the ModifyListItem
method does the work.
... void CAAAfrMRURep::ModifiedCB(CATCallback, void *, CATNotification * iNotification, CATCallbackEvent, CATSubscriberData) { ModifyListItem(); } ... |
This method can be called by the Build
Method, in this case
any push item has already been created, or by the ModifyCB
method and in this case some push items can already exist. This method
consists in to:
_pItemList
list as in the list of items to display,The first step consists in to retrieve the Dialog parent of the graphic
representation to create. This information is kept by the CATAfrCommandHeaderRep
class, and retrieved by its GetDialogParent
method.
... HRESULT CAAAfrMRURep::ModifyListItem() { const CATDialog * pParent = NULL ; GetDialogParent(&pParent); ... |
Then, the list of item to displayed is retrieved from the
CAAAfrMRUManager thanks to the GetElementList
method of
the CAAIAfrMRUManagement interface. List
is this list,
and SizeList
is the count of element in this list.
... CATListOfCATUnicodeString List ; _pIAfrMRUManagement->GetElementList(List); int SizeList = List.Size(); ... |
Then, for the ith element of the list, if there is no CATDlgPushItem instance
at the ith position in _pItemList
, the data member of the CAAAfrMRURep
class, a new instance is created:
CATDlgPushItem
The last argument of the CATDlgPushItem class is the identifier
of the dialog object. It is recommended to set as value a string with an
index value. Here it is MRUItem_num
where num is the index in
the loop.
AddAnalyseNotificationCB
When an item in the menu is selected by the end user, the push item sends a GetMenuIActivateNotification notification which will be processed in the SelectCB method to launch the command which displays the name of the selected item.
CATINT32ToPtr
is the way to be 64 bits compliant.
SetFather
Finally, the CATCommand parent of the push item is changed. By
default, the command parent is the dialog parent, so it is pParent
,
the container in which the push item will be inserted. If you do not
change the command parent, this, the current CAAAfrMRURep instance,
will do not receive the GetMenuIActivateNotification notification.
Refer to the referenced article about the command tree [9].
... for ( int i= 0 ; i < SizeList ; i++ ) { CATUnicodeString num; num.BuildFromNum(i+1); if ( _pItemList[i] == NULL ) { CATUnicodeString ItemName("MRUItem_"); ItemName += num ; _pItemList[i] = new CATDlgPushItem((CATDialog *)pParent, ItemName.CastToCharPtr()); AddAnalyseNotificationCB(_pItemList[i], _pItemList[i]->GetMenuIActivateNotification(), (CATCommandMethod)&CAAAfrMRURep::SelectCB, (CATCommandClientData) CATINT32ToPtr(i)); _pItemList[i]->SetFather(this); } ... |
Finally, for the ith element of List,
the list kept by the
CAAAfrMRUManager component and retrieved just above, there is a CATDlgPushItem
class instance into the _pItemList
list, the data member of the
CAAAfrMRURep class. The title of the push item is the concatenation
of the position of the element in the list and the name of the item.
exemple: 2 MyItemName.
See the File Menu
picture in the
... num += " "; num += List[i+1] ; _pItemList[i]->SetTitle(num); ... |
The SelectCB
method is called when the end user has selected
an item among the displayed items. When an element of _pItemList
sends a notification, this callback method is called. The goal of this
method is double:
The CATPtrToINT32
macro enables us to translate the
data which is the argument of the AddAnalyseNotificationCB
method. See just above.
_pIAfrMRUManagement
is a CAAIAfrMRUManagement interface
pointer on the unique CAAAfrMRUManager component of the session.
This pointer, initialized in the constructor class, is a data member of
the CAAAfrMRURep class.
The SelectElement
method, with SelElement
as
argument, informs CAAAfrMRUManager that the element at the SelElement
position has been selected. It can reorder its own list of items,
and sends a notification. All CAAAfrMRURep which have set a
callback for a such notification, will may update their list of push
items.
The CATAfrStartCommand
is a global function which enables
us to launch a command header. This command header is identified by its
name, CAAAfrMRUSelElementHdr
. This command header instance
has been created in the Add-in of the General workshop, see the next
section for complete details about this command header instance.
... void CAAAfrMRURep::SelectCB(CATCommand * iPublishingCommand, CATNotification * iNotification, CATCommandClientData iData) { int SelElement = CATPtrToINT32(iData) + 1; _pIAfrMRUManagement->SelectElement(SelElement); CATCommand * pCmd = NULL ; ::CATAfrStartCommand("CAAAfrMRUSelElementHdr",pCmd); ... |
[Top]
The MRU header is independent of the document, so this header is instantiated in an Add-in of the General workshop [3]. Here is an extract of the CAAAfrGeneralWksAdn class which is an implementation of the CATIAfrGeneralWksAddin interface.
... void CAAAfrGeneralWksAdn::CreateCommands() { CATCommandHeader * pHdr = (CATCommandHeader*) new CAAAfrMRUHeader("CAAAfrMRUHdr"); pHdr->SetVisibility(0); ... |
The MRU command header is created using the constructor class. The most
important thing in the usage of the SetVisibility
method. This
method of the CATCommandHeader class allows us to hide the command header
instance in the Tools/Customize command. This command displays a dialog box
containing tab pages. One of them, the Command tab page, displays by category,
all the "visible" command header instances. The two following pictures
explains the difference when the SetVisibility
method is used or
not.
This picture shows the Command tab page of the Tools/Customize command.
In the All Commands category, you see that the CAAAfrMRUHdr appears. To do
that we have set a comment before the SetVisibility
instruction. The MRU header is without NLS resources [10],
so the displayed name is the internal name of the command header instance
(the argument of the constructor class). |
Now, using SetVisibility with 0 as argument,
you can see that between Bulk Loading... and Capture, CAAAfrMRUHdr
is not there. |
The advantage to hidde a command header, is that the end user cannot drag and
drop the command in a toolbar, or it cannot launch it from the power input since
it do not know its name. But caution, SetVisibility
method do not
prohibit to launch the command header in the power input, if you know the name
of the command header. For the MRU header, there is no effect since there is no CATCommand
associated with the MRU Header.
... pHdrMRU = (CATCommandHeader*) new CAAAfrGeneralWksAddinHeader("CAAAfrMRUSelElementHdr", "CAAAfrGeoCommands", "CAAAfrMRUSelElementCmd", (void *) NULL); pHdrMRU->SetVisibility(0); ... |
The next header instance name is CAAAfrMRUSelElementHdr
.
This header is a standard command header. So the CAAAfrGeneralWksAddinHeader
command header class is used to create an instance [3].
This instance launches the CAAAfrMRUSelElementCmd command which is
defined in the CAAAfrGeoCommands module of the CAAApplicationFrame.edu
framework. This instance of command header is also hidden in Tools/Customize,
because the use case want only to launch this command when the end user selects
an item in the File Menu. But if you try to enter CAAAfrMRUSelElementHdr
in the power input the Dialog command is lauched and the current item is
displayed.
The last header about the MRU use case is the CAAAfrMRUAddElementHdr
.
It is a standard command header which launches the CAAAfrMRUAddElementCmd
command which is defined in the CAAAfrGeoCommands module of the
CAAApplicationFrame.edu framework.
... new CAAAfrGeneralWksAddinHeader("CAAAfrMRUAddElementHdr", "CAAAfrGeoCommands", "CAAAfrMRUAddElementCmd", (void *) NULL); ... |
In the CNext/resources/msgcatalog directory [10] you will find in the CAAAfrGeneralWksAddinHeader.CATNls file the following lines:
... CAAAfrGeneralWksAddinHeader.CAAAfrMRUAddElementHdr.Category = "File" ; CAAAfrGeneralWksAddinHeader.CAAAfrMRUAddElementHdr.Title = "Add Item in MRU" ; CAAAfrGeneralWksAddinHeader.CAAAfrMRUAddElementHdr.ShortHelp = "Add Item in MRU" ; CAAAfrGeneralWksAddinHeader.CAAAfrMRUAddElementHdr.Help = "Add Item in MRU" ; CAAAfrGeneralWksAddinHeader.CAAAfrMRUAddElementHdr.LongHelp = "Add Item in MRU This command adds a new item in the MRU list." ; ... |
and in the CAAAfrGeneralWksAddinHeader.CATRsc file
... CAAAfrGeneralWksAddinHeader.CAAAfrMRUAddElementHdr.Icon.Normal = "I_CAAMRUAddItem" ; ... |
where I_CAAMRUAddItem is the following icon: and that you retrieve in the CNext/resources/graphic/icons/normal directory.
[Top]
This use case has explained how to create a command header whose the graphic representation is customized:
The data model is kept by an unique instance during the session.
[Top]
[1] | Creating a Combo Command Header |
[2] | The Command Headers |
[3] | Making Your Document Independent Command Available in All Workbenches |
[4] | CATDlgPushItem |
[5] | Building and Launching a CAA V5 Use Case |
[6] | Creating Interfaces |
[7] | The Callback Mechanism (Technical Article) |
[8] | The Callback Mechanism (Use Case) |
[9] | The CAA Command Model |
[10] | Creating Resources for Command Headers |
[11] | Object Modeler Inheritances |
[Top] |
Version: 1 [Feb 2004] | Document created |
[Top] |
Copyright © 2004, Dassault Systèmes. All rights reserved.