/*------------------------------------------------CIRexxApp::NewScriptIndexDB-+ | Load the scripts DB | +----------------------------------------------------------------------------*/ void CIRexxApp::NewScriptIndexDB() { //<<<JAL since searching for many scripts can be slow, // we draw a little indicator at the start. // palm os does provide a set of progress functions, // but their progress dialog is too much for something simple. Err err; RectangleType saveFrame; WinHandle saveWindow = 0; if (WinGetDrawWindow()) { // If we can't draw yet, forget it! const char * s = getRexxAppMessage(msgRexxIsStarting); // the text in the rectangle const int wFrame = 2; // the width of dialogFrame const int padding = 2; // padding for the text in the rectangle Int16 w = FntCharsWidth(s, StrLen(s)) + (padding * 2); Int16 h = FntCharHeight() + (padding * 2); RectangleType r; RctSetRectangle(&r, (160-w)/2, (160-h)/2, w, h); RctSetRectangle(&saveFrame, r.topLeft.x-wFrame, r.topLeft.y-wFrame, r.extent.x+(wFrame*2), r.extent.y+(wFrame*2)); saveWindow = WinSaveBits(&saveFrame, &err); WinDrawRectangleFrame(dialogFrame, &r); WinDrawChars(s, StrLen(s), r.topLeft.x+padding, r.topLeft.y+padding); } initializeIndexDatabase(); if (saveWindow) { WinRestoreBits(saveWindow, saveFrame.topLeft.x, saveFrame.topLeft.y); } return; }
/*********************************************************************** * * FUNCTION: RepeatDescRectHandler * * DESCRIPTION: This routine is the event handler for rectangle gadget * surrounding the repeat description in the "Repeat * Dialog Box". * * Instead of drawing a static rectangle the size of the * gadget bounds, I have sized the gadget to be the full area * of the repeat dialog the description field will still fit * should the field have to be slightly resized for any reason. * The bounding rect drawn is calculated from the field's * bounding rect. * * PARAMETERS: gadgetP - pointer to the gadget * cmd - the event type to be handled * paramp - any additional data that is passed to the gadget * * RETURNED: true if the event was handled and should not be passed * to a higher level handler. * ***********************************************************************/ static Boolean RepeatDescRectHandler(FormGadgetTypeInCallback *gadgetP, UInt16 cmd, void *paramP) { FieldType* fld = NULL; RectangleType r; Boolean handled = false; switch(cmd) { case formGadgetEraseCmd: case formGadgetDrawCmd: /* Get the repeat description field and calculate a bounding box */ fld = GetObjectPointer(FrmGetFormPtr(RepeatForm), RepeatDescField); FldGetBounds (fld, &r); RctInsetRectangle (&r, -4); if (cmd == formGadgetDrawCmd) WinDrawRectangleFrame(simpleFrame, &r); else WinEraseRectangle(&r, 0); handled = true; break; case formGadgetHandleEventCmd: /* do nothing */ break; default: break; } return handled; }
void _WinDrawRectangleFrame(FrameType frame, RectangleType *rP) { if (hires) HRWinDrawRectangleFrame(hires, frame, rP); else WinDrawRectangleFrame(frame, rP); }
void TPointDraw(TPoint_type p1) { RectangleType rt = { {(short int) (p1.x - POINTSIZE), (short int) (p1.y - POINTSIZE)}, {(short int) (POINTSIZE * 2 + 1), (short int) (POINTSIZE * 2 + 1)} }; WinDrawRectangleFrame(simpleFrame, &rt); }
/***************************************************************************** * Function: GadgetDrawHint * * Description: Draw the hintbox with the hint *****************************************************************************/ void GadgetDrawHint(const char *toptext, const char *bottext, UInt16 note) { RectangleType bounds; UInt16 gadgetIndex; RectangleType rect, textbox_top, textbox_bot; FontID oldFont; ControlType *ctl; Char noteSymb[2] = { GADGET_NOTESYMBOL, 0 }; // Not needed any longer, the hint now has its own Gadget // UInt16 top = GADGET_TOP + (GADGET_STRINGS_NUM-1) * GADGET_STRINGS_OFFSET + 5; // 6 - const = VALUE BELOW if (! gForm) return; gadgetIndex = FrmGetObjectIndex(gForm, gHintGadgetID); FrmGetObjectBounds(gForm, gadgetIndex, &bounds); WinEraseRectangle(&bounds, 0); RctSetRectangle(&rect, bounds.topLeft.x+1, // +1 for border bounds.topLeft.y+1, // Put VALUE BELOW here.... +top+1 removed because of own Gadget bounds.extent.x-3, bounds.extent.y - 3); // -4 for bottom border // Erase Gadget area WinSetForeColor(UIColorGetTableEntryIndex(UIObjectFrame)); WinDrawRectangleFrame(popupFrame, &rect); RctSetRectangle(&textbox_top, rect.topLeft.x+2, rect.topLeft.y, rect.extent.x-2,(Int16)((rect.extent.y-2)/2)); RctSetRectangle(&textbox_bot, textbox_top.topLeft.x, textbox_top.topLeft.y+textbox_top.extent.y+1, textbox_top.extent.x, textbox_top.extent.y); oldFont=FntSetFont(boldFont); TNDrawCharsToFitWidth(toptext, &textbox_top); FntSetFont(oldFont); TNDrawCharsToFitWidth(bottext, &textbox_bot); gHintNote = note; if (note) { // This time has a note oldFont = FntSetFont(symbolFont); RctSetRectangle(&rect, rect.topLeft.x+rect.extent.x-8, rect.topLeft.y+rect.extent.y-12, FntLineWidth(noteSymb, 1), FntLineHeight()); TNDrawCharsToFitWidth(noteSymb, &rect); FntSetFont(oldFont); } ctl=GetObjectPtr(BUTTON_edit); CtlShowControl(ctl); ctl=GetObjectPtr(BUTTON_beam); CtlShowControl(ctl); }
/* ** TrackXferDone */ static void TrackXferDone(DynamicButtonType* btn) { RectangleType bounds[5], frame, popFrame, popShadowFrame; Boolean penDown, on_button; Int16 x, y, clicked_on = 0; Int16 state = 1; Int16 i = 0; WinHandle offscreenH = NULL; FormType* frm = FrmGetActiveForm(); const UInt16 listIdx = FrmGetObjectIndex(frm, XferDoneList); ListType* list = FrmGetObjectPtr(frm, listIdx); UInt16 width = 0, choices = 0; Err err = errNone; Char str[48]; Int16 n = 0; /* Save the old drawing context */ WinPushDrawState(); /* This should match the XferDoneButton bounds */ FrmGetObjectBounds(frm, FrmGetObjectIndex(frm, btn->id), &bounds[0]); /* Invert the done button */ SelectAndDrawButton(btn, true); SndPlaySystemSound(sndClick); /* Set the status of each menu pick */ for (; i < 4; i++) d.xfer.status[i] = 0x00; if (xferGotoIsAlways) d.xfer.status[0] = TRACKXFERDONE_ALWAYS; else if (xferGotoIsNever) d.xfer.status[0] = TRACKXFERDONE_NEVER; else if (p.flags&PFLAGS_XFER_GOTO) d.xfer.status[0] = TRACKXFERDONE_CHECKED; if (xferCompleteIsAlways) d.xfer.status[1] = TRACKXFERDONE_ALWAYS; else if (xferCompleteIsNever) d.xfer.status[1] = TRACKXFERDONE_NEVER; else if (d.xfer.complete) d.xfer.status[1] = TRACKXFERDONE_CHECKED; if (!d.linker_available) d.xfer.status[2] = TRACKXFERDONE_NEVER; else if (p.flags&PFLAGS_XFER_BACKLINK) d.xfer.status[2] = TRACKXFERDONE_CHECKED; if (p.flags&PFLAGS_XFER_DELETE) d.xfer.status[3] = TRACKXFERDONE_CHECKED; for (i = 0; i < 4; ++i) { if (!(d.xfer.status[i] & TRACKXFERDONE_NEVER)) { d.xfer.choice_map[choices] = i; ++choices; /* calculate list width */ SysCopyStringResource(str, XferMenuOptionsStrings + i); n = FntCharsWidth(str, StrLen(str)); width = Max(width, n); } } LstSetDrawFunction(list, XferDoneListDrawFunc); LstSetListChoices(list, 0, choices); LstSetHeight(list, Min(choices, 10)); FrmGetObjectBounds(frm, listIdx, &frame); frame.topLeft.y = 144 - frame.extent.y - 1; /* -1 to compensate for white border */ frame.extent.x = width + 15 + 6; FrmSetObjectBounds(frm, listIdx, &frame); WinGetFramesRectangle(popupFrame, &frame, &popFrame); WinGetFramesRectangle(rectangleFrame, &popFrame, &popShadowFrame); for (i = 0; i < choices; ++i) RctSetRectangle(&bounds[i+1], frame.topLeft.x, frame.topLeft.y + 10 * i, frame.extent.x, 10); /* Save the bits of the whole menu */ offscreenH = WinSaveBits(&popShadowFrame, &err); if (err) abort(); /* None selected */ LstSetSelection(list, -1); FrmShowObject(frm, listIdx); WinEraseRectangle(&popShadowFrame, 0); LstDrawList(list); WinEraseRectangleFrame(rectangleFrame, &frame); WinDrawRectangleFrame(popupFrame, &frame); do { EvtGetPen(&x, &y, &penDown); if (!state || !RctPtInRectangle(x, y, &bounds[state-1])) { on_button = false; for (i = 1; i <= choices + 1; i++) { if ((state != i) && RctPtInRectangle(x, y, &bounds[i-1])) { /* Invert the new state */ LstSetSelection(list, i - 2); LstDrawList(list); WinEraseRectangleFrame(rectangleFrame, &frame); WinDrawRectangleFrame(popupFrame, &frame); SelectAndDrawButton(btn, i == 1); state = i; on_button = true; } } if (state && !on_button) { /* Moved off the current button */ LstSetSelection(list, -1); LstDrawList(list); WinEraseRectangleFrame(rectangleFrame, &frame); WinDrawRectangleFrame(popupFrame, &frame); if (state == 1) SelectAndDrawButton(btn, false); state = 0; } } } while (penDown); FrmHideObject(frm, listIdx); LstEraseList(list); /* Restore the framed rect */ WinRestoreBits(offscreenH, popShadowFrame.topLeft.x, popShadowFrame.topLeft.y); /* Unselect the button */ SelectAndDrawButton(btn, false); /* Finish up if we just tapped the button */ if (RctPtInRectangle(x, y, &bounds[0])) { FinishXferMode(); /* Restore the old draw state */ WinPopDrawState(); return; } /* Change the setting for goto or delete */ for (i = 1; i <= choices; i++) { if (RctPtInRectangle(x, y, &bounds[i])) { clicked_on = i; break; } } if (clicked_on) clicked_on = d.xfer.choice_map[clicked_on-1] + 1; switch (clicked_on) { case 1: /* Goto */ if (d.xfer.status[0] & TRACKXFERDONE_CHECKED) p.flags &= ~PFLAGS_XFER_GOTO; else if (!d.xfer.status[0]) p.flags |= PFLAGS_XFER_GOTO; break; case 2: /* Complete */ if (d.xfer.status[1] & TRACKXFERDONE_CHECKED) d.xfer.complete = false; else if (!d.xfer.status[1]) d.xfer.complete = true; break; case 3: /* BackLink */ if (d.xfer.status[2] & TRACKXFERDONE_CHECKED) p.flags &= ~PFLAGS_XFER_BACKLINK; else if (!d.xfer.status[2]) { p.flags |= PFLAGS_XFER_BACKLINK; p.flags &= ~PFLAGS_XFER_DELETE; /* No delete if backlink */ } break; case 4: /* Delete */ if (d.xfer.status[3] & TRACKXFERDONE_CHECKED) p.flags &= ~PFLAGS_XFER_DELETE; else if (!d.xfer.status[3]) { p.flags |= PFLAGS_XFER_DELETE; p.flags &= ~PFLAGS_XFER_BACKLINK; /* No backlink if delete */ } break; } /* Click and redraw the button */ if (clicked_on) { DrawXferDoneButton(btn); DynBtnDraw(btn); if (d.xfer.status[clicked_on-1] & TRACKXFERDONE_ALWAYS) SndPlaySystemSound(sndWarning); else SndPlaySystemSound(sndClick); } /* Restore the old draw state */ WinPopDrawState(); }
/***************************************************************************** * Function: GadgetDrawHintCurrent * * Description: Draw hint for current gTimeIndex if needed (may be forced NOT * to draw with GadgetSetNeedsRedraw(false)); *****************************************************************************/ void GadgetDrawHintCurrent(void) { Char *tmp, *bot, begin[timeStringLength], end[timeStringLength], *day; MemHandle mc, mt, mh, type; CourseDBRecord c; TimeDBRecord *tc; RectangleType rect, bounds; UInt16 gadgetIndex = FrmGetObjectIndex(gForm, gGadgetID); RGBColorType color, prevColor; UInt16 attr; // Need to check that due to damn f*** DmRecordInfo which will show a // fatal alert when called on non-existing record (this happens for example // right after creating the new database... if ((gTimeIndex >= DmNumRecords(DatabaseGetRef())) || (gCourseIndex >= DmNumRecords(DatabaseGetRef())) ) return; if (gHintDrawn) { // Delete border around previous entry if ( (gTimeDrawnIndex < DmNumRecords(DatabaseGetRef())) && (DmRecordInfo(DatabaseGetRef(), gTimeDrawnIndex, &attr, NULL, NULL) == errNone) ) { attr &= dmRecAttrCategoryMask; if (attr == DatabaseGetCat()) { mt = DmQueryRecord(DatabaseGetRef(), gTimeDrawnIndex); if (mt) { // mt may be null, for example if next is drawn after delete! tc = (TimeDBRecord *)MemHandleLock(mt); if ((tc->type == TYPE_TIME) && GadgetEventIsVisible(tc) ) { TNlist *tmpl = gGadgetTimeList; GadgetTimeListType *gtl = NULL; while (tmpl != NULL) { gtl = tmpl->data; if (gtl->index == gTimeDrawnIndex) { break; } tmpl = tmpl->next; } color.r=tc->color[0]; color.g=tc->color[1]; color.b=tc->color[2]; if (gPrefs.showTimeline) GadgetDrawTimeline(gtErase); if (gtl != NULL) { GadgetDrawTime(tc->begin, tc->end, tc->day, &color, tc->course, gtl->num, gtl->pos); } if (gPrefs.showTimeline) GadgetDrawTimeline(gtDraw); } MemHandleUnlock(mt); } } } } gTimeDrawnIndex=gTimeIndex; gHintDrawn=true; if (DmRecordInfo(DatabaseGetRef(), gCourseIndex, &attr, NULL, NULL) == errNone) { attr &= dmRecAttrCategoryMask; if (attr == DatabaseGetCat()) { // Record is in currently displayed category mc = DmQueryRecord(DatabaseGetRef(), gCourseIndex); if (! mc) return; mt = DmQueryRecord(DatabaseGetRef(), gTimeIndex); if (! mt) return; UnpackCourse(&c, MemHandleLock(mc)); tc = (TimeDBRecord *)MemHandleLock(mt); if ( GadgetEventIsVisible(tc) ) { TNlist *tmpl = gGadgetTimeList; GadgetTimeListType *gtl = NULL; while (tmpl != NULL) { gtl = tmpl->data; if (gtl->index == gTimeDrawnIndex) { break; } tmpl = tmpl->next; } mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+tc->day); day = (Char *)MemHandleLock(mh); // Lecture Name (Teacher) [Typ] tmp=(Char *)MemPtrNew(StrLen(c.name)+StrLen(c.teacherName)+4+3+CTYPE_SHORT_MAXLENGTH); MemSet(tmp, MemPtrSize(tmp), 0); type = MemHandleNew(1); CourseTypeGetShort(&type, c.ctype); StrPrintF(tmp, "%s (%s) [%s]", c.name, c.teacherName, (Char *)MemHandleLock(type)); MemHandleUnlock(type); MemHandleFree(type); // Fr 08:00 - 09:30 (Room) <-- Example // 3 5 3 5 3+StrLen(room) <-- Num Chars for MemPtrNew bot=(Char *)MemPtrNew(20+sizeof(tc->room)+MemPtrSize(day)); MemSet(bot, MemPtrSize(bot), 0); TimeToAscii(tc->begin.hours, tc->begin.minutes, GadgetGetTimeFormat(), begin); TimeToAscii(tc->end.hours, tc->end.minutes, GadgetGetTimeFormat(), end); mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+tc->day); StrPrintF(bot, "%s %s - %s (%s)", day, begin, end, tc->room); FrmGetObjectBounds(gForm, gadgetIndex, &bounds); if (gtl != NULL) { GadgetTimeSetRect(&rect, tc->begin, tc->end, tc->day, gtl->num, gtl->pos); RctSetRectangle(&rect, // + inset (two boxes, one black, one white) rect.topLeft.x + 2, rect.topLeft.y + 2, // width - 2 * inset rect.extent.x - 4, // height - 2 * inset rect.extent.y - 4 ); /* Invert color, looks not so nice aka bad color.r=255- tc->color[0]; color.g=255- tc->color[1]; color.b=255- tc->color[2]; */ color.r=255; color.g=255; color.b=255; TNSetForeColorRGB(&color, &prevColor); WinDrawRectangleFrame(simpleFrame, &rect); color.r=0; color.g=0; color.b=0; RctSetRectangle(&rect, rect.topLeft.x-1, rect.topLeft.y-1, rect.extent.x+2, rect.extent.y+2); TNSetForeColorRGB(&color, NULL); WinDrawRectangleFrame(simpleFrame, &rect); TNSetForeColorRGB(&prevColor, NULL); } // WinInvertRectangleFrame(simpleFrame, &rect); GadgetDrawHint(tmp, bot, tc->note); MemPtrFree((MemPtr) tmp); MemPtrFree((MemPtr) bot); MemHandleUnlock(mh); } else { MemHandleUnlock(mc); MemHandleUnlock(mt); GadgetDrawHintNext(); return; } MemHandleUnlock(mc); MemHandleUnlock(mt); } // End attr == current category } }
/***************************************************************************** * Function: GadgetDraw * * Description: Draws the basic gadget (grid, days, times) *****************************************************************************/ void GadgetDraw(Boolean eraseFirst) { RectangleType bounds; UInt8 i, gadgetWidth; RGBColorType color, prevColor; UInt16 gadgetIndex; RectangleType rect; FormType *frm=gForm; // Check if GadgetSet has already been called. If not => die if (! frm) return; gadgetIndex = FrmGetObjectIndex(frm, gGadgetID); FrmGetObjectBounds(frm, gadgetIndex, &bounds); // Erase background if (eraseFirst) WinEraseRectangle(&bounds, 0); // Write Times if (gGadgetCurScreen == GADGET_SCREEN_DAY) { for (i=0; i < 7; i++) { // 7 because we have to write 7 times 08:00, 10:00,..., 20:00 Char time[timeStringLength]; if (i < 1) StrPrintF(time, "0%u:00", 8+i*2); else StrPrintF(time, "%u:00", 8+i*2); WinDrawChars(time, StrLen(time), bounds.topLeft.x+GADGET_BASELEFT, (i != 7 - 1) ? bounds.topLeft.y+GADGET_STRINGS_TOP+i*GADGET_STRINGS_OFFSET /* ^last^ */ : bounds.topLeft.y+GADGET_STRINGS_TOP+i*GADGET_STRINGS_OFFSET-2); } } else { for (i=0; i < 2; i++) { Char time[timeStringLength]; StrPrintF(time, "%u:00", 20+i*2); WinDrawChars(time, StrLen(time), bounds.topLeft.x+GADGET_BASELEFT, bounds.topLeft.y+GADGET_STRINGS_TOP+i*GADGET_STRINGS_OFFSET); } for (i=2; i < 7; i++) { Char time[timeStringLength]; StrPrintF(time, "0%u:00", (i-2)*2); WinDrawChars(time, StrLen(time), bounds.topLeft.x+GADGET_BASELEFT, (i != 7 - 1) ? bounds.topLeft.y+GADGET_STRINGS_TOP+i*GADGET_STRINGS_OFFSET /* ^last^ */ : bounds.topLeft.y+GADGET_STRINGS_TOP+i*GADGET_STRINGS_OFFSET-2); } } // Write Weekdays GadgetDrawWeekdays(); // Draw Grid: Color is light gray on colored palms, dark gray on gray palms if (TNisColored()) { color.r = 0x77; color.g = 0x77; color.b = 0x77; } else { color.r = 0x44; color.g = 0x44; color.b = 0x44; } TNSetForeColorRGB(&color, &prevColor); gadgetWidth=gGadgetDaysNum * gGadgetDaysWidth + gGadgetDaysNum - 1; RctSetRectangle(&rect, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT, bounds.topLeft.y+GADGET_TOP, gadgetWidth, GADGET_HEIGHT); WinDrawRectangleFrame(simpleFrame, &rect); for(i=1; i <= 5; ++i) { // Draw the 5 gray dashed lines if ( (gGadgetCurScreen == GADGET_SCREEN_NIGHT) && (i == 2)) { WinDrawLine(bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT, bounds.topLeft.y+GADGET_TOP+i*GADGET_STRINGS_OFFSET, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gadgetWidth-1, bounds.topLeft.y+GADGET_TOP+i*GADGET_STRINGS_OFFSET); } else { WinDrawGrayLine(bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT, bounds.topLeft.y+GADGET_TOP+i*GADGET_STRINGS_OFFSET, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+gadgetWidth-1, bounds.topLeft.y+GADGET_TOP+i*GADGET_STRINGS_OFFSET); } } for(i=1; i <= gGadgetDaysNum -1; ++i) { WinDrawLine(bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+i*gGadgetDaysWidth+(i-1), bounds.topLeft.y+GADGET_TOP, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+i*gGadgetDaysWidth+(i-1), bounds.topLeft.y+GADGET_TOP+GADGET_HEIGHT-1); } TNSetForeColorRGB(&prevColor, NULL); }