1 //============================================================================
2 //
3 //   SSSS    tt          lll  lll
4 //  SS  SS   tt           ll   ll
5 //  SS     tttttt  eeee   ll   ll   aaaa
6 //   SSSS    tt   ee  ee  ll   ll      aa
7 //      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator"
8 //  SS  SS   tt   ee      ll   ll  aa  aa
9 //   SSSS     ttt  eeeee llll llll  aaaaa
10 //
11 // Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony
12 // and the Stella Team
13 //
14 // See the file "License.txt" for information on usage and redistribution of
15 // this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 //============================================================================
17 
18 #ifndef EDIT_TEXT_WIDGET_HXX
19 #define EDIT_TEXT_WIDGET_HXX
20 
21 #include "Rect.hxx"
22 #include "EditableWidget.hxx"
23 
24 /* EditTextWidget */
25 class EditTextWidget : public EditableWidget
26 {
27   public:
28     EditTextWidget(GuiObject* boss, const GUI::Font& font,
29                    int x, int y, int w, int h, const string& text = "");
30     ~EditTextWidget() override = default;
31 
32     void setText(const string& str, bool changed = false) override;
33 
34     // Get total width of widget
calcWidth(const GUI::Font & font,int length=0)35     static int calcWidth(const GUI::Font& font, int length = 0)
36     {
37       return length * font.getMaxCharWidth()
38         + (font.getFontHeight() < 24 ? 3 * 2 : 5 * 2);
39     }
40     // Get total width of widget
calcWidth(const GUI::Font & font,const string & str)41     static int calcWidth(const GUI::Font& font, const string& str)
42     {
43       return calcWidth(font, int(str.length()));
44     }
45 
46   protected:
47     void drawWidget(bool hilite) override;
48     void lostFocusWidget() override;
49 
50     void startEditMode() override;
51     void endEditMode() override;
52     void abortEditMode() override;
53 
54     Common::Rect getEditRect() const override;
55 
56     void handleMouseDown(int x, int y, MouseButton b, int clickCount) override;
57 
58   protected:
59     bool   _changed{false};
60     int    _textOfs{0};
61 
62   private:
63     // Following constructors and assignment operators not supported
64     EditTextWidget() = delete;
65     EditTextWidget(const EditTextWidget&) = delete;
66     EditTextWidget(EditTextWidget&&) = delete;
67     EditTextWidget& operator=(const EditTextWidget&) = delete;
68     EditTextWidget& operator=(EditTextWidget&&) = delete;
69 };
70 
71 #endif
72