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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 5029 byte(s)
committing r3113 initial commit again...
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #pragma once
17
18 #include <wx/wx.h>
19 #include "wxGuiTools.h"
20
21 // --------------------------------------------------------------------------------------
22 // pxStaticText
23 // --------------------------------------------------------------------------------------
24 // Important:
25 // Proper use of this class requires using it's custom AddTo( wxSizer& ) method, in the
26 // place of wxSizer.Add(). You can also use the += operator (recommended):
27 //
28 // mySizer += new pxStaticText( this, _("omg translate me?") );
29 //
30 // This class's purpose is to overcome two fundamental annoyances in wxWidgets design:
31 //
32 // * An inability to wrap text to conform to a fitted window (a limitation imposed by
33 // wxWidgets inability to fit individual directions, ie fit widths and then fit heights,
34 // which would allow a textbox to wrap text to a sizer-determined width, and then grow
35 // the sizers vertically to fit the calcuated text-wrapped height).
36 //
37 // * Textbox alignment requires aligning both the textbox contents, and aligning the text
38 // control within it's containing sizer. If both alignment flags do not match the result
39 // is typically undesirable.
40 //
41 // The first one is very hard to fix properly. Currently this class employs a hack where it
42 // grabs the "ideal" fitting width from it's containing panel/window, and then wraps text to
43 // fit within those confines. Under this design, pxStaticText controls will typically be the
44 // "regulators" of the window's display size, since they cannot really participate in the
45 // normal sizer system (since their minimum height is unknown until width-based sizes are
46 // determined).
47 //
48 // Note that if another control in the window has extends that blow the window size larger
49 // than the "ideal" width, then the pxStaticText will remain consistent in it's size. It
50 // will not attempt to grow to fit the expanded area. That might be fixable behavior, but
51 // it was hard enough for me to get this much working. ;)
52 //
53 class pxStaticText : public wxStaticText
54 {
55 typedef wxStaticText _parent;
56
57 protected:
58 wxString m_message;
59 int m_wrapwidth;
60 int m_alignflags;
61 bool m_unsetLabel;
62 double m_centerPadding;
63
64 public:
65 explicit pxStaticText( wxWindow* parent, const wxString& label=wxEmptyString, int style=wxALIGN_LEFT );
66 explicit pxStaticText( wxWindow* parent, int style );
67
68 virtual ~pxStaticText() throw() {}
69
70 void SetLabel( const wxString& label );
71 pxStaticText& SetWrapWidth( int newwidth );
72 pxStaticText& SetToolTip( const wxString& tip );
73
74 wxSize GetMinSize() const;
75 //void DoMoveWindow(int x, int y, int width, int height);
76
77 void AddTo( wxSizer& sizer, wxSizerFlags flags=pxSizerFlags::StdSpace() );
78 void AddTo( wxSizer* sizer, const wxSizerFlags& flags=pxSizerFlags::StdSpace() ) { AddTo( *sizer, flags ); }
79
80 void InsertAt( wxSizer& sizer, int position, wxSizerFlags flags=pxSizerFlags::StdSpace() );
81 int GetIdealWidth() const;
82
83 protected:
84 void _setLabel();
85 };
86
87 extern void operator+=( wxSizer& target, pxStaticText* src );
88 extern void operator+=( wxSizer& target, pxStaticText& src );
89 extern void operator+=( wxSizer* target, pxStaticText& src );
90
91 template<>
92 inline void operator+=( wxSizer& target, const pxWindowAndFlags<pxStaticText>& src )
93 {
94 src.window->AddTo( target, src.flags );
95 //target.Add( src.window, src.flags );
96 }
97
98 template<>
99 inline void operator+=( wxSizer* target, const pxWindowAndFlags<pxStaticText>& src )
100 {
101 src.window->AddTo( target, src.flags );
102 //target.Add( src.window, src.flags );
103 }
104
105 // --------------------------------------------------------------------------------------
106 // pxStaticHeading
107 // --------------------------------------------------------------------------------------
108 // Basically like a pxStaticText, except it defaults to wxALIGN_CENTRE, and it has expanded
109 // left and right side padding.
110 //
111 // The padding is not an exact science and, if there isn't any other controls in the form
112 // that are equal to or exceeding the IdealWidth, the control will end up fitting tightly
113 // to the heading (padding will be nullified).
114 //
115 class pxStaticHeading : public pxStaticText
116 {
117 public:
118 pxStaticHeading( wxWindow* parent, const wxString& label=wxEmptyString, int style=wxALIGN_CENTRE );
119 virtual ~pxStaticHeading() throw() {}
120
121 //using pxStaticText::operator wxSizerFlags;
122 };

  ViewVC Help
Powered by ViewVC 1.1.22