|
From: Foster B. <fos...@us...> - 2005-04-18 21:16:15
|
Update of /cvsroot/adobe-source/sandbox/visual_refactor/adobe/test/visual/sources/mac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27679/adobe/test/visual/sources/mac Added Files: display.cpp main.cpp metrics.cpp ui_core_implementation.cpp Log Message: SO SORRY for the large qty of emails -- creating a branch for Adobe Begin refactoring. --- NEW FILE: display.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 "display.hpp" #include "carbon_safe.hpp" #include "report_exception.hpp" /****************************************************************************************************/ namespace { /****************************************************************************************************/ struct view_wrap { explicit view_wrap(HIViewRef ref) : ref_m(ref) { } HIViewRef ref_m; }; /****************************************************************************************************/ HIViewRef unwrap(adobe::display_t::position_t& position) { return (boost::any_cast<view_wrap>(position)).ref_m; } /****************************************************************************************************/ adobe::display_t::position_t wrap(HIViewRef view) { return adobe::display_t::position_t(view_wrap(view)); } /****************************************************************************************************/ } // namespace /****************************************************************************************************/ #if 0 #pragma mark - #endif /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ struct root_token { }; /****************************************************************************************************/ display_t& get_main_display() { static display_t display_s; return display_s; } /****************************************************************************************************/ struct display_t::implementation_t { void erase(display_t::position_t& position); std::vector<HIViewRef> roots_m; }; /****************************************************************************************************/ template <typename DisplayElement> display_t::position_t insert(display_t& display, display_t::position_t& position, DisplayElement& element) { return display.insert(position, element); } /****************************************************************************************************/ #if 0 #pragma mark - #endif /****************************************************************************************************/ display_t::display_t() : object_m(new implementation_t()) { } display_t::~display_t() { delete object_m; object_m = 0; } display_t::implementation_t& display_t::implementation() { return *object_m; } const display_t::implementation_t& display_t::implementation() const { return *object_m; } display_t::position_t display_t::root() { return display_t::position_t(root_token()); } void display_t::erase(position_t& position) { return object_m->erase(position); } template <typename DisplayElement> display_t::position_t display_t::insert(position_t& parent, DisplayElement& element) { return insert(parent, adobe::view_for_element<HIViewRef>(element)); } /****************************************************************************************************/ template <> display_t::position_t display_t::insert<HIViewRef>(position_t& parent, HIViewRef& element) { if (parent.type() == typeid(view_wrap)) { HIViewRef parent_view(unwrap(parent)); ADOBE_REQUIRE_STATUS(::HIViewAddSubview(parent_view, element)); } else if (parent.type() == typeid(root_token)) { object_m->roots_m.push_back(element); } return wrap(element); } /****************************************************************************************************/ #if 0 #pragma mark - #endif /****************************************************************************************************/ void display_t::implementation_t::erase(display_t::position_t&) { // REVISIT (fbrereto) : What should we do here? // 1) Call DetachSubView on the position? // 2) Call erase recursively for all children of the position? // 3) Invalidate (wipe) the position data? // 4) Invoke some (currently nonexistent) detach() callback for the client? // 4a) With what parameters, considering questions 1, 2, & 3? } /****************************************************************************************************/ } // namespace adobe /****************************************************************************************************/ --- 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/name.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 std::string& xstr, const dictionary_t& context) { dictionary_t result; try { const char* cxstr(xstr.c_str()); std::size_t n(xstr.size()); std::stringstream expression_stream(std::string(xstr_t(cxstr, n, 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 /****************************************************************************************************/ --- 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 <adobe/xstr.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; } /****************************************************************************************************/ --- NEW FILE: ui_core_implementation.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 "ui_core_implementation.hpp" #include "ui_core_common.hpp" #include "carbon_safe.hpp" #include "report_exception.hpp" #include "display.hpp" #include "metrics.hpp" #include <adobe/algorithm.hpp> #include <adobe/array.hpp> #include <adobe/dictionary.hpp> [...5130 lines suppressed...] ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(group_t); ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(tab_group_t); ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(panel_t); ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(radio_button_t); ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(checkbox_t); ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(link_t); 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(slider_t); ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(bevel_button_t); #ifndef NDEBUG ADOBE_VIEW_FOR_ELEMENT_AND_INSERT_BOILERPLATE_SPECIALIZATION(hitless_t); #endif // NDEBUG /****************************************************************************************************/ } // namespace adobe /****************************************************************************************************/ |