hrev46663 adds 5 changesets to branch 'master' old head: 193a3956d26bc0c97ac884850b080d988e1bd66e new head: a6c0fea79c170d7ac8a68d95f9a63eacdb1710d3 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=a6c0fea+%5E193a395 ---------------------------------------------------------------------------- 6a2493e: TextDocument.cpp: Fixed typo 5c3fd46: BView: Don't allow a view to add itself as a child. e9df9f6: Make TextEditor referenceable. 448c87f: TextDocumentView: Update TextEditor about certain changes a6c0fea: HaikuDepot: Some preparations for adding rating comments * The package info area toggles a package's rating to a "Rate package..." button when the mouse hovers it. * Clicking that button opens a window where one can enter a rating. * Totally not working yet, but I want this in VCS. [ Stephan Aßmus <superstippi@xxxxxx> ] ---------------------------------------------------------------------------- 11 files changed, 380 insertions(+), 20 deletions(-) src/apps/haiku-depot/Jamfile | 2 + src/apps/haiku-depot/MainWindow.cpp | 12 ++ src/apps/haiku-depot/PackageInfoView.cpp | 147 +++++++++++++++++-- src/apps/haiku-depot/PackageInfoView.h | 1 + src/apps/haiku-depot/RatePackageWindow.cpp | 106 +++++++++++++ src/apps/haiku-depot/RatePackageWindow.h | 37 +++++ src/apps/haiku-depot/textview/TextDocument.cpp | 4 +- .../haiku-depot/textview/TextDocumentView.cpp | 66 ++++++++- src/apps/haiku-depot/textview/TextDocumentView.h | 13 +- src/apps/haiku-depot/textview/TextEditor.h | 7 +- src/kits/interface/View.cpp | 5 + ############################################################################ Commit: 6a2493e4a65931ec2a390818accf500f9770cd0c URL: http://cgit.haiku-os.org/haiku/commit/?id=6a2493e Author: Stephan Aßmus <superstippi@xxxxxx> Date: Sun Jan 12 15:33:03 2014 UTC TextDocument.cpp: Fixed typo ---------------------------------------------------------------------------- diff --git a/src/apps/haiku-depot/textview/TextDocument.cpp b/src/apps/haiku-depot/textview/TextDocument.cpp index 58b0dcd..c86e86f 100644 --- a/src/apps/haiku-depot/textview/TextDocument.cpp +++ b/src/apps/haiku-depot/textview/TextDocument.cpp @@ -17,12 +17,12 @@ TextDocument::TextDocument() } -TextDocument::TextDocument(const CharacterStyle& CharacterStyle, +TextDocument::TextDocument(const CharacterStyle& characterStyle, const ParagraphStyle& paragraphStyle) : fParagraphs(), fEmptyLastParagraph(paragraphStyle), - fDefaultCharacterStyle(CharacterStyle) + fDefaultCharacterStyle(characterStyle) { } ############################################################################ Commit: 5c3fd4605e0ab84490620c980a746c5ba26a9400 URL: http://cgit.haiku-os.org/haiku/commit/?id=5c3fd46 Author: Stephan Aßmus <superstippi@xxxxxx> Date: Sun Jan 12 19:36:49 2014 UTC BView: Don't allow a view to add itself as a child. ---------------------------------------------------------------------------- diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 16200bd..6c51460 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -3935,6 +3935,11 @@ BView::_AddChild(BView* child, BView* before) return false; } + if (child == this) { + debugger("AddChild failed - cannot add a view to itself."); + return false; + } + bool lockedOwner = false; if (fOwner && !fOwner->IsLocked()) { fOwner->Lock(); ############################################################################ Commit: e9df9f664fe705c26dde186fe6047f77663c82ef URL: http://cgit.haiku-os.org/haiku/commit/?id=e9df9f6 Author: Stephan Aßmus <superstippi@xxxxxx> Date: Sun Jan 12 21:02:36 2014 UTC Make TextEditor referenceable. ---------------------------------------------------------------------------- diff --git a/src/apps/haiku-depot/textview/TextEditor.h b/src/apps/haiku-depot/textview/TextEditor.h index c52c4b2..77c851e 100644 --- a/src/apps/haiku-depot/textview/TextEditor.h +++ b/src/apps/haiku-depot/textview/TextEditor.h @@ -6,6 +6,8 @@ #define TEXT_EDITOR_H +#include <Referenceable.h> + #include "CharacterStyle.h" #include "TextDocument.h" #include "TextDocumentLayout.h" @@ -21,7 +23,7 @@ public: }; -class TextEditor { +class TextEditor : public BReferenceable { public: TextEditor(); TextEditor(const TextEditor& other); @@ -82,4 +84,7 @@ private: }; +typedef BReference<TextEditor> TextEditorRef; + + #endif // TEXT_EDITOR_H ############################################################################ Commit: 448c87fb4ecb8a7ee590c304d03af30566c18298 URL: http://cgit.haiku-os.org/haiku/commit/?id=448c87f Author: Stephan Aßmus <superstippi@xxxxxx> Date: Sun Jan 12 21:03:24 2014 UTC TextDocumentView: Update TextEditor about certain changes ---------------------------------------------------------------------------- diff --git a/src/apps/haiku-depot/textview/TextDocumentView.cpp b/src/apps/haiku-depot/textview/TextDocumentView.cpp index 7ef8f99..ab7df8d 100644 --- a/src/apps/haiku-depot/textview/TextDocumentView.cpp +++ b/src/apps/haiku-depot/textview/TextDocumentView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2013, Stephan Aßmus <superstippi@xxxxxx>. + * Copyright 2013-2014, Stephan Aßmus <superstippi@xxxxxx>. * 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()); } @@ -89,6 +92,13 @@ TextDocumentView::Draw(BRect updateRect) void +TextDocumentView::Pulse() +{ + // TODO: Blink cursor +} + + +void TextDocumentView::AttachedToWindow() { _UpdateScrollBars(); @@ -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; @@ -218,6 +261,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) { SetInsets(inset, inset, inset, inset); diff --git a/src/apps/haiku-depot/textview/TextDocumentView.h b/src/apps/haiku-depot/textview/TextDocumentView.h index 7cf4fe6..1d9498f 100644 --- a/src/apps/haiku-depot/textview/TextDocumentView.h +++ b/src/apps/haiku-depot/textview/TextDocumentView.h @@ -1,5 +1,5 @@ /* - * Copyright 2013, Stephan Aßmus <superstippi@xxxxxx>. + * Copyright 2013-2014, Stephan Aßmus <superstippi@xxxxxx>. * 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; ############################################################################ Revision: hrev46663 Commit: a6c0fea79c170d7ac8a68d95f9a63eacdb1710d3 URL: http://cgit.haiku-os.org/haiku/commit/?id=a6c0fea Author: Stephan Aßmus <superstippi@xxxxxx> Date: Sun Jan 12 21:04:07 2014 UTC HaikuDepot: Some preparations for adding rating comments * The package info area toggles a package's rating to a "Rate package..." button when the mouse hovers it. * Clicking that button opens a window where one can enter a rating. * Totally not working yet, but I want this in VCS. ---------------------------------------------------------------------------- diff --git a/src/apps/haiku-depot/Jamfile b/src/apps/haiku-depot/Jamfile index 899aa60..ddbe9de 100644 --- a/src/apps/haiku-depot/Jamfile +++ b/src/apps/haiku-depot/Jamfile @@ -49,6 +49,7 @@ Application HaikuDepot : PackageInfoView.cpp PackageListView.cpp PackageManager.cpp + RatePackageWindow.cpp support.cpp # package_daemon @@ -73,6 +74,7 @@ DoCatalogs HaikuDepot : PackageInfoView.cpp PackageListView.cpp PackageManager.cpp + UserRatingWindow.cpp ; Application TextDocumentTest : diff --git a/src/apps/haiku-depot/MainWindow.cpp b/src/apps/haiku-depot/MainWindow.cpp index c9455b8..910cd83 100644 --- a/src/apps/haiku-depot/MainWindow.cpp +++ b/src/apps/haiku-depot/MainWindow.cpp @@ -44,6 +44,7 @@ #include "PackageInfoView.h" #include "PackageListView.h" #include "PackageManager.h" +#include "RatePackageWindow.h" #undef B_TRANSLATION_CONTEXT @@ -259,6 +260,17 @@ MainWindow::MessageReceived(BMessage* message) PackageInfoRef ref(info, true); fModel.SetPackageState(ref, ref->State()); } + break; + } + + case MSG_RATE_PACKAGE: + { + // TODO: Allow only one RatingWindow + // TODO: Mechanism for remembering the window frame + RatePackageWindow* window = new RatePackageWindow(this, + BRect(0, 0, 500, 400)); + window->Show(); + break; } default: diff --git a/src/apps/haiku-depot/PackageInfoView.cpp b/src/apps/haiku-depot/PackageInfoView.cpp index 6c4e87d..0790955 100644 --- a/src/apps/haiku-depot/PackageInfoView.cpp +++ b/src/apps/haiku-depot/PackageInfoView.cpp @@ -390,6 +390,73 @@ private: enum { MSG_PACKAGE_ACTION = 'pkga', + MSG_MOUSE_ENTERED_RATING = 'menr', + MSG_MOUSE_EXITED_RATING = 'mexr', +}; + + +class TransitReportingButton : public BButton { +public: + TransitReportingButton(const char* name, const char* label, + BMessage* message) + : + BButton(name, label, message), + fTransitMessage(NULL) + { + } + + virtual ~TransitReportingButton() + { + SetTransitMessage(NULL); + } + + virtual void MouseMoved(BPoint point, uint32 transit, + const BMessage* dragMessage) + { + BButton::MouseMoved(point, transit, dragMessage); + + if (fTransitMessage != NULL && transit == B_EXITED_VIEW) + Invoke(fTransitMessage); + } + + void SetTransitMessage(BMessage* message) + { + if (fTransitMessage != message) { + delete fTransitMessage; + fTransitMessage = message; + } + } + +private: + BMessage* fTransitMessage; +}; + + +class TransitReportingRatingView : public RatingView, public BInvoker { +public: + TransitReportingRatingView(BMessage* transitMessage) + : + RatingView(), + fTransitMessage(transitMessage) + { + } + + virtual ~TransitReportingRatingView() + { + delete fTransitMessage; + } + + virtual void MouseMoved(BPoint point, uint32 transit, + const BMessage* dragMessage) + { + RatingView::MouseMoved(point, transit, dragMessage); + + if (fTransitMessage != NULL && transit == B_ENTERED_VIEW) + Invoke(fTransitMessage); + } + +private: + BMessage* fTransitMessage; }; @@ -432,7 +499,8 @@ public: fVersionInfo->SetHighColor(kLightBlack); // Rating view - fRatingView = new RatingView(); + fRatingView = new TransitReportingRatingView( + new BMessage(MSG_MOUSE_ENTERED_RATING)); fAvgRating = new BStringView("package average rating", ""); fAvgRating->SetFont(&font); @@ -445,6 +513,33 @@ public: fVoteInfo->SetFont(&font); fVoteInfo->SetHighColor(kLightBlack); + // Rate button + fRateButton = new TransitReportingButton("rate", + B_TRANSLATE("Rate package" B_UTF8_ELLIPSIS), + new BMessage(MSG_RATE_PACKAGE)); + fRateButton->SetTransitMessage(new BMessage(MSG_MOUSE_EXITED_RATING)); + fRateButton->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, + B_ALIGN_VERTICAL_CENTER)); + + // Rating group + BView* ratingStack = new BView("rating stack", 0); + fRatingLayout = new BCardLayout(); + ratingStack->SetLayout(fRatingLayout); + ratingStack->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + ratingStack->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + BGroupView* ratingGroup = new BGroupView(B_HORIZONTAL, + B_USE_SMALL_SPACING); + BLayoutBuilder::Group<>(ratingGroup) + .Add(fRatingView) + .Add(fAvgRating) + .Add(fVoteInfo) + ; + + ratingStack->AddChild(ratingGroup); + ratingStack->AddChild(fRateButton); + fRatingLayout->SetVisibleItem((int32)0); + BLayoutBuilder::Group<>(this) .Add(fIconView) .AddGroup(B_VERTICAL, 1.0f, 2.2f) @@ -453,12 +548,7 @@ public: .SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)) .End() .AddGlue(0.1f) - .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING, 0.8f) - .Add(fRatingView) - .Add(fAvgRating) - .Add(fVoteInfo) - .SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)) - .End() + .Add(ratingStack, 0.8f) .AddGlue(0.2f) .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING, 2.0f) .Add(fVersionInfo) @@ -474,6 +564,31 @@ public: { } + virtual void AttachedToWindow() + { + fRateButton->SetTarget(this); + fRatingView->SetTarget(this); + } + + virtual void MessageReceived(BMessage* message) + { + switch (message->what) { + case MSG_RATE_PACKAGE: + // Forward to window (The button has us as target so + // we receive the message below.) + Window()->PostMessage(MSG_RATE_PACKAGE); + break; + + case MSG_MOUSE_ENTERED_RATING: + fRatingLayout->SetVisibleItem(1); + break; + + case MSG_MOUSE_EXITED_RATING: + fRatingLayout->SetVisibleItem((int32)0); + break; + } + } + void SetPackage(const PackageInfo& package) { if (package.Icon().Get() != NULL) @@ -527,16 +642,20 @@ public: } private: - BitmapView* fIconView; + BitmapView* fIconView; - BStringView* fTitleView; - BStringView* fPublisherView; + BStringView* fTitleView; + BStringView* fPublisherView; - BStringView* fVersionInfo; + BStringView* fVersionInfo; - RatingView* fRatingView; - BStringView* fAvgRating; - BStringView* fVoteInfo; + BCardLayout* fRatingLayout; + + TransitReportingRatingView* fRatingView; + BStringView* fAvgRating; + BStringView* fVoteInfo; + + TransitReportingButton* fRateButton; }; diff --git a/src/apps/haiku-depot/PackageInfoView.h b/src/apps/haiku-depot/PackageInfoView.h index eb2848f..de03f5e 100644 --- a/src/apps/haiku-depot/PackageInfoView.h +++ b/src/apps/haiku-depot/PackageInfoView.h @@ -21,6 +21,7 @@ class PagesView; enum { MSG_VOTE_UP = 'vtup', MSG_VOTE_DOWN = 'vtdn', + MSG_RATE_PACKAGE = 'rate', }; diff --git a/src/apps/haiku-depot/RatePackageWindow.cpp b/src/apps/haiku-depot/RatePackageWindow.cpp new file mode 100644 index 0000000..2a7833a --- /dev/null +++ b/src/apps/haiku-depot/RatePackageWindow.cpp @@ -0,0 +1,106 @@ +/* + * Copyright 2014, Stephan Aßmus <superstippi@xxxxxx>. + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "RatePackageWindow.h" + +#include <algorithm> +#include <stdio.h> + +#include <Alert.h> +#include <Catalog.h> +#include <Button.h> +#include <LayoutBuilder.h> +#include <ScrollView.h> + +#include "MarkupParser.h" +#include "TextDocumentView.h" + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "RatePackageWindow" + + +enum { + MSG_SEND = 'send' +}; + + +RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame) + : + BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Your rating"), + B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL, + B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), + fRatingText() +{ + AddToSubset(parent); + CenterIn(parent->Frame()); + + TextDocumentView* textView = new TextDocumentView(); + BScrollView* textScrollView = new BScrollView("rating scroll view", + textView); + + MarkupParser parser; + fRatingText = parser.CreateDocumentFromMarkup( + "Here is where you ''could'' type your awesome rating comment, " + "if only this were already implemented."); + + textView->SetInsets(10.0f); + textView->SetTextDocument(fRatingText); + textView->SetTextEditor(TextEditorRef(new TextEditor(), true)); + + fSendButton = new BButton("send", B_TRANSLATE("Send"), + new BMessage(MSG_SEND)); + + // Build layout + BLayoutBuilder::Group<>(this, B_VERTICAL) + .Add(textScrollView) + .AddGroup(B_HORIZONTAL) + .AddGlue() + .Add(fSendButton) + .End() + .SetInsets(B_USE_DEFAULT_SPACING) + ; +} + + +RatePackageWindow::~RatePackageWindow() +{ +} + + +void +RatePackageWindow::MessageReceived(BMessage* message) +{ + switch (message->what) { + case MSG_SEND: + _SendRating(); + break; + + default: + BWindow::MessageReceived(message); + break; + } +} + + +void +RatePackageWindow::SetPackage(const PackageInfoRef& package) +{ + // TODO: Just remember which package the rating is for. +} + + +void +RatePackageWindow::_SendRating() +{ + // TODO: Implement... + BAlert* alert = new BAlert("Not implemented", + "Sorry, the web application is not yet finished and " + "this functionality is not implemented.", + "Thanks for telling me after I typed all this!"); + alert->Go(NULL); + + PostMessage(B_QUIT_REQUESTED); +} diff --git a/src/apps/haiku-depot/RatePackageWindow.h b/src/apps/haiku-depot/RatePackageWindow.h new file mode 100644 index 0000000..c3082a1 --- /dev/null +++ b/src/apps/haiku-depot/RatePackageWindow.h @@ -0,0 +1,37 @@ +/* + * Copyright 2014, Stephan Aßmus <superstippi@xxxxxx>. + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef RATE_PACKAGE_WINDOW_H +#define RATE_PACKAGE_WINDOW_H + +#include <Window.h> + +#include "PackageInfo.h" +#include "TextDocument.h" + + +class BButton; +class TextDocumentView; + + +class RatePackageWindow : public BWindow { +public: + RatePackageWindow(BWindow* parent, BRect frame); + virtual ~RatePackageWindow(); + + virtual void MessageReceived(BMessage* message); + + void SetPackage(const PackageInfoRef& package); + +private: + void _SendRating(); + +private: + TextDocumentRef fRatingText; + BButton* fSendButton; + PackageInfoRef fPackage; +}; + + +#endif // RATE_PACKAGE_WINDOW_H