Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa_test / FormFiller_Test / BookMarkView.cpp
1 // BookMarkView.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "ReaderVC.h"\r
6 #include "ChildFrm.h"\r
7 #include "BookMarkView.h"\r
8 #include "ReaderVCDoc.h"\r
9 #include "ReaderVCView.h"\r
10 \r
11 #ifdef _DEBUG\r
12 #define new DEBUG_NEW\r
13 #undef THIS_FILE\r
14 static char THIS_FILE[] = __FILE__;\r
15 #endif\r
16 \r
17 /////////////////////////////////////////////////////////////////////////////\r
18 // CBookMarkView\r
19 \r
20 IMPLEMENT_DYNCREATE(CBookMarkView, CTreeView)\r
21 \r
22 CBookMarkView::CBookMarkView()\r
23 {\r
24         m_pFram = NULL;\r
25         m_pDoc = NULL;\r
26 }\r
27 \r
28 CBookMarkView::~CBookMarkView()\r
29 {\r
30 }\r
31 \r
32 \r
33 BEGIN_MESSAGE_MAP(CBookMarkView, CTreeView)\r
34         //{{AFX_MSG_MAP(CBookMarkView)\r
35         ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)\r
36         //}}AFX_MSG_MAP\r
37 END_MESSAGE_MAP()\r
38 \r
39 /////////////////////////////////////////////////////////////////////////////\r
40 // CBookMarkView drawing\r
41 \r
42 void CBookMarkView::OnDraw(CDC* pDC)\r
43 {\r
44         CReaderVCDoc* pDoc = GetDocument();\r
45         // TODO: add draw code here\r
46 }\r
47 \r
48 /////////////////////////////////////////////////////////////////////////////\r
49 // CBookMarkView diagnostics\r
50 \r
51 #ifdef _DEBUG\r
52 void CBookMarkView::AssertValid() const\r
53 {\r
54         CTreeView::AssertValid();\r
55 }\r
56 \r
57 void CBookMarkView::Dump(CDumpContext& dc) const\r
58 {\r
59         CTreeView::Dump(dc);\r
60 }\r
61 \r
62 CReaderVCDoc* CBookMarkView::GetDocument() // non-debug version is inline\r
63 {\r
64         ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CReaderVCDoc)));\r
65         return (CReaderVCDoc*)m_pDocument;\r
66 }\r
67 #endif //_DEBUG\r
68 \r
69 /////////////////////////////////////////////////////////////////////////////\r
70 // CBookMarkView message handlers\r
71 \r
72 void CBookMarkView::OnInitialUpdate() \r
73 {\r
74         CTreeView::OnInitialUpdate();\r
75         CReaderVCDoc* pDoc = GetDocument();\r
76         if (! m_pFram || !m_pFram->m_pView)\r
77         return;\r
78         m_pDoc = m_pFram->m_pView->GetPDFDoc();\r
79         if(m_pDoc == NULL) return;\r
80         int num = m_pFram->m_pView->GetTotalPages();\r
81     CString strName = pDoc->GetTitle();\r
82         FPDF_BOOKMARK bookmark1 = NULL;\r
83 \r
84         //////////////////////////////////////////////////////////////////////////\r
85         //insert items\r
86         \r
87 //      CTreeCtrl &treeCtrl = this->GetTreeCtrl();\r
88 //      m_hItemRoot = treeCtrl.InsertItem(strName,0,0,TVI_ROOT,TVI_FIRST);\r
89 //      treeCtrl.SetItemData(m_hItemRoot,0);\r
90 //      bookmark1 = FPDFBookmark_GetFirstChild(m_pDoc, NULL);\r
91 //      if (bookmark1 == NULL)//insert the page index to tree  \r
92 //      {\r
93 //              for (int i=0; i<num; i++)\r
94 //              {\r
95 //                      CString str;\r
96 //                      str.Format(_T("Page%d"), i+1);\r
97 //                      HTREEITEM hItem = treeCtrl.InsertItem(str);\r
98 //                      treeCtrl.SetItemData(hItem, i);\r
99 //              }\r
100 //      }else{\r
101 //              while(bookmark1 != NULL) {\r
102 //                      this->InsertChildItem(bookmark1, m_hItemRoot, treeCtrl);\r
103 //                      bookmark1 = FPDFBookmark_GetNextSibling(m_pDoc,bookmark1);\r
104 //              } \r
105 //      }\r
106 //      treeCtrl.Expand(m_hItemRoot,TVE_EXPAND);\r
107 //      \r
108 //      LONG nStyle = ::GetWindowLong(this->m_hWnd, GWL_STYLE);\r
109 //      nStyle |= TVS_LINESATROOT;\r
110 //      nStyle |= TVS_HASLINES;\r
111 //      nStyle |= TVS_HASBUTTONS;\r
112 //      ::SetWindowLong(this->m_hWnd, GWL_STYLE, nStyle);\r
113         \r
114 }\r
115 \r
116 void CBookMarkView::InsertChildItem(FPDF_BOOKMARK bookmark, HTREEITEM hItem, CTreeCtrl &treectrl)\r
117 {\r
118 \r
119 //      CString strTitle;\r
120 //      DWORD dwItemData = 0;\r
121 //      WCHAR buffer[1024];\r
122 //      CString str;\r
123 //      int strlenth = 0;\r
124 //      unsigned long pdf_actType = 0;\r
125 //      //FPDF_BOOKMARK \r
126 //      FPDF_DEST dest = NULL;\r
127 //      FPDF_ACTION action = NULL;\r
128 //      \r
129 //      memset(buffer,0,1024*sizeof(WCHAR));\r
130 //      strlenth = FPDFBookmark_GetTitle(bookmark, buffer, 0);\r
131 //      int nlen = WideCharToMultiByte(CP_ACP,0,buffer,-1,NULL,NULL,NULL,NULL);\r
132 //      char *buffer1 = new char[nlen];\r
133 //      memset(buffer1,0,nlen);\r
134 //      WideCharToMultiByte(CP_ACP,0,buffer,strlenth,buffer1,nlen,NULL,NULL);\r
135 //      buffer1[nlen -1] = '\0';\r
136 // /*   int strl = strlen(buffer1);\r
137 //      strTitle = buffer;//\r
138 //      strTitle = strTitle.Left(strl-1);*/\r
139 //      hItem = treectrl.InsertItem(buffer1, 0, 0, hItem, TVI_LAST);\r
140 //      action = FPDFBookmark_GetAction(bookmark);\r
141 //      if (action != NULL)\r
142 //      {\r
143 //              pdf_actType = FPDFAction_GetType(action);\r
144 //              if (pdf_actType == 1)\r
145 //              {\r
146 //                      dest = FPDFAction_GetDest(m_pDoc, action);\r
147 //                      dwItemData = FPDFDest_GetPageIndex(m_pDoc, dest);\r
148 //                      int nZoomMode = FPDFDest_GetZoomMode(dest);\r
149 //                      if(nZoomMode == 1)\r
150 //                      {\r
151 //                              double nStartX = FPDFDest_GetZoomParam(dest, 0);\r
152 //                              double nStartY = FPDFDest_GetZoomParam(dest, 1);\r
153 //                              CPoint pos((int)nStartX, (int)nStartY);\r
154 //                              m_PosMap.SetAt(hItem, pos);\r
155 //                      }\r
156 //                      treectrl.SetItemData(hItem, dwItemData);\r
157 //                      \r
158 //              }else{\r
159 //                      dwItemData = 0;\r
160 //                      treectrl.SetItemData(hItem, dwItemData);\r
161 //              }\r
162 //              \r
163 //      }else{\r
164 //              dest = FPDFBookmark_GetDest(m_pDoc, bookmark);\r
165 //              dwItemData = FPDFDest_GetPageIndex(m_pDoc, dest);\r
166 //              treectrl.SetItemData(hItem, dwItemData);\r
167 //      }\r
168 //      \r
169 //      bookmark = FPDFBookmark_GetFirstChild(m_pDoc, bookmark);\r
170 //      while(bookmark != NULL)\r
171 //      {\r
172 //              this->InsertChildItem(bookmark, hItem, treectrl);\r
173 //              bookmark = FPDFBookmark_GetNextSibling(m_pDoc, bookmark);\r
174 //      } \r
175 //      delete buffer1;\r
176 }\r
177 \r
178 void CBookMarkView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) \r
179 {\r
180         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;\r
181         // TODO: Add your control notification handler code here\r
182         HTREEITEM hItem;\r
183         DWORD dwPageIdex= 0;\r
184         if(m_pDoc == NULL) return;\r
185         hItem = GetTreeCtrl().GetSelectedItem();\r
186         dwPageIdex = GetTreeCtrl().GetItemData(hItem);\r
187         CPoint p;\r
188         if(0 == m_PosMap.Lookup(hItem, p))\r
189         {\r
190                 p.x = 0; \r
191                 p.y = 0;\r
192         }\r
193         m_pFram->m_pView->LoadPDFPage(m_pDoc, dwPageIdex, p);\r
194         m_pFram->m_pView->Invalidate();\r
195         *pResult = 0;\r
196 }\r
197 \r