Ticket #511: CInputEnhancementsAndFixes.patch

File CInputEnhancementsAndFixes.patch, 23.2 KB (added by Kenny Long, 13 years ago)
  • binaries/data/config/default.cfg

     
    129129hotkey.console.toggle = BackQuote, F9       ; Open/close console
    130130hotkey.console.copy = "Ctrl+C"              ; Copy from console to clipboard
    131131hotkey.console.paste = "Ctrl+V"             ; Paste clipboard to console
     132hotkey.console.cut = "Ctrl+X"               ; Cut the selected text and copy it to the clipboard
    132133
    133134; > ENTITY SELECTION
    134135hotkey.selection.add = Shift                ; Add units to selection
     
    186187; > HOTKEYS ONLY
    187188hotkey.chat = Return                        ; Toggle chat window
    188189
     190; > GUI TEXTBOX HOTKEYS
     191hotkey.text.delete.word.left = "Ctrl+Backspace"    ; Used in text input boxes to delete word to the left of cursor
     192hotkey.text.delete.word.right = "Ctrl+Del"         ; Used in text input boxes to delete word to the right of cursor
     193hotkey.text.move.word.left = "Ctrl+LeftArrow"      ; Move cursor to start of word to the left of cursor
     194hotkey.text.move.word.right = "Ctrl+RightArrow"    ; Move cursor to start of word to the left of cursor
     195
    189196; > PROFILER
    190197hotkey.profile.toggle = "F11"               ; Enable/disable real-time profiler
    191198hotkey.profile.save = "Shift+F11"           ; Save current profiler data to logs/profile.txt
  • source/gui/CInput.cpp

     
    3434#include "ps/CLogger.h"
    3535#include "ps/Globals.h"
    3636
     37#include <sstream>
    3738
    3839//-------------------------------------------------------------------
    3940//  Constructor / Destructor
     
    7071{
    7172    ENSURE(m_iBufferPos != -1);
    7273
    73     // Since the GUI framework doesn't handle to set settings
    74     //  in Unicode (CStrW), we'll simply retrieve the actual
    75     //  pointer and edit that.
    76     CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    77 
    7874    if (ev->ev.type == SDL_HOTKEYDOWN)
    7975    {
    80         std::string hotkey = static_cast<const char*>(ev->ev.user.data1);
    81         if (hotkey == "console.paste")
    82         {
    83             wchar_t* text = sys_clipboard_get();
    84             if (text)
    85             {
    86                 if (m_iBufferPos == (int)pCaption->length())
    87                     *pCaption += text;
    88                 else
    89                     *pCaption = pCaption->Left(m_iBufferPos) + text +
    90                     pCaption->Right((long) pCaption->length()-m_iBufferPos);
    91 
    92                 UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
    93 
    94                 m_iBufferPos += (int)wcslen(text);
    95 
    96                 sys_clipboard_free(text);
    97             }
    98 
    99             return IN_HANDLED;
    100         }
     76        return(ManuallyHandleHotkeyEvent(ev));
    10177    }
    10278    else if (ev->ev.type == SDL_KEYDOWN)
    10379    {
     80        // Since the GUI framework doesn't handle to set settings
     81        //  in Unicode (CStrW), we'll simply retrieve the actual
     82        //  pointer and edit that.
     83        CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     84        bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT];
     85
    10486        int szChar = ev->ev.key.keysym.sym;
    10587        wchar_t cooked = (wchar_t)ev->ev.key.keysym.unicode;
    10688
    10789        switch (szChar)
    10890        {
    109             case '\t':
     91            case SDLK_TAB: // '\t'
    11092                /* Auto Complete */
    11193                // TODO Gee: (2004-09-07) What to do with tab?
    11294                break;
    11395
    114             case '\b':
    115                 m_WantedX=0.f;
     96            case SDLK_BACKSPACE: // '\b'
     97                m_WantedX=0.0f;
    11698
    11799                if (SelectingText())
    118100                    DeleteCurSelection();
     
    120102                {
    121103                    m_iBufferPos_Tail = -1;
    122104
    123                     if (pCaption->empty() ||
    124                         m_iBufferPos == 0)
     105                    if (pCaption->empty() || m_iBufferPos == 0)
     106                    {
    125107                        break;
    126 
    127                     if (m_iBufferPos == (int)pCaption->length())
    128                         *pCaption = pCaption->Left( (long) pCaption->length()-1);
     108                    }
    129109                    else
    130                         *pCaption = pCaption->Left( m_iBufferPos-1 ) +
    131                                     pCaption->Right( (long) pCaption->length()-m_iBufferPos );
     110                    {
     111                        if (m_iBufferPos == (int)pCaption->length())
     112                            *pCaption = pCaption->Left( (long) pCaption->length()-1);
     113                        else
     114                            *pCaption = pCaption->Left( m_iBufferPos-1 ) +
     115                                        pCaption->Right( (long) pCaption->length()-m_iBufferPos );
    132116
    133                     --m_iBufferPos;
     117                        --m_iBufferPos;
    134118                   
    135                     UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
     119                        UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
     120                    }
    136121                }
    137122
    138123                UpdateAutoScroll();
    139124                break;
    140125
    141126            case SDLK_DELETE:
    142                 m_WantedX=0.f;
     127                m_WantedX=0.0f;
    143128                // If selection:
    144129                if (SelectingText())
    145130                {
     
    147132                }
    148133                else
    149134                {
    150                     if (pCaption->empty() ||
    151                         m_iBufferPos == (int)pCaption->length())
     135                    if (pCaption->empty() || m_iBufferPos == (int)pCaption->length())
     136                    {
    152137                        break;
     138                    }
     139                    else
     140                    {
     141                        *pCaption = pCaption->Left( m_iBufferPos ) +
     142                                    pCaption->Right( (long) pCaption->length()-(m_iBufferPos+1) );
    153143
    154                     *pCaption = pCaption->Left( m_iBufferPos ) +
    155                                 pCaption->Right( (long) pCaption->length()-(m_iBufferPos+1) );
    156 
    157                     UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
     144                        UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
     145                    }
    158146                }
    159147
    160148                UpdateAutoScroll();
     
    162150
    163151            case SDLK_HOME:
    164152                // If there's not a selection, we should create one now
    165                 if (!g_keys[SDLK_RSHIFT] && !g_keys[SDLK_LSHIFT])
     153                if (!shiftKeyPressed)
    166154                {
    167155                    // Make sure a selection isn't created.
    168156                    m_iBufferPos_Tail = -1;
     
    174162                }
    175163
    176164                m_iBufferPos = 0;
    177                 m_WantedX=0.f;
     165                m_WantedX=0.0f;
    178166
    179167                UpdateAutoScroll();
    180168                break;
    181169
    182170            case SDLK_END:
    183171                // If there's not a selection, we should create one now
    184                 if (!g_keys[SDLK_RSHIFT] && !g_keys[SDLK_LSHIFT])
     172                if (!shiftKeyPressed)
    185173                {
    186174                    // Make sure a selection isn't created.
    187175                    m_iBufferPos_Tail = -1;
     
    193181                }
    194182
    195183                m_iBufferPos = (long) pCaption->length();
    196                 m_WantedX=0.f;
     184                m_WantedX=0.0f;
    197185
    198186                UpdateAutoScroll();
    199187                break;
     
    221209
    222210            **/
    223211            case SDLK_LEFT:
    224                 // reset m_WantedX, very important
    225212                m_WantedX=0.f;
    226213
    227                 if (g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT] ||
    228                     !SelectingText())
     214                if (shiftKeyPressed || !SelectingText())
    229215                {
    230                     // If there's not a selection, we should create one now
    231                     if (!SelectingText() && !g_keys[SDLK_RSHIFT] && !g_keys[SDLK_LSHIFT])
     216                    if (!shiftKeyPressed)
    232217                    {
    233                         // Make sure a selection isn't created.
    234218                        m_iBufferPos_Tail = -1;
    235219                    }
    236220                    else if (!SelectingText())
    237221                    {
    238                         // Place tail at the current point:
    239222                        m_iBufferPos_Tail = m_iBufferPos;
    240223                    }
    241224
    242                     if (m_iBufferPos)
     225                    if (m_iBufferPos > 0)
    243226                        --m_iBufferPos;
    244227                }
    245228                else
     
    254237                break;
    255238
    256239            case SDLK_RIGHT:
    257                 m_WantedX=0.f;
     240                m_WantedX=0.0f;
    258241
    259                 if (g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT] ||
    260                     !SelectingText())
     242                if (shiftKeyPressed || !SelectingText())
    261243                {
    262                     // If there's not a selection, we should create one now
    263                     if (!SelectingText() && !g_keys[SDLK_RSHIFT] && !g_keys[SDLK_LSHIFT])
     244                    if (!shiftKeyPressed)
    264245                    {
    265                         // Make sure a selection isn't created.
    266246                        m_iBufferPos_Tail = -1;
    267247                    }
    268248                    else if (!SelectingText())
    269249                    {
    270                         // Place tail at the current point:
    271250                        m_iBufferPos_Tail = m_iBufferPos;
    272251                    }
    273252
    274 
    275                     if (m_iBufferPos != (int)pCaption->length())
     253                    if (m_iBufferPos < (int)pCaption->length())
    276254                        ++m_iBufferPos;
    277255                }
    278256                else
     
    308286            **/
    309287            case SDLK_UP:
    310288            {
    311                 // If there's not a selection, we should create one now
    312                 if (!g_keys[SDLK_RSHIFT] && !g_keys[SDLK_LSHIFT])
     289                if (!shiftKeyPressed)
    313290                {
    314                     // Make sure a selection isn't created.
    315291                    m_iBufferPos_Tail = -1;
    316292                }
    317293                else if (!SelectingText())
    318294                {
    319                     // Place tail at the current point:
    320295                    m_iBufferPos_Tail = m_iBufferPos;
    321296                }
    322297
     
    356331
    357332            case SDLK_DOWN:
    358333            {
    359                 // If there's not a selection, we should create one now
    360                 if (!g_keys[SDLK_RSHIFT] && !g_keys[SDLK_LSHIFT])
     334                if (!shiftKeyPressed)
    361335                {
    362                     // Make sure a selection isn't created.
    363336                    m_iBufferPos_Tail = -1;
    364337                }
    365338                else if (!SelectingText())
    366339                {
    367                     // Place tail at the current point:
    368340                    m_iBufferPos_Tail = m_iBufferPos;
    369341                }
    370342
     
    428400                }
    429401            default: //Insert a character
    430402                {
    431                 // If there's a selection, delete if first.
    432403                if (cooked == 0)
    433404                    return IN_PASS; // Important, because we didn't use any key
    434405
     
    438409                if (max_length != 0 && (int)pCaption->length() >= max_length)
    439410                    break;
    440411
    441                 m_WantedX=0.f;
     412                m_WantedX=0.0f;
    442413
    443414                if (SelectingText())
    444415                    DeleteCurSelection();
     
    465436    return IN_PASS;
    466437}
    467438
     439
     440InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
     441{
     442    CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     443    bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT];
     444
     445    std::string hotkey = static_cast<const char*>(ev->ev.user.data1);
     446    if (hotkey == "console.paste")
     447    {
     448        m_WantedX=0.0f;
     449
     450        wchar_t* text = sys_clipboard_get();
     451        if (text)
     452        {
     453            if (m_iBufferPos == (int)pCaption->length())
     454                *pCaption += text;
     455            else
     456                *pCaption = pCaption->Left(m_iBufferPos) + text +
     457                pCaption->Right((long) pCaption->length()-m_iBufferPos);
     458
     459            UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
     460
     461            m_iBufferPos += (int)wcslen(text);
     462
     463            sys_clipboard_free(text);
     464        }
     465
     466        return IN_HANDLED;
     467    }
     468    else if (hotkey == "console.copy" || hotkey == "console.cut")
     469    {
     470        m_WantedX=0.0f;
     471
     472        if (SelectingText())
     473        {
     474            int virtualFrom;
     475            int virtualTo;
     476
     477            if (m_iBufferPos_Tail >= m_iBufferPos)
     478            {
     479                virtualFrom = m_iBufferPos;
     480                virtualTo = m_iBufferPos_Tail;
     481            }
     482            else
     483            {
     484                virtualFrom = m_iBufferPos_Tail;
     485                virtualTo = m_iBufferPos;
     486            }
     487
     488            CStrW text = (pCaption->Left(virtualTo)).Right(virtualTo - virtualFrom);
     489
     490            sys_clipboard_set(&text[0]);
     491
     492            if (hotkey == "console.cut")
     493            {
     494                DeleteCurSelection();
     495            }
     496        }
     497
     498        return IN_HANDLED;
     499    }
     500    else if (hotkey == "text.delete.word.left")
     501    {
     502        m_WantedX=0.0f;
     503
     504        if (SelectingText())
     505        {
     506            DeleteCurSelection();
     507        }
     508        if (!pCaption->empty() && !m_iBufferPos == 0)
     509        {
     510            m_iBufferPos_Tail = m_iBufferPos;
     511            CStrW searchString = pCaption->Left( m_iBufferPos );
     512
     513            // If we are starting in whitespace, adjust position until we get a non whitespace
     514            while (m_iBufferPos > 0)
     515            {
     516                if (!iswspace(searchString[m_iBufferPos - 1]))
     517                    break;
     518
     519                m_iBufferPos--;
     520            }
     521               
     522            // If we end up on a puctuation char we just delete it (treat punct like a word)
     523            if (iswpunct(searchString[m_iBufferPos - 1]))
     524                m_iBufferPos--;
     525            else
     526            {
     527                // Now we are on a non white space character, adjust position to char after next whitespace char is found
     528                while (m_iBufferPos > 0)
     529                {
     530                    if (iswspace(searchString[m_iBufferPos - 1]) || iswpunct(searchString[m_iBufferPos - 1]))
     531                        break;
     532
     533                    m_iBufferPos--;
     534                }
     535            }
     536
     537            DeleteCurSelection();
     538        }
     539        return IN_HANDLED;
     540    }
     541    else if (hotkey == "text.delete.word.right")
     542    {
     543        m_WantedX=0.0f;
     544
     545        if (SelectingText())
     546        {
     547            DeleteCurSelection();
     548        }
     549        if (!pCaption->empty() && m_iBufferPos < (int)pCaption->length())
     550        {
     551            // Delete the word to the right of the cursor
     552            m_iBufferPos_Tail = m_iBufferPos;
     553
     554            // Delete chars to the right unit we hit whitespace
     555            while (++m_iBufferPos < (int)pCaption->length())
     556            {
     557                if (iswspace((*pCaption)[m_iBufferPos]) || iswpunct((*pCaption)[m_iBufferPos]))
     558                    break;
     559            }
     560
     561            // Eliminate any whitespace behind the word we just deleted
     562            while (m_iBufferPos < (int)pCaption->length())
     563            {
     564                if (!iswspace((*pCaption)[m_iBufferPos]))
     565                    break;
     566
     567                m_iBufferPos++;
     568            }
     569            DeleteCurSelection();
     570        }
     571        return IN_HANDLED;         
     572    }
     573    else if (hotkey == "text.move.word.left")
     574    {
     575        m_WantedX=0.0f;
     576               
     577        if (shiftKeyPressed || !SelectingText())
     578        {
     579            if (!shiftKeyPressed)
     580            {
     581                m_iBufferPos_Tail = -1;
     582            }
     583            else if (!SelectingText())
     584            {
     585                m_iBufferPos_Tail = m_iBufferPos;
     586            }
     587
     588            if (!pCaption->empty() && !m_iBufferPos == 0)
     589            {
     590                CStrW searchString = pCaption->Left( m_iBufferPos );
     591
     592                // If we are starting in whitespace, adjust position until we get a non whitespace
     593                while (m_iBufferPos > 0)
     594                {
     595                    if (!iswspace(searchString[m_iBufferPos - 1]))
     596                        break;
     597
     598                    m_iBufferPos--;
     599                }
     600               
     601                // If we end up on a puctuation char we just select it (treat punct like a word)
     602                if (iswpunct(searchString[m_iBufferPos - 1]))
     603                    m_iBufferPos--;
     604                else
     605                {
     606                    // Now we are on a non white space character, adjust position to char after next whitespace char is found
     607                    while (m_iBufferPos > 0)
     608                    {
     609                        if (iswspace(searchString[m_iBufferPos - 1]) || iswpunct(searchString[m_iBufferPos - 1]))
     610                            break;
     611
     612                        m_iBufferPos--;
     613                    }
     614                }
     615            }
     616        }
     617        else
     618        {
     619            if (m_iBufferPos_Tail < m_iBufferPos)
     620                m_iBufferPos = m_iBufferPos_Tail;
     621
     622            m_iBufferPos_Tail = -1;
     623        }
     624
     625        UpdateAutoScroll();
     626
     627        return IN_HANDLED;
     628    }
     629    else if (hotkey == "text.move.word.right")
     630    {
     631        m_WantedX=0.0f;
     632
     633        if (shiftKeyPressed || !SelectingText())
     634        {
     635            if (!shiftKeyPressed)
     636            {
     637                m_iBufferPos_Tail = -1;
     638            }
     639            else if (!SelectingText())
     640            {
     641                m_iBufferPos_Tail = m_iBufferPos;
     642            }
     643
     644            if (!pCaption->empty() && m_iBufferPos < (int)pCaption->length())
     645            {
     646                CStrW searchString = *pCaption;
     647
     648                // Select chars to the right until we hit whitespace
     649                while (++m_iBufferPos < (int)pCaption->length())
     650                {
     651                    if (iswspace((*pCaption)[m_iBufferPos]) || iswpunct((*pCaption)[m_iBufferPos]))
     652                        break;
     653                }
     654
     655                // Also select any whitespace following the word we just selected
     656                while (m_iBufferPos < (int)pCaption->length())
     657                {
     658                    if (!iswspace((*pCaption)[m_iBufferPos]))
     659                        break;
     660
     661                    m_iBufferPos++;
     662                }
     663            }
     664        }
     665        else
     666        {
     667            if (m_iBufferPos_Tail > m_iBufferPos)
     668                m_iBufferPos = m_iBufferPos_Tail;
     669
     670            m_iBufferPos_Tail = -1;
     671        }           
     672
     673        UpdateAutoScroll();
     674
     675        return IN_HANDLED;
     676    }
     677    else
     678    {
     679        return IN_PASS;
     680    }
     681}
     682
     683
    468684void CInput::HandleMessage(SGUIMessage &Message)
    469685{
    470686    // TODO Gee:
     
    560776       
    561777        UpdateAutoScroll();
    562778
    563         // If we immediately release the button it will just be seen as a click
     779        // If we immediately release the  button it will just be seen as a click
    564780        //  for the user though.
    565781
    566782        }break;
    567783
     784    case GUIM_MOUSE_DBLCLICK_LEFT:
     785        {
     786            CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     787            m_iBufferPos = m_iBufferPos_Tail = GetMouseHoveringTextPosition();
     788
     789            // See if we are clicking over whitespace
     790            if (iswspace((*pCaption)[m_iBufferPos]))
     791            {
     792                // see if we are in a section of whitespace greater than one character
     793                if ((m_iBufferPos + 1 < (int) pCaption->length() && iswspace((*pCaption)[m_iBufferPos + 1])) ||
     794                    (m_iBufferPos - 1 > 0 && iswspace((*pCaption)[m_iBufferPos - 1])))
     795                {
     796                    //
     797                    // We are clicking in an area with more than one whitespace character
     798                    // so we select both the word to the left and then the word to the right
     799                    //
     800                    // [1] First the left
     801                    // skip the whitespace
     802                    while (m_iBufferPos > 0)
     803                    {
     804                        if (!iswspace((*pCaption)[m_iBufferPos - 1]))
     805                            break;
     806
     807                        m_iBufferPos--;
     808                    }
     809                    // now go until we hit white space or punctuation
     810                    while (m_iBufferPos > 0)
     811                    {
     812                        if (iswspace((*pCaption)[m_iBufferPos - 1]))
     813                            break;
     814
     815                        m_iBufferPos--;
     816
     817                        if (iswpunct((*pCaption)[m_iBufferPos]))
     818                            break;
     819                    }
     820
     821                    // [2] Then the right
     822                    // go right until we are not in whitespace
     823                    while (++m_iBufferPos_Tail < (int)pCaption->length())
     824                    {
     825                        if (!iswspace((*pCaption)[m_iBufferPos_Tail]))
     826                            break;
     827                    }
     828                    // now go to the right until we hit whitespace or punctuation
     829                    while (++m_iBufferPos_Tail < (int)pCaption->length())
     830                    {
     831                        if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
     832                            break;
     833                    }
     834                }
     835                else
     836                {
     837                    // single whitespace so select word to the right
     838                    while (++m_iBufferPos_Tail < (int)pCaption->length())
     839                    {
     840                        if (!iswspace((*pCaption)[m_iBufferPos_Tail]))
     841                            break;
     842                    }
     843
     844                    // Don't include the leading whitespace
     845                    m_iBufferPos = m_iBufferPos_Tail;
     846
     847                    // now go to the right until we hit whitespace or punctuation
     848                    while (++m_iBufferPos_Tail < (int)pCaption->length())
     849                    {
     850                        if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
     851                            break;
     852                    }
     853                }
     854            }
     855            else
     856            {
     857                // clicked on non-whitespace so select current word
     858                // go until we hit white space or punctuation
     859                while (m_iBufferPos > 0)
     860                {
     861                    if (iswspace((*pCaption)[m_iBufferPos - 1]))
     862                        break;
     863
     864                    m_iBufferPos--;
     865
     866                    if (iswpunct((*pCaption)[m_iBufferPos]))
     867                        break;
     868                }
     869                // go to the right until we hit whitespace or punctuation
     870                while (++m_iBufferPos_Tail < (int)pCaption->length())
     871                {
     872                    if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
     873                        break;
     874                }
     875            }
     876        }
     877        break;
     878
    568879    case GUIM_MOUSE_RELEASE_LEFT:
    569880        if (m_SelectingText)
    570881        {
     
    14281739        return 0;
    14291740
    14301741    // Return position
    1431     int RetPosition;
     1742    int retPosition;
    14321743
    14331744    float buffer_zone;
    14341745    bool multiline;
     
    14931804    }
    14941805
    14951806    //m_iBufferPos = m_CharacterPositions.get.m_ListStart;
    1496     RetPosition = current->m_ListStart;
     1807    retPosition = current->m_ListStart;
    14971808   
    14981809    // Okay, now loop through the glyphs to find the appropriate X position
    14991810    float dummy;
    1500     RetPosition += GetXTextPosition(current, mouse.x, dummy);
     1811    retPosition += GetXTextPosition(current, mouse.x, dummy);
    15011812
    1502     return RetPosition;
     1813    return retPosition;
    15031814}
    15041815
    15051816// Does not process horizontal scrolling, 'x' must be modified before inputted.
    15061817int CInput::GetXTextPosition(const std::list<SRow>::iterator &current, const float &x, float &wanted)
    15071818{
    1508     int Ret=0;
    1509 
     1819    int ret=0;
    15101820    float previous=0.f;
    15111821    int i=0;
    15121822
     
    15171827        if (*it >= x)
    15181828        {
    15191829            if (x - previous >= *it - x)
    1520                 Ret += i+1;
     1830                ret += i+1;
    15211831            else
    1522                 Ret += i;
     1832                ret += i;
    15231833
    15241834            break;
    15251835        }
     
    15291839    //  character of that line.
    15301840    if (i == (int)current->m_ListOfX.size())
    15311841    {
    1532         Ret += i;
     1842        ret += i;
    15331843        wanted = x;
    15341844    }
    15351845    else wanted = 0.f;
    15361846
    1537     return Ret;
     1847    return ret;
    15381848}
    15391849
    15401850void CInput::DeleteCurSelection()
    15411851{
    15421852    CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    15431853
    1544     int VirtualFrom, VirtualTo;
     1854    int virtualFrom;
     1855    int virtualTo;
    15451856
    15461857    if (m_iBufferPos_Tail >= m_iBufferPos)
    15471858    {
    1548         VirtualFrom = m_iBufferPos;
    1549         VirtualTo = m_iBufferPos_Tail;
     1859        virtualFrom = m_iBufferPos;
     1860        virtualTo = m_iBufferPos_Tail;
    15501861    }
    15511862    else
    15521863    {
    1553         VirtualFrom = m_iBufferPos_Tail;
    1554         VirtualTo = m_iBufferPos;
     1864        virtualFrom = m_iBufferPos_Tail;
     1865        virtualTo = m_iBufferPos;
    15551866    }
    15561867
    1557     *pCaption = pCaption->Left( VirtualFrom ) +
    1558                 pCaption->Right( (long) pCaption->length()-(VirtualTo) );
     1868    *pCaption = pCaption->Left( virtualFrom ) +
     1869                pCaption->Right( (long) pCaption->length() - (virtualTo) );
    15591870
    1560     UpdateText(VirtualFrom, VirtualTo, VirtualFrom);
     1871    UpdateText(virtualFrom, virtualTo, virtualFrom);
    15611872
    15621873    // Remove selection
    15631874    m_iBufferPos_Tail = -1;
    1564     m_iBufferPos = VirtualFrom;
     1875    m_iBufferPos = virtualFrom;
    15651876}
    15661877
    15671878bool CInput::SelectingText() const
  • source/gui/CInput.h

     
    9797    virtual InReaction ManuallyHandleEvent(const SDL_Event_* ev);
    9898
    9999    /**
     100     * Handle hotkey events (MannuallHandleEvent call this for Hotkeys)
     101     */
     102    virtual InReaction ManuallyHandleHotkeyEvent(const SDL_Event_* ev);
     103
     104    /**
    100105     * @see IGUIObject#UpdateCachedSize()
    101106     */
    102107    virtual void UpdateCachedSize();
  • source/lib/sysdep/os/win/wclipboard.cpp

     
    3030static Status SetClipboardText(const wchar_t* text, HGLOBAL* hMem)
    3131{
    3232    const size_t numChars = wcslen(text);
    33     *hMem = GlobalAlloc(GMEM_MOVEABLE, (numChars+1) * sizeof(wchar_t));
     33    *hMem = GlobalAlloc(GHND | GMEM_SHARE, (numChars + 1) * sizeof(wchar_t));
    3434    if(!*hMem)
    3535        WARN_RETURN(ERR::NO_MEM);
    3636
     
    5050// "copy" text into the clipboard. replaces previous contents.
    5151Status sys_clipboard_set(const wchar_t* text)
    5252{
     53    //
    5354    // note: MSDN claims that the window handle must not be 0;
    5455    // that does actually work on WinXP, but we'll play it safe.
    55     if(!OpenClipboard(wutil_AppWindow()))
     56    //
     57    // Update (6/22/2011):
     58    // -------------------------------------------------
     59    // DOESNT WORK --> HWND hWnd = wutil_AppWindow();
     60    // -------------------------------------------------
     61    //
     62    // Using the above handle would allow you to open the clipboard
     63    // but then upon trying to read from clipboard you would always
     64    // get the error "The Handle Is Invalid" when calling GlobalLock
     65    // on the clipboard memory handle.  Strangely enough you could
     66    // copy and paste between other applications, but not within
     67    // this application.
     68    //
     69    // hWnd = NULL does work.
     70    //
     71    // From MSDN: A handle to the window to be associated with the
     72    // open clipboard. If this parameter is NULL, the open clipboard
     73    // is associated with the current task.
     74    //
     75    // This works with text, but may need to revisited if we want to
     76    // cut and paste other things like graphics other digital assets.
     77    // In that case we may need to add support to the AppWindow for
     78    // processing WM_RENDERFORMAT and WM_RENDERALLFORMATS it has to
     79    // do with some lazy update logic in the clipboard.
     80    //
     81    HWND hWnd = NULL;
     82    if(!OpenClipboard(hWnd))
    5683        WARN_RETURN(ERR::FAIL);
    5784    EmptyClipboard();
    5885
     
    6592    // freed until after CloseClipboard. however, GlobalFree still fails
    6693    // after the successful completion of both. we'll leave it in to avoid
    6794    // memory leaks, but ignore its return value.
     95    //
     96    // Update (6/22/2011):
     97    // This is working fine now, GlobalFree is returning null indicating
     98    // that it was successful.  I will leave the message for historic and
     99    // debugging purposes since the clipboard is a bit temperamental.
    68100    (void)GlobalFree(hMem);
    69101
    70102    return ret;
     
    74106static wchar_t* CopyClipboardContents()
    75107{
    76108    // Windows NT/2000+ auto convert UNICODETEXT <-> TEXT
     109    if (!IsClipboardFormatAvailable(CF_UNICODETEXT))
     110        return 0;
     111
    77112    HGLOBAL hMem = GetClipboardData(CF_UNICODETEXT);
    78113    if(!hMem)
    79114        return 0;
     
    91126    return text;
    92127}
    93128
    94 // allow "pasting" from clipboard. returns the current contents if they
     129// Allow "pasting" from clipboard. returns the current contents if they
    95130// can be represented as text, otherwise 0.
    96 // when it is no longer needed, the returned pointer must be freed via
     131// When it is no longer needed, the returned pointer must be freed via
    97132// sys_clipboard_free. (NB: not necessary if zero, but doesn't hurt)
    98133wchar_t* sys_clipboard_get()
    99134{
    100135    if(!OpenClipboard(wutil_AppWindow()))
    101136        return 0;
     137       
    102138    wchar_t* const ret = CopyClipboardContents();
    103139    CloseClipboard();
     140
    104141    return ret;
    105142}
    106143
    107144
    108 // frees memory used by <copy>, which must have been returned by
     145// Frees memory used by <copy>, which must have been returned by
    109146// sys_clipboard_get. see note above.
    110147Status sys_clipboard_free(wchar_t* text)
    111148{