tiny_shell.h

Go to the documentation of this file.
00001 #ifndef TINY_SHELL_CLASS
00002 #define TINY_SHELL_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : tiny_shell                                                        *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *    The tiny shell provides a simple way to create an application.           *
00012 *  The templated tiny application will create your object (which you          *
00013 *  derive from tiny shell) and will automatically provide an ini editor,      *
00014 *  a debugging console and some miscellaneous windows support.                *
00015 *                                                                             *
00016 *  Notes:                                                                     *
00017 *                                                                             *
00018 *    All tiny_shell programs must plug in the DEFINE_INSTANCE_HANDLE macro.   *
00019 *  This supports the need to find local resources without getting stuck in    *
00020 *  the MFC resource chain.  See basis/portable.h for more details.            *
00021 *                                                                             *
00022 *  This is a heavy-weight header and is intended mainly for the definition    *
00023 *  of main programs that use MFC.                                             *
00024 *                                                                             *
00025 *******************************************************************************
00026 * Copyright (c) 1995-$now By Author.  This program is free software; you can  *
00027 * redistribute it and/or modify it under the terms of the GNU General Public  *
00028 * License as published by the Free Software Foundation; either version 2 of   *
00029 * the License or (at your option) any later version.  This is online at:      *
00030 *     http://www.fsf.org/copyleft/gpl.html                                    *
00031 * Please send any updates to: fred@gruntose.com                               *
00032 \*****************************************************************************/
00033 
00034 #include "mfc_dll.h"
00035 
00036 #include <basis/portable.h>
00037 #include <opsystem/application_shell.h>
00038 
00039 // forward.
00040 class debugger;
00041 class debugging_console_window;
00042 class log_base;
00043 class outcome;
00044 
00045 class MFC_EXTENSIONS_CLASS_STYLE tiny_shell
00046 : public CFrameWnd,
00047   public application_shell
00048 {
00049 public:  
00050   tiny_shell(const istring &window_title, const istring &name_root,
00051           int file_size = int(1.2 * MEGABYTE),
00052           const istring &logfile_name = "");
00053     // constructs a tiny_shell window with the "window_title".  the
00054     // "name_root" is used as the base part of the config file's name and
00055     // diagnostic log file's name.  if "logfile_name" is not empty, then
00056     // that is used for the name of the diagnostic log instead.
00057 
00058   virtual ~tiny_shell();
00059 
00060   virtual int execute() = 0;
00061     // must be overridden by the derived object.  this usually performs the
00062     // main activity of the particular tiny shell object.  the function will be
00063     // called after the SetupWindow() method is finished.  it is alright for
00064     // this function to be an empty implementation, in which case the normal
00065     // owl mechanisms take over.
00066 
00067   int execute_returned() const { return _execute_returned; }
00068     // the execute method completes long before the object exits (usually).
00069     // this records the value returned by the execute method.  if execute
00070     // never got invoked (due to problems in creating underlying graphical
00071     // objects), then this value is meaningless.
00072 
00073   bool Create();
00074     // performs the actual creation using the data passed to the constructor.
00075     // the creation process is split into two steps to appease MFC.
00076 
00077   inline u_int menu() const { return _menu; }
00078   inline void menu(u_int new_menu) { _menu = new_menu; }
00079     // observes or modifies the menu to be used with the tiny shell.  by
00080     // default, this is zero and will not be set.  if it is to be changed, it
00081     // should be set up by the derived class' constructor or by a derived
00082     // SetupWindow() function before calling the base SetupWindow().
00083 
00084   inline u_int icon() const { return _icon; }
00085   inline void icon(u_int new_icon) { _icon = new_icon; }
00086     // observes or modifies the program icon.  this also should be set up in
00087     // the constructor if it is to be used.
00088 
00089   outcome log(const istring &to_print);
00090   outcome print(const istring &to_print);
00091     // sends a debugging line into the debugging console and also to the
00092     // log file.
00093 
00094   debugging_console_window &console() const;
00095     // the window that gets sent debugging information.  this is public to
00096     // allow better control over the debugging window.  it is constructed by
00097     // the time of the execute() function, but must not be used before then.
00098     // the console will not be very useful until Create() has been invoked.
00099 
00100   debugger &debug() const;
00101     // this object is pointed at the "console" to allow debugging information
00102     // to be sent.  it also is valid by the time the execute() function is
00103     // called.  it can be passed around as a valid log_base object before then,
00104     // but items logged to it will be discarded until the tiny_shell window
00105     // is created (just before execute() is invoked).  the initial style of
00106     // delivery for the debugging items is "delayed" (see debugger.h), but this
00107     // can be changed.  however, it is not recommended because that can cause
00108     // misordering of debug messages when other senders are targeting the same
00109     // debugging window.
00110 
00111   virtual bool good_version() const;
00112     // this function should be implemented by derived tiny_shells as something
00113     // like: @code
00114     //   #include <i_library/i_library_version.h>
00115     //   ....
00116     //   bool tiny_shell_X::good_version() const {
00117     //     return CHECK_I_COMMUNICATION;
00118     //   } @endcode
00119     // where all dlls used by the tiny_shell based program are checked.  the
00120     // function's implementation should not expect any other class members
00121     // to be available yet.  the constructor of the derived tiny_shell should
00122     // also have done very minimal member construction yet, since this approach
00123     // is not airtight in the presence of a dll conflict.
00124 //hmmm: make this approach airtight.  currently it suffers from needing to
00125 //      create the tiny shell object before the version can be checked, which
00126 //      is just busted.  we need some kind of thing that's both virtual and
00127 //      static, kinda.
00128 
00129 protected:
00130   // mfc encrudulations:
00131   DECLARE_MESSAGE_MAP()
00132   afx_msg void OnClose();
00133   afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
00134   afx_msg void OnMove(int x, int y);
00135   afx_msg void OnSize(u_int nType, int cx, int cy);
00136   void OnSetFocus(CWnd *old_window);
00137 
00138 private:
00139   debugger *_debug;  // our debugging message zinger.
00140   debugging_console_window *_console;  // our window for showing info.
00141   u_int _menu;  // value for our menu resource.
00142   u_int _icon;  // value for our icon resource.
00143   CMenu _mfc_menu;  // holds the MFC menu object when we have a menu id.
00144   istring *_win_title;  // the name on the window.
00145   bool _exiting;  // the program is leaving if this is true.
00146   log_base *_held_logger;  // tracks the prior logger.
00147   istring *_logfile_name;  // name of the logfile if not default.
00148   int _execute_returned;  // the return value of the execute() method.
00149 
00150   afx_msg LRESULT do_execute(WPARAM wparam, LPARAM lparam);
00151     // called when the tiny shell has finished setting up the window and is
00152     // about to start running the client program.
00153 
00154   afx_msg LRESULT print_debug(WPARAM wparam, LPARAM lparam);
00155     // when DEBUG::EVENT events happen, this sends the message to
00156     // the console.
00157 
00158   // unused.
00159   tiny_shell(const tiny_shell &);
00160   tiny_shell &operator =(const tiny_shell &);
00161 };
00162 
00163 #endif 
00164 

Generated on Fri Nov 21 04:29:17 2008 for HOOPLE Libraries by  doxygen 1.5.1