Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / base / cursor / cursor_loader_win.cc
blob7c8d18f72ae54c0b381f3f19fba58434164f8f4a
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"
12 namespace ui {
14 namespace {
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()) {
20 case kCursorNull:
21 return IDC_ARROW;
22 case kCursorPointer:
23 return IDC_ARROW;
24 case kCursorCross:
25 return IDC_CROSS;
26 case kCursorHand:
27 return IDC_HAND;
28 case kCursorIBeam:
29 return IDC_IBEAM;
30 case kCursorWait:
31 return IDC_WAIT;
32 case kCursorHelp:
33 return IDC_HELP;
34 case kCursorEastResize:
35 return IDC_SIZEWE;
36 case kCursorNorthResize:
37 return IDC_SIZENS;
38 case kCursorNorthEastResize:
39 return IDC_SIZENESW;
40 case kCursorNorthWestResize:
41 return IDC_SIZENWSE;
42 case kCursorSouthResize:
43 return IDC_SIZENS;
44 case kCursorSouthEastResize:
45 return IDC_SIZENWSE;
46 case kCursorSouthWestResize:
47 return IDC_SIZENESW;
48 case kCursorWestResize:
49 return IDC_SIZEWE;
50 case kCursorNorthSouthResize:
51 return IDC_SIZENS;
52 case kCursorEastWestResize:
53 return IDC_SIZEWE;
54 case kCursorNorthEastSouthWestResize:
55 return IDC_SIZENESW;
56 case kCursorNorthWestSouthEastResize:
57 return IDC_SIZENWSE;
58 case kCursorMove:
59 return IDC_SIZEALL;
60 case kCursorProgress:
61 return IDC_APPSTARTING;
62 case kCursorNoDrop:
63 return IDC_NO;
64 case kCursorNotAllowed:
65 return IDC_NO;
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);
90 case kCursorCell:
91 return MAKEINTRESOURCE(IDC_CELL);
92 case kCursorZoomIn:
93 return MAKEINTRESOURCE(IDC_ZOOMIN);
94 case kCursorZoomOut:
95 return MAKEINTRESOURCE(IDC_ZOOMOUT);
96 case kCursorGrab:
97 return MAKEINTRESOURCE(IDC_HAND_GRAB);
98 case kCursorGrabbing:
99 return MAKEINTRESOURCE(IDC_HAND_GRABBING);
100 case kCursorCopy:
101 return MAKEINTRESOURCE(IDC_COPYCUR);
102 case kCursorAlias:
103 return MAKEINTRESOURCE(IDC_ALIAS);
104 case kCursorNone:
105 return MAKEINTRESOURCE(IDC_CURSOR_NONE);
106 case kCursorContextMenu:
107 case kCursorCustom:
108 NOTIMPLEMENTED();
109 return IDC_ARROW;
110 default:
111 NOTREACHED();
112 return IDC_ARROW;
116 } // namespace
118 CursorLoader* CursorLoader::Create() {
119 return new CursorLoaderWin;
122 CursorLoaderWin::CursorLoaderWin() {
125 CursorLoaderWin::~CursorLoaderWin() {
128 void CursorLoaderWin::LoadImageCursor(int id,
129 int resource_id,
130 const gfx::Point& hot) {
131 // NOTIMPLEMENTED();
134 void CursorLoaderWin::LoadAnimatedCursor(int id,
135 int resource_id,
136 const gfx::Point& hot,
137 int frame_delay_ms) {
138 // NOTIMPLEMENTED();
141 void CursorLoaderWin::UnloadAll() {
142 // NOTIMPLEMENTED();
145 void CursorLoaderWin::SetPlatformCursor(gfx::NativeCursor* cursor) {
146 if (cursor->native_type() != kCursorCustom) {
147 if (cursor->platform()) {
148 cursor->SetPlatformCursor(cursor->platform());
149 } else {
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()),
155 cursor_id);
157 cursor->SetPlatformCursor(platform_cursor);
162 // static
163 void CursorLoaderWin::SetCursorResourceModule(
164 const base::string16& module_name) {
165 g_cursor_resource_module_name.Get() = module_name;
168 } // namespace ui