<< Return to Main Index

< Return to Class Index

CGXProperties::SubstTokenText

virtual CString SubstTokenText(int nToken, CString& sRest);

nToken

A unique index for the token. AddToken generates this index.

sRest

The remaining cell text string.

Return Value

The string which shall be printed instead of the token.

Remarks

Override this method if you want to provide more tokens to the end user.

If you want to provide more tokens to the end user, the following steps are necessary:

1.Derive a class from CGXProperties.

2.Register the tokens by calling AddToken. Save the index returned by AddToken into a member variable.

3.Override SubstTokenText and compare nToken with the index returned by AddToken.  If it matches, you can replace the text.

Please note that tokens can also have arguments. You can call GetTokenArgs to determine any token arguments. See the example.

Control-Factory Specific ->

This method has been implemented using the abstraction mechanism as discussed in the chapter "Reducing the size of your application" in the user's guide. A call to the ImplementPrinting method from within the control factory class' InitializeGridComponents method will make the concrete implementation of this method available to your application.

If no concrete implementation is available this method returns an empty string. No action is performed.

END Control-Factory Specific

See Also

CGXProperties::AddToken CGXProperties::GetTokenArgs

ExampleThis example illustrates how to provide more tokens to the end user.

class CMyProperties : public CGXProperties
{
   GRID_DECLARE_SERIAL(CMyProperties);
public:
   CMyProperties();

   // substitute tokens
   virtual CString SubstTokenText(int nToken, CString& sRest);

protected:
   int m_nTokDate;
   int m_nTokText;
};

CMyProperties::CMyProperties()
{
   m_nTokDate = AddToken("#DATE#");
   m_nTokText = AddToken("$T");

   CGXData& mapDataHeader = GetDataHeader();
   CGXData& mapDataFooter = GetDataFooter();

   mapDataHeader.DeleteContents();

   mapDataHeader.StoreStyleRowCol(1, 2, CGXStyle()
      .SetValue("Header")
      .SetFont(CGXFont().SetSize(10))
      , gxCopy
      );

   mapDataHeader.StoreStyleRowCol(2, 2, CGXStyle()
      .SetValue("$R")
      .SetFont(CGXFont()
         .SetBold(TRUE)
         .SetSize(16))
      , gxCopy
      );

   mapDataHeader.StoreStyleRowCol(2, 3, CGXStyle()
      .SetValue("Datum: #DATE#{%x, %X}")  // see  GXIntlStrFTime for date formatting
      .SetFont(CGXFont().SetSize(10))
      , gxCopy
      );


   mapDataFooter.DeleteContents();

   mapDataFooter.StoreStyleRowCol(1, 2, CGXStyle()
      .SetValue("Footer")
      .SetFont(CGXFont().SetSize(10).SetBold(TRUE))
      , gxCopy
      );
   mapDataFooter.StoreStyleRowCol(2, 2, CGXStyle()
      .SetValue("- $T -")
      , gxCopy
      );
}

CString CMyProperties::SubstTokenText(int nToken, CString& sRest)
{
   if (nToken == m_nTokDate)
   {
      CString args = GetTokenArgs(sRest);
      if (args.IsEmpty())
         args = "%c";

      TCHAR szBuffer[255];

      // GetCurrentTime
      time_t ti = time(NULL);
      struct tm* ptmTemp = localtime(&ti);
      ASSERT(ptmTemp != NULL); // make sure the time has been initialized!

      if (!GXIntlStrFtime(AfxGetResourceHandle(), GX_IDS_TIME_ADAY1,
            szBuffer, sizeof(szBuffer), args, ptmTemp))
         szBuffer[0] = '\0';
      return szBuffer;
   }
   else if (nToken == m_nTokText)
   {
      return "Text-Token";
   }

   return CGXProperties::SubstTokenText(nToken, sRest);
}

CGXProperties

Class Overview | Class Members