stlab.adobe.com Adobe Systems Incorporated

sheet_hooks.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2008 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef ADOBE_SHEET_HOOKS
00010 #define ADOBE_SHEET_HOOKS
00011 
00012 /*************************************************************************************************/
00013 
00014 #include <adobe/adam.hpp>
00015 #include <adobe/widget_proxies.hpp>
00016 #include <adobe/dictionary.hpp>
00017 
00018 /*************************************************************************************************/
00019 
00020 namespace adobe {
00021 
00022 /*************************************************************************************************/
00030 template <typename Sheet, typename View>
00031 void attach_view_to_model(adobe::assemblage_t& assemblage,
00032                           Sheet&               model,
00033                           adobe::name_t        cell,
00034                           View&                view)
00035 {
00036     adobe::poly_view_t* poly_view(new adobe::poly_view_t(boost::ref(view)));
00037 
00038     assemblage_cleanup_ptr(assemblage, poly_view);
00039 
00040     adobe::sheet_t::monitor_value_t m(boost::bind(&adobe::ViewConcept<adobe::poly_view_t>::display,
00041                                                   boost::ref(*poly_view), _1));
00042 
00043     typename Sheet::connection_t c(model.monitor_value(cell, m));
00044 
00045     assemblage_cleanup_connection(assemblage, c);
00046 }
00047 
00048 /*************************************************************************************************/
00057 template <typename T>
00058 inline void forward_to_model(adobe::sheet_t& property_model,
00059                              adobe::name_t   cell,
00060                              const T&        value)
00061 {
00062     property_model.set(cell, adobe::any_regular_t(value));
00063     property_model.update();
00064 }
00065 
00066 /*************************************************************************************************/
00074 template <typename Controller>
00075 void attach_controller_to_model(adobe::assemblage_t& assemblage,
00076                                 adobe::sheet_t&      property_model,
00077                                 adobe::name_t        cell,
00078                                 Controller&          controller)
00079 {
00080     typedef typename adobe::ControllerConcept<Controller>::model_type controller_model_type;
00081 
00082     void (*forward_proc)(adobe::sheet_t&, adobe::name_t, const controller_model_type&) =
00083         &forward_to_model<controller_model_type>;
00084 
00085     controller.monitor(boost::bind(forward_proc, boost::ref(property_model), cell, _1));
00086 
00087     adobe::sheet_t::connection_t connection =
00088         property_model.monitor_enabled(cell, NULL, NULL,
00089                                        boost::bind(&Controller::enable, boost::ref(controller), _1));
00090 
00091     assemblage_cleanup_connection(assemblage, connection);
00092 }
00093 
00094 /*************************************************************************************************/
00095 #if 0
00096 #pragma mark -
00097 #endif
00098 /*************************************************************************************************/
00106 template <typename ArgumentType, typename Sheet, typename Function>
00107 inline void attach_view_function_to_model(adobe::assemblage_t& assemblage,
00108                                           Sheet&               model,
00109                                           adobe::name_t        cell,
00110                                           const Function&      function)
00111 {
00112     adobe::poly_view_t* view(new adobe::poly_view_t(adobe::make_function_as_poly_view<ArgumentType>(function)));
00113 
00114     assemblage_cleanup_ptr(assemblage, view);
00115 
00116     attach_view_to_model(assemblage, model, cell, *view);
00117 }
00118 
00119 /*************************************************************************************************/
00124 template <typename T,
00125           typename Sheet,
00126           typename MonitorFunction,
00127           typename EnableFunction>
00128 inline void attach_controller_functions_to_model(adobe::assemblage_t&   assemblage,
00129                                                  Sheet&                 model,
00130                                                  adobe::name_t          cell,
00131                                                  const MonitorFunction& monitor_function,
00132                                                  const EnableFunction&  enable_function)
00133 {
00134     adobe::poly_controller_t* controller(new adobe::poly_controller_t(adobe::make_functions_as_poly_controller<T>(monitor_function, enable_function)));
00135 
00136     assemblage_cleanup_ptr(assemblage, controller);
00137 
00138     attach_controller_to_model(assemblage, model, cell, *controller);
00139 }
00140 
00141 /*************************************************************************************************/
00142 
00157 template <typename T,
00158           typename Sheet,
00159           typename DisplayFunction,
00160           typename MonitorFunction,
00161           typename EnableFunction>
00162 inline void attach_widget_proxies_to_model(adobe::assemblage_t&   assemblage,
00163                                            Sheet&                 model,
00164                                            adobe::name_t          cell,
00165                                            const DisplayFunction& display_function,
00166                                            const MonitorFunction& monitor_function,
00167                                            const EnableFunction&  enable_function)
00168 {
00169     attach_view_function_to_model<T>(assemblage, model, cell, display_function);
00170     attach_controller_functions_to_model<T>(assemblage, model, cell, monitor_function, enable_function);
00171 }
00172 
00173 
00174 //Attach only two fucntions as a controller for a cell
00175 
00176 template <typename T ,
00177 typename MonitorFunction,
00178 typename EnableFunction,
00179 typename FactoryToken>
00180 void attach_controller_functions_direct(const FactoryToken& token,
00181                                         const adobe::name_t         cell,
00182                                         const MonitorFunction& monitor_function,
00183                                         const EnableFunction&  enable_function)
00184 {
00185     basic_sheet_t& layout_sheet(*token.mEveViewHolder.mLayoutSheet);
00186     // is the cell in the layout sheet or the Adam sheet?
00187     if (layout_sheet.count_interface(cell) != 0)
00188     {
00189         
00190         attach_controller_functions_to_model<T>(token.mEveViewHolder.GetAssemblage(),
00191                                                 layout_sheet,               
00192                                                 cell,
00193                                                 monitor_function,
00194                                                 enable_function);   
00195     }
00196     else
00197     {
00198         attach_controller_functions_to_model<T>(token.mEveViewHolder.GetAssemblage(),
00199                                                 *token.mSheet,              
00200                                                 cell,
00201                                                 monitor_function,
00202                                                 enable_function);   
00203     }
00204 }
00205 
00206 template <typename T, 
00207 typename MonitorFunction,
00208 typename EnableFunction,
00209 typename FactoryToken>
00210 void attach_controller_functions(const adobe::dictionary_t& parameters,
00211                                  const FactoryToken&            token,
00212                                  const adobe::name_t            key_name,
00213                                  const MonitorFunction& monitor_function,
00214                                  const EnableFunction&  enable_function)
00215 {
00216     if (parameters.count(key_name) 
00217         && get_value(parameters, key_name).type_info() == adobe::type_info<name_t>())
00218     {
00219         name_t         cell(get_value(parameters,key_name).cast<name_t>());     
00220         
00221         attach_controller_functions_direct<T>(token,cell,monitor_function,enable_function);
00222     }
00223 }
00224     
00225     
00226 //Attach only the view to a funtion
00227     
00228 template <typename T ,
00229           typename Function, 
00230           typename FactoryToken>
00231 void attach_view_function_direct(const FactoryToken&    token,
00232                                  const name_t           cell,
00233                                  const Function&        function )
00234 {
00235     sheet_t& layout_sheet(*token.mEveViewHolder.mLayoutSheet);
00236     // is the cell in the layout sheet or the Adam sheet?
00237     if (layout_sheet.count_interface(cell) != 0)
00238     {
00239             
00240         attach_view_function_to_model<T>(token.mEveViewHolder.GetAssemblage(),
00241                                          layout_sheet,              
00242                                          cell,
00243                                          function); 
00244     }
00245     else
00246     {
00247         attach_view_function_to_model<T>(token.mEveViewHolder.GetAssemblage(),
00248                                          *token.mSheet,             
00249                                          cell,
00250                                          function); 
00251     }
00252 }
00253     
00254 template <typename T, 
00255           typename Function,
00256           typename FactoryToken>
00257 void attach_view_function(const adobe::dictionary_t&    parameters,
00258                           const FactoryToken&           token,
00259                           const adobe::name_t           key_name,
00260                           const Function&               function )
00261 {
00262     if (parameters.count(key_name) 
00263         && get_value(parameters, key_name).type_info() == adobe::type_info<name_t>())
00264     {
00265         name_t         cell(get_value(parameters,key_name).cast<name_t>());     
00266         
00267         attach_view_function_direct<T>(token,cell,function);
00268     }
00269 }
00270     
00271 /*************************************************************************************************/
00272 
00273 } // namespace adobe
00274 
00275 /*************************************************************************************************/
00276 // ADOBE_SHEET_HOOKS
00277 #endif
00278 /*************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google