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/>.
16
// For any comment, suggestion or feature request, please contact the manager of
17
// the project at cecilios@users.sourceforge.net
19
//-------------------------------------------------------------------------------------
21
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
22
#pragma implementation "ToolsBox.h"
25
// For compilers that support precompilation, includes <wx/wx.h>.
26
#include <wx/wxprec.h>
36
#include <wx/cursor.h>
37
#include <wx/statline.h>
39
#include "../MainFrame.h"
41
#include "ToolBoxEvents.h"
42
#include "../ArtProvider.h" // to use ArtProvider for managing icons
43
#include "../TheApp.h"
44
#include "../ScoreCanvas.h"
45
#include "../../widgets/Button.h"
48
//-----------------------------------------------------------------------------------
51
// Things to do to add a new tools panel to the Tools Box dialog:
52
// 1. Create a new panel class derived from lmToolPage
53
// 2. Look for "//TO_ADD:" tags in ToolsBox.h and follow instructions there
54
// 3. Look for "//TO_ADD:" tags in this file and follow instructions there
56
//-----------------------------------------------------------------------------------
59
#include "ToolNotes.h"
61
#include "ToolBarlines.h"
62
#include "ToolSymbols.h"
63
//TO_ADD: add here the new tool panel include file
66
//-------------------------------------------------------------------------------------------------
67
// lmToolBoxConfiguration: Helper class to define a ToolBox configuration
68
//-------------------------------------------------------------------------------------------------
72
//-------------------------------------------------------------------------------------------------
73
// lmToolBox implementation
74
//-------------------------------------------------------------------------------------------------
77
const int SPACING = 4; //spacing (pixels) around each sizer
78
const int BUTTON_SPACING = 4; //spacing (pixels) between buttons
79
const int BUTTON_SIZE = 32; //tools button size (pixels)
80
const int NUM_COLUMNS = 4; //number of buttons per row
81
// ToolBox width = NUM_COLUMNS * BUTTON_SIZE + 2*(NUM_COLUMNS-1)*BUTTON_SPACING + 2*SPACING
82
// = 4*32 + 2*3*4 + 2*4 = 128+24+8 = 160
84
//const int ID_BUTTON = 2200;
85
#define lm_NUM_MOUSE_MODE_BUTTONS 2
90
lmID_BT_MouseMode_Pointer = ID_BUTTON + 16, //+ NUM_BUTTONS,
91
lmID_BT_MouseMode_DataEntry,
95
BEGIN_EVENT_TABLE(lmToolBox, wxPanel)
96
EVT_CHAR (lmToolBox::OnKeyPress)
97
EVT_COMMAND_RANGE (ID_BUTTON, ID_BUTTON+NUM_BUTTONS-1, wxEVT_COMMAND_BUTTON_CLICKED, lmToolBox::OnButtonClicked)
98
EVT_SIZE (lmToolBox::OnResize)
99
//EVT_ERASE_BACKGROUND(lmToolBox::OnEraseBackground)
102
IMPLEMENT_CLASS(lmToolBox, wxPanel)
105
lmToolBox::lmToolBox(wxWindow* parent, wxWindowID id)
106
: wxPanel(parent, id, wxPoint(0,0), wxSize(170, -1), wxBORDER_NONE)
107
, m_nCurPageID(lmPAGE_NONE)
110
m_colors.SetBaseColor( wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE) );
112
//initialize pages's array with default standard pages
113
for (int i=0; i < (int)lmPAGE_MAX; i++)
115
lmToolPage* pPage = CreatePage((lmEToolPageID)i);
116
AddPage(pPage, (lmEToolPageID)i);
117
m_cActivePages[i] = (int)m_cPages.size() - 1;
122
SelectToolPage(lmPAGE_NOTES);
125
void lmToolBox::CreateControls()
127
//Controls creation for ToolsBox Dlg
129
//the main sizer, to contain the three areas
130
wxBoxSizer* pMainSizer = new wxBoxSizer(wxVERTICAL);
132
//panel for the mouse mode group
133
m_pMouseModeGroup = new lmGrpMouseMode(this, pMainSizer, &m_colors);
134
m_pMouseModeGroup->CreateGroupControls(pMainSizer);
136
//panel for the fixed group
137
m_pSpecialGroup = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxSize( -1,-1 ), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
138
pMainSizer->Add( m_pSpecialGroup, 0, wxEXPAND, 5 );
139
m_pSpecialGroup->Show(false);
142
wxStaticLine* pLine1 = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
143
pMainSizer->Add( pLine1, 0, wxEXPAND|wxTOP, 2);
145
//the tool page buttons selection area
146
wxPanel* pSelectPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
147
wxBORDER_NONE|wxTAB_TRAVERSAL );
148
pSelectPanel->SetBackgroundColour(m_colors.Bright());
150
wxBoxSizer* pSelectSizer = new wxBoxSizer( wxVERTICAL );
152
wxGridSizer* pButtonsSizer = new wxGridSizer(NUM_COLUMNS);
154
wxSize btSize(BUTTON_SIZE, BUTTON_SIZE);
156
int iMax = m_cPages.size();
157
std::vector<lmToolPage*>::iterator it;
158
for(it=m_cPages.begin(); it != m_cPages.end(); ++it, ++iB)
160
m_pButton[iB] = new lmCheckButton(pSelectPanel, ID_BUTTON + iB, wxBitmap(btSize.x, btSize.y));
161
m_pButton[iB]->SetBitmapUp((*it)->GetPageBitmapName(), _T(""), btSize);
162
m_pButton[iB]->SetBitmapDown((*it)->GetPageBitmapName(), _T("button_selected_flat"), btSize);
163
m_pButton[iB]->SetBitmapOver((*it)->GetPageBitmapName(), _T("button_over_flat"), btSize);
164
m_pButton[iB]->SetToolTip((*it)->GetPageToolTip());
166
if (iB > 0) sides |= wxLEFT;
167
if (iB < iMax-1) sides |= wxRIGHT;
168
pButtonsSizer->Add(m_pButton[iB],
169
wxSizerFlags(0).Border(sides, BUTTON_SPACING) );
172
pSelectSizer->Add( pButtonsSizer, 1, wxEXPAND|wxALL, SPACING );
174
pSelectPanel->SetSizer( pSelectSizer );
175
pSelectPanel->Layout();
176
pSelectSizer->Fit( pSelectPanel );
177
pMainSizer->Add( pSelectPanel, 0, 0, SPACING );
180
wxStaticLine* pLine2 = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
181
pMainSizer->Add( pLine2, 0, wxEXPAND, 0);
184
m_pPageSizer = new wxBoxSizer( wxVERTICAL );
186
int nWidth = NUM_COLUMNS * BUTTON_SIZE + 2*(NUM_COLUMNS-1)*BUTTON_SPACING + 2*SPACING;
187
m_pEmptyPage = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 800),
188
wxBORDER_NONE|wxTAB_TRAVERSAL );
189
m_pEmptyPage->SetBackgroundColour(m_colors.Bright());
190
m_pCurPage = m_pEmptyPage;
191
m_pPageSizer->Add( m_pCurPage, 1, wxEXPAND, SPACING );
193
pMainSizer->Add( m_pPageSizer, 1, wxEXPAND, SPACING );
195
SetSizer( pMainSizer );
196
pMainSizer->SetSizeHints(this);
201
lmToolBox::~lmToolBox()
205
void lmToolBox::GetConfiguration(lmToolBoxConfiguration* pConfig)
207
//Updates received config object with current configuration data
210
for (int i=0; i < (int)lmPAGE_MAX; i++)
211
pConfig->m_Pages[i] = m_cActivePages[i];
214
pConfig->m_pSpecialGroup = m_pSpecialGroup;
215
pConfig->m_fSpecialGroupVisible = m_pSpecialGroup->IsShown();
216
pConfig->m_nCurPageID = m_nCurPageID; //selected page
219
pConfig->m_fIsValid = true;
222
void lmToolBox::SetConfiguration(lmToolBoxConfiguration* pConfig)
224
//Reconfigures ToolBox as specified by received pConfig parameter
228
SetDefaultConfiguration();
232
wxASSERT(pConfig->IsOk());
235
for (int i=0; i < (int)lmPAGE_MAX; i++)
236
m_cActivePages[i] = pConfig->m_Pages[i];
239
m_pSpecialGroup = pConfig->m_pSpecialGroup; //panel for the special group
240
m_nCurPageID = pConfig->m_nCurPageID; //selected page
244
m_pSpecialGroup->Show(pConfig->m_fSpecialGroupVisible);
246
GetSizer()->Layout();
248
SelectToolPage(m_nCurPageID);
251
lmToolPage* lmToolBox::CreatePage(lmEToolPageID nPanel)
255
return new lmToolPageClefs(this);
258
lmToolPageNotes* pPage = new lmToolPageNotesStd(this);
259
pPage->CreateGroups();
262
case lmPAGE_BARLINES:
263
return new lmToolPageBarlines(this);
265
return new lmToolPageSymbols(this);
267
//TO_ADD: Add a new case block for creating the new tool panel
271
return (lmToolPage*)NULL;
275
void lmToolBox::AddPage(lmToolPage* pPage, int nToolId)
277
//Adds a page to the toolbox.
279
//add the page to the panel's array
281
m_cPages.push_back(pPage);
284
void lmToolBox::SetAsActive(lmToolPage* pPage, int nToolId)
288
std::vector<lmToolPage*>::iterator it;
289
for (it = m_cPages.begin(); it != m_cPages.end(); ++it, ++nPage)
294
wxASSERT(*it == pPage);
296
int nOldPage = m_cActivePages[nToolId];
297
m_cActivePages[nToolId] = nPage;
299
////hide old page and show the new active one
300
//m_cPages[nOldPage]->Hide();
302
//m_pPageSizer->Replace(m_cPages[nOldPage], pPage);
304
//GetSizer()->Layout();
307
void lmToolBox::OnButtonClicked(wxCommandEvent& event)
309
//identify button pressed
310
SelectToolPage((lmEToolPageID)(event.GetId() - ID_BUTTON));
313
void lmToolBox::SelectToolPage(lmEToolPageID nTool)
315
if (!(nTool > lmPAGE_NONE && nTool < lmPAGE_MAX))
318
SelectButton((int)nTool);
319
m_nCurPageID = nTool;
321
//hide current page and save it
322
wxPanel* pOldPage = m_pCurPage;
326
int nActivePage = m_cActivePages[nTool];
327
m_pCurPage = (m_cPages[nActivePage] ? m_cPages[nActivePage] : m_pEmptyPage);
329
m_pPageSizer->Replace(pOldPage, m_pCurPage);
330
m_pCurPage->SetFocus();
331
GetSizer()->Layout();
333
//return focus to active view
334
GetMainFrame()->SetFocusOnActiveView();
336
//post tool box page change event to the active controller
337
wxWindow* pWnd = GetMainFrame()->GetActiveController();
340
lmToolBoxPageChangedEvent event(nTool);
341
::wxPostEvent(pWnd, event);
346
lmToolPageNotes* lmToolBox::GetNoteProperties() const
348
return (lmToolPageNotes*)m_cPages[ m_cActivePages[lmPAGE_NOTES] ];
351
void lmToolBox::SelectButton(int nTool)
353
// Set selected button as 'pressed' and all others as 'released'
354
for(int i=0; i < (int)lmPAGE_MAX; i++)
357
m_pButton[i]->Release();
359
m_pButton[i]->Press();
363
void lmToolBox::OnKeyPress(wxKeyEvent& event)
365
//redirect all key press events to the active child window
366
GetMainFrame()->RedirectKeyPressEvent(event);
369
void lmToolBox::OnResize(wxSizeEvent& event)
371
//wxSize newSize = event.GetSize();
372
//wxLogMessage(_T("[lmToolBox::OnResize] New size: %d, %d"), newSize.x, newSize.y);
375
void lmToolBox::AddSpecialTools(wxPanel* pNewPanel, wxEvtHandler* pHandler)
377
//Adds the special tools panel at top of ToolBox
379
wxPanel* pOldPanel = m_pSpecialGroup;
380
m_pSpecialGroup->Show(false);
382
wxSizer* pMainSizer = GetSizer();
383
pMainSizer->Replace(pOldPanel, pNewPanel);
385
m_cSpecialGroups.push_back(pNewPanel);
388
m_pSpecialGroup = pNewPanel;
389
m_pSpecialGroup->Show(true);
390
pMainSizer->Layout();
393
void lmToolBox::SetDefaultConfiguration()
395
for (int i=0; i < (int)lmPAGE_MAX; i++)
396
SetAsActive(m_cPages[i], i);
398
//hide fixed group if displayed
400
m_pSpecialGroup->Show(false);
402
SelectToolPage(m_nCurPageID);
405
wxMenu* lmToolBox::GetContextualMenuForSelectedPage()
407
lmToolPage* pSelPage = m_cPages[ m_cActivePages[m_nCurPageID] ];
408
return pSelPage->GetContextualMenuForToolPage();
411
void lmToolBox::OnPopUpMenuEvent(wxCommandEvent& event)
413
lmToolPage* pSelPage = m_cPages[ m_cActivePages[m_nCurPageID] ];
414
pSelPage->OnPopUpMenuEvent(event);
417
int lmToolBox::GetMouseMode()
419
//Determines selected mouse mode (pointer, data entry, eraser, etc.)
421
return m_pMouseModeGroup->GetMouseMode();
424
wxString lmToolBox::GetToolShortDescription()
426
//returns a short description of the selected tool. This description is used to
427
//be displayed in the status bar
429
return GetSelectedPage()->GetToolShortDescription();
432
lmEToolGroupID lmToolBox::GetCurrentGroupID()
434
return GetSelectedPage()->GetCurrentGroupID();
437
lmEToolID lmToolBox::GetCurrentToolID()
439
return GetSelectedPage()->GetCurrentToolID();
442
void lmToolBox::OnEraseBackground(wxEraseEvent& event)
444
//wxDC* pDC = event.GetDC();
445
//pDC->SetBrush(*wxRED_BRUSH);
446
//pDC->DrawRectangle(this->GetRect());
451
//--------------------------------------------------------------------------------
452
// lmGrpMouseMode implementation
453
//--------------------------------------------------------------------------------
455
lmGrpMouseMode::lmGrpMouseMode(wxPanel* pParent, wxBoxSizer* pMainSizer, lmColorScheme* pColours)
456
: lmToolButtonsGroup(pParent, lm_eGT_Options, lm_NUM_MOUSE_MODE_BUTTONS,
457
lmTBG_ONE_SELECTED, pMainSizer,
458
lmID_BT_MouseMode_Pointer, lmTOOL_NONE, pColours)
462
void lmGrpMouseMode::CreateGroupControls(wxBoxSizer* pMainSizer)
464
//create the common controls for a group
465
SetGroupTitle(_("Mouse mode"));
466
wxBoxSizer* pCtrolsSizer = CreateGroupSizer(pMainSizer);
468
wxBoxSizer* pButtonsSizer = new wxBoxSizer(wxHORIZONTAL);
469
pCtrolsSizer->Add(pButtonsSizer);
470
wxSize btSize(24, 24);
472
//Selection tool mode
473
m_pButton[0] = new lmCheckButton(this, lmID_BT_MouseMode_Pointer, wxBitmap(24, 24));
474
wxString sBtName = _T("mouse_mode_selection");
475
m_pButton[0]->SetBitmapUp(sBtName, _T(""), btSize);
476
m_pButton[0]->SetBitmapDown(sBtName, _T("button_selected_flat"), btSize);
477
m_pButton[0]->SetBitmapOver(sBtName, _T("button_over_flat"), btSize);
478
m_pButton[0]->SetToolTip(_("Mouse will behave as pointer and selection tool"));
479
pButtonsSizer->Add(m_pButton[0], wxSizerFlags(0).Border(wxALL, 0) );
482
m_pButton[1] = new lmCheckButton(this, lmID_BT_MouseMode_DataEntry, wxBitmap(24, 24));
483
sBtName = _T("mouse_mode_data_entry");
484
m_pButton[1]->SetBitmapUp(sBtName, _T(""), btSize);
485
m_pButton[1]->SetBitmapDown(sBtName, _T("button_selected_flat"), btSize);
486
m_pButton[1]->SetBitmapOver(sBtName, _T("button_over_flat"), btSize);
487
m_pButton[1]->SetToolTip(_("Mouse will be used to add objects to the score"));
488
pButtonsSizer->Add(m_pButton[1], wxSizerFlags(0).Border(wxALL, 0) );
492
SetMouseMode(lmMM_POINTER); //select pointer tool mode
495
int lmGrpMouseMode::GetMouseMode()
499
case 0: return lmMM_POINTER;
500
case 1: return lmMM_DATA_ENTRY;
501
default: return lmMM_UNDEFINED;
505
void lmGrpMouseMode::SetMouseMode(int nMouseMode)
509
case lmMM_POINTER: SelectButton(0); break;
510
case lmMM_DATA_ENTRY: SelectButton(1); break;