38
38
* --------------------------------------------------------------------------
39
39
* $Log: vibwndws.c,v $
40
* Revision 6.66 2004/07/19 13:37:24 bollin
41
* adjusted FixVisibilityIssues function to handle nesting of groups
43
* Revision 6.65 2004/07/16 18:47:29 bollin
44
* added FixVisibilityIssues function to handle LessTif problems with not correctly hiding
45
* widgets before the parent widget is managed.
46
* Also replaced obsolete XmFontListCreate function to get rid of run-time warning.
48
* Revision 6.64 2004/06/02 15:53:17 bollin
49
* fixed Nlm_ProcessKeyPress for MOTIF to handle arrow keys
51
* Revision 6.63 2004/06/02 14:54:33 bollin
52
* fixed Nlm_ProcessKeyPress to also handle arrow keys
54
* Revision 6.62 2004/04/14 19:14:06 sinyakov
55
* WIN_MSWIN: support X-Windows-like -bg color command line option
57
* Choi: Added support for either the left or right monitor being the primary
58
* monitor in a dual monitor setup. Added function Nlm_UsePrimaryMonitor.
60
* Choi: modified Nlm_SetupWindows to use the virtual screen
61
* size to support dual monitor setups. this effectively limits our target
62
* platform to WINVER >= 0x0500 (Windows2000 or later) which all indexers
63
* have. modified Nlm_HasDualScreen to use system metrics call for
64
* windows2000 or later platforms.
66
* Revision 6.61 2004/02/03 23:34:58 sinyakov
67
* Nlm_WindowGainFocus(): call Nlm_GetNext() before calling Nlm_DoGainFocus()
69
* Revision 6.60 2004/01/20 23:35:38 sinyakov
70
* [WIN_MSWIN] implemented menu accelerators
72
* Revision 6.59 2004/01/05 18:42:40 kans
73
* record screen mode at time of window creation
75
* Revision 6.58 2004/01/05 17:08:09 kans
76
* added functions to control use of dual screens
78
* Revision 6.57 2003/12/03 17:45:21 kans
79
* For OS_MAC, always include Profiler.h
81
* Revision 6.56 2003/11/17 17:03:30 kans
82
* changed C++ style comments to C comments
84
* Revision 6.55 2003/11/03 21:57:48 sinyakov
85
* WIN_MSWIN: added ability to put a message into message processing loop
86
* to call a callback function within the main GUI thread
87
* callback function address is passed in WPARAM,
88
* callback function parameter is passed in LPARAM
89
* this functionality is used by Win32 implementation of smartnet.c module
91
* Revision 6.54 2003/04/09 18:16:53 kans
92
* motif version of Nlm_ProcessKeyPress sets ctrlKey and shftKey, clears cmmdKey and optKey, leaves dblClick alone
94
* Revision 6.53 2003/01/27 17:43:03 kans
95
* do not set silent if xx_argc > 1
97
* Revision 6.52 2003/01/24 20:55:42 rsmith
98
* ConvertFilename now extern not static, renamed Nlm_* and only defined in vibutils.c
100
* Revision 6.51 2002/11/06 21:32:50 ucko
101
* Accept "--help" as a synonym for the less intuitive "-"
103
* Revision 6.50 2002/07/09 15:20:19 lavr
104
* Call CONNECT_Init(0) in initialization sequence
106
* Revision 6.49 2002/06/13 16:15:13 kans
107
* fix includes for OS_UNIX_DARWIN with WIN_MAC (EN) - still bug in vibutils.c file dialog
109
* Revision 6.48 2002/05/07 16:50:14 bazhin
110
* Changes in Nlm_SetWindowConfigureCallback().
112
* Revision 6.47 2002/04/30 18:25:12 bazhin
113
* Added function "Nlm_SetWindowConfigureCallback(WindoW w)", which
114
* allows to catch events, when window just moved without resizing.
115
* Fixed some "gcc -Wall -ansi" warnings.
117
* Revision 6.46 2002/03/28 13:30:28 kans
118
* check for OS_UNIX_DARWIN before including MoreCarbonAccessors.h, Profiler.h (EN)
120
* Revision 6.45 2002/03/18 16:55:19 kans
121
* ProfilerInit stackDepth parameter to 50
123
* Revision 6.44 2002/03/18 16:33:53 kans
124
* ProfilerInit numFunctions parameter to 1000
40
126
* Revision 6.43 2001/11/26 21:25:04 juran
41
127
* Define type AERefCon as SInt32 for AE handler prototypes.
42
128
* It may need to be UInt32 for pre-3.4 Universal Interfaces under Carbon, or something.
3143
NLM_EXTERN void Nlm_UseFullScreen (void)
3146
Nlm_screenMode = USE_FULL_SCREEN;
3149
NLM_EXTERN void Nlm_UseLeftScreen (void)
3152
Nlm_screenMode = USE_LEFT_SCREEN;
3155
NLM_EXTERN void Nlm_UseRightScreen (void)
3158
Nlm_screenMode = USE_RIGHT_SCREEN;
3161
NLM_EXTERN void Nlm_UsePrimaryMonitor (void)
3164
Nlm_screenMode = USE_PRIMARY_MONITOR;
3167
NLM_EXTERN Nlm_Boolean Nlm_HasDualScreen (void)
3170
#if(WINVER >= 0x0500)
3171
int num_monitors = (Nlm_Int2)GetSystemMetrics (SM_CMONITORS);
3172
if (num_monitors == 2) {
3177
if (screenBitBounds.right > 2000 && screenBitBounds.bottom < 800) {
3179
} else if (screenBitBounds.right > 2500 && screenBitBounds.bottom < 1100) {
3008
3186
/* esl: extraWidth parameter added */
3009
3187
static void Nlm_ResizeWindow (Nlm_GraphiC w, Nlm_Int2 dragHeight,
3010
3188
Nlm_Int2 scrollWidth, Nlm_Int2 minWidth,
3062
3241
height = r.bottom + extraHeight;
3063
3242
if (r.left < 0)
3065
free = screenBitBounds.right - width;
3066
rleft = (Nlm_Int4)r.left;
3067
leftpix = free * (-rleft) / 100;
3068
r.left = (Nlm_Int2)leftpix;
3244
#if(WINVER >= 0x0500)
3245
if (Nlm_HasDualScreen ()) {
3246
screenMode = Nlm_GetScreenMode ((Nlm_WindoW) w);
3247
if (screenMode == USE_PRIMARY_MONITOR) {
3248
free = (screenBitBounds.right - screenBitBounds.left) / 2 - width;
3249
rleft = (Nlm_Int4)r.left;
3250
leftpix = free * (-rleft) / 100;
3251
r.left = (Nlm_Int2)leftpix;
3252
} else if (screenMode == USE_LEFT_SCREEN) {
3253
free = (screenBitBounds.right - screenBitBounds.left) / 2 - width;
3254
rleft = (Nlm_Int4)r.left;
3255
leftpix = free * (-rleft) / 100;
3256
r.left = (Nlm_Int2)leftpix + screenBitBounds.left;
3257
} else if (screenMode == USE_RIGHT_SCREEN) {
3258
free = (screenBitBounds.right - screenBitBounds.left) / 2 - width;
3259
rleft = (Nlm_Int4)r.left;
3260
leftpix = free * (-rleft) / 100;
3261
r.left = (Nlm_Int2)leftpix + screenBitBounds.left;
3262
r.left += (screenBitBounds.right - screenBitBounds.left) / 2;
3264
free = (screenBitBounds.right - screenBitBounds.left) - width;
3265
rleft = (Nlm_Int4)r.left;
3266
leftpix = free * (-rleft) / 100;
3267
r.left = (Nlm_Int2)leftpix + screenBitBounds.left;
3270
free = screenBitBounds.right - width;
3271
rleft = (Nlm_Int4)r.left;
3272
leftpix = free * (-rleft) / 100;
3273
r.left = (Nlm_Int2)leftpix;
3276
if (Nlm_HasDualScreen ()) {
3277
screenMode = Nlm_GetScreenMode ((Nlm_WindoW) w);
3278
if (screenMode == USE_LEFT_SCREEN) {
3279
free = screenBitBounds.right / 2 - width;
3280
rleft = (Nlm_Int4)r.left;
3281
leftpix = free * (-rleft) / 100;
3282
r.left = (Nlm_Int2)leftpix;
3283
} else if (screenMode == USE_RIGHT_SCREEN) {
3284
free = screenBitBounds.right / 2 - width;
3285
rleft = (Nlm_Int4)r.left;
3286
leftpix = free * (-rleft) / 100;
3287
r.left = (Nlm_Int2)leftpix;
3288
r.left += screenBitBounds.right / 2;
3290
free = screenBitBounds.right - width;
3291
rleft = (Nlm_Int4)r.left;
3292
leftpix = free * (-rleft) / 100;
3293
r.left = (Nlm_Int2)leftpix;
3296
free = screenBitBounds.right - width;
3297
rleft = (Nlm_Int4)r.left;
3298
leftpix = free * (-rleft) / 100;
3299
r.left = (Nlm_Int2)leftpix;
3568
#if defined(LESSTIF_VERSION)
3570
static void FixVisibilityIssues (Nlm_GraphiC g)
3574
for (child = Nlm_GetChild (g); child != NULL; child = Nlm_GetNext (child))
3576
if (!Nlm_GetVisible (child))
3579
FixVisibilityIssues (child);
3584
FixVisibilityIssues (child);
3335
3590
extern void Nlm_RealizeWindow (Nlm_WindoW w)
3338
3593
if (w != NULL) {
3339
3594
Nlm_DoShow ((Nlm_GraphiC) w, FALSE, TRUE);
3597
#if defined(LESSTIF_VERSION)
3598
FixVisibilityIssues ((Nlm_GraphiC) w);
3343
3602
extern void Nlm_IconifyWindow(Nlm_WindoW w)
5373
5637
mess = (Nlm_currentEvent.message & osEvtMessageMask) >> 24;
5374
5638
if (mess == suspendResumeMessage) {
5375
5639
if (Nlm_currentEvent.message & resumeFlag) {
5377
5641
#if !TARGET_API_MAC_CARBON
5378
5642
if (Nlm_currentEvent.message & convertClipboardFlag) {
5380
// We always convert the clipboard.
5381
// If it turns out that pasting is noticeably slow, I'll change it.
5644
* We always convert the clipboard.
5645
* If it turns out that pasting is noticeably slow, I'll change it.
5387
5653
} else if (mess == mouseMovedMessage) {
5388
5654
if (mouseMovedAction != NULL) {
5743
6010
case WM_CTLCOLORLISTBOX:
5744
6011
case WM_CTLCOLOREDIT:
5746
SetBkColor((HDC)wParam, RGB(255, 255, 255));
5747
mainwndrsult = (long)GetStockObject( WHITE_BRUSH );
6013
if(Nlm_hasBackColor)
6015
SetBkColor((HDC)wParam, Nlm_crBackColor);
6016
mainwndrsult = (long)Nlm_hbrWindowBackground;
6020
SetBkColor((HDC)wParam, RGB(255, 255, 255));
6021
mainwndrsult = (long)GetStockObject( WHITE_BRUSH );
6025
case WM_CTLCOLORDLG:
6026
case WM_CTLCOLORBTN:
6028
if(Nlm_hasBackColor)
6030
SetBkColor((HDC)wParam, Nlm_crBackColor);
6031
mainwndrsult = (long)Nlm_hbrWindowBackground;
6034
mainwndrsult = DefWindowProc (hwnd, message, wParam, lParam);
6135
static Nlm_RGBName* Nlm_FindRGBName(const Nlm_Char* name)
6139
for(p = RGBNames; p->name; ++p) {
6140
if (StringICmp(p->name, name) == 0)
6148
static void Nlm_ParseXArguments(int* argc, char** argv)
6153
if (argc == 0 || argv == NULL)
6156
for(i = 0, j = 0; i < *argc; ) {
6157
if (StringCmp(argv[i], "-bg") == 0 && argv[i+1] != NULL) {
6158
Nlm_RGBName* p = Nlm_FindRGBName(argv[i+1]);
6160
/* Set user-defined background color */
6161
Nlm_hasBackColor = TRUE;
6162
Nlm_crBackColor = RGB(p->red, p->green, p->blue);
6163
Nlm_hbrWindowBackground = CreateSolidBrush( Nlm_crBackColor );
6168
argv[j++] = argv[i++];
5843
6174
static Nlm_Boolean Nlm_SetupWindows (void)
5850
6181
Nlm_Int2 width;
6183
int xx_argc = (int)Nlm_GetArgc();
6184
char **xx_argv = Nlm_GetArgv();
6187
Using SM_CXVIRTUALSCREEN to accomodate dual monitors effectively limits target platform
6188
to Windows2000 or later (i.e. Win95/98/ME are NOT supported).
6189
In order to use these identifiers, must define WINVER=0x0500.
6191
#if(WINVER >= 0x0500)
6192
int x = (Nlm_Int2)GetSystemMetrics (SM_XVIRTUALSCREEN);
6193
int y = (Nlm_Int2)GetSystemMetrics (SM_YVIRTUALSCREEN);
6194
width = (Nlm_Int2)GetSystemMetrics (SM_CXVIRTUALSCREEN);
6195
height = (Nlm_Int2)GetSystemMetrics (SM_CYVIRTUALSCREEN);
6196
Nlm_LoadRect (&screenBitBounds, x, y, x+width, y+height);
6197
Nlm_LoadPt (&pt, x, y);
5852
6199
width = (Nlm_Int2)GetSystemMetrics (SM_CXSCREEN);
5853
6200
height = (Nlm_Int2)GetSystemMetrics (SM_CYSCREEN);
5854
6201
Nlm_LoadRect (&screenBitBounds, 0, 0, width, height);
5855
6202
Nlm_LoadPt (&pt, 0, 0);
5856
6204
r = screenBitBounds;
5857
6205
Nlm_screenRect = screenBitBounds;
5858
6206
Nlm_desktopWindow = (Nlm_WindoW) Nlm_HandNew (sizeof (Nlm_WindowRec));
6708
extern Nlm_Int2 Nlm_Main(void) __attribute__((weak));
6711
#ifdef OS_UNIX_DARWIN
6712
int main (int argc, char *argv[])
6717
Nlm_SetupArguments (argc, argv);
6718
# else /* ! OS_UNIX_DARWIN */
6360
6725
#if __profile__
6361
ProfilerInit (collectDetailed, bestTimeBase, 100, 20);
6726
ProfilerInit (collectDetailed, bestTimeBase, 1000, 50);
6362
6727
ProfilerSetStatus (FALSE);
6365
6730
#if TARGET_API_MAC_CARBON >= 1
6366
// carbon changes the API: pass the number of master pointers to allocate
6367
//MoreMasters (1280);
6368
// 2001-03-22: Joshua Juran
6369
// CarbonDater report says to use MoreMasterPointers() instead of MoreMasters().
6370
// Universal Interfaces 3.3.2 declares MoreMasters(void) under Carbon.
6732
carbon changes the API: pass the number of master pointers to allocate
6734
2001-03-22: Joshua Juran
6735
CarbonDater report says to use MoreMasterPointers() instead of MoreMasters().
6736
Universal Interfaces 3.3.2 declares MoreMasters(void) under Carbon.
6371
6738
MoreMasterPointers(1280);
6372
6739
FlushEvents (everyEvent, 0);
6373
// the rest of the toolbox is done for us can't init them...
6740
/* the rest of the toolbox is done for us can't init them...
6375
6743
MaxApplZone ();
6903
7303
static void Nlm_ProcessKeyPress (XEvent *event)
6908
if (event->type == KeyPress && keyAction != NULL &&
6909
XLookupString(&event->xkey, buffer, sizeof(buffer), NULL, NULL) == 1)
6910
keyAction( *buffer );
7308
if (event->type == KeyPress && keyAction != NULL)
7310
ch = Nlm_GetInputChar (&event->xkey);
7311
Nlm_ctrlKey = ((event->xkey.state & ControlMask) != 0);
7312
Nlm_shftKey = ((event->xkey.state & ShiftMask ) != 0);
7313
Nlm_cmmdKey = FALSE;
7322
typedef void (LIBCALLBACK *CallbackProc)(void* data);
7323
static UINT idWMVibrantCallback = 0;
7325
static void Nlm_InitVibrantCallback ()
7328
idWMVibrantCallback = RegisterWindowMessage("VibrantCallback");
7332
static Nlm_Boolean Nlm_ProcessVibrantCallback (LPMSG lpMsg)
7335
if(idWMVibrantCallback && idWMVibrantCallback == lpMsg->message)
7337
CallbackProc proc = (CallbackProc)lpMsg->wParam;
7338
proc((void*)(lpMsg->lParam));
7348
extern Nlm_Handle Nlm_GetWindowHAccel (Nlm_WindoW w)
7352
Nlm_WindowData wdata;
7354
rsult = (Nlm_Handle) 0;
7356
Nlm_GetWindowData (w, &wdata);
7357
rsult = wdata.haccel;
7363
extern void Nlm_SetWindowHAccel (Nlm_WindoW w, Nlm_Handle h)
7366
Nlm_WindowData wdata;
7369
Nlm_GetWindowData (w, &wdata);
7371
Nlm_SetWindowData (w, &wdata);
7376
static Nlm_Boolean Nlm_ProcessAccelerator (LPMSG lpMsg)
7379
if(lpMsg->hwnd != NULL &&
7380
(lpMsg->message == WM_KEYDOWN ||
7381
lpMsg->message == WM_KEYUP ||
7382
lpMsg->message == WM_SYSKEYDOWN ||
7383
lpMsg->message == WM_SYSKEYUP ||
7384
lpMsg->message == WM_CHAR))
7386
Nlm_WindoW w = (Nlm_WindoW) GetProp (lpMsg->hwnd, (LPSTR) "Nlm_VibrantProp");
7389
Nlm_WindoW p = Nlm_GetParentWindow((Nlm_GraphiC)w);
7392
Nlm_WindowData wdata;
7393
Nlm_GetWindowData(p, &wdata);
7394
if(wdata.haccel != NULL)
7396
int ret = TranslateAccelerator(wdata.handle, wdata.haccel, lpMsg);
7087
7584
if (GetMessage (&Nlm_currentMssg, NULL, 0, 0)) {
7088
TranslateMessage (&Nlm_currentMssg);
7089
Nlm_ProcessKeyPress (&Nlm_currentMssg);
7090
DispatchMessage (&Nlm_currentMssg);
7585
if(!Nlm_ProcessAccelerator(&Nlm_currentMssg)) {
7586
TranslateMessage (&Nlm_currentMssg);
7587
Nlm_ProcessKeyPress (&Nlm_currentMssg);
7588
Nlm_ProcessVibrantCallback(&Nlm_currentMssg);
7589
DispatchMessage (&Nlm_currentMssg);
7091
7591
Nlm_RemoveDyingWindows ();
8033
8536
systemProcs->linkIn = Nlm_LinkIn;
8540
/**********************************************************/
8541
static void WindowStructFocusCallbackEx(Widget wd, XtPointer client_data,
8542
XEvent *event, Boolean *contin)
8544
Nlm_WindowData wdata;
8552
Window *children = NULL;
8553
unsigned int nchildren;
8557
if(event->type != ConfigureNotify)
8559
WindowStructFocusCallback(wd, client_data, event, contin);
8563
XSetErrorHandler(ignoreXerror_handler);
8564
for(xw = XtWindow(wd); xw; xw = parent)
8566
if(!XQueryTree(Nlm_currentXDisplay, xw, &root, &parent, &children,
8567
&nchildren) || root == parent)
8569
XFree((char *) children);
8572
XSetErrorHandler(defaultXerror_handler);
8573
if(children != NULL)
8574
XFree((char *) children);
8579
w = (Nlm_WindoW) client_data;
8581
XTranslateCoordinates(Nlm_currentXDisplay, xw, root, (Position) 0,
8582
(Position) 0, &x, &y, &child);
8586
rtool.width = event->xconfigure.width;
8587
rtool.height = event->xconfigure.height;
8588
if(Nlm_GetWindowMenuBar(w) != NULL)
8589
rtool.height -= Nlm_internalMenuBarHeight;
8591
Nlm_RectToolToRecT(&rtool, &r);
8592
Nlm_SetRect((Nlm_GraphiC) w, &r);
8593
Nlm_GetWindowData(w, &wdata);
8595
if(wdata.resize != NULL && Nlm_WindowHasBeenShown(w) &&
8596
Nlm_GetVisible((Nlm_GraphiC) w))
8604
/**********************************************************/
8605
extern void Nlm_SetWindowConfigureCallback(Nlm_WindoW w)
8613
wd = (Widget) Nlm_GetWindowShell(w);
8614
XtRemoveEventHandler(wd, (StructureNotifyMask | FocusChangeMask), FALSE,
8615
WindowStructFocusCallback, (XtPointer) w);
8616
XtAddEventHandler(wd, (StructureNotifyMask | FocusChangeMask), FALSE,
8617
WindowStructFocusCallbackEx, (XtPointer) w);