UNIXworkcode

1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * 3 * ***** BEGIN LICENSE BLOCK ***** 4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 5 * 6 * The contents of this file are subject to the Mozilla Public License Version 7 * 1.1 (the "License"); you may not use this file except in compliance with 8 * the License. You may obtain a copy of the License at 9 * http://www.mozilla.org/MPL/ 10 * 11 * Software distributed under the License is distributed on an "AS IS" basis, 12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 * for the specific language governing rights and limitations under the 14 * License. 15 * 16 * The Original Code is the Microline Widget Library, originally made available under the NPL by Neuron Data <http://www.neurondata.com>. 17 * 18 * The Initial Developer of the Original Code is 19 * Netscape Communications Corporation. 20 * Portions created by the Initial Developer are Copyright (C) 1998 21 * the Initial Developer. All Rights Reserved. 22 * 23 * Contributor(s): 24 * 25 * Alternatively, the contents of this file may be used under the terms of 26 * either the GNU General Public License Version 2 or later (the "GPL"), or 27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 28 * in which case the provisions of the GPL or the LGPL are applicable instead 29 * of those above. If you wish to allow use of your version of this file only 30 * under the terms of either the GPL or the LGPL, and not to allow others to 31 * use your version of this file under the terms of the MPL, indicate your 32 * decision by deleting the provisions above and replace them with the notice 33 * and other provisions required by the GPL or the LGPL. If you do not delete 34 * the provisions above, a recipient may use your version of this file under 35 * the terms of any one of the MPL, the GPL or the LGPL. 36 * 37 * In addition, as a special exception to the GNU GPL, the copyright holders 38 * give permission to link the code of this program with the Motif and Open 39 * Motif libraries (or with modified versions of these that use the same 40 * license), and distribute linked combinations including the two. You 41 * must obey the GNU General Public License in all respects for all of 42 * the code used other than linking with Motif/Open Motif. If you modify 43 * this file, you may extend this exception to your version of the file, 44 * but you are not obligated to do so. If you do not wish to do so, 45 * delete this exception statement from your version. 46 * 47 * ***** END LICENSE BLOCK ***** */ 48 49 /*----------------------------------------------------------------------*/ 50 /* */ 51 /* Name: <XmL/GridUtil.c> */ 52 /* */ 53 /* Description: XmLGrid misc utilities. They are here in order not to */ 54 /* continue bloating Grid.c beyond hope. */ 55 /* */ 56 /* Author: Ramiro Estrugo <ramiro@netscape.com> */ 57 /* */ 58 /* Created: Thu May 28 21:55:45 PDT 1998 */ 59 /* */ 60 /*----------------------------------------------------------------------*/ 61 62 #include "GridP.h" 63 64 #include <assert.h> 65 66 /*----------------------------------------------------------------------*/ 67 /* extern */ int 68 XmLGridGetRowCount(Widget w) 69 { 70 XmLGridWidget g = (XmLGridWidget) w; 71 72 assert( g != NULL ); 73 74 #ifdef DEBUG_ramiro 75 { 76 int rows = 0; 77 78 XtVaGetValues(w,XmNrows,&rows,NULL); 79 80 assert( rows == g->grid.rowCount ); 81 } 82 #endif 83 84 return g->grid.rowCount; 85 } 86 /*----------------------------------------------------------------------*/ 87 /* extern */ int 88 XmLGridGetColumnCount(Widget w) 89 { 90 XmLGridWidget g = (XmLGridWidget) w; 91 92 assert( g != NULL ); 93 94 #ifdef DEBUG_ramiro 95 { 96 int columns = 0; 97 98 XtVaGetValues(w,XmNcolumns,&columns,NULL); 99 100 assert( columns == g->grid.colCount ); 101 } 102 #endif 103 104 return g->grid.colCount; 105 } 106 /*----------------------------------------------------------------------*/ 107 /* extern */ void 108 XmLGridXYToCellTracking(Widget widget, 109 int x, /* input only args. */ 110 int y, /* input only args. */ 111 Boolean * m_inGrid, /* input/output args. */ 112 int * m_lastRow, /* input/output args. */ 113 int * m_lastCol, /* input/output args. */ 114 unsigned char * m_lastRowtype, /* input/output args. */ 115 unsigned char * m_lastColtype,/* input/output args. */ 116 int * outRow, /* output only args. */ 117 int * outCol, /* output only args. */ 118 Boolean * enter, /* output only args. */ 119 Boolean * leave) /* output only args. */ 120 { 121 int m_totalLines = 0; 122 int m_numcolumns = 0; 123 int row = 0; 124 int column = 0; 125 unsigned char rowtype = XmCONTENT; 126 unsigned char coltype = XmCONTENT; 127 128 if (0 > XmLGridXYToRowColumn(widget, 129 x, 130 y, 131 &rowtype, 132 &row, 133 &coltype, 134 &column)) 135 { 136 /* In grid; but, not in any cells 137 */ 138 /* treat it as a leave 139 */ 140 *enter = FALSE; 141 *leave = TRUE; 142 return; 143 }/* if */ 144 145 m_totalLines = XmLGridGetRowCount(widget); 146 m_numcolumns = XmLGridGetColumnCount(widget); 147 148 if ((row < m_totalLines) && 149 (column < m_numcolumns) && 150 ((*m_lastRow != row)|| 151 (*m_lastCol != column) || 152 (*m_lastRowtype != rowtype)|| 153 (*m_lastColtype != coltype))) 154 { 155 *outRow = (rowtype == XmHEADING)?-1:row; 156 *outCol = column; 157 158 if (*m_inGrid == False) 159 { 160 *m_inGrid = True; 161 162 /* enter a cell 163 */ 164 *enter = TRUE; 165 *leave = FALSE; 166 167 }/* if */ 168 else 169 { 170 /* Cruising among cells 171 */ 172 *enter = TRUE; 173 *leave = TRUE; 174 }/* else */ 175 *m_lastRow = row; 176 *m_lastCol = column; 177 *m_lastRowtype = rowtype ; 178 *m_lastColtype = coltype ; 179 }/* row /col in grid */ 180 } 181 /*----------------------------------------------------------------------*/ 182