2009-07-12 00:01 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com)

* harbour/contrib/hbxbp/Makefile
 * harbour/contrib/hbxbp/xbp.ch
 * harbour/contrib/hbxbp/xbpdialog.prg
 * harbour/contrib/hbxbp/xbpgeneric.prg
 * harbour/contrib/hbxbp/xbpprinter.prg
 + harbour/contrib/hbxbp/xbprtf.prg
   + Implemented XbpRtf() class - the toughest so far.
     Example code lifted from Xbase++ documentaion is working as is
     except for one feature. Still more work is required. I see a 
     possibility of lot more features in this class - later.

 * harbour/contrib/hbxbp/tests/demoxbp.prg
   + Demonstrated the XbpRtf() class implementation.
     Click on <Rtf> tab-page and view the results. Also examine the code.
This commit is contained in:
Pritpal Bedi
2009-07-12 07:06:11 +00:00
parent 224e184791
commit 9bc00dd21d
8 changed files with 842 additions and 48 deletions

View File

@@ -17,6 +17,22 @@
past entries belonging to author(s): Viktor Szakats.
*/
2009-07-12 00:01 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com)
* harbour/contrib/hbxbp/Makefile
* harbour/contrib/hbxbp/xbp.ch
* harbour/contrib/hbxbp/xbpdialog.prg
* harbour/contrib/hbxbp/xbpgeneric.prg
* harbour/contrib/hbxbp/xbpprinter.prg
+ harbour/contrib/hbxbp/xbprtf.prg
+ Implemented XbpRtf() class - the toughest so far.
Example code lifted from Xbase++ documentaion is working as is
except for one feature. Still more work is required. I see a
possibility of lot more features in this class - later.
* harbour/contrib/hbxbp/tests/demoxbp.prg
+ Demonstrated the XbpRtf() class implementation.
Click on <Rtf> tab-page and view the results. Also examine the code.
2009-07-11 11:44 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com)
* harbour/contrib/hbqt/generator/hbqtgen.prg

View File

@@ -67,6 +67,7 @@ PRG_SOURCES=\
xbpfiledialog.prg \
xbpfontdialog.prg \
xbpbitmap.prg \
xbprtf.prg \
xbppresspace.prg \
xbpprinter.prg \
xbpprintdialog.prg \

View File

@@ -67,6 +67,7 @@
#define TAB_3 3
#define TAB_4 4
#define TAB_5 5
#define TAB_6 6
#define CRLF chr( 13 )+chr( 10 )
@@ -162,7 +163,8 @@ PROCEDURE BuildADialog()
/* Build HTML Viewer */
oHtm := Build_HTMLViewer( aTabs[ TAB_1 ] )
/* Build RTF */
Build_Rtf( aTabs[ TAB_6 ] )
/* Present the dialog on the screen */
oDlg:Show()
@@ -221,9 +223,9 @@ STATIC FUNCTION uiXtoS( xVar )
CASE cType == "A"
RETURN "A:"+hb_ntos( len( xVar ) )
CASE cType == "O"
RETURN "<OBJECT>"
RETURN "[OBJECT]"
OTHERWISE
RETURN "<"+cType+">"
RETURN "["+cType+"]"
ENDCASE
RETURN xVar
@@ -233,23 +235,18 @@ STATIC FUNCTION uiXtoS( xVar )
FUNCTION uiDebug( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 )
LOCAL s
s := ' ' + uiXtoS( p1 ) + CRLF
s += ' ' + uiXtoS( p2 ) + CRLF
s += ' ' + uiXtoS( p3 ) + CRLF
s += ' ' + uiXtoS( p4 ) + CRLF
s += ' ' + uiXtoS( p5 ) + CRLF
s += ' ' + uiXtoS( p6 ) + CRLF
s += ' ' + uiXtoS( p7 ) + CRLF
s += ' ' + uiXtoS( p8 ) + CRLF
s += ' ' + uiXtoS( p9 ) + CRLF
s += ' ' + uiXtoS( p10 )
s := uiXtoS( p1 ) + CRLF
s += uiXtoS( p2 ) + CRLF
s += uiXtoS( p3 ) + CRLF
s += uiXtoS( p4 ) + CRLF
s += uiXtoS( p5 ) + CRLF
s += uiXtoS( p6 ) + CRLF
s += uiXtoS( p7 ) + CRLF
s += uiXtoS( p8 ) + CRLF
s += uiXtoS( p9 ) + CRLF
s += uiXtoS( p10 )
#ifdef __XPP__
MsgBox( s )
#else
//MsgBox( s )
hb_outDebug( s )
#endif
RETURN nil
@@ -262,11 +259,7 @@ STATIC FUNCTION PP_Debug( oXbp )
aeval( aPP, {|e_| s += ( hb_ntos( e_[ 1 ] ) +' '+ valtype( e_[ 2 ] ) +' '+ ;
IF( valtype( e_[ 2 ] )=='N', hb_ntos( e_[ 2 ] ), ' ' ) + '; '+ CRLF ) } )
#ifdef __XPP__
MsgBox( s )
#else
hb_outDebug( s )
#endif
RETURN nil
@@ -545,55 +538,62 @@ FUNCTION Build_RadioButton( oStatic )
FUNCTION Build_TabPages( oWnd )
LOCAL nHeight := 390
LOCAL aTabs := { NIL,NIL,NIL,NIL,NIL }
LOCAL aTabs := { NIL,NIL,NIL,NIL,NIL,NIL }
aTabs[ TAB_1 ] := XbpTabPage():new( oWnd, , { 510, 20 }, { 360, nHeight } )
aTabs[ TAB_1 ] := XbpTabPage():new( oWnd, , { 510, 20 }, { 360, nHeight }, , .t. )
aTabs[ TAB_1 ]:caption := "Web"
aTabs[ TAB_1 ]:preOffset := 20
aTabs[ TAB_1 ]:postOffset := 60
// aTabs[ TAB_1 ]:preOffset := 10
// aTabs[ TAB_1 ]:postOffset := 300
aTabs[ TAB_1 ]:minimized := .F.
aTabs[ TAB_1 ]:create()
aTabs[ TAB_1 ]:TabActivate := SetMaximized( aTabs, 1 )
aTabs[ TAB_2 ] := XbpTabPage():new( oWnd, , { 510, 20 }, { 360, nHeight } )
aTabs[ TAB_2 ] := XbpTabPage():new( oWnd, , { 510, 20 }, { 360, nHeight }, , .t. )
aTabs[ TAB_2 ]:caption := "MLE"
aTabs[ TAB_2 ]:preOffset := 40
aTabs[ TAB_2 ]:postOffset := 60
aTabs[ TAB_2 ]:preOffset := 20
aTabs[ TAB_2 ]:postOffset := 120
aTabs[ TAB_2 ]:create()
aTabs[ TAB_2 ]:TabActivate := SetMaximized( aTabs, 1 )
aTabs[ TAB_2 ]:TabActivate := SetMaximized( aTabs, 2 )
aTabs[ TAB_3 ] := XbpTabPage():new( oWnd, , { 510, 20 }, { 360, nHeight } )
aTabs[ TAB_3 ] := XbpTabPage():new( oWnd, , { 510, 20 }, { 360, nHeight }, , .t. )
aTabs[ TAB_3 ]:caption := "Buttons"
aTabs[ TAB_3 ]:preOffset := 60
aTabs[ TAB_3 ]:postOffset := 40
aTabs[ TAB_3 ]:preOffset := 40
aTabs[ TAB_3 ]:postOffset := 100
aTabs[ TAB_3 ]:create()
aTabs[ TAB_3 ]:TabActivate := SetMaximized( aTabs, 3 )
aTabs[ TAB_4 ] := XbpTabPage():new( oWnd, , { 510, 20 }, { 360, nHeight } )
aTabs[ TAB_4 ] := XbpTabPage():new( oWnd, , { 510, 20 }, { 360, nHeight }, , .t. )
aTabs[ TAB_4 ]:caption := "Tree"
aTabs[ TAB_4 ]:preOffset := 80
aTabs[ TAB_4 ]:postOffset := 20
aTabs[ TAB_4 ]:preOffset := 60
aTabs[ TAB_4 ]:postOffset := 80
aTabs[ TAB_4 ]:create()
aTabs[ TAB_4 ]:TabActivate := SetMaximized( aTabs, 4 )
aTabs[ TAB_4 ]:setColorBG( GraMakeRGBColor( {198,198,198} ) )
aTabs[ TAB_5 ] := XbpTabPage():new( oWnd, , { 510, 20 }, { 360, nHeight } )
aTabs[ TAB_5 ]:minimized := .F.
aTabs[ TAB_5 ]:caption := "Lists"
aTabs[ TAB_4 ]:preOffset := 100
aTabs[ TAB_4 ]:postOffset := 20
aTabs[ TAB_5 ] := XbpTabPage():new( oWnd, , { 510, 20 }, { 360, nHeight }, , .t. )
aTabs[ TAB_5 ]:minimized := .F.
aTabs[ TAB_5 ]:caption := "Lists"
aTabs[ TAB_5 ]:preOffset := 80
aTabs[ TAB_5 ]:postOffset := 60
aTabs[ TAB_5 ]:create()
aTabs[ TAB_5 ]:TabActivate := SetMaximized( aTabs, 5 )
aTabs[ TAB_5 ]:setPointer( , XBPSTATIC_SYSICON_SIZENESW, XBPWINDOW_POINTERTYPE_SYSPOINTER )
/* comment our following line to position tabs at the bottom */
/* aTabs[ TAB_5 ]:type := XBPTABPAGE_TAB_BOTTOM */
aTabs[ TAB_6 ] := XbpTabPage():new( oWnd, , { 510, 20 }, { 360, nHeight }, , .t. )
aTabs[ TAB_6 ]:caption := "Rtf"
aTabs[ TAB_6 ]:preOffset := 100
aTabs[ TAB_6 ]:postOffset := 40
aTabs[ TAB_6 ]:create()
aTabs[ TAB_6 ]:TabActivate := SetMaximized( aTabs, 6 )
RETURN aTabs
/*----------------------------------------------------------------------*/
STATIC FUNCTION SetMaximized( aTabs, nMax )
RETURN {|| aeval( aTabs, {|o,i| IF( i == nMax, o:maximize(), o:minimize() ) } ) }
RETURN {|| aeval( aTabs, {|o,i| IF( i != nMax, o:minimize(), ) } ), aTabs[ nMax ]:maximize() }
/*----------------------------------------------------------------------*/
@@ -1075,7 +1075,7 @@ FUNCTION Build_HTMLViewer( oWnd )
oHtm := XbpHTMLViewer():new( oFrm, , {10,10}, {sz_[1]-10-10,sz_[2]-10-10} )
oHtm:create()
oHtm:navigate( "http://www.harbour-project.org" )
oHtm:titleChange := {|e| hb_outDebug( e ) }
oHtm:titleChange := {|e| hb_outDebug( e ) }
// oHtm:progressChange := {|nProg,nMax| hb_outDebug( "Downloaded: "+str( nProg*100/nMax,10,0 ) ) }
RETURN oHtm
@@ -1208,10 +1208,68 @@ FUNCTION Build_PrintDialog( oWnd )
oPrn:setFormSize() , ;
oPrn:setResolution()[1], ;
oPrn:setNumCopies() , ;
oPrn:setPaperBin() )
oPrn:setPaperBin() , ;
oPrn:setColorMode() , ;
oPrn:setDuplexMode() , ;
oPrn:setCollationMode() ;
)
ENDIF
RETURN nil
/*----------------------------------------------------------------------*/
FUNCTION Build_Rtf( oWnd )
LOCAL oRTF
LOCAL sz_:= oWnd:currentSize()
oRTF := XbpRtf():new( oWnd )
oRTF:create( , , { 10,10 }, { sz_[ 1 ]-23, sz_[ 2 ]-50 } )
oRTF:setColorBG( GraMakeRGBColor( {255,255,200} ) )
oRTF:setFontCompoundName( "12.Times" )
oRTF:change := {|| hb_outDebug( "change" ) }
// Assign text to the RTF object's text buffer
oRTF:text := "Text with varying " + Chr(10) +;
"text attributes. Made possible by the " + Chr(10) +;
"XbpRtf edit control." + Chr(10)
//
// Use the selection manipulation methods to
// assign different attributes to the text
//
// Set the selection using abolute character positions
oRTF:SelStart := 5
oRTF:SelLength := 30
oRTF:SelColor := GRA_CLR_BLUE
// Set the selection by selecting a specific word
// in the text
oRTF:SelStart := 0
oRTF:Find( "Made possible" )
oRTF:SelBold := .T.
// Find a specific word and expand the selection
// to include another one
oRTF:SelLength := 0
oRTF:Find( "XbpRtf" )
// oRTF:Span( ".",, .T. ) /* TODO */
oRTF:SelColor := GRA_CLR_RED
oRTF:SelFontName := "Courier New"
oRTF:SelFontSize := 30
oRTF:SelBold := .T.
oRTF:SelItalic := .T.
// oRTF:SelStrikeThru := .T. /* OK */
oRTF:SelUnderline := .T.
oRTF:selAlignment := 2 //XBPRTF_SELALIGN_RIGHT
// Reset the text cursor
//
oRTF:SelStart := Len( oRTF:Text )
RETURN nil
/*----------------------------------------------------------------------*/

View File

@@ -21,6 +21,9 @@
#define HBXBP_EVENT_HANDLED 0
#define HBXBP_EVENT_UNHANDLED 1
#define XBTOQT_FROM_XB 1
#define XBTOQT_FROM_QT 2
/*----------------------------------------------------------------------*/
#define XBP_AUTOSIZE -1
@@ -287,6 +290,21 @@
#define XBPPDLG_MODE_DRIVER 1
#define XBPPDLG_MODE_APPLICATION 2
#define XBP_SCROLLBAR_NONE 0
#define XBP_SCROLLBAR_HORIZ 1
#define XBP_SCROLLBAR_VERT 2
#define XBP_APPEARANCE_FLAT 0
#define XBP_APPEARANCE_3D 1
#define XBPRTF_ALIGN_LEFT 0
#define XBPRTF_ALIGN_RIGHT 1
#define XBPRTF_ALIGN_CENTER 2
#define XBPRTF_MATCH_WHOLEWORD 2
#define XBPRTF_MATCH_CASE 4
#define XBPRTF_MATCH_NOHILIGHT 8
/*----------------------------------------------------------------------*/
#define _XBP_CH

View File

@@ -208,6 +208,8 @@ METHOD XbpDialog:destroy()
::xbpWindow:destroy()
::oWidget:destroy()
RETURN nil
/*----------------------------------------------------------------------*/

View File

@@ -68,6 +68,8 @@
#include "common.ch"
#include "xbp.ch"
#include "gra.ch"
#include "hbqt.ch"
/*----------------------------------------------------------------------*/
@@ -234,6 +236,10 @@ FUNCTION MsgBox( cMsg, cTitle )
DEFAULT cTitle TO " "
cMsg := strtran( cMsg, chr( 13 )+chr( 10 ), "<BR>" )
cMsg := strtran( cMsg, chr( 13 ), "<BR>" )
cMsg := strtran( cMsg, chr( 10 ), "<BR>" )
oMB := QMessageBox():new()
oMB:setText( "<b>"+ cMsg +"</b>" )
oMB:setIcon( QMessageBox_Information )
@@ -310,10 +316,10 @@ FUNCTION RemoveEventLoop( oEventLoop )
#define CRLF chr( 13 )+chr( 10 )
FUNCTION Xbp_Debug( ... )
LOCAL s := CRLF
LOCAL s := ""
LOCAL aP := hb_aParams()
aeval( aP, {|e| s += Xbp_XtoS( e ) + CRLF } )
aeval( aP, {|e| s += Xbp_XtoS( e ) + ' ' } )
hb_outDebug( s )
RETURN nil
@@ -346,3 +352,49 @@ STATIC FUNCTION Xbp_XtoS( xVar )
RETURN xVar
/*----------------------------------------------------------------------*/
FUNCTION ConvertAFact( cMode, nFrom, xValue )
LOCAL n, a_:= {}
cMode := upper( cMode )
DO CASE
CASE cMode == "COLOR"
aadd( a_, { GRA_CLR_WHITE , Qt_white } )
aadd( a_, { GRA_CLR_BLACK , Qt_black } )
aadd( a_, { GRA_CLR_BLUE , Qt_blue } )
aadd( a_, { GRA_CLR_RED , Qt_red } )
aadd( a_, { GRA_CLR_PINK , Qt_magenta } )
aadd( a_, { GRA_CLR_GREEN , Qt_darkGreen } )
aadd( a_, { GRA_CLR_CYAN , Qt_cyan } )
aadd( a_, { GRA_CLR_YELLOW , Qt_yellow } )
aadd( a_, { GRA_CLR_DARKGRAY , Qt_darkGray } )
aadd( a_, { GRA_CLR_DARKBLUE , Qt_darkBlue } )
aadd( a_, { GRA_CLR_DARKRED , Qt_darkRed } )
aadd( a_, { GRA_CLR_DARKPINK , Qt_darkMagenta } )
aadd( a_, { GRA_CLR_DARKGREEN , Qt_darkGreen } )
aadd( a_, { GRA_CLR_DARKCYAN , Qt_darkCyan } )
aadd( a_, { GRA_CLR_BROWN , Qt_darkYellow } )
aadd( a_, { GRA_CLR_PALEGRAY , Qt_lightGray } )
CASE cMode == "RTFVERTICALALIGN"
aadd( a_, { 0, QTextCharFormat_AlignNormal } )
aadd( a_, { 1, QTextCharFormat_AlignSuperScript } )
aadd( a_, { -1, QTextCharFormat_AlignSubScript } )
CASE cMode == "RTFSELALIGNMENT"
aadd( a_, { XBPRTF_ALIGN_LEFT , Qt_AlignLeft } )
aadd( a_, { XBPRTF_ALIGN_RIGHT , Qt_AlignRight } )
aadd( a_, { XBPRTF_ALIGN_CENTER, Qt_AlignCenter } )
CASE cMode == "SOMEOTHER"
ENDCASE
IF ( n := ascan( a_, {|e_| e_[ nFrom ] == xValue } ) ) > 0
RETURN a_[ n, IF( nFrom == 2, 1, 2 ) ]
ENDIF
RETURN xValue
/*----------------------------------------------------------------------*/

View File

@@ -119,6 +119,7 @@ CLASS XbpPrinter
METHOD setPaperBin( nBin )
METHOD setPrintFile( cFileName )
METHOD setResolution( aResolution )
METHOD setupDialog()
METHOD abort()
@@ -213,7 +214,7 @@ METHOD XbpPrinter:paperSize()
/*----------------------------------------------------------------------*/
METHOD XbpPrinter:printerStatus()
LOCAL nStatus := 0
LOCAL nStatus := ::oWidget:printerState()
RETURN nStatus
/*----------------------------------------------------------------------*/
@@ -389,7 +390,8 @@ METHOD XbpPrinter:setFormSize( nFormID )
/*----------------------------------------------------------------------*/
METHOD XbpPrinter:setNumCopies( nNumCopies )
LOCAL nOldNumCopies := ::oWidget:numCopies()
//LOCAL nOldNumCopies := ::oWidget:numCopies()
LOCAL nOldNumCopies := ::getEngineProperty( QPrintEngine_PPK_NumberOfCopies )
IF hb_isNumeric( nNumCopies )
::oWidget:setNumCopies( nNumCopies )
@@ -530,27 +532,42 @@ METHOD XbpPrinter:getEngineProperty( nProperty )
DO CASE
CASE nProperty == QPrintEngine_PPK_CollateCopies
RETURN oVariant:toBool()
CASE nProperty == QPrintEngine_PPK_ColorMode
RETURN oVariant:toInt()
CASE nProperty == QPrintEngine_PPK_Creator
CASE nProperty == QPrintEngine_PPK_Duplex
RETURN oVariant:toInt()
CASE nProperty == QPrintEngine_PPK_DocumentName
RETURN oVariant:toString()
CASE nProperty == QPrintEngine_PPK_FontEmbedding
CASE nProperty == QPrintEngine_PPK_FullPage
RETURN oVariant:toBool()
CASE nProperty == QPrintEngine_PPK_NumberOfCopies
RETURN oVariant:toInt()
CASE nProperty == QPrintEngine_PPK_Orientation
RETURN oVariant:toInt()
CASE nProperty == QPrintEngine_PPK_OutputFileName
RETURN oVariant:toString()
CASE nProperty == QPrintEngine_PPK_PageOrder
RETURN oVariant:toInt()
CASE nProperty == QPrintEngine_PPK_PageRect
CASE nProperty == QPrintEngine_PPK_PageSize
RETURN oVariant:toInt()
CASE nProperty == QPrintEngine_PPK_PaperRect
CASE nProperty == QPrintEngine_PPK_PaperSource
RETURN oVariant:toInt()
CASE nProperty == QPrintEngine_PPK_PaperSources
CASE nProperty == QPrintEngine_PPK_PaperSize
RETURN oVariant:toInt()
CASE nProperty == QPrintEngine_PPK_PrinterName
RETURN oVariant:toString()
CASE nProperty == QPrintEngine_PPK_PrinterProgram
RETURN oVariant:toString()
CASE nProperty == QPrintEngine_PPK_Resolution
RETURN oVariant:toInt()
CASE nProperty == QPrintEngine_PPK_SelectionOption
RETURN oVariant:toInt()
CASE nProperty == QPrintEngine_PPK_SupportedResolutions
CASE nProperty == QPrintEngine_PPK_SuppressSystemPrintStatus
CASE nProperty == QPrintEngine_PPK_WindowsPageSize

View File

@@ -0,0 +1,630 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Source file for the Xbp*Classes
*
* Copyright 2009 Pritpal Bedi <pritpal@vouchcac.com>
* http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*
* EkOnkar
* ( The LORD is ONE )
*
* Xbase++ Compatible XbpRtf Class
*
* Pritpal Bedi <pritpal@vouchcac.com>
* 10Jul2009
*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
#include "hbclass.ch"
#include "common.ch"
#include "xbp.ch"
#include "gra.ch"
#include "appevent.ch"
#include "hbqt.ch"
/*----------------------------------------------------------------------*/
CLASS XbpRtf INHERIT XbpWindow
METHOD init()
METHOD create()
METHOD configure()
METHOD destroy()
METHOD exeBlock()
DATA appearance INIT XBP_APPEARANCE_3D
DATA bulletIndent INIT 0
DATA changed INIT .F.
DATA hideSelection INIT .T.
DATA locked INIT .F.
DATA maxLength INIT 0
DATA popupMenu INIT NIL // XbpMenu
DATA rightMargin INIT 0
DATA scrollbars INIT XBP_SCROLLBAR_HORIZ + XBP_SCROLLBAR_VERT
DATA usePopupMenu INIT .T.
METHOD text SETGET
METHOD textRTF SETGET
METHOD selAlignment SETGET // XBPRTF_ALIGN_LEFT
METHOD selBold SETGET // .F.
METHOD selBullet SETGET // .F.
METHOD selCharOffset SETGET // 0
METHOD selColor SETGET //
METHOD selFontName SETGET // ""
METHOD selFontSize SETGET // 0
METHOD selHangingIndent SETGET // 0
METHOD selIndent SETGET // 0
METHOD selItalic SETGET // .F.
METHOD selLength SETGET // 0
METHOD selRightIndent SETGET // 0
METHOD selStart SETGET // 0
METHOD selStrikeThru SETGET // .F.
METHOD selTabCount SETGET // 0
METHOD selReadOnly SETGET // .F.
METHOD selText SETGET // ""
METHOD selUnderline SETGET // .F.
METHOD loadFile( cFile )
METHOD saveFile( cFile )
METHOD clear()
METHOD copy()
METHOD cut()
METHOD find( cSearchString, nStart, nEnd, nOptions )
METHOD getLineFromChar( nChar )
METHOD getLineStart( nLine )
METHOD undo()
METHOD paste()
METHOD print( oXbpPrinter, lOnlySelection )
METHOD selTabs( nTab, nPos )
METHOD span( cCharacters, bForward, bExclude )
DATA sl_xbeRTF_Change
METHOD change() SETGET
DATA sl_xbeRTF_SelChange
METHOD selChange() SETGET
PROTECTED:
DATA oTextCharFormat INIT QTextCharFormat()
DATA oTextDocument INIT QTextDocument()
DATA oTextCursor INIT QTextCursor()
DATA oCurCursor // ontained by one of :sel*
ENDCLASS
/*----------------------------------------------------------------------*/
METHOD XbpRtf:init( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
::xbpWindow:init( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
::xbpWindow:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible )
::oWidget := QTextEdit():new( ::pParent )
::connect( ::pWidget, "copyAvailable(bool)" , {|o,p| ::exeBlock( 1, p, o ) } )
::connect( ::pWidget, "currentCharFormatChanged(QTextCharFormat)", {|o,p| ::exeBlock( 2, p, o ) } )
::connect( ::pWidget, "cursorPositionChanged()" , {|o,p| ::exeBlock( 3, p, o ) } )
::connect( ::pWidget, "redoAvailable(bool)" , {|o,p| ::exeBlock( 4, p, o ) } )
::connect( ::pWidget, "undoAvailable(available)" , {|o,p| ::exeBlock( 5, p, o ) } )
::connect( ::pWidget, "textChanged()" , {|o,p| ::exeBlock( 6, p, o ) } )
::connect( ::pWidget, "selectionChanged()" , {|o,p| ::exeBlock( 7, p, o ) } )
::setPosAndSize()
IF ::visible
::show()
ENDIF
::oParent:AddChild( SELF )
::oTextDocument:pPtr := ::oWidget:document()
::oTextCursor:pPtr := ::oWidget:textCursor()
::oTextCharFormat:pPtr := ::oTextCursor:charFormat()
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:exeBlock( nEvent, p1 )
HB_SYMBOL_UNUSED( p1 )
DO CASE
CASE nEvent == 1
CASE nEvent == 2
CASE nEvent == 3
CASE nEvent == 4
CASE nEvent == 5
CASE nEvent == 6 /* Xbase++ Implements */
::changed := .t. // .f. only at save
::change()
CASE nEvent == 7 /* Xbase++ Implements */
::selChange()
ENDCASE
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:configure()
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:destroy()
::xbpWindow:destroy()
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:loadFile( cFile )
HB_SYMBOL_UNUSED( cFile )
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:saveFile( cFile )
HB_SYMBOL_UNUSED( cFile )
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:clear()
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:copy()
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:cut()
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:find( cSearchString, nStart, nEnd, nOptions )
LOCAL nPos := 0
HB_SYMBOL_UNUSED( nStart )
HB_SYMBOL_UNUSED( nEnd )
HB_SYMBOL_UNUSED( nOptions )
IF hb_isChar( cSearchString )
::oTextDocument:pPtr := ::oWidget:document()
::oTextCursor:pPtr := ::oTextDocument:find_2( cSearchString )
::oCurCursor := ::oTextCursor
ENDIF
RETURN nPos
/*----------------------------------------------------------------------*/
METHOD XbpRtf:getLineFromChar( nChar )
LOCAL nLine := 0
HB_SYMBOL_UNUSED( nChar )
RETURN nLine
/*----------------------------------------------------------------------*/
METHOD XbpRtf:getLineStart( nLine )
LOCAL nChar := 0
HB_SYMBOL_UNUSED( nLine )
RETURN nChar
/*----------------------------------------------------------------------*/
METHOD XbpRtf:undo()
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:paste()
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:print( oXbpPrinter, lOnlySelection )
HB_SYMBOL_UNUSED( oXbpPrinter )
HB_SYMBOL_UNUSED( lOnlySelection )
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selTabs( nTab, nPos )
HB_SYMBOL_UNUSED( nTab )
HB_SYMBOL_UNUSED( nPos )
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:span( cCharacters, bForward, bExclude )
DEFAULT bForward TO .T.
HB_SYMBOL_UNUSED( cCharacters )
HB_SYMBOL_UNUSED( bForward )
HB_SYMBOL_UNUSED( bExclude )
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:change( ... )
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isBlock( aP[ 1 ] )
::sl_xbeRTF_Change := aP[ 1 ]
ELSEIF hb_isBlock( ::sl_xbeRTF_Change )
asize( aP, 2 )
eval( ::sl_xbeRTF_Change, aP[ 1 ], aP[ 2 ], Self )
ENDIF
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selChange( ... )
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isBlock( aP[ 1 ] )
::sl_xbeRTF_SelChange := aP[ 1 ]
ELSEIF hb_isBlock( ::sl_xbeRTF_SelChange )
asize( aP, 2 )
eval( ::sl_xbeRTF_SelChange, aP[ 1 ], aP[ 2 ], Self )
ENDIF
RETURN Self
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selAlignment( ... ) // XBPRTF_ALIGN_LEFT
LOCAL xRet := XBPRTF_ALIGN_LEFT
LOCAL aP := hb_aParams()
LOCAL oTBFormat
IF len( aP ) >= 1 .and. hb_isNumeric( aP[ 1 ] )
oTBFormat := QTextBlockFormat():configure( ::oCurCursor:blockFormat() )
xRet := oTBFormat:alignment()
oTBFormat:setAlignment( ConvertAFact( "RTFSELALIGNMENT", XBTOQT_FROM_XB, aP[ 1 ] ) )
::oCurCursor:setBlockFormat( QT_PTROF( oTBFormat ) )
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selBold( ... ) // .F.
LOCAL xRet := .f.
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isLogical( aP[ 1 ] )
::oTextCharFormat:pPtr := ::oCurCursor:charFormat()
IF ::oTextCharFormat:isValid()
::oTextCharFormat:setFontWeight( QFont_Bold )
::oCurCursor:setCharFormat( QT_PTROF( ::oTextCharFormat ) )
ENDIF
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selBullet( ... ) // .F.
LOCAL xRet := 0
LOCAL aP := hb_aParams()
// ::bulletIndent
IF len( aP ) >= 1
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selCharOffset( ... ) // 0
LOCAL xRet := 0, nAlign
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isNumeric( aP[ 1 ] )
::oTextCharFormat:pPtr := ::oCurCursor:charFormat()
IF ::oTextCharFormat:isValid()
nAlign := IF( aP[ 1 ] < 0, -1, IF( aP[ 1 ] > 0, 1, 0 ) )
xRet := ::oTextCharFormat:verticalAlignment()
::oTextCharFormat:setVerticalAlignment( ConvertAFact( "RtfVerticalAlign", XBTOQT_FROM_XB, nAlign ) )
::oCurCursor:setCharFormat( QT_PTROF( ::oTextCharFormat ) )
ENDIF
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selColor( ... )
LOCAL xRet := 0
LOCAL oBrush, nColor
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isNumeric( aP[ 1 ] )
::oTextCharFormat:pPtr := ::oCurCursor:charFormat()
IF ::oTextCharFormat:isValid()
xRet := ::oTextCharFormat:foreground()
nColor := ConvertAFact( "COLOR", XBTOQT_FROM_XB, aP[ 1 ] )
oBrush := QBrush():new( "QColor", QT_PTROF( QColor():new( nColor ) ) )
::oTextCharFormat:setForeground( QT_PTROF( oBrush ) )
::oCurCursor:setCharFormat( QT_PTROF( ::oTextCharFormat ) )
ENDIF
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selFontName( ... ) // ""
LOCAL xRet := 0
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isChar( aP[ 1 ] )
::oTextCharFormat:pPtr := ::oCurCursor:charFormat()
IF ::oTextCharFormat:isValid()
xRet := ::oTextCharFormat:fontFamily()
::oTextCharFormat:setFontFamily( aP[ 1 ] )
::oCurCursor:setCharFormat( QT_PTROF( ::oTextCharFormat ) )
ENDIF
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selFontSize( ... ) // 0
LOCAL xRet := 0
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isNumeric( aP[ 1 ] )
::oTextCharFormat:pPtr := ::oCurCursor:charFormat()
IF ::oTextCharFormat:isValid()
xRet := ::oTextCharFormat:fontPointSize()
::oTextCharFormat:setFontPointSize( aP[ 1 ] )
::oCurCursor:setCharFormat( QT_PTROF( ::oTextCharFormat ) )
ENDIF
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selHangingIndent( ... ) // 0
LOCAL xRet := 0
LOCAL aP := hb_aParams()
IF len( aP ) >= 1
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selIndent( ... ) // 0
LOCAL xRet := 0
LOCAL aP := hb_aParams()
IF len( aP ) >= 1
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selItalic( ... ) // .F.
LOCAL xRet := .f.
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isLogical( aP[ 1 ] )
::oTextCharFormat:pPtr := ::oCurCursor:charFormat()
IF ::oTextCharFormat:isValid()
::oTextCharFormat:setFontItalic( aP[ 1 ] )
::oCurCursor:setCharFormat( QT_PTROF( ::oTextCharFormat ) )
ENDIF
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selLength( ... ) // 0
LOCAL xRet := 0
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isNumeric( ap[ 1 ] )
::oCurCursor:movePosition( QTextCursor_NextCharacter, QTextCursor_KeepAnchor, aP[ 1 ] )
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selRightIndent( ... ) // 0
LOCAL xRet := 0
LOCAL aP := hb_aParams()
IF len( aP ) >= 1
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selStart( ... ) // 0
LOCAL xRet := 0
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isNumeric( aP[ 1 ] )
::oTextCursor:pPtr := ::oWidget:textCursor()
::oCurCursor := ::oTextCursor
xRet := ::oCurCursor:position()
::oCurCursor:setPosition( aP[ 1 ] )
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selStrikeThru( ... ) // .F.
LOCAL xRet := .f.
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isLogical( aP[ 1 ] )
::oTextCharFormat:pPtr := ::oCurCursor:charFormat()
IF ::oTextCharFormat:isValid()
::oTextCharFormat:setFontStrikeOut( aP[ 1 ] )
::oCurCursor:setCharFormat( QT_PTROF( ::oTextCharFormat ) )
ENDIF
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selTabCount( ... ) // 0
LOCAL xRet := 0
LOCAL aP := hb_aParams()
IF len( aP ) >= 1
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selReadOnly( ... ) // .F.
LOCAL xRet := .f.
LOCAL aP := hb_aParams()
IF len( aP ) >= 1
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selText( ... ) // ""
LOCAL xRet := ""
LOCAL aP := hb_aParams()
IF len( aP ) >= 1
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:selUnderline( ... ) // .F.
LOCAL xRet := .f.
LOCAL aP := hb_aParams()
IF len( aP ) >= 1 .and. hb_isLogical( aP[ 1 ] )
::oTextCharFormat:pPtr := ::oCurCursor:charFormat()
IF ::oTextCharFormat:isValid()
::oTextCharFormat:setFontUnderline( aP[ 1 ] )
::oCurCursor:setCharFormat( QT_PTROF( ::oTextCharFormat ) )
ENDIF
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:text( ... ) // ""
LOCAL xRet := ::oWidget:toPlainText()
LOCAL aP := hb_aParams()
IF len( aP ) == 1 .and. hb_isChar( aP[ 1 ] )
::oWidget:setPlainText( aP[ 1 ] )
ENDIF
IF len( aP ) >= 1
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/
METHOD XbpRtf:textRTF( ... ) // ""
LOCAL xRet := ::oWidget:toHtml()
LOCAL aP := hb_aParams()
IF len( aP ) == 1 .and. hb_isChar( aP[ 1 ] )
::oWidget:setHtmlText( aP[ 1 ] )
ENDIF
IF len( aP ) >= 1
ENDIF
RETURN xRet
/*----------------------------------------------------------------------*/