]> git.saurik.com Git - wxWidgets.git/blame - src/generic/textdlgg.cpp
Listctrl should now send char and key_down events.
[wxWidgets.git] / src / generic / textdlgg.cpp
CommitLineData
c801d85f
KB
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
dfad0599 47// Split message, using constraints to position controls
87138c52 48static void wxSplitMessage2(const wxChar *message, wxList *messageList, wxWindow *parent, wxRowColSizer *sizer)
dfad0599 49{
87138c52 50 wxChar *copyMessage = copystring(message);
dfad0599 51 size_t i = 0;
87138c52
OK
52 size_t len = wxStrlen(copyMessage);
53 wxChar *currentMessage = copyMessage;
dfad0599
JS
54
55// wxWindow *lastWindow = parent;
56
57 while (i < len) {
87138c52 58 while ((i < len) && (copyMessage[i] != _T('\n'))) i++;
dfad0599
JS
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}
c801d85f
KB
79
80wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent, const wxString& message, const wxString& caption,
81 const wxString& value, long style, const wxPoint& pos):
2a47d3c1 82 wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL)
c801d85f
KB
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);
3502e687 130 buttonSizer->SetSpacing(12,0);
c801d85f
KB
131
132 wxButton *ok = NULL;
133 wxButton *cancel = NULL;
134
135 if (style & wxOK) {
3502e687 136 ok = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxSize(75,-1));
c801d85f
KB
137 buttonSizer->AddSizerChild(ok);
138 }
139
140 if (style & wxCANCEL) {
3502e687 141 cancel = new wxButton(this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxSize(75,-1));
c801d85f
KB
142 buttonSizer->AddSizerChild(cancel);
143 }
144
145 if (ok)
c801d85f 146 ok->SetDefault();
c801d85f
KB
147
148 Layout();
149 Centre(wxBOTH);
150
151 wxEndBusyCursor();
152}
153
154void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
155{
156 wxTextCtrl *textCtrl = (wxTextCtrl *)FindWindow(wxID_TEXT);
157 if ( textCtrl )
158 m_value = textCtrl->GetValue();
159
160 EndModal(wxID_OK);
161}
162