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

📄 kwqevent.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2001, 2002 Apple Computer, Inc.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */#include "KWQEvent.h"#include "KWQLogging.h"#include <gdk/gdkevents.h>#include <gdk/gdkkeysyms.h>// In GDK we don't have autorepeat property for key event// so tune _autorepeat_thresholdstatic const unsigned int _autorepeat_threshold = 500; // microsecondsstatic QString keyIdentifierForKeyEvent(GdkEventKey *event){    QString s;    if (event->string)	s = QString::fromUtf8(event->string);	    if (s.length() != 1) {        LOG(Events, "received an unexpected number of characters in key event: %u", s.length());        return "Unidentified";    }    guint c = event->keyval;    switch (c) {        // Each identifier listed in the DOM spec is listed here.        // Many are simply commented out since they do not appear on standard Macintosh keyboards        // or are on a key that doesn't have a corresponding character.        // "Accept"        // "AllCandidates"        // "Alt"        // "Apps"        // "BrowserBack"        // "BrowserForward"        // "BrowserHome"        // "BrowserRefresh"        // "BrowserSearch"        // "BrowserStop"        // "CapsLock"        // "Clear"        case GDK_Clear:            return "Clear";        // "CodeInput"        // "Compose"        // "Control"        // "Crsel"        // "Convert"        // "Copy"        // "Cut"        // "Down"        case GDK_Down:            return "Down";        // "End"        case GDK_End:            return "End";        // "Enter"        case GDK_Return: case GDK_KP_Enter: // Macintosh calls the one on the main keyboard Return, but Windows calls it Enter, so we'll do the same for the DOM            return "Enter";        // "EraseEof"        // "Execute"        case GDK_Execute:            return "Execute";        // "Exsel"        // "F1"        case GDK_F1:            return "F1";        // "F2"        case GDK_F2:            return "F2";        // "F3"        case GDK_F3:            return "F3";        // "F4"        case GDK_F4:            return "F4";        // "F5"        case GDK_F5:            return "F5";        // "F6"        case GDK_F6:            return "F6";        // "F7"        case GDK_F7:            return "F7";        // "F8"        case GDK_F8:            return "F8";        // "F9"        case GDK_F9:            return "F9";        // "F10"        case GDK_F10:            return "F10";        // "F11"        case GDK_F11:            return "F11";        // "F12"        case GDK_F12:            return "F12";        // "F13"        case GDK_F13:            return "F13";        // "F14"        case GDK_F14:            return "F14";        // "F15"        case GDK_F15:            return "F15";        // "F16"        case GDK_F16:            return "F16";        // "F17"        case GDK_F17:            return "F17";        // "F18"        case GDK_F18:            return "F18";        // "F19"        case GDK_F19:            return "F19";        // "F20"        case GDK_F20:            return "F20";        // "F21"        case GDK_F21:            return "F21";        // "F22"        case GDK_F22:            return "F22";        // "F23"        case GDK_F23:            return "F23";        // "F24"        case GDK_F24:            return "F24";        // "FinalMode"        // "Find"        case GDK_Find:            return "Find";        // "ForwardDelete" (Non-standard)        case GDK_Delete:            return "ForwardDelete";        // "FullWidth"        // "HalfWidth"        // "HangulMode"        // "HanjaMode"        // "Help"        case GDK_Help:            return "Help";        // "Hiragana"        // "Home"        case GDK_Home:            return "Home";        // "Insert"        case GDK_Insert:            return "Insert";        // "JapaneseHiragana"        // "JapaneseKatakana"        // "JapaneseRomaji"        // "JunjaMode"        // "KanaMode"        // "KanjiMode"        // "Katakana"        // "LaunchApplication1"        // "LaunchApplication2"        // "LaunchMail"        // "Left"        case GDK_Left:            return "Left";        // "Meta"        // "MediaNextTrack"        // "MediaPlayPause"        // "MediaPreviousTrack"        // "MediaStop"        // "ModeChange"        case GDK_Mode_switch:            return "ModeChange";        // "Nonconvert"        // "NumLock"        // "PageDown"        case GDK_Page_Down:            return "PageDown";        // "PageUp"        case GDK_Page_Up:            return "PageUp";        // "Paste"        // "Pause"        case GDK_Pause:            return "Pause";        // "Play"        // "PreviousCandidate"        // "PrintScreen"        case GDK_Print:            return "PrintScreen";        // "Process"        // "Props"        // "Right"        case GDK_Right:            return "Right";        // "RomanCharacters"        // "Scroll"        // "Select"        // "SelectMedia"        // "Shift"        // "Stop"        //case GDK_Stop:        //    return "Stop";        // "Up"        case GDK_Up:            return "Up";        // "Undo"        case GDK_Undo:            return "Undo";        // "VolumeDown"        // "VolumeMute"        // "VolumeUp"        // "Win"        // "Zoom"        // Turn 0x7F into 0x08, because backspace needs to always be 0x08.        case 0x7F:            return "U+000008";        default:            return QString().sprintf( "U+%06X", s.at(0).upper().unicode() );    }}static bool isKeypadEvent(GdkEvent *event){    // Check that this is the type of event that has a keyCode.    switch (event->type) {    case GDK_KEY_PRESS:    case GDK_KEY_RELEASE:	break;    default:            return false;    }    switch ( ((GdkEventKey*)event)->keyval) {    case GDK_KP_Space:    case GDK_KP_Tab:    case GDK_KP_Enter:    case GDK_KP_F1:    case GDK_KP_F2:    case GDK_KP_F3:    case GDK_KP_F4:    case GDK_KP_Home:    case GDK_KP_Left:    case GDK_KP_Up:    case GDK_KP_Right:    case GDK_KP_Down:	//case GDK_KP_Prior:    case GDK_KP_Page_Up:	//case GDK_KP_Next:    case GDK_KP_Page_Down:    case GDK_KP_End:    case GDK_KP_Begin:    case GDK_KP_Insert:    case GDK_KP_Delete:    case GDK_KP_Equal:    case GDK_KP_Multiply:    case GDK_KP_Add:    case GDK_KP_Separator:    case GDK_KP_Subtract:    case GDK_KP_Decimal:    case GDK_KP_Divide:    case GDK_KP_0:    case GDK_KP_1:    case GDK_KP_2:    case GDK_KP_3:    case GDK_KP_4:    case GDK_KP_5:    case GDK_KP_6:    case GDK_KP_7:    case GDK_KP_8:    case GDK_KP_9:    	return true;    }         return false;}static int WindowsKeyCodeForKeyEvent(GdkEventKey *event){    switch (event->keyval) {        // VK_CLEAR (0C) CLEAR key        case GDK_Clear: return 0x0C;        // VK_NUMPAD0 (60) Numeric keypad 0 key        case GDK_KP_0: return 0x60;        // VK_NUMPAD1 (61) Numeric keypad 1 key        case GDK_KP_1: return 0x61;        // VK_NUMPAD2 (62) Numeric keypad 2 key        case GDK_KP_2: return 0x62;        // VK_NUMPAD3 (63) Numeric keypad 3 key        case GDK_KP_3: return 0x63;        // VK_NUMPAD4 (64) Numeric keypad 4 key        case GDK_KP_4: return 0x64;        // VK_NUMPAD5 (65) Numeric keypad 5 key        case GDK_KP_5: return 0x65;        // VK_NUMPAD6 (66) Numeric keypad 6 key        case GDK_KP_6: return 0x66;        // VK_NUMPAD7 (67) Numeric keypad 7 key        case GDK_KP_7: return 0x67;        // VK_NUMPAD8 (68) Numeric keypad 8 key        case GDK_KP_8: return 0x68;        // VK_NUMPAD9 (69) Numeric keypad 9 key        case GDK_KP_9: return 0x69;        // VK_MULTIPLY (6A) Multiply key        case GDK_KP_Multiply: return 0x6A;        // VK_ADD (6B) Add key        case GDK_KP_Add: return 0x6B;        // VK_SUBTRACT (6D) Subtract key        case GDK_KP_Subtract: return 0x6D;        // VK_DECIMAL (6E) Decimal key        case GDK_KP_Decimal: return 0x6E;        // VK_DIVIDE (6F) Divide key        case GDK_KP_Divide: return 0x6F;     }    QString s;    if (event->string)	s = QString::fromUtf8( event->string );        if (s.length() != 1) {        return 0;    }    switch (event->keyval) {        // VK_LBUTTON (01) Left mouse button        // VK_RBUTTON (02) Right mouse button        // VK_CANCEL (03) Control-break processing        // VK_MBUTTON (04) Middle mouse button (three-button mouse)        // VK_XBUTTON1 (05)        // VK_XBUTTON2 (06)        // VK_BACK (08) BACKSPACE key        case GDK_BackSpace: case 0x7F: return 0x08;        // VK_TAB (09) TAB key        case GDK_Tab: return 0x09;        // VK_CLEAR (0C) CLEAR key        // handled by key code above        // VK_RETURN (0D)        case GDK_Clear: case 3: return 0x0D;        // VK_SHIFT (10) SHIFT key        // VK_CONTROL (11) CTRL key        // VK_MENU (12) ALT key        // VK_PAUSE (13) PAUSE key        case GDK_Pause: return 0x13;        // VK_CAPITAL (14) CAPS LOCK key        // VK_KANA (15) Input Method Editor (IME) Kana mode        // VK_HANGUEL (15) IME Hanguel mode (maintained for compatibility; use VK_HANGUL)        // VK_HANGUL (15) IME Hangul mode        // VK_JUNJA (17) IME Junja mode        // VK_FINAL (18) IME final mode        // VK_HANJA (19) IME Hanja mode        // VK_KANJI (19) IME Kanji mode        // VK_ESCAPE (1B) ESC key        case GDK_Escape: return 0x1B;

⌨️ 快捷键说明

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