Page 1 of 1

CJpushButton FONT

Posted: Thu Jul 01, 2010 10:14 pm
by skiman
Hi,

I posted the FONT problem about a month ago to the codejock developer forum. There wasn't any response, their support could be better. :(

After testing a bit with the cjpushbutton, I realised that it should be possible to use the XAML possibilities to use a font, with the normal eXpress++ syntax. This is my workaround for the font problem.

Code: Select all

	@ 10,10 CJPushButton oBut1 ;
       Size 130,80 ; 
	   BITMAP ABO_LEVERN ;    // bitmap from resources
       Caption "Testing font" ;  
       Font '12.Arial bold italic' ;
       TextImageRelation xtpImageAboveText ;
       Transparent ;
	   IMAGEALIGNMENT xtpAlignCenter ;
	   textalign xtpAlignCenter ;
       Appearance xtpAppearanceOffice2007 ;
       Style xtpButtonNormal ;
	   ACTION {|o| ....  } PIXEL
If the command doesn't set the ENABLEMARKUP and there is a FONT defined, I added the following in the cjclass.prg.

Code: Select all

...
cCaption := aGetListItem[cGETLIST_CAPTION]
::caption := cCaption
// start workaround font lockup chris andries 01/07/10
// if enablemarkup is not set, and there is a font, create a simple xaml command to use the font.
if !aOptions[8] .and. !empty(cFont)    
    cFont = upper(cFont)
	cPointSize := left(cFont,at('.',cFont)-1)
	IF 'BOLD' $ Upper(cFont)
		lBold := .T.
		cFont := StrTran(cFont,' BOLD','')
	ENDIF
	IF 'ITALIC' $ Upper(cFont)
		lItalic := .T.
		cFont := StrTran(cFont,' ITALIC','')
	ENDIF
		
	cFont := Alltrim(StrTran(CJ_Token(cFont,'.',2),'.',' '))
	cFont := StrTran(cFont,'  ',' ')

    cCaption := "<TextBlock FontFamily='"+cFont+"' FontSize='"+cPointSize+"'"
	cCaption += iif(lBold, " FontWeight='Bold'","") 
	cCaption += iif(lItalic," FontStyle='Italic'","")
    cCaption += ">" + aGetListItem[cGETLIST_CAPTION]+"</TextBlock>"
	::enableMarkup := .T. 
	::caption := cCaption
endif
// stop workaround
::setColor( aGetListItem )
...
This way a font can be used without a problem, and without any knowledge of the xaml possibilities.

Re: CJpushButton FONT

Posted: Fri Jul 02, 2010 6:50 am
by rdonnay
Thanks Chris. I will add this to the code.

Re: CJpushButton FONT

Posted: Mon Jan 10, 2011 12:35 pm
by skiman
Hi Roger,

I modified the code to have multi-line captions on the cj_buttons. If there is a semo-colom ';' used in the caption, I create a multiline caption with xaml.

Here is the complete class.

Code: Select all

CLASS CJ_PushButton FROM DC_XbpActiveXControl, CJ_Parts

EXPORTED:

INLINE METHOD Init( oParent, oOwner, aPos, aSize, aPres, lVisible, oGetList )
::clsid := 'CodeJock.PushButton' + CJ_Version()
::license := CJ_LicenseControls()
::DC_XbpActiveXControl:init( @oParent, @oOwner, aPos, aSize, aPres, lVisible, oGetList )
::CJ_Parts:init(.t.)

RETURN self

INLINE METHOD Create( oParent, oOwner, aPos, aSize, aPres, lVisible )

LOCAL aGetListItem, aOptions, cFont, cCaption, aColor, oIcon
Local aResFile , nHandle , i
Local lBold := .F. , lItalic := .F. , cFamilyName := "" , cPointsize := ""

::DC_XbpActiveXControl:create( @oParent, @oOwner, aPos, aSize, aPres, lVisible )

aGetListItem := ::getList:getListArray[::getListPointer]
aOptions := aGetListItem[xGETLIST_OPTIONS3]

cFont := aGetListItem[cGETLIST_FONT]
//IF !Empty(cFont)
//  ::setFont(CJ_Font(cFont,.f.))
//  ::setProperty('font',CJ_Font(cFont)) // << locks up app
// ENDIF


DEFAULT aOptions := {}
ASize(aOptions,24)

DEFAULT aOptions[1] := xtpAppearanceFlat, ;
        aOptions[2] := 2, ;
        aOptions[4] := .f., ;
        aOptions[5] := .f., ;
        aOptions[6] := .t., ;
        aOptions[7] := .f., ;
        aOptions[8] := .f., ;
        aOptions[11] := 2, ;
        aOptions[12] := xtpAlignLeft, ;
        aOptions[14] := .t., ;
        aOptions[15] := .f., ;
        aOptions[16] := xtpButtonNormal, ;
        aOptions[17] := xtpAlignCenter, ;
        aOptions[18] := xtpImageBeforeText, ;
        aOptions[19] := .f., ;
        aOptions[20] := .f.

// ::borderGap := aOptions[2]
IF Valtype(aOptions[3]) == 'O'
  ::buddyControl := aOptions[3]
ENDIF
::checked := aOptions[4]
::default := aOptions[5]
::drawFocusRect := aOptions[6]
::flatStyle := aOptions[7]
::enableMarkup := aOptions[8]
::imageGap := aOptions[11]
::imageAlignment := aOptions[12]
::rightToLeft := aOptions[15]
::style := aOptions[16]
::textAlignment := aOptions[17]
::textImageRelation := aOptions[18]
::transparent := aOptions[19]
::useVisualStyle := aOptions[20]
::setProperty("multiLine",aOptions[14])

IF Valtype(aOptions[21]) == 'B'
  ::click := {||PostAppEvent(DCGUI_EVENT_ACTION,aOptions[21],,self)}
ENDIF
IF Valtype(aOptions[22]) == 'B'
  ::dropDown := {||PostAppEvent(DCGUI_EVENT_ACTION,aOptions[22],,self)}
ENDIF
IF Valtype(aOptions[23]) == 'B'
  ::keyDown := {||PostAppEvent(DCGUI_EVENT_ACTION,aOptions[23],,self)}
ENDIF

cCaption := aGetListItem[cGETLIST_CAPTION]
::caption := cCaption

if !aOptions[8] .and. !empty(cFont)
    cFont = upper(cFont)
	cPointSize := left(cFont,at('.',cFont)-1)
	IF 'BOLD' $ Upper(cFont)
		lBold := .T.
		cFont := StrTran(cFont,' BOLD','')
	ENDIF
	IF 'ITALIC' $ Upper(cFont)
		lItalic := .T.
		cFont := StrTran(cFont,' ITALIC','')
	ENDIF
		
	cFont := Alltrim(StrTran(CJ_Token(cFont,'.',2),'.',' '))
	cFont := StrTran(cFont,'  ',' ')

    cCaption := "<TextBlock FontFamily='"+cFont+"' FontSize='"+cPointSize+"'"
	cCaption += iif(lBold, " FontWeight='Bold'","") 
	cCaption += iif(lItalic," FontStyle='Italic'","")
	if ";" $ aGetListItem[cGETLIST_CAPTION]
		aGetListItem[cGETLIST_CAPTION] := strtran(aGetListItem[cGETLIST_CAPTION],";","<LineBreak/>")
	endif
    cCaption += ">" + aGetListItem[cGETLIST_CAPTION]+"</TextBlock>"
	::enableMarkup := .T. 
	::caption := cCaption
endif
::setColor( aGetListItem )

IF !Empty(aOptions[10])
  ::picture := CJ_Picture(aOptions[10],xtpImageNormal)
ENDIF

IF !Empty(aOptions[9])
	if valtype(aOptions[9]) == "C"
		CJLoadIcon aOptions[9] ID 1 STATE xtpImageNormal PARENT ::globalSettings:icons
		oIcon := ::globalSettings:icons:getImage(1,32)
		::picture := CJ_Picture(oIcon,xtpImageNormal)
	endif
	/*
	if valtype(aOptions[9]) == "N"
		aResFile := DC_BitmapResourceFile()
		FOR i := 1 TO Len(aResFile)
			nHandle := aResFile[i]
			CJLoadIconFromResource aOptions[9] HANDLE nHandle ID 1 STATE xtpImageNormal PARENT ::globalSettings:icons
			oIcon := ::globalSettings:icons:getImage(1,32)
			::picture := CJ_Picture(oIcon,xtpImageNormal)
		next
	endif
	*/
ENDIF

IF !Empty(aOptions[24])
	if valtype(aOptions[24]) == "C"
		CJLoadBitmap aOptions[24] ID 1 STATE xtpImageNormal PARENT ::globalSettings:icons
		oIcon := ::globalSettings:icons:getImage(1,32)
		::picture := CJ_Picture(oIcon,xtpImageNormal)
	endif
	if valtype(aOptions[24]) == "N"
		aResFile := DC_BitmapResourceFile()
		FOR i := 1 TO Len(aResFile)
			nHandle := aResFile[i]
			CJLoadBitmapFromResource aOptions[24] HANDLE nHandle ID 1 STATE xtpImageNormal PARENT ::globalSettings:icons
			oIcon := ::globalSettings:icons:getImage(1,32)
			::picture := CJ_Picture(oIcon,xtpImageNormal)
		next
	endif
ENDIF

::appearance := aOptions[1]

RETURN self

INLINE METHOD Destroy()

::CJ_Parts:destroy()
::DC_XbpActiveXControl:destroy()

ENDCLASS


Re: CJpushButton FONT

Posted: Mon Jan 10, 2011 6:18 pm
by rdonnay
I was just preparing to release build 255.

I will add your changes before I do. Thank you again.