]> git.saurik.com Git - wxWidgets.git/blame - src/common/dlgcmn.cpp
Added chapter on collection and container classes to contents
[wxWidgets.git] / src / common / dlgcmn.cpp
CommitLineData
e37feda2
VZ
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
e37feda2 20#ifdef __GNUG__
1b68e0b5 21 #pragma implementation "dialogbase.h"
e37feda2
VZ
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
f6bcfd97 32 #include "wx/button.h"
e37feda2
VZ
33 #include "wx/dialog.h"
34 #include "wx/dcclient.h"
9f3a38fc 35 #include "wx/intl.h"
e37feda2 36 #include "wx/settings.h"
9f3a38fc 37 #include "wx/stattext.h"
92afa2b1 38 #include "wx/sizer.h"
f6bcfd97 39 #include "wx/button.h"
e37feda2
VZ
40#endif
41
92afa2b1
RR
42//--------------------------------------------------------------------------
43// wxDialogBase
44//--------------------------------------------------------------------------
e37feda2 45
92afa2b1 46wxSizer *wxDialogBase::CreateTextSizer( const wxString &message )
e37feda2 47{
92afa2b1 48 wxBoxSizer *box = new wxBoxSizer( wxVERTICAL );
b730516c 49
8a5137d7
RR
50 // get line height for empty lines
51 int y = 0;
f1df0927
VZ
52 wxFont font( GetFont() );
53 if (!font.Ok())
54 font = *wxSWISS_FONT;
55 GetTextExtent(_T("H"), (int*)NULL, &y, (int*)NULL, (int*)NULL, &font);
b730516c 56
92afa2b1
RR
57 wxString line;
58 for (size_t pos = 0; pos < message.Len(); pos++)
e37feda2 59 {
223d09f6 60 if (message[pos] == wxT('\n'))
e37feda2 61 {
92afa2b1 62 if (!line.IsEmpty())
e37feda2 63 {
92afa2b1 64 wxStaticText *s1 = new wxStaticText( this, -1, line );
f1df0927 65 box->Add( s1 );
223d09f6 66 line = wxT("");
e37feda2 67 }
f1df0927
VZ
68 else
69 {
70 box->Add( 5, y );
71 }
e37feda2
VZ
72 }
73 else
74 {
92afa2b1 75 line += message[pos];
e37feda2
VZ
76 }
77 }
b730516c 78
92afa2b1
RR
79 // remaining text behind last '\n'
80 if (!line.IsEmpty())
e37feda2 81 {
92afa2b1 82 wxStaticText *s2 = new wxStaticText( this, -1, line );
f1df0927 83 box->Add( s2 );
e37feda2 84 }
b730516c 85
92afa2b1 86 return box;
e37feda2 87}
b730516c 88
92afa2b1 89wxSizer *wxDialogBase::CreateButtonSizer( long flags )
e37feda2 90{
92afa2b1 91 wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL );
e37feda2 92
92afa2b1 93#if defined(__WXMSW__) || defined(__WXMAC__)
f1df0927 94 static const int margin = 6;
92afa2b1 95#else
f1df0927 96 static const int margin = 10;
92afa2b1 97#endif
e37feda2 98
92afa2b1
RR
99 wxButton *ok = (wxButton *) NULL;
100 wxButton *cancel = (wxButton *) NULL;
101 wxButton *yes = (wxButton *) NULL;
102 wxButton *no = (wxButton *) NULL;
9c884972
RR
103
104 // always show an OK button, unless only YES_NO is given
105 if ((flags & wxYES_NO) == 0) flags = flags | wxOK;
b730516c
RD
106
107 if (flags & wxYES_NO)
e37feda2 108 {
92afa2b1
RR
109 yes = new wxButton( this, wxID_YES, _("Yes") );
110 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
111 no = new wxButton( this, wxID_NO, _("No") );
112 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
b730516c
RD
113 } else
114 if (flags & wxYES)
92afa2b1
RR
115 {
116 yes = new wxButton( this, wxID_YES, _("Yes") );
117 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
b730516c
RD
118 } else
119 if (flags & wxNO)
92afa2b1
RR
120 {
121 no = new wxButton( this, wxID_NO, _("No") );
122 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
e37feda2 123 }
92afa2b1 124
b730516c 125 if (flags & wxOK)
e37feda2 126 {
92afa2b1
RR
127 ok = new wxButton( this, wxID_OK, _("OK") );
128 box->Add( ok, 0, wxLEFT|wxRIGHT, margin );
e37feda2
VZ
129 }
130
b730516c
RD
131 if (flags & wxFORWARD)
132 box->Add( new wxButton( this, wxID_FORWARD, _("Forward") ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 133
b730516c 134 if (flags & wxBACKWARD)
92afa2b1 135 box->Add( new wxButton( this, wxID_BACKWARD, _("Backward") ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 136
b730516c 137 if (flags & wxSETUP)
92afa2b1 138 box->Add( new wxButton( this, wxID_SETUP, _("Setup") ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 139
b730516c 140 if (flags & wxMORE)
92afa2b1 141 box->Add( new wxButton( this, wxID_MORE, _("More...") ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 142
92afa2b1
RR
143 if (flags & wxHELP)
144 box->Add( new wxButton( this, wxID_HELP, _("Help") ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 145
b730516c 146 if (flags & wxCANCEL)
e37feda2 147 {
92afa2b1
RR
148 cancel = new wxButton( this, wxID_CANCEL, _("Cancel") );
149 box->Add( cancel, 0, wxLEFT|wxRIGHT, margin );
e37feda2
VZ
150 }
151
b730516c
RD
152 if (flags & wxNO_DEFAULT)
153 {
154 if (no)
155 {
156 no->SetDefault();
157 no->SetFocus();
158 }
159 }
160 else
92afa2b1
RR
161 {
162 if (ok)
163 {
164 ok->SetDefault();
165 ok->SetFocus();
166 }
167 else if (yes)
168 {
169 yes->SetDefault();
170 yes->SetFocus();
171 }
172 }
b730516c 173
92afa2b1 174 return box;
e37feda2
VZ
175}
176