1
//--------------------------------------------------------------------------------------
2
// LenMus Phonascus: The teacher of music
3
// Copyright (c) 2002-2010 LenMus project
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU General Public License as published by the Free Software Foundation,
7
// either version 3 of the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License along with this
14
// program. If not, see <http://www.gnu.org/licenses/>.
17
// For any comment, suggestion or feature request, please contact the manager of
18
// the project at cecilios@users.sourceforge.net
20
//-------------------------------------------------------------------------------------
22
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
23
#pragma implementation "ToolGroup.h"
26
// For compilers that support precompilation, includes <wx/wx.h>.
27
#include <wx/wxprec.h>
37
#include "ToolGroup.h"
39
#include "ColorScheme.h"
40
#include "ToolBoxEvents.h"
41
#include "../ArtProvider.h" // to use ArtProvider for managing icons
42
#include "../../widgets/Button.h"
43
#include "../TheApp.h" //to use GetMainFrame()
44
#include "../MainFrame.h" //to use lmMainFrame
47
#define lmTOOLGROUP_SIZE wxSize(160, 90)
48
#define lmTOOLGROUP_STYLE wxCAPTION | wxRESIZE_BORDER
52
//-----------------------------------------------------------------------------------
53
// lmToolGroup implementation
54
//-----------------------------------------------------------------------------------
56
BEGIN_EVENT_TABLE(lmToolGroup, wxPanel)
57
//EVT_MOTION(lmToolGroup::OnMouseMoved)
58
EVT_LEFT_DOWN(lmToolGroup::OnMouseDown)
59
EVT_LEFT_UP(lmToolGroup::OnMouseReleased)
60
//EVT_RIGHT_DOWN(lmToolGroup::OnRightClick)
61
EVT_LEAVE_WINDOW(lmToolGroup::OnMouseLeftWindow)
62
//EVT_KEY_DOWN(lmToolGroup::OnKeyPressed)
63
//EVT_KEY_UP(lmToolGroup::OnKeyReleased)
64
//EVT_MOUSEWHEEL(lmToolGroup::OnMouseWheelMoved)
65
EVT_PAINT(lmToolGroup::OnPaintEvent)
68
lmToolGroup::lmToolGroup(wxPanel* pParent, lmEGroupType nGroupType,
69
lmColorScheme* pColours, int nValidMouseModes)
70
: wxPanel(pParent, wxID_ANY, wxDefaultPosition, lmTOOLGROUP_SIZE)
72
, m_nGroupType(nGroupType)
73
, m_pColours(pColours)
74
, m_nValidMouseModes(nValidMouseModes)
75
, m_fMousePressedDown(false)
77
, m_fAlwaysDisabled(false)
79
//set font to draw group labels
80
SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD, false, wxT("Tahoma")));
82
//Any ToolGroup can be used as a control in properties dialogs. In them,
83
//the owner is not a lmToolPage and pointer pColors is NULL
84
m_fGuiControl = (m_pParent->IsKindOf(CLASSINFO(lmToolPage)) ? false : true);
88
SetForegroundColour(pColours->PrettyDark());
89
SetBackgroundColour(pColours->Normal()); //Bright());
93
//the group must be used as GUI control
94
wxASSERT(m_fGuiControl);
98
lmToolGroup::~lmToolGroup()
102
wxBoxSizer* lmToolGroup::CreateGroupSizer(wxBoxSizer* pMainSizer)
104
//create common controls for a lmToolGroup and returns the sizer in which
105
//derived class must add its controls
107
m_pCtrolsSizer = new wxBoxSizer( wxVERTICAL );
109
//spacer for group title
110
if (m_sTitle != _T(""))
111
m_pCtrolsSizer->Add( 0, 0, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 10 );
113
m_pGroupSizer = new wxBoxSizer( wxVERTICAL );
114
m_pCtrolsSizer->Add( m_pGroupSizer, 1, wxEXPAND|wxALL, 5 );
116
this->SetSizer( m_pCtrolsSizer );
118
m_pCtrolsSizer->Fit( this );
119
pMainSizer->Add( this, 0, wxLEFT|wxRIGHT|wxTOP|wxEXPAND, 2 );
121
return m_pGroupSizer;
124
void lmToolGroup::SetSelected(bool fSelected)
126
//set selected/deselected state for tool-selector groups
127
//If group was disabled it is first enabled.
129
wxASSERT(IsToolSelectorGroup());
131
//check if anything to do
132
if (m_fSelected == fSelected)
135
//change selected/deselected state
136
m_fSelected = fSelected;
138
//if group is disabled, enable it
139
if (!this->IsEnabled())
145
int lmToolGroup::GetGroupWitdh()
148
m_pParent->GetClientSize(&width, &height);
152
void lmToolGroup::EnableGroup(bool fEnable)
154
//enable/disable the group and repaints group to display new state
155
//if enable, for tool-selector groups the previous state (selected/deselected)
158
//force disabled if gris marked as 'always disabled'
159
fEnable &= !m_fAlwaysDisabled;
161
//check if anything to do
162
if (this->IsEnabled() == fEnable)
165
//for tool-selector groups save/restore state before disabling/enabling the group
166
if (IsToolSelectorGroup())
169
m_fSelected = m_fSaveSelected;
171
m_fSaveSelected = m_fSelected;
178
void lmToolGroup::PostToolBoxEvent(lmEToolID nToolID, bool fSelected)
180
//post tool box event to the active controller
181
wxWindow* pWnd = GetMainFrame()->GetActiveController();
184
lmToolBox* pToolBox = GetMainFrame()->GetActiveToolBox();
186
lmToolBoxToolSelectedEvent event(this->GetToolGroupID(), pToolBox->GetCurrentPageID(), nToolID,
188
::wxPostEvent( pWnd, event );
192
void lmToolGroup::OnPaintEvent(wxPaintEvent & evt)
194
//called by the system when the panel needs to be redrawn. You can also trigger
195
//this call by calling Refresh()/Update().
201
void lmToolGroup::DoRender(wxDC& dc)
203
//Here we do the actual rendering. It is a separate method so that it can work
204
//no matter what type of DC is used (i.e. wxPaintDC or wxClientDC)
207
//AWARE: ToolGroup is used as a control in properties dialogs. In them,
208
// the owner is not a lmToolPage and pointer pColors is NULL
210
wxColour colorMaxHight = wxSystemSettings::GetColour( wxSYS_COLOUR_3DHIGHLIGHT); //button highlight
211
wxColour colorHiLight = wxSystemSettings::GetColour( wxSYS_COLOUR_3DHILIGHT);
212
wxColour colorMoreLight = wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT );
213
wxColour colorLight = wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE); //button face
214
wxColour colorLessLight = wxSystemSettings::GetColour( wxSYS_COLOUR_3DSHADOW); //button shadow
215
wxColour colorDark = wxSystemSettings::GetColour( wxSYS_COLOUR_3DDKSHADOW );
218
wxColour colorBg = colorLight;
222
// colorBg = m_pColours->GetColour(lmCOLOUR_GROUP_BACKGROUND_SELECTED);
224
colorBg = m_pColours->GetColour(lmCOLOUR_GROUP_BACKGROUND_NORMAL);
228
wxColour colorBorder = colorLessLight;
230
colorBorder = m_pColours->GetColour(lmCOLOUR_GROUP_BORDER_ACTIVE);
233
wxColour colorTitle = colorLessLight;
237
colorTitle = m_pColours->GetColour(lmCOLOUR_GROUP_TITLE_ACTIVE);
239
colorTitle = m_pColours->GetColour(lmCOLOUR_GROUP_TITLE_INACTIVE);
247
GetClientSize(&rect.width, &rect.height);
249
wxRect rectBg = rect;
250
rectBg.Deflate(1, 1);
252
dc.SetPen( wxPen(colorBg));
253
dc.SetBrush( wxBrush(colorBg));
254
dc.DrawRectangle(rectBg);
256
if (m_sTitle != _T(""))
258
rectBg.SetHeight(13);
261
// wxColour cTop = wxColour(215,224,224); //lmColorScheme::LightenColour(colorBg, 0.9f);
262
// wxColour cBottom = wxColour(182,202,202); //lmColorScheme::DarkenColour(cTop, 0.2f);
263
// dc.GradientFillLinear(rectBg, cTop, cBottom, wxSOUTH );
267
wxColour cTop = lmColorScheme::LightenColour(colorBg, 0.6f);
268
wxColour cBottom = colorBg; //lmColorScheme::DarkenColour(colorBg, 0.15f);
269
dc.GradientFillLinear(rectBg, cTop, cBottom, wxSOUTH );
273
dc.GradientFillLinear(rectBg, colorMoreLight, colorLight, wxSOUTH );
277
dc.SetPen(colorBorder);
279
dc.DrawLine(rect.GetLeft(), rect.GetTop()+2,
280
rect.GetLeft(), rect.GetBottom()-2);
282
dc.DrawLine(rect.GetLeft()+2, rect.GetTop(),
283
rect.GetRight()-2, rect.GetTop());
285
dc.DrawLine(rect.GetRight()-1, rect.GetTop()+2,
286
rect.GetRight()-1, rect.GetBottom()-2);
289
dc.DrawLine(rect.GetLeft()+2, rect.GetBottom()-1,
290
rect.GetRight()-2, rect.GetBottom()-1);
293
dc.DrawPoint(rect.GetLeft()+1, rect.GetTop()+1);
294
dc.DrawPoint(rect.GetLeft()+1, rect.GetTop()+2);
295
dc.DrawPoint(rect.GetLeft()+2, rect.GetTop()+1);
298
dc.DrawPoint(rect.GetRight()-2, rect.GetTop()+1);
299
dc.DrawPoint(rect.GetRight()-2, rect.GetTop()+2);
300
dc.DrawPoint(rect.GetRight()-3, rect.GetTop()+1);
302
//bottom right corner
303
dc.DrawPoint(rect.GetRight()-2, rect.GetBottom()-2);
304
dc.DrawPoint(rect.GetRight()-2, rect.GetBottom()-3);
305
dc.DrawPoint(rect.GetRight()-3, rect.GetBottom()-2);
308
dc.DrawPoint(rect.GetLeft()+1, rect.GetBottom()-2);
309
dc.DrawPoint(rect.GetLeft()+1, rect.GetBottom()-3);
310
dc.DrawPoint(rect.GetLeft()+2, rect.GetBottom()-2);
313
dc.SetPen( lmColorScheme::LightenColour(colorBg, 0.9f) );
315
dc.DrawLine(rect.GetLeft()+1, rect.GetTop()+3,
316
rect.GetLeft()+1, rect.GetBottom()-3);
318
dc.DrawLine(rect.GetLeft()+3, rect.GetTop()+1,
319
rect.GetRight()-3, rect.GetTop()+1);
321
dc.DrawLine(rect.GetRight(), rect.GetTop()+2,
322
rect.GetRight(), rect.GetBottom()-2);
325
dc.DrawLine(rect.GetLeft()+3, rect.GetBottom(),
326
rect.GetRight()-2, rect.GetBottom());
331
if (m_sTitle != _T(""))
333
dc.SetFont( wxFont( 8, 74, 90, 90, false, wxT("Tahoma") ) );
334
if (!this->IsEnabled())
336
dc.SetTextForeground(*wxWHITE);
337
dc.DrawText( m_sTitle, 5, 2 );
339
dc.SetTextForeground(colorTitle);
340
dc.DrawText( m_sTitle, 4, 1 );
344
void lmToolGroup::DoPaintNow()
346
//you can use a clientDC to paint on the panel
347
//at any time. Using this generally does not free you from
348
//catching paint events, since it is possible that e.g. the window
349
//manager throws away your drawing when the window comes to the
350
//background, and expects you will redraw it when the window comes
351
//back (by sending a paint event).
353
// depending on your system you may need to look at double-buffered dcs
358
void lmToolGroup::OnMouseDown(wxMouseEvent& event)
360
//m_fMousePressedDown = true;
364
void lmToolGroup::OnMouseReleased(wxMouseEvent& event)
366
//m_fMousePressedDown = false;
369
////wxMessageBox( _T("Click on group") );
370
//select tool group by clicking on it
371
if (!m_fGuiControl && IsToolSelectorGroup() && this->IsEnabled())
372
((lmToolPage*)m_pParent)->SelectGroup(this);
375
void lmToolGroup::OnMouseLeftWindow(wxMouseEvent& event)
377
//if (m_fMousePressedDown)
379
// m_fMousePressedDown = false;
384
void lmToolGroup::EnableForMouseMode(int nMode)
386
//Enable/disable this group, depending on its usability for specified mouse mode
388
EnableGroup((m_nValidMouseModes & nMode) != 0);
393
//-----------------------------------------------------------------------------------
394
// lmToolButtonsGroup implementation
395
// A group of buttons, only one of them selected. If fAllowNone=true then the group
396
// can have no button selected
397
//-----------------------------------------------------------------------------------
399
lmToolButtonsGroup::lmToolButtonsGroup(wxPanel* pParent, lmEGroupType nGroupType,
400
int nNumButtons, bool fAllowNone,
401
wxBoxSizer* pMainSizer, int nFirstButtonEventID,
402
lmEToolID nFirstButtonToolID,
403
lmColorScheme* pColours,
404
int nValidMouseModes)
405
: lmToolGroup(pParent, nGroupType, pColours, nValidMouseModes)
406
, m_nSelButton(-1) //none selected
407
, m_nSelButtonSave(-1)
408
, m_nFirstButtonEventID(nFirstButtonEventID)
409
, m_nFirstButtonToolID((int)nFirstButtonToolID)
410
, m_fAllowNone(fAllowNone)
411
, m_nNumButtons(nNumButtons)
413
m_pButton.resize(nNumButtons);
414
ConnectButtonEvents();
417
lmToolButtonsGroup::~lmToolButtonsGroup()
421
void lmToolButtonsGroup::ConnectButtonEvents()
423
//connect OnButton events
424
Connect( m_nFirstButtonEventID, m_nFirstButtonEventID + m_nNumButtons - 1,
425
wxEVT_COMMAND_BUTTON_CLICKED,
426
(wxObjectEventFunction)& lmToolButtonsGroup::OnButton );
429
void lmToolButtonsGroup::SelectButton(int iB)
431
// Set selected button as 'pressed' and all others as 'released'
434
if (m_nSelButtonSave == -1)
435
m_nSelButtonSave = iB;
436
for(int i=0; i < m_nNumButtons; i++)
439
m_pButton[i]->Release();
442
m_pButton[i]->Press();
446
//return focus to active view
447
GetMainFrame()->SetFocusOnActiveView();
450
void lmToolButtonsGroup::SetSelected(bool fSelected)
452
//check if something to do
453
if (fSelected == m_fSelected)
457
m_fSelected = fSelected;
459
//if not allowed 'no button selected' hide/restore selected button
460
if (fSelected && !m_fAllowNone && m_nSelButtonSave != -1)
461
SelectButton(m_nSelButtonSave);
462
else if (!fSelected && !m_fAllowNone && m_nSelButton != -1)
464
m_pButton[m_nSelButton]->Release();
465
m_nSelButtonSave = m_nSelButton;
469
void lmToolButtonsGroup::SelectNextButton()
471
if (++m_nSelButton == m_nNumButtons)
472
m_nSelButton = (m_fAllowNone ? -1 : 0);
474
SelectButton(m_nSelButton);
477
void lmToolButtonsGroup::SelectPrevButton()
481
if (m_nSelButton == -1)
482
m_nSelButton = m_nNumButtons;
486
if (m_nSelButton == 0)
487
m_nSelButton = m_nNumButtons;
491
SelectButton(m_nSelButton);
494
void lmToolButtonsGroup::OnButton(wxCommandEvent& event)
496
int iB = event.GetId() - GetFirstButtonEventID();
497
if (IsNoneAllowed() && GetSelectedButton() == iB)
498
SelectButton(-1); //no button selected
502
m_nSelButtonSave = iB;
506
OnButtonSelected( m_nSelButton );
509
void lmToolButtonsGroup::OnButtonSelected(int nSelButton)
511
//Notify owner page about the tool change, unless it is the MouseGroup, In this
512
//case post a tool change event directly to the active controller
514
//AWARE: ToolGroup can be used as a control in properties dialogs. In them,
515
// the owner is not a lmToolPage but a wxPanel. Events will not be posted
518
if ( m_pParent->IsKindOf(CLASSINFO(lmToolPage)) )
520
//notify owner page about the tool change
521
((lmToolPage*)m_pParent)->OnToolChanged(this->GetToolGroupID(),
522
(lmEToolID)(nSelButton+m_nFirstButtonToolID));
524
else if (this->GetToolGroupID() == lmGRP_MouseMode)
526
//post tool box event to the active controller
527
wxWindow* pWnd = GetMainFrame()->GetActiveController();
530
lmToolBox* pToolBox = GetMainFrame()->GetActiveToolBox();
532
lmToolBoxToolSelectedEvent event(this->GetToolGroupID(), pToolBox->GetCurrentPageID(),
534
::wxPostEvent( pWnd, event );
539
//this ToolGroup is used as a control in properties dialogs. Default
540
//behaviour is to do nothing