void KprLabelFlagged(KprLabel self) { if (KprContentIsFocus((KprContent)self)) { KprContentInvalidate((KprContent)self); KprContentReflow((KprContent)self, kprPositionChanged); } }
void KPR_canvas_getContext(xsMachine *the) { KprCanvas self = xsGetHostData(xsThis); if (self->cnv) { FskCanvas2dContext ctx = FskCanvasGet2dContext(self->cnv); xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("canvasRenderingContext2D"))); xsSetHostData(xsResult, ctx); xsSet(xsResult, xsID("canvas"), xsThis); KprContentInvalidate((KprContent)self); } }
void KprLabelActivated(void* it, Boolean activateIt) { KprLabel self = it; if (KprContentIsFocus(it)) { KprContentInvalidate(it); if (activateIt) KprContentReflow(it, kprPositionChanged); else KprShellSetCaret(self->shell, self, NULL); KprShellKeyActivate(self->shell, activateIt); } }
FskErr KprLabelSetText(KprLabel self, char* text, UInt32 size) { FskErr err = kFskErrNone; char* buffer; bailIfError(FskMemPtrNew(size + 1, &buffer)); if (size > 0) FskMemMove(buffer, text, size); buffer[size] = 0; self->length = fxUnicodeLength(text); self->from = self->to = 0; FskMemPtrDispose(self->text); self->text = buffer; bail: if (self->shell) { KprLabelMeasureSelection(self); KprContentInvalidate((KprContent)self); KprContentReflow((KprContent)self, kprSizeChanged); } return err; }
FskErr KprLabelInsertStringWithLength(KprLabel self, char* text, UInt32 size) { FskErr err = kFskErrNone; UInt32 oldSize = FskStrLen(self->text); SInt32 fromSize = fxUnicodeToUTF8Offset(self->text, self->from); SInt32 toSize = fxUnicodeToUTF8Offset(self->text, self->to); UInt32 newSize = oldSize - (toSize - fromSize) + size; char* buffer; bailIfError(FskMemPtrNew(newSize + 1, &buffer)); if (fromSize > 0) FskMemMove(buffer, self->text, fromSize); if (size > 0) FskMemMove(buffer + fromSize, text, size); if (oldSize - toSize > 0) FskMemMove(buffer + fromSize + size, self->text + toSize, oldSize - toSize); buffer[newSize] = 0; FskMemPtrDispose(self->text); if (self->flags & kprTextHidden) { if ((self->from == self->length) && (self->to == self->length) && (fxUTF8ToUnicodeOffset(text, size) == 1)) { self->flags |= kprTextShowLast; if (!self->showLastCallback) FskTimeCallbackNew(&self->showLastCallback); FskTimeCallbackScheduleFuture(self->showLastCallback, 1, 0, KprLabelShowLastCallback, self); } else { if (self->showLastCallback) FskTimeCallbackRemove(self->showLastCallback); self->flags &= ~kprTextShowLast; } } self->text = buffer; self->length = fxUnicodeLength(buffer); self->from = self->to = fxUTF8ToUnicodeOffset(buffer, fromSize + size); bail: if (self->shell) { KprLabelMeasureSelection(self); KprContentInvalidate((KprContent)self); KprContentReflow((KprContent)self, kprSizeChanged); } return err; }
FskErr KprLabelSelect(KprLabel self, SInt32 selectionOffset, UInt32 selectionLength) { SInt32 from = selectionOffset; SInt32 to = selectionOffset + selectionLength; if (from < 0) from = 0; else if (from > (SInt32)self->length) from = self->length; if (to < 0) to = 0; else if (to > (SInt32)self->length) to = self->length; self->from = from; self->to = to; if (self->shell) { KprLabelMeasureSelection(self); KprContentInvalidate((KprContent)self); KprContentReflow((KprContent)self, kprPositionChanged); } return kFskErrNone; }