📄 keyboardappview.cpp
字号:
/* $Id: KeyboardAppView.cpp,v 1.30 2003/11/12 07:48:15 chrisf Exp $ *//* Copyright (c) 2003 Chris Faherty and others *//*This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/#include <eiklabel.h>#include <eikrted.h>#include <eikenv.h>#include <qikutils.h>#include <apgtask.h>#include <coeaui.h>#include <barsread.h> // for resource reader#include <Keyboard.rsg>#include <string.h>#include "KeyboardAppView.h"#include "KeyboardLayouts.h"#include "Keyboard.pan"const unsigned char layout_offsets[] = { 0x1b, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x32, 0x18, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x44, 0x45, 0x46, 0x47, 0x56, 0x57, 0x58, 0x03, 0x10, 0x2c, 0x2d, 0x2e, 0x2f, 0x4c, 0x4d, 0x4e, 0x48, 0x59, 0x3a, 0x1a, 0x08, 0x23, 0x22, 0x17, 0x37, 0x24, 0x51, 0x52, 0x53, 0x50};// Standard Epoc construction sequenceCKeyboardAppView *CKeyboardAppView::NewL(const TRect &aRect){ CKeyboardAppView *self = CKeyboardAppView::NewLC(aRect); CleanupStack::Pop(self); return self;}CKeyboardAppView *CKeyboardAppView::NewLC(const TRect &aRect){ CKeyboardAppView *self = new (ELeave)CKeyboardAppView; CleanupStack::PushL(self); self->ConstructL(aRect); return self;}void CKeyboardAppView::SetModel(CKeyboardAppModel *aModel){ iModel = aModel;}int CKeyboardAppView::getKeyboardModel(){ return keyboard_model;}int CKeyboardAppView::getKeyboardLayout(){ return keyboard_layout;}void CKeyboardAppView::setKeyboardModel(int model){ keyboard_model= model;}void CKeyboardAppView::setKeyboardLayout(int layout){ keyboard_layout= layout; if (keyboard_model == THINKOUTSIDE_MODEL) { switch(keyboard_layout) { case US_LAYOUT: initThinkoutsideLayout(layout_us_plain, layout_us_shifted, layout_us_func, layout_us_func2); break; case FR_LAYOUT: initThinkoutsideLayout(layout_fr_plain, layout_fr_shifted, layout_fr_func, layout_fr_func2); break; case DE_LAYOUT: initThinkoutsideLayout(layout_de_plain, layout_de_shifted, layout_de_func, layout_de_func2); break; case NO_LAYOUT: initThinkoutsideLayout(layout_no_plain, layout_no_shifted, layout_no_func, layout_no_func2); break; case PT_LAYOUT: initThinkoutsideLayout(layout_pt_plain, layout_pt_shifted, layout_pt_func, layout_pt_func2); break; } }}void CKeyboardAppView::ConstructL(const TRect &aRect){ // Definitions const TPoint KLabelPosition = TPoint(10, 10); const TSize KLabelSize = TSize(180, 70); const TPoint KOutputPosition = TPoint(10, 85); const TSize KOutputSize = TSize(180, 80); CreateWindowL(); TResourceReader reader; iCoeEnv->CreateResourceReaderLC(reader, R_ABOUT_LABEL); iStatusWindow = new (ELeave)CEikLabel(); iStatusWindow->SetContainerWindowL(*this); iStatusWindow->ConstructFromResourceL(reader); CleanupStack::PopAndDestroy(); // Resource reader iStatusWindow->SetFocus(ETrue); iStatusWindow->SetExtent(KLabelPosition, KLabelSize); // iStatusWindow->SetFont(LatinPlain12()); iCoeEnv->CreateResourceReaderLC(reader, R_TEST_RTEXTED); iOutputWindow = new (ELeave)CEikRichTextEditor(); iOutputWindow->SetContainerWindowL(*this); iOutputWindow->ConstructFromResourceL(reader); CleanupStack::PopAndDestroy(); // Resource reader iOutputWindow->SetFocus(ETrue); iOutputWindow->SetExtent(KOutputPosition, KOutputSize); SetRect(aRect); ActivateL(); iTimer = CPeriodic::NewL(CActive::EPriorityStandard); iForceBreakTimer = CPeriodic::NewL(CActive::EPriorityStandard);}CKeyboardAppView::CKeyboardAppView(){ // defaults keyboard_model = THINKOUTSIDE_MODEL; setKeyboardLayout(US_LAYOUT); }CKeyboardAppView::~CKeyboardAppView(){ iTimer->Cancel(); delete iTimer; iTimer = NULL; iForceBreakTimer->Cancel(); ForceBreakTick(this); /* better do a forcebreak to be safe */ delete iForceBreakTimer; iForceBreakTimer = NULL; delete iStatusWindow; iStatusWindow = NULL; delete iOutputWindow; iOutputWindow = NULL;}void CKeyboardAppView::initThinkoutsideLayout(const int * layout_plain,const int * layout_shifted,const int * layout_func,const int * layout_func2){ for(unsigned int i=0;i<sizeof(layout_offsets);i++) { int offset = layout_offsets[i]; thinkoutside_plain[offset] = layout_plain[i]; thinkoutside_shifted[offset] = layout_shifted[i]; thinkoutside_func[offset] = layout_func[i]; thinkoutside_func2[offset] = layout_func2[i]; } }void CKeyboardAppView::Init(){ shift = capslock = ctrl = alt = func = pt_shift = num_shift = false; thinkoutside_state = 0; lastraw = 0; lastscode = -1; iOutputWindow->Text()->Reset(); iOutputWindow->HandleTextChangedL(); iOutputWindow->SetCursorPosL(0, EFalse);}// Draw this application's view to the screenvoid CKeyboardAppView::Draw(const TRect & aRect) const{ // Clear the screen CWindowGc & gc = SystemGc(); gc.Clear(aRect);}TInt CKeyboardAppView::CountComponentControls() const{ return 2;}CCoeControl *CKeyboardAppView::ComponentControl(TInt aIndex) const{ switch (aIndex) { case 0: return iStatusWindow; case 1: return iOutputWindow; default: User::Panic(KPanicKeyboard, EKeyboardAppView); return 0; }}TKeyResponse CKeyboardAppView::OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType){ return iOutputWindow->OfferKeyEventL(aKeyEvent, aType);}void CKeyboardAppView::Incoming(TDesC8 &buf){ int i; switch (keyboard_model) { case POCKETOP_MODEL: for (i=0; i < buf.Length(); i++) pocketop(buf[i], false); break; case TARGUS_MODEL: for (i=0; i < buf.Length(); i++) targus(buf[i], false); break; default: for (i=0; i < buf.Length(); i++) thinkoutside(buf[i], false); break; } User::ResetInactivityTime(); /* keep backlight on */ tick = 0; iTimer->Cancel(); /* 10 second periodic timer */ iTimer->Start(10*1000*1000, 10*1000*1000, TCallBack(Tick, this));}TInt CKeyboardAppView::Tick(TAny *aObject){ CKeyboardAppView *taui=(CKeyboardAppView *)aObject; if (++(taui->tick) < 3) { /* 30 seconds */ User::ResetInactivityTime(); /* keep backlight on */ return 1; } return 0;}TInt CKeyboardAppView::ForceBreakTick(TAny *aObject){ CKeyboardAppView *taui=(CKeyboardAppView *)aObject; switch (taui->keyboard_model) { case TARGUS_MODEL: taui->targus(0, true); break; case POCKETOP_MODEL: taui->pocketop(0, true); break; default: taui->thinkoutside(0, true); } return 0;}void CKeyboardAppView::pocketop(unsigned char raw, TBool forcebreak){ unsigned char cook; TRawEvent aEvent; CCoeEnv *ccoeenv=CCoeEnv::Static(); if (forcebreak) { raw = (unsigned char)(lastraw|0x80); /* force break code */ } lastraw = raw; cook = (unsigned char)(raw&0x7f); if (cook >= sizeof(pockettop_lut)) return; TInt code=pockettop_lut[cook]; TInt scode=0; switch (code) { case EKeyLeftShift: shift = (bool)!(raw&0x80); code = 0; break; case EKeyRightShift: shift = (bool)!(raw&0x80); code = 0; break; case EKeyRightFunc: pt_shift = (bool)!(raw&0x80); code = 0; break; case EKeyNumLock: if(shift) { if (!(raw&0x80)) num_shift = !num_shift; /* toggle */ } else { num_shift = (bool)!(raw&0x80); } code = 0; break; case EKeyCapsLock: if (!(raw&0x80)) capslock = !capslock; /* toggle */ code = 0; break; case EKeyLeftCtrl: ctrl = (bool)!(raw&0x80); code = EKeyLeftCtrl; break; case EKeyLeftAlt: alt = (bool)!(raw&0x80); code = EKeyLeftAlt; break; case EKeyLeftFunc: func = (bool)!(raw&0x80); //code = 0; /* i need this for later, and then i zero it */ break; } if (raw&0x80) { /* high-bit on is break code */ /* send keyup event */ aEvent.Set(TRawEvent::EKeyUp, scode); ccoeenv->WsSession().SimulateRawEvent(aEvent); return; } if (!code && !scode) return; /* make it into control chars if needed */ if (ctrl) { if ((code >= 'a') && (code <= 'z')) code = code-'a'+1; if ((code >= '[') && (code <= '_')) code = code-'A'; } if (shift) { /* other chars */ switch (code) { case '-': code = '_'; break; case ';': code = ':'; break; case ',': code = '<'; break; case '.': code = '>'; break; } } /* func keys */ if (func) { switch (code) { case EKeyUpArrow: code = EKeyPageUp; break; case EKeyLeftArrow: code = EKeyHome; break; case EKeyDownArrow: code = EKeyPageDown; break; case EKeyRightArrow: code = EKeyEnd; break; case EKeyDevice1: code = EKeyDevice9; break; case EKeyDevice2: code = EKeyDevice3; break; case EKeyEnter: code = EKeyDevice8; break; } } /* punct keys */ if (pt_shift) { switch (code) { case 'q': code = '!'; break; case 'w': code = '@'; break; case 'e': code = '#'; break; case 'r': code = '$'; break; case 't': code = '%'; break; case 'y': code = '^'; break; case 'u': code = '&'; break; case 'i': code = '*'; break; case 'o': code = '('; break; case 'p': code = ')'; break; case '-': code = '+'; break; case 'a': code = '`'; break; case 's': code = '~'; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -