A file comment description codeblock. It is formatted the same as the header file. |
//---------------------------------------------------------------------------------------- /*! \file bookmark_dialog.cpp \modified \copyright (c) Robert O'Connor ( rob@medicalmnemonics.com ) \licence GPL \brief Describes bookmark_dialog class \author Robert O'Connor \date 2002/01/03 */ // RCS-ID: $Id: included_breakdown_cpp.html,v 1.2 2003/03/17 17:43:21 robertoconnor Exp $ //----------------------------------------------------------------------------------------
GCC implementation codeblock. This is the second part of the GCC #pragma interface/implementation combo. It goes as the first line. This #pragma tells the compiler that is the one and only .cpp file that should hold the debug info for the class. It should be the header of this class. Turned off for APPLE, since OSX Jaguar doesn't like it (or need it). |
//---------------------------------------------------------------------------------------- // GCC implementation //---------------------------------------------------------------------------------------- #if defined(__GNUG__) && ! defined(__APPLE__) #pragma implementation "bookmark_dialog.h" #endif
Application setup.h codeblock: Include the application's setup.h file, so that we can remove everything in the next part, if the feature is one that we want to compile out. |
//---------------------------------------------------------------------------------------- // Setup information //---------------------------------------------------------------------------------------- #include "setup.h"
Start feature removal codeblock: Same idea as header had. |
//---------------------------------------------------------------------------------------- // Begin feature removal condition //---------------------------------------------------------------------------------------- #if ( setupUSE_INTEGRATED_HTML_EDITOR )
Standard wxWindows headers codeblock: A block that will be the same unchanged in every single .cpp file of the project. (You can skip reading through the details of it if you what if you don't care about what is going on). |
//---------------------------------------------------------------------------------------- // Standard wxWindows headers //----------------------------------------------------------------------------------------
This includes the headers for the compilers that support precompiled headers to increase compile speed of the application. |
// For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h"
The #pragma hdrstop for BCC tells the compiler that all the headers above that pragma are the same same (which they are, since BCC compiler won't see the #pragma interface of GCC). BCC has precompiled headers which will greatly speed up compile time, but for it to work, everything above #pragma hdrstop has to be the same for all the .cpp files. Therefore put the headers that are unique to this file after this #pragma hdrstop. |
#ifdef __BORLANDC__ #pragma hdrstop #endif
If it isn't a compiler that can support precompiled headers, then just include a long list of the most commonly used headers in the wxWindows library, like windows, strings, etc. |
// For all others, include the necessary headers (this file is usually all you // need because it includes almost all "standard" wxWindows headers) #ifndef WX_PRECOMP #include "wx/wx.h" #endif
Header of this .cpp file codeblock |
//---------------------------------------------------------------------------------------- // Header of this .cpp file //---------------------------------------------------------------------------------------- #include "bookmark_dialog.h"
Remaining headers codeblock: These are the unique headers needed by this class. For better sourcecode organization, they are always arranged in the order of first the wxWindows library headers required by the class, then any wxWindows/contrib headers required (often just the XRC resources header), then finally any headers of the application. |
//---------------------------------------------------------------------------------------- // Remaining headers: Needed wx headers, then wx/contrib headers, then application headers //---------------------------------------------------------------------------------------- #include "wx/xrc/xmlres.h" // XRC XML resouces //---------------------------------------------------------------------------------------- #include "utils_controls.h" #include "help_controller.h"
Internal constants codeblock (some classes) Some classes may use some internal constants, such as id numbers for a popup menu, list columns, etc. If so, these internal constants should go into this block. |
//---------------------------------------------------------------------------------------- // Internal constants //---------------------------------------------------------------------------------------- // Popup menu (PU) item IDs enum { PU_ADD_CHANNEL = wxID_HIGHEST + 2, PU_ADD_CHANNEL_WIZARD, PU_CONFIGURE_CHANNEL };
DECLARE_DYNAMIC/ABSTRACT_CLASS codeblock: If the header had a DECLARE_DYNAMIC_CLASS(), then a IMPLEMENT_DYNAMIC_CLASS() now needs to go here. If it was DECLARE_ABSTRACT_CLASS() in the header it wold be a IMPLEMENT_ABSTRACT_CLASS() here instead. |
//---------------------------------------------------------------------------------------- // wxWindows macro: implement dynamic class //---------------------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS( bookmark_dialog, wxDialog )
Event table codeblock (classes that want to handle events): This is the event table for the class. This is used for you to connect a certain event to a certain custom function. |
//---------------------------------------------------------------------------------------- // Event table: connect the events to the handler functions to process them //---------------------------------------------------------------------------------------- BEGIN_EVENT_TABLE( bookmark_dialog, wxDialog )
Entries for children of the class have 3 parts: -EVT_BUTTON: What type of event it is that should be connected to the custom function (a button click event) -wxID_HELP_CONTEXT: Only events raised by buttons by that ID will be sent to the custom function. wxID_HELP_CONTEXT is a special ID nubmer define for the help button. The ID number of -1 would specify events raised by all buttons. -bookmark_dialog::on_help_button: This is the custom function that should be fired by button events raised by the buttons with an ID of wxID_HELP_CONTEXT. |
EVT_BUTTON( wxID_HELP_CONTEXT, bookmark_dialog::on_help_button ) EVT_BUTTON( wxID_OK, bookmark_dialog::OnOK )
If the event is raised by a some child control in the XML resources, then just specify the control with a XRCID() macro. In this hypothetical example, only button click events named "bookmark_dialog_preferences_button" in the XRC file will trigger the on_preferences_button() function. |
EVT_BUTTON( XRCID( "bookmark_dialog_preferences_button" ), bookmark_dialog::on_preferences_button )
An event raised by the class itself for example the event of
this dialog closing obviously doen't need an identifier, so just 2 parts here: -EVT_CLOSE: Only close events will be sent to the custom function. -on_close(): The custom function that should be fired. |
EVT_CLOSE( main_frame::on_close ) END_EVENT_TABLE()
Public members codeblock: A block of what the public members of the class should do. The first member is the constructor, then the destructor, then the rest. |
//---------------------------------------------------------------------------------------- // Public members //---------------------------------------------------------------------------------------- bookmark_dialog::bookmark_dialog( wxWindow* parent ) { wxXmlResource::Get()->LoadDialog( this, parent, "bookmark_dialog" ); } bookmark_dialog::~bookmark_dialog() { } void bookmark_dialog::transfer_to( wxString& starting_text, wxString& ending_text ) { starting_text = m_starting_text; ending_text = m_ending_text; }
Protected members codeblock: A block of what the protected members of the class should do, if there is any. |
//---------------------------------------------------------------------------------------- // Protected members //----------------------------------------------------------------------------------------
Private members codeblock: A block of what the private members of the class should do. |
//---------------------------------------------------------------------------------------- // Private members //---------------------------------------------------------------------------------------- void bookmark_dialog::OnOK( wxCommandEvent& event ) { wxString output_string; wxString buf; output_string = "<a"; wxString name_string = XRCCTRL( *this, "bookmark_dialog_name_textctrl", wxTextCtrl )->GetValue(); output_string += " name=\"" + name_string + "\">"; wxString description_string = XRCCTRL( *this, "bookmark_dialog_description_textctrl", wxTextCtrl )->GetValue(); output_string += description_string; output_string += "</a>"; // Store the starting and ending strings as class members, ready to be transferred // by transfer_to(...) method. m_starting_text = output_string; m_ending_text = ""; // Get rid of the modal dialog. Not transferring any info from this modal's control // to a parent dialog, so don't have to bother with wxWindow::Validate or // wxWindow::TransferDataFromWindow. EndModal( wxID_OK ); } void bookmark_dialog::on_help_button( wxCommandEvent &event ) { #if ( setupUSE_ONLINE_HELP ) help_controller::get()->show_help_topic( plkrHELP_ID_BOOKMARK_DIALOG ); #endif }
Module definition block (only a few global classes): Not in bookmark_dialog, but in a few classes such as plucker_controller, help_controller, and commandline_parser, you will see they are set up with wxModules. These wxModules remove the requirement and headaches of creating and cleaning up globals. To use a wxModule instead of a global, there is a derived class wxModule definition down at the bottom of the class's .cpp file (the module doesn't need to be mentioned in any header anywhere). Before the program 'starts' any execution, it gets a list of all the modules in the application and runs all of their OnInit() functions (which will do nothing in this application; they just return TRUE). After the program 'ends', then all of the wxModule's OnExit() functions are called, which will clean up the classes managed by the wxModule. Each of the classes managed by wxModule have a get() and set() method which gets or sets the single instance. By calling some_class::get() you can create an instance on demand if there isn't one yet, but retrieve the existing instance if there is one already made. For example, see the call to help_controller::get()->show_help_topic(plkrHELP_ID_BOOKMARK_DIALOG) in the bookmark_dialog::on_help_button() above: it will get the single help_controller and call its show_help_topic() method if it exists already, or else create one on demand and then do its show_help_topic() method. |
//---------------------------------------------------------------------------------------- // Module definition //---------------------------------------------------------------------------------------- class module_body_dialog : public wxModule { DECLARE_DYNAMIC_CLASS( module_body_dialog ) public: module_body_dialog() {} bool OnInit() { return TRUE; } void OnExit() { wxLogDebug( "Entered module_body_dialog::OnExit()" ); // We set it to null, and a pointer returns to the previous one, which we delete. delete body_dialog::set( NULL ); wxLogDebug( "Completed module_body_dialog::OnExit()" ); } }; IMPLEMENT_DYNAMIC_CLASS( module_body_dialog, wxModule )
End feature removal condition codeblock: If this .cpp file was part of a feature that could be compiled out, then close the #if compiler directive that we started way back at the top of this file. It is now visible why the application's setup.h works to remove the feature: since if the define was set to zero, then this whole .cpp file would pretty much collapse to zero code. |
//---------------------------------------------------------------------------------------- // End feature removal condition //---------------------------------------------------------------------------------------- #endif // setupUSE_INTEGRATED_HTML_EDITOR