summaryrefslogtreecommitdiff
path: root/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx')
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx114
1 files changed, 54 insertions, 60 deletions
diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
index 10c6a7b38..ab20cfe32 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
@@ -1,6 +1,4 @@
//
-// "$Id$"
-//
// Definition of Windows system driver for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2020 by Bill Spitzak and others.
@@ -11,9 +9,9 @@
//
// https://www.fltk.org/COPYING.php
//
-// Please report all bugs and problems on the following page:
+// Please see the following page on how to report bugs and issues:
//
-// https://www.fltk.org/str.php
+// https://www.fltk.org/bugs.php
//
#include "../../config_lib.h"
@@ -92,12 +90,12 @@ extern "C" {
Pseudo doxygen docs (static function intentionally not documented):
- param[in] utf8 input string (UTF-8)
- param[in,out] wbuf in: pointer to output string buffer
- out: new string (the pointer may be changed)
- param[in] lg optional: input string length (default = -1)
+ param[in] utf8 input string (UTF-8)
+ param[in,out] wbuf in: pointer to output string buffer
+ out: new string (the pointer may be changed)
+ param[in] lg optional: input string length (default = -1)
- returns pointer to string buffer
+ returns pointer to string buffer
*/
static wchar_t *utf8_to_wchar(const char *utf8, wchar_t *&wbuf, int lg = -1) {
unsigned len = (lg >= 0) ? (unsigned)lg : (unsigned)strlen(utf8);
@@ -129,11 +127,11 @@ static wchar_t *utf8_to_wchar(const char *utf8, wchar_t *&wbuf, int lg = -1) {
Pseudo doxygen docs (static function intentionally not documented):
- param[in] wstr input string (wide character, UTF-16)
- param[in,out] utf8 in: pointer to output string buffer
- out: new string (pointer may be changed)
+ param[in] wstr input string (wide character, UTF-16)
+ param[in,out] utf8 in: pointer to output string buffer
+ out: new string (pointer may be changed)
- returns pointer to string buffer
+ returns pointer to string buffer
*/
static char *wchar_to_utf8(const wchar_t *wstr, char *&utf8) {
unsigned len = (unsigned)wcslen(wstr);
@@ -146,7 +144,7 @@ static char *wchar_to_utf8(const wchar_t *wstr, char *&utf8) {
/*
Creates a driver that manages all system related calls.
-
+
This function must be implemented once for every platform.
*/
Fl_System_Driver *Fl_System_Driver::newSystemDriver()
@@ -239,7 +237,7 @@ int Fl_WinAPI_System_Driver::execvp(const char *file, char *const *argv) {
# else
wchar_t **ar;
utf8_to_wchar(file, wbuf);
-
+
int i = 0, n = 0;
while (argv[i]) {i++; n++;}
ar = (wchar_t **)malloc(sizeof(wchar_t *) * (n + 1));
@@ -254,14 +252,14 @@ int Fl_WinAPI_System_Driver::execvp(const char *file, char *const *argv) {
i++;
}
ar[n] = NULL;
- _wexecvp(wbuf, ar); // STR #3040
+ _wexecvp(wbuf, ar); // STR #3040
i = 0;
while (i < n) {
free(ar[i]);
i++;
}
free(ar);
- return -1; // STR #3040
+ return -1; // STR #3040
#endif
}
@@ -362,7 +360,7 @@ char *fl_locale_to_utf8(const char *s, int len, UINT codepage)
}
if (codepage < 1) codepage = fl_codepage;
buf[l] = 0;
-
+
l = MultiByteToWideChar(codepage, 0, s, len, (WCHAR*)wbufa, buf_len);
if (l < 0) l = 0;
wbufa[l] = 0;
@@ -503,16 +501,16 @@ int Fl_WinAPI_System_Driver::filename_expand(char *to, int tolen, const char *fr
char *start = temp;
char *end = temp+strlen(temp);
int ret = 0;
- for (char *a=temp; a<end; ) { // for each slash component
+ for (char *a=temp; a<end; ) { // for each slash component
char *e; for (e=a; e<end && !isdirsep(*e); e++) {/*empty*/} // find next slash
const char *value = 0; // this will point at substitute value
switch (*a) {
- case '~': // a home directory name
- if (e <= a+1) { // current user's directory
+ case '~': // a home directory name
+ if (e <= a+1) { // current user's directory
value = getenv("HOME");
}
break;
- case '$': /* an environment variable */
+ case '$': /* an environment variable */
{char t = *e; *(char *)e = 0; value = getenv(a+1); *(char *)e = t;}
break;
}
@@ -539,16 +537,16 @@ int Fl_WinAPI_System_Driver::filename_expand(char *to, int tolen, const char *fr
}
int // O - 0 if no change, 1 if changed
-Fl_WinAPI_System_Driver::filename_relative(char *to, // O - Relative filename
+Fl_WinAPI_System_Driver::filename_relative(char *to, // O - Relative filename
int tolen, // I - Size of "to" buffer
const char *from, // I - Absolute filename
const char *base) // I - Find path relative to this path
{
- char *newslash; // Directory separator
- const char *slash; // Directory separator
+ char *newslash; // Directory separator
+ const char *slash; // Directory separator
char *cwd = 0L, *cwd_buf = 0L;
if (base) cwd = cwd_buf = strdup(base);
-
+
// return if "from" is not an absolute path
if (from[0] == '\0' ||
(!isdirsep(*from) && !isalpha(*from) && from[1] != ':' &&
@@ -557,7 +555,7 @@ Fl_WinAPI_System_Driver::filename_relative(char *to, // O - Relative filename
if (cwd_buf) free(cwd_buf);
return 0;
}
-
+
// return if "cwd" is not an absolute path
if (!cwd || cwd[0] == '\0' ||
(!isdirsep(*cwd) && !isalpha(*cwd) && cwd[1] != ':' &&
@@ -566,18 +564,18 @@ Fl_WinAPI_System_Driver::filename_relative(char *to, // O - Relative filename
if (cwd_buf) free(cwd_buf);
return 0;
}
-
+
// convert all backslashes into forward slashes
for (newslash = strchr(cwd, '\\'); newslash; newslash = strchr(newslash + 1, '\\'))
*newslash = '/';
-
+
// test for the exact same string and return "." if so
if (!strcasecmp(from, cwd)) {
strlcpy(to, ".", tolen);
free(cwd_buf);
return (1);
}
-
+
// test for the same drive. Return the absolute path if not
if (tolower(*from & 255) != tolower(*cwd & 255)) {
// Not the same drive...
@@ -585,44 +583,44 @@ Fl_WinAPI_System_Driver::filename_relative(char *to, // O - Relative filename
free(cwd_buf);
return 0;
}
-
+
// compare the path name without the drive prefix
from += 2; cwd += 2;
-
+
// compare both path names until we find a difference
for (slash = from, newslash = cwd;
*slash != '\0' && *newslash != '\0';
slash ++, newslash ++)
if (isdirsep(*slash) && isdirsep(*newslash)) continue;
else if (tolower(*slash & 255) != tolower(*newslash & 255)) break;
-
+
// skip over trailing slashes
if ( *newslash == '\0' && *slash != '\0' && !isdirsep(*slash)
&&(newslash==cwd || !isdirsep(newslash[-1])) )
newslash--;
-
+
// now go back to the first character of the first differing paths segment
while (!isdirsep(*slash) && slash > from) slash --;
if (isdirsep(*slash)) slash ++;
-
+
// do the same for the current dir
if (isdirsep(*newslash)) newslash --;
if (*newslash != '\0')
while (!isdirsep(*newslash) && newslash > cwd) newslash --;
-
+
// prepare the destination buffer
to[0] = '\0';
to[tolen - 1] = '\0';
-
+
// now add a "previous dir" sequence for every following slash in the cwd
while (*newslash != '\0') {
if (isdirsep(*newslash)) strlcat(to, "../", tolen);
newslash ++;
}
-
+
// finally add the differing path from "from"
strlcat(to, slash, tolen);
-
+
free(cwd_buf);
return 1;
}
@@ -668,9 +666,9 @@ int Fl_WinAPI_System_Driver::filename_absolute(char *to, int tolen, const char *
int Fl_WinAPI_System_Driver::filename_isdir(const char *n)
{
- struct _stat s;
- char fn[FL_PATH_MAX];
- int length;
+ struct _stat s;
+ char fn[FL_PATH_MAX];
+ int length;
length = (int) strlen(n);
// This workaround brought to you by the fine folks at Microsoft!
// (read lots of sarcasm in that...)
@@ -711,7 +709,7 @@ const char *Fl_WinAPI_System_Driver::filename_ext(const char *buf) {
int Fl_WinAPI_System_Driver::open_uri(const char *uri, char *msg, int msglen)
{
- if (msg) snprintf(msg, msglen, "open %s", uri);
+ if (msg) snprintf(msg, msglen, "open %s", uri);
return (int)(ShellExecute(HWND_DESKTOP, "open", uri, NULL, NULL, SW_SHOW) > (void *)32);
}
@@ -734,7 +732,7 @@ int Fl_WinAPI_System_Driver::file_browser_load_filesystem(Fl_File_Browser *brows
//
// Normal Windows code uses drive bits...
//
- DWORD drives; // Drive available bits
+ DWORD drives; // Drive available bits
drives = GetLogicalDrives();
for (int i = 'A'; i <= 'Z'; i ++, drives >>= 1)
if (drives & 1)
@@ -773,19 +771,19 @@ void Fl_WinAPI_System_Driver::newUUID(char *uuidBuffer)
UUID ud;
UUID *pu = &ud;
int got_uuid = 0;
-
- if (!hMod) { // first time in?
+
+ if (!hMod) { // first time in?
hMod = LoadLibrary("Rpcrt4.dll");
}
-
- if (hMod) { // do we have a usable handle to Rpcrt4.dll?
+
+ if (hMod) { // do we have a usable handle to Rpcrt4.dll?
uuid_func uuid_crt = (uuid_func)GetProcAddress(hMod, "UuidCreate");
if (uuid_crt != NULL) {
RPC_STATUS rpc_res = uuid_crt(pu);
if ( // is the return status OK for our needs?
- (rpc_res == RPC_S_OK) || // all is well
+ (rpc_res == RPC_S_OK) || // all is well
(rpc_res == RPC_S_UUID_LOCAL_ONLY) || // only unique to this machine
- (rpc_res == RPC_S_UUID_NO_ADDRESS) // probably only locally unique
+ (rpc_res == RPC_S_UUID_NO_ADDRESS) // probably only locally unique
) {
got_uuid = -1;
sprintf(uuidBuffer, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
@@ -795,14 +793,14 @@ void Fl_WinAPI_System_Driver::newUUID(char *uuidBuffer)
}
}
}
- if (got_uuid == 0) { // did not make a UUID - use fallback logic
+ if (got_uuid == 0) { // did not make a UUID - use fallback logic
unsigned char b[16];
- time_t t = time(0); // first 4 byte
+ time_t t = time(0); // first 4 byte
b[0] = (unsigned char)t;
b[1] = (unsigned char)(t>>8);
b[2] = (unsigned char)(t>>16);
b[3] = (unsigned char)(t>>24);
- int r = rand(); // four more bytes
+ int r = rand(); // four more bytes
b[4] = (unsigned char)r;
b[5] = (unsigned char)(r>>8);
b[6] = (unsigned char)(r>>16);
@@ -836,8 +834,8 @@ void Fl_WinAPI_System_Driver::newUUID(char *uuidBuffer)
char *Fl_WinAPI_System_Driver::preference_rootnode(Fl_Preferences *prefs, Fl_Preferences::Root root, const char *vendor,
const char *application)
{
-# define FLPREFS_RESOURCE "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"
-# define FLPREFS_RESOURCEW L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"
+# define FLPREFS_RESOURCE "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"
+# define FLPREFS_RESOURCEW L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"
static char *filename = 0L;
// make enough room for a UTF16 pathname
if (!filename) filename = (char*)::malloc(2*FL_PATH_MAX);
@@ -847,7 +845,7 @@ char *Fl_WinAPI_System_Driver::preference_rootnode(Fl_Preferences *prefs, Fl_Pre
DWORD nn;
LONG err;
HKEY key;
-
+
switch (root&Fl_Preferences::ROOT_MASK) {
case Fl_Preferences::SYSTEM:
err = RegOpenKeyW( HKEY_LOCAL_MACHINE, FLPREFS_RESOURCEW, &key );
@@ -953,7 +951,3 @@ void Fl_WinAPI_System_Driver::gettime(time_t *sec, int *usec) {
*sec = t.time;
*usec = t.millitm * 1000;
}
-
-//
-// End of "$Id$".
-//