pdf/plugin_impl/render_settings_impl.cpp

Go to the documentation of this file.
00001 /*
00002  * File Name: render_settings_impl.cpp
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 #include "render_settings_impl.h"
00028 #include "pdf_renderer.h"
00029 
00030 namespace pdf
00031 {
00032 
00033 utils::ObjectTable<PluginRenderSettingsImpl> 
00034 PluginRenderSettingsImpl::g_instances_table;
00035 
00036 PluginRenderSettingsImpl::PluginRenderSettingsImpl(void)
00037 : attr()
00038 {
00039     // IPluginUnknown
00040     query_interface = query_interface_impl;
00041     release         = release_impl;
00042 
00043     // IPluginClone
00044     create_clone_object = create_clone_object_impl;
00045     
00046     // IPluginRenderSettings, no method yet.
00047 
00048     // IPluginZoom
00049     set_zoom_factor     = set_zoom_factor_impl;
00050     get_zoom_factor     = get_zoom_factor_impl;
00051 
00052     // IPluginRotation
00053     set_rotation = set_rotation_impl;
00054     get_rotation = get_rotation_impl;
00055 
00056     g_instances_table.add_interface<IPluginUnknown>(this);
00057     g_instances_table.add_interface<IPluginClone>(this);
00058     g_instances_table.add_interface<IPluginRenderSettings>(this);
00059     g_instances_table.add_interface<IPluginZoom>(this);
00060     g_instances_table.add_interface<IPluginRotation>(this);
00061 }
00062 
00063 PluginRenderSettingsImpl::PluginRenderSettingsImpl(const PluginRenderSettingsImpl &ref)
00064 : attr(ref.attr)
00065 {
00066     // IPluginUnknown
00067     query_interface = query_interface_impl;
00068     release         = release_impl;
00069 
00070     // IPluginClone
00071     create_clone_object = create_clone_object_impl;
00072     
00073     // IPluginRenderSettings, no method yet.
00074 
00075     // IPluginZoom
00076     set_zoom_factor     = set_zoom_factor_impl;
00077     get_zoom_factor     = get_zoom_factor_impl;
00078 
00079     // IPluginRotation
00080     set_rotation = set_rotation_impl;
00081     get_rotation = get_rotation_impl;
00082 
00083     g_instances_table.add_interface<IPluginUnknown>(this);
00084     g_instances_table.add_interface<IPluginClone>(this);
00085     g_instances_table.add_interface<IPluginRenderSettings>(this);
00086     g_instances_table.add_interface<IPluginZoom>(this);
00087     g_instances_table.add_interface<IPluginRotation>(this);
00088 }
00089 
00090 PluginRenderSettingsImpl::~PluginRenderSettingsImpl(void)
00091 {
00092     g_instances_table.remove(this);
00093 }
00094 
00095 PluginRenderSettingsImpl * 
00096 PluginRenderSettingsImpl::query_instance(IPluginUnknown * thiz)
00097 {
00098     return g_instances_table.get_object(thiz);
00099 }
00100 
00101 PluginStatus 
00102 PluginRenderSettingsImpl::query_interface_impl(IPluginUnknown    *thiz,
00103                                                const UDSString   *id, 
00104                                                void              **ptr)
00105 {
00106     PluginRenderSettingsImpl * instance = g_instances_table.get_object(thiz);
00107     if (g_instances_table.query_interface(instance, id->get_buffer(id), ptr))
00108     {
00109         return PLUGIN_OK;
00110     }
00111     return PLUGIN_FAIL;
00112 }
00113 
00114 int 
00115 PluginRenderSettingsImpl::release_impl(IPluginUnknown  *thiz)
00116 {
00117     // Have to handle the object cloned and object created by view.
00118     // For cloned object, its life cycle is not limited.
00119     // For object created by view, view keeps a reference to it, so
00120     // it should notify view when it's to be released.
00121     PluginRenderSettingsImpl * instance = g_instances_table.get_object(thiz);
00122     if (instance->release_signal.count())
00123     {
00124         instance->release_signal.safe_broadcast(instance);
00125     }
00126     else
00127     {
00128         delete instance;
00129     }
00130     return 0;
00131 }
00132 
00133 IPluginUnknown* 
00134 PluginRenderSettingsImpl::create_clone_object_impl(IPluginUnknown *thiz)
00135 {
00136     PluginRenderSettingsImpl * instance = g_instances_table.get_object(thiz);
00137     PluginRenderSettingsImpl * another_instance 
00138         = new PluginRenderSettingsImpl(*instance);
00139 
00140     // DON'T need to connect the release signal.
00141     return static_cast<IPluginUnknown *>(another_instance);
00142 }
00143 
00144 PluginStatus 
00145 PluginRenderSettingsImpl::set_zoom_factor_impl(IPluginUnknown *thiz,
00146                                                const float zoom_factor)
00147 {
00148     PluginRenderSettingsImpl *instance = g_instances_table.get_object(thiz);
00149 
00150     // Should check the zoom factor boundary. TODO
00151     instance->attr.set_zoom_setting(static_cast<double>(zoom_factor));
00152     return PLUGIN_OK;
00153 }
00154 
00155 float 
00156 PluginRenderSettingsImpl::get_zoom_factor_impl(IPluginUnknown *thiz)
00157 {
00158     PluginRenderSettingsImpl * instance = g_instances_table.get_object(thiz);
00159     return static_cast<float>(instance->attr.get_zoom_setting());
00160 }
00161     
00162 PluginStatus 
00163 PluginRenderSettingsImpl::set_rotation_impl(IPluginUnknown  *thiz,
00164                                             const PluginRotationDegree rotation)
00165 {
00166     PluginRenderSettingsImpl * instance = g_instances_table.get_object(thiz);
00167     instance->attr.set_rotate(static_cast<int>(rotation));
00168     return PLUGIN_OK;
00169 }
00170     
00171 PluginRotationDegree 
00172 PluginRenderSettingsImpl::get_rotation_impl(IPluginUnknown  *thiz)
00173 {    
00174     PluginRenderSettingsImpl * instance = g_instances_table.get_object(thiz);
00175     return static_cast<PluginRotationDegree>(instance->attr.get_rotate());
00176 }
00177 
00178 } // namespace pdf
00179 
Generated by  doxygen 1.6.2-20100208