* 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:
@@ -1,30 +1,14 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2005, Haiku, Inc.
|
* Copyright 2001-2005, Haiku Inc.
|
||||||
//
|
* Distributed under the terms of the MIT License.
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
*
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
* Authors:
|
||||||
// to deal in the Software without restriction, including without limitation
|
* Hiroshi Lockheimer (BTextView is based on his STEEngine)
|
||||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
* Marc Flerackers ([email protected])
|
||||||
// and/or sell copies of the Software, and to permit persons to whom the
|
* Stefano Ceccherini ([email protected])
|
||||||
// Software is furnished to do so, subject to the following conditions:
|
*/
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
/** BTextView displays and manages styled text. */
|
||||||
// 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.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// TODOs:
|
// TODOs:
|
||||||
// - Finish documenting this class
|
// - Finish documenting this class
|
||||||
@@ -37,8 +21,8 @@
|
|||||||
// Known Bugs:
|
// Known Bugs:
|
||||||
// - Double buffering doesn't work well (disabled by default)
|
// - Double buffering doesn't work well (disabled by default)
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <stdio.h>
|
||||||
#include <cstdio>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Beep.h>
|
#include <Beep.h>
|
||||||
@@ -691,18 +675,31 @@ BTextView::WindowActivated(bool state)
|
|||||||
void
|
void
|
||||||
BTextView::KeyDown(const char *bytes, int32 numBytes)
|
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];
|
const char keyPressed = bytes[0];
|
||||||
|
|
||||||
// if the character is not allowed, bail out.
|
if (!fEditable) {
|
||||||
if (fDisallowedChars
|
// only arrow and page keys are allowed
|
||||||
&& fDisallowedChars->HasItem(reinterpret_cast<void *>((uint32)keyPressed))) {
|
// (no need to hide the cursor)
|
||||||
beep();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,6 +739,13 @@ BTextView::KeyDown(const char *bytes, int32 numBytes)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
// if the character is not allowed, bail out.
|
||||||
|
if (fDisallowedChars
|
||||||
|
&& fDisallowedChars->HasItem(reinterpret_cast<void *>((uint32)keyPressed))) {
|
||||||
|
beep();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
HandleAlphaKey(bytes, numBytes);
|
HandleAlphaKey(bytes, numBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -3807,7 +3811,7 @@ BTextView::DrawCaret(int32 offset)
|
|||||||
BRect caretRect;
|
BRect caretRect;
|
||||||
caretRect.left = caretRect.right = caretPoint.x;
|
caretRect.left = caretRect.right = caretPoint.x;
|
||||||
caretRect.top = caretPoint.y;
|
caretRect.top = caretPoint.y;
|
||||||
caretRect.bottom = caretPoint.y + lineHeight;
|
caretRect.bottom = caretPoint.y + lineHeight - 1;
|
||||||
|
|
||||||
InvertRect(caretRect);
|
InvertRect(caretRect);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user