1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/toolbar.cpp
3 // Author: Robert Roebling
5 // Copyright: (c) 2001 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // ============================================================================
11 // ============================================================================
13 // ----------------------------------------------------------------------------
15 // ----------------------------------------------------------------------------
18 #pragma implementation "univtoolbar.h"
21 // For compilers that support precompilation, includes "wx.h".
22 #include "wx/wxprec.h"
33 #include "wx/toolbar.h"
34 #include "wx/validate.h"
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 BEGIN_EVENT_TABLE(wxToolBar
,wxToolBarBase
)
41 EVT_MOUSE_EVENTS( wxToolBar::OnMouse
)
42 EVT_PAINT( wxToolBar::OnPaint
)
43 EVT_SIZE( wxToolBar::OnSize
)
46 bool wxToolBar::Create( wxWindow
*parent
, wxWindowID id
,
47 const wxPoint
& pos
, const wxSize
& size
,
48 long style
, const wxString
& name
)
50 bool ret
= wxToolBarBase::Create( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
55 void wxToolBar::Init()
59 SetToolBitmapSize( wxSize(16,15) );
62 wxToolBarToolBase
*wxToolBar::FindToolForPosition(wxCoord x
, wxCoord y
) const
67 void wxToolBar::SetToolShortHelp(int id
, const wxString
& helpString
)
71 bool wxToolBar::DoInsertTool(size_t pos
, wxToolBarToolBase
*tool
)
76 bool wxToolBar::DoDeleteTool(size_t pos
, wxToolBarToolBase
*tool
)
81 void wxToolBar::DoEnableTool(wxToolBarToolBase
*tool
, bool enable
)
85 void wxToolBar::DoToggleTool(wxToolBarToolBase
*tool
, bool toggle
)
87 wxToolBarTool
*my_tool
= (wxToolBarTool
*) tool
;
89 bool refresh
= (my_tool
->IsToggled() != toggle
);
91 my_tool
->m_isDown
= toggle
;
94 RefreshTool( my_tool
);
97 void wxToolBar::DoSetToggle(wxToolBarToolBase
*tool
, bool toggle
)
101 wxToolBarToolBase
*wxToolBar::CreateTool(int id
,
102 const wxBitmap
& bitmap1
,
103 const wxBitmap
& bitmap2
,
105 wxObject
*clientData
,
106 const wxString
& shortHelpString
,
107 const wxString
& longHelpString
)
109 return new wxToolBarTool( this, id
, bitmap1
, bitmap2
, toggle
,
110 clientData
, shortHelpString
, longHelpString
);
113 wxToolBarToolBase
*wxToolBar::CreateTool(wxControl
*control
)
115 wxFAIL_MSG( wxT("Toolbar doesn't support controls yet.") );
120 void wxToolBar::RefreshTool( wxToolBarTool
*tool
)
122 wxRect
rect( tool
->m_x
, tool
->m_y
, m_defaultWidth
+6, m_defaultHeight
+6 );
123 Refresh( TRUE
, &rect
);
126 void wxToolBar::DrawToolBarTool( wxToolBarTool
*tool
, wxDC
&dc
, bool down
)
130 dc
.DrawBitmap( tool
->GetBitmap1(), tool
->m_x
+4, tool
->m_y
+4, TRUE
);
132 dc
.SetPen( *wxGREY_PEN
);
133 dc
.DrawLine( tool
->m_x
, tool
->m_y
, tool
->m_x
+m_defaultWidth
+5, tool
->m_y
);
134 dc
.DrawLine( tool
->m_x
, tool
->m_y
, tool
->m_x
, tool
->m_y
+m_defaultHeight
+5 );
136 dc
.SetPen( *wxBLACK_PEN
);
137 dc
.DrawLine( tool
->m_x
+1, tool
->m_y
+1, tool
->m_x
+m_defaultWidth
+4, tool
->m_y
+1 );
138 dc
.DrawLine( tool
->m_x
+1, tool
->m_y
+1, tool
->m_x
+1, tool
->m_y
+m_defaultHeight
+4 );
140 dc
.SetPen( *wxWHITE_PEN
);
141 dc
.DrawLine( tool
->m_x
, tool
->m_y
+m_defaultHeight
+5, tool
->m_x
+m_defaultWidth
+6, tool
->m_y
+m_defaultHeight
+5 );
142 dc
.DrawLine( tool
->m_x
+m_defaultWidth
+5, tool
->m_y
, tool
->m_x
+m_defaultWidth
+5, tool
->m_y
+m_defaultHeight
+6 );
146 dc
.DrawBitmap( tool
->GetBitmap1(), tool
->m_x
+3, tool
->m_y
+3, TRUE
);
148 dc
.SetPen( *wxWHITE_PEN
);
149 dc
.DrawLine( tool
->m_x
, tool
->m_y
, tool
->m_x
+m_defaultWidth
+5, tool
->m_y
);
150 dc
.DrawLine( tool
->m_x
, tool
->m_y
, tool
->m_x
, tool
->m_y
+m_defaultHeight
+5 );
151 dc
.DrawLine( tool
->m_x
+m_defaultWidth
+4, tool
->m_y
, tool
->m_x
+m_defaultWidth
+4, tool
->m_y
+2 );
152 dc
.DrawLine( tool
->m_x
, tool
->m_y
+m_defaultHeight
+4, tool
->m_x
+2, tool
->m_y
+m_defaultHeight
+4 );
154 dc
.SetPen( *wxBLACK_PEN
);
155 dc
.DrawLine( tool
->m_x
, tool
->m_y
+m_defaultHeight
+5, tool
->m_x
+m_defaultWidth
+6, tool
->m_y
+m_defaultHeight
+5 );
156 dc
.DrawLine( tool
->m_x
+m_defaultWidth
+5, tool
->m_y
, tool
->m_x
+m_defaultWidth
+5, tool
->m_y
+m_defaultHeight
+6 );
158 dc
.SetPen( *wxGREY_PEN
);
159 dc
.DrawLine( tool
->m_x
+1, tool
->m_y
+m_defaultHeight
+4, tool
->m_x
+m_defaultWidth
+5, tool
->m_y
+m_defaultHeight
+4 );
160 dc
.DrawLine( tool
->m_x
+m_defaultWidth
+4, tool
->m_y
+1, tool
->m_x
+m_defaultWidth
+4, tool
->m_y
+m_defaultHeight
+5 );
164 void wxToolBar::OnPaint(wxPaintEvent
&event
)
168 wxSize clientSize
= GetClientSize();
169 dc
.SetPen( *wxBLACK_PEN
);
170 dc
.DrawLine( 0,0, clientSize
.x
,0 );
172 for ( wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
174 node
= node
->GetNext() )
176 wxToolBarTool
*tool
= (wxToolBarTool
*) node
->Data();
178 if (tool
->GetId() == -1) continue;
180 DrawToolBarTool( tool
, dc
, tool
->m_isDown
);
184 bool wxToolBar::Realize()
186 if (!wxToolBarBase::Realize())
191 for ( wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
193 node
= node
->GetNext() )
195 wxToolBarTool
*tool
= (wxToolBarTool
*) node
->Data();
197 if (tool
->GetId() == -1)
205 x
+= m_defaultWidth
+ 6;
208 SetSize( x
+16, m_defaultHeight
+ 14 );
213 void wxToolBar::OnMouse(wxMouseEvent
&event
)
215 wxToolBarTool
*hit
= NULL
;
216 int x
= event
.GetX();
217 int y
= event
.GetY();
219 for ( wxToolBarToolsList::Node
*node
= m_tools
.GetFirst();
221 node
= node
->GetNext() )
223 wxToolBarTool
*tool
= (wxToolBarTool
*) node
->Data();
225 if ((x
> tool
->m_x
) && (x
< tool
->m_x
+m_defaultWidth
+5) &&
226 (y
> tool
->m_y
) && (y
< tool
->m_y
+m_defaultHeight
+5))
233 if (event
.LeftDown() && (hit
))
238 m_captured
->m_isDown
= TRUE
;
239 RefreshTool( m_captured
);
244 if (event
.Dragging() && (m_captured
))
246 bool is_down
= (hit
== m_captured
);
247 if (is_down
!= m_captured
->m_isDown
)
249 m_captured
->m_isDown
= is_down
;
250 RefreshTool( m_captured
);
256 if (event
.LeftUp() && (m_captured
))
260 m_captured
->m_isDown
= FALSE
;
261 RefreshTool( m_captured
);
263 if (hit
== m_captured
)
265 wxCommandEvent
cevent( wxEVT_COMMAND_TOOL_CLICKED
, m_captured
->GetId() );
266 cevent
.SetEventObject( this );
267 // cevent.SetExtraLong((long) toggleDown);
268 GetEventHandler()->ProcessEvent( cevent
);