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