import "ecere" MainW frmMain {}; int cpLeft[], cpTop[], cpRight[], cpBottom[]; //each childs size/position properties int mostLeft = 0, mostRight = 0, mostTop = 0, mostBottom = 0; //The margines that go outside of ClientSpace the most. int ChildN = 0; //Number of child forms //Children DBa[]; //Children ChildBase[]; /***********************************************************************/ /* WINDOW CLASSES *//*******************************************/ /***********************************************************************/ class MainW : Window { background = lightGray; borderStyle = sizable; minClientSize = { 60, 60 }; hasMaximize = true; hasMinimize = true; hasClose = true; hasMenuBar = true; hasStatusBar = true; size = { 566, 648 }; state = maximized; hasHorzScroll = true; hasVertScroll = true; showInTaskBar = true; moveable = true; bool OnCreate() { ShowDecision(); return true; } void ShowDecision() { FormDecision frmDecision { this}; DBa[0] = {"Decision", frmDecision.position.x,frmDecision.position.y,frmDecision.size.h,frmDecision.size.w}; ChildN++; } } //********************************************* class FormDecision : Window { borderStyle = contour; size = { 500, 500 }; moveable = false; background = frmMain.background; icon = frmMain.icon; autoCreate = true; bool OnCreate() { //FirmLoad(2010,dropbFirmName); ChildCreated(name,position.x,position.y,size.w,size.h); cpLeft[ChildN] = position.x; cpTop[ChildN] = position.y; cpRight[ChildN] = position.x + size.w; cpBottom[ChildN] = position.y + size.h; ChildN++; return true; } void OnDestroyed() { //ChildExited(name); ChildN--; CheckChildrenPos(0,0,0,0,false); } bool OnMoving(int * x, int * y, int w, int h) { CheckChildrenPos(*x,*y,w,h,false); return true; } /***********************************************************************/ /* FUNCTIONS *//************************************************/ /***********************************************************************/ /** CHILDREN **/ void CheckChildrenPos(int x, int y, int w, int h, bool stopMe) { // stopMe = true only when called from the inside.. bool Changed = false; if (x < mostLeft) { mostLeft = x; Changed = true; } if (y < mostTop) { mostTop = y; Changed = true; } if ((x + w) > mostRight) { mostRight = x + w; Changed = true; } if ((y + h) > mostBottom) { mostBottom = y + h; Changed = true; } if (Changed == true) // alocate correct Scroll Area { frmMain.scrollArea.w = mostLeft + mostRight;//scrollArea.h frmMain.scrollArea.h = mostTop + mostBottom;//scrollArea.w } else if (ChildN < 0) // If by mistake there is -1..to avoid the crashes.. { return; } else //Check all Child Windows to find corect h-w area { int i, ll = 0,lt = 0,lr = 0,lb = 0; if (ChildN > 1 && stopMe == false) { for(i = 0; i < (ChildN - 1); i++) // It has to go as (ChildN - 1) because of the [i+1] { //promenjiva = (CONDITION) ? izraz1 : izraz2 ll = (cpLeft[i] < cpLeft[i+1]) ? cpLeft[i] : cpLeft[i+1]; lt = (cpTop[i] < cpTop[i+1]) ? cpTop[i] : cpTop[i+1]; lr = (cpRight[i] < cpRight[i+1]) ? cpRight[i] : cpRight[i+1]; lb = (cpBottom[i] < cpBottom[i+1]) ? cpBottom[i] : cpBottom[i+1]; } CheckChildrenPos(ll,lt,lr-ll,lt-lb,true); } else { mostLeft = (x == 0) ? x : 0; mostTop = (y == 0) ? y : 0; mostBottom = ((y + h) > frmMain.size.h) ? (y + h) : frmMain.size.h; mostRight = ((x + w) > frmMain.size.w) ? (x + w) : frmMain.size.w; /* A nice solution to loose trail when moveing child windows, and it offers the scroll space adjustment. If there is an upgrade to include negative positions, not just positive, the ( X / 2) will prabably need to be removed, cause it's probably going to take one half to one side, and another to other... (not all will be moved to positive numbers side). */ // Create some space to have around the child windows. frmMain.scrollArea.w = (mostLeft / 2) + mostRight; frmMain.scrollArea.h = (mostTop / 2) + mostBottom; /* // Create the scroll area in a way the Window is finished right after the child window frmMain.scrollArea.w = mostRight; frmMain.scrollArea.h = mostBottom; */ } } } bool ChildCreated(char * wName, int wLeft, int wTop, int wWidth, int wHeight)// << --- HERE { /* return values: false - unsuccesfull true - succesfull */ /* What to do: 1. place the values in the class vector (Children[x]) 2. increment children count (ChildN) */ if (ChildN < 0) { // something went off..correct so this works ChildN = 0; }MessageBox {text = wName};//no name... /* -- couses errors to occure //ChildBase[ChildN].cName = wName; // with err - 1423 // without err - 14b3 ChildBase[ChildN].cLeft = wLeft; ChildBase[ChildN].cTop = wTop; ChildBase[ChildN].cWidth = wWidth; ChildBase[ChildN].cHeight = wHeight; ChildN++; */ } int ChildUpdate(char * wName, int wLeft, int wTop, int wWidth, int wHeight) { /* return values: 0 - unsuccesfull 1 - succesfull 2 - unable to find the window (not entered correctly, or the call gave bad name) 3 - negativ values detected but all is registered 4 - negative value detected, and could not finish registration */ /* What to do: 1. find the window with entered name (breake if not found) 2. update it's values.. */ int i; // for(start; end;step){} for(i = 0; i < ChildN; i++) { //1423 /*if (wName == ChildBase[i].cName) { ChildBase[i].cLeft = wLeft; ChildBase[i].cTop = wTop; ChildBase[i].cWidth = wWidth; ChildBase[i].cHeight = wHeight; return (1); }*/ } } bool ChildExited(char * wName) { /* return values: 0 - unsuccesfull 1 - succesfull */ /* What to do: 1. find the window with entered name (breake if not found) 2. erase it 3. find the youngest child and move it here... // maybe better to move all one down, but this way it's faster. */ int i; // for(start; end;step){} for(i = 0; i < ChildN; i++) { /*if (wName == ChildBase[i].cName) { ChildBase[i].cLeft = ChildBase[ChildN-1].cLeft; ChildBase[i].cTop = ChildBase[ChildN-1].cTop; ChildBase[i].cWidth = ChildBase[ChildN-1].cWidth; ChildBase[i].cHeight = ChildBase[ChildN-1].cHeight; ChildN--; delete ChildBase[ChildN]; return (1); }*/ } } /*class Children { char * cName; int cLeft , cTop , cWidth , cHeight ; public: property char * cName { get { return cName; } set { cName = value; } } property int cLeft { get { return cLeft; } set { cLeft = value; } } property int cTop { get { return cTop; } set { cTop = value; } } property int cWidth { get { return cWidth; } set { cWidth = value; } } property int cHeight { get { return cHeight; } set { cHeight = value; } } }*/