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
11 namespace 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.
MessageBox(HWND hwnd,const string16 & text,const string16 & caption,UINT flags)16 int MessageBox(HWND hwnd,
17 const string16& text,
18 const 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 string16 localized_text = text;
28 base::i18n::AdjustStringForLocaleDirection(&localized_text);
29 const wchar_t* text_ptr = localized_text.c_str();
30
31 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