OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/input_window_dialog.h" | 5 #include "chrome/browser/ui/input_window_dialog_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
11 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/ui/gtk/gtk_util.h" | 10 #include "chrome/browser/ui/gtk/gtk_util.h" |
13 #include "ui/base/gtk/gtk_signal.h" | 11 #include "ui/base/gtk/gtk_signal.h" |
14 | 12 |
15 class InputWindowDialogGtk : public InputWindowDialog { | |
16 public: | |
17 // Creates a dialog. Takes ownership of |delegate|. | |
18 InputWindowDialogGtk(GtkWindow* parent, | |
19 const std::string& window_title, | |
20 const std::string& label, | |
21 const std::string& contents, | |
22 Delegate* delegate); | |
23 virtual ~InputWindowDialogGtk(); | |
24 | |
25 virtual void Show(); | |
26 virtual void Close(); | |
27 | |
28 private: | |
29 CHROMEG_CALLBACK_0(InputWindowDialogGtk, void, OnEntryChanged, GtkEditable*); | |
30 CHROMEGTK_CALLBACK_1(InputWindowDialogGtk, void, OnResponse, int); | |
31 CHROMEGTK_CALLBACK_1(InputWindowDialogGtk, gboolean, | |
32 OnWindowDeleteEvent, GdkEvent*); | |
33 CHROMEGTK_CALLBACK_0(InputWindowDialogGtk, void, OnWindowDestroy); | |
34 | |
35 // The underlying gtk dialog window. | |
36 GtkWidget* dialog_; | |
37 | |
38 // The GtkEntry in this form. | |
39 GtkWidget* input_; | |
40 | |
41 // Our delegate. Consumes the window's output. | |
42 scoped_ptr<InputWindowDialog::Delegate> delegate_; | |
43 }; | |
44 | |
45 | |
46 InputWindowDialogGtk::InputWindowDialogGtk(GtkWindow* parent, | 13 InputWindowDialogGtk::InputWindowDialogGtk(GtkWindow* parent, |
47 const std::string& window_title, | 14 const std::string& window_title, |
48 const std::string& label, | 15 const std::string& label, |
49 const std::string& contents, | 16 const std::string& contents, |
50 Delegate* delegate) | 17 Delegate* delegate) |
51 : dialog_(gtk_dialog_new_with_buttons( | 18 : dialog_(gtk_dialog_new_with_buttons( |
52 window_title.c_str(), | 19 window_title.c_str(), |
53 parent, | 20 parent, |
54 GTK_DIALOG_MODAL, | 21 GTK_DIALOG_MODAL, |
55 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, | 22 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 92 |
126 // Return true to prevent the gtk dialog from being destroyed. Close will | 93 // Return true to prevent the gtk dialog from being destroyed. Close will |
127 // destroy it for us and the default gtk_dialog_delete_event_handler() will | 94 // destroy it for us and the default gtk_dialog_delete_event_handler() will |
128 // force the destruction without us being able to stop it. | 95 // force the destruction without us being able to stop it. |
129 return TRUE; | 96 return TRUE; |
130 } | 97 } |
131 | 98 |
132 void InputWindowDialogGtk::OnWindowDestroy(GtkWidget* widget) { | 99 void InputWindowDialogGtk::OnWindowDestroy(GtkWidget* widget) { |
133 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 100 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
134 } | 101 } |
135 | |
136 InputWindowDialog* InputWindowDialog::Create(gfx::NativeWindow parent, | |
137 const string16& window_title, | |
138 const string16& label, | |
139 const string16& contents, | |
140 Delegate* delegate) { | |
141 return new InputWindowDialogGtk(parent, | |
142 UTF16ToUTF8(window_title), | |
143 UTF16ToUTF8(label), | |
144 UTF16ToUTF8(contents), | |
145 delegate); | |
146 } | |
OLD | NEW |