BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / sudoku / SudokuView.h
blobae30889fea67c39efd1ad8fcf51eb8140dcec3a6
1 /*
2 * Copyright 2007-2015, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef SUDOKU_VIEW_H
6 #define SUDOKU_VIEW_H
9 #include <View.h>
10 #include <ObjectList.h>
13 class BDataIO;
14 class SudokuField;
15 class SudokuSolver;
16 struct entry_ref;
19 enum {
20 kMarkValidHints = 0x01,
21 kMarkInvalid = 0x02,
25 enum {
26 kExportAsText,
27 kExportAsHTML,
28 kExportAsBitmap,
29 kExportAsPicture
33 class SudokuView : public BView {
34 public:
35 SudokuView(BRect frame, const char* name,
36 const BMessage& settings,
37 uint32 resizingMode);
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();
58 void ClearChanged();
59 void ClearAll();
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(); }
71 void Undo();
72 void Redo();
74 protected:
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);
87 private:
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,
110 uint32& y);
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,
116 uint32 value);
117 void _RemoveHintValue(uint32 x, uint32 y,
118 uint32 valueMask);
119 void _SetAllHints();
120 void _Solve();
121 void _SolveSingle();
122 bool _GetSolutions(SudokuSolver& solver);
123 void _UndoRedo(BObjectList<BMessage>& undos,
124 BObjectList<BMessage>& redos);
125 void _PushUndo();
126 void _SetValueHintValue(uint32 value);
127 void _RemoveHint();
128 void _FitFont(BFont& font, float width,
129 float height);
130 void _DrawKeyboardFocus();
131 void _DrawHints(uint32 x, uint32 y);
133 private:
134 rgb_color fBackgroundColor;
135 SudokuField* fField;
136 BObjectList<BMessage> fUndos;
137 BObjectList<BMessage> fRedos;
138 uint32 fBlockSize;
139 float fWidth;
140 float fHeight;
141 float fBaseline;
142 BFont fFieldFont;
143 BFont fHintFont;
144 float fHintHeight;
145 float fHintWidth;
146 float fHintBaseline;
147 uint32 fShowHintX;
148 uint32 fShowHintY;
149 uint32 fLastHintValue;
150 bool fLastHintValueSet;
151 uint32 fValueHintValue;
152 uint32 fLastField;
153 uint32 fKeyboardX;
154 uint32 fKeyboardY;
155 uint32 fHintFlags;
156 bool fShowKeyboardFocus;
157 bool fShowCursor;
158 bool fEditable;
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