1 // Copyright (c) 2012 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 #include "ui/base/cursor/cursor_loader_win.h"
7 #include "base/lazy_instance.h"
8 #include "base/strings/string16.h"
9 #include "ui/base/cursor/cursor.h"
10 #include "ui/resources/grit/ui_unscaled_resources.h"
16 base::LazyInstance
<base::string16
> g_cursor_resource_module_name
;
18 const wchar_t* GetCursorId(gfx::NativeCursor native_cursor
) {
19 switch (native_cursor
.native_type()) {
34 case kCursorEastResize
:
36 case kCursorNorthResize
:
38 case kCursorNorthEastResize
:
40 case kCursorNorthWestResize
:
42 case kCursorSouthResize
:
44 case kCursorSouthEastResize
:
46 case kCursorSouthWestResize
:
48 case kCursorWestResize
:
50 case kCursorNorthSouthResize
:
52 case kCursorEastWestResize
:
54 case kCursorNorthEastSouthWestResize
:
56 case kCursorNorthWestSouthEastResize
:
61 return IDC_APPSTARTING
;
64 case kCursorNotAllowed
:
66 case kCursorColumnResize
:
67 return MAKEINTRESOURCE(IDC_COLRESIZE
);
68 case kCursorRowResize
:
69 return MAKEINTRESOURCE(IDC_ROWRESIZE
);
70 case kCursorMiddlePanning
:
71 return MAKEINTRESOURCE(IDC_PAN_MIDDLE
);
72 case kCursorEastPanning
:
73 return MAKEINTRESOURCE(IDC_PAN_EAST
);
74 case kCursorNorthPanning
:
75 return MAKEINTRESOURCE(IDC_PAN_NORTH
);
76 case kCursorNorthEastPanning
:
77 return MAKEINTRESOURCE(IDC_PAN_NORTH_EAST
);
78 case kCursorNorthWestPanning
:
79 return MAKEINTRESOURCE(IDC_PAN_NORTH_WEST
);
80 case kCursorSouthPanning
:
81 return MAKEINTRESOURCE(IDC_PAN_SOUTH
);
82 case kCursorSouthEastPanning
:
83 return MAKEINTRESOURCE(IDC_PAN_SOUTH_EAST
);
84 case kCursorSouthWestPanning
:
85 return MAKEINTRESOURCE(IDC_PAN_SOUTH_WEST
);
86 case kCursorWestPanning
:
87 return MAKEINTRESOURCE(IDC_PAN_WEST
);
88 case kCursorVerticalText
:
89 return MAKEINTRESOURCE(IDC_VERTICALTEXT
);
91 return MAKEINTRESOURCE(IDC_CELL
);
93 return MAKEINTRESOURCE(IDC_ZOOMIN
);
95 return MAKEINTRESOURCE(IDC_ZOOMOUT
);
97 return MAKEINTRESOURCE(IDC_HAND_GRAB
);
99 return MAKEINTRESOURCE(IDC_HAND_GRABBING
);
101 return MAKEINTRESOURCE(IDC_COPYCUR
);
103 return MAKEINTRESOURCE(IDC_ALIAS
);
105 return MAKEINTRESOURCE(IDC_CURSOR_NONE
);
106 case kCursorContextMenu
:
118 CursorLoader
* CursorLoader::Create() {
119 return new CursorLoaderWin
;
122 CursorLoaderWin::CursorLoaderWin() {
125 CursorLoaderWin::~CursorLoaderWin() {
128 void CursorLoaderWin::LoadImageCursor(int id
,
130 const gfx::Point
& hot
) {
134 void CursorLoaderWin::LoadAnimatedCursor(int id
,
136 const gfx::Point
& hot
,
137 int frame_delay_ms
) {
141 void CursorLoaderWin::UnloadAll() {
145 void CursorLoaderWin::SetPlatformCursor(gfx::NativeCursor
* cursor
) {
146 if (cursor
->native_type() != kCursorCustom
) {
147 if (cursor
->platform()) {
148 cursor
->SetPlatformCursor(cursor
->platform());
150 const wchar_t* cursor_id
= GetCursorId(*cursor
);
151 PlatformCursor platform_cursor
= LoadCursor(NULL
, cursor_id
);
152 if (!platform_cursor
&& !g_cursor_resource_module_name
.Get().empty()) {
153 platform_cursor
= LoadCursor(
154 GetModuleHandle(g_cursor_resource_module_name
.Get().c_str()),
157 cursor
->SetPlatformCursor(platform_cursor
);
163 void CursorLoaderWin::SetCursorResourceModule(
164 const base::string16
& module_name
) {
165 g_cursor_resource_module_name
.Get() = module_name
;