⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyboarddialog.cpp

📁 roadnav 内含一个基于wxWindows库的车载导航系统。编译后
💻 CPP
字号:
/* *  Roadnav *  KeyboardDialog.cpp * *  Copyright (c) 2004 - 2006 Richard L. Lynch <rllynch@users.sourceforge.net> * *  This program is free software; you can redistribute it and/or *  modify it under the terms of version 2 of the GNU General Public License *  as published by the Free Software Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *////////////////////////////////////////////////////////////////////////////////// \file////// Contains a dialog containing an onscreen keyboard, allowing text to be/// entered into a wxTextCtrl without using a physical keyboard./////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H#  include <config.h>#endif#include <wx/wx.h>#include "KeyboardDialog.h"//////////////////////////////////////////////////////////////////////////////////// \brief KeyboardDialog event table/////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(KeyboardDialog, wxDialog)	EVT_BUTTON(wxID_OK, KeyboardDialog::OnOk)	EVT_CUSTOM_RANGE(wxEVT_COMMAND_BUTTON_CLICKED, 0, 255, KeyboardDialog::OnKBButtonPress)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// \brief KeyboardDialog constructor////// Creates the various controls in the dialog box/////////////////////////////////////////////////////////////////////////////////KeyboardDialog::KeyboardDialog(wxWindow *parent, wxString strTitle, wxTextCtrl * pctlText)             : wxDialog(parent, -1, strTitle, wxDefaultPosition, wxSize(630, 450)){	int iLine;	int iWidth;	int iHeight;		GetSize(&iWidth, &iHeight);		int iKeyboardX = 10;	int iKeyboardY = 90;	int iKeyWidth = 50;	// Actual vertical size of the button control#ifdef __DARWIN__	int iKeyHeight = 22;#else	int iKeyHeight = 50;#endif	// Vertical spacing for button controls	int iKeyVerticalSpacing = 50;		char * pszLines[] = {"1234567890\b",     "QWERTYUIOP",         "ASDFGHJKL\r",       "ZXCVBNM,.", NULL};	int iLineOffset[] = {0,                iKeyWidth / 3,        iKeyWidth * 2 / 3, iKeyWidth, 0};	m_fntThis = *wxNORMAL_FONT;	m_fntThis.SetPointSize(18);	SetFont(m_fntThis);	m_pctlText = pctlText;	m_pctlThisText = new wxTextCtrl(this, -1, m_pctlText->GetValue(), wxPoint(10, 10), wxSize(iWidth - 20, iKeyVerticalSpacing));		for (iLine = 0; pszLines[iLine]; iLine++)	{		int iChar;				for (iChar = 0; pszLines[iLine][iChar]; iChar++)		{			wxString strLabel;			int iThisKeyWidth;						if (pszLines[iLine][iChar] == '\b')			{				strLabel = wxT("<-");				iThisKeyWidth = iKeyWidth * 2;			}			else if (pszLines[iLine][iChar] == '\r')			{				strLabel = wxT("Enter");				iThisKeyWidth = iKeyWidth * 2;			}			else			{				strLabel = wxString::Format(wxT("%c"), pszLines[iLine][iChar]);				iThisKeyWidth = iKeyWidth;			}						new wxButton(this, pszLines[iLine][iChar], strLabel, wxPoint(iKeyboardX + iKeyWidth * iChar + iLineOffset[iLine], iKeyboardY + iKeyVerticalSpacing * iLine), wxSize(iThisKeyWidth, iKeyHeight));		}	}	new wxButton(this, ' ', wxT("Spacebar"), wxPoint(iKeyboardX + iKeyWidth * 2, iKeyboardY + iKeyVerticalSpacing * iLine), wxSize(iKeyWidth * 8, iKeyHeight));		new wxButton(this, wxID_OK, wxT("&OK"), wxPoint(iWidth / 2 - 150 - 25, iHeight - 100), wxSize(150, 50));	new wxButton(this, wxID_CANCEL, wxT("&Cancel"), wxPoint(iWidth / 2 + 25, iHeight - 100), wxSize(150, 50));		Center();}//////////////////////////////////////////////////////////////////////////////////// \brief A key on the keyboard was pressed. Take the appropriate action./////////////////////////////////////////////////////////////////////////////////void KeyboardDialog::OnKBButtonPress(wxEvent & event){	wxString strText;	long lStart, lEnd;		if (event.GetId() == '\r')	{		wxCommandEvent evOk(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);		OnOk(evOk);		return;	}	m_pctlThisText->GetSelection(&lStart, &lEnd);	m_pctlThisText->Remove(lStart, lEnd);		strText = m_pctlThisText->GetValue();		if (event.GetId() != '\b')	{		strText = strText.Left(lStart) + wxString::Format(wxT("%c"), event.GetId()) + strText.Mid(lStart);	}	else	{		if (lStart == lEnd)			if (lStart > 0)			{				strText = strText.Left(lStart - 1) + strText.Mid(lStart);				lStart -= 2;			}	}	m_pctlThisText->SetValue(strText);		m_pctlThisText->SetFocus();	m_pctlThisText->SetSelection(lStart + 1, lStart + 1);}//////////////////////////////////////////////////////////////////////////////////// \brief Ok button was pressed. Copy the contents of the keyboard back/// to the original wxTextCtrl./////////////////////////////////////////////////////////////////////////////////void KeyboardDialog::OnOk(wxCommandEvent & event){	m_pctlText->SetValue(m_pctlThisText->GetValue());	wxDialog::OnOK(event);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -