00001
00002
00003
00004
00005
00006 #ifndef H_CPPPDFViewCtrl
00007 #define H_CPPPDFViewCtrl
00008
00009 #include <PDF/PDFDoc.h>
00010 #include <PDF/PDFRasterizer.h>
00011 #include <PDF/Highlights.h>
00012 #include <PDF/OCG/Context.h>
00013 #include <C/PDF/TRN_PDFViewCtrl.h>
00014
00015 namespace pdftron {
00016 namespace PDF {
00017
00018
00031 class PDFViewCtrl
00032 {
00033 public:
00034
00042 PDFViewCtrl(void* parent_hwnd, void* hinstance);
00043 ~PDFViewCtrl();
00044
00052 bool SetDoc(PDFDoc& doc, const char* password = 0);
00053
00057 void CloseDoc();
00058
00062 PDFDoc* GetDoc();
00063
00064
00069 enum WindowID {
00070 e_main_view,
00071 e_thumb_view,
00072 e_bookmark_view,
00073 e_layers_view
00074 };
00075
00076 enum ControlEventType {
00077 e_mouse_move,
00078 e_mouse_enter,
00079 e_mouse_leave,
00080 e_mouse_left_down,
00081 e_mouse_left_up,
00082 e_mouse_left_dclick,
00083 e_mouse_right_down,
00084 e_mouse_right_up,
00085 e_mouse_right_dclick,
00086 e_mouse_middle_down,
00087 e_mouse_middle_up,
00088 e_mouse_middle_dclick,
00089 e_mouse_wheel,
00090 e_context_menu,
00091 e_key_down,
00092 e_key_up,
00093 e_key_press,
00094 e_paint
00095 };
00096
00097
00102 struct MouseEvent {
00103 int m_x;
00104 int m_y;
00105 int m_wheelRotation;
00106 int m_wheelDelta;
00107 int m_linesPerAction;
00108 UInt8 m_leftDown;
00109 UInt8 m_middleDown;
00110 UInt8 m_rightDown;
00111 UInt8 m_controlDown;
00112 UInt8 m_shiftDown;
00113 UInt8 m_altDown;
00114 UInt8 m_metaDown;
00115
00116
00117 enum ControlEventType m_event_type;
00118
00119 enum WindowID m_event_window;
00120
00121 UInt8 m_pdfviewctrl_processed;
00122 };
00123
00128 struct KeyEvent {
00129 int m_x;
00130 int m_y;
00131 long int m_keyCode;
00132 Unicode m_unicode;
00133 UInt8 m_controlDown;
00134 UInt8 m_shiftDown;
00135 UInt8 m_altDown;
00136 UInt8 m_metaDown;
00137
00138 enum ControlEventType m_event_type;
00139
00140 enum WindowID m_event_window;
00141
00142 UInt8 m_pdfviewctrl_processed;
00143 };
00144
00149 struct PaintEvent {
00150
00151 void* m_hdc;
00152 enum TRN_PDFViewCtrlWindowID m_event_window;
00153 TRN_Bool m_pdfviewctrl_processed;
00154 };
00155
00156 struct SizeEvent {
00157 int m_width;
00158 int m_height;
00159 int m_x_position;
00160 int m_y_position;
00161
00162 enum WindowID m_event_window;
00163 };
00164
00165
00166
00167 typedef UInt8 (*MouseEventHandler) ( struct MouseEvent* evt, void* custom_data );
00168 typedef UInt8 (*KeyEventHandler) ( struct KeyEvent* evt, void* custom_data );
00169 typedef UInt8 (*PaintEventHandler) ( struct PaintEvent* evt, void* custom_data );
00170 typedef UInt8 (*SizeEventHandler) ( struct SizeEvent* evt, void* custom_data );
00171
00176 struct EventHandlers
00177 {
00178 MouseEventHandler mouse_move;
00179 MouseEventHandler mouse_enter;
00180 MouseEventHandler mouse_leave;
00181 MouseEventHandler mouse_left_down;
00182 MouseEventHandler mouse_left_up;
00183 MouseEventHandler mouse_left_dclick;
00184 MouseEventHandler mouse_right_down;
00185 MouseEventHandler mouse_right_up;
00186 MouseEventHandler mouse_right_dclick;
00187 MouseEventHandler mouse_middle_down;
00188 MouseEventHandler mouse_middle_up;
00189 MouseEventHandler mouse_middle_dclick;
00190 MouseEventHandler on_mousewheel;
00191 MouseEventHandler on_context_menu;
00192 KeyEventHandler key_down;
00193 KeyEventHandler key_up;
00194 KeyEventHandler character_entered;
00195 PaintEventHandler on_paint;
00196 SizeEventHandler on_size;
00197
00198 void* custom_data;
00199
00200 EventHandlers();
00201 };
00202
00207 void SetCustomEventHandlers( EventHandlers* handlers );
00208
00216 typedef UInt8 (*ActionHandler) ( TRN_Action action, void* custom_data );
00217
00222 void SetActionHandler( ActionHandler action_callback, void* custom_data );
00223
00229 void ExecuteAction( Action action );
00230
00239 typedef void (*CurrentPageHandler) (int current_page, int num_pages, void* data);
00240
00249 void SetCurrentPageHandler(CurrentPageHandler curr_pagenum_proc, void* data);
00250
00251 typedef void (*ErrorReportHandler) (const char* message, void* data);
00252
00260 void SetErrorReportHandler(ErrorReportHandler error_proc, void* data);
00261
00272 void OnSize(int x, int y, int width, int height);
00273
00278 void Find();
00279
00283 void Copy();
00284
00288 void SelectAll();
00289
00295 void SetProgressiveRendering(bool progressive=true);
00296
00301 void ShowNavPanel(bool show);
00302
00307 void EnableScrollbar( bool show );
00308
00313 void ShowToolbar( bool show);
00314
00319 void ShowStatusBar( bool show);
00320
00325 void ShowNavToolbar( bool show);
00326
00331 void ShowMenuBar( bool show );
00332
00337 void EnableInteractiveForms(bool on);
00338
00344 void ShowDialogs(bool show);
00345
00346 static const UInt32 e_none=0x00;
00347 static const UInt32 e_bookmarks=0x01;
00348 static const UInt32 e_layers=0x02;
00349 static const UInt32 e_thumbview=0x04;
00350 static const UInt32 e_all=0x07;
00351 typedef UInt32 PanelType;
00352
00357 void SetEnabledPanels(UInt32 panels);
00358
00364 UInt32 GetEnabledPanels() const ;
00365
00370 void SetSelectedPanel(PanelType panel);
00371
00376 PanelType GetSelectedPanel() const ;
00377
00382 void SetSplitPosition(int pos);
00383
00388 int GetSplitPosition() const ;
00389
00394 void Print();
00395
00405 void Print(int first_page, int last_page, Page::Rotate rotation,
00406 int copies, const char* printer_name);
00407
00408
00412 void Refresh();
00413
00417 void CaptureMouse();
00418
00422 void ReleaseMouse();
00423
00427 bool HasCapture() const;
00428
00433 void EnableLinkActivation(bool enable);
00434
00440 void LoadCurrentConfiguration( const UString & path );
00441
00447 void SaveCurrentConfiguration( const UString & path, Common::ProgressMonitor* progress = 0 );
00448
00461 Annot GetDefaultAnnotation( const char* type );
00462
00466 void SetFocus();
00467
00468
00469
00473 void DocProperties();
00474
00478 void DeletePages();
00479
00483 void InsertPages(const UString& src_name);
00484
00488 void InsertBlankPages();
00489
00494 void ReplacePages(const UString& src_name = UString());
00495
00499 void RotatePages();
00500
00504 void ExtractPages();
00505
00510 void CropPages();
00511
00515 void AddWatermark();
00516
00517
00518
00531 enum PageViewMode
00532 {
00533 e_fit_page = 0,
00534 e_fit_width,
00535 e_fit_height,
00536 e_zoom
00537 };
00538
00545 void SetPageViewMode(PageViewMode mode);
00546
00550 PageViewMode GetPageViewMode() const ;
00551
00555 enum PagePresentationMode
00556 {
00557 e_single_page = 1,
00558 e_single_continuous,
00559 e_facing,
00560 e_facing_continuous,
00561 e_facing_cover,
00562 e_facing_continuous_cover
00563 };
00564
00571 void SetPagePresentationMode(PagePresentationMode mode);
00572
00576 PagePresentationMode GetPagePresentationMode() const ;
00577
00581 int GetCurrentPage() const ;
00582
00586 int GetPageCount() const ;
00587
00593 bool GotoFirstPage();
00594
00600 bool GotoLastPage();
00601
00607 bool GotoNextPage();
00608
00614 bool GotoPreviousPage();
00615
00621 bool SetCurrentPage(int page_num);
00622
00630 bool ShowRect( int page_num, const Rect& rect );
00631
00637 double GetZoom() const ;
00638
00646 bool SetZoom(double zoom);
00647
00660 bool SetZoom(int x, int y, double zoom);
00661
00665 void RotateClockwise();
00666
00670 void RotateCounterClockwise();
00671
00675 Page::Rotate GetRotation() const ;
00676
00682 int GetPageNumberFromScreenPt(double x, double y) const ;
00683
00687 void ConvScreenPtToCanvasPt(double& x, double& y) const ;
00688
00692 void ConvCanvasPtToScreenPt(double& x, double& y) const;
00693
00701 void ConvCanvasPtToPagePt(double& x, double& y, int page_num = -1) const;
00702
00710 void ConvPagePtToCanvasPt(double& x, double& y, int page_num = -1) const;
00711
00719 void ConvScreenPtToPagePt(double& x, double& y, int page_num = -1) const;
00720
00728 void ConvPagePtToScreenPt(double& x, double& y, int page_num = -1) const;
00729
00745 Common::Matrix2D GetDeviceTransform(int page_num = -1) const;
00746
00750 double GetCanvasWidth() const;
00751
00755 double GetCanvasHeight() const;
00756
00762 double GetHScrollPos() const;
00763
00769 double GetVScrollPos() const;
00770
00771
00778 void OnScroll(int pix_dx, int pix_dy);
00779
00787 void SetHScrollPos(double pos);
00788
00796 void SetVScrollPos(double pos);
00797
00802 bool IsFinishedRendering() const;
00803
00808 void CancelRendering();
00809
00813 void Update();
00814
00819 void Update(const Rect& update);
00820
00826 void Update(const Annot& annot, int page_num);
00827
00834 void UpdatePageLayout();
00835
00840 int GetViewWidth() const;
00841
00846 int GetViewHeight() const;
00847
00848
00855 void SetDrawAnnotations(bool render_annots);
00856
00866 void SetAntiAliasing(bool enable_aa);
00867
00881 void SetImageSmoothing(bool smoothing_enabled = true);
00882
00890 void SetCaching(bool enabled);
00891
00900 void SetRasterizerType (PDFRasterizer::Type type);
00901
00914 void SetGamma(double exp);
00915
00931 void SetOCGContext(const OCG::Context& ctx);
00932
00940 OCG::Context GetOCGContext();
00941
00946 enum ToolMode
00947 {
00948 e_custom,
00949 e_pan,
00950 e_text_rect_select,
00951 e_text_struct_select,
00952 e_zoom_in,
00953 e_zoom_out,
00954 e_annot_edit,
00955 e_line_create,
00956 e_arrow_create,
00957 e_rect_create,
00958 e_oval_create,
00959 e_ink_create,
00960 e_text_annot_create,
00961 e_stamp_create,
00962 e_highlight_create,
00963 e_underline_create,
00964 e_strikeout_create,
00965 e_squiggly_create,
00966 e_text_box_create,
00967 e_calloutbox_create,
00968 e_polygon_create,
00969 e_polyline_create,
00970 e_file_attachment,
00971 e_sound_attachment,
00972 e_movie_attachment,
00973 e_caret_create,
00974 e_redaction_create,
00975 e_text_field_create,
00976 e_check_box_create,
00977 e_radio_button_create,
00978 e_list_box_create,
00979 e_combo_box_create,
00980 e_button_create,
00981 e_link_create,
00982 e_tool_mode_end
00983 };
00984
00989 void SetToolMode(ToolMode mode);
00990
00994 ToolMode GetToolMode() const;
00995
00999 class Selection {
01000 public:
01004 int GetPageNum() const;
01005
01028 int GetQuads(const double* &quads) const;
01029
01033 void GetAsUnicode(UString& out_str) const;
01034
01041 const char* GetAsHtml() const;
01042
01044 Selection();
01045 Selection(const Selection&);
01046 Selection& operator=(const Selection&);
01047 Selection(TRN_PDFViewCtrlSelection impl);
01048 private:
01049 TRN_PDFViewCtrlSelection mp_selection;
01051 };
01052
01060 bool SelectByRect(double x1, double y1, double x2, double y2);
01061
01070 bool SelectByStruct(double x1, double y1, double x2, double y2);
01071
01078 bool SelectByHighlights(const Highlights& highlights);
01079
01090 bool FindText(const UString& search_str, bool match_case = false, bool match_whole_word = false, bool search_up = false, bool reg_exp = false);
01091
01095 bool HasSelection() const;
01096
01100 void ClearSelection();
01101
01107 PDFViewCtrl::Selection GetSelection( int page = -1 ) const;
01108
01113 int GetSelectionBeginPage() const ;
01114
01119 int GetSelectionEndPage() const;
01120
01125 bool HasSelectionOnPage( int ipage ) const;
01126
01131 void SetPageBorderVisibility(bool border_visible);
01132
01137 void SetDefaultPageColor(UInt8 r, UInt8 g, UInt8 b);
01138
01143 void SetBackgroundColor(UInt8 r, UInt8 g, UInt8 b);
01144
01154 void SetHorizontalAlign(int align);
01155
01165 void SetVerticalAlign(int align);
01166
01180 void SetPageSpacing(int horiz_col_space, int vert_col_space, int horiz_pad, int vert_pad);
01181
01182
01183 private:
01184 TRN_PDFViewCtrl mp_view;
01185 TRN_PDFDoc temp_doc;
01186 };
01187
01188
01189
01190 #include <Impl/PDFViewCtrl.inl>
01191
01192 }
01193 }
01194
01195 #endif