summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>1999-12-29 03:14:41 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>1999-12-29 03:14:41 +0000
commit30ce47ef696b67375cb083db70754cb36f00bb18 (patch)
tree2e40b3fc4a4e0418901355e4e9474629eb0a7656
parent825182635768d61ffd86c3c806230e64a64412b3 (diff)
New WSAAsyncSelect code for WIN32 Fl::add_fd() support.
Fixes for Fl_Scrollbar - pushed_ bits wrong... git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@965 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--src/Fl_Scrollbar.cxx22
-rw-r--r--src/Fl_win32.cxx109
-rw-r--r--visualc/fltk.lib.dsp15
-rw-r--r--visualc/fluid.dsp3
4 files changed, 69 insertions, 80 deletions
diff --git a/src/Fl_Scrollbar.cxx b/src/Fl_Scrollbar.cxx
index 14ccd7345..88dc8971b 100644
--- a/src/Fl_Scrollbar.cxx
+++ b/src/Fl_Scrollbar.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Scrollbar.cxx,v 1.7.2.3 1999/12/07 17:53:08 bill Exp $"
+// "$Id: Fl_Scrollbar.cxx,v 1.7.2.4 1999/12/29 03:14:37 mike Exp $"
//
// Scroll bar widget for the Fast Light Tool Kit (FLTK).
//
@@ -39,8 +39,8 @@ void Fl_Scrollbar::increment_cb() {
switch (pushed_) {
case 1: i = -linesize_; break;
default:i = linesize_; break;
- case 3: i = -int(S * (maximum() - minimum()) / W); break;
- case 4: i = int(S * (maximum() - minimum()) / W); break;
+ case 5: i = -int(S * (maximum() - minimum()) / W); break;
+ case 6: i = int(S * (maximum() - minimum()) / W); break;
}
if (maximum() < minimum() && pushed_ < 3) i = -i;
handle_drag(clamp(value() + i));
@@ -80,9 +80,9 @@ int Fl_Scrollbar::handle(int event) {
else if (val <= 0.0) sliderx = 0;
else sliderx = int(val*(W-S)+.5);
- if (mx < X+sliderx) area = 3;
- else if (mx >= X+sliderx+S) area = 4;
- else area = 5;
+ if (mx < X+sliderx) area = 5;
+ else if (mx >= X+sliderx+S) area = 6;
+ else area = 8;
}
} else {
if (mx < X || mx >= X+W) area = 0;
@@ -96,9 +96,9 @@ int Fl_Scrollbar::handle(int event) {
else if (val <= 0.0) slidery = 0;
else slidery = int(val*(H-S)+.5);
- if (my < Y+slidery) area = 3;
- else if (my >= Y+slidery+S) area = 4;
- else area = 5;
+ if (my < Y+slidery) area = 5;
+ else if (my >= Y+slidery+S) area = 6;
+ else area = 8;
}
}
switch (event) {
@@ -115,7 +115,7 @@ int Fl_Scrollbar::handle(int event) {
return 1;
case FL_PUSH:
if (pushed_) return 1;
- if (area != 5) pushed_ = area;
+ if (area != 8) pushed_ = area;
if (pushed_) {
handle_push();
Fl::add_timeout(INITIALREPEAT, timeout_cb, this);
@@ -241,5 +241,5 @@ Fl_Scrollbar::Fl_Scrollbar(int X, int Y, int W, int H, const char* L)
}
//
-// End of "$Id: Fl_Scrollbar.cxx,v 1.7.2.3 1999/12/07 17:53:08 bill Exp $".
+// End of "$Id: Fl_Scrollbar.cxx,v 1.7.2.4 1999/12/29 03:14:37 mike Exp $".
//
diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx
index f2187750d..e2ec08283 100644
--- a/src/Fl_win32.cxx
+++ b/src/Fl_win32.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_win32.cxx,v 1.33.2.17 1999/12/15 04:58:27 bill Exp $"
+// "$Id: Fl_win32.cxx,v 1.33.2.18 1999/12/29 03:14:38 mike Exp $"
//
// WIN32-specific code for the Fast Light Tool Kit (FLTK).
//
@@ -39,6 +39,12 @@
#include <ctype.h>
//
+// USE_ASYNC_SELECT - define it if you have WSAAsyncSelect()...
+//
+
+#define USE_ASYNC_SELECT
+
+//
// WM_SYNCPAINT is an "undocumented" message, which is finally defined in
// VC++ 6.0.
//
@@ -50,16 +56,22 @@
# define WM_MOUSELEAVE 0x02a3
#endif
+//
+// WM_FLSELECT is the user-defined message that we get when one of
+// the sockets has pending data, etc.
+//
+
+#define WM_FLSELECT (WM_USER+0x0400)
+
////////////////////////////////////////////////////////////////
// interface to poll/select call:
// fd's are only implemented for sockets. Microsoft Windows does not
// have a unified IO system, so it doesn't support select() on files,
-// devices, or pipes... Also, unlike UNIX the Windows select() call
-// doesn't use the nfds parameter, so we don't need to keep track of
-// the maximum FD number...
+// devices, or pipes... Also, Microsoft provides an asynchronous
+// select function that sends a WIN32 message when the select condition
+// exists...
-static fd_set fdsets[3];
#define POLLIN 1
#define POLLOUT 4
#define POLLERR 8
@@ -74,6 +86,7 @@ static struct FD {
} *fd = 0;
void Fl::add_fd(int n, int events, void (*cb)(int, void*), void *v) {
+ int mask;
remove_fd(n,events);
int i = nfds++;
if (i >= fd_array_size) {
@@ -84,9 +97,11 @@ void Fl::add_fd(int n, int events, void (*cb)(int, void*), void *v) {
fd[i].events = events;
fd[i].cb = cb;
fd[i].arg = v;
- if (events & POLLIN) FD_SET(n, &fdsets[0]);
- if (events & POLLOUT) FD_SET(n, &fdsets[1]);
- if (events & POLLERR) FD_SET(n, &fdsets[2]);
+ mask = 0;
+ if (events & POLLIN) mask |= FD_READ;
+ if (events & POLLOUT) mask |= FD_WRITE;
+ if (events & POLLERR) mask |= FD_CLOSE;
+ WSAAsyncSelect(n, fl_window, WM_FLSELECT, mask);
}
void Fl::add_fd(int fd, void (*cb)(int, void*), void* v) {
@@ -108,9 +123,14 @@ void Fl::remove_fd(int n, int events) {
j++;
}
nfds = j;
+
+#ifdef USE_ASYNC_SELECT
+ WSAAsyncSelect(n, 0, 0, 0);
+#else
if (events & POLLIN) FD_CLR(unsigned(n), &fdsets[0]);
if (events & POLLOUT) FD_CLR(unsigned(n), &fdsets[1]);
if (events & POLLERR) FD_CLR(unsigned(n), &fdsets[2]);
+#endif // USE_ASYNC_SELECT
}
void Fl::remove_fd(int n) {
@@ -121,64 +141,17 @@ MSG fl_msg;
int fl_ready() {
if (PeekMessage(&fl_msg, NULL, 0, 0, PM_NOREMOVE)) return 1;
-
- timeval t;
- t.tv_sec = 0;
- t.tv_usec = 0;
- fd_set fdt[3];
- fdt[0] = fdsets[0];
- fdt[1] = fdsets[1];
- fdt[2] = fdsets[2];
- return ::select(0,&fdt[0],&fdt[1],&fdt[2],&t);
+ else return (0);
}
double fl_wait(int timeout_flag, double time) {
int have_message = 0;
int timerid;
- if (nfds) {
- // For WIN32 we need to poll for socket input FIRST, since
- // the event queue is not something we can select() on...
- timeval t;
- t.tv_sec = 0;
- t.tv_usec = 0;
-
- fd_set fdt[3];
- fdt[0] = fdsets[0];
- fdt[1] = fdsets[1];
- fdt[2] = fdsets[2];
-
- if (::select(0,&fdt[0],&fdt[1],&fdt[2],&t)) {
- // We got something - do the callback!
- for (int i = 0; i < nfds; i ++) {
- int f = fd[i].fd;
- short revents = 0;
- if (FD_ISSET(f,&fdt[0])) revents |= POLLIN;
- if (FD_ISSET(f,&fdt[1])) revents |= POLLOUT;
- if (FD_ISSET(f,&fdt[2])) revents |= POLLERR;
- if (fd[i].events & revents) fd[i].cb(f, fd[i].arg);
- }
- }
- }
-
// get the first message by waiting the correct amount of time:
if (!timeout_flag) {
- // If we are monitoring sockets we need to check them periodically,
- // so set a timer in this case...
- if (nfds) {
- // First see if there is a message waiting...
- have_message = PeekMessage(&fl_msg, NULL, 0, 0, PM_REMOVE);
- if (!have_message) {
- // If not then set a 1ms timer...
- timerid = SetTimer(NULL, 0, 1, NULL);
- GetMessage(&fl_msg, NULL, 0, 0);
- KillTimer(NULL, timerid);
- }
- } else {
- // Wait for a message...
- GetMessage(&fl_msg, NULL, 0, 0);
- }
- have_message = 1;
+ // Wait for a message...
+ have_message = GetMessage(&fl_msg, NULL, 0, 0);
} else {
// Perform the requested timeout...
have_message = PeekMessage(&fl_msg, NULL, 0, 0, PM_REMOVE);
@@ -186,16 +159,30 @@ double fl_wait(int timeout_flag, double time) {
int t = (int)(time * 1000.0);
if (t <= 0) t = 1;
timerid = SetTimer(NULL, 0, t, NULL);
- GetMessage(&fl_msg, NULL, 0, 0);
+ have_message = GetMessage(&fl_msg, NULL, 0, 0);
KillTimer(NULL, timerid);
- have_message = 1;
}
}
// execute it, them execute any other messages that become ready during it:
while (have_message) {
+#ifdef USE_ASYNC_SELECT
+ if (fl_msg.message == WM_FLSELECT) {
+ // Got notification for socket
+ for (int i = 0; i < nfds; i ++)
+ if (fd[i].fd == fl_msg.wParam) {
+ (fd[i].cb)(fd[i].fd, fd[i].arg);
+ break;
+ }
+ } else {
+ // Some other message...
+ DispatchMessage(&fl_msg);
+ }
+#else
TranslateMessage(&fl_msg);
DispatchMessage(&fl_msg);
+#endif // USE_ASYNC_SELECT
+
have_message = PeekMessage(&fl_msg, NULL, 0, 0, PM_REMOVE);
}
@@ -896,5 +883,5 @@ void Fl_Window::make_current() {
}
//
-// End of "$Id: Fl_win32.cxx,v 1.33.2.17 1999/12/15 04:58:27 bill Exp $".
+// End of "$Id: Fl_win32.cxx,v 1.33.2.18 1999/12/29 03:14:38 mike Exp $".
//
diff --git a/visualc/fltk.lib.dsp b/visualc/fltk.lib.dsp
index 328ba864f..955b953bd 100644
--- a/visualc/fltk.lib.dsp
+++ b/visualc/fltk.lib.dsp
@@ -1,5 +1,5 @@
# Microsoft Developer Studio Project File - Name="fltk" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 5.00
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
@@ -22,9 +22,11 @@ CFG=fltk - Win32 Debug
!MESSAGE
# Begin Project
+# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
+RSC=rc.exe
!IF "$(CFG)" == "fltk - Win32 Release"
@@ -38,11 +40,11 @@ CPP=cl.exe
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
-RSC=rc.exe
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /MT /GX /Ot /Op /Ob2 /I "." /I ".." /D "FL_STATIC" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "WIN32_LEAN_AND_MEAN" /D "VC_EXTRA_LEAN" /D "WIN32_EXTRA_LEAN" /YX /FD /c
+# SUBTRACT CPP /Os
# ADD BASE RSC /l 0x409
# ADD RSC /l 0x409
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MT /GX /Os /Ob2 /I "." /I ".." /D "FL_STATIC" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "WIN32_LEAN_AND_MEAN" /D "VC_EXTRA_LEAN" /D "WIN32_EXTRA_LEAN" /YX /FD /c
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
@@ -62,11 +64,10 @@ LIB32=link.exe -lib
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
-RSC=rc.exe
-# ADD BASE RSC /l 0x409
-# ADD RSC /l 0x409
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MTd /GX /Z7 /Od /I "." /I ".." /D "FL_STATIC" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "WIN32_LEAN_AND_MEAN" /D "VC_EXTRA_LEAN" /D "WIN32_EXTRA_LEAN" /FR /YX /FD /c
+# ADD BASE RSC /l 0x409
+# ADD RSC /l 0x409
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
diff --git a/visualc/fluid.dsp b/visualc/fluid.dsp
index e2bec5854..7e6151d0f 100644
--- a/visualc/fluid.dsp
+++ b/visualc/fluid.dsp
@@ -43,7 +43,8 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MT /GX /Os /Ob2 /I ".." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "WIN32_LEAN_AND_MEAN" /D "VC_EXTRA_LEAN" /D "WIN32_EXTRA_LEAN" /YX /FD /c
+# ADD CPP /nologo /MT /GX /Ot /Op /Ob2 /I ".." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "WIN32_LEAN_AND_MEAN" /D "VC_EXTRA_LEAN" /D "WIN32_EXTRA_LEAN" /YX /FD /c
+# SUBTRACT CPP /Os
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"