blob: 06dd64db39e4f12cf2460f71ace13b5dc86e2a8b [file] [log] [blame]
sky@chromium.org922da972009-11-04 14:05:48 +09001// 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
3// found in the LICENSE file.
4
5#ifndef BASE_SCOPED_HANDLE_GTK_H_
6#define BASE_SCOPED_HANDLE_GTK_H_
7
8#include <gdk/gdk.h>
9
10// Wraps a GdkRegion. This class provides the same methods as ScopedGDIObject in
11// scoped_handle_win.
12class ScopedRegion {
13 public:
14 ScopedRegion() : region_(NULL) {}
15 explicit ScopedRegion(GdkRegion* region) : region_(region) {}
16
17 ~ScopedRegion() {
18 Close();
19 }
20
21 void Set(GdkRegion* region) {
22 Close();
23
24 region_ = region;
25 }
26
27 GdkRegion* Get() {
28 return region_;
29 }
30
31 GdkRegion* release() {
32 GdkRegion* region = region_;
33 region_ = NULL;
34 return region;
35 }
36
37 private:
38 void Close() {
39 if (region_) {
40 gdk_region_destroy(region_);
41 region_ = NULL;
42 }
43 }
44
45 GdkRegion* region_;
46
47 DISALLOW_COPY_AND_ASSIGN(ScopedRegion);
48};
49
50#endif // BASE_SCOPED_HANDLE_GTK_H_