00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "gui/SubMenu.h"
00017 #include "gui/PrintControl.h"
00018 #include "gui/SimpleCommand.h"
00019
00020
00021 #include <cassert>
00022
00023 namespace gui {
00025
00026
00027
00028 PrintControl::PrintControl(Menu& menu, std::ostream*out )
00029 : m_print(out),
00030 m_menu(menu)
00031 {
00032 setup();
00033 }
00034
00035 PrintControl::~PrintControl()
00036 {
00037 PrintList::iterator it = m_print_commands.begin();
00038 while (it != m_print_commands.end())
00039 delete (*it++);
00040
00041 }
00042
00043 PrintCommand::~PrintCommand()
00044 {
00045 delete m_cmd;
00046 }
00047
00048 void PrintControl::setup()
00049 {
00050 s_instance = this;
00051 disable();
00052
00053 m_sub_menu = &m_menu.subMenu("Print");
00054
00055 m_menu.add(new MenuClient<PrintControl>(this));
00056
00057 }
00058
00059
00060
00061
00062
00063
00064 void PrintControl::add(Command* cmd, const std::string& title, bool enabled)
00065 {
00066
00067 PrintCommand* prt = new PrintCommand(cmd, this, enabled);
00068 m_print_commands.push_back(prt);
00069
00070 m_sub_menu->addToggle(title, enabled
00071 ,new SimpleCommand<PrintCommand>(prt, &PrintCommand::enable)
00072 ,new SimpleCommand<PrintCommand>(prt, &PrintCommand::disable) );
00073 }
00074
00075
00076 void PrintControl::enable(){ m_enabled = true;}
00077 void PrintControl::disable(){ m_enabled = false;}
00078
00079
00080 void
00081 PrintControl::printAll()
00082 {
00083 if(m_enabled) printNow();
00084 }
00085 void
00086 PrintControl::printNow()
00087 {
00088 for( PrintList::iterator it = m_print_commands.begin(); it != m_print_commands.end(); ++it)
00089 (*it)->execute();
00090 }
00091
00092
00093 void
00094 PrintControl::finishSetup()
00095 {
00096
00097 m_sub_menu->addSeparator();
00098 m_sub_menu->addToggle("print after event", true,
00099 new SimpleCommand<PrintControl>(this,&PrintControl::enable),
00100 new SimpleCommand<PrintControl>(this,&PrintControl::disable));
00101 m_sub_menu->addButton("print now", new SimpleCommand<PrintControl>(this,&PrintControl::printNow) );
00102
00103 }
00104
00105 void PrintControl::clear(){m_print->clear();}
00106
00107 void PrintControl::flush(){m_print->flush();}
00108
00109
00110
00111 PrintControl* PrintControl::s_instance = 0;
00112
00113 PrintControl* PrintControl::instance()
00114 {
00115 assert( s_instance!=0) ;
00116 return s_instance;
00117 }
00118
00119 }