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

📄 guitexteditctrl.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 3 页
字号:
      {
         // Added UNIX emacs key bindings - just a little hack here...

         // BJGTODO: Add vi bindings.

         // Ctrl-B - move one character back
         case KEY_B:
         { GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_LEFT;
            return(onKeyDown(new_event));
         }

         // Ctrl-F - move one character forward
         case KEY_F:
         { GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_RIGHT;
            return(onKeyDown(new_event));
         }

         // Ctrl-A - move to the beginning of the line
         case KEY_A:
         { GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_HOME;
            return(onKeyDown(new_event));
         }

         // Ctrl-E - move to the end of the line
         case KEY_E:
         { GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_END;
            return(onKeyDown(new_event));
         }

         // Ctrl-P - move backward in history
         case KEY_P:
         { GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_UP;
            return(onKeyDown(new_event));
         }

         // Ctrl-N - move forward in history
         case KEY_N:
         { GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_DOWN;
            return(onKeyDown(new_event));
         }

         // Ctrl-D - delete under cursor
         case KEY_D:
         { GuiEvent new_event;
            new_event.modifier = 0;
            new_event.keyCode = KEY_DELETE;
            return(onKeyDown(new_event));
         }

         case KEY_U:
         { GuiEvent new_event;
            new_event.modifier = SI_CTRL;
            new_event.keyCode = KEY_DELETE;
            return(onKeyDown(new_event));
         }

         // End added UNIX emacs key bindings

         case KEY_C:
         case KEY_X:
            // Don't copy/cut password field!
            if(mPasswordText)
               return true;

            UTF8 buf[GuiTextCtrl::MAX_STRING_LENGTH + 1];
            if (mBlockEnd > 0)
            {
               //save the current state
               saveUndoState();

               //copy the text to the clipboard
               StringBuffer tmp = mTextBuffer.substring(mBlockStart, mBlockEnd - mBlockStart);
               FrameTemp<UTF8> clipBuff((mBlockEnd-mBlockStart) * 3 + 1);
               tmp.get(clipBuff, (mBlockEnd-mBlockStart) * 3 + 1);

               Platform::setClipboard((char*)(UTF8*)clipBuff);

               //if we pressed ctrl-x, we need to cut the selected text from the control...
               if (event.keyCode == KEY_X)
               {
                  mTextBuffer.cut(mBlockStart, mBlockEnd - mBlockStart);
                  mCursorPos = mBlockStart;
               }

               mBlockStart = 0;
               mBlockEnd = 0;
            }

            return true;

         case KEY_V:
         {
            UTF8 buf[GuiTextCtrl::MAX_STRING_LENGTH + 1];

            //first, make sure there's something in the clipboard to copy...
            const char *temp = (const char*)Platform::getClipboard();
            UTF8 *clipBuf = (UTF8*)GuiMLTextCtrl::stripControlChars(temp);
            if (dStrlen(clipBuf) <= 0)
               return true;

            //save the current state
            saveUndoState();

            //delete anything hilited
            if (mBlockEnd > 0)
            {
               mTextBuffer.cut(mBlockStart, mBlockEnd - mBlockStart);
               mCursorPos = mBlockStart;
               mBlockStart = 0;
               mBlockEnd = 0;
            }

            StringBuffer tmp(clipBuf);
            S32 pasteLen = tmp.length();
            if ((stringLen + pasteLen) > mMaxStrLen)
            {
               pasteLen = mMaxStrLen - stringLen;

               // Trim down to be pasteLen long.
               tmp.cut(pasteLen, tmp.length() - pasteLen);
            }


            if (mCursorPos == stringLen)
            {
               mTextBuffer.append(tmp);
            }
            else
            {
               mTextBuffer.insert(mCursorPos, tmp);
            }
            mCursorPos += tmp.length();

            return true;
         }

         case KEY_Z:
            if (! mDragHit)
            {
                StringBuffer tempBuffer;
                S32 tempBlockStart;
                S32 tempBlockEnd;
                S32 tempCursorPos;

                //save the current
                tempBuffer.set(&mTextBuffer);
                tempBlockStart = mBlockStart;
                tempBlockEnd   = mBlockEnd;
                tempCursorPos  = mCursorPos;

                //restore the prev
                mTextBuffer.set(&mUndoText);
                mBlockStart = mUndoBlockStart;
                mBlockEnd   = mUndoBlockEnd;
                mCursorPos  = mUndoCursorPos;

                //update the undo
                mUndoText.set(&tempBuffer);
                mUndoBlockStart = tempBlockStart;
                mUndoBlockEnd   = tempBlockEnd;
                mUndoCursorPos  = tempCursorPos;

                return true;
             }

         case KEY_DELETE:
         case KEY_BACKSPACE:
            //save the current state
            saveUndoState();

            //delete everything in the field
            mTextBuffer.set("");
            mCursorPos  = 0;
            mBlockStart = 0;
            mBlockEnd  = 0;

            execConsoleCallback();

            return true;
#ifdef TGE_RPG
			default:
				return false;
#endif
      }
   }
   else
   {
      switch(event.keyCode)
      {
         case KEY_ESCAPE:
            if ( mEscapeCommand[0] )
            {
               Con::evaluate( mEscapeCommand );
               return( true );
            }
            return( Parent::onKeyDown( event ) );

         case KEY_RETURN:
         case KEY_NUMPADENTER:
            //first validate
            if (mProfile->mReturnTab)
            {
               onLoseFirstResponder();
            }

            updateHistory(&mTextBuffer, true);
            mHistoryDirty = false;

            //next exec the alt console command
            if ( mAltConsoleCommand[0] )
            {
               char buf[16];
               dSprintf( buf, sizeof( buf ), "%d", getId() );
               Con::setVariable( "$ThisControl", buf );
               Con::evaluate( mAltConsoleCommand, false );
            }

            if (mProfile->mReturnTab)
            {
               GuiCanvas *root = getRoot();
               if (root)
               {
                  root->tabNext();
                  return true;
               }
            }
            return true;

         case KEY_UP:
         {
            if(mHistoryDirty)
            {
               updateHistory(&mTextBuffer, false);
               mHistoryDirty = false;
            }

            mHistoryIndex--;
            
            if(mHistoryIndex >= 0 && mHistoryIndex <= mHistoryLast)
               setText((char*)mHistoryBuf[mHistoryIndex]);
            else if(mHistoryIndex < 0)
               mHistoryIndex = 0;
            
            return true;
         }

         case KEY_DOWN:
            if(mHistoryDirty)
            {
               updateHistory(&mTextBuffer, false);
               mHistoryDirty = false;
            }
            mHistoryIndex++;
            if(mHistoryIndex > mHistoryLast)
            {
               mHistoryIndex = mHistoryLast + 1;
               setText("");
            }
            else
               setText((char*)mHistoryBuf[mHistoryIndex]);
            return true;

         case KEY_LEFT:
            mBlockStart = 0;
            mBlockEnd = 0;
            if (mCursorPos > 0)
            {
                mCursorPos--;
            }
            return true;

         case KEY_RIGHT:
            mBlockStart = 0;
            mBlockEnd = 0;
            if (mCursorPos < stringLen)
            {
                mCursorPos++;
            }
            return true;

         case KEY_BACKSPACE:
dealWithBackspace:
            //save the current state
            saveUndoState();

            if (mBlockEnd > 0)
            {
               mTextBuffer.cut(mBlockStart, mBlockEnd-mBlockStart);
               mCursorPos  = mBlockStart;
               mBlockStart = 0;
               mBlockEnd   = 0;
               mHistoryDirty = true;

               // Execute the console command!
               execConsoleCallback();

            }
            else if (mCursorPos > 0)
            {
               mTextBuffer.cut(mCursorPos-1, 1);
               mCursorPos--;
               mHistoryDirty = true;

               // Execute the console command!
               execConsoleCallback();
            }
            return true;

         case KEY_DELETE:
            //save the current state
            saveUndoState();

            if (mBlockEnd > 0)
            {
               mHistoryDirty = true;
               mTextBuffer.cut(mBlockStart, mBlockEnd-mBlockStart);

               mCursorPos = mBlockStart;
               mBlockStart = 0;
               mBlockEnd = 0;

               // Execute the console command!
               execConsoleCallback();
            }
            else if (mCursorPos < stringLen)
            {
               mHistoryDirty = true;
               mTextBuffer.cut(mCursorPos, 1);

               // Execute the console command!
               execConsoleCallback();
            }
            return true;

         case KEY_INSERT:
            mInsertOn = !mInsertOn;
            return true;

         case KEY_HOME:
            mBlockStart = 0;
            mBlockEnd   = 0;
            mCursorPos  = 0;
            return true;

         case KEY_END:
            mBlockStart = 0;
            mBlockEnd   = 0;
            mCursorPos  = stringLen;
            return true;

         }
   }

   switch ( event.keyCode )
   {
      case KEY_TAB:
         if ( mTabComplete )
         {
            Con::executef( this, 2, "onTabComplete", "0" );
            return( true );
         }
      case KEY_UP:
      case KEY_DOWN:
      case KEY_ESCAPE:
         return Parent::onKeyDown( event );
   }

   if ( mFont->isValidChar( event.ascii ) )
   {
      // Get the character ready to add to a UTF8 string.
      UTF16 conv[2] = { event.ascii, 0 };
      StringBuffer convertedChar(conv);

#if 0
      {
         UTF8 pony[10];
         convertedChar.get(pony, 10);
         Con::printf("Got key '%s' (0x%x)", pony, event.ascii );
      }
#endif

      //see if it's a number field
      if ( mProfile->mNumbersOnly )
      {
         if (event.ascii == '-')
         {
            //a minus sign only exists at the beginning, and only a single minus sign
            if ( mCursorPos != 0 )
            {
               playDeniedSound();
               return true;
            }

            if ( mInsertOn && ( mTextBuffer.getChar(0) == '-' ) ) 
            {
               playDeniedSound();
               return true;
            }
         }
         // BJTODO: This is probably not unicode safe.
         else if ( event.ascii < '0' || event.ascii > '9' )
         {
            playDeniedSound();
            return true;
         }
      }

      //save the current state
      saveUndoState();

⌨️ 快捷键说明

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