]> git.saurik.com Git - wxWidgets.git/commitdiff
1. corrected client data deletion in wxListBox (no more memory leaks in controls
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 24 Oct 1999 16:29:08 +0000 (16:29 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 24 Oct 1999 16:29:08 +0000 (16:29 +0000)
   sample)
2. added wxST_NO_AUTORESIZE style for wxGTK and wxMSW and added test for it to
   the controls sample

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4161 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/defs.h
samples/controls/controls.cpp
src/gtk/stattext.cpp
src/gtk1/stattext.cpp
src/msw/listbox.cpp
src/msw/stattext.cpp

index 5154c388ab4d59979b3a53c81467931dbc8bb2b8..bf12c02ae0e58abbedc736836dd0f1e8f87961a9 100644 (file)
@@ -1024,6 +1024,11 @@ enum wxStretch
  */
 #define wxST_SIZEGRIP         0x0010
 
+/*
+ * wxStaticText flags
+ */
+#define wxST_NO_AUTORESIZE    0x0001
+
 /*
  * wxStaticLine flags
  */
index c08dff38078fb96f7abf8f4ee68dfbfc5c6214d4..2336b8c823bec8a441538b6858e64ebef7bd518b 100644 (file)
@@ -96,6 +96,7 @@ public:
     void OnPageChanged( wxNotebookEvent &event );
     void OnPageChanging( wxNotebookEvent &event );
     void OnSliderUpdate( wxCommandEvent &event );
+    void OnUpdateLabel( wxCommandEvent &event );
 #if wxUSE_SPINBUTTON
     void OnSpinUp( wxSpinEvent &event );
     void OnSpinDown( wxSpinEvent &event );
@@ -130,6 +131,8 @@ public:
     wxTextCtrl    *m_text;
     wxNotebook    *m_notebook;
 
+    wxStaticText  *m_label;
+
 private:
     DECLARE_EVENT_TABLE()
 };
@@ -200,7 +203,7 @@ bool MyApp::OnInit()
     wxMenu *tooltip_menu = new wxMenu;
     tooltip_menu->Append(MINIMAL_SET_TOOLTIP_DELAY, "Set &delay\tCtrl-D");
     tooltip_menu->AppendSeparator();
-    tooltip_menu->Append(MINIMAL_ENABLE_TOOLTIPS, "&Toggle tooltips\tCrtl-T",
+    tooltip_menu->Append(MINIMAL_ENABLE_TOOLTIPS, "&Toggle tooltips\tCtrl-T",
             "enable/disable tooltips", TRUE);
     tooltip_menu->Check(MINIMAL_ENABLE_TOOLTIPS, TRUE);
     menu_bar->Append(tooltip_menu, "&Tooltips");
@@ -267,6 +270,7 @@ const int  ID_SLIDER            = 181;
 
 const int  ID_SPIN              = 182;
 const int  ID_BTNPROGRESS       = 183;
+const int  ID_BUTTON_LABEL      = 184;
 
 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
 EVT_SIZE      (                         MyPanel::OnSize)
@@ -313,6 +317,7 @@ EVT_SPIN_DOWN (ID_SPIN,                 MyPanel::OnSpinDown)
 EVT_UPDATE_UI (ID_BTNPROGRESS,          MyPanel::OnUpdateShowProgress)
 EVT_BUTTON    (ID_BTNPROGRESS,          MyPanel::OnShowProgress)
 #endif
+EVT_BUTTON    (ID_BUTTON_LABEL,         MyPanel::OnUpdateLabel)
 END_EVENT_TABLE()
 
 MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
@@ -539,16 +544,11 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
     dc.DrawText("Bitmap", 20, 20);
     dc.SelectObject( wxNullBitmap );
 
-    wxBitmapButton *bmpBtn = new wxBitmapButton
-                                 (
-                                  panel,
-                                  -1,
-                                  bitmap,
-                                  wxPoint(100, 20)
-                                 );
-    bmpBtn = NULL; // suppress warning
-
-    new wxButton(panel, -1, "Another button", wxPoint(250, 20));
+    (void)new wxBitmapButton(panel, -1, bitmap, wxPoint(100, 20));
+    (void)new wxButton(panel, ID_BUTTON_LABEL, "Toggle label", wxPoint(250, 20));
+    m_label = new wxStaticText(panel, -1, "Label with some long text",
+                               wxPoint(250, 60), wxDefaultSize,
+                               wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
 
     m_notebook->AddPage(panel, "wxBitmapXXX");
 
@@ -586,11 +586,11 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
   panel->SetAutoLayout( true );
 
   wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
-  
+
   sizer->Add( new wxButton(panel, -1, "Test Button" ), 3, wxALL, 10 );
   sizer->Add( 20,20, 1 );
   sizer->Add( new wxButton(panel, -1, "Test Button 2" ), 3, wxGROW|wxALL, 10 );
-  
+
   panel->SetSizer( sizer );
 
   m_notebook->AddPage(panel, "wxSizer");
@@ -892,6 +892,14 @@ void MyPanel::OnSetFont( wxCommandEvent &WXUNUSED(event) )
     m_text->SetFont( *wxITALIC_FONT );
 }
 
+void MyPanel::OnUpdateLabel( wxCommandEvent &WXUNUSED(event) )
+{
+    static bool s_long = TRUE;
+
+    s_long = !s_long;
+    m_label->SetLabel(s_long ? "very very very long text" : "shorter text");
+}
+
 void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
 {
     m_gauge->SetValue( m_slider->GetValue() );
index f2340eaa85ec243e989dd27c0b50cd6b6986fbed..2055e54fd51de5510f31cdb94a6fd18cd808c2d1 100644 (file)
@@ -52,7 +52,7 @@ bool wxStaticText::Create(wxWindow *parent,
         !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
     {
         wxFAIL_MSG( wxT("wxXX creation failed") );
-       return FALSE;
+        return FALSE;
     }
 
     // notice that we call the base class version which will just remove the
@@ -74,7 +74,7 @@ bool wxStaticText::Create(wxWindow *parent,
     // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
     static const float labelAlignments[] = { 0.0, 1.0, 0.5 };
     gtk_misc_set_alignment(GTK_MISC(m_widget), labelAlignments[justify], 0.0);
-    
+
     GtkRequisition req;
     (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
 
@@ -110,14 +110,15 @@ void wxStaticText::SetLabel( const wxString &label )
 
     gtk_label_set( GTK_LABEL(m_widget), m_label.mbc_str() );
 
-    // adjust the label size to the new label
-
-    // TODO there should be a way to prevent SetLabel() from doing it (an
-    //      additional parameter?)
-    GtkRequisition req;
-    (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
+    // adjust the label size to the new label unless disabled
+    if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
+    {
+        GtkRequisition req;
+        (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request )
+            (m_widget, &req );
 
-    SetSize( req.width, req.height );
+        SetSize( req.width, req.height );
+    }
 }
 
 void wxStaticText::ApplyWidgetStyle()
index f2340eaa85ec243e989dd27c0b50cd6b6986fbed..2055e54fd51de5510f31cdb94a6fd18cd808c2d1 100644 (file)
@@ -52,7 +52,7 @@ bool wxStaticText::Create(wxWindow *parent,
         !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
     {
         wxFAIL_MSG( wxT("wxXX creation failed") );
-       return FALSE;
+        return FALSE;
     }
 
     // notice that we call the base class version which will just remove the
@@ -74,7 +74,7 @@ bool wxStaticText::Create(wxWindow *parent,
     // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2
     static const float labelAlignments[] = { 0.0, 1.0, 0.5 };
     gtk_misc_set_alignment(GTK_MISC(m_widget), labelAlignments[justify], 0.0);
-    
+
     GtkRequisition req;
     (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
 
@@ -110,14 +110,15 @@ void wxStaticText::SetLabel( const wxString &label )
 
     gtk_label_set( GTK_LABEL(m_widget), m_label.mbc_str() );
 
-    // adjust the label size to the new label
-
-    // TODO there should be a way to prevent SetLabel() from doing it (an
-    //      additional parameter?)
-    GtkRequisition req;
-    (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
+    // adjust the label size to the new label unless disabled
+    if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
+    {
+        GtkRequisition req;
+        (* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request )
+            (m_widget, &req );
 
-    SetSize( req.width, req.height );
+        SetSize( req.width, req.height );
+    }
 }
 
 void wxStaticText::ApplyWidgetStyle()
index 985187379eef99e368c858b3e9346cce028dfdf1..5b2e30ab63554e9363e881e8ba195fb5e1286210 100644 (file)
@@ -359,13 +359,17 @@ void wxListBox::Clear()
 void wxListBox::Free()
 {
 #if wxUSE_OWNER_DRAWN
-    size_t uiCount = m_aItems.Count();
-    while ( uiCount-- != 0 ) {
-        delete m_aItems[uiCount];
-    }
+    if ( m_windowStyle & wxLB_OWNERDRAW )
+    {
+        size_t uiCount = m_aItems.Count();
+        while ( uiCount-- != 0 ) {
+            delete m_aItems[uiCount];
+        }
 
-    m_aItems.Clear();
-#else // !wxUSE_OWNER_DRAWN
+        m_aItems.Clear();
+    }
+    else
+#endif // wxUSE_OWNER_DRAWN
     if ( HasClientObjectData() )
     {
         for ( size_t n = 0; n < (size_t)m_noItems; n++ )
@@ -373,7 +377,6 @@ void wxListBox::Free()
             delete GetClientObject(n);
         }
     }
-#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
 }
 
 void wxListBox::SetSelection(int N, bool select)
index f1a947d26649f56338ba55d816bb321b796e8e18..b0b6fd21f84f6d8666497ce189072f38db5ce6b7 100644 (file)
@@ -129,10 +129,12 @@ void wxStaticText::SetLabel(const wxString& label)
 {
     SetWindowText(GetHwnd(), label);
 
-    // adjust the size of the window to fit to the label (this behaviour is
-    // backward compatible and generally makes sense but we might want to still
-    // provide the user a way to disable it) (VZ)
-    DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
+    // adjust the size of the window to fit to the label unless autoresizing is
+    // disabled
+    if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) )
+    {
+        DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
+    }
 }
 
 WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,