stlab.adobe.com Adobe Systems Incorporated

edit_number.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 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_WIDGETS_EDIT_NUMBER_HPP
00010 #define ADOBE_WIDGETS_EDIT_NUMBER_HPP
00011 
00012 /****************************************************************************************************/
00013 
00014 #include <adobe/config.hpp>
00015 
00016 #include <adobe/future/debounce.hpp>
00017 #include <adobe/future/number_formatter.hpp>
00018 #include <adobe/future/widgets/headers/platform_edit_text.hpp>
00019 #include <adobe/future/widgets/headers/number_unit.hpp>
00020 #include <adobe/future/widgets/headers/platform_popup.hpp>
00021 #include <adobe/future/widgets/headers/platform_edit_number.hpp>
00022 #include <adobe/future/widgets/headers/widget_utils.hpp>
00023 #include <adobe/future/locale.hpp>
00024 #include <adobe/future/cursor.hpp>
00025 
00026 #include <boost/noncopyable.hpp>
00027 
00028 #include <cctype>
00029 
00030 /****************************************************************************************************/
00031 
00032 namespace adobe {
00033 
00034 /****************************************************************************************************/
00035 
00041 struct edit_number_unit_subwidget_t
00042 {
00043     typedef std::string model_type;
00044 
00045     explicit edit_number_unit_subwidget_t(edit_number_t& edit_number);
00046 
00047     void display(const model_type& value);
00048 
00049     edit_number_t& edit_number_m;
00050 };
00051 
00052 /****************************************************************************************************/
00053 
00061 struct edit_number_t : boost::noncopyable
00062 {
00063     typedef double model_type;
00064 
00065     template <typename ForwardIterator>
00066     edit_number_t(const edit_text_ctor_block_t& block,
00067                   const ForwardIterator         first,
00068                   const ForwardIterator         last);
00069 
00070     ~edit_number_t()
00071     {
00072         locale_change_connection_m.disconnect();
00073     }
00074 
00081     void measure(extents_t& result);
00082 
00083     void place(const place_data_t& place_data);
00085 
00091     struct controller_t
00092     {
00093         typedef edit_number_t::model_type      model_type;
00094         typedef boost::function<void (const model_type&)> setter_proc_t;
00095 
00096         explicit controller_t(edit_number_t* control = 0,
00097                                   name_t  cell = name_t()) :
00098             control_m(control),
00099             enabled_m(true),
00100             cell_m(cell)
00101         { }
00102 
00109         void monitor(const setter_proc_t& value);
00110         void enable(bool make_enabled);
00112 
00113         name_t cell() const { return cell_m; }
00114 
00115     private:
00116         friend struct edit_number_t;
00117 
00118         edit_number_t* control_m;
00119         setter_proc_t  setter_m;
00120         bool           enabled_m;
00121         name_t  cell_m;
00122     };
00123 
00129     struct view_t
00130     {
00131         typedef edit_number_t::model_type model_type;
00132 
00133         explicit view_t(edit_number_t* control = 0,
00134                         name_t  cell = name_t()) :
00135             control_m(control),
00136             cell_m(cell)
00137         { }
00138 
00145         void display(const model_type& value);
00147 
00148         name_t cell() const { return cell_m; }
00149 
00150     private:
00151         friend struct edit_number_t;
00152 
00153         edit_number_t* control_m;
00154         name_t  cell_m;
00155     };
00156 
00157 #ifndef ADOBE_NO_DOCUMENTATION
00158     any_regular_t underlying_handler() { return any_regular_t(edit_text().control_m); }
00159 
00160     bool handle_key(key_type key, bool pressed, modifiers_t modifiers);
00161 
00162     typedef view_t                 view_type;
00163     typedef std::vector<view_type> view_set_t;
00164     typedef view_set_t::iterator   view_iterator;
00165 
00166     view_iterator view_begin() { return view_set_m.begin(); }
00167     view_iterator view_end()   { return view_set_m.end(); }
00168 
00169     typedef controller_t                 controller_type;
00170     typedef std::vector<controller_type> controller_set_t;
00171     typedef controller_set_t::iterator   controller_iterator;
00172 
00173     controller_iterator controller_begin() { return controller_set_m.begin(); }
00174     controller_iterator controller_end()   { return controller_set_m.end(); }
00175 
00176     inline bool using_popup() const
00177     { return unit_set_m.size() > 1; }
00178 
00179     struct base_unit_t
00180     {
00181         base_unit_t(name_t name, double min, double max) :
00182             name_m(name), min_m(min), max_m(max)
00183         { }
00184 
00185         name_t name_m;
00186         double        min_m;
00187         double        max_m;
00188     };
00189 
00190     typedef std::vector<base_unit_t> base_unit_set_t;
00191 
00192     // REVISIT (fbrereto) : I'm not happy about these, but we need them
00193     //                      for the time being so the template specialization
00194     //                      of insert(display, etc.) can get to them
00195     inline edit_text_t& edit_text() { return edit_text_m; }
00196     inline popup_t&     popup()     { return popup_m; }
00197     void        initialize();
00198     void        monitor_locale(const dictionary_t& value);
00199 
00200 private:
00201     void        monitor_text(const std::string& new_value, bool display_was_updated=true);
00202     void        monitor_popup(const any_regular_t& new_value);
00203     void        field_text_filter(const std::string& candidate, bool& squelch);
00204     void        increment(bool up);
00205     void        increment_n(long n); // in current units
00206     void        refresh_enabled_state(edit_number_t::controller_t* src);
00207     void        refresh_view(edit_number_t::view_t* src, const model_type& new_value, bool force = false);
00208     std::size_t current_base_unit_index();
00209 
00210     static const adobe_cursor_t scrubby_cursor();
00211 
00212     // these are for edit_number_unit_subwidget_t
00213     friend struct edit_number_unit_subwidget_t;
00214     void display_unit(const edit_number_unit_subwidget_t::model_type& unit_name);
00215 
00216     // the debounce type is double because if it is the formatted
00217     // string value the real value will be clipped by the formatter.
00218     // this will cause the value to be converted to an incorrect
00219     // scaled value should it be needed by a scaled unit. This was
00220     // found when incrementing a value stored in units celsius by
00221     // single units fahrenheit: the celsius value gets clipped and
00222     // the round-tripping of the fahrenheit value is then incorrect.
00223 
00224     typedef double                     debounce_type;
00225     typedef std::vector<debounce_type> debounce_set_t;
00226     typedef std::vector<unit_t>        unit_set_t;
00227 
00228     friend struct edit_number_platform_data_t;
00229 
00230     edit_text_t                 edit_text_m;
00231     popup_t                     popup_m;
00232     number_formatter_t          number_formatter_m;
00233     std::size_t                 edit_text_width_m;
00234     std::size_t                 unit_index_m; // this is the current index of the *popup*
00235     unit_set_t                  unit_set_m;
00236     base_unit_set_t             base_unit_set_m;
00237     view_set_t                  view_set_m;
00238     controller_set_t            controller_set_m;
00239     debounce_set_t              debounce_set_m;
00240     double                      min_m;
00241     double                      max_m;
00242     edit_number_platform_data_t platform_m;
00243 public:
00244     boost::signals::connection  locale_change_connection_m;
00245 #endif
00246 };
00247 
00248 /****************************************************************************************************/
00249 
00250 template <typename ForwardIterator>
00251 edit_number_t::edit_number_t(const edit_text_ctor_block_t& block,
00252                              const ForwardIterator         first,
00253                              const ForwardIterator         last) :
00254     edit_text_m(block),
00255     popup_m(std::string(), block.alt_text_m, std::string(), 0, 0, block.theme_m),
00256     edit_text_width_m(0),
00257     unit_index_m(0),
00258     unit_set_m(first, last),
00259     platform_m(0)
00260 {
00261     platform_m = edit_number_platform_data_t(this);
00262 }
00263 
00264 /****************************************************************************************************/
00265 
00266 inline edit_number_unit_subwidget_t::edit_number_unit_subwidget_t(edit_number_t& edit_number) :
00267     edit_number_m(edit_number)
00268 { }
00269 
00270 inline void edit_number_unit_subwidget_t::display(const model_type& value)
00271 {
00272     edit_number_m.display_unit(value);
00273 }
00274 
00275 /****************************************************************************************************/
00276 
00277 } //namespace adobe
00278 
00279 /****************************************************************************************************/
00280 
00281 // ADOBE_WIDGETS_EDIT_NUMBER_HPP
00282 #endif
00283 
00284 /****************************************************************************************************/

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