Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa_test / FormFiller_Test / ReaderVCView.cpp
1 // ReaderVCView.cpp : implementation of the CReaderVCView class\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "ReaderVC.h"\r
6 #include "MainFrm.h"\r
7 #include "ChildFrm.h"\r
8 #include "ReaderVCDoc.h"\r
9 #include "ReaderVCView.h"\r
10 \r
11 #include "GotoPageDlg.h"\r
12 #include "ZoomDlg.h"\r
13 #include "FindDlg.h"\r
14 #include "ConvertDlg.h"\r
15 #include "JS_ResponseDlg.h"\r
16 #include "TestJsDlg.h"\r
17 //#include "../../include/pp_event.h"\r
18 \r
19 #ifdef _DEBUG\r
20 #define new DEBUG_NEW\r
21 #undef THIS_FILE\r
22 static char THIS_FILE[] = __FILE__;\r
23 #endif\r
24 \r
25 /////////////////////////////////////////////////////////////////////////////\r
26 // CReaderVCView\r
27 \r
28 IMPLEMENT_DYNCREATE(CReaderVCView, CView)\r
29 \r
30 BEGIN_MESSAGE_MAP(CReaderVCView, CView)\r
31         //{{AFX_MSG_MAP(CReaderVCView)\r
32         ON_COMMAND(ID_DOC_FIRSTPAGE, OnDocFirstpage)\r
33         ON_COMMAND(ID_DOC_GOTOPAGE, OnDocGotopage)\r
34         ON_COMMAND(ID_DOC_LASTPAGE, OnDocLastpage)\r
35         ON_COMMAND(ID_DOC_NEXTPAGE, OnDocNextpage)\r
36         ON_COMMAND(ID_DOC_PREPAGE, OnDocPrepage)\r
37         ON_COMMAND(ID_VIEW_CLOCKWISE, OnClockwise)\r
38         ON_COMMAND(ID_VIEW_COUNTERCLOCKWISE, OnCounterclockwise)\r
39         ON_COMMAND(ID_VIEW_ACTUALSIZE, OnViewActualSize)\r
40         ON_COMMAND(ID_VIEW_FITPAGE, OnViewFitPage)\r
41         ON_COMMAND(ID_VIEW_FITWIDTH, OnViewFitWidth)\r
42         ON_COMMAND(ID_VIEW_ZOOMIN, OnViewZoomIn)\r
43         ON_COMMAND(ID_VIEW_ZOOMOUT, OnViewZoomOut)\r
44         ON_COMMAND(ID_VIEW_ZOOMTO, OnViewZoomTo)\r
45         ON_COMMAND(ID_EDIT_FIND, OnEditFind)\r
46         ON_COMMAND(ID_FILE_PRINT, OnFilePrint)\r
47         ON_WM_LBUTTONDOWN()\r
48         ON_WM_LBUTTONUP()\r
49         ON_WM_MOUSEMOVE()\r
50         ON_WM_KEYDOWN()\r
51         ON_COMMAND(ID_TOOL_SNAPSHOT, OnToolSnapshot)\r
52         ON_COMMAND(ID_TOOL_SELECT, OnToolSelect)\r
53         ON_COMMAND(ID_TOOL_HAND, OnToolHand)\r
54         ON_COMMAND(ID_TOOL_PDF2TXT, OnToolPdf2txt)\r
55         ON_WM_SIZE()\r
56         ON_WM_HSCROLL()\r
57         ON_WM_VSCROLL()\r
58         ON_COMMAND(ID_TOOL_EXTRACTLINKS, OnToolExtractlinks)\r
59         ON_WM_DESTROY()\r
60         ON_UPDATE_COMMAND_UI(ID_DOC_FIRSTPAGE, OnUpdateDocFirstpage)\r
61         ON_UPDATE_COMMAND_UI(ID_DOC_LASTPAGE, OnUpdateDocLastpage)\r
62         ON_UPDATE_COMMAND_UI(ID_DOC_NEXTPAGE, OnUpdateDocNextpage)\r
63         ON_UPDATE_COMMAND_UI(ID_DOC_PREPAGE, OnUpdateDocPrepage)\r
64         ON_UPDATE_COMMAND_UI(ID_TOOL_HAND, OnUpdateToolHand)\r
65         ON_UPDATE_COMMAND_UI(ID_TOOL_SNAPSHOT, OnUpdateToolSnapshot)\r
66         ON_UPDATE_COMMAND_UI(ID_TOOL_SELECT, OnUpdateToolSelect)\r
67         ON_COMMAND(ID_VIEW_BOOKMARK, OnViewBookmark)\r
68         ON_WM_MOUSEWHEEL()\r
69         ON_WM_CONTEXTMENU()\r
70         ON_COMMAND(ID_EDIT_COPY, OnEditCopy)\r
71         ON_COMMAND(ID_RENDERBITMAP, OnRenderbitmap)\r
72         ON_COMMAND(ID_EXPORT_PDF_TO_BITMAP, OnExportPdfToBitmap)\r
73         ON_WM_CHAR()\r
74         ON_WM_KEYUP()\r
75         ON_COMMAND(ID_FILE_SAVE, OnFileSave)\r
76         ON_COMMAND(IDM_Test_JS, OnTestJS)\r
77         ON_COMMAND(TEST_PRINT_METALFILE, OnPrintMetalfile)\r
78         //}}AFX_MSG_MAP\r
79         // Standard printing commands\r
80         ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)\r
81         ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)\r
82         ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)\r
83 END_MESSAGE_MAP()\r
84 \r
85 /////////////////////////////////////////////////////////////////////////////\r
86 // CReaderVCView construction/destruction\r
87 void Sample_PageToDevice(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page,double page_x,double page_y, int* device_x, int* device_y)\r
88 {\r
89         CReaderVCView* pView =(CReaderVCView*)pThis;\r
90         if ( pView )\r
91         {\r
92                 pView->PageToDeviceImpl(page, page_x, page_y, device_x, device_y);\r
93         }\r
94         //((CReaderVCView*)pThis)->PageToDeviceImpl(page, page_x, page_y, device_x, device_y);\r
95 }\r
96 \r
97 void Sample_Invalidate(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page, double left, double top, double right, double bottom)\r
98 {\r
99         CReaderVCView* pView =(CReaderVCView*)pThis;\r
100         if ( pView )\r
101         {\r
102                 pView->InvalidateImpl(page,left, top, right, bottom);\r
103         }\r
104         //((CReaderVCView*)pThis)->InvalidateImpl(page,left, top, right, bottom);\r
105 }\r
106 \r
107 void Sample_OutputSelectedRect(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page, double left, double top, double right, double bottom)\r
108 {\r
109         CReaderVCView* pView =(CReaderVCView*)pThis;\r
110         if ( pView )\r
111         {\r
112                 pView->OutputSelectedRectImpl(page,left, top, right, bottom);\r
113         }\r
114 }\r
115 \r
116 void Sample_DeviceToPage(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page,int device_x, int device_y, double* page_x, double* page_y)\r
117 {\r
118         CReaderVCView* pView =(CReaderVCView*)pThis;\r
119         if ( pView )\r
120         {\r
121                 pView->DeviceToPageImpl(page, device_x, device_y, page_x, page_y);\r
122         }\r
123         //((CReaderVCView*)pThis)->DeviceToPageImpl(page, device_x, device_y, page_x, page_y);\r
124 }\r
125 /* /* Remove by Amy Lin 20100913, Since we don't this the FFI_SetCaret any more.\r
126 void Sample_SetCaret(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page,double page_x, double page_y, int nWidth, int nHeight)\r
127 {\r
128         CReaderVCView* pView =(CReaderVCView*)pThis;\r
129         if ( pView )\r
130         {\r
131                 pView->SetCaretImpl(page, page_x, page_y, nWidth,  nHeight);\r
132         }\r
133         //((CReaderVCView*)pThis)->SetCaretImpl(page, page_x, page_y, nWidth,  nHeight);\r
134 }\r
135 */\r
136 void Sample_Release(struct _FPDF_FORMFILLINFO* pThis)\r
137 {\r
138         CReaderVCView* pView =(CReaderVCView*)pThis;\r
139         if ( pView )\r
140         {\r
141                 pView->ReleaseImpl();\r
142         }\r
143         //((CReaderVCView*)pThis)->ReleaseImpl();\r
144 }\r
145 \r
146 \r
147 int Sample_SetTimer(struct _FPDF_FORMFILLINFO* pThis, int uElapse, TimerCallback lpTimerFunc)\r
148 {\r
149         CReaderVCView* pView =(CReaderVCView*)pThis;\r
150         if ( pView )\r
151         {\r
152                 return pView->SetTimerImpl(uElapse, lpTimerFunc);\r
153         }else{\r
154                 return -1;\r
155         }\r
156         //return ((CReaderVCView*)pThis)->SetTimerImpl(uElapse, lpTimerFunc);\r
157 }\r
158 \r
159 void Sample_KillTimer(struct _FPDF_FORMFILLINFO* pThis,int nID)\r
160 {\r
161         CReaderVCView* pView =(CReaderVCView*)pThis;\r
162         if ( pView )\r
163         {\r
164                 pView->KillTimerImpl(nID);\r
165         }\r
166         //((CReaderVCView*)pThis)->KillTimerImpl(nID);\r
167 }\r
168 \r
169 void Sample_SetCursor(struct _FPDF_FORMFILLINFO* pThis,int nCursorType)\r
170 {\r
171         CReaderVCView* pView =(CReaderVCView*)pThis;\r
172         if ( pView )\r
173         {\r
174                 pView->SetCurorImpl(nCursorType);\r
175         }\r
176         //((CReaderVCView*)pThis)->SetCurorImpl(nCursorType);\r
177 }\r
178 \r
179 void Sample_OnChange(struct _FPDF_FORMFILLINFO* pThis)\r
180 {\r
181         CReaderVCView* pView =(CReaderVCView*)pThis;\r
182         if ( pView )\r
183         {\r
184                 pView->OnChangeImpl();\r
185         }\r
186 }\r
187 FPDF_BOOL       Sample_IsSHIFTKeyDown(struct _FPDF_FORMFILLINFO* pThis)\r
188 {\r
189         CReaderVCView* pView =(CReaderVCView*)pThis;\r
190         if ( pView )\r
191         {\r
192                 return pView->IsSHIFTKeyDownImpl();\r
193         }\r
194         return FALSE;\r
195 }\r
196 FPDF_BOOL       Sample_IsCTRLKeyDown(struct _FPDF_FORMFILLINFO* pThis)\r
197 {\r
198         CReaderVCView* pView =(CReaderVCView*)pThis;\r
199         if ( pView )\r
200         {\r
201                 return pView->IsCTRLKeyDownImpl();\r
202         }\r
203         return FALSE;\r
204 }\r
205 FPDF_BOOL       Sample_IsALTKeyDown(struct _FPDF_FORMFILLINFO* pThis) \r
206 {\r
207         CReaderVCView* pView =(CReaderVCView*)pThis;\r
208         if ( pView )\r
209         {\r
210                 return pView->IsALTKeyDownImpl();\r
211         }\r
212         return FALSE;\r
213 }\r
214 FPDF_BOOL       Sample_IsINSERTKeyDown(struct _FPDF_FORMFILLINFO* pThis) \r
215 {\r
216         CReaderVCView* pView =(CReaderVCView*)pThis;\r
217         if ( pView )\r
218         {\r
219                 return pView->IsINSERTKeyDownImpl();\r
220         }\r
221         return FALSE;\r
222 }\r
223 \r
224 FPDF_PAGE Sample_GetPage(struct _FPDF_FORMFILLINFO* pThis,FPDF_DOCUMENT document, int nPageIndex)\r
225 {\r
226         CReaderVCView* pView =(CReaderVCView*)pThis;\r
227         if ( pView )\r
228         {\r
229                 return pView->GetPageImpl(document,nPageIndex);\r
230         }\r
231         return NULL;\r
232 }\r
233 \r
234 FPDF_PAGE Sample_GetCurrentPage(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document)\r
235 {\r
236         CReaderVCView* pView =(CReaderVCView*)pThis;\r
237         if ( pView )\r
238         {\r
239                 return pView->GetCurrentPageImpl(document);\r
240         }\r
241         return NULL;\r
242 }\r
243 \r
244 int Sample_GetRotation(struct _FPDF_FORMFILLINFO* pThis, FPDF_PAGE page)\r
245 {\r
246         CReaderVCView* pView =(CReaderVCView*)pThis;\r
247         if ( pView )\r
248         {\r
249                 return pView->GetRotationImpl(page);\r
250         }\r
251         return NULL;\r
252 }\r
253 FPDF_SYSTEMTIME Sample_GetLocalTime(struct _FPDF_FORMFILLINFO* pThis)\r
254 {\r
255         CReaderVCView* pView =(CReaderVCView*)pThis;\r
256         if ( pView )\r
257         {\r
258                 return pView->GetLocalTimeImpl();\r
259         }\r
260         return FPDF_SYSTEMTIME();\r
261 }\r
262 \r
263 void SampleRelease(struct _FPDF_SYSFONTINFO* pThis)\r
264 {\r
265         ((CSampleFontInfo*)pThis)->ReleaseImpl();\r
266 }\r
267 \r
268 void SampleEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper)\r
269 {\r
270         ((CSampleFontInfo*)pThis)->EnumFontsImpl(pMapper);\r
271 }\r
272 \r
273 void* SampleMapFont(struct _FPDF_SYSFONTINFO* pThis, int weight, int bItalic, int charset, int pitch_family, \r
274                                                 const char* face, int* bExact)\r
275 {\r
276         return ((CSampleFontInfo*)pThis)->MapFontImpl(weight, bItalic, charset, pitch_family, face, bExact);\r
277 }\r
278 \r
279 unsigned long SampleGetFontData(struct _FPDF_SYSFONTINFO* pThis, void* hFont,\r
280                                                                 unsigned int table, unsigned char* buffer, unsigned long buf_size)\r
281 {\r
282         return ((CSampleFontInfo*)pThis)->GetFontDataImpl(hFont, table, buffer, buf_size);\r
283 }\r
284 \r
285 unsigned long SampleGetFaceName(struct _FPDF_SYSFONTINFO* pThis, void* hFont, char* buffer, unsigned long buf_size)\r
286 {\r
287         return ((CSampleFontInfo*)pThis)->GetFaceNameImpl(hFont, buffer, buf_size);\r
288 }\r
289 \r
290 int SampleGetFontCharset(struct _FPDF_SYSFONTINFO* pThis, void* hFont)\r
291 {\r
292         return ((CSampleFontInfo*)pThis)->GetFontCharsetImpl(hFont);\r
293 }\r
294 \r
295 void SampleDeleteFont(struct _FPDF_SYSFONTINFO* pThis, void* hFont)\r
296 {\r
297         ((CSampleFontInfo*)pThis)->DeleteFontImpl(hFont);\r
298 }\r
299 \r
300 void SetSampleFontInfo()\r
301 {\r
302         CSampleFontInfo* pFontInfo = new CSampleFontInfo;\r
303         pFontInfo->version = 1;\r
304         pFontInfo->DeleteFont = SampleDeleteFont;\r
305         pFontInfo->EnumFonts = SampleEnumFonts;\r
306         pFontInfo->GetFaceName = SampleGetFaceName;\r
307         pFontInfo->GetFont = NULL;\r
308         pFontInfo->GetFontCharset = SampleGetFontCharset;\r
309         pFontInfo->GetFontData = SampleGetFontData;\r
310         pFontInfo->MapFont = SampleMapFont;\r
311         pFontInfo->Release = SampleRelease;\r
312         FPDF_SetSystemFontInfo(pFontInfo);\r
313 }\r
314 \r
315 void    Sample_ExecuteNamedAction(struct _FPDF_FORMFILLINFO* pThis, FPDF_BYTESTRING namedAction)\r
316 {\r
317         CReaderVCView* pView =(CReaderVCView*)pThis;\r
318         if ( pView )\r
319         {\r
320                  pView->ExecuteNamedActionImpl(namedAction);\r
321         }\r
322 \r
323 }\r
324 void CReaderVCView::ExecuteNamedActionImpl(FPDF_BYTESTRING namedaction)\r
325 {\r
326         if(strcmp("Print", (LPCSTR)namedaction) == 0)\r
327                 OnFilePrint();\r
328 }\r
329 void CReaderVCView::OutputSelectedRectImpl(FPDF_PAGE page, double left, double top, double right, double bottom)\r
330 {\r
331 \r
332         if(page == m_pPage)\r
333         {\r
334 \r
335                 int device_left, device_top, device_right, device_bottom;\r
336                 \r
337                 int nActualRangeX = 0;\r
338                 int nActualRangeY = 0;\r
339                 if ( m_nRotateFlag % 2 == 0 )\r
340                 {\r
341                         nActualRangeX = m_nActualSizeX;\r
342                         nActualRangeY = m_nActualSizeY;\r
343                 }else{\r
344                         nActualRangeX = m_nActualSizeY;\r
345                         nActualRangeY = m_nActualSizeX;\r
346                 }\r
347                 \r
348                 FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
349                         (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, left, top, &device_left, &device_top);\r
350                 \r
351                 FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
352                         (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, right, bottom, &device_right, &device_bottom);\r
353                 \r
354                 CRect rc(device_left,device_top, device_right, device_bottom);\r
355 \r
356 \r
357 \r
358                 m_SelectArray.Add(rc);\r
359 \r
360 \r
361         }\r
362 }\r
363 \r
364 void            Sample_Release(FPDF_LPVOID clientData)\r
365 {\r
366         if (!clientData) return;\r
367 \r
368         fclose(((FPDF_FILE*)clientData)->file);\r
369         delete ((FPDF_FILE*)clientData);\r
370 }\r
371 \r
372 FPDF_DWORD      Sample_GetSize(FPDF_LPVOID clientData)\r
373 {\r
374         if (!clientData) return 0;\r
375 \r
376         long curPos = ftell(((FPDF_FILE*)clientData)->file);\r
377         fseek(((FPDF_FILE*)clientData)->file, 0, SEEK_END);\r
378         long size = ftell(((FPDF_FILE*)clientData)->file);\r
379         fseek(((FPDF_FILE*)clientData)->file, curPos, SEEK_SET);\r
380 \r
381         return (FPDF_DWORD)size;\r
382 }\r
383 \r
384 FPDF_RESULT     Sample_ReadBlock(FPDF_LPVOID clientData, FPDF_DWORD offset, FPDF_LPVOID buffer, FPDF_DWORD size)\r
385 {\r
386         if (!clientData) return -1;\r
387 \r
388         fseek(((FPDF_FILE*)clientData)->file, (long)offset, SEEK_SET);\r
389         size_t readSize = fread(buffer, 1, size, ((FPDF_FILE*)clientData)->file);\r
390         return readSize == size ? 0 : -1;\r
391 }\r
392 \r
393 FPDF_RESULT     Sample_WriteBlock(FPDF_LPVOID clientData, FPDF_DWORD offset, FPDF_LPCVOID buffer, FPDF_DWORD size)\r
394 {\r
395         if (!clientData) return -1;\r
396 \r
397         fseek(((FPDF_FILE*)clientData)->file, (long)offset, SEEK_SET);\r
398         //Write data\r
399         size_t writeSize = fwrite(buffer, 1, size, ((FPDF_FILE*)clientData)->file);\r
400         return writeSize == size ? 0 : -1;\r
401 }\r
402 \r
403 FPDF_RESULT     Sample_Flush(FPDF_LPVOID clientData)\r
404 {\r
405         if (!clientData) return -1;\r
406 \r
407         //Flush file\r
408         fflush(((FPDF_FILE*)clientData)->file);\r
409 \r
410         return 0;\r
411 }\r
412 \r
413 FPDF_RESULT     Sample_Truncate(FPDF_LPVOID clientData, FPDF_DWORD size)\r
414 {\r
415         return 0;\r
416 }\r
417 \r
418 void    Sample_DisplayCaret(struct _FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, FPDF_BOOL bVisible, double left, double top, double right, double bottom)\r
419 {\r
420         CReaderVCView* pView =(CReaderVCView*)pThis;\r
421         if (!pView) return;\r
422 \r
423         HWND hWnd = pView->m_hWnd;\r
424 \r
425         if (bVisible)\r
426         {\r
427                 CPoint ltPt;\r
428                 pView->PageToDevice(left, top, ltPt);\r
429                 CPoint rbPt;\r
430                 pView->PageToDevice(right, bottom, rbPt);\r
431                 CRect rcCaret(ltPt, rbPt);\r
432                 \r
433                 ::DestroyCaret();\r
434                 ::CreateCaret(hWnd, (HBITMAP)0, rcCaret.Width(), rcCaret.Height());\r
435                 ::SetCaretPos (rcCaret.left, rcCaret.top);\r
436                 ::ShowCaret(hWnd);\r
437         }\r
438         else\r
439         {\r
440                 ::DestroyCaret();\r
441                 ::HideCaret(hWnd);\r
442         }\r
443 }\r
444 \r
445 int             Sample_GetCurrentPageIndex(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document)\r
446 {\r
447         CReaderVCView* pView =(CReaderVCView*)pThis;\r
448         if (!pView) return -1;\r
449 \r
450         return pView->GetCurrentPageIndex();\r
451 }\r
452 \r
453 void    Sample_SetCurrentPage(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, int iCurPage)\r
454 {\r
455         CReaderVCView* pView = (CReaderVCView*)pThis;\r
456         if (!pView) return;\r
457 \r
458         FPDF_DOCUMENT curDoc = pView->GetPDFDoc();\r
459         if (curDoc != document)\r
460                 return;\r
461 \r
462         int nPageCount = FPDF_GetPageCount(curDoc);\r
463         if (nPageCount > iCurPage)\r
464         {\r
465                 int nCurPageInx = pView->GetCurrentPageIndex();\r
466                 if (nCurPageInx != iCurPage)\r
467                 {\r
468                         pView->GotoPage(nCurPageInx);\r
469                 }\r
470         }\r
471 }\r
472 \r
473 void    Sample_GotoURL(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, FPDF_WIDESTRING wsURL)\r
474 {\r
475         CReaderVCView* pView = (CReaderVCView*)pThis;\r
476         if (!pView) return;\r
477 \r
478         wchar_t* pURL = (wchar_t*)wsURL;\r
479         MessageBoxW(NULL, pURL, NULL, MB_OK);\r
480 }\r
481 \r
482 FPDF_WIDESTRING Sample_GetURL(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document)\r
483 {\r
484         CReaderVCView* pView = (CReaderVCView*)pThis;\r
485         if (!pView) return NULL;\r
486 \r
487         if (pView->GetPDFDoc() != document)\r
488                 return NULL;\r
489 \r
490         //not support in this demo\r
491 \r
492         return NULL;\r
493 }\r
494 \r
495 void Sample_AddDoRecord(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, FPDF_WIDGET hWidget)\r
496 {\r
497         //not support\r
498 }\r
499 \r
500 void    Sample_PageEvent(struct _FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, FPDF_DWORD eventFlag)\r
501 {\r
502         //\r
503 }\r
504 \r
505 void    Sample_GetPageViewRect(struct _FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, double* left, double* top, double* right, double* bottom)\r
506 {\r
507         CReaderVCView* pView = (CReaderVCView*)pThis;\r
508         if (!pView) return;\r
509 \r
510         if (pView->GetPage() != page)\r
511                 return;\r
512 \r
513         CRect clientRect;\r
514         pView->GetClientRect(&clientRect);\r
515 \r
516         *left = (double)clientRect.left;\r
517         *right = (double)clientRect.right;\r
518         *top = (double)clientRect.top;\r
519         *bottom = (double)clientRect.bottom;\r
520 }\r
521 \r
522 #define  WM_XFAMENU_COPY          10000\r
523 \r
524 FPDF_BOOL Sample_PopupMenu(struct _FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, FPDF_WIDGET hWidget, int menuFlag, float x, float y)\r
525 {\r
526         CReaderVCView* pView = (CReaderVCView*)pThis;\r
527         if (!pView)\r
528                 return FALSE;\r
529 \r
530         CMenu menu;\r
531         menu.CreatePopupMenu();\r
532 \r
533         int nMenuIndex = 0;\r
534 \r
535         if (menuFlag & FXFA_MEMU_COPY)\r
536                 menu.InsertMenu(nMenuIndex++, MF_BYPOSITION, WM_XFAMENU_COPY, "Copy");\r
537         //...\r
538 \r
539         CPoint pt;\r
540         pView->PageToDevice(x, y, pt);\r
541 \r
542         UINT nID = menu.TrackPopupMenu(TPM_RIGHTBUTTON, pt.x, pt.y, pView);\r
543         switch(nID)\r
544         {\r
545         case WM_XFAMENU_COPY:\r
546                 {\r
547                         FPDF_DWORD length = 0;\r
548                         FPDF_Widget_Copy(pView->GetPDFDoc(), hWidget, NULL, &length);\r
549                         if (length > 0)\r
550                         {\r
551                                 unsigned short* buffer = (unsigned short*)malloc((length+1)*sizeof(unsigned short));\r
552                                 memset(buffer, 0, (length+1)*sizeof(unsigned short));\r
553                                 FPDF_Widget_Copy(pView->GetPDFDoc(), hWidget, buffer, &length);\r
554                                 free(buffer);\r
555                         }\r
556                 }\r
557                 break;\r
558         }\r
559 \r
560         menu.DestroyMenu();\r
561 \r
562         return TRUE;\r
563 }\r
564 \r
565 FPDF_FILEHANDLER* Sample_OpenFile(struct _FPDF_FORMFILLINFO* pThis, int fileFlag, FPDF_WIDESTRING wsURL)\r
566 {\r
567         char* pszURL;\r
568         CString strURL;\r
569         if (wsURL == NULL) {\r
570                 if (fileFlag == FXFA_FILE_XDP)\r
571                         strURL = "C://temp.xdp";\r
572                 else if(fileFlag == FXFA_FILE_XML)\r
573                         strURL = "C://temp.xml";\r
574         }\r
575         else {\r
576                 int iSize;\r
577                 iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, NULL, 0, NULL, NULL);\r
578                 pszURL = (char*)malloc((iSize+1));\r
579                 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, pszURL, iSize, NULL, NULL);\r
580                 CString str(pszURL);\r
581                 strURL = str;\r
582         }\r
583         \r
584 \r
585         FILE* file = fopen(strURL, "r");\r
586         FPDF_FILE* pFileHander = new FPDF_FILE;\r
587         pFileHander->file = file;\r
588         pFileHander->fileHandler.clientData = pFileHander;\r
589         pFileHander->fileHandler.Flush = Sample_Flush;\r
590         pFileHander->fileHandler.GetSize = Sample_GetSize;\r
591         pFileHander->fileHandler.ReadBlock = Sample_ReadBlock;\r
592         pFileHander->fileHandler.Release = Sample_Release;\r
593         pFileHander->fileHandler.Truncate = Sample_Truncate;\r
594         pFileHander->fileHandler.WriteBlock = Sample_WriteBlock;\r
595 \r
596         free(pszURL);\r
597         return &pFileHander->fileHandler;\r
598 }\r
599 \r
600 FPDF_BOOL Sample_GetFilePath(struct _FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* pFileHandler, FPDF_BSTR* path)\r
601 {\r
602         CReaderVCView* pView = (CReaderVCView*)pThis;\r
603         if (!pView)\r
604                 return NULL;\r
605 \r
606         CString filePath = pView->GetFilePath();\r
607         FPDF_BStr_Set(path, filePath.GetBuffer(filePath.GetLength()), filePath.GetLength());\r
608 \r
609         return TRUE;\r
610 }\r
611 \r
612 void    Sample_EmailTo(struct _FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* fileHandler, FPDF_WIDESTRING emailTo)\r
613 {\r
614         MessageBoxW(NULL, (wchar_t*)emailTo, L"Sample_email", MB_OK);\r
615 }\r
616 \r
617 void    Sample_UploadTo(struct _FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* fileHandler, FPDF_WIDESTRING uploadTo)\r
618 {\r
619         int iSize;\r
620         char* pszURL;\r
621         iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)uploadTo, -1, NULL, 0, NULL, NULL);\r
622         pszURL = (char*)malloc((iSize+1));\r
623         WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)uploadTo, -1, pszURL, iSize, NULL, NULL);\r
624         CString strPath(pszURL);\r
625 \r
626         CString strUploadPath = "C://test";\r
627         int pos = strPath.ReverseFind('.');\r
628         if (pos != -1){\r
629                 CString suffix = strPath.Right(strPath.GetLength()-pos);\r
630                 strUploadPath += suffix;\r
631         }\r
632 \r
633         FILE* file = fopen(strUploadPath, "r");\r
634         if (file) {\r
635                 int size = fileHandler->GetSize(fileHandler->clientData);\r
636                 BYTE* buffer = (BYTE*)malloc(size);\r
637                 fileHandler->ReadBlock(fileHandler->clientData, 0, buffer, size);\r
638                 fwrite(buffer, size, 1, file);\r
639                 fflush(file);\r
640                 fclose(file);\r
641                 free(buffer);\r
642         }\r
643 \r
644         free(pszURL);\r
645 }\r
646 \r
647 int             Sample_GetAppName(struct _FPDF_FORMFILLINFO* pThis, void* appName, int length)\r
648 {\r
649         if(appName == NULL || length <= 0)\r
650         {\r
651                 CString name = AfxGetAppName();\r
652                 return name.GetLength();\r
653         }       \r
654         else\r
655         {\r
656                 CString name = AfxGetAppName();\r
657                 int len = name.GetLength();\r
658                 if(length > len)\r
659                         length = len;\r
660                 memcpy(appName, name.GetBuffer(name.GetLength()), length);\r
661                 return length;\r
662         }\r
663 }\r
664 \r
665 int             Sample_GetPlatform(struct _FPDF_FORMFILLINFO* pThis, void* platform, int length)\r
666 {\r
667         if(platform == NULL || length <= 0)\r
668         {\r
669                 return 3;\r
670         }       \r
671         else\r
672         {\r
673                 if(length > 3)\r
674                         length = 3;\r
675                 memcpy(platform, "win", length);\r
676                 return length;\r
677         }\r
678 }\r
679 \r
680 int             Sample_GetDocumentCount(struct _FPDF_FORMFILLINFO* pThis)\r
681 {\r
682         return 1;\r
683 }\r
684 \r
685 int             Sample_GetCurDocumentIndex(struct _FPDF_FORMFILLINFO* pThis)\r
686 {\r
687         return 0;\r
688 }\r
689 \r
690 FPDF_LPFILEHANDLER      Sample_DownloadFromURL(struct _FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING URL)\r
691 {\r
692         int iSize;\r
693         char* pszURL;\r
694         iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)URL, -1, NULL, 0, NULL, NULL);\r
695         pszURL = (char*)malloc((iSize+1));\r
696         WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)URL, -1, pszURL, iSize, NULL, NULL);\r
697         CString strURL(pszURL);\r
698 \r
699         CString bsLocal = strURL;\r
700         CReaderVCView::CreateLocalPath(bsLocal);\r
701 \r
702         if (strURL.Left(7) == "http://")\r
703         {\r
704                 CInternetSession sess;\r
705                 CHttpFile *pFile = (CHttpFile*)sess.OpenURL(strURL);\r
706                 int iLength = pFile->GetLength();\r
707                 if (pFile == NULL || iLength < 1) return NULL;\r
708 \r
709                 FILE *pImageFile = fopen(bsLocal, "wb");\r
710 \r
711                 BYTE* pContent = new BYTE[iLength];\r
712                 memset(pContent, 0, iLength);\r
713                 int iRead = pFile->Read(pContent, iLength);\r
714 \r
715                 fwrite(pContent, 1, iLength, pImageFile);\r
716                 free(pContent);\r
717                 fflush(pImageFile);\r
718                 fclose(pImageFile);\r
719 \r
720                 pFile->Close();\r
721                 delete pFile;\r
722                 sess.Close();\r
723         }\r
724         else if (strURL.Left(6) == "ftp://")\r
725         {\r
726                 CInternetSession sess;\r
727                 CFtpConnection* pConnect = sess.GetFtpConnection(bsLocal, "NULL", "NULL"); \r
728                 CInternetFile* pFile = pConnect->OpenFile(bsLocal);\r
729 \r
730                 int iLength = pFile->GetLength();\r
731                 if (pFile == NULL || iLength < 1) return NULL;\r
732                 FILE *pImageFile = fopen(bsLocal, "wb");\r
733 \r
734                 BYTE* pContent = new BYTE[iLength];\r
735                 memset(pContent, 0, iLength);\r
736                 int iRead = pFile->Read(pContent, iLength);\r
737 \r
738                 fwrite(pContent, 1, iLength, pImageFile);\r
739                 free(pContent);\r
740                 fflush(pImageFile);\r
741                 fclose(pImageFile);\r
742 \r
743                 pFile->Close();\r
744                 delete pFile;\r
745                 sess.Close();\r
746         }       \r
747         \r
748         free(pszURL);\r
749         \r
750         FPDF_FILE* fileWrap = new FPDF_FILE;\r
751         FILE* file = fopen(bsLocal, "r");\r
752         fileWrap->file = file;\r
753         fileWrap->fileHandler.clientData = fileWrap;\r
754         fileWrap->fileHandler.ReadBlock = Sample_ReadBlock;\r
755         fileWrap->fileHandler.GetSize = Sample_GetSize;\r
756         fileWrap->fileHandler.Flush = Sample_Flush;\r
757         fileWrap->fileHandler.Release = Sample_Release;\r
758         fileWrap->fileHandler.Truncate = Sample_Truncate;\r
759         fileWrap->fileHandler.WriteBlock = Sample_WriteBlock;\r
760 \r
761         return &fileWrap->fileHandler;\r
762 }\r
763 \r
764 FPDF_BOOL       Sample_PostRequestURL(struct _FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsURL, FPDF_WIDESTRING wsData, FPDF_WIDESTRING wsContentType, FPDF_WIDESTRING wsEncode, FPDF_WIDESTRING wsHeader, FPDF_BSTR* respone)\r
765 {\r
766         int iSize;\r
767         char* pszURL;\r
768         iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, NULL, 0, NULL, NULL);\r
769         pszURL = (char*)malloc((iSize+1));\r
770         WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, pszURL, iSize, NULL, NULL);\r
771         CString csURL(pszURL);\r
772 \r
773         char* pszData;\r
774         iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsData, -1, NULL, 0, NULL, NULL);\r
775         pszData = (char*)malloc(iSize+1);\r
776         WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsData, -1, pszData, iSize, NULL, NULL);\r
777         CString csData(pszData);\r
778         \r
779         char* pszContentType;\r
780         iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsContentType, -1, NULL, 0, NULL, NULL);\r
781         pszContentType = (char*)malloc(iSize+1);\r
782         WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsContentType, -1, pszContentType, iSize, NULL, NULL);\r
783         CString csContentType(pszContentType);\r
784         \r
785         char* pszHeader;\r
786         iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsHeader, -1, NULL, 0, NULL, NULL);\r
787         pszHeader = (char*)malloc(iSize+1);\r
788         WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsHeader, -1, pszHeader, iSize, NULL, NULL);\r
789         CString csHeader(pszHeader);\r
790 \r
791         CString csApp = AfxGetAppName();\r
792         csApp += L"/1.0";\r
793         BOOL bRet = FALSE;\r
794         DWORD dwServiceType = 0, dwFlags = ICU_NO_META;\r
795         CString csServer, sObject, csUserName, csPassword;\r
796         INTERNET_PORT nPort = 0;\r
797 \r
798         bRet = AfxParseURLEx(csURL, dwServiceType, csServer, sObject, nPort, csUserName, csPassword, dwFlags);\r
799         if (!bRet)\r
800                 return bRet;\r
801 \r
802         if (dwServiceType != AFX_INET_SERVICE_HTTP && dwServiceType != AFX_INET_SERVICE_HTTPS)\r
803                 return bRet;\r
804 \r
805         CString csObject = sObject;\r
806         CString csResponse;\r
807         bRet = CReaderVCView::HttpDataPost(csData, csApp, csObject, csServer, csUserName, csPassword, nPort,\r
808                 dwServiceType == AFX_INET_SERVICE_HTTPS, csContentType, csHeader, csResponse);\r
809 \r
810         FPDF_BStr_Init(respone);\r
811         FPDF_BStr_Set(respone, (FPDF_LPCSTR)csResponse.GetBuffer(csResponse.GetLength()), csResponse.GetLength());\r
812 \r
813         free(pszURL);\r
814         free(pszData);\r
815         free(pszContentType);\r
816         free(pszHeader);\r
817 \r
818         return true;\r
819 }\r
820 \r
821 FPDF_BOOL       Sample_PutRequestURL(struct _FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsURL, FPDF_WIDESTRING wsData, FPDF_WIDESTRING wsEncode)\r
822 {\r
823         int iSize;\r
824         char* pszURL;\r
825         iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, NULL, 0, NULL, NULL);\r
826         pszURL = (char*)malloc((iSize+1));\r
827         WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, pszURL, iSize, NULL, NULL);\r
828         CString csURL(pszURL);\r
829 \r
830         char* pszData;\r
831         iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsData, -1, NULL, 0, NULL, NULL);\r
832         pszData = (char*)malloc((iSize+1));\r
833         WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsData, -1, pszData, iSize, NULL, NULL);\r
834         CString csData(pszData);\r
835 \r
836         CString csApp = AfxGetAppName();\r
837         csApp += L"/1.0";\r
838         BOOL bRet = FALSE;\r
839         DWORD dwServiceType = 0, dwFlags = ICU_NO_META;\r
840         CString csServer, sObject, csUserName, csPassword;\r
841         INTERNET_PORT nPort = 0;\r
842 \r
843         bRet = AfxParseURLEx(csURL, dwServiceType, csServer, sObject, nPort, csUserName, csPassword, dwFlags);\r
844         if (!bRet)\r
845                 return bRet;\r
846 \r
847         if (dwServiceType != AFX_INET_SERVICE_HTTP && dwServiceType != AFX_INET_SERVICE_HTTPS)\r
848                 return bRet;\r
849 \r
850         CString csObject = sObject;\r
851 \r
852         bRet = CReaderVCView::HttpDataPut(csData, csApp, csObject, csServer, csUserName, csPassword, nPort, dwServiceType == AFX_INET_SERVICE_HTTPS);\r
853         \r
854         free(pszData);\r
855         free(pszURL);\r
856         return TRUE;\r
857 }\r
858 \r
859 FPDF_BOOL       Sample_ShowFileDialog(struct _FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsTitle, FPDF_WIDESTRING wsFilter, FPDF_BOOL isOpen, FPDF_STRINGHANDLE pathArr)\r
860 {\r
861         int iSize;\r
862         char* pszFilter;\r
863         iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsFilter, -1, NULL, 0, NULL, NULL);\r
864         pszFilter = (char*)malloc((iSize+1));\r
865         WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsFilter, -1, pszFilter, iSize, NULL, NULL);\r
866 \r
867         CFileDialog fileOpen(isOpen, NULL,NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST, pszFilter);\r
868         //      fileOpen.m_ofn.Flags|=OFN_ENABLEHOOK|OFN_ALLOWMULTISELECT;\r
869         if(fileOpen.DoModal()==IDCANCEL) \r
870         { \r
871                 return FALSE;   \r
872         }\r
873         \r
874         POSITION pos;   \r
875         pos=fileOpen.GetStartPosition(); \r
876         CString csFile;\r
877         while(pos!=NULL) \r
878         { \r
879                 csFile=fileOpen.GetNextPathName(pos); \r
880                 FPDF_StringHandleAddString(pathArr, csFile.GetBuffer(csFile.GetLength()), csFile.GetLength());          \r
881         }\r
882 \r
883         free(pszFilter);\r
884         return TRUE;\r
885 }\r
886 \r
887 FPDF_SYSTEMTIME CReaderVCView::GetLocalTimeImpl()\r
888 {\r
889         FPDF_SYSTEMTIME sys;\r
890         time_t curTime;\r
891         time(&curTime);\r
892         tm* pTm = localtime(&curTime);\r
893         if(pTm)\r
894         {\r
895                 sys.wDay = pTm->tm_mday;\r
896                 sys.wDayOfWeek= pTm->tm_wday;\r
897                 sys.wHour = pTm->tm_hour;\r
898                 sys.wMilliseconds = 0;\r
899                 sys.wMinute = pTm->tm_min;\r
900                 sys.wMonth = pTm->tm_mon;\r
901                 sys.wSecond = pTm->tm_sec;\r
902                 sys.wYear = pTm->tm_year + 1900;\r
903         }\r
904         \r
905         return sys;\r
906 }\r
907 \r
908 int CReaderVCView::GetRotationImpl(FPDF_PAGE page)\r
909 {\r
910         return m_nRotateFlag;\r
911 }\r
912 \r
913 FPDF_PAGE CReaderVCView::GetPageImpl(FPDF_DOCUMENT document,int nPageIndex)\r
914 {\r
915         FPDF_PAGE page = NULL;\r
916         m_pageMap.Lookup(nPageIndex, page);\r
917         if(page)\r
918                 return page;\r
919         page = FPDF_LoadPage(document, nPageIndex);\r
920         FORM_OnAfterLoadPage(page, m_pApp);\r
921         m_pageMap.SetAt(nPageIndex, page);\r
922         return page;\r
923 }\r
924 \r
925 FPDF_PAGE CReaderVCView::GetCurrentPageImpl(FPDF_DOCUMENT document)\r
926 {\r
927         return m_pPage;\r
928 }\r
929 \r
930 bool CReaderVCView::IsALTKeyDownImpl()\r
931 {\r
932         return GetKeyState(VK_MENU) < 0;\r
933 }\r
934 bool CReaderVCView::IsINSERTKeyDownImpl()\r
935 {\r
936         return GetKeyState(VK_INSERT) & 0x01;\r
937 }\r
938 bool CReaderVCView::IsSHIFTKeyDownImpl()\r
939 {\r
940         return !((GetKeyState(VK_SHIFT)&0x8000) == 0);\r
941 }\r
942 bool CReaderVCView::IsCTRLKeyDownImpl()\r
943 {\r
944         return GetKeyState(VK_CONTROL) < 0;\r
945 }\r
946 \r
947 void CReaderVCView::OnChangeImpl()\r
948 {\r
949 \r
950 }\r
951 \r
952 CString CReaderVCView::GetFilePath()\r
953 {\r
954         CReaderVCDoc* pDoc = GetDocument();\r
955         if(pDoc)\r
956         {\r
957                 return pDoc->m_strPDFName;\r
958         }\r
959         return "";\r
960 }\r
961 \r
962 BOOL CReaderVCView::SubmitFormImpl(void* pBuffer, int nLength, CString strURL)\r
963 {\r
964         CString tempFDFFile = "D://1.fdf";\r
965 \r
966         if (pBuffer == NULL || nLength <= 0)\r
967         {\r
968                 return FALSE;\r
969         }\r
970 \r
971         CFile file;\r
972         if (file.Open(tempFDFFile, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary))\r
973         {\r
974                 file.Write(pBuffer, nLength);\r
975                 file.Close();\r
976         }\r
977 \r
978         return TRUE;\r
979 }\r
980 \r
981 int Sample_appResponse(struct _IPDF_JsPlatform* pThis, FPDF_WIDESTRING Question, FPDF_WIDESTRING Title, \r
982                                            FPDF_WIDESTRING Default, FPDF_WIDESTRING cLabel, FPDF_BOOL bPassword, void* response, int length)\r
983 {\r
984         CReaderVCView* pView = (CReaderVCView*)pThis->m_pFormfillinfo;\r
985         FPDF_WIDESTRING wsResponse;\r
986 \r
987         if (pView->m_pwsResponse && response != NULL)\r
988         {\r
989                 wsResponse = (FPDF_WIDESTRING)pView->m_pwsResponse;\r
990                 length = wcslen((const wchar_t*)wsResponse);\r
991                 memcpy(response, wsResponse, length*sizeof(wchar_t));\r
992                 pView->m_pwsResponse = NULL;\r
993         }       \r
994         else\r
995         {\r
996                 CJS_ResponseDlg dlg;\r
997                 dlg.SetTitle(Title);\r
998                 dlg.SetDefault(Default);\r
999                 dlg.SetLabel(cLabel);\r
1000                 dlg.SetQuestion(Question);\r
1001                 dlg.SetIsVisible(bPassword);\r
1002                 int iRet = dlg.DoModal();               \r
1003                 \r
1004                 if (iRet == 1)\r
1005                 {\r
1006                         wsResponse = dlg.GetResponse();\r
1007                         length = wcslen((const wchar_t*)wsResponse);\r
1008                         pView->m_pwsResponse = new wchar_t[length+1];\r
1009                         memset(pView->m_pwsResponse, 0, length*sizeof(wchar_t));\r
1010                         memcpy(pView->m_pwsResponse, wsResponse, length*sizeof(wchar_t));\r
1011                         pView->m_pwsResponse[length] = L'\0';\r
1012                 }\r
1013         }\r
1014         \r
1015         return length*sizeof(wchar_t);\r
1016 }\r
1017 \r
1018 int Sample_appalert(struct _IPDF_JsPlatform* pThis, FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon)\r
1019 {\r
1020         int nRet = 0;\r
1021         if(pThis && pThis->m_pFormfillinfo)\r
1022         {\r
1023                 CReaderVCView* pView = (CReaderVCView*)pThis->m_pFormfillinfo;\r
1024                 int msgType = MB_OK;\r
1025                 switch(Type)\r
1026                 {\r
1027         \r
1028                 case 1:\r
1029                         msgType = MB_OKCANCEL;\r
1030                         break;\r
1031                 case 2:\r
1032                         msgType = MB_YESNO;\r
1033                         break;\r
1034                 case 3:\r
1035                         msgType = MB_YESNOCANCEL;\r
1036                         break;  \r
1037                 case 0:\r
1038                 default:\r
1039                         break;\r
1040                 }\r
1041                 nRet = MessageBoxW(pView->m_hWnd, (const wchar_t*)Msg, (const wchar_t*)Title, msgType);\r
1042                 switch(nRet)\r
1043                 {\r
1044                 case IDOK:\r
1045                         return 1;\r
1046                 case IDCANCEL:\r
1047                         return 2;\r
1048                 case IDNO:\r
1049                         return 3;\r
1050                 case IDYES:\r
1051                         return 4;\r
1052                 }\r
1053                 return nRet;\r
1054         }\r
1055         return nRet;\r
1056 }\r
1057 \r
1058 void Sample_appbeep(struct _IPDF_JsPlatform* pThis, int nType)\r
1059 {\r
1060         MessageBeep(nType);\r
1061         //AfxMessageBox("aaaa");\r
1062 }\r
1063 \r
1064 \r
1065 CString userSelFilePath;\r
1066 int  Sample_fieldBrowse(struct _IPDF_JsPlatform* pThis,void* filePath, int length)\r
1067 {\r
1068         if(userSelFilePath.IsEmpty())\r
1069         {\r
1070                 CFileDialog fd(FALSE, "fdf");\r
1071                 if(fd.DoModal() == IDOK)\r
1072                 {\r
1073                         userSelFilePath = fd.GetPathName();\r
1074                         \r
1075                         if(filePath == NULL || length == 0)\r
1076                                 return userSelFilePath.GetLength() + 1;\r
1077                         else\r
1078                                 return 0;\r
1079                 }\r
1080                 else\r
1081                         return 0;\r
1082         }       \r
1083         else\r
1084         {\r
1085                 int nLen = userSelFilePath.GetLength()+1;\r
1086                 if(length > nLen)\r
1087                         length = nLen;\r
1088                 memcpy(filePath, userSelFilePath.GetBuffer(length), length);\r
1089                 userSelFilePath.ReleaseBuffer();\r
1090                 userSelFilePath = "";\r
1091                 return length;\r
1092         }\r
1093 }\r
1094 int Sample_docGetFilePath(struct _IPDF_JsPlatform* pThis, void* filePath, int length)\r
1095 {\r
1096         if(pThis && pThis->m_pFormfillinfo)\r
1097         {\r
1098                 CReaderVCView* pView = (CReaderVCView*)pThis->m_pFormfillinfo;\r
1099                 CString csFilePath = pView->GetFilePath();\r
1100 \r
1101                 int nbufflen = csFilePath.GetLength() + 1;\r
1102                 if(filePath == NULL || length == 0)\r
1103                         return nbufflen;\r
1104 \r
1105                 if(length > nbufflen)\r
1106                         length = nbufflen;\r
1107                 memcpy(filePath, csFilePath.GetBuffer(length), length);\r
1108                 csFilePath.ReleaseBuffer();\r
1109 \r
1110                 return length;\r
1111 \r
1112         }\r
1113         return 0;\r
1114 }\r
1115 \r
1116 void Sample_docSubmitForm(struct _IPDF_JsPlatform* pThis,void* formData, int length, FPDF_WIDESTRING URL)\r
1117 {\r
1118         if(pThis && pThis->m_pFormfillinfo)\r
1119         {\r
1120                 CReaderVCView *pView = (CReaderVCView*)pThis->m_pFormfillinfo;\r
1121                 if (pView)\r
1122                 {\r
1123                         pView->SubmitFormImpl(formData, length, "");\r
1124                 }\r
1125         }       \r
1126 }\r
1127 \r
1128 void Sample_gotoPage(struct _IPDF_JsPlatform* pThis, int nPageNum)\r
1129 {\r
1130         if(pThis && pThis->m_pFormfillinfo)\r
1131         {\r
1132                 CReaderVCView *pView = (CReaderVCView*)pThis->m_pFormfillinfo;\r
1133                 if (pView)\r
1134                 {\r
1135                         pView->GotoPage(nPageNum);\r
1136                 }\r
1137         }       \r
1138 }\r
1139 \r
1140 CReaderVCView::CReaderVCView()\r
1141 {\r
1142         // TODO: add construction code here\r
1143         m_pFram = NULL;\r
1144         m_pExportPageDlg = NULL;\r
1145         m_pDoc = NULL;\r
1146         m_pPage = NULL;\r
1147         m_nTotalPage = 0;\r
1148         m_nRotateFlag = 0;\r
1149         m_dbScaleFactor = 1.0f;\r
1150         m_nPageIndex = -1;\r
1151         m_dbPageWidth = 0.0f;\r
1152         m_dbPageHeight = 0.0f;\r
1153         m_nStartX = 0;\r
1154         m_nStartY = 0;\r
1155         m_nActualSizeX = 0;\r
1156         m_nActualSizeY = 0;\r
1157 \r
1158         //for search text\r
1159         m_pTextPage = NULL;\r
1160         m_FindInfo.m_strFind = _T("");\r
1161         m_FindInfo.m_nFlag = -1;\r
1162         m_FindInfo.m_nDirection = -1;\r
1163         m_FindInfo.m_nStartPageIndex = -1;\r
1164         m_FindInfo.m_nStartCharIndex = -1;\r
1165         m_FindInfo.m_bFirst = TRUE;\r
1166         m_FindInfo.m_pCurFindBuf = NULL;\r
1167         m_pSCHHandle = NULL;\r
1168 \r
1169         m_rtFind = NULL;\r
1170         m_nRectNum = 0;\r
1171         \r
1172         //for select text\r
1173         m_bSelect = FALSE;\r
1174         m_bHand = TRUE;\r
1175         m_bSnap = FALSE;\r
1176         m_bHasChar = FALSE;\r
1177         \r
1178         m_ptLBDown.x = m_ptLBDown.y = 0;\r
1179         m_ptLBUp.x = m_ptLBUp.y = 0;\r
1180         m_ptOld.x = m_ptOld.y = 0;\r
1181 \r
1182         m_nStartIndex = m_nEndIndex = m_nOldIndex = -1;\r
1183         m_rtArray.RemoveAll();\r
1184         m_rtOld.left = m_rtOld.right = m_rtOld.bottom = m_rtOld.top = 0;\r
1185 \r
1186         m_nPosH = m_nPosV = -1;\r
1187 \r
1188         // for links\r
1189         m_pLink = NULL;\r
1190         m_bBookmark = FALSE;\r
1191 \r
1192         m_bmp = NULL;\r
1193         m_pwsResponse = NULL;\r
1194 \r
1195         this->FFI_Invalidate = Sample_Invalidate;\r
1196         this->Release= Sample_Release;\r
1197         this->FFI_SetTimer = Sample_SetTimer;\r
1198         this->FFI_KillTimer = Sample_KillTimer;\r
1199         this->FFI_GetLocalTime = Sample_GetLocalTime;\r
1200         this->FFI_SetCursor = Sample_SetCursor;\r
1201         this->FFI_OnChange = Sample_OnChange;\r
1202         this->FFI_GetPage = Sample_GetPage;\r
1203         this->FFI_GetCurrentPage = Sample_GetCurrentPage;\r
1204         this->FFI_GetRotation = Sample_GetRotation;\r
1205         this->FFI_OutputSelectedRect = Sample_OutputSelectedRect;\r
1206         this->FFI_ExecuteNamedAction = Sample_ExecuteNamedAction;\r
1207         this->FFI_OutputSelectedRect  = NULL;\r
1208         this->FFI_SetTextFieldFocus = NULL;\r
1209         this->FFI_DoGoToAction = NULL;\r
1210         this->FFI_DoURIAction = NULL;\r
1211         this->FFI_DisplayCaret = Sample_DisplayCaret;\r
1212         this->FFI_GetCurrentPageIndex = Sample_GetCurrentPageIndex;\r
1213         this->FFI_SetCurrentPage = Sample_SetCurrentPage;\r
1214         this->FFI_GotoURL = Sample_GotoURL;\r
1215         this->FFI_GetPageViewRect = Sample_GetPageViewRect;\r
1216         this->FFI_PopupMenu = Sample_PopupMenu;\r
1217         this->FFI_OpenFile = Sample_OpenFile;\r
1218         this->FFI_GetFilePath = Sample_GetFilePath;\r
1219         this->FFI_EmailTo = Sample_EmailTo;\r
1220         this->FFI_UploadTo = Sample_UploadTo;\r
1221         this->FFI_GetPlatform = Sample_GetPlatform;\r
1222         this->FFI_GetDocumentCount = Sample_GetDocumentCount;\r
1223         this->FFI_GetCurDocumentIndex = Sample_GetCurDocumentIndex;\r
1224         this->FFI_DownloadFromURL = Sample_DownloadFromURL;\r
1225         this->FFI_PostRequestURL = Sample_PostRequestURL;\r
1226         this->FFI_PutRequestURL = Sample_PutRequestURL;\r
1227         this->FFI_ShowFileDialog = Sample_ShowFileDialog;       \r
1228         this->version = 1;\r
1229         \r
1230         this->m_pJsPlatform = NULL;\r
1231         this->m_pJsPlatform = new IPDF_JSPLATFORM;\r
1232         memset(m_pJsPlatform, 0, sizeof(IPDF_JSPLATFORM));\r
1233         this->m_pJsPlatform->app_alert = Sample_appalert;\r
1234         this->m_pJsPlatform->app_response = Sample_appResponse;\r
1235         this->m_pJsPlatform->app_beep = Sample_appbeep;\r
1236         this->m_pJsPlatform->Field_browse =Sample_fieldBrowse;\r
1237         this->m_pJsPlatform->Doc_getFilePath = Sample_docGetFilePath;\r
1238         this->m_pJsPlatform->Doc_submitForm = Sample_docSubmitForm;\r
1239         this->m_pJsPlatform->Doc_gotoPage = Sample_gotoPage;\r
1240         this->m_pJsPlatform->m_pFormfillinfo = this;\r
1241 \r
1242         m_pApp = NULL;\r
1243 }\r
1244 \r
1245 \r
1246 CReaderVCView::~CReaderVCView()\r
1247 {\r
1248 \r
1249 //      FPDF_DestroyApp(m_App);\r
1250 \r
1251         if(m_pTextPage != NULL)\r
1252         {\r
1253                 FPDFText_ClosePage(m_pTextPage);\r
1254                 m_pTextPage = NULL;\r
1255         }\r
1256         if (m_pLink != NULL)\r
1257         {\r
1258                 FPDFLink_CloseWebLinks(m_pLink);\r
1259                 m_pLink = NULL;\r
1260         }\r
1261 \r
1262         POSITION pos = m_pageMap.GetStartPosition();\r
1263         while(pos)\r
1264         {\r
1265                 int nIndex = 0;\r
1266                 FPDF_PAGE page = NULL;\r
1267                 m_pageMap.GetNextAssoc(pos, nIndex, page);\r
1268 \r
1269                 if (page)\r
1270                 {\r
1271                         FORM_OnBeforeClosePage(page, m_pApp);\r
1272                         FPDF_ClosePage(page);\r
1273                 }\r
1274         }\r
1275         m_pPage = NULL;\r
1276 \r
1277         if (m_pDoc != NULL)\r
1278         {\r
1279                 //Should strictly follow the reverse order of initialization .\r
1280                 FORM_DoDocumentAAction(m_pApp, FPDFDOC_AACTION_WC);\r
1281                 if(m_pApp)\r
1282                         FPDFDOC_ExitFormFillEnviroument(m_pApp);\r
1283                 FPDF_CloseDocument(m_pDoc);\r
1284                 m_pDoc = NULL;\r
1285         }\r
1286         if (m_FindInfo.m_pCurFindBuf != NULL)\r
1287         {\r
1288                 delete []m_FindInfo.m_pCurFindBuf;\r
1289                 m_FindInfo.m_pCurFindBuf = NULL;\r
1290         }\r
1291         if (m_rtFind != NULL)\r
1292         {\r
1293                 delete m_rtFind;\r
1294                 m_rtFind = NULL;\r
1295         }\r
1296         if(m_bmp != NULL)\r
1297         {\r
1298                 FPDFBitmap_Destroy(m_bmp);\r
1299         }\r
1300 \r
1301         if (m_pwsResponse)\r
1302         {\r
1303                 delete m_pwsResponse;\r
1304                 m_pwsResponse = NULL;\r
1305         }\r
1306 \r
1307         if(this->m_pJsPlatform)\r
1308                 delete m_pJsPlatform;\r
1309 \r
1310         m_mapTimerFuns.RemoveAll();\r
1311 //      m_formFiledInfo.Release();\r
1312 //      }\r
1313 //      m_rtArray.RemoveAll();\r
1314 }\r
1315 \r
1316 BOOL CReaderVCView::PreCreateWindow(CREATESTRUCT& cs)\r
1317 {\r
1318         // TODO: Modify the Window class or styles here by modifying\r
1319         //  the CREATESTRUCT cs\r
1320         cs.style |= WS_MAXIMIZE | WS_VISIBLE | WS_VSCROLL |WS_HSCROLL;\r
1321         return CView::PreCreateWindow(cs);\r
1322 }\r
1323 \r
1324 /////////////////////////////////////////////////////////////////////////////\r
1325 // CReaderVCView drawing\r
1326 \r
1327 void CReaderVCView::OnDraw(CDC* pDC)\r
1328 {\r
1329         CReaderVCDoc* pDoc = GetDocument();\r
1330         ASSERT_VALID(pDoc);\r
1331         // TODO: add draw code for native data here\r
1332         DrawPage(m_nRotateFlag, pDC);\r
1333         DrawAllRect(pDC);\r
1334 }\r
1335 \r
1336 /////////////////////////////////////////////////////////////////////////////\r
1337 // CReaderVCView printing\r
1338 \r
1339 BOOL CReaderVCView::OnPreparePrinting(CPrintInfo* pInfo)\r
1340 {\r
1341         // default preparation\r
1342         return DoPreparePrinting(pInfo);\r
1343 }\r
1344 \r
1345 void CReaderVCView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)\r
1346 {\r
1347         // TODO: add extra initialization before printing\r
1348 }\r
1349 \r
1350 void CReaderVCView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)\r
1351 {\r
1352         // TODO: add cleanup after printing\r
1353 }\r
1354 \r
1355 /////////////////////////////////////////////////////////////////////////////\r
1356 // CReaderVCView diagnostics\r
1357 \r
1358 #ifdef _DEBUG\r
1359 void CReaderVCView::AssertValid() const\r
1360 {\r
1361         CView::AssertValid();\r
1362 }\r
1363 \r
1364 void CReaderVCView::Dump(CDumpContext& dc) const\r
1365 {\r
1366         CView::Dump(dc);\r
1367 }\r
1368 \r
1369 CReaderVCDoc* CReaderVCView::GetDocument() // non-debug version is inline\r
1370 {\r
1371         ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CReaderVCDoc)));\r
1372         return (CReaderVCDoc*)m_pDocument;\r
1373 }\r
1374 #endif //_DEBUG\r
1375 \r
1376 /////////////////////////////////////////////////////////////////////////////\r
1377 // CReaderVCView message handlers\r
1378 \r
1379 BOOL CReaderVCView::LoadPDFPage(FPDF_DOCUMENT doc, int nIndex, CPoint pos)\r
1380 {\r
1381         if(NULL == doc) return FALSE;\r
1382         if(nIndex < 0) nIndex = 0;\r
1383         if(nIndex > m_nTotalPage) nIndex = m_nTotalPage;\r
1384 \r
1385         FORM_DoPageAAction(m_pPage, m_pApp, FPDFPAGE_AACTION_CLOSE);\r
1386 \r
1387         m_pPage = NULL;\r
1388         m_pageMap.Lookup(nIndex, m_pPage);\r
1389         if(!m_pPage)\r
1390         {\r
1391                 m_pPage = FPDF_LoadPage(doc, nIndex);\r
1392                 FORM_OnAfterLoadPage(m_pPage, m_pApp);\r
1393                 m_pageMap.SetAt(nIndex, m_pPage);       \r
1394         }\r
1395         if(NULL == m_pPage) return FALSE;\r
1396 \r
1397         FORM_DoPageAAction(m_pPage, m_pApp, FPDFPAGE_AACTION_OPEN);\r
1398 \r
1399         m_nPageIndex = nIndex;\r
1400     SetPageMetrics(m_pPage);\r
1401 \r
1402         if (m_pTextPage != NULL)\r
1403         {\r
1404                 FPDFText_ClosePage(m_pTextPage);\r
1405                 m_pTextPage = NULL;     \r
1406         }\r
1407         m_pTextPage = FPDFText_LoadPage(m_pPage);\r
1408 \r
1409 \r
1410         CChildFrame *pParent = (CChildFrame *)this->GetParentFrame();\r
1411         if (pParent != NULL)\r
1412         {\r
1413                 pParent->SetActiveView(this);\r
1414                 SyncScroll();   \r
1415         }\r
1416         \r
1417         if(pos.x !=0 && pos.y != 0)\r
1418         {\r
1419                 FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(m_nActualSizeX * m_dbScaleFactor),\r
1420                         (int)(m_nActualSizeY * m_dbScaleFactor), m_nRotateFlag, pos.x, pos.y, &m_nStartX, &m_nStartY);                  \r
1421                 m_nStartX = -m_nStartX + 20;\r
1422                 m_nStartY = -m_nStartY + 20;\r
1423                 \r
1424                 int nSizeX = 0; \r
1425                 int nSizeY = 0;\r
1426                 if (1 == m_nRotateFlag || 3 == m_nRotateFlag)\r
1427                 {\r
1428                         nSizeX = m_nActualSizeY;\r
1429                         nSizeY = m_nActualSizeX;\r
1430                 }\r
1431                 else\r
1432                 {\r
1433                         nSizeX = m_nActualSizeX;\r
1434                         nSizeY = m_nActualSizeY;\r
1435                 }\r
1436                 SCROLLINFO scrinfo;\r
1437                 GetScrollInfo(SB_VERT, &scrinfo);                                         \r
1438                 scrinfo.nMin = 0;                                                         \r
1439                 scrinfo.nMax =(int) (nSizeY * m_dbScaleFactor + abs(m_nStartY));                                             \r
1440                 SetScrollInfo(SB_VERT, &scrinfo);  \r
1441                 SetScrollPos(SB_VERT, abs(m_nStartY), TRUE);\r
1442 \r
1443                 GetScrollInfo(SB_HORZ, &scrinfo);                                         \r
1444                 scrinfo.nMin = 0;                                                         \r
1445                 scrinfo.nMax = (int)(nSizeX * m_dbScaleFactor + abs(m_nStartX));                                             \r
1446                 SetScrollInfo(SB_HORZ, &scrinfo);  \r
1447                 SetScrollPos(SB_HORZ, abs(m_nStartX), TRUE);\r
1448         }\r
1449         this->Invalidate(TRUE);\r
1450 //      FPDFApp_SetPage(m_App, m_pPage);\r
1451         return TRUE;\r
1452 \r
1453 }\r
1454 \r
1455 \r
1456 void CReaderVCView::InvalidateImpl(FPDF_PAGE page, double left, double top, double right, double bottom)\r
1457 {\r
1458         int device_left, device_top, device_right, device_bottom;\r
1459 \r
1460         int nActualRangeX = 0;\r
1461         int nActualRangeY = 0;\r
1462         if ( m_nRotateFlag % 2 == 0 )\r
1463         {\r
1464                 nActualRangeX = m_nActualSizeX;\r
1465                 nActualRangeY = m_nActualSizeY;\r
1466         }else{\r
1467                 nActualRangeX = m_nActualSizeY;\r
1468                 nActualRangeY = m_nActualSizeX;\r
1469         }\r
1470 \r
1471         FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
1472                 (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, left, top, &device_left, &device_top);\r
1473 \r
1474         FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
1475                 (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, right, bottom, &device_right, &device_bottom);\r
1476 \r
1477         CRect rc(device_left,device_top, device_right, device_bottom);\r
1478 //      TRACE("left = %d\r\n", device_left);\r
1479 //              TRACE("top = %d\r\n", device_top);\r
1480 //                      TRACE("right = %d\r\n", device_right);\r
1481 //                              TRACE("bottom = %d\r\n", device_bottom);\r
1482         if(device_right-device_left>5)\r
1483         TRACE("left=%d,top=%d,right=%d,bottom=%d\r\n",device_left,device_top,device_right,device_bottom);\r
1484         ::InvalidateRect(m_hWnd, rc, FALSE);\r
1485 }\r
1486 \r
1487 void CReaderVCView::SetCaretImpl(FPDF_PAGE page,double page_x, double page_y, int nWidth, int nHeight)\r
1488 {\r
1489 \r
1490 }\r
1491 \r
1492 void CReaderVCView::ReleaseImpl()\r
1493 {\r
1494 \r
1495 }\r
1496 CMap<int, int,TimerCallback, TimerCallback> CReaderVCView::m_mapTimerFuns;\r
1497 int CReaderVCView::SetTimerImpl(int uElapse, TimerCallback lpTimerFunc)\r
1498 {\r
1499         int nTimeID =  ::SetTimer(NULL, 0, uElapse, TimerProc); \r
1500         m_mapTimerFuns.SetAt(nTimeID, lpTimerFunc);\r
1501         return nTimeID;\r
1502 }\r
1503 \r
1504 void CReaderVCView::KillTimerImpl(int nID)\r
1505 {\r
1506         ::KillTimer(NULL, nID);\r
1507         m_mapTimerFuns.RemoveKey(nID);\r
1508 }\r
1509 \r
1510 void CReaderVCView::SetCurorImpl(int nCursorType)\r
1511 {\r
1512         HCURSOR hcur = LoadCursor(NULL, IDC_UPARROW);\r
1513         switch(nCursorType)\r
1514         {\r
1515                 case    FXCT_ARROW:\r
1516                 case    FXCT_NESW:              \r
1517                 case    FXCT_NWSE:              \r
1518                 case    FXCT_VBEAM:             \r
1519                 case    FXCT_HBEAM:             \r
1520                 case    FXCT_HAND:\r
1521                 //      ::SetCursor(hcur);\r
1522                 break;\r
1523         }\r
1524 }\r
1525 \r
1526 void CReaderVCView::PageToDeviceImpl(FPDF_PAGE page,double page_x,double page_y, int* device_x, int* device_y)\r
1527 {\r
1528         int nActualRangeX = 0;\r
1529         int nActualRangeY = 0;\r
1530         if ( m_nRotateFlag % 2 == 0 )\r
1531         {\r
1532                 nActualRangeX = m_nActualSizeX;\r
1533                 nActualRangeY = m_nActualSizeY;\r
1534         }else{\r
1535                 nActualRangeX = m_nActualSizeY;\r
1536                 nActualRangeY = m_nActualSizeX;\r
1537         }\r
1538         FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
1539                                 (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, page_x, page_y,device_x, device_y);\r
1540 }\r
1541 \r
1542 void CReaderVCView::DeviceToPageImpl(FPDF_PAGE page,int device_x, int device_y, double* page_x, double* page_y)\r
1543 {\r
1544         int nActualRangeX = 0;\r
1545         int nActualRangeY = 0;\r
1546         if ( m_nRotateFlag % 2 == 0 )\r
1547         {\r
1548                 nActualRangeX = m_nActualSizeX;\r
1549                 nActualRangeY = m_nActualSizeY;\r
1550         }else{\r
1551                 nActualRangeX = m_nActualSizeY;\r
1552                 nActualRangeY = m_nActualSizeX;\r
1553         }\r
1554         FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
1555                 (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, device_x, device_y, page_x, page_y);\r
1556 \r
1557 }\r
1558 \r
1559 void CReaderVCView::SetPageMetrics(FPDF_PAGE pPage)\r
1560 {\r
1561         m_nStartX = 10;\r
1562         m_nStartY = 10;\r
1563         if(NULL==pPage) return;\r
1564         //get pdf page width an height;\r
1565         m_dbPageWidth = FPDF_GetPageWidth(pPage);\r
1566         m_dbPageHeight = FPDF_GetPageHeight(pPage);\r
1567 \r
1568         CDC *pDC = GetDC();\r
1569         int ix, iy;\r
1570         ix = pDC->GetDeviceCaps(LOGPIXELSX);\r
1571         iy = pDC->GetDeviceCaps(LOGPIXELSY);\r
1572         m_nActualSizeX = (int)(m_dbPageWidth / 72 * ix + 0.5f);//convert pdf coordinates to device\r
1573         m_nActualSizeY = (int)(m_dbPageHeight / 72 * iy + 0.5f);//convert pdf coordinates to device\r
1574         ReleaseDC(pDC);\r
1575 \r
1576 }\r
1577 \r
1578 void CReaderVCView::SetScalFactor(double dbScal)\r
1579 {\r
1580         if(dbScal > 64 ) m_dbScaleFactor = 64;\r
1581         if( dbScal < 0) m_dbScaleFactor = 0.08f;\r
1582         m_dbScaleFactor = dbScal;\r
1583 }\r
1584 void CReaderVCView::DrawPage(int nRotate, CDC *pDC)\r
1585 {\r
1586         int nSizeX = m_nActualSizeX;\r
1587         int nSizeY = m_nActualSizeY;\r
1588 \r
1589         if (1 == nRotate || 3 == nRotate)\r
1590         {\r
1591                 int temp = nSizeX;\r
1592                 nSizeX = nSizeY;\r
1593                 nSizeY = temp;\r
1594         }\r
1595         \r
1596         int nShowSizeX = (int)(nSizeX * m_dbScaleFactor + m_nStartX);\r
1597         int nShowSizeY = (int)(nSizeY * m_dbScaleFactor + m_nStartY);\r
1598         \r
1599 \r
1600         CRect rc; \r
1601         pDC->GetClipBox(&rc);\r
1602                 FPDF_BITMAP bmptemp = FPDFBitmap_Create(rc.Width(), rc.Height(), 0);\r
1603                 int nClientWidth = FPDFBitmap_GetWidth(bmptemp);\r
1604                 int nClientHeight = FPDFBitmap_GetHeight(bmptemp);\r
1605                 \r
1606                 \r
1607                 FPDFBitmap_FillRect(bmptemp, 0, 0, nClientWidth, nClientHeight, 255,255,255, 0);\r
1608                 FPDF_RenderPageBitmap(bmptemp, m_pPage, m_nStartX-rc.left, m_nStartY-rc.top, (int)(nSizeX * m_dbScaleFactor), (int)(nSizeY * m_dbScaleFactor), nRotate, \r
1609                         FPDF_LCD_TEXT | FPDF_NO_NATIVETEXT);\r
1610                 FPDF_FFLDraw(m_pApp, bmptemp, m_pPage, m_nStartX-rc.left, m_nStartY-rc.top, (int)(nSizeX * m_dbScaleFactor), (int)(nSizeY * m_dbScaleFactor), nRotate, \r
1611                         FPDF_ANNOT | FPDF_LCD_TEXT | FPDF_NO_NATIVETEXT);\r
1612                 \r
1613                 //      m_pPage2 = FPDF_LoadPage(m_pDoc, 2);\r
1614                 //      FPDF_RenderPageBitmap(m_bmp, m_pPage2, m_nStartX+500, m_nStartY, (int)(nSizeX * m_dbScaleFactor), (int)(nSizeY * m_dbScaleFactor), nRotate, \r
1615                 //              FPDF_LCD_TEXT | FPDF_NO_NATIVETEXT);\r
1616                 //      FPDF_FFLDraw(m_pApp, m_bmp, m_pPage2, m_nStartX+500, m_nStartY, (int)(nSizeX * m_dbScaleFactor), (int)(nSizeY * m_dbScaleFactor), nRotate, \r
1617                 //              FPDF_ANNOT | FPDF_LCD_TEXT | FPDF_NO_NATIVETEXT);\r
1618                 \r
1619                 int t = FPDFBitmap_GetStride(bmptemp);\r
1620                 int bufsize=FPDFBitmap_GetStride(bmptemp)*nClientHeight;\r
1621                 void* bmpbuf=FPDFBitmap_GetBuffer(bmptemp);\r
1622                 CDC MemDC;\r
1623                 \r
1624                 CBitmap winbmp;\r
1625                 MemDC.CreateCompatibleDC(pDC);\r
1626                 if((HBITMAP)winbmp != NULL)\r
1627                         winbmp.DeleteObject();\r
1628                 if(HBITMAP(winbmp) == NULL)\r
1629                 {\r
1630                         winbmp.CreateCompatibleBitmap(pDC,nClientWidth,nClientHeight);\r
1631                         winbmp.SetBitmapBits(bufsize,bmpbuf);\r
1632                 }\r
1633                 \r
1634                 MemDC.SelectObject(&winbmp); \r
1635                 \r
1636                 pDC->BitBlt(rc.left , rc.top , nClientWidth, nClientHeight, &MemDC,0,0,SRCCOPY);\r
1637                 MemDC.DeleteDC();    \r
1638                 \r
1639                 FPDFBitmap_Destroy(bmptemp);\r
1640         \r
1641         \r
1642         int size = m_SelectArray.GetSize();\r
1643         for(int i=0; i<size; i++)\r
1644         {\r
1645                 \r
1646                 \r
1647                 CRect rc = m_SelectArray.GetAt(i);\r
1648                 \r
1649                 CDC memdc;\r
1650                 CBitmap bmp,*pOldBitmap; \r
1651                 memdc.CreateCompatibleDC(pDC); \r
1652                 \r
1653                 bmp.CreateCompatibleBitmap(pDC,rc.Width(),rc.Height());\r
1654                 \r
1655                 pOldBitmap = memdc.SelectObject(&bmp);\r
1656                 \r
1657                 memdc.FillSolidRect(0,0,rc.Width(),rc.Height(),RGB(0,100,160));\r
1658                 \r
1659                 BLENDFUNCTION bf; \r
1660                 \r
1661                 bf.BlendOp = AC_SRC_OVER; \r
1662                 \r
1663                 bf.BlendFlags = 0; \r
1664                 \r
1665                 bf.SourceConstantAlpha = 0x4f; \r
1666                 \r
1667                 bf.AlphaFormat = 0;\r
1668                 \r
1669 \r
1670                 \r
1671                 BOOL ret=AlphaBlend(pDC->GetSafeHdc(),rc.left,rc.top,rc.Width(),rc.Height(),memdc.GetSafeHdc(),0,0,rc.Width(),rc.Height(),bf);\r
1672                 \r
1673                 memdc.SelectObject(pOldBitmap);\r
1674                 memdc.DeleteDC();\r
1675                 bmp.DeleteObject();\r
1676                 \r
1677         }\r
1678         m_SelectArray.RemoveAll();\r
1679 \r
1680 \r
1681 \r
1682 \r
1683 }\r
1684 \r
1685 void CReaderVCView::GetNewPageSize(int &nsizeX, int &nsizeY)\r
1686 {\r
1687         int nSizeX = m_nActualSizeX;\r
1688         int nSizeY = m_nActualSizeY;\r
1689         if (1 == m_nRotateFlag || 3 == m_nRotateFlag)\r
1690         {\r
1691                 int temp = nSizeX;\r
1692                 nSizeX = nSizeY;\r
1693                 nSizeY = temp;\r
1694         }\r
1695          nsizeX = (int)(nSizeX*m_dbScaleFactor);\r
1696          nsizeY = (int)(nSizeY*m_dbScaleFactor);\r
1697 }\r
1698 \r
1699 void CReaderVCView::OnDocFirstpage() \r
1700 {\r
1701 \r
1702         if(m_nPageIndex == 0) return;\r
1703         this->m_nPageIndex = 0;\r
1704         this->LoadPDFPage(m_pDoc, 0);\r
1705         DeleteAllRect();\r
1706 }\r
1707 \r
1708 void CReaderVCView::OnDocGotopage() \r
1709 {\r
1710         CGotoPageDlg dlg;\r
1711         dlg.DoModal();  \r
1712 }\r
1713 \r
1714 void CReaderVCView::OnDocLastpage() \r
1715 {\r
1716 //      FPDF_DOCUMENT doc = FPDF_LoadDocument("d:\\a1.pdf", "");\r
1717 //     FPDF_PAGE page = FPDF_LoadPage(doc, 0);\r
1718 //      FPDF_IMAGEOBJECT imgObject = FPDFPageObj_NewImgeObj(doc);\r
1719 //       long ret = FPDFImageObj_LoadFromFileEx(&page, 1 ,\r
1720 //                                                               imgObject, "E:\\temp\\temp\\k.gif",TRUE\r
1721 //                                                               );\r
1722 //       FPDFImageObj_SetMatrix(imgObject, 240, 0, 0, 160, 1*50, 0 );\r
1723 //       FPDFPage_InsertObject(page, imgObject);\r
1724 //       FPDFPage_GenerateContent(page);\r
1725 //       FPDF_SaveAsFile(doc, "D:\\out.pdf", 0, NULL, 0, NULL, 0);\r
1726 //       FPDF_ClosePage(page);\r
1727 //       FPDF_CloseDocument(doc);\r
1728 //      return;\r
1729 \r
1730 \r
1731         if(m_nPageIndex == m_nTotalPage -1) return;\r
1732         this->m_nPageIndex = m_nTotalPage -1;\r
1733         LoadPDFPage(m_pDoc, m_nPageIndex);\r
1734         DeleteAllRect();\r
1735 }\r
1736 \r
1737 void CReaderVCView::OnDocNextpage() \r
1738 {\r
1739         m_nPageIndex ++ ;\r
1740         m_nPageIndex %= m_nTotalPage;\r
1741         LoadPDFPage(m_pDoc, m_nPageIndex);\r
1742         DeleteAllRect();\r
1743 }\r
1744 \r
1745 void CReaderVCView::OnDocPrepage() \r
1746 {\r
1747         m_nPageIndex --;\r
1748         if(m_nPageIndex < 0) m_nPageIndex = m_nTotalPage-1;\r
1749         LoadPDFPage(m_pDoc, m_nPageIndex);\r
1750         DeleteAllRect();\r
1751 }\r
1752 \r
1753 void CReaderVCView::OnClockwise() \r
1754 {\r
1755         m_nRotateFlag ++;\r
1756         m_nRotateFlag %= 4;\r
1757         LoadPDFPage(m_pDoc, m_nPageIndex);\r
1758 }\r
1759 \r
1760 void CReaderVCView::OnCounterclockwise() \r
1761 {\r
1762         m_nRotateFlag --;\r
1763         if (m_nRotateFlag < 0) m_nRotateFlag = 3;\r
1764         LoadPDFPage(m_pDoc, m_nPageIndex);\r
1765 }\r
1766 \r
1767 BOOL CReaderVCView::SetPDFDocument(FPDF_DOCUMENT pDoc, int nPageNum)\r
1768 {\r
1769         if(pDoc == NULL) return FALSE;\r
1770 \r
1771         m_pApp = FPDFDOC_InitFormFillEnviroument(pDoc,this);\r
1772         FPDF_LoadXFA(pDoc);\r
1773 \r
1774         FORM_DoDocumentJSAction(m_pApp);\r
1775         FORM_DoDocumentOpenAction(m_pApp);\r
1776 //      FORM_OnAfterLoadDocument(m_pApp);\r
1777         FPDF_SetFormFieldHighlightColor(m_pApp, 0, RGB(0,255, 0));\r
1778         FPDF_SetFormFieldHighlightAlpha(m_pApp, 128);\r
1779 \r
1780         \r
1781         m_pDoc = pDoc;\r
1782         m_nTotalPage = nPageNum;\r
1783         if(!LoadPDFPage(m_pDoc, 0)) return FALSE;\r
1784 \r
1785         return TRUE;\r
1786 }\r
1787 \r
1788 void CReaderVCView::GotoPage(int index)\r
1789 {\r
1790         if(index < 0 || index >= m_nTotalPage){MessageBoxA("Invalidate index");}\r
1791         if(index == m_nPageIndex) return;\r
1792         if(!LoadPDFPage(m_pDoc, index)) return;\r
1793         DeleteAllRect();\r
1794 }\r
1795 \r
1796 void CReaderVCView::OnViewActualSize() \r
1797 {\r
1798         m_nStartX = m_nStartY = 10;\r
1799         ScalPage(1.0f);\r
1800 }\r
1801 \r
1802 void CReaderVCView::OnViewFitPage() \r
1803 {\r
1804         m_nStartX = m_nStartY = 10;\r
1805         CRect rect;\r
1806         GetClientRect(rect);\r
1807         double dbHeight = rect.Height();        \r
1808         double dbScal = dbHeight / m_nActualSizeY;\r
1809         ScalPage(dbScal);\r
1810 }\r
1811 \r
1812 void CReaderVCView::OnViewFitWidth() \r
1813 {\r
1814         m_nStartX = m_nStartY = 10;\r
1815         CRect rect;\r
1816         GetClientRect(rect);\r
1817         double dbWidth= rect.Width();\r
1818         double dbScal = dbWidth / m_nActualSizeX;\r
1819         ScalPage(dbScal);\r
1820 }\r
1821 \r
1822 void CReaderVCView::OnViewZoomIn() \r
1823 {\r
1824         double dbScal = m_dbScaleFactor;\r
1825         dbScal += 0.25f;\r
1826         if(dbScal > 6400.0f) return;\r
1827         ScalPage(dbScal);\r
1828         \r
1829 }\r
1830 \r
1831 void CReaderVCView::OnViewZoomOut() \r
1832 {\r
1833         double dbScal = m_dbScaleFactor;\r
1834         dbScal -= 0.25f;\r
1835         if(dbScal < 0.25f) return;\r
1836         ScalPage(dbScal);\r
1837 }\r
1838 \r
1839 void CReaderVCView::OnViewZoomTo() \r
1840 {\r
1841         CZoomDlg dlg;\r
1842         dlg.DoModal();\r
1843 }\r
1844 \r
1845 void CReaderVCView::ScalPage(double dbScal)\r
1846 {\r
1847         SetScalFactor(dbScal);\r
1848         CChildFrame *pParent = (CChildFrame *)this->GetParentFrame();\r
1849         if (pParent != NULL)\r
1850         {\r
1851                 pParent->SetActiveView(this);\r
1852                 SyncScroll();   \r
1853         }\r
1854         Invalidate(TRUE);\r
1855 }\r
1856 \r
1857 void CReaderVCView::OnEditFind() \r
1858 {\r
1859         if(m_pTextPage == NULL)\r
1860         {\r
1861                 AfxMessageBox("Sorry, the fpdftext.dll may has expired. For keeping on using the dll, please contact sales@foxitsoftware.com.");\r
1862                 return;\r
1863         }\r
1864         CFindDlg dlg;\r
1865         dlg.DoModal();  \r
1866 }\r
1867 \r
1868 void CReaderVCView::FindText(CString strFind, BOOL bCase, BOOL bWholeword, int Direction)\r
1869 {\r
1870         CString str;\r
1871         str = m_FindInfo.m_strFind;\r
1872         int nFlag = 0;\r
1873         if(bCase) { nFlag |= FPDF_MATCHCASE; }\r
1874         if(bWholeword) { nFlag |= FPDF_MATCHWHOLEWORD; }\r
1875 \r
1876         if(NULL == m_pTextPage) return;\r
1877 \r
1878         if (strFind.Compare(str) != 0 || nFlag != m_FindInfo.m_nFlag)//new search\r
1879         {\r
1880                 if (NULL == m_pTextPage) return;\r
1881                 if (NULL != m_pSCHHandle)\r
1882                 {\r
1883                         FPDFText_FindClose(m_pSCHHandle);\r
1884                         m_pSCHHandle  = NULL;\r
1885                 }\r
1886 \r
1887                 int len = MultiByteToWideChar(CP_ACP, 0, strFind.GetBuffer(0), -1, NULL, NULL);\r
1888                 wchar_t *pBuf = new wchar_t[len];\r
1889                 memset(pBuf, 0, len*sizeof(wchar_t));\r
1890                 MultiByteToWideChar(CP_ACP, 0, strFind.GetBuffer(0), strFind.GetLength(), pBuf, len);\r
1891                 pBuf[len-1] = L'\0';\r
1892                 m_pSCHHandle = FPDFText_FindStart(m_pTextPage, (FPDF_WIDESTRING)pBuf, nFlag, 0);\r
1893                 if(NULL == m_pSCHHandle) return;\r
1894                 \r
1895         if (m_FindInfo.m_pCurFindBuf != NULL)\r
1896                 {\r
1897                         delete []m_FindInfo.m_pCurFindBuf;\r
1898                         m_FindInfo.m_pCurFindBuf = NULL;\r
1899                 }\r
1900                 m_FindInfo.m_pCurFindBuf = new wchar_t[len];\r
1901                 memset(m_FindInfo.m_pCurFindBuf, 0, len*sizeof(wchar_t));\r
1902                 memcpy(m_FindInfo.m_pCurFindBuf, pBuf, len*sizeof(wchar_t));\r
1903 \r
1904                 delete []pBuf;\r
1905                 \r
1906 \r
1907                 //save the find info\r
1908                 m_FindInfo.m_strFind = strFind;\r
1909                 m_FindInfo.m_nFlag = nFlag;\r
1910                 m_FindInfo.m_nDirection = Direction;\r
1911                 m_FindInfo.m_nStartPageIndex = m_nPageIndex;\r
1912                 m_FindInfo.m_bFirst = TRUE;\r
1913                 \r
1914                 \r
1915         }\r
1916         FindNext(Direction);\r
1917 }\r
1918 \r
1919 void CReaderVCView::FindNext(int nDirection)\r
1920 {\r
1921         if(NULL == m_pSCHHandle) return;\r
1922         BOOL bResult = FALSE;\r
1923         \r
1924         if (nDirection != m_FindInfo.m_nDirection)\r
1925         {\r
1926                 m_FindInfo.m_nDirection = nDirection;\r
1927                 m_FindInfo.m_bFirst = TRUE;\r
1928         }\r
1929 \r
1930         if (0 == nDirection)// find down\r
1931         {\r
1932                 bResult = FPDFText_FindNext(m_pSCHHandle);\r
1933         }\r
1934         if (1 == nDirection)\r
1935         {\r
1936                 bResult = FPDFText_FindPrev(m_pSCHHandle);\r
1937         }\r
1938         \r
1939         while(!bResult){\r
1940 \r
1941                         if (m_rtFind != NULL)\r
1942                         {\r
1943                                 delete [] m_rtFind;\r
1944                                 m_rtFind = NULL;\r
1945                         }\r
1946 \r
1947                         if (0 == nDirection)\r
1948                         {\r
1949                                 m_nPageIndex ++;\r
1950                                 m_nPageIndex %= m_nTotalPage;\r
1951                                 if(!LoadPDFPage(m_pDoc, m_nPageIndex)) return;\r
1952                                 if (NULL == m_pTextPage) return;\r
1953                                 if (NULL != m_pSCHHandle)\r
1954                                 {\r
1955                                         FPDFText_FindClose(m_pSCHHandle);\r
1956                                         m_pSCHHandle  = NULL;\r
1957                                 }\r
1958                                 m_pSCHHandle = FPDFText_FindStart(m_pTextPage, (FPDF_WIDESTRING)m_FindInfo.m_pCurFindBuf, m_FindInfo.m_nFlag, 0);\r
1959                                 if(NULL == m_pSCHHandle) break;\r
1960                                 bResult = FPDFText_FindNext(m_pSCHHandle);\r
1961                                 if(!bResult && m_nPageIndex == m_FindInfo.m_nStartPageIndex) break;\r
1962                         } \r
1963                         else\r
1964                         {\r
1965                                 m_nPageIndex --;\r
1966                                 if (m_nPageIndex < 0) {m_nPageIndex = m_nTotalPage - 1;}\r
1967                                 if(!LoadPDFPage(m_pDoc, m_nPageIndex)) return;\r
1968                                 if (NULL == m_pTextPage) return;\r
1969                                 if (NULL != m_pSCHHandle)\r
1970                                 {\r
1971                                         FPDFText_FindClose(m_pSCHHandle);\r
1972                                         m_pSCHHandle  = NULL;\r
1973                                 }\r
1974                                 m_pSCHHandle = FPDFText_FindStart(m_pTextPage, (FPDF_WIDESTRING)m_FindInfo.m_pCurFindBuf, m_FindInfo.m_nFlag, 0);\r
1975                                 if(NULL == m_pSCHHandle) break;\r
1976                                 bResult = FPDFText_FindPrev(m_pSCHHandle);\r
1977                                 if(!bResult && m_nPageIndex == m_FindInfo.m_nStartPageIndex) break;\r
1978                         }\r
1979         }//end while\r
1980         \r
1981         if(!bResult)//find over\r
1982         {\r
1983                 FPDFText_FindClose(m_pSCHHandle);\r
1984                 m_pSCHHandle = NULL;\r
1985 \r
1986                 if (m_rtFind != NULL)\r
1987                 {\r
1988                         delete [] m_rtFind;\r
1989                         m_rtFind = NULL;\r
1990                 }\r
1991                 \r
1992                 m_FindInfo.m_bFirst = TRUE;\r
1993                 m_FindInfo.m_nDirection = -1;\r
1994                 m_FindInfo.m_nFlag = -1;\r
1995                 m_FindInfo.m_nStartCharIndex = -1;\r
1996                 m_FindInfo.m_nStartPageIndex = -1;\r
1997                 m_FindInfo.m_pCurFindBuf = NULL;\r
1998                 m_FindInfo.m_strFind = _T("");\r
1999 \r
2000                 MessageBox("Find complete!", "Find Infomation", MB_OK | MB_ICONINFORMATION);\r
2001                 return;\r
2002         }\r
2003         \r
2004         \r
2005         \r
2006         int index = FPDFText_GetSchResultIndex(m_pSCHHandle);\r
2007         if (m_nPageIndex == m_FindInfo.m_nStartPageIndex && index == m_FindInfo.m_nStartCharIndex && !m_FindInfo.m_bFirst )\r
2008         {\r
2009                 if (NULL != m_pSCHHandle)\r
2010                 {\r
2011                         FPDFText_FindClose(m_pSCHHandle);\r
2012                         m_pSCHHandle  = NULL;\r
2013                 }\r
2014                 MessageBox("Find complete!", "Find Infomation", MB_OK | MB_ICONINFORMATION);\r
2015                 return;\r
2016         }else{\r
2017                 CDC *pDC = GetDC();\r
2018                 DrawAllRect(pDC);//update\r
2019 \r
2020                 int nCount = FPDFText_GetSchCount(m_pSCHHandle);\r
2021                 int nRects = FPDFText_CountRects(m_pTextPage, index, nCount);\r
2022                 if (m_rtFind != NULL)\r
2023                 {\r
2024                         delete [] m_rtFind;\r
2025                         m_rtFind = NULL;\r
2026                 }\r
2027                 m_rtFind = new PDFRect[nRects];\r
2028                 m_nRectNum = nRects;\r
2029                 for (int i=0; i<nRects; i++)\r
2030                 {       \r
2031                         double left, top, right, bottom;        \r
2032                         FPDFText_GetRect(m_pTextPage, i, &left, &top, &right, &bottom);\r
2033                         m_rtFind[i].m_dbLeft = left;\r
2034                         m_rtFind[i].m_dbTop = top;\r
2035                         m_rtFind[i].m_dbRight = right;\r
2036                         m_rtFind[i].m_dbBottom = bottom;\r
2037                 }\r
2038                 DrawAllRect(pDC);//draw new rect\r
2039                 ReleaseDC(pDC);\r
2040         }\r
2041 \r
2042         if (m_FindInfo.m_bFirst)\r
2043         {//find first string, store info;\r
2044                 m_FindInfo.m_bFirst = FALSE;\r
2045                 m_FindInfo.m_nStartCharIndex = index;\r
2046                 m_FindInfo.m_nStartPageIndex = m_nPageIndex; \r
2047         }\r
2048         \r
2049 }\r
2050 \r
2051 void CReaderVCView::DrawReverse(CDC *pDC, CRect rect)\r
2052 {\r
2053         CRect rt = rect;\r
2054         rect.left = __min(rt.left, rt.right);\r
2055         rect.right = __max(rt.left, rt.right);\r
2056         rect.top = __min(rt.top, rt.bottom);\r
2057         rect.bottom = __max(rt.top, rt.bottom);\r
2058 \r
2059         ASSERT(pDC);\r
2060         int bmp_width=abs(rect.Width());\r
2061         int bmp_height=abs(rect.Height());      \r
2062         HBITMAP hbmp = CreateCompatibleBitmap(pDC->m_hDC, bmp_width, bmp_height);\r
2063         CDC MemDC;\r
2064         MemDC.CreateCompatibleDC(pDC);\r
2065         HBITMAP holdbmp  = (HBITMAP)MemDC.SelectObject(hbmp);\r
2066         // copy screen DC to memory DC\r
2067         BitBlt(MemDC, 0, 0, bmp_width, bmp_height,      pDC->m_hDC, rect.left,rect.top, SRCCOPY);\r
2068         MemDC.SelectObject(holdbmp);\r
2069         \r
2070         BITMAPINFO bmi;\r
2071         memset(&bmi, 0, sizeof bmi);\r
2072         bmi.bmiHeader.biSize = sizeof bmi.bmiHeader;\r
2073         bmi.bmiHeader.biBitCount = 24;\r
2074         bmi.bmiHeader.biClrImportant = 0;\r
2075         bmi.bmiHeader.biClrUsed = 0;\r
2076         bmi.bmiHeader.biCompression = BI_RGB;\r
2077         bmi.bmiHeader.biHeight = bmp_height;\r
2078         bmi.bmiHeader.biPlanes = 1;\r
2079         bmi.bmiHeader.biSizeImage = 0;\r
2080         bmi.bmiHeader.biWidth = bmp_width;\r
2081         bmi.bmiHeader.biXPelsPerMeter = 0;\r
2082         bmi.bmiHeader.biYPelsPerMeter = 0;\r
2083         \r
2084         // get bitmap stream\r
2085         int ret = GetDIBits(MemDC, hbmp, 0,bmp_height, NULL, &bmi, DIB_RGB_COLORS);\r
2086         \r
2087         int size = bmi.bmiHeader.biSizeImage;\r
2088         \r
2089         BYTE* pBits = new BYTE[size];\r
2090         memset(pBits, 0, size);\r
2091         ret = GetDIBits(MemDC, hbmp, 0,bmp_height, pBits, &bmi, DIB_RGB_COLORS);\r
2092         ret = GetLastError();\r
2093         DeleteObject(hbmp);\r
2094         MemDC.DeleteDC();\r
2095         for (int row = 0; row < bmp_height; row ++) {\r
2096                 int pitch = (bmp_width * 3 + 3) / 4 * 4;\r
2097                 int rowpos = row * pitch;\r
2098                 for(int col = 0; col < bmp_width; col ++){\r
2099                         int i = rowpos + col * 3;       \r
2100                         pBits[i]                = 255-pBits[i] ;                \r
2101                         pBits[i + 1]    = 255-pBits[i + 1];\r
2102                         pBits[i + 2]    = 255-pBits[i + 2];     \r
2103                 }\r
2104         }\r
2105         ret = SetDIBitsToDevice(pDC->m_hDC,rect.left,rect.top,bmp_width, bmp_height,0, 0, 0, bmp_height, pBits, &bmi, DIB_RGB_COLORS);\r
2106         delete []pBits; \r
2107 \r
2108 }\r
2109 \r
2110 void CReaderVCView::DrawAllRect(CDC *pDC)\r
2111 {\r
2112         int i;\r
2113         int left, top, right, bottom;\r
2114 \r
2115         int nSizeX = 0; \r
2116         int nSizeY = 0;\r
2117 //      int temp = 0;   \r
2118         if (1 == m_nRotateFlag || 3 == m_nRotateFlag)\r
2119         {\r
2120                 nSizeX = m_nActualSizeY;\r
2121                 nSizeY = m_nActualSizeX;\r
2122         }\r
2123         else\r
2124         {\r
2125                 nSizeX = m_nActualSizeX;\r
2126                 nSizeY = m_nActualSizeY;\r
2127         }\r
2128         ASSERT(pDC);\r
2129         if (m_rtFind != NULL)\r
2130         {\r
2131                 for (i=0; i<m_nRectNum; i++)\r
2132                 {\r
2133                         \r
2134                         PDFRect rect = m_rtFind[i];\r
2135                         FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nSizeX * m_dbScaleFactor),\r
2136                                 (int)(nSizeY * m_dbScaleFactor), m_nRotateFlag, rect.m_dbLeft, rect.m_dbTop, &left, &top);\r
2137                         FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nSizeX * m_dbScaleFactor),\r
2138                                 (int)(nSizeY * m_dbScaleFactor), m_nRotateFlag, rect.m_dbRight, rect.m_dbBottom, &right, &bottom);\r
2139                         CRect rt(left, top, right, bottom);\r
2140                         DrawReverse(pDC, rt);\r
2141 \r
2142                 }\r
2143         }\r
2144 \r
2145         if (m_rtArray.GetSize() != 0)\r
2146         {\r
2147                 for (i=0; i<m_rtArray.GetSize(); i++)\r
2148                 {\r
2149                         PDFRect rect = m_rtArray.GetAt(i);\r
2150                         FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nSizeX * m_dbScaleFactor),\r
2151                                 (int)(nSizeY * m_dbScaleFactor), m_nRotateFlag, rect.m_dbLeft, rect.m_dbTop, &left, &top);\r
2152                         FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nSizeX * m_dbScaleFactor),\r
2153                                 (int)(nSizeY * m_dbScaleFactor), m_nRotateFlag, rect.m_dbRight, rect.m_dbBottom, &right, &bottom);\r
2154                         CRect rt(left, top, right, bottom);\r
2155                         DrawReverse(pDC, rt);\r
2156                 }\r
2157         }\r
2158 }\r
2159 \r
2160 void CReaderVCView::DeleteAllRect()\r
2161 {\r
2162         CDC *pDC = GetDC();\r
2163         DrawAllRect(pDC);\r
2164         ReleaseDC(pDC);\r
2165 \r
2166         if (m_rtFind != NULL)\r
2167         {\r
2168                 delete []m_rtFind;\r
2169                 m_rtFind = NULL;\r
2170         }\r
2171         \r
2172         if (m_rtArray.GetSize() != 0)\r
2173         {\r
2174                 m_rtArray.RemoveAll();\r
2175         }\r
2176 }\r
2177 \r
2178 void CReaderVCView::OnFilePrint() \r
2179 {\r
2180         CString strDoc = GetDocument()->GetTitle(); \r
2181         CPrintDialog dlg(FALSE, PD_PAGENUMS | PD_USEDEVMODECOPIES);\r
2182         dlg.m_pd.nMinPage = dlg.m_pd.nFromPage =1;\r
2183         dlg.m_pd.nMaxPage = dlg.m_pd.nToPage = m_nTotalPage;\r
2184         if (dlg.DoModal() == IDOK)\r
2185         {\r
2186                 int from_page, to_page;\r
2187                 if (dlg.PrintAll())              \r
2188                 {\r
2189                         from_page = dlg.m_pd.nMinPage;\r
2190                         to_page = dlg.m_pd.nMaxPage;\r
2191                 }\r
2192                 else if (dlg.PrintRange())       \r
2193                 {                                \r
2194                         from_page = dlg.GetFromPage();\r
2195                         to_page = dlg.GetToPage();\r
2196                 }\r
2197                 else if (dlg.PrintSelection())   \r
2198                 {\r
2199                         from_page = to_page = m_nPageIndex + 1;     \r
2200                 }\r
2201                 \r
2202                 HDC printDC;\r
2203                 DOCINFO docInfo;\r
2204 \r
2205                 printDC = dlg.CreatePrinterDC();\r
2206                 if(NULL == printDC) return;\r
2207                 docInfo.cbSize = sizeof(DOCINFO);\r
2208                 docInfo.fwType = 0;\r
2209                 docInfo.lpszDatatype = NULL;\r
2210                 docInfo.lpszOutput = NULL;\r
2211                 docInfo.lpszDocName = strDoc;\r
2212 \r
2213         if(StartDoc(printDC, &docInfo) <= 0) return;\r
2214                 //FPDF_DOCUMENT pDoc = NULL;\r
2215                 FPDF_PAGE pPage = NULL;\r
2216                 CString str;\r
2217                 for (int i=from_page-1; i<to_page; i++)\r
2218                 {\r
2219                         if(pPage != NULL)\r
2220                         {\r
2221                                 FPDF_ClosePage(pPage);\r
2222                                 pPage = NULL;\r
2223                         }\r
2224                         pPage = FPDF_LoadPage(m_pDoc, i);\r
2225                         double npagewidth = FPDF_GetPageWidth(m_pPage);\r
2226                         double npageheight = FPDF_GetPageHeight(m_pPage);\r
2227                         \r
2228                         int logpixelsx,logpixelsy;\r
2229                         //calculate the page size\r
2230                         logpixelsx = GetDeviceCaps(printDC,LOGPIXELSX);\r
2231                         logpixelsy = GetDeviceCaps(printDC,LOGPIXELSY);\r
2232                         int nsizeX = (int)(npagewidth / 72 *logpixelsx + 0.5f);\r
2233                         int nsizeY = (int)(npageheight / 72 *logpixelsy + 0.5f);\r
2234                         \r
2235                         if(StartPage(printDC) <= 0)\r
2236                         {       \r
2237                                 str.Format("one error occured when start the page %d", i);\r
2238                                 MessageBox(str);\r
2239                                 return;\r
2240                         }\r
2241 \r
2242                         //render to print device\r
2243                         FPDF_RenderPage(printDC, pPage, m_nStartX, m_nStartY, nsizeX, nsizeY, m_nRotateFlag, 0);\r
2244                         \r
2245                         if(EndPage(printDC) <= 0)\r
2246                         {\r
2247                                 str.Format("one error occured when close the page %d", i);\r
2248                                 MessageBox(str);\r
2249                                 return;\r
2250                         }\r
2251 \r
2252                 }//end for\r
2253                 EndDoc(printDC);\r
2254                 if(!DeleteDC(printDC))// delete printDC\r
2255                         MessageBox("can not delete the printer");\r
2256         }       \r
2257 }\r
2258 \r
2259 void CReaderVCView::OnLButtonDown(UINT nFlags, CPoint point) \r
2260 {\r
2261         // TODO: Add your message handler code here and/or call default\r
2262 \r
2263         double page_x = 0;\r
2264         double page_y = 0;\r
2265         DeviceToPage(point, page_x, page_y);\r
2266 \r
2267         if(m_pApp)\r
2268         {\r
2269                 FPDF_BOOL b=  FORM_OnLButtonDown(m_pApp, m_pPage,ComposeFlag(),page_x, page_y);\r
2270                 if(b)\r
2271                         return;\r
2272         }\r
2273         DeleteAllRect();\r
2274         LoadMyCursor(1);\r
2275         m_ptLBDown = point;\r
2276 \r
2277 \r
2278         if (m_bSelect)\r
2279         {\r
2280                 m_bHasChar = GetCharIndexByPoint(point, m_nStartIndex);\r
2281                 CreateCaret(point);\r
2282         }\r
2283         if (m_bHand)\r
2284         {       \r
2285                 m_nPosH = GetScrollPos(SB_HORZ);//SetScrollPos(SB_VERT, point.y, TRUE);\r
2286                 m_nPosV = GetScrollPos(SB_VERT);\r
2287         }\r
2288         CView::OnLButtonDown(nFlags, point);\r
2289 }\r
2290 \r
2291 void CReaderVCView::OnLButtonUp(UINT nFlags, CPoint point) \r
2292 {\r
2293 \r
2294         // TODO: Add your message handler code here and/or call default\r
2295         double page_x = 0;\r
2296         double page_y = 0;\r
2297         DeviceToPage(point, page_x, page_y);\r
2298 \r
2299         if(m_pApp)\r
2300         {\r
2301                 if(FORM_OnLButtonUp(m_pApp, m_pPage,ComposeFlag(), page_x, page_y))\r
2302                         return;\r
2303         }\r
2304         LoadMyCursor();\r
2305         m_ptLBUp = point;\r
2306         if (m_bSelect || m_bSnap)\r
2307         {\r
2308                 CDC *pDC  = GetDC();\r
2309                 CPen *pOldPen;\r
2310                 CPen pen;\r
2311                 CBrush *pOldBr;\r
2312                 CRect rect;\r
2313                 pen.CreatePen(PS_DASH, 2, RGB(255,0,0));\r
2314                 pOldPen = pDC->SelectObject(&pen);\r
2315                 pOldBr = (CBrush*) (pDC->SelectStockObject(NULL_BRUSH));\r
2316                 int nOldRop = pDC->SetROP2(R2_XORPEN);\r
2317                 pDC->Rectangle(m_rtOld);\r
2318                 pDC->SetROP2(nOldRop);\r
2319                 m_rtOld.left = m_rtOld.top = m_rtOld.right = m_rtOld.bottom = 0;\r
2320                 ReleaseDC(pDC);\r
2321         }\r
2322         \r
2323         if (m_bSnap)\r
2324         {       \r
2325                 BOOL open = OpenClipboard();\r
2326                 if (open)\r
2327                 {\r
2328                         ::EmptyClipboard();\r
2329                         int bmpWidth = abs(point.x - m_ptLBDown.x);\r
2330                         int bmpHeight = abs(point.y - m_ptLBDown.y);\r
2331                         if (bmpHeight == 0 || bmpWidth == 0)return;\r
2332                         CRect bmpRect(m_ptLBDown, point);\r
2333                         CClientDC dc(this);\r
2334                         CBitmap *pBitmap = new CBitmap();\r
2335                         pBitmap->CreateCompatibleBitmap(&dc,bmpWidth,bmpHeight);\r
2336                         CDC memDC;\r
2337                         memDC.CreateCompatibleDC(&dc);\r
2338                         memDC.SelectObject(pBitmap);\r
2339                         CBrush whiteBrush(RGB(255,255,255));\r
2340                         //memDC.FillRect(bmpRect,&whiteBrush);\r
2341                         memDC.BitBlt(0, 0, bmpRect.Width(), bmpRect.Height(),&dc, bmpRect.left, bmpRect.top,SRCCOPY);\r
2342                         HBITMAP hBitmap = (HBITMAP) *pBitmap;\r
2343                         :: SetClipboardData(CF_BITMAP, hBitmap);\r
2344                         ::CloseClipboard();\r
2345                         MessageBox("The selected area has been copied to clipboard!");\r
2346                         delete pBitmap;\r
2347                 }\r
2348         }\r
2349         \r
2350         FPDF_LINK hlink=NULL;\r
2351         double pdfx,pdfy;\r
2352 \r
2353         int nActualRangeX = 0;\r
2354         int nActualRangeY = 0;\r
2355         if ( m_nRotateFlag % 2 == 0 )\r
2356         {\r
2357                 nActualRangeX = m_nActualSizeX;\r
2358                 nActualRangeY = m_nActualSizeY;\r
2359         }else{\r
2360                 nActualRangeX = m_nActualSizeY;\r
2361                 nActualRangeY = m_nActualSizeX;\r
2362         }\r
2363 \r
2364         FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
2365                 (int)(nActualRangeY * m_dbScaleFactor),m_nRotateFlag,point.x,point.y,&pdfx,&pdfy);\r
2366         hlink=FPDFLink_GetLinkAtPoint(m_pPage,pdfx,pdfy);\r
2367         if (hlink)\r
2368         {\r
2369                 FPDF_ACTION haction=NULL;\r
2370                 FPDF_DEST hLinkDest=NULL;\r
2371                 haction=FPDFLink_GetAction(hlink);\r
2372                 hLinkDest=FPDFLink_GetDest(m_pDoc,hlink);\r
2373                 if (haction)\r
2374                 {\r
2375                         int nActionType=FPDFAction_GetType(haction);\r
2376                         switch(nActionType)\r
2377                         {\r
2378                         case PDFACTION_UNSUPPORTED: // Unsupported action type\r
2379                                 break;\r
2380                         case PDFACTION_GOTO:            // Go to a destination within current document  \r
2381                                 {\r
2382                                         FPDF_LINK hActLinkDest =  FPDFAction_GetDest(m_pDoc,haction);\r
2383                                         if (hActLinkDest)\r
2384                                         {\r
2385                                                 int nPageIndex=FPDFDest_GetPageIndex(m_pDoc,hActLinkDest);\r
2386                                                 GotoPage(nPageIndex);\r
2387                                         }\r
2388                                 }\r
2389                                 break;\r
2390                         case PDFACTION_REMOTEGOTO:      // Go to a destination within another document\r
2391                                 \r
2392                                 //      FPDFAction_GetFilePath(...);\r
2393                                 //      .....   \r
2394                                 break;\r
2395                         case PDFACTION_URI:             // Universal Resource Identifier, including web pages and \r
2396                                 // other Internet based resources\r
2397                                 //      int nsize= FPDFAction_GetURIPath(m_pDoc,haction);\r
2398                                 //      ...\r
2399                                 break;\r
2400                         case PDFACTION_LAUNCH:                  // Launch an application or open a file\r
2401                                 //      FPDFAction_GetFilePath(...)\r
2402                                 break;\r
2403                         default :\r
2404                                 break;\r
2405                         }\r
2406                 }\r
2407                 else if (hLinkDest)\r
2408                 {\r
2409                         int nPageIndex=FPDFDest_GetPageIndex(m_pDoc,hLinkDest);\r
2410                         GotoPage(nPageIndex);\r
2411                 }\r
2412         }\r
2413         CView::OnLButtonUp(nFlags, point);\r
2414 }\r
2415 \r
2416 void CReaderVCView::OnMouseMove(UINT nFlags, CPoint point) \r
2417 {\r
2418         // TODO: Add your message handler code here and/or call default\r
2419         double page_x = 0;\r
2420         double page_y = 0;\r
2421         DeviceToPage(point, page_x, page_y);\r
2422 \r
2423         if(m_pApp)\r
2424         {\r
2425                 if(FORM_OnMouseMove(m_pApp, m_pPage,ComposeFlag(), page_x, page_y))\r
2426                         return;\r
2427         }\r
2428         if (nFlags == MK_LBUTTON)\r
2429         {\r
2430                 LoadMyCursor(1);\r
2431         }else{LoadMyCursor();}\r
2432         \r
2433         CDC *pDC = GetDC();\r
2434 \r
2435         if (m_bSelect && nFlags == MK_LBUTTON)\r
2436         {\r
2437                 if (m_bHasChar)\r
2438                 {\r
2439                         if (m_ptOld.x == 0 && m_ptOld.y == 0){m_ptOld = m_ptLBDown;}\r
2440         \r
2441                         int nIndex = 0;\r
2442                         if (!GetCharIndexByPoint(point, nIndex)) return;\r
2443                         if(nIndex == m_nEndIndex) return;\r
2444                         \r
2445                         DrawAllRect(pDC);//update all rect\r
2446                         \r
2447                         m_nEndIndex = nIndex;\r
2448                         GetRects(m_nStartIndex, m_nEndIndex);   //get the rect and store into m_rtArray\r
2449                         DrawAllRect(pDC);//draw new rect        \r
2450                 }\r
2451                 else \r
2452                 {\r
2453                         CPen *pOldPen;\r
2454                         CPen pen;\r
2455                         CBrush *pOldBr;\r
2456                         CRect rect;\r
2457                         pen.CreatePen(PS_DASH, 2, RGB(255,0,0));\r
2458                         pOldPen = pDC->SelectObject(&pen);\r
2459                         pOldBr = (CBrush*) (pDC->SelectStockObject(NULL_BRUSH));\r
2460                         int nOldRop = pDC->SetROP2(R2_XORPEN);\r
2461                         int nModle = pDC->Rectangle(m_rtOld);\r
2462                 \r
2463                         \r
2464                         DrawAllRect(pDC);//update all rect\r
2465                         rect = SelectSegment(m_ptLBDown, point);\r
2466                         DrawAllRect(pDC);\r
2467 \r
2468                         pDC->Rectangle(rect);\r
2469                         pDC->SelectObject(pOldBr);\r
2470                         pDC->SelectObject(pOldPen);\r
2471                         pDC->SetROP2(nModle);\r
2472                         m_rtOld = rect; \r
2473                 }\r
2474         }\r
2475 \r
2476         if (m_bHand && nFlags == MK_LBUTTON)\r
2477         {\r
2478                 int curPos, prevPos;\r
2479                 //CChildFrame *pFrame = (CChildFrame *) GetParentFrame();\r
2480                 \r
2481                 int dy = m_ptLBDown.y - point.y;\r
2482                 prevPos = m_nPosV;\r
2483                 curPos = prevPos + dy;\r
2484                 prevPos = SetScrollPos(SB_VERT, curPos, TRUE);\r
2485                 curPos = GetScrollPos(SB_VERT);\r
2486                 int distance;\r
2487                 distance = prevPos - curPos;\r
2488                 m_nStartY += distance;\r
2489                 ScrollWindow(0, distance);\r
2490         \r
2491                 dy = m_ptLBDown.x - point.x;\r
2492                 prevPos = m_nPosH;\r
2493                 curPos = prevPos + dy;\r
2494                 prevPos = SetScrollPos(SB_HORZ, curPos, TRUE);\r
2495                 curPos = GetScrollPos(SB_HORZ);\r
2496                 distance = prevPos - curPos;\r
2497                 m_nStartX += distance;\r
2498                 ScrollWindow(distance, 0);\r
2499 \r
2500         }\r
2501         if (m_bSnap && nFlags == MK_LBUTTON)\r
2502         {\r
2503                 CPen *pOldPen;\r
2504                 CPen pen;\r
2505                 CBrush *pOldBr;\r
2506                 CRect rect(m_ptLBDown, point);\r
2507                 pen.CreatePen(PS_DASH, 2, RGB(255,0,0));\r
2508                 pOldPen = pDC->SelectObject(&pen);\r
2509                 pOldBr = (CBrush*) (pDC->SelectStockObject(NULL_BRUSH));\r
2510                 int nOldRop = pDC->SetROP2(R2_XORPEN);\r
2511                 int nModle = pDC->Rectangle(m_rtOld);\r
2512                 \r
2513                 pDC->Rectangle(rect);\r
2514                 pDC->SelectObject(pOldBr);\r
2515                 pDC->SelectObject(pOldPen);\r
2516                 pDC->SetROP2(nModle);\r
2517                 m_rtOld = rect;\r
2518                 \r
2519         }\r
2520         \r
2521         FPDF_LINK hlink=NULL;\r
2522         double pdfx,pdfy;\r
2523 \r
2524         int nActualRangeX = 0;\r
2525         int nActualRangeY = 0;\r
2526         if ( m_nRotateFlag % 2 == 0 )\r
2527         {\r
2528                 nActualRangeX = m_nActualSizeX;\r
2529                 nActualRangeY = m_nActualSizeY;\r
2530         }else{\r
2531                 nActualRangeX = m_nActualSizeY;\r
2532                 nActualRangeY = m_nActualSizeX;\r
2533         }\r
2534 \r
2535         FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
2536                 (int)(nActualRangeY * m_dbScaleFactor),m_nRotateFlag,point.x,point.y,&pdfx,&pdfy);\r
2537         hlink=FPDFLink_GetLinkAtPoint(m_pPage,pdfx,pdfy);\r
2538         if (hlink)\r
2539         {\r
2540                 HCURSOR hCur = AfxGetApp()->LoadCursor(IDC_CURSOR4);\r
2541             ::SetCursor(hCur);\r
2542         }\r
2543         ReleaseDC(pDC);\r
2544 //              \r
2545         CView::OnMouseMove(nFlags, point);\r
2546 }\r
2547 \r
2548 void CReaderVCView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) \r
2549 {\r
2550         // TODO: Add your message handler code here and/or call default\r
2551 //      double page_x = 0;\r
2552 //      double page_y = 0;\r
2553 //      DeviceToPage(point, page_x, page_y);\r
2554 \r
2555         if(m_pApp)\r
2556         {\r
2557                 if(FORM_OnKeyDown(m_pApp, m_pPage, nChar, ComposeFlag()))\r
2558                         return;\r
2559         }\r
2560         switch(nChar)\r
2561         {\r
2562         case 35:\r
2563                 OnDocLastpage();        \r
2564                 break;\r
2565         case 36:\r
2566                 OnDocFirstpage();\r
2567                 break;\r
2568         case 37:\r
2569                 this->OnDocPrepage();\r
2570                 break;\r
2571         case 39:\r
2572                 this->OnDocNextpage();\r
2573                 break;\r
2574         case 38:\r
2575                 \r
2576                 break;\r
2577         case 40:\r
2578                 \r
2579                 break;\r
2580         default:\r
2581                 break;\r
2582         }\r
2583         CView::OnKeyDown(nChar, nRepCnt, nFlags);\r
2584 }\r
2585 \r
2586 void CReaderVCView::OnToolSnapshot() \r
2587 {\r
2588         m_bSnap = TRUE;\r
2589         m_bHand = FALSE;\r
2590         m_bSelect = FALSE;\r
2591         this->HideCaret();\r
2592 }\r
2593 \r
2594 void CReaderVCView::OnToolSelect() \r
2595 {\r
2596         if(m_pTextPage == NULL)\r
2597         {\r
2598                 AfxMessageBox("Sorry, the fpdftext.dll may has expired. For keeping on using the dll, please contact sales@foxitsoftware.com.");\r
2599                 return;\r
2600         }\r
2601         m_bSnap = FALSE;\r
2602         m_bHand = FALSE;\r
2603         m_bSelect = TRUE;\r
2604 }\r
2605 \r
2606 void CReaderVCView::OnToolHand() \r
2607 {\r
2608         m_bSnap = FALSE;\r
2609         m_bHand = TRUE;\r
2610         m_bSelect = FALSE;\r
2611         this->HideCaret();\r
2612 }\r
2613 \r
2614 void CReaderVCView::LoadMyCursor(int nflag)\r
2615 {\r
2616         HCURSOR hCur;\r
2617         if (nflag == 1)\r
2618         {\r
2619                 if (m_bSelect)\r
2620                 {\r
2621                         hCur = AfxGetApp()->LoadCursor(IDC_CURSOR3);\r
2622                 }\r
2623                 else if (m_bSnap)\r
2624                 {\r
2625                         hCur = AfxGetApp()->LoadStandardCursor(IDC_CROSS);\r
2626                 }\r
2627                 else\r
2628                 {\r
2629                         hCur = AfxGetApp()->LoadCursor(IDC_CURSOR1);\r
2630                 }\r
2631         }\r
2632         else if (m_bHand)\r
2633         {\r
2634                 hCur = AfxGetApp()->LoadCursor(IDC_CURSOR2);\r
2635         }\r
2636         else if (m_bSelect)\r
2637         {\r
2638                 hCur = AfxGetApp()->LoadCursor(IDC_CURSOR3);\r
2639         }\r
2640         else if (m_bSnap)\r
2641         {\r
2642                 hCur = AfxGetApp()->LoadStandardCursor(IDC_CROSS);\r
2643         }else \r
2644         {\r
2645                 hCur = AfxGetApp()->LoadStandardCursor(IDC_ARROW);\r
2646         }\r
2647         ::SetCursor(hCur);\r
2648 }\r
2649 \r
2650 BOOL CReaderVCView::DeviceToPage(CPoint pt, double& page_x, double& page_y)\r
2651 {\r
2652 //      if(NULL == m_pTextPage) return FALSE;\r
2653         int nActualRangeX = 0;\r
2654         int nActualRangeY = 0;\r
2655         if ( m_nRotateFlag % 2 == 0 )\r
2656         {\r
2657                 nActualRangeX = m_nActualSizeX;\r
2658                 nActualRangeY = m_nActualSizeY;\r
2659         }else{\r
2660                 nActualRangeX = m_nActualSizeY;\r
2661                 nActualRangeY = m_nActualSizeX;\r
2662         }\r
2663 //      switch ( m_nRotateFlag % 4 )\r
2664 //      {\r
2665 //      case 0:\r
2666 //      case 2:\r
2667 //              {\r
2668 //                      FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,\r
2669 //                      m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, pt.x, pt.y, &page_x, &page_y);\r
2670 //                      break;\r
2671 //              }\r
2672 //      case 1:\r
2673 //      case 3:\r
2674 //              {\r
2675 //                      FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, m_nActualSizeY * m_dbScaleFactor,\r
2676 //                              m_nActualSizeX * m_dbScaleFactor, m_nRotateFlag, pt.x, pt.y, &page_x, &page_y);\r
2677 //                      break;\r
2678 //              }\r
2679 //      }\r
2680 \r
2681         FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
2682                 (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, pt.x, pt.y, &page_x, &page_y);\r
2683         return TRUE;\r
2684 }\r
2685 \r
2686 BOOL CReaderVCView::PageToDevice(double page_x, double page_y, CPoint& pt)\r
2687 {\r
2688         int nActualRangeX = 0;\r
2689         int nActualRangeY = 0;\r
2690         if ( m_nRotateFlag % 2 == 0 )\r
2691         {\r
2692                 nActualRangeX = m_nActualSizeX;\r
2693                 nActualRangeY = m_nActualSizeY;\r
2694         }else{\r
2695                 nActualRangeX = m_nActualSizeY;\r
2696                 nActualRangeY = m_nActualSizeX;\r
2697         }\r
2698 \r
2699         FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
2700                 (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, page_x, page_y, (int*)&pt.x, (int*)&pt.y);\r
2701         return TRUE;\r
2702 }\r
2703 \r
2704 BOOL CReaderVCView::GetCharIndexByPoint(CPoint pt, int &nIndex)\r
2705 {\r
2706         double page_x = 0.0f;\r
2707         double page_y = 0.0f;\r
2708 \r
2709         if(NULL == m_pTextPage) return FALSE;\r
2710         int nActualRangeX = 0;\r
2711         int nActualRangeY = 0;\r
2712         if ( m_nRotateFlag % 2 == 0 )\r
2713         {\r
2714                 nActualRangeX = m_nActualSizeX;\r
2715                 nActualRangeY = m_nActualSizeY;\r
2716         }else{\r
2717                 nActualRangeX = m_nActualSizeY;\r
2718                 nActualRangeY = m_nActualSizeX;\r
2719         }\r
2720         FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
2721                 (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, pt.x, pt.y, &page_x, &page_y);\r
2722 //      FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,\r
2723 //              m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, pt.x, pt.y, &page_x, &page_y);\r
2724         \r
2725         nIndex = FPDFText_GetCharIndexAtPos(m_pTextPage, page_x, page_y, 10, 10);\r
2726         if (-3 == nIndex || -1 == nIndex) return FALSE;\r
2727         return TRUE;\r
2728 }\r
2729 \r
2730 void CReaderVCView::CreateCaret(CPoint pt)\r
2731 {\r
2732         double a, b, c, d;\r
2733         int nIndex = 0;\r
2734         int nAcent = 0, nDecent = 0;\r
2735         double orgx = 0.0f, orgy = 0.0f;\r
2736         double fontsize = 0.0f;\r
2737         int left = 0, right = 0;\r
2738         int top = 0, bottom = 0;\r
2739         //double left_char, right_char, top_char, bottom_char;//char bounding box       \r
2740         FPDF_FONT pfont = NULL;\r
2741 \r
2742         if(!GetCharIndexByPoint(pt, nIndex)) return;\r
2743         fontsize = FPDFText_GetFontSize(m_pTextPage, nIndex);\r
2744 //      FPDFText_GetOrigin(m_pTextPage, nIndex, &orgx, &orgy);\r
2745 //      pfont = FPDFText_GetFont(m_pTextPage, nIndex);\r
2746 //      if(NULL == pfont) return;\r
2747 //      nAcent = FPDFFont_GetAscent(pfont);\r
2748 //      nDecent = FPDFFont_GetDescent(pfont);\r
2749 //      FPDFText_GetMatrix(m_pTextPage, nIndex, &a, &b, &c, &d);\r
2750 //      nAcent =(int)((nAcent * fontsize / 1000.0f) * d + orgy + 0.5f);\r
2751 //      nDecent = (int)((nDecent * fontsize / 1000.0f) * d + orgy + 0.5f);\r
2752 // \r
2753 //      int nActualRangeX = 0;\r
2754 //      int nActualRangeY = 0;\r
2755 //      if ( m_nRotateFlag % 2 == 0 )\r
2756 //      {\r
2757 //              nActualRangeX = m_nActualSizeX;\r
2758 //              nActualRangeY = m_nActualSizeY;\r
2759 //      }else{\r
2760 //              nActualRangeX = m_nActualSizeY;\r
2761 //              nActualRangeY = m_nActualSizeX;\r
2762 //      }\r
2763 //      FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
2764 //              (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, orgx, nAcent, &left, &top);\r
2765 // \r
2766 //      FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
2767 //              (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, orgx, nDecent, &right, &bottom);\r
2768 // \r
2769 // //   FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,\r
2770 // //           m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, orgx, nAcent, &left, &top);\r
2771 // // \r
2772 // //   FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,\r
2773 // //           m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, orgx, nDecent, &right, &bottom);\r
2774 // \r
2775 //      this->CreateSolidCaret(2, abs(top - bottom));\r
2776 //      \r
2777 // /*   FPDFText_GetCharBox(m_pTextPage, nIndex, &left_char, &right_char, &bottom_char, &top_char);\r
2778 // \r
2779 //      FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,\r
2780 //              m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, left_char, top_char, &left, &top);\r
2781 //      FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,\r
2782 //              m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, right_char, bottom_char, &right, &bottom);*/\r
2783 //      this->SetCaretPos(CPoint(left, top-2));\r
2784 //      this->ShowCaret();\r
2785         \r
2786 \r
2787 }\r
2788 \r
2789 void CReaderVCView::GetRects(int nStart, int nEnd)\r
2790 {\r
2791         int temp, nCount;\r
2792         nCount = nEnd - nStart;\r
2793         if (nCount < 0)\r
2794         {\r
2795                 temp = nEnd;\r
2796                 nEnd = nStart;\r
2797                 nStart = temp;\r
2798 \r
2799                 nCount = abs(nCount);\r
2800         }\r
2801          nCount ++;\r
2802 \r
2803          int num = FPDFText_CountRects(m_pTextPage, nStart, nCount);\r
2804          if(num == 0) return;\r
2805          \r
2806          if (m_rtArray.GetSize() > 0)\r
2807          {\r
2808                  m_rtArray.RemoveAll();\r
2809          }\r
2810          PDFRect rect;\r
2811          for (int i=0; i<num; i++)\r
2812          {\r
2813                  FPDFText_GetRect(m_pTextPage, i, &rect.m_dbLeft, &rect.m_dbTop, &rect.m_dbRight, &rect.m_dbBottom);\r
2814                  m_rtArray.Add(rect);\r
2815          }\r
2816         return;\r
2817 }\r
2818 \r
2819 CRect CReaderVCView::SelectSegment(CPoint pt_lt, CPoint pt_rb)\r
2820 {\r
2821         CRect rect(pt_lt, pt_rb);\r
2822 //      double left, top, right, bottom;\r
2823 //      int start_index = 0, nCount = 0;\r
2824 //      int nRect = 0;\r
2825 // \r
2826 //      int nActualRangeX = 0;\r
2827 //      int nActualRangeY = 0;\r
2828 //      if ( m_nRotateFlag % 2 == 0 )\r
2829 //      {\r
2830 //              nActualRangeX = m_nActualSizeX;\r
2831 //              nActualRangeY = m_nActualSizeY;\r
2832 //      }else{\r
2833 //              nActualRangeX = m_nActualSizeY;\r
2834 //              nActualRangeY = m_nActualSizeX;\r
2835 //      }\r
2836 //      FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
2837 //              (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, rect.left, rect.top, &left, &top);\r
2838 //      FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),\r
2839 //              (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, rect.right, rect.bottom, &right, &bottom);\r
2840 // \r
2841 // //   FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,\r
2842 // //           m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, rect.left, rect.top, &left, &top);\r
2843 // //   FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,\r
2844 // //           m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, rect.right, rect.bottom, &right, &bottom);\r
2845 // \r
2846 //      int num = FPDFText_CountBoundedSegments(m_pTextPage, left, top, right, bottom);\r
2847 // \r
2848 //      if (m_rtArray.GetSize() > 0)\r
2849 //      {\r
2850 //              m_rtArray.RemoveAll();\r
2851 //      }\r
2852 // \r
2853 //      CDC *pDC = GetDC();\r
2854 //      for (int i=0; i<num; i++)\r
2855 //      {\r
2856 //              FPDFText_GetBoundedSegment(m_pTextPage, i, &start_index, &nCount);\r
2857 //              nRect = FPDFText_CountRects(m_pTextPage, start_index, nCount);\r
2858 // \r
2859 //              PDFRect rect_select;\r
2860 //              for (int j=0; j<num; j++)\r
2861 //              {\r
2862 //                      FPDFText_GetRect(m_pTextPage, j, &rect_select.m_dbLeft, &rect_select.m_dbTop, &rect_select.m_dbRight, &rect_select.m_dbBottom);\r
2863 //                      m_rtArray.Add(rect_select);\r
2864 //              }\r
2865 //      }\r
2866 //      ReleaseDC(pDC);\r
2867         return rect;\r
2868 }\r
2869 \r
2870 void CReaderVCView::OnToolPdf2txt() \r
2871 {\r
2872         // TODO: Add your command handler code here\r
2873         if(m_pTextPage == NULL)\r
2874         {\r
2875                 AfxMessageBox("Sorry, the fpdftext.dll may has expired. For keeping on using the dll, please contact sales@foxitsoftware.com.");\r
2876                 return;\r
2877         }\r
2878         CConvertDlg condlg;\r
2879         if(condlg.DoModal() == IDOK)\r
2880         {\r
2881                 int nFlag=condlg.m_nFlag;\r
2882                 CReaderVCDoc *pDoc = this->GetDocument();\r
2883                 CString pdfname=pDoc->m_strPDFName;\r
2884                 CString strname=pdfname,stem;\r
2885                 if (strname.Find(".pdf") != -1 || strname.Find(".PDF") != -1)\r
2886                 {\r
2887                         int startatr=strname.ReverseFind('\\');\r
2888                         stem=strname.Mid(startatr+1,strname.GetLength()-startatr-5);\r
2889                 }\r
2890                 CString defaultname=stem+".txt";\r
2891 \r
2892                 char szFilter[] = "Text File(*.txt)|*.txt";\r
2893                 CFileDialog dlg(FALSE, ".txt", defaultname, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, NULL);\r
2894 \r
2895                 if (dlg.DoModal() == IDOK)\r
2896                 {\r
2897 //                      CString txtname=dlg.GetPathName();\r
2898 //                      BOOL bFlag=FPDFText_PDFToText(pdfname,txtname,nFlag,NULL);\r
2899 //                      if(! bFlag) \r
2900 //                              MessageBox("Convert Failure!");\r
2901                 }\r
2902         }       \r
2903 }\r
2904 \r
2905 void CReaderVCView::SyncScroll()\r
2906 {\r
2907         CRect rect;                                                               \r
2908         GetClientRect(rect);                                                      \r
2909         \r
2910         int nSizeX = 0; \r
2911         int nSizeY = 0;\r
2912         //int temp = 0;\r
2913 \r
2914         if (1 == m_nRotateFlag || 3 == m_nRotateFlag)\r
2915         {\r
2916                 nSizeX = m_nActualSizeY;\r
2917                 nSizeY = m_nActualSizeX;\r
2918         }\r
2919         else\r
2920         {\r
2921                 nSizeX = m_nActualSizeX;\r
2922                 nSizeY = m_nActualSizeY;\r
2923         }\r
2924         \r
2925         SCROLLINFO scrinfo;                                                       \r
2926         scrinfo.cbSize = sizeof(SCROLLINFO);                                      \r
2927         GetScrollInfo(SB_HORZ, &scrinfo);                                         \r
2928         scrinfo.nMin =0;                                                          \r
2929         scrinfo.nMax = (int)(nSizeX * m_dbScaleFactor);                                                 \r
2930         scrinfo.nPage = (unsigned int)(__min(nSizeX * m_dbScaleFactor, rect.Width()));                              \r
2931         if (nSizeX * m_dbScaleFactor < rect.Width()){scrinfo.fMask |= SIF_DISABLENOSCROLL;}         \r
2932         SetScrollInfo(SB_HORZ, &scrinfo);                                         \r
2933         SetScrollPos(SB_HORZ, 0);                                           \r
2934         //m_nPosH = nPosH;                                                          \r
2935         \r
2936         GetScrollInfo(SB_VERT, &scrinfo);                                         \r
2937         scrinfo.nMin = 0;                                                         \r
2938         scrinfo.nMax = (int)(nSizeY * m_dbScaleFactor);                                             \r
2939         scrinfo.nPage =(unsigned int)( __min(nSizeY * m_dbScaleFactor, rect.Height()));                             \r
2940         if (nSizeY * m_dbScaleFactor < rect.Height()){scrinfo.fMask |= SIF_DISABLENOSCROLL;}        \r
2941         SetScrollInfo(SB_VERT, &scrinfo);                                         \r
2942         SetScrollPos(SB_VERT, 0);                                             \r
2943                                                              \r
2944 }\r
2945 \r
2946 void CReaderVCView::OnSize(UINT nType, int cx, int cy) \r
2947 {\r
2948         CView::OnSize(nType, cx, cy);\r
2949         SyncScroll();\r
2950         if(m_bmp)\r
2951         {\r
2952                 FPDFBitmap_Destroy(m_bmp);\r
2953                 m_bmp = NULL;\r