ReactOS 0.4.15-dev-8145-ga541a46
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
45 (LONG_PTR)((LPCREATESTRUCT)lParam)->lpCreateParams);
46 return 0;
47
48 case WM_PAINT:
49 {
50 PAINTSTRUCT paint;
51 HDC hDC = BeginPaint(hWnd, &paint);
52
53 if (hDC) {
54 char text[MAX_PATH];
55 int len;
56 RECT rc;
57
58
60
63
64 len = GetWindowText(hWnd, text, sizeof(text));
65
66 rc.top = 8;
67 rc.left = 8;
68 rc.right = paint.rcPaint.right;
69 rc.bottom = paint.rcPaint.bottom;
70
71 DrawText(hDC, text, len, &rc, DT_LEFT | DT_TOP);
72
73 EndPaint(hWnd, &paint);
74 }
75 }
76 return 0;
77
78 case WM_KILLFOCUS:
80 // Stick tool tip - Closed on kill focus
82 }
83 return 0;
84
85 case WM_SETCURSOR:
87 // Non-stick tool tip - Closed when cursor leaves
88 TRACKMOUSEEVENT track;
89
90 track.cbSize = sizeof(track);
91 track.dwFlags = TME_LEAVE;
92 track.hwndTrack = hWnd;
93 track.dwHoverTime = 0;
94
95 TrackMouseEvent(&track);
96 }
97 return 0;
98
99 case WM_MOUSELEAVE:
100 // Non-stick tool tip - Closed when cursor leaves
102 return 0;
103
104 case WM_LBUTTONDOWN:
105 case WM_MBUTTONDOWN:
106 case WM_RBUTTONDOWN:
107 // Both stick and non-stick tool tip
108 // Closed when clicked
110 return 0;
111
112 case WM_LBUTTONUP:
113 case WM_MBUTTONUP:
114 case WM_RBUTTONUP:
115 // Both stick and non-stick tool tip
116 // Closed when clicked
117 if (GetCapture() == hWnd) {
119 }
120 return 0;
121
122 case WM_DESTROY:
123 // delete font
125 return 0;
126 }
127
128 return DefWindowProc(hWnd, uMsg, wParam, lParam);
129}
130
131//
132// Create and show tooltip window
133//
135 HWND hParent,
136 PCSTR sText,
137 int pos_x,
138 int pos_y,
139 BOOL stick)
140{
141#ifndef __REACTOS__
142 HWND hWnd;
143#endif
144 WNDCLASS wc = {0};
145 LOGFONT lf;
146 HFONT font;
147 HDC dc;
148 int len;
149 SIZE sz;
150 RECT rc;
151 int scr_x;
152 int scr_y;
153
154 //
155 // Register Window Class
156 //
157
161 wc.hbrBackground = (HBRUSH)(COLOR_INFOBK + 1);
163
164 RegisterClass(&wc);
165
166 //
167 // Create Tool Tip Font (== Icon title font)
168 //
169
171 SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
172
174
175 //
176 // Calculate Tool Tip Window size
177 //
178
179 dc = GetDC(hParent);
180
182
183 len = strlen(sText);
184
185 GetTextExtentPoint32(dc, sText, len, &sz);
186
187 rc.left = 0;
188 rc.top = 0;
189 rc.right = sz.cx;
190 rc.bottom = sz.cy;
191
192 DrawText(dc, sText, len, &rc, DT_CALCRECT | DT_LEFT | DT_TOP);
193
194 ReleaseDC(hParent, dc);
195
196 sz.cx = rc.right - rc.left + 16;
197 sz.cy = rc.bottom - rc.top + 16;
198
199 //
200 // Decide the window position
201 //
202 if (pos_x == -1 || pos_y == -1) {
203 //
204 // Use current cursor position
205 //
206 POINT pt;
207
209
210 pos_x = pt.x - (sz.cx / 2);
211 pos_y = pt.y - (sz.cy / 2);
212 }
213 else {
214 pos_x = pos_x - (sz.cx / 2);
215 }
216
217 //
218 // make sure the tip window fits in visible area
219 //
222
223 if (pos_x < 0) {
224 pos_x = 0;
225 }
226 if (pos_x + sz.cx > scr_x) {
227 pos_x = scr_x - sz.cx;
228 }
229 if (pos_y < 0) {
230 pos_y = 0;
231 }
232 if (pos_y + sz.cy > scr_y) {
233 pos_y = scr_y - sz.cy;
234 }
235
236 //
237 // Create the tool tip window
238 //
239#ifndef __REACTOS__
241#else
243#endif
244 stick ? 0 : WS_EX_TOPMOST,
246 sText,
248 pos_x, pos_y,
249 sz.cx, sz.cy,
250 hParent,
251 NULL,
252 NULL,
253 (PVOID)font);
254
255 //
256 // Give focus if it is not a stick tool-tip
257 //
258 if (!stick) {
259 SetFocus(hParent);
260 }
261}
262
263//
264// Show an image information tooltip
265//
267 HWND hParent,
268 ULONG nDevice)
269{
270 HANDLE hDevice;
271 PSTR info_str = NULL;
272 PSTR type_str = NULL;
273 PSTR prot_str = NULL;
274 PCSTR media_str = NULL;
277 VFD_DISKTYPE disk_type;
278 VFD_MEDIA media_type;
279 VFD_FLAGS media_flags;
282 DWORD file_attr;
283 ULONG ret;
284
285 hDevice = VfdOpenDevice(nDevice);
286
287 if (hDevice == INVALID_HANDLE_VALUE) {
288 VfdToolTip(hParent,
289 SystemMessage(GetLastError()), -1, -1, FALSE);
290 return;
291 }
292
294 hDevice,
295 path,
296 &disk_type,
297 &media_type,
298 &media_flags,
299 &file_type,
300 &image_size);
301
302 CloseHandle(hDevice);
303
304 if (ret != ERROR_SUCCESS) {
305 VfdToolTip(hParent, SystemMessage(ret), -1, -1, FALSE);
306 return;
307 }
308
309 if (path[0]) {
310 file_attr = GetFileAttributes(path);
311 }
312 else {
313 if (disk_type != VFD_DISKTYPE_FILE) {
314 strcpy(path, "<RAM>");
315 }
316 file_attr = 0;
317 }
318
319 VfdMakeFileDesc(desc, sizeof(desc),
320 file_type, image_size, file_attr);
321
322 if (disk_type == VFD_DISKTYPE_FILE) {
323 type_str = "FILE";
324 }
325 else {
326 type_str = "RAM";
327 }
328
329 media_str = VfdMediaTypeName(media_type);
330
331 if (media_flags & VFD_FLAG_WRITE_PROTECTED) {
332 prot_str = ModuleMessage(MSG_WRITE_PROTECTED);
333 }
334 else {
335 prot_str = ModuleMessage(MSG_WRITE_ALLOWED);
336 }
337
338 info_str = ModuleMessage(
339 MSG_IMAGE_INFOTIP,
340 path,
341 desc,
342 type_str ? type_str : "",
343 media_str ? media_str : "",
344 prot_str ? prot_str : "");
345
346 if (info_str) {
347 VfdToolTip(hParent, info_str, -1, -1, FALSE);
348 LocalFree(info_str);
349 }
350
351 if (prot_str) {
352 LocalFree(prot_str);
353 }
354}
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:1799
#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:92
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
#define TME_LEAVE
Definition: commctrl.h:4981
#define WM_MOUSELEAVE
Definition: commctrl.h:4975
#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:3170
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
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:266
void WINAPI VfdToolTip(HWND hParent, PCSTR sText, int pos_x, int pos_y, BOOL stick)
Definition: vfdguitip.c:134
#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:3815
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:1539
#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:1620
HWND WINAPI SetCapture(_In_ HWND hWnd)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define CreateWindowEx
Definition: winuser.h:5755
DWORD WINAPI GetSysColor(_In_ int)
#define COLOR_INFOBK
Definition: winuser.h:942
#define SM_CYSCREEN
Definition: winuser.h:960
#define WM_CREATE
Definition: winuser.h:1608
#define IDC_ARROW
Definition: winuser.h:687
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2701
#define WM_RBUTTONUP
Definition: winuser.h:1780
HWND WINAPI GetCapture(void)
Definition: message.c:2881
BOOL WINAPI TrackMouseEvent(_Inout_ LPTRACKMOUSEEVENT)
#define SPI_GETICONTITLELOGFONT
Definition: winuser.h:1380
#define WM_LBUTTONDOWN
Definition: winuser.h:1776
#define DrawText
Definition: winuser.h:5771
#define WM_RBUTTONDOWN
Definition: winuser.h:1779
#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:941
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define LoadCursor
Definition: winuser.h:5812
HDC WINAPI GetDC(_In_opt_ HWND)
#define GetWindowLong
Definition: winuser.h:5796
#define WM_LBUTTONUP
Definition: winuser.h:1777
#define GetWindowText
Definition: winuser.h:5798
#define WM_SETCURSOR
Definition: winuser.h:1636
#define RegisterClass
Definition: winuser.h:5836
#define WM_DESTROY
Definition: winuser.h:1609
#define SM_CXSCREEN
Definition: winuser.h:959
#define DT_CALCRECT
Definition: winuser.h:526
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define SystemParametersInfo
Definition: winuser.h:5858
#define WM_MBUTTONUP
Definition: winuser.h:1783
BOOL WINAPI DestroyWindow(_In_ HWND)
#define WM_KILLFOCUS
Definition: winuser.h:1614
int WINAPI GetSystemMetrics(_In_ int)
#define WM_MBUTTONDOWN
Definition: winuser.h:1782
#define GWL_EXSTYLE
Definition: winuser.h:851
char CHAR
Definition: xmlstorage.h:175