* Disallowed chars now work correctly and no longer prevent the BTextView from

being edited.
* A non editable BTextView is now still navigable.
* Made cursor one pixel shorter (at least it looked a bit too long to me...).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14862 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-12 13:04:29 +00:00
parent 723de034c6
commit ee694ac85f
+46 -42
View File
@@ -1,30 +1,14 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: TextView.cpp
// Authors: Hiroshi Lockheimer (BTextView is based on his STEEngine)
// Marc Flerackers ([email protected])
// Stefano Ceccherini ([email protected])
// Description: BTextView displays and manages styled text.
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* Hiroshi Lockheimer (BTextView is based on his STEEngine)
* Marc Flerackers ([email protected])
* Stefano Ceccherini ([email protected])
*/
/** BTextView displays and manages styled text. */
// TODOs:
// - Finish documenting this class
@@ -37,8 +21,8 @@
// Known Bugs:
// - Double buffering doesn't work well (disabled by default)
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <Application.h>
#include <Beep.h>
@@ -691,18 +675,31 @@ BTextView::WindowActivated(bool state)
void
BTextView::KeyDown(const char *bytes, int32 numBytes)
{
// TODO: Remove this and move it to specific key handlers ?
// moreover, we should check if ARROW keys work in case the object
// isn't editable
if (!fEditable)
return;
const char keyPressed = bytes[0];
// if the character is not allowed, bail out.
if (fDisallowedChars
&& fDisallowedChars->HasItem(reinterpret_cast<void *>((uint32)keyPressed))) {
beep();
if (!fEditable) {
// only arrow and page keys are allowed
// (no need to hide the cursor)
switch (keyPressed) {
case B_LEFT_ARROW:
case B_RIGHT_ARROW:
case B_UP_ARROW:
case B_DOWN_ARROW:
HandleArrowKey(keyPressed);
break;
case B_HOME:
case B_END:
case B_PAGE_UP:
case B_PAGE_DOWN:
HandlePageKey(keyPressed);
break;
default:
BView::KeyDown(bytes, numBytes);
break;
}
return;
}
@@ -742,6 +739,13 @@ BTextView::KeyDown(const char *bytes, int32 numBytes)
break;
default:
// if the character is not allowed, bail out.
if (fDisallowedChars
&& fDisallowedChars->HasItem(reinterpret_cast<void *>((uint32)keyPressed))) {
beep();
return;
}
HandleAlphaKey(bytes, numBytes);
break;
}
@@ -3613,7 +3617,7 @@ BTextView::DoInsertText(const char *inText, int32 inLength, int32 inOffset,
void
BTextView::DoDeleteText(int32 fromOffset, int32 toOffset,
_BTextChangeResult_ *outResult)
_BTextChangeResult_ *outResult)
{
CALLED();
}
@@ -3621,7 +3625,7 @@ BTextView::DoDeleteText(int32 fromOffset, int32 toOffset,
void
BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
bool erase)
bool erase)
{
// clip the text
BRect clipRect = Bounds() & fTextRect;
@@ -3807,7 +3811,7 @@ BTextView::DrawCaret(int32 offset)
BRect caretRect;
caretRect.left = caretRect.right = caretPoint.x;
caretRect.top = caretPoint.y;
caretRect.bottom = caretPoint.y + lineHeight;
caretRect.bottom = caretPoint.y + lineHeight - 1;
InvertRect(caretRect);
}