diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2010-09-29 16:21:04 -0400 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2010-09-29 16:21:04 -0400 |
commit | 49b7f991a509528302d2d1987d3f6c38bd108798 (patch) | |
tree | c205628d3f47dc5b8dc7fe79c74263bc3b5eea4a | |
parent | 13b0fc7375271ed58f563306ef57f81808ac9289 (diff) |
Ported autocorrect-accidental-caps-lock-vcl.diff from ooo-build.
-rw-r--r-- | vcl/aqua/inc/salframe.h | 2 | ||||
-rw-r--r-- | vcl/aqua/source/window/salframe.cxx | 11 | ||||
-rw-r--r-- | vcl/inc/vcl/keycodes.hxx | 12 | ||||
-rw-r--r-- | vcl/inc/vcl/salframe.hxx | 9 | ||||
-rw-r--r-- | vcl/inc/vcl/window.hxx | 16 | ||||
-rw-r--r-- | vcl/os2/inc/salframe.h | 2 | ||||
-rw-r--r-- | vcl/os2/source/window/salframe.cxx | 13 | ||||
-rw-r--r-- | vcl/source/window/window.cxx | 10 | ||||
-rw-r--r-- | vcl/unx/gtk/window/gtkframe.cxx | 12 | ||||
-rw-r--r-- | vcl/unx/headless/svpframe.cxx | 11 | ||||
-rw-r--r-- | vcl/unx/headless/svpframe.hxx | 2 | ||||
-rw-r--r-- | vcl/unx/inc/plugins/gtk/gtkframe.hxx | 4 | ||||
-rw-r--r-- | vcl/unx/inc/saldisp.hxx | 2 | ||||
-rw-r--r-- | vcl/unx/inc/salframe.h | 2 | ||||
-rw-r--r-- | vcl/unx/source/app/saldisp.cxx | 73 | ||||
-rw-r--r-- | vcl/unx/source/window/salframe.cxx | 12 | ||||
-rw-r--r-- | vcl/win/inc/salframe.h | 2 | ||||
-rw-r--r-- | vcl/win/source/window/salframe.cxx | 35 |
18 files changed, 229 insertions, 1 deletions
diff --git a/vcl/aqua/inc/salframe.h b/vcl/aqua/inc/salframe.h index c2ded3267f45..ee4d0373b2cc 100644 --- a/vcl/aqua/inc/salframe.h +++ b/vcl/aqua/inc/salframe.h @@ -152,6 +152,8 @@ public: virtual void Beep( SoundType eSoundType ); virtual const SystemEnvData* GetSystemData() const; virtual SalPointerState GetPointerState(); + virtual SalIndicatorState GetIndicatorState(); + virtual void SimulateKeyPress( USHORT nKeyCode ); virtual void SetParent( SalFrame* pNewParent ); virtual bool SetPluginParent( SystemParentData* pNewParent ); virtual void SetExtendedFrameStyle( SalExtStyle ); diff --git a/vcl/aqua/source/window/salframe.cxx b/vcl/aqua/source/window/salframe.cxx index b14354e1b4bd..1fb97ee82048 100644 --- a/vcl/aqua/source/window/salframe.cxx +++ b/vcl/aqua/source/window/salframe.cxx @@ -1436,6 +1436,17 @@ SalPointerState AquaSalFrame::GetPointerState() return state; } +SalFrame::SalIndicatorState AquaSalFrame::GetIndicatorState() +{ + SalIndicatorState aState; + aState.mnState = 0; + return aState; +} + +void AquaSalFrame::SimulateKeyPress( USHORT /*nKeyCode*/ ) +{ +} + bool AquaSalFrame::SetPluginParent( SystemParentData* pNewParent ) { // plugin parent may be killed unexpectedly by diff --git a/vcl/inc/vcl/keycodes.hxx b/vcl/inc/vcl/keycodes.hxx index 4b306ac4b4ce..8cbec63373d2 100644 --- a/vcl/inc/vcl/keycodes.hxx +++ b/vcl/inc/vcl/keycodes.hxx @@ -158,6 +158,10 @@ #define KEY_BRACKETLEFT ((USHORT)::com::sun::star::awt::Key::BRACKETLEFT) #define KEY_BRACKETRIGHT ((USHORT)::com::sun::star::awt::Key::BRACKETRIGHT) +#define KEY_CAPSLOCK ((USHORT)::com::sun::star::awt::Key::CAPSLOCK) +#define KEY_NUMLOCK ((USHORT)::com::sun::star::awt::Key::NUMLOCK) +#define KEY_SCROLLLOCK ((USHORT)::com::sun::star::awt::Key::SCROLLLOCK) + #define KEY_CODE ((USHORT)0x0FFF) // Modifier-Tasten @@ -190,4 +194,12 @@ #define MOUSE_MIDDLE ((USHORT)0x0002) #define MOUSE_RIGHT ((USHORT)0x0004) +// ------------------- +// - Indicator-Types - +// ------------------- + +#define INDICATOR_CAPSLOCK 0x0001 +#define INDICATOR_NUMLOCK 0x0002 +#define INDICATOR_SCROLLLOCK 0x0004 + #endif // _SV_KEYCODES_HXX diff --git a/vcl/inc/vcl/salframe.hxx b/vcl/inc/vcl/salframe.hxx index 08548d7dda40..83ef6ae6cc36 100644 --- a/vcl/inc/vcl/salframe.hxx +++ b/vcl/inc/vcl/salframe.hxx @@ -250,6 +250,15 @@ public: virtual SalPointerState GetPointerState() = 0; + struct SalIndicatorState + { + USHORT mnState; + }; + + virtual SalIndicatorState GetIndicatorState() = 0; + + virtual void SimulateKeyPress( USHORT nKeyCode ) = 0; + // set new parent window virtual void SetParent( SalFrame* pNewParent ) = 0; // reparent window to act as a plugin; implementation diff --git a/vcl/inc/vcl/window.hxx b/vcl/inc/vcl/window.hxx index 8264767e59ad..5a3693c85b2e 100644 --- a/vcl/inc/vcl/window.hxx +++ b/vcl/inc/vcl/window.hxx @@ -1101,6 +1101,22 @@ public: */ void doLazyDelete(); + //------------------------------------- + // Keyboard access functions + //------------------------------------- + + /** Query the states of keyboard indicators - Caps Lock, Num Lock and + Scroll Lock. Use the following mask to retrieve the state of each + indicator: + + INDICATOR_CAPS_LOCK + INDICATOR_NUM_LOCK + INDICATOR_SCROLL_LOCK + */ + USHORT GetIndicatorState() const; + + void SimulateKeyPress( USHORT nKeyCode ) const; + virtual XubString GetSurroundingText() const; virtual Selection GetSurroundingTextSelection() const; }; diff --git a/vcl/os2/inc/salframe.h b/vcl/os2/inc/salframe.h index f02a39f80955..ca16fbebc54a 100644 --- a/vcl/os2/inc/salframe.h +++ b/vcl/os2/inc/salframe.h @@ -152,6 +152,8 @@ public: virtual void Beep( SoundType eSoundType ); virtual const SystemEnvData* GetSystemData() const; virtual SalPointerState GetPointerState(); + virtual SalIndicatorState GetIndicatorState(); + virtual void SimulateKeyPress( USHORT nKeyCode ); virtual void SetParent( SalFrame* pNewParent ); virtual bool SetPluginParent( SystemParentData* pNewParent ); virtual void SetBackgroundBitmap( SalBitmap* ); diff --git a/vcl/os2/source/window/salframe.cxx b/vcl/os2/source/window/salframe.cxx index f3314c725255..ca40441ccda7 100644 --- a/vcl/os2/source/window/salframe.cxx +++ b/vcl/os2/source/window/salframe.cxx @@ -2354,6 +2354,19 @@ SalFrame::SalPointerState Os2SalFrame::GetPointerState() // ----------------------------------------------------------------------- +SalFrame::SalIndicatorState Os2SalFrame::GetIndicatorState() +{ + SalIndicatorState aState; + aState.mnState = 0; + return aState; +} + +void Os2SalFrame::SimulateKeyPress( USHORT /*nKeyCode*/ ) +{ +} + +// ----------------------------------------------------------------------- + void Os2SalFrame::SetBackgroundBitmap( SalBitmap* ) { } diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index adedbde4c0f2..a51a525a5f70 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -4791,6 +4791,16 @@ void Window::doLazyDelete() vcl::LazyDeletor<Window>::Delete( this ); } +USHORT Window::GetIndicatorState() const +{ + return mpWindowImpl->mpFrame->GetIndicatorState().mnState; +} + +void Window::SimulateKeyPress( USHORT nKeyCode ) const +{ + mpWindowImpl->mpFrame->SimulateKeyPress(nKeyCode); +} + // ----------------------------------------------------------------------- void Window::MouseMove( const MouseEvent& rMEvt ) diff --git a/vcl/unx/gtk/window/gtkframe.cxx b/vcl/unx/gtk/window/gtkframe.cxx index 99ac8748af8a..171913128b96 100644 --- a/vcl/unx/gtk/window/gtkframe.cxx +++ b/vcl/unx/gtk/window/gtkframe.cxx @@ -2257,6 +2257,18 @@ SalFrame::SalPointerState GtkSalFrame::GetPointerState() return aState; } +SalFrame::SalIndicatorState GtkSalFrame::GetIndicatorState() +{ + SalIndicatorState aState; + aState.mnState = GetX11SalData()->GetDisplay()->GetIndicatorState(); + return aState; +} + +void GtkSalFrame::SimulateKeyPress( USHORT nKeyCode ) +{ + GetX11SalData()->GetDisplay()->SimulateKeyPress(nKeyCode); +} + void GtkSalFrame::SetInputContext( SalInputContext* pContext ) { if( ! pContext ) diff --git a/vcl/unx/headless/svpframe.cxx b/vcl/unx/headless/svpframe.cxx index 1adf9a51cce4..2b030970db98 100644 --- a/vcl/unx/headless/svpframe.cxx +++ b/vcl/unx/headless/svpframe.cxx @@ -415,6 +415,17 @@ SalFrame::SalPointerState SvpSalFrame::GetPointerState() return aState; } +SalFrame::SalIndicatorState SvpSalFrame::GetIndicatorState() +{ + SalIndicatorState aState; + aState.mnState = 0; + return aState; +} + +void SvpSalFrame::SimulateKeyPress( USHORT /*nKeyCode*/ ) +{ +} + void SvpSalFrame::SetParent( SalFrame* pNewParent ) { if( m_pParent ) diff --git a/vcl/unx/headless/svpframe.hxx b/vcl/unx/headless/svpframe.hxx index de968bbf7a4a..f982c9743207 100644 --- a/vcl/unx/headless/svpframe.hxx +++ b/vcl/unx/headless/svpframe.hxx @@ -112,6 +112,8 @@ public: virtual void Beep( SoundType eSoundType ); virtual const SystemEnvData* GetSystemData() const; virtual SalPointerState GetPointerState(); + virtual SalIndicatorState GetIndicatorState(); + virtual void SimulateKeyPress( USHORT nKeyCode ); virtual void SetParent( SalFrame* pNewParent ); virtual bool SetPluginParent( SystemParentData* pNewParent ); virtual void SetBackgroundBitmap( SalBitmap* pBitmap ); diff --git a/vcl/unx/inc/plugins/gtk/gtkframe.hxx b/vcl/unx/inc/plugins/gtk/gtkframe.hxx index d47e5fb50fca..648d61b44d61 100644 --- a/vcl/unx/inc/plugins/gtk/gtkframe.hxx +++ b/vcl/unx/inc/plugins/gtk/gtkframe.hxx @@ -371,6 +371,10 @@ public: // get current modifier and button mask virtual SalPointerState GetPointerState(); + virtual SalIndicatorState GetIndicatorState(); + + virtual void SimulateKeyPress( USHORT nKeyCode ); + // set new parent window virtual void SetParent( SalFrame* pNewParent ); // reparent window to act as a plugin; implementation diff --git a/vcl/unx/inc/saldisp.hxx b/vcl/unx/inc/saldisp.hxx index 3734cbec6ef7..2558f899c558 100644 --- a/vcl/unx/inc/saldisp.hxx +++ b/vcl/unx/inc/saldisp.hxx @@ -445,6 +445,8 @@ public: void Beep() const; void ModifierMapping(); + void SimulateKeyPress( USHORT nKeyCode ); + USHORT GetIndicatorState() const; String GetKeyNameFromKeySym( KeySym keysym ) const; XubString GetKeyName( USHORT nKeyCode ) const; USHORT GetKeyCode( KeySym keysym, char*pcPrintable ) const; diff --git a/vcl/unx/inc/salframe.h b/vcl/unx/inc/salframe.h index ed173e61fe61..954cf8f5bd2d 100644 --- a/vcl/unx/inc/salframe.h +++ b/vcl/unx/inc/salframe.h @@ -254,6 +254,8 @@ public: virtual void Beep( SoundType eSoundType ); virtual const SystemEnvData* GetSystemData() const; virtual SalPointerState GetPointerState(); + virtual SalIndicatorState GetIndicatorState(); + virtual void SimulateKeyPress( USHORT nKeyCode ); virtual void SetParent( SalFrame* pNewParent ); virtual bool SetPluginParent( SystemParentData* pNewParent ); virtual void SetBackgroundBitmap( SalBitmap* pBitmap ); diff --git a/vcl/unx/source/app/saldisp.cxx b/vcl/unx/source/app/saldisp.cxx index f3220c106797..ca1f0052d8f0 100644 --- a/vcl/unx/source/app/saldisp.cxx +++ b/vcl/unx/source/app/saldisp.cxx @@ -54,7 +54,7 @@ #define XK_KOREAN #endif #include <X11/keysym.h> - +#include <X11/XKBlib.h> #include <X11/Xatom.h> #ifdef USE_XINERAMA @@ -1037,6 +1037,77 @@ void SalDisplay::Beep() const // Keyboard // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +namespace { + +bool InitXkb(Display* dpy) +{ + int nOpcode, nEvent, nError; + int nXkbMajor = XkbMajorVersion; + int nXkbMinor = XkbMinorVersion; + + if (!XkbLibraryVersion(&nXkbMajor, &nXkbMinor)) + return false; + + return XkbQueryExtension( + dpy, &nOpcode, &nEvent, &nError, &nXkbMajor, &nXkbMinor); +} + +unsigned int GetKeySymMask(Display* dpy, KeySym nKeySym) +{ + int nMask = 0; + XModifierKeymap* pXmkMap = XGetModifierMapping(dpy); + KeyCode nKeyCode = XKeysymToKeycode(dpy, nKeySym); + if (nKeyCode == NoSymbol) + return 0; + + for (int i = 0; i < 8; ++i) + { + KeyCode nThisKeyCode = pXmkMap->modifiermap[pXmkMap->max_keypermod*i]; + if (nThisKeyCode == nKeyCode) + nMask = 1 << i; + } + XFreeModifiermap(pXmkMap); + return nMask; +} + +} + +void SalDisplay::SimulateKeyPress( USHORT nKeyCode ) +{ + if (nKeyCode == KEY_CAPSLOCK) + { + Display* dpy = GetDisplay(); + if (!InitXkb(dpy)) + return; + + unsigned int nMask = GetKeySymMask(dpy, XK_Caps_Lock); + XkbStateRec xkbState; + XkbGetState(dpy, XkbUseCoreKbd, &xkbState); + unsigned int nCapsLockState = xkbState.locked_mods & nMask; + if (nCapsLockState) + XkbLockModifiers (dpy, XkbUseCoreKbd, nMask, 0); + else + XkbLockModifiers (dpy, XkbUseCoreKbd, nMask, nMask); + } +} + +USHORT SalDisplay::GetIndicatorState() const +{ + unsigned int _state = 0; + USHORT nState = 0; + XkbGetIndicatorState(pDisp_, XkbUseCoreKbd, &_state); + + if ((_state & 0x00000001)) + nState |= INDICATOR_CAPSLOCK; + if ((_state & 0x00000002)) + nState |= INDICATOR_NUMLOCK; + if ((_state & 0x00000004)) + nState |= INDICATOR_SCROLLLOCK; + + return nState; +} + String SalDisplay::GetKeyNameFromKeySym( KeySym nKeySym ) const { String aRet; diff --git a/vcl/unx/source/window/salframe.cxx b/vcl/unx/source/window/salframe.cxx index b0248662a2a2..cb0b7b08f8ec 100644 --- a/vcl/unx/source/window/salframe.cxx +++ b/vcl/unx/source/window/salframe.cxx @@ -2849,6 +2849,18 @@ SalFrame::SalPointerState X11SalFrame::GetPointerState() return aState; } +SalFrame::SalIndicatorState X11SalFrame::GetIndicatorState() +{ + SalIndicatorState aState; + aState.mnState = GetX11SalData()->GetDisplay()->GetIndicatorState(); + return aState; +} + +void X11SalFrame::SimulateKeyPress( USHORT nKeyCode ) +{ + GetX11SalData()->GetDisplay()->SimulateKeyPress(nKeyCode); +} + long X11SalFrame::HandleMouseEvent( XEvent *pEvent ) { SalMouseEvent aMouseEvt; diff --git a/vcl/win/inc/salframe.h b/vcl/win/inc/salframe.h index f9aa8ef9dc4b..b2092943f5ef 100644 --- a/vcl/win/inc/salframe.h +++ b/vcl/win/inc/salframe.h @@ -135,6 +135,8 @@ public: virtual void Beep( SoundType eSoundType ); virtual const SystemEnvData* GetSystemData() const; virtual SalPointerState GetPointerState(); + virtual SalIndicatorState GetIndicatorState(); + virtual void SimulateKeyPress( USHORT nKeyCode ); virtual void SetParent( SalFrame* pNewParent ); virtual bool SetPluginParent( SystemParentData* pNewParent ); virtual void SetBackgroundBitmap( SalBitmap* ); diff --git a/vcl/win/source/window/salframe.cxx b/vcl/win/source/window/salframe.cxx index f0ca1d68ef41..081bd4827a9b 100644 --- a/vcl/win/source/window/salframe.cxx +++ b/vcl/win/source/window/salframe.cxx @@ -3227,6 +3227,41 @@ SalFrame::SalPointerState WinSalFrame::GetPointerState() // ----------------------------------------------------------------------- +SalFrame::SalIndicatorState WinSalFrame::GetIndicatorState() +{ + SalIndicatorState aState; + aState.mnState = 0; + if (::GetKeyState(VK_CAPITAL)) + aState.mnState |= INDICATOR_CAPSLOCK; + + if (::GetKeyState(VK_NUMLOCK)) + aState.mnState |= INDICATOR_NUMLOCK; + + if (::GetKeyState(VK_SCROLL)) + aState.mnState |= INDICATOR_SCROLLLOCK; + + return aState; +} + +void WinSalFrame::SimulateKeyPress( USHORT nKeyCode ) +{ + BYTE nVKey = 0; + switch (nKeyCode) + { + case KEY_CAPSLOCK: + nVKey = VK_CAPITAL; + break; + } + + if (nVKey > 0 && nVKey < 255) + { + ::keybd_event(nVKey, 0x45, KEYEVENTF_EXTENDEDKEY, 0); + ::keybd_event(nVKey, 0x45, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0); + } +} + +// ----------------------------------------------------------------------- + void WinSalFrame::SetBackgroundBitmap( SalBitmap* ) { } |