* Fix several visual glitches in the selection highlight and selection behavior.
* Highlight the source view to indicate focus. * Add rudimentary menu bar with quit and copy options (copy not yet working) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31549 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ab3c00eef3
commit
8bf1b2d603
@ -10,12 +10,14 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <Clipboard.h>
|
||||||
#include <LayoutUtils.h>
|
#include <LayoutUtils.h>
|
||||||
#include <Looper.h>
|
#include <Looper.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Polygon.h>
|
#include <Polygon.h>
|
||||||
#include <Region.h>
|
#include <Region.h>
|
||||||
#include <ScrollBar.h>
|
#include <ScrollBar.h>
|
||||||
|
#include <ScrollView.h>
|
||||||
|
|
||||||
#include <AutoLocker.h>
|
#include <AutoLocker.h>
|
||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
@ -208,7 +210,7 @@ public:
|
|||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
|
|
||||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||||
|
virtual void MakeFocus(bool isFocused);
|
||||||
virtual void MouseDown(BPoint where);
|
virtual void MouseDown(BPoint where);
|
||||||
virtual void MouseMoved(BPoint where, uint32 transit,
|
virtual void MouseMoved(BPoint where, uint32 transit,
|
||||||
const BMessage* dragMessage);
|
const BMessage* dragMessage);
|
||||||
@ -232,6 +234,7 @@ private:
|
|||||||
BString& formattedLine);
|
BString& formattedLine);
|
||||||
SelectionPoint _SelectionPointAt(BPoint where) const;
|
SelectionPoint _SelectionPointAt(BPoint where) const;
|
||||||
void _GetSelectionRegion(BRegion& region) const;
|
void _GetSelectionRegion(BRegion& region) const;
|
||||||
|
void _CopySelectionToClipboard() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -934,29 +937,32 @@ SourceView::TextView::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SourceView::TextView::MakeFocus(bool isFocused)
|
||||||
|
{
|
||||||
|
fSourceView->HighlightBorder(isFocused);
|
||||||
|
|
||||||
|
SourceView::BaseView::MakeFocus(isFocused);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SourceView::TextView::MouseDown(BPoint where)
|
SourceView::TextView::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
if (fSourceCode != NULL) {
|
if (fSourceCode != NULL) {
|
||||||
if (!IsFocus()) {
|
if (!IsFocus())
|
||||||
MakeFocus(true);
|
MakeFocus(true);
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
SelectionPoint point = _SelectionPointAt(where);
|
// don't reset the selection if the user clicks within the
|
||||||
if (point.line >= 0) {
|
// current selection range
|
||||||
// don't reset the selection if the user clicks within the
|
BRegion region;
|
||||||
// current selection range
|
_GetSelectionRegion(region);
|
||||||
|
if (!region.Contains(where)) {
|
||||||
if (fSelectionStart.line < 0 || fSelectionEnd.line < 0
|
SelectionPoint point = _SelectionPointAt(where);
|
||||||
|| (fSelectionStart.line >= 0
|
fSelectionBase = fSelectionStart = fSelectionEnd = point;
|
||||||
&& point.line < fSelectionStart.line)
|
fSelectionMode = true;
|
||||||
|| (fSelectionEnd.line >= 0
|
Invalidate();
|
||||||
&& point.line > fSelectionEnd.line)) {
|
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
|
||||||
fSelectionBase = point;
|
|
||||||
fSelectionMode = true;
|
|
||||||
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -968,6 +974,8 @@ SourceView::TextView::MouseMoved(BPoint where, uint32 transit,
|
|||||||
|
|
||||||
{
|
{
|
||||||
if (fSelectionMode) {
|
if (fSelectionMode) {
|
||||||
|
BRegion oldRegion;
|
||||||
|
_GetSelectionRegion(oldRegion);
|
||||||
SelectionPoint point = _SelectionPointAt(where);
|
SelectionPoint point = _SelectionPointAt(where);
|
||||||
switch (transit) {
|
switch (transit) {
|
||||||
case B_INSIDE_VIEW:
|
case B_INSIDE_VIEW:
|
||||||
@ -991,7 +999,8 @@ SourceView::TextView::MouseMoved(BPoint where, uint32 transit,
|
|||||||
}
|
}
|
||||||
BRegion region;
|
BRegion region;
|
||||||
_GetSelectionRegion(region);
|
_GetSelectionRegion(region);
|
||||||
Invalidate(region.Frame());
|
region.Include(&oldRegion);
|
||||||
|
Invalidate(®ion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1043,7 +1052,7 @@ SourceView::TextView::SelectionPoint
|
|||||||
SourceView::TextView::_SelectionPointAt(BPoint where) const
|
SourceView::TextView::_SelectionPointAt(BPoint where) const
|
||||||
{
|
{
|
||||||
int32 line = LineAtOffset(where.y);
|
int32 line = LineAtOffset(where.y);
|
||||||
int32 offset = (int32)max_c(where.x / fCharacterWidth, 0);
|
int32 offset = (int32)max_c((where.x - kLeftTextMargin) / fCharacterWidth, 0);
|
||||||
return SelectionPoint(line, offset);
|
return SelectionPoint(line, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1057,11 +1066,13 @@ SourceView::TextView::_GetSelectionRegion(BRegion ®ion) const
|
|||||||
BRect selectionRect;
|
BRect selectionRect;
|
||||||
|
|
||||||
if (fSelectionStart.line == fSelectionEnd.line) {
|
if (fSelectionStart.line == fSelectionEnd.line) {
|
||||||
selectionRect.left = fSelectionStart.offset * fCharacterWidth;
|
if (fSelectionStart.offset != fSelectionEnd.offset) {
|
||||||
selectionRect.top = fSelectionStart.line * fFontInfo->lineHeight;
|
selectionRect.left = fSelectionStart.offset * fCharacterWidth;
|
||||||
selectionRect.right = fSelectionEnd.offset * fCharacterWidth;
|
selectionRect.top = fSelectionStart.line * fFontInfo->lineHeight;
|
||||||
selectionRect.bottom = selectionRect.top + fFontInfo->lineHeight;
|
selectionRect.right = fSelectionEnd.offset * fCharacterWidth;
|
||||||
region.Include(selectionRect);
|
selectionRect.bottom = selectionRect.top + fFontInfo->lineHeight;
|
||||||
|
region.Include(selectionRect);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// add rect for starting line
|
// add rect for starting line
|
||||||
selectionRect.left = selectionRect.left = fSelectionStart.offset
|
selectionRect.left = selectionRect.left = fSelectionStart.offset
|
||||||
@ -1088,8 +1099,39 @@ SourceView::TextView::_GetSelectionRegion(BRegion ®ion) const
|
|||||||
region.Include(selectionRect);
|
region.Include(selectionRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
region.OffsetBy(kLeftTextMargin, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SourceView::TextView::_CopySelectionToClipboard(void) const
|
||||||
|
{
|
||||||
|
if (fSelectionStart.line == -1 || fSelectionEnd.line == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BString text;
|
||||||
|
if (fSelectionStart.line == fSelectionEnd.line)
|
||||||
|
text.SetTo(fSourceCode->LineAt(fSelectionStart.line)
|
||||||
|
+ fSelectionStart.offset, fSelectionEnd.offset
|
||||||
|
- fSelectionStart.offset);
|
||||||
|
else {
|
||||||
|
text << (fSourceCode->LineAt(fSelectionStart.line)
|
||||||
|
+ fSelectionStart.offset);
|
||||||
|
for (int32 i = fSelectionStart.line + 1; i < fSelectionEnd.line; i++)
|
||||||
|
text += fSourceCode->LineAt(i);
|
||||||
|
text.Append(fSourceCode->LineAt(fSelectionEnd.line),
|
||||||
|
fSelectionEnd.offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
be_clipboard->Lock();
|
||||||
|
be_clipboard->Clear();
|
||||||
|
be_clipboard->Data()->AddData ("text/plain",
|
||||||
|
B_MIME_TYPE, text.String(), text.Length());
|
||||||
|
be_clipboard->Unlock();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - SourceView
|
// #pragma mark - SourceView
|
||||||
|
|
||||||
|
|
||||||
@ -1272,6 +1314,15 @@ printf(" -> scrolling to (%f, %f)\n", visible.left, top - (visible.Height() + 1
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SourceView::HighlightBorder(bool state)
|
||||||
|
{
|
||||||
|
BScrollView *parent = dynamic_cast<BScrollView *>(Parent());
|
||||||
|
if (parent)
|
||||||
|
parent->SetBorderHighlighted(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SourceView::TargetedByScrollView(BScrollView* scrollView)
|
SourceView::TargetedByScrollView(BScrollView* scrollView)
|
||||||
{
|
{
|
||||||
|
@ -43,6 +43,7 @@ public:
|
|||||||
bool ScrollToAddress(target_addr_t address);
|
bool ScrollToAddress(target_addr_t address);
|
||||||
bool ScrollToLine(uint32 line);
|
bool ScrollToLine(uint32 line);
|
||||||
|
|
||||||
|
void HighlightBorder(bool state);
|
||||||
virtual void TargetedByScrollView(BScrollView* scrollView);
|
virtual void TargetedByScrollView(BScrollView* scrollView);
|
||||||
|
|
||||||
virtual BSize MinSize();
|
virtual BSize MinSize();
|
||||||
@ -62,6 +63,7 @@ private:
|
|||||||
float lineHeight;
|
float lineHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Init();
|
void _Init();
|
||||||
void _UpdateScrollBars();
|
void _UpdateScrollBars();
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
|
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
|
#include <Menu.h>
|
||||||
|
#include <MenuBar.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <TabView.h>
|
#include <TabView.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
@ -298,6 +301,7 @@ TeamWindow::_Init()
|
|||||||
BScrollView* sourceScrollView;
|
BScrollView* sourceScrollView;
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||||
|
.Add(fMenuBar = new BMenuBar("Menu"))
|
||||||
.AddSplit(B_VERTICAL, 3.0f)
|
.AddSplit(B_VERTICAL, 3.0f)
|
||||||
.SetInsets(4.0f, 4.0f, 4.0f, 4.0f)
|
.SetInsets(4.0f, 4.0f, 4.0f, 4.0f)
|
||||||
.Add(fTabView = new BTabView("tab view"), 0.4f)
|
.Add(fTabView = new BTabView("tab view"), 0.4f)
|
||||||
@ -354,6 +358,19 @@ TeamWindow::_Init()
|
|||||||
fRunButton->SetTarget(this);
|
fRunButton->SetTarget(this);
|
||||||
fStepOutButton->SetTarget(this);
|
fStepOutButton->SetTarget(this);
|
||||||
|
|
||||||
|
// add menus and menu items
|
||||||
|
BMenu *menu = new BMenu("File");
|
||||||
|
fMenuBar->AddItem(menu);
|
||||||
|
BMenuItem *item = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED),
|
||||||
|
'Q');
|
||||||
|
menu->AddItem(item);
|
||||||
|
item->SetTarget(this);
|
||||||
|
menu = new BMenu("Edit");
|
||||||
|
fMenuBar->AddItem(menu);
|
||||||
|
item = new BMenuItem("Copy", new BMessage(B_COPY), 'C');
|
||||||
|
menu->AddItem(item);
|
||||||
|
item->SetTarget(fSourceView);
|
||||||
|
|
||||||
AutoLocker<TeamDebugModel> locker(fDebugModel);
|
AutoLocker<TeamDebugModel> locker(fDebugModel);
|
||||||
_UpdateRunButtons();
|
_UpdateRunButtons();
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class BButton;
|
class BButton;
|
||||||
|
class BMenuBar;
|
||||||
class BTabView;
|
class BTabView;
|
||||||
class Image;
|
class Image;
|
||||||
class RegisterView;
|
class RegisterView;
|
||||||
@ -123,6 +124,7 @@ private:
|
|||||||
BButton* fStepOverButton;
|
BButton* fStepOverButton;
|
||||||
BButton* fStepIntoButton;
|
BButton* fStepIntoButton;
|
||||||
BButton* fStepOutButton;
|
BButton* fStepOutButton;
|
||||||
|
BMenuBar* fMenuBar;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user