GG

AdamDlg.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003-2008 T. Zachary Laine
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License
00007    as published by the Free Software Foundation; either version 2.1
00008    of the License, or (at your option) any later version.
00009    
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014     
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA
00019 
00020    If you do not wish to comply with the terms of the LGPL please
00021    contact the author as other terms are available for a fee.
00022     
00023    Zach Laine
00024    whatwasthataddress@gmail.com */
00025    
00033 #ifndef _AdamDlg_h_
00034 #define _AdamDlg_h_
00035 
00036 #include <GG/AdamGlue.h>
00037 
00038 #include <GG/adobe/adam.hpp>
00039 #include <GG/adobe/dictionary.hpp>
00040 #include <GG/adobe/dictionary.hpp>
00041 #include <GG/adobe/future/widgets/headers/virtual_machine_extension.hpp>
00042 
00043 #include <boost/function.hpp>
00044 #include <boost/filesystem/path.hpp>
00045 
00046 
00047 namespace GG {
00048 
00049 class Wnd;
00050 
00053 enum AdamDialogDisplayOption
00054 {
00056     ADAM_DIALOG_DISPLAY_ALWAYS,
00057 
00062     ADAM_DIALOG_DISPLAY_AS_NEEDED,
00063 
00066     ADAM_DIALOG_DISPLAY_NEVER
00067 };
00068 
00070 struct AdamDialogResult
00071 {
00078     adobe::dictionary_t m_property_state;
00079 
00086     adobe::dictionary_t m_result_values;
00087 
00091     adobe::name_t m_terminating_action;
00092 };
00093 
00103 typedef boost::function <bool (adobe::name_t, const adobe::any_regular_t&)> AdamDialogActionCallback;
00104 
00106 class AdamModalDialog
00107 {
00108 public:
00145     AdamModalDialog(const std::string& sheet_definition,
00146                     const adobe::dictionary_t& input,
00147                     const adobe::dictionary_t& previous_property_state,
00148                     AdamDialogDisplayOption display_option,
00149                     GG::Wnd* dlg,
00150                     AdamDialogActionCallback callback,
00151                     boost::filesystem::path working_directory);
00152 
00156     bool NeedUI() const;
00157 
00159     template <
00160         class AdamValueType,
00161         class GGValueType,
00162         class ControlType
00163     >
00164     void BindCell(ControlType& control, adobe::name_t cell);
00165 
00167     AdamDialogResult Result();
00168 
00171     boost::signal<void (adobe::name_t, const adobe::any_regular_t&)> DialogActionSignal;
00172 
00173 private:
00174     void LatchCallback(adobe::name_t action, const adobe::any_regular_t& value);
00175     void MonitorPropertyState(const adobe::dictionary_t& property_state);
00176     void MonitorInvariants(bool valid);
00177 
00178     adobe::dictionary_t      m_input;
00179     adobe::dictionary_t      m_previous_property_state;
00180     AdamDialogDisplayOption  m_display_option;
00181     AdamDialogActionCallback m_callback;
00182     boost::filesystem::path  m_working_directory;
00183     adobe::sheet_t           m_sheet;
00184     adobe::vm_lookup_t       m_vm_lookup;
00185     bool                     m_need_ui;
00186     AdamDialogResult         m_result;
00187     adobe::dictionary_t      m_contributing;
00188     GG::Wnd*                 m_dlg;
00189 
00190     std::vector<boost::shared_ptr<AdamCellGlueBase> > m_cells;
00191 };
00192 
00193 // implementations
00194 
00195 template <
00196     class AdamValueType,
00197     class GGValueType,
00198     class ControlType
00199 >
00200 void AdamModalDialog::BindCell(ControlType& control, adobe::name_t cell)
00201 {
00202     m_cells.push_back(
00203         boost::shared_ptr<AdamCellGlueBase>(
00204             new AdamCellGlue<ControlType, AdamValueType, GGValueType>(
00205                 control, m_sheet, cell
00206             )
00207         )
00208     );
00209 }
00210 
00211 }
00212 
00213 #endif