00001 #ifndef DEBUGGING_BASE_CLASS 00002 #define DEBUGGING_BASE_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : debugging_base_support * 00007 * Author : Chris Koeritz * 00008 * * 00009 * Purpose: * 00010 * * 00011 * A shared set of operations on edit controls that permits different * 00012 * manners of creating and presenting the windows that really show the info. * 00013 * * 00014 ******************************************************************************* 00015 * Copyright (c) 1995-$now By Author. This program is free software; you can * 00016 * redistribute it and/or modify it under the terms of the GNU General Public * 00017 * License as published by the Free Software Foundation; either version 2 of * 00018 * the License or (at your option) any later version. This is online at: * 00019 * http://www.fsf.org/copyleft/gpl.html * 00020 * Please send any updates to: fred@gruntose.com * 00021 \*****************************************************************************/ 00022 00023 #include "mfc_dll.h" 00024 00025 #include <basis/log_base.h> 00026 #include <basis/portable.h> 00027 #include <win_ext/debugger.h> 00028 00029 // forward. 00030 class file_logger; 00031 class uls; 00032 00033 class MFC_EXTENSIONS_CLASS_STYLE debugging_base : public log_base 00034 { 00035 public: 00036 enum debugging_defaults { 00037 MAX_BUFFER_SIZE = 2 * MEGABYTE, 00038 MAX_FILE_SIZE = int(1.2 * MEGABYTE) 00039 }; 00040 00041 debugging_base(CEdit &to_manipulate, int buffer_size = MAX_BUFFER_SIZE, 00042 int file_size = MAX_FILE_SIZE, bool logging_to_file = false); 00043 // the editor "to_manipulate" is managed by this object as the repository 00044 // for the debugging information. the "buffer_size" is the maximum number 00045 // of characters allowed in the editor. the size is ignored on w9x. 00046 // if "logging_to_file" is true, then the ULS will not be used and output 00047 // will simply be written to a file. 00048 00049 virtual ~debugging_base(); 00050 00051 IMPLEMENT_CLASS_NAME("debugging_base"); 00052 00053 void setup(bool fixed_width = true); 00054 // this must be called when appropriate. the CEdit must be a valid window 00055 // at the time this method is invoked. the "fixed_width" flag specifies 00056 // if the text in the edit control should be changed to a fixed width font 00057 // (when flag is true) or if it should be left unchanged (flag is false). 00058 00059 void shut_down(); 00060 // prepares the object for destruction by closing down any networked 00061 // logging support. 00062 00063 int current_length(); 00064 // returns the current length of the edit buffer. 00065 00066 // logs a message to the log file and window, as required by log_base. 00067 // it uses the current ending as set in our members. 00068 virtual outcome log(const istring &info, int filter = ALWAYS_PRINT); 00069 00070 // logs a message to the logging file, if one exists, and allows the ending 00071 // to be specified separately. 00072 void log_ending(const istring &to_show, int filter = ALWAYS_PRINT, 00073 line_ending ending = CRLF_AT_END); 00074 00075 // prints a message to the window and logs it. this is just a synonym for 00076 // log() above. 00077 outcome print(const istring &to_show, int filter = ALWAYS_PRINT) 00078 { return log(to_show, filter); } 00079 00080 istring name() const; 00081 void name(const istring &new_name); 00082 // allows the file name for logging to be observed or modified. 00083 00084 int buffer_limit(); 00085 void buffer_limit(int new_limit); 00086 // observes or modifies the limit on the buffer length. 00087 00088 int file_limit() const; 00089 void file_limit(int new_limit); 00090 // allows the log file size limit to be observed or modified. 00091 00092 void go_to_end(); 00093 // causes the window to jump to the last line such that all future output 00094 // scrolls from there. 00095 00096 bool get_contents(istring &to_fill); 00097 // returns the entire current contents of the window as a string. true is 00098 // returned if we succeeded in getting the contents. 00099 00100 bool get_selection(int &start, int &end); 00101 // returns the selection position for the edit window. false is returned 00102 // if nothing is currently selected, although the "start" and "end" will 00103 // still be set correctly. 00104 00105 void select(int start, int end, bool scroll = true); 00106 // selects the text in the window between "start" and "end" if possible. 00107 // if "scroll" is true, then the selected text is scrolled into view. 00108 00109 void reset(); 00110 // clears all text out of the debugging console. 00111 00112 // internal functions: messy but sometimes useful as public. 00113 00114 #define DECLARE_BUG_EVENT 00116 #define DEFINE_BUG_EVENT 00118 #define ADD_DEBUGGER_MAP(to_invoke) \ 00119 ON_REGISTERED_MESSAGE(debugger::EVENT(), to_invoke) 00120 // these macros can be used to hook a function to the debugging info event. 00121 // DEFINE_BUG_EVENT must be used before the message map for a window that 00122 // wants to handle these events. it defines a variable used by the 00123 // ADD_DEBUGGER_MAP macro (which is required due to how mfc does registered 00124 // messages in the map). the function "to_invoke" must have the form of 00125 // an ON_MESSAGE event handler like: 00126 // LRESULT display_debug_message(WPARAM wparam, LPARAM lparam); 00127 // that method just needs to invoke the display_message() method below. 00128 00129 void display_message(WPARAM wparam, LPARAM lparam); 00130 // prints the debugging information that is sent to a window. this can 00131 // be invoked by windows that are receiving debugging messages. 00132 00133 CEdit &get_editor(); 00134 // allows access to the lower-level object used for the editing window. 00135 00136 log_base &logging(); 00137 // allows the underlying logging support to be accessed. 00138 00139 private: 00140 CEdit &_editor; // the edit window object. 00141 int _length; 00142 // current length (our internal count; might not be accurate to exact 00143 // buffer contents). 00144 int _maximum_active_length; 00145 // this is the point at which the information in the debugging window is 00146 // shortened. the top chunk is clipped to ensure that the buffer doesn't 00147 // overflow (because there are varying results when this happens, depending 00148 // on the platform). 00149 int _file_limit; // the maximum length the log file can attain. 00150 istring *_log_name; // the name of the log file or stream. 00151 log_base *_the_log; // our polymorphic logging support. 00152 bool _file_logging; // true if we log to a file. 00153 00154 int locked_current_length(); // the real function, for internal use only. 00155 00156 bool get_contents_via_clipboard(istring &to_fill); 00157 }; 00158 00159 #endif 00160
1.5.1