Allow to put URLs into "<>" and allow spaces and other chars there (as the RichEdit...
[TortoiseGit.git] / src / Utils / MiscUI / Cursor.h
bloba6a657aa903698019c2a193e7e4d0e7f8218ba2c
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006 - Stefan Kueng
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
21 /**
22 * \ingroup Utils
23 * Helper class for setting mouse cursors.\n
24 * There are two ways of using this class:
25 * -# Just declare a CCursor object with the
26 * required cursor. As soon as the object
27 * goes out of scope the previous cursor
28 * is restored.
29 * \code
30 * someMethod()
31 * {
32 * CCursor(IDC_WAIT);
33 * //do something here
34 * }
35 * //now CCursor is out of scope and the default cursor is restored
36 * \endcode
37 * -# use the object the usual way. Declare a CCursor object
38 * and use the methods to set the cursors.
40 * \remark the class can be used on Win95 and NT4 too, but the
41 * hand cursor won't be available.
43 class CCursor
45 public:
46 /**
47 * Constructs a CCursor object.
49 CCursor(LPCTSTR CursorName)
51 ASSERT(this);
52 m_bInitialized = FALSE;
53 m_hOldCursor = nullptr;
54 SetCursor(CursorName);
57 CCursor()
59 ASSERT(this);
60 m_bInitialized = FALSE;
61 m_hOldCursor = nullptr;
63 ~CCursor(void)
65 ASSERT(this);
66 Restore();
68 /**
69 * Sets a new cursor. If you previously set a new cursor then
70 * before setting a second cursor the old one is restored and
71 * then the new one is set.
73 HCURSOR SetCursor(LPCTSTR CursorName)
75 //first restore possible old cursor before setting new one
76 Restore();
77 //try to load system cursor
78 HCURSOR NewCursor = ::LoadCursor(NULL, CursorName);
79 if(!NewCursor)
80 //try to load application cursor
81 NewCursor = ::LoadCursor(AfxGetResourceHandle(), CursorName);
82 if(NewCursor)
84 m_hOldCursor = ::SetCursor(NewCursor);
85 m_bInitialized = TRUE;
87 else
89 m_bInitialized = FALSE;
90 TRACE("cursor not found!\n");
92 return m_hOldCursor;
94 /**
95 * Restores the cursor.
97 void Restore()
99 ASSERT(this);
100 if(m_bInitialized)
102 ::SetCursor(m_hOldCursor);
103 m_hOldCursor = NULL;
105 m_bInitialized = FALSE;
108 private:
109 HCURSOR m_hOldCursor;
110 BOOL m_bInitialized;