|
From: <ma...@us...> - 2003-12-22 09:53:02
|
Update of /cvsroot/sharedaemon/ui-wx/src
In directory sc8-pr-cvs1:/tmp/cvs-serv5388
Modified Files:
MBitmapButton.cpp
Log Message:
Fixes wxGTK sidebar buttons
Index: MBitmapButton.cpp
===================================================================
RCS file: /cvsroot/sharedaemon/ui-wx/src/MBitmapButton.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- MBitmapButton.cpp 22 Dec 2003 05:04:15 -0000 1.1
+++ MBitmapButton.cpp 22 Dec 2003 09:52:58 -0000 1.2
@@ -50,32 +50,32 @@
wxWindow *parent, wxWindowID id, const wxString &name, const wxBitmap
&image, const wxPoint &pos, const wxSize &size, long style
) : wxButton(parent, id, name, pos, size, style) {
-
- wxString imgname;
+
+ wxString imgname;
imgname.Format(wxT("%simg_%s"), imgname.c_str(), name.c_str());
-
+
wxFlexGridSizer *s_main = new wxFlexGridSizer(0, 0);
wxStaticBitmap *img = new wxStaticBitmap(
this, 1000, image, wxDefaultPosition,
wxSize(image.GetWidth(), image.GetHeight()), 5, imgname
);
- s_main->Add(img, 0, wxLEFT|wxALIGN_CENTER_VERTICAL|wxADJUST_MINSIZE, 5);
-
- /**
- * Dirty trick:
- * Create a hidden textctrl to force button take correct size.
+ s_main->Add(img, 0, wxLEFT|wxALIGN_CENTER_VERTICAL|wxADJUST_MINSIZE, 5);
+
+ /**
+ * Dirty trick:
+ * Create a hidden textctrl to force button take correct size.
*/
wxStaticText *txt = new wxStaticText(
this, -1, name, wxDefaultPosition,
wxDefaultSize, wxTRANSPARENT_WINDOW
- );
+ );
txt->Hide();
- s_main->Add(txt, 1, wxALL|wxADJUST_MINSIZE, 5);
-
+ s_main->Add(txt, 1, wxALL|wxADJUST_MINSIZE, 5);
+
SetSizer(s_main);
SetAutoLayout(true);
s_main->Fit(this);
- s_main->SetSizeHints(this);
+ s_main->SetSizeHints(this);
Layout();
}
@@ -113,36 +113,36 @@
wxMemoryDC mdc;
wxBitmap *tmp;
wxCoord x, y;
-
- mdc.SelectObject(wxBitmap(100, 100));
- mdc.SetFont(wxFont(BTN_FONT_SIZE, wxDEFAULT, wxNORMAL, wxNORMAL));
- mdc.GetTextExtent(name, &x, &y);
-
- x+=image.GetWidth()+10;
- image.GetHeight() > y ? y = image.GetHeight()+5 : y+=5;
-
- tmp = new wxBitmap(x, y);
-
- 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(image, 5, (y-image.GetHeight())/2, true);
-
- mdc.SetTextForeground(wxColour(1, 1, 1));
- mdc.DrawText(name, image.GetWidth()+10, (tmp->GetHeight()-GetCharHeight())/2);
-#ifndef __WXMSW__
- tmp->SetMask(new wxMask(*tmp, wxColour(0, 0, 0)));
-#endif
- SetBitmapLabel(*tmp);
- SetSize(wxSize(tmp->GetWidth()+5, tmp->GetHeight()+5));
- delete tmp;
+
+ mdc.SelectObject(wxBitmap(100, 100));
+ mdc.SetFont(wxFont(BTN_FONT_SIZE, wxDEFAULT, wxNORMAL, wxNORMAL));
+ mdc.GetTextExtent(name, &x, &y);
+
+ x+=image.GetWidth()+10;
+ image.GetHeight() > y ? y = image.GetHeight()+5 : y+=5;
+
+ tmp = new wxBitmap(x, y);
+
+ 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(image, 5, (y-image.GetHeight())/2, true);
+
+ mdc.SetTextForeground(wxColour(1, 1, 1));
+ mdc.DrawText(name, image.GetWidth()+10, (tmp->GetHeight()-GetCharHeight())/2);
+#ifndef __WXMSW__
+ tmp->SetMask(new wxMask(*tmp, wxColour(0, 0, 0)));
+#endif
+ SetBitmapLabel(*tmp);
+ SetSize(wxSize(tmp->GetWidth()+5, tmp->GetHeight()+5));
+ delete tmp;
}
/********************************************************************* OnSize */
@@ -152,24 +152,26 @@
/* after size change. */
/******************************************************************************/
void MBitmapButton::OnSize(wxSizeEvent &event) {
-wxMemoryDC mdc;
-
- wxBitmap tmp(GetSize().GetWidth(), GetSize().GetHeight());
- 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(GetBitmapLabel(), 0, 1, true);
-#ifndef __WXMSW__
- tmp.SetMask(new wxMask(tmp, wxColour(0, 0, 0)));
-#endif
- SetBitmapLabel(tmp);
- event.Skip();
+wxMemoryDC mdc;
+
+ /* GTK adds 6 pixels between image and button - substract it. */
+ wxBitmap tmp(GetSize().GetWidth()-6, GetSize().GetHeight()-6);
+ 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(GetBitmapLabel(), 0, 0, true);
+#ifndef __WXMSW__
+ tmp.SetMask(new wxMask(tmp, wxColour(0, 0, 0)));
+#endif
+ SetBitmapLabel(tmp);
+
+ event.Skip();
}
#endif
|