2018-10-03 10:02:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-07-15 19:26:35 +00:00
|
|
|
* Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-10-03 10:02:43 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file ui_common.h
|
|
|
|
* Functions to provide common constants and other functions to assist
|
|
|
|
* in making a consistent UI
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UI_COMMON_H
|
|
|
|
#define UI_COMMON_H
|
|
|
|
|
2024-03-20 01:53:21 +00:00
|
|
|
#include <kicommon.h>
|
2021-08-16 11:49:22 +00:00
|
|
|
#include "report_severity.h" // enum SEVERITY
|
2020-10-18 11:31:07 +00:00
|
|
|
#include <wx/string.h>
|
2021-06-29 17:27:05 +00:00
|
|
|
#include <wx/font.h>
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2024-05-26 22:02:09 +00:00
|
|
|
class wxBitmapBundle;
|
2020-10-25 16:41:38 +00:00
|
|
|
class wxSize;
|
|
|
|
class wxTextCtrl;
|
|
|
|
class wxTextEntry;
|
|
|
|
class wxWindow;
|
2023-10-16 23:40:46 +00:00
|
|
|
class wxMenuItem;
|
|
|
|
class wxMenu;
|
2020-10-25 16:41:38 +00:00
|
|
|
|
2022-09-16 11:25:04 +00:00
|
|
|
/**
|
|
|
|
* Used for holding indeterminate values, such as with multiple selections
|
|
|
|
* holding different values or controls which do not wish to set a value.
|
|
|
|
*/
|
|
|
|
#define INDETERMINATE_STATE _( "-- mixed values --" )
|
|
|
|
#define INDETERMINATE_ACTION _( "-- leave unchanged --" )
|
|
|
|
|
2018-10-03 10:02:43 +00:00
|
|
|
namespace KIUI
|
|
|
|
{
|
|
|
|
|
2024-05-26 19:14:52 +00:00
|
|
|
const int c_IndicatorSizeDIP = 10;
|
2024-05-26 13:37:05 +00:00
|
|
|
|
|
|
|
|
2018-10-03 10:02:43 +00:00
|
|
|
/**
|
|
|
|
* Get the standard margin around a widget in the KiCad UI
|
|
|
|
* @return margin in pixels
|
|
|
|
*/
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API int GetStdMargin();
|
2018-10-03 10:02:43 +00:00
|
|
|
|
2020-10-25 16:41:38 +00:00
|
|
|
/**
|
|
|
|
* Return the size of @a aSingleLine of text when it is rendered in @a aWindow
|
|
|
|
* using whatever font is currently set in that window.
|
|
|
|
*/
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API wxSize GetTextSize( const wxString& aSingleLine, wxWindow* aWindow );
|
2020-10-25 16:41:38 +00:00
|
|
|
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API wxFont GetMonospacedUIFont();
|
2021-06-29 17:27:05 +00:00
|
|
|
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API wxFont GetControlFont( wxWindow* aWindow );
|
|
|
|
KICOMMON_API wxFont GetInfoFont( wxWindow* aWindow );
|
|
|
|
KICOMMON_API wxFont GetDockedPaneFont( wxWindow* aWindow );
|
|
|
|
KICOMMON_API wxFont GetStatusFont( wxWindow* aWindow );
|
2021-09-08 20:34:02 +00:00
|
|
|
|
2020-10-25 16:41:38 +00:00
|
|
|
/**
|
|
|
|
* Set the minimum pixel width on a text control in order to make a text
|
|
|
|
* string be fully visible within it.
|
|
|
|
*
|
|
|
|
* The current font within the text control is considered. The text can come either from
|
|
|
|
* the control or be given as an argument. If the text control is larger than needed, then
|
|
|
|
* nothing is done.
|
|
|
|
*
|
|
|
|
* @param aCtrl the text control to potentially make wider.
|
|
|
|
* @param aString the text that is used in sizing the control's pixel width.
|
|
|
|
* If NULL, then
|
|
|
|
* the text already within the control is used.
|
2021-07-15 19:26:35 +00:00
|
|
|
* @return true if the \a aCtrl had its size changed, else false.
|
2020-10-25 16:41:38 +00:00
|
|
|
*/
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = nullptr );
|
2020-10-25 16:41:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Select the number (or "?") in a reference for ease of editing.
|
|
|
|
*/
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API void SelectReferenceNumber( wxTextEntry* aTextEntry );
|
2020-10-25 16:41:38 +00:00
|
|
|
|
2022-08-22 16:39:19 +00:00
|
|
|
/**
|
|
|
|
* Ellipsize text (at the end) to be no more than 1/3 of the window width.
|
|
|
|
*
|
|
|
|
* @return shortened text ending with an ellipsis.
|
|
|
|
*/
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API wxString EllipsizeStatusText( wxWindow* aWindow, const wxString& aString );
|
2022-08-22 16:39:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ellipsize text (at the end) to be no more than 36 characters.
|
|
|
|
*
|
|
|
|
* @return shortened text ending with an ellipsis.
|
|
|
|
*/
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API wxString EllipsizeMenuText( const wxString& aString );
|
2022-08-22 16:39:19 +00:00
|
|
|
|
2020-11-05 02:06:36 +00:00
|
|
|
/**
|
2021-08-16 11:49:22 +00:00
|
|
|
* Check if a input control has focus.
|
2021-07-05 23:47:03 +00:00
|
|
|
*
|
|
|
|
* @param aFocus Control that has focus, if null, wxWidgets will be queried
|
|
|
|
*/
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API bool IsInputControlFocused( wxWindow* aFocus = nullptr );
|
2021-07-05 23:47:03 +00:00
|
|
|
|
|
|
|
/**
|
2021-08-16 11:49:22 +00:00
|
|
|
* Check if a input control has focus.
|
2021-07-05 23:47:03 +00:00
|
|
|
*
|
|
|
|
* @param aFocus Control that test if editable
|
2021-07-15 19:26:35 +00:00
|
|
|
* @return True if control is input and editable OR control is not a input. False if control is
|
|
|
|
* input and not editable.
|
2020-11-05 02:06:36 +00:00
|
|
|
*/
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API bool IsInputControlEditable( wxWindow* aControl );
|
2020-11-05 02:06:36 +00:00
|
|
|
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API bool IsModalDialogFocused();
|
2020-11-26 15:43:48 +00:00
|
|
|
|
2021-10-05 20:30:15 +00:00
|
|
|
/**
|
|
|
|
* Makes a window read-only. Does some extra work over wxWindow::Disable() to make sure you
|
|
|
|
* can still scroll around in sub-windows.
|
|
|
|
*/
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API void Disable( wxWindow* aWindow );
|
2021-10-05 20:30:15 +00:00
|
|
|
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API extern const wxString s_FocusStealableInputName;
|
2023-05-31 02:06:49 +00:00
|
|
|
|
2023-10-16 23:40:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a bitmap to a menuitem.
|
|
|
|
*
|
|
|
|
* It is added only if use images in menus config option allows it. For wxITEM_CHECK
|
|
|
|
* or wxITEM_RADIO menuitems, the bitmap is added only on Windows, other platforms do
|
|
|
|
* not support it
|
|
|
|
*
|
|
|
|
* @param aMenu is the menuitem.
|
|
|
|
* @param aImage is the icon to add to aMenu.
|
|
|
|
*/
|
2024-05-26 22:02:09 +00:00
|
|
|
KICOMMON_API void AddBitmapToMenuItem( wxMenuItem* aMenu, const wxBitmapBundle& aImage );
|
2023-10-16 23:40:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and insert a menu item with an icon into \a aMenu.
|
|
|
|
*
|
|
|
|
* @param aMenu is the menu to add the new item.
|
|
|
|
* @param aId is the command ID for the new menu item.
|
|
|
|
* @param aText is the string for the new menu item.
|
|
|
|
* @param aImage is the icon to add to the new menu item.
|
|
|
|
* @param aType is the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
|
|
|
|
* @return a pointer to the new created wxMenuItem.
|
|
|
|
*/
|
2024-05-26 22:02:09 +00:00
|
|
|
KICOMMON_API wxMenuItem* AddMenuItem( wxMenu* aMenu, int aId, const wxString& aText,
|
|
|
|
const wxBitmapBundle& aImage,
|
|
|
|
wxItemKind aType = wxITEM_NORMAL );
|
2023-10-16 23:40:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and insert a menu item with an icon and a help message string into \a aMenu.
|
|
|
|
*
|
|
|
|
* @param aMenu is the menu to add the new item.
|
|
|
|
* @param aId is the command ID for the new menu item.
|
|
|
|
* @param aText is the string for the new menu item.
|
|
|
|
* @param aHelpText is the help message string for the new menu item.
|
|
|
|
* @param aImage is the icon to add to the new menu item.
|
|
|
|
* @param aType is the type of menu :wxITEM_NORMAL (default), wxITEM_CHECK ...
|
|
|
|
* @return a pointer to the new created wxMenuItem.
|
|
|
|
*/
|
2024-05-26 22:02:09 +00:00
|
|
|
KICOMMON_API wxMenuItem* AddMenuItem( wxMenu* aMenu, int aId, const wxString& aText,
|
|
|
|
const wxString& aHelpText, const wxBitmapBundle& aImage,
|
|
|
|
wxItemKind aType = wxITEM_NORMAL );
|
2023-10-16 23:40:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and insert a menu item with an icon into \a aSubMenu in \a aMenu.
|
|
|
|
*
|
|
|
|
* @param aMenu is the menu to add the new submenu item.
|
|
|
|
* @param aSubMenu is the submenu to add the new menu.
|
|
|
|
* @param aId is the command ID for the new menu item.
|
|
|
|
* @param aText is the string for the new menu item.
|
|
|
|
* @param aImage is the icon to add to the new menu item.
|
|
|
|
* @return a pointer to the new created wxMenuItem,
|
|
|
|
*/
|
2024-05-26 22:02:09 +00:00
|
|
|
KICOMMON_API wxMenuItem* AddMenuItem( wxMenu* aMenu, wxMenu* aSubMenu, int aId,
|
|
|
|
const wxString& aText, const wxBitmapBundle& aImage );
|
2023-10-16 23:40:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and insert a menu item with an icon and a help message string into
|
|
|
|
* \a aSubMenu in \a aMenu.
|
|
|
|
*
|
|
|
|
* @param aMenu is the menu to add the new submenu item.
|
|
|
|
* @param aSubMenu is the submenu to add the new menu.
|
|
|
|
* @param aId is the command ID for the new menu item.
|
|
|
|
* @param aText is the string for the new menu item.
|
|
|
|
* @param aHelpText is the help message string for the new menu item.
|
|
|
|
* @param aImage is the icon to add to the new menu item.
|
|
|
|
* @return a pointer to the new created wxMenuItem.
|
|
|
|
*/
|
2024-05-26 22:02:09 +00:00
|
|
|
KICOMMON_API wxMenuItem* AddMenuItem( wxMenu* aMenu, wxMenu* aSubMenu, int aId,
|
|
|
|
const wxString& aText, const wxString& aHelpText,
|
|
|
|
const wxBitmapBundle& aImage );
|
2018-10-03 10:02:43 +00:00
|
|
|
}
|
|
|
|
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API SEVERITY SeverityFromString( const wxString& aSeverity );
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2024-03-20 01:53:21 +00:00
|
|
|
KICOMMON_API wxString SeverityToString( const SEVERITY& aSeverity );
|
2020-02-28 00:05:40 +00:00
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
#endif // UI_COMMON_H
|