From 0abb35c2fc32044a42977509836ed80a6113d4af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sun, 3 Feb 2008 23:00:56 +0000 Subject: [PATCH] It's now replicable. The dragger doesn't move correctly on resize though. And it needs a better menu. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23856 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/sudoku/SudokuView.cpp | 95 +++++++++++++++++++++++++++------- src/apps/sudoku/SudokuView.h | 7 ++- 2 files changed, 82 insertions(+), 20 deletions(-) diff --git a/src/apps/sudoku/SudokuView.cpp b/src/apps/sudoku/SudokuView.cpp index 55dfc819bc..ffc3abf9cd 100644 --- a/src/apps/sudoku/SudokuView.cpp +++ b/src/apps/sudoku/SudokuView.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -30,22 +31,84 @@ const uint32 kMsgCheckSolved = 'chks'; const uint32 kStrongLineSize = 2; +extern const char* kSignature; + SudokuView::SudokuView(BRect frame, const char* name, const BMessage& settings, uint32 resizingMode) : BView(frame, name, resizingMode, - B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), - fField(NULL), - fShowHintX(~0UL), - fLastHintValue(~0UL), - fLastField(~0UL), - fKeyboardX(0), - fKeyboardY(0), - fShowKeyboardFocus(false), - fEditable(true) + B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS) { + InitObject(&settings); + + BRect rect(Bounds()); + rect.top = rect.bottom - 7; + rect.left = rect.right - 7; + BDragger *dw = new BDragger(rect, this); + AddChild(dw); +} + + +SudokuView::SudokuView(BMessage* archive) + : BView(archive) +{ + InitObject(archive); +} + + +SudokuView::~SudokuView() +{ + delete fField; +} + + +status_t +SudokuView::Archive(BMessage* into, bool deep = true) const +{ + status_t status; + + status = BView::Archive(into, deep); + if (status < B_OK) + return status; + + status = into->AddString("add_on", kSignature); + if (status < B_OK) + return status; + + status = into->AddRect("bounds", Bounds()); + if (status < B_OK) + return status; + + status = SaveState(*into); + if (status < B_OK) + return status; + return B_OK; +} + + +BArchivable* +SudokuView::Instantiate(BMessage* archive) +{ + if (!validate_instantiation(archive, "SudokuView")) + return NULL; + return new SudokuView(archive); +} + + +void +SudokuView::InitObject(const BMessage* archive) +{ + fField = NULL; + fShowHintX = ~0UL; + fLastHintValue = ~0UL; + fLastField = ~0UL; + fKeyboardX = 0; + fKeyboardY = 0; + fShowKeyboardFocus = false; + fEditable = true; + BMessage field; - if (settings.FindMessage("field", &field) == B_OK) { + if (archive->FindMessage("field", &field) == B_OK) { fField = new SudokuField(&field); if (fField->InitCheck() != B_OK) { delete fField; @@ -58,9 +121,9 @@ SudokuView::SudokuView(BRect frame, const char* name, fBlockSize = fField->BlockSize(); - if (settings.FindInt32("hint flags", (int32*)&fHintFlags) != B_OK) + if (archive->FindInt32("hint flags", (int32*)&fHintFlags) != B_OK) fHintFlags = kMarkInvalid; - if (settings.FindBool("show cursor", &fShowCursor) != B_OK) + if (archive->FindBool("show cursor", &fShowCursor) != B_OK) fShowCursor = false; SetViewColor(B_TRANSPARENT_COLOR); @@ -72,14 +135,8 @@ SudokuView::SudokuView(BRect frame, const char* name, } -SudokuView::~SudokuView() -{ - delete fField; -} - - status_t -SudokuView::SaveState(BMessage& state) +SudokuView::SaveState(BMessage& state) const { BMessage field; status_t status = fField->Archive(&field, true); diff --git a/src/apps/sudoku/SudokuView.h b/src/apps/sudoku/SudokuView.h index ca0dfccc44..03fd8e7317 100644 --- a/src/apps/sudoku/SudokuView.h +++ b/src/apps/sudoku/SudokuView.h @@ -31,9 +31,14 @@ class SudokuView : public BView { public: SudokuView(BRect frame, const char* name, const BMessage& settings, uint32 resizingMode); + SudokuView(BMessage* archive); virtual ~SudokuView(); - status_t SaveState(BMessage& state); + virtual status_t Archive(BMessage* into, bool deep = true) const; + static BArchivable* Instantiate(BMessage* archive); + void InitObject(const BMessage* archive); + + status_t SaveState(BMessage& state) const; status_t SetTo(entry_ref& ref); status_t SetTo(const char* data);