]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/textdlgg.cpp
Compile fixes for tree ctrl
[wxWidgets.git] / src / generic / textdlgg.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: textdlgg.cpp
3// Purpose: wxTextEntryDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "textdlgg.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include <stdio.h>
25#include "wx/utils.h"
26#include "wx/dialog.h"
27#include "wx/listbox.h"
28#include "wx/button.h"
29#include "wx/stattext.h"
30#include "wx/textctrl.h"
31#include "wx/layout.h"
32#include "wx/intl.h"
33#endif
34
35#include "wx/generic/textdlgg.h"
36
37// wxTextEntryDialog
38
39#if !USE_SHARED_LIBRARY
40BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
41 EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
42END_EVENT_TABLE()
43
44IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
45#endif
46
47// Split message, using constraints to position controls
48static void wxSplitMessage2(const char *message, wxList *messageList, wxWindow *parent, wxRowColSizer *sizer)
49{
50 char *copyMessage = copystring(message);
51 size_t i = 0;
52 size_t len = strlen(copyMessage);
53 char *currentMessage = copyMessage;
54
55// wxWindow *lastWindow = parent;
56
57 while (i < len) {
58 while ((i < len) && (copyMessage[i] != '\n')) i++;
59 if (i < len) copyMessage[i] = 0;
60 wxStaticText *mess = new wxStaticText(parent, -1, currentMessage);
61
62/*
63 wxLayoutConstraints *c = new wxLayoutConstraints;
64 c->left.SameAs (parent, wxLeft, 10);
65 c->top.SameAs (lastWindow, wxBottom, 5);
66 c->right.AsIs ();
67 c->height.AsIs ();
68
69 mess->SetConstraints(c);
70*/
71 sizer->AddSizerChild(mess);
72
73 messageList->Append(mess);
74
75 currentMessage = copyMessage + i + 1;
76 }
77 delete[] copyMessage;
78}
79
80wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent, const wxString& message, const wxString& caption,
81 const wxString& value, long style, const wxPoint& pos):
82 wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
83{
84 m_dialogStyle = style;
85 m_value = value;
86
87 wxBeginBusyCursor();
88
89 wxSizer *topSizer = new wxSizer(this, wxSizerShrink);
90 topSizer->SetBorder(10, 10);
91
92 wxRowColSizer *messageSizer = new wxRowColSizer(topSizer, wxSIZER_COLS, 100);
93 messageSizer->SetName("messageSizer");
94
95// bool centre = ((style & wxCENTRE) == wxCENTRE);
96
97 wxList messageList;
98 wxSplitMessage2(message, &messageList, this, messageSizer);
99
100 // Insert a spacer
101 wxSpacingSizer *spacingSizer = new wxSpacingSizer(topSizer, wxBelow, messageSizer, 10);
102
103 wxTextCtrl *textCtrl = new wxTextCtrl(this, wxID_TEXT, value, wxPoint(-1, -1), wxSize(350, -1));
104
105 wxRowColSizer *textSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
106 textSizer->AddSizerChild(textCtrl);
107 textSizer->SetName("textSizer");
108
109 // Create constraints for the text sizer
110 wxLayoutConstraints *textC = new wxLayoutConstraints;
111 textC->left.SameAs (messageSizer, wxLeft);
112 textC->top.Below (spacingSizer);
113 textSizer->SetConstraints(textC);
114
115 // Insert another spacer
116 wxSpacingSizer *spacingSizer2 = new wxSpacingSizer(topSizer, wxBelow, textSizer, 10);
117 spacingSizer->SetName("spacingSizer2");
118
119 // Insert a sizer for the buttons
120 wxRowColSizer *buttonSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
121 buttonSizer->SetName("buttonSizer");
122
123 // Specify constraints for the button sizer
124 wxLayoutConstraints *c = new wxLayoutConstraints;
125 c->width.AsIs ();
126 c->height.AsIs ();
127 c->top.Below (spacingSizer2);
128 c->centreX.SameAs (textSizer, wxCentreX);
129 buttonSizer->SetConstraints(c);
130
131 wxButton *ok = NULL;
132 wxButton *cancel = NULL;
133
134 if (style & wxOK) {
135 ok = new wxButton(this, wxID_OK, _("OK"));
136 buttonSizer->AddSizerChild(ok);
137 }
138
139 if (style & wxCANCEL) {
140 cancel = new wxButton(this, wxID_CANCEL, _("Cancel"));
141 buttonSizer->AddSizerChild(cancel);
142 }
143
144 if (ok)
145 ok->SetDefault();
146
147 Layout();
148 Centre(wxBOTH);
149
150 wxEndBusyCursor();
151}
152
153void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
154{
155 wxTextCtrl *textCtrl = (wxTextCtrl *)FindWindow(wxID_TEXT);
156 if ( textCtrl )
157 m_value = textCtrl->GetValue();
158
159 EndModal(wxID_OK);
160}
161