summaryrefslogtreecommitdiffstats
path: root/views/controls/native_control.h
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 00:34:05 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 00:34:05 +0000
commit2362e4fe2905ab75d3230ebc3e307ae53e2b8362 (patch)
treee6d88357a2021811e0e354f618247217be8bb3da /views/controls/native_control.h
parentdb23ac3e713dc17509b2b15d3ee634968da45715 (diff)
downloadchromium_src-2362e4fe2905ab75d3230ebc3e307ae53e2b8362.zip
chromium_src-2362e4fe2905ab75d3230ebc3e307ae53e2b8362.tar.gz
chromium_src-2362e4fe2905ab75d3230ebc3e307ae53e2b8362.tar.bz2
Move src/chrome/views to src/views. RS=darin http://crbug.com/11387
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15604 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/native_control.h')
-rw-r--r--views/controls/native_control.h132
1 files changed, 132 insertions, 0 deletions
diff --git a/views/controls/native_control.h b/views/controls/native_control.h
new file mode 100644
index 0000000..0573168
--- /dev/null
+++ b/views/controls/native_control.h
@@ -0,0 +1,132 @@
+// 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_NATIVE_CONTROL_H_
+#define VIEWS_CONTROLS_NATIVE_CONTROL_H_
+
+#include <windows.h>
+
+#include "views/view.h"
+
+namespace views {
+
+class HWNDView;
+class NativeControlContainer;
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// NativeControl is an abstract view that is used to implement views wrapping
+// native controls. Subclasses can simply implement CreateNativeControl() to
+// wrap a new kind of control
+//
+////////////////////////////////////////////////////////////////////////////////
+class NativeControl : public View {
+ public:
+ enum Alignment {
+ LEADING = 0,
+ CENTER,
+ TRAILING };
+
+ NativeControl();
+ virtual ~NativeControl();
+
+ virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child);
+ virtual void Layout();
+
+ // Overridden to properly set the native control state.
+ virtual void SetVisible(bool f);
+ virtual void SetEnabled(bool enabled);
+
+ // Overridden to do nothing.
+ virtual void Paint(ChromeCanvas* canvas);
+ protected:
+ friend class NativeControlContainer;
+
+ // Overridden by sub-classes to create the windows control which is wrapped
+ virtual HWND CreateNativeControl(HWND parent_container) = 0;
+
+ // Invoked when the native control sends a WM_NOTIFY message to its parent
+ virtual LRESULT OnNotify(int w_param, LPNMHDR l_param) = 0;
+
+ // Invoked when the native control sends a WM_COMMAND message to its parent
+ virtual LRESULT OnCommand(UINT code, int id, HWND source) { return 0; }
+
+ // Invoked when the appropriate gesture for a context menu is issued.
+ virtual void OnContextMenu(const CPoint& location);
+
+ // Overridden so to set the native focus to the native control.
+ virtual void Focus();
+
+ // Invoked when the native control sends a WM_DESTORY message to its parent.
+ virtual void OnDestroy() { }
+
+ // Return the native control
+ virtual HWND GetNativeControlHWND();
+
+ // Invoked by the native windows control when it has been destroyed. This is
+ // invoked AFTER WM_DESTORY has been sent. Any window commands send to the
+ // HWND will most likely fail.
+ void NativeControlDestroyed();
+
+ // Overridden so that the control properly reflects parent's visibility.
+ virtual void VisibilityChanged(View* starting_from, bool is_visible);
+
+ // Controls that have fixed sizes should call these methods to specify the
+ // actual size and how they should be aligned within their parent.
+ void SetFixedWidth(int width, Alignment alignment);
+ void SetFixedHeight(int height, Alignment alignment);
+
+ // Derived classes interested in receiving key down notification should
+ // override this method and return true. In which case OnKeyDown is called
+ // when a key down message is sent to the control.
+ // Note that this method is called at the time of the control creation: the
+ // behavior will not change if the returned value changes after the control
+ // has been created.
+ virtual bool NotifyOnKeyDown() const { return false; }
+
+ // Invoked when a key is pressed on the control (if NotifyOnKeyDown returns
+ // true). Should return true if the key message was processed, false
+ // otherwise.
+ virtual bool OnKeyDown(int virtual_key_code) { return false; }
+
+ // 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;
+
+ // This variable is protected to provide subclassers direct access. However
+ // subclassers should always check for NULL since this variable is only
+ // initialized in ValidateNativeControl().
+ HWNDView* hwnd_view_;
+
+ // Fixed size information. -1 for a size means no fixed size.
+ int fixed_width_;
+ Alignment horizontal_alignment_;
+ int fixed_height_;
+ Alignment vertical_alignment_;
+
+ private:
+
+ void ValidateNativeControl();
+
+ static LRESULT CALLBACK NativeControlWndProc(HWND window, UINT message,
+ WPARAM w_param, LPARAM l_param);
+
+ NativeControlContainer* container_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeControl);
+};
+
+} // namespace views
+
+#endif // VIEWS_CONTROLS_NATIVE_CONTROL_H_