summaryrefslogtreecommitdiffstats
path: root/views/controls
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-31 02:36:23 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-31 02:36:23 +0000
commite80daf62322d8494212abacd6c810eddef59b2be (patch)
tree6d338dab3602fe38d94a98d690948e9ce2e92ecc /views/controls
parent6e9b3df82a13faebedf10cfca50392f8d909d71b (diff)
downloadchromium_src-e80daf62322d8494212abacd6c810eddef59b2be.zip
chromium_src-e80daf62322d8494212abacd6c810eddef59b2be.tar.gz
chromium_src-e80daf62322d8494212abacd6c810eddef59b2be.tar.bz2
Split out the views table functions into separate header files. Many users only
need either the view or model observers and that's it. I moved the model constructors to a .cc file so we don't have to include l10n_util.h for everybody. A surprising number of files were getting l10n_util from the table code, so I had to add it in a bunch of places. There should be no code change except I made the table column cosntructors take wstring references instead of copies. Review URL: http://codereview.chromium.org/115969 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17295 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r--views/controls/button/native_button.h2
-rw-r--r--views/controls/button/native_button_wrapper.h3
-rw-r--r--views/controls/button/text_button.h6
-rw-r--r--views/controls/table/group_table_view.h1
-rw-r--r--views/controls/table/table_model.cc68
-rw-r--r--views/controls/table/table_model.h154
-rw-r--r--views/controls/table/table_model_observer.h29
-rw-r--r--views/controls/table/table_view.cc2
-rw-r--r--views/controls/table/table_view.h214
-rw-r--r--views/controls/table/table_view_observer.h35
-rw-r--r--views/controls/table/table_view_unittest.cc1
11 files changed, 298 insertions, 217 deletions
diff --git a/views/controls/button/native_button.h b/views/controls/button/native_button.h
index 50aaff73..3b77d5f 100644
--- a/views/controls/button/native_button.h
+++ b/views/controls/button/native_button.h
@@ -99,4 +99,4 @@ class NativeButton : public Button {
} // namespace views
-#endif // #ifndef VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_H_
+#endif // VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_H_
diff --git a/views/controls/button/native_button_wrapper.h b/views/controls/button/native_button_wrapper.h
index 4ae939c..07739af 100644
--- a/views/controls/button/native_button_wrapper.h
+++ b/views/controls/button/native_button_wrapper.h
@@ -53,9 +53,8 @@ class NativeButtonWrapper {
static NativeButtonWrapper* CreateCheckboxWrapper(Checkbox* checkbox);
static NativeButtonWrapper* CreateRadioButtonWrapper(
RadioButton* radio_button);
-
};
} // namespace views
-#endif // #ifndef VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_WRAPPER_H_
+#endif // VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_WRAPPER_H_
diff --git a/views/controls/button/text_button.h b/views/controls/button/text_button.h
index 8b3d343..1a8134e 100644
--- a/views/controls/button/text_button.h
+++ b/views/controls/button/text_button.h
@@ -32,8 +32,6 @@ class TextButtonBorder : public Border {
virtual void GetInsets(gfx::Insets* insets) const;
private:
- DISALLOW_EVIL_CONSTRUCTORS(TextButtonBorder);
-
// Images
struct MBBImageSet {
SkBitmap* top_left;
@@ -48,6 +46,8 @@ class TextButtonBorder : public Border {
};
MBBImageSet hot_set_;
MBBImageSet pushed_set_;
+
+ DISALLOW_COPY_AND_ASSIGN(TextButtonBorder);
};
@@ -130,7 +130,7 @@ class TextButton : public CustomButton {
// indicates the width is not constrained.
int max_width_;
- DISALLOW_EVIL_CONSTRUCTORS(TextButton);
+ DISALLOW_COPY_AND_ASSIGN(TextButton);
};
} // namespace views
diff --git a/views/controls/table/group_table_view.h b/views/controls/table/group_table_view.h
index e581d5d..c92587f 100644
--- a/views/controls/table/group_table_view.h
+++ b/views/controls/table/group_table_view.h
@@ -6,6 +6,7 @@
#define VIEWS_CONTROLS_TABLE_GROUP_TABLE_VIEW_H_
#include "base/task.h"
+#include "views/controls/table/table_model.h"
#include "views/controls/table/table_view.h"
// The GroupTableView adds grouping to the TableView class.
diff --git a/views/controls/table/table_model.cc b/views/controls/table/table_model.cc
new file mode 100644
index 0000000..7e1dd0e
--- /dev/null
+++ b/views/controls/table/table_model.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "views/controls/table/table_model.h"
+
+#include "app/l10n_util.h"
+
+namespace views {
+
+TableColumn::TableColumn()
+ : id(0),
+ title(),
+ alignment(LEFT),
+ width(-1),
+ percent(),
+ min_visible_width(0),
+ sortable(false) {
+}
+
+TableColumn::TableColumn(int id, const std::wstring& title,
+ Alignment alignment,
+ int width)
+ : id(id),
+ title(title),
+ alignment(alignment),
+ width(width),
+ percent(0),
+ min_visible_width(0),
+ sortable(false) {
+}
+
+TableColumn::TableColumn(int id, const std::wstring& title,
+ Alignment alignment, int width, float percent)
+ : id(id),
+ title(title),
+ alignment(alignment),
+ width(width),
+ percent(percent),
+ min_visible_width(0),
+ sortable(false) {
+}
+
+// It's common (but not required) to use the title's IDS_* tag as the column
+// id. In this case, the provided conveniences look up the title string on
+// bahalf of the caller.
+TableColumn::TableColumn(int id, Alignment alignment, int width)
+ : id(id),
+ alignment(alignment),
+ width(width),
+ percent(0),
+ min_visible_width(0),
+ sortable(false) {
+ title = l10n_util::GetString(id);
+}
+
+TableColumn::TableColumn(int id, Alignment alignment, int width, float percent)
+ : id(id),
+ alignment(alignment),
+ width(width),
+ percent(percent),
+ min_visible_width(0),
+ sortable(false) {
+ title = l10n_util::GetString(id);
+}
+
+} // namespace views
+
diff --git a/views/controls/table/table_model.h b/views/controls/table/table_model.h
new file mode 100644
index 0000000..5c377c7
--- /dev/null
+++ b/views/controls/table/table_model.h
@@ -0,0 +1,154 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_
+#define VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_
+
+#include <string>
+#include <vector>
+
+#include "base/logging.h"
+#include "unicode/coll.h"
+
+class SkBitmap;
+
+namespace views {
+
+class TableModelObserver;
+
+// The model driving the TableView.
+class TableModel {
+ public:
+ // See HasGroups, get GetGroupID for details as to how this is used.
+ struct Group {
+ // The title text for the group.
+ std::wstring title;
+
+ // Unique id for the group.
+ int id;
+ };
+ typedef std::vector<Group> Groups;
+
+ // Number of rows in the model.
+ virtual int RowCount() = 0;
+
+ // Returns the value at a particular location in text.
+ virtual std::wstring GetText(int row, int column_id) = 0;
+
+ // Returns the small icon (16x16) that should be displayed in the first
+ // column before the text. This is only used when the TableView was created
+ // with the ICON_AND_TEXT table type. Returns an isNull() bitmap if there is
+ // no bitmap.
+ virtual SkBitmap GetIcon(int row);
+
+ // Sets whether a particular row is checked. This is only invoked
+ // if the TableView was created with show_check_in_first_column true.
+ virtual void SetChecked(int row, bool is_checked) {
+ NOTREACHED();
+ }
+
+ // Returns whether a particular row is checked. This is only invoked
+ // if the TableView was created with show_check_in_first_column true.
+ virtual bool IsChecked(int row) {
+ return false;
+ }
+
+ // Returns true if the TableView has groups. Groups provide a way to visually
+ // delineate the rows in a table view. When groups are enabled table view
+ // shows a visual separator for each group, followed by all the rows in
+ // the group.
+ //
+ // On win2k a visual separator is not rendered for the group headers.
+ virtual bool HasGroups() { return false; }
+
+ // Returns the groups.
+ // This is only used if HasGroups returns true.
+ virtual Groups GetGroups() {
+ // If you override HasGroups to return true, you must override this as
+ // well.
+ NOTREACHED();
+ return std::vector<Group>();
+ }
+
+ // Returns the group id of the specified row.
+ // This is only used if HasGroups returns true.
+ virtual int GetGroupID(int row) {
+ // If you override HasGroups to return true, you must override this as
+ // well.
+ NOTREACHED();
+ return 0;
+ }
+
+ // Sets the observer for the model. The TableView should NOT take ownership
+ // of the observer.
+ virtual void SetObserver(TableModelObserver* observer) = 0;
+
+ // Compares the values in the column with id |column_id| for the two rows.
+ // Returns a value < 0, == 0 or > 0 as to whether the first value is
+ // <, == or > the second value.
+ //
+ // This implementation does a case insensitive locale specific string
+ // comparison.
+ virtual int CompareValues(int row1, int row2, int column_id);
+
+ protected:
+ // Returns the collator used by CompareValues.
+ Collator* GetCollator();
+};
+
+// TableColumn specifies the title, alignment and size of a particular column.
+struct TableColumn {
+ enum Alignment {
+ LEFT, RIGHT, CENTER
+ };
+
+ TableColumn();
+ TableColumn(int id, const std::wstring& title,
+ Alignment alignment, int width);
+ TableColumn(int id, const std::wstring& title,
+ Alignment alignment, int width, float percent);
+
+ // It's common (but not required) to use the title's IDS_* tag as the column
+ // id. In this case, the provided conveniences look up the title string on
+ // bahalf of the caller.
+ TableColumn(int id, Alignment alignment, int width);
+ TableColumn(int id, Alignment alignment, int width, float percent);
+
+ // A unique identifier for the column.
+ int id;
+
+ // The title for the column.
+ std::wstring title;
+
+ // Alignment for the content.
+ Alignment alignment;
+
+ // The size of a column may be specified in two ways:
+ // 1. A fixed width. Set the width field to a positive number and the
+ // column will be given that width, in pixels.
+ // 2. As a percentage of the available width. If width is -1, and percent is
+ // > 0, the column is given a width of
+ // available_width * percent / total_percent.
+ // 3. If the width == -1 and percent == 0, the column is autosized based on
+ // the width of the column header text.
+ //
+ // Sizing is done in four passes. Fixed width columns are given
+ // their width, percentages are applied, autosized columns are autosized,
+ // and finally percentages are applied again taking into account the widths
+ // of autosized columns.
+ int width;
+ float percent;
+
+ // The minimum width required for all items in this column
+ // (including the header)
+ // to be visible.
+ int min_visible_width;
+
+ // Is this column sortable? Default is false
+ bool sortable;
+};
+
+} // namespace views
+
+#endif // VIEWS_CONTROLS_TABLE_TABLE_MODEL_H_
diff --git a/views/controls/table/table_model_observer.h b/views/controls/table/table_model_observer.h
new file mode 100644
index 0000000..b968a9f
--- /dev/null
+++ b/views/controls/table/table_model_observer.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef VIEWS_CONTROL_TABLE_TABLE_MODEL_OBSERVER_H_
+#define VIEWS_CONTROL_TABLE_TABLE_MODEL_OBSERVER_H_
+
+namespace views {
+
+// Observer for a TableModel. Anytime the model changes, it must notify its
+// observer.
+class TableModelObserver {
+ public:
+ // Invoked when the model has been completely changed.
+ virtual void OnModelChanged() = 0;
+
+ // Invoked when a range of items has changed.
+ virtual void OnItemsChanged(int start, int length) = 0;
+
+ // Invoked when new items are added.
+ virtual void OnItemsAdded(int start, int length) = 0;
+
+ // Invoked when a range of items has been removed.
+ virtual void OnItemsRemoved(int start, int length) = 0;
+};
+
+} // namespace views
+
+#endif // VIEWS_CONTROL_TABLE_TABLE_MODEL_OBSERVER_H_
diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc
index d114b2d6..4e095cf 100644
--- a/views/controls/table/table_view.cc
+++ b/views/controls/table/table_view.cc
@@ -22,6 +22,8 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "views/controls/native/native_view_host.h"
+#include "views/controls/table/table_model.h"
+#include "views/controls/table/table_view_observer.h"
namespace views {
diff --git a/views/controls/table/table_view.h b/views/controls/table/table_view.h
index c1a9a23..94198f8 100644
--- a/views/controls/table/table_view.h
+++ b/views/controls/table/table_view.h
@@ -13,17 +13,14 @@ typedef struct tagNMLVCUSTOMDRAW NMLVCUSTOMDRAW;
#endif // defined(OS_WIN)
#include <map>
-#include <unicode/coll.h>
-#include <unicode/uchar.h>
#include <vector>
-#include "app/l10n_util.h"
-#include "base/logging.h"
#include "third_party/skia/include/core/SkColor.h"
#if defined(OS_WIN)
// TODO(port): remove the ifdef when native_control.h is ported.
#include "views/controls/native_control.h"
#endif // defined(OS_WIN)
+#include "views/controls/table/table_model_observer.h"
class SkBitmap;
@@ -55,6 +52,8 @@ class ListView;
class ListViewParent;
class TableView;
struct TableColumn;
+class TableModel;
+class TableViewObserver;
// The cells in the first column of a table can contain:
// - only text
@@ -66,192 +65,6 @@ enum TableTypes {
CHECK_BOX_AND_TEXT
};
-// Any time the TableModel changes, it must notify its observer.
-class TableModelObserver {
- public:
- // Invoked when the model has been completely changed.
- virtual void OnModelChanged() = 0;
-
- // Invoked when a range of items has changed.
- virtual void OnItemsChanged(int start, int length) = 0;
-
- // Invoked when new items are added.
- virtual void OnItemsAdded(int start, int length) = 0;
-
- // Invoked when a range of items has been removed.
- virtual void OnItemsRemoved(int start, int length) = 0;
-};
-
-// The model driving the TableView.
-class TableModel {
- public:
- // See HasGroups, get GetGroupID for details as to how this is used.
- struct Group {
- // The title text for the group.
- std::wstring title;
-
- // Unique id for the group.
- int id;
- };
- typedef std::vector<Group> Groups;
-
- // Number of rows in the model.
- virtual int RowCount() = 0;
-
- // Returns the value at a particular location in text.
- virtual std::wstring GetText(int row, int column_id) = 0;
-
- // Returns the small icon (16x16) that should be displayed in the first
- // column before the text. This is only used when the TableView was created
- // with the ICON_AND_TEXT table type. Returns an isNull() bitmap if there is
- // no bitmap.
- virtual SkBitmap GetIcon(int row);
-
- // Sets whether a particular row is checked. This is only invoked
- // if the TableView was created with show_check_in_first_column true.
- virtual void SetChecked(int row, bool is_checked) {
- NOTREACHED();
- }
-
- // Returns whether a particular row is checked. This is only invoked
- // if the TableView was created with show_check_in_first_column true.
- virtual bool IsChecked(int row) {
- return false;
- }
-
- // Returns true if the TableView has groups. Groups provide a way to visually
- // delineate the rows in a table view. When groups are enabled table view
- // shows a visual separator for each group, followed by all the rows in
- // the group.
- //
- // On win2k a visual separator is not rendered for the group headers.
- virtual bool HasGroups() { return false; }
-
- // Returns the groups.
- // This is only used if HasGroups returns true.
- virtual Groups GetGroups() {
- // If you override HasGroups to return true, you must override this as
- // well.
- NOTREACHED();
- return std::vector<Group>();
- }
-
- // Returns the group id of the specified row.
- // This is only used if HasGroups returns true.
- virtual int GetGroupID(int row) {
- // If you override HasGroups to return true, you must override this as
- // well.
- NOTREACHED();
- return 0;
- }
-
- // Sets the observer for the model. The TableView should NOT take ownership
- // of the observer.
- virtual void SetObserver(TableModelObserver* observer) = 0;
-
- // Compares the values in the column with id |column_id| for the two rows.
- // Returns a value < 0, == 0 or > 0 as to whether the first value is
- // <, == or > the second value.
- //
- // This implementation does a case insensitive locale specific string
- // comparison.
- virtual int CompareValues(int row1, int row2, int column_id);
-
- protected:
- // Returns the collator used by CompareValues.
- Collator* GetCollator();
-};
-
-// TableColumn specifies the title, alignment and size of a particular column.
-struct TableColumn {
- enum Alignment {
- LEFT, RIGHT, CENTER
- };
-
- TableColumn()
- : id(0),
- title(),
- alignment(LEFT),
- width(-1),
- percent(),
- min_visible_width(0),
- sortable(false) {
- }
- TableColumn(int id, const std::wstring title, Alignment alignment, int width)
- : id(id),
- title(title),
- alignment(alignment),
- width(width),
- percent(0),
- min_visible_width(0),
- sortable(false) {
- }
- TableColumn(int id, const std::wstring title, Alignment alignment, int width,
- float percent)
- : id(id),
- title(title),
- alignment(alignment),
- width(width),
- percent(percent),
- min_visible_width(0),
- sortable(false) {
- }
- // It's common (but not required) to use the title's IDS_* tag as the column
- // id. In this case, the provided conveniences look up the title string on
- // bahalf of the caller.
- TableColumn(int id, Alignment alignment, int width)
- : id(id),
- alignment(alignment),
- width(width),
- percent(0),
- min_visible_width(0),
- sortable(false) {
- title = l10n_util::GetString(id);
- }
- TableColumn(int id, Alignment alignment, int width, float percent)
- : id(id),
- alignment(alignment),
- width(width),
- percent(percent),
- min_visible_width(0),
- sortable(false) {
- title = l10n_util::GetString(id);
- }
-
- // A unique identifier for the column.
- int id;
-
- // The title for the column.
- std::wstring title;
-
- // Alignment for the content.
- Alignment alignment;
-
- // The size of a column may be specified in two ways:
- // 1. A fixed width. Set the width field to a positive number and the
- // column will be given that width, in pixels.
- // 2. As a percentage of the available width. If width is -1, and percent is
- // > 0, the column is given a width of
- // available_width * percent / total_percent.
- // 3. If the width == -1 and percent == 0, the column is autosized based on
- // the width of the column header text.
- //
- // Sizing is done in four passes. Fixed width columns are given
- // their width, percentages are applied, autosized columns are autosized,
- // and finally percentages are applied again taking into account the widths
- // of autosized columns.
- int width;
- float percent;
-
- // The minimum width required for all items in this column
- // (including the header)
- // to be visible.
- int min_visible_width;
-
- // Is this column sortable? Default is false
- bool sortable;
-};
-
// Returned from SelectionBegin/SelectionEnd
class TableSelectionIterator {
public:
@@ -273,27 +86,6 @@ class TableSelectionIterator {
int model_index_;
};
-// TableViewObserver is notified about the TableView selection.
-class TableViewObserver {
- public:
- virtual ~TableViewObserver() {}
-
- // Invoked when the selection changes.
- virtual void OnSelectionChanged() = 0;
-
- // Optional method invoked when the user double clicks on the table.
- virtual void OnDoubleClick() {}
-
- // Optional method invoked when the user middle clicks on the table.
- virtual void OnMiddleClick() {}
-
- // Optional method invoked when the user hits a key with the table in focus.
- virtual void OnKeyDown(unsigned short virtual_keycode) {}
-
- // Invoked when the user presses the delete key.
- virtual void OnTableViewDelete(TableView* table_view) {}
-};
-
#if defined(OS_WIN)
// TODO(port): Port TableView.
class TableView : public NativeControl,
diff --git a/views/controls/table/table_view_observer.h b/views/controls/table/table_view_observer.h
new file mode 100644
index 0000000..c88cb21
--- /dev/null
+++ b/views/controls/table/table_view_observer.h
@@ -0,0 +1,35 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef VIEWS_CONTROLS_TABLE_TABLE_VIEW_OBSERVER_H_
+#define VIEWS_CONTROLS_TABLE_TABLE_VIEW_OBSERVER_H_
+
+namespace views {
+
+class TableView;
+
+// TableViewObserver is notified about the TableView selection.
+class TableViewObserver {
+ public:
+ virtual ~TableViewObserver() {}
+
+ // Invoked when the selection changes.
+ virtual void OnSelectionChanged() = 0;
+
+ // Optional method invoked when the user double clicks on the table.
+ virtual void OnDoubleClick() {}
+
+ // Optional method invoked when the user middle clicks on the table.
+ virtual void OnMiddleClick() {}
+
+ // Optional method invoked when the user hits a key with the table in focus.
+ virtual void OnKeyDown(unsigned short virtual_keycode) {}
+
+ // Invoked when the user presses the delete key.
+ virtual void OnTableViewDelete(TableView* table_view) {}
+};
+
+} // namespace views
+
+#endif // VIEWS_CONTROLS_TABLE_TABLE_VIEW_OBSERVER_H_
diff --git a/views/controls/table/table_view_unittest.cc b/views/controls/table/table_view_unittest.cc
index e0f08e2..c3d0a75 100644
--- a/views/controls/table/table_view_unittest.cc
+++ b/views/controls/table/table_view_unittest.cc
@@ -7,6 +7,7 @@
#include "base/message_loop.h"
#include "base/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "views/controls/table/table_model.h"
#include "views/controls/table/table_view.h"
#include "views/window/window_delegate.h"
#include "views/window/window_win.h"