/[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 62 - (show annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (9 years, 4 months ago) by william
File MIME type: text/plain
File size: 4301 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./trunk
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 "wxGuiTools.h"
19
20 // --------------------------------------------------------------------------------------
21 // pxStaticText
22 // --------------------------------------------------------------------------------------
23 // 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
26 // 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
28 // the sizers vertically to fit the calculated text-wrapped height).
29 //
30 // * 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
32 // is typically undesirable.
33 //
34 class pxStaticText : public wxControl
35 {
36 typedef wxControl _parent;
37
38 protected:
39 wxString m_label;
40 wxString m_wrappedLabel;
41
42 wxAlignment m_align;
43 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 protected:
53 explicit pxStaticText( wxWindow* parent=NULL );
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() {}
64
65 wxFont GetFontOk() const;
66 bool Enable( bool enabled=true );
67
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 pxStaticText& SetHeight( int lines );
75 pxStaticText& Align( wxAlignment align );
76 pxStaticText& Bold();
77 pxStaticText& WrapAt( int width );
78
79 pxStaticText& Unwrapped();
80
81 pxStaticText& PaddingPixH( int pixels );
82 pxStaticText& PaddingPixV( int pixels );
83
84 pxStaticText& PaddingPctH( float pct );
85 pxStaticText& PaddingPctV( float pct );
86 //pxStaticText& DoBestGuessHeight();
87
88 protected:
89 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 );
119 extern void operator+=( wxSizer& target, pxStaticText& src );
120 extern void operator+=( wxSizer* target, pxStaticText& src );
121
122 template<>
123 inline void operator+=( wxSizer& target, const pxWindowAndFlags<pxStaticText>& src )
124 {
125 target.Add( src.window, src.flags );
126 }
127
128 template<>
129 inline void operator+=( wxSizer* target, const pxWindowAndFlags<pxStaticText>& src )
130 {
131 target->Add( src.window, src.flags );
132 }

  ViewVC Help
Powered by ViewVC 1.1.22