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
This commit is contained in:
Robert Roebling
2002-02-24 19:49:36 +00:00
parent ae45f98300
commit c08a4f0068
9 changed files with 407 additions and 3 deletions

View File

@@ -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:

View File

@@ -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"

118
include/wx/univ/toolbar.h Normal file
View File

@@ -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_

View File

@@ -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)

View File

@@ -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) $<

View File

@@ -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

270
src/univ/toolbar.cpp Normal file
View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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 \