From 047749a8dca3829cfe95bf897c802bba89024b8d Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 2 Sep 2013 11:06:17 +0200 Subject: [PATCH] minor changes and refinement in class pcb layer box --- common/class_layer_box_selector.cpp | 12 +++++------ include/class_layer_box_selector.h | 2 +- pcbnew/class_pcb_layer_box_selector.cpp | 28 ++++++++++++++++++------- pcbnew/class_pcb_layer_box_selector.h | 5 +++-- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/common/class_layer_box_selector.cpp b/common/class_layer_box_selector.cpp index c5eb0b237a..a4676e91cf 100644 --- a/common/class_layer_box_selector.cpp +++ b/common/class_layer_box_selector.cpp @@ -50,15 +50,13 @@ void LAYER_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer ) bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() ); } -/* class to display a layer list. - * +/* class to display a layer list in a wxBitmapComboBox. */ - LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, int n, const wxString choices[] ) : - LAYER_SELECTOR(), - wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ) + wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ), + LAYER_SELECTOR() { if( choices != NULL ) ResyncBitmapOnly(); @@ -68,8 +66,8 @@ LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, const wxArrayString& choices ) : - LAYER_SELECTOR(), - wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY ) + wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY ), + LAYER_SELECTOR() { if( !choices.IsEmpty() ) ResyncBitmapOnly(); diff --git a/include/class_layer_box_selector.h b/include/class_layer_box_selector.h index 4f6cf5d04e..27d19b8a18 100644 --- a/include/class_layer_box_selector.h +++ b/include/class_layer_box_selector.h @@ -46,7 +46,7 @@ protected: /* class to display a layer list in a wxBitmapComboBox. */ -class LAYER_BOX_SELECTOR : public LAYER_SELECTOR, public wxBitmapComboBox +class LAYER_BOX_SELECTOR :public wxBitmapComboBox, public LAYER_SELECTOR { public: // Hotkey Info diff --git a/pcbnew/class_pcb_layer_box_selector.cpp b/pcbnew/class_pcb_layer_box_selector.cpp index 807e8b0f78..30a3f56938 100644 --- a/pcbnew/class_pcb_layer_box_selector.cpp +++ b/pcbnew/class_pcb_layer_box_selector.cpp @@ -40,10 +40,7 @@ #include -/* class to display a layer list. - * - */ - +// class to display a layer list in a wxBitmapComboBox. // Reload the Layers void PCB_LAYER_BOX_SELECTOR::Resync() @@ -53,9 +50,16 @@ void PCB_LAYER_BOX_SELECTOR::Resync() static DECLARE_LAYERS_ORDER_LIST( layertranscode ); static DECLARE_LAYERS_HOTKEY( layerhk ); + // Tray to fix a minimum width fot the BitmapComboBox + int minwidth, h; + wxClientDC dc( GetParent() ); // The DC for "this" is not always initialized + wxString dummyText( wxT("XXXXXXXXXXXX") ); + dc.GetTextExtent ( dummyText, &minwidth, &h ); + + #define BM_SIZE 14 for( LAYER_NUM i = FIRST_LAYER; i < NB_LAYERS; ++i ) { - wxBitmap layerbmp( 14, 14 ); + wxBitmap layerbmp( BM_SIZE, BM_SIZE ); wxString layername; LAYER_NUM layerid = i; @@ -73,10 +77,20 @@ void PCB_LAYER_BOX_SELECTOR::Resync() layername = GetLayerName( layerid ); if( m_layerhotkeys && m_hotkeys != NULL ) - layername = AddHotkeyName( layername, m_hotkeys, layerhk[layerid], IS_COMMENT ); + layername = AddHotkeyName( layername, m_hotkeys, + layerhk[layerid], IS_COMMENT ); Append( layername, layerbmp, (void*)(intptr_t) layerid ); - } + int w; + dc.GetTextExtent ( layername, &w, &h ); + + minwidth = std::max( minwidth, w ); + } + + minwidth += BM_SIZE + 12; // Take in account the bitmap size and margins +wxLogMessage( "minw %d min %d", minwidth, GetMinClientSize().x ); +// SetMinClientSize( wxSize( minwidth, -1 ) ); + Layout(); } diff --git a/pcbnew/class_pcb_layer_box_selector.h b/pcbnew/class_pcb_layer_box_selector.h index 0a63b65032..5ac87e5da4 100644 --- a/pcbnew/class_pcb_layer_box_selector.h +++ b/pcbnew/class_pcb_layer_box_selector.h @@ -19,9 +19,9 @@ public: public: // If you are thinking the constructor is a bit curious, - // just remember it is used by automaticallty generated by wxFormBuilder files, + // just remember it is used by automaticallty generated by wxFormBuilder files, // and it should mimic the wxBitmapComboBox constructor. - // Therefore, value, pos, size, n, choices and style are not yet used, + // Therefore, value, style are not yet used, // but they are here for compatibility PCB_LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id, const wxString& value = wxEmptyString, @@ -49,6 +49,7 @@ public: // Virtual function void Resync(); +private: // Returns a color index from the layer id // Virtual function EDA_COLOR_T GetLayerColor( LAYER_NUM aLayer ) const;