1 class Pusher : public Ctrl { 2 public: 3 virtual void CancelMode(); 4 virtual void LeftDown(Point, dword); 5 virtual void MouseMove(Point, dword); 6 virtual void MouseLeave(); 7 virtual void LeftRepeat(Point, dword); 8 virtual void LeftUp(Point, dword); 9 virtual void GotFocus(); 10 virtual void LostFocus(); 11 virtual void State(int); 12 virtual String GetDesc() const; 13 virtual bool Key(dword key, int); 14 virtual bool HotKey(dword key); 15 virtual dword GetAccessKeys() const; 16 virtual void AssignAccessKeys(dword used); 17 18 private: 19 bool push:1; 20 bool keypush:1; 21 bool clickfocus:1; 22 23 void EndPush(); 24 25 protected: 26 int accesskey; 27 String label; 28 Font font; 29 30 void KeyPush(); IsPush()31 bool IsPush() const { return push || keypush; } IsKeyPush()32 bool IsKeyPush() { return keypush; } 33 bool FinishPush(); 34 35 protected: 36 virtual void RefreshPush(); 37 virtual void RefreshFocus(); 38 virtual void PerformAction(); 39 40 public: 41 Pusher& SetFont(Font fnt); 42 Pusher& SetLabel(const char *text); 43 Pusher& ClickFocus(bool cf = true); NoClickFocus()44 Pusher& NoClickFocus() { return ClickFocus(false); } IsClickFocus()45 bool IsClickFocus() const { return clickfocus; } 46 GetFont()47 Font GetFont() const { return font; } GetLabel()48 String GetLabel() const { return label; } 49 50 void PseudoPush(); 51 52 int GetVisualState() const; 53 54 Event<> WhenPush; 55 Event<> WhenRepeat; 56 57 Pusher(); 58 virtual ~Pusher(); 59 }; 60 61 class Button : public Pusher { 62 public: 63 virtual void Paint(Draw& draw); 64 virtual bool Key(dword key, int); 65 virtual bool HotKey(dword key); 66 virtual void MouseEnter(Point, dword); 67 virtual void MouseLeave(); 68 virtual dword GetAccessKeys() const; 69 virtual void AssignAccessKeys(dword used); 70 virtual void Layout(); 71 virtual void GotFocus(); 72 virtual void LostFocus(); 73 virtual int OverPaint() const; 74 75 public: 76 struct Style : ChStyle<Style> { 77 Value look[4]; 78 Color monocolor[4], textcolor[4]; 79 Point pressoffset; 80 int focusmargin; 81 int overpaint; 82 Font font; 83 Image ok, cancel, exit; 84 bool transparent; 85 bool focus_use_ok; 86 }; 87 88 protected: 89 enum { NORMAL, OK, CANCEL, EXIT }; 90 const Style *style; 91 Image img; 92 bool monoimg; 93 byte type; 94 95 void RefreshOK(Ctrl *p); 96 const Style *St() const; 97 98 public: 99 Button& SetImage(const Image& img); 100 Button& SetMonoImage(const Image& img); 101 102 static const Style& StyleNormal(); 103 static const Style& StyleOk(); 104 static const Style& StyleEdge(); 105 static const Style& StyleLeftEdge(); 106 static const Style& StyleScroll(); 107 static const Style& StyleNaked(); 108 109 Button& SetStyle(const Style& s); 110 Button& AutoStyle(); 111 NormalStyle()112 Button& NormalStyle() { return SetStyle(StyleNormal()); } EdgeStyle()113 Button& EdgeStyle() { return SetStyle(StyleEdge()); } LeftEdgeStyle()114 Button& LeftEdgeStyle() { return SetStyle(StyleLeftEdge()); } ScrollStyle()115 Button& ScrollStyle() { return SetStyle(StyleScroll()); } NakedStyle()116 Button& NakedStyle() { return SetStyle(StyleNaked()); } 117 118 Button& Ok(); 119 Button& Cancel(); 120 Button& Exit(); Normal()121 Button& Normal() { type = NORMAL; Refresh(); return *this; } 122 123 Button(); 124 virtual ~Button(); 125 }; 126 127 Color ButtonMonoColor(int i); 128 129 class SpinButtons : public CtrlFrame { 130 public: 131 virtual void FrameLayout(Rect& r); 132 virtual void FrameAddSize(Size& sz); 133 virtual void FrameAdd(Ctrl& ctrl); 134 virtual void FrameRemove(); 135 136 public: 137 struct Style : ChStyle<Style> { 138 Button::Style inc; 139 Button::Style dec; 140 int width; 141 int over; 142 bool onsides; 143 }; 144 145 private: 146 bool visible; 147 const Style *style; 148 149 public: 150 Button inc; 151 Button dec; 152 153 void Show(bool s = true); IsVisible()154 bool IsVisible() const { return visible; } 155 156 static const Style& StyleDefault(); 157 static const Style& StyleOnSides(); 158 159 SpinButtons& SetStyle(const Style& s); 160 161 SpinButtons& OnSides(bool b = true) { return SetStyle(b ? StyleOnSides() : StyleDefault()); } IsOnSides()162 bool IsOnSides() const { return style->onsides; } 163 164 SpinButtons(); 165 virtual ~SpinButtons(); 166 }; 167 168 class Option : public Pusher { 169 public: 170 virtual void Paint(Draw& draw); 171 virtual Size GetMinSize() const; 172 virtual void SetData(const Value& data); 173 virtual Value GetData() const; 174 virtual void MouseEnter(Point, dword); 175 virtual void MouseLeave(); 176 virtual void State(int); 177 178 protected: 179 virtual void RefreshPush(); 180 virtual void RefreshFocus(); 181 virtual void PerformAction(); 182 183 protected: 184 Image edge, edged; 185 int option; 186 bool switchimage; 187 bool threestate; 188 bool notnull; 189 bool blackedge; 190 bool showlabel; 191 bool box; 192 bool autobox; 193 Color color; 194 195 void AutoSync(); 196 197 public: 198 Option& Set(int b); Get()199 int Get() const { return option; } 200 201 operator int() const { return option; } 202 void operator=(int b) { Set(b); } 203 204 void EnableBox(bool b); EnableBox()205 void EnableBox() { EnableBox(option); } 206 207 Option& BlackEdge(bool b = true) { blackedge = b; Refresh(); return *this; } IsBlackEdge()208 bool IsBlackEdge() const { return blackedge; } 209 Option& SwitchImage(bool b = true) { switchimage = b; Refresh(); return *this; } IsSwitchImage()210 bool IsSwitchImage() const { return switchimage; } 211 Option& ThreeState(bool b = true) { threestate = b; notnull = false; return *this; } IsThreeState()212 bool IsThreeState() const { return threestate; } 213 Option& ShowLabel(bool b = true) { showlabel = b; Refresh(); return *this; } IsShowLabel()214 bool IsShowLabel() const { return showlabel; } 215 Option& NotNull(bool nn = true) { notnull = nn; Refresh(); return *this; } NoNotNull()216 Option& NoNotNull() { return NotNull(false); } IsNotNull()217 bool IsNotNull() const { return notnull; } SetColor(Color c)218 Option& SetColor(Color c) { color = c; Refresh(); return *this; } 219 Option& Box(bool b = true) { box = b; return *this; } 220 Option& AutoBox(bool b = true) { Box(autobox = b); return *this; } 221 222 Option(); 223 virtual ~Option(); 224 }; 225 226 class OptionBox : public Option { 227 public: OptionBox()228 OptionBox() { Box(); } 229 }; 230 231 class ButtonOption : public Ctrl { 232 public: 233 virtual void Paint(Draw& w); 234 virtual void LeftDown(Point, dword); 235 virtual void LeftUp(Point, dword); 236 virtual void MouseMove(Point, dword); 237 virtual void MouseEnter(Point, dword); 238 virtual void MouseLeave(); 239 virtual void SetData(const Value& v); 240 virtual Value GetData() const; 241 virtual void Serialize(Stream& s); 242 virtual dword GetAccessKeys() const; 243 virtual void AssignAccessKeys(dword used); 244 245 public: 246 struct Style : ChStyle<Style> { 247 Value look[4]; 248 Color textcolor[4]; 249 bool drawfocus; 250 }; 251 252 private: 253 Image image; 254 Image image1; 255 String label; 256 const Style *style; 257 int accesskey; 258 bool option; 259 bool push; 260 261 public: SetImage(const Image & img)262 ButtonOption& SetImage(const Image& img) { image = img; Refresh(); return *this; } SetImage(const Image & m,const Image & m1)263 ButtonOption& SetImage(const Image& m, const Image& m1) { image = m; image1 = m1; Refresh(); return *this; } 264 void operator=(const Image& img) { SetImage(img); } 265 266 ButtonOption& SetLabel(const String& text); GetLabel()267 String GetLabel() const { return label; } 268 Set(bool b)269 void Set(bool b) { option = b; UpdateRefresh(); } Get()270 bool Get() const { return option; } 271 272 void operator=(bool b) { Set(b); } 273 operator bool() const { return Get(); } 274 275 static const Style& StyleDefault(); 276 static const Style& StyleFlat(); 277 SetStyle(const Style & s)278 ButtonOption& SetStyle(const Style& s) { style = &s; Refresh(); return *this; } AutoStyle()279 ButtonOption& AutoStyle() { style = NULL; Refresh(); return *this; } 280 281 ButtonOption(); 282 }; 283 284 class Switch : public Ctrl { 285 public: 286 virtual void Paint(Draw& draw); 287 virtual void CancelMode(); 288 virtual void MouseMove(Point p, dword keyflags); 289 virtual void LeftDown(Point p, dword keyflags); 290 virtual void LeftUp(Point p, dword keyflags); 291 virtual void MouseLeave(); 292 virtual bool Key(dword key, int count); 293 virtual bool HotKey(dword key); 294 virtual dword GetAccessKeys() const; 295 virtual void AssignAccessKeys(dword used); 296 virtual void SetData(const Value& data); 297 virtual Value GetData() const; 298 virtual void GotFocus(); 299 virtual void LostFocus(); 300 301 public: 302 struct Case { 303 String label; 304 Value value; 305 int accesskey = 0; 306 bool enabled = true; 307 int gap = 0; 308 Rect16 rect = Rect16(0, 0, 0, 0); 309 }; 310 311 private: 312 Font font; 313 Value value; 314 int pushindex; 315 Array<Case> cs; 316 int linecy; 317 int light; 318 int mincy; 319 int direction; 320 321 int GetIndex() const; 322 int GetIndex(Point p); 323 bool DoHot(dword key); 324 void Updates(); 325 void RefreshCase(int i); 326 327 Rect GetCaseRect(int i) const; 328 Rect GetCheckRect(int i) const; 329 330 public: 331 enum { GAP_SEPARATOR = 1 << 20 }; 332 333 Switch& SetLabel(int i, const char *text, int gap = 0); 334 Switch& SetLabel(const char *text); GetLabel()335 String GetLabel() const { return GetLabel(GetIndex()); } GetLabel(int i)336 String GetLabel(int i) const { return cs[i].label; } 337 Switch& Set(int i, const Value& val, const char *text, int gap = 0); 338 Switch& Set(int i, const Value& val); 339 Switch& Add(const Value& val, const char *text, int gap = 0); 340 Switch& Add(const char *text, int gap = 0); 341 342 void EnableCase(int i, bool enable = true); DisableCase(int i)343 void DisableCase(int i) { EnableCase(i, false); } 344 345 void EnableValue(const Value& val, bool enable = true); DisableValue(const Value & val)346 void DisableValue(const Value& val) { EnableValue(val, false); } 347 Reset()348 void Reset() { cs.Clear(); } 349 GetCases()350 const Array<Case>& GetCases() const { return cs; } 351 352 operator int() const { return GetData(); } 353 void operator=(const Value& v) { SetData(v); } 354 SetFont(Font f)355 Switch& SetFont(Font f) { font = f; Refresh(); return *this; } GetFont()356 Font GetFont() const { return font; } MinCaseHeight(int cy)357 Switch& MinCaseHeight(int cy) { mincy = cy; Refresh(); return *this; } SetAutoDirection()358 Switch& SetAutoDirection() { direction = 0; return *this; } SetHorizontal()359 Switch& SetHorizontal() { direction = 1; return *this; } SetVertical()360 Switch& SetVertical() { direction = -1; return *this; } 361 362 Switch(); 363 virtual ~Switch(); 364 }; 365 366 class DataPusher : public Pusher 367 { 368 public: 369 virtual void Paint(Draw& draw); 370 371 private: 372 const Convert *convert; 373 const Display *display; 374 Value data; 375 376 WString nulltext; 377 Color nullink; 378 Font nullfont; 379 380 ActiveEdgeFrame edge; 381 382 void RefreshAll(); 383 Color GetPaper(); 384 385 protected: 386 virtual void RefreshPush(); 387 virtual void RefreshFocus(); 388 virtual void PerformAction(); 389 virtual void DoAction(); 390 391 public: 392 Event<> WhenPreAction; 393 394 SetConvert(const Convert & _convert)395 DataPusher& SetConvert(const Convert& _convert) { convert = &_convert; Refresh(); return *this; } GetConvert()396 const Convert& GetConvert() const { return *convert; } 397 SetDisplay(const Display & _display)398 DataPusher& SetDisplay(const Display& _display) { display = &_display; Refresh(); return *this; } GetDisplay()399 const Display& GetDisplay() const { return *display; } 400 401 virtual Value GetData() const; 402 virtual void SetData(const Value& value); 403 404 void SetDataAction(const Value& value); 405 406 void Set(const Value& value); 407 408 DataPusher& NullText(const char *text = t_("(default)"), Color ink = Brown); 409 DataPusher& NullText(const char *text, Font fnt, Color ink); 410 411 DataPusher(); 412 DataPusher(const Convert& convert, const Display& display = StdDisplay()); // deprecated 413 DataPusher(const Display& display); // deprecated 414 }; 415