plaintext/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-plaintext.
00007  *
00008  * uds-plugin-plaintext 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-plaintext 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 TEXT_PLUGIN_DOCUMENT_IMPL_H_
00028 #define TEXT_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 "text_model.h"
00037 #include "text_controller.h"
00038 #include "string_impl.h"
00039 
00040 using namespace utils;
00041 
00042 namespace text
00043 {
00044 
00045 struct RangeImpl
00046 {
00047 public:
00048     RangeImpl(const Range& range)
00049     {
00050         start_anchor = new StringImpl(range.start.to_string());
00051         end_anchor = new StringImpl(range.end.to_string());
00052     }
00053 
00054     ~RangeImpl()
00055     {
00056         delete start_anchor;
00057         delete end_anchor;
00058     }
00059 
00060 public:
00061     UDSString* start_anchor;
00062     UDSString* end_anchor;
00063 };
00064 
00065 class PluginViewImpl;
00066 
00067 /// @brief Implement all necessary interfaces for document object.
00068 /// If the interface is not supported, the impl can remove 
00069 /// them from parent class list.
00070 class PluginDocImpl : public IPluginUnknown 
00071                     , public IPluginDocument 
00072                     , public IPluginDocNavigator
00073                     , public IPluginDocAttributes
00074                     , public IPluginEventBroadcaster
00075                     , public IPluginDocHyperlink
00076                     , public IPluginDocDictionary
00077                     , public IPluginDocMarker
00078                     , public IPluginDocSearch
00079 {
00080 public:
00081     PluginDocImpl();
00082     ~PluginDocImpl();
00083 
00084 public:
00085     TextModel & get_model() { return document; }
00086 
00087 public:
00088     /// The release signal.
00089     Signal<PluginDocImpl *> release_signal;
00090 
00091     /// Handle search done event.
00092     void on_search_done(const std::vector<Range>& result, const SearchContext* sc);
00093 
00094 private:
00095     // IPluginUnknown.
00096     static PluginStatus query_interface_impl(
00097         IPluginUnknown      *thiz,
00098         const UDSString     *id, 
00099         void                **ptr );
00100 
00101     static int release_impl(
00102         IPluginUnknown      *thiz );
00103 
00104     // IPluginDocument.
00105     static PluginStatus open_impl(
00106         IPluginUnknown      *thiz, 
00107         const UDSString     *path);
00108 
00109     static PluginBool is_open_impl(
00110         IPluginUnknown      *thiz);
00111 
00112     static PluginStatus close_impl(
00113         IPluginUnknown      *thiz);
00114 
00115     static IPluginUnknown * create_view_impl(
00116         IPluginUnknown      *thiz);
00117 
00118     // IPluginDocNavigator
00119     static PluginStatus get_initial_anchor_impl(
00120         IPluginUnknown      *thiz, 
00121         UDSString           *anchor);
00122 
00123     static PluginStatus get_object_from_anchor_impl(
00124         IPluginUnknown      *thiz,
00125         const UDSString     *anchor, 
00126         PluginRange         *range);
00127 
00128     static PluginDocObjectType get_type_of_object_impl(
00129         IPluginUnknown      *thiz,
00130         const PluginRange   *range);
00131     
00132     static PluginStatus get_words_from_range_impl(
00133         IPluginUnknown      *thiz, 
00134         const PluginRange   *char_range, 
00135         PluginRange         *word_range );
00136 
00137     static PluginStatus get_text_from_range_impl(
00138         IPluginUnknown      *thiz, 
00139         const PluginRange   *range, 
00140         UDSString           *result );
00141 
00142     static PluginBool is_anchor_in_current_document_impl(
00143         IPluginUnknown      *thiz,
00144         const UDSString     *anchor );
00145 
00146     static PluginStatus get_file_name_from_anchor_impl(
00147         IPluginUnknown    *thiz,
00148         const UDSString   *anchor,
00149         UDSString         *file_name );
00150 
00151     static PluginStatus get_file_position_from_anchor_impl(
00152         IPluginUnknown    *thiz,
00153         const UDSString   *anchor,
00154         signed long long  *position );
00155 
00156     static int compare_anchor_location_impl(
00157         IPluginUnknown      *thiz,
00158         const UDSString     *anchor_a,
00159         const UDSString     *anchor_b );
00160 
00161     // IPluginDocAttributes.
00162     static PluginStatus get_attribute_impl(
00163         IPluginUnknown      *thiz,
00164         const UDSString     *key, 
00165         UDSString           *value );
00166 
00167     static PluginStatus set_attribute_impl(
00168         IPluginUnknown      *thiz,
00169         const UDSString     *key,
00170         const UDSString     *value );
00171 
00172     // IPluginEventBroadcaster
00173     static PluginStatus add_event_receiver_impl(
00174         IPluginUnknown      *thiz,
00175         const PluginEvent   plugin_event,
00176         EventFunc           callback,
00177         void                *user_data,
00178         unsigned long       *handler_id);
00179 
00180     static PluginStatus remove_event_receiver_impl(
00181         IPluginUnknown      *thiz,
00182         unsigned long       handler_id );
00183 
00184     // IPluginDocHyperlink
00185     static PluginBool is_hyperlink_impl(
00186         IPluginUnknown      *thiz,
00187         const PluginRange   *range );
00188 
00189     static PluginStatus get_target_from_hyperlink_impl(
00190         IPluginUnknown      *thiz,
00191         const PluginRange   *range, 
00192         UDSString           *anchor );
00193 
00194     // IPluginDocDictionary
00195     static PluginBool is_dictionary_impl( 
00196         IPluginUnknown      *thiz );
00197 
00198     // IPluginDocMarker. No such interface.
00199     // Place holder for these two functions.
00200     static IPluginUnknown* get_supported_marker_types_impl(
00201         IPluginUnknown  *thiz );
00202 
00203     static PluginStatus request_marker_trees_impl(
00204         IPluginUnknown     *thiz, 
00205         const unsigned int uds_private_size );
00206 
00207     // IPluginDocSearch
00208     static IPluginUnknown * create_search_criteria_impl(
00209         IPluginUnknown      *thiz );
00210 
00211     static PluginStatus request_search_next_impl(
00212         IPluginUnknown      *thiz,
00213         IPluginUnknown      *criteria,
00214         const UDSString     *from_anchor,
00215         const unsigned int  search_id);
00216 
00217     static PluginStatus request_search_all_impl( 
00218         IPluginUnknown *thiz,
00219         IPluginUnknown *criteria,
00220         const unsigned int  search_id);
00221 
00222     static PluginStatus abort_search_impl(
00223         IPluginUnknown     *thiz,
00224         const unsigned int search_id);
00225 
00226 private:
00227     typedef PluginViewImpl * ViewPtr;
00228     
00229 private:
00230     static utils::ObjectTable<PluginDocImpl> g_instances_table;
00231 
00232 private:
00233     TextController *controller; ///< Controller instance.
00234     utils::Listeners listeners; ///< All listeners.
00235     text::TextModel document;   ///< The document model.
00236 
00237 private:
00238     void init_doc_attributes();
00239     typedef std::map<std::string, std::string> DocAttrMap;
00240     typedef DocAttrMap::iterator               DocAttrMapIter;
00241     DocAttrMap doc_attr_map;
00242 };
00243 
00244 };  // namespace text
00245 
00246 #endif
00247 
Generated by  doxygen 1.6.2-20100208