Пример #1
0
        //----------------------------------------------------
        /// <summary>
        /// Crée l'image d'un item
        /// </summary>
        /// <param name="item"></param>
        /// <param name="bGereItemEnCours">si true, en sortie, le contrôle
        /// aura repris l'aspect qu'il avait avant</param>
        /// <returns></returns>
        public Image CreateImage(CCustomizableListItem item, bool bGereItemEnCours)
        {
            CCustomizableListItem old = m_currentItem;

            IsCreatingImage = true;
            if (item != m_currentItem || AspectDifferentEnInactif)
            {
                OnStartCreateImage();
                if (bGereItemEnCours)
                {
                    MajChamps();
                }
                InitChamps(item);
            }
            Image img = CreateCurrentItemImage();

            IsCreatingImage = false;
            if (item != m_currentItem)
            {
                if (bGereItemEnCours)
                {
                    InitChamps(old);
                }
            }

            return(img);
        }
Пример #2
0
 //-------------------------------------------
 private void AddToDicImages(CCustomizableListItem item, CCacheImage cache)
 {
     m_dicItemToImage[item] = cache;
     if (m_dicItemToImage.Count > m_nMaxImagesInCache)
     {
         //Supprime l'image la plus vieille
         DateTime?dt = null;
         KeyValuePair <CCustomizableListItem, CCacheImage>?toDelete = null;
         foreach (KeyValuePair <CCustomizableListItem, CCacheImage> kv in m_dicItemToImage)
         {
             if (dt == null || kv.Value.LastAcces < dt.Value)
             {
                 toDelete = kv;
                 dt       = kv.Value.LastAcces;
             }
         }
         if (toDelete != null)
         {
             if (toDelete.Value.Value.Image != null)
             {
                 toDelete.Value.Value.Image.Dispose();
             }
             m_dicItemToImage.Remove(toDelete.Value.Key);
         }
     }
 }
Пример #3
0
 //-------------------------------------------
 public void AddItem(CCustomizableListItem item, bool bRedraw)
 {
     m_listeItems.Add(item);
     item.Index = m_listeItems.Count - 1;
     if (bRedraw)
     {
         Refresh();
     }
 }
Пример #4
0
 //-------------------------------------------
 public void InsertItem(int nIndex, CCustomizableListItem item, bool bRedraw)
 {
     m_listeItems.Insert(nIndex, item);
     RenumerotteItems();
     if (bRedraw)
     {
         Refresh();
     }
 }
Пример #5
0
 //----------------------------------------------------
 /// <summary>
 /// Permet de calculer la hauteur d'un ITEM.
 /// Par défaut retourne la hauteur du contrôle
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public virtual int GetItemHeight(CCustomizableListItem item)
 {
     if (item.IsMasque)
     {
         return(0);
     }
     if (IsFixedSize || item.Height == null)
     {
         return(Height);
     }
     return(item.Height.Value);
 }
Пример #6
0
 //-------------------------------------------
 /// <summary>
 /// Retourne le précédent visible d'un index
 /// </summary>
 /// <param name="nIndex"></param>
 /// <returns></returns>
 public CCustomizableListItem GetVisibleItemBefore(int nIndex)
 {
     nIndex--;
     if (nIndex >= 0)
     {
         CCustomizableListItem item = m_listeItems[nIndex];
         if (item.IsMasque)
         {
             return(GetVisibleItemBefore(nIndex));
         }
         return(item);
     }
     return(null);
 }
Пример #7
0
 //-------------------------------------------
 /// <summary>
 /// Retourne le suivant visible d'un index
 /// </summary>
 /// <param name="nIndex"></param>
 /// <returns></returns>
 public CCustomizableListItem GetVisibleItemAfter(int nIndex)
 {
     nIndex++;
     if (nIndex < m_listeItems.Count)
     {
         CCustomizableListItem item = m_listeItems[nIndex];
         if (item.IsMasque)
         {
             return(GetVisibleItemAfter(nIndex));
         }
         return(item);
     }
     return(null);
 }
Пример #8
0
 //-------------------------------------------
 public void RefreshItem(CCustomizableListItem item)
 {
     if (item != null)
     {
         lock (typeof(CLockerImages))
         {
             CCacheImage cache = null;
             if (m_dicItemToImage.TryGetValue(item, out cache))
             {
                 if (cache.Image != null)
                 {
                     cache.Image.Dispose();
                 }
                 m_dicItemToImage.Remove(item);
             }
         }
     }
 }
Пример #9
0
        protected virtual void MoveItem(int nIndexSource, int nIndexDest, bool bCursorIsAvant)
        {
            CCustomizableListItem item = m_listeItems[nIndexSource];

            if (nIndexDest > nIndexSource)
            {
                m_listeItems.Insert(nIndexDest, item);
                m_listeItems.RemoveAt(nIndexSource);
                CurrentItemIndex = nIndexDest - 1;
            }
            else
            {
                m_listeItems.RemoveAt(nIndexSource);
                m_listeItems.Insert(nIndexDest, item);
                CurrentItemIndex = nIndexDest;
            }

            RenumerotteItems();
        }
Пример #10
0
        //----------------------------------------------------
        public CResultAErreur InitChamps(CCustomizableListItem item)
        {
            m_currentItem = item;
            CResultAErreur result = MyInitChamps(item);

            if (result)
            {
                HasChange = false;
            }
            if (item != null && item.DonneesControles != null)
            {
                CUtilDonneesSpecifiquesDansCustomList.RestoreDonneesControle(this, item.DonneesControles);
            }
            if (item != null)
            {
                item.Height = item.IsMasque?0:Height;
            }
            return(result);
        }
Пример #11
0
        //-------------------------------------------
        public int GetItemTop(int nItem)
        {
            if (m_controle == null)
            {
                return(0);
            }
            if (m_controle.IsFixedSize)
            {
                return(nItem * m_controle.Height);
            }
            int nPos = 0;

            for (int nItemTest = 0; nItemTest < nItem; nItemTest++)
            {
                CCustomizableListItem item = m_listeItems[nItemTest];
                nPos += m_controle.GetItemHeight(item);
            }
            return(nPos);
        }
Пример #12
0
 public virtual void OnStartCreateImage()
 {
     if (m_bAToutSauvéAvantDeFaireDesImages)
     {
         return;
     }
     m_bAToutSauvéAvantDeFaireDesImages = true;
     m_itemBeforePaint = CurrentItem;
     if (Bottom > 0)
     {
         if (CurrentItem != null)
         {
             MajChamps();
         }
         m_listActives           = CUtilControl.GetActiveControls(this);
         m_ptLocationBeforePaint = Location;
         Location      = new Point(0, -Height * 100);
         ActiveControl = null;
     }
 }
Пример #13
0
 //-------------------------------------------
 public Image GetImage(CCustomizableListItem item, bool bKeepItemEnCours)
 {
     if (item == null)
     {
         return(null);
     }
     lock (typeof(CLockerImages))
     {
         CCacheImage cache = null;
         if (m_dicItemToImage.TryGetValue(item, out cache))
         {
             if (cache.Image.Size == new Size(m_controle.Size.Width, item.Height != null?item.Height.Value : m_controle.Height))
             {
                 cache.LastAcces = DateTime.Now;
                 return(cache.Image);
             }
             else
             {
                 cache = null;
             }
         }
         if (cache == null)
         {
             cache = new CCacheImage();
             if (m_controle != null)
             {
                 bool bOldEnEdition = m_bControlEnEdition;
                 m_bControlEnEdition = false;
                 cache.Image         = m_controle.CreateImage(item, bKeepItemEnCours);
                 m_bControlEnEdition = bOldEnEdition;
                 if (cache.Image != null)
                 {
                     AddToDicImages(item, cache);
                     return(cache.Image);
                 }
             }
         }
     }
     return(null);
 }
Пример #14
0
        //-------------------------------------------
        public int?GetItemIndexAtPosition(int nY)
        {
            int nPos = 0;

            if (m_controle == null)
            {
                return(null);
            }
            //contrôle à taille fixe->fastoche
            if (m_controle.IsFixedSize)
            {
                return(nY / m_controle.Height);
            }

            //Sinon, on est obligé de calculer la taille de tous les précédents !
            int?nLastNotHeightZero = null;

            for (int nIndex = 0; nIndex < m_listeItems.Count(); nIndex++)
            {
                CCustomizableListItem item = m_listeItems[nIndex];
                int nHeight = m_controle.GetItemHeight(item);
                if (nHeight > 0)
                {
                    nLastNotHeightZero = nIndex;
                }
                if (nPos <= nY && nPos + nHeight > nY)
                {
                    if (nLastNotHeightZero != null)
                    {
                        return(nLastNotHeightZero.Value);
                    }
                    return(nIndex);
                }
                nPos += nHeight;
            }
            return(null);
        }
Пример #15
0
        //-------------------------------------------
        public void RemoveItem(CCustomizableListItem item, bool bRedraw)
        {
            if (item != null)
            {
                RemoveItem(item.Index, bRedraw);
            }

            /*int nItem = item.Index;
             * if (CurrentItemIndex != null && CurrentItemIndex == nItem)
             * {
             *  m_controle.CancelEdit();
             *  if (nItem < m_listeItems.Count - 1)
             *      CurrentItemIndex = nItem + 1;
             *  else if (nItem > 0)
             *      CurrentItemIndex = nItem - 1;
             *  else
             *      CurrentItemIndex = -1;
             * }
             * }
             * m_listeItems.Remove(item);
             * RenumerotteItems();
             * if (bRedraw)
             * Refresh(); */
        }
Пример #16
0
        //-------------------------------------------------------
        private int?GetItemIndex(CCustomizableListItem item)
        {
            int nIndex = m_listeItems.IndexOf(item);

            return(nIndex >= 0 ? (int?)nIndex : null);
        }
Пример #17
0
 //----------------------------------------------------
 public void CancelEdit()
 {
     m_currentItem = null;
 }
Пример #18
0
        private void m_PanelDessin_Paint(object sender, PaintEventArgs e)
        {
            if (m_bIsDrawing)
            {
                return;
            }
            try
            {
                if (Items.Count() == 0 && ItemControl != null)
                {
                    ItemControl.Visible = false;
                }
                if (Items.Count() > 0 && ItemControl != null)
                {
                    ItemControl.Visible = true;
                }

                m_bIsDrawing = true;
                if (!m_bMouseWheelHandled)
                {
                    Form frm = FindForm();
                    if (frm != null)
                    {
                        frm.MouseWheel      += new MouseEventHandler(frm_MouseWheel);
                        m_bMouseWheelHandled = true;
                    }
                }
                if (m_controle != null)
                {
                    m_controle.PreparePaintList();
                    RecalcScrollSizes();
                    int?nCurrent = CurrentItemIndex;
                    int?nItem    = GetItemIndexAtPosition(-m_panelDessin.AutoScrollPosition.Y);
                    if (nItem == null)
                    {
                        return;
                    }
                    int nY = GetItemTop(nItem.Value) + m_panelDessin.AutoScrollPosition.Y;
                    while (nY < ClientSize.Height && nItem < m_listeItems.Count)
                    {
                        CCustomizableListItem item = m_listeItems[nItem.Value];
                        if (!item.IsMasque)
                        {
                            Image img = GetImage(item, false);
                            if (item.Height > 0)
                            {
                                Rectangle rct = new Rectangle(-5, nY, m_panelDessin.ClientSize.Width + 10, item.Height.Value);
                                Brush     br  = new SolidBrush(BackColor);
                                e.Graphics.FillRectangle(br, rct);
                                br.Dispose();

                                if (img != null)
                                {
                                    e.Graphics.DrawImageUnscaled(img,
                                                                 new Point(m_panelDessin.AutoScrollPosition.X, nY));
                                }
                                if (nCurrent == nItem)
                                {
                                    Pen p = new Pen(m_controle.BackColor);
                                    e.Graphics.DrawRectangle(p, m_panelDessin.AutoScrollPosition.X, nY, m_controle.Width - 1, item.Height.Value - 1);
                                    p.Dispose();
                                }
                            }
                        }
                        else
                        {
                            item.Height = 0;
                        }
                        nItem++;
                        if (item.Height == null)
                        {
                            nY += m_controle.GetItemHeight(item);
                        }
                        else
                        {
                            nY += item.Height.Value;
                        }
                    }

                    if (m_controle != null)
                    {
                        m_controle.OnEndPaintList();
                    }

                    /*if ( nCurrent != null && (m_controle.CurrentItem == null ||
                     *  m_controle.CurrentItem.Index != nCurrent ))
                     *  m_controle.InitChamps ( Items[nCurrent.Value] );*/
                }
            }
            finally
            {
                m_bIsDrawing = false;
            }
            if (AfterPaint != null)
            {
                AfterPaint(this, null);
            }
        }
Пример #19
0
 //----------------------------------------------------
 protected virtual CResultAErreur MyInitChamps(CCustomizableListItem item)
 {
     return(CResultAErreur.True);
 }