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