ReactOS  0.4.14-dev-55-g2da92ac
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,
38  WPARAM wParam,
39  LPARAM lParam)
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
109  SetCapture(hWnd);
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 
159  wc.hInstance = g_hDllModule;
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 
173  font = CreateFontIndirect(&lf);
174 
175  //
176  // Calculate Tool Tip Window size
177  //
178 
179  dc = GetDC(hParent);
180 
181  SelectObject(dc, font);
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 
208  GetCursorPos(&pt);
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  //
220  scr_x = GetSystemMetrics(SM_CXSCREEN);
221  scr_y = GetSystemMetrics(SM_CYSCREEN);
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;
275  CHAR path[MAX_PATH];
276  CHAR desc[MAX_PATH];
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) {
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) {
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 }
#define WM_MBUTTONUP
Definition: winuser.h:1765
PSTR ModuleMessage(DWORD nFormat,...)
Definition: vfdlib.c:124
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WM_LBUTTONDOWN
Definition: winuser.h:1758
UCHAR VFD_DISKTYPE
Definition: vfdtypes.h:60
HDC WINAPI GetDC(_In_opt_ HWND)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
Definition: mk_font.cpp:20
#define pt(x, y)
Definition: drawing.c:79
const WCHAR * text
Definition: package.c:1827
char CHAR
Definition: xmlstorage.h:175
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
void WINAPI VfdToolTip(HWND hParent, PCSTR sText, int pos_x, int pos_y, BOOL stick)
Definition: vfdguitip.c:134
#define SystemParametersInfo
Definition: winuser.h:5759
LONG top
Definition: windef.h:292
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define GWL_EXSTYLE
Definition: winuser.h:845
HWND WINAPI SetFocus(_In_opt_ HWND)
HDC dc
Definition: cylfrac.c:34
UINT_PTR WPARAM
Definition: windef.h:207
UCHAR VFD_FLAGS
Definition: vfdtypes.h:63
HBRUSH hbrBackground
Definition: winuser.h:3144
LONG left
Definition: windef.h:291
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2635
LONG right
Definition: windef.h:293
BOOL WINAPI DestroyWindow(_In_ HWND)
#define SetWindowLongPtr
Definition: treelist.c:70
DWORD WINAPI GetSysColor(_In_ int)
WPARAM wParam
Definition: combotst.c:138
#define DrawText
Definition: winuser.h:5672
BOOL WINAPI TrackMouseEvent(_Inout_ LPTRACKMOUSEEVENT)
#define GetWindowText
Definition: winuser.h:5699
#define COLOR_INFOBK
Definition: winuser.h:932
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1032
#define SM_CXSCREEN
Definition: winuser.h:949
#define DT_LEFT
Definition: winuser.h:534
#define DT_CALCRECT
Definition: winuser.h:526
unsigned int BOOL
Definition: ntddk_ex.h:94
#define WM_SETCURSOR
Definition: winuser.h:1618
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
HWND WINAPI GetCapture(void)
Definition: message.c:2879
#define WM_MOUSELEAVE
Definition: commctrl.h:4946
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HCURSOR hCursor
Definition: winuser.h:3143
#define CreateWindowEx
Definition: winuser.h:5656
#define TRANSPARENT
Definition: wingdi.h:949
#define GWLP_USERDATA
Definition: treelist.c:63
const struct builtin_class_descr * desc
Definition: regcontrol.c:48
smooth NULL
Definition: ftsmooth.c:416
LONG cx
Definition: windef.h:319
LONG_PTR LPARAM
Definition: windef.h:208
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define WM_RBUTTONDOWN
Definition: winuser.h:1761
#define VFD_FLAG_WRITE_PROTECTED
Definition: vfdtypes.h:68
#define SM_CYSCREEN
Definition: winuser.h:950
#define WM_KILLFOCUS
Definition: winuser.h:1596
if(!(yy_init))
Definition: macro.lex.yy.c:714
PCSTR SystemMessage(DWORD nError)
Definition: vfdlib.c:147
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:8
HINSTANCE g_hDllModule
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
void WINAPI VfdImageTip(HWND hParent, ULONG nDevice)
Definition: vfdguitip.c:266
FD_TYPE file_type(FDSC **curr, char *fixed)
Definition: file.c:221
#define WM_RBUTTONUP
Definition: winuser.h:1762
PCSTR WINAPI VfdMediaTypeName(VFD_MEDIA nMediaType)
Definition: vfdctl.c:3280
#define WM_PAINT
Definition: winuser.h:1602
int ret
UCHAR VFD_FILETYPE
Definition: vfdtypes.h:62
#define GetWindowLong
Definition: winuser.h:5697
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
GLenum GLsizei len
Definition: glext.h:6722
#define WS_EX_TOPMOST
Definition: pedump.c:647
HANDLE WINAPI VfdOpenDevice(ULONG nTarget)
Definition: vfdctl.c:1215
LPCSTR lpszClassName
Definition: winuser.h:3146
#define COLOR_INFOTEXT
Definition: winuser.h:931
#define GetFileAttributes
Definition: winbase.h:3632
#define LoadCursor
Definition: winuser.h:5713
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
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:888
static HDC hDC
Definition: 3dtext.c:33
HWND WINAPI SetCapture(_In_ HWND hWnd)
#define WS_BORDER
Definition: pedump.c:625
HINSTANCE hInstance
Definition: winuser.h:3141
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define TME_LEAVE
Definition: commctrl.h:4952
#define WM_LBUTTONUP
Definition: winuser.h:1759
#define WM_MBUTTONDOWN
Definition: winuser.h:1764
Definition: services.c:325
signed char * PSTR
Definition: retypes.h:7
#define VFD_INFOTIP_WNDCLASS
Definition: vfdguitip.c:30
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define DT_TOP
Definition: winuser.h:542
#define WS_POPUP
Definition: pedump.c:616
static LRESULT CALLBACK ToolTipProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: vfdguitip.c:35
#define CreateFontIndirect
Definition: wingdi.h:4439
unsigned int UINT
Definition: ndis.h:50
#define SPI_GETICONTITLELOGFONT
Definition: winuser.h:1362
WNDPROC lpfnWndProc
Definition: winuser.h:3138
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define IDC_ARROW
Definition: winuser.h:682
#define GetTextExtentPoint32
Definition: wingdi.h:4467
#define WM_CREATE
Definition: winuser.h:1590
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
LONG bottom
Definition: windef.h:294
void WINAPI VfdMakeFileDesc(PSTR pBuffer, ULONG nBufSize, VFD_FILETYPE nFileType, ULONG nFileSize, DWORD nFileAttr)
Definition: vfdguiut.c:376
const char * PCSTR
Definition: typedefs.h:51
#define RegisterClass
Definition: winuser.h:5737
#define GetWindowLongPtr
Definition: treelist.c:73
LONG_PTR LRESULT
Definition: windef.h:209
#define WS_VISIBLE
Definition: pedump.c:620
LONG cy
Definition: windef.h:320
LPARAM lParam
Definition: combotst.c:139
UCHAR VFD_MEDIA
Definition: vfdtypes.h:61
static GLint image_size(GLint width, GLint height, GLenum format, GLenum type)
Definition: mipmap.c:4856