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.
5 #ifndef UI_VIEWS_CONTROLS_NATIVE_CONTROL_WIN_H_
6 #define UI_VIEWS_CONTROLS_NATIVE_CONTROL_WIN_H_
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"
20 // A View that hosts a native Windows control.
21 class NativeControlWin : public ChildWindowMessageProcessor,
22 public NativeViewHost {
25 virtual ~NativeControlWin();
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; }
32 // Overridden from ChildWindowMessageProcessor:
33 virtual bool ProcessMessage(UINT message,
36 LRESULT* result) OVERRIDE;
38 // Overridden from View:
39 virtual void OnEnabledChanged() OVERRIDE;
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;
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);
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;
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);
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.
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;
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;
76 typedef ScopedVector<ui::ViewProp> ViewProps;
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);
83 // Our subclass window procedure for the attached control.
84 static LRESULT CALLBACK NativeControlWndProc(HWND window,
89 // The window procedure before we subclassed.
90 WNDPROC original_wndproc_;
94 DISALLOW_COPY_AND_ASSIGN(NativeControlWin);
99 #endif // UI_VIEWS_CONTROLS_NATIVE_CONTROL_WIN_H_