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

Contents of /trunk/common/include/Utilities/pxRadioPanel.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: 4969 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 <wx/wx.h>
19 #include "SafeArray.h"
20 #include "wxGuiTools.h"
21
22 // --------------------------------------------------------------------------------------
23 // RadioPanelItem
24 // --------------------------------------------------------------------------------------
25
26 struct RadioPanelItem
27 {
28 wxString Label;
29 wxString SubText;
30 wxString ToolTip;
31
32 int SomeInt;
33 void* SomePtr;
34
35 RadioPanelItem( const wxString& label, const wxString& subtext=wxEmptyString, const wxString& tooltip=wxEmptyString )
36 : Label( label )
37 , SubText( subtext )
38 , ToolTip( tooltip )
39 {
40 SomeInt = 0;
41 SomePtr = NULL;
42 }
43
44 RadioPanelItem& SetToolTip( const wxString& tip )
45 {
46 ToolTip = tip;
47 return *this;
48 }
49
50 RadioPanelItem& SetSubText( const wxString& text )
51 {
52 SubText = text;
53 return *this;
54 }
55
56 RadioPanelItem& SetInt( int intval )
57 {
58 SomeInt = intval;
59 return *this;
60 }
61
62 RadioPanelItem& SetPtr( void* ptrval )
63 {
64 SomePtr = ptrval;
65 return *this;
66 }
67 };
68
69
70 // Used as a cache for the "original" labels and subtexts, so that text can be properly
71 // wrapped and re-wrapped with multiple calls to OnResize().
72 struct RadioPanelObjects
73 {
74 wxRadioButton* LabelObj;
75 pxStaticText* SubTextObj;
76 };
77
78 // --------------------------------------------------------------------------------------
79 // pxRadioPanel
80 // --------------------------------------------------------------------------------------
81 //
82 // Rationale:
83 // Radio buttons work best when they are created consecutively, and then their subtext
84 // created in a second sweep (this keeps the radio buttons together in the parent window's
85 // child list, and avoids potentially unwanted behavior with radio buttons failing to
86 // group expectedly). Because of this, our radio button helper is shaped as a panel of
87 // a group of radio buttons only, instead of bothering with the lower level per-button
88 // design. This makes a few other things nicer as well, such as binding a single message
89 // handler to all radio buttons in the panel.
90 //
91 class pxRadioPanel : public wxPanelWithHelpers
92 {
93 protected:
94 typedef std::vector<RadioPanelItem> ButtonArray;
95 typedef SafeArray<RadioPanelObjects> ButtonObjArray;
96
97 ButtonArray m_buttonStrings;
98 ButtonObjArray m_objects;
99
100 bool m_IsRealized;
101
102 wxSize m_padding;
103 int m_Indentation;
104 int m_DefaultIdx; // index of the default option (gets specific color/font treatment)
105
106 public:
107 template< int size >
108 pxRadioPanel( wxWindow* parent, const RadioPanelItem (&src)[size] )
109 : wxPanelWithHelpers( parent, wxVERTICAL )
110 {
111 Init( src, size );
112 }
113
114 pxRadioPanel( wxWindow* parent )
115 : wxPanelWithHelpers( parent, wxVERTICAL )
116 {
117 Init();
118 }
119
120 virtual ~pxRadioPanel() throw() {}
121
122 void Reset();
123 void Realize();
124
125 pxStaticText* GetSubText( int idx );
126 const pxStaticText* GetSubText( int idx ) const;
127 pxRadioPanel& Append( const RadioPanelItem& entry );
128
129 pxRadioPanel& SetToolTip( int idx, const wxString& tip );
130 pxRadioPanel& SetSelection( int idx );
131 pxRadioPanel& SetDefaultItem( int idx );
132 pxRadioPanel& EnableItem( int idx, bool enable=true );
133
134 const RadioPanelItem& Item(int idx) const;
135 RadioPanelItem& Item(int idx);
136
137 int GetSelection() const;
138 wxWindowID GetSelectionId() const;
139 bool IsSelected( int idx ) const;
140
141 const RadioPanelItem& SelectedItem() const { return Item(GetSelection()); }
142 RadioPanelItem& SelectedItem() { return Item(GetSelection()); }
143
144 wxRadioButton* GetButton( int idx );
145 const wxRadioButton* GetButton( int idx ) const;
146
147 int GetPaddingVert() const { return m_padding.GetHeight(); }
148 int GetIndentation() const { return m_Indentation; }
149
150 pxRadioPanel& SetPaddingHoriz( int newpad )
151 {
152 m_padding.SetHeight( newpad );
153 return *this;
154 }
155
156 pxRadioPanel& SetIndentation( int newdent )
157 {
158 m_Indentation = newdent;
159 return *this;
160 }
161
162 bool HasSubText( int idx ) const
163 {
164 return !m_buttonStrings[idx].SubText.IsEmpty();
165 }
166
167 pxRadioPanel& Append( const wxString& label, const wxString& subtext=wxEmptyString, const wxString& tooltip=wxEmptyString )
168 {
169 return Append( RadioPanelItem(label, subtext, tooltip) );
170 }
171
172 protected:
173 void Init( const RadioPanelItem* srcArray=NULL, int arrsize=0 );
174 void _setToolTipImmediate( int idx, const wxString &tip );
175 void _RealizeDefaultOption();
176 };

  ViewVC Help
Powered by ViewVC 1.1.22