Update of /cvsroot/sharedaemon/ui-wx/src In directory sc8-pr-cvs1:/tmp/cvs-serv28213 Modified Files: Images.cpp MainDlg.cpp MainDlg.h Makefile.am defines.h Added Files: MBitmapButton.cpp MBitmapButton.h MMultiButton.cpp MMultiButton.h Log Message: New MBitmapButton and MMultiButton controls - button-with-image-and-text and control-with-n-sub-buttons, respectivly. Now toolbar looks really cool :) --- NEW FILE: MBitmapButton.cpp --- /* * This file is part of wxInterface. * Copyright (C) 2003 Alo Sarv <ma...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef __GNUG__ #pragma implementation "MBitmapButton.cpp" #endif // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #include "MBitmapButton.h" #if defined(__WXMSW__) /* On wxMSW, use wxButton as base */ BEGIN_EVENT_TABLE(MBitmapButton, wxButton) EVT_BUTTON(-1, MBitmapButton::OnClick) END_EVENT_TABLE() /************************************************************** MBitmapButton */ /* This method constructs a bitmapbutton object by attaching a sizer to the */ /* wxButton and stuffing the wxStaticBitmap/wxStaticText in there. */ /* @parent Which wxWindow shall be this controls parent */ /* @id Identification code (int) for this control */ /* @name Name label to be shown on this button */ /* @image Image label to be shown on this button */ /* @pos Position to insert this control to */ /* @size Size of this control */ /* @style Style flag - see wxWindow/wxControl style flags in wxHelp */ /******************************************************************************/ MBitmapButton::MBitmapButton( 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; 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. */ wxStaticText *txt = new wxStaticText( this, -1, name, wxDefaultPosition, wxDefaultSize, wxTRANSPARENT_WINDOW ); txt->Hide(); s_main->Add(txt, 1, wxALL|wxADJUST_MINSIZE, 5); SetSizer(s_main); SetAutoLayout(true); s_main->Fit(this); s_main->SetSizeHints(this); Layout(); } /******************************************************************** OnClick */ /* Redraws the bitmap and skips the event (to be handled in parent control. */ /******************************************************************************/ void MBitmapButton::OnClick(wxCommandEvent &event) { Refresh(); event.Skip(); } #else /* Use wxBitmapButton on other platforms */ 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. */ /* @parent Which wxWindow shall be this controls parent */ /* @id Identification code (int) for this control */ /* @name Name label to be shown on this button */ /* @image Image label to be shown on this button */ /* @pos Position to insert this control to */ /* @size Size of this control */ /* @style Style flag - see wxWindow/wxControl style flags in wxHelp */ /******************************************************************************/ MBitmapButton::MBitmapButton( wxWindow *parent, wxWindowID id, const wxString &name, const wxBitmap &image, const wxPoint &pos, const wxSize &size, long style, const wxValidator &val) : wxBitmapButton(parent, id, wxNullBitmap, pos, size, style, val, name) { 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; } /********************************************************************* 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(), 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(); } #endif --- NEW FILE: MBitmapButton.h --- /* * This file is part of wxInterface. * Copyright (C) 2003 Alo Sarv <ma...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __MBitmapButton__ #define __MBitmapButton__ #ifdef __GNUG__ #pragma interface "MBitmapButton.cpp" #endif #ifndef WX_PRECOMP #include "wx/wx.h" #endif #if defined(__WXMSW__) || defined(__GTK2__) #define BTN_FONT_SIZE 10 #else #define BTN_FONT_SIZE 12 #endif #if defined(__WXMSW__) /* Need to use wxButton on MSW */ /******************************************************** class MBitmapButton */ /* This class provides functionality of having image AND text on the same */ /* button. This is done by attaching a sizer into the button, with */ /* wxStaticBitmap and wxStaticText controls in it. */ /******************************************************************************/ class MBitmapButton : public wxButton { public: MBitmapButton( /* Constructor */ wxWindow *parent, wxWindowID id, const wxString &title, const wxBitmap &image, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxNO_FULL_REPAINT_ON_RESIZE ); private: DECLARE_EVENT_TABLE() void OnClick(wxCommandEvent &event); /* Skips the events */ }; #else // !__WXMSW__ /* Use wxBitmapButton elsewhere */ /******************************************************** class MBitmapButton */ /* This class provides functionality of having image AND text on the same */ /* button. This is done by generating a new wxBitmap image from the arguments */ /* passed to us and setting it as this controls BitmapLabel. */ /******************************************************************************/ class MBitmapButton : public wxBitmapButton { public: MBitmapButton( /* Constructor */ wxWindow *parent, wxWindowID id, const wxString &title, const wxBitmap &image, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxBU_AUTODRAW, const wxValidator &val = wxDefaultValidator ); private: DECLARE_EVENT_TABLE() void OnClick(wxCommandEvent &event){ event.Skip(); } /* Skips events */ void OnSize(wxSizeEvent &event); /* Updates image */ }; #endif // ___WXMSW__ #endif // __MBITMAPBUTTON_H__ --- NEW FILE: MMultiButton.cpp --- /* * This file is part of wxInterface. * Copyright (C) 2003 Alo Sarv <ma...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef __GNUG__ #pragma implementation "MMultiButton.cpp" #endif // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #include "MMultiButton.h" #include <wx/listimpl.cpp> WX_DEFINE_LIST(MBitmapList); BEGIN_EVENT_TABLE(MMultiButton, wxControl) EVT_PAINT(MMultiButton::OnPaint) END_EVENT_TABLE() /*************************************************************** MMultiButton */ /* This constructor creates a multi-button control with normal wxButton type */ /* children. Derived from wxControl, it creates a sizer to contain the sub- */ /* controls, and adds them there. Finally, background colour is set to match */ /* parent's background colour. */ /* @parent Which wxWindow shall be this controls parent */ /* @id Identification code (int) for this control */ /* @count Number of buttons to be added to this control */ /* @names Array containing list of button names to be added */ /* @ids Array of integers containing ID codes for sub-buttons */ /* @pos Position to insert this control to */ /* @size Size of this control */ /* @style Style flag - see wxWindow/wxControl style flags in wxHelp */ /******************************************************************************/ MMultiButton::MMultiButton( wxWindow *parent, wxWindowID id, size_t count, const wxArrayString &names, int ids[], const wxPoint &pos, const wxSize &size, long style ) : wxControl(parent, id, pos, size, style) { wxASSERT(count <= names.GetCount()); wxFlexGridSizer *s_main = new wxFlexGridSizer(1); s_main->AddGrowableCol(0); for (size_t i=0;i<count;i++) { s_main->Add(new wxButton(this, ids[i], names[i]), 0, wxGROW, 0); } SetBackgroundColour(parent->GetBackgroundColour()); SetSizer(s_main); SetAutoLayout(true); s_main->Fit(this); s_main->SetSizeHints(this); Fit(); Layout(); } /*************************************************************** MMultiButton */ /* This constructor creates a multi-button control with MBitmapButton type */ /* children. Derived from wxControl, it creates a sizer to contain the sub- */ /* controls, and adds them there. Finally, background colour is set to match */ /* parent's background colour. */ /* @parent Which wxWindow shall be this controls parent */ /* @id Identification code (int) for this control */ /* @count Number of buttons to be added to this control */ /* @names Array containing list of button names to be added */ /* @ids Array of integers containing ID codes for sub-buttons */ /* @images List of images to be used for buttons */ /* @pos Position to insert this control to */ /* @size Size of this control */ /* @style Style flag - see wxWindow/wxControl style flags in wxHelp */ /******************************************************************************/ MMultiButton::MMultiButton( wxWindow *parent, wxWindowID id, size_t count, const wxArrayString &names, int ids[], const MBitmapList &images, const wxPoint &pos, const wxSize &size, long style ) : wxControl(parent, id, pos, size, style) { MBitmapButton *btn; wxASSERT(count <= names.GetCount()); wxASSERT(count <= images.GetCount()); wxFlexGridSizer *s_main = new wxFlexGridSizer(1); s_main->AddGrowableCol(0); for (size_t i=0;i<count;i++) { btn = new MBitmapButton(this, ids[i], names[i], *(images.Item(i)->GetData())); s_main->Add(btn, 0, wxGROW, 0); } SetBackgroundColour(parent->GetBackgroundColour()); SetSizer(s_main); SetAutoLayout(true); s_main->Fit(this); s_main->SetSizeHints(this); Fit(); Layout(); } /******************************************************************** OnPaint */ /* Paint events handler, usually called from Event table. This sets controls */ /* background colour to match parents background colour and updates size. */ /* This is needed to keep the control up-to-date even after system colours */ /* or fonts change. */ /* @event References to the event. */ /******************************************************************************/ void MMultiButton::OnPaint(wxPaintEvent &event) { SetBackgroundColour(GetParent()->GetBackgroundColour()); Fit(); event.Skip(); } --- NEW FILE: MMultiButton.h --- /* * This file is part of wxInterface. * Copyright (C) 2003 Alo Sarv <ma...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __MMULTIBUTTON_H__ #define __MMULTIBUTTON_H__ #ifdef __GNUG__ #pragma interface "MMultiButton.cpp" #endif #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "MBitmapButton.h" WX_DECLARE_LIST(wxBitmap, MBitmapList); /*************************************************************** MMultiButton */ /* MMultiButton is a control with multiple buttons. The buttons can either be */ /* normal buttons, or MBitmapButtons. */ /******************************************************************************/ class MMultiButton : public wxControl { public: MMultiButton( /* Constructs a multi-button with normal wxButtons. */ wxWindow *parent, wxWindowID id, size_t count, const wxArrayString &names, int ids[], const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxNO_BORDER|wxNO_FULL_REPAINT_ON_RESIZE ); MMultiButton( /* Constructs a multi-button with MBitmapButtons. */ wxWindow *parent, wxWindowID id, size_t count, const wxArrayString &names, int ids[], const MBitmapList &images, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxNO_BORDER| wxNO_FULL_REPAINT_ON_RESIZE ); private: DECLARE_EVENT_TABLE() void OnPaint(wxPaintEvent &event); /* Updates background colour */ }; #endif Index: Images.cpp =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/Images.cpp,v retrieving revision 1.40 retrieving revision 1.41 diff -u -d -r1.40 -r1.41 --- Images.cpp 22 Dec 2003 01:55:10 -0000 1.40 +++ Images.cpp 22 Dec 2003 05:04:15 -0000 1.41 @@ -229,6 +229,18 @@ wxT("rightarrow"), new wxBitmap(path+wxT("rightarrow.png"), wxBITMAP_TYPE_ANY) ); + images.Append( + wxT("options"), + new wxBitmap(path+wxT("options.png"), wxBITMAP_TYPE_ANY) + ); + images.Append( + wxT("help"), + new wxBitmap(path+wxT("help.png"), wxBITMAP_TYPE_ANY) + ); + images.Append( + wxT("quit"), + new wxBitmap(path+wxT("quit.png"), wxBITMAP_TYPE_ANY) + ); } /** Index: MainDlg.cpp =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/MainDlg.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- MainDlg.cpp 21 Dec 2003 04:25:18 -0000 1.31 +++ MainDlg.cpp 22 Dec 2003 05:04:15 -0000 1.32 @@ -138,6 +138,8 @@ BEGIN_EVENT_TABLE(CMainDlg, wxFrame) EVT_CLOSE(CMainDlg::OnCloseWindow) /* Shutdown event */ EVT_TOOL(-1, CMainDlg::MenuOrToolEvent) /* Menu/Toolbar events */ + EVT_BUTTON(ID_BTN_GUISETTINGS, CMainDlg::ShowGUISettingsDlg) + EVT_BUTTON(ID_QUIT, CMainDlg::OnCloseWindow) END_EVENT_TABLE() #include <wx/listimpl.cpp> @@ -317,6 +319,11 @@ int tool_align; /* For storing values read from configuration */ bool show_tool; /* For storing values read from configuration */ unsigned int i; /* Loop counter */ +wxArrayString names; /* Names for multibutton controls */ +MBitmapList images; /* Images for multibutton controls */ +int ids[2]; /* Identifiers for multibutton controls */ + + images.DeleteContents(true); MyToolBar *toolbar = (MyToolBar*)GetToolBar(); delete toolbar; @@ -339,14 +346,12 @@ if (start_up) { wxArrayString names; - names.Add(_("Connect")); for (i=0;i<pages.GetCount();i++) { if (pages.IsEmpty()) { break; } names.Add(pages.Item(i)->GetData()->short_title); } - names.Add(_("Preferences")); img->CalcToolBitmapSize(names); } @@ -355,16 +360,16 @@ ); tb->SetMargins(2, 2); - if (gen_images) { - img->MakeToolImage(_("Connect"), wxT("btn_connect")); - } + names.Add(_("Connect")); + names.Add(_("Log")); + ids[1] = ID_BTN_CONNECT; + ids[1] = ID_BTN_LOG; + images.Append(new wxBitmap(img->GetImage(wxT("connection")))); + images.Append(new wxBitmap(img->GetImage(wxT("log")))); + tb->AddControl(new MMultiButton(tb, -1, 2, names, ids, images)); + images.Clear(); + names.Empty(); - tb->AddTool( - ID_BTN_CONNECT, _("Connect"), - img->GetImage(wxT("btn_connect")), - wxNullBitmap, wxITEM_NORMAL, _("Connect to any server") - ); - tb->AddSeparator(); for (i=0;i<pages.GetCount();i++) { if (pages.IsEmpty()){ break; @@ -385,15 +390,16 @@ pages.Item(i)->GetData()->content ); } - tb->AddSeparator(); - if (gen_images) { - img->MakeToolImage(_("Preferences"), wxT("btn_guisettings")); - } - tb->AddTool( - ID_BTN_GUISETTINGS, _("Preferences"), - img->GetImage(wxT("btn_guisettings")), - wxNullBitmap, wxITEM_NORMAL, _("Modify settings") - ); + + names.Add(_("Options")); + names.Add(_("Help")); + ids[0] = ID_BTN_GUISETTINGS; + ids[1] = ID_BTN_HELP; + images.Append(new wxBitmap(img->GetImage(wxT("options")))); + images.Append(new wxBitmap(img->GetImage(wxT("help")))); + tb->AddControl(new MMultiButton(tb, -1, 2, names, ids, images)); + images.Clear(); + names.Empty(); tb->Realize(); SetToolBar(tb); Index: MainDlg.h =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/MainDlg.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- MainDlg.h 20 Dec 2003 08:51:55 -0000 1.14 +++ MainDlg.h 22 Dec 2003 05:04:15 -0000 1.15 @@ -42,6 +42,7 @@ #include "SysTray.h" #include "Images.h" #include "GUISettingsDlg.h" +#include "MMultiButton.h" /* Constants for MainDlg */ #define ID_QUIT 100 Index: Makefile.am =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Makefile.am 20 Dec 2003 08:54:09 -0000 1.7 +++ Makefile.am 22 Dec 2003 05:04:15 -0000 1.8 @@ -7,7 +7,9 @@ KnownListCtrl.o \ MainDlg.o \ MessagesWnd.o \ + MBitmapButton.o \ MListCtrl.o \ + MMultiButton.o \ QueueListCtrl.o \ SBPanel.o \ SearchListCtrl.o \ @@ -67,10 +69,10 @@ false; \ fi; -.rc.res: - @echo -e -n "$(ACTIONCOLOR)Compiling $(INPUTCOLOR)$<$(ACTIONCOLOR) to " - @echo -e -n "$(OUTPUTCOLOR)$@$(ACTIONCOLOR): $(ATTENTIONCOLOR)" - @if windres -i $< -I rc -o $@ -O coff --include-dir=/local/include 2>.err; then \ +@RES@: + @echo -e -n "$(ACTIONCOLOR)Compiling $(INPUTCOLOR)$<$(ACTIONCOLOR) to "; + @echo -e -n "$(OUTPUTCOLOR)$@$(ACTIONCOLOR): $(ATTENTIONCOLOR)"; + @if windres -i wxInterface_private.rc -I rc -o $@ -O coff --include-dir=/local/include 2>.err; then \ if test -s .err; then \ echo -e "$(WARNINGCOLOR)ok, but warnings:"; \ cat .err; \ Index: defines.h =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/defines.h,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -r1.43 -r1.44 --- defines.h 19 Dec 2003 03:01:14 -0000 1.43 +++ defines.h 22 Dec 2003 05:04:15 -0000 1.44 @@ -79,7 +79,8 @@ ID_BTN_CONNECT, /* Toolbar buttons */ ID_BTN_STATISTICS, ID_BTN_GUISETTINGS, - ID_BTN_CORESETTINGS, + ID_BTN_HELP, + ID_BTN_LOG, ID_TOOLBAR, /* Toolbar itself */ ID_DETACH, /* Deatch_Current_page menubar object */ ID_FULLSCREEN, /* Fullscreen switch (in menu) */ |