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