|
From: Foster B. <fos...@us...> - 2005-04-02 05:48:06
|
Update of /cvsroot/adobe-source/adobe-source/adobe/test/visual/sources/mac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17172/adobe/test/visual/sources/mac Modified Files: ui_core_implementation.cpp Added Files: main.cpp Log Message: asl 1.0.2 --- NEW FILE: main.cpp --- /* Copyright 2005 Ralph Thomas Distributed under the MIT License (see accompanyinf file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /****************************************************************************************************/ #include "express_viewer.hpp" #include "report_exception.hpp" #include "carbon_safe.hpp" #include <boost/filesystem/convenience.hpp> #include <sstream> #include <string> /****************************************************************************************************/ #define kHICommandRefreshView 'Reld' #define kHICommandRefreshSheet 'RfsS' #define kHICommandNormalDialogSize 'NrSz' #define kHICommandSmallDialogSize 'SmSz' #define kHICommandMiniDialogSize 'MnSz' #define kHICommandFrameWidgets 'TgFm' #define kHICommandClearWidgetFrames 'ClFr' #define kHICommandSerializeWidgets 'SzWg' const CFStringRef kMainNibFileName (CFSTR( "Begin" )); const CFStringRef kMenuBarNibName (CFSTR( "MenuBar" )); /****************************************************************************************************/ namespace bfs = boost::filesystem; /****************************************************************************************************/ namespace { /****************************************************************************************************/ // /// Convert a MacOS FSRef into a Boost path. This allows us to use the /// boost::filesystem library to perform operations on the path, rather /// than using the FSRef API. /// /// \param location the FSRef to make into a bfs::path /// \return a bfs path of the given location. // boost::filesystem::path fsref_to_path( const FSRef& location ) { std::size_t max_size (1024); std::vector<char> path_buffer(max_size); OSErr error (noErr); while (true) { error = FSRefMakePath(&location, reinterpret_cast<UInt8*>(&path_buffer[0]), max_size); if (error != pathTooLongErr) break; max_size *= 2; path_buffer.resize(max_size); } ADOBE_REQUIRE_STATUS(error); return boost::filesystem::path( &path_buffer[0], boost::filesystem::native ); } /****************************************************************************************************/ // /// Attempt to open the documents in the given AEDescList. // void OpenTheDocuments(AEDescList* documents) { adobe::simpleApplication* theApp = adobe::simpleApplication::getInstance(); long doc_count; FSRef file; AEKeyword keyword; DescType type_code; Size actual_size; ADOBE_REQUIRE_STATUS(AECountItems(documents, &doc_count)); bool is_adam (false); bool is_eve (false); for (long i = 1 ; i <= doc_count; ++i) { /* get the i'th FSSpec record. NOTE: implicity, we are calling a coercion handler because this list actually contains alias records. In particular, the coercion handler converts them from alias records into FSSpec records. */ ADOBE_REQUIRE_STATUS(AEGetNthPtr(documents, i, typeFSRef, &keyword, &type_code, (Ptr) &file, sizeof(file), (actual_size = sizeof(file), &actual_size))); // // We need to get the directory name and the file name of the document // which we have been asked to open. // bfs::path file_name( fsref_to_path( file ) ); std::string extension( boost::filesystem::extension( file_name ) ); if (extension == ".eve") { theApp->set_eve_file( file_name ); is_eve = true; } else if (extension == ".adm") { theApp->set_adam_file( file_name ); is_adam = true; } } if (is_adam) theApp->load_sheet(); // will display window else if (is_eve) theApp->display_window(); } /****************************************************************************************************/ // /// Handle "open documents" requests coming from AppleEvents. /// /// \param appleEvt the apple event to respond to. /// \param reply the default reply event /// \param ref the AE dispatch table.. // pascal OSErr handle_open( const AppleEvent* appleEvt, AppleEvent* /*reply*/, long /*ref*/ ) try { OSErr error; AEDescList documents; // // Allocate AEDescList's internals. // AECreateDesc( typeNull, 0, 0, &documents ); // // Try to get the list of documents to open. // error = AEGetParamDesc( appleEvt, keyDirectObject, typeAEList, &documents ); if( error == noErr ) OpenTheDocuments( &documents ); // // Release the document list and return. // AEDisposeDesc( &documents ); return error; } catch( ... ) { adobe::report_exception(); return -1; // REVISIT } /****************************************************************************************************/ // /// Handle commands coming from the menubar. /// /// \param handler the next handler to call. /// \param event description of the event. /// \param data the simpleApplication we need to communicate with. // static pascal OSStatus menu_command( EventHandlerCallRef /*handler*/, EventRef event, void* data ) try { adobe::simpleApplication* theApp( static_cast<adobe::simpleApplication*>( data ) ); OSStatus result( noErr ); HICommand command; // // We can't do anything without a pointer to the application // object. // if( !theApp ) return eventNotHandledErr; if( GetEventParameter( event, kEventParamDirectObject, typeHICommand, 0, sizeof( command ), 0, &command ) ) return eventNotHandledErr; // // Figure out what we're meant to do. // switch( command.commandID ) { #ifndef NDEBUG case kHICommandFrameWidgets: theApp->frame_window(); break; case kHICommandClearWidgetFrames: theApp->clear_window_frames(); break; #else case kHICommandFrameWidgets: case kHICommandClearWidgetFrames: adobe::system_beep(); break; #endif case kHICommandNormalDialogSize: theApp->set_dialog_size( size_normal_s ); theApp->display_window(); break; case kHICommandSmallDialogSize: theApp->set_dialog_size( size_small_s ); theApp->display_window(); break; case kHICommandMiniDialogSize: theApp->set_dialog_size( size_mini_s ); theApp->display_window(); break; case kHICommandRefreshView: theApp->display_window(); break; case kHICommandSerializeWidgets: theApp->serialize_connections(); break; case kHICommandSave: case kHICommandSaveAs: case kHICommandClose: case kHICommandNew: case kHICommandOpen: case kHICommandPageSetup: case kHICommandPrint: adobe::system_beep(); break; default: result = eventNotHandledErr; break; } return result; } catch( ... ) { adobe::report_exception(); return eventNotHandledErr; } /****************************************************************************************************/ } // namespace /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ // /// These template ensures that the static auto_ptr event handlers get /// released when the app closes. // template<> struct adobe::delete_ptr<AEEventHandlerUPP> { void operator()( AEEventHandlerUPP x ) const { if( x ) DisposeAEEventHandlerUPP( x ); } }; /****************************************************************************************************/ template<> struct adobe::delete_ptr<EventHandlerUPP> { void operator()( EventHandlerUPP x ) const { if( x ) DisposeEventHandlerUPP( x ); } }; /****************************************************************************************************/ bool os_initialize( adobe::simpleApplication* theApp ) { // // On the Mac we need to install the application menus, respond // to AppleEvents and set the resource path. We set the resource // path first. // ProcessSerialNumber psn; ADOBE_REQUIRE_STATUS( GetCurrentProcess( &psn ) ); FSRef location; ADOBE_REQUIRE_STATUS( GetProcessBundleLocation( &psn, &location ) ); theApp->set_resource_directory( fsref_to_path( location ) / "Contents/Resources" ); // // Now load our bundle, sign up for AppleEvents and show the menu. // CFBundleRef bundle = CFBundleGetMainBundle(); IBNibRef nibs = 0; if( !bundle ) return false; ADOBE_REQUIRE_STATUS( CreateNibReferenceWithCFBundle( bundle, kMainNibFileName, &nibs ) ); if( !nibs ) { ::CFRelease( bundle ); return false; } // // Sign up to handle the "Open" AppleEvent. // static adobe::auto_resource<AEEventHandlerUPP> ae_handler( NewAEEventHandlerUPP( handle_open ) ); AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments, ae_handler.get(), 0, false ); // // Install the menu, and it's event handler. // ADOBE_REQUIRE_STATUS( SetMenuBarFromNib( nibs, kMenuBarNibName ) ); static EventTypeSpec hi_event = { kEventClassCommand, kHICommandFromMenu }; static adobe::auto_resource<EventHandlerUPP> hi_handler( NewEventHandlerUPP( menu_command ) ); InstallApplicationEventHandler( hi_handler.get(), 1, &hi_event, theApp, 0 ); // // Now that we've finished initializing we can set the cursor to // a pointy arrow (instead of the hourglass). // InitCursor(); // // Register this app as an Appearance Client // RegisterAppearanceClient(); return true; } /****************************************************************************************************/ void os_mainloop() { RunApplicationEventLoop(); } /****************************************************************************************************/ void os_end_mainloop() { QuitApplicationEventLoop(); } /****************************************************************************************************/ } /****************************************************************************************************/ int main() { try { adobe::simpleApplication* theApp = adobe::simpleApplication::getInstance(); if( theApp ) theApp->run(); } catch( ... ) { adobe::report_exception(); } return 0; } /****************************************************************************************************/ Index: ui_core_implementation.cpp =================================================================== RCS file: /cvsroot/adobe-source/adobe-source/adobe/test/visual/sources/mac/ui_core_implementation.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ui_core_implementation.cpp 17 Mar 2005 18:03:20 -0000 1.1 --- ui_core_implementation.cpp 2 Apr 2005 05:47:39 -0000 1.2 *************** *** 13,21 **** #include "display.hpp" - #include <adobe/value.hpp> - #include <adobe/future/memory.hpp> - #include <adobe/future/enum_ops.hpp> #include <adobe/algorithm.hpp> #include <adobe/dictionary.hpp> #include <boost/type_traits.hpp> --- 13,23 ---- #include "display.hpp" #include <adobe/algorithm.hpp> + #include <adobe/array.hpp> #include <adobe/dictionary.hpp> + #include <adobe/value.hpp> + + #include <adobe/future/enum_ops.hpp> + #include <adobe/future/memory.hpp> #include <boost/type_traits.hpp> *************** *** 25,28 **** --- 27,34 ---- /****************************************************************************************************/ + namespace adobe { + + /****************************************************************************************************/ + /* REVIST (sparent) : Need to file a bug report on this with Apple. Our default bounds is large *************** *** 36,39 **** --- 42,49 ---- /****************************************************************************************************/ + } // namespace adobe + + /****************************************************************************************************/ + enum metrics { gap = 6 // Measured as space from popup to label. *************** *** 46,49 **** --- 56,144 ---- /****************************************************************************************************/ + #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 + + /****************************************************************************************************/ + std::string cfstring_to_string(CFStringRef x) { *************** *** 66,70 **** adobe::auto_resource<CFStringRef> string_to_cfstring(const std::string& x) { ! return adobe::auto_resource<CFStringRef>(::CFStringCreateWithCString(NULL, x.c_str(), kCFStringEncodingUTF8)); } --- 161,167 ---- adobe::auto_resource<CFStringRef> string_to_cfstring(const std::string& x) { ! adobe::auto_resource<CFStringRef> convertedString(::CFStringCreateWithCString(NULL, x.c_str(), kCFStringEncodingUTF8)); ! ! return convertedString; } *************** *** 196,199 **** --- 293,310 ---- /****************************************************************************************************/ + + // REVISIT (sparent) : This seems useful enough that we might want to move it into array.hpp + + template <typename T1, typename T2> + inline adobe::array_t make_array(std::pair<T1, T2> p) + { + adobe::array_t a; + a.push_back(p.first); + a.push_back(p.second); + return a; + } + + /****************************************************************************************************/ + adobe::dictionary_t rectangle_slice_to_dictionary(const adobe::rectangle_t::slice_t& s) { *************** *** 208,211 **** --- 319,323 ---- if (s.poi_m.size()) { + #if 0 adobe::points_of_interest_t::const_iterator first(s.poi_m.begin()); adobe::points_of_interest_t::const_iterator last(s.poi_m.end()); *************** *** 213,217 **** for (; first != last; ++first) ! poi_array = adobe::array_push_back(poi_array, adobe::value_t(*first)); result.set(adobe::static_name_t("poi_set"), poi_array); --- 325,334 ---- for (; first != last; ++first) ! poi_array.push_back(*first); ! #endif ! ! adobe::array_t poi_array; ! ! adobe::copy(s.poi_m, poi_array.back_inserter()); result.set(adobe::static_name_t("poi_set"), poi_array); *************** *** 220,231 **** if (s.outset_m.first || s.outset_m.second) { ! adobe::array_t empty; ! result.set(adobe::static_name_t("outset"), adobe::array_push_back(adobe::array_push_back(empty, s.outset_m.first), s.outset_m.second)); } if (s.frame_m.first || s.outset_m.second) { ! adobe::array_t empty; ! result.set(adobe::static_name_t("frame"), adobe::array_push_back(adobe::array_push_back(empty, s.frame_m.first), s.frame_m.second)); } --- 337,346 ---- if (s.outset_m.first || s.outset_m.second) { ! result.set(adobe::static_name_t("outset"), make_array(s.outset_m)); } if (s.frame_m.first || s.outset_m.second) { ! result.set(adobe::static_name_t("frame"), make_array(s.frame_m)); } *************** *** 233,237 **** { adobe::array_t empty; ! result.set(adobe::static_name_t("inset"), adobe::array_push_back(adobe::array_push_back(empty, s.inset_m.first), s.inset_m.second)); } --- 348,352 ---- { adobe::array_t empty; ! result.set(adobe::static_name_t("inset"), make_array(s.inset_m)); } *************** *** 290,298 **** geometry.slice_m[adobe::rectangle_slices_t::horizontal].length_m += fudges.left() + fudges.right(); ! // why did we do this? ! //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(); adobe::points_of_interest_t& poi(geometry.slice_m[adobe::rectangle_slices_t::vertical].poi_m); --- 405,414 ---- 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); *************** *** 307,311 **** position.second -= fudges.top(); position.first -= fudges.left(); ! geometry.height() -= fudges.bottom(); geometry.width() -= fudges.right(); --- 423,427 ---- position.second -= fudges.top(); position.first -= fudges.left(); ! geometry.height() -= fudges.bottom(); geometry.width() -= fudges.right(); *************** *** 2282,2287 **** assert(control_m); ! point_t position(pos); ! rectangle_t geometry(geo); shed_fudges(position, geometry, fudges_m); --- 2398,2403 ---- assert(control_m); ! point_t position(pos); ! rectangle_t geometry(geo); shed_fudges(position, geometry, fudges_m); *************** *** 2322,2325 **** --- 2438,2461 ---- set_widget_data(control_m, kControlEntireControl, kControlFontStyleTag, new_style, false); + + #if 0 + try + { + ControlSize control_size(kControlSizeNormal); + + switch ( theme & theme_mask_s ) + { + case theme_large_s: control_size = kControlSizeLarge; break; + //case theme_normal_s: control_size = kControlSizeNormal; break; + case theme_small_s: control_size = kControlSizeSmall; break; + case theme_mini_s: control_size = kControlSizeMini; break; + } + + // could throw -- we don't care + set_widget_data(control_m, kControlEntireControl, kControlSizeTag, control_size); + } + catch (...) + { } + #endif } *************** *** 2678,2683 **** dict.set(static_name_t("name"), first->name_m); dict.set(static_name_t("value"), first->value_m); ! ! tab_array = array_push_back(tab_array, adobe::value_t(dict)); } --- 2814,2819 ---- dict.set(static_name_t("name"), first->name_m); dict.set(static_name_t("value"), first->value_m); ! ! tab_array.push_back(dict); } *************** *** 2896,2901 **** dict.set(static_name_t("modifiers"), first->modifiers_m); dict.set(static_name_t("value"), first->value_m); ! ! state_array = array_push_back(state_array, adobe::value_t(dict)); } --- 3032,3037 ---- dict.set(static_name_t("modifiers"), first->modifiers_m); dict.set(static_name_t("value"), first->value_m); ! ! state_array.push_back(dict); } *************** *** 3057,3062 **** { assert(control_m); ! ! rectangle_t result(_super::best_bounds()); if (get_control_title(control_m).empty()) --- 3193,3200 ---- { assert(control_m); ! #if 0 ! return widget_measurement(*this); ! #else ! rectangle_t result(_super::best_bounds()); if (get_control_title(control_m).empty()) *************** *** 3071,3075 **** 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); --- 3209,3213 ---- 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); *************** *** 3083,3086 **** --- 3221,3225 ---- return result; + #endif } *************** *** 4176,4180 **** dict.set(static_name_t("value"), first->second); ! popup_array = array_push_back(popup_array, adobe::value_t(dict)); } --- 4315,4319 ---- dict.set(static_name_t("value"), first->second); ! popup_array.push_back(dict); } *************** *** 4926,4929 **** --- 5065,5072 ---- { return element; } + template <> + HIViewRef view_for_element<HIViewRef, window_t>(window_t& element) + { return element.implementation().root_control_m.control_m; } + /****************************************************************************************************/ /* Macros to define default functionality for display mechanism hook-up */ *************** *** 4944,4955 **** /****************************************************************************************************/ /* Non-default specialization for window_t */ ADOBE_INSERT_BOILERPLATE_SPECIALIZATION(window_t); - template <> - HIViewRef view_for_element<HIViewRef, window_t>(window_t& element) - { return element.implementation().root_control_m.control_m; } - /****************************************************************************************************/ /* Non-default specialization for edit_text_t */ --- 5087,5098 ---- /****************************************************************************************************/ + + ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(static_text_t); + + /****************************************************************************************************/ /* Non-default specialization for window_t */ ADOBE_INSERT_BOILERPLATE_SPECIALIZATION(window_t); /****************************************************************************************************/ /* Non-default specialization for edit_text_t */ *************** *** 5060,5064 **** ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(progress_bar_t); ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(separator_t); - ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(static_text_t); ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(slider_t); ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(bevel_button_t); --- 5203,5206 ---- |