Zhu Lihua wrote:

>> "Modules" here means the application module. While slotids mark a
>> functionality in the UI, whichids mark the corresponding attribute in
>> the document core of the application.
> Does it mean WhichID is a root ID of the corresponding SlotIDs?
> I guess, common functionality in different module have different SlotID,
> but they have the same WhichID which match this functionality. So we
> convert it to WhichID, and the program know which functionality is it.
> Right?

A whichid is only valid in the code of a particular application module.
Even slotids that are common to all modules have different whichids
assigned in the applications).

>> The slotid is a universal ID, it is understood in all modules. In the
>> code of each application module there is a conversion table that
>> converts the slot ids into the matching whichids.
> Where is this table? I believe it helps to me to understand the
> relationship of the SlotID and WhichID. Does it exist as a file? or Is
> it a dynamic array in the run time?

This mapping table is constructed as part of the module's pool. In
Writer this e.g. happens in sw/source/core/bastyp/init.cxx, in Calc it's
sc/source/core/data/docpool.cxx.

You will find an array of SlotIds there, and the the whichid belonging
to each slotid just is the position in this array plus an offset that is
specified when the pool is created. In Calc you can see:

static SfxItemInfo __READONLY_DATA  aItemInfos[] =
{
    { SID_ATTR_CHAR_FONT, SFX_ITEM_POOLABLE },       // ATTR_FONT
    { SID_ATTR_CHAR_FONTHEIGHT, SFX_ITEM_POOLABLE }, // ATTR_FONT_HEIGHT
    { SID_ATTR_CHAR_WEIGHT, SFX_ITEM_POOLABLE },     // ATTR_FONT_WEIGHT
.....
};

where the index of the slotid SID_ATTR_CHAR_FONT is 0.

When the ctor of the ScDocumentPool initializes its base class
SfxItemPool it hands over this array and an offset:

ScDocumentPool::ScDocumentPool(
        SfxItemPool* pSecPool, BOOL bLoadRefCounts )
  :SfxItemPool (
    String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("ScDocumentPool")),
        ATTR_STARTINDEX, ATTR_ENDINDEX,
        aItemInfos, NULL, bLoadRefCounts ),
        pSecondary      ( pSecPool )
{
......
}

This offset is ATTR_STARTINDEX (=100 as defined in sc/inc/scitems.hxx).
So now the pool knows that the whichid 100 is assigned to the slotid
SID_ATTR_CHAR_FONT, 101 is assigned to SID_ATTR_CHAR_FONTHEIGHT etc.

If you look at the definition of aItemInfos, you will find some array
members with slotid 0:

  { SID_ATTR_CHAR_RELIEF, SFX_ITEM_POOLABLE },      //
ATTR_FONT_RELIEF                  { SID_ATTR_ALIGN_HYPHENATION, 
SFX_ITEM_POOLABLE },//
ATTR_HYPHENATE
  { 0,                  SFX_ITEM_POOLABLE },        // ATTR_SCRIPTSPACE         

These whichids don't have a slotid assigned. A whichid whose attribute
is not manipulated by dispatch calls or generic dialogs (see below)
doesn't need a slotid as this is the only place in the code where
slotids are needed. To handle the attribute in the document core code
the whichid is sufficient.

OTOH many slotids don't have a whichid assigned in a particular pool.
Only core attributes (as the Font attributes shown above) have it, but
e.g. an SfxDocumentInfoItem doesn't.

If an SfxItemSet is created, it must get an SfxItemPool. If an item is
put into the SfxItemSet that matches the specified "WhichRanges" (an
unfortunate name as it can contain whichids as well as slotids) of the
SfxItemSet, the SfxItemSet checks whether the id is a slotid or a
whichid ( this is simple: slotids are >= 5000, whichids are < 5000). The
SfxItemSet can convert the slotid to the assigned whichid by using the
table of the pool. If no whichid for the slotid is found in the pool,
the item keeps its slotid. Getting this item back from the pool must be
aware of that and use whichids where necessary.

This procedure is needed in two scenarios: UI controls (e.g. toolbar
controls) and generic (application independent) dialogs. Both UI
elements may pass information as SfxPoolItems in an SfxItemSet. As they
don't know in which application they are used, they use the globally
unique slotids to identify items. OTOH the document that finally
receives the call wants to work with its own whichids. So the SfxItemSet
and its SfxItemPool together work as a "translator" from "slot language"
to "which language". In case of generic dialogs the SfxItemSet is passed
to them when the dialog is constructed, in case of dispatch calls from
UI controls the SfxItemSet is retrieved from the document by the
framework code that receives the SfxPoolItems from the control and puts
it into an SfxItemSet that the document code receives as part of an
SfxRequest object.

HTH,
Mathias


-- 
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
Please don't reply to "nospamfor...@gmx.de".
I use it for the OOo lists and only rarely read other mails sent to it.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@openoffice.org
For additional commands, e-mail: dev-h...@openoffice.org

Reply via email to