Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: views/controls/separator.cc

Issue 118065: Make separator portable. Simpler than other native controls so no wrapper int... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/separator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/controls/separator.h" 5 #include "views/controls/separator.h"
6 6
7 #include "views/controls/native/native_view_host.h" 7 #if defined(OS_LINUX)
8 #include "views/controls/native_control_gtk.h"
9 #elif defined(OS_WIN)
10 #include "views/controls/native_control_win.h"
11 #endif
12 #include "views/widget/widget.h"
8 13
9 namespace views { 14 namespace views {
10 15
11 static const int kSeparatorSize = 2; 16 #if defined(OS_WIN)
17 class NativeSeparatorWin : public NativeControlWin {
18 public:
19 explicit NativeSeparatorWin(Separator* separator) : separator_(separator) {}
20 virtual ~NativeSeparatorWin() {}
21
22 // Overridden from NativeControlWin:
23 virtual void CreateNativeControl() {
24 HWND control_hwnd = CreateWindowEx(GetAdditionalExStyle(), L"STATIC", L"",
25 WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN,
26 0, 0, width(), height(),
27 separator_->GetWidget()->GetNativeView(),
28 NULL, NULL, NULL);
29 NativeControlCreated(control_hwnd);
30 }
31
32 private:
33 Separator* separator_;
34
35 DISALLOW_COPY_AND_ASSIGN(NativeSeparatorWin);
36 };
37 #elif defined(OS_LINUX)
38 class NativeSeparatorGtk : public NativeControlGtk {
39 public:
40 explicit NativeSeparatorGtk(Separator* separator) : separator_(separator) {}
41 virtual ~NativeSeparatorGtk() {}
42
43 // Overridden from NativeSeparatorGtk:
44 virtual void CreateNativeControl() {
45 // TODO(port): create a separator widget and pass to NativeControlCreated.
46 }
47
48 private:
49 Separator* separator_;
50
51 DISALLOW_COPY_AND_ASSIGN(NativeSeparatorGtk);
52 };
53 #endif
54
55 // static
56 const char Separator::kViewClassName[] = "views/Separator";
57
58 const int kSeparatorSize = 2;
12 59
13 Separator::Separator() { 60 Separator::Separator() {
14 SetFocusable(false); 61 SetFocusable(false);
15 } 62 }
16 63
17 Separator::~Separator() { 64 Separator::~Separator() {
18 } 65 }
19 66
20 HWND Separator::CreateNativeControl(HWND parent_container) { 67 ////////////////////////////////////////////////////////////////////////////////
21 SetFixedHeight(kSeparatorSize, CENTER); 68 // Separator, View overrides:
22 69
23 return ::CreateWindowEx(GetAdditionalExStyle(), L"STATIC", L"", 70 gfx::Size Separator::GetPreferredSize() {
24 WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN, 71 return gfx::Size(width(), kSeparatorSize);
25 0, 0, width(), height(),
26 parent_container, NULL, NULL, NULL);
27 } 72 }
28 73
29 LRESULT Separator::OnNotify(int w_param, LPNMHDR l_param) { 74 void Separator::Layout() {
30 return 0; 75 if (native_wrapper_) {
76 native_wrapper_->SetBounds(0, 0, width(), height());
77 native_wrapper_->Layout();
78 }
31 } 79 }
32 80
33 gfx::Size Separator::GetPreferredSize() { 81 void Separator::ViewHierarchyChanged(bool is_add, View* parent,
34 return gfx::Size(width(), fixed_height_); 82 View* child) {
83 if (is_add && !native_wrapper_ && GetWidget()) {
84 CreateNativeWrapper();
85 AddChildView(native_wrapper_);
86 }
87 }
88
89 std::string Separator::GetClassName() const {
90 return kViewClassName;
91 }
92
93 ////////////////////////////////////////////////////////////////////////////////
94 // Separator, private:
95
96 void Separator::CreateNativeWrapper() {
97 #if defined(OS_WIN)
98 native_wrapper_ = new NativeSeparatorWin(this);
99 #elif defined(OS_LINUX)
100 native_wrapper_ = new NativeSeparatorGtk(this);
101 #endif
35 } 102 }
36 103
37 } // namespace views 104 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/separator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698