TextDocumentView: Update TextEditor about certain changes
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013, Stephan Aßmus <[email protected]>.
|
* Copyright 2013-2014, Stephan Aßmus <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -17,7 +17,8 @@
|
|||||||
|
|
||||||
TextDocumentView::TextDocumentView(const char* name)
|
TextDocumentView::TextDocumentView(const char* name)
|
||||||
:
|
:
|
||||||
BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
|
BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS
|
||||||
|
| B_PULSE_NEEDED),
|
||||||
fInsetLeft(0.0f),
|
fInsetLeft(0.0f),
|
||||||
fInsetTop(0.0f),
|
fInsetTop(0.0f),
|
||||||
fInsetRight(0.0f),
|
fInsetRight(0.0f),
|
||||||
@@ -39,6 +40,8 @@ TextDocumentView::TextDocumentView(const char* name)
|
|||||||
|
|
||||||
TextDocumentView::~TextDocumentView()
|
TextDocumentView::~TextDocumentView()
|
||||||
{
|
{
|
||||||
|
// Don't forget to remove listeners
|
||||||
|
SetTextEditor(TextEditorRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -88,6 +91,13 @@ TextDocumentView::Draw(BRect updateRect)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TextDocumentView::Pulse()
|
||||||
|
{
|
||||||
|
// TODO: Blink cursor
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TextDocumentView::AttachedToWindow()
|
TextDocumentView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
@@ -155,6 +165,34 @@ TextDocumentView::MouseMoved(BPoint where, uint32 transit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TextDocumentView::KeyDown(const char* bytes, int32 numBytes)
|
||||||
|
{
|
||||||
|
if (fTextEditor.Get() == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
KeyEvent event;
|
||||||
|
event.bytes = bytes;
|
||||||
|
event.length = numBytes;
|
||||||
|
event.key = 0;
|
||||||
|
event.modifiers = modifiers();
|
||||||
|
|
||||||
|
if (Window() != NULL && Window()->CurrentMessage() != NULL) {
|
||||||
|
BMessage* message = Window()->CurrentMessage();
|
||||||
|
message->FindInt32("key", &event.key);
|
||||||
|
message->FindInt32("modifiers", &event.modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
|
fTextEditor->KeyDown(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TextDocumentView::KeyUp(const char* bytes, int32 numBytes)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BSize
|
BSize
|
||||||
TextDocumentView::MinSize()
|
TextDocumentView::MinSize()
|
||||||
{
|
{
|
||||||
@@ -201,11 +239,16 @@ TextDocumentView::GetHeightForWidth(float width, float* min, float* max,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TextDocumentView::SetTextDocument(const TextDocumentRef& document)
|
TextDocumentView::SetTextDocument(const TextDocumentRef& document)
|
||||||
{
|
{
|
||||||
fTextDocument = document;
|
fTextDocument = document;
|
||||||
fTextDocumentLayout.SetTextDocument(fTextDocument);
|
fTextDocumentLayout.SetTextDocument(fTextDocument);
|
||||||
|
if (fTextEditor.Get() != NULL)
|
||||||
|
fTextEditor->SetDocument(document);
|
||||||
|
|
||||||
fSelectionAnchorOffset = 0;
|
fSelectionAnchorOffset = 0;
|
||||||
fCaretOffset = 0;
|
fCaretOffset = 0;
|
||||||
@@ -217,6 +260,25 @@ TextDocumentView::SetTextDocument(const TextDocumentRef& document)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TextDocumentView::SetTextEditor(const TextEditorRef& editor)
|
||||||
|
{
|
||||||
|
if (fTextEditor == editor)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (fTextEditor.Get() != NULL) {
|
||||||
|
// TODO: Probably has to remove listeners
|
||||||
|
}
|
||||||
|
|
||||||
|
fTextEditor = editor;
|
||||||
|
|
||||||
|
if (fTextEditor.Get() != NULL) {
|
||||||
|
fTextEditor->SetDocument(fTextDocument);
|
||||||
|
// TODO: Probably has to add listeners
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TextDocumentView::SetInsets(float inset)
|
TextDocumentView::SetInsets(float inset)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013, Stephan Aßmus <[email protected]>.
|
* Copyright 2013-2014, Stephan Aßmus <[email protected]>.
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef TEXT_DOCUMENT_VIEW_H
|
#ifndef TEXT_DOCUMENT_VIEW_H
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "TextDocument.h"
|
#include "TextDocument.h"
|
||||||
#include "TextDocumentLayout.h"
|
#include "TextDocumentLayout.h"
|
||||||
|
#include "TextEditor.h"
|
||||||
|
|
||||||
|
|
||||||
class BClipboard;
|
class BClipboard;
|
||||||
@@ -20,9 +21,11 @@ public:
|
|||||||
TextDocumentView(const char* name = NULL);
|
TextDocumentView(const char* name = NULL);
|
||||||
virtual ~TextDocumentView();
|
virtual ~TextDocumentView();
|
||||||
|
|
||||||
|
// BView implementation
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
|
virtual void Pulse();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void FrameResized(float width, float height);
|
virtual void FrameResized(float width, float height);
|
||||||
@@ -34,6 +37,9 @@ public:
|
|||||||
virtual void MouseMoved(BPoint where, uint32 transit,
|
virtual void MouseMoved(BPoint where, uint32 transit,
|
||||||
const BMessage* dragMessage);
|
const BMessage* dragMessage);
|
||||||
|
|
||||||
|
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||||
|
virtual void KeyUp(const char* bytes, int32 numBytes);
|
||||||
|
|
||||||
virtual BSize MinSize();
|
virtual BSize MinSize();
|
||||||
virtual BSize MaxSize();
|
virtual BSize MaxSize();
|
||||||
virtual BSize PreferredSize();
|
virtual BSize PreferredSize();
|
||||||
@@ -42,9 +48,13 @@ public:
|
|||||||
virtual void GetHeightForWidth(float width, float* min,
|
virtual void GetHeightForWidth(float width, float* min,
|
||||||
float* max, float* preferred);
|
float* max, float* preferred);
|
||||||
|
|
||||||
|
// TextDocumentView interface
|
||||||
void SetTextDocument(
|
void SetTextDocument(
|
||||||
const TextDocumentRef& document);
|
const TextDocumentRef& document);
|
||||||
|
|
||||||
|
void SetTextEditor(
|
||||||
|
const TextEditorRef& editor);
|
||||||
|
|
||||||
void SetInsets(float inset);
|
void SetInsets(float inset);
|
||||||
void SetInsets(float horizontal, float vertical);
|
void SetInsets(float horizontal, float vertical);
|
||||||
void SetInsets(float left, float top, float right,
|
void SetInsets(float left, float top, float right,
|
||||||
@@ -72,6 +82,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
TextDocumentRef fTextDocument;
|
TextDocumentRef fTextDocument;
|
||||||
TextDocumentLayout fTextDocumentLayout;
|
TextDocumentLayout fTextDocumentLayout;
|
||||||
|
TextEditorRef fTextEditor;
|
||||||
|
|
||||||
float fInsetLeft;
|
float fInsetLeft;
|
||||||
float fInsetTop;
|
float fInsetTop;
|
||||||
|
|||||||
Reference in New Issue
Block a user