[Win] Show buttons in message box.

This commit is contained in:
Cheng Zhao 2013-07-25 15:22:44 +08:00
parent 2e7dcade25
commit 489c5daff5

View file

@ -8,12 +8,11 @@
#include "base/run_loop.h"
#include "base/utf_string_conversions.h"
#include "browser/native_window.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/message_box_view.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/window/client_view.h"
namespace atom {
@ -21,6 +20,7 @@ namespace {
class MessageDialog : public base::MessageLoop::Dispatcher,
public views::WidgetDelegate,
public views::View,
public views::ButtonListener {
public:
MessageDialog(NativeWindow* parent_window,
@ -39,7 +39,7 @@ class MessageDialog : public base::MessageLoop::Dispatcher,
virtual void WindowClosing() OVERRIDE;
virtual views::Widget* GetWidget() OVERRIDE;
virtual const views::Widget* GetWidget() const OVERRIDE;
virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
virtual views::View* GetContentsView() OVERRIDE;
virtual ui::ModalType GetModalType() const OVERRIDE;
// Overridden from views::ButtonListener:
@ -62,18 +62,51 @@ MessageDialog::MessageDialog(NativeWindow* parent_window,
const std::string& title,
const std::string& message,
const std::string& detail)
: should_close_(false) {
: should_close_(false),
widget_(NULL),
message_box_view_(NULL) {
set_owned_by_client();
views::MessageBoxView::InitParams params(UTF8ToUTF16(title));
params.message = UTF8ToUTF16(message);
message_box_view_ = new views::MessageBoxView(params);
views::GridLayout* layout = new views::GridLayout(this);
SetLayoutManager(layout);
const int message_box_column = 0;
views::ColumnSet* column_set = layout->AddColumnSet(message_box_column);
column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
views::GridLayout::USE_PREF, 0, 0);
layout->StartRow(1 /* expand */, message_box_column);
layout->AddView(message_box_view_);
const int button_column = 1;
column_set = layout->AddColumnSet(button_column);
for (size_t i = 0; i < buttons.size(); ++i)
column_set->AddColumn(views::GridLayout::CENTER,
views::GridLayout::CENTER,
0.f, views::GridLayout::USE_PREF, 0, 0);
layout->StartRow(0 /* no expand */, button_column);
for (size_t i = 0; i < buttons.size(); ++i) {
views::LabelButton* button = new views::LabelButton(
this, UTF8ToUTF16(buttons[i]));
button->set_tag(i);
button->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
layout->AddView(button);
}
views::Widget::InitParams widget_params;
widget_params.delegate = this;
if (parent_window)
widget_params.parent = parent_window->GetNativeWindow();
widget_ = new views::Widget;
widget_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_NATIVE);
widget_->Init(widget_params);
set_background(views::Background::CreateStandardPanelBackground());
widget_->Show();
}
@ -101,8 +134,8 @@ const views::Widget* MessageDialog::GetWidget() const {
return widget_;
}
views::ClientView* MessageDialog::CreateClientView(views::Widget* widget) {
return new views::ClientView(widget, message_box_view_);
views::View* MessageDialog::GetContentsView() {
return this;
}
ui::ModalType MessageDialog::GetModalType() const {