summaryrefslogtreecommitdiffstats
path: root/views/controls/native_control_win.h
blob: c9c18a6d15e09c7de16dc2ef1930d69a65eaa100 (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
// 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_NATIVE_CONTROL_WIN_H_
#define VIEWS_CONTROLS_NATIVE_CONTROL_WIN_H_

#include "views/controls/native/native_view_host.h"

namespace views {

// A View that hosts a native Windows control.
class NativeControlWin : public NativeViewHost {
 public:
  static const wchar_t* kNativeControlWinKey;

  NativeControlWin();
  virtual ~NativeControlWin();

  // Called by the containing WidgetWin when a message is received from the HWND
  // created by an object derived from NativeControlWin. Derived classes MUST
  // call _this_ version of the function if they override it and do not handle
  // all of the messages listed in widget_win.cc ProcessNativeControlWinMessage.
  // Returns true if the message was handled, with a valid result in |result|.
  // Returns false if the message was not handled.
  virtual bool ProcessMessage(UINT message,
                              WPARAM w_param,
                              LPARAM l_param,
                              LRESULT* result);

  // Called by our subclassed window procedure when a WM_KEYDOWN message is
  // received by the HWND created by an object derived from NativeControlWin.
  // Returns true if the key was processed, false otherwise.
  virtual bool OnKeyDown(int vkey) { return false; }

  // Overridden from View:
  virtual void SetEnabled(bool enabled);

 protected:
  virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child);
  virtual void VisibilityChanged(View* starting_from, bool is_visible);
  virtual void Focus();

  // Called by the containing WidgetWin when a WM_CONTEXTMENU message is
  // received from the HWND created by an object derived from NativeControlWin.
  virtual void ShowContextMenu(const gfx::Point& location);

  // Called when the NativeControlWin is attached to a View hierarchy with a
  // valid Widget. The NativeControlWin should use this opportunity to create
  // its associated HWND.
  virtual void CreateNativeControl() = 0;

  // MUST be called by the subclass implementation of |CreateNativeControl|
  // immediately after creating the control HWND, otherwise it won't be attached
  // to the NativeViewHost and will be effectively orphaned.
  virtual void NativeControlCreated(HWND native_control);

  // Returns additional extended style flags. When subclasses call
  // CreateWindowEx in order to create the underlying control, they must OR the
  // ExStyle parameter with the value returned by this function.
  //
  // We currently use this method in order to add flags such as WS_EX_LAYOUTRTL
  // to the HWND for views with right-to-left UI layout.
  DWORD GetAdditionalExStyle() const;

  // TODO(xji): we use the following temporary function as we transition the
  // various native controls to use the right set of RTL flags. This function
  // will go away (and be replaced by GetAdditionalExStyle()) once all the
  // controls are properly transitioned.
  DWORD GetAdditionalRTLStyle() const;

 private:
  // Called by the containing WidgetWin when a message of type WM_CTLCOLORBTN or
  // WM_CTLCOLORSTATIC is sent from the HWND created by an object dreived from
  // NativeControlWin.
  LRESULT GetControlColor(UINT message, HDC dc, HWND sender);

  // Our subclass window procedure for the attached control.
  static LRESULT CALLBACK NativeControlWndProc(HWND window,
                                               UINT message,
                                               WPARAM w_param,
                                               LPARAM l_param);

  // The window procedure before we subclassed.
  WNDPROC original_wndproc_;

  DISALLOW_COPY_AND_ASSIGN(NativeControlWin);
};

}  // namespace views

#endif  // #ifndef VIEWS_CONTROLS_NATIVE_CONTROL_WIN_H_