void TCalendarView::draw() { AllocLocalStr(str, size.x + 1); unsigned current = 1 - dayOfWeek(1, month, year); unsigned days = daysInMonth[month] + ((year % 4 == 0 && month == 2) ? 1 : 0); char color, boldColor; int i, j; TDrawBuffer buf; color = getColor(6); boldColor = getColor(7); buf.moveChar(0, ' ', color, size.x); sprintf(str, "%c%12s %4d %c", upArrowChar, monthNames[month], year, downArrowChar); //wsz: to see full year and down arrow /*ostrstream( str, sizeof str) << setw(9) << monthNames[month] << " " << setw(4) << year << " " << (char) 30 << " " << (char) 31 << " " << ends;*/ buf.moveStr(0, str, color); writeLine(0, 0, size.x, 1, buf); buf.moveChar(0, ' ', color, size.x); buf.moveStr(0, "Su Mo Tu We Th Fr Sa", color); writeLine(0, 1, size.x, 1, buf); for (i = 1; i <= 6; i++) { buf.moveChar(0, ' ', color, size.x); for (j = 0; j <= 6; j++) { if (current < 1 || current > days) buf.moveStr(j * 3, " ", color); else { sprintf(str, "%2d", (int) current); if (year == curYear && month == curMonth && current == curDay) buf.moveStr(j * 3, str, boldColor); else buf.moveStr(j * 3, str, color); } current++; } writeLine(0, (short) (i + 1), size.x, 1, buf); } }
//***************************************************************** // a single mouse click is not cleared by List View Box, Dialog uses it // to erase inputline if user clicks off of it . void TListViewDialog::handleEvent(TEvent &event) { AllocLocalStr(b,inputLineLen); switch(event.what) { case evMouseDown: // clears input line if (inputLine->state&sfSelected) { inputLine->hide(); } break; case evKeyDown: switch(event.keyDown.keyCode) { case kbEsc: // clears input line if (inputLine->state&sfSelected) { inputLine->hide(); clearEvent(event); } break; case kbEnter: // saves input line to list box using listBoxPtr if (inputLine->state&sfSelected) { listBoxPtr->putData( (void *)inputLine->getData() ); inputLine->hide(); clearEvent(event); } break; } case evBroadcast: // from List Boxes, infoPtr points to orginator switch (event.message.command) { case cmListItemSelected: // if input line is already showing, hide it if (inputLine->state&sfSelected) { inputLine->hide(); clearEvent(event); } else { // show empty input line int mouseLocY =((TListViewBox *)event.message.infoPtr)->cursor.y ; int mouseLocX =((TListViewBox *)event.message.infoPtr)->origin.x ; listBoxPtr =(TListViewBox *)event.message.infoPtr; inputLine->moveTo(mouseLocX, mouseLocY+2); inputLine->setDataFromStr( (void *)" " ); inputLine->show(); clearEvent(event); } break; case cmListKeyEnter: // enter key pressed in list box, copy data to inputline int mouseLocY =((TListViewBox *)event.message.infoPtr)->cursor.y ; int mouseLocX =((TListViewBox *)event.message.infoPtr)->origin.x ; listBoxPtr =(TListViewBox *)event.message.infoPtr; inputLine->moveTo(mouseLocX, mouseLocY+2); listBoxPtr->getText( b,listBoxPtr->focused,inputLineLen ); inputLine->setDataFromStr( b ); inputLine->show(); clearEvent(event); break; } } // Let TDialog handler do it's thing with any remaining events. TDialog::handleEvent(event); sprintf(b,"%d",listBox->focused); itemNumber->setDataFromStr( b ); itemNumber->draw(); } // end of MyDialogBox::eventHandler()