2 * Copyright 2007-2015, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
10 #include <ObjectList.h>
20 kMarkValidHints
= 0x01,
33 class SudokuView
: public BView
{
35 SudokuView(BRect frame
, const char* name
,
36 const BMessage
& settings
,
38 SudokuView(const char* name
,
39 const BMessage
& settings
);
40 SudokuView(BMessage
* archive
);
41 virtual ~SudokuView();
43 virtual status_t
Archive(BMessage
* into
, bool deep
= true) const;
44 static BArchivable
* Instantiate(BMessage
* archive
);
46 status_t
SaveState(BMessage
& state
) const;
48 status_t
SetTo(entry_ref
& ref
);
49 status_t
SetTo(const char* data
);
50 status_t
SetTo(SudokuField
* field
);
52 status_t
SaveTo(entry_ref
& ref
,
53 uint32 as
= kExportAsText
);
54 status_t
SaveTo(BDataIO
&to
, uint32 as
= kExportAsText
);
56 status_t
CopyToClipboard();
61 void SetHintFlags(uint32 flags
);
62 uint32
HintFlags() const { return fHintFlags
; }
64 SudokuField
* Field() { return fField
; }
66 void SetEditable(bool editable
);
67 bool Editable() const { return fEditable
; }
69 bool CanUndo() { return !fUndos
.IsEmpty(); }
70 bool CanRedo() { return !fRedos
.IsEmpty(); }
75 virtual void AttachedToWindow();
77 virtual void FrameResized(float width
, float height
);
78 virtual void MouseDown(BPoint where
);
79 virtual void MouseMoved(BPoint where
, uint32 transit
,
80 const BMessage
* dragMessage
);
81 virtual void KeyDown(const char *bytes
, int32 numBytes
);
83 virtual void MessageReceived(BMessage
* message
);
85 virtual void Draw(BRect updateRect
);
88 void _InitObject(const BMessage
* archive
);
90 status_t
_FilterString(const char* data
,
91 size_t dataLength
, char* buffer
,
92 uint32
& out
, bool& ignore
);
93 void _SetText(char* text
, uint32 value
);
94 char _BaseCharacter();
95 bool _ValidCharacter(char c
);
96 BPoint
_LeftTop(uint32 x
, uint32 y
);
97 BRect
_Frame(uint32
, uint32 y
);
98 void _InvalidateHintField(uint32 x
, uint32 y
,
99 uint32 hintX
, uint32 hintY
);
100 void _InvalidateField(uint32 x
, uint32 y
);
101 void _InvalidateValue(uint32 value
,
102 bool invalidateHint
= false,
103 uint32 x
= UINT32_MAX
,
104 uint32 y
= UINT32_MAX
);
105 void _InvalidateKeyboardFocus(uint32 x
, uint32 y
);
106 void _InsertKey(char rawKey
, int32 modifiers
);
107 bool _GetHintFieldFor(BPoint where
, uint32 x
,
108 uint32 y
, uint32
& hintX
, uint32
& hintY
);
109 bool _GetFieldFor(BPoint where
, uint32
& x
,
111 void _SetValue(uint32 x
, uint32 y
, uint32 value
);
112 void _ToggleHintValue(uint32 x
, uint32 y
,
113 uint32 hintX
, uint32 hintY
,
114 uint32 value
, uint32 field
);
115 void _RemoveHintValues(uint32 atX
, uint32 atY
,
117 void _RemoveHintValue(uint32 x
, uint32 y
,
122 bool _GetSolutions(SudokuSolver
& solver
);
123 void _UndoRedo(BObjectList
<BMessage
>& undos
,
124 BObjectList
<BMessage
>& redos
);
126 void _SetValueHintValue(uint32 value
);
128 void _FitFont(BFont
& font
, float width
,
130 void _DrawKeyboardFocus();
131 void _DrawHints(uint32 x
, uint32 y
);
134 rgb_color fBackgroundColor
;
136 BObjectList
<BMessage
> fUndos
;
137 BObjectList
<BMessage
> fRedos
;
149 uint32 fLastHintValue
;
150 bool fLastHintValueSet
;
151 uint32 fValueHintValue
;
156 bool fShowKeyboardFocus
;
162 static const uint32 kMsgSudokuSolved
= 'susl';
163 static const uint32 kMsgSolveSudoku
= 'slvs';
164 static const uint32 kMsgSolveSingle
= 'slsg';
165 static const uint32 kMsgSetAllHints
= 'salh';
167 // you can observe these:
168 static const int32 kUndoRedoChanged
= 'unre';
171 #endif // SUDOKU_VIEW_H