OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_BROWSER_SHELL_DIALOGS_H_ | 5 #ifndef CHROME_BROWSER_SHELL_DIALOGS_H_ |
6 #define CHROME_BROWSER_SHELL_DIALOGS_H_ | 6 #define CHROME_BROWSER_SHELL_DIALOGS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/gfx/native_widget_types.h" | 12 #include "base/gfx/native_widget_types.h" |
13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 | 15 |
16 class ChromeFont; | 16 class ChromeFont; |
17 | 17 |
18 // Helpers to show certain types of Windows shell dialogs in a way that doesn't | |
19 // block the UI of the entire app. | |
20 | |
21 // A base class for shell dialogs. | 18 // A base class for shell dialogs. |
22 class BaseShellDialog { | 19 class BaseShellDialog { |
23 public: | 20 public: |
24 // Returns true if the a shell dialog box is currently being shown modally | 21 // Returns true if the a shell dialog box is currently being shown modally |
25 // to the specified owner. | 22 // to the specified owner. |
26 virtual bool IsRunning(gfx::NativeWindow owning_window) const = 0; | 23 virtual bool IsRunning(gfx::NativeWindow owning_window) const = 0; |
27 | 24 |
28 // Notifies the dialog box that the listener has been destroyed and it should | 25 // Notifies the dialog box that the listener has been destroyed and it should |
29 // no longer be sent notifications. | 26 // no longer be sent notifications. |
30 virtual void ListenerDestroyed() = 0; | 27 virtual void ListenerDestroyed() = 0; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // Notifies the Listener that the file/folder selection was aborted (via | 61 // Notifies the Listener that the file/folder selection was aborted (via |
65 // the user canceling or closing the selection dialog box, for example). | 62 // the user canceling or closing the selection dialog box, for example). |
66 // |params| is contextual passed to SelectFile. | 63 // |params| is contextual passed to SelectFile. |
67 virtual void FileSelectionCanceled(void* params) {}; | 64 virtual void FileSelectionCanceled(void* params) {}; |
68 }; | 65 }; |
69 | 66 |
70 // Creates a dialog box helper. This object is ref-counted, but the returned | 67 // Creates a dialog box helper. This object is ref-counted, but the returned |
71 // object will have no reference (refcount is 0). | 68 // object will have no reference (refcount is 0). |
72 static SelectFileDialog* Create(Listener* listener); | 69 static SelectFileDialog* Create(Listener* listener); |
73 | 70 |
| 71 // Holds information about allowed extensions on a file save dialog. |
| 72 // |extensions| is a list of allowed extensions. For example, it might be |
| 73 // { { "htm", "html" }, { "txt" } }. Only pass more than one extension |
| 74 // in the inner vector if the extensions are equivalent. Do NOT include |
| 75 // leading periods. |
| 76 // |extension_description_overrides| overrides the system descriptions of the |
| 77 // specified extensions. Entries correspond to |extensions|; if left blank |
| 78 // the system descriptions will be used. |
| 79 // |include_all_files| specifies whether all files (e.g. *.*) will be allowed |
| 80 // in the file filtering. |
| 81 struct FileTypeInfo { |
| 82 std::vector<std::vector<FilePath::StringType> > extensions; |
| 83 std::vector<string16> extension_description_overrides; |
| 84 bool include_all_files; |
| 85 }; |
| 86 |
74 // Selects a file. This will start displaying the dialog box. This will also | 87 // Selects a file. This will start displaying the dialog box. This will also |
75 // block the calling window until the dialog box is complete. The listener | 88 // block the calling window until the dialog box is complete. The listener |
76 // associated with this object will be notified when the selection is | 89 // associated with this object will be notified when the selection is |
77 // complete. | 90 // complete. |
78 // |type| is the type of file dialog to be shown, see Type enumeration above. | 91 // |type| is the type of file dialog to be shown, see Type enumeration above. |
79 // |title| is the title to be displayed in the dialog. If this string is | 92 // |title| is the title to be displayed in the dialog. If this string is |
80 // empty, the default title is used. | 93 // empty, the default title is used. |
81 // |default_path| is the default path and suggested file name to be shown in | 94 // |default_path| is the default path and suggested file name to be shown in |
82 // the dialog. This only works for SELECT_SAVEAS_FILE and SELECT_OPEN_FILE. | 95 // the dialog. This only works for SELECT_SAVEAS_FILE and SELECT_OPEN_FILE. |
83 // Can be an empty string to indicate Windows should choose the default to | 96 // Can be an empty string to indicate the platform default. |
84 // show. | 97 // |file_types| holds the infomation about the file types allowed. Pass NULL |
85 // |filter| is a null (\0) separated list of alternating filter description | 98 // to get no special behavior |
86 // and filters and terminated with two nulls. | 99 // |file_type_index| is the 1-based index into the file type list in |
87 // |filter_index| is the 1-based index into the filter list in |filter|. | 100 // |file_types|. Specify 0 if you don't need to specify extension behavior. |
88 // Specify 0 if you don't need filters, or if you only need the default | 101 // |default_extension| is the default extension to add to the file if the |
89 // (first filter) behavior. | 102 // user doesn't type one. This should NOT include the '.'. On Windows, if |
| 103 // you specify this you must also specify |file_types|. |
90 // |owning_window| is the window the dialog is modal to, or NULL for a | 104 // |owning_window| is the window the dialog is modal to, or NULL for a |
91 // modeless dialog. | 105 // modeless dialog. |
92 // |default_extension| is the default extension to add to the file if the | |
93 // user doesn't type one. This should NOT include the '.'. If you specify | |
94 // this you must also specify a filter. | |
95 // |params| is data from the calling context which will be passed through to | 106 // |params| is data from the calling context which will be passed through to |
96 // the listener. Can be NULL. | 107 // the listener. Can be NULL. |
97 // NOTE: only one instance of any shell dialog can be shown per owning_window | 108 // NOTE: only one instance of any shell dialog can be shown per owning_window |
98 // at a time (for obvious reasons). | 109 // at a time (for obvious reasons). |
99 virtual void SelectFile(Type type, | 110 virtual void SelectFile(Type type, |
100 const string16& title, | 111 const string16& title, |
101 const FilePath& default_path, | 112 const FilePath& default_path, |
102 const std::wstring& filter, | 113 const FileTypeInfo* file_types, |
103 int filter_index, | 114 int file_type_index, |
104 const FilePath::StringType& default_extension, | 115 const FilePath::StringType& default_extension, |
105 gfx::NativeWindow owning_window, | 116 gfx::NativeWindow owning_window, |
106 void* params) = 0; | 117 void* params) = 0; |
107 }; | 118 }; |
108 | 119 |
109 // Shows a dialog box for selecting a font. | 120 // Shows a dialog box for selecting a font. |
110 class SelectFontDialog | 121 class SelectFontDialog |
111 : public base::RefCountedThreadSafe<SelectFileDialog>, | 122 : public base::RefCountedThreadSafe<SelectFileDialog>, |
112 public BaseShellDialog { | 123 public BaseShellDialog { |
113 public: | 124 public: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 161 |
151 // Same as above - also support specifying the default font selected in the | 162 // Same as above - also support specifying the default font selected in the |
152 // list when the dialog appears. | 163 // list when the dialog appears. |
153 virtual void SelectFont(gfx::NativeWindow owning_window, | 164 virtual void SelectFont(gfx::NativeWindow owning_window, |
154 void* params, | 165 void* params, |
155 const std::wstring& font_name, | 166 const std::wstring& font_name, |
156 int font_size) = 0; | 167 int font_size) = 0; |
157 }; | 168 }; |
158 | 169 |
159 #endif // CHROME_BROWSER_SHELL_DIALOGS_H_ | 170 #endif // CHROME_BROWSER_SHELL_DIALOGS_H_ |
OLD | NEW |