Style and license fixes, added Marc Flerackers to the authors list.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9392 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-10-18 13:39:20 +00:00
parent 058691d409
commit 99a5b57a50
+69 -72
View File
@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS // Copyright (c) 2001-2004, Haiku, Inc.
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@@ -20,34 +20,24 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
// File Name: TextInput.cpp // File Name: TextInput.cpp
// Author: Frans van Nispen ([email protected]) // Authors: Frans van Nispen ([email protected])
// Marc Flerackers ([email protected])
// Description: The BTextView derivative owned by an instance of // Description: The BTextView derivative owned by an instance of
// BTextControl. // BTextControl.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
// System Includes -------------------------------------------------------------
#include <InterfaceDefs.h> #include <InterfaceDefs.h>
#include <TextControl.h>
#include <Window.h>
#include <Message.h> #include <Message.h>
#include <TextControl.h>
#include <TextView.h> #include <TextView.h>
#include <Window.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
#include "TextInput.h" #include "TextInput.h"
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
_BTextInput_::_BTextInput_(BRect frame, BRect textRect, uint32 resizeMask, _BTextInput_::_BTextInput_(BRect frame, BRect textRect, uint32 resizeMask,
uint32 flags) uint32 flags)
: BTextView(frame, "_input_", textRect, resizeMask, flags), : BTextView(frame, "_input_", textRect, resizeMask, flags),
@@ -56,7 +46,8 @@ _BTextInput_::_BTextInput_(BRect frame, BRect textRect, uint32 resizeMask,
{ {
MakeResizable(true); MakeResizable(true);
} }
//------------------------------------------------------------------------------
_BTextInput_::_BTextInput_(BMessage *archive) _BTextInput_::_BTextInput_(BMessage *archive)
: BTextView(archive), : BTextView(archive),
fPreviousText(NULL), fPreviousText(NULL),
@@ -64,43 +55,49 @@ _BTextInput_::_BTextInput_(BMessage *archive)
{ {
MakeResizable(true); MakeResizable(true);
} }
//------------------------------------------------------------------------------
_BTextInput_::~_BTextInput_() _BTextInput_::~_BTextInput_()
{ {
if (fPreviousText)
free(fPreviousText); free(fPreviousText);
} }
//------------------------------------------------------------------------------
BArchivable *_BTextInput_::Instantiate(BMessage *archive)
BArchivable *
_BTextInput_::Instantiate(BMessage *archive)
{ {
if (validate_instantiation(archive, "_BTextInput_")) if (validate_instantiation(archive, "_BTextInput_"))
return new _BTextInput_(archive); return new _BTextInput_(archive);
else else
return NULL; return NULL;
} }
//------------------------------------------------------------------------------
status_t _BTextInput_::Archive(BMessage *data, bool deep) const
status_t
_BTextInput_::Archive(BMessage *data, bool deep) const
{ {
return BTextView::Archive(data, true); return BTextView::Archive(data, true);
} }
//------------------------------------------------------------------------------
void _BTextInput_::FrameResized(float width, float height)
void
_BTextInput_::FrameResized(float width, float height)
{ {
BTextView::FrameResized(width, height); BTextView::FrameResized(width, height);
AlignTextRect(); AlignTextRect();
} }
//------------------------------------------------------------------------------
void _BTextInput_::KeyDown(const char* bytes, int32 numBytes)
{ void
switch (*bytes) _BTextInput_::KeyDown(const char* bytes, int32 numBytes)
{ {
switch (*bytes) {
case B_ENTER: case B_ENTER:
{ {
if (!TextControl()->IsEnabled()) if (!TextControl()->IsEnabled())
break; break;
if(strcmp(Text(), fPreviousText) != 0) if(strcmp(Text(), fPreviousText) != 0) {
{
TextControl()->Invoke(); TextControl()->Invoke();
free(fPreviousText); free(fPreviousText);
fPreviousText = strdup(Text()); fPreviousText = strdup(Text());
@@ -116,32 +113,31 @@ void _BTextInput_::KeyDown(const char* bytes, int32 numBytes)
default: default:
BTextView::KeyDown(bytes, numBytes); BTextView::KeyDown(bytes, numBytes);
break;
} }
} }
//------------------------------------------------------------------------------
void _BTextInput_::MakeFocus(bool state)
void
_BTextInput_::MakeFocus(bool state)
{ {
if (state == IsFocus()) if (state == IsFocus())
return; return;
BTextView::MakeFocus(state); BTextView::MakeFocus(state);
if (state) if (state) {
{
SetInitialText(); SetInitialText();
fBool = true; fBool = true;
if (Window()) if (Window()) {
{ BMessage *message = Window()->CurrentMessage();
BMessage *msg = Window()->CurrentMessage();
if (msg && msg->what == B_KEY_DOWN) if (message && message->what == B_KEY_DOWN)
SelectAll(); SelectAll();
} }
} } else {
else
{
if (strcmp(Text(), fPreviousText) != 0) if (strcmp(Text(), fPreviousText) != 0)
TextControl()->Invoke(); TextControl()->Invoke();
@@ -149,33 +145,32 @@ void _BTextInput_::MakeFocus(bool state)
fPreviousText = NULL; fPreviousText = NULL;
fBool = false; fBool = false;
if (Window()) if (Window()) {
{ BMessage *message = Window()->CurrentMessage();
BMessage *msg = Window()->CurrentMessage();
if (msg && msg->what == B_MOUSE_DOWN) if (message && message->what == B_MOUSE_DOWN)
{
Select(0, 0); Select(0, 0);
} }
} }
}
if (Window()) if (Window()) {
{
Draw(Bounds()); Draw(Bounds());
Flush(); Flush();
} }
} }
//------------------------------------------------------------------------------
void _BTextInput_::AlignTextRect()
void
_BTextInput_::AlignTextRect()
{ {
// TODO // TODO
} }
//------------------------------------------------------------------------------
void _BTextInput_::SetInitialText()
{ void
if (fPreviousText) _BTextInput_::SetInitialText()
{ {
if (fPreviousText) {
free(fPreviousText); free(fPreviousText);
fPreviousText = NULL; fPreviousText = NULL;
} }
@@ -183,24 +178,26 @@ void _BTextInput_::SetInitialText()
if (Text()) if (Text())
fPreviousText = strdup(Text()); fPreviousText = strdup(Text());
} }
//------------------------------------------------------------------------------
void _BTextInput_::Paste(BClipboard *clipboard)
void
_BTextInput_::Paste(BClipboard *clipboard)
{ {
BTextView::Paste(clipboard); BTextView::Paste(clipboard);
Invalidate(); Invalidate();
} }
//------------------------------------------------------------------------------
void _BTextInput_::InsertText(const char *inText, int32 inLength,
void
_BTextInput_::InsertText(const char *inText, int32 inLength,
int32 inOffset, const text_run_array *inRuns) int32 inOffset, const text_run_array *inRuns)
{ {
char *buffer = NULL; char *buffer = NULL;
if (strpbrk(inText, "\r\n") && inLength <= 1024) if (strpbrk(inText, "\r\n") && inLength <= 1024) {
{
buffer = (char *)malloc(inLength); buffer = (char *)malloc(inLength);
if (buffer) if (buffer) {
{
strcpy(buffer, inText); strcpy(buffer, inText);
for (int32 i = 0; i < inLength; i++) for (int32 i = 0; i < inLength; i++)
@@ -215,30 +212,30 @@ void _BTextInput_::InsertText(const char *inText, int32 inLength,
TextControl()->InvokeNotify(TextControl()->ModificationMessage(), TextControl()->InvokeNotify(TextControl()->ModificationMessage(),
B_CONTROL_MODIFIED); B_CONTROL_MODIFIED);
if (buffer)
free(buffer); free(buffer);
} }
//------------------------------------------------------------------------------
void _BTextInput_::DeleteText(int32 fromOffset, int32 toOffset)
void
_BTextInput_::DeleteText(int32 fromOffset, int32 toOffset)
{ {
BTextView::DeleteText(fromOffset, toOffset); BTextView::DeleteText(fromOffset, toOffset);
TextControl()->InvokeNotify(TextControl()->ModificationMessage(), TextControl()->InvokeNotify(TextControl()->ModificationMessage(),
B_CONTROL_MODIFIED); B_CONTROL_MODIFIED);
} }
//------------------------------------------------------------------------------
BTextControl *_BTextInput_::TextControl()
BTextControl *
_BTextInput_::TextControl()
{ {
BTextControl *textControl; BTextControl *textControl = NULL;
if (Parent()) if (Parent())
textControl = dynamic_cast<BTextControl*>(Parent()); textControl = dynamic_cast<BTextControl*>(Parent());
else
textControl = NULL;
if (!textControl) if (!textControl)
debugger("_BTextInput_ should have a BTextControl as parent"); debugger("_BTextInput_ should have a BTextControl as parent");
return textControl; return textControl;
} }
//------------------------------------------------------------------------------