From: <ma...@us...> - 2003-12-27 08:39:08
|
Update of /cvsroot/sharedaemon/ui-wx/src In directory sc8-pr-cvs1:/tmp/cvs-serv10573 Modified Files: Images.cpp Images.h MBitmapButton.cpp MBitmapButton.h Log Message: wxGTK/wxMac version of MBitmapButton now also updates itself correctly on iconset change. Index: Images.cpp =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/Images.cpp,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -r1.43 -r1.44 --- Images.cpp 25 Dec 2003 02:18:57 -0000 1.43 +++ Images.cpp 27 Dec 2003 08:39:04 -0000 1.44 @@ -273,6 +273,9 @@ GetImage(parent->GetName()) ); } + if (parent->GetClassInfo()->IsKindOf(CLASSINFO(MBitmapButton))) { + ((MBitmapButton*)parent)->GenImage(); + } wxWindowList controls; controls = parent->GetChildren(); for (unsigned int i=0;i<controls.GetCount();i++) { Index: Images.h =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/Images.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- Images.h 25 Dec 2003 02:18:57 -0000 1.20 +++ Images.h 27 Dec 2003 08:39:04 -0000 1.21 @@ -29,6 +29,7 @@ #endif #include "defines.h" +#include "MBitmapButton.h" WX_DECLARE_LIST(wxBitmap, ListOfBitmaps); Index: MBitmapButton.cpp =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/MBitmapButton.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- MBitmapButton.cpp 27 Dec 2003 07:18:20 -0000 1.9 +++ MBitmapButton.cpp 27 Dec 2003 08:39:04 -0000 1.10 @@ -87,15 +87,16 @@ } #else /* Use wxBitmapButton on other platforms */ + +IMPLEMENT_DYNAMIC_CLASS(MBitmapButton, wxBitmapButton) + BEGIN_EVENT_TABLE(MBitmapButton, wxBitmapButton) EVT_BUTTON(-1, MBitmapButton::OnClick) EVT_SIZE(MBitmapButton::OnSize) END_EVENT_TABLE() /************************************************************** MBitmapButton */ -/* This method constructs a bitmapbutton control from the passed arguments by */ -/* creating a new wxBitmap in memoryDC, drawing the passed name/image in it, */ -/* and setting it as BitmapLabel. */ +/* Constructor - stores the neccesery variables locally and calls GenImage(). */ /* @parent Which wxWindow shall be this controls parent */ /* @id Identification code (int) for this control */ /* @name Name label to be shown on this button */ @@ -105,19 +106,66 @@ /* @style Style flag - see wxWindow/wxControl style flags in wxHelp */ /******************************************************************************/ MBitmapButton::MBitmapButton( - wxWindow *parent, wxWindowID id, const wxString &name, const wxBitmap + wxWindow *parent, wxWindowID id, const wxString &name, const wxString &image, const wxPoint &pos, const wxSize &size, long style, const wxValidator &val) : wxBitmapButton(parent, id, wxNullBitmap, pos, size, style, val, name) { + m_name = name; + m_image = image; + GenImage(); +} + +/********************************************************************* OnSize */ +/* This method creates a new temporary bitmap with new control size, copies */ +/* the currently set bitmap into the temporary bitmap and sets the new image */ +/* as BitmapLabel. This is done to preserve the label left-alignment even */ +/* after size change. */ +/******************************************************************************/ +void MBitmapButton::OnSize(wxSizeEvent &event) { +wxMemoryDC mdc; + + wxBitmap tmp( + GetSize().GetWidth()+LABEL_POS_OFFSET, + GetSize().GetHeight()+LABEL_POS_OFFSET + ); + mdc.SelectObject(tmp); + +#ifdef __WXMSW__ /* This gives transparent image on wxMSW */ + mdc.SetPen(*wxTRANSPARENT_PEN); + mdc.SetBrush(wxBrush(*wxLIGHT_GREY, wxSOLID)); +#else /* Elsewhere, it will be done with wxMask later */ + mdc.SetBrush(wxBrush(wxColour(0, 0, 0), wxSOLID)); +#endif + mdc.DrawRectangle(0, 0, tmp.GetWidth(), tmp.GetHeight()); + mdc.DrawBitmap(orig_img, 0, 0, true); +#ifndef __WXMSW__ + tmp.SetMask(new wxMask(tmp, wxColour(0, 0, 0))); +#endif + SetBitmapLabel(tmp); + + event.Skip(); +} + +/******************************************************************* GenImage */ +/* This method generates the bitmap label for this control. We create a */ +/* temporary bitmap for measuring font length, and then create final image */ +/* with correct calculated size. Finally, draw the image and text there. */ +/* Rectangle drawing and various #ifdefs are required to achieve correct */ +/* transparency on all platforms. */ +/******************************************************************************/ +void MBitmapButton::GenImage() { wxMemoryDC mdc; wxBitmap *tmp; wxCoord x, y; + + wxBitmap bitmap(img->GetImage(m_image)); + mdc.SelectObject(wxBitmap(100, 100)); mdc.SetFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT)); - mdc.GetTextExtent(name, &x, &y); - x+=image.GetWidth()+LABEL_WIDTH_ADDITION; + mdc.GetTextExtent(m_name, &x, &y); + x+=bitmap.GetWidth()+LABEL_WIDTH_ADDITION; - image.GetHeight() > y ? y = image.GetHeight()+5 : y+=5; + bitmap.GetHeight() > y ? y = bitmap.GetHeight()+5 : y+=5; tmp = new wxBitmap(x, y); @@ -131,12 +179,12 @@ mdc.DrawRectangle(0, 0, tmp->GetWidth(), tmp->GetHeight()); mdc.DrawBitmap( - image, 5, ((y-image.GetHeight())/2)+BITMAP_Y_POS_OFFSET, true + bitmap, 5, ((y-bitmap.GetHeight())/2)+BITMAP_Y_POS_OFFSET, true ); mdc.SetTextForeground(wxColour(50, 50, 50)); mdc.DrawText( - name, image.GetWidth()+10, + m_name, bitmap.GetWidth()+10, ((tmp->GetHeight()-GetCharHeight())/2)+TEXT_Y_POS_OFFSET ); @@ -147,37 +195,6 @@ orig_img = *tmp; SetSize(wxSize(tmp->GetWidth()+10, tmp->GetHeight()+5)); delete tmp; -} - -/********************************************************************* OnSize */ -/* This method creates a new temporary bitmap with new control size, copies */ -/* the currently set bitmap into the temporary bitmap and sets the new image */ -/* as BitmapLabel. This is done to preserve the label left-alignment even */ -/* after size change. */ -/******************************************************************************/ -void MBitmapButton::OnSize(wxSizeEvent &event) { -wxMemoryDC mdc; - - wxBitmap tmp( - GetSize().GetWidth()+LABEL_POS_OFFSET, - GetSize().GetHeight()+LABEL_POS_OFFSET - ); - mdc.SelectObject(tmp); - -#ifdef __WXMSW__ /* This gives transparent image on wxMSW */ - mdc.SetPen(*wxTRANSPARENT_PEN); - mdc.SetBrush(wxBrush(*wxLIGHT_GREY, wxSOLID)); -#else /* Elsewhere, it will be done with wxMask later */ - mdc.SetBrush(wxBrush(wxColour(0, 0, 0), wxSOLID)); -#endif - mdc.DrawRectangle(0, 0, tmp.GetWidth(), tmp.GetHeight()); - mdc.DrawBitmap(orig_img, 0, 0, true); -#ifndef __WXMSW__ - tmp.SetMask(new wxMask(tmp, wxColour(0, 0, 0))); -#endif - SetBitmapLabel(tmp); - - event.Skip(); } #endif Index: MBitmapButton.h =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/MBitmapButton.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- MBitmapButton.h 27 Dec 2003 07:18:20 -0000 1.7 +++ MBitmapButton.h 27 Dec 2003 08:39:04 -0000 1.8 @@ -94,18 +94,22 @@ /* passed to us and setting it as this controls BitmapLabel. */ /******************************************************************************/ class MBitmapButton : public wxBitmapButton { +DECLARE_DYNAMIC_CLASS(MBitmapButton) public: MBitmapButton( /* Constructor */ wxWindow *parent, wxWindowID id, const wxString &title, const - wxBitmap &image, const wxPoint &pos = wxDefaultPosition, + wxString &image, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxBU_AUTODRAW, const wxValidator &val = wxDefaultValidator ); + MBitmapButton() {} /* Default constructor */ + void GenImage(); /* Generates the image for this control */ private: DECLARE_EVENT_TABLE() void OnClick(wxCommandEvent &event){ event.Skip(); } /* Skips events */ void OnSize(wxSizeEvent &event); /* Updates image */ wxBitmap orig_img; /* Original generated image */ + wxString m_name, m_image; /* Name and image of the control */ }; #endif // ___WXMSW__ |