2021-03-01 21:53:20 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2024-05-25 18:47:31 +00:00
|
|
|
* Copyright (C) 2021-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-03-01 21:53:20 +00:00
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wx/aui/aui.h>
|
2021-03-02 04:10:03 +00:00
|
|
|
#include <wx/aui/framemanager.h>
|
2021-03-01 21:53:20 +00:00
|
|
|
#include <wx/bitmap.h>
|
|
|
|
#include <wx/dc.h>
|
|
|
|
#include <wx/settings.h>
|
|
|
|
|
|
|
|
#include <kiplatform/ui.h>
|
2023-10-22 00:41:02 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/common_settings.h>
|
2021-03-02 04:10:03 +00:00
|
|
|
#include <widgets/wx_aui_art_providers.h>
|
2021-03-01 21:53:20 +00:00
|
|
|
|
2021-07-15 19:26:35 +00:00
|
|
|
|
2023-10-22 00:41:02 +00:00
|
|
|
wxSize WX_AUI_TOOLBAR_ART::GetToolSize( wxDC& aDc, wxWindow* aWindow,
|
|
|
|
const wxAuiToolBarItem& aItem )
|
|
|
|
{
|
|
|
|
// Based on the upstream wxWidgets implementation, but simplified for our application
|
|
|
|
int size = Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size;
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
size *= KIPLATFORM::UI::GetContentScaleFactor( aWindow );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int width = size;
|
|
|
|
int height = size;
|
|
|
|
|
|
|
|
if( m_flags & wxAUI_TB_TEXT )
|
|
|
|
{
|
|
|
|
aDc.SetFont( m_font );
|
|
|
|
int tx, ty;
|
|
|
|
|
|
|
|
if( m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM )
|
|
|
|
{
|
|
|
|
aDc.GetTextExtent( wxT( "ABCDHgj" ), &tx, &ty );
|
|
|
|
height += ty;
|
|
|
|
|
|
|
|
if( !aItem.GetLabel().empty() )
|
|
|
|
{
|
|
|
|
aDc.GetTextExtent( aItem.GetLabel(), &tx, &ty );
|
|
|
|
width = wxMax( width, tx + aWindow->FromDIP( 6 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( m_textOrientation == wxAUI_TBTOOL_TEXT_RIGHT && !aItem.GetLabel().empty() )
|
|
|
|
{
|
|
|
|
width += aWindow->FromDIP( 3 ); // space between left border and bitmap
|
|
|
|
width += aWindow->FromDIP( 3 ); // space between bitmap and text
|
|
|
|
|
|
|
|
if( !aItem.GetLabel().empty() )
|
|
|
|
{
|
|
|
|
aDc.GetTextExtent( aItem.GetLabel(), &tx, &ty );
|
|
|
|
width += tx;
|
|
|
|
height = wxMax( height, ty );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aItem.HasDropDown() )
|
|
|
|
{
|
|
|
|
int dropdownWidth = GetElementSize( wxAUI_TBART_DROPDOWN_SIZE );
|
|
|
|
width += dropdownWidth + aWindow->FromDIP( 4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxSize( width, height );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-02 04:10:03 +00:00
|
|
|
void WX_AUI_TOOLBAR_ART::DrawButton( wxDC& aDc, wxWindow* aWindow, const wxAuiToolBarItem& aItem,
|
|
|
|
const wxRect& aRect )
|
2021-03-01 21:53:20 +00:00
|
|
|
{
|
2023-10-22 00:41:02 +00:00
|
|
|
// Taken from upstream implementation; modified to respect tool size
|
|
|
|
wxSize bmpSize = GetToolSize( aDc, aWindow, aItem );
|
|
|
|
|
|
|
|
int textWidth = 0, textHeight = 0;
|
2021-03-01 21:53:20 +00:00
|
|
|
|
|
|
|
if( m_flags & wxAUI_TB_TEXT )
|
|
|
|
{
|
|
|
|
aDc.SetFont( m_font );
|
|
|
|
|
|
|
|
int tx, ty;
|
|
|
|
|
|
|
|
aDc.GetTextExtent( wxT( "ABCDHgj" ), &tx, &textHeight );
|
|
|
|
textWidth = 0;
|
|
|
|
aDc.GetTextExtent( aItem.GetLabel(), &textWidth, &ty );
|
|
|
|
}
|
|
|
|
|
|
|
|
int bmpX = 0, bmpY = 0;
|
|
|
|
int textX = 0, textY = 0;
|
|
|
|
|
2023-10-22 19:40:05 +00:00
|
|
|
double scale = KIPLATFORM::UI::GetPixelScaleFactor( aWindow );
|
2023-10-22 00:41:02 +00:00
|
|
|
const wxBitmapBundle& bundle = ( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
|
|
|
|
? aItem.GetDisabledBitmapBundle()
|
|
|
|
: aItem.GetBitmapBundle();
|
|
|
|
wxBitmap bmp = bundle.GetBitmap( bmpSize * scale );
|
|
|
|
|
|
|
|
// wxBitmapBundle::GetBitmap thinks we need this rescaled to match the base size, which we don't
|
|
|
|
if( bmp.IsOk() )
|
|
|
|
bmp.SetScaleFactor( scale );
|
|
|
|
|
2021-03-01 21:53:20 +00:00
|
|
|
if( m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM )
|
|
|
|
{
|
2023-10-22 00:41:02 +00:00
|
|
|
bmpX = aRect.x + ( aRect.width / 2 ) - ( bmpSize.x / 2 );
|
2021-03-01 21:53:20 +00:00
|
|
|
|
2023-10-22 00:41:02 +00:00
|
|
|
bmpY = aRect.y + ( ( aRect.height - textHeight ) / 2 ) - ( bmpSize.y / 2 );
|
2021-03-01 21:53:20 +00:00
|
|
|
|
|
|
|
textX = aRect.x + ( aRect.width / 2 ) - ( textWidth / 2 ) + 1;
|
|
|
|
textY = aRect.y + aRect.height - textHeight - 1;
|
|
|
|
}
|
|
|
|
else if( m_textOrientation == wxAUI_TBTOOL_TEXT_RIGHT )
|
|
|
|
{
|
2023-10-22 00:41:02 +00:00
|
|
|
bmpX = aRect.x + aWindow->FromDIP( 3 );
|
2021-03-01 21:53:20 +00:00
|
|
|
|
2023-10-22 00:41:02 +00:00
|
|
|
bmpY = aRect.y + ( aRect.height / 2 ) - ( bmpSize.y / 2 );
|
2021-03-01 21:53:20 +00:00
|
|
|
|
2023-10-22 00:41:02 +00:00
|
|
|
textX = bmpX + aWindow->FromDIP( 3 ) + bmpSize.x;
|
2021-03-01 21:53:20 +00:00
|
|
|
textY = aRect.y + ( aRect.height / 2 ) - ( textHeight / 2 );
|
|
|
|
}
|
|
|
|
|
2023-10-22 00:41:02 +00:00
|
|
|
bool isThemeDark = KIPLATFORM::UI::IsDarkTheme();
|
|
|
|
|
2021-03-01 21:53:20 +00:00
|
|
|
if( !( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED ) )
|
|
|
|
{
|
|
|
|
if( aItem.GetState() & wxAUI_BUTTON_STATE_PRESSED )
|
|
|
|
{
|
|
|
|
aDc.SetPen( wxPen( m_highlightColour ) );
|
2023-10-22 00:41:02 +00:00
|
|
|
aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 20 : 150 ) ) );
|
2021-03-01 21:53:20 +00:00
|
|
|
aDc.DrawRectangle( aRect );
|
|
|
|
}
|
|
|
|
else if( ( aItem.GetState() & wxAUI_BUTTON_STATE_HOVER ) || aItem.IsSticky() )
|
|
|
|
{
|
|
|
|
aDc.SetPen( wxPen( m_highlightColour ) );
|
2023-10-22 00:41:02 +00:00
|
|
|
aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 40 : 170 ) ) );
|
2021-03-01 21:53:20 +00:00
|
|
|
|
2023-10-22 00:41:02 +00:00
|
|
|
// draw an even lighter background for checked item hovers (since
|
2021-03-01 21:53:20 +00:00
|
|
|
// the hover background is the same color as the check background)
|
|
|
|
if( aItem.GetState() & wxAUI_BUTTON_STATE_CHECKED )
|
2023-10-22 00:41:02 +00:00
|
|
|
aDc.SetBrush(
|
|
|
|
wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 50 : 180 ) ) );
|
2021-03-01 21:53:20 +00:00
|
|
|
|
|
|
|
aDc.DrawRectangle( aRect );
|
|
|
|
}
|
|
|
|
else if( aItem.GetState() & wxAUI_BUTTON_STATE_CHECKED )
|
|
|
|
{
|
|
|
|
// it's important to put this code in an else statement after the
|
2023-10-22 00:41:02 +00:00
|
|
|
// hover, otherwise hovers won't draw properly for checked items
|
2021-03-01 21:53:20 +00:00
|
|
|
aDc.SetPen( wxPen( m_highlightColour ) );
|
2023-10-22 00:41:02 +00:00
|
|
|
aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( isThemeDark ? 40 : 170 ) ) );
|
2021-03-01 21:53:20 +00:00
|
|
|
aDc.DrawRectangle( aRect );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bmp.IsOk() )
|
2024-05-25 18:47:31 +00:00
|
|
|
{
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
// Optimization - see https://github.com/wxWidgets/wxWidgets/issues/23841
|
|
|
|
aDc.GetAsBitmap().ConvertToDIB();
|
|
|
|
#endif
|
2021-03-01 21:53:20 +00:00
|
|
|
aDc.DrawBitmap( bmp, bmpX, bmpY, true );
|
2024-05-25 18:47:31 +00:00
|
|
|
}
|
2021-03-01 21:53:20 +00:00
|
|
|
|
2023-10-22 00:41:02 +00:00
|
|
|
// set the item's text color based on if it is disabled
|
|
|
|
aDc.SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
|
2021-03-01 21:53:20 +00:00
|
|
|
|
|
|
|
if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
|
2023-10-22 00:41:02 +00:00
|
|
|
{
|
2021-03-01 21:53:20 +00:00
|
|
|
aDc.SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
2023-10-22 00:41:02 +00:00
|
|
|
}
|
2021-03-01 21:53:20 +00:00
|
|
|
|
|
|
|
if( ( m_flags & wxAUI_TB_TEXT ) && !aItem.GetLabel().empty() )
|
|
|
|
{
|
|
|
|
aDc.DrawText( aItem.GetLabel(), textX, textY );
|
|
|
|
}
|
|
|
|
}
|
2021-03-02 04:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
WX_AUI_DOCK_ART::WX_AUI_DOCK_ART() : wxAuiDefaultDockArt()
|
|
|
|
{
|
|
|
|
#if defined( _WIN32 )
|
|
|
|
// Use normal control font, wx likes to use "small"
|
|
|
|
m_captionFont = *wxNORMAL_FONT;
|
|
|
|
|
|
|
|
// Increase the box the caption rests in size a bit
|
2024-01-18 02:45:09 +00:00
|
|
|
m_captionSize = ( wxNORMAL_FONT->GetPixelSize().y * 7 ) / 4;
|
2021-03-02 04:10:03 +00:00
|
|
|
#endif
|
|
|
|
|
2021-04-20 01:12:02 +00:00
|
|
|
SetColour( wxAUI_DOCKART_ACTIVE_CAPTION_TEXT_COLOUR,
|
|
|
|
wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
|
|
|
|
SetColour( wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR,
|
|
|
|
wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
|
|
|
|
|
2021-03-02 04:10:03 +00:00
|
|
|
// Turn off the ridiculous looking gradient
|
|
|
|
m_gradientType = wxAUI_GRADIENT_NONE;
|
|
|
|
}
|