]> git.saurik.com Git - wxWidgets.git/commitdiff
Added simplistic wxToolBar to wxUniversal. It
authorRobert Roebling <robert@roebling.de>
Sun, 24 Feb 2002 19:49:36 +0000 (19:49 +0000)
committerRobert Roebling <robert@roebling.de>
Sun, 24 Feb 2002 19:49:36 +0000 (19:49 +0000)
   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
include/wx/toolbar.h
include/wx/univ/toolbar.h [new file with mode: 0644]
src/generic/tbarsmpl.cpp
src/mgl/makefile.wat
src/univ/files.lst
src/univ/toolbar.cpp [new file with mode: 0644]
src/wxUniv.dsp
src/x11/files.lst

index 2c294e8d739b51287dc9495f57b64cc04dfb81c9..cc00e84a984039aacf0d94e57d10a78ca3b53967 100644 (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:
index ab920c591a6e16b367cbf6ff2ba2d13fc3e5620c..6b49e4b4dfb17c4f88a75e1a13588078391a292d 100644 (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"
diff --git a/include/wx/univ/toolbar.h b/include/wx/univ/toolbar.h
new file mode 100644 (file)
index 0000000..ac130e9
--- /dev/null
@@ -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_
index dd79b926b4ec3d110576f7151b4b9830f165c624..31608af0bdbf9669ad3f636b817afbcd08b954a6 100644 (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)
index 05ce7a849412c399e86e23e2a8ba4bed705253c4..66ce15ec981acda0bb0d9d4c14ecddb5b1dcc5e5 100644 (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) $<
 
index 4cb6f59e7fea7dad273b771ac7e56d0f6359d1b2..2d1bb7b545fc5533a28fc5d80927420bf770aee9 100644 (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
diff --git a/src/univ/toolbar.cpp b/src/univ/toolbar.cpp
new file mode 100644 (file)
index 0000000..d6735a1
--- /dev/null
@@ -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;
+    }
+}
+
index 635fb3f7793ee358c877a64d5e3a689e729b5849..9e8982d81525aeab4cf6e8c5c9ee0d05d305c263 100644 (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
index 96c5323cf200677dc00ba345c68b0a94ca185fc6..691edda06e686e2a6926fe6bd560d51a2d109edb 100644 (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 \