TextDocumentView: Update TextEditor about certain changes
This commit is contained in:
parent
e9df9f664f
commit
448c87fb4e
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@ -17,7 +17,8 @@
|
||||
|
||||
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),
|
||||
fInsetTop(0.0f),
|
||||
fInsetRight(0.0f),
|
||||
@ -39,6 +40,8 @@ TextDocumentView::TextDocumentView(const char* name)
|
||||
|
||||
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
|
||||
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
|
||||
TextDocumentView::MinSize()
|
||||
{
|
||||
@ -201,11 +239,16 @@ TextDocumentView::GetHeightForWidth(float width, float* min, float* max,
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
void
|
||||
TextDocumentView::SetTextDocument(const TextDocumentRef& document)
|
||||
{
|
||||
fTextDocument = document;
|
||||
fTextDocumentLayout.SetTextDocument(fTextDocument);
|
||||
if (fTextEditor.Get() != NULL)
|
||||
fTextEditor->SetDocument(document);
|
||||
|
||||
fSelectionAnchorOffset = 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
|
||||
TextDocumentView::SetInsets(float inset)
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef TEXT_DOCUMENT_VIEW_H
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#include "TextDocument.h"
|
||||
#include "TextDocumentLayout.h"
|
||||
#include "TextEditor.h"
|
||||
|
||||
|
||||
class BClipboard;
|
||||
@ -20,9 +21,11 @@ public:
|
||||
TextDocumentView(const char* name = NULL);
|
||||
virtual ~TextDocumentView();
|
||||
|
||||
// BView implementation
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void Pulse();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void FrameResized(float width, float height);
|
||||
@ -34,6 +37,9 @@ public:
|
||||
virtual void MouseMoved(BPoint where, uint32 transit,
|
||||
const BMessage* dragMessage);
|
||||
|
||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||
virtual void KeyUp(const char* bytes, int32 numBytes);
|
||||
|
||||
virtual BSize MinSize();
|
||||
virtual BSize MaxSize();
|
||||
virtual BSize PreferredSize();
|
||||
@ -42,9 +48,13 @@ public:
|
||||
virtual void GetHeightForWidth(float width, float* min,
|
||||
float* max, float* preferred);
|
||||
|
||||
// TextDocumentView interface
|
||||
void SetTextDocument(
|
||||
const TextDocumentRef& document);
|
||||
|
||||
void SetTextEditor(
|
||||
const TextEditorRef& editor);
|
||||
|
||||
void SetInsets(float inset);
|
||||
void SetInsets(float horizontal, float vertical);
|
||||
void SetInsets(float left, float top, float right,
|
||||
@ -72,6 +82,7 @@ private:
|
||||
private:
|
||||
TextDocumentRef fTextDocument;
|
||||
TextDocumentLayout fTextDocumentLayout;
|
||||
TextEditorRef fTextEditor;
|
||||
|
||||
float fInsetLeft;
|
||||
float fInsetTop;
|
||||
|
Loading…
Reference in New Issue
Block a user