summaryrefslogtreecommitdiffstats
path: root/views/controls
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-10 19:20:56 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-10 19:20:56 +0000
commite9923cb7a30065c91964acecf537fe15c2bf768e (patch)
tree75f33127aaa09bb9d1c6491aa42afcf1f4a327bd /views/controls
parentcd6993de91f8eb452d3d92916ed63c78612ffff0 (diff)
downloadchromium_src-e9923cb7a30065c91964acecf537fe15c2bf768e.zip
chromium_src-e9923cb7a30065c91964acecf537fe15c2bf768e.tar.gz
chromium_src-e9923cb7a30065c91964acecf537fe15c2bf768e.tar.bz2
Lands http://codereview.chromium.org/194014 for Oshima:
* enable MessageBoxView convert wstring to string16 when necessary using WideToUTF16Hack, which is no-op on Windows. * updated checkbox to get state update working state handing is a bit hacky, esp. b/c gtk sends signal even when the state is changed via API. If there is better way, please let me know. BUG=none TEST=none Review URL: http://codereview.chromium.org/201079 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25896 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r--views/controls/button/native_button_gtk.cc45
-rw-r--r--views/controls/button/native_button_gtk.h21
-rw-r--r--views/controls/message_box_view.cc6
3 files changed, 64 insertions, 8 deletions
diff --git a/views/controls/button/native_button_gtk.cc b/views/controls/button/native_button_gtk.cc
index 900a2b2..c5f0f1a 100644
--- a/views/controls/button/native_button_gtk.cc
+++ b/views/controls/button/native_button_gtk.cc
@@ -57,7 +57,9 @@ void NativeButtonGtk::UpdateEnabled() {
void NativeButtonGtk::UpdateDefault() {
if (!native_view())
return;
- if (!IsCheckbox())
+ if (IsCheckbox())
+ UpdateChecked();
+ else
NOTIMPLEMENTED();
}
@@ -115,15 +117,54 @@ void NativeButtonGtk::OnClicked() {
native_button_->ButtonPressed();
}
+////////////////////////////////////////////////////////////////////////////////
+// NativeCheckboxGtk
NativeCheckboxGtk::NativeCheckboxGtk(Checkbox* checkbox)
- : NativeButtonGtk(checkbox) {
+ : NativeButtonGtk(checkbox),
+ checkbox_(checkbox),
+ deliver_click_event_(true) {
}
void NativeCheckboxGtk::CreateNativeControl() {
GtkWidget* widget = gtk_check_button_new();
+ g_signal_connect(G_OBJECT(widget), "clicked",
+ G_CALLBACK(CallClicked), this);
NativeControlCreated(widget);
}
+void NativeCheckboxGtk::OnClicked() {
+ // ignore event if the event is generated by
+ // gtk_toggle_button_set_active below.
+ if (deliver_click_event_) {
+ checkbox_->SetChecked(!checkbox_->checked());
+ NativeButtonGtk::OnClicked();
+ }
+}
+
+void NativeCheckboxGtk::UpdateChecked() {
+ if (!native_view())
+ return;
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(native_view()))
+ != checkbox_->checked()) {
+ // gtk_toggle_button_set_active emites "clicked" signal, which
+ // invokes OnClicked method above. deliver_click_event_ flag is used
+ // to prevent such signal to invoke OnClicked callback.
+ deliver_click_event_ = false;
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(native_view()),
+ checkbox_->checked());
+ deliver_click_event_ = true;
+ }
+}
+
+// static
+void NativeCheckboxGtk::CallClicked(GtkButton* widget,
+ NativeCheckboxGtk* button) {
+ button->OnClicked();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeButtonWrapper
+
// static
int NativeButtonWrapper::GetFixedWidth() {
// TODO(brettw) implement this properly.
diff --git a/views/controls/button/native_button_gtk.h b/views/controls/button/native_button_gtk.h
index 4b609d9..e44b8b3 100644
--- a/views/controls/button/native_button_gtk.h
+++ b/views/controls/button/native_button_gtk.h
@@ -33,15 +33,15 @@ class NativeButtonGtk : public NativeControlGtk, public NativeButtonWrapper {
virtual void CreateNativeControl();
virtual void NativeControlCreated(GtkWidget* widget);
+ // Invoked when the user clicks on the button.
+ virtual void OnClicked();
+
// Returns true if this button is actually a checkbox or radio button.
virtual bool IsCheckbox() const { return false; }
private:
static void CallClicked(GtkButton* widget, NativeButtonGtk* button);
- // Invoked when the user clicks on the button.
- void OnClicked();
-
// The NativeButton we are bound to.
NativeButton* native_button_;
@@ -59,10 +59,25 @@ class NativeCheckboxGtk : public NativeButtonGtk {
explicit NativeCheckboxGtk(Checkbox* checkbox);
private:
+ static void CallClicked(GtkButton* widget, NativeCheckboxGtk* button);
+
virtual void CreateNativeControl();
+ // Invoked when the user clicks on the button.
+ virtual void OnClicked();
+
+ // Overidden from NativeButtonWrapper
+ virtual void UpdateChecked();
+
// Returns true if this button is actually a checkbox or radio button.
virtual bool IsCheckbox() const { return true; }
+
+ Checkbox* checkbox_;
+
+ // a flag to prevent OnClicked event when updating
+ // gtk control via API gtk_toggle_button_set_active.
+ bool deliver_click_event_;
+
DISALLOW_COPY_AND_ASSIGN(NativeCheckboxGtk);
};
diff --git a/views/controls/message_box_view.cc b/views/controls/message_box_view.cc
index 8d68e4f..a90d440 100644
--- a/views/controls/message_box_view.cc
+++ b/views/controls/message_box_view.cc
@@ -47,7 +47,7 @@ MessageBoxView::MessageBoxView(int dialog_flags,
std::wstring MessageBoxView::GetInputText() {
if (prompt_field_)
- return prompt_field_->text();
+ return UTF16ToWideHack(prompt_field_->text());
return EmptyWString();
}
@@ -106,7 +106,7 @@ bool MessageBoxView::AcceleratorPressed(
return false;
ScopedClipboardWriter scw(clipboard);
- scw.WriteText(message_label_->GetText());
+ scw.WriteText(WideToUTF16Hack(message_label_->GetText()));
return true;
}
@@ -138,7 +138,7 @@ void MessageBoxView::Init(int dialog_flags,
if (dialog_flags & MessageBoxFlags::kFlagHasPromptField) {
prompt_field_ = new views::Textfield;
- prompt_field_->SetText(default_prompt);
+ prompt_field_->SetText(WideToUTF16Hack(default_prompt));
}
ResetLayoutManager();