Page 1 of 2

Align text to Center in StatusBar

Posted: Wed Dec 17, 2014 1:34 am
by Pablo César
Hi all,

Is it posible to set text at StatusBar's items to be aligned to center ?

I found this in code C# for right align text. I do not know how to do it in C and for center aligment:
Screen1.png
Screen1.png (27.9 KiB) Viewed 4765 times
I would like to see this in our library will be nice to have it.

I used the Courrier New (monospaced font) with PADC. But sometimes we do not know how long in characters would it can be applied for StatusBar when Window is not fixed sizes.

Align text to Center in StatusBar

Posted: Wed Dec 24, 2014 4:06 pm
by Pablo César
I come here to say there is a litle bug around SetStatusItemText() at c_status.c.

Normally when we need to change the text in one cell of StatusBar, we use:

<WindowName>.<ControlName>. Item (<nItem>) := ItemText

And this is interpreted by _SetItem() identifying de type of control and redirect to SetStatusItemText()

The problem is when one or more item is RAISED style.
Screen1.png
Screen1.png (26.51 KiB) Viewed 4691 times
When by ACTION we need to change it text, then worngly the item changes the style :o
I mean, changes from RAISED to FLAT... :(

See demo expressing this bug:

Code: Select all

#include "hmg.ch"

Function Main
DEFINE WINDOW Form_1 ;
    AT 0,0 ;
    WIDTH 600 HEIGHT 400 ;
    TITLE 'HMG StatusBar Demo' ;
    MAIN ;
    FONT 'Arial' SIZE 10 

    DEFINE STATUSBAR 
        STATUSITEM "Item 1" ACTION {|| Form_1.StatusBar.Item(1):="Changed !"} RAISED 
        STATUSITEM "Item 2" WIDTH 100 ACTION MsgInfo('Click! 2') TOOLTIP "Item 2"
        STATUSITEM 'A Car!' WIDTH 100
        CLOCK 
        DATE  TOOLTIP "Item date"
    END STATUSBAR

END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil
Sorry Claudio to ask indirectly to you, but I couldn't fails to inform about it.
If you can do something to correct this, is very appreciated, as always ! :)
..by the way, in case you have to work on that c function, would you add that new implement (CENTER text) ?

Thank you in advanced !

Re: Align text to Center in StatusBar

Posted: Wed Dec 24, 2014 10:10 pm
by srvet_claudio
Pablo César wrote:I come here to say there is a litle bug around SetStatusItemText() at c_status.c.
Hi Pablo,
change in file c_status.c the original SETSTATUSITEMTEXT() function for this:

Code: Select all

HB_FUNC (SETSTATUSITEMTEXT)
{  
   TCHAR * text = (TCHAR *) HMG_parc(2);
   WORD nDraw = HIWORD ( SendMessage ((HWND) HMG_parnl (1), SB_GETTEXTLENGTH, (WPARAM) hb_parnl (3), 0) );
   SendMessage( (HWND) HMG_parnl (1) , SB_SETTEXT , (WPARAM) (nDraw | hb_parnl (3)) , (LPARAM) text ) ;
}

Align text to Center in StatusBar

Posted: Wed Dec 24, 2014 10:26 pm
by Pablo César
Perfecto ! :D

Thank you Claudio, you are great ! Now RAISED style is respected as accordingly, thanks to you ! :)

And what about the probably to include JUSTIFY ( JTFY_LEFT, JTFY_RIGHT, JTFY_RIGHT ), is it very complexed for implementation ?

Align text to Center in StatusBar

Posted: Fri Mar 27, 2015 8:18 pm
by Pablo César
Hi HMG DT,

I have two questions regarding StatusBar for posible enhance:
  1. Is it posible to set text at StatusBar's items to be aligned to center ?
    Like as to include at anWidths:={ LEFT, CENTER, RIGHT}
     
  2. StatusBar when there is more than on item, always it takes the first cell at most left for trimming propose.
    Is it posible to expand as possibilities selecting which cell it could be used for trimming ?

    I've got an idea and I make some test already by changing StatuBar in our library with three options:
    1. When just one of cell is Nil Width size.
      It will take this cell for trimming.
    2. When all Width sizes are defined.
      It will take the bigger width size cell for trimming.
    3. When all Width sizes are equally.
      It will take the first cell for trimming, as ever done.

      Actually we have:

      Code: Select all

      	For i := 2 To HMG_LEN (anWidths)
      		If ValType ( anWidths [i] ) <> 'N'
      			anWidths [i] := 120
      		EndIf
      		nTotWidth := nTotWidth + anWidths [i]
      	Next i
      	anWidths [1] := GetWindowWidth ( nParentHandle ) - nTotWidth
      Please note always is taking the most left cell for trimming.

      I propose to change as follows:

      Code: Select all

      Local nMaxWidth:=0
      Local aNil:={}
      Local nP:=1
      
      	For i := 1 To HMG_LEN (anWidths)
      		If ValType ( anWidths [i] ) <> 'N'
      			anWidths [i] := 120
      			Aadd(aNil,i)
      		EndIf
      		If anWidths[i] > nMaxWidth
      		   nMaxWidth := anWidths[i]
      		   nP := i
      		Endif
      		nTotWidth := nTotWidth + anWidths [i]
      	Next i
      	If HMG_Len(aNil)=1
      	   nP := aNil[1]
      	ElseIf HMG_Len(aNil)>1
      	   nP := 1
      	Endif
      	nTotWidth := nTotWidth - anWidths [nP]
      	anWidths[nP] := GetWindowWidth ( nParentHandle ) - nTotWidth
      As you can see three options wil be considered for trimming.
As it's now for trimming widths cells at first cell, it's quite imposible to adjust midle cells... :(
Screen1.png
Screen1.png (21.34 KiB) Viewed 4571 times
By this way midle cell will be easy let with width size for trimming. Specially when we have different screen resolutions.

I'm asking these features in order to leave more versatile StatuBar control.

I do not know colleagues here has experienced the same difficulty. It is very annoying to have to leave the fixed windows for the StatusBar do not be disproportionated ...

If is not possible to accept these implementations at Width size, I shall ask if is not posible to let Widths assignable like as is in Minigui Extended.
Screen2.png
Screen2.png (7.2 KiB) Viewed 4571 times
If Width becomes assignable, then we can use it to fix all widths sizes.
Here we find a solution for this second case.

Re: Align text to Center in StatusBar

Posted: Sat Mar 28, 2015 5:06 am
by Rathinagiri
Thank you for the suggestion Pablo. Nice improvement.

Align text to Center in StatusBar

Posted: Sat Mar 28, 2015 1:57 pm
by Pablo César
Thank you Rathi, all for HMG.

It also will be a big and old wish if we can get aligments in StatusBar's Items, this is important too IMO.

Re: Align text to Center in StatusBar

Posted: Sat Mar 28, 2015 4:33 pm
by serge_girard
Thanks all for this improvement!

Serge

Align text to Center in StatusBar

Posted: Tue Mar 31, 2015 3:01 pm
by Pablo César
serge_girard wrote:Thanks all for this improvement!

Serge
Dank u Serge !
But it's just an indication of implementation.
I do not know yet whether it will be approved by HMG DT.

But that does not stop me or what else by providing routines that may be useful to the community, to improve and get a more concistent looking of the StatusBar. :D

Here are two more resources to the StatusBar at: viewtopic.php?p=40634#p40634

I hope you enjoy it ! :D

@ Dr. Claudio,

I have two frustrations in this my last example: (These I already solved, not more fustrations around)
  1. I can not make trimming in other fonts. I only handle with monospaced fonts.
    (This I already solved)
    Is there any other way to do it ? I saw something like Add a ToolstripLabel to the StatusStrip (but I do not know how to do it... :oops:
     
  2. When at ON SIZE event, I can not make My_SetStatusBarSize properly.
    (This I also already solved)
    I believe this is happening probably due to this event calls the FIXED internal routine of:

    For i := 2 To HMG_LEN (anWidths) :cry:

    Probably at our library, this could be fixed ?
All of us will appreciate once again your efforts, knowledges and a helping hand... :P

Re: Align text to Center in StatusBar

Posted: Wed Apr 01, 2015 7:37 am
by serge_girard
Pablo,

I know it is an indication; your suggestions of improvements are great!

Serge