home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / ole_vbx1 / testvvw.cpp < prev    next >
C/C++ Source or Header  |  1994-02-16  |  9KB  |  321 lines

  1. // testvvw.cpp : implementation of the CTestvbxView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "testvbx.h"
  6.  
  7. #include "testvdoc.h"
  8. #include "testvvw.h" 
  9. #include "mainfrm.h"
  10. #include "outline.h"
  11.  
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CTestvbxView
  19.  
  20. IMPLEMENT_DYNCREATE(CTestvbxView, CFormView)
  21.  
  22. BEGIN_MESSAGE_MAP(CTestvbxView, CFormView)
  23.     //{{AFX_MSG_MAP(CTestvbxView)
  24.     ON_VBXEVENT(VBN_ADDNODE, IDC_OL_VBX1, OnAddnodeOlVbx1)
  25.     ON_VBXEVENT(VBN_CHANGENODE, IDC_OL_VBX1, OnChangenodeOlVbx1)
  26.     ON_VBXEVENT(VBN_INSERTNODE, IDC_OL_VBX1, OnInsertnodeOlVbx1)
  27.     ON_VBXEVENT(VBN_CHANGESELECTION, IDC_OL_VBX1, OnChangeselectionOlVbx1)
  28.     ON_VBXEVENT(VBN_DELETENODE, IDC_OL_VBX1, OnDeletenodeOlVbx1)
  29.     ON_VBXEVENT(VBN_INDENTNODE, IDC_OL_VBX1, OnIndentnodeOlVbx1)
  30.     ON_VBXEVENT(VBN_KILLFOCUS, IDC_OL_VBX1, OnKillfocusOlVbx1)
  31.     ON_VBXEVENT(VBN_LEFTBUTTONCLICK, IDC_OL_VBX1, OnLeftbuttonclickOlVbx1)
  32.     ON_VBXEVENT(VBN_MIDDLEBUTTONCLICK, IDC_OL_VBX1, OnMiddlebuttonclickOlVbx1)
  33.     ON_VBXEVENT(VBN_RIGHTBUTTONCLICK, IDC_OL_VBX1, OnRightbuttonclickOlVbx1)
  34.     ON_VBXEVENT(VBN_SETFOCUS, IDC_OL_VBX1, OnSetfocusOlVbx1)
  35.     ON_VBXEVENT(VBN_VERTICALSCROLL, IDC_OL_VBX1, OnVerticalscrollOlVbx1)
  36.     ON_BN_CLICKED(OKBUTTON, OnOKBUTTON)
  37.     ON_BN_CLICKED(IDC_ADDNODE, OnAddnode)
  38.     ON_BN_CLICKED(IDC_ALLOWAPPEND, OnAllowappend)
  39.     ON_BN_CLICKED(IDC_ALLOWDELETE, OnAllowdelete)
  40.     ON_BN_CLICKED(IDC_ALLOWEDIT, OnAllowedit)
  41.     ON_BN_CLICKED(IDC_ALLOWINSERT, OnAllowinsert)
  42.     ON_BN_CLICKED(IDC_ALLOWREDRAW, OnAllowredraw)
  43.     ON_EN_KILLFOCUS(IDC_CURRENTNODE, OnKillfocusCurrentnode)
  44.     ON_BN_CLICKED(IDC_DELNODE, OnDelnode)
  45.     ON_BN_CLICKED(IDC_FLUSH, OnFlush)
  46.     ON_EN_KILLFOCUS(IDC_INDENTLEVEL, OnKillfocusIndentlevel)
  47.     ON_EN_KILLFOCUS(IDC_MAXINDENT, OnKillfocusMaxindent)
  48.     ON_BN_CLICKED(IDC_NUMBERING, OnNumbering)
  49.     ON_WM_GETDLGCODE()
  50.     //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CTestvbxView construction/destruction
  55.  
  56. CTestvbxView::CTestvbxView()
  57.     : CFormView(CTestvbxView::IDD)
  58. {
  59.     //{{AFX_DATA_INIT(CTestvbxView)
  60.     pOutline1 = NULL;
  61.     nNumNodes = 0;
  62.     nMaxIndent = 7;
  63.     nIndentLevel = 0;
  64.     nCurrentNode = 0;
  65.     bAllowAppend = TRUE;
  66.     bAllowDelete = TRUE;
  67.     bAllowEdit = TRUE;
  68.     bAllowInsert = TRUE;
  69.     bAllowRedraw = TRUE;
  70.     bNumbering = TRUE;
  71.     //}}AFX_DATA_INIT
  72. }
  73.  
  74. CTestvbxView::~CTestvbxView()
  75. {
  76. }
  77.  
  78. void CTestvbxView::DoDataExchange(CDataExchange* pDX)
  79. {
  80.     CFormView::DoDataExchange(pDX);
  81.     //{{AFX_DATA_MAP(CTestvbxView)
  82.     DDX_VBControl(pDX, IDC_OL_VBX1, pOutline1);
  83.     DDX_Text(pDX, IDC_NUMNODES, nNumNodes);
  84.     DDX_Text(pDX, IDC_MAXINDENT, nMaxIndent);
  85.     DDX_Text(pDX, IDC_INDENTLEVEL, nIndentLevel);
  86.     DDX_Text(pDX, IDC_CURRENTNODE, nCurrentNode);
  87.     DDX_Check(pDX, IDC_ALLOWAPPEND, bAllowAppend);
  88.     DDX_Check(pDX, IDC_ALLOWDELETE, bAllowDelete);
  89.     DDX_Check(pDX, IDC_ALLOWEDIT, bAllowEdit);
  90.     DDX_Check(pDX, IDC_ALLOWINSERT, bAllowInsert);
  91.     DDX_Check(pDX, IDC_ALLOWREDRAW, bAllowRedraw);
  92.     DDX_Check(pDX, IDC_NUMBERING, bNumbering);
  93.     //}}AFX_DATA_MAP
  94. }
  95.  
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CTestvbxView diagnostics
  98.  
  99. #ifdef _DEBUG
  100. void CTestvbxView::AssertValid() const
  101. {
  102.     CFormView::AssertValid();
  103. }
  104.  
  105. void CTestvbxView::Dump(CDumpContext& dc) const
  106. {
  107.     CFormView::Dump(dc);
  108. }
  109.  
  110. CTestvbxDoc* CTestvbxView::GetDocument() // non-debug version is inline
  111. {
  112.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestvbxDoc)));
  113.     return (CTestvbxDoc*)m_pDocument;
  114. }
  115. #endif //_DEBUG
  116.  
  117. /////////////////////////////////////////////////////////////////////////////
  118. // CTestvbxView message handlers 
  119.  
  120. BOOL CTestvbxView::UpdateData(BOOL bSaveAndValidate)
  121. {
  122.     if (bSaveAndValidate == TRUE)
  123.     {                   
  124.         // Update the member variable from the screen
  125.         CFormView::UpdateData(bSaveAndValidate);
  126.         
  127.         // Update the outline values from the member variables           
  128.         pOutline1->SetNumProperty("AllowAppend", bAllowAppend);
  129.         pOutline1->SetNumProperty("AllowDelete", bAllowDelete);
  130.         pOutline1->SetNumProperty("AllowEdit", bAllowEdit);
  131.         pOutline1->SetNumProperty("AllowInsert", bAllowInsert);
  132.         pOutline1->SetNumProperty("Redraw", bAllowRedraw);
  133.         
  134.         pOutline1->SetNumProperty("MaximumIndent", nMaxIndent);
  135.         pOutline1->SetNumProperty("Numbering", bNumbering);
  136.         
  137.         // Only set the current node if it has changed. This will stop alot
  138.         // of redrawing and flicker        
  139.         if (nCurrentNode != (UINT) pOutline1->GetNumProperty("Position"))
  140.             pOutline1->SetNumProperty("Position", nCurrentNode);
  141.     }
  142.     else
  143.     {                                                         
  144.         // Update the member variables from the outline control
  145.         bAllowAppend = (BOOL) pOutline1->GetNumProperty("AllowAppend");    
  146.         bAllowDelete = (BOOL) pOutline1->GetNumProperty("AllowDelete");    
  147.         bAllowEdit = (BOOL) pOutline1->GetNumProperty("AllowEdit");    
  148.         bAllowInsert = (BOOL) pOutline1->GetNumProperty("AllowInsert");
  149.         bAllowRedraw = (BOOL) pOutline1->GetNumProperty("Redraw");
  150.         
  151.         nNumNodes = (UINT) pOutline1->GetNumProperty("Count");   
  152. //        nIndentLevel = (UINT) pOutline1->GetNumProperty("Indent");
  153.         nMaxIndent = (UINT) pOutline1->GetNumProperty("MaximumIndent");
  154.         bNumbering = (UINT) pOutline1->GetNumProperty("Numbering");
  155.         nCurrentNode = (UINT) pOutline1->GetNumProperty("Position");
  156.         
  157.         // Update the screen from the member variables
  158.         CFormView::UpdateData(bSaveAndValidate);
  159.     }
  160.     return TRUE;
  161. }
  162.  
  163. void CTestvbxView::OnAddnodeOlVbx1(UINT, int, CWnd*, LPVOID)
  164. {
  165.     // Update the screen
  166.     UpdateData(FALSE);
  167.  
  168.     pFrame->setStatusText("VBX1 - AddNode");
  169. }
  170.  
  171. void CTestvbxView::OnChangenodeOlVbx1(UINT, int, CWnd*, LPVOID)
  172. {
  173.     pFrame->setStatusText("VBX1 - ChangeNode");
  174. }
  175.  
  176. void CTestvbxView::OnInsertnodeOlVbx1(UINT, int, CWnd*, LPVOID)
  177. {
  178.     // Update the screen
  179.     UpdateData(FALSE);
  180.  
  181.     pFrame->setStatusText("VBX1 - InsertNode");
  182. }
  183.  
  184. void CTestvbxView::OnChangeselectionOlVbx1(UINT, int, CWnd*, LPVOID)
  185. {
  186.     // Update the screen
  187.     UpdateData(FALSE);
  188.  
  189.     pFrame->setStatusText("VBX1 - Change node selection");
  190. }
  191.  
  192. void CTestvbxView::OnDeletenodeOlVbx1(UINT, int, CWnd*, LPVOID)
  193. {
  194.     // Update the screen
  195.     UpdateData(FALSE);
  196.  
  197.     pFrame->setStatusText("VBX1 - Delete node");
  198. }
  199.  
  200. void CTestvbxView::OnIndentnodeOlVbx1(UINT, int, CWnd*, LPVOID)
  201. {
  202.     // Update the screen
  203.     UpdateData(FALSE);
  204.  
  205.     pFrame->setStatusText("VBX1 - Indent node");
  206. }
  207.  
  208. void CTestvbxView::OnKillfocusOlVbx1(UINT, int, CWnd*, LPVOID)
  209. {
  210.     pFrame->setStatusText("VBX1 - Kill focus");
  211. }
  212.  
  213. void CTestvbxView::OnLeftbuttonclickOlVbx1(UINT, int, CWnd*, LPVOID)
  214. {
  215.     pFrame->setStatusText("VBX1 - Left button click");
  216. }
  217.  
  218. void CTestvbxView::OnMiddlebuttonclickOlVbx1(UINT, int, CWnd*, LPVOID)
  219. {
  220.     pFrame->setStatusText("VBX1 - Middle button click");
  221. }
  222.  
  223. void CTestvbxView::OnRightbuttonclickOlVbx1(UINT, int, CWnd*, LPVOID)
  224. {
  225.     pFrame->setStatusText("VBX1 - Right button click");
  226. }
  227.  
  228. void CTestvbxView::OnSetfocusOlVbx1(UINT, int, CWnd*, LPVOID)
  229. {
  230.     pFrame->setStatusText("VBX1 - Set focus");
  231. }
  232.  
  233. void CTestvbxView::OnVerticalscrollOlVbx1(UINT, int, CWnd*, LPVOID)
  234. {
  235.     pFrame->setStatusText("VBX1 - Vertical scroll");
  236. }
  237.  
  238. void CTestvbxView::OnOKBUTTON()
  239. {
  240.     PostMessage(WM_COMMAND, ID_FILE_CLOSE);
  241. }
  242.  
  243.  
  244. void CTestvbxView::OnAddnode()
  245. {                                             
  246.     // Update the data in the member variables first
  247.     UpdateData(TRUE);
  248.     
  249.     // The outline AddItem function is different than the standard AddItem.
  250.     // The second argument takes the indent level, not the index to place
  251.     // the item at.
  252.     pOutline1->AddItem("This is a test node", nIndentLevel);
  253. }
  254.  
  255. void CTestvbxView::OnAllowappend()
  256. {
  257.     UpdateData(TRUE);
  258. }
  259.  
  260. void CTestvbxView::OnAllowdelete()
  261. {
  262.     UpdateData(TRUE);
  263. }
  264.  
  265. void CTestvbxView::OnAllowedit()
  266. {
  267.     UpdateData(TRUE);
  268. }
  269.  
  270. void CTestvbxView::OnAllowinsert()
  271. {
  272.     UpdateData(TRUE);
  273. }
  274.  
  275. void CTestvbxView::OnAllowredraw()
  276. {
  277.     UpdateData(TRUE);
  278. }
  279.  
  280. void CTestvbxView::OnKillfocusCurrentnode()
  281. {
  282.     UpdateData(TRUE);
  283. }
  284.  
  285. void CTestvbxView::OnDelnode()
  286. {
  287.     // Update the data in the member variables first
  288.     UpdateData(TRUE);
  289.     
  290.     pOutline1->RemoveItem(nCurrentNode);
  291. }
  292.  
  293. void CTestvbxView::OnFlush()
  294. {
  295.     pOutline1->SendMessage(OL_FLUSH, 0, 0L);
  296.     UpdateData(TRUE);
  297.  
  298. }
  299.  
  300. void CTestvbxView::OnKillfocusIndentlevel()
  301. {
  302.     UpdateData(TRUE);
  303.     
  304.     pOutline1->SetNumProperty("Indent", nIndentLevel);
  305. }
  306.  
  307. void CTestvbxView::OnKillfocusMaxindent()
  308. {
  309.     UpdateData(TRUE);
  310. }
  311.  
  312. void CTestvbxView::OnNumbering()
  313. {
  314.     UpdateData(TRUE);
  315. }
  316.  
  317. UINT CTestvbxView::OnGetDlgCode()
  318. {
  319.     return DLGC_WANTALLKEYS | DLGC_WANTARROWS | DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTTAB;
  320. }
  321.