|
From: Foster B. <fos...@us...> - 2005-04-12 17:25:01
|
Update of /cvsroot/adobe-source/sandbox/adobe-source/adobe/test/visual/sources/mac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29764/adobe-source/adobe/test/visual/sources/mac Modified Files: main.cpp ui_core_implementation.cpp Added Files: metrics.cpp Log Message: Adding error diagnostics to xstr; beginning metrics work on Mac Begin --- NEW FILE: metrics.cpp --- /* Copyright 2005 Adobe Systems Incorporated Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /****************************************************************************************************/ #include "metrics.hpp" #include "report_exception.hpp" #include <adobe/xstr.hpp> #include <adobe/virtual_machine.hpp> #include <adobe/source/expression_parser.hpp> #include <adobe/dictionary.hpp> #include <adobe/array.hpp> #include <sstream> /****************************************************************************************************/ namespace { /****************************************************************************************************/ /****************************************************************************************************/ } // namespace /****************************************************************************************************/ #if 0 #pragma mark - #endif /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ dictionary_t widget_metrics(const dictionary_t& context) { dictionary_t result; try { std::string metric_xstr("<xstr id='metric'/>"); std::stringstream expression_stream(std::string(xstr_t(metric_xstr.c_str(), metric_xstr.size(), context).get())); expression_parser parser(expression_stream, line_position_t("widget_metrics")); array_t expression; parser.require_expression(expression); virtual_machine_t machine; machine.evaluate(expression); result = machine.back().value_m.template get<adobe::dictionary_t>(); } catch(...) { report_exception(); } return result; } /****************************************************************************************************/ } // namespace adobe /****************************************************************************************************/ Index: main.cpp =================================================================== RCS file: /cvsroot/adobe-source/sandbox/adobe-source/adobe/test/visual/sources/mac/main.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** main.cpp 31 Mar 2005 22:50:43 -0000 1.6 --- main.cpp 12 Apr 2005 17:24:49 -0000 1.7 *************** *** 12,15 **** --- 12,17 ---- #include <boost/filesystem/convenience.hpp> + #include <adobe/xstr.hpp> + #include <sstream> #include <string> Index: ui_core_implementation.cpp =================================================================== RCS file: /cvsroot/adobe-source/sandbox/adobe-source/adobe/test/visual/sources/mac/ui_core_implementation.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ui_core_implementation.cpp 10 Apr 2005 07:00:46 -0000 1.8 --- ui_core_implementation.cpp 12 Apr 2005 17:24:49 -0000 1.9 *************** *** 12,15 **** --- 12,16 ---- #include "report_exception.hpp" #include "display.hpp" + #include "metrics.hpp" #include <adobe/algorithm.hpp> *************** *** 42,141 **** /****************************************************************************************************/ ! } // namespace adobe ! ! /****************************************************************************************************/ ! ! enum metrics { ! gap = 6 // Measured as space from popup to label. ! }; ! ! /****************************************************************************************************/ ! ! namespace { ! ! /****************************************************************************************************/ ! ! #if 0 ! #pragma mark - ! #endif ! ! /****************************************************************************************************/ ! ! inline long theme_metric(ThemeMetric metric) ! { ! SInt32 value(0); ! ::GetThemeMetric(metric, &value); ! return value; ! } /****************************************************************************************************/ ! template <typename T> ! adobe::rectangle_t widget_metrics(adobe::theme_t /*theme*/) ! { return adobe::rectangle_t(); } /****************************************************************************************************/ ! template <> ! adobe::rectangle_t widget_metrics<adobe::checkbox_t::implementation_t>(adobe::theme_t theme) ! { ! adobe::rectangle_t result; ! ! theme &= adobe::theme_mask_s; ! ! if (theme == adobe::theme_mini_s) ! { ! result.width() += theme_metric(kThemeMetricMiniCheckBoxWidth); ! ! result.height() += theme_metric(kThemeMetricMiniCheckBoxHeight); ! } ! else if (theme == adobe::theme_small_s) ! { ! result.width() += theme_metric(kThemeMetricSmallCheckBoxWidth); ! ! result.height() += theme_metric(kThemeMetricSmallCheckBoxHeight); ! } ! else // if (theme == adobe::theme_normal_s) ! { ! result.width() += theme_metric(kThemeMetricCheckBoxWidth); ! ! result.height() += theme_metric(kThemeMetricCheckBoxHeight); ! } ! ! return result; ! } /****************************************************************************************************/ ! std::string get_control_title(ControlRef control); ! adobe::rectangle_t get_text_dimensions(const std::string& text, adobe::theme_t theme); /****************************************************************************************************/ ! template <typename T> ! adobe::rectangle_t widget_measurement(const T& widget) ! { ! std::string name(get_control_title(widget.control_m)); ! adobe::rectangle_t result(widget_metrics<T>(widget.theme_m)); ! adobe::rectangle_t text(get_text_dimensions(name, widget.theme_m)); ! ! result.width() += text.width(); ! ! if (name.size()) ! result.width() += gap; ! ! adobe::copy( text.slice_m[adobe::rectangle_slices_t::vertical].poi_m, ! std::back_inserter(result.slice_m[adobe::rectangle_slices_t::vertical].poi_m)); ! ! return result; ! } ! ! /****************************************************************************************************/ ! #if 0 ! #pragma mark - ! #endif /****************************************************************************************************/ --- 43,89 ---- /****************************************************************************************************/ ! #define ADOBE_WIDGET_TAG_BOILERPLATE(widget, static_tag) \ ! template <> name_t widget_tag<widget>(const widget&) { return static_name_t(static_tag); } ! template <typename T> name_t widget_tag(const T&) { return static_name_t("unknown"); } ! ADOBE_WIDGET_TAG_BOILERPLATE(adobe::checkbox_t::implementation_t, "checkbox") ! ADOBE_WIDGET_TAG_BOILERPLATE(adobe::radio_button_t::implementation_t, "radio_button") /****************************************************************************************************/ ! } // namespace adobe /****************************************************************************************************/ ! enum metrics { ! gap = 6 // Measured as space from popup to label. ! }; /****************************************************************************************************/ ! namespace { /****************************************************************************************************/ ! adobe::static_name_t k_attribute_theme("theme"); ! adobe::static_name_t k_attribute_theme_large("large"); ! adobe::static_name_t k_attribute_theme_normal("normal"); ! adobe::static_name_t k_attribute_theme_small("small"); ! adobe::static_name_t k_attribute_theme_mini("mini"); ! adobe::static_name_t k_attribute_widget("widget"); ! adobe::static_name_t k_metric_height("height"); ! adobe::static_name_t k_metric_width("width"); ! adobe::static_name_t k_metric_fudge_top("fudge_top"); ! adobe::static_name_t k_metric_fudge_left("fudge_left"); ! adobe::static_name_t k_metric_fudge_height("fudge_height"); ! adobe::static_name_t k_metric_fudge_width("fudge_width"); ! adobe::static_name_t k_metric_fudge_baseline("fudge_baseline"); ! adobe::static_name_t k_metric_outset_top("outset_top"); ! adobe::static_name_t k_metric_outset_left("outset_left"); ! adobe::static_name_t k_metric_outset_bottom("outset_bottom"); ! adobe::static_name_t k_metric_outset_right("outset_right"); ! adobe::static_name_t k_metric_text_gap("text_gap"); /****************************************************************************************************/ *************** *** 374,439 **** /****************************************************************************************************/ - adobe::fudge_t factory_fudge_table(const adobe::dictionary_t& ui_state) - { - typedef std::pair<adobe::dictionary_t, adobe::fudge_t> fudge_pair_t; - typedef std::vector<fudge_pair_t> fudge_table_t; - typedef fudge_table_t::iterator iterator; - - static bool inited(false); - static fudge_table_t fudge_table; - - if (!inited) - { - adobe::dictionary_t index; - adobe::dictionary_t::write_reference d(index.write()); - - // fill in the table here - - inited = true; - } - - iterator result(adobe::find_if(fudge_table, boost::bind(std::equal_to<fudge_pair_t::first_type>(), ui_state, boost::bind(&fudge_pair_t::first, _1)))); - - return result == fudge_table.end() ? adobe::fudge_t() : result->second; - } - - /****************************************************************************************************/ - - void apply_fudges(adobe::rectangle_t& geometry, const adobe::fudge_t& fudges) - { - geometry.slice_m[adobe::rectangle_slices_t::vertical].length_m += fudges.top() + fudges.bottom(); - geometry.slice_m[adobe::rectangle_slices_t::horizontal].length_m += fudges.left() + fudges.right(); - - #if 0 - geometry.slice_m[adobe::rectangle_slices_t::vertical].outset_m.first += fudges.top(); - geometry.slice_m[adobe::rectangle_slices_t::vertical].outset_m.second -= fudges.bottom() + fudges.top(); - geometry.slice_m[adobe::rectangle_slices_t::horizontal].outset_m.first += fudges.left(); - geometry.slice_m[adobe::rectangle_slices_t::horizontal].outset_m.second -= fudges.right() + fudges.left(); - #endif - - adobe::points_of_interest_t& poi(geometry.slice_m[adobe::rectangle_slices_t::vertical].poi_m); - - if (poi.size()) poi[0] += fudges.baseline_m; - } - - /****************************************************************************************************/ - - void shed_fudges(adobe::point_t& position, adobe::rectangle_t& geometry, const adobe::fudge_t& fudges) - { - position.second -= fudges.top(); - position.first -= fudges.left(); - - geometry.height() -= fudges.bottom(); - geometry.width() -= fudges.right(); - } - - /****************************************************************************************************/ - - #if 0 - #pragma mark - - #endif - - /****************************************************************************************************/ - template <typename T> void get_widget_data(::ControlRef widget, UInt32 part, UInt32 tag, T& data, bool throwing = true) --- 322,325 ---- *************** *** 2002,2005 **** --- 1888,1999 ---- /****************************************************************************************************/ + #if 0 + #pragma mark - + #endif + + /****************************************************************************************************/ + + template <typename Widget> + adobe::metric_extractor_t metric_extractor(const Widget& w) + { + adobe::static_name_t attribute_theme_value("unknown"); + adobe::dictionary_t context; + + switch (w.theme_m & adobe::theme_mask_s) + { + case adobe::theme_large_s: attribute_theme_value = k_attribute_theme_large; break; + case adobe::theme_normal_s: attribute_theme_value = k_attribute_theme_normal; break; + case adobe::theme_small_s: attribute_theme_value = k_attribute_theme_small; break; + case adobe::theme_mini_s: attribute_theme_value = k_attribute_theme_mini; break; + } + + adobe::dictionary_t::write_reference context_write(context.write()); + + context_write[k_attribute_theme] = adobe::value_t(attribute_theme_value); + context_write[k_attribute_widget] = adobe::value_t(widget_tag(w)); + + return adobe::metric_extractor_t(widget_metrics(context)); + } + + /****************************************************************************************************/ + + template <typename Widget> + adobe::rectangle_t widget_best_bounds(Widget& w, const std::string* first, const std::string* last) + { + adobe::rectangle_t result; + long text_height(0); + long text_width(0); + long text_baseline(-1); + + w.metrics_m = metric_extractor(w); + + for (; first != last; ++first) + { + adobe::rectangle_t geometry(get_text_dimensions(*first, w.theme_m)); + adobe::points_of_interest_t& poi(geometry.slice_m[adobe::rectangle_slices_t::vertical].poi_m); + + text_height = std::max(text_height, geometry.height()); + text_width = std::max(text_width, geometry.width()); + + if (poi.size()) + text_baseline = std::max(text_baseline, poi[0]); + } + + result.height() = w.metrics_m(k_metric_height) - w.metrics_m(k_metric_fudge_height); + result.width() = w.metrics_m(k_metric_width) - w.metrics_m(k_metric_fudge_width); + + if (text_width != 0) + result.width() += text_width + w.metrics_m(k_metric_text_gap); + + if (text_baseline != -1) + result.slice_m[adobe::rectangle_slices_t::vertical].poi_m.push_back(text_baseline - w.metrics_m(k_metric_fudge_baseline)); + + // adjust outsets in accordance with the fudges + + result.slice_m[adobe::rectangle_slices_t::vertical].outset_m.first += w.metrics_m(k_metric_outset_top); + result.slice_m[adobe::rectangle_slices_t::vertical].outset_m.second -= w.metrics_m(k_metric_outset_top) + w.metrics_m(k_metric_outset_bottom); + result.slice_m[adobe::rectangle_slices_t::horizontal].outset_m.first += w.metrics_m(k_metric_outset_left); + result.slice_m[adobe::rectangle_slices_t::horizontal].outset_m.second -= w.metrics_m(k_metric_outset_left) + w.metrics_m(k_metric_outset_right); + + return result; + } + + /****************************************************************************************************/ + + template <typename Widget> + inline adobe::rectangle_t widget_best_bounds(Widget& w, const std::string& name) + { + std::vector<std::string> name_set; + + if (!name.empty()) + name_set.push_back(name); + + return widget_best_bounds(w, &name_set[0], &name_set[0] + name_set.size()); + } + + /****************************************************************************************************/ + + #if 0 + #pragma mark - + #endif + + /****************************************************************************************************/ + + void shed_fudges(const adobe::control_t& control, adobe::point_t& position, adobe::rectangle_t& geometry) + { + position.first = position.first - control.metrics_m(k_metric_fudge_left) - geometry.slice_m[adobe::rectangle_slices_t::horizontal].outset_m.first; + position.second = position.second - control.metrics_m(k_metric_fudge_top) - geometry.slice_m[adobe::rectangle_slices_t::vertical].outset_m.first; + + long outset_height( geometry.slice_m[adobe::rectangle_slices_t::vertical].outset_m.first + + geometry.slice_m[adobe::rectangle_slices_t::vertical].outset_m.second); + long outset_width( geometry.slice_m[adobe::rectangle_slices_t::horizontal].outset_m.first + + geometry.slice_m[adobe::rectangle_slices_t::horizontal].outset_m.second); + + geometry.height() += control.metrics_m(k_metric_fudge_height) + outset_height; + geometry.width() += control.metrics_m(k_metric_fudge_width) + outset_width; + } + + /****************************************************************************************************/ + } // namespace *************** *** 2347,2351 **** control_t::control_t() : ! control_m(0), focus_callback_ref_m(0), theme_m(theme_default_s) { } --- 2341,2345 ---- control_t::control_t() : ! control_m(0), focus_callback_ref_m(0), theme_m(theme_default_s), metrics_m(adobe::dictionary_t()) { } *************** *** 2353,2357 **** control_t::control_t(const control_t& rhs) : ! control_m(0), theme_m(rhs.theme_m), fudges_m(rhs.fudges_m) { } --- 2347,2351 ---- control_t::control_t(const control_t& rhs) : ! control_m(0), theme_m(rhs.theme_m), metrics_m(rhs.metrics_m) { } *************** *** 2387,2392 **** result.slice_m[rectangle_slices_t::vertical].poi_m.push_back(bounds.bottom - bounds.top + best_baseline); - apply_fudges(result, fudges_m); - return result; } --- 2381,2384 ---- *************** *** 2401,2405 **** rectangle_t geometry(geo); ! shed_fudges(position, geometry, fudges_m); Rect new_bounds = --- 2393,2397 ---- rectangle_t geometry(geo); ! shed_fudges(*this, position, geometry); Rect new_bounds = *************** *** 2439,2443 **** set_widget_data(control_m, kControlEntireControl, kControlFontStyleTag, new_style, false); - #if 0 try { --- 2431,2434 ---- *************** *** 2457,2461 **** catch (...) { } - #endif } --- 2448,2451 ---- *************** *** 2639,2643 **** assert(!control_m); ! fudges_m.bottom() = -1; ADOBE_REQUIRE_STATUS(::CreateGroupBoxControl( 0, &bounds, --- 2629,2633 ---- assert(!control_m); ! //fudges_m.bottom() = -1; ADOBE_REQUIRE_STATUS(::CreateGroupBoxControl( 0, &bounds, *************** *** 2705,2710 **** assert (!control_m); ! fudges_m.top() = 7; ! fudges_m.bottom() = -8; ControlTabSize size(kControlSizeNormal); --- 2695,2700 ---- assert (!control_m); ! //fudges_m.top() = 7; ! //fudges_m.bottom() = -8; ControlTabSize size(kControlSizeNormal); *************** *** 2916,2920 **** assert(first != last); ! fudges_m.bottom() = 1; std::copy(first, last, std::back_inserter<implementation_t::state_set_t>(state_set_m)); --- 2906,2910 ---- assert(first != last); ! //fudges_m.bottom() = 1; std::copy(first, last, std::back_inserter<implementation_t::state_set_t>(state_set_m)); *************** *** 3051,3062 **** radio_button_t::implementation_t::implementation_t() ! { ! // NOTE (fbrereto) : These fudges are different than checkbox fudges. ! fudges_m.top() = 2; ! fudges_m.left() = 2; ! fudges_m.bottom() = -5; ! fudges_m.right() = -4; ! fudges_m.baseline_m = -1; ! } /****************************************************************************************************/ --- 3041,3045 ---- radio_button_t::implementation_t::implementation_t() ! { } /****************************************************************************************************/ *************** *** 3089,3119 **** assert(control_m); ! rectangle_t result(_super::best_bounds()); ! ! if (get_control_title(control_m).empty()) ! { ! // No name? You'll get bogus measurements for the baseline. This fixes that. ! // also, the width is wrong; this fixes that, too. ! ! radio_button_t temp; ! ! temp.initialize("--"); ! ! temp.set_theme(theme_m); ! ! rectangle_t result2(temp.best_bounds()); ! ! points_of_interest_t& dst_poi(result.slice_m[rectangle_slices_t::vertical].poi_m); ! ! dst_poi = points_of_interest_t(); ! ! copy(result2.slice_m[rectangle_slices_t::vertical].poi_m, std::back_inserter(dst_poi)); ! ! if (dst_poi.size()) dst_poi[0] += fudges_m.baseline_m; // apply baseline adjustment to new baseline ! ! result.width() = result.height(); ! } ! ! return result; } --- 3072,3076 ---- assert(control_m); ! return widget_best_bounds(*this, get_control_title(control_m)); } *************** *** 3156,3167 **** checkbox_t::implementation_t::implementation_t() ! { ! // NOTE (fbrereto) : These fudges are different than radio_button fudges. ! fudges_m.top() = 3; ! fudges_m.left() = 2; ! fudges_m.bottom() = -7; ! fudges_m.right() = -4; ! fudges_m.baseline_m = -2; ! } /****************************************************************************************************/ --- 3113,3117 ---- checkbox_t::implementation_t::implementation_t() ! { } /****************************************************************************************************/ *************** *** 3193,3225 **** { assert(control_m); - #if 0 - return widget_measurement(*this); - #else - rectangle_t result(_super::best_bounds()); - - if (get_control_title(control_m).empty()) - { - // No name? You'll get bogus measurements for the baseline. This fixes that. - // also, the width is wrong; this fixes that, too. ! checkbox_t temp; ! ! temp.initialize("--"); ! ! temp.set_theme(theme_m); ! ! rectangle_t result2(temp.best_bounds()); ! ! points_of_interest_t& dst_poi(result.slice_m[rectangle_slices_t::vertical].poi_m); ! ! dst_poi = points_of_interest_t(); ! ! copy(result2.slice_m[rectangle_slices_t::vertical].poi_m, std::back_inserter(dst_poi)); ! ! result.width() = result.height(); ! } ! ! return result; ! #endif } --- 3143,3148 ---- { assert(control_m); ! return widget_best_bounds(*this, get_control_title(control_m)); } *************** *** 3499,3505 **** static_text_t::implementation_t::implementation_t() { ! fudges_m.top() = 2; ! fudges_m.bottom() = -4; ! fudges_m.baseline_m = -2; } --- 3422,3428 ---- static_text_t::implementation_t::implementation_t() { ! //fudges_m.top() = 2; ! //fudges_m.bottom() = -4; ! //fudges_m.baseline_m = -2; } *************** *** 3536,3541 **** rectangle_t result(get_text_dimensions(get_control_string(*this), theme_m)); - apply_fudges(result, fudges_m); - return result; } --- 3459,3462 ---- *************** *** 3693,3705 **** false, num_tags, &tags[0], &data[0])); ! fudges_m.top() = 3; ! fudges_m.left() = 3; ! fudges_m.bottom() = -6; ! fudges_m.right() = -6; } else { ! fudges_m.left() = 2; ! fudges_m.right() = -2; ADOBE_REQUIRE_STATUS(::CreateEditUnicodeTextControl(0, &bounds, CFSTR(""), --- 3614,3626 ---- false, num_tags, &tags[0], &data[0])); ! //fudges_m.top() = 3; ! //fudges_m.left() = 3; ! //fudges_m.bottom() = -6; ! //fudges_m.right() = -6; } else { ! //fudges_m.left() = 2; ! //fudges_m.right() = -2; ADOBE_REQUIRE_STATUS(::CreateEditUnicodeTextControl(0, &bounds, CFSTR(""), *************** *** 3719,3729 **** if (using_label_m) { - #if 0 - // This doesn't seem to do anything when enabled... - - get_label().implementation().fudges_m.left() += fudges_m.left(); - get_label().implementation().fudges_m.right() += fudges_m.right(); - #endif - get_label().initialize(name); get_label().adorn_theme(theme_adornment_label_s); --- 3640,3643 ---- *************** *** 3842,3846 **** if (scroll_control_m) { ! shed_fudges(position, geometry, fudges_m); Rect bounds = --- 3756,3760 ---- if (scroll_control_m) { ! shed_fudges(*this, position, geometry); Rect bounds = *************** *** 4040,4044 **** static_disabled_m(false), using_label_m(false), static_width_m(0) { ! fudges_m.bottom() = 1; } --- 3954,3958 ---- static_disabled_m(false), using_label_m(false), static_width_m(0) { ! //fudges_m.bottom() = 1; } *************** *** 4085,4090 **** if (!using_label_m) { ! fudges_m.left() = 1; ! fudges_m.right() = -1; } } --- 3999,4004 ---- if (!using_label_m) { ! //fudges_m.left() = 1; ! //fudges_m.right() = -1; } } *************** *** 4572,4608 **** ::SetControlReference(control_m, reinterpret_cast<SInt32>(this)); if (style == slider_points_not_s) { if (is_vertical) { ! fudges_m.left() = 3; ! fudges_m.right() = -10; } else { ! fudges_m.top() = 3; ! fudges_m.bottom() = -9; } } else if (style == slider_points_right_s) { ! fudges_m.left() = 2; ! fudges_m.right() = -6; } else if (style == slider_points_left_s) { ! fudges_m.left() = 8; ! fudges_m.right() = -10; } else if (style == slider_points_up_s) { ! fudges_m.top() = 8; ! fudges_m.bottom() = -9; } else if (style == slider_points_down_s) { ! fudges_m.top() = 2; ! fudges_m.bottom() = -5; } } --- 4486,4524 ---- ::SetControlReference(control_m, reinterpret_cast<SInt32>(this)); + #if 0 if (style == slider_points_not_s) { if (is_vertical) { ! //fudges_m.left() = 3; ! //fudges_m.right() = -10; } else { ! //fudges_m.top() = 3; ! //fudges_m.bottom() = -9; } } else if (style == slider_points_right_s) { ! //fudges_m.left() = 2; ! //fudges_m.right() = -6; } else if (style == slider_points_left_s) { ! //fudges_m.left() = 8; ! //fudges_m.right() = -10; } else if (style == slider_points_up_s) { ! //fudges_m.top() = 8; ! //fudges_m.bottom() = -9; } else if (style == slider_points_down_s) { ! //fudges_m.top() = 2; ! //fudges_m.bottom() = -5; } + #endif } |