* 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 <Clipboard.h>
|
||||
#include <LayoutUtils.h>
|
||||
#include <Looper.h>
|
||||
#include <Message.h>
|
||||
#include <Polygon.h>
|
||||
#include <Region.h>
|
||||
#include <ScrollBar.h>
|
||||
#include <ScrollView.h>
|
||||
|
||||
#include <AutoLocker.h>
|
||||
#include <ObjectList.h>
|
||||
@ -208,7 +210,7 @@ public:
|
||||
virtual void Draw(BRect updateRect);
|
||||
|
||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||
|
||||
virtual void MakeFocus(bool isFocused);
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void MouseMoved(BPoint where, uint32 transit,
|
||||
const BMessage* dragMessage);
|
||||
@ -232,6 +234,7 @@ private:
|
||||
BString& formattedLine);
|
||||
SelectionPoint _SelectionPointAt(BPoint where) const;
|
||||
void _GetSelectionRegion(BRegion& region) const;
|
||||
void _CopySelectionToClipboard() const;
|
||||
|
||||
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
|
||||
SourceView::TextView::MouseDown(BPoint where)
|
||||
{
|
||||
if (fSourceCode != NULL) {
|
||||
if (!IsFocus()) {
|
||||
if (!IsFocus())
|
||||
MakeFocus(true);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
SelectionPoint point = _SelectionPointAt(where);
|
||||
if (point.line >= 0) {
|
||||
// don't reset the selection if the user clicks within the
|
||||
// current selection range
|
||||
|
||||
if (fSelectionStart.line < 0 || fSelectionEnd.line < 0
|
||||
|| (fSelectionStart.line >= 0
|
||||
&& point.line < fSelectionStart.line)
|
||||
|| (fSelectionEnd.line >= 0
|
||||
&& point.line > fSelectionEnd.line)) {
|
||||
fSelectionBase = point;
|
||||
fSelectionMode = true;
|
||||
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
|
||||
}
|
||||
// don't reset the selection if the user clicks within the
|
||||
// current selection range
|
||||
BRegion region;
|
||||
_GetSelectionRegion(region);
|
||||
if (!region.Contains(where)) {
|
||||
SelectionPoint point = _SelectionPointAt(where);
|
||||
fSelectionBase = fSelectionStart = fSelectionEnd = point;
|
||||
fSelectionMode = true;
|
||||
Invalidate();
|
||||
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -968,6 +974,8 @@ SourceView::TextView::MouseMoved(BPoint where, uint32 transit,
|
||||
|
||||
{
|
||||
if (fSelectionMode) {
|
||||
BRegion oldRegion;
|
||||
_GetSelectionRegion(oldRegion);
|
||||
SelectionPoint point = _SelectionPointAt(where);
|
||||
switch (transit) {
|
||||
case B_INSIDE_VIEW:
|
||||
@ -991,7 +999,8 @@ SourceView::TextView::MouseMoved(BPoint where, uint32 transit,
|
||||
}
|
||||
BRegion region;
|
||||
_GetSelectionRegion(region);
|
||||
Invalidate(region.Frame());
|
||||
region.Include(&oldRegion);
|
||||
Invalidate(®ion);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1043,7 +1052,7 @@ SourceView::TextView::SelectionPoint
|
||||
SourceView::TextView::_SelectionPointAt(BPoint where) const
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@ -1057,11 +1066,13 @@ SourceView::TextView::_GetSelectionRegion(BRegion ®ion) const
|
||||
BRect selectionRect;
|
||||
|
||||
if (fSelectionStart.line == fSelectionEnd.line) {
|
||||
selectionRect.left = fSelectionStart.offset * fCharacterWidth;
|
||||
selectionRect.top = fSelectionStart.line * fFontInfo->lineHeight;
|
||||
selectionRect.right = fSelectionEnd.offset * fCharacterWidth;
|
||||
selectionRect.bottom = selectionRect.top + fFontInfo->lineHeight;
|
||||
region.Include(selectionRect);
|
||||
if (fSelectionStart.offset != fSelectionEnd.offset) {
|
||||
selectionRect.left = fSelectionStart.offset * fCharacterWidth;
|
||||
selectionRect.top = fSelectionStart.line * fFontInfo->lineHeight;
|
||||
selectionRect.right = fSelectionEnd.offset * fCharacterWidth;
|
||||
selectionRect.bottom = selectionRect.top + fFontInfo->lineHeight;
|
||||
region.Include(selectionRect);
|
||||
}
|
||||
} else {
|
||||
// add rect for starting line
|
||||
selectionRect.left = selectionRect.left = fSelectionStart.offset
|
||||
@ -1088,8 +1099,39 @@ SourceView::TextView::_GetSelectionRegion(BRegion ®ion) const
|
||||
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
|
||||
|
||||
|
||||
@ -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
|
||||
SourceView::TargetedByScrollView(BScrollView* scrollView)
|
||||
{
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
bool ScrollToAddress(target_addr_t address);
|
||||
bool ScrollToLine(uint32 line);
|
||||
|
||||
void HighlightBorder(bool state);
|
||||
virtual void TargetedByScrollView(BScrollView* scrollView);
|
||||
|
||||
virtual BSize MinSize();
|
||||
@ -62,6 +63,7 @@ private:
|
||||
float lineHeight;
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
void _Init();
|
||||
void _UpdateScrollBars();
|
||||
|
@ -9,6 +9,9 @@
|
||||
|
||||
#include <Button.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <Menu.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
#include <Message.h>
|
||||
#include <TabView.h>
|
||||
#include <ScrollView.h>
|
||||
@ -298,6 +301,7 @@ TeamWindow::_Init()
|
||||
BScrollView* sourceScrollView;
|
||||
|
||||
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||
.Add(fMenuBar = new BMenuBar("Menu"))
|
||||
.AddSplit(B_VERTICAL, 3.0f)
|
||||
.SetInsets(4.0f, 4.0f, 4.0f, 4.0f)
|
||||
.Add(fTabView = new BTabView("tab view"), 0.4f)
|
||||
@ -354,6 +358,19 @@ TeamWindow::_Init()
|
||||
fRunButton->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);
|
||||
_UpdateRunButtons();
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
|
||||
class BButton;
|
||||
class BMenuBar;
|
||||
class BTabView;
|
||||
class Image;
|
||||
class RegisterView;
|
||||
@ -123,6 +124,7 @@ private:
|
||||
BButton* fStepOverButton;
|
||||
BButton* fStepIntoButton;
|
||||
BButton* fStepOutButton;
|
||||
BMenuBar* fMenuBar;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user