Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
LostFocus for the header control
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00556206
Message ID:
00556664
Vues:
17
Ok, I thought, it would be easier... :( I spent the whole afternoon (from 9am to 2pm) to make all necessary changes. Unfortunately, the classes now inter - dependant, though I check with Pemstatus to make it more universal.

Here is myHeader Class:
********************************************************************
*  Description.......: myHeader.Definition
*  Calling Samples...:
*  Parameter List....: tcCaption
*  Ideas by..........: Cetin Basoz & David Frankenbach & Vlad Grynchyshyn 
*  Modified by.......: Nadya Nosonovsky 09/14/2001 10:50:09 AM
********************************************************************
define class MyHeader as header
     mcArrowName = ""    && name of the arrow used for all headers of the grid
     mlAscending = .f.   && flag for sort order
     mlColumnMoved = .f. && flag indicating column was moved
     mnColumnOrder = 0   && original column order
     mlColumnSized = .f. && flag indicating column was resized
     mnColumnWidth = 0   && original size of column
     nOriginalForeColor = 0  && original ForeColor
     nForeColorAsc =  16711935 && Fore Color, when the column is in ASC order
     nForeColorDesc = 8388863   && Fore Color, when the column is in DESC order

     procedure init
     lparameters tcCaption
     local ix, lcProperty
     with this
          if vartype(m.tcCaption) # "C" ;
                    or empty(m.tcCaption)
               tcCaption = .caption
          endif
          .caption = m.tcCaption
          .alignment = 2
          .nOriginalForeColor=.forecolor
          if !pemstatus(.parent.parent,"nCurOrderedColumnIndex",5)
               .parent.parent.addproperty("nCurOrderedColumnIndex",0)
          endif
          if !pemstatus(.parent.parent,"nCurActiveColumnIndex",5)
               .parent.parent.addproperty("nCurActiveColumnIndex",0)
          endif

     endwith
endproc

     procedure ForeColor_assign
     lparameters vNewVal     

*To do: Modify this routine for the Assign method
     with this
          if inlist(m.vNewVal, .nForeColorAsc, .nForeColorDesc)
               .parent.parent.nCurOrderedColumnIndex=.GetColumnIndex()
          else
               .nOriginalForeColor= m.vNewVal
               .parent.parent.nCurActiveColumnIndex=.GetColumnIndex()
          endif     
          .forecolor = m.vNewVal          
     endwith

     procedure GetColumnIndex
     local lnI, lnIndex
     lnIndex=0
     with this.parent
          for lnI=1 to .parent.columncount
               if .parent.columns[m.lnI].columnorder=.columnorder
                    lnIndex=m.lnI
                    exit
               endif
          next
     endwith
     return m.lnIndex
endproc

     procedure Order_Highlight
     local lnOldIndex, lnIndex
     * lnIndex = this.GetColumnIndex()
     lnOldIndex = this.parent.parent.nCurOrderedColumnIndex
     with this.parent.parent
          if m.lnOldIndex > 0 
               .columns[m.lnOldIndex].Header1.forecolor= ;
               .columns[m.lnOldIndex].Header1.nOriginalForeColor
          endif
     endwith
     with this
          if .mlAscending
               .forecolor = .nForeColorAsc && Red
          else
               .forecolor = .nForeColorDesc
          endif
     endwith
endproc

     procedure click     
     local nTempCurRec, lcTagName
     with this
          if ! .mlColumnMoved and ! .mlColumnSized
* sortable column that was clicked
               .mlAscending = ! .mlAscending
               thisform.lockscreen = .t.
               lcTagName=justext(.parent.controlsource)
               select (.parent.parent.recordsource)
               if tagno(m.lcTagName)> 0
                    nTempCurRec = recno(.parent.parent.recordsource)
                    if .mlAscending
                         set order to tag (m.lcTagName) ;
                              in (.parent.parent.recordsource) ascending
                    else
                         set order to tag (m.lcTagName) ;
                              in (.parent.parent.recordsource) descending
                    endif
                    .Order_Highlight() && Show color
                    .parent.parent.refresh
                    if type('thisform.navstand.name')='C'
                         thisform.navstand.lstOrders.value=m.lcTagName
                    endif
                    if between(m.nTempCurRec,1,reccount(.parent.parent.recordsource))
                         go m.nTempCurRec in (.parent.parent.recordsource)
                    endif
               endif
               thisform.lockscreen = .f.
          endif
     endwith
endproc

     procedure mousedown
     lparameters nButton, nShift, nXCoord, nYCoord

     with this

* initialize items that will be tested in MouseUp
          .mnColumnOrder = this.parent.columnorder
          .mnColumnWidth = this.parent.width
     endwith
endproc

     procedure mouseup
     lparameters nButton, nShift, nXCoord, nYCoord

     with this
* check to see if this was a resize or move
          .mlColumnMoved = ( this.parent.columnorder != .mnColumnOrder )
          .mlColumnSized = ( this.parent.width != .mnColumnWidth )
*          .ForeColor=.nOriginalForeColor
     endwith

endproc
     procedure dblclick
     this.parent.parent.SetOrder(this.parent.controlsource)
endproc
enddefine
And here is EditInGrid.GotFocus() event:
********************************************************************
*  Description.......: EditInGrid.GotFocus()
*  Calling Samples...: 
*  Parameter List....: 
*  Created by........:  
*  Modified by.......: Nadya Nosonovsky 09/14/2001 01:57:54 PM
********************************************************************
local lnWhiteColor, lnIndex, lnOldIndex, lnBlackColor
lnBlackColor = rgb(0,0,0) && Black
lnIndex = this.GetColumnIndex()
if !pemstatus(this.parent.parent,"nCurActiveColumnIndex",5)
    this.parent.parent.AddProperty("nCurActiveColumnIndex",0)
endif  
lnOldIndex = this.parent.parent.nCurActiveColumnIndex
if  m.lnOldIndex > 0 and m.lnOldIndex <> m.lnIndex
   with this.parent.parent.columns[m.lnOldIndex].Header1 && I probably should check for the name...              
          .backcolor = rgb(192,192,192) && gray
          if pemstatus(this.parent.parent.columns[m.lnOldIndex].Header1,"nForeColorAsc",5) && nForeColorAsc exists
           if not inlist(.forecolor,.nForeColorAsc, .nForeColorDesc)
              .forecolor= m.lnBlackCOlor && black
              .nOriginalForeColor = m.lnBlackColor
          endif
          else && Normal Header
                   .forecolor=rgb(0,0,0) && black
          endif          
     endwith
endif
this.parent.parent.nCurActiveColumnIndex = m.lnIndex
lnWhiteColor = rgb(255,255,255)
with this
     if .parent.readonly or .parent.parent.readonly
          set cursor off
     endif
     .backcolor=.parent.parent.cCurRecBackColor
     .forecolor=.parent.parent.cCurRecForeColor
     .fontbold=.t.
     .OldValue=evaluate(.parent.controlsource) && Save the current value
     if type('this.parent.header1.name')='C'
          with .parent.Header1
               .backcolor=rgb(64,128,128) && green
               if pemstatus(.parent.parent,"nCurOrderedColumnIndex",5)
                    if .nOriginalForeColor = m.lnWhiteColor
** Don't update ForeColor, already White
                    else
                         .forecolor = m.lnWhiteColor
                    endif
               else
                    .forecolor = m.lnWhiteColor && white
               endif
          endwith
     endif
endwith
dodefault()
Uf, now I have to concentrate on all other tasks...


>Hi!
>
>>>>Besided, I can click on text in another column in a grid, and the header would not change color
>
>Nadya, why you need this, in other words, what is use-case of such coloring? Just AfterRowColChange event.
>
>About SetAll and about remembering of the column index I already mentioned in your previous thread.
>
>Also, to make it generic, I would like to add that you cand define a method in the header class called "Highlight" or something like that. This method will control the index of current highlighted column in the GRID class. You will be able to call it from any place in the grid include from the AfterRowColChange. In the method you will read previous index from grid property, if it is not zero (no column highlighted) - restore back color, then set back color of the "this" header and set column index to the current column index (either using loop or using saved index in the header in separate property for each column). About RestoreToDefault, it is also not a good idea to use it in case you predict back color could be changed by programmer in run-time mode. It is good idea to define Header.BackColor_Assign method where you store the color change in the OriginalBackColor and check - if this column is highlighted, do not change BackColor. When restoring color, instead of ResetToDefault copy
>the value from the OriginalBackColor to restore header color. In the Init, of course, set initial value of the Original BackColor property.
>
>HTH.
>
>P.S. I did passed the time such grid developed, so you can ask also for more complex questions. For example, instead of header coloring, put arrow to indicate sorted column and the direction of sorting.
>
>>>Putting this in the MouseMouve of each header works for me:
>>>LPARAMETERS nButton, nShift, nXCoord, nYCoord
>>>local lnI
>>>for lnI = 1 to This.Parent.Parent.ColumnCount
>>>    This.Parent.Parent.Columns(lnI).Header1.ForeColor = rgb(0,0,0)
>>>endfor
>>>This.ForeColor = rgb(200,0,0)
>>>
>>
>>Thanks, Mark. As I thought about this problem on the way home, there are couple of complications. First of all, I want to restore color, which may be not necessary black. Secondly, I thought, that I should leave red color on the column, which is ordered until the other column is re-ordered. Third complication is, that I have ability to change order by some other form control, and I want to change color accordingly. I was trying to work out a solution in my mind, but haven't developed anything general and simple so far.
>>
>>
>>>>Hi everybody,
>>>>
>>>>How can I determine, that the current Header is loosing focus? In other words, suppose, I click on the Header on the grid and change its color. When I click on another column header, I want to reset previously current Header color to the original color, and change color of the currently clicked Header?
>>>>
>>>>Do you have an idea, how can I achieve this functionality?
>>>>I tried this.parent.parent.SetAll(..) from the click event of the Header, but it's not exactly, what I want. Besided, I can click on text in another column in a grid, and the header would not change color :(
>>>>
>>>>Thanks a lot in advance for ideas.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform