From: Foster B. <fos...@us...> - 2006-01-24 19:39:06
|
Update of /cvsroot/adobe-source/sandbox/adobe-source/adobe/future/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12473/adobe-source/adobe/future/source Added Files: modal_dialog_interface.cpp Log Message: moved win/ directories to win32/ to anticipate a possible widgets port for WPF; added a 'mini-sheet' to Eve so you can save UI state information (what tab is currently selected) without mucking up your Adam model; started the modal_dialog_interface, an API that'll be used to direct a modal dialog interaction between the user and the application (it's still in its infancy); other misc bug fixes --- NEW FILE: modal_dialog_interface.cpp --- /* Copyright 2005-2006 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 <adobe/future/modal_dialog_interface.hpp> #include <adobe/adam_evaluate.hpp> #include <adobe/adam_parser.hpp> #include <adobe/future/widgets/headers/client_assembler.hpp> #include <adobe/future/widgets/headers/factory.hpp> #if ADOBE_PLATFORM_MAC #include <adobe/future/widgets/headers/mac/carbon_safe.hpp> #elif ADOBE_PLATFORM_WIN #define WINDOWS_LEAN_AND_MEAN 1 #include <windows.h> #include <adobe/future/widgets/headers/win32/event_dispatcher.hpp> #endif /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ std::string getline(std::istream& stream) { std::string result; result.reserve(128); while (true) { int c(stream.get()); if (c == EOF || c == '\n' || c == '\r') break; result += static_cast<char>(c); } return result; } /****************************************************************************************************/ std::string mdi_getline(std::istream& layout_definition, adobe::name_t, std::streampos line_start_position) { std::streampos old_pos(layout_definition.tellg()); layout_definition.clear(); layout_definition.seekg(line_start_position); std::string result(getline(layout_definition)); layout_definition.seekg(old_pos); return result; } /****************************************************************************************************/ struct mdi_op_callback_t { typedef void result_type; mdi_op_callback_t() : view_m(0) { } void callback(adobe::name_t, const adobe::value_t&) try { assert(view_m); // system_beep(); // unknown request. #if ADOBE_PLATFORM_MAC HIViewRef cntl(adobe::unwrap_display_token<HIViewRef>(view_m->root_display_m)); WindowRef owner(::GetControlOwner(cntl)); ::QuitAppModalLoopForWindow(owner); #elif ADOBE_PLATFORM_WIN ::PostQuitMessage(0); #endif } catch(...) { std::cerr << "Exception caught in mdi_op_callback" << std::endl; } eve_client::eve_client_holder* view_m; }; /****************************************************************************************************/ void monitor_invariant(bool& need_ui, bool is_set) { need_ui = !is_set; } /****************************************************************************************************/ adobe::dialog_result_t handle_dialog( const adobe::dictionary_t& input, const adobe::record_info_t& record, const adobe::dictionary_t& display_state, adobe::display_options_t display_options, std::istream& layout_definition, std::istream& sheet_definition) { assert ( !layout_definition.fail() ); assert ( !sheet_definition.fail() ); adobe::dialog_result_t result; adobe::sheet_t sheet; adobe::auto_ptr<eve_client::eve_client_holder> view; mdi_op_callback_t view_callback; // // Parse the Adam stream // adobe::parse( sheet_definition, adobe::line_position_t( "Adam sheet definition" ), adobe::bind_to_sheet( sheet ) ); // // Set up the sheet with initial inputs, etc. // for (adobe::dictionary_t::const_iterator first(input.begin()), last(input.end()); first != last; ++first) sheet.set(first->first, first->second); for (adobe::dictionary_t::const_iterator first(record.first.begin()), last(record.first.end()); first != last; ++first) sheet.set(first->first, first->second); if (!record.second.empty()) { std::vector<adobe::name_t> touch_set; for (adobe::array_t::const_iterator first(record.second.begin()), last(record.second.end()); first != last; ++first) touch_set.push_back(first->get<adobe::name_t>()); const adobe::name_t* touch_first(&touch_set.front()); const adobe::name_t* touch_last(&touch_set.back()); sheet.touch(touch_first, ++touch_last); } bool need_ui(false); sheet.monitor_invariant_dependent(adobe::static_name_t("result"), boost::bind(&monitor_invariant, boost::ref(need_ui), _1)); sheet.update(); if (display_options == dialog_never_display_s && need_ui) throw std::runtime_error("handle_dialog: Invalid command parameters and UI not permitted."); if ((display_options == dialog_no_display_s && need_ui) || display_options == dialog_display_s) { line_position_t::getline_proc_t getline_proc(new line_position_t::getline_proc_impl_t(boost::bind(&mdi_getline, boost::ref(layout_definition), _1, _2))); view.reset(eve_client::make_view( adobe::name_t( "eve definition" ), getline_proc, layout_definition, sheet, boost::bind(&mdi_op_callback_t::callback, boost::ref(view_callback), _1, _2), size_normal_s, default_factory ).release() ); view_callback.view_m = view.get(); // // Set up the view's sheet with display state values, etc. // for (adobe::dictionary_t::const_iterator first(display_state.begin()), last(display_state.end()); first != last; ++first) view->layout_sheet_m.set(first->first, first->second); sheet.update(); // // Show the GUI. // view->eve_m.evaluate(adobe::eve_t::evaluate_nested); view->show_window_m(); #if ADOBE_PLATFORM_MAC HIViewRef cntl(adobe::unwrap_display_token<HIViewRef>(view->root_display_m)); WindowRef owner(::GetControlOwner(cntl)); ::RunAppModalLoopForWindow(owner); #elif ADOBE_PLATFORM_WIN MSG msg; while ( ::GetMessage( &msg, 0, 0, 0 ) ) { try { // // Push every message through the event_dispatcher, in case it is a keyboard // modifier. // event_dispatcher::keyboard(msg.message, msg.wParam); // // We always pass every message though to the application anyway. // TranslateMessage( &msg ); DispatchMessage( &msg ); } catch ( const std::exception& doh ) { std::cerr << "Exception: " << doh.what() << std::endl; } catch ( ... ) { std::cerr << "Exception: Unknown" << std::endl; } } #endif } return result; } /****************************************************************************************************/ } // namespace adobe /****************************************************************************************************/ |