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 // This class assists you in dealing with a specific situation when managing | 5 // This class assists you in dealing with a specific situation when managing |
6 // ownership between a C++ object and a GTK widget. It is common to have a | 6 // ownership between a C++ object and a GTK widget. It is common to have a |
7 // C++ object which encapsulates a GtkWidget, and that widget is exposed from | 7 // C++ object which encapsulates a GtkWidget, and that widget is exposed from |
8 // the object for use outside of the class. In this situation, you commonly | 8 // the object for use outside of the class. In this situation, you commonly |
9 // want the GtkWidget's lifetime to match its C++ object's lifetime. Using an | 9 // want the GtkWidget's lifetime to match its C++ object's lifetime. Using an |
10 // OwnedWigetGtk will take ownership over the initial reference of the | 10 // OwnedWigetGtk will take ownership over the initial reference of the |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // GtkWidget* widget = gtk_widget_new(); | 43 // GtkWidget* widget = gtk_widget_new(); |
44 // g_object_ref_sink(widget); // Claim the initial floating reference. | 44 // g_object_ref_sink(widget); // Claim the initial floating reference. |
45 // ... | 45 // ... |
46 // gtk_destroy_widget(widget); // Ask all code to destroy their references. | 46 // gtk_destroy_widget(widget); // Ask all code to destroy their references. |
47 // g_object_unref(widget); // Destroy the initial reference we had claimed. | 47 // g_object_unref(widget); // Destroy the initial reference we had claimed. |
48 | 48 |
49 #ifndef UI_BASE_GTK_OWNED_WIDGET_GTK_H_ | 49 #ifndef UI_BASE_GTK_OWNED_WIDGET_GTK_H_ |
50 #define UI_BASE_GTK_OWNED_WIDGET_GTK_H_ | 50 #define UI_BASE_GTK_OWNED_WIDGET_GTK_H_ |
51 | 51 |
52 #include "base/basictypes.h" | 52 #include "base/basictypes.h" |
53 #include "ui/base/ui_export.h" | 53 #include "ui/base/ui_base_export.h" |
54 | 54 |
55 typedef struct _GtkWidget GtkWidget; | 55 typedef struct _GtkWidget GtkWidget; |
56 | 56 |
57 namespace ui { | 57 namespace ui { |
58 | 58 |
59 class UI_EXPORT OwnedWidgetGtk { | 59 class UI_BASE_EXPORT OwnedWidgetGtk { |
60 public: | 60 public: |
61 // Create an instance that isn't managing any ownership. | 61 // Create an instance that isn't managing any ownership. |
62 OwnedWidgetGtk() : widget_(NULL) { } | 62 OwnedWidgetGtk() : widget_(NULL) { } |
63 // Create an instance that owns |widget|. | 63 // Create an instance that owns |widget|. |
64 explicit OwnedWidgetGtk(GtkWidget* widget) : widget_(NULL) { Own(widget); } | 64 explicit OwnedWidgetGtk(GtkWidget* widget) : widget_(NULL) { Own(widget); } |
65 | 65 |
66 ~OwnedWidgetGtk(); | 66 ~OwnedWidgetGtk(); |
67 | 67 |
68 // Return the currently owned widget, or NULL if no widget is owned. | 68 // Return the currently owned widget, or NULL if no widget is owned. |
69 GtkWidget* get() const { return widget_; } | 69 GtkWidget* get() const { return widget_; } |
(...skipping 16 matching lines...) Expand all Loading... |
86 | 86 |
87 private: | 87 private: |
88 GtkWidget* widget_; | 88 GtkWidget* widget_; |
89 | 89 |
90 DISALLOW_COPY_AND_ASSIGN(OwnedWidgetGtk); | 90 DISALLOW_COPY_AND_ASSIGN(OwnedWidgetGtk); |
91 }; | 91 }; |
92 | 92 |
93 } // namespace ui | 93 } // namespace ui |
94 | 94 |
95 #endif // UI_BASE_GTK_OWNED_WIDGET_GTK_H_ | 95 #endif // UI_BASE_GTK_OWNED_WIDGET_GTK_H_ |
OLD | NEW |