Add platform-specific code to allow wxChoice to ellipsize

Fixes https://gitlab.com/kicad/code/kicad/issues/5377
This commit is contained in:
Ian McInerney 2020-10-17 22:55:38 +01:00
parent c0d381e588
commit 06f01d0d8a
5 changed files with 55 additions and 3 deletions

View File

@ -35,6 +35,8 @@
#include <filename_resolver.h>
#include <pcbnew/class_module.h>
#include <kiplatform/ui.h>
DLG_SELECT_3DMODEL::DLG_SELECT_3DMODEL( wxWindow* aParent, S3D_CACHE* aCacheManager,
MODULE_3D_SETTINGS* aModelItem, wxString& prevModelSelectDir, int& prevModelWildcard ) :
@ -117,6 +119,12 @@ DLG_SELECT_3DMODEL::DLG_SELECT_3DMODEL( wxWindow* aParent, S3D_CACHE* aCacheMana
m_FileTree->SetFilterIndex( 0 );
}
// Fix the filter box on the file selector widget so that it always shows the start of the filter
// string in the combobox. Otherwise it will only show the end of the string, which is empty for
// all but the all supported filters option.
wxChoice* filterBox = m_FileTree->GetFilterListCtrl();
KIPLATFORM::UI::EllipsizeChoiceBox( filterBox );
m_FileTree->SetPath( m_previousDir );
updateDirChoiceList();

View File

@ -20,10 +20,13 @@
#include <kiplatform/ui.h>
#include <wx/choice.h>
#include <wx/nonownedwnd.h>
#include <wx/settings.h>
#include <wx/window.h>
#include <gtk/gtk.h>
bool KIPLATFORM::UI::IsDarkTheme()
{
@ -68,3 +71,23 @@ bool KIPLATFORM::UI::IsStockCursorOk( wxStockCursor aCursor )
return false;
}
}
void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
{
// This function is based on the code inside the function post_process_ui in gtkfilechooserwidget.c
GList* cells = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( aChoice->m_widget ) );
if( !cells )
return;
GtkCellRenderer* cell = (GtkCellRenderer*) cells->data;
if( !cell )
return;
g_object_set( G_OBJECT( cell ), "ellipsize", PANGO_ELLIPSIZE_END, NULL );
// Only the list of cells must be freed, the renderer isn't ours to free
g_list_free( cells );
}

View File

@ -23,6 +23,7 @@
#include <wx/cursor.h>
class wxChoice;
class wxNonOwnedWindow;
class wxWindow;
@ -76,6 +77,14 @@ namespace KIPLATFORM
* @param aCursor is wxStockCursor we want to see if its acceptable
*/
bool IsStockCursorOk( wxStockCursor aCursor );
/**
* Configure a wxChoice control to ellipsize the shown text in the button with the ellipses
* placed at the end of the string.
*
* @param aChoice is the choice box to ellipsize
*/
void EllipsizeChoiceBox( wxChoice* aChoice );
}
}

View File

@ -47,7 +47,7 @@ bool KIPLATFORM::UI::IsDarkTheme()
return false;
long val = 0;
if( !themeKey.QueryValue( lightModeKey, &val ) )
return false;
@ -88,4 +88,10 @@ bool KIPLATFORM::UI::IsStockCursorOk( wxStockCursor aCursor )
default:
return false;
}
}
}
void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
{
// Not implemented
}

View File

@ -84,4 +84,10 @@ bool KIPLATFORM::UI::IsStockCursorOk( wxStockCursor aCursor )
default:
return false;
}
}
}
void KIPLATFORM::UI::EllipsizeChoiceBox( wxChoice* aChoice )
{
// Not implemented
}