home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / componen / interact / demo / data.2 / samples / ansic / INTERACT / IFACE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  12.6 KB  |  429 lines

  1.  
  2.  
  3. /*
  4.  *   These are implementations of functions to be called by a program (like Obsydian)
  5.  *   to implement functionality on the IDO.
  6.  */
  7.  
  8. #include <WINDOWS.H>
  9. #include "idoiface.h"
  10. #include "pvido.h"
  11.  
  12.  
  13.  
  14. static char szDSLTextBuffer[500+1];
  15. static char szObjName[199+1];
  16.  
  17.  
  18. HINSTANCE IDO_LoadDLL()
  19. {
  20.    HINSTANCE hIDOdll;
  21.  
  22.  
  23. #ifdef WIN32
  24.    hIDOdll = LoadLibrary("pvido32.dll");
  25. #else
  26.    hIDOdll = LoadLibrary("pvido.dll");
  27. #endif
  28.    if(hIDOdll < HINSTANCE_ERROR)
  29.       return 0;
  30.    else
  31.       return hIDOdll;
  32. }
  33. void IDO_FreeDLL(HINSTANCE hIDOdll)
  34. {
  35.    FreeLibrary(hIDOdll);
  36. }
  37.  
  38.  
  39. HWND IDO_CreateInstance(HWND hDialog, HINSTANCE hApp, UINT id,
  40.                         int x, int y, int width, int height)
  41. {
  42.    long lStyle = WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_TABSTOP;
  43.    HWND hControl = 0;
  44.  
  45. #ifdef WIN32
  46.    hControl = CreateWindow("pvIDO32", "", lStyle, x, y, width, height, hDialog, (HMENU)id, hApp, NULL);
  47. #else
  48.    hControl = CreateWindow("pvIDO", "", lStyle, x, y, width, height, hDialog, (HMENU)id, hApp, NULL);
  49. #endif
  50.  
  51.    return hControl;
  52. }
  53. BOOL IDO_DestroyInstance(HWND hIDO)
  54. {
  55.    if(!IsWindow(hIDO))
  56.       return FALSE;
  57.  
  58.    DestroyWindow(hIDO);
  59.  
  60.    return TRUE;
  61. }
  62.  
  63.  
  64. void IDO_Move(HWND hIDO, int x, int y, int width, int height)
  65. {
  66.    if(!IsWindow(hIDO))
  67.       return;
  68.  
  69.    SetWindowPos(hIDO, NULL, x, y,
  70.                 width, height,
  71.                 SWP_NOZORDER);
  72. }
  73.  
  74. void IDO_ToggleUserIdoMenus(HWND hIDO)
  75. {
  76.    if(!IsWindow(hIDO))
  77.       return;
  78.  
  79.    if(idoGetPopupMenu(hIDO, IDOMENU_IDO))
  80.    {
  81.       idoSetPopupMenu(hIDO, IDOMENU_IDO, FALSE);
  82.       idoSetPopupMenu(hIDO, IDOMENU_ENTITY, FALSE);
  83.       idoSetPopupMenu(hIDO, IDOMENU_LINE, FALSE);
  84.    }
  85.    else
  86.    {
  87.       idoSetPopupMenu(hIDO, IDOMENU_IDO, TRUE);
  88.       idoSetPopupMenu(hIDO, IDOMENU_ENTITY, TRUE);
  89.       idoSetPopupMenu(hIDO, IDOMENU_LINE, TRUE);
  90.    }
  91. }
  92.  
  93. void IDO_ToggleEditMode(HWND hIDO)
  94. {
  95.    if(!IsWindow(hIDO))
  96.       return;
  97.  
  98.    if(idoGetEditMode(hIDO))
  99.       idoSetEditMode(hIDO, FALSE);
  100.    else
  101.       idoSetEditMode(hIDO, TRUE);
  102. }
  103.  
  104. void IDO_ToggleSnap(HWND hIDO)
  105. {
  106.    if(!IsWindow(hIDO))
  107.       return;
  108.  
  109.    if(idoGetSnapToGrid(hIDO))
  110.       idoSetSnapToGrid(hIDO, FALSE);
  111.    else
  112.       idoSetSnapToGrid(hIDO, TRUE);
  113. }
  114.  
  115. void IDO_ToggleGrid(HWND hIDO)
  116. {
  117.    if(!IsWindow(hIDO))
  118.       return;
  119.  
  120.    if(idoGetGridLines(hIDO))
  121.       idoSetGridLines(hIDO, FALSE);
  122.    else
  123.       idoSetGridLines(hIDO, TRUE);
  124. }
  125.  
  126.  
  127. void IDO_TogglePalette(HWND hIDO)
  128. {
  129.    if(!IsWindow(hIDO))
  130.       return;
  131.  
  132.    if(idoGetToolsPalette(hIDO))
  133.       idoSetToolsPalette(hIDO, FALSE);
  134.    else
  135.       idoSetToolsPalette(hIDO, TRUE);
  136. }
  137.  
  138.  
  139. void IDO_OpenJobFile(HWND hIDO, LPSTR lpszFile)
  140. {
  141.    BOOL bEnforce;
  142.  
  143.    if(!IsWindow(hIDO))
  144.       return;
  145.  
  146.    // were rules being enforced?
  147.    bEnforce = idoGetRulesEnforced(hIDO);
  148.    // turn off rules enforcement
  149.    idoSetRulesEnforced(hIDO, FALSE);
  150.    // read JOBS file
  151.    SendMessage(hIDO, IDOM_READJOBSFILE, 0, (LPARAM)(LPSTR)lpszFile);
  152.    // restore rules enforcement
  153.    idoSetRulesEnforced(hIDO, TRUE);
  154. }
  155.  
  156.  
  157. void IDO_Redraw(HWND hIDO)
  158. {
  159.    if(!IsWindow(hIDO))
  160.       return;
  161.  
  162.    InvalidateRect(hIDO, NULL, TRUE);
  163.    UpdateWindow(hIDO);
  164. }
  165.  
  166.  
  167. //***********************************************************************************
  168. //***********************************************************************************
  169.  
  170. /*
  171.  *   These are implementations of functions to be called by a program (like Obsydian)
  172.  *   to respond to messages from the IDO.
  173.  */
  174.  
  175. //***********************************************************************************
  176. //***********************************************************************************
  177.  
  178.  
  179. void IDO_n_ClickRelation(HWND hIDO, long lFlag)
  180. {
  181.    RELATION relation;
  182.  
  183.  
  184.    if(!idoGetNotifyRelation(hIDO, &relation))
  185.       return;
  186.  
  187.    switch(lFlag)
  188.    {
  189.       case NOTIFY_CLICK_LEFT :
  190.          wsprintf(szDSLTextBuffer, "Line Left Clicked: %ld, %s.", relation.id, (LPSTR)relation.name);
  191.          break;
  192.       case NOTIFY_CLICK_LEFT_DBL :
  193.          wsprintf(szDSLTextBuffer, "Line Left Dbl Clicked: %ld, %s.", relation.id, (LPSTR)relation.name);
  194.          break;
  195.       case NOTIFY_CLICK_RIGHT :
  196.          wsprintf(szDSLTextBuffer, "Line Right Clicked: %ld, %s.", relation.id, (LPSTR)relation.name);
  197.          break;
  198.       case NOTIFY_CLICK_RIGHT_DBL :
  199.          wsprintf(szDSLTextBuffer, "Line Right Dbl Clicked: %ld, %s.", relation.id, (LPSTR)relation.name);
  200.          break;
  201.    }
  202.  
  203.    DisplayDSL(szDSLTextBuffer);
  204. }
  205. void IDO_n_ClickEntity(HWND hIDO, long lFlag)
  206. {
  207.    ENTITY entity;
  208.  
  209.  
  210.    if(!idoGetNotifyEntity(hIDO, &entity))
  211.       return;
  212.  
  213.    switch(lFlag)
  214.    {
  215.       case NOTIFY_CLICK_LEFT :
  216.          wsprintf(szDSLTextBuffer, "Entity Left Clicked: %ld, %s.", entity.id, (LPSTR)entity.name);
  217.          break;
  218.       case NOTIFY_CLICK_LEFT_DBL :
  219.          wsprintf(szDSLTextBuffer, "Entity Left Dbl Clicked: %ld, %s.", entity.id, (LPSTR)entity.name);
  220.          break;
  221.       case NOTIFY_CLICK_RIGHT :
  222.          wsprintf(szDSLTextBuffer, "Entity Right Clicked: %ld, %s.", entity.id, (LPSTR)entity.name);
  223.          break;
  224.       case NOTIFY_CLICK_RIGHT_DBL :
  225.          wsprintf(szDSLTextBuffer, "Entity Right Dbl Clicked: %ld, %s.", entity.id, (LPSTR)entity.name);
  226.          break;
  227.    }
  228.  
  229.    DisplayDSL(szDSLTextBuffer);
  230. }
  231. void IDO_n_ClickIDO(HWND hIDO, long lFlag)
  232. {
  233.  
  234.    switch(lFlag)
  235.    {
  236.       case NOTIFY_CLICK_LEFT :
  237.          lstrcpy(szDSLTextBuffer, "IDO Left Clicked.");
  238.          break;
  239.       case NOTIFY_CLICK_LEFT_DBL :
  240.          lstrcpy(szDSLTextBuffer, "IDO Left Dbl Clicked.");
  241.          break;
  242.       case NOTIFY_CLICK_RIGHT :
  243.          lstrcpy(szDSLTextBuffer, "IDO Right Clicked.");
  244.          break;
  245.       case NOTIFY_CLICK_RIGHT_DBL :
  246.          lstrcpy(szDSLTextBuffer, "IDO Right Dbl Clicked.");
  247.          break;
  248.    }
  249.  
  250.    DisplayDSL(szDSLTextBuffer);
  251. }
  252.  
  253.  
  254. void IDO_n_FileIO(UINT Msg, LPSTR lpszFile)
  255. {
  256.    switch(Msg)
  257.    {
  258.        case IDOM_NOTIFY_BEFOREDIAGRAMLOADED :
  259.           wsprintf(szDSLTextBuffer, "Before Diagram Loaded: %s", lpszFile);
  260.           break;
  261.        case IDOM_NOTIFY_DIAGRAMLOADED :
  262.           wsprintf(szDSLTextBuffer, "Diagram Loaded: %s", lpszFile);
  263.           break;
  264.        case IDOM_NOTIFY_BEFOREDIAGRAMSAVED :
  265.           wsprintf(szDSLTextBuffer, "Before Diagram Saved: %s", lpszFile);
  266.           break;
  267.        case IDOM_NOTIFY_DIAGRAMSAVED :
  268.           wsprintf(szDSLTextBuffer, "Diagram Saved: %s", lpszFile);
  269.           break;
  270.        case IDOM_NOTIFY_BEFOREDIAGRAMRESET :
  271.           wsprintf(szDSLTextBuffer, "Before Diagram Reset. %s", lpszFile);
  272.           break;
  273.        case IDOM_NOTIFY_DIAGRAMRESET :
  274.           wsprintf(szDSLTextBuffer, "Diagram Reset. %s", lpszFile);
  275.           break;
  276.        case IDOM_NOTIFY_BEFOREPALETTELOADED :
  277.           wsprintf(szDSLTextBuffer, "Before Palette Loaded: %s", lpszFile);
  278.           break;
  279.        case IDOM_NOTIFY_PALETTELOADED :
  280.           wsprintf(szDSLTextBuffer, "Palette Loaded: %s", lpszFile);
  281.           break;
  282.        case IDOM_NOTIFY_BEFOREPALETTESAVED :
  283.           wsprintf(szDSLTextBuffer, "Before Palette Saved: %s", lpszFile);
  284.           break;
  285.        case IDOM_NOTIFY_PALETTESAVED :
  286.           wsprintf(szDSLTextBuffer, "Palette Saved: %s", lpszFile);
  287.           break;
  288.        case IDOM_NOTIFY_BEFOREPALETTERESET :
  289.           wsprintf(szDSLTextBuffer, "Before Palette Reset. %s", lpszFile);
  290.           break;
  291.        case IDOM_NOTIFY_PALETTERESET :
  292.           wsprintf(szDSLTextBuffer, "Palette Reset. %s", lpszFile);
  293.           break;
  294.        default :
  295.           MessageBeep(0);
  296.           break;
  297.    }
  298.    DisplayDSL(szDSLTextBuffer);
  299. }
  300.  
  301. void IDO_n_DeleteRelationRequest(HWND hIDO, UINT uAllowed, LPLINE_CLASS_STRUCT lpLine)
  302. {
  303.    wsprintf(szDSLTextBuffer, "Delete Relation?: %s, %s.", lpLine->name, lpLine->classname);
  304.    DisplayDSL(szDSLTextBuffer);
  305.  
  306.    /*
  307.     *   If we don't want to delete the relation, send IDO_NOTIFY_NODELETERELATION,
  308.     *   else don't do a thing to delete the relation.
  309.     */
  310.    if(IDNO==MessageBox(NULL, szDSLTextBuffer, "Confirm Delete?", MB_YESNO | MB_ICONQUESTION))
  311.       SendMessage(hIDO, IDOM_NOTIFYRESULT, 0, IDO_NOTIFY_NODELETERELATION);
  312. }
  313. void IDO_n_DeletedRelation(LPLINE_CLASS_STRUCT lpLine)
  314. {
  315.    wsprintf(szDSLTextBuffer, "Deleted Relation: %s, %s.", lpLine->name, lpLine->classname);
  316.    DisplayDSL(szDSLTextBuffer);
  317. }
  318.  
  319. void IDO_n_AddRelationRequest(HWND hIDO, UINT uAllowed, LPLINE_CLASS_STRUCT lpRel)
  320. {
  321.    wsprintf(szDSLTextBuffer, "Add Relation?: %s,%li <%s> %s,%li.", lpRel->Src_name, lpRel->Src_id,
  322.                                                                  lpRel->classname,
  323.                                                                  lpRel->Dst_name, lpRel->Dst_id);
  324.    DisplayDSL(szDSLTextBuffer);
  325.  
  326.  
  327.    /*
  328.     *   If the relation we wished to add did not exist, we are returned IDO_NOTIFY_NOADDRELATION.
  329.     *   We must override the default behavior to force the item to be added.
  330.     *
  331.     *   If the relation we wished to add does exist, we are returned IDO_NOTIFY_ADDRELATION.
  332.     *   We must override the default behavior to prevent the item from being added.
  333.     */
  334.    if(uAllowed == IDO_NOTIFY_NOADDRELATION)
  335.    {
  336.       /*
  337.        *   If we don't want to add the relation, send IDO_NOTIFY_NOADDRELATION,
  338.        *   else don't do a thing to add the relation.
  339.        */
  340.       if(IDYES==MessageBox(NULL, szDSLTextBuffer, "Class or rule doesn't exist.  Add anyway?", MB_YESNO | MB_ICONQUESTION))
  341.          SendMessage(hIDO, IDOM_NOTIFYRESULT, 0, IDO_NOTIFY_ADDRELATION);
  342.    }
  343.    else
  344.    {
  345.       /*
  346.        *   If we don't want to add the relation, send IDO_NOTIFY_NOADDRELATION,
  347.        *   else don't do a thing to add the relation.
  348.        */
  349.       if(IDNO==MessageBox(NULL, szDSLTextBuffer, "Confirm add?", MB_YESNO | MB_ICONQUESTION))
  350.          SendMessage(hIDO, IDOM_NOTIFYRESULT, 0, IDO_NOTIFY_NOADDRELATION);
  351.    }
  352. }
  353. void IDO_n_AddedRelation(LPLINE_CLASS_STRUCT lpRel)
  354. {
  355.    wsprintf(szDSLTextBuffer, "Relation added: %s,%li <%s> %s,%li.", lpRel->Src_name, lpRel->Src_id,
  356.                                                                  lpRel->classname,
  357.                                                                  lpRel->Dst_name, lpRel->Dst_id);
  358.    DisplayDSL(szDSLTextBuffer);
  359. }
  360.  
  361.  
  362.  
  363. void IDO_n_DeleteEntityRequest(HWND hIDO, UINT uAllowed, LPENTITY_CLASS_STRUCT lpEntity)
  364. {
  365.    wsprintf(szDSLTextBuffer, "Delete Entity?: %s, %s.", lpEntity->name, lpEntity->classname);
  366.    DisplayDSL(szDSLTextBuffer);
  367.  
  368.    /*
  369.     *   If we don't want to delete the entity, send IDO_NOTIFY_NODELETEENTITY,
  370.     *   else don't do a thing to delete the entity.
  371.     */
  372.    if(IDNO==MessageBox(NULL, szDSLTextBuffer, "Confirm Delete?", MB_YESNO | MB_ICONQUESTION))
  373.       SendMessage(hIDO, IDOM_NOTIFYRESULT, 0, IDO_NOTIFY_NODELETEENTITY);
  374. }
  375. void IDO_n_DeletedEntity(LPENTITY_CLASS_STRUCT lpEntity)
  376. {
  377.    wsprintf(szDSLTextBuffer, "Deleted Entity: %s, %s.", lpEntity->name, lpEntity->classname);
  378.    DisplayDSL(szDSLTextBuffer);
  379. }
  380.  
  381.  
  382. void IDO_n_AddEntityRequest(HWND hIDO, UINT uAllowed, LPENTITY_CLASS_STRUCT lpEntity)
  383. {
  384.    wsprintf(szDSLTextBuffer, "Add Entity?: %s, %s.", lpEntity->name, lpEntity->classname);
  385.    DisplayDSL(szDSLTextBuffer);
  386.  
  387.  
  388.    /*
  389.     *   If the class we wished to add did not exist, we are returned IDO_NOTIFY_NOADDENTITY.
  390.     *   We must override the default behavior to force the item to be added.
  391.     *
  392.     *   If the class we wished to add does exist, we are returned IDO_NOTIFY_ADDENTITY.
  393.     *   We must override the default behavior to prevent the item from being added.
  394.     */
  395.    if(uAllowed == IDO_NOTIFY_NOADDENTITY)
  396.    {
  397.       /*
  398.        *   If we don't want to add the entity, send IDO_NOTIFY_NOADDENTITY,
  399.        *   else don't do a thing to add the entity.
  400.        */
  401.       if(IDYES==MessageBox(NULL, szDSLTextBuffer, "Class doesn't exist.  Add anyway?", MB_YESNO | MB_ICONQUESTION))
  402.          SendMessage(hIDO, IDOM_NOTIFYRESULT, 0, IDO_NOTIFY_ADDENTITY);
  403.    }
  404.    else
  405.    {
  406.       /*
  407.        *   If we don't want to add the entity, send IDO_NOTIFY_NOADDENTITY,
  408.        *   else don't do a thing to add the entity.
  409.        */
  410.       if(IDNO==MessageBox(NULL, szDSLTextBuffer, "Confirm add?", MB_YESNO | MB_ICONQUESTION))
  411.          SendMessage(hIDO, IDOM_NOTIFYRESULT, 0, IDO_NOTIFY_NOADDENTITY);
  412.    }
  413. }
  414. void IDO_n_AddedEntity(LPENTITY_CLASS_STRUCT lpEntity)
  415. {
  416.    wsprintf(szDSLTextBuffer, "Added Entity: %s, %s.", lpEntity->name, lpEntity->classname);
  417.    DisplayDSL(szDSLTextBuffer);
  418. }
  419.  
  420.  
  421. void IDO_n_InvalidEditEvent()
  422. {
  423.    wsprintf(szDSLTextBuffer, "Cannot perform action: not in Edit mode.");
  424.    DisplayDSL(szDSLTextBuffer);
  425. }
  426.  
  427.  
  428.  
  429.