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 "base/lazy_instance.h"
      6 #include "base/strings/string16.h"
      7 #include "ui/base/cursor/cursor_loader_win.h"
      8 #include "grit/ui_unscaled_resources.h"
      9 
     10 namespace ui {
     11 
     12 #if defined(USE_AURA)
     13 
     14 namespace {
     15 
     16 base::LazyInstance<string16> g_cursor_resource_module_name;
     17 
     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;
    113   }
    114 }
    115 
    116 }  // namespace
    117 
    118 #endif
    119 
    120 CursorLoader* CursorLoader::Create() {
    121   return new CursorLoaderWin;
    122 }
    123 
    124 CursorLoaderWin::CursorLoaderWin() {
    125 }
    126 
    127 CursorLoaderWin::~CursorLoaderWin() {
    128 }
    129 
    130 void CursorLoaderWin::LoadImageCursor(int id,
    131                                       int resource_id,
    132                                       const gfx::Point& hot) {
    133   // NOTIMPLEMENTED();
    134 }
    135 
    136 void CursorLoaderWin::LoadAnimatedCursor(int id,
    137                                          int resource_id,
    138                                          const gfx::Point& hot,
    139                                          int frame_delay_ms) {
    140   // NOTIMPLEMENTED();
    141 }
    142 
    143 void CursorLoaderWin::UnloadAll() {
    144   // NOTIMPLEMENTED();
    145 }
    146 
    147 void CursorLoaderWin::SetPlatformCursor(gfx::NativeCursor* cursor) {
    148 #if defined(USE_AURA)
    149   if (cursor->native_type() != kCursorCustom) {
    150     if (cursor->platform()) {
    151       cursor->SetPlatformCursor(cursor->platform());
    152     } else {
    153       const wchar_t* cursor_id = GetCursorId(*cursor);
    154       PlatformCursor platform_cursor = LoadCursor(NULL, cursor_id);
    155       if (!platform_cursor && !g_cursor_resource_module_name.Get().empty()) {
    156         platform_cursor = LoadCursor(
    157             GetModuleHandle(g_cursor_resource_module_name.Get().c_str()),
    158                             cursor_id);
    159       }
    160       cursor->SetPlatformCursor(platform_cursor);
    161     }
    162   }
    163 #endif
    164 }
    165 
    166 #if defined(USE_AURA)
    167 // static
    168 void CursorLoaderWin::SetCursorResourceModule(const string16& module_name) {
    169   g_cursor_resource_module_name.Get() = module_name;
    170 }
    171 #endif
    172 
    173 }  // namespace ui
    174