OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/task_manager_gtk.h" | 5 #include "chrome/browser/gtk/task_manager_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "app/gfx/gtk_util.h" | 12 #include "app/gfx/gtk_util.h" |
13 #include "app/l10n_util.h" | 13 #include "app/l10n_util.h" |
14 #include "app/resource_bundle.h" | 14 #include "app/resource_bundle.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "chrome/browser/browser_list.h" | |
17 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/browser_window.h" | |
19 #include "chrome/browser/gtk/gtk_chrome_link_button.h" | 17 #include "chrome/browser/gtk/gtk_chrome_link_button.h" |
20 #include "chrome/browser/gtk/gtk_theme_provider.h" | 18 #include "chrome/browser/gtk/gtk_theme_provider.h" |
21 #include "chrome/browser/gtk/menu_gtk.h" | 19 #include "chrome/browser/gtk/menu_gtk.h" |
22 #include "chrome/common/gtk_tree.h" | 20 #include "chrome/common/gtk_tree.h" |
23 #include "chrome/common/gtk_util.h" | 21 #include "chrome/common/gtk_util.h" |
24 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
25 #include "chrome/common/pref_service.h" | 23 #include "chrome/common/pref_service.h" |
26 #include "grit/app_resources.h" | 24 #include "grit/app_resources.h" |
27 #include "grit/chromium_strings.h" | 25 #include "grit/chromium_strings.h" |
28 | 26 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 258 |
261 TaskManagerGtk::~TaskManagerGtk() { | 259 TaskManagerGtk::~TaskManagerGtk() { |
262 task_manager_->OnWindowClosed(); | 260 task_manager_->OnWindowClosed(); |
263 model_->RemoveObserver(this); | 261 model_->RemoveObserver(this); |
264 | 262 |
265 gtk_accel_group_disconnect_key(accel_group_, GDK_w, GDK_CONTROL_MASK); | 263 gtk_accel_group_disconnect_key(accel_group_, GDK_w, GDK_CONTROL_MASK); |
266 gtk_window_remove_accel_group(GTK_WINDOW(dialog_), accel_group_); | 264 gtk_window_remove_accel_group(GTK_WINDOW(dialog_), accel_group_); |
267 g_object_unref(accel_group_); | 265 g_object_unref(accel_group_); |
268 accel_group_ = NULL; | 266 accel_group_ = NULL; |
269 | 267 |
| 268 // Disconnect the destroy signal so it doesn't delete |this|. |
| 269 g_signal_handler_disconnect(G_OBJECT(dialog_), destroy_handler_id_); |
270 gtk_widget_destroy(dialog_); | 270 gtk_widget_destroy(dialog_); |
271 } | 271 } |
272 | 272 |
273 //////////////////////////////////////////////////////////////////////////////// | 273 //////////////////////////////////////////////////////////////////////////////// |
274 // TaskManagerGtk, TaskManagerModelObserver implementation: | 274 // TaskManagerGtk, TaskManagerModelObserver implementation: |
275 | 275 |
276 void TaskManagerGtk::OnModelChanged() { | 276 void TaskManagerGtk::OnModelChanged() { |
277 // Nothing to do. | 277 // Nothing to do. |
278 } | 278 } |
279 | 279 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 // Setting the link widget to secondary positions the button on the left side | 368 // Setting the link widget to secondary positions the button on the left side |
369 // of the action area (vice versa for RTL layout). | 369 // of the action area (vice versa for RTL layout). |
370 gtk_button_box_set_child_secondary( | 370 gtk_button_box_set_child_secondary( |
371 GTK_BUTTON_BOX(GTK_DIALOG(dialog_)->action_area), link, TRUE); | 371 GTK_BUTTON_BOX(GTK_DIALOG(dialog_)->action_area), link, TRUE); |
372 | 372 |
373 ConnectAccelerators(); | 373 ConnectAccelerators(); |
374 | 374 |
375 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), | 375 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), |
376 gtk_util::kContentAreaSpacing); | 376 gtk_util::kContentAreaSpacing); |
377 | 377 |
| 378 destroy_handler_id_ = g_signal_connect(G_OBJECT(dialog_), "destroy", |
| 379 G_CALLBACK(OnDestroy), this); |
378 g_signal_connect(G_OBJECT(dialog_), "response", G_CALLBACK(OnResponse), this); | 380 g_signal_connect(G_OBJECT(dialog_), "response", G_CALLBACK(OnResponse), this); |
379 g_signal_connect(G_OBJECT(dialog_), "button-release-event", | 381 g_signal_connect(G_OBJECT(dialog_), "button-release-event", |
380 G_CALLBACK(OnButtonReleaseEvent), this); | 382 G_CALLBACK(OnButtonReleaseEvent), this); |
381 gtk_widget_add_events(dialog_, | 383 gtk_widget_add_events(dialog_, |
382 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); | 384 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); |
383 | 385 |
384 // Wrap the treeview widget in a scrolled window in order to have a frame. | 386 // Wrap the treeview widget in a scrolled window in order to have a frame. |
385 GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL); | 387 GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL); |
386 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), | 388 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), |
387 GTK_SHADOW_ETCHED_IN); | 389 GTK_SHADOW_ETCHED_IN); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 } | 667 } |
666 | 668 |
667 gint TaskManagerGtk::CompareImpl(GtkTreeModel* model, GtkTreeIter* a, | 669 gint TaskManagerGtk::CompareImpl(GtkTreeModel* model, GtkTreeIter* a, |
668 GtkTreeIter* b, int id) { | 670 GtkTreeIter* b, int id) { |
669 int row1 = gtk_tree::GetRowNumForIter(model, a); | 671 int row1 = gtk_tree::GetRowNumForIter(model, a); |
670 int row2 = gtk_tree::GetRowNumForIter(model, b); | 672 int row2 = gtk_tree::GetRowNumForIter(model, b); |
671 return model_->CompareValues(row1, row2, id); | 673 return model_->CompareValues(row1, row2, id); |
672 } | 674 } |
673 | 675 |
674 // static | 676 // static |
| 677 void TaskManagerGtk::OnDestroy(GtkDialog* dialog, |
| 678 TaskManagerGtk* task_manager) { |
| 679 instance_ = NULL; |
| 680 delete task_manager; |
| 681 } |
| 682 |
| 683 // static |
675 void TaskManagerGtk::OnResponse(GtkDialog* dialog, gint response_id, | 684 void TaskManagerGtk::OnResponse(GtkDialog* dialog, gint response_id, |
676 TaskManagerGtk* task_manager) { | 685 TaskManagerGtk* task_manager) { |
677 if (response_id == GTK_RESPONSE_DELETE_EVENT) { | 686 if (response_id == GTK_RESPONSE_DELETE_EVENT) { |
678 // Store the dialog's size so we can restore it the next time it's opened. | 687 // Store the dialog's size so we can restore it the next time it's opened. |
679 if (g_browser_process->local_state()) { | 688 if (g_browser_process->local_state()) { |
680 gint x = 0, y = 0, width = 1, height = 1; | 689 gint x = 0, y = 0, width = 1, height = 1; |
681 gtk_window_get_position(GTK_WINDOW(dialog), &x, &y); | 690 gtk_window_get_position(GTK_WINDOW(dialog), &x, &y); |
682 gtk_window_get_size(GTK_WINDOW(dialog), &width, &height); | 691 gtk_window_get_size(GTK_WINDOW(dialog), &width, &height); |
683 | 692 |
684 DictionaryValue* placement_pref = | 693 DictionaryValue* placement_pref = |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 TaskManagerGtk* task_manager) { | 792 TaskManagerGtk* task_manager) { |
784 if (keyval == GDK_w && modifier == GDK_CONTROL_MASK) { | 793 if (keyval == GDK_w && modifier == GDK_CONTROL_MASK) { |
785 // The GTK_RESPONSE_DELETE_EVENT response must be sent before the widget | 794 // The GTK_RESPONSE_DELETE_EVENT response must be sent before the widget |
786 // is destroyed. The deleted object will receive gtk signals otherwise. | 795 // is destroyed. The deleted object will receive gtk signals otherwise. |
787 gtk_dialog_response(GTK_DIALOG(task_manager->dialog_), | 796 gtk_dialog_response(GTK_DIALOG(task_manager->dialog_), |
788 GTK_RESPONSE_DELETE_EVENT); | 797 GTK_RESPONSE_DELETE_EVENT); |
789 } | 798 } |
790 | 799 |
791 return TRUE; | 800 return TRUE; |
792 } | 801 } |
OLD | NEW |