1// Copyright (c) 2011 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.
4
5#ifndef UI_VIEWS_CONTROLS_NATIVE_CONTROL_WIN_H_
6#define UI_VIEWS_CONTROLS_NATIVE_CONTROL_WIN_H_
7
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "base/memory/scoped_vector.h"
11#include "ui/views/controls/native/native_view_host.h"
12#include "ui/views/widget/child_window_message_processor.h"
13
14namespace ui {
15class ViewProp;
16}
17
18namespace views {
19
20// A View that hosts a native Windows control.
21class NativeControlWin : public ChildWindowMessageProcessor,
22                         public NativeViewHost {
23 public:
24  NativeControlWin();
25  virtual ~NativeControlWin();
26
27  // Called by our subclassed window procedure when a WM_KEYDOWN message is
28  // received by the HWND created by an object derived from NativeControlWin.
29  // Returns true if the key was processed, false otherwise.
30  virtual bool OnKeyDown(int vkey) { return false; }
31
32  // Overridden from ChildWindowMessageProcessor:
33  virtual bool ProcessMessage(UINT message,
34                              WPARAM w_param,
35                              LPARAM l_param,
36                              LRESULT* result) OVERRIDE;
37
38  // Overridden from View:
39  virtual void OnEnabledChanged() OVERRIDE;
40
41 protected:
42  virtual void ViewHierarchyChanged(
43      const ViewHierarchyChangedDetails& details) OVERRIDE;
44  virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE;
45  virtual void OnFocus() OVERRIDE;
46
47  // Called by the containing NativeWidgetWin when a WM_CONTEXTMENU message is
48  // received from the HWND created by an object derived from NativeControlWin.
49  virtual void ShowContextMenu(const gfx::Point& location);
50
51  // Called when the NativeControlWin is attached to a View hierarchy with a
52  // valid Widget. The NativeControlWin should use this opportunity to create
53  // its associated HWND.
54  virtual void CreateNativeControl() = 0;
55
56  // MUST be called by the subclass implementation of |CreateNativeControl|
57  // immediately after creating the control HWND, otherwise it won't be attached
58  // to the NativeViewHost and will be effectively orphaned.
59  virtual void NativeControlCreated(HWND native_control);
60
61  // Returns additional extended style flags. When subclasses call
62  // CreateWindowEx in order to create the underlying control, they must OR the
63  // ExStyle parameter with the value returned by this function.
64  //
65  // We currently use this method in order to add flags such as WS_EX_LAYOUTRTL
66  // to the HWND for views with right-to-left UI layout.
67  DWORD GetAdditionalExStyle() const;
68
69  // TODO(xji): we use the following temporary function as we transition the
70  // various native controls to use the right set of RTL flags. This function
71  // will go away (and be replaced by GetAdditionalExStyle()) once all the
72  // controls are properly transitioned.
73  DWORD GetAdditionalRTLStyle() const;
74
75 private:
76  typedef ScopedVector<ui::ViewProp> ViewProps;
77
78  // Called by the containing NativeWidgetWin when a message of type
79  // WM_CTLCOLORBTN or WM_CTLCOLORSTATIC is sent from the HWND created by an
80  // object derived from NativeControlWin.
81  LRESULT GetControlColor(UINT message, HDC dc, HWND sender);
82
83  // Our subclass window procedure for the attached control.
84  static LRESULT CALLBACK NativeControlWndProc(HWND window,
85                                               UINT message,
86                                               WPARAM w_param,
87                                               LPARAM l_param);
88
89  // The window procedure before we subclassed.
90  WNDPROC original_wndproc_;
91
92  ViewProps props_;
93
94  DISALLOW_COPY_AND_ASSIGN(NativeControlWin);
95};
96
97}  // namespace views
98
99#endif  // UI_VIEWS_CONTROLS_NATIVE_CONTROL_WIN_H_
100