diff --git a/src/apps/debugger/gui/team_window/SourceView.cpp b/src/apps/debugger/gui/team_window/SourceView.cpp index f819080a48..fc0d30cafc 100644 --- a/src/apps/debugger/gui/team_window/SourceView.cpp +++ b/src/apps/debugger/gui/team_window/SourceView.cpp @@ -10,12 +10,14 @@ #include +#include #include #include #include #include #include #include +#include #include #include @@ -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(Parent()); + if (parent) + parent->SetBorderHighlighted(state); +} + + void SourceView::TargetedByScrollView(BScrollView* scrollView) { diff --git a/src/apps/debugger/gui/team_window/SourceView.h b/src/apps/debugger/gui/team_window/SourceView.h index 480679f14e..c42e87a8e5 100644 --- a/src/apps/debugger/gui/team_window/SourceView.h +++ b/src/apps/debugger/gui/team_window/SourceView.h @@ -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(); diff --git a/src/apps/debugger/gui/team_window/TeamWindow.cpp b/src/apps/debugger/gui/team_window/TeamWindow.cpp index 35cf639289..2689285438 100644 --- a/src/apps/debugger/gui/team_window/TeamWindow.cpp +++ b/src/apps/debugger/gui/team_window/TeamWindow.cpp @@ -9,6 +9,9 @@ #include #include +#include +#include +#include #include #include #include @@ -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 locker(fDebugModel); _UpdateRunButtons(); } diff --git a/src/apps/debugger/gui/team_window/TeamWindow.h b/src/apps/debugger/gui/team_window/TeamWindow.h index 0c5bddec49..80d0e19e1a 100644 --- a/src/apps/debugger/gui/team_window/TeamWindow.h +++ b/src/apps/debugger/gui/team_window/TeamWindow.h @@ -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; };