2
0

msgBox.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "core/strings/stringFunctions.h"
  23. #include "core/module.h"
  24. #include "console/console.h"
  25. #include "console/engineAPI.h"
  26. #include "platform/nativeDialogs/msgBox.h"
  27. DefineEnumType( MBButtons );
  28. DefineEnumType( MBIcons );
  29. DefineEnumType( MBReturnVal );
  30. static const MBReturnVal gsOK = MROk;
  31. static const MBReturnVal gsCancel = MRCancel;
  32. static const MBReturnVal gsRetry = MRRetry;
  33. static const MBReturnVal gsDontSave = MRDontSave;
  34. AFTER_MODULE_INIT( Sim )
  35. {
  36. #if !defined( _XBOX ) && !defined( TORQUE_DEDICATED )
  37. Con::addConstant( "$MROk", TypeS32, &gsOK, "Determines the ok button press state in a message box.\n"
  38. "@ingroup Platform" );
  39. Con::addConstant( "$MRCancel", TypeS32, &gsCancel, "Determines the cancel button press state in a message box.\n"
  40. "@ingroup Platform" );
  41. Con::addConstant( "$MRRetry", TypeS32, &gsRetry, "Determines the retry button press state in a message box.\n"
  42. "@ingroup Platform");
  43. Con::addConstant( "$MRDontSave", TypeS32, &gsDontSave, "Determines the don't save button press state in a message box.\n"
  44. "@ingroup Platform" );
  45. #endif
  46. }
  47. //-----------------------------------------------------------------------------
  48. ImplementEnumType( MBButtons,
  49. "Which buttons to display on a message box.\n\n"
  50. "@ingroup Platform" )
  51. { MBOk, "Ok" },
  52. { MBOkCancel, "OkCancel" },
  53. { MBRetryCancel, "RetryCancel" },
  54. { MBSaveDontSave, "SaveDontSave" }, // maps to yes/no on win, to save/discard on mac.
  55. { MBSaveDontSaveCancel, "SaveDontSaveCancel" }, // maps to yes/no/cancel on win, to save/cancel/don'tsave on mac.
  56. EndImplementEnumType;
  57. ImplementEnumType( MBIcons,
  58. "What icon to show on a message box.\n\n"
  59. "@ingroup Platform" )
  60. { MIInformation, "Information" },// win: blue i, mac: app icon or talking head
  61. { MIWarning, "Warning" }, // win & mac: yellow triangle with exclamation pt
  62. { MIStop, "Stop" }, // win: red x, mac: app icon or stop icon, depending on version
  63. { MIQuestion, "Question" }, // win: blue ?, mac: app icon
  64. EndImplementEnumType;
  65. ImplementEnumType( MBReturnVal,
  66. "Return value for messageBox() indicating which button was pressed by the user.\n\n"
  67. "@ingroup Platform" )
  68. { MROk, "OK" },
  69. { MRCancel, "Cancelled" },
  70. { MRRetry, "Retry" },
  71. { MRDontSave, "DontSave" }
  72. EndImplementEnumType;
  73. //-----------------------------------------------------------------------------
  74. DefineEngineFunction( messageBox, S32, ( const char* title, const char* message, MBButtons buttons, MBIcons icons ), ( MBOkCancel, MIInformation ),
  75. "Display a modal message box using the platform's native message box implementation.\n\n"
  76. "@param title The title to display on the message box window.\n"
  77. "@param message The text message to display in the box.\n"
  78. "@param buttons Which buttons to put on the message box.\n"
  79. "@param icons Which icon to show next to the message.\n"
  80. "@return One of $MROK, $MRCancel, $MRRetry, and $MRDontSave identifying the button that the user pressed.\n"
  81. "@tsexample\n"
  82. "messageBox( \"Error\", \"\" );\n" //TODO
  83. "@endtsexample\n\n"
  84. "@ingroup Platform" )
  85. {
  86. return Platform::messageBox( title, message, buttons, icons );
  87. }