wxSize wxChoice::DoGetSizeFromTextSize(int xlen, int ylen) const { wxASSERT_MSG( m_widget, wxS("GetSizeFromTextSize called before creation") ); // a GtkEntry for wxComboBox and a GtkCellView for wxChoice GtkWidget* childPart = gtk_bin_get_child(GTK_BIN(m_widget)); // Set a as small as possible size for the control, so preferred sizes // return "natural" sizes, not taking into account the previous ones (which // seems to be GTK+3 behaviour) gtk_widget_set_size_request(m_widget, 0, 0); // We are interested in the difference of sizes between the whole contol // and its child part. I.e. arrow, separators, etc. GtkRequisition req; gtk_widget_get_preferred_size(childPart, NULL, &req); wxSize totalS = GTKGetPreferredSize(m_widget); wxSize tsize(xlen + totalS.x - req.width, totalS.y); // For a wxChoice, not for wxComboBox, add some margins if ( !GTK_IS_ENTRY(childPart) ) tsize.IncBy(5, 0); // Perhaps the user wants something different from CharHeight if ( ylen > 0 ) tsize.IncBy(0, ylen - GetCharHeight()); return tsize; }
wxSize wxSpinCtrlGTKBase::DoGetSizeFromTextSize(int xlen, int ylen) const { wxASSERT_MSG( m_widget, wxS("GetSizeFromTextSize called before creation") ); // Set an as small as possible size for the control, so preferred sizes // return "natural" sizes, not taking into account the previous ones (which // seems to be GTK+3 behaviour) gtk_widget_set_size_request(m_widget, 0, 0); // Both Gtk+2 and Gtk+3 use current value/range to measure control's width. // So, we can't ask Gtk+ for its width. Instead, we used hardcoded values. // Returned height is OK wxSize totalS = GTKGetPreferredSize(m_widget); #if GTK_CHECK_VERSION(3,4,0) // two buttons in horizontal totalS.x = 46 + 15; // margins included #else // two small buttons in vertical totalS.x = GetFont().GetPixelSize().y + 13; // margins included #endif wxSize tsize(xlen + totalS.x, totalS.y); // Check if the user requested a non-standard height. if ( ylen > 0 ) tsize.IncBy(0, ylen - GetCharHeight()); return tsize; }
wxSize wxChoice::DoGetSizeFromTextSize(int xlen, int ylen) const { wxASSERT_MSG( m_widget, wxS("GetSizeFromTextSize called before creation") ); // a GtkEntry for wxComboBox and a GtkCellView for wxChoice GtkWidget* childPart = gtk_bin_get_child(GTK_BIN(m_widget)); // We are interested in the difference of sizes between the whole contol // and its child part. I.e. arrow, separators, etc. GtkRequisition req; gtk_widget_get_preferred_size(childPart, NULL, &req); wxSize totalS = GTKGetPreferredSize(m_widget); wxSize tsize(xlen + totalS.x - req.width, totalS.y); // For a wxChoice, not for wxComboBox, add some margins if ( !GTK_IS_ENTRY(childPart) ) tsize.IncBy(5, 0); // Perhaps the user wants something different from CharHeight if ( ylen > 0 ) tsize.IncBy(0, ylen - GetCharHeight()); return tsize; }
bool wxCollapsiblePane::Create(wxWindow *parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxValidator& val, const wxString& name) { m_bIgnoreNextChange = false; if ( !PreCreation( parent, pos, size ) || !wxControl::CreateBase(parent, id, pos, size, style, val, name) ) { wxFAIL_MSG( wxT("wxCollapsiblePane creation failed") ); return false; } m_widget = gtk_expander_new_with_mnemonic(wxGTK_CONV(GTKConvertMnemonics(label))); g_object_ref(m_widget); // Connect to the "notify::expanded" signal instead of the more common // "activate" one in order to use the new state in our callback, which is // more convenient e.g. because calling GetBestSize() returns the suitable // size for the new state. g_signal_connect(m_widget, "notify::expanded", G_CALLBACK(gtk_collapsiblepane_expanded_callback), this); // this the real "pane" m_pPane = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxNO_BORDER, wxS("wxCollapsiblePanePane")); m_parent->DoAddChild( this ); PostCreation(size); // we should blend into our parent background const wxColour bg = parent->GetBackgroundColour(); SetBackgroundColour(bg); m_pPane->SetBackgroundColour(bg); // remember the size of this control when it's collapsed m_szCollapsed = GTKGetPreferredSize(m_widget); return true; }
wxSize wxControl::DoGetBestSize() const { // Do not return any arbitrary default value... wxASSERT_MSG( m_widget, wxT("DoGetBestSize called before creation") ); wxSize best; if (m_wxwindow) { // this is not a native control, size_request is likely to be (0,0) best = wxControlBase::DoGetBestSize(); } else { best = GTKGetPreferredSize(m_widget); } return best; }