From c08a4f0068a616f3726fd0403b3b75caac3fa702 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 24 Feb 2002 19:49:36 +0000 Subject: [PATCH] Added simplistic wxToolBar to wxUniversal. It still corrupts the non-client area. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14394 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- distrib/msw/tmake/filelist.txt | 2 + include/wx/toolbar.h | 6 +- include/wx/univ/toolbar.h | 118 ++++++++++++++ src/generic/tbarsmpl.cpp | 2 +- src/mgl/makefile.wat | 4 + src/univ/files.lst | 3 + src/univ/toolbar.cpp | 270 +++++++++++++++++++++++++++++++++ src/wxUniv.dsp | 4 + src/x11/files.lst | 1 + 9 files changed, 407 insertions(+), 3 deletions(-) create mode 100644 include/wx/univ/toolbar.h create mode 100644 src/univ/toolbar.cpp diff --git a/distrib/msw/tmake/filelist.txt b/distrib/msw/tmake/filelist.txt index 2c294e8d73..cc00e84a98 100644 --- a/distrib/msw/tmake/filelist.txt +++ b/distrib/msw/tmake/filelist.txt @@ -400,6 +400,7 @@ statline.cpp Univ stattext.cpp Univ statusbr.cpp Univ textctrl.cpp Univ +toolbar.cpp Univ theme.cpp Univ gtk.cpp Univ Theme winuniv.cpp Univ @@ -1515,6 +1516,7 @@ stattext.h UnivH statusbr.h UnivH textctrl.h UnivH theme.h UnivH +toolbar.h UnivH window.h UnivH # wxMGL: diff --git a/include/wx/toolbar.h b/include/wx/toolbar.h index ab920c591a..6b49e4b4df 100644 --- a/include/wx/toolbar.h +++ b/include/wx/toolbar.h @@ -15,7 +15,7 @@ #include "wx/tbarbase.h" // the base class for all toolbars #if wxUSE_TOOLBAR - #if !wxUSE_TOOLBAR_NATIVE || defined(__WXUNIVERSAL__) + #if !wxUSE_TOOLBAR_NATIVE #include "wx/tbarsmpl.h" class WXDLLEXPORT wxToolBar : public wxToolBarSimple @@ -79,7 +79,9 @@ DECLARE_DYNAMIC_CLASS(wxToolBar) }; #else // wxUSE_TOOLBAR_NATIVE - #if defined(__WXMSW__) && defined(__WIN95__) + #if defined(__WXUNIVERSAL__) + #include "wx/univ/toolbar.h" + #elif defined(__WXMSW__) && defined(__WIN95__) #include "wx/msw/tbar95.h" #elif defined(__WXMSW__) #include "wx/msw/tbarmsw.h" diff --git a/include/wx/univ/toolbar.h b/include/wx/univ/toolbar.h new file mode 100644 index 0000000000..ac130e9feb --- /dev/null +++ b/include/wx/univ/toolbar.h @@ -0,0 +1,118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/univ/toolbar.h +// Purpose: wxToolBar declaration +// Author: Robert Roebling +// Modified by: +// Created: 10.09.00 +// RCS-ID: $Id$ +// Copyright: (c) Robert Roebling +// Licence: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_UNIV_TOOLBAR_H_ +#define _WX_UNIV_TOOLBAR_H_ + +#ifdef __GNUG__ + #pragma interface "univtoolbar.h" +#endif + +#include "wx/window.h" + +// ---------------------------------------------------------------------------- +// wxToolbar +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxToolBarTool : public wxToolBarToolBase +{ +public: + wxToolBarTool( wxToolBarBase *tbar = (wxToolBarBase *)NULL, + int id = wxID_SEPARATOR, + const wxBitmap& bitmap1 = wxNullBitmap, + const wxBitmap& bitmap2 = wxNullBitmap, + bool toggle = FALSE, + wxObject *clientData = (wxObject *) NULL, + const wxString& shortHelpString = wxEmptyString, + const wxString& longHelpString = wxEmptyString ) : + wxToolBarToolBase( tbar, id, bitmap1, bitmap2, toggle, clientData, + shortHelpString, longHelpString ) + { + m_isDown = FALSE; + m_x = -1; + m_y = -1; + } + +public: + bool m_isDown; + int m_x; + int m_y; +}; + +class WXDLLEXPORT wxToolBar: public wxToolBarBase +{ +public: + // construction/destruction + wxToolBar() { Init(); } + wxToolBar( wxWindow *parent, + wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxToolBarNameStr ) + { + Init(); + + Create(parent, id, pos, size, style, name); + } + + bool Create( wxWindow *parent, + wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxToolBarNameStr ); + +#ifdef __DARWIN__ + virtual ~wxToolBar() { } +#endif + + virtual bool Realize(); + + virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const; + + virtual void SetToolShortHelp(int id, const wxString& helpString); + +protected: + // common part of all ctors + void Init(); + + // implement base class pure virtuals + virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool); + virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool); + + virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable); + virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle); + virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle); + + virtual wxToolBarToolBase *CreateTool(int id, + const wxBitmap& bitmap1, + const wxBitmap& bitmap2, + bool toggle, + wxObject *clientData, + const wxString& shortHelpString, + const wxString& longHelpString); + virtual wxToolBarToolBase *CreateTool(wxControl *control); + +private: + wxToolBarTool *m_captured; + +private: + void OnMouse( wxMouseEvent &event ); + void RefreshTool( wxToolBarTool *tool ); + void DrawToolBarTool( wxToolBarTool *tool, wxDC &dc, bool down ); + void OnPaint( wxPaintEvent &event ); + +private: + DECLARE_EVENT_TABLE() +}; + +#endif // _WX_UNIV_TOOLBAR_H_ diff --git a/src/generic/tbarsmpl.cpp b/src/generic/tbarsmpl.cpp index dd79b926b4..31608af0bd 100644 --- a/src/generic/tbarsmpl.cpp +++ b/src/generic/tbarsmpl.cpp @@ -85,7 +85,7 @@ public: IMPLEMENT_DYNAMIC_CLASS(wxToolBarSimple, wxToolBarBase) -#if !wxUSE_TOOLBAR_NATIVE || defined(__WXUNIVERSAL__) +#if !wxUSE_TOOLBAR_NATIVE #include "wx/toolbar.h" IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarSimple) diff --git a/src/mgl/makefile.wat b/src/mgl/makefile.wat index 05ce7a8494..66ce15ec98 100644 --- a/src/mgl/makefile.wat +++ b/src/mgl/makefile.wat @@ -272,6 +272,7 @@ UNIVOBJS = bmpbuttn.obj & statusbr.obj & textctrl.obj & theme.obj & + toolbar.obj & topluniv.obj & winuniv.obj @@ -501,6 +502,9 @@ textctrl.obj: $(UNIVDIR)\textctrl.cpp theme.obj: $(UNIVDIR)\theme.cpp *$(CCC) $(CPPFLAGS) $(IFLAGS) $< +toolbar.obj: $(UNIVDIR)\toolbar.cpp + *$(CCC) $(CPPFLAGS) $(IFLAGS) $< + topluniv.obj: $(UNIVDIR)\topluniv.cpp *$(CCC) $(CPPFLAGS) $(IFLAGS) $< diff --git a/src/univ/files.lst b/src/univ/files.lst index 4cb6f59e7f..2d1bb7b545 100644 --- a/src/univ/files.lst +++ b/src/univ/files.lst @@ -33,6 +33,7 @@ UNIV_SOURCES = \ univ/statusbr.cpp \ univ/textctrl.cpp \ univ/theme.cpp \ + univ/toolbar.cpp \ univ/topluniv.cpp \ univ/themes/win32.cpp \ univ/winuniv.cpp @@ -73,6 +74,7 @@ UNIV_HEADERS = \ univ/statusbr.h \ univ/textctrl.h \ univ/theme.h \ + univ/toolbar.h \ univ/toplevel.h \ univ/window.h @@ -109,6 +111,7 @@ UNIVOBJS = \ statusbr.o \ textctrl.o \ theme.o \ + toolbar.o \ topluniv.o \ win32.o \ winuniv.o diff --git a/src/univ/toolbar.cpp b/src/univ/toolbar.cpp new file mode 100644 index 0000000000..d6735a1abc --- /dev/null +++ b/src/univ/toolbar.cpp @@ -0,0 +1,270 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/univ/toolbar.cpp +// Author: Robert Roebling +// Id: $Id$ +// Copyright: (c) 2001 Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "univtoolbar.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/utils.h" + #include "wx/app.h" +#endif + +#include "wx/toolbar.h" +#include "wx/validate.h" + +//----------------------------------------------------------------------------- +// wxToolBar +//----------------------------------------------------------------------------- + +BEGIN_EVENT_TABLE(wxToolBar,wxToolBarBase) + EVT_MOUSE_EVENTS( wxToolBar::OnMouse ) + EVT_PAINT( wxToolBar::OnPaint ) + EVT_SIZE( wxToolBar::OnSize ) +END_EVENT_TABLE() + +bool wxToolBar::Create( wxWindow *parent, wxWindowID id, + const wxPoint& pos, const wxSize& size, + long style, const wxString& name ) +{ + bool ret = wxToolBarBase::Create( parent, id, pos, size, style, wxDefaultValidator, name ); + + return ret; +} + +void wxToolBar::Init() +{ + m_captured = NULL; + + SetToolBitmapSize( wxSize(16,15) ); +} + +wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const +{ + return NULL; +} + +void wxToolBar::SetToolShortHelp(int id, const wxString& helpString) +{ +} + +bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *tool) +{ + return TRUE; +} + +bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) +{ + return TRUE; +} + +void wxToolBar::DoEnableTool(wxToolBarToolBase *tool, bool enable) +{ +} + +void wxToolBar::DoToggleTool(wxToolBarToolBase *tool, bool toggle) +{ + wxToolBarTool *my_tool = (wxToolBarTool*) tool; + + bool refresh = (my_tool->IsToggled() != toggle); + + my_tool->m_isDown = toggle; + + if (refresh) + RefreshTool( my_tool ); +} + +void wxToolBar::DoSetToggle(wxToolBarToolBase *tool, bool toggle) +{ +} + +wxToolBarToolBase *wxToolBar::CreateTool(int id, + const wxBitmap& bitmap1, + const wxBitmap& bitmap2, + bool toggle, + wxObject *clientData, + const wxString& shortHelpString, + const wxString& longHelpString) +{ + return new wxToolBarTool( this, id, bitmap1, bitmap2, toggle, + clientData, shortHelpString, longHelpString); +} + +wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) +{ + wxFAIL_MSG( wxT("Toolbar doesn't support controls yet.") ); + + return NULL; +} + +void wxToolBar::RefreshTool( wxToolBarTool *tool ) +{ + wxRect rect( tool->m_x, tool->m_y, m_defaultWidth+6, m_defaultHeight+6 ); + Refresh( TRUE, &rect ); +} + +void wxToolBar::DrawToolBarTool( wxToolBarTool *tool, wxDC &dc, bool down ) +{ + if (down) + { + dc.DrawBitmap( tool->GetBitmap1(), tool->m_x+4, tool->m_y+4, TRUE ); + + dc.SetPen( *wxGREY_PEN ); + dc.DrawLine( tool->m_x, tool->m_y, tool->m_x+m_defaultWidth+5, tool->m_y ); + dc.DrawLine( tool->m_x, tool->m_y, tool->m_x, tool->m_y+m_defaultHeight+5 ); + + dc.SetPen( *wxBLACK_PEN ); + dc.DrawLine( tool->m_x+1, tool->m_y+1, tool->m_x+m_defaultWidth+4, tool->m_y+1 ); + dc.DrawLine( tool->m_x+1, tool->m_y+1, tool->m_x+1, tool->m_y+m_defaultHeight+4 ); + + dc.SetPen( *wxWHITE_PEN ); + dc.DrawLine( tool->m_x, tool->m_y+m_defaultHeight+5, tool->m_x+m_defaultWidth+6, tool->m_y+m_defaultHeight+5 ); + dc.DrawLine( tool->m_x+m_defaultWidth+5, tool->m_y, tool->m_x+m_defaultWidth+5, tool->m_y+m_defaultHeight+6 ); + } + else + { + dc.DrawBitmap( tool->GetBitmap1(), tool->m_x+3, tool->m_y+3, TRUE ); + + dc.SetPen( *wxWHITE_PEN ); + dc.DrawLine( tool->m_x, tool->m_y, tool->m_x+m_defaultWidth+5, tool->m_y ); + dc.DrawLine( tool->m_x, tool->m_y, tool->m_x, tool->m_y+m_defaultHeight+5 ); + dc.DrawLine( tool->m_x+m_defaultWidth+4, tool->m_y, tool->m_x+m_defaultWidth+4, tool->m_y+2 ); + dc.DrawLine( tool->m_x, tool->m_y+m_defaultHeight+4, tool->m_x+2, tool->m_y+m_defaultHeight+4 ); + + dc.SetPen( *wxBLACK_PEN ); + dc.DrawLine( tool->m_x, tool->m_y+m_defaultHeight+5, tool->m_x+m_defaultWidth+6, tool->m_y+m_defaultHeight+5 ); + dc.DrawLine( tool->m_x+m_defaultWidth+5, tool->m_y, tool->m_x+m_defaultWidth+5, tool->m_y+m_defaultHeight+6 ); + + dc.SetPen( *wxGREY_PEN ); + dc.DrawLine( tool->m_x+1, tool->m_y+m_defaultHeight+4, tool->m_x+m_defaultWidth+5, tool->m_y+m_defaultHeight+4 ); + dc.DrawLine( tool->m_x+m_defaultWidth+4, tool->m_y+1, tool->m_x+m_defaultWidth+4, tool->m_y+m_defaultHeight+5 ); + } +} + +void wxToolBar::OnPaint(wxPaintEvent &event) +{ + wxPaintDC dc(this); + + for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); + node; + node = node->GetNext() ) + { + wxToolBarTool *tool = (wxToolBarTool*) node->Data(); + + if (tool->GetId() == -1) continue; + + DrawToolBarTool( tool, dc, tool->m_isDown ); + } +} + +bool wxToolBar::Realize() +{ + if (!wxToolBarBase::Realize()) + return FALSE; + + int x = 5; + + for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); + node; + node = node->GetNext() ) + { + wxToolBarTool *tool = (wxToolBarTool*) node->Data(); + + if (tool->GetId() == -1) + { + x += 6; + continue; + } + + tool->m_x = x; + tool->m_y = 4; + x += m_defaultWidth + 6; + } + + return TRUE; +} + +void wxToolBar::OnMouse(wxMouseEvent &event) +{ + wxToolBarTool *hit = NULL; + int x = event.GetX(); + int y = event.GetY(); + + for ( wxToolBarToolsList::Node *node = m_tools.GetFirst(); + node; + node = node->GetNext() ) + { + wxToolBarTool *tool = (wxToolBarTool*) node->Data(); + + if ((x > tool->m_x) && (x < tool->m_x+m_defaultWidth+5) && + (y > tool->m_y) && (y < tool->m_y+m_defaultHeight+5)) + { + hit = tool; + break; + } + } + + if (event.LeftDown() && (hit)) + { + CaptureMouse(); + m_captured = hit; + + m_captured->m_isDown = TRUE; + RefreshTool( m_captured ); + + return; + } + + if (event.Dragging() && (m_captured)) + { + bool is_down = (hit == m_captured); + if (is_down != m_captured->m_isDown) + { + m_captured->m_isDown = is_down; + RefreshTool( m_captured ); + } + + return; + } + + if (event.LeftUp() && (m_captured)) + { + ReleaseMouse(); + + m_captured->m_isDown = FALSE; + RefreshTool( m_captured ); + + if (hit == m_captured) + { + wxCommandEvent cevent( wxEVT_COMMAND_TOOL_CLICKED, m_captured->GetId() ); + cevent.SetEventObject( this ); + // cevent.SetExtraLong((long) toggleDown); + GetEventHandler()->ProcessEvent( cevent ); + } + + m_captured = NULL; + + return; + } +} + diff --git a/src/wxUniv.dsp b/src/wxUniv.dsp index 635fb3f779..9e8982d815 100644 --- a/src/wxUniv.dsp +++ b/src/wxUniv.dsp @@ -1164,6 +1164,10 @@ SOURCE=.\univ\theme.cpp # End Source File # Begin Source File +SOURCE=.\univ\toolbar.cpp +# End Source File +# Begin Source File + SOURCE=.\univ\topluniv.cpp # End Source File # Begin Source File diff --git a/src/x11/files.lst b/src/x11/files.lst index 96c5323cf2..691edda06e 100644 --- a/src/x11/files.lst +++ b/src/x11/files.lst @@ -531,6 +531,7 @@ ALL_HEADERS = \ univ/statusbr.h \ univ/textctrl.h \ univ/theme.h \ + univ/toolbar.h \ univ/toplevel.h \ univ/window.h \ generic/accel.h \ -- 2.45.2