1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
//
// Copyright (C) 2009-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
// (C) 2014-2016 Gunter Königsmann <wxMaxima@physikbuch.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// SPDX-License-Identifier: GPL-2.0+
/*! \file
This file defines the class CharacterButton
This file contains the definition of the class CharacterButton that allows to
select arbitrary unicode symbols.
*/
#include "CharButton.h"
#include "UnicodeSidebar.h"
#include "wx/sizer.h"
#include <wx/settings.h>
void CharButton::ForwardToParent(wxMouseEvent &event)
{
event.Skip();
if(GetParent())
GetParent()->GetEventHandler()->QueueEvent(new wxMouseEvent(event));
}
void CharButton::MouseOverPanel(wxMouseEvent &event)
{
m_mouseOverPanel = true;
m_backgroundColorChangeNeeded = true;
event.Skip();
}
void CharButton::MouseLeftPanel(wxMouseEvent &event)
{
m_mouseOverPanel = false;
m_backgroundColorChangeNeeded = true;
event.Skip();
}
void CharButton::MouseOverText(wxMouseEvent &event)
{
m_mouseOverText = true;
m_backgroundColorChangeNeeded = true;
event.Skip();
}
void CharButton::MouseLeftText(wxMouseEvent &event)
{
m_mouseOverText = false;
m_backgroundColorChangeNeeded = true;
event.Skip();
}
void CharButton::OnIdle(wxIdleEvent &event)
{
if(!m_backgroundColorChangeNeeded)
return;
m_backgroundColorChangeNeeded = false;
if((m_mouseOverPanel)||(m_mouseOverText))
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
else
// An invalid color means "the default background"
SetBackgroundColour(wxColour());
event.Skip();
}
void CharButton::CharButtonPressed(wxCommandEvent &WXUNUSED(event))
{
wxCommandEvent *ev = new wxCommandEvent(SIDEBARKEYEVENT, (long)(m_char));
m_worksheet->GetEventHandler()->QueueEvent(ev);
}
void CharButton::OnSize(wxSizeEvent &event)
{
wxFont fnt = GetFont();
wxClientDC dc(this);
dc.SetFont(fnt);
auto size = dc.GetTextExtent(m_char);
auto minSize = dc.GetTextExtent("M");
minSize.x *= 1.5;
minSize.y *= 1.5;
size.x += 2 * GetContentScaleFactor();
size.y += 2 * GetContentScaleFactor();
if(minSize.x < minSize.y)
minSize.x = minSize.y;
if(minSize.x > size.x)
size.x = minSize.x;
if(minSize.y > size.y)
size.y = minSize.y;
SetSize(size);
SetMinSize(size);
event.Skip();
}
CharButton::CharButton(wxWindow *parent, wxWindow *worksheet, const Definition &def) :
wxPanel(parent, wxID_ANY),
m_char(def.symbol),
m_worksheet(worksheet)
{
Connect(wxEVT_SIZE, wxSizeEventHandler(CharButton::OnSize));
Connect(wxEVT_IDLE,
wxIdleEventHandler(CharButton::OnIdle), NULL, this);
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
m_buttonText = new wxStaticText(this, -1, wxString(m_char));
sizer->AddStretchSpacer(1);
sizer->Add(m_buttonText, 0, wxALIGN_CENTER_VERTICAL);
sizer->AddStretchSpacer(1);
SetSizer(sizer);
FitInside();
SetToolTip(def.description);
Connect(wxEVT_LEFT_UP, wxCommandEventHandler(CharButton::CharButtonPressed), NULL, this);
Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(CharButton::ForwardToParent), NULL, this);
Connect(wxEVT_IDLE, wxIdleEventHandler(CharButton::OnIdle), NULL, this);
Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(CharButton::MouseOverPanel), NULL, this);
Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(CharButton::MouseLeftPanel), NULL, this);
m_buttonText->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(CharButton::MouseOverText), NULL, this);
m_buttonText->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(CharButton::MouseLeftText), NULL, this);
m_buttonText->Connect(wxEVT_LEFT_UP, wxCommandEventHandler(CharButton::CharButtonPressed), NULL, this);
m_buttonText->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(CharButton::ForwardToParent), NULL, this);
}
|