OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #if defined(OS_LINUX) | 7 #include "views/controls/native/native_view_host.h" |
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" | |
13 | 8 |
14 namespace views { | 9 namespace views { |
15 | 10 |
16 #if defined(OS_WIN) | 11 static const int kSeparatorSize = 2; |
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; | |
59 | 12 |
60 Separator::Separator() { | 13 Separator::Separator() { |
61 SetFocusable(false); | 14 SetFocusable(false); |
62 } | 15 } |
63 | 16 |
64 Separator::~Separator() { | 17 Separator::~Separator() { |
65 } | 18 } |
66 | 19 |
67 //////////////////////////////////////////////////////////////////////////////// | 20 HWND Separator::CreateNativeControl(HWND parent_container) { |
68 // Separator, View overrides: | 21 SetFixedHeight(kSeparatorSize, CENTER); |
| 22 |
| 23 return ::CreateWindowEx(GetAdditionalExStyle(), L"STATIC", L"", |
| 24 WS_CHILD | SS_ETCHEDHORZ | SS_SUNKEN, |
| 25 0, 0, width(), height(), |
| 26 parent_container, NULL, NULL, NULL); |
| 27 } |
| 28 |
| 29 LRESULT Separator::OnNotify(int w_param, LPNMHDR l_param) { |
| 30 return 0; |
| 31 } |
69 | 32 |
70 gfx::Size Separator::GetPreferredSize() { | 33 gfx::Size Separator::GetPreferredSize() { |
71 return gfx::Size(width(), kSeparatorSize); | 34 return gfx::Size(width(), fixed_height_); |
72 } | |
73 | |
74 void Separator::Layout() { | |
75 if (native_wrapper_) { | |
76 native_wrapper_->SetBounds(0, 0, width(), height()); | |
77 native_wrapper_->Layout(); | |
78 } | |
79 } | |
80 | |
81 void Separator::ViewHierarchyChanged(bool is_add, View* parent, | |
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 | |
102 } | 35 } |
103 | 36 |
104 } // namespace views | 37 } // namespace views |
OLD | NEW |