Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

PrintControl.cxx

Go to the documentation of this file.
00001 //     $Id: PrintControl.cxx,v 1.2 2001/01/25 23:08:40 tlindner Exp $
00002 //  Author: Toby Burnett
00003 //
00004 //
00005 // Implement the PrintControl class 
00006 //
00007 // When this class has been set up, new print commands can be added to the menu
00008 // by:      
00009 //      PrintControl::instance()->addItem("my printout", myCommand);
00010 //
00011 // where
00012 //    myCommand is an instance of a subclass of Command that will output to
00013 // the std::ostream* PrintControl::instance()->out(); 
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 //   Constructor: set up menu, get the GUI's text window to print to
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     // create Print pull-down menu
00053     m_sub_menu = &m_menu.subMenu("Print");
00054     // schedule call back to finishSetup method
00055     m_menu.add(new MenuClient<PrintControl>(this));
00056 
00057 }
00058 
00059 
00060 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00061 // file scope class that implements the command, followed by a flush
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 //   stuff for singleton 
00111 PrintControl* PrintControl::s_instance = 0;
00112 
00113 PrintControl* PrintControl::instance()
00114 {
00115     assert( s_instance!=0)      ;
00116     return s_instance;
00117 }
00118 
00119 } // namespace gui

Generated at Wed Nov 21 12:20:55 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000