| 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-2019 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 | #include "Dialog.hxx" | 
|---|
| 19 | #include "OSystem.hxx" | 
|---|
| 20 | #include "Version.hxx" | 
|---|
| 21 | #include "Widget.hxx" | 
|---|
| 22 | #include "Font.hxx" | 
|---|
| 23 | #include "StringParser.hxx" | 
|---|
| 24 | #include "MessageBox.hxx" | 
|---|
| 25 |  | 
|---|
| 26 | namespace GUI { | 
|---|
| 27 |  | 
|---|
| 28 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 29 | MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font, | 
|---|
| 30 | const StringList& text, int max_w, int max_h, int cmd, | 
|---|
| 31 | const string& okText, const string& cancelText, | 
|---|
| 32 | const string& title, | 
|---|
| 33 | bool focusOKButton) | 
|---|
| 34 | : Dialog(boss->instance(), boss->parent(), font, title, 0, 0, max_w, max_h), | 
|---|
| 35 | CommandSender(boss), | 
|---|
| 36 | myCmd(cmd) | 
|---|
| 37 | { | 
|---|
| 38 | addText(font, text); | 
|---|
| 39 |  | 
|---|
| 40 | WidgetArray wid; | 
|---|
| 41 | addOKCancelBGroup(wid, font, okText, cancelText, focusOKButton); | 
|---|
| 42 | addToFocusList(wid); | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 46 | MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font, | 
|---|
| 47 | const string& text, int max_w, int max_h, int cmd, | 
|---|
| 48 | const string& okText, const string& cancelText, | 
|---|
| 49 | const string& title, | 
|---|
| 50 | bool focusOKButton) | 
|---|
| 51 | : MessageBox(boss, font, StringParser(text).stringList(), max_w, max_h, | 
|---|
| 52 | cmd, okText, cancelText, title, focusOKButton) | 
|---|
| 53 | { | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 57 | void MessageBox::addText(const GUI::Font& font, const StringList& text) | 
|---|
| 58 | { | 
|---|
| 59 | const int lineHeight = font.getLineHeight(), | 
|---|
| 60 | fontWidth  = font.getMaxCharWidth(), | 
|---|
| 61 | fontHeight = font.getFontHeight(); | 
|---|
| 62 | int xpos, ypos; | 
|---|
| 63 |  | 
|---|
| 64 | // Set real dimensions | 
|---|
| 65 | int str_w = 0; | 
|---|
| 66 | for(const auto& s: text) | 
|---|
| 67 | str_w = std::max(int(s.length()), str_w); | 
|---|
| 68 | _w = std::min(str_w * fontWidth + 20, _w); | 
|---|
| 69 | _h = std::min(uInt32((text.size() + 2) * lineHeight + 20 + _th), uInt32(_h)); | 
|---|
| 70 |  | 
|---|
| 71 | xpos = 10;  ypos = 10 + _th; | 
|---|
| 72 | for(const auto& s: text) | 
|---|
| 73 | { | 
|---|
| 74 | new StaticTextWidget(this, font, xpos, ypos, _w - 20, | 
|---|
| 75 | fontHeight, s, TextAlign::Left); | 
|---|
| 76 | ypos += fontHeight; | 
|---|
| 77 | } | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 81 | void MessageBox::handleCommand(CommandSender* sender, int cmd, int data, int id) | 
|---|
| 82 | { | 
|---|
| 83 | switch(cmd) | 
|---|
| 84 | { | 
|---|
| 85 | case GuiObject::kOKCmd: | 
|---|
| 86 | { | 
|---|
| 87 | close(); | 
|---|
| 88 |  | 
|---|
| 89 | // Send a signal to the calling class that 'OK' has been selected | 
|---|
| 90 | // Since we aren't derived from a widget, we don't have a 'data' or 'id' | 
|---|
| 91 | if(myCmd) | 
|---|
| 92 | sendCommand(myCmd, 0, 0); | 
|---|
| 93 |  | 
|---|
| 94 | break; | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | default: | 
|---|
| 98 | Dialog::handleCommand(sender, cmd, data, id); | 
|---|
| 99 | break; | 
|---|
| 100 | } | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | }  // namespace GUI | 
|---|
| 104 |  | 
|---|