home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / componen / interact / demo / data.2 / samples / ansic / INTERACT / ALIGNER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-21  |  6.2 KB  |  259 lines

  1. //lRegen_FileHeading
  2. //lRegen_FileHeading
  3.  
  4.      /********************************************************************
  5.       *
  6.       *   Source File:  aligner.c
  7.       *   Author:
  8.       *   Module:
  9.       *   Program Desc:
  10.       *   Date:         Mon Feb 19 13:11:40 1996
  11.       *   Language:     ANSI C
  12.       *
  13.       ********************************************************************/
  14.  
  15. #include ".\idoiface.h"
  16.  
  17.  
  18. //lRegen_Variables
  19. #include <pvido.h>
  20.  
  21.  
  22. static BOOL bVisible = FALSE;
  23. static HWND hAlignPalette;
  24.  
  25. HWND GetAlignPaletteWnd()
  26. {
  27.    return hAlignPalette;
  28. }
  29.  
  30. void ResizeEntities(BOOL bWidth, BOOL bHeight);
  31. void RepositionEntities(BOOL bLeft, BOOL bTop, BOOL bRight, BOOL bBottom);
  32.  
  33.  
  34. //lRegen_Variables
  35.  
  36. VIEW     hViewaligner;
  37. HWND     hWndaligner;
  38. LRESULT CALLBACK EXPORT fnalignerWndProc(HWND, UINT, WPARAM, LPARAM);
  39.  
  40. int fnaligner(HWND hParentWnd, UINT iData, void FAR *lpData)
  41. {
  42.    //lRegen_BeginFunction
  43.    //lRegen_BeginFunction
  44.  
  45.    //lRegen_InitDlg
  46.    if(bVisible)
  47.    {
  48.       DestroyWindow(hAlignPalette);
  49.       return 0;
  50.    }
  51.    //lRegen_InitDlg
  52.  
  53.    if(NULL == (hViewaligner = vwCreateView(hInstance,
  54.                    MAKEINTRESOURCE(aligner),
  55.                    hParentWnd,
  56.                    (VIEWPROC)fnalignerWndProc,
  57.                    NULL)))
  58.    {
  59.          //lRegen_Create
  60.          //lRegen_Create
  61.         return FALSE;
  62.    }
  63.    //lRegen_InitView
  64.    //lRegen_InitView
  65.    if((hWndaligner = vwShowView(hViewaligner)) == (HWND)-1)
  66.    {
  67.         MessageBox(NULL, "Unable to display view", "System Error",
  68.                    MB_SYSTEMMODAL | MB_ICONHAND | MB_OK);
  69.         return FALSE;
  70.    }
  71.  
  72.    //lRegen_TermView
  73.    //lRegen_TermView
  74.    return(TRUE);
  75. }
  76.  
  77. LRESULT CALLBACK EXPORT fnalignerWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  78. {
  79. GETVIEW;
  80.    WORD CtlId;
  81.    WORD Notify;
  82.    HWND CtlWnd;
  83.  
  84.    //lRegen_WindowProcVariables
  85.    //lRegen_WindowProcVariables
  86.  
  87.    switch(uMessage)
  88.    {
  89.       //lRegen_WndProc
  90.       //lRegen_WndProc
  91.  
  92.       case WM_INITDIALOG :
  93.          //lRegen_InitDialogBegin
  94.          bVisible = TRUE;
  95.          hAlignPalette = hWnd;
  96.          //lRegen_InitDialogBegin
  97.          //Regen_WM_InitDialog
  98.          //Regen_WM_InitDialog
  99.          return TRUE;
  100.  
  101.       case WM_COMMAND :
  102.       #ifdef WIN32
  103.          CtlId  = LOWORD(wParam);
  104.          Notify = HIWORD(wParam);
  105.          CtlWnd = (HWND)lParam;
  106.       #else
  107.          CtlId  = wParam;
  108.          Notify = HIWORD(lParam);
  109.          CtlWnd = (HWND)LOWORD(lParam);
  110.       #endif
  111.          switch(CtlId)
  112.          {
  113.             case ID_HORZ :
  114.                //Regen_ID_HORZ
  115.                ResizeEntities(TRUE, FALSE);
  116.                //Regen_ID_HORZ
  117.                break;
  118.  
  119.             case ID_VERT :
  120.                //Regen_ID_VERT
  121.                ResizeEntities(FALSE, TRUE);
  122.                //Regen_ID_VERT
  123.                break;
  124.  
  125.             case ID_BOTH :
  126.                //Regen_ID_BOTH
  127.                ResizeEntities(TRUE, TRUE);
  128.                //Regen_ID_BOTH
  129.                break;
  130.  
  131.             case IDC_LEFT :
  132.                //Regen_IDC_LEFT
  133.                RepositionEntities(TRUE, FALSE, FALSE, FALSE);
  134.                //Regen_IDC_LEFT
  135.                break;
  136.  
  137.             case IDC_TOP :
  138.                //Regen_IDC_TOP
  139.                RepositionEntities(FALSE, TRUE, FALSE, FALSE);
  140.                //Regen_IDC_TOP
  141.                break;
  142.  
  143.             case IDC_RIGHT :
  144.                //Regen_IDC_RIGHT
  145.                RepositionEntities(FALSE, FALSE, TRUE, FALSE);
  146.                //Regen_IDC_RIGHT
  147.                break;
  148.  
  149.             case IDC_BOTTOM :
  150.                //Regen_IDC_BOTTOM
  151.                RepositionEntities(FALSE, FALSE, FALSE, TRUE);
  152.                //Regen_IDC_BOTTOM
  153.                break;
  154.  
  155.             //lRegen_CustomCommand
  156.             //lRegen_CustomCommand
  157.             }
  158.             break;
  159.  
  160.       case WM_DESTROY :
  161.         //Regen_WM_Destroy
  162.         bVisible = FALSE;
  163.         hAlignPalette = 0;
  164.         //Regen_WM_Destroy
  165.          break;
  166.    }
  167.    return DefViewProc(hWnd, uMessage, wParam, lParam);
  168. }
  169.  
  170. //Regen_CustomCode
  171. void ResizeEntities(BOOL bWidth, BOOL bHeight)
  172. {
  173.    RECT rect;
  174.    int  width, height;
  175.    HWND hido;
  176.    ENTITY entity;
  177.  
  178.  
  179.    if(hido = GetActiveIDO())
  180.    {
  181.       if(idoGetCurrentEntity(hido, &entity))
  182.       {
  183.          idoEntityGetRect(&entity, &rect);
  184.          width  = rect.right - rect.left;
  185.          height = rect.bottom - rect.top;
  186.  
  187.          idoIterateSelectedEntityFirst(hido);
  188.          while(idoIterateSelectedEntityNext(hido, &entity))
  189.          {
  190.             idoEntityGetRect(&entity, &rect);
  191.             if(bWidth)
  192.                rect.right = rect.left + width;
  193.             if(bHeight)
  194.                rect.bottom = rect.top + height;
  195.             idoEntitySetRect(&entity, &rect);
  196.          }
  197.  
  198.          InvalidateRect(hido, NULL, TRUE);
  199.          UpdateWindow(hido);
  200.       }
  201.    }
  202. }
  203.  
  204. void RepositionEntities(BOOL bLeft, BOOL bTop, BOOL bRight, BOOL bBottom)
  205. {
  206.    RECT rect;
  207.    RECT anchor;
  208.    int  width, height;
  209.    HWND hido;
  210.    ENTITY entity;
  211.  
  212.  
  213.  
  214.    if(hido = GetActiveIDO())
  215.    {
  216.       if(idoGetCurrentEntity(hido, &entity))
  217.       {
  218.          idoEntityGetRect(&entity, &rect);
  219.          anchor = rect;
  220.  
  221.          idoIterateSelectedEntityFirst(hido);
  222.          while(idoIterateSelectedEntityNext(hido, &entity))
  223.          {
  224.             idoEntityGetRect(&entity, &rect);
  225.             width  = rect.right - rect.left;
  226.             height = rect.bottom - rect.top;
  227.  
  228.             if(bLeft)
  229.             {
  230.                rect.left  = anchor.left;
  231.                rect.right = rect.left + width;
  232.             }
  233.             if(bTop)
  234.             {
  235.                rect.top    = anchor.top;
  236.                rect.bottom = rect.top + height;
  237.             }
  238.             if(bRight)
  239.             {
  240.                rect.right = anchor.right;
  241.                rect.left  = rect.right - width;
  242.             }
  243.             if(bBottom)
  244.             {
  245.                rect.bottom = anchor.bottom;
  246.                rect.top    = rect.bottom - height;
  247.             }
  248.  
  249.             idoEntitySetRect(&entity, &rect);
  250.          }
  251.  
  252.          InvalidateRect(hido, NULL, TRUE);
  253.          UpdateWindow(hido);
  254.       }
  255.    }
  256. }
  257.  
  258. //Regen_CustomCode
  259.