A class for manipulating the clipboard. Note that this is not compatible with the
clipboard class from wxWindows 1.xx, which has the same name but a different implementation.
-To use the clipboard, construct a wxClipboard object on the stack and
-call \helpref{wxClipboard::Open}{wxclipboardopen}. If this operation returns TRUE, you
+To use the clipboard, you call member functions of the global {\bf wxTheClipboard} object.
+
+Call \helpref{wxClipboard::Open}{wxclipboardopen} to get ownership of the clipboard. If this operation returns TRUE, you
now own the clipboard. Call \helpref{wxClipboard::SetData}{wxclipboardsetdata} to put data
on the clipboard (one or more times), or \helpref{wxClipboard::GetData}{wxclipboardgetdata} to
retrieve data from the clipboard. Call \helpref{wxClipboard::Close}{wxclipboardclose} to close
For example:
\begin{verbatim}
- wxClipboard clipboard;
-
// Write some text to the clipboard
- if (clipboard.Open())
+ if (wxTheClipboard->Open())
{
- wxTextDataObject object("Some text");
- clipboard.SetData(& object);
- clipboard.Close();
+ // This object is held by the clipboard, so do not delete it in the app.
+ wxTextDataObject* object = new wxTextDataObject("Some text");
+ wxTheClipboard->SetData(& object);
+ wxTheClipboard->Close();
}
// Read some text
- if (clipboard.Open() && clipboard.IsSupportedFormat(wxDF_TEXT))
+ if (wxTheClipboard->Open() && wxTheClipboard->IsSupportedFormat(wxDF_TEXT))
{
wxTextDataObject object;
- clipboard.GetData(& object);
- clipboard.Close();
+ wxTheClipboard->GetData(& object);
+ wxTheClipboard->Close();
wxMessageBox(object.GetText());
}
\section{\class{wxKeyEvent}}\label{wxkeyevent}
-This event class contains information about keypress (character) events. See \helpref{wxWindow::OnChar}{wxwindowonchar}.
+This event class contains information about keypress (character) events.
\wxheading{Derived from}
\twocolwidtha{7cm}
\begin{twocollist}\itemsep=0pt
+\twocolitem{{\bf EVT\_CHAR(func)}}{Process a wxEVT\_CHAR event (an ASCII key has been pressed).}
+\twocolitem{{\bf EVT\_KEY\_DOWN(func)}}{Process a wxEVT\_KEY\_DOWN event (any key has been pressed).}
+\twocolitem{{\bf EVT\_KEY\_UP(func)}}{Process a wxEVT\_KEY\_UP event (any key has been released).}
\twocolitem{{\bf EVT\_CHAR(func)}}{Process a wxEVT\_CHAR event.}
\twocolitem{{\bf EVT\_CHAR\_HOOK(func)}}{Process a wxEVT\_CHAR\_HOOK event.}
\end{twocollist}%
+\wxheading{See also}
+
+\helpref{wxWindow::OnChar}{wxwindowonchar},
+\helpref{wxWindow::OnCharHook}{wxwindowoncharhook},
+\helpref{wxWindow::OnKeyDown}{wxwindowonkeydown},
+\helpref{wxWindow::OnKeyUp}{wxwindowonkeyup}
+
\latexignore{\rtfignore{\wxheading{Members}}}
\membersection{wxKeyEvent::m\_altDown}
\func{void}{OnChar}{\param{wxKeyEvent\&}{ event}}
-Called when the user has pressed a key.
+Called when the user has pressed a key, which has been translated into an ASCII value.
\wxheading{Parameters}
Note that the ASCII values do not have explicit key codes: they are passed as ASCII
values.
+Note that not all keypresses can be intercepted this way. If you wish to intercept special
+keys, such as shift, control, and function keys, then you will need to use \helpref{wxWindow::OnKeyDown}{wxwindowonkeydown} or
+\helpref{wxWindow::OnKeyUp}{wxwindowonkeyup}.
+
Most, but not all, windows allow keypresses to be intercepted.
\wxheading{See also}
+\helpref{wxWindow::OnKeyDown}{wxwindowonkeydown}, \helpref{wxWindow::OnKeyUp}{wxwindowonkeyup},\rtfsp
\helpref{wxKeyEvent}{wxkeyevent}, \helpref{wxWindow::OnCharHook}{wxwindowoncharhook},\rtfsp
\helpref{Event handling overview}{eventhandlingoverview}
\helpref{wxEraseEvent}{wxeraseevent}, \helpref{Event handling overview}{eventhandlingoverview}
+\membersection{wxWindow::OnKeyDown}\label{wxwindowonkeydown}
+
+\func{void}{OnKeyDown}{\param{wxKeyEvent\&}{ event}}
+
+Called when the user has pressed a key, before it is translated into an ASCII value using other
+modifier keys that might be pressed at the same time.
+
+\wxheading{Parameters}
+
+\docparam{event}{Object containing keypress information. See \helpref{wxKeyEvent}{wxkeyevent} for
+details about this class.}
+
+\wxheading{Remarks}
+
+This member function is called in response to a key down event. To intercept this event,
+use the EVT\_KEY\_DOWN macro in an event table definition. Your {\bf OnKeyDown} handler may call this
+default function to achieve default keypress functionality.
+
+Note that not all keypresses can be intercepted this way. If you wish to intercept special
+keys, such as shift, control, and function keys, then you will need to use \helpref{wxWindow::OnKeyDown}{wxwindowonkeydown} or
+\helpref{wxWindow::OnKeyUp}{wxwindowonkeyup}.
+
+Most, but not all, windows allow keypresses to be intercepted.
+
+\wxheading{See also}
+
+\helpref{wxWindow::OnChar}{wxwindowonchar}, \helpref{wxWindow::OnKeyUp}{wxwindowonkeyup},\rtfsp
+\helpref{wxKeyEvent}{wxkeyevent}, \helpref{wxWindow::OnCharHook}{wxwindowoncharhook},\rtfsp
+\helpref{Event handling overview}{eventhandlingoverview}
+
+\membersection{wxWindow::OnKeyUp}\label{wxwindowonkeyup}
+
+\func{void}{OnKeyUp}{\param{wxKeyEvent\&}{ event}}
+
+Called when the user has released a key.
+
+\wxheading{Parameters}
+
+\docparam{event}{Object containing keypress information. See \helpref{wxKeyEvent}{wxkeyevent} for
+details about this class.}
+
+\wxheading{Remarks}
+
+This member function is called in response to a key up event. To intercept this event,
+use the EVT\_KEY\_UP macro in an event table definition. Your {\bf OnKeyUp} handler may call this
+default function to achieve default keypress functionality.
+
+Note that not all keypresses can be intercepted this way. If you wish to intercept special
+keys, such as shift, control, and function keys, then you will need to use \helpref{wxWindow::OnKeyDown}{wxwindowonkeydown} or
+\helpref{wxWindow::OnKeyUp}{wxwindowonkeyup}.
+
+Most, but not all, windows allow key up events to be intercepted.
+
+\wxheading{See also}
+
+\helpref{wxWindow::OnChar}{wxwindowonchar}, \helpref{wxWindow::OnKeyDown}{wxwindowonkeydown},\rtfsp
+\helpref{wxKeyEvent}{wxkeyevent}, \helpref{wxWindow::OnCharHook}{wxwindowoncharhook},\rtfsp
+\helpref{Event handling overview}{eventhandlingoverview}
+
\membersection{wxWindow::OnKillFocus}\label{wxwindowonkillfocus}
\func{void}{OnKillFocus}{\param{wxFocusEvent\& }{event}}
- Get wxGLCanvas from 1.68 working.
-- Implement missing wxImage functions for Motif.
-
- wxClipboard
+- EVT_KEY_DOWN, EVT_KEY_UP events.
+
Low Priority
------------
/* Character input event type */
const wxEventType wxEVT_CHAR = wxEVT_FIRST + 212;
-const wxEventType wxEVT_NAVIGATION_KEY = wxEVT_FIRST + 213;
+const wxEventType wxEVT_CHAR_HOOK = wxEVT_FIRST + 213;
+const wxEventType wxEVT_NAVIGATION_KEY = wxEVT_FIRST + 214;
+const wxEventType wxEVT_KEY_DOWN = wxEVT_FIRST + 215;
+const wxEventType wxEVT_KEY_UP = wxEVT_FIRST + 216;
/*
* Scrollbar event identifiers
const wxEventType wxEVT_QUERY_END_SESSION = wxEVT_FIRST + 404;
const wxEventType wxEVT_ACTIVATE_APP = wxEVT_FIRST + 405;
const wxEventType wxEVT_POWER = wxEVT_FIRST + 406;
-const wxEventType wxEVT_CHAR_HOOK = wxEVT_FIRST + 407;
-const wxEventType wxEVT_KEY_UP = wxEVT_FIRST + 408;
const wxEventType wxEVT_ACTIVATE = wxEVT_FIRST + 409;
const wxEventType wxEVT_CREATE = wxEVT_FIRST + 410;
const wxEventType wxEVT_DESTROY = wxEVT_FIRST + 411;
/*
wxEVT_CHAR
wxEVT_CHAR_HOOK
+ wxEVT_KEY_DOWN
wxEVT_KEY_UP
*/
#define EVT_PAINT(func) { wxEVT_PAINT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxPaintEventFunction) & func, (wxObject *) NULL },
#define EVT_ERASE_BACKGROUND(func) { wxEVT_ERASE_BACKGROUND, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxEraseEventFunction) & func, (wxObject *) NULL },
#define EVT_CHAR(func) { wxEVT_CHAR, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCharEventFunction) & func, (wxObject *) NULL },
+#define EVT_KEY_DOWN(func) { wxEVT_KEY_DOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCharEventFunction) & func, (wxObject *) NULL },
+#define EVT_KEY_UP(func) { wxEVT_KEY_UP, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCharEventFunction) & func, (wxObject *) NULL },
#define EVT_CHAR_HOOK(func) { wxEVT_CHAR_HOOK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxCharEventFunction) & func, NULL },
#define EVT_MENU_HIGHLIGHT(id, func) { wxEVT_MENU_HIGHLIGHT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxMenuEventFunction) & func, (wxObject *) NULL },
#define EVT_MENU_HIGHLIGHT_ALL(func) { wxEVT_MENU_HIGHLIGHT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMenuEventFunction) & func, (wxObject *) NULL },
void OnEraseBackground(wxEraseEvent& event);
void OnChar(wxKeyEvent& event);
+ void OnKeyDown(wxKeyEvent& event);
+ void OnKeyUp(wxKeyEvent& event);
+ void OnChar(wxKeyEvent& event);
void OnPaint(wxPaintEvent& event);
void OnIdle(wxIdleEvent& event);
#if wxUSE_CLIPBOARD
#include "wx/list.h"
+#include "wx/module.h"
// These functions superceded by wxClipboard, but retained in order to implement
// wxClipboard, and for compatibility.
// implementation
bool m_open;
+ wxList m_data;
};
/* The clipboard */
-// WXDLLEXPORT_DATA(extern wxClipboard*) wxTheClipboard;
+WXDLLEXPORT_DATA(extern wxClipboard*) wxTheClipboard;
+
+//-----------------------------------------------------------------------------
+// wxClipboardModule
+//-----------------------------------------------------------------------------
+
+class wxClipboardModule: public wxModule
+{
+ DECLARE_DYNAMIC_CLASS(wxClipboardModule)
+
+public:
+ wxClipboardModule() {}
+ bool OnInit();
+ void OnExit();
+};
#endif // wxUSE_CLIPBOARD
#endif
void OnEraseBackground(wxEraseEvent& event);
void OnChar(wxKeyEvent& event);
+ void OnKeyDown(wxKeyEvent& event);
+ void OnKeyUp(wxKeyEvent& event);
void OnPaint(wxPaintEvent& event);
void OnIdle(wxIdleEvent& event);
virtual void MSWOnMouseLeave(int x, int y, WXUINT flags);
virtual void MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE);
+ virtual void MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE);
+ virtual void MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE);
virtual bool MSWOnActivate(int flag, bool minimized, WXHWND activate);
virtual long MSWOnMDIActivate(long flag, WXHWND activate, WXHWND deactivate);
void OnEraseBackground(wxEraseEvent& event);
void OnChar(wxKeyEvent& event);
+ void OnKeyDown(wxKeyEvent& event);
+ void OnKeyUp(wxKeyEvent& event);
void OnPaint(wxPaintEvent& event);
void OnIdle(wxIdleEvent& event);
#endif
-// TODO
-
#ifdef __WXMOTIF__
#include <Xm/Xm.h>
BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
EVT_CHAR(wxWindow::OnChar)
+ EVT_KEY_DOWN(wxWindow::OnKeyDown)
+ EVT_KEY_UP(wxWindow::OnKeyUp)
EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
EVT_INIT_DIALOG(wxWindow::OnInitDialog)
void wxWindow::OnChar(wxKeyEvent& event)
{
+/* ??
if ( event.KeyCode() == WXK_TAB ) {
// propagate the TABs to the parent - it's up to it to decide what
// to do with it
return;
}
}
+*/
+}
+
+void wxWindow::OnKeyDown(wxKeyEvent& event)
+{
+ Default();
+}
+
+void wxWindow::OnKeyUp(wxKeyEvent& event)
+{
+ Default();
}
void wxWindow::OnPaint(wxPaintEvent& event)
IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject)
+wxClipboard* wxTheClipboard = (wxClipboard*) NULL;
+
wxClipboard::wxClipboard()
{
m_open = FALSE;
void wxClipboard::Clear()
{
+ wxNode* node = m_data.First();
+ while (node)
+ {
+ wxDataObject* data = (wxDataObject*) node->Data();
+ delete data;
+ node = node->Next();
+ }
+ m_data.Clear();
}
bool wxClipboard::Open()
#endif
}
+//-----------------------------------------------------------------------------
+// wxClipboardModule
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule)
+
+bool wxClipboardModule::OnInit()
+{
+ wxTheClipboard = new wxClipboard();
+
+ return TRUE;
+}
+
+void wxClipboardModule::OnExit()
+{
+ if (wxTheClipboard) delete wxTheClipboard;
+ wxTheClipboard = (wxClipboard*) NULL;
+}
+
#endif // wxUSE_CLIPBOARD
+
BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
EVT_CHAR(wxWindow::OnChar)
+ EVT_KEY_DOWN(wxWindow::OnKeyDown)
+ EVT_KEY_UP(wxWindow::OnKeyUp)
EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
EVT_INIT_DIALOG(wxWindow::OnInitDialog)
}
case WM_KEYDOWN:
+ {
+ MSWOnKeyDown((WORD) wParam, lParam);
+#if 0
// we consider these message "not interesting"
if ( wParam == VK_SHIFT || wParam == VK_CONTROL )
return Default();
MSWOnChar((WORD)wParam, lParam);
else
return Default();
+#endif
break;
+ }
+ case WM_KEYUP:
+ {
+ MSWOnKeyUp((WORD) wParam, lParam);
+ break;
+ }
case WM_CHAR: // Always an ASCII character
{
MSWOnChar((WORD)wParam, lParam, TRUE);
}
}
+void wxWindow::MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam, bool isASCII)
+{
+ int id;
+
+ if ((id = wxCharCodeMSWToWX(wParam)) == 0) {
+ id = wParam;
+ }
+
+ if (id != -1)
+ {
+ wxKeyEvent event(wxEVT_KEY_DOWN);
+ event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
+ event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
+ if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN)
+ event.m_altDown = TRUE;
+
+ event.m_eventObject = this;
+ event.m_keyCode = id;
+ event.SetTimestamp(wxApp::sm_lastMessageTime);
+
+ POINT pt ;
+ GetCursorPos(&pt) ;
+ RECT rect ;
+ GetWindowRect((HWND) GetHWND(),&rect) ;
+ pt.x -= rect.left ;
+ pt.y -= rect.top ;
+
+ event.m_x = pt.x; event.m_y = pt.y;
+
+ if (!GetEventHandler()->ProcessEvent(event))
+ Default();
+ }
+}
+
+void wxWindow::MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam, bool isASCII)
+{
+ int id;
+
+ if ((id = wxCharCodeMSWToWX(wParam)) == 0) {
+ id = wParam;
+ }
+
+ if (id != -1)
+ {
+ wxKeyEvent event(wxEVT_KEY_UP);
+ event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
+ event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
+ if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN)
+ event.m_altDown = TRUE;
+
+ event.m_eventObject = this;
+ event.m_keyCode = id;
+ event.SetTimestamp(wxApp::sm_lastMessageTime);
+
+ POINT pt ;
+ GetCursorPos(&pt) ;
+ RECT rect ;
+ GetWindowRect((HWND) GetHWND(),&rect) ;
+ pt.x -= rect.left ;
+ pt.y -= rect.top ;
+
+ event.m_x = pt.x; event.m_y = pt.y;
+
+ if (!GetEventHandler()->ProcessEvent(event))
+ Default();
+ }
+}
+
void wxWindow::MSWOnJoyDown(int joystick, int x, int y, WXUINT flags)
{
int buttons = 0;
void wxWindow::OnChar(wxKeyEvent& event)
{
+/* I'm commenting this out because otherwise, we lose tabs in e.g. a text window (see MDI sample)
+ * (JACS, 14/01/99)
if ( event.KeyCode() == WXK_TAB ) {
// propagate the TABs to the parent - it's up to it to decide what
// to do with it
return;
}
}
+*/
bool isVirtual;
int id = wxCharCodeWXToMSW((int)event.KeyCode(), &isVirtual);
(void) MSWDefWindowProc(m_lastMsg, (WPARAM) id, m_lastLParam);
}
+void wxWindow::OnKeyDown(wxKeyEvent& event)
+{
+ Default();
+}
+
+void wxWindow::OnKeyUp(wxKeyEvent& event)
+{
+ Default();
+}
+
void wxWindow::OnPaint(wxPaintEvent& event)
{
Default();
BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
EVT_CHAR(wxWindow::OnChar)
+ EVT_KEY_DOWN(wxWindow::OnKeyDown)
+ EVT_KEY_UP(wxWindow::OnKeyUp)
EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
EVT_INIT_DIALOG(wxWindow::OnInitDialog)
void wxWindow::OnChar(wxKeyEvent& event)
{
+/* ??
if ( event.KeyCode() == WXK_TAB ) {
// propagate the TABs to the parent - it's up to it to decide what
// to do with it
return;
}
}
+*/
+ Default();
+}
+
+void wxWindow::OnKeyDown(wxKeyEvent& event)
+{
+ Default();
+}
+
+void wxWindow::OnKeyUp(wxKeyEvent& event)
+{
+ Default();
}
void wxWindow::OnPaint(wxPaintEvent& event)