Example #1
0
        // Given a SpecificLayout, sets any necessary properties to make it suitable to return to the caller of GetBestLayout(LayoutQuery)
        protected SpecificLayout prepareLayoutForQuery(SpecificLayout layout, LayoutQuery query)
        {
            if (layout != null)
            {
                if (layout.Width < 0 || layout.Height < 0)
                {
                    ErrorReporter.ReportParadox("Illegal layout size: " + layout.Size);
                    this.GetBestLayout(query);
                }
            }
            int numMatches;

            //if (query.Debug)
            {
                if (query.ProposedSolution_ForDebugging != null)
                {
                    if (!query.Accepts(query.ProposedSolution_ForDebugging))
                    {
                        ErrorReporter.ReportParadox("Error: the proposed solution was not valid");
                    }
                }
                if (layout != null && !query.Accepts(layout))
                {
                    ErrorReporter.ReportParadox("Error: the returned layout was not valid");
                    LayoutQuery query2 = query.DebugClone();
                    this.GetBestLayout(query2);
                }
            }

            if (layout != null)
            {
                //layout.Set_SourceParent(this);

                numMatches = 0;

                /*foreach (LayoutChoice_Set ancestor in layout.GetAncestors())
                 * {
                 *  if (ancestor == this)
                 *      numMatches++;
                 * }
                 * if (numMatches == 0)
                 *  ErrorReporter.ReportParadox("Error: the returned layout did not come from this layout");
                 * if (numMatches > 1)
                 *  ErrorReporter.ReportParadox("Error: the returned layout contained multiple ancestors matching this one");
                 */
                layout.SourceQuery = query;
            }

            if (this.parents.Count < 1 && !(this is ViewManager))
            {
                throw new InvalidOperationException("No parents assigned to " + this);
            }

            query.OnAnswered(this);

            return(layout);
        }