14c8945a0SNathan Whitehorn /* 2*2a3e3873SBaptiste Daroussin * $Id: mouse.c,v 1.20 2012/12/21 10:00:30 tom Exp $ 34c8945a0SNathan Whitehorn * 44c8945a0SNathan Whitehorn * mouse.c -- mouse support for dialog 54c8945a0SNathan Whitehorn * 6*2a3e3873SBaptiste Daroussin * Copyright 2002-2007,2012 Thomas E. Dickey 74c8945a0SNathan Whitehorn * 84c8945a0SNathan Whitehorn * This program is free software; you can redistribute it and/or modify 94c8945a0SNathan Whitehorn * it under the terms of the GNU Lesser General Public License, version 2.1 104c8945a0SNathan Whitehorn * as published by the Free Software Foundation. 114c8945a0SNathan Whitehorn * 124c8945a0SNathan Whitehorn * This program is distributed in the hope that it will be useful, but 134c8945a0SNathan Whitehorn * WITHOUT ANY WARRANTY; without even the implied warranty of 144c8945a0SNathan Whitehorn * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 154c8945a0SNathan Whitehorn * Lesser General Public License for more details. 164c8945a0SNathan Whitehorn * 174c8945a0SNathan Whitehorn * You should have received a copy of the GNU Lesser General Public 184c8945a0SNathan Whitehorn * License along with this program; if not, write to 194c8945a0SNathan Whitehorn * Free Software Foundation, Inc. 204c8945a0SNathan Whitehorn * 51 Franklin St., Fifth Floor 214c8945a0SNathan Whitehorn * Boston, MA 02110, USA. 224c8945a0SNathan Whitehorn */ 234c8945a0SNathan Whitehorn 244c8945a0SNathan Whitehorn #include <dialog.h> 254c8945a0SNathan Whitehorn #include <dlg_keys.h> 264c8945a0SNathan Whitehorn 274c8945a0SNathan Whitehorn #if USE_MOUSE 284c8945a0SNathan Whitehorn 29*2a3e3873SBaptiste Daroussin static int basex, basey, basecode; 304c8945a0SNathan Whitehorn 314c8945a0SNathan Whitehorn static mseRegion *regionList = NULL; 324c8945a0SNathan Whitehorn 334c8945a0SNathan Whitehorn /*=========== region related functions =============*/ 344c8945a0SNathan Whitehorn 354c8945a0SNathan Whitehorn static mseRegion * 364c8945a0SNathan Whitehorn find_region_by_code(int code) 374c8945a0SNathan Whitehorn { 384c8945a0SNathan Whitehorn mseRegion *butPtr; 394c8945a0SNathan Whitehorn 404c8945a0SNathan Whitehorn for (butPtr = regionList; butPtr; butPtr = butPtr->next) { 414c8945a0SNathan Whitehorn if (code == butPtr->code) 424c8945a0SNathan Whitehorn break; 434c8945a0SNathan Whitehorn } 444c8945a0SNathan Whitehorn return butPtr; 454c8945a0SNathan Whitehorn } 464c8945a0SNathan Whitehorn 474c8945a0SNathan Whitehorn void 484c8945a0SNathan Whitehorn dlg_mouse_setbase(int x, int y) 494c8945a0SNathan Whitehorn { 504c8945a0SNathan Whitehorn basex = x; 514c8945a0SNathan Whitehorn basey = y; 524c8945a0SNathan Whitehorn } 534c8945a0SNathan Whitehorn 544c8945a0SNathan Whitehorn void 55*2a3e3873SBaptiste Daroussin dlg_mouse_setcode(int code) 56*2a3e3873SBaptiste Daroussin { 57*2a3e3873SBaptiste Daroussin basecode = code; 58*2a3e3873SBaptiste Daroussin } 59*2a3e3873SBaptiste Daroussin 60*2a3e3873SBaptiste Daroussin void 614c8945a0SNathan Whitehorn dlg_mouse_mkbigregion(int y, int x, 624c8945a0SNathan Whitehorn int height, int width, 634c8945a0SNathan Whitehorn int code, 644c8945a0SNathan Whitehorn int step_y, int step_x, 654c8945a0SNathan Whitehorn int mode) 664c8945a0SNathan Whitehorn { 674c8945a0SNathan Whitehorn mseRegion *butPtr = dlg_mouse_mkregion(y, x, height, width, -DLGK_MOUSE(code)); 684c8945a0SNathan Whitehorn butPtr->mode = mode; 694c8945a0SNathan Whitehorn butPtr->step_x = MAX(1, step_x); 704c8945a0SNathan Whitehorn butPtr->step_y = MAX(1, step_y); 714c8945a0SNathan Whitehorn } 724c8945a0SNathan Whitehorn 734c8945a0SNathan Whitehorn void 744c8945a0SNathan Whitehorn dlg_mouse_free_regions(void) 754c8945a0SNathan Whitehorn { 764c8945a0SNathan Whitehorn while (regionList != 0) { 774c8945a0SNathan Whitehorn mseRegion *butPtr = regionList->next; 784c8945a0SNathan Whitehorn free(regionList); 794c8945a0SNathan Whitehorn regionList = butPtr; 804c8945a0SNathan Whitehorn } 814c8945a0SNathan Whitehorn } 824c8945a0SNathan Whitehorn 834c8945a0SNathan Whitehorn mseRegion * 844c8945a0SNathan Whitehorn dlg_mouse_mkregion(int y, int x, int height, int width, int code) 854c8945a0SNathan Whitehorn { 864c8945a0SNathan Whitehorn mseRegion *butPtr; 874c8945a0SNathan Whitehorn 88*2a3e3873SBaptiste Daroussin if ((butPtr = find_region_by_code(basecode + code)) == 0) { 894c8945a0SNathan Whitehorn butPtr = dlg_malloc(mseRegion, 1); 904c8945a0SNathan Whitehorn assert_ptr(butPtr, "dlg_mouse_mkregion"); 914c8945a0SNathan Whitehorn butPtr->next = regionList; 924c8945a0SNathan Whitehorn regionList = butPtr; 934c8945a0SNathan Whitehorn } 944c8945a0SNathan Whitehorn if (butPtr != 0) { 954c8945a0SNathan Whitehorn butPtr->mode = -1; 964c8945a0SNathan Whitehorn butPtr->step_x = 0; 974c8945a0SNathan Whitehorn butPtr->step_y = 0; 984c8945a0SNathan Whitehorn butPtr->y = basey + y; 994c8945a0SNathan Whitehorn butPtr->Y = basey + y + height; 1004c8945a0SNathan Whitehorn butPtr->x = basex + x; 1014c8945a0SNathan Whitehorn butPtr->X = basex + x + width; 102*2a3e3873SBaptiste Daroussin butPtr->code = basecode + code; 1034c8945a0SNathan Whitehorn } 1044c8945a0SNathan Whitehorn return butPtr; 1054c8945a0SNathan Whitehorn } 1064c8945a0SNathan Whitehorn 1074c8945a0SNathan Whitehorn /* retrieve the frame under the pointer */ 1084c8945a0SNathan Whitehorn static mseRegion * 1094c8945a0SNathan Whitehorn any_mouse_region(int y, int x, int small) 1104c8945a0SNathan Whitehorn { 1114c8945a0SNathan Whitehorn mseRegion *butPtr; 1124c8945a0SNathan Whitehorn 1134c8945a0SNathan Whitehorn for (butPtr = regionList; butPtr; butPtr = butPtr->next) { 114*2a3e3873SBaptiste Daroussin if (small ^ (butPtr->code >= 0)) { 1154c8945a0SNathan Whitehorn continue; 116*2a3e3873SBaptiste Daroussin } 117*2a3e3873SBaptiste Daroussin if (y < butPtr->y || y >= butPtr->Y) { 1184c8945a0SNathan Whitehorn continue; 119*2a3e3873SBaptiste Daroussin } 120*2a3e3873SBaptiste Daroussin if (x < butPtr->x || x >= butPtr->X) { 1214c8945a0SNathan Whitehorn continue; 122*2a3e3873SBaptiste Daroussin } 1234c8945a0SNathan Whitehorn break; /* found */ 1244c8945a0SNathan Whitehorn } 1254c8945a0SNathan Whitehorn return butPtr; 1264c8945a0SNathan Whitehorn } 1274c8945a0SNathan Whitehorn 1284c8945a0SNathan Whitehorn /* retrieve the frame under the pointer */ 1294c8945a0SNathan Whitehorn mseRegion * 1304c8945a0SNathan Whitehorn dlg_mouse_region(int y, int x) 1314c8945a0SNathan Whitehorn { 1324c8945a0SNathan Whitehorn return any_mouse_region(y, x, TRUE); 1334c8945a0SNathan Whitehorn } 1344c8945a0SNathan Whitehorn 1354c8945a0SNathan Whitehorn /* retrieve the bigframe under the pointer */ 1364c8945a0SNathan Whitehorn mseRegion * 1374c8945a0SNathan Whitehorn dlg_mouse_bigregion(int y, int x) 1384c8945a0SNathan Whitehorn { 1394c8945a0SNathan Whitehorn return any_mouse_region(y, x, FALSE); 1404c8945a0SNathan Whitehorn } 1414c8945a0SNathan Whitehorn 1424c8945a0SNathan Whitehorn #else 1434c8945a0SNathan Whitehorn void mouse_dummy(void); 1444c8945a0SNathan Whitehorn void 1454c8945a0SNathan Whitehorn mouse_dummy(void) 1464c8945a0SNathan Whitehorn { 1474c8945a0SNathan Whitehorn } 1484c8945a0SNathan Whitehorn #endif /* USE_MOUSE */ 149