home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / componen / interact / demo / data.2 / samples / vc / EXPAND / EXPAND~1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-22  |  6.5 KB  |  270 lines

  1. // expandDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "expand.h"
  6. #include "expandDlg.h"
  7. #include "ido.h"
  8. #include "entity.h"
  9. #include "relation.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CAboutDlg dialog used for App About
  20.  
  21. class CAboutDlg : public CDialog
  22. {
  23. public:
  24.     CAboutDlg();
  25.  
  26. // Dialog Data
  27.     //{{AFX_DATA(CAboutDlg)
  28.     enum { IDD = IDD_ABOUTBOX };
  29.     //}}AFX_DATA
  30.  
  31.     // ClassWizard generated virtual function overrides
  32.     //{{AFX_VIRTUAL(CAboutDlg)
  33.     protected:
  34.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  35.     //}}AFX_VIRTUAL
  36.  
  37.  
  38. // Implementation
  39. protected:
  40.     //{{AFX_MSG(CAboutDlg)
  41.     //}}AFX_MSG
  42.     DECLARE_MESSAGE_MAP()
  43. };
  44.  
  45. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  46. {
  47.     //{{AFX_DATA_INIT(CAboutDlg)
  48.     //}}AFX_DATA_INIT
  49. }
  50.  
  51. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  52. {
  53.     CDialog::DoDataExchange(pDX);
  54.     //{{AFX_DATA_MAP(CAboutDlg)
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  59.     //{{AFX_MSG_MAP(CAboutDlg)
  60.         // No message handlers
  61.     //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CExpandDlg dialog
  66.  
  67. CExpandDlg::CExpandDlg(CWnd* pParent /*=NULL*/)
  68.     : CDialog(CExpandDlg::IDD, pParent)
  69. {
  70.     //{{AFX_DATA_INIT(CExpandDlg)
  71.         // NOTE: the ClassWizard will add member initialization here
  72.     //}}AFX_DATA_INIT
  73.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  74.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  75. }
  76.  
  77. void CExpandDlg::DoDataExchange(CDataExchange* pDX)
  78. {
  79.     CDialog::DoDataExchange(pDX);
  80.     //{{AFX_DATA_MAP(CExpandDlg)
  81.     DDX_Control(pDX, IDC_INTERACTCTRL1, m_IDO);
  82.     //}}AFX_DATA_MAP
  83. }
  84.  
  85. BEGIN_MESSAGE_MAP(CExpandDlg, CDialog)
  86.     //{{AFX_MSG_MAP(CExpandDlg)
  87.     ON_WM_SYSCOMMAND()
  88.     ON_WM_PAINT()
  89.     ON_WM_QUERYDRAGICON()
  90.     //}}AFX_MSG_MAP
  91.  
  92.    ON_MESSAGE(UM_TOP, CreateTopDiagram)
  93.    ON_MESSAGE(UM_OPEN, CreateOpenDiagram)
  94.  
  95. END_MESSAGE_MAP()
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CExpandDlg message handlers
  99.  
  100. BOOL CExpandDlg::OnInitDialog()
  101. {
  102.     CDialog::OnInitDialog();
  103.  
  104.     // Add "About..." menu item to system menu.
  105.  
  106.     // IDM_ABOUTBOX must be in the system command range.
  107.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  108.     ASSERT(IDM_ABOUTBOX < 0xF000);
  109.  
  110.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  111.     CString strAboutMenu;
  112.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  113.     if (!strAboutMenu.IsEmpty())
  114.     {
  115.         pSysMenu->AppendMenu(MF_SEPARATOR);
  116.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  117.     }
  118.  
  119.     // Set the icon for this dialog.  The framework does this automatically
  120.     //  when the application's main window is not a dialog
  121.     SetIcon(m_hIcon, TRUE);            // Set big icon
  122.     SetIcon(m_hIcon, FALSE);        // Set small icon
  123.     
  124.     // TODO: Add extra initialization here
  125.    m_IDO.SetGridHeight(50);
  126.    m_IDO.SetSnapToGrid(FALSE);
  127.    CreateTopDiagram(0, 0L);
  128.  
  129.  
  130.     return TRUE;  // return TRUE  unless you set the focus to a control
  131. }
  132.  
  133. void CExpandDlg::OnSysCommand(UINT nID, LPARAM lParam)
  134. {
  135.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  136.     {
  137.         CAboutDlg dlgAbout;
  138.         dlgAbout.DoModal();
  139.     }
  140.     else
  141.     {
  142.         CDialog::OnSysCommand(nID, lParam);
  143.     }
  144. }
  145.  
  146. // If you add a minimize button to your dialog, you will need the code below
  147. //  to draw the icon.  For MFC applications using the document/view model,
  148. //  this is automatically done for you by the framework.
  149.  
  150. void CExpandDlg::OnPaint() 
  151. {
  152.     if (IsIconic())
  153.     {
  154.         CPaintDC dc(this); // device context for painting
  155.  
  156.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  157.  
  158.         // Center icon in client rectangle
  159.         int cxIcon = GetSystemMetrics(SM_CXICON);
  160.         int cyIcon = GetSystemMetrics(SM_CYICON);
  161.         CRect rect;
  162.         GetClientRect(&rect);
  163.         int x = (rect.Width() - cxIcon + 1) / 2;
  164.         int y = (rect.Height() - cyIcon + 1) / 2;
  165.  
  166.         // Draw the icon
  167.         dc.DrawIcon(x, y, m_hIcon);
  168.     }
  169.     else
  170.     {
  171.         CDialog::OnPaint();
  172.     }
  173. }
  174.  
  175. // The system calls this to obtain the cursor to display while the user drags
  176. //  the minimized window.
  177. HCURSOR CExpandDlg::OnQueryDragIcon()
  178. {
  179.     return (HCURSOR) m_hIcon;
  180. }
  181.  
  182. LRESULT CExpandDlg::CreateTopDiagram(WPARAM wParam, LPARAM lParam)
  183. {
  184.    m_IDO.SetRedraw(FALSE);
  185.  
  186.    m_IDO.ResetDiagram();
  187.    m_IDO.AddEntityFromClass(1, "", "Picture", "", 50, 50, 100, 100);
  188.    m_IDO.AddEntityFromClass(3, "", "Text Class", "Click On the \'X\' To Expand", 200, 50, 100, 100);
  189.    
  190.    CEntity Entity;
  191.    Entity = m_IDO.GetEntity(1, "");
  192.    Entity.SetGraphic("A_Out.BMP");
  193.    Entity.SetReadOnly(TRUE);
  194.  
  195.    Entity = m_IDO.GetEntity(1, "");
  196.    Entity.SetReadOnly(TRUE);
  197.    Entity.SetSelect(FALSE);
  198.  
  199.    m_IDO.SetRedraw(TRUE);
  200.  
  201.    return TRUE;
  202. }
  203.  
  204. LRESULT CExpandDlg::CreateOpenDiagram(WPARAM wParam, LPARAM lParam)
  205. {
  206.    m_IDO.SetRedraw(FALSE);
  207.  
  208.    m_IDO.ResetDiagram();
  209.    m_IDO.AddEntityFromClass(2, "", "Picture", "", 50, 50, 100, 100);
  210.    
  211.    CEntity Entity;
  212.    Entity = m_IDO.GetEntity(2, "");
  213.    Entity.SetGraphic("A_In.BMP");
  214.    Entity.SetReadOnly(TRUE);
  215.  
  216.    m_IDO.AddEntityFromClass(5, "", "Text Class", "", 150, 0,  100, 30);
  217.    Entity = m_IDO.GetEntity(5, "");
  218.    Entity.SetText("Convey");
  219.    Entity.SetReadOnly(TRUE);
  220.  
  221.    m_IDO.AddEntityFromClass(6, "", "Text Class", "", 150, 50, 100, 30);
  222.    Entity = m_IDO.GetEntity(6, "");
  223.    Entity.SetText("Ideas");
  224.    Entity.SetReadOnly(TRUE);
  225.  
  226.    m_IDO.AddEntityFromClass(7, "", "Text Class", "", 150, 100, 100, 30);
  227.    Entity = m_IDO.GetEntity(7, "");
  228.    Entity.SetText("Visually");
  229.    Entity.SetReadOnly(TRUE);
  230.    Entity.SetSelect(FALSE);
  231.  
  232.    CRelation Relation;
  233.    m_IDO.AddRelationFromClass(11, "", "Generic Relation", "", 5, "", 6, "");
  234. //   Relation = m_IDO.GetRelation(11, "");
  235. //   Relation.Repaint();
  236.  
  237.    m_IDO.AddRelationFromClass(13, "", "Generic Relation", "", 6, "", 7, "");
  238. //   Relation = m_IDO.GetRelation(13, "");
  239. //   Relation.Repaint();
  240.  
  241.    m_IDO.SetRedraw(TRUE);
  242.  
  243.    return TRUE;
  244. }
  245.  
  246. BEGIN_EVENTSINK_MAP(CExpandDlg, CDialog)
  247.     //{{AFX_EVENTSINK_MAP(CExpandDlg)
  248.     ON_EVENT(CExpandDlg, IDC_INTERACTCTRL1, 21 /* ClickEntity */, OnClickEntityInteractctrl1, VTS_I4)
  249.     //}}AFX_EVENTSINK_MAP
  250. END_EVENTSINK_MAP()
  251.  
  252. void CExpandDlg::OnClickEntityInteractctrl1(long MouseStatus) 
  253. {
  254.    CEntity Entity;
  255.    
  256.    Entity = m_IDO.GetNotifyEntity();    
  257.    if(Entity.UserID() == 1)
  258.    {
  259.       PostMessage(UM_OPEN, 0, 0L);
  260.    }
  261.    else
  262.    {
  263.       if(Entity.UserID() == 2)
  264.       {
  265.          PostMessage(UM_TOP, 0, 0L);
  266.       }
  267.    }
  268.  
  269. }
  270.