Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[c8d76d]: src / ui / Windows / InputBox.cpp Maximize Restore History

Download this file

InputBox.cpp    128 lines (98 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// InputBox.cpp : implementation file
//
/*
* Copyright (c) 2003-2014 Rony Shapiro <ronys@users.sourceforge.net>.
* All rights reserved. Use of the code is allowed under the
* Artistic License 2.0 terms, as specified in the LICENSE file
* distributed with this code, or available from
* http://www.opensource.org/licenses/artistic-license-2.0.php
*/
#include "stdafx.h"
#include "InputBox.h"
#include "resource3.h"
// CInputBox dialog
IMPLEMENT_DYNAMIC(CInputBox, CPWDialog)
CInputBox::CInputBox(UINT nIDCaption, CString csInitalText, int maxlen,
const bool bReadOnly, CWnd *pParent)
: CPWDialog(CInputBox::IDD, pParent), m_nIDCaption(nIDCaption), m_maxlen(maxlen),
m_csText(csInitalText), m_bReadOnly(bReadOnly), m_bInitDone(false)
{
}
CInputBox::~CInputBox()
{
}
void CInputBox::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_INPUTBOX_TEXT, m_edText);
}
BEGIN_MESSAGE_MAP(CInputBox, CPWDialog)
ON_WM_ACTIVATE()
ON_BN_CLICKED(IDOK, OnOK)
ON_EN_CHANGE(IDC_INPUTBOX_TEXT, OnInputChanged)
END_MESSAGE_MAP()
// CInputBox message handlers
BOOL CInputBox::OnInitDialog()
{
CPWDialog::OnInitDialog();
CString csCaption(MAKEINTRESOURCE(m_nIDCaption));
SetWindowText(csCaption);
m_edText.SetWindowText(m_csText);
if (m_maxlen > 0)
m_edText.SetLimitText(m_maxlen);
else
GetDlgItem(IDC_INPUTBOX_CHAR_COUNT)->ShowWindow(SW_HIDE);
if (m_bReadOnly) {
// Hide the Cancel button and centre the OK button
GetDlgItem(IDCANCEL)->ShowWindow(SW_HIDE);
GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
CString csClose(MAKEINTRESOURCE(IDS_CLOSE));
GetDlgItem(IDOK)->SetWindowText(csClose);
CRect dlgRect, btnRect;
GetClientRect(&dlgRect);
GetDlgItem(IDOK)->GetWindowRect(&btnRect);
ScreenToClient(&btnRect);
int ytop = btnRect.top;
int xleft = (dlgRect.Width() / 2) - (btnRect.Width() / 2);
GetDlgItem(IDOK)->SetWindowPos(NULL, xleft, ytop, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER);
// Make Edit control R-O
m_edText.SetReadOnly(TRUE);
}
if (m_maxlen > 0) {
CString csNumChars;
csNumChars.Format(IDS_INPUTBOX_CHAR_COUNT, m_csText.GetLength());
GetDlgItem(IDC_INPUTBOX_CHAR_COUNT)->SetWindowText(csNumChars);
}
GotoDlgCtrl(GetDlgItem(IDC_INPUTBOX_TEXT));
return FALSE;
}
BOOL CInputBox::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE) {
PostMessage(WM_COMMAND, MAKELONG(IDCANCEL, BN_CLICKED), NULL);
return TRUE;
}
return CPWDialog::PreTranslateMessage(pMsg);
}
void CInputBox::OnActivate(UINT , CWnd *, BOOL )
{
if (!m_bInitDone) {
m_edText.SetSel(-1, 0);
m_bInitDone = true;
}
}
void CInputBox::OnOK()
{
UpdateData(TRUE);
m_edText.GetWindowText(m_csText);
CPWDialog::OnOK();
}
void CInputBox::OnInputChanged()
{
if (m_maxlen > 0) {
CString csText, csNumChars;
m_edText.GetWindowText(csText);
csNumChars.Format(IDS_INPUTBOX_CHAR_COUNT, csText.GetLength());
GetDlgItem(IDC_INPUTBOX_CHAR_COUNT)->SetWindowText(csNumChars);
}
}