/* * Copyright 2006-2011, Stephan Aßmus . * Copyright 2023, Haiku, Inc. * All rights reserved. Distributed under the terms of the MIT License. * * Authors: * Zardshard */ #include "MainWindow.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "support_ui.h" #include "AddPathsCommand.h" #include "AddShapesCommand.h" #include "AddStylesCommand.h" #include "AttributeSaver.h" #include "BitmapExporter.h" #include "BitmapSetSaver.h" #include "CanvasView.h" #include "CommandStack.h" #include "CompoundCommand.h" #include "CurrentColor.h" #include "Document.h" #include "FlatIconExporter.h" #include "FlatIconFormat.h" #include "FlatIconImporter.h" #include "IconObjectListView.h" #include "IconEditorApp.h" #include "IconView.h" #include "MessageExporter.h" #include "MessageImporter.h" #include "MessengerSaver.h" #include "NativeSaver.h" #include "PathListView.h" #include "RDefExporter.h" #include "ScrollView.h" #include "SimpleFileSaver.h" #include "ShapeListView.h" #include "SourceExporter.h" #include "StyleListView.h" #include "StyleView.h" #include "SVGExporter.h" #include "SVGImporter.h" #include "SwatchGroup.h" #include "TransformerListView.h" #include "TransformGradientBox.h" #include "TransformShapesBox.h" #include "Util.h" // TODO: just for testing #include "AffineTransformer.h" #include "GradientTransformable.h" #include "Icon.h" #include "MultipleManipulatorState.h" #include "PathManipulator.h" #include "PathSourceShape.h" #include "ReferenceImage.h" #include "Shape.h" #include "ShapeListView.h" #include "StrokeTransformer.h" #include "Style.h" #include "VectorPath.h" #include "StyledTextImporter.h" #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "Icon-O-Matic-Main" using std::nothrow; enum { MSG_UNDO = 'undo', MSG_REDO = 'redo', MSG_UNDO_STACK_CHANGED = 'usch', MSG_PATH_SELECTED = 'vpsl', MSG_STYLE_SELECTED = 'stsl', MSG_SHAPE_SELECTED = 'spsl', MSG_SHAPE_RESET_TRANSFORMATION = 'rtsh', MSG_STYLE_RESET_TRANSFORMATION = 'rtst', MSG_MOUSE_FILTER_MODE = 'mfmd', MSG_RENAME_OBJECT = 'rnam', }; MainWindow::MainWindow(BRect frame, IconEditorApp* app, const BMessage* settings) : BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Icon-O-Matic"), B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), fApp(app), fDocument(new Document(B_TRANSLATE("Untitled"))), fCurrentColor(new CurrentColor()), fIcon(NULL), fMessageAfterSave(NULL) { _Init(); RestoreSettings(settings); } MainWindow::~MainWindow() { SetIcon(NULL); delete fState; // Make sure there are no listeners attached to the document anymore. while (BView* child = ChildAt(0L)) { child->RemoveSelf(); delete child; } fDocument->CommandStack()->RemoveObserver(this); // NOTE: it is important that the GUI has been deleted // at this point, so that all the listener/observer // stuff is properly detached delete fDocument; delete fCurrentColor; delete fMessageAfterSave; } // #pragma mark - void MainWindow::MessageReceived(BMessage* message) { bool discard = false; // Figure out if we need the write lock on the Document. For most // messages we do, but exporting takes place in another thread and // locking is taken care of there. bool requiresWriteLock = true; switch (message->what) { case MSG_SAVE: case MSG_EXPORT: case MSG_SAVE_AS: case MSG_EXPORT_AS: requiresWriteLock = false; break; default: break; } if (requiresWriteLock && !fDocument->WriteLock()) { BWindow::MessageReceived(message); return; } if (message->WasDropped()) { const rgb_color* color; ssize_t length; // create styles from dropped colors for (int32 i = 0; message->FindData("RGBColor", B_RGB_COLOR_TYPE, i, (const void**)&color, &length) == B_OK; i++) { if (length != sizeof(rgb_color)) continue; char name[30]; sprintf(name, B_TRANSLATE_COMMENT("Color (#%02x%02x%02x)", "Style name after dropping a color"), color->red, color->green, color->blue); Style* style = new (nothrow) Style(*color); style->SetName(name); Style* styles[1] = { style }; AddCommand