summaryrefslogtreecommitdiffstats
path: root/views/controls/table/native_table_win.h
blob: 509febd61dc990586a36e4da1622cf7db849c8b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) 2010 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_NATIVE_TABLE_WIN_H_
#define VIEWS_CONTROLS_TABLE_NATIVE_TABLE_WIN_H_

#include <windows.h>

#include "app/table_model.h"
#include "views/controls/native_control_win.h"
#include "views/controls/table/native_table_wrapper.h"

typedef struct tagNMLVCUSTOMDRAW NMLVCUSTOMDRAW;

namespace views {

class TableView2;

// A View that hosts a native Windows table.
class NativeTableWin : public NativeControlWin, public NativeTableWrapper {
 public:
  explicit NativeTableWin(TableView2* table);
  virtual ~NativeTableWin();

  // NativeTableWrapper implementation:
  virtual int GetRowCount() const;
  virtual View* GetView();
  virtual void SetFocus();
  virtual gfx::NativeView GetTestingHandle() const;
  virtual void InsertColumn(const TableColumn& column, int index);
  virtual void RemoveColumn(int index);
  virtual int GetColumnWidth(int column_index) const;
  virtual void SetColumnWidth(int column_index, int width);
  virtual int GetSelectedRowCount() const;
  virtual int GetFirstSelectedRow() const;
  virtual int GetFirstFocusedRow() const;
  virtual void ClearSelection();
  virtual void ClearRowFocus();
  virtual void SetSelectedState(int model_row, bool state);
  virtual void SetFocusState(int model_row, bool state);
  virtual bool IsRowSelected(int model_row) const;
  virtual bool IsRowFocused(int model_row) const;
  virtual void OnRowsChanged(int start, int length);
  virtual void OnRowsAdded(int start, int length);
  virtual void OnRowsRemoved(int start, int length);
  virtual gfx::Rect GetBounds() const;

  // Overridden from View:
  virtual gfx::Size GetPreferredSize();

  // Overridden from NativeControlWin:
  virtual bool ProcessMessage(UINT message,
                              WPARAM w_param,
                              LPARAM l_param,
                              LRESULT* result);

 protected:
  virtual void CreateNativeControl();

 private:
  // Makes |model_row| the only selected and focused row.
  void Select(int model_row);

  // Notification from the ListView that the selected state of an item has
  // changed.
  virtual void OnSelectedStateChanged();

  // Notification from the ListView that the used double clicked the table.
  virtual void OnDoubleClick();

  // Notification from the ListView that the user middle clicked the table.
  virtual void OnMiddleClick();

  // Overridden from NativeControl. Notifies the observer.
  virtual bool OnKeyDown(base::KeyboardCode virtual_keycode);

  // Custom drawing of our icons.
  LRESULT OnCustomDraw(NMLVCUSTOMDRAW* draw_info);

  void UpdateListViewCache(int start, int length, bool add);

  void UpdateContentOffset();

  // Window procedure of the list view class. We subclass the list view to
  // ignore WM_ERASEBKGND, which gives smoother painting during resizing.
  static LRESULT CALLBACK TableWndProc(HWND window,
                                       UINT message,
                                       WPARAM w_param,
                                       LPARAM l_param);

  // Window procedure of the header class. We subclass the header of the table
  // to disable resizing of columns.
  static LRESULT CALLBACK TableHeaderWndProc(HWND window,
                                             UINT message,
                                             WPARAM w_param,
                                             LPARAM l_param);

  // If true, any events that would normally be propagated to the observer
  // are ignored. For example, if this is true and the selection changes in
  // the listview, the observer is not notified.
  bool ignore_listview_change_;

  // The Table we are bound to.
  TableView2* table_;

  // The Y offset from the top of the table to the actual content (passed the
  // header if any).
  int content_offset_;

  // The list view's header original proc handler. It is required when
  // subclassing.
  WNDPROC header_original_handler_;

  // Window procedure of the listview before we subclassed it.
  WNDPROC original_handler_;

  // Size (width and height) of images.
  static const int kImageSize;

  DISALLOW_COPY_AND_ASSIGN(NativeTableWin);
};

}  // namespace views

#endif  // VIEWS_CONTROLS_TABLE_NATIVE_TABLE_WIN_H_