pdf/plugin_impl/document_impl.h

Go to the documentation of this file.
00001 /*
00002  * File Name: document_impl.h
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-pdf.
00007  *
00008  * uds-plugin-pdf is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-pdf is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #ifndef PDF_PLUGIN_DOCUMENT_IMPL_H_
00028 #define PDF_PLUGIN_DOCUMENT_IMPL_H_
00029 
00030 #include <string>
00031 #include <vector>
00032 #include "plugin_inc.h"
00033 #include "interfaces_utils.h"
00034 #include "signal_slot.h"
00035 #include "listeners.h"
00036 #include "marker_entry_impl.h"
00037 #include "pdf_doc_controller.h"
00038 
00039 using namespace utils;
00040 
00041 namespace pdf
00042 {
00043 
00044 class PluginViewImpl;
00045 
00046 /// @brief Implement all necessary interfaces for document object.
00047 /// If the interface is not supported, the impl can remove 
00048 /// them from parent class list.
00049 class PluginDocImpl : public IPluginUnknown 
00050                     , public IPluginDocument 
00051                     , public IPluginDocNavigator
00052                     , public IPluginDocAttributes
00053                     , public IPluginEventBroadcaster
00054                     , public IPluginDocHyperlink
00055                     , public IPluginDocDictionary
00056                     , public IPluginDocMarker
00057                     , public IPluginDocSearch
00058 {
00059 public:
00060     PluginDocImpl();
00061     ~PluginDocImpl();
00062 
00063 public:
00064     /// Retrieve total page number. This function is used by
00065     /// PluginViewImpl
00066     unsigned int get_page_count();
00067 
00068     /// Retrieve page number from anchor. This function is used
00069     /// by PluginViewImpl.
00070     unsigned int get_page_number(const std::string & anchor);
00071 
00072     /// Retrieve the anchor for given page number.
00073     bool get_anchor_of_page(const unsigned int page_number, 
00074                             std::string & anchor);
00075 
00076     /// Anchor iteraotr: retrieve the previous anchor.
00077     bool get_prev_page(std::string & anchor);
00078 
00079     /// Anchor iteraotr: retrieve the next anchor.
00080     bool get_next_page(std::string & anchor);
00081 
00082     bool get_original_size(const std::string &anchor,
00083                            unsigned int &width,
00084                            unsigned int &height);
00085 
00086     bool get_content_area(const std::string &anchor,
00087                           RenderArea &area);
00088 
00089     PluginRotationDegree get_page_original_rotation(const std::string &anchor);
00090 
00091     /// Get the renderer
00092     PDFRenderer* get_renderer() { return doc_ctrl.get_renderer(); }
00093 
00094     /// Get the document controller
00095     PDFController & get_doc_ctrl() { return doc_ctrl; }
00096 
00097     /// Get the file name
00098     const string& get_file_name() { return doc_ctrl.name(); }
00099 
00100 public:
00101     /// The release signal.
00102     utils::Signal<PluginDocImpl *> release_signal;
00103 
00104 private:
00105     // IPluginUnknown.
00106     static PluginStatus query_interface_impl(
00107         IPluginUnknown      *thiz,
00108         const UDSString     *id, 
00109         void                **ptr );
00110 
00111     static int release_impl(
00112         IPluginUnknown      *thiz );
00113 
00114     // IPluginDocument.
00115     static PluginStatus open_impl(
00116         IPluginUnknown      *thiz, 
00117         const UDSString     *path);
00118 
00119     static PluginBool is_open_impl(
00120         IPluginUnknown      *thiz);
00121 
00122     static PluginStatus close_impl(
00123         IPluginUnknown      *thiz);
00124 
00125     static IPluginUnknown * create_view_impl(
00126         IPluginUnknown      *thiz);
00127 
00128     // IPluginDocNavigator
00129     static PluginStatus get_initial_anchor_impl(
00130         IPluginUnknown      *thiz, 
00131         UDSString           *anchor);
00132 
00133     static PluginStatus get_object_from_anchor_impl(
00134         IPluginUnknown      *thiz,
00135         const UDSString     *anchor, 
00136         PluginRange         *range);
00137 
00138     static PluginDocObjectType get_type_of_object_impl(
00139         IPluginUnknown      *thiz,
00140         const PluginRange   *range);
00141     
00142     static PluginStatus get_words_from_range_impl(
00143         IPluginUnknown      *thiz, 
00144         const PluginRange   *chars_range, 
00145         PluginRange         *words_range );
00146 
00147     static PluginStatus get_text_from_range_impl(
00148         IPluginUnknown      *thiz, 
00149         const PluginRange   *range, 
00150         UDSString           *result );
00151 
00152     static PluginBool is_anchor_in_current_document_impl(
00153         IPluginUnknown      *thiz,
00154         const UDSString     *anchor );
00155 
00156     static PluginStatus get_file_name_from_anchor_impl(
00157         IPluginUnknown      *thiz,
00158         const UDSString     *anchor,
00159         UDSString           *file_name);
00160 
00161     static PluginStatus get_file_position_from_anchor_impl(
00162         IPluginUnknown      *thiz,
00163         const UDSString     *anchor,
00164         signed long long    *position);
00165 
00166     static int compare_anchor_location_impl(
00167         IPluginUnknown      *thiz,
00168         const UDSString     *anchor_a,
00169         const UDSString     *anchor_b );
00170 
00171     static PluginStatus get_attribute_impl(
00172         IPluginUnknown      *thiz,
00173         const UDSString     *key, 
00174         UDSString           *value );
00175 
00176     static PluginStatus set_attribute_impl(
00177         IPluginUnknown      *thiz,
00178         const UDSString     *key,
00179         const UDSString     *value );
00180 
00181     // IPluginEventBroadcaster
00182     static PluginStatus add_event_receiver_impl(
00183         IPluginUnknown      *thiz,
00184         const PluginEvent   plugin_event,
00185         EventFunc           callback,
00186         void                *user_data,
00187         unsigned long       *handler_id);
00188 
00189     static PluginStatus remove_event_receiver_impl(
00190         IPluginUnknown      *thiz,
00191         unsigned long       handler_id );
00192 
00193     // IPluginDocHyperlink
00194     static PluginBool is_hyperlink_impl(
00195         IPluginUnknown      *thiz,
00196         const PluginRange   *range );
00197 
00198     static PluginStatus get_target_from_hyperlink_impl(
00199         IPluginUnknown      *thiz,
00200         const PluginRange   *range, 
00201         UDSString           *anchor );
00202 
00203     static IPluginUnknown* get_hyperlinks_in_range_impl(
00204         IPluginUnknown      *thiz,
00205         const PluginRange   *range );
00206 
00207     // IPluginDocDictionary
00208     static PluginBool is_dictionary_impl( 
00209         IPluginUnknown      *thiz );
00210 
00211     // IPluginDocMarker
00212     static IPluginUnknown* get_supported_marker_types_impl(
00213         IPluginUnknown      *thiz );
00214 
00215     static PluginBool has_toc_impl(
00216         IPluginUnknown      *thiz );
00217 
00218     static PluginStatus request_marker_trees_impl(
00219         IPluginUnknown      *thiz, 
00220         const unsigned int  uds_private_size );
00221 
00222     // IPluginDocSearch
00223     static IPluginUnknown * create_search_criteria_impl(
00224         IPluginUnknown      *thiz );
00225 
00226     static PluginStatus request_search_next_impl(
00227         IPluginUnknown      *thiz,
00228         IPluginUnknown      *criteria,
00229         const UDSString     *from_anchor,
00230         const unsigned int  search_id);
00231 
00232     static PluginStatus request_search_all_impl( 
00233         IPluginUnknown *thiz,
00234         IPluginUnknown *criteria,
00235         const unsigned int  search_id);
00236 
00237     static PluginStatus abort_search_impl(
00238         IPluginUnknown *thiz,
00239         const unsigned int  search_id);
00240 
00241 private:
00242     MarkerEntry* generate_marker_entry(const std::string & anchor,
00243                                        const std::string & text,
00244                                        const std::string & goto_anchor,
00245                                        const unsigned int uds_private_size);
00246 
00247     void add_toc_children(MarkerEntry * parent, 
00248                           TocItem * item,
00249                           const unsigned int uds_private_size);
00250 
00251 private:
00252     typedef PluginViewImpl * ViewPtr;
00253     typedef std::vector<ViewPtr> Views;
00254     typedef std::vector<ViewPtr>::iterator ViewsIter;
00255     
00256 private:
00257     // Handle the view release event
00258     void on_view_released(ViewPtr view);
00259 
00260     // Handle the search ready event
00261     void on_search_results_ready(SearchResult res, PDFRangeCollection* coll
00262         , unsigned int search_id);
00263 
00264 private:
00265     static utils::ObjectTable<PluginDocImpl> g_instances_table;
00266 
00267 private:
00268     utils::Listeners listeners;
00269     PDFController    doc_ctrl;
00270     Views            views;
00271 
00272     friend class PluginViewImpl;
00273 
00274 private:
00275     void init_doc_attributes();
00276     typedef std::map<std::string, std::string> DocAttrMap;
00277     typedef DocAttrMap::iterator               DocAttrMapIter;
00278     DocAttrMap doc_attr_map;
00279 };
00280 
00281 };  // namespace pdf
00282 
00283 #endif
00284 
Generated by  doxygen 1.6.2-20100208