From f7ff8e8094838430abe35dba107c199db46ffe04 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Fri, 10 Mar 2023 16:25:10 +0530 Subject: [PATCH 01/16] Delete DeskNoteView.h --- DeskNoteView.h | 93 -------------------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 DeskNoteView.h diff --git a/DeskNoteView.h b/DeskNoteView.h deleted file mode 100644 index 6a705f8..0000000 --- a/DeskNoteView.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). - * All rights reserved. - * Distributed under the terms of the BSD (3-clause) License. - * - * Authors: - * Janus2, 2015 - * Humdinger, 2021 - * - */ - - -#ifndef _DESKNOTEVIEW_H -#define _DESKNOTEVIEW_H - -#include -#include -#include - -#include "ColorMenuItem.h" -#include "DeskNoteApp.h" -#include "DeskNoteTextView.h" - - -#define DN_LAUNCH 'dnLN' -#define DN_COLOR 'dnCL' - -const rgb_color palette[] = { - { 255, 221, 191, 255 }, // lightest red - { 255, 187, 128, 255 }, // light red - { 216, 158, 108, 255 }, // red - { 179, 83, 0, 255 }, // dark red - - { 255, 244, 191, 255 }, // lightest yellow - { 255, 233, 128, 255 }, // light yellow - { 215, 178, 0, 255 }, // yellow - { 179, 148, 0, 255 }, // dark yellow - - { 216, 255, 180, 255 }, // lightest green - { 177, 255, 169, 255 }, // light green - { 72, 187, 61, 255 }, // green - { 47, 122, 40, 255 }, // dark green - - { 213, 234, 255, 255 }, // lightest blue - { 170, 213, 255, 255 }, // light blue - { 67, 131, 196, 255 }, // blue - { 36, 71, 106, 255 }, // dark blue - - { 244, 244, 244, 255 }, // off white - { 188, 188, 188, 255 }, // light grey - { 96, 96, 96, 255 }, // dark grey - { 11, 11, 11, 255 }, // off black -}; - -class DeskNoteTextView; - -class DeskNoteView : public BView { -public: - DeskNoteView(BRect rect); - DeskNoteView(BMessage* data); - ~DeskNoteView(); - - virtual status_t Archive(BMessage* data, bool deep = true) const; - virtual void Draw(BRect rect); - virtual void MessageReceived(BMessage* msg); - virtual void FrameResized(float width, float height); - virtual void MouseDown(BPoint point); - virtual void SaveNote(BMessage* msg); - virtual void RestoreNote(BMessage* msg); - - static BArchivable* Instantiate(BMessage* data); - static int32 ResizeViewMethod(void* data); - - static const char defaultText[]; - static const char aboutText[]; - -private: - void _BuildColorMenu(BMenu* menu); - void _SetColors(); - void _ShowContextMenu(BPoint where); - bool WeAreAReplicant; - DeskNoteTextView* textView; - BRect ourSize; - BMenu* colorMenu; - BMessage* orginalSettings; - BPopUpMenu* popupMenu; - rgb_color background; - rgb_color foreground; - rgb_color widgetcolour; - BDragger* dragger; -}; - -#endif // _DESKNOTEVIEW_H From 0c5d93eb29f05696a734d2e6c0a9cb666d754440 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Fri, 10 Mar 2023 16:25:47 +0530 Subject: [PATCH 02/16] Delete DeskNoteView.cpp --- DeskNoteView.cpp | 432 ----------------------------------------------- 1 file changed, 432 deletions(-) delete mode 100644 DeskNoteView.cpp diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp deleted file mode 100644 index 3943d9b..0000000 --- a/DeskNoteView.cpp +++ /dev/null @@ -1,432 +0,0 @@ -/* - * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). - * All rights reserved. - * Distributed under the terms of the BSD (3-clause) License. - * - * Authors: - * Janus2, 2015 - * Humdinger, 2021 - * - */ - - -#include "DeskNoteView.h" - -#include -#include -#include -#include -#include -#include -#include - - -#undef B_TRANSLATION_CONTEXT -#define B_TRANSLATION_CONTEXT "View" - -const float kWidgetSize = 7; - - -DeskNoteView::DeskNoteView(BRect rect) - : - BView(rect, "DeskNotes", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS) -{ - BRect draggerRect = rect; - BRect textViewRect = rect; - BPopUpMenu* draggerPop; - BMenuItem* popupMenu; - BMessage* popupMessage; - ourSize = rect; - - WeAreAReplicant = false; - - draggerRect.OffsetTo(B_ORIGIN); - draggerRect.top = draggerRect.bottom - kWidgetSize; - draggerRect.right = draggerRect.left + kWidgetSize; - - dragger = new BDragger(draggerRect, this, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - textViewRect.bottom -= kWidgetSize + 1; // Don't collide with the widgets. - - textView = new DeskNoteTextView(textViewRect, "TextView", textViewRect, - B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED); - BString defaultText(B_TRANSLATE( - "\n\tWelcome to DeskNotes!\n\n" - "\t*\tUse as Replicants on your Desktop\n" - "\t*\tResize with the bottom-right widget\n" - "\t*\tRight-click for a context menu\n" - "\t*\tUse different colors from the 'Color' menu\n" - "\t*\tColors dropped from other apps like\n" - "\t\tIcon-O-Matic change the background\n\n" - "\tHave a nice day!")); - textView->SetText(defaultText); - AddChild(textView); - - background = palette[0]; - SetViewColor(background); - AddChild(dragger); - _SetColors(); -} - - -DeskNoteView::DeskNoteView(BMessage* data) - : - BView(data) -{ - const rgb_color* bckgrnd; - ssize_t size; - - WeAreAReplicant = true; - textView = dynamic_cast(FindView("TextView")); - dragger = dynamic_cast(FindView("_dragger_")); - - data->FindData( - "background_colour", B_RGB_COLOR_TYPE, (const void**) &bckgrnd, &size); - - background = *bckgrnd; - _SetColors(); - SetResizingMode(B_FOLLOW_NONE); -} - - -DeskNoteView::~DeskNoteView() -{ -} - - -status_t -DeskNoteView::Archive(BMessage* data, bool deep) const -{ - BView::Archive(data, deep); - // These first two fields are internal Archiving fields. - data->AddString("class", "DeskNoteView"); - data->AddString("add_on", app_signature); - - // Now add the foreground and background colours. - data->AddData( - "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); - - return B_NO_ERROR; -} - - -void -DeskNoteView::Draw(BRect rct) -{ - ourSize = Bounds(); - BRect rect = ourSize; - BRect cleanRect = ourSize; - - rect.top = rect.bottom - kWidgetSize; - rect.left = rect.right - kWidgetSize; - - cleanRect.top = rect.top; - cleanRect.right = rect.left - 1; // Don't overlap with the resize widget. - SetHighColor(widgetcolour); - FillRect(rect); - SetHighColor(background); - FillRect(cleanRect); -} - - -void -DeskNoteView::MessageReceived(BMessage* msg) -{ - BAlert* alert; - BRect windSize, ourSize; - BMessenger* messenger; - BFont currentFont; - font_family currentFamily; - font_style currentStyle; - uint16 currentFace; - const rgb_color* bckgrnd; - ssize_t size; - - switch (msg->what) { - case B_ABOUT_REQUESTED: - { - // Set the mouse cursor! - be_app->SetCursor(B_HAND_CURSOR); - - BAboutWindow* aboutWin = new BAboutWindow("DeskNotes", - app_signature); - aboutWin->AddDescription(B_TRANSLATE( - "Pin little notes as replicants on your Desktop.\n" - "Dropped colors change the background of a note.")); - const char* extraCopyrights[] = { - "2012 siarzhuk ", - "2015 Janus", - "2021 Humdinger", - NULL - }; - const char* authors[] = { - B_TRANSLATE("Colin Stewart (original author)"), - "Humdinger", - "Janus", - "siarzhuk", - NULL - }; - aboutWin->AddCopyright(2000, "Colin Stewart", extraCopyrights); - aboutWin->AddAuthors(authors); - aboutWin->Show(); - break; - } - case DN_LAUNCH: - { - be_roster->Launch(app_signature); - break; - } - case DN_COLOR: - { - ssize_t colorLength; - if (msg->FindData("color", B_RGB_COLOR_TYPE, - (const void**)&bckgrnd, &colorLength) == B_OK - && colorLength == sizeof(rgb_color)) { - background = *bckgrnd; - _SetColors(); - } - break; - } - default: - BView::MessageReceived(msg); - } -} - - -void -DeskNoteView::FrameResized(float width, float height) -{ - BRect nowRect = textView->TextRect(); - BRect txtSize = ourSize = Bounds(); - txtSize.InsetBy(nowRect.left, 0); // keep left/right margins of the textview - - txtSize.bottom -= kWidgetSize + 2; - textView->SetTextRect(txtSize); - Invalidate(); -} - - -void -DeskNoteView::MouseDown(BPoint point) -{ - thread_id resizeThread; - BMessage* msg; - BMenuItem* menuItem; - BPoint mousePoint; - uint32 mouseButtons; - - if (!Window()->IsActive()) - Window()->Activate(true); - - textView->MakeFocus(true); - - GetMouse(&mousePoint, &mouseButtons, false); - if (point.x >= (ourSize.right - kWidgetSize) && point.y - >= (ourSize.bottom - kWidgetSize)) { - resizeThread = spawn_thread(DeskNoteView::ResizeViewMethod, - "Resize Thread", B_DISPLAY_PRIORITY, this); - if (resizeThread > 0) - resume_thread(resizeThread); - - } else if (mouseButtons == B_SECONDARY_MOUSE_BUTTON) - _ShowContextMenu(mousePoint); -} - - -void -DeskNoteView::_BuildColorMenu(BMenu* menu) -{ - if (menu == NULL) - return; - - BFont font; - menu->GetFont(&font); - font_height fh; - font.GetHeight(&fh); - - const float itemHeight = ceilf(fh.ascent + fh.descent + 2 * fh.leading); - const float margin = 8.0; - const int nbColumns = 4; - - BMessage msgTemplate(DN_COLOR); - BRect matrixArea(0, 0, 0, 0); - - // we place the color palette, reserving room at the top - for (uint i = 0; i < sizeof(palette) / sizeof(rgb_color); i++) { - BPoint topLeft((i % nbColumns) * (itemHeight + margin), - (i / nbColumns) * (itemHeight + margin)); - BRect buttonArea(topLeft.x, topLeft.y, topLeft.x + itemHeight, - topLeft.y + itemHeight); - buttonArea.OffsetBy(margin, margin); - - ColorMenuItem* colItem - = new ColorMenuItem("", palette[i], new BMessage(msgTemplate)); - - if (colItem != NULL && palette[i] == background) - colItem->SetMarked(true); - - colItem->SetTarget(this); - menu->AddItem(colItem, buttonArea); - - buttonArea.OffsetBy(margin, margin); - matrixArea = matrixArea | buttonArea; - } - - // separator at the bottom to add spacing in the matrix menu - matrixArea.top = matrixArea.bottom; - menu->AddItem(new BSeparatorItem(), matrixArea); -} - - -void -DeskNoteView::_SetColors() -{ - float thresh - = background.red + (background.green * 1.25f) + (background.blue * 0.45f); - if (thresh >= 360) { - foreground.red = 11; - foreground.green = 11; - foreground.blue = 11; - widgetcolour = tint_color(background, B_DARKEN_1_TINT); - } else { - foreground.red = 244; - foreground.green = 244; - foreground.blue = 244; - widgetcolour = tint_color(background, B_LIGHTEN_1_TINT); - } - - BFont font; - GetFont(&font); - textView->SetFontAndColor(&font, B_FONT_ALL, &foreground); - textView->SetViewColor(background); - this->Invalidate(); - textView->Invalidate(); - SetViewColor(background); - if (dragger != NULL) - dragger->Invalidate(); -} - - -void -DeskNoteView::_ShowContextMenu(BPoint where) -{ - bool isRedo; - undo_state state = textView->UndoState(&isRedo); - bool isUndo = state != B_UNDO_UNAVAILABLE && !isRedo; - - int32 start; - int32 finish; - textView->GetSelection(&start, &finish); - - bool canEdit = textView->IsEditable(); - int32 length = textView->TextLength(); - - BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false); - - colorMenu = new BMenu(B_TRANSLATE("Color"), 0, 0); - _BuildColorMenu(colorMenu); - - BLayoutBuilder::Menu<>(menu) - .AddItem(B_TRANSLATE("Undo"), B_UNDO) - .SetEnabled(canEdit && isUndo) - .AddItem(B_TRANSLATE("Redo"), B_UNDO) - .SetEnabled(canEdit && isRedo) - .AddSeparator() - .AddItem(B_TRANSLATE("Cut"), B_CUT) - .SetEnabled(canEdit && start != finish) - .AddItem(B_TRANSLATE("Copy"), B_COPY) - .SetEnabled(start != finish) - .AddItem(B_TRANSLATE("Paste"), B_PASTE) - .SetEnabled(canEdit && be_clipboard->SystemCount() > 0) - .AddSeparator() - .AddItem(B_TRANSLATE("Select all"), B_SELECT_ALL) - .SetEnabled(!(start == 0 && finish == length)) - // custom menu - .AddSeparator() - .AddItem(colorMenu) - .AddItem(B_TRANSLATE("About DeskNotes" B_UTF8_ELLIPSIS), - new BMessage(B_ABOUT_REQUESTED)); - - // If we are replicant add the launch desknotes command to the menu. - if (WeAreAReplicant) { - menu->AddItem(new BMenuItem( - B_TRANSLATE("Launch DeskNotes" B_UTF8_ELLIPSIS), - new BMessage(DN_LAUNCH))); - } - - menu->SetTargetForItems(textView); - ConvertToScreen(&where); - menu->Go(where, true, true, true); -} - - -void -DeskNoteView::SaveNote(BMessage* msg) -{ - // Save the text of the note. - msg->AddString("NoteText", textView->Text()); - - // Save the foreground and background colours. - msg->AddData( - "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); -} - - -void -DeskNoteView::RestoreNote(BMessage* msg) -{ - const rgb_color* bckgrnd; - ssize_t size; - const char* text; - - // Find the text of the note. - if (msg->FindString("NoteText", &text) == B_OK) - textView->SetText(text); - - // Find the background colour. - if (msg->FindData("background_colour", B_RGB_COLOR_TYPE, - (const void**) &bckgrnd, &size) == B_OK) - background = *bckgrnd; - - // Update the colour of the text view and widget. - _SetColors(); -} - - -BArchivable* -DeskNoteView::Instantiate(BMessage* data) -{ - if (!validate_instantiation(data, "DeskNoteView")) - return NULL; - return new DeskNoteView(data); -} - - -int32 -DeskNoteView::ResizeViewMethod(void* data) -{ - uint32 buttons; - BPoint cursor; - float x, y; - DeskNoteView* theView = (DeskNoteView*) data; - - do { - theView->Window()->Lock(); - theView->GetMouse(&cursor, &buttons); - if (cursor.x > 30) - x = cursor.x; - else - x = 30; - if (cursor.y > 20) - y = cursor.y; - else - y = 20; - if (theView->WeAreAReplicant) - theView->ResizeTo(x, y); - else - theView->Window()->ResizeTo(x, y); - theView->Window()->Unlock(); - snooze(20 * 1000); - } while (buttons); - - return 0; -} From f52c4f8a6b3721e7caf069b38e7a3cb73e6b5e70 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Fri, 10 Mar 2023 16:26:38 +0530 Subject: [PATCH 03/16] Add files via upload --- DeskNoteView.cpp | 575 +++++++++++++++++++++++++++++++++++++++++++++++ DeskNoteView.h | 105 +++++++++ 2 files changed, 680 insertions(+) create mode 100644 DeskNoteView.cpp create mode 100644 DeskNoteView.h diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp new file mode 100644 index 0000000..e410e0c --- /dev/null +++ b/DeskNoteView.cpp @@ -0,0 +1,575 @@ +/* + * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). + * All rights reserved. + * Distributed under the terms of the BSD (3-clause) License. + * + * Authors: + * Janus2, 2015 + * Humdinger, 2021 + * + */ + + +#include "DeskNoteView.h" + +#include +#include +#include +#include +#include +#include +#include + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "View" + + +#define FONT_FAMILY 'fntf' +#define FONT_STYLE 'ftst' + +const float kWidgetSize = 7; + + +DeskNoteView::DeskNoteView(BRect rect) + : + BView(rect, "DeskNotes", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS) +{ + BRect draggerRect = rect; + BRect textViewRect = rect; + BPopUpMenu* draggerPop; + BMenuItem* popupMenu; + BMessage* popupMessage; + ourSize = rect; + + WeAreAReplicant = false; + + draggerRect.OffsetTo(B_ORIGIN); + draggerRect.top = draggerRect.bottom - kWidgetSize; + draggerRect.right = draggerRect.left + kWidgetSize; + + dragger = new BDragger(draggerRect, this, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); + textViewRect.bottom -= kWidgetSize + 1; // Don't collide with the widgets. + + textView = new DeskNoteTextView(textViewRect, "TextView", textViewRect, + B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED); + BString defaultText(B_TRANSLATE( + "\n\tWelcome to DeskNotes!\n\n" + "\t*\tUse as Replicants on your Desktop\n" + "\t*\tResize with the bottom-right widget\n" + "\t*\tRight-click for a context menu\n" + "\t*\tUse different colors from the 'Color' menu\n" + "\t*\tColors dropped from other apps like\n" + "\t\tIcon-O-Matic change the background\n\n" + "\tHave a nice day!")); + textView->SetText(defaultText); + AddChild(textView); + + background = palette[0]; + SetViewColor(background); + AddChild(dragger); + _SetColors(); +} + + +DeskNoteView::DeskNoteView(BMessage* data) + : + BView(data) +{ + const rgb_color* bckgrnd; + ssize_t size; + + WeAreAReplicant = true; + textView = dynamic_cast(FindView("TextView")); + dragger = dynamic_cast(FindView("_dragger_")); + + data->FindData( + "background_colour", B_RGB_COLOR_TYPE, (const void**) &bckgrnd, &size); + + background = *bckgrnd; + _SetColors(); + SetResizingMode(B_FOLLOW_NONE); +} + + +DeskNoteView::~DeskNoteView() +{ +} + + +status_t +DeskNoteView::Archive(BMessage* data, bool deep) const +{ + BView::Archive(data, deep); + // These first two fields are internal Archiving fields. + data->AddString("class", "DeskNoteView"); + data->AddString("add_on", app_signature); + + // Now add the foreground and background colours. + data->AddData( + "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); + + return B_NO_ERROR; +} + + +void +DeskNoteView::Draw(BRect rct) +{ + ourSize = Bounds(); + BRect rect = ourSize; + BRect cleanRect = ourSize; + + rect.top = rect.bottom - kWidgetSize; + rect.left = rect.right - kWidgetSize; + + cleanRect.top = rect.top; + cleanRect.right = rect.left - 1; // Don't overlap with the resize widget. + SetHighColor(widgetcolour); + FillRect(rect); + SetHighColor(background); + FillRect(cleanRect); +} + + +void +DeskNoteView::MessageReceived(BMessage* msg) +{ + BAlert *alert; + BRect windSize, + ourSize; + BMessenger *messenger; + BMessage *message; + BFont currentFont; + BMenuItem *item; + BMenu *menu; + font_family currentFamily; + font_style currentStyle; + uint16 currentFace; + const rgb_color *bckgrnd; + ssize_t size; + const char *fontFamily, + *fontStyle; + void *ptr; + + switch (msg->what) { + case B_ABOUT_REQUESTED: + { + // Set the mouse cursor! + be_app->SetCursor(B_HAND_CURSOR); + + BAboutWindow* aboutWin = new BAboutWindow("DeskNotes", + app_signature); + aboutWin->AddDescription(B_TRANSLATE( + "Pin little notes as replicants on your Desktop.\n" + "Dropped colors change the background of a note.")); + const char* extraCopyrights[] = { + "2012 siarzhuk ", + "2015 Janus", + "2021 Humdinger", + NULL + }; + const char* authors[] = { + B_TRANSLATE("Colin Stewart (original author)"), + "Humdinger", + "Janus", + "siarzhuk", + NULL + }; + aboutWin->AddCopyright(2000, "Colin Stewart", extraCopyrights); + aboutWin->AddAuthors(authors); + aboutWin->Show(); + break; + } + case DN_LAUNCH: + { + be_roster->Launch(app_signature); + break; + } + case DN_COLOR: + { + ssize_t colorLength; + if (msg->FindData("color", B_RGB_COLOR_TYPE, + (const void**)&bckgrnd, &colorLength) == B_OK + && colorLength == sizeof(rgb_color)) { + background = *bckgrnd; + _SetColors(); + } + break; + + // Font type + case FONT_FAMILY: { + + fontFamily = NULL; + fontStyle = NULL; + + // Setting the font family + message->FindPointer ("source", &ptr); + fCurrentFont = static_cast (ptr); + fontFamily = fCurrentFont->Label(); + SetFontStyle (fontFamily, fontStyle); + } + break; + + /*// Font style + case FONT_STYLE: { + + /*fontFamily = NULL; + fontStyle = NULL; + + // Setting the font style + message->FindPointer ("source", &ptr); + item = static_cast (ptr); + fontStyle = item->Label(); + menu = item->Menu(); + + if (menu != NULL) { + fCurrentFont = menu->Superitem(); + if (fCurrentFont != NULL) + fontFamily = fCurrentFont->Label(); + } + SetFontStyle (fontFamily, fontStyle); + + }*/ + break; + + default: + BView::MessageReceived(msg); + } +} + +} + + +void +DeskNoteView::FrameResized(float width, float height) +{ + BRect nowRect = textView->TextRect(); + BRect txtSize = ourSize = Bounds(); + txtSize.InsetBy(nowRect.left, 0); // keep left/right margins of the textview + + txtSize.bottom -= kWidgetSize + 2; + textView->SetTextRect(txtSize); + Invalidate(); +} + + +void +DeskNoteView::MouseDown(BPoint point) +{ + thread_id resizeThread; + BMessage* msg; + BMenuItem* menuItem; + BPoint mousePoint; + uint32 mouseButtons; + + if (!Window()->IsActive()) + Window()->Activate(true); + + textView->MakeFocus(true); + + GetMouse(&mousePoint, &mouseButtons, false); + if (point.x >= (ourSize.right - kWidgetSize) && point.y + >= (ourSize.bottom - kWidgetSize)) { + resizeThread = spawn_thread(DeskNoteView::ResizeViewMethod, + "Resize Thread", B_DISPLAY_PRIORITY, this); + if (resizeThread > 0) + resume_thread(resizeThread); + + } else if (mouseButtons == B_SECONDARY_MOUSE_BUTTON) + _ShowContextMenu(mousePoint); +} + +void +DeskNoteView::_BuildStyleMenu(BMenu* menu) +{ + //variables + font_family plainFamily, + family; + font_style plainStyle, + style; + BMenuItem* menuItem = NULL; + int32 numFamilies, + numStyles; + BMenu* fontMenu; + uint32 flags; + + + //Font Menu + fCurrentFont = 0; + + be_plain_font->GetFamilyAndStyle (&plainFamily,&plainStyle); + + // Taking the number of font families + numFamilies = count_font_families(); + for (int32 i = 0; i < numFamilies; i++) { + + // Getting the font families + if (get_font_family(i, &family) == B_OK) { + + // Creating a menu of that font family + fontMenu = new BMenu (family); + fontMenu->SetRadioMode (true); // I can set only one item as "in use" + fFontMenu->AddItem (menuItem = new BMenuItem (fontMenu, new BMessage (FONT_FAMILY))); + + if (!strcmp (plainFamily,family)) { + menuItem->SetMarked (true); + fCurrentFont = menuItem; + } + //Number of styles of that font family + numStyles = count_font_styles (family); + + // Creating a submenu about each of that styles + for (int32 j = 0; j < numStyles; j++) { + + if (get_font_style(family,j,&style,&flags)==B_OK) { + fontMenu->AddItem (menuItem = new BMenuItem (style, new BMessage(FONT_STYLE))); + + if (!strcmp (plainStyle, style)) + menuItem->SetMarked(true); + + } + } + } + } +} + +void +DeskNoteView::_BuildColorMenu(BMenu* menu) +{ + if (menu == NULL) + return; + + BFont font; + menu->GetFont(&font); + font_height fh; + font.GetHeight(&fh); + + const float itemHeight = ceilf(fh.ascent + fh.descent + 2 * fh.leading); + const float margin = 8.0; + const int nbColumns = 4; + + BMessage msgTemplate(DN_COLOR); + BRect matrixArea(0, 0, 0, 0); + + // we place the color palette, reserving room at the top + for (uint i = 0; i < sizeof(palette) / sizeof(rgb_color); i++) { + BPoint topLeft((i % nbColumns) * (itemHeight + margin), + (i / nbColumns) * (itemHeight + margin)); + BRect buttonArea(topLeft.x, topLeft.y, topLeft.x + itemHeight, + topLeft.y + itemHeight); + buttonArea.OffsetBy(margin, margin); + + ColorMenuItem* colItem + = new ColorMenuItem("", palette[i], new BMessage(msgTemplate)); + + if (colItem != NULL && palette[i] == background) + colItem->SetMarked(true); + + colItem->SetTarget(this); + menu->AddItem(colItem, buttonArea); + + buttonArea.OffsetBy(margin, margin); + matrixArea = matrixArea | buttonArea; + } + + // separator at the bottom to add spacing in the matrix menu + matrixArea.top = matrixArea.bottom; + menu->AddItem(new BSeparatorItem(), matrixArea); +} + + +void +DeskNoteView::_SetColors() +{ + float thresh + = background.red + (background.green * 1.25f) + (background.blue * 0.45f); + if (thresh >= 360) { + foreground.red = 11; + foreground.green = 11; + foreground.blue = 11; + widgetcolour = tint_color(background, B_DARKEN_1_TINT); + } else { + foreground.red = 244; + foreground.green = 244; + foreground.blue = 244; + widgetcolour = tint_color(background, B_LIGHTEN_1_TINT); + } + + BFont font; + GetFont(&font); + textView->SetFontAndColor(&font, B_FONT_ALL, &foreground); + textView->SetViewColor(background); + this->Invalidate(); + textView->Invalidate(); + SetViewColor(background); + if (dragger != NULL) + dragger->Invalidate(); +} + + +void +DeskNoteView::_ShowContextMenu(BPoint where) +{ + bool isRedo; + undo_state state = textView->UndoState(&isRedo); + bool isUndo = state != B_UNDO_UNAVAILABLE && !isRedo; + + int32 start; + int32 finish; + textView->GetSelection(&start, &finish); + + bool canEdit = textView->IsEditable(); + int32 length = textView->TextLength(); + + BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false); + + colorMenu = new BMenu(B_TRANSLATE("Color"), 0, 0); + _BuildColorMenu(colorMenu); + + styleMenu = new BMenu(B_TRANSLATE("Font Style"), 0, 0); + _BuildStyleMenu(styleMenu); + + BLayoutBuilder::Menu<>(menu) + .AddItem(B_TRANSLATE("Undo"), B_UNDO) + .SetEnabled(canEdit && isUndo) + .AddItem(B_TRANSLATE("Redo"), B_UNDO) + .SetEnabled(canEdit && isRedo) + .AddSeparator() + .AddItem(B_TRANSLATE("Cut"), B_CUT) + .SetEnabled(canEdit && start != finish) + .AddItem(B_TRANSLATE("Copy"), B_COPY) + .SetEnabled(start != finish) + .AddItem(B_TRANSLATE("Paste"), B_PASTE) + .SetEnabled(canEdit && be_clipboard->SystemCount() > 0) + .AddSeparator() + .AddItem(B_TRANSLATE("Select all"), B_SELECT_ALL) + .SetEnabled(!(start == 0 && finish == length)) + .AddSeparator() + // custom menu + .AddItem(styleMenu) + .AddItem(colorMenu) + .AddSeparator() + // About section + .AddItem(B_TRANSLATE("About DeskNotes" B_UTF8_ELLIPSIS), + new BMessage(B_ABOUT_REQUESTED)); + + // If we are replicant add the launch desknotes command to the menu. + if (WeAreAReplicant) { + menu->AddItem(new BMenuItem( + B_TRANSLATE("Launch DeskNotes" B_UTF8_ELLIPSIS), + new BMessage(DN_LAUNCH))); + } + + menu->SetTargetForItems(textView); + ConvertToScreen(&where); + menu->Go(where, true, true, true); +} + + +void +DeskNoteView::SaveNote(BMessage* msg) +{ + // Save the text of the note. + msg->AddString("NoteText", textView->Text()); + + // Save the foreground and background colours. + msg->AddData( + "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); +} + +// Function for the changes in the "type of font" +void DeskNoteView :: SetFontStyle (const char* fontFamily, const char* fontStyle) { + // Variables + BMenuItem *superItem; + BMenuItem *menuItem; + BFont font; + font_family oldFamily; + font_style oldStyle; + uint32 sameProperties; + rgb_color sameColor; + BMenuItem *oldItem; + + //fNoteText->GetFontAndColor (&font, &sameProperties, &sameColor); + // Copying the current font family and font style + font.GetFamilyAndStyle (&oldFamily, &oldStyle); + + if (strcmp (oldFamily, fontFamily)) { + oldItem = fFontMenu->FindItem (oldFamily); + + if (oldItem != NULL) + // Removing the check + oldItem->SetMarked (false); + } + + font.SetFamilyAndStyle (fontFamily, fontStyle); + //fNoteText->SetFontAndColor (&font); + + superItem = fFontMenu->FindItem (fontFamily); + + if (superItem != NULL ) + superItem->SetMarked (true); // Check the one that was selected + + menuItem = fFontMenu->FindItem("Black"); + menuItem->SetMarked(true); +} + +void +DeskNoteView::RestoreNote(BMessage* msg) +{ + const rgb_color* bckgrnd; + ssize_t size; + const char* text; + + // Find the text of the note. + if (msg->FindString("NoteText", &text) == B_OK) + textView->SetText(text); + + // Find the background colour. + if (msg->FindData("background_colour", B_RGB_COLOR_TYPE, + (const void**) &bckgrnd, &size) == B_OK) + background = *bckgrnd; + + // Update the colour of the text view and widget. + _SetColors(); +} + + +BArchivable* +DeskNoteView::Instantiate(BMessage* data) +{ + if (!validate_instantiation(data, "DeskNoteView")) + return NULL; + return new DeskNoteView(data); +} + + +int32 +DeskNoteView::ResizeViewMethod(void* data) +{ + uint32 buttons; + BPoint cursor; + float x, y; + DeskNoteView* theView = (DeskNoteView*) data; + + do { + theView->Window()->Lock(); + theView->GetMouse(&cursor, &buttons); + if (cursor.x > 30) + x = cursor.x; + else + x = 30; + if (cursor.y > 20) + y = cursor.y; + else + y = 20; + if (theView->WeAreAReplicant) + theView->ResizeTo(x, y); + else + theView->Window()->ResizeTo(x, y); + theView->Window()->Unlock(); + snooze(20 * 1000); + } while (buttons); + + return 0; +} diff --git a/DeskNoteView.h b/DeskNoteView.h new file mode 100644 index 0000000..feb7b1a --- /dev/null +++ b/DeskNoteView.h @@ -0,0 +1,105 @@ +/* + * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). + * All rights reserved. + * Distributed under the terms of the BSD (3-clause) License. + * + * Authors: + * Janus2, 2015 + * Humdinger, 2021 + * + */ + + +#ifndef _DESKNOTEVIEW_H +#define _DESKNOTEVIEW_H + +#include +#include +#include + +#include "ColorMenuItem.h" +#include "DeskNoteApp.h" +#include "DeskNoteTextView.h" + + + +#define DN_LAUNCH 'dnLN' +#define DN_COLOR 'dnCL' + +const rgb_color palette[] = { + { 255, 221, 191, 255 }, // lightest red + { 255, 187, 128, 255 }, // light red + { 216, 158, 108, 255 }, // red + { 179, 83, 0, 255 }, // dark red + + { 255, 244, 191, 255 }, // lightest yellow + { 255, 233, 128, 255 }, // light yellow + { 215, 178, 0, 255 }, // yellow + { 179, 148, 0, 255 }, // dark yellow + + { 216, 255, 180, 255 }, // lightest green + { 177, 255, 169, 255 }, // light green + { 72, 187, 61, 255 }, // green + { 47, 122, 40, 255 }, // dark green + + { 213, 234, 255, 255 }, // lightest blue + { 170, 213, 255, 255 }, // light blue + { 67, 131, 196, 255 }, // blue + { 36, 71, 106, 255 }, // dark blue + + { 244, 244, 244, 255 }, // off white + { 188, 188, 188, 255 }, // light grey + { 96, 96, 96, 255 }, // dark grey + { 11, 11, 11, 255 }, // off black +}; + +class DeskNoteTextView; + +class DeskNoteView : public BView { +public: + DeskNoteView(BRect rect); + DeskNoteView(BMessage* data); + ~DeskNoteView(); + + virtual status_t Archive(BMessage* data, bool deep = true) const; + virtual void Draw(BRect rect); + virtual void MessageReceived(BMessage* msg); + virtual void FrameResized(float width, float height); + virtual void MouseDown(BPoint point); + virtual void SaveNote(BMessage* msg); + virtual void RestoreNote(BMessage* msg); + + static BArchivable* Instantiate(BMessage* data); + static int32 ResizeViewMethod(void* data); + + static const char defaultText[]; + static const char aboutText[]; + + void SetFontStyle(const char* fontFamily, + const char *fontStyle); + + + + +private: + void _BuildColorMenu(BMenu* menu); + void _BuildStyleMenu(BMenu* menu); + void _SetColors(); + void _ShowContextMenu(BPoint where); + bool WeAreAReplicant; + DeskNoteTextView* textView; + BRect ourSize; + BMenu* colorMenu; + BMenu* styleMenu; + BMenu* fFontMenu; + BMenuItem* fCurrentFont; + BMessage* orginalSettings; + BPopUpMenu* popupMenu; + rgb_color background; + rgb_color foreground; + rgb_color widgetcolour; + BDragger* dragger; + +}; + +#endif // _DESKNOTEVIEW_H From 03bba6b8d3fc5d87f844ffa0ba85582555c6e86f Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Fri, 10 Mar 2023 20:20:26 +0530 Subject: [PATCH 04/16] Delete DeskNoteView.cpp --- DeskNoteView.cpp | 575 ----------------------------------------------- 1 file changed, 575 deletions(-) delete mode 100644 DeskNoteView.cpp diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp deleted file mode 100644 index e410e0c..0000000 --- a/DeskNoteView.cpp +++ /dev/null @@ -1,575 +0,0 @@ -/* - * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). - * All rights reserved. - * Distributed under the terms of the BSD (3-clause) License. - * - * Authors: - * Janus2, 2015 - * Humdinger, 2021 - * - */ - - -#include "DeskNoteView.h" - -#include -#include -#include -#include -#include -#include -#include - - -#undef B_TRANSLATION_CONTEXT -#define B_TRANSLATION_CONTEXT "View" - - -#define FONT_FAMILY 'fntf' -#define FONT_STYLE 'ftst' - -const float kWidgetSize = 7; - - -DeskNoteView::DeskNoteView(BRect rect) - : - BView(rect, "DeskNotes", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS) -{ - BRect draggerRect = rect; - BRect textViewRect = rect; - BPopUpMenu* draggerPop; - BMenuItem* popupMenu; - BMessage* popupMessage; - ourSize = rect; - - WeAreAReplicant = false; - - draggerRect.OffsetTo(B_ORIGIN); - draggerRect.top = draggerRect.bottom - kWidgetSize; - draggerRect.right = draggerRect.left + kWidgetSize; - - dragger = new BDragger(draggerRect, this, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - textViewRect.bottom -= kWidgetSize + 1; // Don't collide with the widgets. - - textView = new DeskNoteTextView(textViewRect, "TextView", textViewRect, - B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED); - BString defaultText(B_TRANSLATE( - "\n\tWelcome to DeskNotes!\n\n" - "\t*\tUse as Replicants on your Desktop\n" - "\t*\tResize with the bottom-right widget\n" - "\t*\tRight-click for a context menu\n" - "\t*\tUse different colors from the 'Color' menu\n" - "\t*\tColors dropped from other apps like\n" - "\t\tIcon-O-Matic change the background\n\n" - "\tHave a nice day!")); - textView->SetText(defaultText); - AddChild(textView); - - background = palette[0]; - SetViewColor(background); - AddChild(dragger); - _SetColors(); -} - - -DeskNoteView::DeskNoteView(BMessage* data) - : - BView(data) -{ - const rgb_color* bckgrnd; - ssize_t size; - - WeAreAReplicant = true; - textView = dynamic_cast(FindView("TextView")); - dragger = dynamic_cast(FindView("_dragger_")); - - data->FindData( - "background_colour", B_RGB_COLOR_TYPE, (const void**) &bckgrnd, &size); - - background = *bckgrnd; - _SetColors(); - SetResizingMode(B_FOLLOW_NONE); -} - - -DeskNoteView::~DeskNoteView() -{ -} - - -status_t -DeskNoteView::Archive(BMessage* data, bool deep) const -{ - BView::Archive(data, deep); - // These first two fields are internal Archiving fields. - data->AddString("class", "DeskNoteView"); - data->AddString("add_on", app_signature); - - // Now add the foreground and background colours. - data->AddData( - "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); - - return B_NO_ERROR; -} - - -void -DeskNoteView::Draw(BRect rct) -{ - ourSize = Bounds(); - BRect rect = ourSize; - BRect cleanRect = ourSize; - - rect.top = rect.bottom - kWidgetSize; - rect.left = rect.right - kWidgetSize; - - cleanRect.top = rect.top; - cleanRect.right = rect.left - 1; // Don't overlap with the resize widget. - SetHighColor(widgetcolour); - FillRect(rect); - SetHighColor(background); - FillRect(cleanRect); -} - - -void -DeskNoteView::MessageReceived(BMessage* msg) -{ - BAlert *alert; - BRect windSize, - ourSize; - BMessenger *messenger; - BMessage *message; - BFont currentFont; - BMenuItem *item; - BMenu *menu; - font_family currentFamily; - font_style currentStyle; - uint16 currentFace; - const rgb_color *bckgrnd; - ssize_t size; - const char *fontFamily, - *fontStyle; - void *ptr; - - switch (msg->what) { - case B_ABOUT_REQUESTED: - { - // Set the mouse cursor! - be_app->SetCursor(B_HAND_CURSOR); - - BAboutWindow* aboutWin = new BAboutWindow("DeskNotes", - app_signature); - aboutWin->AddDescription(B_TRANSLATE( - "Pin little notes as replicants on your Desktop.\n" - "Dropped colors change the background of a note.")); - const char* extraCopyrights[] = { - "2012 siarzhuk ", - "2015 Janus", - "2021 Humdinger", - NULL - }; - const char* authors[] = { - B_TRANSLATE("Colin Stewart (original author)"), - "Humdinger", - "Janus", - "siarzhuk", - NULL - }; - aboutWin->AddCopyright(2000, "Colin Stewart", extraCopyrights); - aboutWin->AddAuthors(authors); - aboutWin->Show(); - break; - } - case DN_LAUNCH: - { - be_roster->Launch(app_signature); - break; - } - case DN_COLOR: - { - ssize_t colorLength; - if (msg->FindData("color", B_RGB_COLOR_TYPE, - (const void**)&bckgrnd, &colorLength) == B_OK - && colorLength == sizeof(rgb_color)) { - background = *bckgrnd; - _SetColors(); - } - break; - - // Font type - case FONT_FAMILY: { - - fontFamily = NULL; - fontStyle = NULL; - - // Setting the font family - message->FindPointer ("source", &ptr); - fCurrentFont = static_cast (ptr); - fontFamily = fCurrentFont->Label(); - SetFontStyle (fontFamily, fontStyle); - } - break; - - /*// Font style - case FONT_STYLE: { - - /*fontFamily = NULL; - fontStyle = NULL; - - // Setting the font style - message->FindPointer ("source", &ptr); - item = static_cast (ptr); - fontStyle = item->Label(); - menu = item->Menu(); - - if (menu != NULL) { - fCurrentFont = menu->Superitem(); - if (fCurrentFont != NULL) - fontFamily = fCurrentFont->Label(); - } - SetFontStyle (fontFamily, fontStyle); - - }*/ - break; - - default: - BView::MessageReceived(msg); - } -} - -} - - -void -DeskNoteView::FrameResized(float width, float height) -{ - BRect nowRect = textView->TextRect(); - BRect txtSize = ourSize = Bounds(); - txtSize.InsetBy(nowRect.left, 0); // keep left/right margins of the textview - - txtSize.bottom -= kWidgetSize + 2; - textView->SetTextRect(txtSize); - Invalidate(); -} - - -void -DeskNoteView::MouseDown(BPoint point) -{ - thread_id resizeThread; - BMessage* msg; - BMenuItem* menuItem; - BPoint mousePoint; - uint32 mouseButtons; - - if (!Window()->IsActive()) - Window()->Activate(true); - - textView->MakeFocus(true); - - GetMouse(&mousePoint, &mouseButtons, false); - if (point.x >= (ourSize.right - kWidgetSize) && point.y - >= (ourSize.bottom - kWidgetSize)) { - resizeThread = spawn_thread(DeskNoteView::ResizeViewMethod, - "Resize Thread", B_DISPLAY_PRIORITY, this); - if (resizeThread > 0) - resume_thread(resizeThread); - - } else if (mouseButtons == B_SECONDARY_MOUSE_BUTTON) - _ShowContextMenu(mousePoint); -} - -void -DeskNoteView::_BuildStyleMenu(BMenu* menu) -{ - //variables - font_family plainFamily, - family; - font_style plainStyle, - style; - BMenuItem* menuItem = NULL; - int32 numFamilies, - numStyles; - BMenu* fontMenu; - uint32 flags; - - - //Font Menu - fCurrentFont = 0; - - be_plain_font->GetFamilyAndStyle (&plainFamily,&plainStyle); - - // Taking the number of font families - numFamilies = count_font_families(); - for (int32 i = 0; i < numFamilies; i++) { - - // Getting the font families - if (get_font_family(i, &family) == B_OK) { - - // Creating a menu of that font family - fontMenu = new BMenu (family); - fontMenu->SetRadioMode (true); // I can set only one item as "in use" - fFontMenu->AddItem (menuItem = new BMenuItem (fontMenu, new BMessage (FONT_FAMILY))); - - if (!strcmp (plainFamily,family)) { - menuItem->SetMarked (true); - fCurrentFont = menuItem; - } - //Number of styles of that font family - numStyles = count_font_styles (family); - - // Creating a submenu about each of that styles - for (int32 j = 0; j < numStyles; j++) { - - if (get_font_style(family,j,&style,&flags)==B_OK) { - fontMenu->AddItem (menuItem = new BMenuItem (style, new BMessage(FONT_STYLE))); - - if (!strcmp (plainStyle, style)) - menuItem->SetMarked(true); - - } - } - } - } -} - -void -DeskNoteView::_BuildColorMenu(BMenu* menu) -{ - if (menu == NULL) - return; - - BFont font; - menu->GetFont(&font); - font_height fh; - font.GetHeight(&fh); - - const float itemHeight = ceilf(fh.ascent + fh.descent + 2 * fh.leading); - const float margin = 8.0; - const int nbColumns = 4; - - BMessage msgTemplate(DN_COLOR); - BRect matrixArea(0, 0, 0, 0); - - // we place the color palette, reserving room at the top - for (uint i = 0; i < sizeof(palette) / sizeof(rgb_color); i++) { - BPoint topLeft((i % nbColumns) * (itemHeight + margin), - (i / nbColumns) * (itemHeight + margin)); - BRect buttonArea(topLeft.x, topLeft.y, topLeft.x + itemHeight, - topLeft.y + itemHeight); - buttonArea.OffsetBy(margin, margin); - - ColorMenuItem* colItem - = new ColorMenuItem("", palette[i], new BMessage(msgTemplate)); - - if (colItem != NULL && palette[i] == background) - colItem->SetMarked(true); - - colItem->SetTarget(this); - menu->AddItem(colItem, buttonArea); - - buttonArea.OffsetBy(margin, margin); - matrixArea = matrixArea | buttonArea; - } - - // separator at the bottom to add spacing in the matrix menu - matrixArea.top = matrixArea.bottom; - menu->AddItem(new BSeparatorItem(), matrixArea); -} - - -void -DeskNoteView::_SetColors() -{ - float thresh - = background.red + (background.green * 1.25f) + (background.blue * 0.45f); - if (thresh >= 360) { - foreground.red = 11; - foreground.green = 11; - foreground.blue = 11; - widgetcolour = tint_color(background, B_DARKEN_1_TINT); - } else { - foreground.red = 244; - foreground.green = 244; - foreground.blue = 244; - widgetcolour = tint_color(background, B_LIGHTEN_1_TINT); - } - - BFont font; - GetFont(&font); - textView->SetFontAndColor(&font, B_FONT_ALL, &foreground); - textView->SetViewColor(background); - this->Invalidate(); - textView->Invalidate(); - SetViewColor(background); - if (dragger != NULL) - dragger->Invalidate(); -} - - -void -DeskNoteView::_ShowContextMenu(BPoint where) -{ - bool isRedo; - undo_state state = textView->UndoState(&isRedo); - bool isUndo = state != B_UNDO_UNAVAILABLE && !isRedo; - - int32 start; - int32 finish; - textView->GetSelection(&start, &finish); - - bool canEdit = textView->IsEditable(); - int32 length = textView->TextLength(); - - BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false); - - colorMenu = new BMenu(B_TRANSLATE("Color"), 0, 0); - _BuildColorMenu(colorMenu); - - styleMenu = new BMenu(B_TRANSLATE("Font Style"), 0, 0); - _BuildStyleMenu(styleMenu); - - BLayoutBuilder::Menu<>(menu) - .AddItem(B_TRANSLATE("Undo"), B_UNDO) - .SetEnabled(canEdit && isUndo) - .AddItem(B_TRANSLATE("Redo"), B_UNDO) - .SetEnabled(canEdit && isRedo) - .AddSeparator() - .AddItem(B_TRANSLATE("Cut"), B_CUT) - .SetEnabled(canEdit && start != finish) - .AddItem(B_TRANSLATE("Copy"), B_COPY) - .SetEnabled(start != finish) - .AddItem(B_TRANSLATE("Paste"), B_PASTE) - .SetEnabled(canEdit && be_clipboard->SystemCount() > 0) - .AddSeparator() - .AddItem(B_TRANSLATE("Select all"), B_SELECT_ALL) - .SetEnabled(!(start == 0 && finish == length)) - .AddSeparator() - // custom menu - .AddItem(styleMenu) - .AddItem(colorMenu) - .AddSeparator() - // About section - .AddItem(B_TRANSLATE("About DeskNotes" B_UTF8_ELLIPSIS), - new BMessage(B_ABOUT_REQUESTED)); - - // If we are replicant add the launch desknotes command to the menu. - if (WeAreAReplicant) { - menu->AddItem(new BMenuItem( - B_TRANSLATE("Launch DeskNotes" B_UTF8_ELLIPSIS), - new BMessage(DN_LAUNCH))); - } - - menu->SetTargetForItems(textView); - ConvertToScreen(&where); - menu->Go(where, true, true, true); -} - - -void -DeskNoteView::SaveNote(BMessage* msg) -{ - // Save the text of the note. - msg->AddString("NoteText", textView->Text()); - - // Save the foreground and background colours. - msg->AddData( - "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); -} - -// Function for the changes in the "type of font" -void DeskNoteView :: SetFontStyle (const char* fontFamily, const char* fontStyle) { - // Variables - BMenuItem *superItem; - BMenuItem *menuItem; - BFont font; - font_family oldFamily; - font_style oldStyle; - uint32 sameProperties; - rgb_color sameColor; - BMenuItem *oldItem; - - //fNoteText->GetFontAndColor (&font, &sameProperties, &sameColor); - // Copying the current font family and font style - font.GetFamilyAndStyle (&oldFamily, &oldStyle); - - if (strcmp (oldFamily, fontFamily)) { - oldItem = fFontMenu->FindItem (oldFamily); - - if (oldItem != NULL) - // Removing the check - oldItem->SetMarked (false); - } - - font.SetFamilyAndStyle (fontFamily, fontStyle); - //fNoteText->SetFontAndColor (&font); - - superItem = fFontMenu->FindItem (fontFamily); - - if (superItem != NULL ) - superItem->SetMarked (true); // Check the one that was selected - - menuItem = fFontMenu->FindItem("Black"); - menuItem->SetMarked(true); -} - -void -DeskNoteView::RestoreNote(BMessage* msg) -{ - const rgb_color* bckgrnd; - ssize_t size; - const char* text; - - // Find the text of the note. - if (msg->FindString("NoteText", &text) == B_OK) - textView->SetText(text); - - // Find the background colour. - if (msg->FindData("background_colour", B_RGB_COLOR_TYPE, - (const void**) &bckgrnd, &size) == B_OK) - background = *bckgrnd; - - // Update the colour of the text view and widget. - _SetColors(); -} - - -BArchivable* -DeskNoteView::Instantiate(BMessage* data) -{ - if (!validate_instantiation(data, "DeskNoteView")) - return NULL; - return new DeskNoteView(data); -} - - -int32 -DeskNoteView::ResizeViewMethod(void* data) -{ - uint32 buttons; - BPoint cursor; - float x, y; - DeskNoteView* theView = (DeskNoteView*) data; - - do { - theView->Window()->Lock(); - theView->GetMouse(&cursor, &buttons); - if (cursor.x > 30) - x = cursor.x; - else - x = 30; - if (cursor.y > 20) - y = cursor.y; - else - y = 20; - if (theView->WeAreAReplicant) - theView->ResizeTo(x, y); - else - theView->Window()->ResizeTo(x, y); - theView->Window()->Unlock(); - snooze(20 * 1000); - } while (buttons); - - return 0; -} From 5ff6c58e03fccfc83670a5767093028ea52342e5 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Fri, 10 Mar 2023 20:20:37 +0530 Subject: [PATCH 05/16] Delete DeskNoteView.h --- DeskNoteView.h | 105 ------------------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 DeskNoteView.h diff --git a/DeskNoteView.h b/DeskNoteView.h deleted file mode 100644 index feb7b1a..0000000 --- a/DeskNoteView.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). - * All rights reserved. - * Distributed under the terms of the BSD (3-clause) License. - * - * Authors: - * Janus2, 2015 - * Humdinger, 2021 - * - */ - - -#ifndef _DESKNOTEVIEW_H -#define _DESKNOTEVIEW_H - -#include -#include -#include - -#include "ColorMenuItem.h" -#include "DeskNoteApp.h" -#include "DeskNoteTextView.h" - - - -#define DN_LAUNCH 'dnLN' -#define DN_COLOR 'dnCL' - -const rgb_color palette[] = { - { 255, 221, 191, 255 }, // lightest red - { 255, 187, 128, 255 }, // light red - { 216, 158, 108, 255 }, // red - { 179, 83, 0, 255 }, // dark red - - { 255, 244, 191, 255 }, // lightest yellow - { 255, 233, 128, 255 }, // light yellow - { 215, 178, 0, 255 }, // yellow - { 179, 148, 0, 255 }, // dark yellow - - { 216, 255, 180, 255 }, // lightest green - { 177, 255, 169, 255 }, // light green - { 72, 187, 61, 255 }, // green - { 47, 122, 40, 255 }, // dark green - - { 213, 234, 255, 255 }, // lightest blue - { 170, 213, 255, 255 }, // light blue - { 67, 131, 196, 255 }, // blue - { 36, 71, 106, 255 }, // dark blue - - { 244, 244, 244, 255 }, // off white - { 188, 188, 188, 255 }, // light grey - { 96, 96, 96, 255 }, // dark grey - { 11, 11, 11, 255 }, // off black -}; - -class DeskNoteTextView; - -class DeskNoteView : public BView { -public: - DeskNoteView(BRect rect); - DeskNoteView(BMessage* data); - ~DeskNoteView(); - - virtual status_t Archive(BMessage* data, bool deep = true) const; - virtual void Draw(BRect rect); - virtual void MessageReceived(BMessage* msg); - virtual void FrameResized(float width, float height); - virtual void MouseDown(BPoint point); - virtual void SaveNote(BMessage* msg); - virtual void RestoreNote(BMessage* msg); - - static BArchivable* Instantiate(BMessage* data); - static int32 ResizeViewMethod(void* data); - - static const char defaultText[]; - static const char aboutText[]; - - void SetFontStyle(const char* fontFamily, - const char *fontStyle); - - - - -private: - void _BuildColorMenu(BMenu* menu); - void _BuildStyleMenu(BMenu* menu); - void _SetColors(); - void _ShowContextMenu(BPoint where); - bool WeAreAReplicant; - DeskNoteTextView* textView; - BRect ourSize; - BMenu* colorMenu; - BMenu* styleMenu; - BMenu* fFontMenu; - BMenuItem* fCurrentFont; - BMessage* orginalSettings; - BPopUpMenu* popupMenu; - rgb_color background; - rgb_color foreground; - rgb_color widgetcolour; - BDragger* dragger; - -}; - -#endif // _DESKNOTEVIEW_H From 512f90f36c3f02a45ea0899a433e8f0fac3e7498 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Fri, 10 Mar 2023 20:22:10 +0530 Subject: [PATCH 06/16] Add files via upload --- DeskNoteView.cpp | 575 +++++++++++++++++++++++++++++++++++++++++++++++ DeskNoteView.h | 105 +++++++++ 2 files changed, 680 insertions(+) create mode 100644 DeskNoteView.cpp create mode 100644 DeskNoteView.h diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp new file mode 100644 index 0000000..d8cb1b8 --- /dev/null +++ b/DeskNoteView.cpp @@ -0,0 +1,575 @@ +/* + * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). + * All rights reserved. + * Distributed under the terms of the BSD (3-clause) License. + * + * Authors: + * Janus2, 2015 + * Humdinger, 2021 + * + */ + + +#include "DeskNoteView.h" + +#include +#include +#include +#include +#include +#include +#include + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "View" + + +#define FONT_FAMILY 'fntf' +#define FONT_STYLE 'ftst' + +const float kWidgetSize = 7; + + +DeskNoteView::DeskNoteView(BRect rect) + : + BView(rect, "DeskNotes", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS) +{ + BRect draggerRect = rect; + BRect textViewRect = rect; + BPopUpMenu* draggerPop; + BMenuItem* popupMenu; + BMessage* popupMessage; + ourSize = rect; + + WeAreAReplicant = false; + + draggerRect.OffsetTo(B_ORIGIN); + draggerRect.top = draggerRect.bottom - kWidgetSize; + draggerRect.right = draggerRect.left + kWidgetSize; + + dragger = new BDragger(draggerRect, this, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); + textViewRect.bottom -= kWidgetSize + 1; // Don't collide with the widgets. + + textView = new DeskNoteTextView(textViewRect, "TextView", textViewRect, + B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED); + BString defaultText(B_TRANSLATE( + "\n\tWelcome to DeskNotes!\n\n" + "\t*\tUse as Replicants on your Desktop\n" + "\t*\tResize with the bottom-right widget\n" + "\t*\tRight-click for a context menu\n" + "\t*\tUse different colors from the 'Color' menu\n" + "\t*\tColors dropped from other apps like\n" + "\t\tIcon-O-Matic change the background\n\n" + "\tHave a nice day!")); + textView->SetText(defaultText); + AddChild(textView); + + background = palette[0]; + SetViewColor(background); + AddChild(dragger); + _SetColors(); +} + + +DeskNoteView::DeskNoteView(BMessage* data) + : + BView(data) +{ + const rgb_color* bckgrnd; + ssize_t size; + + WeAreAReplicant = true; + textView = dynamic_cast(FindView("TextView")); + dragger = dynamic_cast(FindView("_dragger_")); + + data->FindData( + "background_colour", B_RGB_COLOR_TYPE, (const void**) &bckgrnd, &size); + + background = *bckgrnd; + _SetColors(); + SetResizingMode(B_FOLLOW_NONE); +} + + +DeskNoteView::~DeskNoteView() +{ +} + + +status_t +DeskNoteView::Archive(BMessage* data, bool deep) const +{ + BView::Archive(data, deep); + // These first two fields are internal Archiving fields. + data->AddString("class", "DeskNoteView"); + data->AddString("add_on", app_signature); + + // Now add the foreground and background colours. + data->AddData( + "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); + + return B_NO_ERROR; +} + + +void +DeskNoteView::Draw(BRect rct) +{ + ourSize = Bounds(); + BRect rect = ourSize; + BRect cleanRect = ourSize; + + rect.top = rect.bottom - kWidgetSize; + rect.left = rect.right - kWidgetSize; + + cleanRect.top = rect.top; + cleanRect.right = rect.left - 1; // Don't overlap with the resize widget. + SetHighColor(widgetcolour); + FillRect(rect); + SetHighColor(background); + FillRect(cleanRect); +} + + +void +DeskNoteView::MessageReceived(BMessage* msg) +{ + BAlert *alert; + BRect windSize, + ourSize; + BMessenger *messenger; + BMessage *message; + BFont currentFont; + BMenuItem *item; + BMenu *menu; + font_family currentFamily; + font_style currentStyle; + uint16 currentFace; + const rgb_color *bckgrnd; + ssize_t size; + const char *fontFamily, + *fontStyle; + void *ptr; + + switch (msg->what) { + case B_ABOUT_REQUESTED: + { + // Set the mouse cursor! + be_app->SetCursor(B_HAND_CURSOR); + + BAboutWindow* aboutWin = new BAboutWindow("DeskNotes", + app_signature); + aboutWin->AddDescription(B_TRANSLATE( + "Pin little notes as replicants on your Desktop.\n" + "Dropped colors change the background of a note.")); + const char* extraCopyrights[] = { + "2012 siarzhuk ", + "2015 Janus", + "2021 Humdinger", + NULL + }; + const char* authors[] = { + B_TRANSLATE("Colin Stewart (original author)"), + "Humdinger", + "Janus", + "siarzhuk", + NULL + }; + aboutWin->AddCopyright(2000, "Colin Stewart", extraCopyrights); + aboutWin->AddAuthors(authors); + aboutWin->Show(); + break; + } + case DN_LAUNCH: + { + be_roster->Launch(app_signature); + break; + } + case DN_COLOR: + { + ssize_t colorLength; + if (msg->FindData("color", B_RGB_COLOR_TYPE, + (const void**)&bckgrnd, &colorLength) == B_OK + && colorLength == sizeof(rgb_color)) { + background = *bckgrnd; + _SetColors(); + } + break; + + // Font type + case FONT_FAMILY: { + + fontFamily = NULL; + fontStyle = NULL; + + // Setting the font family + message->FindPointer ("source", &ptr); + fCurrentFont = static_cast (ptr); + fontFamily = fCurrentFont->Label(); + SetFontStyle (fontFamily, fontStyle); + } + break; + + /*// Font style + case FONT_STYLE: { + + fontFamily = NULL; + fontStyle = NULL; + + // Setting the font style + message->FindPointer ("source", &ptr); + item = static_cast (ptr); + fontStyle = item->Label(); + menu = item->Menu(); + + if (menu != NULL) { + fCurrentFont = menu->Superitem(); + if (fCurrentFont != NULL) + fontFamily = fCurrentFont->Label(); + } + SetFontStyle (fontFamily, fontStyle); + + } + break;*/ + + default: + BView::MessageReceived(msg); + } +} + +} + + +void +DeskNoteView::FrameResized(float width, float height) +{ + BRect nowRect = textView->TextRect(); + BRect txtSize = ourSize = Bounds(); + txtSize.InsetBy(nowRect.left, 0); // keep left/right margins of the textview + + txtSize.bottom -= kWidgetSize + 2; + textView->SetTextRect(txtSize); + Invalidate(); +} + + +void +DeskNoteView::MouseDown(BPoint point) +{ + thread_id resizeThread; + BMessage* msg; + BMenuItem* menuItem; + BPoint mousePoint; + uint32 mouseButtons; + + if (!Window()->IsActive()) + Window()->Activate(true); + + textView->MakeFocus(true); + + GetMouse(&mousePoint, &mouseButtons, false); + if (point.x >= (ourSize.right - kWidgetSize) && point.y + >= (ourSize.bottom - kWidgetSize)) { + resizeThread = spawn_thread(DeskNoteView::ResizeViewMethod, + "Resize Thread", B_DISPLAY_PRIORITY, this); + if (resizeThread > 0) + resume_thread(resizeThread); + + } else if (mouseButtons == B_SECONDARY_MOUSE_BUTTON) + _ShowContextMenu(mousePoint); +} + +void +DeskNoteView::_BuildStyleMenu(BMenu* menu) +{ + //variables + font_family plainFamily, + family; + font_style plainStyle, + style; + BMenuItem* menuItem = NULL; + int32 numFamilies, + numStyles; + BMenu* fontMenu; + uint32 flags; + + + //Font Menu + fCurrentFont = 0; + + be_plain_font->GetFamilyAndStyle (&plainFamily,&plainStyle); + + // Taking the number of font families + numFamilies = count_font_families(); + for (int32 i = 0; i < numFamilies; i++) { + + // Getting the font families + if (get_font_family(i, &family) == B_OK) { + + // Creating a menu of that font family + fontMenu = new BMenu (family); + fontMenu->SetRadioMode (true); // I can set only one item as "in use" + styleMenu->AddItem (menuItem = new BMenuItem (fontMenu, new BMessage (FONT_FAMILY))); + + if (!strcmp (plainFamily,family)) { + menuItem->SetMarked (true); + fCurrentFont = menuItem; + } + //Number of styles of that font family + numStyles = count_font_styles (family); + + // Creating a submenu about each of that styles + for (int32 j = 0; j < numStyles; j++) { + + if (get_font_style(family,j,&style,&flags)==B_OK) { + fontMenu->AddItem (menuItem = new BMenuItem (style, new BMessage(FONT_STYLE))); + + if (!strcmp (plainStyle, style)) + menuItem->SetMarked(true); + + } + } + } + } +} + +void +DeskNoteView::_BuildColorMenu(BMenu* menu) +{ + if (menu == NULL) + return; + + BFont font; + menu->GetFont(&font); + font_height fh; + font.GetHeight(&fh); + + const float itemHeight = ceilf(fh.ascent + fh.descent + 2 * fh.leading); + const float margin = 8.0; + const int nbColumns = 4; + + BMessage msgTemplate(DN_COLOR); + BRect matrixArea(0, 0, 0, 0); + + // we place the color palette, reserving room at the top + for (uint i = 0; i < sizeof(palette) / sizeof(rgb_color); i++) { + BPoint topLeft((i % nbColumns) * (itemHeight + margin), + (i / nbColumns) * (itemHeight + margin)); + BRect buttonArea(topLeft.x, topLeft.y, topLeft.x + itemHeight, + topLeft.y + itemHeight); + buttonArea.OffsetBy(margin, margin); + + ColorMenuItem* colItem + = new ColorMenuItem("", palette[i], new BMessage(msgTemplate)); + + if (colItem != NULL && palette[i] == background) + colItem->SetMarked(true); + + colItem->SetTarget(this); + menu->AddItem(colItem, buttonArea); + + buttonArea.OffsetBy(margin, margin); + matrixArea = matrixArea | buttonArea; + } + + // separator at the bottom to add spacing in the matrix menu + matrixArea.top = matrixArea.bottom; + menu->AddItem(new BSeparatorItem(), matrixArea); +} + + +void +DeskNoteView::_SetColors() +{ + float thresh + = background.red + (background.green * 1.25f) + (background.blue * 0.45f); + if (thresh >= 360) { + foreground.red = 11; + foreground.green = 11; + foreground.blue = 11; + widgetcolour = tint_color(background, B_DARKEN_1_TINT); + } else { + foreground.red = 244; + foreground.green = 244; + foreground.blue = 244; + widgetcolour = tint_color(background, B_LIGHTEN_1_TINT); + } + + BFont font; + GetFont(&font); + textView->SetFontAndColor(&font, B_FONT_ALL, &foreground); + textView->SetViewColor(background); + this->Invalidate(); + textView->Invalidate(); + SetViewColor(background); + if (dragger != NULL) + dragger->Invalidate(); +} + + +void +DeskNoteView::_ShowContextMenu(BPoint where) +{ + bool isRedo; + undo_state state = textView->UndoState(&isRedo); + bool isUndo = state != B_UNDO_UNAVAILABLE && !isRedo; + + int32 start; + int32 finish; + textView->GetSelection(&start, &finish); + + bool canEdit = textView->IsEditable(); + int32 length = textView->TextLength(); + + BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false,B_ITEMS_IN_COLUMN); + + colorMenu = new BMenu(B_TRANSLATE("Color"), 0, 0); + _BuildColorMenu(colorMenu); + + styleMenu = new BMenu(B_TRANSLATE("Font Style"), 0, 0); + _BuildStyleMenu(styleMenu); + + BLayoutBuilder::Menu<>(menu) + .AddItem(B_TRANSLATE("Undo"), B_UNDO) + .SetEnabled(canEdit && isUndo) + .AddItem(B_TRANSLATE("Redo"), B_UNDO) + .SetEnabled(canEdit && isRedo) + .AddSeparator() + .AddItem(B_TRANSLATE("Cut"), B_CUT) + .SetEnabled(canEdit && start != finish) + .AddItem(B_TRANSLATE("Copy"), B_COPY) + .SetEnabled(start != finish) + .AddItem(B_TRANSLATE("Paste"), B_PASTE) + .SetEnabled(canEdit && be_clipboard->SystemCount() > 0) + .AddSeparator() + .AddItem(B_TRANSLATE("Select all"), B_SELECT_ALL) + .SetEnabled(!(start == 0 && finish == length)) + .AddSeparator() + // custom menu + .AddItem(styleMenu) + .AddItem(colorMenu) + .AddSeparator() + // About section + .AddItem(B_TRANSLATE("About DeskNotes" B_UTF8_ELLIPSIS), + new BMessage(B_ABOUT_REQUESTED)); + + // If we are replicant add the launch desknotes command to the menu. + if (WeAreAReplicant) { + menu->AddItem(new BMenuItem( + B_TRANSLATE("Launch DeskNotes" B_UTF8_ELLIPSIS), + new BMessage(DN_LAUNCH))); + } + + menu->SetTargetForItems(textView); + ConvertToScreen(&where); + menu->Go(where, true, true, true); +} + + +void +DeskNoteView::SaveNote(BMessage* msg) +{ + // Save the text of the note. + msg->AddString("NoteText", textView->Text()); + + // Save the foreground and background colours. + msg->AddData( + "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); +} + +// Function for the changes in the "type of font" +void DeskNoteView :: SetFontStyle (const char* fontFamily, const char* fontStyle) { + // Variables + BMenuItem *superItem; + BMenuItem *menuItem; + BFont font; + font_family oldFamily; + font_style oldStyle; + uint32 sameProperties; + rgb_color sameColor; + BMenuItem *oldItem; + + + // Copying the current font family and font style + font.GetFamilyAndStyle (&oldFamily, &oldStyle); + + if (strcmp (oldFamily, fontFamily)) { + oldItem = styleMenu->FindItem (oldFamily); + + if (oldItem != NULL) + // Removing the check + oldItem->SetMarked (false); + } + + font.SetFamilyAndStyle (fontFamily, fontStyle); + + + superItem = styleMenu->FindItem (fontFamily); + + if (superItem != NULL ) + superItem->SetMarked (true); // Check the one that was selected + + menuItem = fFontMenu->FindItem("Black"); + menuItem->SetMarked(true); +} + +void +DeskNoteView::RestoreNote(BMessage* msg) +{ + const rgb_color* bckgrnd; + ssize_t size; + const char* text; + + // Find the text of the note. + if (msg->FindString("NoteText", &text) == B_OK) + textView->SetText(text); + + // Find the background colour. + if (msg->FindData("background_colour", B_RGB_COLOR_TYPE, + (const void**) &bckgrnd, &size) == B_OK) + background = *bckgrnd; + + // Update the colour of the text view and widget. + _SetColors(); +} + + +BArchivable* +DeskNoteView::Instantiate(BMessage* data) +{ + if (!validate_instantiation(data, "DeskNoteView")) + return NULL; + return new DeskNoteView(data); +} + + +int32 +DeskNoteView::ResizeViewMethod(void* data) +{ + uint32 buttons; + BPoint cursor; + float x, y; + DeskNoteView* theView = (DeskNoteView*) data; + + do { + theView->Window()->Lock(); + theView->GetMouse(&cursor, &buttons); + if (cursor.x > 30) + x = cursor.x; + else + x = 30; + if (cursor.y > 20) + y = cursor.y; + else + y = 20; + if (theView->WeAreAReplicant) + theView->ResizeTo(x, y); + else + theView->Window()->ResizeTo(x, y); + theView->Window()->Unlock(); + snooze(20 * 1000); + } while (buttons); + + return 0; +} diff --git a/DeskNoteView.h b/DeskNoteView.h new file mode 100644 index 0000000..feb7b1a --- /dev/null +++ b/DeskNoteView.h @@ -0,0 +1,105 @@ +/* + * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). + * All rights reserved. + * Distributed under the terms of the BSD (3-clause) License. + * + * Authors: + * Janus2, 2015 + * Humdinger, 2021 + * + */ + + +#ifndef _DESKNOTEVIEW_H +#define _DESKNOTEVIEW_H + +#include +#include +#include + +#include "ColorMenuItem.h" +#include "DeskNoteApp.h" +#include "DeskNoteTextView.h" + + + +#define DN_LAUNCH 'dnLN' +#define DN_COLOR 'dnCL' + +const rgb_color palette[] = { + { 255, 221, 191, 255 }, // lightest red + { 255, 187, 128, 255 }, // light red + { 216, 158, 108, 255 }, // red + { 179, 83, 0, 255 }, // dark red + + { 255, 244, 191, 255 }, // lightest yellow + { 255, 233, 128, 255 }, // light yellow + { 215, 178, 0, 255 }, // yellow + { 179, 148, 0, 255 }, // dark yellow + + { 216, 255, 180, 255 }, // lightest green + { 177, 255, 169, 255 }, // light green + { 72, 187, 61, 255 }, // green + { 47, 122, 40, 255 }, // dark green + + { 213, 234, 255, 255 }, // lightest blue + { 170, 213, 255, 255 }, // light blue + { 67, 131, 196, 255 }, // blue + { 36, 71, 106, 255 }, // dark blue + + { 244, 244, 244, 255 }, // off white + { 188, 188, 188, 255 }, // light grey + { 96, 96, 96, 255 }, // dark grey + { 11, 11, 11, 255 }, // off black +}; + +class DeskNoteTextView; + +class DeskNoteView : public BView { +public: + DeskNoteView(BRect rect); + DeskNoteView(BMessage* data); + ~DeskNoteView(); + + virtual status_t Archive(BMessage* data, bool deep = true) const; + virtual void Draw(BRect rect); + virtual void MessageReceived(BMessage* msg); + virtual void FrameResized(float width, float height); + virtual void MouseDown(BPoint point); + virtual void SaveNote(BMessage* msg); + virtual void RestoreNote(BMessage* msg); + + static BArchivable* Instantiate(BMessage* data); + static int32 ResizeViewMethod(void* data); + + static const char defaultText[]; + static const char aboutText[]; + + void SetFontStyle(const char* fontFamily, + const char *fontStyle); + + + + +private: + void _BuildColorMenu(BMenu* menu); + void _BuildStyleMenu(BMenu* menu); + void _SetColors(); + void _ShowContextMenu(BPoint where); + bool WeAreAReplicant; + DeskNoteTextView* textView; + BRect ourSize; + BMenu* colorMenu; + BMenu* styleMenu; + BMenu* fFontMenu; + BMenuItem* fCurrentFont; + BMessage* orginalSettings; + BPopUpMenu* popupMenu; + rgb_color background; + rgb_color foreground; + rgb_color widgetcolour; + BDragger* dragger; + +}; + +#endif // _DESKNOTEVIEW_H From ab219d93e6724e7046f0d7096fbf9cf2e6f4ce71 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Sat, 11 Mar 2023 04:54:57 +0530 Subject: [PATCH 07/16] Update DeskNoteView.cpp --- DeskNoteView.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp index d8cb1b8..57de4d1 100644 --- a/DeskNoteView.cpp +++ b/DeskNoteView.cpp @@ -211,7 +211,7 @@ DeskNoteView::MessageReceived(BMessage* msg) } break; - /*// Font style + // Font style case FONT_STYLE: { fontFamily = NULL; @@ -231,7 +231,7 @@ DeskNoteView::MessageReceived(BMessage* msg) SetFontStyle (fontFamily, fontStyle); } - break;*/ + break; default: BView::MessageReceived(msg); @@ -310,7 +310,7 @@ DeskNoteView::_BuildStyleMenu(BMenu* menu) // Creating a menu of that font family fontMenu = new BMenu (family); fontMenu->SetRadioMode (true); // I can set only one item as "in use" - styleMenu->AddItem (menuItem = new BMenuItem (fontMenu, new BMessage (FONT_FAMILY))); + menu->AddItem (menuItem = new BMenuItem (fontMenu, new BMessage (FONT_FAMILY))); if (!strcmp (plainFamily,family)) { menuItem->SetMarked (true); From 392477455d357abccbb5d1877ae325ed0fff72e9 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Sat, 11 Mar 2023 14:35:50 +0530 Subject: [PATCH 08/16] Update DeskNoteView.cpp --- DeskNoteView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp index 57de4d1..1e3096b 100644 --- a/DeskNoteView.cpp +++ b/DeskNoteView.cpp @@ -427,7 +427,7 @@ DeskNoteView::_ShowContextMenu(BPoint where) colorMenu = new BMenu(B_TRANSLATE("Color"), 0, 0); _BuildColorMenu(colorMenu); - styleMenu = new BMenu(B_TRANSLATE("Font Style"), 0, 0); + styleMenu = new BMenu(B_TRANSLATE("Font Style")); _BuildStyleMenu(styleMenu); BLayoutBuilder::Menu<>(menu) From efafde864aeb997e1c88e0e613fce527f5341c54 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Sat, 11 Mar 2023 09:35:45 +0000 Subject: [PATCH 09/16] Update DeskNoteView.cpp --- DeskNoteView.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp index 1e3096b..3916082 100644 --- a/DeskNoteView.cpp +++ b/DeskNoteView.cpp @@ -196,7 +196,7 @@ DeskNoteView::MessageReceived(BMessage* msg) _SetColors(); } break; - + } // Font type case FONT_FAMILY: { @@ -238,7 +238,7 @@ DeskNoteView::MessageReceived(BMessage* msg) } } -} + void From 9c0c0ac69e562a5d80bcd73d033db31f25ca62e2 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Sun, 12 Mar 2023 21:16:20 +0530 Subject: [PATCH 10/16] Delete DeskNoteView.cpp --- DeskNoteView.cpp | 575 ----------------------------------------------- 1 file changed, 575 deletions(-) delete mode 100644 DeskNoteView.cpp diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp deleted file mode 100644 index 3916082..0000000 --- a/DeskNoteView.cpp +++ /dev/null @@ -1,575 +0,0 @@ -/* - * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). - * All rights reserved. - * Distributed under the terms of the BSD (3-clause) License. - * - * Authors: - * Janus2, 2015 - * Humdinger, 2021 - * - */ - - -#include "DeskNoteView.h" - -#include -#include -#include -#include -#include -#include -#include - - -#undef B_TRANSLATION_CONTEXT -#define B_TRANSLATION_CONTEXT "View" - - -#define FONT_FAMILY 'fntf' -#define FONT_STYLE 'ftst' - -const float kWidgetSize = 7; - - -DeskNoteView::DeskNoteView(BRect rect) - : - BView(rect, "DeskNotes", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS) -{ - BRect draggerRect = rect; - BRect textViewRect = rect; - BPopUpMenu* draggerPop; - BMenuItem* popupMenu; - BMessage* popupMessage; - ourSize = rect; - - WeAreAReplicant = false; - - draggerRect.OffsetTo(B_ORIGIN); - draggerRect.top = draggerRect.bottom - kWidgetSize; - draggerRect.right = draggerRect.left + kWidgetSize; - - dragger = new BDragger(draggerRect, this, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - textViewRect.bottom -= kWidgetSize + 1; // Don't collide with the widgets. - - textView = new DeskNoteTextView(textViewRect, "TextView", textViewRect, - B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED); - BString defaultText(B_TRANSLATE( - "\n\tWelcome to DeskNotes!\n\n" - "\t*\tUse as Replicants on your Desktop\n" - "\t*\tResize with the bottom-right widget\n" - "\t*\tRight-click for a context menu\n" - "\t*\tUse different colors from the 'Color' menu\n" - "\t*\tColors dropped from other apps like\n" - "\t\tIcon-O-Matic change the background\n\n" - "\tHave a nice day!")); - textView->SetText(defaultText); - AddChild(textView); - - background = palette[0]; - SetViewColor(background); - AddChild(dragger); - _SetColors(); -} - - -DeskNoteView::DeskNoteView(BMessage* data) - : - BView(data) -{ - const rgb_color* bckgrnd; - ssize_t size; - - WeAreAReplicant = true; - textView = dynamic_cast(FindView("TextView")); - dragger = dynamic_cast(FindView("_dragger_")); - - data->FindData( - "background_colour", B_RGB_COLOR_TYPE, (const void**) &bckgrnd, &size); - - background = *bckgrnd; - _SetColors(); - SetResizingMode(B_FOLLOW_NONE); -} - - -DeskNoteView::~DeskNoteView() -{ -} - - -status_t -DeskNoteView::Archive(BMessage* data, bool deep) const -{ - BView::Archive(data, deep); - // These first two fields are internal Archiving fields. - data->AddString("class", "DeskNoteView"); - data->AddString("add_on", app_signature); - - // Now add the foreground and background colours. - data->AddData( - "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); - - return B_NO_ERROR; -} - - -void -DeskNoteView::Draw(BRect rct) -{ - ourSize = Bounds(); - BRect rect = ourSize; - BRect cleanRect = ourSize; - - rect.top = rect.bottom - kWidgetSize; - rect.left = rect.right - kWidgetSize; - - cleanRect.top = rect.top; - cleanRect.right = rect.left - 1; // Don't overlap with the resize widget. - SetHighColor(widgetcolour); - FillRect(rect); - SetHighColor(background); - FillRect(cleanRect); -} - - -void -DeskNoteView::MessageReceived(BMessage* msg) -{ - BAlert *alert; - BRect windSize, - ourSize; - BMessenger *messenger; - BMessage *message; - BFont currentFont; - BMenuItem *item; - BMenu *menu; - font_family currentFamily; - font_style currentStyle; - uint16 currentFace; - const rgb_color *bckgrnd; - ssize_t size; - const char *fontFamily, - *fontStyle; - void *ptr; - - switch (msg->what) { - case B_ABOUT_REQUESTED: - { - // Set the mouse cursor! - be_app->SetCursor(B_HAND_CURSOR); - - BAboutWindow* aboutWin = new BAboutWindow("DeskNotes", - app_signature); - aboutWin->AddDescription(B_TRANSLATE( - "Pin little notes as replicants on your Desktop.\n" - "Dropped colors change the background of a note.")); - const char* extraCopyrights[] = { - "2012 siarzhuk ", - "2015 Janus", - "2021 Humdinger", - NULL - }; - const char* authors[] = { - B_TRANSLATE("Colin Stewart (original author)"), - "Humdinger", - "Janus", - "siarzhuk", - NULL - }; - aboutWin->AddCopyright(2000, "Colin Stewart", extraCopyrights); - aboutWin->AddAuthors(authors); - aboutWin->Show(); - break; - } - case DN_LAUNCH: - { - be_roster->Launch(app_signature); - break; - } - case DN_COLOR: - { - ssize_t colorLength; - if (msg->FindData("color", B_RGB_COLOR_TYPE, - (const void**)&bckgrnd, &colorLength) == B_OK - && colorLength == sizeof(rgb_color)) { - background = *bckgrnd; - _SetColors(); - } - break; - } - // Font type - case FONT_FAMILY: { - - fontFamily = NULL; - fontStyle = NULL; - - // Setting the font family - message->FindPointer ("source", &ptr); - fCurrentFont = static_cast (ptr); - fontFamily = fCurrentFont->Label(); - SetFontStyle (fontFamily, fontStyle); - } - break; - - // Font style - case FONT_STYLE: { - - fontFamily = NULL; - fontStyle = NULL; - - // Setting the font style - message->FindPointer ("source", &ptr); - item = static_cast (ptr); - fontStyle = item->Label(); - menu = item->Menu(); - - if (menu != NULL) { - fCurrentFont = menu->Superitem(); - if (fCurrentFont != NULL) - fontFamily = fCurrentFont->Label(); - } - SetFontStyle (fontFamily, fontStyle); - - } - break; - - default: - BView::MessageReceived(msg); - } -} - - - - -void -DeskNoteView::FrameResized(float width, float height) -{ - BRect nowRect = textView->TextRect(); - BRect txtSize = ourSize = Bounds(); - txtSize.InsetBy(nowRect.left, 0); // keep left/right margins of the textview - - txtSize.bottom -= kWidgetSize + 2; - textView->SetTextRect(txtSize); - Invalidate(); -} - - -void -DeskNoteView::MouseDown(BPoint point) -{ - thread_id resizeThread; - BMessage* msg; - BMenuItem* menuItem; - BPoint mousePoint; - uint32 mouseButtons; - - if (!Window()->IsActive()) - Window()->Activate(true); - - textView->MakeFocus(true); - - GetMouse(&mousePoint, &mouseButtons, false); - if (point.x >= (ourSize.right - kWidgetSize) && point.y - >= (ourSize.bottom - kWidgetSize)) { - resizeThread = spawn_thread(DeskNoteView::ResizeViewMethod, - "Resize Thread", B_DISPLAY_PRIORITY, this); - if (resizeThread > 0) - resume_thread(resizeThread); - - } else if (mouseButtons == B_SECONDARY_MOUSE_BUTTON) - _ShowContextMenu(mousePoint); -} - -void -DeskNoteView::_BuildStyleMenu(BMenu* menu) -{ - //variables - font_family plainFamily, - family; - font_style plainStyle, - style; - BMenuItem* menuItem = NULL; - int32 numFamilies, - numStyles; - BMenu* fontMenu; - uint32 flags; - - - //Font Menu - fCurrentFont = 0; - - be_plain_font->GetFamilyAndStyle (&plainFamily,&plainStyle); - - // Taking the number of font families - numFamilies = count_font_families(); - for (int32 i = 0; i < numFamilies; i++) { - - // Getting the font families - if (get_font_family(i, &family) == B_OK) { - - // Creating a menu of that font family - fontMenu = new BMenu (family); - fontMenu->SetRadioMode (true); // I can set only one item as "in use" - menu->AddItem (menuItem = new BMenuItem (fontMenu, new BMessage (FONT_FAMILY))); - - if (!strcmp (plainFamily,family)) { - menuItem->SetMarked (true); - fCurrentFont = menuItem; - } - //Number of styles of that font family - numStyles = count_font_styles (family); - - // Creating a submenu about each of that styles - for (int32 j = 0; j < numStyles; j++) { - - if (get_font_style(family,j,&style,&flags)==B_OK) { - fontMenu->AddItem (menuItem = new BMenuItem (style, new BMessage(FONT_STYLE))); - - if (!strcmp (plainStyle, style)) - menuItem->SetMarked(true); - - } - } - } - } -} - -void -DeskNoteView::_BuildColorMenu(BMenu* menu) -{ - if (menu == NULL) - return; - - BFont font; - menu->GetFont(&font); - font_height fh; - font.GetHeight(&fh); - - const float itemHeight = ceilf(fh.ascent + fh.descent + 2 * fh.leading); - const float margin = 8.0; - const int nbColumns = 4; - - BMessage msgTemplate(DN_COLOR); - BRect matrixArea(0, 0, 0, 0); - - // we place the color palette, reserving room at the top - for (uint i = 0; i < sizeof(palette) / sizeof(rgb_color); i++) { - BPoint topLeft((i % nbColumns) * (itemHeight + margin), - (i / nbColumns) * (itemHeight + margin)); - BRect buttonArea(topLeft.x, topLeft.y, topLeft.x + itemHeight, - topLeft.y + itemHeight); - buttonArea.OffsetBy(margin, margin); - - ColorMenuItem* colItem - = new ColorMenuItem("", palette[i], new BMessage(msgTemplate)); - - if (colItem != NULL && palette[i] == background) - colItem->SetMarked(true); - - colItem->SetTarget(this); - menu->AddItem(colItem, buttonArea); - - buttonArea.OffsetBy(margin, margin); - matrixArea = matrixArea | buttonArea; - } - - // separator at the bottom to add spacing in the matrix menu - matrixArea.top = matrixArea.bottom; - menu->AddItem(new BSeparatorItem(), matrixArea); -} - - -void -DeskNoteView::_SetColors() -{ - float thresh - = background.red + (background.green * 1.25f) + (background.blue * 0.45f); - if (thresh >= 360) { - foreground.red = 11; - foreground.green = 11; - foreground.blue = 11; - widgetcolour = tint_color(background, B_DARKEN_1_TINT); - } else { - foreground.red = 244; - foreground.green = 244; - foreground.blue = 244; - widgetcolour = tint_color(background, B_LIGHTEN_1_TINT); - } - - BFont font; - GetFont(&font); - textView->SetFontAndColor(&font, B_FONT_ALL, &foreground); - textView->SetViewColor(background); - this->Invalidate(); - textView->Invalidate(); - SetViewColor(background); - if (dragger != NULL) - dragger->Invalidate(); -} - - -void -DeskNoteView::_ShowContextMenu(BPoint where) -{ - bool isRedo; - undo_state state = textView->UndoState(&isRedo); - bool isUndo = state != B_UNDO_UNAVAILABLE && !isRedo; - - int32 start; - int32 finish; - textView->GetSelection(&start, &finish); - - bool canEdit = textView->IsEditable(); - int32 length = textView->TextLength(); - - BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false,B_ITEMS_IN_COLUMN); - - colorMenu = new BMenu(B_TRANSLATE("Color"), 0, 0); - _BuildColorMenu(colorMenu); - - styleMenu = new BMenu(B_TRANSLATE("Font Style")); - _BuildStyleMenu(styleMenu); - - BLayoutBuilder::Menu<>(menu) - .AddItem(B_TRANSLATE("Undo"), B_UNDO) - .SetEnabled(canEdit && isUndo) - .AddItem(B_TRANSLATE("Redo"), B_UNDO) - .SetEnabled(canEdit && isRedo) - .AddSeparator() - .AddItem(B_TRANSLATE("Cut"), B_CUT) - .SetEnabled(canEdit && start != finish) - .AddItem(B_TRANSLATE("Copy"), B_COPY) - .SetEnabled(start != finish) - .AddItem(B_TRANSLATE("Paste"), B_PASTE) - .SetEnabled(canEdit && be_clipboard->SystemCount() > 0) - .AddSeparator() - .AddItem(B_TRANSLATE("Select all"), B_SELECT_ALL) - .SetEnabled(!(start == 0 && finish == length)) - .AddSeparator() - // custom menu - .AddItem(styleMenu) - .AddItem(colorMenu) - .AddSeparator() - // About section - .AddItem(B_TRANSLATE("About DeskNotes" B_UTF8_ELLIPSIS), - new BMessage(B_ABOUT_REQUESTED)); - - // If we are replicant add the launch desknotes command to the menu. - if (WeAreAReplicant) { - menu->AddItem(new BMenuItem( - B_TRANSLATE("Launch DeskNotes" B_UTF8_ELLIPSIS), - new BMessage(DN_LAUNCH))); - } - - menu->SetTargetForItems(textView); - ConvertToScreen(&where); - menu->Go(where, true, true, true); -} - - -void -DeskNoteView::SaveNote(BMessage* msg) -{ - // Save the text of the note. - msg->AddString("NoteText", textView->Text()); - - // Save the foreground and background colours. - msg->AddData( - "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); -} - -// Function for the changes in the "type of font" -void DeskNoteView :: SetFontStyle (const char* fontFamily, const char* fontStyle) { - // Variables - BMenuItem *superItem; - BMenuItem *menuItem; - BFont font; - font_family oldFamily; - font_style oldStyle; - uint32 sameProperties; - rgb_color sameColor; - BMenuItem *oldItem; - - - // Copying the current font family and font style - font.GetFamilyAndStyle (&oldFamily, &oldStyle); - - if (strcmp (oldFamily, fontFamily)) { - oldItem = styleMenu->FindItem (oldFamily); - - if (oldItem != NULL) - // Removing the check - oldItem->SetMarked (false); - } - - font.SetFamilyAndStyle (fontFamily, fontStyle); - - - superItem = styleMenu->FindItem (fontFamily); - - if (superItem != NULL ) - superItem->SetMarked (true); // Check the one that was selected - - menuItem = fFontMenu->FindItem("Black"); - menuItem->SetMarked(true); -} - -void -DeskNoteView::RestoreNote(BMessage* msg) -{ - const rgb_color* bckgrnd; - ssize_t size; - const char* text; - - // Find the text of the note. - if (msg->FindString("NoteText", &text) == B_OK) - textView->SetText(text); - - // Find the background colour. - if (msg->FindData("background_colour", B_RGB_COLOR_TYPE, - (const void**) &bckgrnd, &size) == B_OK) - background = *bckgrnd; - - // Update the colour of the text view and widget. - _SetColors(); -} - - -BArchivable* -DeskNoteView::Instantiate(BMessage* data) -{ - if (!validate_instantiation(data, "DeskNoteView")) - return NULL; - return new DeskNoteView(data); -} - - -int32 -DeskNoteView::ResizeViewMethod(void* data) -{ - uint32 buttons; - BPoint cursor; - float x, y; - DeskNoteView* theView = (DeskNoteView*) data; - - do { - theView->Window()->Lock(); - theView->GetMouse(&cursor, &buttons); - if (cursor.x > 30) - x = cursor.x; - else - x = 30; - if (cursor.y > 20) - y = cursor.y; - else - y = 20; - if (theView->WeAreAReplicant) - theView->ResizeTo(x, y); - else - theView->Window()->ResizeTo(x, y); - theView->Window()->Unlock(); - snooze(20 * 1000); - } while (buttons); - - return 0; -} From f239a6d6782d275b84455d8d82260a6f30889255 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Sun, 12 Mar 2023 21:16:34 +0530 Subject: [PATCH 11/16] Delete DeskNoteView.h --- DeskNoteView.h | 105 ------------------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 DeskNoteView.h diff --git a/DeskNoteView.h b/DeskNoteView.h deleted file mode 100644 index feb7b1a..0000000 --- a/DeskNoteView.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). - * All rights reserved. - * Distributed under the terms of the BSD (3-clause) License. - * - * Authors: - * Janus2, 2015 - * Humdinger, 2021 - * - */ - - -#ifndef _DESKNOTEVIEW_H -#define _DESKNOTEVIEW_H - -#include -#include -#include - -#include "ColorMenuItem.h" -#include "DeskNoteApp.h" -#include "DeskNoteTextView.h" - - - -#define DN_LAUNCH 'dnLN' -#define DN_COLOR 'dnCL' - -const rgb_color palette[] = { - { 255, 221, 191, 255 }, // lightest red - { 255, 187, 128, 255 }, // light red - { 216, 158, 108, 255 }, // red - { 179, 83, 0, 255 }, // dark red - - { 255, 244, 191, 255 }, // lightest yellow - { 255, 233, 128, 255 }, // light yellow - { 215, 178, 0, 255 }, // yellow - { 179, 148, 0, 255 }, // dark yellow - - { 216, 255, 180, 255 }, // lightest green - { 177, 255, 169, 255 }, // light green - { 72, 187, 61, 255 }, // green - { 47, 122, 40, 255 }, // dark green - - { 213, 234, 255, 255 }, // lightest blue - { 170, 213, 255, 255 }, // light blue - { 67, 131, 196, 255 }, // blue - { 36, 71, 106, 255 }, // dark blue - - { 244, 244, 244, 255 }, // off white - { 188, 188, 188, 255 }, // light grey - { 96, 96, 96, 255 }, // dark grey - { 11, 11, 11, 255 }, // off black -}; - -class DeskNoteTextView; - -class DeskNoteView : public BView { -public: - DeskNoteView(BRect rect); - DeskNoteView(BMessage* data); - ~DeskNoteView(); - - virtual status_t Archive(BMessage* data, bool deep = true) const; - virtual void Draw(BRect rect); - virtual void MessageReceived(BMessage* msg); - virtual void FrameResized(float width, float height); - virtual void MouseDown(BPoint point); - virtual void SaveNote(BMessage* msg); - virtual void RestoreNote(BMessage* msg); - - static BArchivable* Instantiate(BMessage* data); - static int32 ResizeViewMethod(void* data); - - static const char defaultText[]; - static const char aboutText[]; - - void SetFontStyle(const char* fontFamily, - const char *fontStyle); - - - - -private: - void _BuildColorMenu(BMenu* menu); - void _BuildStyleMenu(BMenu* menu); - void _SetColors(); - void _ShowContextMenu(BPoint where); - bool WeAreAReplicant; - DeskNoteTextView* textView; - BRect ourSize; - BMenu* colorMenu; - BMenu* styleMenu; - BMenu* fFontMenu; - BMenuItem* fCurrentFont; - BMessage* orginalSettings; - BPopUpMenu* popupMenu; - rgb_color background; - rgb_color foreground; - rgb_color widgetcolour; - BDragger* dragger; - -}; - -#endif // _DESKNOTEVIEW_H From 18adae415e553a353309102f5fc5f23896254317 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty <87941013+BarmenduC@users.noreply.github.com> Date: Sun, 12 Mar 2023 21:17:35 +0530 Subject: [PATCH 12/16] Add files via upload --- DeskNoteView.cpp | 581 +++++++++++++++++++++++++++++++++++++++++++++++ DeskNoteView.h | 107 +++++++++ 2 files changed, 688 insertions(+) create mode 100644 DeskNoteView.cpp create mode 100644 DeskNoteView.h diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp new file mode 100644 index 0000000..be05fb3 --- /dev/null +++ b/DeskNoteView.cpp @@ -0,0 +1,581 @@ +/* + * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). + * All rights reserved. + * Distributed under the terms of the BSD (3-clause) License. + * + * Authors: + * Janus2, 2015 + * Humdinger, 2021 + * + */ + + +#include "DeskNoteView.h" + +#include +#include +#include +#include +#include +#include +#include + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "View" + + + + +const float kWidgetSize = 7; + + +DeskNoteView::DeskNoteView(BRect rect) + : + BView(rect, "DeskNotes", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS) +{ + BRect draggerRect = rect; + BRect textViewRect = rect; + BPopUpMenu* draggerPop; + BMenuItem* popupMenu; + BMessage* popupMessage; + ourSize = rect; + + WeAreAReplicant = false; + + draggerRect.OffsetTo(B_ORIGIN); + draggerRect.top = draggerRect.bottom - kWidgetSize; + draggerRect.right = draggerRect.left + kWidgetSize; + + dragger = new BDragger(draggerRect, this, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); + textViewRect.bottom -= kWidgetSize + 1; // Don't collide with the widgets. + + textView = new DeskNoteTextView(textViewRect, "TextView", textViewRect, + B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED); + BString defaultText(B_TRANSLATE( + "\n\tWelcome to DeskNotes!\n\n" + "\t*\tUse as Replicants on your Desktop\n" + "\t*\tResize with the bottom-right widget\n" + "\t*\tRight-click for a context menu\n" + "\t*\tUse different colors from the 'Color' menu\n" + "\t*\tColors dropped from other apps like\n" + "\t\tIcon-O-Matic change the background\n\n" + "\tHave a nice day!")); + textView->SetText(defaultText); + AddChild(textView); + + background = palette[0]; + SetViewColor(background); + AddChild(dragger); + _SetColors(); +} + + +DeskNoteView::DeskNoteView(BMessage* data) + : + BView(data) +{ + const rgb_color* bckgrnd; + ssize_t size; + + WeAreAReplicant = true; + textView = dynamic_cast(FindView("TextView")); + dragger = dynamic_cast(FindView("_dragger_")); + + data->FindData( + "background_colour", B_RGB_COLOR_TYPE, (const void**) &bckgrnd, &size); + + background = *bckgrnd; + _SetColors(); + SetResizingMode(B_FOLLOW_NONE); +} + + +DeskNoteView::~DeskNoteView() +{ +} + + +status_t +DeskNoteView::Archive(BMessage* data, bool deep) const +{ + BView::Archive(data, deep); + // These first two fields are internal Archiving fields. + data->AddString("class", "DeskNoteView"); + data->AddString("add_on", app_signature); + + // Now add the foreground and background colours. + data->AddData( + "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); + + return B_NO_ERROR; +} + + +void +DeskNoteView::Draw(BRect rct) +{ + ourSize = Bounds(); + BRect rect = ourSize; + BRect cleanRect = ourSize; + + rect.top = rect.bottom - kWidgetSize; + rect.left = rect.right - kWidgetSize; + + cleanRect.top = rect.top; + cleanRect.right = rect.left - 1; // Don't overlap with the resize widget. + SetHighColor(widgetcolour); + FillRect(rect); + SetHighColor(background); + FillRect(cleanRect); +} + + +void +DeskNoteView::MessageReceived(BMessage* msg) +{ + BAlert *alert; + BRect windSize, + ourSize; + BMessenger *messenger; + BMessage *message; + //BFont currentFont; + BMenuItem *item; + BMenu *menu; + //font_family currentFamily; + //font_style currentStyle; + uint16 currentFace; + const rgb_color *bckgrnd; + ssize_t size; + const char *fontFamily, + *fontStyle; + void *ptr; + + switch (msg->what) { + case B_ABOUT_REQUESTED: + { + // Set the mouse cursor! + be_app->SetCursor(B_HAND_CURSOR); + + BAboutWindow* aboutWin = new BAboutWindow("DeskNotes", + app_signature); + aboutWin->AddDescription(B_TRANSLATE( + "Pin little notes as replicants on your Desktop.\n" + "Dropped colors change the background of a note.")); + const char* extraCopyrights[] = { + "2012 siarzhuk ", + "2015 Janus", + "2021 Humdinger", + NULL + }; + const char* authors[] = { + B_TRANSLATE("Colin Stewart (original author)"), + "Humdinger", + "Janus", + "siarzhuk", + NULL + }; + aboutWin->AddCopyright(2000, "Colin Stewart", extraCopyrights); + aboutWin->AddAuthors(authors); + aboutWin->Show(); + break; + } + case DN_LAUNCH: + { + be_roster->Launch(app_signature); + break; + } + case DN_COLOR: + { + ssize_t colorLength; + if (msg->FindData("color", B_RGB_COLOR_TYPE, + (const void**)&bckgrnd, &colorLength) == B_OK + && colorLength == sizeof(rgb_color)) { + background = *bckgrnd; + _SetColors(); + } + break; + } + // Font type + case FONT_FAMILY: { + + fontFamily = NULL; + fontStyle = NULL; + + // Setting the font family + msg->FindPointer ("source", &ptr); + fCurrentFont = static_cast (ptr); + fontFamily = fCurrentFont->Label(); + SetFontStyle (fontFamily, fontStyle); + } + break; + + // Font style + case FONT_STYLE: { + + fontFamily = NULL; + fontStyle = NULL; + + // Setting the font style + msg->FindPointer ("source", &ptr); + item = static_cast (ptr); + fontStyle = item->Label(); + menu = item->Menu(); + + if (menu != NULL) { + fCurrentFont = menu->Superitem(); + if (fCurrentFont != NULL) + fontFamily = fCurrentFont->Label(); + } + SetFontStyle (fontFamily, fontStyle); + } + + break; + + default: + BView::MessageReceived(msg); + } +} + + + +void +DeskNoteView::FrameResized(float width, float height) +{ + BRect nowRect = textView->TextRect(); + BRect txtSize = ourSize = Bounds(); + txtSize.InsetBy(nowRect.left, 0); // keep left/right margins of the textview + + txtSize.bottom -= kWidgetSize + 2; + textView->SetTextRect(txtSize); + Invalidate(); +} + + +void +DeskNoteView::MouseDown(BPoint point) +{ + thread_id resizeThread; + BMessage* msg; + BMenuItem* menuItem; + BPoint mousePoint; + uint32 mouseButtons; + + if (!Window()->IsActive()) + Window()->Activate(true); + + textView->MakeFocus(true); + + GetMouse(&mousePoint, &mouseButtons, false); + if (point.x >= (ourSize.right - kWidgetSize) && point.y + >= (ourSize.bottom - kWidgetSize)) { + resizeThread = spawn_thread(DeskNoteView::ResizeViewMethod, + "Resize Thread", B_DISPLAY_PRIORITY, this); + if (resizeThread > 0) + resume_thread(resizeThread); + + } else if (mouseButtons == B_SECONDARY_MOUSE_BUTTON) + _ShowContextMenu(mousePoint); +} + +void +DeskNoteView::_BuildStyleMenu(BMenu* menu) +{ + //variables + font_family plainFamily, + family; + font_style plainStyle, + style; + BMenuItem* menuItem = NULL; + int32 numFamilies, + numStyles; + BMenu* fontMenu; + uint32 flags; + + if (menu == NULL) + return; + + + //Font Menu + fCurrentFont = 0; + + be_plain_font->GetFamilyAndStyle (&plainFamily,&plainStyle); + + // Taking the number of font families + numFamilies = count_font_families(); + for (int32 i = 0; i < numFamilies; i++) { + + // Getting the font families + if (get_font_family(i, &family) == B_OK) { + + // Creating a menu of that font family + fontMenu = new BMenu (family); + fontMenu->SetRadioMode (true); // I can set only one item as "in use" + menuItem = new BMenuItem (fontMenu, new BMessage (FONT_FAMILY)); + menuItem->SetTarget(this); + menu->AddItem (menuItem); + + if (!strcmp (plainFamily,family)) { + //menuItem->SetMarked (true); + fCurrentFont = menuItem; + } + //Number of styles of that font family + numStyles = count_font_styles (family); + + // Creating a submenu about each of that styles + for (int32 j = 0; j < numStyles; j++) { + + if (get_font_style(family,j,&style,&flags)==B_OK) { + menuItem = new BMenuItem (style, new BMessage(FONT_STYLE)); + menuItem->SetTarget(this); + fontMenu->AddItem (menuItem); + + //if (!strcmp (plainStyle, style)) + //menuItem->SetMarked(true); + + } + } + } + } +} + +void +DeskNoteView::_BuildColorMenu(BMenu* menu) +{ + if (menu == NULL) + return; + + BFont font; + menu->GetFont(&font); + font_height fh; + font.GetHeight(&fh); + + const float itemHeight = ceilf(fh.ascent + fh.descent + 2 * fh.leading); + const float margin = 8.0; + const int nbColumns = 4; + + BMessage msgTemplate(DN_COLOR); + BRect matrixArea(0, 0, 0, 0); + + // we place the color palette, reserving room at the top + for (uint i = 0; i < sizeof(palette) / sizeof(rgb_color); i++) { + BPoint topLeft((i % nbColumns) * (itemHeight + margin), + (i / nbColumns) * (itemHeight + margin)); + BRect buttonArea(topLeft.x, topLeft.y, topLeft.x + itemHeight, + topLeft.y + itemHeight); + buttonArea.OffsetBy(margin, margin); + + ColorMenuItem* colItem + = new ColorMenuItem("", palette[i], new BMessage(msgTemplate)); + + if (colItem != NULL && palette[i] == background) + colItem->SetMarked(true); + + colItem->SetTarget(this); + menu->AddItem(colItem, buttonArea); + + buttonArea.OffsetBy(margin, margin); + matrixArea = matrixArea | buttonArea; + } + + // separator at the bottom to add spacing in the matrix menu + matrixArea.top = matrixArea.bottom; + menu->AddItem(new BSeparatorItem(), matrixArea); +} + + +void +DeskNoteView::_SetColors() +{ + float thresh + = background.red + (background.green * 1.25f) + (background.blue * 0.45f); + if (thresh >= 360) { + foreground.red = 11; + foreground.green = 11; + foreground.blue = 11; + widgetcolour = tint_color(background, B_DARKEN_1_TINT); + } else { + foreground.red = 244; + foreground.green = 244; + foreground.blue = 244; + widgetcolour = tint_color(background, B_LIGHTEN_1_TINT); + } + + BFont font; + GetFont(&font); + textView->SetFontAndColor(&font, B_FONT_ALL, &foreground); + textView->SetViewColor(background); + this->Invalidate(); + textView->Invalidate(); + SetViewColor(background); + if (dragger != NULL) + dragger->Invalidate(); +} + + +void +DeskNoteView::_ShowContextMenu(BPoint where) +{ + bool isRedo; + undo_state state = textView->UndoState(&isRedo); + bool isUndo = state != B_UNDO_UNAVAILABLE && !isRedo; + + int32 start; + int32 finish; + textView->GetSelection(&start, &finish); + + bool canEdit = textView->IsEditable(); + int32 length = textView->TextLength(); + + BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false,B_ITEMS_IN_COLUMN); + + colorMenu = new BMenu(B_TRANSLATE("Color"), 0, 0); + _BuildColorMenu(colorMenu); + + styleMenu = new BMenu(B_TRANSLATE("Font Style")); + styleMenu->SetRadioMode(true); + _BuildStyleMenu(styleMenu); + + BLayoutBuilder::Menu<>(menu) + .AddItem(B_TRANSLATE("Undo"), B_UNDO) + .SetEnabled(canEdit && isUndo) + .AddItem(B_TRANSLATE("Redo"), B_UNDO) + .SetEnabled(canEdit && isRedo) + .AddSeparator() + .AddItem(B_TRANSLATE("Cut"), B_CUT) + .SetEnabled(canEdit && start != finish) + .AddItem(B_TRANSLATE("Copy"), B_COPY) + .SetEnabled(start != finish) + .AddItem(B_TRANSLATE("Paste"), B_PASTE) + .SetEnabled(canEdit && be_clipboard->SystemCount() > 0) + .AddSeparator() + .AddItem(B_TRANSLATE("Select all"), B_SELECT_ALL) + .SetEnabled(!(start == 0 && finish == length)) + .AddSeparator() + // custom menu + .AddItem(colorMenu) + .AddItem(styleMenu) + .AddSeparator() + // About section + .AddItem(B_TRANSLATE("About DeskNotes" B_UTF8_ELLIPSIS), + new BMessage(B_ABOUT_REQUESTED)); + + // If we are replicant add the launch desknotes command to the menu. + if (WeAreAReplicant) { + menu->AddItem(new BMenuItem( + B_TRANSLATE("Launch DeskNotes" B_UTF8_ELLIPSIS), + new BMessage(DN_LAUNCH))); + } + + menu->SetTargetForItems(textView); + ConvertToScreen(&where); + menu->Go(where, true, true, true); +} + + +void +DeskNoteView::SaveNote(BMessage* msg) +{ + // Save the text of the note. + msg->AddString("NoteText", textView->Text()); + + // Save the foreground and background colours. + msg->AddData( + "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); +} + +// Function for the changes in the "type of font" +void DeskNoteView :: SetFontStyle (const char* fontFamily, const char* fontStyle) { + // Variables + BMenuItem *superItem; + BMenuItem *menuItem; + BFont font; + font_family oldFamily; + font_style oldStyle; + uint32 sameProperties; + rgb_color sameColor; + BMenuItem *oldItem; + + textView->GetFontAndColor (&font, &sameProperties, &sameColor); + // Copying the current font family and font style + font.GetFamilyAndStyle (&oldFamily, &oldStyle); + + if (strcmp (oldFamily, fontFamily)) { + oldItem = styleMenu->FindItem (oldFamily); + + if (oldItem != NULL) + // Removing the check + oldItem->SetMarked (false); + } + + font.SetFamilyAndStyle (fontFamily, fontStyle); + textView->SetFontAndColor(&font); + + superItem = styleMenu->FindItem (fontFamily); + + if (superItem != NULL ) + superItem->SetMarked (true); // Check the one that was selected + + menuItem = styleMenu->FindItem("Black"); + menuItem->SetMarked(true); +} + +void +DeskNoteView::RestoreNote(BMessage* msg) +{ + const rgb_color* bckgrnd; + ssize_t size; + const char* text; + + // Find the text of the note. + if (msg->FindString("NoteText", &text) == B_OK) + textView->SetText(text); + + // Find the background colour. + if (msg->FindData("background_colour", B_RGB_COLOR_TYPE, + (const void**) &bckgrnd, &size) == B_OK) + background = *bckgrnd; + + // Update the colour of the text view and widget. + _SetColors(); +} + + +BArchivable* +DeskNoteView::Instantiate(BMessage* data) +{ + if (!validate_instantiation(data, "DeskNoteView")) + return NULL; + return new DeskNoteView(data); +} + + +int32 +DeskNoteView::ResizeViewMethod(void* data) +{ + uint32 buttons; + BPoint cursor; + float x, y; + DeskNoteView* theView = (DeskNoteView*) data; + + do { + theView->Window()->Lock(); + theView->GetMouse(&cursor, &buttons); + if (cursor.x > 30) + x = cursor.x; + else + x = 30; + if (cursor.y > 20) + y = cursor.y; + else + y = 20; + if (theView->WeAreAReplicant) + theView->ResizeTo(x, y); + else + theView->Window()->ResizeTo(x, y); + theView->Window()->Unlock(); + snooze(20 * 1000); + } while (buttons); + + return 0; +} diff --git a/DeskNoteView.h b/DeskNoteView.h new file mode 100644 index 0000000..d21ffa1 --- /dev/null +++ b/DeskNoteView.h @@ -0,0 +1,107 @@ +/* + * Original copyright 2000 by Colin Stewart (http://www.owlfish.com/). + * All rights reserved. + * Distributed under the terms of the BSD (3-clause) License. + * + * Authors: + * Janus2, 2015 + * Humdinger, 2021 + * + */ + + +#ifndef _DESKNOTEVIEW_H +#define _DESKNOTEVIEW_H + +#include +#include +#include + +#include "ColorMenuItem.h" +#include "DeskNoteApp.h" +#include "DeskNoteTextView.h" + + + +#define DN_LAUNCH 'dnLN' +#define DN_COLOR 'dnCL' +#define FONT_FAMILY 'fntf' +#define FONT_STYLE 'ftst' + +const rgb_color palette[] = { + { 255, 221, 191, 255 }, // lightest red + { 255, 187, 128, 255 }, // light red + { 216, 158, 108, 255 }, // red + { 179, 83, 0, 255 }, // dark red + + { 255, 244, 191, 255 }, // lightest yellow + { 255, 233, 128, 255 }, // light yellow + { 215, 178, 0, 255 }, // yellow + { 179, 148, 0, 255 }, // dark yellow + + { 216, 255, 180, 255 }, // lightest green + { 177, 255, 169, 255 }, // light green + { 72, 187, 61, 255 }, // green + { 47, 122, 40, 255 }, // dark green + + { 213, 234, 255, 255 }, // lightest blue + { 170, 213, 255, 255 }, // light blue + { 67, 131, 196, 255 }, // blue + { 36, 71, 106, 255 }, // dark blue + + { 244, 244, 244, 255 }, // off white + { 188, 188, 188, 255 }, // light grey + { 96, 96, 96, 255 }, // dark grey + { 11, 11, 11, 255 }, // off black +}; + +class DeskNoteTextView; + +class DeskNoteView : public BView { +public: + DeskNoteView(BRect rect); + DeskNoteView(BMessage* data); + ~DeskNoteView(); + + virtual status_t Archive(BMessage* data, bool deep = true) const; + virtual void Draw(BRect rect); + virtual void MessageReceived(BMessage* msg); + virtual void FrameResized(float width, float height); + virtual void MouseDown(BPoint point); + virtual void SaveNote(BMessage* msg); + virtual void RestoreNote(BMessage* msg); + + static BArchivable* Instantiate(BMessage* data); + static int32 ResizeViewMethod(void* data); + + static const char defaultText[]; + static const char aboutText[]; + + void SetFontStyle(const char* fontFamily, + const char *fontStyle); + + + + +private: + void _BuildColorMenu(BMenu* menu); + void _BuildStyleMenu(BMenu* menu); + void _SetColors(); + void _ShowContextMenu(BPoint where); + bool WeAreAReplicant; + DeskNoteTextView* textView; + BRect ourSize; + BMenu* colorMenu; + BMenu* styleMenu; + BMenu* fFontMenu; + BMenuItem* fCurrentFont; + BMessage* orginalSettings; + BPopUpMenu* popupMenu; + rgb_color background; + rgb_color foreground; + rgb_color widgetcolour; + BDragger* dragger; + +}; + +#endif // _DESKNOTEVIEW_H From e426ffc415e9d98ea03a9b48313dc2b3fa427c3c Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty Date: Mon, 13 Mar 2023 01:34:41 +0000 Subject: [PATCH 13/16] Font menu added --- DeskNoteView.cpp | 206 ++++++++++++++++++++++++----------------------- 1 file changed, 105 insertions(+), 101 deletions(-) diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp index be05fb3..d2c8caf 100644 --- a/DeskNoteView.cpp +++ b/DeskNoteView.cpp @@ -25,8 +25,6 @@ #define B_TRANSLATION_CONTEXT "View" - - const float kWidgetSize = 7; @@ -134,24 +132,20 @@ DeskNoteView::Draw(BRect rct) void DeskNoteView::MessageReceived(BMessage* msg) { - BAlert *alert; - BRect windSize, - ourSize; - BMessenger *messenger; - BMessage *message; - //BFont currentFont; - BMenuItem *item; - BMenu *menu; - //font_family currentFamily; - //font_style currentStyle; - uint16 currentFace; - const rgb_color *bckgrnd; - ssize_t size; - const char *fontFamily, - *fontStyle; - void *ptr; - - switch (msg->what) { + BAlert *alert; + BRect windSize, ourSize; + BMessenger *messenger; + BMessage *message; + BMenuItem *item; + BMenu *menu; + uint16 currentFace; + const rgb_color *bckgrnd; + ssize_t size; + const char *fontFamily, *fontStyle; + void *ptr; + + switch(msg->what) + { case B_ABOUT_REQUESTED: { // Set the mouse cursor! @@ -162,13 +156,15 @@ DeskNoteView::MessageReceived(BMessage* msg) aboutWin->AddDescription(B_TRANSLATE( "Pin little notes as replicants on your Desktop.\n" "Dropped colors change the background of a note.")); - const char* extraCopyrights[] = { + const char* extraCopyrights[] = + { "2012 siarzhuk ", "2015 Janus", "2021 Humdinger", NULL }; - const char* authors[] = { + const char* authors[] = + { B_TRANSLATE("Colin Stewart (original author)"), "Humdinger", "Janus", @@ -188,48 +184,50 @@ DeskNoteView::MessageReceived(BMessage* msg) case DN_COLOR: { ssize_t colorLength; - if (msg->FindData("color", B_RGB_COLOR_TYPE, + if(msg->FindData("color", B_RGB_COLOR_TYPE, (const void**)&bckgrnd, &colorLength) == B_OK - && colorLength == sizeof(rgb_color)) { + && colorLength == sizeof(rgb_color)) + { background = *bckgrnd; _SetColors(); } break; } // Font type - case FONT_FAMILY: { - + case FONT_FAMILY: + { fontFamily = NULL; fontStyle = NULL; // Setting the font family - msg->FindPointer ("source", &ptr); + msg->FindPointer("source", &ptr); fCurrentFont = static_cast (ptr); fontFamily = fCurrentFont->Label(); - SetFontStyle (fontFamily, fontStyle); + SetFontStyle(fontFamily, fontStyle); } break; // Font style - case FONT_STYLE: { + case FONT_STYLE: + { fontFamily = NULL; fontStyle = NULL; // Setting the font style - msg->FindPointer ("source", &ptr); + msg->FindPointer("source", &ptr); item = static_cast (ptr); fontStyle = item->Label(); menu = item->Menu(); - if (menu != NULL) { + if(menu != NULL) + { fCurrentFont = menu->Superitem(); - if (fCurrentFont != NULL) + if(fCurrentFont != NULL) fontFamily = fCurrentFont->Label(); } - SetFontStyle (fontFamily, fontStyle); + SetFontStyle(fontFamily, fontStyle); } - break; default: @@ -261,20 +259,21 @@ DeskNoteView::MouseDown(BPoint point) BPoint mousePoint; uint32 mouseButtons; - if (!Window()->IsActive()) + if(!Window()->IsActive()) Window()->Activate(true); textView->MakeFocus(true); GetMouse(&mousePoint, &mouseButtons, false); - if (point.x >= (ourSize.right - kWidgetSize) && point.y - >= (ourSize.bottom - kWidgetSize)) { + if(point.x >=(ourSize.right - kWidgetSize) && point.y + >=(ourSize.bottom - kWidgetSize)) { resizeThread = spawn_thread(DeskNoteView::ResizeViewMethod, "Resize Thread", B_DISPLAY_PRIORITY, this); - if (resizeThread > 0) + if(resizeThread > 0) resume_thread(resizeThread); - } else if (mouseButtons == B_SECONDARY_MOUSE_BUTTON) + } + else if(mouseButtons == B_SECONDARY_MOUSE_BUTTON) _ShowContextMenu(mousePoint); } @@ -282,53 +281,52 @@ void DeskNoteView::_BuildStyleMenu(BMenu* menu) { //variables - font_family plainFamily, - family; - font_style plainStyle, - style; - BMenuItem* menuItem = NULL; - int32 numFamilies, - numStyles; - BMenu* fontMenu; - uint32 flags; + font_family plainFamily, family; + font_style plainStyle, style; + BMenuItem* menuItem = NULL; + int32 numFamilies, numStyles; + BMenu* fontMenu; + uint32 flags; - if (menu == NULL) + if(menu == NULL) return; //Font Menu fCurrentFont = 0; - be_plain_font->GetFamilyAndStyle (&plainFamily,&plainStyle); + be_plain_font->GetFamilyAndStyle(&plainFamily,&plainStyle); // Taking the number of font families numFamilies = count_font_families(); - for (int32 i = 0; i < numFamilies; i++) { + for(int32 i = 0; i < numFamilies; i++) + { // Getting the font families - if (get_font_family(i, &family) == B_OK) { - - // Creating a menu of that font family - fontMenu = new BMenu (family); - fontMenu->SetRadioMode (true); // I can set only one item as "in use" - menuItem = new BMenuItem (fontMenu, new BMessage (FONT_FAMILY)); + if(get_font_family(i, &family) == B_OK) + { + fontMenu = new BMenu(family); + fontMenu->SetRadioMode(true); // I can set only one item as "in use" + menuItem = new BMenuItem(fontMenu, new BMessage(FONT_FAMILY)); menuItem->SetTarget(this); - menu->AddItem (menuItem); + menu->AddItem(menuItem); - if (!strcmp (plainFamily,family)) { + if(!strcmp(plainFamily,family)) + { //menuItem->SetMarked (true); fCurrentFont = menuItem; } //Number of styles of that font family - numStyles = count_font_styles (family); + numStyles = count_font_styles(family); - // Creating a submenu about each of that styles - for (int32 j = 0; j < numStyles; j++) { + for(int32 j = 0; j < numStyles; j++) + { - if (get_font_style(family,j,&style,&flags)==B_OK) { - menuItem = new BMenuItem (style, new BMessage(FONT_STYLE)); + if(get_font_style(family,j,&style,&flags)==B_OK) + { + menuItem = new BMenuItem(style, new BMessage(FONT_STYLE)); menuItem->SetTarget(this); - fontMenu->AddItem (menuItem); + fontMenu->AddItem(menuItem); //if (!strcmp (plainStyle, style)) //menuItem->SetMarked(true); @@ -342,7 +340,7 @@ DeskNoteView::_BuildStyleMenu(BMenu* menu) void DeskNoteView::_BuildColorMenu(BMenu* menu) { - if (menu == NULL) + if(menu == NULL) return; BFont font; @@ -358,7 +356,8 @@ DeskNoteView::_BuildColorMenu(BMenu* menu) BRect matrixArea(0, 0, 0, 0); // we place the color palette, reserving room at the top - for (uint i = 0; i < sizeof(palette) / sizeof(rgb_color); i++) { + for(uint i = 0; i < sizeof(palette) / sizeof(rgb_color); i++) + { BPoint topLeft((i % nbColumns) * (itemHeight + margin), (i / nbColumns) * (itemHeight + margin)); BRect buttonArea(topLeft.x, topLeft.y, topLeft.x + itemHeight, @@ -368,7 +367,7 @@ DeskNoteView::_BuildColorMenu(BMenu* menu) ColorMenuItem* colItem = new ColorMenuItem("", palette[i], new BMessage(msgTemplate)); - if (colItem != NULL && palette[i] == background) + if(colItem != NULL && palette[i] == background) colItem->SetMarked(true); colItem->SetTarget(this); @@ -389,12 +388,15 @@ DeskNoteView::_SetColors() { float thresh = background.red + (background.green * 1.25f) + (background.blue * 0.45f); - if (thresh >= 360) { + if(thresh >= 360) + { foreground.red = 11; foreground.green = 11; foreground.blue = 11; widgetcolour = tint_color(background, B_DARKEN_1_TINT); - } else { + } + else + { foreground.red = 244; foreground.green = 244; foreground.blue = 244; @@ -432,7 +434,7 @@ DeskNoteView::_ShowContextMenu(BPoint where) colorMenu = new BMenu(B_TRANSLATE("Color"), 0, 0); _BuildColorMenu(colorMenu); - styleMenu = new BMenu(B_TRANSLATE("Font Style")); + styleMenu = new BMenu(B_TRANSLATE("Font")); styleMenu->SetRadioMode(true); _BuildStyleMenu(styleMenu); @@ -461,7 +463,8 @@ DeskNoteView::_ShowContextMenu(BPoint where) new BMessage(B_ABOUT_REQUESTED)); // If we are replicant add the launch desknotes command to the menu. - if (WeAreAReplicant) { + if(WeAreAReplicant) + { menu->AddItem(new BMenuItem( B_TRANSLATE("Launch DeskNotes" B_UTF8_ELLIPSIS), new BMessage(DN_LAUNCH))); @@ -485,39 +488,38 @@ DeskNoteView::SaveNote(BMessage* msg) } // Function for the changes in the "type of font" -void DeskNoteView :: SetFontStyle (const char* fontFamily, const char* fontStyle) { +void DeskNoteView :: SetFontStyle(const char* fontFamily, const char* fontStyle) +{ // Variables - BMenuItem *superItem; - BMenuItem *menuItem; - BFont font; + BMenuItem *superItem; + BMenuItem *menuItem; + BFont font; font_family oldFamily; - font_style oldStyle; - uint32 sameProperties; - rgb_color sameColor; - BMenuItem *oldItem; + font_style oldStyle; + uint32 sameProperties; + rgb_color sameColor; + BMenuItem *oldItem; - textView->GetFontAndColor (&font, &sameProperties, &sameColor); + textView->GetFontAndColor(&font, &sameProperties, &sameColor); // Copying the current font family and font style - font.GetFamilyAndStyle (&oldFamily, &oldStyle); + font.GetFamilyAndStyle(&oldFamily, &oldStyle); - if (strcmp (oldFamily, fontFamily)) { - oldItem = styleMenu->FindItem (oldFamily); + if(strcmp(oldFamily, fontFamily)) + { + oldItem = styleMenu->FindItem(oldFamily); - if (oldItem != NULL) + if(oldItem != NULL) // Removing the check - oldItem->SetMarked (false); + oldItem->SetMarked(false); } - font.SetFamilyAndStyle (fontFamily, fontStyle); + font.SetFamilyAndStyle(fontFamily, fontStyle); textView->SetFontAndColor(&font); - superItem = styleMenu->FindItem (fontFamily); + superItem = styleMenu->FindItem(fontFamily); - if (superItem != NULL ) - superItem->SetMarked (true); // Check the one that was selected - - menuItem = styleMenu->FindItem("Black"); - menuItem->SetMarked(true); + if(superItem != NULL) + superItem->SetMarked(true); // Check the one that was selected } void @@ -528,11 +530,11 @@ DeskNoteView::RestoreNote(BMessage* msg) const char* text; // Find the text of the note. - if (msg->FindString("NoteText", &text) == B_OK) + if(msg->FindString("NoteText", &text) == B_OK) textView->SetText(text); // Find the background colour. - if (msg->FindData("background_colour", B_RGB_COLOR_TYPE, + if(msg->FindData("background_colour", B_RGB_COLOR_TYPE, (const void**) &bckgrnd, &size) == B_OK) background = *bckgrnd; @@ -544,7 +546,7 @@ DeskNoteView::RestoreNote(BMessage* msg) BArchivable* DeskNoteView::Instantiate(BMessage* data) { - if (!validate_instantiation(data, "DeskNoteView")) + if(!validate_instantiation(data, "DeskNoteView")) return NULL; return new DeskNoteView(data); } @@ -558,24 +560,26 @@ DeskNoteView::ResizeViewMethod(void* data) float x, y; DeskNoteView* theView = (DeskNoteView*) data; - do { + do + { theView->Window()->Lock(); theView->GetMouse(&cursor, &buttons); - if (cursor.x > 30) + if(cursor.x > 30) x = cursor.x; else x = 30; - if (cursor.y > 20) + if(cursor.y > 20) y = cursor.y; else y = 20; - if (theView->WeAreAReplicant) + if(theView->WeAreAReplicant) theView->ResizeTo(x, y); else theView->Window()->ResizeTo(x, y); theView->Window()->Unlock(); snooze(20 * 1000); - } while (buttons); + } + while(buttons); return 0; } From aede7753bece741d66991973084c0fb56e65e74f Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty Date: Wed, 15 Mar 2023 04:52:17 +0000 Subject: [PATCH 14/16] Font menu added and codestyle fixed --- DeskNoteView.cpp | 109 +++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 61 deletions(-) diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp index d2c8caf..5dcce68 100644 --- a/DeskNoteView.cpp +++ b/DeskNoteView.cpp @@ -10,8 +10,6 @@ */ -#include "DeskNoteView.h" - #include #include #include @@ -21,6 +19,9 @@ #include +#include "DeskNoteView.h" + + #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "View" @@ -144,8 +145,7 @@ DeskNoteView::MessageReceived(BMessage* msg) const char *fontFamily, *fontStyle; void *ptr; - switch(msg->what) - { + switch (msg->what) { case B_ABOUT_REQUESTED: { // Set the mouse cursor! @@ -156,15 +156,13 @@ DeskNoteView::MessageReceived(BMessage* msg) aboutWin->AddDescription(B_TRANSLATE( "Pin little notes as replicants on your Desktop.\n" "Dropped colors change the background of a note.")); - const char* extraCopyrights[] = - { + const char* extraCopyrights[] = "2012 siarzhuk ", "2015 Janus", "2021 Humdinger", NULL }; - const char* authors[] = - { + const char* authors[] = { B_TRANSLATE("Colin Stewart (original author)"), "Humdinger", "Janus", @@ -176,23 +174,25 @@ DeskNoteView::MessageReceived(BMessage* msg) aboutWin->Show(); break; } + case DN_LAUNCH: { be_roster->Launch(app_signature); break; } + case DN_COLOR: { ssize_t colorLength; - if(msg->FindData("color", B_RGB_COLOR_TYPE, + if (msg->FindData("color", B_RGB_COLOR_TYPE, (const void**)&bckgrnd, &colorLength) == B_OK - && colorLength == sizeof(rgb_color)) - { + && colorLength == sizeof(rgb_color)) { background = *bckgrnd; _SetColors(); } break; } + // Font type case FONT_FAMILY: { @@ -210,7 +210,6 @@ DeskNoteView::MessageReceived(BMessage* msg) // Font style case FONT_STYLE: { - fontFamily = NULL; fontStyle = NULL; @@ -220,10 +219,9 @@ DeskNoteView::MessageReceived(BMessage* msg) fontStyle = item->Label(); menu = item->Menu(); - if(menu != NULL) - { + if (menu != NULL) { fCurrentFont = menu->Superitem(); - if(fCurrentFont != NULL) + if (fCurrentFont != NULL) fontFamily = fCurrentFont->Label(); } SetFontStyle(fontFamily, fontStyle); @@ -236,7 +234,6 @@ DeskNoteView::MessageReceived(BMessage* msg) } - void DeskNoteView::FrameResized(float width, float height) { @@ -259,39 +256,39 @@ DeskNoteView::MouseDown(BPoint point) BPoint mousePoint; uint32 mouseButtons; - if(!Window()->IsActive()) + if (!Window()->IsActive()) Window()->Activate(true); textView->MakeFocus(true); GetMouse(&mousePoint, &mouseButtons, false); - if(point.x >=(ourSize.right - kWidgetSize) && point.y - >=(ourSize.bottom - kWidgetSize)) { + if (point.x >= (ourSize.right - kWidgetSize) && point.y + >= (ourSize.bottom - kWidgetSize)) { resizeThread = spawn_thread(DeskNoteView::ResizeViewMethod, "Resize Thread", B_DISPLAY_PRIORITY, this); - if(resizeThread > 0) + if (resizeThread > 0) resume_thread(resizeThread); } - else if(mouseButtons == B_SECONDARY_MOUSE_BUTTON) + else if (mouseButtons == B_SECONDARY_MOUSE_BUTTON) _ShowContextMenu(mousePoint); } + void DeskNoteView::_BuildStyleMenu(BMenu* menu) { //variables - font_family plainFamily, family; + font_family plainFamily, family; font_style plainStyle, style; BMenuItem* menuItem = NULL; int32 numFamilies, numStyles; BMenu* fontMenu; uint32 flags; - if(menu == NULL) + if (menu == NULL) return; - //Font Menu fCurrentFont = 0; @@ -299,31 +296,24 @@ DeskNoteView::_BuildStyleMenu(BMenu* menu) // Taking the number of font families numFamilies = count_font_families(); - for(int32 i = 0; i < numFamilies; i++) - { - + for (int32 i = 0; i < numFamilies; i++) { // Getting the font families - if(get_font_family(i, &family) == B_OK) - { + if (get_font_family(i, &family) == B_OK) { fontMenu = new BMenu(family); fontMenu->SetRadioMode(true); // I can set only one item as "in use" menuItem = new BMenuItem(fontMenu, new BMessage(FONT_FAMILY)); menuItem->SetTarget(this); menu->AddItem(menuItem); - if(!strcmp(plainFamily,family)) - { + if (!strcmp(plainFamily,family)) { //menuItem->SetMarked (true); fCurrentFont = menuItem; } - //Number of styles of that font family + //Number of styles of that font family numStyles = count_font_styles(family); - for(int32 j = 0; j < numStyles; j++) - { - - if(get_font_style(family,j,&style,&flags)==B_OK) - { + for (int32 j = 0; j < numStyles; j++) { + if (get_font_style(family,j,&style,&flags)==B_OK) { menuItem = new BMenuItem(style, new BMessage(FONT_STYLE)); menuItem->SetTarget(this); fontMenu->AddItem(menuItem); @@ -337,10 +327,11 @@ DeskNoteView::_BuildStyleMenu(BMenu* menu) } } + void DeskNoteView::_BuildColorMenu(BMenu* menu) { - if(menu == NULL) + if (menu == NULL) return; BFont font; @@ -356,8 +347,7 @@ DeskNoteView::_BuildColorMenu(BMenu* menu) BRect matrixArea(0, 0, 0, 0); // we place the color palette, reserving room at the top - for(uint i = 0; i < sizeof(palette) / sizeof(rgb_color); i++) - { + for (uint i = 0; i < sizeof(palette) / sizeof(rgb_color); i++) { BPoint topLeft((i % nbColumns) * (itemHeight + margin), (i / nbColumns) * (itemHeight + margin)); BRect buttonArea(topLeft.x, topLeft.y, topLeft.x + itemHeight, @@ -367,7 +357,7 @@ DeskNoteView::_BuildColorMenu(BMenu* menu) ColorMenuItem* colItem = new ColorMenuItem("", palette[i], new BMessage(msgTemplate)); - if(colItem != NULL && palette[i] == background) + if (colItem != NULL && palette[i] == background) colItem->SetMarked(true); colItem->SetTarget(this); @@ -388,15 +378,13 @@ DeskNoteView::_SetColors() { float thresh = background.red + (background.green * 1.25f) + (background.blue * 0.45f); - if(thresh >= 360) - { + if (thresh >= 360) { foreground.red = 11; foreground.green = 11; foreground.blue = 11; widgetcolour = tint_color(background, B_DARKEN_1_TINT); } - else - { + else { foreground.red = 244; foreground.green = 244; foreground.blue = 244; @@ -463,8 +451,7 @@ DeskNoteView::_ShowContextMenu(BPoint where) new BMessage(B_ABOUT_REQUESTED)); // If we are replicant add the launch desknotes command to the menu. - if(WeAreAReplicant) - { + if (WeAreAReplicant) { menu->AddItem(new BMenuItem( B_TRANSLATE("Launch DeskNotes" B_UTF8_ELLIPSIS), new BMessage(DN_LAUNCH))); @@ -487,8 +474,9 @@ DeskNoteView::SaveNote(BMessage* msg) "background_colour", B_RGB_COLOR_TYPE, &background, sizeof(rgb_color)); } + // Function for the changes in the "type of font" -void DeskNoteView :: SetFontStyle(const char* fontFamily, const char* fontStyle) +void DeskNoteView::SetFontStyle(const char* fontFamily, const char* fontStyle) { // Variables BMenuItem *superItem; @@ -504,11 +492,10 @@ void DeskNoteView :: SetFontStyle(const char* fontFamily, const char* fontStyle) // Copying the current font family and font style font.GetFamilyAndStyle(&oldFamily, &oldStyle); - if(strcmp(oldFamily, fontFamily)) - { + if (strcmp(oldFamily, fontFamily)) { oldItem = styleMenu->FindItem(oldFamily); - if(oldItem != NULL) + if (oldItem != NULL) // Removing the check oldItem->SetMarked(false); } @@ -518,10 +505,11 @@ void DeskNoteView :: SetFontStyle(const char* fontFamily, const char* fontStyle) superItem = styleMenu->FindItem(fontFamily); - if(superItem != NULL) + if (superItem != NULL) superItem->SetMarked(true); // Check the one that was selected } + void DeskNoteView::RestoreNote(BMessage* msg) { @@ -530,11 +518,11 @@ DeskNoteView::RestoreNote(BMessage* msg) const char* text; // Find the text of the note. - if(msg->FindString("NoteText", &text) == B_OK) + if (msg->FindString("NoteText", &text) == B_OK) textView->SetText(text); // Find the background colour. - if(msg->FindData("background_colour", B_RGB_COLOR_TYPE, + if (msg->FindData("background_colour", B_RGB_COLOR_TYPE, (const void**) &bckgrnd, &size) == B_OK) background = *bckgrnd; @@ -546,7 +534,7 @@ DeskNoteView::RestoreNote(BMessage* msg) BArchivable* DeskNoteView::Instantiate(BMessage* data) { - if(!validate_instantiation(data, "DeskNoteView")) + if (!validate_instantiation(data, "DeskNoteView")) return NULL; return new DeskNoteView(data); } @@ -560,26 +548,25 @@ DeskNoteView::ResizeViewMethod(void* data) float x, y; DeskNoteView* theView = (DeskNoteView*) data; - do - { + do { theView->Window()->Lock(); theView->GetMouse(&cursor, &buttons); - if(cursor.x > 30) + if (cursor.x > 30) x = cursor.x; else x = 30; - if(cursor.y > 20) + if (cursor.y > 20) y = cursor.y; else y = 20; - if(theView->WeAreAReplicant) + if (theView->WeAreAReplicant) theView->ResizeTo(x, y); else theView->Window()->ResizeTo(x, y); theView->Window()->Unlock(); snooze(20 * 1000); } - while(buttons); + while (buttons); return 0; } From 3cd61dbec30e291624cca9468883defe3287a56a Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty Date: Wed, 15 Mar 2023 04:58:37 +0000 Subject: [PATCH 15/16] Added .haiku-format --- .haiku-format | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .haiku-format diff --git a/.haiku-format b/.haiku-format new file mode 100644 index 0000000..c38e456 --- /dev/null +++ b/.haiku-format @@ -0,0 +1,25 @@ +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignEscapedNewlines: DontAlign +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AlwaysBreakAfterReturnType: TopLevelDefinitions +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterExternBlock: true + AfterFunction: true + BeforeCatch: true +ColumnLimit: 100 +IndentCaseLabels: true +IndentWidth: 4 +MaxEmptyLinesToKeep: 2 +PointerAlignment: Left +SpaceAfterCStyleCast: true +SpaceAfterTemplateKeyword: false +TabWidth: 4 +UseTab: Always From 935631ec7da2df59464fbf61edb3b10befa3c734 Mon Sep 17 00:00:00 2001 From: Barmendu Chakraborty Date: Wed, 15 Mar 2023 21:52:18 +0000 Subject: [PATCH 16/16] Updated DeskNoteView.cpp and deleted .haiku-format --- .haiku-format | 25 ------------------------- DeskNoteView.cpp | 27 +++++++++++---------------- 2 files changed, 11 insertions(+), 41 deletions(-) delete mode 100644 .haiku-format diff --git a/.haiku-format b/.haiku-format deleted file mode 100644 index c38e456..0000000 --- a/.haiku-format +++ /dev/null @@ -1,25 +0,0 @@ -AccessModifierOffset: -4 -AlignAfterOpenBracket: DontAlign -AlignEscapedNewlines: DontAlign -AlignOperands: false -AlignTrailingComments: false -AllowAllParametersOfDeclarationOnNextLine: false -AllowShortFunctionsOnASingleLine: InlineOnly -AlwaysBreakAfterReturnType: TopLevelDefinitions -BreakBeforeBinaryOperators: All -BreakBeforeBraces: Custom -BraceWrapping: - AfterCaseLabel: true - AfterClass: true - AfterExternBlock: true - AfterFunction: true - BeforeCatch: true -ColumnLimit: 100 -IndentCaseLabels: true -IndentWidth: 4 -MaxEmptyLinesToKeep: 2 -PointerAlignment: Left -SpaceAfterCStyleCast: true -SpaceAfterTemplateKeyword: false -TabWidth: 4 -UseTab: Always diff --git a/DeskNoteView.cpp b/DeskNoteView.cpp index 5dcce68..e7216b9 100644 --- a/DeskNoteView.cpp +++ b/DeskNoteView.cpp @@ -142,7 +142,7 @@ DeskNoteView::MessageReceived(BMessage* msg) uint16 currentFace; const rgb_color *bckgrnd; ssize_t size; - const char *fontFamily, *fontStyle; + const char *fontFamily, *fontStyle; void *ptr; switch (msg->what) { @@ -156,7 +156,7 @@ DeskNoteView::MessageReceived(BMessage* msg) aboutWin->AddDescription(B_TRANSLATE( "Pin little notes as replicants on your Desktop.\n" "Dropped colors change the background of a note.")); - const char* extraCopyrights[] = + const char* extraCopyrights[] = { "2012 siarzhuk ", "2015 Janus", "2021 Humdinger", @@ -174,13 +174,11 @@ DeskNoteView::MessageReceived(BMessage* msg) aboutWin->Show(); break; } - case DN_LAUNCH: { be_roster->Launch(app_signature); break; } - case DN_COLOR: { ssize_t colorLength; @@ -192,9 +190,8 @@ DeskNoteView::MessageReceived(BMessage* msg) } break; } - // Font type - case FONT_FAMILY: + case FONT_FAMILY: { fontFamily = NULL; fontStyle = NULL; @@ -203,10 +200,9 @@ DeskNoteView::MessageReceived(BMessage* msg) msg->FindPointer("source", &ptr); fCurrentFont = static_cast (ptr); fontFamily = fCurrentFont->Label(); - SetFontStyle(fontFamily, fontStyle); + SetFontStyle(fontFamily, fontStyle); } break; - // Font style case FONT_STYLE: { @@ -227,7 +223,6 @@ DeskNoteView::MessageReceived(BMessage* msg) SetFontStyle(fontFamily, fontStyle); } break; - default: BView::MessageReceived(msg); } @@ -269,7 +264,7 @@ DeskNoteView::MouseDown(BPoint point) if (resizeThread > 0) resume_thread(resizeThread); - } + } else if (mouseButtons == B_SECONDARY_MOUSE_BUTTON) _ShowContextMenu(mousePoint); } @@ -282,13 +277,13 @@ DeskNoteView::_BuildStyleMenu(BMenu* menu) font_family plainFamily, family; font_style plainStyle, style; BMenuItem* menuItem = NULL; - int32 numFamilies, numStyles; + int32 numFamilies, numStyles; BMenu* fontMenu; uint32 flags; - + if (menu == NULL) return; - + //Font Menu fCurrentFont = 0; @@ -421,7 +416,7 @@ DeskNoteView::_ShowContextMenu(BPoint where) colorMenu = new BMenu(B_TRANSLATE("Color"), 0, 0); _BuildColorMenu(colorMenu); - + styleMenu = new BMenu(B_TRANSLATE("Font")); styleMenu->SetRadioMode(true); _BuildStyleMenu(styleMenu); @@ -494,7 +489,7 @@ void DeskNoteView::SetFontStyle(const char* fontFamily, const char* fontStyle) if (strcmp(oldFamily, fontFamily)) { oldItem = styleMenu->FindItem(oldFamily); - + if (oldItem != NULL) // Removing the check oldItem->SetMarked(false); @@ -504,7 +499,7 @@ void DeskNoteView::SetFontStyle(const char* fontFamily, const char* fontStyle) textView->SetFontAndColor(&font); superItem = styleMenu->FindItem(fontFamily); - + if (superItem != NULL) superItem->SetMarked(true); // Check the one that was selected }