Fixed issue #1741: Push / Pull Dialog URL combo box should not be filled unless enabled
[TortoiseGit.git] / src / Utils / MiscUI / Cursor.h
blob7f184039a66fe482b80532cdc4bf72091505940e
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 SetCursor(CursorName);
56 CCursor()
58 ASSERT(this);
59 m_bInitialized = FALSE;
61 ~CCursor(void)
63 ASSERT(this);
64 Restore();
66 /**
67 * Sets a new cursor. If you previously set a new cursor then
68 * before setting a second cursor the old one is restored and
69 * then the new one is set.
71 HCURSOR SetCursor(LPCTSTR CursorName)
73 //first restore possible old cursor before setting new one
74 Restore();
75 //try to load system cursor
76 HCURSOR NewCursor = ::LoadCursor(NULL, CursorName);
77 if(!NewCursor)
78 //try to load application cursor
79 NewCursor = ::LoadCursor(AfxGetResourceHandle(), CursorName);
80 if(NewCursor)
82 m_hOldCursor = ::SetCursor(NewCursor);
83 m_bInitialized = TRUE;
85 else
87 m_bInitialized = FALSE;
88 TRACE("cursor not found!\n");
90 return m_hOldCursor;
92 /**
93 * Restores the cursor.
95 void Restore()
97 ASSERT(this);
98 if(m_bInitialized)
100 ::SetCursor(m_hOldCursor);
101 m_hOldCursor = NULL;
103 m_bInitialized = FALSE;
106 private:
107 HCURSOR m_hOldCursor;
108 BOOL m_bInitialized;