]> git.saurik.com Git - wxWidgets.git/blob - src/common/dlgcmn.cpp
Corrected wxImage for use with mono wxBitmaps,
[wxWidgets.git] / src / common / dlgcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/dlgcmn.cpp
3 // Purpose: common (to all ports) wxDialog functions
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 28.06.99
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "dialogbase.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/dialog.h"
33 #include "wx/dcclient.h"
34 #include "wx/intl.h"
35 #include "wx/settings.h"
36 #include "wx/stattext.h"
37 #include "wx/sizer.h"
38 #endif
39
40 //--------------------------------------------------------------------------
41 // wxDialogBase
42 //--------------------------------------------------------------------------
43
44 wxSizer *wxDialogBase::CreateTextSizer( const wxString &message )
45 {
46 wxBoxSizer *box = new wxBoxSizer( wxVERTICAL );
47
48 // get line height for empty lines
49 int y = 0;
50 wxFont new_font( GetFont() );
51 if (!new_font.Ok()) new_font = *wxSWISS_FONT;
52 GetTextExtent( "H", (int*)NULL, &y, (int*)NULL, (int*)NULL, &new_font );
53
54 wxString line;
55 for (size_t pos = 0; pos < message.Len(); pos++)
56 {
57 if (message[pos] == wxT('\n'))
58 {
59 if (!line.IsEmpty())
60 {
61 wxStaticText *s1 = new wxStaticText( this, -1, line );
62 box->Add( s1 );
63 line = wxT("");
64 }
65 else
66 {
67 box->Add( 5, y );
68 }
69 }
70 else
71 {
72 line += message[pos];
73 }
74 }
75
76 // remaining text behind last '\n'
77 if (!line.IsEmpty())
78 {
79 wxStaticText *s2 = new wxStaticText( this, -1, line );
80 box->Add( s2 );
81 }
82
83 return box;
84 }
85
86 wxSizer *wxDialogBase::CreateButtonSizer( long flags )
87 {
88 wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL );
89
90 #if defined(__WXMSW__) || defined(__WXMAC__)
91 int margin = 6;
92 #else
93 int margin = 10;
94 #endif
95
96 wxButton *ok = (wxButton *) NULL;
97 wxButton *cancel = (wxButton *) NULL;
98 wxButton *yes = (wxButton *) NULL;
99 wxButton *no = (wxButton *) NULL;
100
101 // always show an OK button, unless only YES_NO is given
102 if ((flags & wxYES_NO) == 0) flags = flags | wxOK;
103
104 if (flags & wxYES_NO)
105 {
106 yes = new wxButton( this, wxID_YES, _("Yes") );
107 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
108 no = new wxButton( this, wxID_NO, _("No") );
109 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
110 } else
111 if (flags & wxYES)
112 {
113 yes = new wxButton( this, wxID_YES, _("Yes") );
114 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
115 } else
116 if (flags & wxNO)
117 {
118 no = new wxButton( this, wxID_NO, _("No") );
119 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
120 }
121
122 if (flags & wxOK)
123 {
124 ok = new wxButton( this, wxID_OK, _("OK") );
125 box->Add( ok, 0, wxLEFT|wxRIGHT, margin );
126 }
127
128 if (flags & wxFORWARD)
129 box->Add( new wxButton( this, wxID_FORWARD, _("Forward") ), 0, wxLEFT|wxRIGHT, margin );
130
131 if (flags & wxBACKWARD)
132 box->Add( new wxButton( this, wxID_BACKWARD, _("Backward") ), 0, wxLEFT|wxRIGHT, margin );
133
134 if (flags & wxSETUP)
135 box->Add( new wxButton( this, wxID_SETUP, _("Setup") ), 0, wxLEFT|wxRIGHT, margin );
136
137 if (flags & wxMORE)
138 box->Add( new wxButton( this, wxID_MORE, _("More...") ), 0, wxLEFT|wxRIGHT, margin );
139
140 if (flags & wxHELP)
141 box->Add( new wxButton( this, wxID_HELP, _("Help") ), 0, wxLEFT|wxRIGHT, margin );
142
143 if (flags & wxCANCEL)
144 {
145 cancel = new wxButton( this, wxID_CANCEL, _("Cancel") );
146 box->Add( cancel, 0, wxLEFT|wxRIGHT, margin );
147 }
148
149 if (flags & wxNO_DEFAULT)
150 {
151 if (no)
152 {
153 no->SetDefault();
154 no->SetFocus();
155 }
156 }
157 else
158 {
159 if (ok)
160 {
161 ok->SetDefault();
162 ok->SetFocus();
163 }
164 else if (yes)
165 {
166 yes->SetDefault();
167 yes->SetFocus();
168 }
169 }
170
171 return box;
172 }
173