Home | History | Annotate | Download | only in cursor
      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.
      4 
      5 #include "ui/base/cursor/cursor_loader_win.h"
      6 
      7 #include "base/lazy_instance.h"
      8 #include "base/strings/string16.h"
      9 #include "grit/ui_unscaled_resources.h"
     10 
     11 #if defined(USE_AURA)
     12 #include "ui/base/cursor/cursor.h"
     13 #endif
     14 
     15 namespace ui {
     16 
     17 #if defined(USE_AURA)
     18 
     19 namespace {
     20 
     21 base::LazyInstance<string16> g_cursor_resource_module_name;
     22 
     23 const wchar_t* GetCursorId(gfx::NativeCursor native_cursor) {
     24   switch (native_cursor.native_type()) {
     25     case kCursorNull:
     26       return IDC_ARROW;
     27     case kCursorPointer:
     28       return IDC_ARROW;
     29     case kCursorCross:
     30       return IDC_CROSS;
     31     case kCursorHand:
     32       return IDC_HAND;
     33     case kCursorIBeam:
     34       return IDC_IBEAM;
     35     case kCursorWait:
     36       return IDC_WAIT;
     37     case kCursorHelp:
     38       return IDC_HELP;
     39     case kCursorEastResize:
     40       return IDC_SIZEWE;
     41     case kCursorNorthResize:
     42       return IDC_SIZENS;
     43     case kCursorNorthEastResize:
     44       return IDC_SIZENESW;
     45     case kCursorNorthWestResize:
     46       return IDC_SIZENWSE;
     47     case kCursorSouthResize:
     48       return IDC_SIZENS;
     49     case kCursorSouthEastResize:
     50       return IDC_SIZENWSE;
     51     case kCursorSouthWestResize:
     52       return IDC_SIZENESW;
     53     case kCursorWestResize:
     54       return IDC_SIZEWE;
     55     case kCursorNorthSouthResize:
     56       return IDC_SIZENS;
     57     case kCursorEastWestResize:
     58       return IDC_SIZEWE;
     59     case kCursorNorthEastSouthWestResize:
     60       return IDC_SIZENESW;
     61     case kCursorNorthWestSouthEastResize:
     62       return IDC_SIZENWSE;
     63     case kCursorMove:
     64       return IDC_SIZEALL;
     65     case kCursorProgress:
     66       return IDC_APPSTARTING;
     67     case kCursorNoDrop:
     68       return IDC_NO;
     69     case kCursorNotAllowed:
     70       return IDC_NO;
     71     case kCursorColumnResize:
     72       return MAKEINTRESOURCE(IDC_COLRESIZE);
     73     case kCursorRowResize:
     74       return MAKEINTRESOURCE(IDC_ROWRESIZE);
     75     case kCursorMiddlePanning:
     76       return MAKEINTRESOURCE(IDC_PAN_MIDDLE);
     77     case kCursorEastPanning:
     78       return MAKEINTRESOURCE(IDC_PAN_EAST);
     79     case kCursorNorthPanning:
     80       return MAKEINTRESOURCE(IDC_PAN_NORTH);
     81     case kCursorNorthEastPanning:
     82       return MAKEINTRESOURCE(IDC_PAN_NORTH_EAST);
     83     case kCursorNorthWestPanning:
     84       return MAKEINTRESOURCE(IDC_PAN_NORTH_WEST);
     85     case kCursorSouthPanning:
     86       return MAKEINTRESOURCE(IDC_PAN_SOUTH);
     87     case kCursorSouthEastPanning:
     88       return MAKEINTRESOURCE(IDC_PAN_SOUTH_EAST);
     89     case kCursorSouthWestPanning:
     90       return MAKEINTRESOURCE(IDC_PAN_SOUTH_WEST);
     91     case kCursorWestPanning:
     92       return MAKEINTRESOURCE(IDC_PAN_WEST);
     93     case kCursorVerticalText:
     94       return MAKEINTRESOURCE(IDC_VERTICALTEXT);
     95     case kCursorCell:
     96       return MAKEINTRESOURCE(IDC_CELL);
     97     case kCursorZoomIn:
     98       return MAKEINTRESOURCE(IDC_ZOOMIN);
     99     case kCursorZoomOut:
    100       return MAKEINTRESOURCE(IDC_ZOOMOUT);
    101     case kCursorGrab:
    102       return MAKEINTRESOURCE(IDC_HAND_GRAB);
    103     case kCursorGrabbing:
    104       return MAKEINTRESOURCE(IDC_HAND_GRABBING);
    105     case kCursorCopy:
    106       return MAKEINTRESOURCE(IDC_COPYCUR);
    107     case kCursorAlias:
    108       return MAKEINTRESOURCE(IDC_ALIAS);
    109     case kCursorNone:
    110       return MAKEINTRESOURCE(IDC_CURSOR_NONE);
    111     case kCursorContextMenu:
    112     case kCursorCustom:
    113       NOTIMPLEMENTED();
    114       return IDC_ARROW;
    115     default:
    116       NOTREACHED();
    117       return IDC_ARROW;
    118   }
    119 }
    120 
    121 }  // namespace
    122 
    123 #endif
    124 
    125 CursorLoader* CursorLoader::Create() {
    126   return new CursorLoaderWin;
    127 }
    128 
    129 CursorLoaderWin::CursorLoaderWin() {
    130 }
    131 
    132 CursorLoaderWin::~CursorLoaderWin() {
    133 }
    134 
    135 void CursorLoaderWin::LoadImageCursor(int id,
    136                                       int resource_id,
    137                                       const gfx::Point& hot) {
    138   // NOTIMPLEMENTED();
    139 }
    140 
    141 void CursorLoaderWin::LoadAnimatedCursor(int id,
    142                                          int resource_id,
    143                                          const gfx::Point& hot,
    144                                          int frame_delay_ms) {
    145   // NOTIMPLEMENTED();
    146 }
    147 
    148 void CursorLoaderWin::UnloadAll() {
    149   // NOTIMPLEMENTED();
    150 }
    151 
    152 void CursorLoaderWin::SetPlatformCursor(gfx::NativeCursor* cursor) {
    153 #if defined(USE_AURA)
    154   if (cursor->native_type() != kCursorCustom) {
    155     if (cursor->platform()) {
    156       cursor->SetPlatformCursor(cursor->platform());
    157     } else {
    158       const wchar_t* cursor_id = GetCursorId(*cursor);
    159       PlatformCursor platform_cursor = LoadCursor(NULL, cursor_id);
    160       if (!platform_cursor && !g_cursor_resource_module_name.Get().empty()) {
    161         platform_cursor = LoadCursor(
    162             GetModuleHandle(g_cursor_resource_module_name.Get().c_str()),
    163                             cursor_id);
    164       }
    165       cursor->SetPlatformCursor(platform_cursor);
    166     }
    167   }
    168 #endif
    169 }
    170 
    171 #if defined(USE_AURA)
    172 // static
    173 void CursorLoaderWin::SetCursorResourceModule(const string16& module_name) {
    174   g_cursor_resource_module_name.Get() = module_name;
    175 }
    176 #endif
    177 
    178 }  // namespace ui
    179