ReactOS 0.4.16-dev-334-g4d9f67c
vfdguitip.c
Go to the documentation of this file.
1/*
2 vfdguitip.c
3
4 Virtual Floppy Drive for Windows
5 Driver control library
6 tooltip information GUI utility functions
7
8 Copyright (c) 2003-2005 Ken Kato
9*/
10
11#ifdef __cplusplus
12#pragma message(__FILE__": Compiled as C++ for testing purpose.")
13#endif // __cplusplus
14
15#define WIN32_LEAN_AND_MEAN
16#include <windows.h>
17
18#include "vfdtypes.h"
19#include "vfdapi.h"
20#include "vfdlib.h"
21#ifndef __REACTOS__
22#include "vfdmsg.h"
23#else
24#include "vfdmsg_lib.h"
25#endif
26
27//
28// tooltip window class name
29//
30#define VFD_INFOTIP_WNDCLASS "VfdInfoTip"
31
32//
33// the window procedure
34//
36 HWND hWnd,
37 UINT uMsg,
40{
41 switch (uMsg) {
42 case WM_CREATE:
43 // Store Font handle
44#ifndef __REACTOS__
46 (LONG)((LPCREATESTRUCT)lParam)->lpCreateParams);
47#else
49 (LONG_PTR)((LPCREATESTRUCT)lParam)->lpCreateParams);
50#endif
51 return 0;
52
53 case WM_PAINT:
54 {
55 PAINTSTRUCT paint;
56 HDC hDC = BeginPaint(hWnd, &paint);
57
58 if (hDC) {
59 char text[MAX_PATH];
60 int len;
61 RECT rc;
62
63
64#ifndef __REACTOS__
66#else
68#endif
69
72
73 len = GetWindowText(hWnd, text, sizeof(text));
74
75 rc.top = 8;
76 rc.left = 8;
77 rc.right = paint.rcPaint.right;
78 rc.bottom = paint.rcPaint.bottom;
79
80 DrawText(hDC, text, len, &rc, DT_LEFT | DT_TOP);
81
82 EndPaint(hWnd, &paint);
83 }
84 }
85 return 0;
86
87 case WM_KILLFOCUS:
89 // Stick tool tip - Closed on kill focus
91 }
92 return 0;
93
94 case WM_SETCURSOR:
96 // Non-stick tool tip - Closed when cursor leaves
97 TRACKMOUSEEVENT track;
98
99 track.cbSize = sizeof(track);
100 track.dwFlags = TME_LEAVE;
101 track.hwndTrack = hWnd;
102 track.dwHoverTime = 0;
103
104 TrackMouseEvent(&track);
105 }
106 return 0;
107
108 case WM_MOUSELEAVE:
109 // Non-stick tool tip - Closed when cursor leaves
111 return 0;
112
113 case WM_LBUTTONDOWN:
114 case WM_MBUTTONDOWN:
115 case WM_RBUTTONDOWN:
116 // Both stick and non-stick tool tip
117 // Closed when clicked
119 return 0;
120
121 case WM_LBUTTONUP:
122 case WM_MBUTTONUP:
123 case WM_RBUTTONUP:
124 // Both stick and non-stick tool tip
125 // Closed when clicked
126 if (GetCapture() == hWnd) {
128 }
129 return 0;
130
131 case WM_DESTROY:
132 // delete font
133#ifndef __REACTOS__
135#else
137#endif
138 return 0;
139 }
140
141 return DefWindowProc(hWnd, uMsg, wParam, lParam);
142}
143
144//
145// Create and show tooltip window
146//
148 HWND hParent,
149 PCSTR sText,
150 int pos_x,
151 int pos_y,
152 BOOL stick)
153{
154#ifndef __REACTOS__
155 HWND hWnd;
156#endif
157 WNDCLASS wc = {0};
158 LOGFONT lf;
159 HFONT font;
160 HDC dc;
161 int len;
162 SIZE sz;
163 RECT rc;
164 int scr_x;
165 int scr_y;
166
167 //
168 // Register Window Class
169 //
170
174 wc.hbrBackground = (HBRUSH)(COLOR_INFOBK + 1);
176
177 RegisterClass(&wc);
178
179 //
180 // Create Tool Tip Font (== Icon title font)
181 //
182
184 SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
185
187
188 //
189 // Calculate Tool Tip Window size
190 //
191
192 dc = GetDC(hParent);
193
195
196 len = strlen(sText);
197
198 GetTextExtentPoint32(dc, sText, len, &sz);
199
200 rc.left = 0;
201 rc.top = 0;
202 rc.right = sz.cx;
203 rc.bottom = sz.cy;
204
205 DrawText(dc, sText, len, &rc, DT_CALCRECT | DT_LEFT | DT_TOP);
206
207 ReleaseDC(hParent, dc);
208
209 sz.cx = rc.right - rc.left + 16;
210 sz.cy = rc.bottom - rc.top + 16;
211
212 //
213 // Decide the window position
214 //
215 if (pos_x == -1 || pos_y == -1) {
216 //
217 // Use current cursor position
218 //
219 POINT pt;
220
222
223 pos_x = pt.x - (sz.cx / 2);
224 pos_y = pt.y - (sz.cy / 2);
225 }
226 else {
227 pos_x = pos_x - (sz.cx / 2);
228 }
229
230 //
231 // make sure the tip window fits in visible area
232 //
235
236 if (pos_x < 0) {
237 pos_x = 0;
238 }
239 if (pos_x + sz.cx > scr_x) {
240 pos_x = scr_x - sz.cx;
241 }
242 if (pos_y < 0) {
243 pos_y = 0;
244 }
245 if (pos_y + sz.cy > scr_y) {
246 pos_y = scr_y - sz.cy;
247 }
248
249 //
250 // Create the tool tip window
251 //
252#ifndef __REACTOS__
254#else
256#endif
257 stick ? 0 : WS_EX_TOPMOST,
259 sText,
261 pos_x, pos_y,
262 sz.cx, sz.cy,
263 hParent,
264 NULL,
265 NULL,
266 (PVOID)font);
267
268 //
269 // Give focus if it is not a stick tool-tip
270 //
271 if (!stick) {
272 SetFocus(hParent);
273 }
274}
275
276//
277// Show an image information tooltip
278//
280 HWND hParent,
281 ULONG nDevice)
282{
283 HANDLE hDevice;
284 PSTR info_str = NULL;
285 PSTR type_str = NULL;
286 PSTR prot_str = NULL;
287 PCSTR media_str = NULL;
290 VFD_DISKTYPE disk_type;
291 VFD_MEDIA media_type;
292 VFD_FLAGS media_flags;
295 DWORD file_attr;
296 ULONG ret;
297
298 hDevice = VfdOpenDevice(nDevice);
299
300 if (hDevice == INVALID_HANDLE_VALUE) {
301 VfdToolTip(hParent,
302 SystemMessage(GetLastError()), -1, -1, FALSE);
303 return;
304 }
305
307 hDevice,
308 path,
309 &disk_type,
310 &media_type,
311 &media_flags,
312 &file_type,
313 &image_size);
314
315 CloseHandle(hDevice);
316
317 if (ret != ERROR_SUCCESS) {
318 VfdToolTip(hParent, SystemMessage(ret), -1, -1, FALSE);
319 return;
320 }
321
322 if (path[0]) {
323 file_attr = GetFileAttributes(path);
324 }
325 else {
326 if (disk_type != VFD_DISKTYPE_FILE) {
327 strcpy(path, "<RAM>");
328 }
329 file_attr = 0;
330 }
331
332 VfdMakeFileDesc(desc, sizeof(desc),
333 file_type, image_size, file_attr);
334
335 if (disk_type == VFD_DISKTYPE_FILE) {
336 type_str = "FILE";
337 }
338 else {
339 type_str = "RAM";
340 }
341
342 media_str = VfdMediaTypeName(media_type);
343
344 if (media_flags & VFD_FLAG_WRITE_PROTECTED) {
345 prot_str = ModuleMessage(MSG_WRITE_PROTECTED);
346 }
347 else {
348 prot_str = ModuleMessage(MSG_WRITE_ALLOWED);
349 }
350
351 info_str = ModuleMessage(
352 MSG_IMAGE_INFOTIP,
353 path,
354 desc,
355 type_str ? type_str : "",
356 media_str ? media_str : "",
357 prot_str ? prot_str : "");
358
359 if (info_str) {
360 VfdToolTip(hParent, info_str, -1, -1, FALSE);
361 LocalFree(info_str);
362 }
363
364 if (prot_str) {
365 LocalFree(prot_str);
366 }
367}
static HDC hDC
Definition: 3dtext.c:33
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
HWND hWnd
Definition: settings.c:17
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
#define CALLBACK
Definition: compat.h:35
const WCHAR * text
Definition: package.c:1794
#define pt(x, y)
Definition: drawing.c:79
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
pKey DeleteObject()
GLenum GLsizei len
Definition: glext.h:6722
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
if(dx< 0)
Definition: linetemp.h:194
static const WCHAR dc[]
static GLint image_size(GLint width, GLint height, GLenum format, GLenum type)
Definition: mipmap.c:4858
static HDC
Definition: imagelist.c:88
static const WCHAR desc[]
Definition: protectdata.c:36
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
Definition: mk_font.cpp:20
unsigned int UINT
Definition: ndis.h:50
#define WS_BORDER
Definition: pedump.c:625
#define WS_POPUP
Definition: pedump.c:616
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_EX_TOPMOST
Definition: pedump.c:647
long LONG
Definition: pedump.c:60
#define TME_LEAVE
Definition: commctrl.h:4986
#define WM_MOUSELEAVE
Definition: commctrl.h:4980
#define DefWindowProc
Definition: ros2win.h:31
FD_TYPE file_type(FDSC **curr, char *fixed)
Definition: file.c:221
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
HBRUSH hbrBackground
Definition: winuser.h:3173
HINSTANCE hInstance
Definition: winuser.h:3170
HCURSOR hCursor
Definition: winuser.h:3172
LPCSTR lpszClassName
Definition: winuser.h:3175
WNDPROC lpfnWndProc
Definition: winuser.h:3167
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_USERDATA
Definition: treelist.c:63
char * PSTR
Definition: typedefs.h:51
const char * PCSTR
Definition: typedefs.h:52
uint32_t ULONG
Definition: typedefs.h:59
void WINAPI VfdMakeFileDesc(PSTR pBuffer, ULONG nBufSize, VFD_FILETYPE nFileType, ULONG nFileSize, DWORD nFileAttr)
Definition: vfdguiut.c:376
DWORD WINAPI VfdGetImageInfo(HANDLE hDevice, PSTR sFileName, PVFD_DISKTYPE pDiskType, PVFD_MEDIA pMediaType, PVFD_FLAGS pMediaFlags, PVFD_FILETYPE pFileType, PULONG pImageSize)
Definition: vfdctl.c:1839
HANDLE WINAPI VfdOpenDevice(ULONG nTarget)
Definition: vfdctl.c:1215
PCSTR WINAPI VfdMediaTypeName(VFD_MEDIA nMediaType)
Definition: vfdctl.c:3280
static LRESULT CALLBACK ToolTipProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: vfdguitip.c:35
void WINAPI VfdImageTip(HWND hParent, ULONG nDevice)
Definition: vfdguitip.c:279
void WINAPI VfdToolTip(HWND hParent, PCSTR sText, int pos_x, int pos_y, BOOL stick)
Definition: vfdguitip.c:147
#define VFD_INFOTIP_WNDCLASS
Definition: vfdguitip.c:30
PSTR ModuleMessage(DWORD nFormat,...)
Definition: vfdlib.c:124
HINSTANCE g_hDllModule
PCSTR SystemMessage(DWORD nError)
Definition: vfdlib.c:147
UCHAR VFD_FILETYPE
Definition: vfdtypes.h:62
UCHAR VFD_MEDIA
Definition: vfdtypes.h:61
UCHAR VFD_DISKTYPE
Definition: vfdtypes.h:60
@ VFD_DISKTYPE_FILE
Definition: vfdtypes.h:18
#define VFD_FLAG_WRITE_PROTECTED
Definition: vfdtypes.h:68
UCHAR VFD_FLAGS
Definition: vfdtypes.h:63
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetFileAttributes
Definition: winbase.h:3840
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define GetTextExtentPoint32
Definition: wingdi.h:4472
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
#define TRANSPARENT
Definition: wingdi.h:950
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:918
#define CreateFontIndirect
Definition: wingdi.h:4444
#define WM_PAINT
Definition: winuser.h:1623
HWND WINAPI SetCapture(_In_ HWND hWnd)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define CreateWindowEx
Definition: winuser.h:5767
DWORD WINAPI GetSysColor(_In_ int)
#define SetWindowLong
Definition: winuser.h:5865
#define COLOR_INFOBK
Definition: winuser.h:945
#define GWL_USERDATA
Definition: winuser.h:864
#define SM_CYSCREEN
Definition: winuser.h:963
#define WM_CREATE
Definition: winuser.h:1611
#define IDC_ARROW
Definition: winuser.h:687
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2722
#define WM_RBUTTONUP
Definition: winuser.h:1783
HWND WINAPI GetCapture(void)
Definition: message.c:2881
BOOL WINAPI TrackMouseEvent(_Inout_ LPTRACKMOUSEEVENT)
#define SPI_GETICONTITLELOGFONT
Definition: winuser.h:1383
#define WM_LBUTTONDOWN
Definition: winuser.h:1779
#define DrawText
Definition: winuser.h:5783
#define WM_RBUTTONDOWN
Definition: winuser.h:1782
#define DT_LEFT
Definition: winuser.h:534
#define DT_TOP
Definition: winuser.h:542
HWND WINAPI SetFocus(_In_opt_ HWND)
#define COLOR_INFOTEXT
Definition: winuser.h:944
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define LoadCursor
Definition: winuser.h:5824
HDC WINAPI GetDC(_In_opt_ HWND)
#define GetWindowLong
Definition: winuser.h:5808
#define WM_LBUTTONUP
Definition: winuser.h:1780
#define GetWindowText
Definition: winuser.h:5810
#define WM_SETCURSOR
Definition: winuser.h:1639
#define RegisterClass
Definition: winuser.h:5848
#define WM_DESTROY
Definition: winuser.h:1612
#define SM_CXSCREEN
Definition: winuser.h:962
#define DT_CALCRECT
Definition: winuser.h:526
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define SystemParametersInfo
Definition: winuser.h:5870
#define WM_MBUTTONUP
Definition: winuser.h:1786
BOOL WINAPI DestroyWindow(_In_ HWND)
#define WM_KILLFOCUS
Definition: winuser.h:1617
int WINAPI GetSystemMetrics(_In_ int)
#define WM_MBUTTONDOWN
Definition: winuser.h:1785
#define GWL_EXSTYLE
Definition: winuser.h:854
char CHAR
Definition: xmlstorage.h:175