| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: gtk/statbox.cpp |
| 3 | // Purpose: |
| 4 | // Author: Robert Roebling |
| 5 | // Id: $Id$ |
| 6 | // Copyright: (c) 1998 Robert Roebling |
| 7 | // Licence: wxWindows licence |
| 8 | ///////////////////////////////////////////////////////////////////////////// |
| 9 | |
| 10 | // For compilers that support precompilation, includes "wx.h". |
| 11 | #include "wx/wxprec.h" |
| 12 | |
| 13 | #if wxUSE_STATBOX |
| 14 | |
| 15 | #include "wx/statbox.h" |
| 16 | #include "wx/gtk1/private.h" |
| 17 | |
| 18 | #include "gdk/gdk.h" |
| 19 | #include "gtk/gtk.h" |
| 20 | |
| 21 | //----------------------------------------------------------------------------- |
| 22 | // wxStaticBox |
| 23 | //----------------------------------------------------------------------------- |
| 24 | |
| 25 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl) |
| 26 | |
| 27 | wxStaticBox::wxStaticBox() |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | wxStaticBox::wxStaticBox( wxWindow *parent, |
| 32 | wxWindowID id, |
| 33 | const wxString &label, |
| 34 | const wxPoint& pos, |
| 35 | const wxSize& size, |
| 36 | long style, |
| 37 | const wxString& name ) |
| 38 | { |
| 39 | Create( parent, id, label, pos, size, style, name ); |
| 40 | } |
| 41 | |
| 42 | bool wxStaticBox::Create( wxWindow *parent, |
| 43 | wxWindowID id, |
| 44 | const wxString& label, |
| 45 | const wxPoint& pos, |
| 46 | const wxSize& size, |
| 47 | long style, |
| 48 | const wxString& name ) |
| 49 | { |
| 50 | m_needParent = TRUE; |
| 51 | |
| 52 | if (!PreCreation( parent, pos, size ) || |
| 53 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) |
| 54 | { |
| 55 | wxFAIL_MSG( wxT("wxStaticBox creation failed") ); |
| 56 | return FALSE; |
| 57 | } |
| 58 | |
| 59 | m_widget = gtk_frame_new(NULL); |
| 60 | SetLabel(label); |
| 61 | |
| 62 | m_parent->DoAddChild( this ); |
| 63 | |
| 64 | PostCreation(size); |
| 65 | |
| 66 | // need to set non default alignment? |
| 67 | gfloat xalign; |
| 68 | if ( style & wxALIGN_CENTER ) |
| 69 | xalign = 0.5; |
| 70 | else if ( style & wxALIGN_RIGHT ) |
| 71 | xalign = 1.0; |
| 72 | else // wxALIGN_LEFT |
| 73 | xalign = 0.0; |
| 74 | |
| 75 | if ( style & (wxALIGN_RIGHT | wxALIGN_CENTER) ) // left alignment is default |
| 76 | gtk_frame_set_label_align(GTK_FRAME( m_widget ), xalign, 0.5); |
| 77 | |
| 78 | return TRUE; |
| 79 | } |
| 80 | |
| 81 | void wxStaticBox::SetLabel( const wxString& label ) |
| 82 | { |
| 83 | wxCHECK_RET( m_widget != NULL, wxT("invalid staticbox") ); |
| 84 | |
| 85 | GTKSetLabelForFrame(GTK_FRAME(m_widget), label); |
| 86 | } |
| 87 | |
| 88 | void wxStaticBox::DoApplyWidgetStyle(GtkRcStyle *style) |
| 89 | { |
| 90 | gtk_widget_modify_style(m_widget, style); |
| 91 | } |
| 92 | |
| 93 | // static |
| 94 | wxVisualAttributes |
| 95 | wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) |
| 96 | { |
| 97 | return GetDefaultAttributesFromGTKWidget(gtk_frame_new); |
| 98 | } |
| 99 | |
| 100 | #endif // wxUSE_STATBOX |