////////////////////////////////////////////////////////////////////////////// // Service mouse button clicks to inc or dec the selected frequency ////////////////////////////////////////////////////////////////////////////// void CFreqCtrl::mousePressEvent(QMouseEvent * event) { QPoint pt = event->pos(); if(event->button() == Qt::LeftButton) { for(int i=m_DigStart; i<m_NumDigits; i++) { if( InRect( m_DigitInfo[i].dQRect, pt) ) //if in i'th digit { if( m_LRMouseFreqSel ) { DecFreq(); } else { if(pt.y() < m_DigitInfo[i].dQRect.bottom()/2) //top half? IncFreq(); else DecFreq(); //bottom half } } } } else if(event->button() == Qt::RightButton) { for(int i=m_DigStart; i<m_NumDigits; i++) { if( InRect( m_DigitInfo[i].dQRect, pt) ) //if in i'th digit { if( m_LRMouseFreqSel ) { IncFreq(); } else { if(pt.y() < m_DigitInfo[i].dQRect.bottom()/2) //top half? IncDigit(); else DecDigit(); //botom half } } } } }
static void StepValue(Widget W, int a, int b) { Widget Rc = XtParent(XtParent(W)); Position Place; char *buf; #ifdef DEBUG printf("NumEntry - StepValue(%s) - %s\n", XtName(W), XtName(Rc)); #endif buf = XmTextFieldGetString(NumEntry_TextField(Rc)); Place = XmTextFieldGetInsertionPosition(NumEntry_TextField(Rc)); if (buf[Place] != '.') { buf = IncDigit(buf, &Place, a); XmTextFieldSetString(NumEntry_TextField(Rc), buf); XmTextFieldSetInsertionPosition(NumEntry_TextField(Rc), Place); DoMath(Rc); } XtFree(buf); }
static char * IncDigit(char *buf, Position *Place, int a) { if (*Place < 0) { if (a > 0) { buf = XtRealloc(buf, strlen(buf) + 2); memmove(&buf[1], &buf[0], strlen(buf) + 1); buf[0] = '0'; *Place += 1; buf = IncDigit(buf, Place, a); } else { buf[*Place + 1] = '0'; } return (buf); } if ((buf[*Place] >= '0') && (buf[*Place] <= '9')) { buf[*Place] = buf[*Place] + a; if (buf[*Place] > '9') { if (*Place < 0 || buf[*Place - 1] == '-') { buf = XtRealloc(buf, strlen(buf) + 2); memmove(&buf[*Place + 1], &buf[*Place], strlen(buf) + 1); buf[*Place] = '0'; *Place += 1; buf = IncDigit(buf, Place, a); } buf[*Place] = '0'; if (buf[*Place - 1] != '.') { *Place -= 1; buf = IncDigit(buf, Place, a); *Place += 1; } else { *Place -= 2; buf = IncDigit(buf, Place, a); *Place += 2; } } if (buf[*Place] < '0') { buf[*Place] = '9'; if (buf[*Place - 1] != '.') { *Place -= 1; buf = IncDigit(buf, Place, a); *Place += 1; } else { *Place -= 2; buf = IncDigit(buf, Place, a); *Place += 2; } } if (buf[*Place] == '0' && *Place == 0) { *Place -= 1; } } else { } return (buf); }