Changeset 22129

Show
Ignore:
Timestamp:
08/31/07 03:39:18 (15 months ago)
Author:
jackburton
Message:

If typing is hidden, don't reply to B_COPY or B_CUT messages, but beep()
in this case. Note that the public methods still let you copy and cut
the real text. Also prevented stealing passwords via scripting (not
tested, though). Fixes bug #1354
Got rid of the _BTextGapBuffer_::[] operator since using it creates less readable code.
Also Implemented _BTextGapBuffer_::RealText() and used it instead of Text() inside BTextView. Will make sense later.

Location:
haiku/trunk/src/kits/interface
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/src/kits/interface/TextView.cpp

    r22095 r22129  
    774774        switch (message->what) { 
    775775                case B_CUT: 
    776                         Cut(be_clipboard); 
     776                        if (!IsTypingHidden()) 
     777                                Cut(be_clipboard); 
     778                        else 
     779                                beep(); 
    777780                        break; 
    778781                         
    779782                case B_COPY: 
    780                         Copy(be_clipboard); 
     783                        if (!IsTypingHidden()) 
     784                                Copy(be_clipboard); 
     785                        else 
     786                                beep(); 
    781787                        break; 
    782788                         
     
    846852                                break; 
    847853                        } 
    848  
     854                         
     855                        BMessage reply; 
     856                        bool handled = false; 
    849857                        switch(message->what) {          
    850858                                case B_GET_PROPERTY: 
    851                                 { 
    852                                         BMessage reply; 
    853                                         GetProperty(&specifier, specifier.what, property, &reply); 
    854                                         message->SendReply(&reply); 
     859                                        handled = GetProperty(&specifier, specifier.what, property, &reply); 
    855860                                        break; 
    856                                 } 
    857861                                 
    858862                                case B_SET_PROPERTY: 
    859                                 { 
    860                                         BMessage reply; 
    861                                         SetProperty(&specifier, specifier.what, property, &reply); 
    862                                         message->SendReply(&reply); 
     863                                        handled = SetProperty(&specifier, specifier.what, property, &reply); 
    863864                                        break; 
    864                                 } 
    865865                                 
    866866                                case B_COUNT_PROPERTIES: 
    867                                 { 
    868                                         BMessage reply; 
    869                                         CountProperties(&specifier, specifier.what, property, &reply);   
    870                                         message->SendReply(&reply); 
     867                                        handled = CountProperties(&specifier, specifier.what, property, &reply);         
    871868                                        break; 
    872                                 } 
    873869                                 
    874870                                default: 
    875871                                        break; 
    876872                        } 
    877  
     873                        if (handled) 
     874                                message->SendReply(&reply); 
     875                        else 
     876                                BView::MessageReceived(message); 
    878877                        break; 
    879878                } 
     
    11331132BTextView::Text() const 
    11341133{ 
    1135         return fText->Text(); 
     1134        return fText->RealText(); 
    11361135} 
    11371136 
     
    11651164                return '\0'; 
    11661165                 
    1167         return (*fText)[offset]; 
     1166        return fText->RealCharAt(offset); 
    11681167} 
    11691168 
     
    16361635         
    16371636                // special case: go down one line if inOffset is a newline 
    1638                 if (inOffset == textLength && (*fText)[inOffset - 1] == B_ENTER) { 
     1637                if (inOffset == textLength && fText->RealCharAt(inOffset - 1) == B_ENTER) { 
    16391638                        result.y += height; 
    16401639                        height = LineHeight(CountLines() - 1); 
     
    18631862        float height = (*fLines)[endLine + 1]->origin - (*fLines)[startLine]->origin; 
    18641863                                 
    1865         if (startLine != endLine && endLine == numLines - 1 && (*fText)[fText->Length() - 1] == B_ENTER) 
     1864        if (startLine != endLine && endLine == numLines - 1 && fText->RealCharAt(fText->Length() - 1) == B_ENTER) 
    18661865                height += (*fLines)[endLine + 1]->origin - (*fLines)[endLine]->origin; 
    18671866         
     
    26532652         
    26542653        // add the text 
    2655         drag->AddData("text/plain", B_MIME_TYPE, fText->Text() + fSelStart,  
     2654        drag->AddData("text/plain", B_MIME_TYPE, fText->RealText() + fSelStart,  
    26562655                                  fSelEnd - fSelStart); 
    26572656         
     
    32883287                } 
    32893288                for ( ; (offset + delta) < limit; delta++) { 
    3290                         uchar theChar = (*fText)[offset + delta]; 
     3289                        uchar theChar = fText->RealCharAt(offset + delta); 
    32913290                        if (!CanEndLine(offset + delta)) 
    32923291                                break; 
     
    33213320                else { 
    33223321                        int32 tabCount = 0; 
    3323                         for (int32 i = delta - 1; (*fText)[offset + i] == B_TAB; i--) 
     3322                        for (int32 i = delta - 1; fText->RealCharAt(offset + i) == B_TAB; i--) 
    33243323                                tabCount++; 
    33253324                                 
     
    33513350                        if (!foundNewline) { 
    33523351                                for ( ; (offset + delta) < limit; delta++) { 
    3353                                         if ((*fText)[offset + delta] != B_SPACE && 
    3354                                                 (*fText)[offset + delta] != B_TAB) 
     3352                                        const char realChar = fText->RealCharAt(offset + delta); 
     3353                                        if (realChar != B_SPACE 
     3354                                                && realChar != B_TAB) 
    33553355                                                break; 
    33563356                                } 
    3357                                 if ( (offset + delta) < limit &&  
    3358                                          (*fText)[offset + delta] == B_ENTER ) 
     3357                                if ((offset + delta) < limit 
     3358                                        && fText->RealCharAt(offset + delta) == B_ENTER ) 
    33593359                                        delta++; 
    33603360                        } 
     
    34273427                } else 
    34283428#endif 
    3429                         result += font->StringWidth(fText->Text() + fromOffset, numChars); 
     3429                        result += font->StringWidth(fText->RealText() + fromOffset, numChars); 
    34303430                 
    34313431                fromOffset += numChars; 
     
    35943594                                 
    35953595                                int32 returnedBytes = tabChars; 
    3596                                 view->DrawString(fText->GetString(offset, &returnedBytes), returnedBytes); 
    3597                                  
     3596                                const char *stringToDraw = fText->GetString(offset, &returnedBytes); 
     3597                                         
     3598                                view->DrawString(stringToDraw, returnedBytes); 
    35983599                                if (foundTab) { 
    35993600                                        float penPos = PenLocation().x - fTextRect.left; 
     
    43094310 
    43104311        } else if (strcmp(property, "Text") == 0) { 
     4312                 
     4313                if (IsTypingHidden()) { 
     4314                        // Do not allow stealing passwords via scripting                         
     4315                        beep(); 
     4316                        return false;            
     4317                }                
     4318 
    43114319                int32 index, range; 
    43124320                 
  • haiku/trunk/src/kits/interface/textview_support/TextGapBuffer.cpp

    r18987 r22129  
    88 */ 
    99 
     10#include <cstdio> 
    1011#include <cstdlib> 
    1112#include <cstring> 
     
    194195                 
    195196                for (long i = 0; i < numBytes; i++) 
    196                         fScratchBuffer[i] = (*this)[fromOffset + i]; 
     197                        fScratchBuffer[i] = RealCharAt(fromOffset + i); 
    197198 
    198199                result = fScratchBuffer; 
     
    204205                uint32 numChars = UTF8CountChars(result, numBytes); 
    205206                uint32 charLen = UTF8CountBytes(B_UTF8_BULLET, 1); 
    206                 uint32 newSize = numChars * charLen + 1; 
     207                uint32 newSize = numChars * charLen; 
     208                 
    207209                if ((uint32)fScratchSize < newSize) { 
    208210                        fScratchBuffer = (char *)realloc(fScratchBuffer, newSize); 
     
    216218                        scratchPtr += charLen; 
    217219                } 
    218                 scratchPtr = '\0';       
    219220                *_numBytes = newSize - 1;        
    220221        } 
     
    229230        long numChars = *ioDelta; 
    230231        for (long i = 0; i < numChars; i++) { 
    231                 if (((*this)[fromIndex + i] & 0xc0) == 0x80) 
     232                if ((RealCharAt(fromIndex + i) & 0xc0) == 0x80) 
    232233                        continue; 
    233                 if ((*this)[fromIndex + i] == inChar) { 
     234                if (RealCharAt(fromIndex + i) == inChar) { 
    234235                        *ioDelta = i; 
    235236                        return true; 
     
    244245_BTextGapBuffer_::Text() 
    245246{ 
     247        const char *realText = RealText(); 
     248         
     249        if (fPasswordMode) { 
     250                const uint32 numChars = UTF8CountChars(realText, Length()); 
     251                const uint32 bulletCharLen = UTF8CountBytes(B_UTF8_BULLET, 1); 
     252                uint32 newSize = numChars * bulletCharLen + 1; 
     253                 
     254                if ((uint32)fScratchSize < newSize) { 
     255                        fScratchBuffer = (char *)realloc(fScratchBuffer, newSize); 
     256                        fScratchSize = newSize; 
     257                } 
     258                 
     259                char *scratchPtr = fScratchBuffer; 
     260                for (uint32 i = 0; i < numChars; i++) { 
     261                        memcpy(scratchPtr, B_UTF8_BULLET, bulletCharLen); 
     262                        scratchPtr += bulletCharLen; 
     263                } 
     264                scratchPtr = '\0'; 
     265 
     266                return fScratchBuffer; 
     267        } 
     268         
     269        return realText; 
     270} 
     271 
     272 
     273const char * 
     274_BTextGapBuffer_::RealText() 
     275{ 
    246276        MoveGapTo(fItemCount); 
    247277        fBuffer[fItemCount] = '\0'; 
     
    249279        return fBuffer; 
    250280} 
    251  
    252  
    253 /*char * 
    254 _BTextGapBuffer_::RealText() 
    255 { 
    256         return fText; 
    257 }*/ 
    258281 
    259282 
     
    299322 
    300323 
    301 char  
    302 _BTextGapBuffer_::RealCharAt(int32 offset) const 
    303 { 
    304         return (offset < fGapIndex) ? fBuffer[offset] : fBuffer[offset + fGapCount]; 
    305 } 
    306  
    307  
    308324bool 
    309325_BTextGapBuffer_::PasswordMode() const 
  • haiku/trunk/src/kits/interface/textview_support/TextGapBuffer.h

    r18987 r22129  
    3030 
    3131                const char      *Text(); 
     32                const char      *RealText(); 
    3233                int32           Length() const; 
    33                 char            operator[](int32 index) const; 
    34  
    3534                 
    36 //              char            *RealText(); 
    3735                const char      *GetString(int32 fromOffset, int32 *numBytes); 
    3836                void            GetString(int32 offset, int32 length, char *buffer); 
     
    6664 
    6765inline char  
    68 _BTextGapBuffer_::operator[](long index) const 
     66_BTextGapBuffer_::RealCharAt(long index) const 
    6967{ 
    7068        return (index < fGapIndex) ? fBuffer[index] : fBuffer[index + fGapCount];