home *** CD-ROM | disk | FTP | other *** search
- /*
- GIK/2 1.0.1 EWYBACC.C 5621-432 (C) COPYRIGHT IBM CORP 1993. ALL RIGHTS RESERVED. LICENSED MATERIALS - PROPERTY OF IBM.
- */
- /**********************************************************************/
- /* */
- /* MODULE PROLOGUE */
- /* */
- /* COMPONENT NAME: C++ CLASS BROWSER EXAMPLE */
- /* */
- /* MODULE NAME: EWYBACC */
- /* */
- /* DESCRIPTIVE NAME: Custom Dialogs and Routines */
- /* */
- /* PURPOSE: */
- /* */
- /* This module contains the dialogs and the tree handling functions */
- /* for the C++ class browser example. */
- /* */
- /* The sample code shows, how to drive a diagram from application */
- /* data. */
- /* */
- /* The graphical symbols are linked to the application data by */
- /* storing a pointer to their data structure. */
- /* */
- /* The application data is linked to the graphical data by storing */
- /* the symbol handles. */
- /* */
- /* COPYRIGHT: (C) 1993 IBM Corporation */
- /* */
- /* DISCLAIMER OF WARRANTIES. The following [enclosed] code is */
- /* sample code created by IBM Corporation. This sample code is not */
- /* part of any standard or IBM product and is provided to you solely */
- /* for the purpose of assisting you in the development of your */
- /* applications. The code is provided "AS IS", without */
- /* warranty of any kind. IBM shall not be liable for any damages */
- /* arising out of your use of the sample code, even if they have been */
- /* advised of the possibility of such damages. */
- /**********************************************************************/
-
- /*--------------------------------------------------------------------*/
- /* INCLUDE RELATED DEFINES */
- /*--------------------------------------------------------------------*/
-
- #define INCL_DOS /* OS/2 definitions */
- #define INCL_PM /* PM definitions */
-
- /*--------------------------------------------------------------------*/
- /* HEADER FILES */
- /*--------------------------------------------------------------------*/
-
- #include <os2.h> /* OS/2 standard header */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <malloc.h>
- #include <ewyga.h> /* GS main header file */
- #include "ewybadf.h" /* Generated header file */
- #include "ewybacc.h" /* module header */
- #include "ewybarc.h" /* resource constants */
- #include "ewybapa.h" /* C++ mini parser */
-
- /*--------------------------------------------------------------------*/
- /* LOCAL CONSTANTS */
- /*--------------------------------------------------------------------*/
- /*--------------------------------------------------------------------*/
- /* LOCAL VARIABLES */
- /*--------------------------------------------------------------------*/
-
- static CHAR M_szRoot[] = "*TOP*";
- static CHAR M_szInvalid[] = "*DUMP*";
-
- /*--------------------------------------------------------------------*/
- /* LOCAL FUNCTION PROTOTYPES */
- /*--------------------------------------------------------------------*/
-
- static VOID InitTree(DHND hDiag);
- static VOID DeleteTree(DHND hDiag);
- static VOID InsertNode(PNODETYPE pParent,PNODETYPE pChild);
- static PNODETYPE SearchNode(PNODETYPE pTop,PSZ pszName);
- static MRESULT EXPENTRY BrowseDlgProc(HWND hwndDlg,ULONG ulMsg,MPARAM
- mp1,MPARAM mp2);
-
- /*--------------------------------------------------------------------*/
- /* CODE */
- /*--------------------------------------------------------------------*/
- /**********************************************************************/
- /* BuildTree */
- /* */
- /* Parameters: */
- /* DHND hDiag (I): Diagram handle. */
- /* PSZ pszFile (I): C++ header file name */
- /* */
- /* Returns: */
- /* VOID */
- /* */
- /* Description: */
- /* The function builds a new tree for a C++ class hierarchy */
- /**********************************************************************/
-
- VOID BuildTree(DHND hDiag,PSZ pszFile)
- {
-
- /********************************************************************/
- /* ** init the tree ** */
- /********************************************************************/
-
- DeleteTree(hDiag);
- InitTree(hDiag);
-
- /********************************************************************/
- /* ** parse the tree ** */
- /********************************************************************/
-
- ParseFile(hDiag, pszFile);
-
- /********************************************************************/
- /* ** ok ** */
- /********************************************************************/
-
- return ;
- }
-
- /**********************************************************************/
- /* InitTree */
- /* */
- /* Parameters: */
- /* DHND hDiag (I): Diagram handle. */
- /* */
- /* Returns: */
- /* VOID */
- /* */
- /* Description: */
- /* The function initializes a C++ class tree */
- /**********************************************************************/
-
- static VOID InitTree(DHND hDiag)
- {
- PNODETYPE pRoot; /* root node */
- PNODETYPE pInvalid; /* for invalid class */
- PSZ pszParents[2]; /* parent names */
- INT i;
-
- /********************************************************************/
- /* ** allocate and initialize root node ** */
- /********************************************************************/
-
- pRoot = malloc(sizeof(NODETYPE));
- memset(pRoot, 0, sizeof(NODETYPE));
- strcpy(pRoot->szClassName, M_szRoot);
- pRoot->pszMethods = NULL;
- pRoot->pUpLink = NULL;
- pRoot->pLeftDown = NULL;
- pRoot->pRightDown = NULL;
- pRoot->pLeftSame = NULL;
- pRoot->pRightSame = NULL;
- pRoot->fDisplay = FALSE;
- pRoot->hUpLink = GS_INVALID_SHND;
- for (i = 0; i < MAX_UPLINKS; i++)
- {
- pRoot->hUpLinkMulti[i] = GS_INVALID_SHND;
- pRoot->pUpLinkMulti[i] = NULL;
- }
-
- /********************************************************************/
- /* ** add root node ** */
- /********************************************************************/
-
- GsAddSym(hDiag, &pRoot->hSym, NODE, NODE_FORM);
- GsPutPartText(hDiag, pRoot->hSym, NODE_TEXT, pRoot->szClassName);
-
- /********************************************************************/
- /* ** store a pointer to the symbol ** */
- /********************************************************************/
-
- GsPutSymPointer(hDiag, pRoot->hSym, pRoot);
-
- /********************************************************************/
- /* ** store the root pointer in the diagram ** */
- /********************************************************************/
-
- GsPutDiagPointerN(hDiag, 0, pRoot);
-
- /********************************************************************/
- /* ** add invalid node ** */
- /********************************************************************/
-
- pszParents[0] = M_szRoot;
- pszParents[1] = NULL;
- InsertClass(hDiag, M_szInvalid, pszParents, NULL);
- pInvalid = SearchNode(pRoot, M_szInvalid);
- pInvalid->fDisplay = FALSE;
-
- /********************************************************************/
- /* ** store the invalid pointer in the diagram ** */
- /********************************************************************/
-
- GsPutDiagPointerN(hDiag, 1, pInvalid);
- return ;
- }
-
- /**********************************************************************/
- /* DeleteTree */
- /* */
- /* Parameters: */
- /* DHND hDiag (I): Diagram handle. */
- /* */
- /* Returns: */
- /* VOID */
- /* */
- /* Description: */
- /* The function deletes the class tree */
- /**********************************************************************/
-
- static VOID DeleteTree(DHND hDiag)
- {
- SHND hSym; /* symbol handle */
- PNODETYPE pNode; /* node */
-
- /********************************************************************/
- /* ** collect all nodes ** */
- /********************************************************************/
-
- GsCollectSym(hDiag, GS_NODE, GS_ANY_SYM, GS_LOWER_FIRST);
- while ((GsGetCollectedSym(hDiag, &hSym) != GSE_COLLECTION_EMPTY))
- {
- if (hSym != GS_INVALID_SHND)
- {
- pNode = NULL;
- GsGetSymPointer(hDiag, hSym, (PVOID)(&pNode));
- if (pNode != NULL)
- {
-
- /**************************************************************/
- /* ** delete the node ** */
- /**************************************************************/
-
- if (pNode->pszMethods != NULL)
- free(pNode->pszMethods);
- free(pNode);
- }
- }
- }
-
- /********************************************************************/
- /* ** and now delete all GIK/2 symbols and links ** */
- /********************************************************************/
-
- GsDeleteAllSym(hDiag);
- GsPutDiagPointerN(hDiag, 0, NULL);
- GsPutDiagPointerN(hDiag, 1, NULL);
- return ;
- }
-
- /**********************************************************************/
- /* InsertClass */
- /* */
- /* Parameters: */
- /* DHND hDiag (I): diagram handle */
- /* PSZ pszName (I): C++ class name */
- /* PSZ pszParentName[] (I): names of the parent class(es), */
- /* a NULL in the array means */
- /* no more entries */
- /* PSZ pszMethods (I): pointer to a text buffer which */
- /* contains the class methods */
- /* */
- /* Returns: */
- /* VOID */
- /* */
- /* Description: */
- /* The function inserts the given C++ class */
- /**********************************************************************/
-
- VOID InsertClass(DHND hDiag,PSZ pszName,PSZ pszParentName[],PSZ
- pszMethods)
- {
- PNODETYPE pClass; /* class to insert */
- PNODETYPE pParent; /* superclass */
- PNODETYPE pMultiParent; /* superclass */
- PNODETYPE pRoot; /* root of tree */
- PNODETYPE pInvalid; /* for invalid superclasses */
- SHND hParent; /* handle of parent symbol */
- INT i;
-
- /********************************************************************/
- /* ** get root and invalid node pointers ** */
- /********************************************************************/
-
- pRoot = NULL;
- pInvalid = NULL;
- GsGetDiagPointerN(hDiag, 0, (PVOID)(&pRoot));
- GsGetDiagPointerN(hDiag, 1, (PVOID)(&pInvalid));
-
- /********************************************************************/
- /* ** allocate and initialize new node ** */
- /********************************************************************/
-
- pClass = malloc(sizeof(NODETYPE));
- memset(pClass, 0, sizeof(NODETYPE));
- strcpy(pClass->szClassName, pszName);
- pClass->pszMethods = pszMethods; /* buffer transfer not needed */
- pClass->fDisplay = TRUE;
- for (i = 0; i < MAX_UPLINKS; i++)
- {
- pClass->hUpLinkMulti[i] = GS_INVALID_SHND;
- }
-
- /********************************************************************/
- /* ** search for superclass ** */
- /********************************************************************/
-
- if (pszParentName[0] != NULL)
- pParent = SearchNode(pRoot, pszParentName[0]);
- else
- pParent = pRoot;
- if (pParent == NULL)
- pParent = pInvalid;
- if (pParent == NULL)
- return ;
-
- /********************************************************************/
- /* ** link with other nodes in the tree ** */
- /********************************************************************/
-
- InsertNode(pParent, pClass);
-
- /********************************************************************/
- /* ** now add GIK/2 symbols and links ** */
- /********************************************************************/
-
- GsAddSym(hDiag, &pClass->hSym, NODE, NODE_FORM);
- GsAddSym(hDiag, &pClass->hUpLink, LINK, LINK_FORM);
-
- /********************************************************************/
- /* ** connect the class with its superclass ** */
- /********************************************************************/
-
- GsPutSymTerminal(hDiag, pClass->hUpLink, GS_SOURCE, pParent->hSym);
- GsPutSymTerminal(hDiag, pClass->hUpLink, GS_TARGET, pClass->hSym);
-
- /********************************************************************/
- /* ** set class name ** */
- /********************************************************************/
-
- GsPutPartText(hDiag, pClass->hSym, NODE_TEXT, pClass->szClassName);
-
- /********************************************************************/
- /* ** store a pointer to the node ** */
- /********************************************************************/
-
- GsPutSymPointer(hDiag, pClass->hSym, pClass);
-
- /********************************************************************/
- /* ** store superclass symbol handle ** */
- /********************************************************************/
-
- if (pClass->pUpLink == NULL)
- hParent = GS_INVALID_SHND;
- else
- hParent = pClass->pUpLink->hSym;
- pClass->hUpLink = hParent;
-
- /********************************************************************/
- /* ** handle multiple inheritance ** */
- /********************************************************************/
-
- i = 1;
- while (pszParentName[i] != NULL)
- {
- pMultiParent = SearchNode(pRoot, pszParentName[i]);
- if (pMultiParent != NULL)
- {
-
- /****************************************************************/
- /* ** another superclass found ... ** */
- /****************************************************************/
-
- pClass->pUpLinkMulti[i-1] = pMultiParent;
-
- /****************************************************************/
- /* ** add also a link to this superclass ** */
- /****************************************************************/
-
- GsAddSym(hDiag, &pClass->hUpLinkMulti[i-1], LINK, LINK_FORM);
- GsPutSymTerminal(hDiag, pClass->hUpLinkMulti[i-1], GS_SOURCE,
- pMultiParent->hSym);
- GsPutSymTerminal(hDiag, pClass->hUpLinkMulti[i-1], GS_TARGET,
- pClass->hSym);
- }
- i++;
- }
- return ;
- }
-
- /**********************************************************************/
- /* InsertNode */
- /* */
- /* Parameters: */
- /* PNODETYPE pParent (I): parent of node to insert */
- /* PNODETYPE pNode (I): node to insert */
- /* */
- /* Returns: */
- /* VOID */
- /* */
- /* Description: */
- /* The function inserts the given node into the class tree */
- /**********************************************************************/
-
- static VOID InsertNode(PNODETYPE pParent,PNODETYPE pNode)
- {
- PNODETYPE pNeighbor;
- INT i;
-
- /********************************************************************/
- /* ** initialize node ** */
- /********************************************************************/
-
- pNode->pLeftDown = NULL;
- pNode->pRightDown = NULL;
- pNode->pLeftSame = NULL;
- pNode->pRightSame = NULL;
- pNode->pUpLink = pParent;
- for (i = 0; i < MAX_UPLINKS; i++)
- {
- pNode->pUpLinkMulti[i] = NULL;
- }
-
- /********************************************************************/
- /* ** link with other nodes ** */
- /********************************************************************/
-
- if (pParent->pRightDown == NULL)
- {
-
- /******************************************************************/
- /* ** parent has no childs ** */
- /******************************************************************/
-
- pParent->pLeftDown = pNode;
- pParent->pRightDown = pNode;
- }
- else
- {
-
- /******************************************************************/
- /* ** parent has at least one child ** */
- /******************************************************************/
-
- pNeighbor = pParent->pRightDown;
- pNeighbor->pRightSame = pNode;
- pNode->pLeftSame = pNeighbor;
- pParent->pRightDown = pNode;
- }
- return ;
- }
-
- /**********************************************************************/
- /* SearchNode */
- /* */
- /* Parameters: */
- /* PNODETYPE pRoot (I): root (top) node of the tree */
- /* PSZ pszName (I): node name to search for */
- /* */
- /* Returns: */
- /* PNODETYPE pointer to a node */
- /* or NULL for not found */
- /* */
- /* Description: */
- /* The function searches for the specified node */
- /**********************************************************************/
-
- static PNODETYPE SearchNode(PNODETYPE pRoot,PSZ pszName)
- {
- PNODETYPE p;
-
- if (pRoot == NULL)
- return NULL;
-
- /********************************************************************/
- /* ** node found ** */
- /********************************************************************/
-
- if (!strcmp(pRoot->szClassName, pszName))
- return (pRoot);
-
- /********************************************************************/
- /* ** search left children (recursivly) ** */
- /********************************************************************/
-
- p = SearchNode(pRoot->pLeftDown, pszName);
- if (p != NULL)
- return (p);
-
- /********************************************************************/
- /* ** search right siblings (recursivly) ** */
- /********************************************************************/
-
- p = SearchNode(pRoot->pRightSame, pszName);
- if (p != NULL)
- return (p);
-
- /********************************************************************/
- /* ** node not found ** */
- /********************************************************************/
-
- return NULL;
- }
-
- /**********************************************************************/
- /* ShowClassMethods */
- /* */
- /* Parameters: */
- /* DHND hDiag (I): diagram handle */
- /* SHND hSym (I): symbol handle */
- /* */
- /* Returns: */
- /* VOID */
- /* */
- /* Description: */
- /* The function brings up a dialog to show the class methods */
- /* of the given C++ class */
- /**********************************************************************/
-
- VOID ShowClassMethods(DHND hDiag,SHND hSym)
- {
- HWND hwndClient; /* client window handle */
- HMODULE hmodCustomCode; /* custom code module */
- PNODETYPE pNode; /* pointer to node data */
-
- /********************************************************************/
- /* ** get the pointer to the node data ** */
- /********************************************************************/
-
- pNode = NULL;
- GsGetSymPointer(hDiag, hSym, (PVOID)(&pNode));
- if ((pNode == NULL) || (!pNode->fDisplay))
- return ;
-
- /********************************************************************/
- /* ** get diagram window handle and custom code module handle ** */
- /********************************************************************/
-
- GsGetHwnd(hDiag, GS_WIN_MAIN, FID_CLIENT, 0, &hwndClient);
- GsGetCcModuleHandle(hDiag, &hmodCustomCode);
-
- /********************************************************************/
- /* ** show class methods (MLE edit field) ** */
- /********************************************************************/
-
- WinDlgBox(HWND_DESKTOP,
- hwndClient,
- BrowseDlgProc,
- hmodCustomCode,
- DID_BROWSE_DIALOG,
- pNode);
- return ;
- }
-
- /**********************************************************************/
- /* BrowseDlgProc */
- /* */
- /* Parameters: */
- /* HWND hwndDlg (I): Dialog window handle */
- /* ULONG ulMsg (I): PM message */
- /* MPARAM mp1 (I): message parameter 1 */
- /* MPARAM mp2 (I): message parameter 2 */
- /* */
- /* Returns: */
- /* MRESULT */
- /* */
- /* Description: */
- /* This is the dialog procedure for browsing the class methods. */
- /* The dialog is invoked, whenever the user double clicks */
- /* on a node symbol representing a C++ class. */
- /* */
- /* Browsing is done with a readonly MLE field. */
- /* */
- /**********************************************************************/
-
- static MRESULT EXPENTRY BrowseDlgProc(HWND hwndDlg,ULONG ulMsg,MPARAM
- mp1,MPARAM mp2)
- {
- static PNODETYPE pNode; /* pointer to node data */
-
- switch (ulMsg)
- {
- case WM_INITDLG :
-
- /****************************************************************/
- /* ** get the pointer to the node data ** ** this was passed as */
- /* a parameter to the dialog procedure ** */
- /****************************************************************/
-
- pNode = PVOIDFROMMP(mp2);
-
- /****************************************************************/
- /* ** set window title and MLE text ** */
- /****************************************************************/
-
- WinSetWindowText(hwndDlg,
- pNode->szClassName);
- if (pNode->pszMethods != NULL)
- {
- WinSendDlgItemMsg(hwndDlg,
- DID_CLASS_METHODS,
- MLM_INSERT,
- MPFROMP(pNode->pszMethods),
- 0);
- }
- return ((MRESULT)0);
- case WM_CLOSE :
- WinDismissDlg(hwndDlg,
- FALSE);
- break;
- case WM_COMMAND :
- break;
- default :
- return (WinDefDlgProc(hwndDlg, ulMsg, mp1, mp2));
- }
- return ((MRESULT)0);
- }