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.
5 #include "ui/base/win/message_box_win.h"
7 #include "base/command_line.h"
8 #include "base/i18n/rtl.h"
9 #include "ui/base/ui_base_switches.h"
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.
16 int MessageBox(HWND hwnd
,
17 const base::string16
& text
,
18 const base::string16
& caption
,
20 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoMessageBox
))
23 UINT actual_flags
= flags
;
24 if (base::i18n::IsRTL())
25 actual_flags
|= MB_RIGHT
| MB_RTLREADING
;
27 base::string16 localized_text
= text
;
28 base::i18n::AdjustStringForLocaleDirection(&localized_text
);
29 const wchar_t* text_ptr
= localized_text
.c_str();
31 base::string16 localized_caption
= caption
;
32 base::i18n::AdjustStringForLocaleDirection(&localized_caption
);
33 const wchar_t* caption_ptr
= localized_caption
.c_str();
35 return ::MessageBox(hwnd
, text_ptr
, caption_ptr
, actual_flags
);