|
From: <ma...@us...> - 2003-12-29 04:34:37
|
Update of /cvsroot/sharedaemon/ui-wx/src
In directory sc8-pr-cvs1:/tmp/cvs-serv7064
Modified Files:
Images.cpp Images.h SBPanel.cpp SBPanel.h
Log Message:
Improved documentation of CImages and CSBPanel classes.
Index: Images.cpp
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/Images.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- Images.cpp 29 Dec 2003 03:54:50 -0000 1.46
+++ Images.cpp 29 Dec 2003 04:34:33 -0000 1.47
@@ -30,32 +30,38 @@
#include "Images.h"
+/* List to store all bitmaps in */
#include <wx/listimpl.cpp>
WX_DEFINE_LIST(ListOfBitmaps);
-/* Constructor for CImages class */
+/******************************************************************** CImages */
+/* Constructor for CImages class */
+/* Initialises images list and calls LoadImages to populate it. */
+/******************************************************************************/
CImages::CImages() {
images = ListOfBitmaps(wxKEY_STRING);
tool_img_height = tool_img_width = 0;
LoadImages();
}
-/**
- * Destructor for CImages class. Deletes contents of `images` list
- */
+/******************************************************************* ~CImages */
+/* Destructor for CImages class. Deletes contents of `images` list. */
+/******************************************************************************/
CImages::~CImages() {
images.DeleteContents(true);
images.Clear();
}
-/**
- * This method loads all images into the global variables.
- */
+/***************************************************************** LoadImages */
+/* This method first clears up any contents previously in @images list, and */
+/* then proceeds to populate the list with images loaded from files at */
+/* directory specified by MakePath() method. */
+/* TODO: Put names into temporary wxString array and use for-loop to load 'em.*/
+/******************************************************************************/
void CImages::LoadImages() {
wxString path;
tool_img_width = 32;
- /* Just in case theres anything in there, delete it */
images.DeleteContents(true);
images.Clear();
@@ -243,11 +249,12 @@
);
}
-/**
- * This is an "Images Getter". It finds the requested image by searching
- * the image list by name. If not found, error message is generated,
- * but we still return the pointer (even if its illegal).
- */
+/******************************************************************* GetImage */
+/* This is an "Images Getter". It finds the requested image by searching the */
+/* image list by name. If not found, error message is generated and */
+/* wxNullBitmap returned. */
+/* @name Name of the image to be searched from @images list */
+/******************************************************************************/
wxBitmap& CImages::GetImage(const wxString &name) {
ListOfBitmaps::Node *tmp = images.Find(name);
@@ -262,11 +269,13 @@
return *(tmp->GetData());
}
-/**
- * This method searches recusivly through all children under *parent for
- * wxStaticBitmap type windows and sets their image by looking up the
- * correct image by its name.
- */
+/*************************************************************** UpdateImages */
+/* This method searches recusivly through all children under *parent for */
+/* wxStaticBitmap type windows and sets their image by looking up the */
+/* correct image by its name. */
+/* On wxGTK/wxMac, MBitmapButtons are also searched for and updated. */
+/* @parent Window to start recursive searching from. */
+/******************************************************************************/
void CImages::UpdateImages(wxWindow *parent) {
if (parent->GetClassInfo()->IsKindOf(CLASSINFO(wxStaticBitmap))) {
((wxStaticBitmap*)parent)->SetBitmap(
@@ -285,13 +294,19 @@
}
}
-/**
- * This method makes a new toolbar image. `name` is the label to be printed on
- * the final image, `image` is a name of the image in Images list. we create
- * a new wxBitmap object with width according to the length of width of `name`,
- * and draw the bitmap+text on it. Finally, the generated image is saved back
- * to Images list under the same name (previous version is deleted).
- */
+/******************************************************************************/
+/* This method generates a new image for usage on toolbar from the passed */
+/* name and image by loading the @image into wxMemoryDC, and then drawing */
+/* the text also there. Finally, the image is saved back to @images list */
+/* under @name. The tricky part here is finding out the width of the image */
+/* (which is done in CalcToolBitmapSize). Don't call this method before */
+/* calling CalcToolBitmapSize, otherwise the results from this method might */
+/* be... un-satisfying. Second tricky part here is getting transparency */
+/* working. On wxMSW, we draw background with wxLIGHT_GREY brush (heh, go */
+/* figure :)), elsewhere we use a black wxMask. */
+/* @name String to be printed on the image */
+/* @image Image to be looked up from @images and drawn. */
+/******************************************************************************/
wxBitmap& CImages::MakeToolImage(const wxString &name, const wxString &image) {
wxMemoryDC mdc;
wxBitmap tmp, tmp_new;
@@ -323,9 +338,9 @@
mdc.GetTextExtent(name, &x, &y);
mdc.DrawText(name, (tmp_new.GetWidth()-x)/2, 36);
#ifndef __WXMSW__ /* Use wxMask for transparency */
- wxMask *tmp_mask;
- tmp_mask = new wxMask(tmp_new, wxColour(0,0,0));
- tmp_new.SetMask(tmp_mask);
+ wxMask *tmp_mask;
+ tmp_mask = new wxMask(tmp_new, wxColour(0,0,0));
+ tmp_new.SetMask(tmp_mask);
#endif
mdc.EndDrawing();
@@ -341,7 +356,7 @@
/* calculated text length exceeds what is stored in global variables, update */
/* the global variables with new values. All this is neccesery to do before */
/* calling MakeToolImage(),otherwise the toolbar won't be correctly centered. */
-/* @names wxArrayString containing all toolbar button names. */
+/* @names wxArrayString containing all toolbar button names. */
/******************************************************************************/
void CImages::CalcToolBitmapSize(const wxArrayString &names) {
unsigned int i=0; /* Loop counter */
@@ -363,19 +378,19 @@
}
}
-/****************************************************************** MakePath */
-/* This method creates a platform-dependant path string for accessing images */
-/* from. Since various platforms use various standard locations for resouce */
-/* locations, this method handles it as follows: */
-/* Win32 @executable_path@/images/@iconsetname@/ */
-/* Linux @executable_path@/images/@iconsetname@/ */
-/* Mac OS X */
-/* CodeWarrior :@executable_path@::Resources:images:@iconsetname@ */
-/* GNU gcc @executable_path@/images/@iconsetname@/ */
-/* */
-/* TODO: Use /usr/share area on Linux */
-/* Check various locations, detect if images can be found. */
-/*****************************************************************************/
+/******************************************************************* MakePath */
+/* This method creates a platform-dependant path string for accessing images */
+/* from. Since various platforms use various standard locations for resouce */
+/* locations, this method handles it as follows: */
+/* Win32 @executable_path@/images/@iconsetname@/ */
+/* Linux @executable_path@/images/@iconsetname@/ */
+/* Mac OS X */
+/* CodeWarrior :@executable_path@::Resources:images:@iconsetname@ */
+/* GNU gcc @executable_path@/images/@iconsetname@/ */
+/* */
+/* TODO: Use /usr/share area on Linux */
+/* Check various locations, detect if images can be found. */
+/******************************************************************************/
wxString CImages::MakePath() {
wxString path, apppath;
wxChar sep;
Index: Images.h
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/Images.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- Images.h 27 Dec 2003 08:39:04 -0000 1.21
+++ Images.h 29 Dec 2003 04:34:33 -0000 1.22
@@ -31,22 +31,34 @@
#include "defines.h"
#include "MBitmapButton.h"
+/* List to store the images in */
WX_DECLARE_LIST(wxBitmap, ListOfBitmaps);
+/****************************** CImages class *********************************/
+/* This class stores a list of wxBitmap's and provides getting/putting */
+/* functionality. The idea is to keep all images of the interface in one */
+/* place, which makes it easier to do runtime iconsets updating and similar. */
+/* Also, other several images-related methods are here, like MakeToolImage, */
+/* UpdateImages etc. */
+/******************************************************************************/
extern class CImages *img;
class CImages {
public:
- CImages();
- virtual ~CImages();
- wxBitmap& MakeToolImage(const wxString &name, const wxString &image);
- int tool_img_width, tool_img_height;
- void LoadImages();
- wxBitmap& GetImage(const wxString &name);
- void UpdateImages(wxWindow *parent);
- void CalcToolBitmapSize(const wxArrayString &names);
+ CImages(); /* Constructor, empties @images and calls LoadImages() */
+ virtual ~CImages(); /* Destructor, empties @images */
+ wxBitmap& MakeToolImage( /* Generates image for showing in ToolBar */
+ const wxString &name, const wxString &image
+ );
+ int tool_img_width, tool_img_height; /* Toolbar image x/y sizes */
+ void LoadImages(); /* Loads images from files */
+ wxBitmap& GetImage(const wxString &name);/* Returns image named @name */
+ void UpdateImages(wxWindow *parent); /* Recursivly updates GUI images */
+ void CalcToolBitmapSize( /* Calculates image size for toolbar buttons */
+ const wxArrayString &names
+ );
private:
- ListOfBitmaps images;
- wxString MakePath();
+ ListOfBitmaps images; /* The list of wxBitmap's */
+ wxString MakePath();/* Generates platform-dependant path to the files */
};
#endif /* __IMAGES_H__ */
Index: SBPanel.cpp
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/SBPanel.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- SBPanel.cpp 29 Dec 2003 03:54:50 -0000 1.17
+++ SBPanel.cpp 29 Dec 2003 04:34:33 -0000 1.18
@@ -30,17 +30,20 @@
#include "SBPanel.h"
-/**
- * CSBPanel class
- */
BEGIN_EVENT_TABLE(CSBPanel, wxPanel)
EVT_BUTTON(-1, CSBPanel::Toggle)
END_EVENT_TABLE()
-/**
- * Constructor for CSBPanel object. We create a Static Box inside this panel
- * and a "headerbutton" which will then provide us with toggling functionality.
- */
+/******************************************************************* CSBPanel */
+/* Constructor for CSBPanel object. We create a Static Box inside this panel */
+/* and a "headerbutton" which will then provide us with toggling */
+/* functionality. */
+/* @parent Parent window for this control */
+/* @id ID for this panel */
+/* @title String to be used for toggle-button */
+/* @name Name for this panel (used for state saving location) */
+/* @image Name of the image that will be retreived from CImages class */
+/******************************************************************************/
CSBPanel::CSBPanel(
wxWindow *parent, wxWindowID id, const wxString &title,
const wxString &name, const wxString &image
@@ -74,7 +77,7 @@
);
wxFont fnt = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
fnt.SetWeight(wxBOLD);
- headerbmpbtn->SetFont(fnt);
+ headerbtn->SetFont(fnt);
header_btn_id = headerbtn->GetId();
mainsizer->Add(headerbtn, 0, wxGROW|wxADJUST_MINSIZE, 5);
@@ -88,10 +91,10 @@
shown = false;
}
-/**
- * Destructor. Save content displayment bool into config object under
- * /ParentName/ThisName
- */
+/****************************************************************** ~CSBPanel */
+/* Destructor. Save content displayment bool into config object under */
+/* ParentName/ThisName */
+/******************************************************************************/
CSBPanel::~CSBPanel() {
m_config->Write(
wxT("/")+GetParent()->GetName()+wxT("/")+GetName(),
@@ -99,12 +102,12 @@
);
}
-/**
- * Toggle method provides functionality for showing/hiding the contents
- * of this panel. First we check that the triggered event actually belongs
- * to our toggler-button. If so, we Hide the content, and call Fit() and
- * Layout() as neccesery.
- */
+/********************************************************************* Toggle */
+/* Toggle method provides functionality for showing/hiding the contents */
+/* of this panel. First we check that the triggered event actually belongs */
+/* to our toggler-button. If so, we Hide the content, and call Layout() as */
+/* neccesery. */
+/******************************************************************************/
void CSBPanel::Toggle(wxCommandEvent &event) {
if (event.GetId() != header_btn_id) {
event.Skip();
@@ -121,13 +124,13 @@
GetParent()->Layout();
}
-/**
- * This method adds contents (a sizer) into the section. We store
- * the pointer to the content sizer locally for easier access.
- * If there is any existing content in CSBPAnel, it is removed.
- * And last, read from config under section /ParentWindowName/SectionName
- * if the new section should be shown or not (default: true)
- */
+/***************************************************************** SetContent */
+/* This method adds contents (a sizer) into the section. We store the pointer */
+/* to the content sizer locally for easier access. If there is any existing */
+/* content in CSBPAnel, it is removed. And last, read from config under */
+/* section /ParentWindowName/SectionName if the new section should be shown */
+/* or not (default: true) and "Toggle" if needed. */
+/******************************************************************************/
void CSBPanel::SetContent(wxSizer *data) {
bool tmp;
@@ -145,22 +148,9 @@
wxT("/")+GetParent()->GetName()+wxT("/")+GetName(), &tmp, true
);
- /**
- * If config instructs us to NOT show the contents, call Toggle()
- * method with nullevent .
- */
if (!tmp) {
wxCommandEvent nullevent;
nullevent.SetId(header_btn_id);
Toggle(nullevent);
}
}
-
-
-
-
-
-
-
-
-
Index: SBPanel.h
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/SBPanel.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- SBPanel.h 27 Dec 2003 07:18:20 -0000 1.7
+++ SBPanel.h 29 Dec 2003 04:34:33 -0000 1.8
@@ -34,40 +34,33 @@
#include "MBitmapButton.h"
#include "Images.h"
-#if defined(__WXMSW__) || defined(__GTK2__)
- #define SB_BTN_FONT_SIZE 10
-#else
- #define SB_BTN_FONT_SIZE 12
-#endif
-
-/**
- * SBPanel, or SideBar Panel is a panel with a button on top of it
- * that provides its "closing" and "opening" functionality.
- * Usage:
- * Create new CSBPanel object and call SetContent(wxPanel *data) to
- * populate the panel with contents. You CAN NOT set two contents to
- * one section, but calling SetContent() at later time will replace
- * current contents with new contents.
- */
+/******************************************************************************/
+/* SBPanel, or SideBar Panel is a panel with a button on top of it that */
+/* provides its "closing" and "opening" functionality. */
+/* Usage: */
+/* Create new CSBPanel object and call SetContent(wxPanel *data) to populate */
+/* the panel with contents. You CAN NOT set two contents to one section, but */
+/* calling SetContent() at later time will replace current contents with new */
+/* contents. */
+/******************************************************************************/
class CSBPanel : public wxPanel {
public:
- CSBPanel(
+ CSBPanel( /* Constructor, creates header button */
wxWindow *parent, wxWindowID id,
const wxString &title, const wxString &name,
const wxString &image = wxEmptyString
);
- virtual ~CSBPanel();
+ virtual ~CSBPanel(); /* Destructor, saves toggle state */
- void SetContent(wxSizer *data);
- void Toggle(wxCommandEvent &event);
+ void SetContent(wxSizer *data); /* Set @data as content */
+ void Toggle(wxCommandEvent &event);/* Toggles displayment of @content */
private:
DECLARE_EVENT_TABLE();
-
- wxStaticBoxSizer *mainsizer;
- wxSizer *content;
- int header_btn_id;
- bool shown;
- bool use_image;
+ wxStaticBoxSizer *mainsizer; /* Main sizer of this control */
+ wxSizer *content; /* The content of this control */
+ int header_btn_id; /* ID of the header toggle button */
+ bool shown; /* Wether @content is shown or not */
+ bool use_image; /* Wether image is used in headerbtn */
};
#endif
|