[Win] Show buttons in message box.
This commit is contained in:
parent
2e7dcade25
commit
489c5daff5
1 changed files with 39 additions and 6 deletions
|
@ -8,12 +8,11 @@
|
||||||
#include "base/run_loop.h"
|
#include "base/run_loop.h"
|
||||||
#include "base/utf_string_conversions.h"
|
#include "base/utf_string_conversions.h"
|
||||||
#include "browser/native_window.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/controls/message_box_view.h"
|
||||||
#include "ui/views/layout/grid_layout.h"
|
#include "ui/views/layout/grid_layout.h"
|
||||||
#include "ui/views/widget/widget.h"
|
#include "ui/views/widget/widget.h"
|
||||||
#include "ui/views/widget/widget_delegate.h"
|
#include "ui/views/widget/widget_delegate.h"
|
||||||
#include "ui/views/window/client_view.h"
|
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -21,6 +20,7 @@ namespace {
|
||||||
|
|
||||||
class MessageDialog : public base::MessageLoop::Dispatcher,
|
class MessageDialog : public base::MessageLoop::Dispatcher,
|
||||||
public views::WidgetDelegate,
|
public views::WidgetDelegate,
|
||||||
|
public views::View,
|
||||||
public views::ButtonListener {
|
public views::ButtonListener {
|
||||||
public:
|
public:
|
||||||
MessageDialog(NativeWindow* parent_window,
|
MessageDialog(NativeWindow* parent_window,
|
||||||
|
@ -39,7 +39,7 @@ class MessageDialog : public base::MessageLoop::Dispatcher,
|
||||||
virtual void WindowClosing() OVERRIDE;
|
virtual void WindowClosing() OVERRIDE;
|
||||||
virtual views::Widget* GetWidget() OVERRIDE;
|
virtual views::Widget* GetWidget() OVERRIDE;
|
||||||
virtual const views::Widget* GetWidget() const 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;
|
virtual ui::ModalType GetModalType() const OVERRIDE;
|
||||||
|
|
||||||
// Overridden from views::ButtonListener:
|
// Overridden from views::ButtonListener:
|
||||||
|
@ -62,18 +62,51 @@ MessageDialog::MessageDialog(NativeWindow* parent_window,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& detail)
|
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));
|
views::MessageBoxView::InitParams params(UTF8ToUTF16(title));
|
||||||
params.message = UTF8ToUTF16(message);
|
params.message = UTF8ToUTF16(message);
|
||||||
message_box_view_ = new views::MessageBoxView(params);
|
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;
|
views::Widget::InitParams widget_params;
|
||||||
widget_params.delegate = this;
|
widget_params.delegate = this;
|
||||||
if (parent_window)
|
if (parent_window)
|
||||||
widget_params.parent = parent_window->GetNativeWindow();
|
widget_params.parent = parent_window->GetNativeWindow();
|
||||||
widget_ = new views::Widget;
|
widget_ = new views::Widget;
|
||||||
|
widget_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_NATIVE);
|
||||||
widget_->Init(widget_params);
|
widget_->Init(widget_params);
|
||||||
|
|
||||||
|
set_background(views::Background::CreateStandardPanelBackground());
|
||||||
widget_->Show();
|
widget_->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,8 +134,8 @@ const views::Widget* MessageDialog::GetWidget() const {
|
||||||
return widget_;
|
return widget_;
|
||||||
}
|
}
|
||||||
|
|
||||||
views::ClientView* MessageDialog::CreateClientView(views::Widget* widget) {
|
views::View* MessageDialog::GetContentsView() {
|
||||||
return new views::ClientView(widget, message_box_view_);
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui::ModalType MessageDialog::GetModalType() const {
|
ui::ModalType MessageDialog::GetModalType() const {
|
||||||
|
|
Loading…
Reference in a new issue