OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_FRAME_IN_PLACE_MENU_H_ | 5 #ifndef CHROME_FRAME_IN_PLACE_MENU_H_ |
6 #define CHROME_FRAME_IN_PLACE_MENU_H_ | 6 #define CHROME_FRAME_IN_PLACE_MENU_H_ |
7 | 7 |
8 // in_place_menu.h : menu merging implementation | 8 // in_place_menu.h : menu merging implementation |
9 // | 9 // |
10 // This file is a modified version of the menu.h file, which is | 10 // This file is a modified version of the menu.h file, which is |
11 // part of the ActiveDoc MSDN sample. The modifications are largely | 11 // part of the ActiveDoc MSDN sample. The modifications are largely |
12 // conversions to Google coding guidelines. Below is the original header | 12 // conversions to Google coding guidelines. Below is the original header |
13 // from the file. | 13 // from the file. |
14 | 14 |
15 // This is a part of the Active Template Library. | 15 // This is a part of the Active Template Library. |
16 // Copyright (c) Microsoft Corporation. All rights reserved. | 16 // Copyright (c) Microsoft Corporation. All rights reserved. |
17 // | 17 // |
18 // This source code is only intended as a supplement to the | 18 // This source code is only intended as a supplement to the |
19 // Active Template Library Reference and related | 19 // Active Template Library Reference and related |
20 // electronic documentation provided with the library. | 20 // electronic documentation provided with the library. |
21 // See these sources for detailed information regarding the | 21 // See these sources for detailed information regarding the |
22 // Active Template Library product. | 22 // Active Template Library product. |
23 | 23 |
24 #include "base/logging.h" | 24 #include "base/logging.h" |
25 #include "base/scoped_comptr_win.h" | 25 #include "base/win/scoped_comptr.h" |
26 | 26 |
27 template <class T> | 27 template <class T> |
28 class InPlaceMenu { | 28 class InPlaceMenu { |
29 public: | 29 public: |
30 InPlaceMenu() : shared_menu_(NULL), ole_menu_(NULL), our_menu_(NULL) { | 30 InPlaceMenu() : shared_menu_(NULL), ole_menu_(NULL), our_menu_(NULL) { |
31 } | 31 } |
32 | 32 |
33 ~InPlaceMenu() { | 33 ~InPlaceMenu() { |
34 InPlaceMenuDestroy(); | 34 InPlaceMenuDestroy(); |
35 } | 35 } |
36 | 36 |
37 HRESULT InPlaceMenuCreate(LPCWSTR menu_name) { | 37 HRESULT InPlaceMenuCreate(LPCWSTR menu_name) { |
38 // We might already have an in-place menu set, because we set menus | 38 // We might already have an in-place menu set, because we set menus |
39 // IOleDocumentView::UIActivate as well as in | 39 // IOleDocumentView::UIActivate as well as in |
40 // IOleInPlaceActiveObject::OnDocWindowActivate. If we have already | 40 // IOleInPlaceActiveObject::OnDocWindowActivate. If we have already |
41 // done our work, just return silently | 41 // done our work, just return silently |
42 if (ole_menu_ || shared_menu_) | 42 if (ole_menu_ || shared_menu_) |
43 return S_OK; | 43 return S_OK; |
44 | 44 |
45 ScopedComPtr<IOleInPlaceFrame> in_place_frame; | 45 base::win::ScopedComPtr<IOleInPlaceFrame> in_place_frame; |
46 GetInPlaceFrame(in_place_frame.Receive()); | 46 GetInPlaceFrame(in_place_frame.Receive()); |
47 // We have no IOleInPlaceFrame, no menu merging possible | 47 // We have no IOleInPlaceFrame, no menu merging possible |
48 if (!in_place_frame) { | 48 if (!in_place_frame) { |
49 NOTREACHED(); | 49 NOTREACHED(); |
50 return E_FAIL; | 50 return E_FAIL; |
51 } | 51 } |
52 // Create a blank menu and ask the container to add | 52 // Create a blank menu and ask the container to add |
53 // its menus into the OLEMENUGROUPWIDTHS structure | 53 // its menus into the OLEMENUGROUPWIDTHS structure |
54 shared_menu_ = ::CreateMenu(); | 54 shared_menu_ = ::CreateMenu(); |
55 OLEMENUGROUPWIDTHS mgw = {0}; | 55 OLEMENUGROUPWIDTHS mgw = {0}; |
56 HRESULT hr = in_place_frame->InsertMenus(shared_menu_, &mgw); | 56 HRESULT hr = in_place_frame->InsertMenus(shared_menu_, &mgw); |
57 if (FAILED(hr)) { | 57 if (FAILED(hr)) { |
58 ::DestroyMenu(shared_menu_); | 58 ::DestroyMenu(shared_menu_); |
59 shared_menu_ = NULL; | 59 shared_menu_ = NULL; |
60 return hr; | 60 return hr; |
61 } | 61 } |
62 // Insert our menus | 62 // Insert our menus |
63 our_menu_ = LoadMenu(_AtlBaseModule.GetResourceInstance(),menu_name); | 63 our_menu_ = LoadMenu(_AtlBaseModule.GetResourceInstance(),menu_name); |
64 MergeMenus(shared_menu_, our_menu_, &mgw.width[0], 1); | 64 MergeMenus(shared_menu_, our_menu_, &mgw.width[0], 1); |
65 // Send the menu to the client | 65 // Send the menu to the client |
66 ole_menu_ = (HMENU)OleCreateMenuDescriptor(shared_menu_, &mgw); | 66 ole_menu_ = (HMENU)OleCreateMenuDescriptor(shared_menu_, &mgw); |
67 T* t = static_cast<T*>(this); | 67 T* t = static_cast<T*>(this); |
68 in_place_frame->SetMenu(shared_menu_, ole_menu_, t->m_hWnd); | 68 in_place_frame->SetMenu(shared_menu_, ole_menu_, t->m_hWnd); |
69 return S_OK; | 69 return S_OK; |
70 } | 70 } |
71 | 71 |
72 HRESULT InPlaceMenuDestroy() { | 72 HRESULT InPlaceMenuDestroy() { |
73 ScopedComPtr<IOleInPlaceFrame> in_place_frame; | 73 base::win::ScopedComPtr<IOleInPlaceFrame> in_place_frame; |
74 GetInPlaceFrame(in_place_frame.Receive()); | 74 GetInPlaceFrame(in_place_frame.Receive()); |
75 if (in_place_frame) { | 75 if (in_place_frame) { |
76 in_place_frame->RemoveMenus(shared_menu_); | 76 in_place_frame->RemoveMenus(shared_menu_); |
77 in_place_frame->SetMenu(NULL, NULL, NULL); | 77 in_place_frame->SetMenu(NULL, NULL, NULL); |
78 } | 78 } |
79 if (ole_menu_) { | 79 if (ole_menu_) { |
80 OleDestroyMenuDescriptor(ole_menu_); | 80 OleDestroyMenuDescriptor(ole_menu_); |
81 ole_menu_ = NULL; | 81 ole_menu_ = NULL; |
82 } | 82 } |
83 if (shared_menu_) { | 83 if (shared_menu_) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 NOTREACHED(); | 170 NOTREACHED(); |
171 return E_POINTER; | 171 return E_POINTER; |
172 } | 172 } |
173 T* t = static_cast<T*>(this); | 173 T* t = static_cast<T*>(this); |
174 HRESULT hr = E_FAIL; | 174 HRESULT hr = E_FAIL; |
175 if (S_OK != t->GetInPlaceFrame(in_place_frame)) { | 175 if (S_OK != t->GetInPlaceFrame(in_place_frame)) { |
176 // We weren't given an IOleInPlaceFrame pointer, so | 176 // We weren't given an IOleInPlaceFrame pointer, so |
177 // we'll have to get it ourselves. | 177 // we'll have to get it ourselves. |
178 if (t->m_spInPlaceSite) { | 178 if (t->m_spInPlaceSite) { |
179 t->frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO); | 179 t->frame_info_.cb = sizeof(OLEINPLACEFRAMEINFO); |
180 ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window; | 180 base::win::ScopedComPtr<IOleInPlaceUIWindow> in_place_ui_window; |
181 RECT position_rect = {0}; | 181 RECT position_rect = {0}; |
182 RECT clip_rect = {0}; | 182 RECT clip_rect = {0}; |
183 hr = t->m_spInPlaceSite->GetWindowContext(in_place_frame, | 183 hr = t->m_spInPlaceSite->GetWindowContext(in_place_frame, |
184 in_place_ui_window.Receive(), | 184 in_place_ui_window.Receive(), |
185 &position_rect, &clip_rect, | 185 &position_rect, &clip_rect, |
186 &t->frame_info_); | 186 &t->frame_info_); |
187 } | 187 } |
188 } | 188 } |
189 return hr; | 189 return hr; |
190 } | 190 } |
191 | 191 |
192 protected: | 192 protected: |
193 // The OLE menu descriptor created by the OleCreateMenuDescriptor | 193 // The OLE menu descriptor created by the OleCreateMenuDescriptor |
194 HMENU ole_menu_; | 194 HMENU ole_menu_; |
195 // The shared menu that we pass to IOleInPlaceFrame::SetMenu | 195 // The shared menu that we pass to IOleInPlaceFrame::SetMenu |
196 HMENU shared_menu_; | 196 HMENU shared_menu_; |
197 // Our menu resource that we want to insert | 197 // Our menu resource that we want to insert |
198 HMENU our_menu_; | 198 HMENU our_menu_; |
199 }; | 199 }; |
200 | 200 |
201 #endif // CHROME_FRAME_IN_PLACE_MENU_H_ | 201 #endif // CHROME_FRAME_IN_PLACE_MENU_H_ |
202 | 202 |
OLD | NEW |