Create a Panel width a text

Re: Create a Panel width a text

Postby Silvio.Falconi » Mon Jan 08, 2024 10:57 pm

Antonio Linares wrote:Dear Silvio,

Please post a screenshot, thanks



Antonio,
the Panel seems to change its size but if there is another panel after the modified one, if the dimensions are small a large space is formed between the panels, if the modified panel has a larger space it is drawn above the panel that follows


If the taskPanel is bigger

Image

if the taskpanel is smaller

Image

the new test code

Code: Select all  Expand view  RUN
#include "FiveWin.ch"
//#include "ribbon.ch"

//----------------------------------------------------------------------------//
static oExBar

function Main()

   local oWnd,  oPanel1, oPanel2, oPanel3, oPanel4
   local bClick := { | o | MsgInfo( o:GetText() ) }


   local uVar, oBrw, oPanel, aDim, oFont
   local aArray := { {"one",time(),DATE()},;
                  {"two",time(),DATE()},;
                  {"three",time(),DATE()},;
                  {"four",time(),DATE()},;
                  {"five",time(),DATE()} }

   local cMsg := "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla"



   DEFINE WINDOW oWnd TITLE "FWH Class TExplorerBar"

   oWnd:SetSize( 550, 600 )

   oExBar = TExplorerBar():New()

   oPanel1 = oExBar:AddPanel( "One", "..\bitmaps\32x32\people.bmp" )
   oPanel1:lSpecial = .T.
   oPanel1:AddLink( "First item", bClick, "..\bitmaps\16x16\additem.bmp" )

   oPanel2 = oExBar:AddPanel( "Two", "..\bitmaps\32x32\case.bmp", 200 )

   oPanel3 = oExBar:AddPanel( "Tree", "..\bitmaps\32x32\case.bmp", 200 )


   Section_advice(oPanel2,cMsg,oPanel1)

   oWnd:oClient = oExBar

   ACTIVATE WINDOW oWnd CENTERED

return nil

Function Section_advice(oPanel2,cMsg,oPanel1)
   local oFont,aDim
   local oPanelText,oBrushtext
   local oPanelshadow,oBrushShadow

   local aGradShadow :={rgb(224,224,224),rgb(224,224,224)  }
   local aGradText :={ rgb(248,248,248),rgb(248,248,248)  }

   local bBoard := { | | ShareBoard(@cMsg,oPanel2,oPanelShadow,oPanelText) }


   oPanel1:AddLink( "Edit board", bBoard, "..\bitmaps\16x16\copy.bmp" )



   DEFINE BRUSH oBrushShadow GRADIENT aGradShadow
   DEFINE BRUSH oBrushtext GRADIENT aGradText

   DEFINE FONT oFont NAME "Verdana" SIZE 0, -12
   aDim = GetLabelDim( oPanel2:hWnd, alltrim(cMsg), oFont:hFont )

    //refresh the oPanel2
    oPanel2:nHeight     :=  aDim[ 2 ] + 50
    oPanel2:nBodyHeight := oPanel2:nHeight - oPanel2:nTitleHeight
    oPanel2:CoorsUpdate()
    oPanel2:UpdateRegion()


   //create a shadow effect
   @ oPanel2:nTitleHeight+5, 10 PANEL oPanelShadow SIZE oPanel2:nwidth, oPanel2:nHeight-40 of oPanel2
   oPanelShadow:SetBrush( oBrushShadow )

   //create a panel with text
   @ 5, 5 PANEL oPanelText SIZE oPanelShadow:nWidth-2, oPanelShadow:nBottom-45 of oPanelShadow
   //oItem2:SetColor( "N/W*" )
   oPanelText:SetBrush( oBrushText  )
  * oPanelText:bPainted = { | hDC | DrawTextTransparent( hDC, cMsg, { 10, 80, aDim[ 1 ] + 120, aDim[ 2 ] + 120 }, 1 ) }

   oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMsg ) ), ;
          { 1 , 50, aDim[ 2 ] + 50, 300 },,oFont, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }



 return nil
//----------------------------------------------------------------------------//
    Function ShareBoard(cMessage,oPanel2,oPanelShadow,oPanelText)
   local oDlgBacheca
   local oBar

   local oBold
   local nWd  := GetSysMetrics(0) * .45
   local nHt  := (GetSysMetrics(1) / 3 )
   local oBtn := array(3)

    local adim
    local nTotRows
    local oFonttext


   IF Empty(cMessage)
      cMessage:= "Notice to users  bla bla bla"
   Endif

   DEFINE FONT oFonttext NAME "Verdana" SIZE 0, -12
   DEFINE DIALOG oDlgBacheca SIZE nWd, nHt PIXEL ;   //TRUEPIXEL
       TITLE  "Shared board" ;
       FONT oFonttext   COLOR CLR_BLACK,  RGB( 245,245,235) ;
       STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
                  WS_MINIMIZEBOX)   //ICON oIcon

    //----------------------------------------------------------------------------//
       DEFINE BUTTONBAR oBar OF oDlgBacheca  SIZE 80,70  BOTTOM NOBORDER  2015

         oBar:bClrGrad := { | lPressed | If( ! lPressed,;
                 { { 1, RGB( 250,250,245), RGB( 250,250,245)} },;
                 { { 1, RGB( 245,245,235), RGB( 245,245,235)} } ) }

      DEFINE BUTTON oBtn[1] OF oBar  ;
      FILENAME "DLG_NO";
      PROMPT "Exit" TOOLTIP "Esci" ;
      ACTION   ( oDlgBacheca:end( IDCANCEL ) )

      DEFINE BUTTON oBtn[2] OF oBar  ;
      FILENAME "HLP_DLG";
      PROMPT "Aiuto" TOOLTIP "Aiuto" ;
      ACTION NIL   GROUP

      DEFINE BUTTON oBtn[3] OF oBar  BTNRIGHT  ;
      FILENAME "DLG_OK";
      PROMPT "Save" ;
      TOOLTIP "Conferma i dati" ;
      ACTION   ( oDlgBacheca:end( IDOK ) )
 //----------------------------------------------------------------------------//

       @ 0, 4  SAY "Wall message shared by all users...."  OF  oDlgBacheca TRANSPARENT
       @  10,   4  GET oText VAR cMessage  OF   oDlgBacheca MEMO  COLOR CLR_BLUE  SIZE 280,  75 PIXEL

     ACTIVATE DIALOG oDlgBacheca CENTERED ;
       ON INIT (  oDlgBacheca:resize(),   ChangeButtons( oBar ) )

  IF oDlgBacheca:nresult == IDOK

     //refresh the oPanel
    aDim := GetLabelDim( oPanel2:hWnd, alltrim(cMessage) , oFonttext:hFont )
    oPanel2:nHeight     :=  aDim[ 2 ] + 70
    oPanel2:nBodyHeight := oPanel2:nHeight - oPanel2:nTitleHeight
    oPanel2:CoorsUpdate()
    oPanel2:UpdateRegion()

      //refresh the oPanel with shadow effect
      oPanelShadow:nWidth:= oPanel2:nwidth-20
      oPanelShadow:nBottom:= oPanel2:nHeight-80
      oPanelShadow:refresh(.t.)

      //refresh the oPanel with Text  cMsg
      oPanelText:nWidth:= oPanelShadow:nWidth-2
      oPanelText:nBottom:= oPanelShadow:nBottom-90


   oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMessage ) ), ;
          { 10, 50, 50, 300 },,oFonttext, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }

  oPanelText:refresh(.t.)



     // oExBar:Refresh()
     // AEval( oExBar:aPanels, { | o | o:Refresh() } )
     // oExBar:CheckScroll()

ENDIF
 return nil

 //----------------------------------------------------------------------------//
function ChangeButtons( oBar )
   AEval( oBar:aControls, { | oCtrl | oCtrl:nTop += 4, oCtrl:nHeight -= 4 } )
return .T.
//----------------------------------------------------------------------------//




 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7070
Joined: Thu Oct 18, 2012 7:17 pm

Re: Create a Panel width a text

Postby Antonio Linares » Tue Jan 09, 2024 7:48 am

Dear Silvio,

Have you considered to rebuild the ExplorerBar after the message is changed ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Create a Panel width a text

Postby Silvio.Falconi » Tue Jan 09, 2024 10:23 am

Antonio Linares wrote:Dear Silvio,

Have you considered to rebuild the ExplorerBar after the message is changed ?



and how ?
Antonio, consider that I insert two explorerbars (one on the right and one on the left) in a main window and do them as if it were a dashboard, in the past I used two TscrollPanels but I saw that when the window was iconized the left scrollpanel lost the scroll, because ui now I'm trying with the explorerbar hoping it might work

and insert a new method to recalc the position nTop for each ::apanels as this

METHOD RecalcPosTask() CLASS TTaskPanel
local n

for n = ::nIndex + 1 to Len( ::oWnd:aPanels )
::nHeight = ::nTotalHeight()
for n = ::nIndex + 1 to Len( ::oWnd:aPanels )
::oWnd:aPanels[ n ]:nTop += ::nBodyHeight
::oWnd:aPanels[ n ]:nTopMargin := 1
next
next
RETURN nil

Could run it ?


I tried and see some result I think it could run if you correct the method :)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7070
Joined: Thu Oct 18, 2012 7:17 pm

Re: Create a Panel width a text

Postby Silvio.Falconi » Sat Jan 27, 2024 9:30 am

Is there anyone who can help me solve this problem?
the class must have the ability to update the panels and their contents
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7070
Joined: Thu Oct 18, 2012 7:17 pm

Re: Create a Panel width a text

Postby Silvio.Falconi » Fri Feb 16, 2024 3:00 pm

I found a function CalcTextHeight(cText, oFont, nWidth,oPanel)

but it not run ok because the other panels are not refreshed


Image


Code: Select all  Expand view  RUN

#include "FiveWin.ch"
//#include "ribbon.ch"

//----------------------------------------------------------------------------//
static oExBar

function Main()

   local oWnd,  oPanel1, oPanel2, oPanel3, oPanel4
   local bClick := { | o | MsgInfo( o:GetText() ) }


   local uVar, oBrw, oPanel, aDim, oFont
   local aArray := { {"one",time(),DATE()},;
                  {"two",time(),DATE()},;
                  {"three",time(),DATE()},;
                  {"four",time(),DATE()},;
                  {"five",time(),DATE()} }

   local cMsg := "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla" + CRLF + ;
      "Notice to users  bla bla bla"



   DEFINE WINDOW oWnd TITLE "FWH Class TExplorerBar"

   oWnd:SetSize( 550, 600 )

   oExBar := TExplorerBar():New()

   oPanel1 = oExBar:AddPanel( "One", "..\bitmaps\32x32\people.bmp" )
   oPanel1:lSpecial = .T.
   oPanel1:AddLink( "First item", bClick, "..\bitmaps\16x16\additem.bmp" )

   oPanel2 = oExBar:AddPanel( "Two", "..\bitmaps\32x32\case.bmp", 200 )

   oPanel3 = oExBar:AddPanel( "Tree", "..\bitmaps\32x32\case.bmp", 200 )


   Section_advice(oPanel2,cMsg,oPanel1)

   oWnd:oClient = oExBar

   ACTIVATE WINDOW oWnd CENTERED

return nil

Function Section_advice(oPanel2,cMsg,oPanel1)
   local oFont,aDim
   local oPanelText,oBrushtext
   local oPanelshadow,oBrushShadow

   local aGradShadow :={rgb(224,224,224),rgb(224,224,224)  }
   local aGradText :={ rgb(248,248,248),rgb(248,248,248)  }

   local bBoard := { | | ShareBoard(@cMsg,oPanel2,oPanelShadow,oPanelText) }


   oPanel1:AddLink( "Edit board", bBoard, "..\bitmaps\16x16\copy.bmp" )



   DEFINE BRUSH oBrushShadow GRADIENT aGradShadow
   DEFINE BRUSH oBrushtext GRADIENT aGradText

   DEFINE FONT oFont NAME "Verdana" SIZE 0, -12
   aDim = GetLabelDim( oPanel2:hWnd, alltrim(cMsg), oFont:hFont )

    //refresh the oPanel2
    oPanel2:nHeight     :=  aDim[ 2 ] + 50
    oPanel2:nBodyHeight := oPanel2:nHeight - oPanel2:nTitleHeight
    oPanel2:CoorsUpdate()
    oPanel2:UpdateRegion()


   //create a shadow effect
   @ oPanel2:nTitleHeight+5, 10 PANEL oPanelShadow SIZE oPanel2:nwidth, oPanel2:nHeight-40 of oPanel2
   oPanelShadow:SetBrush( oBrushShadow )

   //create a panel with text
   @ 5, 5 PANEL oPanelText SIZE oPanelShadow:nWidth-2, oPanelShadow:nBottom-45 of oPanelShadow
   //oItem2:SetColor( "N/W*" )
   oPanelText:SetBrush( oBrushText  )
  * oPanelText:bPainted = { | hDC | DrawTextTransparent( hDC, cMsg, { 10, 80, aDim[ 1 ] + 120, aDim[ 2 ] + 120 }, 1 ) }

   oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMsg ) ), ;
          { 1 , 50, aDim[ 2 ] + 50, 300 },,oFont, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }



 return nil
//----------------------------------------------------------------------------//
    Function ShareBoard(cMessage,oPanel2,oPanelShadow,oPanelText)
   local oDlgBacheca
   local oBar,oPanel

   local oBold
   local nWd  := GetSysMetrics(0) * .45
   local nHt  := (GetSysMetrics(1) / 3 )
   local oBtn := array(3)

    local adim
    local nTotRows
    local oFonttext


   IF Empty(cMessage)
      cMessage:= "Notice to users  bla bla bla"
   Endif

   DEFINE FONT oFonttext NAME "Verdana" SIZE 0, -12
   DEFINE DIALOG oDlgBacheca SIZE nWd, nHt PIXEL ;   //TRUEPIXEL
       TITLE  "Shared board" ;
       FONT oFonttext   COLOR CLR_BLACK,  RGB( 245,245,235) ;
       STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
                  WS_MINIMIZEBOX)   //ICON oIcon

    //----------------------------------------------------------------------------//
       DEFINE BUTTONBAR oBar OF oDlgBacheca  SIZE 80,70  BOTTOM NOBORDER  2015

         oBar:bClrGrad := { | lPressed | If( ! lPressed,;
                 { { 1, RGB( 250,250,245), RGB( 250,250,245)} },;
                 { { 1, RGB( 245,245,235), RGB( 245,245,235)} } ) }

      DEFINE BUTTON oBtn[1] OF oBar  ;
      FILENAME "DLG_NO";
      PROMPT "Exit" TOOLTIP "Esci" ;
      ACTION   ( oDlgBacheca:end( IDCANCEL ) )

      DEFINE BUTTON oBtn[2] OF oBar  ;
      FILENAME "HLP_DLG";
      PROMPT "Aiuto" TOOLTIP "Aiuto" ;
      ACTION NIL   GROUP

      DEFINE BUTTON oBtn[3] OF oBar  BTNRIGHT  ;
      FILENAME "DLG_OK";
      PROMPT "Save" ;
      TOOLTIP "Conferma i dati" ;
      ACTION   ( oDlgBacheca:end( IDOK ) )
 //----------------------------------------------------------------------------//

       @ 0, 4  SAY "Wall message shared by all users...."  OF  oDlgBacheca TRANSPARENT
       @  10,   4  GET oText VAR cMessage  OF   oDlgBacheca MEMO  COLOR CLR_BLUE  SIZE 280,  75 PIXEL

     ACTIVATE DIALOG oDlgBacheca CENTERED ;
       ON INIT (  oDlgBacheca:resize(),   ChangeButtons( oBar ) )

  IF oDlgBacheca:nresult == IDOK

     //refresh the oPanel
      nTextHeight := CalcTextHeight(alltrim(cMessage), oFonttext, oPanel2:nWidth,oPanel2)
      oPanel2:nHeight     :=   nTextHeight

    oPanel2:nBodyHeight := oPanel2:nHeight - oPanel2:nTitleHeight
    oPanel2:CoorsUpdate()
    oPanel2:UpdateRegion()


  //refresh the oPanel with shadow effect
      oPanelShadow:nWidth:= oPanel2:nwidth-20
      oPanelShadow:nBottom:= oPanel2:nHeight-80
      oPanelShadow:refresh(.t.)

      //refresh the oPanel with Text  cMsg
      oPanelText:nWidth:= oPanelShadow:nWidth-2
      oPanelText:nBottom:= oPanelShadow:nBottom-90


   oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMessage ) ), ;
          { 10, 50, aDim[ 2 ] + 50, 300 },,oFonttext, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }

  oPanelText:refresh(.t.)

  for n= 1 to Len( oExbar:aPanels )
          oExbar:aPanels[n]:nBodyHeight += oExbar:aPanels[n]:nHeight - oExbar:aPanels[n]:nTitleHeight
          oExbar:aPanels[n]:CoorsUpdate()
          oExbar:aPanels[n]:UpdateRegion()
       next

      oExbar:CheckScroll()
ENDIF
 return nil

 //----------------------------------------------------------------------------//
function ChangeButtons( oBar )
   AEval( oBar:aControls, { | oCtrl | oCtrl:nTop += 4, oCtrl:nHeight -= 4 } )
return .T.
//----------------------------------------------------------------------------//


 FUNCTION CalcTextHeight(cText, oFont, nWidth,oPanel)
    LOCAL nLineCount := 1
    local hDC := oPanel:GetDC()
   LOCAL  nTxtWidth :=  INT( GettextWidth( hDC, ALLTRIM(cText), oFont:hFont, ) )

   // Calcola il numero di righe in base alla larghezza del testo
   IF nTxtWidth > nWidth
      nLineCount := Ceiling(nTxtWidth / nWidth)
   ENDIF

   // Calcola l'altezza del testo
   RETURN nLineCount * oFont:nHeight
 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7070
Joined: Thu Oct 18, 2012 7:17 pm

Re: Create a Panel width a text

Postby Jimmy » Thu Feb 22, 2024 8:44 pm

hi Silvio,

i have try your Sample and got Problem using PANEL and Codeblock
Code: Select all  Expand view  RUN
  oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMessage ) ), ;
          { 10, 50, aDim[ 2 ] + 50, 300 },,oFonttext, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }

i have replace PANEL using
Code: Select all  Expand view  RUN
  MEMOTEXT := alltrim( cMsg )
   @ oPanel2:nTitleHeight+5, 10  GET oPanelText VAR MEMOTEXT SIZE oPanel2:nWidth-2, oPanel2:nHeight-40 PIXEL MEMO of oPanel2 // oPanelShadow

and "resize" it this Way
Code: Select all  Expand view  RUN
     //refresh the oPanel with Text  cMsg
      oPanelText:Move(oPanel2:nTitleHeight+5, 10, oPanel2:nWidth-2,oPanel2:nHeight-40)
      MEMOTEXT := alltrim( cMessage  )

this seems to work nice
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Create a Panel width a text

Postby nageswaragunupudi » Fri Feb 23, 2024 3:48 am

Code: Select all  Expand view  RUN
function CalcTextHeight( hDC, cText, oFont, nWidth )

   local oWnd, nHt

   DEFAULT hDC := GetDC( 0 )
   if HB_ISOBJECT( hDC )
      oWnd     := hDC
      hDC      := oWnd:GetDC()
      DEFAULT oFont := oWnd:oFont, nWidth := oWnd:nWidth
   else
      DEFAULT nWidth := 800
   endif

   nHt   := DrawTextEx( hDC, cText, { 0, 0, 1000, nWidth }, 1040, ;
               If( oFont == nil, nil, oFont:hFont ),, @nWidth )

   if oWnd == nil
      if PValue( 1 ) == nil
         ReleaseDC( 0, hDC )
      endif
   else
      oWnd:ReleaseDC()
   endif

return nHt
 

1st param can be hDC or oWnd or even nil
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Create a Panel width a text

Postby Silvio.Falconi » Fri Feb 23, 2024 12:07 pm

nageswaragunupudi wrote:
Code: Select all  Expand view  RUN
function CalcTextHeight( hDC, cText, oFont, nWidth )

   local oWnd, nHt

   DEFAULT hDC := GetDC( 0 )
   if HB_ISOBJECT( hDC )
      oWnd     := hDC
      hDC      := oWnd:GetDC()
      DEFAULT oFont := oWnd:oFont, nWidth := oWnd:nWidth
   else
      DEFAULT nWidth := 800
   endif

   nHt   := DrawTextEx( hDC, cText, { 0, 0, 1000, nWidth }, 1040, ;
               If( oFont == nil, nil, oFont:hFont ),, @nWidth )

   if oWnd == nil
      if PValue( 1 ) == nil
         ReleaseDC( 0, hDC )
      endif
   else
      oWnd:ReleaseDC()
   endif

return nHt
 

1st param can be hDC or oWnd or even nil






the text must be inserted inside the oPaneltext panel which in turn is inside the oPanel2 which acts as an external frame, as a shadow effect

Code: Select all  Expand view  RUN
//create a shadow effect
   @ oPanel2:nTitleHeight+5, 10 PANEL oPanelShadow SIZE oPanel2:nwidth, oPanel2:nHeight-40 of oPanel2
   oPanelShadow:SetBrush( oBrushShadow )

   //create a panel with text
   @ 5, 5 PANEL oPanelText SIZE oPanelShadow:nWidth-2, oPanelShadow:nBottom-45 of oPanelShadow
   //oItem2:SetColor( "N/W*" )
   oPanelText:SetBrush( oBrushText  )
  * oPanelText:bPainted = { | hDC | DrawTextTransparent( hDC, cMsg, { 10, 80, aDim[ 1 ] + 120, aDim[ 2 ] + 120 }, 1 ) }

   oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMsg ) ), ;
          { 1 , 50, aDim[ 2 ] + 50, 300 },,oFont, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }
 




Jimmy,
I prefer to use fw_Saytext instead tget control because the messag emust be showed and not scrollabled

Nages
the function CalcTextHeight( hDC, cText, oFont, nWidth ) run ok (thanks) but my problem is another

Initially the message is made up of two lines, when the message is modified in the ShareBoard() function the procedure must calculate the right height
and resize the panel (oPanel2) and in turn oPaneltext where the text of the message is located.

Finally the procedure must refresh all panels except the first one, so that the following panels are one behind the other.

There is no method in the Texplorerbar class to refresh the panels because the ntop has changed, I tried to create this refresh with the following

commands but it doesn't work


Code: Select all  Expand view  RUN
for n= 1 to Len( oExbar:aPanels )
          oExbar:aPanels[n]:nBodyHeight += oExbar:aPanels[n]:nHeight - oExbar:aPanels[n]:nTitleHeight
          oExbar:aPanels[n]:CoorsUpdate()
          oExbar:aPanels[n]:UpdateRegion()
       next



Initially the explorerbar is

Image

on Default there are only two lines

when the message is empty or is less than two lines the procedure must always ensure the default space (height)



the last source after the modifications
Code: Select all  Expand view  RUN

#include "FiveWin.ch"
//#include "ribbon.ch"

//----------------------------------------------------------------------------//
static oExBar

function Main()

   local oWnd,  oPanel1, oPanel2, oPanel3, oPanel4
   local bClick := { | o | MsgInfo( o:GetText() ) }


   local uVar, oBrw, oPanel, aDim, oFont

   local cMsg := "Notice to users  bla bla bla Notice to users  bla bla bla" + CRLF + ;
                  "Notice to users  bla bla bla Notice to users  bla bla bla"+ CRLF

   DEFINE WINDOW oWnd TITLE "FWH Class TExplorerBar"

   oWnd:SetSize( 550, 600 )

   oExBar := TExplorerBar():New()


   oPanel1 = oExBar:AddPanel( "One", "..\bitmaps\32x32\people.bmp" )
   oPanel1:lSpecial = .T.
   oPanel1:AddLink( "First item", bClick, "..\bitmaps\16x16\additem.bmp" )
   oPanel2 = oExBar:AddPanel( "Two", "..\bitmaps\32x32\case.bmp" )
   oPanel3 = oExBar:AddPanel( "Three", "..\bitmaps\32x32\graphics.bmp" )



   Section_advice(oPanel2,cMsg,oPanel1)

   oWnd:oClient = oExBar

   ACTIVATE WINDOW oWnd CENTERED

return nil
//------------------------------------------------------------------//


Function Section_advice(oPanel2,cMsg,oPanel1)
   local oFont,aDim
   local oPanelText,oBrushtext
   local oPanelshadow,oBrushShadow
   local hdc,nTextHeight

   local aGradShadow :={rgb(224,224,224),rgb(224,224,224)  }
   local aGradText :={ rgb(248,248,248),rgb(248,248,248)  }

   local bBoard := { | | ShareBoard(@cMsg,oPanel2,oPanelShadow,oPanelText) }


   oPanel1:AddLink( "Edit board", bBoard, "..\bitmaps\16x16\copy.bmp" )



   DEFINE BRUSH oBrushShadow GRADIENT aGradShadow
   DEFINE BRUSH oBrushtext GRADIENT aGradText

   DEFINE FONT oFont NAME "Verdana" SIZE 0, -12
   aDim = GetLabelDim( oPanel2:hWnd, alltrim(cMsg), oFont:hFont )

    //refresh the oPanel2
    oPanel2:nHeight     :=  aDim[ 2 ] + 50
    oPanel2:nBodyHeight := oPanel2:nHeight - oPanel2:nTitleHeight
    oPanel2:CoorsUpdate()
    oPanel2:UpdateRegion()


   //create a shadow effect
    @ oPanel2:nTitleHeight+5, 2 PANEL oPanelShadow ;
    SIZE oPanel2:nwidth-30, oPanel2:nHeight-40 of oPanel2
   oPanelShadow:SetBrush( oBrushShadow )

   //create a panel with text
   @ 5, 5 PANEL oPanelText SIZE oPanelShadow:nWidth-2, oPanelShadow:nBottom-45 of oPanelShadow
   //oItem2:SetColor( "N/W*" )
   oPanelText:SetBrush( oBrushText  )
  * oPanelText:bPainted = { | hDC | DrawTextTransparent( hDC, cMsg, { 10, 80, aDim[ 1 ] + 120, aDim[ 2 ] + 120 }, 1 ) }



  //show the message
  hdc := oPanelText:getdc()
  nTextHeight := CalcTextHeight(hDC, alltrim(cMsg), oFont, oPanelText:nWidth)



   oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMsg ) ), ;
          { 1 , 1, nTextHeight+10, oPanelText:nWidth },,oFont, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }


 return nil




 //----------------------------------------------------------------------------//


Function ShareBoard(cMessage,oPanel2,oPanelShadow,oPanelText)
   local oDlgBacheca
   local oBar,oPanel

   local oBold
   local nWd  := GetSysMetrics(0) * .45
   local nHt  := (GetSysMetrics(1) / 3 )
   local oBtn := array(3)
   local hdc := oPanelText:getdc()


    local adim
    local nTotRows
    local oFonttext
    local MEMOTEXT := alltrim( cMessage )
    local  nTextHeight,nOldTextHeight

   IF Empty(cMessage)
      cMessage:= "Notice to users  bla bla bla"
   Endif


    nOldTextHeight := CalcTextHeight(hDC, alltrim(cMessage), oFonttext, oPanel2:nWidth)


   DEFINE FONT oFonttext NAME "Verdana" SIZE 0, -12
   DEFINE DIALOG oDlgBacheca SIZE nWd, nHt PIXEL ;   //TRUEPIXEL
       TITLE  "Shared board" ;
       FONT oFonttext   COLOR CLR_BLACK,  RGB( 245,245,235) ;
       STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
                  WS_MINIMIZEBOX)   //ICON oIcon

    //----------------------------------------------------------------------------//
       DEFINE BUTTONBAR oBar OF oDlgBacheca  SIZE 80,70  BOTTOM NOBORDER  2015

         oBar:bClrGrad := { | lPressed | If( ! lPressed,;
                 { { 1, RGB( 250,250,245), RGB( 250,250,245)} },;
                 { { 1, RGB( 245,245,235), RGB( 245,245,235)} } ) }

      DEFINE BUTTON oBtn[1] OF oBar  ;
      FILENAME "DLG_NO";
      PROMPT "Exit" TOOLTIP "Esci" ;
      ACTION   ( oDlgBacheca:end( IDCANCEL ) )

      DEFINE BUTTON oBtn[2] OF oBar  ;
      FILENAME "HLP_DLG";
      PROMPT "Aiuto" TOOLTIP "Aiuto" ;
      ACTION NIL   GROUP

      DEFINE BUTTON oBtn[3] OF oBar  BTNRIGHT  ;
      FILENAME "DLG_OK";
      PROMPT "Save" ;
      TOOLTIP "Conferma i dati" ;
      ACTION   ( oDlgBacheca:end( IDOK ) )
 //----------------------------------------------------------------------------//

       @ 0, 4  SAY "Wall message shared by all users...."  OF  oDlgBacheca TRANSPARENT
       @  10,   4  GET oText VAR cMessage  OF   oDlgBacheca MEMO  COLOR CLR_BLUE  SIZE 280,  75 PIXEL

     ACTIVATE DIALOG oDlgBacheca CENTERED ;
       ON INIT (  oDlgBacheca:resize(),   ChangeButtons( oBar ) )

  IF oDlgBacheca:nresult == IDOK

     //refresh the oPanel
    nTextHeight := CalcTextHeight(hDC, alltrim(cMessage), oFonttext, oPanel2:nWidth)

    IF nTextHeight < nOldTextHeight
           nTextHeight := nOldTextHeight+10
        Endif

    oPanel2:nHeight     :=   nTextHeight

    oPanel2:nBodyHeight := oPanel2:nHeight - oPanel2:nTitleHeight
    oPanel2:CoorsUpdate()
    oPanel2:UpdateRegion()
    oPanel2:refresh(.t.)

  //refresh the oPanel with shadow effect
      oPanelShadow:nWidth:= oPanel2:nwidth-20
      oPanelShadow:nBottom:= oPanel2:nHeight-80
      oPanelShadow:refresh(.t.)

      //refresh the oPanel with Text  cMsg
      oPanelText:nWidth:= oPanelShadow:nWidth-2
      oPanelText:nBottom:= oPanelShadow:nBottom-90



   // solution of Jimmy
  * MEMOTEXT := alltrim( cMsg )
  * @ oPanel2:nTitleHeight+5, 10  GET oPanelText VAR MEMOTEXT SIZE oPanel2:nWidth-2, oPanel2:nHeight-40 PIXEL MEMO of oPanel2 // oPanelShadow


     oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMessage) ), ;
          { 1 , 50,  nTextHeight, 300 },, oFonttext, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }



   //refresh the oPanel with Text  cMsg
    *  oPanelText:Move(oPanel2:nTitleHeight+5, 10, oPanel2:nWidth-2,oPanel2:nHeight-40)
      *MEMOTEXT := alltrim( cMessage  )

  oPanelText:refresh(.t.)

  //refresh all Panels ?
  for n= 1 to Len( oExbar:aPanels )
          oExbar:aPanels[n]:nBodyHeight += oExbar:aPanels[n]:nHeight - oExbar:aPanels[n]:nTitleHeight
          oExbar:aPanels[n]:CoorsUpdate()
          oExbar:aPanels[n]:UpdateRegion()
       next

      oExbar:CheckScroll()
   ENDIF

  // hDC:releasedc()

 return nil

 //----------------------------------------------------------------------------//
function ChangeButtons( oBar )
   AEval( oBar:aControls, { | oCtrl | oCtrl:nTop += 4, oCtrl:nHeight -= 4 } )
return .T.
//----------------------------------------------------------------------------//


 function CalcTextHeight( hDC, cText, oFont, nWidth )

   local oWnd, nHt

   DEFAULT hDC := GetDC( 0 )
   if HB_ISOBJECT( hDC )
      oWnd     := hDC
      hDC      := oWnd:GetDC()
      DEFAULT oFont := oWnd:oFont, nWidth := oWnd:nWidth
   else
      DEFAULT nWidth := 800
   endif

   nHt   := DrawTextEx( hDC, cText, { 0, 0, 1000, nWidth }, 1040, ;
               If( oFont == nil, nil, oFont:hFont ),, @nWidth )

   if oWnd == nil
      if PValue( 1 ) == nil
         ReleaseDC( 0, hDC )
      endif
   else
      oWnd:ReleaseDC()
   endif

return nHt

 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7070
Joined: Thu Oct 18, 2012 7:17 pm

Re: Create a Panel width a text

Postby Jimmy » Sat Feb 24, 2024 5:22 am

hi Silvio,

your last Sample still show the Problem using
Code: Select all  Expand view  RUN
      oPanelText:bPainted = { | hDC | ;
          FW_SayText( hDC, ;
              alltrim( ( cMessage) ), ;
              { 1 , 50,  nTextHeight, 300 },, oFonttext, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }

which do NOT Show hole Text when e.g. TEXT are 4 Lines instead of 2 Lines

also it does WORDBREAK while Default Style of FW_SayText are DT_VCENTER / DT_CENTER
look at FUNCTION FW_SayText() in c:\fwh\source\function\imgtxtio.prg

when using more Lines oPanel2 "grow" but Position of oPanel3 are same so it will "override"

---

i have modify you Sample, using MEMO/READONLY/NOSCROLL instead of (extra) PANEL, which work for me so far
it will "resize" oPanel2 and "reposition" oPanel3

only when "Collapse" oPanel2 i don´t know how to "react" on ( need more "resize/reposition" )
Code: Select all  Expand view  RUN
#include "FiveWin.ch"
//#include "ribbon.ch"

//----------------------------------------------------------------------------//
static oExBar, MEMOTEXT

function Main()
   local oWnd,  oPanel1, oPanel2, oPanel3, oPanel4
   local bClick := { | o | MsgInfo( o:GetText() ) }
   local uVar, oBrw, oPanel, aDim, oFont
   local cMsg := "Notice to users  bla bla bla Notice to users  bla bla bla" + CRLF + ;
                  "Notice to users  bla bla bla Notice to users  bla bla bla"+ CRLF

   DEFINE WINDOW oWnd TITLE "FWH Class TExplorerBar"

   oWnd:SetSize( 550, 600 )

   oExBar := TExplorerBar():New()

   oPanel1 = oExBar:AddPanel( "One", "..\bitmaps\32x32\people.bmp" )
   oPanel1:lSpecial = .T.
   oPanel1:AddLink( "First item", bClick, "..\bitmaps\16x16\additem.bmp" )
   oPanel2 = oExBar:AddPanel( "Two", "..\bitmaps\32x32\case.bmp" )
   oPanel3 = oExBar:AddPanel( "Three", "..\bitmaps\32x32\graphics.bmp" )

   Section_advice(oPanel2,cMsg,oPanel1)

   oWnd:oClient = oExBar

   ACTIVATE WINDOW oWnd CENTERED

return nil
//------------------------------------------------------------------//


Function Section_advice(oPanel2,cMsg,oPanel1)
   local oFont,aDim
   local oPanelText,oBrushtext
   local oPanelshadow,oBrushShadow
   local hdc,nTextHeight

   local aGradShadow :={rgb(224,224,224),rgb(224,224,224)  }
   local aGradText :={ rgb(248,248,248),rgb(248,248,248)  }

   local bBoard := { | | ShareBoard(@cMsg,oPanel2,oPanelShadow,oPanelText) }
LOCAL n, yPos := 0

   oPanel1:AddLink( "Edit board", bBoard, "..\bitmaps\16x16\copy.bmp" )

   DEFINE BRUSH oBrushShadow GRADIENT aGradShadow
   DEFINE BRUSH oBrushtext GRADIENT aGradText

   DEFINE FONT oFont NAME "Verdana" SIZE 0, -12
   aDim = GetLabelDim( oPanel2:hWnd, alltrim(cMsg), oFont:hFont )

    //refresh the oPanel2
    oPanel2:nHeight     := aDim[ 2 ] + (3 * (oFont:nHeight() +2) )
    oPanel2:nBodyHeight := oPanel2:nHeight - oPanel2:nTitleHeight
    oPanel2:CoorsUpdate()
    oPanel2:UpdateRegion()

   //create a shadow effect
    @ oPanel2:nTitleHeight+5, 2 PANEL oPanelShadow ;
    SIZE oPanel2:nwidth-30, oPanel2:nHeight-40 of oPanel2
    oPanelShadow:SetBrush( oBrushShadow )

#IFDEF Use_FW_SayText
   //create a panel with text
   @ 5, 5 PANEL oPanelText SIZE oPanelShadow:nWidth-2, oPanelShadow:nBottom-45 of oPanelShadow
   //oItem2:SetColor( "N/W*" )
   oPanelText:SetBrush( oBrushText  )
  * oPanelText:bPainted = { | hDC | DrawTextTransparent( hDC, cMsg, { 10, 80, aDim[ 1 ] + 120, aDim[ 2 ] + 120 }, 1 ) }

  //show the message
   hdc := oPanelText:getdc()
   nTextHeight := CalcTextHeight(hDC, alltrim(cMsg), oFont, oPanelText:nWidth)

   oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMsg ) ), ;
          { 1 , 1, nTextHeight+10, oPanelText:nWidth },,oFont, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }
#ELSE
   MEMOTEXT := alltrim( cMsg )
   @ oPanel2:nTitleHeight+5, 10  GET oPanelText VAR MEMOTEXT SIZE oPanel2:nWidth-2, oPanel2:nHeight-40 PIXEL MEMO NO VSCROLL READONLY of oPanel2
#ENDIF

   for n= 1 to Len( oExbar:aPanels )
   //  move Panel to new Position
       oExbar:aPanels[n]:Move(yPos)

       oExbar:aPanels[n]:nBodyHeight += oExbar:aPanels[n]:nHeight - oExbar:aPanels[n]:nTitleHeight
       oExbar:aPanels[n]:CoorsUpdate()
       oExbar:aPanels[n]:UpdateRegion()

       oExbar:CheckScroll()
       yPos += oExbar:aPanels[n]:nHeight + 20
   next
   oExbar:Refresh()

 return nil

 //----------------------------------------------------------------------------//


Function ShareBoard(cMessage,oPanel2,oPanelShadow,oPanelText)
   local oDlgBacheca
   local oBar,oPanel

   local oBold
   local nWd  := GetSysMetrics(0) * .45
   local nHt  := (GetSysMetrics(1) / 3 )
   local oBtn := array(3)
   local hdc := oPanelText:getdc()


    local adim
    local nTotRows
    local oFonttext
*    local MEMOTEXT := alltrim( cMessage ) // use FIELD Wide STATIC
    local  nTextHeight,nOldTextHeight
LOCAL oText, n, yPos := 0

   IF Empty(cMessage)
      cMessage:= "Notice to users  bla bla bla"
   Endif
// oFonttext not DEFINE here
*   nOldTextHeight := CalcTextHeight(hDC, alltrim(cMessage), oFonttext, oPanel2:nWidth)

   DEFINE FONT oFonttext NAME "Verdana" SIZE 0, -12
   DEFINE DIALOG oDlgBacheca SIZE nWd, nHt PIXEL ;   //TRUEPIXEL
       TITLE  "Shared board" ;
       FONT oFonttext   COLOR CLR_BLACK,  RGB( 245,245,235) ;
       STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
                  WS_MINIMIZEBOX)   //ICON oIcon

    //----------------------------------------------------------------------------//
       DEFINE BUTTONBAR oBar OF oDlgBacheca  SIZE 80,70  BOTTOM NOBORDER  2015

         oBar:bClrGrad := { | lPressed | If( ! lPressed,;
                 { { 1, RGB( 250,250,245), RGB( 250,250,245)} },;
                 { { 1, RGB( 245,245,235), RGB( 245,245,235)} } ) }

      DEFINE BUTTON oBtn[1] OF oBar  ;
      FILENAME "DLG_NO";
      PROMPT "Exit" TOOLTIP "Esci" ;
      ACTION   ( oDlgBacheca:end( IDCANCEL ) )

      DEFINE BUTTON oBtn[2] OF oBar  ;
      FILENAME "HLP_DLG";
      PROMPT "Aiuto" TOOLTIP "Aiuto" ;
      ACTION NIL   GROUP

      DEFINE BUTTON oBtn[3] OF oBar  BTNRIGHT  ;
      FILENAME "DLG_OK";
      PROMPT "Save" ;
      TOOLTIP "Conferma i dati" ;
      ACTION   ( oDlgBacheca:end( IDOK ) )
 //----------------------------------------------------------------------------//

       @ 0, 4  SAY "Wall message shared by all users...."  OF  oDlgBacheca TRANSPARENT
       @  10,   4  GET oText VAR cMessage  OF   oDlgBacheca MEMO  COLOR CLR_BLUE  SIZE 280,  75 PIXEL

     ACTIVATE DIALOG oDlgBacheca CENTERED ;
       ON INIT (  oDlgBacheca:resize(),   ChangeButtons( oBar ) )

  IF oDlgBacheca:nresult == IDOK
#IFDEF Use_FW_SayText
    nOldTextHeight := CalcTextHeight(hDC, alltrim(cMessage), oFonttext, oPanel2:nWidth)
     //refresh the oPanel
    nTextHeight := CalcTextHeight(hDC, alltrim(cMessage), oFonttext, oPanel2:nWidth)
    IF nTextHeight < nOldTextHeight
       nTextHeight := nOldTextHeight+10
    Endif
    oPanel2:nHeight     :=   nTextHeight
#ELSE
    aDim = GetLabelDim( oPanel2:hWnd, alltrim(cMessage), oFonttext:hFont )
    oPanel2:nHeight     := aDim[ 2 ] + (3 * (oFonttext:nHeight() +2) )
#ENDIF

    oPanel2:nBodyHeight := oPanel2:nHeight - oPanel2:nTitleHeight
    oPanel2:CoorsUpdate()
    oPanel2:UpdateRegion()
    oPanel2:refresh(.t.)

  //refresh the oPanel with shadow effect
      oPanelShadow:nWidth:= oPanel2:nwidth-20
      oPanelShadow:nBottom:= oPanel2:nHeight-80
      oPanelShadow:refresh(.t.)

      //refresh the oPanel with Text  cMsg
      oPanelText:nWidth:= oPanelShadow:nWidth-2
      oPanelText:nBottom:= oPanelShadow:nBottom-90

#IFDEF Use_FW_SayText
     oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMessage) ), ;
          { 1 , 50,  nTextHeight, 300 },, oFonttext, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }

      oPanelText:refresh(.t.)
#ELSE
      // solution of Jimmy
      oPanelText:Move(oPanel2:nTitleHeight+5, 10, oPanel2:nWidth-2,oPanel2:nHeight-40)
     MEMOTEXT := alltrim( cMessage)
#ENDIF

      //refresh all Panels ?
      for n= 1 to Len( oExbar:aPanels )
         // move Panel to new Position
         oExbar:aPanels[n]:Move(yPos)

          oExbar:aPanels[n]:nBodyHeight += oExbar:aPanels[n]:nHeight - oExbar:aPanels[n]:nTitleHeight
          oExbar:aPanels[n]:CoorsUpdate()
          oExbar:aPanels[n]:UpdateRegion()

         oExbar:CheckScroll()
         yPos += oExbar:aPanels[n]:nHeight + 20
      next
      //refresh
      oExbar:Refresh()

   ENDIF

  // hDC:releasedc()

 return nil

 //----------------------------------------------------------------------------//
function ChangeButtons( oBar )
   AEval( oBar:aControls, { | oCtrl | oCtrl:nTop += 4, oCtrl:nHeight -= 4 } )
return .T.
//----------------------------------------------------------------------------//


function CalcTextHeight( hDC, cText, oFont, nWidth )

   local oWnd, nHt

   DEFAULT hDC := GetDC( 0 )
   if HB_ISOBJECT( hDC )
      oWnd     := hDC
      hDC      := oWnd:GetDC()
      DEFAULT oFont := oWnd:oFont, nWidth := oWnd:nWidth
   else
      DEFAULT nWidth := 800
   endif

   nHt   := DrawTextEx( hDC, cText, { 0, 0, 1000, nWidth }, 1040, ;
               If( oFont == nil, nil, oFont:hFont ),, @nWidth )

   if oWnd == nil
      if PValue( 1 ) == nil
         ReleaseDC( 0, hDC )
      endif
   else
      oWnd:ReleaseDC()
   endif

return nHt
 
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Create a Panel width a text

Postby Silvio.Falconi » Sat Feb 24, 2024 11:30 am

Jimmy wrote:hi Silvio,

your last Sample still show the Problem using
Code: Select all  Expand view  RUN
      oPanelText:bPainted = { | hDC | ;
          FW_SayText( hDC, ;
              alltrim( ( cMessage) ), ;
              { 1 , 50,  nTextHeight, 300 },, oFonttext, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }

which do NOT Show hole Text when e.g. TEXT are 4 Lines instead of 2 Lines

also it does WORDBREAK while Default Style of FW_SayText are DT_VCENTER / DT_CENTER
look at FUNCTION FW_SayText() in c:\fwh\source\function\imgtxtio.prg

when using more Lines oPanel2 "grow" but Position of oPanel3 are same so it will "override"

---

i have modify you Sample, using MEMO/READONLY/NOSCROLL instead of (extra) PANEL, which work for me so far
it will "resize" oPanel2 and "reposition" oPanel3

only when "Collapse" oPanel2 i don´t know how to "react" on ( need more "resize/reposition" )
Code: Select all  Expand view  RUN
#include "FiveWin.ch"
//#include "ribbon.ch"

//----------------------------------------------------------------------------//
static oExBar, MEMOTEXT

function Main()
   local oWnd,  oPanel1, oPanel2, oPanel3, oPanel4
   local bClick := { | o | MsgInfo( o:GetText() ) }
   local uVar, oBrw, oPanel, aDim, oFont
   local cMsg := "Notice to users  bla bla bla Notice to users  bla bla bla" + CRLF + ;
                  "Notice to users  bla bla bla Notice to users  bla bla bla"+ CRLF

   DEFINE WINDOW oWnd TITLE "FWH Class TExplorerBar"

   oWnd:SetSize( 550, 600 )

   oExBar := TExplorerBar():New()

   oPanel1 = oExBar:AddPanel( "One", "..\bitmaps\32x32\people.bmp" )
   oPanel1:lSpecial = .T.
   oPanel1:AddLink( "First item", bClick, "..\bitmaps\16x16\additem.bmp" )
   oPanel2 = oExBar:AddPanel( "Two", "..\bitmaps\32x32\case.bmp" )
   oPanel3 = oExBar:AddPanel( "Three", "..\bitmaps\32x32\graphics.bmp" )

   Section_advice(oPanel2,cMsg,oPanel1)

   oWnd:oClient = oExBar

   ACTIVATE WINDOW oWnd CENTERED

return nil
//------------------------------------------------------------------//


Function Section_advice(oPanel2,cMsg,oPanel1)
   local oFont,aDim
   local oPanelText,oBrushtext
   local oPanelshadow,oBrushShadow
   local hdc,nTextHeight

   local aGradShadow :={rgb(224,224,224),rgb(224,224,224)  }
   local aGradText :={ rgb(248,248,248),rgb(248,248,248)  }

   local bBoard := { | | ShareBoard(@cMsg,oPanel2,oPanelShadow,oPanelText) }
LOCAL n, yPos := 0

   oPanel1:AddLink( "Edit board", bBoard, "..\bitmaps\16x16\copy.bmp" )

   DEFINE BRUSH oBrushShadow GRADIENT aGradShadow
   DEFINE BRUSH oBrushtext GRADIENT aGradText

   DEFINE FONT oFont NAME "Verdana" SIZE 0, -12
   aDim = GetLabelDim( oPanel2:hWnd, alltrim(cMsg), oFont:hFont )

    //refresh the oPanel2
    oPanel2:nHeight     := aDim[ 2 ] + (3 * (oFont:nHeight() +2) )
    oPanel2:nBodyHeight := oPanel2:nHeight - oPanel2:nTitleHeight
    oPanel2:CoorsUpdate()
    oPanel2:UpdateRegion()

   //create a shadow effect
    @ oPanel2:nTitleHeight+5, 2 PANEL oPanelShadow ;
    SIZE oPanel2:nwidth-30, oPanel2:nHeight-40 of oPanel2
    oPanelShadow:SetBrush( oBrushShadow )

#IFDEF Use_FW_SayText
   //create a panel with text
   @ 5, 5 PANEL oPanelText SIZE oPanelShadow:nWidth-2, oPanelShadow:nBottom-45 of oPanelShadow
   //oItem2:SetColor( "N/W*" )
   oPanelText:SetBrush( oBrushText  )
  * oPanelText:bPainted = { | hDC | DrawTextTransparent( hDC, cMsg, { 10, 80, aDim[ 1 ] + 120, aDim[ 2 ] + 120 }, 1 ) }

  //show the message
   hdc := oPanelText:getdc()
   nTextHeight := CalcTextHeight(hDC, alltrim(cMsg), oFont, oPanelText:nWidth)

   oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMsg ) ), ;
          { 1 , 1, nTextHeight+10, oPanelText:nWidth },,oFont, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }
#ELSE
   MEMOTEXT := alltrim( cMsg )
   @ oPanel2:nTitleHeight+5, 10  GET oPanelText VAR MEMOTEXT SIZE oPanel2:nWidth-2, oPanel2:nHeight-40 PIXEL MEMO NO VSCROLL READONLY of oPanel2
#ENDIF

   for n= 1 to Len( oExbar:aPanels )
   //  move Panel to new Position
       oExbar:aPanels[n]:Move(yPos)

       oExbar:aPanels[n]:nBodyHeight += oExbar:aPanels[n]:nHeight - oExbar:aPanels[n]:nTitleHeight
       oExbar:aPanels[n]:CoorsUpdate()
       oExbar:aPanels[n]:UpdateRegion()

       oExbar:CheckScroll()
       yPos += oExbar:aPanels[n]:nHeight + 20
   next
   oExbar:Refresh()

 return nil

 //----------------------------------------------------------------------------//


Function ShareBoard(cMessage,oPanel2,oPanelShadow,oPanelText)
   local oDlgBacheca
   local oBar,oPanel

   local oBold
   local nWd  := GetSysMetrics(0) * .45
   local nHt  := (GetSysMetrics(1) / 3 )
   local oBtn := array(3)
   local hdc := oPanelText:getdc()


    local adim
    local nTotRows
    local oFonttext
*    local MEMOTEXT := alltrim( cMessage ) // use FIELD Wide STATIC
    local  nTextHeight,nOldTextHeight
LOCAL oText, n, yPos := 0

   IF Empty(cMessage)
      cMessage:= "Notice to users  bla bla bla"
   Endif
// oFonttext not DEFINE here
*   nOldTextHeight := CalcTextHeight(hDC, alltrim(cMessage), oFonttext, oPanel2:nWidth)

   DEFINE FONT oFonttext NAME "Verdana" SIZE 0, -12
   DEFINE DIALOG oDlgBacheca SIZE nWd, nHt PIXEL ;   //TRUEPIXEL
       TITLE  "Shared board" ;
       FONT oFonttext   COLOR CLR_BLACK,  RGB( 245,245,235) ;
       STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, ;
                  WS_MINIMIZEBOX)   //ICON oIcon

    //----------------------------------------------------------------------------//
       DEFINE BUTTONBAR oBar OF oDlgBacheca  SIZE 80,70  BOTTOM NOBORDER  2015

         oBar:bClrGrad := { | lPressed | If( ! lPressed,;
                 { { 1, RGB( 250,250,245), RGB( 250,250,245)} },;
                 { { 1, RGB( 245,245,235), RGB( 245,245,235)} } ) }

      DEFINE BUTTON oBtn[1] OF oBar  ;
      FILENAME "DLG_NO";
      PROMPT "Exit" TOOLTIP "Esci" ;
      ACTION   ( oDlgBacheca:end( IDCANCEL ) )

      DEFINE BUTTON oBtn[2] OF oBar  ;
      FILENAME "HLP_DLG";
      PROMPT "Aiuto" TOOLTIP "Aiuto" ;
      ACTION NIL   GROUP

      DEFINE BUTTON oBtn[3] OF oBar  BTNRIGHT  ;
      FILENAME "DLG_OK";
      PROMPT "Save" ;
      TOOLTIP "Conferma i dati" ;
      ACTION   ( oDlgBacheca:end( IDOK ) )
 //----------------------------------------------------------------------------//

       @ 0, 4  SAY "Wall message shared by all users...."  OF  oDlgBacheca TRANSPARENT
       @  10,   4  GET oText VAR cMessage  OF   oDlgBacheca MEMO  COLOR CLR_BLUE  SIZE 280,  75 PIXEL

     ACTIVATE DIALOG oDlgBacheca CENTERED ;
       ON INIT (  oDlgBacheca:resize(),   ChangeButtons( oBar ) )

  IF oDlgBacheca:nresult == IDOK
#IFDEF Use_FW_SayText
    nOldTextHeight := CalcTextHeight(hDC, alltrim(cMessage), oFonttext, oPanel2:nWidth)
     //refresh the oPanel
    nTextHeight := CalcTextHeight(hDC, alltrim(cMessage), oFonttext, oPanel2:nWidth)
    IF nTextHeight < nOldTextHeight
       nTextHeight := nOldTextHeight+10
    Endif
    oPanel2:nHeight     :=   nTextHeight
#ELSE
    aDim = GetLabelDim( oPanel2:hWnd, alltrim(cMessage), oFonttext:hFont )
    oPanel2:nHeight     := aDim[ 2 ] + (3 * (oFonttext:nHeight() +2) )
#ENDIF

    oPanel2:nBodyHeight := oPanel2:nHeight - oPanel2:nTitleHeight
    oPanel2:CoorsUpdate()
    oPanel2:UpdateRegion()
    oPanel2:refresh(.t.)

  //refresh the oPanel with shadow effect
      oPanelShadow:nWidth:= oPanel2:nwidth-20
      oPanelShadow:nBottom:= oPanel2:nHeight-80
      oPanelShadow:refresh(.t.)

      //refresh the oPanel with Text  cMsg
      oPanelText:nWidth:= oPanelShadow:nWidth-2
      oPanelText:nBottom:= oPanelShadow:nBottom-90

#IFDEF Use_FW_SayText
     oPanelText:bPainted = { | hDC | ;
    FW_SayText( hDC, ;
           alltrim( ( cMessage) ), ;
          { 1 , 50,  nTextHeight, 300 },, oFonttext, RGB(255,165,0), nARGB(255,rgb(248,248,248)  ) , .f. ) }

      oPanelText:refresh(.t.)
#ELSE
      // solution of Jimmy
      oPanelText:Move(oPanel2:nTitleHeight+5, 10, oPanel2:nWidth-2,oPanel2:nHeight-40)
     MEMOTEXT := alltrim( cMessage)
#ENDIF

      //refresh all Panels ?
      for n= 1 to Len( oExbar:aPanels )
         // move Panel to new Position
         oExbar:aPanels[n]:Move(yPos)

          oExbar:aPanels[n]:nBodyHeight += oExbar:aPanels[n]:nHeight - oExbar:aPanels[n]:nTitleHeight
          oExbar:aPanels[n]:CoorsUpdate()
          oExbar:aPanels[n]:UpdateRegion()

         oExbar:CheckScroll()
         yPos += oExbar:aPanels[n]:nHeight + 20
      next
      //refresh
      oExbar:Refresh()

   ENDIF

  // hDC:releasedc()

 return nil

 //----------------------------------------------------------------------------//
function ChangeButtons( oBar )
   AEval( oBar:aControls, { | oCtrl | oCtrl:nTop += 4, oCtrl:nHeight -= 4 } )
return .T.
//----------------------------------------------------------------------------//


function CalcTextHeight( hDC, cText, oFont, nWidth )

   local oWnd, nHt

   DEFAULT hDC := GetDC( 0 )
   if HB_ISOBJECT( hDC )
      oWnd     := hDC
      hDC      := oWnd:GetDC()
      DEFAULT oFont := oWnd:oFont, nWidth := oWnd:nWidth
   else
      DEFAULT nWidth := 800
   endif

   nHt   := DrawTextEx( hDC, cText, { 0, 0, 1000, nWidth }, 1040, ;
               If( oFont == nil, nil, oFont:hFont ),, @nWidth )

   if oWnd == nil
      if PValue( 1 ) == nil
         ReleaseDC( 0, hDC )
      endif
   else
      oWnd:ReleaseDC()
   endif

return nHt
 

As i told you i prefer use Say and not get
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7070
Joined: Thu Oct 18, 2012 7:17 pm

Re: Create a Panel width a text

Postby Jimmy » Sat Feb 24, 2024 3:52 pm

hi Silvio,
Silvio.Falconi wrote:As i told you i prefer use Say and not get

i have use GET while i had Problem with FW_SayText() and (extra) PANEL :!:
GET use MEMO READONLY NO SCROLL but you can use SAY or RTF too

---

when Edit Item and copy / paste those 2 Lines, save 4 x Lines, it still display 2 Lines but using WORDWRAP :!:
i do not know if you want, using CalcTextHeight(), a "fixed" PANEL Layout :?:

---

in my modify CODE all Lines are displayed and Position of Panel3 will change
Code: Select all  Expand view  RUN
   aDim = GetLabelDim( oPanel2:hWnd, alltrim(cMessage), oFonttext:hFont )

GetLabelDim() will give you "right" Size and
Code: Select all  Expand view  RUN
   oFonttext:nHeight() +2

is hight of each Line.

while Source use oPanelShadow as Parent which does not use "full Area" of TTaskPanel()
Code: Select all  Expand view  RUN
   oPanel2:nHeight     := aDim[ 2 ] + (3 * (oFonttext:nHeight() +2) )

that will give you 3 x Lines when EMPTY(cMessage)

---

to "move" and "resize" TTaskPanel()
Code: Select all  Expand view  RUN
     //refresh all Panels ?
      for n= 1 to Len( oExbar:aPanels )
         // move Panel to new Position
         oExbar:aPanels[n]:Move(yPos)

          oExbar:aPanels[n]:nBodyHeight += oExbar:aPanels[n]:nHeight - oExbar:aPanels[n]:nTitleHeight
          oExbar:aPanels[n]:CoorsUpdate()
          oExbar:aPanels[n]:UpdateRegion()

         oExbar:CheckScroll()
         yPos += oExbar:aPanels[n]:nHeight + 20
      next
      //refresh
      oExbar:Refresh()
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Create a Panel width a text

Postby Silvio.Falconi » Mon Feb 26, 2024 8:14 am

Jimmy wrote:hi Silvio,
Silvio.Falconi wrote:As i told you i prefer use Say and not get

i have use GET while i had Problem with FW_SayText() and (extra) PANEL :!:
GET use MEMO READONLY NO SCROLL but you can use SAY or RTF too

---

when Edit Item and copy / paste those 2 Lines, save 4 x Lines, it still display 2 Lines but using WORDWRAP :!:
i do not know if you want, using CalcTextHeight(), a "fixed" PANEL Layout :?:

---

in my modify CODE all Lines are displayed and Position of Panel3 will change
Code: Select all  Expand view  RUN
   aDim = GetLabelDim( oPanel2:hWnd, alltrim(cMessage), oFonttext:hFont )

GetLabelDim() will give you "right" Size and
Code: Select all  Expand view  RUN
   oFonttext:nHeight() +2

is hight of each Line.

while Source use oPanelShadow as Parent which does not use "full Area" of TTaskPanel()
Code: Select all  Expand view  RUN
   oPanel2:nHeight     := aDim[ 2 ] + (3 * (oFonttext:nHeight() +2) )

that will give you 3 x Lines when EMPTY(cMessage)

---

to "move" and "resize" TTaskPanel()
Code: Select all  Expand view  RUN
     //refresh all Panels ?
      for n= 1 to Len( oExbar:aPanels )
         // move Panel to new Position
         oExbar:aPanels[n]:Move(yPos)

          oExbar:aPanels[n]:nBodyHeight += oExbar:aPanels[n]:nHeight - oExbar:aPanels[n]:nTitleHeight
          oExbar:aPanels[n]:CoorsUpdate()
          oExbar:aPanels[n]:UpdateRegion()

         oExbar:CheckScroll()
         yPos += oExbar:aPanels[n]:nHeight + 20
      next
      //refresh
      oExbar:Refresh()



Jimmy,

It seems strange to me that if Nages said to use the fw_saytext function then it doesn't work, because initially in the section_advice() function the fw_saytext function works well in fact it shows the initial message

then if you see well I replaced the getlabeldim function with CalcTextHeight( hDC, cText, oFont, nWidth ) corrected by Nageswarao


On your sample:
oPaneltext cannot be the same name of a Panel
I propose to usare oTExt

MEMOTEXT := alltrim( cMsg )
@ oPanel2:nTitleHeight+5, 10 GET oText VAR MEMOTEXT SIZE oPaneltext:nWidth-2, oPaneltext:nHeight-40 PIXEL MEMO NO VSCROLL READONLY of oPaneltext

then

do you have try to click collapse button ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7070
Joined: Thu Oct 18, 2012 7:17 pm

Re: Create a Panel width a text

Postby Jimmy » Mon Feb 26, 2024 10:27 pm

hi Silvio,

it seems me that 4th Parametern cAlign of FW_SsayText is missing so
Code: Select all  Expand view  RUN
     nVAlign     := If( "T" $ cAlign, DT_TOP,  If( "B" $ cAlign, DT_BOTTOM, DT_VCENTER ) )
      nHAlign     := iF( "L" $ cAlign, DT_LEFT, If( "R" $ cAlign, DT_RIGHT,  DT_CENTER  ) )

will give you DT_VCENTER / DT_VENTER
that will cause wrap TEXT using TTaskPanel() which have Margin

---

Silvio.Falconi wrote:do you have try to click collapse button ?

YES, so far seen https://forums.fivetechsupport.com/viewtopic.php?f=3&t=44267
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Create a Panel width a text

Postby Silvio.Falconi » Wed Feb 28, 2024 9:51 am

Resolved!!

Image

Only when I close/open taskpanel make error ( of visualization) perhaps it need to explorerbar to activate /noActivate close/open button ?

Another question
when the text is big on width it can be bad

Image

Perhaps we need a function to divide the text inserted into rows ?
cNewMessage:= DivideTestoInRighe(cMessage, 150)

FRom ChatGpt but not run

Code: Select all  Expand view  RUN
FUNCTION DivideTestoInRighe(cTesto, lunghezzaRiga)
   LOCAL nLunghezzaTesto, nRighe, nResto, cRisultato, i, j, nIndex

   // Calcola la lunghezza totale del testo
   nLunghezzaTesto := LEN(cTesto)

   // Calcola il numero di righe necessarie
   nRighe := INT(nLunghezzaTesto / lunghezzaRiga)
   nResto := MOD(nLunghezzaTesto, lunghezzaRiga)
   IF nResto > 0
      nRighe++
   ENDIF

   // Inizializza la stringa risultato
   cRisultato := ""

   // Divide il testo in righe di lunghezza esatta
   FOR i := 1 TO nRighe
      FOR j := 1 TO lunghezzaRiga
         // Calcola l'indice corrispondente nel testo originale
         nIndex := (i - 1) * lunghezzaRiga + j
         // Aggiunge il carattere corrispondente alla riga
         IF nIndex <= nLunghezzaTesto
            cRisultato := cRisultato + SUBSTR(cTesto, nIndex, 1)
         ENDIF
      NEXT j
      // Aggiunge un ritorno a capo alla fine di ogni riga, tranne l'ultima
      IF i < nRighe
         cRisultato := cRisultato + CHR(13) + CHR(10)
      ENDIF
   NEXT i

   RETURN cRisultato








 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7070
Joined: Thu Oct 18, 2012 7:17 pm

Re: Create a Panel width a text

Postby Silvio.Falconi » Wed Feb 28, 2024 10:24 am

corrected
cNewMessage:= DivideTestoInRighe(cMessage, 80)

Image

Code: Select all  Expand view  RUN
FUNCTION DivideTestoInRighe(cTesto, lunghezzaRiga)
   LOCAL nLunghezzaTesto, nRighe, nInizio, cRiga, cRisultato

   // Calcola la lunghezza totale del testo
   nLunghezzaTesto := LEN(cTesto)

   // Inizializza la stringa risultato
   cRisultato := ""

   // Divide il testo in righe di lunghezza esatta
   FOR nInizio := 1 TO nLunghezzaTesto STEP lunghezzaRiga
      // Seleziona una sottostringa di lunghezza desiderata
      cRiga := SUBSTR(cTesto, nInizio, lunghezzaRiga)
      // Aggiunge la riga alla stringa risultato
      cRisultato := cRisultato + cRiga + " "  // Aggiunge uno spazio dopo ogni riga
   NEXT nInizio

   RETURN cRisultato
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7070
Joined: Thu Oct 18, 2012 7:17 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 36 guests