private NSMutableArray ReadRectanglesXml(PinboardData.RectangleInfo screenRectangle)
        {
            var list = new NSMutableArray();

            // Read <Rectangles>
            reader.ReadStartElement(rectanglesAtom);
            reader.MoveToContent();

            while (true)
            {
                if (String.ReferenceEquals(reader.Name, rectanglesAtom))
                {
                    reader.ReadEndElement();
                    reader.MoveToContent();
                    break;
                }

                var rectInfo = ReadRectangleXml();

                // Flip the rectangle top to bottom relative to the screen rectangle
                rectInfo.Y = screenRectangle.Height - rectInfo.Y - rectInfo.Height;

                list.Add(rectInfo);
            }

            return list;
        }
        private void WritePinboardXml(XmlWriter writer, PinboardData data)
        {
            writer.WriteStartElement("Pinboard");
            writer.WriteAttributeString("Format", "2");

            WriteRectangleXml(writer, data.ScreenRectangle);

            WriteRectanglesXml(writer, data);
            writer.WriteEndElement();
        }
 private void WriteRectangleXml(XmlWriter writer, PinboardData.RectangleInfo rectInfo)
 {
     writer.WriteStartElement("Rectangle");
     writer.WriteElementString("Name", rectInfo.Name.ToString());
     writer.WriteElementString("X", rectInfo.X.ToString());
     writer.WriteElementString("Y", rectInfo.Y.ToString());
     writer.WriteElementString("Width", rectInfo.Width.ToString());
     writer.WriteElementString("Height", rectInfo.Height.ToString());
     WriteColorXml(writer, rectInfo.Color);
     writer.WriteEndElement();
 }
        private static void WriteRectanglesXml(XmlWriter writer, PinboardData data)
        {
            writer.WriteStartElement("Rectangles");

            foreach (var rectInfo in data.RectInfos)
            {
                WriteRectangleXml(writer, rectInfo);
            }

            writer.WriteEndElement();
        }
        private void WriteRectanglesXml(XmlWriter writer, PinboardData data)
        {
            writer.WriteStartElement("Rectangles");

            for (nuint i = 0; i < data.Rectangles.Count; i++)
            {
                var rectInfo = data.Rectangles.GetItem<PinboardData.RectangleInfo>(i);
                WriteRectangleXml(writer, rectInfo);
            }

            writer.WriteEndElement();
        }
        private static PinboardData ReadPinboardXml(XmlReader reader)
        {
            PinboardData data = new PinboardData();

            reader.ReadStartElement("Pinboard");
            reader.MoveToContent();
            data.ScreenRectInfo = ReadRectangleXml(reader);

            data.RectInfos = ReadRectanglesXml(reader);

            reader.ReadEndElement();
            reader.MoveToContent();

            return data;
        }
        private PinboardData ReadPinboardXml()
        {
            PinboardData data = new PinboardData();

            reader.ReadStartElement("Pinboard");

            // TODO: Check that version is 2

            reader.MoveToContent();
            data.ScreenRectangle = ReadRectangleXml();

            data.Rectangles = ReadRectanglesXml();

            reader.ReadEndElement();
            reader.MoveToContent();

            return data;
        }
        public override bool ReadFromUrl(NSUrl url, string typeName, out NSError outError)
        {
            outError = null;

            try
            {
                unsafe
                {
                    this.Pinboard = new PinboardDataReaderV1().ReadFromUrl(url.AbsoluteString);
                }
            }
            catch
            {
                // TODO: Set pinboard specific error here
                outError = NSError.FromDomain(NSError.OsStatusErrorDomain, -4);
                return false;
            }

            return true;
        }
        private PinboardData ReadPinboardXml()
        {
            PinboardData data = new PinboardData();

            var format = reader.GetAttribute("Format");

            if (format == null || format != "1")
                // TODO: Don't throw exception, return null with an error code
                throw new FormatException(String.Format("Pinboard "));

            reader.ReadStartElement("Pinboard");

            reader.MoveToContent();
            data.ScreenRectangle = ReadRectangleXml();

            data.Rectangles = ReadRectanglesXml(data.ScreenRectangle);

            reader.ReadEndElement();
            reader.MoveToContent();

            return data;
        }
 public void WriteXml(XmlWriter writer, PinboardData data)
 {
     WritePinboardXml(writer, data);
 }
Exemple #11
0
        private void DrawRectangle(CGContext g, PinboardData.RectangleInfo rectInfo)
        {
            g.SetFillColor(rectInfo.Color);
            g.FillRect(rectInfo.Rectangle);

            float pw = 0.5f;
            CGColor rectBorderColor = new CGColor(0f, rectInfo.Color.Alpha);

            g.SetLineWidth(pw);
            g.SetStrokeColor(rectBorderColor);
            g.SetFillColor(rectInfo.Color);
            g.SetLineJoin(CGLineJoin.Miter);
            g.BeginPath();
            g.StrokeRect(rectInfo.Rectangle);

            int margin = 5;
            // TODO: Make the font configurable
            NSFont font = NSFont.FromFontName("Helvetica", 12f);
            NSObject[] objects = new NSObject[] { font, (NSNumber)0 };
            NSObject[] keys = new NSObject[] { NSAttributedString.FontAttributeName, NSAttributedString.LigatureAttributeName };
            NSDictionary attributes = NSDictionary.FromObjectsAndKeys(objects, keys);
            NSAttributedString attrString = new NSAttributedString(rectInfo.Name, attributes);

            attrString.DrawString(new RectangleF(rectInfo.X + margin, rectInfo.Y + margin, rectInfo.Width - 2 * margin, rectInfo.Height - 2 * margin));
        }