void DBVPolyIF::FourColoring () { char nameStr [DBStringLength]; DBInt symbol, maxSymbol = 0, line, index; DBObjRecord *polyRec,*searchPoly, *neighborPolyRec, *lineRec, *symRec; for (polyRec = FirstItem ();polyRec != (DBObjRecord *) NULL;polyRec = NextItem ()) SymbolFLD->Record (polyRec,(DBObjRecord *) NULL); ListSort (LineNumFLD); for (searchPoly = FirstItem ();searchPoly != (DBObjRecord *) NULL;searchPoly = NextItem ()) { if (((DBInt) (SymbolFLD->Record (searchPoly) - (DBObjRecord *) NULL)) != 0) continue; DBPause (searchPoly->RowID () * 100 / ItemNum ()); symbol = 1; Restart: for (polyRec = ItemTable->First (&index);polyRec != (DBObjRecord *) NULL;polyRec = ItemTable->Next (&index)) { if (strcmp (polyRec->Name (),searchPoly->Name ()) != 0) continue; lineRec = FirstLine (polyRec); for (line = 0;line <= LineNum (polyRec);++line) { if (LineRightPoly (lineRec) == polyRec) { neighborPolyRec = LineLeftPoly (lineRec); lineRec = LineNextLine (lineRec); } else { neighborPolyRec = LineRightPoly (lineRec); lineRec = LinePrevLine (lineRec); } if (neighborPolyRec == (DBObjRecord *) NULL) continue; if (SymbolFLD->Record (neighborPolyRec) == (DBObjRecord *) symbol) { symbol++; goto Restart; } } } for (polyRec = ItemTable->First (&index);polyRec != (DBObjRecord *) NULL;polyRec = ItemTable->Next (&index)) if (strcmp (polyRec->Name (),searchPoly->Name ()) == 0) SymbolFLD->Record (polyRec,(DBObjRecord *) symbol); maxSymbol = maxSymbol > symbol ? maxSymbol : symbol; } while (maxSymbol < SymbolTable->ItemNum ()) SymbolTable->Remove (SymbolTable->ItemNum () - 1); while (maxSymbol > SymbolTable->ItemNum ()) SymbolTable->Add (); for (symbol = 0;symbol < SymbolTable->ItemNum ();++symbol) { symRec = SymbolTable->Item (symbol); sprintf (nameStr,"Symbol:%2d",symbol); symRec->Name (nameStr); StyleFLD->Int (symRec,0); ForegroundFLD->Int (symRec,1); BackgroundFLD->Int (symRec,0); } for (polyRec = FirstItem ();polyRec != (DBObjRecord *) NULL;polyRec = NextItem ()) SymbolFLD->Record (polyRec,SymbolTable->Item ((DBInt) (SymbolFLD->Record (polyRec) - (DBObjRecord *) NULL) - 1)); ListReset (); }
void PrintLine1(char * text) { ClearLine1(); FirstLine(); delay(10); Show((unsigned char*)text); }
DBCoordinate *DBVPolyIF::Vertexes (const DBObjRecord *polyRec) const { DBInt vertex, i, line; DBObjRecord *lineRec, *nodeRec,*firstNodeRec; DBCoordinate *lcoords; vertex = 0; lineRec = FirstLine (polyRec); firstNodeRec = nodeRec = LineRightPoly (lineRec) == polyRec ? FromNode (lineRec) : ToNode (lineRec); for (line = 0;line < LineNum (polyRec);++line) { if (LineRightPoly (lineRec) == polyRec) { if (nodeRec != FromNode (lineRec)) { CoordsPTR [vertex++] = NodeCoord (nodeRec); if (nodeRec != firstNodeRec) CoordsPTR [vertex++] = NodeCoord (firstNodeRec); nodeRec = FromNode (lineRec); } CoordsPTR [vertex++] = NodeCoord (nodeRec); if (DBVLineIF::VertexNum(lineRec) > 0) { lcoords = DBVLineIF::Vertexes (lineRec); for (i = 0;i < DBVLineIF::VertexNum (lineRec);++i) CoordsPTR [vertex++] = lcoords [i]; } nodeRec = ToNode (lineRec); lineRec = LineNextLine (lineRec); } else { if (nodeRec != ToNode (lineRec)) { CoordsPTR [vertex++] = NodeCoord (nodeRec); if (nodeRec != firstNodeRec) CoordsPTR [vertex++] = NodeCoord (firstNodeRec); nodeRec = ToNode (lineRec); } CoordsPTR [vertex++] = NodeCoord (nodeRec); if (DBVLineIF::VertexNum (lineRec) > 0) { lcoords = (DBCoordinate *) (DBVLineIF::Vertexes (lineRec)); for (i = DBVLineIF::VertexNum (lineRec);i > 0;--i) CoordsPTR [vertex++] = lcoords [i - 1]; } nodeRec = FromNode (lineRec); lineRec = LinePrevLine (lineRec); } } CoordsPTR [vertex++] = NodeCoord (nodeRec); if (nodeRec != firstNodeRec) CoordsPTR [vertex++] = NodeCoord (firstNodeRec); if (VertexNum (polyRec) != vertex) CMmsgPrint (CMmsgAppError, "Warning in Polygon %d VertexNum [%d %d] in: %s %d",polyRec->RowID (), VertexNum (polyRec),vertex,__FILE__,__LINE__); return (CoordsPTR); }
//Default version bool OBPlugin::Display(string& txt, const char* param, const char* ID) { //Use the provided ID if possible. if(ID) txt = ID; else txt = GetID(); txt += " ";// was '\t'; but caused problems in GUI menu if(param && !strcasecmp(param, "verbose")) { txt += Description(); txt += '\n'; } else txt += FirstLine(Description()); return true; }
BOOL FAR MergeFile(LPSTR FileName, int view) { HCURSOR hSaveCursor; char line[MAX_USER_LINE + 1]; int offset; //Current offset of storage in block int lineLen; // length of line BYTE prevLength; //Previous line size LPVIEWREC v = &Views[view]; WORD res; LPDOCREC d =&Docs[v->Doc]; LPLINEREC pCurLine, pLastLine; LPBLOCKDEF pCurBlock, pNewBlock; long y; Assert( v->Doc >= 0); if ((hFileDoc = _lopen(FileName, OF_READ)) == HFILE_ERROR) return ErrorBox(ERR_File_Open, (LPSTR)FileName); if ((pszBufferDoc = DocAlloc(DISK_BLOCK_SIZE)) == NULL) { ErrorBox(SYS_Allocate_Memory); goto error1; } dwBytesReadDoc = DISK_BLOCK_SIZE; dwOffsetDoc = DISK_BLOCK_SIZE; lineLen = 0; //Delete selected text if any if (v->BlockStatus) { long XR, YR; GetBlockCoord (view, &(v->X), &(v->Y), &XR, &YR); DeleteStream(view, v->X, v->Y, XR, YR, FALSE); } //Set the Hour glass cursor hSaveCursor = SetCursor(LoadCursor(NULL, IDC_WAIT)); //Insert first line res = LoadLine(line, &lineLen, d->NbLines); if (res == END_OF_FILE || res == END_OF_LINE) { //Add a CR+LF if (res == END_OF_LINE) { line[lineLen] = CR; line[lineLen + 1] = LF; lineLen += 2; } if (!InsertBlock(v->Doc, v->X, v->Y, (WORD) lineLen, line)) goto error2; } else { if (res == ERR_File_Read || res == ERR_Not_A_Text_File) ErrorBox(res, (LPSTR)FileName); goto error2; } if (res != END_OF_FILE) { //Get current line status (we just inserted it) y = v->Y; if (!FirstLine(v->Doc, &pCurLine, &y, &pCurBlock)) return FALSE; //Get next line (just after the line we just inserted) if (!NextLine(v->Doc, &pCurLine, &y, &pCurBlock)) return FALSE; //Set offset to StoreLine start offset = (LPSTR)pCurLine - (LPSTR)pCurBlock->Data; prevLength = pCurLine->PrevLength; //Split block in 2 blocks by first allocating a new block and then //copying right side of block in new block if (!AllocateBlock(pCurBlock, pCurBlock->NextBlock, &pNewBlock)) return FALSE; pLastLine = (LPLINEREC)(pCurBlock->Data + pCurBlock->LastLineOffset); memmove(pNewBlock->Data, (LPSTR)pCurLine, (LPSTR)pLastLine - (LPSTR)pCurLine + pLastLine->Length); //Set new old block len and new new block len pCurBlock->LastLineOffset = (LPSTR)pCurLine - (LPSTR)pCurBlock->Data - pCurLine->PrevLength; pNewBlock->LastLineOffset = (LPSTR)pLastLine - (LPSTR)pCurLine; //Backward links next block with new one if (pCurBlock->NextBlock == NULL) d->LastBlock = pNewBlock; else (pCurBlock->NextBlock)->PrevBlock = pNewBlock; //Forward link current block with new block pCurBlock->NextBlock = pNewBlock; CloseLine(v->Doc, &pCurLine, y, &pCurBlock); //Read and store all lines in new blocks res = LoadLine(line, &lineLen, d->NbLines); while (res == END_OF_LINE) { //Truncate a file too large if (d->NbLines >= MAX_LINE_NUMBER - 1) { ErrorBox(ERR_Truncate_Doc); res = END_OF_FILE; break; } if (!StoreLine(line, lineLen, &offset, &prevLength, &pCurBlock)) { res = END_ABORT; break; } res = LoadLine(line, &lineLen, ++d->NbLines); } //Take decisions switch (res) { case END_OF_FILE: //Store last line if (StoreLine(line, lineLen, &offset, &prevLength, &pCurBlock)) { d->NbLines++; //Forward link of last allocated block with new block pCurBlock->NextBlock = pNewBlock; //Backward link of new block with last allocated block pNewBlock->PrevBlock = pCurBlock; ((LPLINEREC)(pNewBlock->Data))->PrevLength = (BYTE)(lineLen + LHD); //Free memory if (!DocFree(pszBufferDoc)) InternalErrorBox(SYS_Free_Memory); //Restore cursor SetCursor(hSaveCursor); //Check syntax if C if (d->language == C_LANGUAGE) { d->lineTop = 0; d->lineBottom = d->NbLines; CheckSyntax(v->Doc); } SetVerticalScrollBar(view, TRUE); PosXY(view, v->X, v->Y, FALSE); InvalidateRect(v->hwndClient, (LPRECT)NULL, FALSE); CloseHandle (hFileDoc); return TRUE; } else goto abort; case ERR_File_Read: case ERR_Not_A_Text_File: ErrorBox(res, (LPSTR)FileName); //Fall through case END_ABORT: { abort: SetCursor(hSaveCursor); break; } default: Assert(FALSE); break; } } else InvalidateRect(v->hwndClient, (LPRECT)NULL, FALSE); error2: { SetCursor (hSaveCursor); if (!DocFree(pszBufferDoc)) InternalErrorBox(SYS_Free_Memory); } error1: { CloseHandle (hFileDoc); } return FALSE; } /* MergeFile() */
//Save document with (possibly) a new file name BOOL FAR SaveDocument(int doc, LPSTR FileName) { LPLINEREC pl; LPBLOCKDEF pb; long y; register WORD i; WORD len; HCURSOR hSaveCursor; LPDOCREC d = &Docs[doc]; //Set the Hour glass cursor hSaveCursor = SetCursor(LoadCursor(NULL, IDC_WAIT)); //Create file if (HFILE_ERROR == (hFileDoc = _lcreat(FileName, 0)) ) { ErrorBox(ERR_File_Create, (LPSTR)FileName); goto error0; } //Allocate space for Disk Buffer if ((pszBufferDoc = DocAlloc(DISK_BLOCK_SIZE)) == NULL) { ErrorBox(SYS_Allocate_Memory); goto error1; } dwOffsetDoc = 0; y = 0; //Get first line if (!FirstLine (doc, &pl, &y, &pb)) return FALSE; //Save each line of file while (TRUE) { //Remove trailing blanks len = (WORD) (pl->Length - LHD); { TCHAR *pch1; pch1 = pl->Text + (pl->Length - LHD); while (pch1 > pl->Text) { pch1 = CharPrev(pl->Text, pch1); if (*pch1 != ' ' && *pch1 != TAB) { break; } len --; } } //Write line i = 0; while (i < len) { PutChar(FileName, pl->Text[i]); i++; } if (y >= d->NbLines) { if (dwOffsetDoc && !Flush(FileName)) goto error2; break; } else { PutChar (FileName, CR); PutChar (FileName, LF); if (!NextLine (doc, &pl, &y, &pb)) goto error2; } } CloseHandle (hFileDoc); //Update internal file date GetSystemTimeAsFileTime(&d->time); CloseLine(doc, &pl, y, &pb); d->ismodified = FALSE; RefreshWindowsTitle(doc); SetCursor (hSaveCursor); return TRUE; error2: CloseLine(doc, &pl, y, &pb); if (!DocFree(pszBufferDoc)) InternalErrorBox(SYS_Free_Memory); error1: CloseHandle (hFileDoc); error0: SetCursor (hSaveCursor); return FALSE; } /* SaveDocument() */
void TextEdit::Key(const KeyInput &input) { if (!HasFocus()) return; // Process navigation keys. These aren't chars. if (input.flags & KEY_DOWN) { switch (input.keyCode) { case NKCODE_CTRL_LEFT: case NKCODE_CTRL_RIGHT: ctrlDown_ = true; break; case NKCODE_DPAD_LEFT: // ASCII left arrow u8_dec(text_.c_str(), &caret_); break; case NKCODE_DPAD_RIGHT: // ASCII right arrow u8_inc(text_.c_str(), &caret_); break; case NKCODE_MOVE_HOME: case NKCODE_PAGE_UP: caret_ = 0; break; case NKCODE_MOVE_END: case NKCODE_PAGE_DOWN: caret_ = (int)text_.size(); break; case NKCODE_FORWARD_DEL: if (caret_ < (int)text_.size()) { int endCaret = caret_; u8_inc(text_.c_str(), &endCaret); undo_ = text_; text_.erase(text_.begin() + caret_, text_.begin() + endCaret); } break; case NKCODE_DEL: if (caret_ > 0) { int begCaret = caret_; u8_dec(text_.c_str(), &begCaret); undo_ = text_; text_.erase(text_.begin() + begCaret, text_.begin() + caret_); caret_--; } break; } if (ctrlDown_) { switch (input.keyCode) { case NKCODE_C: // Just copy the entire text contents, until we get selection support. System_SendMessage("setclipboardtext", text_.c_str()); break; case NKCODE_V: { std::string clipText = System_GetProperty(SYSPROP_CLIPBOARD_TEXT); clipText = FirstLine(clipText); if (clipText.size()) { // Until we get selection, replace the whole text undo_ = text_; text_.clear(); caret_ = 0; size_t maxPaste = maxLen_ - text_.size(); if (clipText.size() > maxPaste) { int end = 0; while ((size_t)end < maxPaste) { u8_inc(clipText.c_str(), &end); } if (end > 0) { u8_dec(clipText.c_str(), &end); } clipText = clipText.substr(0, end); } InsertAtCaret(clipText.c_str()); } } break; case NKCODE_Z: text_ = undo_; break; } } if (caret_ < 0) { caret_ = 0; } if (caret_ > (int)text_.size()) { caret_ = (int)text_.size(); } } if (input.flags & KEY_UP) { switch (input.keyCode) { case NKCODE_CTRL_LEFT: case NKCODE_CTRL_RIGHT: ctrlDown_ = false; break; } } // Process chars. if (input.flags & KEY_CHAR) { int unichar = input.keyCode; if (unichar >= 0x20 && !ctrlDown_) { // Ignore control characters. // Insert it! (todo: do it with a string insert) char buf[8]; buf[u8_wc_toutf8(buf, unichar)] = '\0'; if (strlen(buf) + text_.size() < maxLen_) { undo_ = text_; InsertAtCaret(buf); } } } }
virtual uint32_t CurrentLine() const { return FirstLine(); }
void NextLine() { if ( ++m_yCaret == m_yChars ) FirstLine(); }
void printLine1(char * text) { FirstLine(); delay(10); Show((unsigned char*)text); }