1 // Copyright (c) 2010 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.
5 #ifndef APP_OS_EXCHANGE_DATA_PROVIDER_GTK_H_
6 #define APP_OS_EXCHANGE_DATA_PROVIDER_GTK_H_
14 #include "app/os_exchange_data.h"
15 #include "base/pickle.h"
16 #include "base/string16.h"
17 #include "gfx/point.h"
18 #include "googleurl/src/gurl.h"
20 // OSExchangeData::Provider implementation for Gtk. OSExchangeDataProviderGtk
21 // is created with a set of known data types. In addition specific data
22 // types can be set on OSExchangeDataProviderGtk by way of the various setters.
23 // The various has methods return true if the format was supplied to the
24 // constructor, or explicitly set.
25 class OSExchangeDataProviderGtk
: public OSExchangeData::Provider
{
27 OSExchangeDataProviderGtk(int known_formats
,
28 const std::set
<GdkAtom
>& known_custom_formats_
);
29 OSExchangeDataProviderGtk();
31 virtual ~OSExchangeDataProviderGtk();
33 int known_formats() const { return known_formats_
; }
34 const std::set
<GdkAtom
>& known_custom_formats() const {
35 return known_custom_formats_
;
38 // Returns true if all the formats and custom formats identified by |formats|
39 // and |custom_formats| have been set in this provider.
41 // NOTE: this is NOT the same as whether a format may be provided (as is
42 // returned by the various HasXXX methods), but rather if the data for the
43 // formats has been set on this provider by way of the various Setter
45 bool HasDataForAllFormats(int formats
,
46 const std::set
<GdkAtom
>& custom_formats
) const;
48 // Returns the set of formats available as a GtkTargetList. It is up to the
49 // caller to free (gtk_target_list_unref) the returned list.
50 GtkTargetList
* GetTargetList() const;
52 // Writes the data to |selection|. |format| is any combination of
53 // OSExchangeData::Formats.
54 void WriteFormatToSelection(int format
,
55 GtkSelectionData
* selection
) const;
58 virtual void SetString(const std::wstring
& data
);
59 virtual void SetURL(const GURL
& url
, const std::wstring
& title
);
60 virtual void SetFilename(const std::wstring
& full_path
);
61 virtual void SetPickledData(OSExchangeData::CustomFormat format
,
63 virtual bool GetString(std::wstring
* data
) const;
64 virtual bool GetURLAndTitle(GURL
* url
, std::wstring
* title
) const;
65 virtual bool GetFilename(std::wstring
* full_path
) const;
66 virtual bool GetPickledData(OSExchangeData::CustomFormat format
,
68 virtual bool HasString() const;
69 virtual bool HasURL() const;
70 virtual bool HasFile() const;
71 virtual bool HasCustomFormat(OSExchangeData::CustomFormat format
) const;
73 // Set the image and cursor offset data for this drag. Will
74 // increment the ref count of pixbuf.
75 void SetDragImage(GdkPixbuf
* pixbuf
, const gfx::Point
& cursor_offset
);
76 GdkPixbuf
* drag_image() const { return drag_image_
; }
77 gfx::Point
cursor_offset() const { return cursor_offset_
; }
80 typedef std::map
<OSExchangeData::CustomFormat
, Pickle
> PickleData
;
82 // Returns true if |formats_| contains a string format and the string can be
84 bool GetPlainTextURL(GURL
* url
) const;
86 // These are the possible formats the OSExchangeData may contain. Don't
87 // confuse this with the actual formats that have been set, which are
88 // |formats_| and |custom_formats_|.
89 const int known_formats_
;
90 const std::set
<GdkAtom
> known_custom_formats_
;
92 // Actual formats that have been set. See comment above |known_formats_|
104 std::string filename_
;
106 // PICKLED_DATA contents.
107 PickleData pickle_data_
;
109 // Drag image and offset data.
110 GdkPixbuf
* drag_image_
;
111 gfx::Point cursor_offset_
;
113 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderGtk
);
116 #endif // APP_OS_EXCHANGE_DATA_PROVIDER_GTK_H_