/[pcsx2_0.9.7]/trunk/common/include/Utilities/pxStaticText.h
ViewVC logotype

Diff of /trunk/common/include/Utilities/pxStaticText.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 61 by william, Tue Sep 7 03:24:11 2010 UTC revision 62 by william, Tue Sep 7 11:08:22 2010 UTC
# Line 15  Line 15 
15    
16  #pragma once  #pragma once
17    
 #include <wx/wx.h>  
18  #include "wxGuiTools.h"  #include "wxGuiTools.h"
19    
20  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
21  //  pxStaticText  //  pxStaticText
22  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
 // Important:  
 //   Proper use of this class requires using it's custom AddTo( wxSizer& ) method, in the  
 //   place of wxSizer.Add().  You can also use the += operator (recommended):  
 //  
 //     mySizer += new pxStaticText( this, _("omg translate me?") );  
 //  
23  // This class's purpose is to overcome two fundamental annoyances in wxWidgets design:  // This class's purpose is to overcome two fundamental annoyances in wxWidgets design:
24  //  //
25  //   * An inability to wrap text to conform to a fitted window (a limitation imposed by  //   * An inability to wrap text to conform to a fitted window (a limitation imposed by
26  //     wxWidgets inability to fit individual directions, ie fit widths and then fit heights,  //     wxWidgets inability to fit individual directions, ie fit widths and then fit heights,
27  //     which would allow a textbox to wrap text to a sizer-determined width, and then grow  //     which would allow a textbox to wrap text to a sizer-determined width, and then grow
28  //     the sizers vertically to fit the calcuated text-wrapped height).  //     the sizers vertically to fit the calculated text-wrapped height).
29  //  //
30  //   * Textbox alignment requires aligning both the textbox contents, and aligning the text  //   * Textbox alignment requires aligning both the textbox contents, and aligning the text
31  //     control within it's containing sizer.  If both alignment flags do not match the result  //     control within it's containing sizer.  If both alignment flags do not match the result
32  //     is typically undesirable.  //     is typically undesirable.
33  //  //
34  // The first one is very hard to fix properly.  Currently this class employs a hack where it  class pxStaticText : public wxControl
 // grabs the "ideal" fitting width from it's containing panel/window, and then wraps text to  
 // fit within those confines.  Under this design, pxStaticText controls will typically be the  
 // "regulators" of the window's display size, since they cannot really participate in the  
 // normal sizer system (since their minimum height is unknown until width-based sizes are  
 // determined).  
 //  
 // Note that if another control in the window has extends that blow the window size larger  
 // than the "ideal" width, then the pxStaticText will remain consistent in it's size.  It  
 // will not attempt to grow to fit the expanded area.  That might be fixable behavior, but  
 // it was hard enough for me to get this much working. ;)  
 //  
 class pxStaticText : public wxStaticText  
35  {  {
36          typedef wxStaticText _parent;          typedef wxControl _parent;
37    
38  protected:  protected:
39          wxString                m_message;          wxString                m_label;
40          int                             m_wrapwidth;          wxString                m_wrappedLabel;
41          int                             m_alignflags;          
42          bool                    m_unsetLabel;          wxAlignment             m_align;
43          double                  m_centerPadding;          bool                    m_autowrap;
44            int                             m_wrappedWidth;
45            int                             m_heightInLines;
46    
47            int                             m_paddingPix_horiz;
48            int                             m_paddingPix_vert;
49            float                   m_paddingPct_horiz;
50            float                   m_paddingPct_vert;
51    
52  public:  protected:
53          explicit pxStaticText( wxWindow* parent, const wxString& label=wxEmptyString, int style=wxALIGN_LEFT );          explicit pxStaticText( wxWindow* parent=NULL );
         explicit pxStaticText( wxWindow* parent, int style );  
54    
55            // wxWindow overloads!
56            bool AcceptsFocus() const { return false; }
57            bool HasTransparentBackground() { return true; }
58            void DoSetSize(int x, int y, int w, int h, int sizeFlags = wxSIZE_AUTO);
59            
60    public:
61            pxStaticText( wxWindow* parent, const wxString& label, wxAlignment align=wxALIGN_CENTRE_HORIZONTAL );
62            pxStaticText( wxWindow* parent, int heightInLines, const wxString& label, wxAlignment align=wxALIGN_CENTRE_HORIZONTAL );
63          virtual ~pxStaticText() throw() {}          virtual ~pxStaticText() throw() {}
64    
65          void SetLabel( const wxString& label );          wxFont GetFontOk() const;
66          pxStaticText& SetWrapWidth( int newwidth );          bool Enable( bool enabled=true );
67          pxStaticText& SetToolTip( const wxString& tip );  
68            virtual void SetLabel(const wxString& label);
69            virtual wxString GetLabel() const { return m_label; }
70    
71            pxStaticText& SetMinWidth( int width );
72            pxStaticText& SetMinHeight( int height );
73    
74          wxSize GetMinSize() const;          pxStaticText& SetHeight( int lines );
75          //void DoMoveWindow(int x, int y, int width, int height);          pxStaticText& Align( wxAlignment align );
76            pxStaticText& Bold();
77            pxStaticText& WrapAt( int width );
78    
79          void AddTo( wxSizer& sizer, wxSizerFlags flags=pxSizerFlags::StdSpace() );          pxStaticText& Unwrapped();
         void AddTo( wxSizer* sizer, const wxSizerFlags& flags=pxSizerFlags::StdSpace() ) { AddTo( *sizer, flags ); }  
80    
81          void InsertAt( wxSizer& sizer, int position, wxSizerFlags flags=pxSizerFlags::StdSpace() );          pxStaticText& PaddingPixH( int pixels );
82          int GetIdealWidth() const;          pxStaticText& PaddingPixV( int pixels );
83    
84            pxStaticText& PaddingPctH( float pct );
85            pxStaticText& PaddingPctV( float pct );
86            //pxStaticText& DoBestGuessHeight();
87    
88  protected:  protected:
89          void _setLabel();          void SetPaddingDefaults();
90            void Init( const wxString& label );
91    
92            wxSize GetBestWrappedSize( const wxClientDC& dc ) const;
93            wxSize DoGetBestSize() const;
94    
95            int calcPaddingWidth( int newWidth ) const;
96            int calcPaddingHeight( int newHeight ) const;
97    
98            void paintEvent(wxPaintEvent& evt);
99    
100            void UpdateWrapping( bool textChanged );
101            bool _updateWrapping( bool textChanged );
102    };
103    
104    
105    class pxStaticHeading : public pxStaticText
106    {
107            typedef pxStaticText _parent;
108    
109    public:
110            pxStaticHeading( wxWindow* parent=NULL, const wxString& label=wxEmptyString );
111            pxStaticHeading( wxWindow* parent, int heightInLines, const wxString& label=wxEmptyString );
112            virtual ~pxStaticHeading() throw() {}
113    
114    protected:
115            void SetPaddingDefaults();
116  };  };
117    
118  extern void operator+=( wxSizer& target, pxStaticText* src );  extern void operator+=( wxSizer& target, pxStaticText* src );
# Line 91  extern void operator+=( wxSizer* target, Line 122  extern void operator+=( wxSizer* target,
122  template<>  template<>
123  inline void operator+=( wxSizer& target, const pxWindowAndFlags<pxStaticText>& src )  inline void operator+=( wxSizer& target, const pxWindowAndFlags<pxStaticText>& src )
124  {  {
125          src.window->AddTo( target, src.flags );          target.Add( src.window, src.flags );
         //target.Add( src.window, src.flags );  
126  }  }
127    
128  template<>  template<>
129  inline void operator+=( wxSizer* target, const pxWindowAndFlags<pxStaticText>& src )  inline void operator+=( wxSizer* target, const pxWindowAndFlags<pxStaticText>& src )
130  {  {
131          src.window->AddTo( target, src.flags );          target->Add( src.window, src.flags );
         //target.Add( src.window, src.flags );  
132  }  }
   
 // --------------------------------------------------------------------------------------  
 //  pxStaticHeading  
 // --------------------------------------------------------------------------------------  
 // Basically like a pxStaticText, except it defaults to wxALIGN_CENTRE, and it has expanded  
 // left and right side padding.  
 //  
 // The padding is not an exact science and, if there isn't any other controls in the form  
 // that are equal to or exceeding the IdealWidth, the control will end up fitting tightly  
 // to the heading (padding will be nullified).  
 //  
 class pxStaticHeading : public pxStaticText  
 {  
 public:  
         pxStaticHeading( wxWindow* parent, const wxString& label=wxEmptyString, int style=wxALIGN_CENTRE );  
         virtual ~pxStaticHeading() throw() {}  
   
         //using pxStaticText::operator wxSizerFlags;  
 };  

Legend:
Removed from v.61  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.22