Torque3D Documentation / _generateds / win32MsgBox.cpp

win32MsgBox.cpp

Engine/source/platformWin32/nativeDialogs/win32MsgBox.cpp

More...

Classes:

Public Functions

Detailed Description

Public Variables

_FlagMap sgButtonMap []
_FlagMap sgIconMap []
_FlagMap sgMsgBoxRetMap []

Public Functions

getMaskFromID(_FlagMap * map, S32 id)

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "platformWin32/platformWin32.h" 
 26#include "platform/platformInput.h"
 27#include "platform/nativeDialogs/msgBox.h"
 28
 29#include "console/console.h"
 30#include "core/strings/unicode.h"
 31
 32#include "windowManager/platformWindowMgr.h"
 33#include "windowManager/win32/win32Window.h"
 34
 35struct _FlagMap
 36{
 37   S32 num;
 38   U32 flag;
 39};
 40
 41static _FlagMap sgButtonMap[] =
 42{
 43   { MBOk,                 MB_OK },
 44   { MBOkCancel,           MB_OKCANCEL },
 45   { MBRetryCancel,        MB_RETRYCANCEL },
 46   { MBSaveDontSave,       MB_YESNO },
 47   { MBSaveDontSaveCancel, MB_YESNOCANCEL },
 48   { 0xffffffff,           0xffffffff }
 49};
 50
 51static _FlagMap sgIconMap[] =
 52{
 53   { MIWarning,            MB_ICONWARNING },
 54   { MIInformation,        MB_ICONINFORMATION },
 55   { MIQuestion,           MB_ICONQUESTION },
 56   { MIStop,               MB_ICONSTOP },
 57   { 0xffffffff,           0xffffffff }
 58};
 59
 60static _FlagMap sgMsgBoxRetMap[] =
 61{
 62   { IDCANCEL,             MRCancel },
 63   { IDNO,                 MRDontSave },
 64   { IDOK,                 MROk},
 65   { IDRETRY,              MRRetry },
 66   { IDYES,                MROk },
 67   { 0xffffffff,           0xffffffff }
 68};
 69
 70//-----------------------------------------------------------------------------
 71
 72static U32 getMaskFromID(_FlagMap *map, S32 id)
 73{
 74   for(S32 i = 0;map[i].num != 0xffffffff && map[i].flag != 0xffffffff;++i)
 75   {
 76      if(map[i].num == id)
 77         return map[i].flag;
 78   }
 79
 80   return 0;
 81}
 82
 83//-----------------------------------------------------------------------------
 84#ifndef TORQUE_SDL
 85S32 Platform::messageBox(const UTF8 *title, const UTF8 *message, MBButtons buttons, MBIcons icon)
 86{
 87   PlatformWindow *pWindow = WindowManager->getFirstWindow();
 88
 89   // Get us rendering while we're blocking.
 90   winState.renderThreadBlocked = true;
 91
 92   // We don't keep a locked mouse or else we're going 
 93   // to end up possibly locking our mouse out of the 
 94   // message box area
 95   bool cursorLocked = pWindow && pWindow->isMouseLocked();
 96   if( cursorLocked )
 97      pWindow->setMouseLocked( false );
 98
 99   // Need a visible cursor to click stuff accurately
100   bool cursorVisible = !pWindow || pWindow->isCursorVisible();
101   if( !cursorVisible )
102      pWindow->setCursorVisible(true);
103
104#ifdef UNICODE
105   const UTF16 *msg = createUTF16string(message);
106   const UTF16 *t = createUTF16string(title);
107#else
108   const UTF8 *msg = message;
109   const UTF8 *t = title;
110#endif
111
112   HWND parent = pWindow ? static_cast<Win32Window*>(pWindow)->getHWND() : NULL;
113   S32 ret = ::MessageBox( parent, msg, t, getMaskFromID(sgButtonMap, buttons) | getMaskFromID(sgIconMap, icon));
114
115#ifdef UNICODE
116   delete [] msg;
117   delete [] t;
118#endif
119
120   // Dialog is gone.
121   winState.renderThreadBlocked = false;
122
123   if( cursorVisible == false )
124      pWindow->setCursorVisible( false );
125
126   if( cursorLocked == true )
127      pWindow->setMouseLocked( true );
128
129   return getMaskFromID(sgMsgBoxRetMap, ret);
130}
131#endif
132