X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/bd6bb5442f78ec84eba0d3ecf715a8a820d32a9c..ee6bb6939fe507dc98986bfc23794da6110f61ef:/src/w32xfns.c diff --git a/src/w32xfns.c b/src/w32xfns.c index 7c61b24152..0e937e9950 100644 --- a/src/w32xfns.c +++ b/src/w32xfns.c @@ -1,5 +1,6 @@ /* Functions taken directly from X sources for use with the Microsoft W32 API. - Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation. + Copyright (C) 1989, 1992, 1993, 1994, 1995, 1999, 2002, 2003, 2004, + 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -15,13 +16,14 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +Boston, MA 02110-1301, USA. */ -#include #include +#include #include #include "lisp.h" +#include "keyboard.h" #include "frame.h" #include "charset.h" #include "fontset.h" @@ -37,7 +39,7 @@ extern HANDLE keyboard_handle; HANDLE input_available = NULL; HANDLE interrupt_handle = NULL; -void +void init_crit () { InitializeCriticalSection (&critsect); @@ -55,7 +57,7 @@ init_crit () interrupt_handle = CreateEvent (NULL, TRUE, FALSE, NULL); } -void +void delete_crit () { DeleteCriticalSection (&critsect); @@ -83,9 +85,17 @@ signal_quit () void select_palette (FRAME_PTR f, HDC hdc) { + struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f); + + if (!display_info->has_palette) + return; + + if (display_info->palette == 0) + return; + if (!NILP (Vw32_enable_palette)) f->output_data.w32->old_palette = - SelectPalette (hdc, one_w32_display_info.palette, FALSE); + SelectPalette (hdc, display_info->palette, FALSE); else f->output_data.w32->old_palette = NULL; @@ -113,10 +123,17 @@ get_frame_dc (FRAME_PTR f) { HDC hdc; + if (f->output_method != output_w32) + abort (); + enter_crit (); hdc = GetDC (f->output_data.w32->window_desc); - select_palette (f, hdc); + + /* If this gets called during startup before the frame is valid, + there is a chance of corrupting random data or crashing. */ + if (hdc) + select_palette (f, hdc); return hdc; } @@ -144,33 +161,33 @@ int_msg *lpHead = NULL; int_msg *lpTail = NULL; int nQueue = 0; -BOOL +BOOL get_next_msg (lpmsg, bWait) W32Msg * lpmsg; BOOL bWait; { BOOL bRet = FALSE; - + enter_crit (); - + /* The while loop takes care of multiple sets */ - + while (!nQueue && bWait) { leave_crit (); WaitForSingleObject (input_available, INFINITE); enter_crit (); } - + if (nQueue) { bcopy (&(lpHead->w32msg), lpmsg, sizeof (W32Msg)); { int_msg * lpCur = lpHead; - + lpHead = lpHead->lpNext; - + myfree (lpCur); } @@ -181,13 +198,13 @@ get_next_msg (lpmsg, bWait) if (nQueue == 0) ResetEvent (input_available); - + leave_crit (); - + return (bRet); } -BOOL +BOOL post_msg (lpmsg) W32Msg * lpmsg; { @@ -205,14 +222,14 @@ post_msg (lpmsg) { lpTail->lpNext = lpNew; } - else + else { lpHead = lpNew; } lpTail = lpNew; SetEvent (input_available); - + leave_crit (); return (TRUE); @@ -239,6 +256,19 @@ prepend_msg (W32Msg *lpmsg) return (TRUE); } +/* Process all messages in the current thread's queue. */ +void +drain_message_queue () +{ + MSG msg; + while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage (&msg); + DispatchMessage (&msg); + } +} + + /* * XParseGeometry parses strings of the form * "=x{+-}{+-}", where @@ -248,7 +278,7 @@ prepend_msg (W32Msg *lpmsg) * It returns a bitmask that indicates which of the four values * were actually found in the string. For each value found, * the corresponding argument is updated; for each value - * not found, the corresponding argument is left unchanged. + * not found, the corresponding argument is left unchanged. */ static int @@ -258,7 +288,7 @@ read_integer (string, NextString) { register int Result = 0; int Sign = 1; - + if (*string == '+') string++; else if (*string == '-') @@ -277,7 +307,7 @@ read_integer (string, NextString) return (-Result); } -int +int XParseGeometry (string, x, y, width, height) char *string; int *x, *y; @@ -288,23 +318,23 @@ XParseGeometry (string, x, y, width, height) unsigned int tempWidth, tempHeight; int tempX, tempY; char *nextCharacter; - + if ((string == NULL) || (*string == '\0')) return (mask); if (*string == '=') string++; /* ignore possible '=' at beg of geometry spec */ - + strind = (char *)string; - if (*strind != '+' && *strind != '-' && *strind != 'x') + if (*strind != '+' && *strind != '-' && *strind != 'x') { tempWidth = read_integer (strind, &nextCharacter); - if (strind == nextCharacter) + if (strind == nextCharacter) return (0); strind = nextCharacter; mask |= WidthValue; } - - if (*strind == 'x' || *strind == 'X') - { + + if (*strind == 'x' || *strind == 'X') + { strind++; tempHeight = read_integer (strind, &nextCharacter); if (strind == nextCharacter) @@ -312,10 +342,10 @@ XParseGeometry (string, x, y, width, height) strind = nextCharacter; mask |= HeightValue; } - - if ((*strind == '+') || (*strind == '-')) + + if ((*strind == '+') || (*strind == '-')) { - if (*strind == '-') + if (*strind == '-') { strind++; tempX = -read_integer (strind, &nextCharacter); @@ -326,7 +356,7 @@ XParseGeometry (string, x, y, width, height) } else - { + { strind++; tempX = read_integer (strind, &nextCharacter); if (strind == nextCharacter) @@ -334,9 +364,9 @@ XParseGeometry (string, x, y, width, height) strind = nextCharacter; } mask |= XValue; - if ((*strind == '+') || (*strind == '-')) + if ((*strind == '+') || (*strind == '-')) { - if (*strind == '-') + if (*strind == '-') { strind++; tempY = -read_integer (strind, &nextCharacter); @@ -357,12 +387,12 @@ XParseGeometry (string, x, y, width, height) mask |= YValue; } } - + /* If strind isn't at the end of the string the it's an invalid geometry specification. */ - + if (*strind != '\0') return (0); - + if (mask & XValue) *x = tempX; if (mask & YValue) @@ -380,3 +410,6 @@ x_sync (f) void *f; { } + +/* arch-tag: 4fab3695-4ad3-4cc6-a2b1-fd2c67dc46be + (do not change this comment) */