|
From: Foster B. <fos...@us...> - 2005-04-18 21:16:17
|
Update of /cvsroot/adobe-source/sandbox/visual_refactor/adobe/test/visual/headers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27679/adobe/test/visual/headers Added Files: client_assembler.hpp display.hpp express_viewer.hpp latch.hpp optional_connect.hpp report_exception.hpp ui_core.hpp ui_core_common.hpp Log Message: SO SORRY for the large qty of emails -- creating a branch for Adobe Begin refactoring. --- NEW FILE: ui_core_common.hpp --- /* 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) */ /****************************************************************************************************/ #ifndef ADOBE_UI_CORE_COMMON_HPP #define ADOBE_UI_CORE_COMMON_HPP /****************************************************************************************************/ #include <adobe/rectangle.hpp> /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ // /// \ingroup widget_lib /// /// This function takes two rectangle slices and "aligns" them by the first /// point of interest (for a vertical slice, the baseline). It takes the /// first slice as a reference, and modifies it such that it's height can /// accommodate the aligned slices. /// /// This function does NOT touch frame, inset and outset values! They might /// be invalid once the function has returned. /// /// \param slice_one the first slice to align, and the one which is modified. /// \param slice_two the slice to align with the first slice. // void align_slices(::adobe::rectangle_t::slice_t& slice_one, ::adobe::rectangle_t::slice_t slice_two); /****************************************************************************************************/ } // namespace adobe /****************************************************************************************************/ #endif /****************************************************************************************************/ --- NEW FILE: display.hpp --- /* 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) */ /****************************************************************************************************/ #ifndef ADOBE_DISPLAY_HPP #define ADOBE_DISPLAY_HPP /****************************************************************************************************/ #include <boost/any.hpp> /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ struct display_t { struct implementation_t; typedef boost::any position_t; display_t(); ~display_t(); position_t root(); void erase(position_t& position); template <typename DisplayElement> position_t insert(position_t& parent, DisplayElement& element); private: implementation_t* object_m; public: implementation_t& implementation(); const implementation_t& implementation() const; }; /****************************************************************************************************/ display_t& get_main_display(); /****************************************************************************************************/ template <typename ReturnType, typename DisplayElement> ReturnType view_for_element(DisplayElement& element); /****************************************************************************************************/ template <typename DisplayElement> display_t::position_t insert(display_t& display, display_t::position_t& parent, DisplayElement& element); /****************************************************************************************************/ } // namespace adobe /****************************************************************************************************/ #endif // ADOBE_DISPLAY_HPP /****************************************************************************************************/ --- NEW FILE: client_assembler.hpp --- /* 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) */ /*************************************************************************************************/ #ifndef EVE_CLIENT_EXAMPLE_HPP #define EVE_CLIENT_EXAMPLE_HPP #include "ui_core.hpp" #include <list> #include <boost/function.hpp> #include <adobe/future/assemblage.hpp> #include <adobe/adam.hpp> #include <adobe/dictionary.hpp> #include <adobe/eve.hpp> #include <adobe/future/memory.hpp> /****************************************************************************************************/ /* REVISIT (sparent) : Size is inherited from the parent during initialization - the size specified to the client is relative to the parent's size. Does this ever need to be specified in absolutes? */ enum size_enum_t { size_mini_s = -2, size_small_s = -1, size_normal_s = 0, size_minimum_s = size_mini_s, size_maximum_s = size_normal_s }; /*************************************************************************************************/ namespace eve_client { /*************************************************************************************************/ /* This is a basic "Window Server" - it can be called to construct a window by name. The window is attached to a sheet as a slave (meaning the Window must be destructed before the sheet). REVISIT (sparent) : Here are some thoughts on the direction this design should be going... We have an assemblage (or package of items with the same lifespace) for the window which includes the eve structure and the slave connection (the wire bundle to attach the assamblage to a sheet). */ class eve_client_holder; class window_server_t { public: typedef boost::function<void (const adobe::name_t&, const adobe::value_t&)> action_fallback_proc_t; window_server_t(const char* directory_path, adobe::sheet_t& sheet); ~window_server_t(); void push_back(const char* name, size_enum_t dialog_size); #if 0 void set_back(const char* name, size_enum_t dialog_size); void pop_back(bool cancel); #endif void set_action_fallback(action_fallback_proc_t proc); void serialize_widgets(std::ostream& s); // REVISIT (sparent) : Hack. These need to go to the correct window. void dispatch_action(adobe::name_t action, const adobe::value_t& parameter); std::size_t size() const { return window_list_m.size(); } private: typedef std::list<eve_client_holder*> window_list_t; typedef window_list_t::iterator iterator; void dispatch_window_action(iterator window, adobe::name_t action, const adobe::value_t& parameter); void erase(iterator window); adobe::sheet_t& sheet_m; std::string directory_path_m; window_list_t window_list_m; action_fallback_proc_t fallback_m; }; /*************************************************************************************************/ typedef boost::function<void (adobe::name_t action, const adobe::value_t&)> button_notifier_t; /*************************************************************************************************/ class eve_client_holder : public boost::noncopyable { public: /* NOTE (sparent) : Order is important here - we want to destruct window_m prior to destructing eve_m so that any notifications sent by the system are sent to valid object. Slots and signals on the window widgets would be a better way to handle this connection but I'm not there yet. */ adobe::eve_t* eve_m; adobe::window_t* window_m; boost::signal<void (std::ostream& s)> widget_stream_m; adobe::assemblage_t assemblage_m; adobe::dictionary_t contributing_m; #ifndef NDEBUG void clear_frames() { if (window_m) adobe::clear_geometry_frames(*window_m); } #endif private: friend adobe::auto_ptr<eve_client_holder> make_view(const char* file_name, adobe::sheet_t& sheet, const button_notifier_t& notifier, size_enum_t dialog_size); }; /*************************************************************************************************/ adobe::auto_ptr<eve_client_holder> make_view( const char* file_name, adobe::sheet_t& sheet, const button_notifier_t& notifier, size_enum_t dialog_size); /*************************************************************************************************/ } // namespace eve_client /*************************************************************************************************/ #endif /*************************************************************************************************/ --- NEW FILE: ui_core.hpp --- /* 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) */ /****************************************************************************************************/ #ifndef ADOBE_UI_CORE_HPP #define ADOBE_UI_CORE_HPP /****************************************************************************************************/ #if ADOBE_PLATFORM_WIN # include <string> # include <sstream> #endif #include <boost/function.hpp> [...995 lines suppressed...] ADOBE_SERIALIZABLE_TOTAL_ORDERING_BOILERPLATE_DECLARATION(adobe::checkbox_t); ADOBE_SERIALIZABLE_TOTAL_ORDERING_BOILERPLATE_DECLARATION(adobe::link_t); ADOBE_SERIALIZABLE_TOTAL_ORDERING_BOILERPLATE_DECLARATION(adobe::progress_bar_t); ADOBE_SERIALIZABLE_TOTAL_ORDERING_BOILERPLATE_DECLARATION(adobe::separator_t); ADOBE_SERIALIZABLE_TOTAL_ORDERING_BOILERPLATE_DECLARATION(adobe::static_text_t); ADOBE_SERIALIZABLE_TOTAL_ORDERING_BOILERPLATE_DECLARATION(adobe::edit_text_t); ADOBE_SERIALIZABLE_TOTAL_ORDERING_BOILERPLATE_DECLARATION(adobe::popup_t); ADOBE_SERIALIZABLE_TOTAL_ORDERING_BOILERPLATE_DECLARATION(adobe::unit_edit_text_t); ADOBE_SERIALIZABLE_TOTAL_ORDERING_BOILERPLATE_DECLARATION(adobe::slider_t); ADOBE_SERIALIZABLE_TOTAL_ORDERING_BOILERPLATE_DECLARATION(adobe::bevel_button_t); /****************************************************************************************************/ } // namespace adobe /****************************************************************************************************/ #endif // ADOBE_UI_CORE_HPP /****************************************************************************************************/ --- NEW FILE: optional_connect.hpp --- /* 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) */ /*************************************************************************************************/ #ifndef ADOBE_OPTIONAL_CONNECTION_HPP #define ADOBE_OPTIONAL_CONNECTION_HPP /*************************************************************************************************/ #include <boost/utility/enable_if.hpp> /*************************************************************************************************/ #ifdef BOOST_MSVC #define ADOBE_OPTIONAL_CONNECT_TEST(p) &p != 0 #else #define ADOBE_OPTIONAL_CONNECT_TEST(p) sizeof(p) != 0 #endif /*************************************************************************************************/ #define ADOBE_OPTIONAL_CONNECT1(ns, func) \ namespace adobe { \ namespace ns { \ namespace implementation { \ template <class R, class T> \ R func(T& t, \ typename boost::enable_if_c<ADOBE_OPTIONAL_CONNECT_TEST(T::##func)>::type* = 0) \ { return t.##func(); } \ template <class R, class T> \ R func(volatile T&, ...) \ { return R(); } \ } \ template <class R, class T> \ R func(T& t) \ { return implementation::##func##<R>(t); } \ } } /*************************************************************************************************/ #define ADOBE_OPTIONAL_CONNECT2(ns, func) \ namespace adobe { \ namespace ns { \ namespace implementation { \ template <class R, class T, class U> \ R func(T& t, U& u, \ typename boost::enable_if_c<ADOBE_OPTIONAL_CONNECT_TEST(T::##func)>::type* = 0) \ { return t.##func##(u); } \ template <class R, class T, class U> \ R func(volatile T&, volatile U&, ...) \ { return R(); } \ } \ template <class R, class T, class U> \ R func(T& t, U& u) \ { return implementation::##func##<R>(t, u); } \ } } /*************************************************************************************************/ #define ADOBE_OPTIONAL_CONNECT3(ns, func) \ namespace adobe { \ namespace ns { \ namespace implementation { \ template <class R, class T, class U, class V> \ R func(T& t, U& u, V& v, \ typename boost::enable_if_c<ADOBE_OPTIONAL_CONNECT_TEST(T::##func)>::type* = 0) \ { return t.##func(u, v); } \ template <class R, class T, class U, class V> \ R func(volatile T&, volatile U&, volatile V&, ...) \ { return R(); } \ } \ template <class R, class T, class U, class V> \ R func(T& t, U& u, V& v) \ { return implementation::##func##<R>(t, u, v); } \ } } /*************************************************************************************************/ #endif // ADOBE_OPTIONAL_CONNECTION_HPP /*************************************************************************************************/ --- NEW FILE: latch.hpp --- /* 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) */ /****************************************************************************************************/ #ifndef ADOBE_LATCH_HPP #define ADOBE_LATCH_HPP /****************************************************************************************************/ #include <adobe/dictionary.hpp> #include <adobe/value.hpp> /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ template <typename ValueType> struct latch_t { typedef ValueType value_type; typedef boost::function<void (const value_type&, bool)> trigger_t; typedef boost::function<void (bool)> valid_t; template <typename TriggerFunction, typename ValidFunction> latch_t(const TriggerFunction& trigger, const ValidFunction& valid) : trigger_m(trigger), valid_m(valid), force_m(true) { } latch_t(const latch_t&) : force_m(true) { } latch_t& operator = (const latch_t&) { // Clear connections on copy force_m = false; trigger_m = trigger_t(); valid_m = valid_t(); return *this; } template <typename TriggerFunction, typename ValidFunction> void attach(const TriggerFunction& trigger, const ValidFunction& valid) { trigger_m = trigger; valid_m = valid; } void set_value(const value_t& new_value, bool is_valid) { if (is_valid != is_valid_m || force_m) valid_m(is_valid); value_m = new_value; is_valid_m = is_valid; force_m = false; } void trigger() const { /* REVISIT (sparent) : should this conditional simply be a pre-condition */ if (!force_m) trigger_m(value_m, is_valid_m); } private: value_type value_m; bool is_valid_m; bool force_m; trigger_t trigger_m; valid_t valid_m; }; /****************************************************************************************************/ } // namespace adobe /****************************************************************************************************/ #endif // ADOBE_LATCH_HPP /****************************************************************************************************/ --- NEW FILE: report_exception.hpp --- /* 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) */ /****************************************************************************************************/ #ifndef ADOBE_REPORT_EXCEPTION_HPP #define ADOBE_REPORT_EXCEPTION_HPP /****************************************************************************************************/ #include <iostream> #include <fstream> #include <sstream> #include <adobe/istream.hpp> #include <adobe/adam.hpp> #include <adobe/name.hpp> /****************************************************************************************************/ /* // // REVISIT (ralpht): Get the editor sheet from the simpleApplication singleton // instead of this global. // extern adobe::sheet_t* editor_sheet_g; extern const adobe::static_name_t editor_error_cell_g; extern const adobe::static_name_t editor_visible_tab_cell_g; extern const adobe::static_name_t editor_key_errors_tab_g; */ /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ void system_beep(); /****************************************************************************************************/ namespace implementation { /*************************************************************************************************/ class os_exception : public std::exception { public: os_exception(long status, const char* file, long line) throw() { try { std::stringstream t; t << status; format(t.str().c_str(), file, line); } catch (...) { } } os_exception(const char* status, const char* file, long line) throw() { format(status, file, line); } os_exception(const std::string& status, const char* file, long line) throw() { format(status.c_str(), file, line); } ~os_exception() throw() {} const char* what () const throw() { return what_m.c_str(); } private: void format(const char* status, const char* file, long line) { try { std::stringstream t; t << "Error: " << status << " (" << file << ", line " << line << ")"; what_m.assign(t.str()); } catch (...) { } } std::string what_m; }; /*************************************************************************************************/ static void ADOBE_REQUIRE_STATUS_impl(long status, char* file, long line) { if (status != 0) throw os_exception(status, file, line); } /*************************************************************************************************/ #define ADOBE_REQUIRE_STATUS(x) adobe::implementation::ADOBE_REQUIRE_STATUS_impl((x), __FILE__, __LINE__) /****************************************************************************************************/ } // namespace implementation /****************************************************************************************************/ inline void report_exception() { std::string err("Exception: "); try { throw; } catch (const adobe::stream_error_t& error) { // REVISIT (sparent) : This can't handle a set of files. std::ifstream file(error.line_position_set().front().stream_name()); err += format_stream_error(file, error); } catch (const std::exception& error) { err += error.what(); } catch (...) { err += "Unknown."; } /* // // REVISIT (ralpht): Get editor_sheet_g from the simpleApplication singleton. // if (editor_sheet_g) { editor_sheet_g->set(editor_error_cell_g, adobe::value_t(err)); editor_sheet_g->set(editor_visible_tab_cell_g, adobe::value_t(editor_key_errors_tab_g)); editor_sheet_g->update(); } else*/ { std::ofstream errorfile("adobe_begin_errors.txt"); errorfile << err; } system_beep(); } /****************************************************************************************************/ } // namespace /****************************************************************************************************/ #endif // ADOBE_REPORT_EXCEPTION_HPP /****************************************************************************************************/ --- NEW FILE: express_viewer.hpp --- /* Copyright 2005 Ralph Thomas Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt or a copy at http://opensource.adobe.com/licenses.html) */ /****************************************************************************************************/ #ifndef ADOBE_EXPRESS_VIEWER_HPP #define ADOBE_EXPRESS_VIEWER_HPP #include <boost/filesystem/path.hpp> #include "client_assembler.hpp" #include <adobe/adam.hpp> #include <adobe/config.hpp> #include <string> #include <iostream> /****************************************************************************************************/ namespace adobe { /****************************************************************************************************/ // /// The stream_sucker is used to extract the data available from a stream and /// deposit it into a string. This is not very efficient but works for a /// demo application. /// /// \param stream the stream to extract data from. /// \return all of the data in the stream. // template<typename InputStream> std::string stream_sucker( InputStream& stream ) { std::string result; if ( stream.is_open() ) { std::istream::char_type c( 0 ); // // Read from the stream character by character until we // reach the end. // while( !stream.eof() ) { stream.get( c ); if ( c == '\n' ) c = '\r'; if ( !stream.eof() ) result += c; } } return result; } /****************************************************************************************************/ // /// The simpleApplication class is implemented in express_viewer.cpp and defines /// the basic application operation. The simpleApplication class is a singleton, /// so you must use simpleApplication::getInstance() to get an instance. // class simpleApplication { boost::filesystem::path _resource_dir_m; ///< The directory containing this applications resource files (i.e.: editor.adm, editor.eve). boost::filesystem::path _eve_path_m; ///< The name of the Eve file we are viewing. boost::filesystem::path _adam_path_m; ///< The name of the Adam file we are viewing. adobe::sheet_t* _sheet_m; ///< The sheet we are viewing. eve_client::window_server_t* _holder_m; ///< Contains Eve instance, and all instanciated widgets. adobe::sheet_t* _editor_sheet_m; ///< The sheet for this editor program. size_enum_t _dialog_size_m; ///< The size of dialog to create. bool _initialized; ///< Are we initialized yet? // /// This constructor is private to ensure that the getInstance /// method is used to return a reference to this class. // simpleApplication(); // /// This destructor releases any allocated sheets and Eve bits. // ~simpleApplication(); // /// Initialize the simpleApplication by attempting to load resources from /// disk. This also calls os_initialize, to perform any OS-specific /// initialization which may be required. /// /// \return true if the initialization is successful, false otherwise. /// \sa os_initialize // bool _initialize(); // /// This function gets invoked whenever an action (e.g.: a button with /// "action: @ok" defined) is unhandled by Adam. It is registered with /// _holder_m by initialize(). Currently this function simply writes the /// given value into the output text area. /// /// \param name the name of the action (e.g.: "ok", "cancel"). /// \param value any parameter associated with the value. /// /// \sa _holder_m // void _button_notifier( const adobe::name_t& name, const adobe::value_t& value ); // /// This function will write the given string to the given path name. It /// is usually called by _editor_op when it needs to write a modified adam /// or eve file to disk before reloading them. /// /// \param file_name the file to write to. /// \param contents the file contents to write out. // void _update_file( const boost::filesystem::path& file_name, std::string contents ); // /// This function handles most editor operations, as defined in the /// editor's Eve file. /// /// \param name the name of the operation to perform. /// \param value a dictionary containing the value specific to the operation. // void _editor_op( adobe::name_t name, const adobe::value_t& value ); #if ADOBE_PLATFORM_MAC // /// The Mac has inherently bad metric information provided to us from the OS /// So here we load up an xstr glossary that contains for us metric information /// on the various platform widgets. // void _load_metrics_glossary(); #endif public: // /// The getInstance method returns a pointer to the single simpleApplication /// instance. If the simpleApplication cannot be initialized then NULL is /// returned. Initialization will fail if: /// <ul> /// <li>The editor.adm and editor.eve files cannot be found</li> /// <li>The editor.adm and editor.eve files do not parse</li> /// <li>OS-specific initialization fails</li> /// </ul> /// /// \return a pointer to the single simpleApplication instance. /// \sa os_initialize // static simpleApplication* getInstance(); // /// Load the main editor GUI and enter the main-loop. This function /// will not return until it's time to quit. // void run(); // /// Load the dialog from disk, and tell the _holder_m to show it. This /// function also updates the contents of the Eve text area to match what /// was loaded from disk. The window loaded is specified by set_eve_file. /// /// \sa set_eve_file // void display_window(); // /// Forget about the existing sheet and load one from disk. This also /// (re)opens the dialog. The sheet loaded is specified by set_adam_file. /// /// \sa set_adam_file // void load_sheet(); // /// Remove any frames which have been drawn around the widgets. // void clear_window_frames(); // /// Draw frames around all widgets. // void frame_window(); // /// Serialize all of the widgets and connections into text and show the /// text in the Results text area. // void serialize_connections(); // /// Set the file name of the Eve file to load. This does not actually /// load the file or display the window, call display_window to make /// that happen. /// /// \param file_name the name of the Eve file to load. /// \sa display_window // void set_eve_file( boost::filesystem::path file_name ); // /// Set the file name of the Adam file to load. This does not actually /// load the file or update the sheet, call load_sheet to make that /// happen. /// /// \param file_name the name of the Adam file to load. /// \sa load_sheet // void set_adam_file( boost::filesystem::path file_name ); // /// Set the directory which is used to load application resources /// (such as the editor.adm and editor.eve files). /// /// \param res_path the directory to load application /// resources from. // void set_resource_directory( boost::filesystem::path res_path ); // /// Set the size of any dialogs which are going to be created after /// this call. /// /// \param s the new size to make dialogs. // void set_dialog_size( size_enum_t s ); }; /****************************************************************************************************/ // /// Emit the system beep sound. // void system_beep(); /****************************************************************************************************/ // /// Perform OS-specific initialization tasks, such as registering menus. This /// function should also set the resource directory used by simpleApplication. /// /// \param theApp the instance of simpleApplication to call into when a menu item is /// selected, or a system event is received. /// \return true if initialization was successful, false otherwise. // bool os_initialize( simpleApplication* theApp ); /****************************************************************************************************/ // /// Enter the OS/toolkit main-loop. This function should return when it's time /// to quit. // void os_mainloop(); /****************************************************************************************************/ // /// Exit the OS/toolkit main-loop. This function should only be called after /// os_mainloop has been called. // void os_end_mainloop(); /****************************************************************************************************/ } // namespace adobe /****************************************************************************************************/ #endif |