menupref.h File Reference

(r1785/r751)

#include "oilfiles.h"
#include "menuitem.h"

Go to the source code of this file.

Functions

MenuItemGetMenuPreferences (UINT32 ResourceID)
 Parses a Menu Script representing the Camelot Default Menus.
MenuItemCreateMenuItem (TCHAR *OpToken, UINT32 ParentId, BOOL Separator)
void ClearArray (TCHAR buffer[], INT32 size)
 Initialises a Character Array with Nulls.
BOOL GetKeyword (CCResTextFile *pResScript, TCHAR keyword[], INT32 size)
 Parses a Menu Script Keyword.
BOOL GetToken (CCResTextFile *pResScript, TCHAR OpToken[], INT32 TokenSize)
 Parses a Menu Script Token.
BOOL GetSeparator (CCResTextFile *pMenuScript, const String &separator_sym, TCHAR SepKeyword[], INT32 size)
 Parses a Menu Script Menu Separator Token.

Variables

UINT32 WindowMenuID


Function Documentation

void ClearArray TCHAR  buffer[],
INT32  size
[inline]
 

Initialises a Character Array with Nulls.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/8/93
Parameters:
Char Array [INPUTS] Integer - Array Size
- [OUTPUTS]
Returns:
-

Errors: -

Definition at line 139 of file menupref.cpp.

00140 {
00141     ::memset(buffer, 0, size * sizeof(buffer[0]));
00142 }

MenuItem* CreateMenuItem TCHAR OpToken,
UINT32  ParentId,
BOOL  Separator
 

BOOL GetKeyword CCResTextFile pResScript,
TCHAR  keyword[],
INT32  size
 

Parses a Menu Script Keyword.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/8/93
Parameters:
Input Stream - Menu Script [INPUTS] Integer - Maximum size of keyword
Char Array - The Keyword [OUTPUTS]
Returns:
TRUE if Keyword is found FALSE otherwize

Errors: -

Definition at line 373 of file menupref.cpp.

00374 {
00375     // Get Keyword
00376     TCHAR ch; 
00377     INT32 i = 0;            
00378     
00379     ClearArray(keyword, size);
00380 
00381     pResScript->read(ch);
00382     
00383     // if not a keyword return false!
00384     if (!String::IsAlpha(ch) && (!pResScript->eof()))
00385         return FALSE;   
00386        
00387     while (String::IsAlpha(ch) && !pResScript->eof() && i < size)
00388     {
00389         keyword[i++] = ch;
00390         pResScript->read(ch);
00391     }           
00392 
00393     if (!pResScript->eof()) 
00394         return TRUE;
00395     else
00396     {
00397 //      TRACEUSER( "JustinF", _T("Menu GetKeyword() - read %s\n"), keyword);
00398         return FALSE;   
00399     }
00400 }           

MenuItem* GetMenuPreferences UINT32  ResourceID  ) 
 

Parses a Menu Script representing the Camelot Default Menus.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/8/93
Parameters:
ResourceID representing the menu resource to be loaded. [INPUTS]
- [OUTPUTS]
Returns:
A MenuItem representing the default Menu that was parsed in or NULL if failed (SetError will be called)

Errors: - SeeAlse: GetToken();

See also:
GetKeyword();

GetSeparator();

Definition at line 164 of file menupref.cpp.

00165 {                              
00166     // Keyword Buffer
00167     const INT32 keywordSize     = 10;
00168     TCHAR keyword[keywordSize];
00169 
00170     // Token Buffer
00171     const INT32 TokenSize   = 30;
00172     TCHAR OpToken[TokenSize];
00173 
00174     // Lexical Tokens
00175     const String_256 menu_sym       = "MENU";
00176     const String_256 submenu_sym    = "SUBMENU";
00177     const String_256 menuitem_sym   = "MENUITEM";
00178     const String_256 end_sym        = "END";
00179     const String_256 separator_sym  = "SEPARATOR";
00180     
00181     CCResTextFile MenuScript;   // Resource File
00182                                                 
00183     // Open Resource File                                                
00184     MenuScript.open(ResourceID, _R(IDT_CAM_MENU_RES));
00185 
00186     // Stack of all the Menus and SubMenus currently in Scope!             
00187     List MenuStack;
00188     
00189     MenuItem*       pCurMenu = NULL;    // Menu Currently in Scope
00190 
00191     MenuItem*       pMenu = NULL; 
00192     MenuItem*       pSubMenu; 
00193     MenuItem*       pMenuItem; 
00194     
00195     while ((MenuScript.isOpen()) && (!MenuScript.eof()))
00196     {
00197         ClearArray(keyword, keywordSize);
00198 
00199         //Get The Keyword
00200         if (GetKeyword(&MenuScript, keyword, keywordSize))
00201         {
00202         // MENU reserved word
00203             if (menu_sym == keyword)                
00204             {
00205                 ERRORIF((!GetToken(&MenuScript, OpToken, TokenSize)), 
00206                         _R(IDE_SYNTAX_ERROR), 
00207                         NULL);
00208                 
00209                 pMenu = new MenuItem(OpToken);
00210 
00211                 if (pMenu==NULL)
00212                 {
00213                     TRACEALL( _T("GetMenuPrefs: failed to allocate MenuItem"));
00214                     break;                                          // willeventually return NULL
00215                 }
00216                 
00217                 pCurMenu = pMenu;
00218             }
00219             // SUBMENU reserved word
00220             else if (submenu_sym == keyword)
00221             {                                       
00222                 ERRORIF((!GetToken(&MenuScript, OpToken, TokenSize)), 
00223                         _R(IDE_SYNTAX_ERROR), 
00224                         NULL);
00225 
00226                 TRACEUSER( "luke", _T("SUBMENU \"%s\" \"%s\"\n"), OpToken, OPTOKEN_DEBUG_MENU );
00227 
00228 #if !defined(_DEBUG)
00229                 // Remove DEBUG menu
00230                 if( 0 == camStrcmp( OpToken, OPTOKEN_DEBUG_MENU ) )
00231                 {
00232                     TRACEUSER( "luke", _T(">-SUBMENU %s\n"), OPTOKEN_DEBUG_MENU );
00233                     MenuStack.AddHead(pCurMenu);    //Push Current Menu onto stack
00234                     pCurMenu = NULL;
00235                     continue;
00236                 }
00237 #endif
00238 
00239                 pSubMenu = CreateMenuItem(  OpToken, 
00240                                             pCurMenu->GetMenuId(),
00241                                             GetSeparator(   &MenuScript, 
00242                                                             separator_sym, 
00243                                                             keyword,
00244                                                             keywordSize)
00245                                          );
00246 
00247                 // stop now if run out of memory
00248                 if (pSubMenu==NULL)
00249                     break;
00250 
00251                 // Get the ID for the Window Menu
00252                 if (String(OpToken) == String(OPTOKEN_WINDOW_MENU))
00253                     //MenuItem ID must be first sub element of menu because in windows 
00254                     //menus do not have IDs
00255                     WindowMenuID = ((pSubMenu->GetMenuId()) + 1);
00256                 
00257                 pCurMenu->AddMenuItem(pSubMenu);
00258                 MenuStack.AddHead(pCurMenu);    //Push Current Menu onto stack
00259                 pCurMenu = pSubMenu;
00260             }
00261             // MENUITEM reserved word
00262             else if (menuitem_sym == keyword)
00263             {
00264                 ERRORIF((!GetToken(&MenuScript, OpToken, TokenSize)), 
00265                         _R(IDE_SYNTAX_ERROR), 
00266                         NULL);
00267 
00268 #if !defined(_DEBUG)
00269                 // Don't add menu itemns if parent not wanted
00270                 if( NULL == pCurMenu )
00271                     continue;
00272 #endif
00273 
00274                 pMenuItem = CreateMenuItem( OpToken,
00275                                             pCurMenu->GetMenuId(),
00276                                             GetSeparator(   &MenuScript, 
00277                                                             separator_sym, 
00278                                                             keyword,
00279                                                             keywordSize)
00280                                           );
00281                 
00282                 if (pMenuItem != NULL)
00283                     pCurMenu->AddMenuItem(pMenuItem);
00284                 else
00285                     break;
00286 
00287             }
00288             // END reserved word
00289             else if (end_sym == keyword)
00290             {                                       // Pop Menu from stack
00291                 pCurMenu = (MenuItem*) MenuStack.RemoveHead();
00292                 // WEBSTER - markn 22/1/97
00293                 // Stops circular menu lists being generated when the last main menu item
00294                 // contains a sub menu (thank you mario)
00295                 if (pCurMenu != NULL)
00296                     pCurMenu->ClearPointers();
00297             }
00298         }
00299 
00300     }                                        
00301         
00302     MenuScript.close();
00303     
00304     return pMenu;   
00305 }

BOOL GetSeparator CCResTextFile pMenuScript,
const String separator_sym,
TCHAR  SepKeyword[],
INT32  size
 

Parses a Menu Script Menu Separator Token.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/8/93
Parameters:
Input Stream - Menu Script [INPUTS] constant String - Separator Symbol Char Array - Keyword Array Integer - size of Symbol
- [OUTPUTS]
Returns:
TRUE if Separator is found FALSE otherwize

Errors: -

Definition at line 482 of file menupref.cpp.

00486 {        
00487     // Get Keyword
00488     TCHAR ch;
00489     INT32 i = 0;            
00490 
00491     ClearArray(SepKeyword, size);
00492     
00493     //Go back one place and reread last character.
00494     pMenuScript->seek((pMenuScript->tell() - 1));
00495     pMenuScript->read(ch);
00496     
00497     //Find First Alpha Numeric Character
00498     while(!String::IsAlpha(ch) && (!pMenuScript->eof()) && (ch != '\n'))
00499         pMenuScript->read(ch);
00500 
00501     //Read in the keyword until not Alpha Numeric
00502     while (String::IsAlpha(ch) && (!pMenuScript->eof()) && (i < size))
00503     {
00504         SepKeyword[i++] = ch;
00505         pMenuScript->read(ch);
00506     }           
00507 
00508     if (separator_sym == SepKeyword)
00509         return TRUE;
00510     else
00511     {
00512 //      TRACEUSER( "JustinF", _T("Menu GetSeparator() - read %s\n"), SepKeyword);
00513         return FALSE;
00514     }
00515 }

BOOL GetToken CCResTextFile pMenuScript,
TCHAR  OpToken[],
INT32  TokenSize
 

Parses a Menu Script Token.

Author:
Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/8/93
Parameters:
Input Stream - Menu Script [INPUTS] Integer - Maximum size of Token
Char Array - The Token [OUTPUTS]
Returns:
TRUE if Token is found FALSE otherwize

Errors: -

Definition at line 418 of file menupref.cpp.

00419 {        
00420     // Get Keyword
00421     TCHAR ch;
00422     INT32 i = 0;            
00423 
00424     ClearArray(OpToken, TokenSize);
00425 
00426     //Go back one place and reread last character.
00427     pMenuScript->seek((pMenuScript->tell() - 1));
00428     pMenuScript->read(ch);
00429      
00430     while (StringBase::IsSpace(ch) && !pMenuScript->eof())
00431         pMenuScript->read(ch);
00432         
00433     if (ch == TEXT('"'))
00434         pMenuScript->read(ch);
00435     else
00436     {
00437 //      TRACEUSER( "JustinF", _T("Menu GetToken() - no opening \"\n"));
00438         pMenuScript->close();
00439         return FALSE;   
00440     }
00441 
00442     while ((String::IsAlphaNumeric(ch) || (ch == _T('_'))) &&
00443            ch != TEXT('"') &&
00444            !pMenuScript->eof() &&
00445            i < TokenSize)
00446     {
00447         OpToken[i++] = ch;
00448         pMenuScript->read(ch);
00449     }           
00450     
00451     if (ch == TEXT('"') && !pMenuScript->eof())
00452         return TRUE;
00453     else
00454     {
00455 //      TRACEUSER( "JustinF", _T("Menu GetToken() - read %s\n"), OpToken);
00456         pMenuScript->close();
00457         return FALSE;   
00458     }
00459 }


Variable Documentation

UINT32 WindowMenuID
 

Definition at line 121 of file menupref.cpp.


Generated on Sat Nov 10 03:49:34 2007 for Camelot by  doxygen 1.4.4