//---------------------------------------------------------------------------- // Project rect // jyu // Copyright © Vesa Lappalainen 1996. All Rights Reserved. // // SUBSYSTEM: rect.apx Application // FILE: rctdcmnt.cpp // AUTHOR: vl // // OVERVIEW // ~~~~~~~~ // Source file for implementation of TRectDocument (TFileDocument). // //---------------------------------------------------------------------------- #include #include #include "rctdcmnt.h" //{{TRectDocument Implementation}} TRectDocument::TRectDocument(TDocument* parent) : TFileDocument(parent), rcount(0) { // INSERT>> Your constructor code here. } TRectDocument::~TRectDocument() { // INSERT>> Your destructor code here. } const TRect *TRectDocument::GetRect(unsigned int index) const { if ( index >= rcount ) return NULL; return &Rect[index]; } const char *TRectDocument::GetRectText(unsigned int index) const { if ( index >= rcount ) return NULL; static char text[100]; wsprintf(text,"%d %d %d %d",Rect[index].left, Rect[index].top, Rect[index].right, Rect[index].bottom ); return text; } bool TRectDocument::Open(int mode, const char far* path) { TInStream* is = InStream(mode,path); if ( !is ) return false; int i = 0; do { *is >> Rect[i].left; *is >> Rect[i].top; *is >> Rect[i].right; *is >> Rect[i].bottom; if ( is->fail() ) break; i++; } while ( i < MAX_RECT ); rcount = i; delete is; SetDirty(false); return true; } bool TRectDocument::InitDoc() { // INSERT>> Your code here. if ( IsOpen() ) return true; if ( !GetDocPath() ) return true; // Uusi tiedosto return Open(ofRead); } bool TRectDocument::Commit(bool force) { if ( !IsDirty() && !force ) return true; TOutStream* os = OutStream(ofWrite); if ( !os ) return false; for ( int i=0; i= rcount ) { if ( rcount >= MAX_RECT ) return false; index = rcount++; } Rect[index] = rect; NotifyViews(vnRectModify,rcount-1); SetDirty(true); return true; } bool TRectDocument::SetRect(const char *text, unsigned int index) { TRect rect(0,0,50,50); sscanf(text,"%d %d %d %d",&rect.left, &rect.top, &rect.right, &rect.bottom ); return SetRect(rect,index); } bool TRectDocument::DelRect(unsigned int index) { if ( index >= rcount ) index = rcount-1; if ( rcount == 0 ) return false; rcount--; for (int i=index; i