|
From: Foster B. <fos...@us...> - 2006-02-03 18:34:26
|
Update of /cvsroot/adobe-source/sandbox/adobe-source/adobe/test/begin/sources/mac In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6755/adobe/test/begin/sources/mac Modified Files: main.cpp Log Message: asl 1.0.13 Index: main.cpp =================================================================== RCS file: /cvsroot/adobe-source/sandbox/adobe-source/adobe/test/begin/sources/mac/main.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** main.cpp 24 Jan 2006 19:38:50 -0000 1.4 --- main.cpp 3 Feb 2006 18:33:39 -0000 1.5 *************** *** 1,6 **** /* ! 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) */ /****************************************************************************************************/ --- 1,6 ---- /* ! 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) */ /****************************************************************************************************/ *************** *** 19,40 **** /****************************************************************************************************/ ! #define kHICommandRefreshView 'Reld' ! #define kHICommandRefreshSheet 'RfsS' ! #define kHICommandNormalDialogSize 'NrSz' ! #define kHICommandSmallDialogSize 'SmSz' ! #define kHICommandMiniDialogSize 'MnSz' ! #define kHICommandFrameWidgets 'TgFm' ! #define kHICommandClearWidgetFrames 'ClFr' ! #define kHICommandSerializeWidgets 'SzWg' ! #define kHICommandRunModal 'dlog' ! #define kHICommandLocalizationENUS 'enus' ! #define kHICommandLocalizationDEDE 'dede' ! #define kHICommandLocalizationJAJP 'jajp' ! #define kHICommandLocalizationKOKR 'kokr' ! #define kHICommandLocalizationPGPG 'pgpg' ! const CFStringRef kMainNibFileName (CFSTR( "begin" )); ! const CFStringRef kMenuBarNibName (CFSTR( "MenuBar" )); /****************************************************************************************************/ --- 19,40 ---- /****************************************************************************************************/ ! #define kHICommandRefreshView 'Reld' ! #define kHICommandRefreshSheet 'RfsS' ! #define kHICommandNormalDialogSize 'NrSz' ! #define kHICommandSmallDialogSize 'SmSz' ! #define kHICommandMiniDialogSize 'MnSz' ! #define kHICommandFrameWidgets 'TgFm' ! #define kHICommandClearWidgetFrames 'ClFr' ! #define kHICommandSerializeWidgets 'SzWg' ! #define kHICommandRunModal 'dlog' ! #define kHICommandLocalizationENUS 'enus' ! #define kHICommandLocalizationDEDE 'dede' ! #define kHICommandLocalizationJAJP 'jajp' ! #define kHICommandLocalizationKOKR 'kokr' ! #define kHICommandLocalizationPGPG 'pgpg' ! const CFStringRef kMainNibFileName (CFSTR( "begin" )); ! const CFStringRef kMenuBarNibName (CFSTR( "MenuBar" )); /****************************************************************************************************/ *************** *** 53,77 **** /// 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); ! OSStatus 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 ); } --- 53,77 ---- /// 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); ! OSStatus 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 ); } *************** *** 83,131 **** void OpenTheDocuments(AEDescList* documents) { ! adobe::application_t* theApp = adobe::application_t::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(); } --- 83,131 ---- void OpenTheDocuments(AEDescList* documents) { ! adobe::application_t* theApp = adobe::application_t::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(); } *************** *** 135,172 **** /// 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 } --- 135,172 ---- /// 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 } *************** *** 176,302 **** /// Handle commands coming from the menubar. /// ! /// \param handler the next handler to call. ! /// \param event description of the event. ! /// \param data the application_t we need to communicate with. // static pascal OSStatus menu_command( EventHandlerCallRef /*handler*/, EventRef event, void* data ) try { ! adobe::application_t* theApp( static_cast<adobe::application_t*>( 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 kHICommandRefreshSheet: ! theApp->load_sheet(); ! break; ! case kHICommandSerializeWidgets: ! theApp->serialize_connections(); ! break; ! case kHICommandRunModal: ! theApp->run_current_as_modal(); ! break; ! case kHICommandLocalizationENUS: ! adobe::implementation::top_frame().attribute_set_m.insert( ! std::make_pair(adobe::static_token_range("lang"), adobe::static_token_range("en-us"))); ! theApp->display_window(); ! break; ! case kHICommandLocalizationDEDE: ! adobe::implementation::top_frame().attribute_set_m.insert( ! std::make_pair(adobe::static_token_range("lang"), adobe::static_token_range("de-de"))); ! theApp->display_window(); ! break; ! case kHICommandLocalizationJAJP: ! adobe::implementation::top_frame().attribute_set_m.insert( ! std::make_pair(adobe::static_token_range("lang"), adobe::static_token_range("ja-jp"))); ! theApp->display_window(); ! break; ! case kHICommandLocalizationKOKR: ! adobe::implementation::top_frame().attribute_set_m.insert( ! std::make_pair(adobe::static_token_range("lang"), adobe::static_token_range("ko-kr"))); ! theApp->display_window(); ! break; ! case kHICommandLocalizationPGPG: ! adobe::implementation::top_frame().attribute_set_m.insert( ! std::make_pair(adobe::static_token_range("lang"), adobe::static_token_range("pg-pg"))); ! theApp->display_window(); ! 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; } --- 176,302 ---- /// Handle commands coming from the menubar. /// ! /// \param handler the next handler to call. ! /// \param event description of the event. ! /// \param data the application_t we need to communicate with. // static pascal OSStatus menu_command( EventHandlerCallRef /*handler*/, EventRef event, void* data ) try { ! adobe::application_t* theApp( static_cast<adobe::application_t*>( 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 kHICommandRefreshSheet: ! theApp->load_sheet(); ! break; ! case kHICommandSerializeWidgets: ! theApp->serialize_connections(); ! break; ! case kHICommandRunModal: ! theApp->run_current_as_modal(); ! break; ! case kHICommandLocalizationENUS: ! adobe::implementation::top_frame().attribute_set_m.insert( ! std::make_pair(adobe::static_token_range("lang"), adobe::static_token_range("en-us"))); ! theApp->display_window(); ! break; ! case kHICommandLocalizationDEDE: ! adobe::implementation::top_frame().attribute_set_m.insert( ! std::make_pair(adobe::static_token_range("lang"), adobe::static_token_range("de-de"))); ! theApp->display_window(); ! break; ! case kHICommandLocalizationJAJP: ! adobe::implementation::top_frame().attribute_set_m.insert( ! std::make_pair(adobe::static_token_range("lang"), adobe::static_token_range("ja-jp"))); ! theApp->display_window(); ! break; ! case kHICommandLocalizationKOKR: ! adobe::implementation::top_frame().attribute_set_m.insert( ! std::make_pair(adobe::static_token_range("lang"), adobe::static_token_range("ko-kr"))); ! theApp->display_window(); ! break; ! case kHICommandLocalizationPGPG: ! adobe::implementation::top_frame().attribute_set_m.insert( ! std::make_pair(adobe::static_token_range("lang"), adobe::static_token_range("pg-pg"))); ! theApp->display_window(); ! 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; } *************** *** 318,325 **** struct delete_ptr<AEEventHandlerUPP> { ! void operator()( AEEventHandlerUPP x ) const ! { ! if( x ) DisposeAEEventHandlerUPP( x ); ! } }; --- 318,325 ---- struct delete_ptr<AEEventHandlerUPP> { ! void operator()( AEEventHandlerUPP x ) const ! { ! if( x ) DisposeAEEventHandlerUPP( x ); ! } }; *************** *** 329,336 **** struct delete_ptr<EventHandlerUPP> { ! void operator()( EventHandlerUPP x ) const ! { ! if( x ) DisposeEventHandlerUPP( x ); ! } }; --- 329,336 ---- struct delete_ptr<EventHandlerUPP> { ! void operator()( EventHandlerUPP x ) const ! { ! if( x ) DisposeEventHandlerUPP( x ); ! } }; *************** *** 339,395 **** bool os_initialize( adobe::application_t* 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 ); ! // ! // Register this app as an Appearance Client ! // ! RegisterAppearanceClient(); ! return true; } --- 339,395 ---- bool os_initialize( adobe::application_t* 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 ); ! // ! // Register this app as an Appearance Client ! // ! RegisterAppearanceClient(); ! return true; } *************** *** 398,402 **** void os_mainloop() { ! RunApplicationEventLoop(); } --- 398,402 ---- void os_mainloop() { ! RunApplicationEventLoop(); } *************** *** 405,409 **** void os_end_mainloop() { ! QuitApplicationEventLoop(); } --- 405,409 ---- void os_end_mainloop() { ! QuitApplicationEventLoop(); } *************** *** 416,431 **** int main() { ! try ! { ! adobe::application_t* theApp = adobe::application_t::getInstance(); ! if( theApp ) theApp->run(); ! } ! catch( ... ) ! { ! adobe::report_exception(); ! } ! return 0; } --- 416,431 ---- int main() { ! try ! { ! adobe::application_t* theApp = adobe::application_t::getInstance(); ! if( theApp ) theApp->run(); ! } ! catch( ... ) ! { ! adobe::report_exception(); ! } ! return 0; } |