1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "ui/base/win/message_box_win.h" 6 7#include "base/command_line.h" 8#include "base/i18n/rtl.h" 9#include "ui/base/ui_base_switches.h" 10 11namespace ui { 12 13// In addition to passing the RTL flags to ::MessageBox if we are running in an 14// RTL locale, we need to make sure that LTR strings are rendered correctly by 15// adding the appropriate Unicode directionality marks. 16int MessageBox(HWND hwnd, 17 const base::string16& text, 18 const base::string16& caption, 19 UINT flags) { 20 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoMessageBox)) 21 return IDOK; 22 23 UINT actual_flags = flags; 24 if (base::i18n::IsRTL()) 25 actual_flags |= MB_RIGHT | MB_RTLREADING; 26 27 base::string16 localized_text = text; 28 base::i18n::AdjustStringForLocaleDirection(&localized_text); 29 const wchar_t* text_ptr = localized_text.c_str(); 30 31 base::string16 localized_caption = caption; 32 base::i18n::AdjustStringForLocaleDirection(&localized_caption); 33 const wchar_t* caption_ptr = localized_caption.c_str(); 34 35 return ::MessageBox(hwnd, text_ptr, caption_ptr, actual_flags); 36} 37 38} // namespace ui 39