Files
harbour-core/harbour/source/rtl/memoedit.prg
Przemyslaw Czerpak c2a1acc14c 2009-01-05 13:33 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbgtcore.h
  * harbour/source/rtl/hbgtcore.c
    * changed BYTE bClearColor to USHORT uiClearColor


  The following modifications were made by Viktor Szakats,
  (2008-11-22 16:15 UTC+0100 - 2008-12-19 12:56 UTC+0100)
  Many thanks. It's the first part without CP conversions in OS calls which
  I will want to check yet. Please tests MS-Windows only modifications.

  * harbour/make_vc.mak
  * harbour/contrib/mtpl_vc.mak
    + Added support for A_USR.

  * harbour/include/set.ch
  * harbour/include/hbextern.ch
  * harbour/source/vm/cmdarg.c
  * harbour/source/vm/set.c
  * harbour/source/rtl/tgetlist.prg
  * harbour/source/rtl/gete.c
  * harbour/contrib/hbhpdf/harupdf.c
    * formatting

  * harbour/source/rtl/hbffind.c
    * Changed few places to use sizeof() instead of
      explicit size macro.

  * harbour/source/vm/extrap.c
    + Added module listing. (also supports Win64)

  * harbour/source/common/hbver.c
    + Added Intel C compiler detection. (from xhb)
    + Added Wine detection (unofficial but stable looking
      detection method. There intentionally doesn't exist
      an official method to do this detection, yet there
      are cases when this is necessary. It's also essential
      for error reports.)
      See also:
      http://www.mail-archive.com/wine-devel@winehq.org/msg48659.html

  * harbour/source/common/hbfopen.c
    ! Reverted recent change to use fopen_s(). fopen_s()
      will always open in exclusive mode, so it could create
      incompatibilities.

  * harbour/source/codepage/cpbgmik.c
    ! Fixed BGMIK collation encoding. Someone familiar with
      BG CPs please confirm this, but previously it was
      almost certainly broken, as the collation was identical
      to BG866.

  * harbour/source/rtl/diskspac.c
  * harbour/source/rtl/disksphb.c
    ! GetModuleHandleA() -> GetModuleHandle()
    ; NOTE: GetModuleHandleA() WinCE emulation in
            source/common/wince.c might be unnecessary
            after this change.

  * harbour/source/rtl/memoedit.prg
  * harbour/source/rtl/teditor.prg
    ! Cleaned insert handling. It now won't anymore mess up
      the cursor on instantiation (in New() method). Internal
      :lInsert state replaced by Set( _SET_INSERT ). Cursor
      is only touched in the editing loop.

  * harbour/source/rtl/version.c
    ! HB_VERSION( HB_VERSION_BUILD_DATE ): Fixed month
      being off by one.

  * harbour/contrib/hbmzip/hbmzip.c
    ! Fixed typo which caused timestamps stored in .zip files
      to be wrong.

  * harbour/contrib/hbhpdf/tests/harupdf.prg
    ! Minor typo in code.

  * harbour/contrib/rddads/rddads.h
    + Added detection for ACE 9.10.

  * harbour/contrib/hbtip/sendmail.prg
    ! Stricter parameter checking in hb_SendMail().

  * harbour/contrib/examples/dbu/hb_dbu.dif
    + Added SET DATE ANSI and SET CENTURY ON

  * harbour/source/rtl/gtxwc/gtxwc.c
    + Generating HB_K_RESIZE keystrokes on screen resize.
      This way it's working similarly to gtwvt.
    ! Typos in comments.

  * harbour/source/rtl/gtwin/gtwin.c
    ! Fixed HB_GTI_KBDSHIFTS not working in console mode.
      Replaced GetKeyboardState() call with GetKeyState() calls.

  * harbour/source/rtl/gtwvt/gtwvt.c
    + Added 'layered' window support. It's enabled on W2K
      and above (and only when not in Terminal Services
      environment, because it makes it perform worse). This
      way the screen is also properly displayed regardless
      of what the Harbour application does. It also fixes
      numerous paint artifacts, when GTWVT window was in
      the background and another window is moved in front
      of it.
    ! Fixed only generate HB_K_RESIZE keystrokes when
      resize mode is HB_GTI_RESIZEMODE_ROWS.
2009-01-05 12:31:02 +00:00

316 lines
10 KiB
Plaintext

/*
* $Id$
*/
/*
* Harbour Project source code:
* MemoEdit() function
*
* Copyright 2000 Maurilio Longo <maurilio.longo@libero.it>
* www - 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.
*
*/
#include "hbclass.ch"
#include "common.ch"
#include "inkey.ch"
#include "memoedit.ch"
#include "setcurs.ch"
// A specialized HBEditor which can simulate MemoEdit() behaviour
CREATE CLASS HBMemoEditor INHERIT HBEditor
VAR xUserFunction // User Function called to change default MemoEdit() behaviour
METHOD MemoInit( xUserFunction ) // This method is called after ::New() returns to perform ME_INIT actions
METHOD Edit() // Calls super:Edit( nKey ) but is needed to handle configurable keys
METHOD KeyboardHook( nKey ) // Gets called every time there is a key not handled directly by HBEditor
METHOD IdleHook() // Gets called every time there are no more keys to hanlde
METHOD HandleUserKey( nKey, nUserKey ) // Handles keys returned to MemoEdit() by user function
METHOD xDo( nStatus ) // Calls xUserFunction saving and restoring cursor position and shape
METHOD MoveCursor( nKey ) // Redefined to properly managed CTRL-W
ENDCLASS
METHOD MemoInit( xUserFunction ) CLASS HBMemoEditor
LOCAL nKey
// Save/Init object internal representation of user function
::xUserFunction := xUserFunction
IF ISCHARACTER( ::xUserFunction )
// Keep calling user function until it returns ME_DEFAULT
DO WHILE ( nKey := ::xDo( ME_INIT ) ) != ME_DEFAULT
// At this time there is no input from user of MemoEdit() only handling
// of values returned by ::xUserFunction, so I pass these value on both
// parameters of ::HandleUserKey()
::HandleUserKey( nKey, nKey )
ENDDO
ENDIF
RETURN Self
METHOD Edit() CLASS HBMemoEditor
LOCAL nKey
// NOTE: K_ALT_W is not compatible with clipper exit memo and save key, but I cannot discriminate
// K_CTRL_W and K_CTRL_END from harbour code.
LOCAL aConfigurableKeys := { K_CTRL_Y, K_CTRL_T, K_CTRL_B, K_CTRL_V, K_ALT_W, K_ESC }
LOCAL bKeyBlock
// If I have an user function I need to trap configurable keys and ask to
// user function if handle them the standard way or not
IF ::lEditAllow .AND. ISCHARACTER( ::xUserFunction )
DO WHILE ! ::lExitEdit
// I need to test this condition here since I never block inside HBEditor:Edit()
// if there is an user function
IF NextKey() == 0
::IdleHook()
ENDIF
nKey := Inkey( 0 )
IF ( bKeyBlock := SetKey( nKey ) ) != NIL
Eval( bKeyBlock )
LOOP
ENDIF
// Is it a configurable key ?
IF AScan( aConfigurableKeys, nKey ) > 0
::HandleUserKey( nKey, ::xDo( iif( ::lDirty, ME_UNKEYX, ME_UNKEY ) ) )
ELSE
::super:Edit( nKey )
ENDIF
ENDDO
ELSE
// If I can't edit text buffer or there is not a user function enter standard HBEditor
// ::Edit() method which is able to handle everything
::super:Edit()
ENDIF
RETURN Self
// I come here if I have an unknown key and it is not a configurable key
// if there is an user function I leave to it its handling
METHOD KeyboardHook( nKey ) CLASS HBMemoEditor
LOCAL nYesNoKey
LOCAL cBackScr
LOCAL nRow
LOCAL nCol
IF ISCHARACTER( ::xUserFunction )
::HandleUserKey( nKey, ::xDo( iif( ::lDirty, ME_UNKEYX, ME_UNKEY ) ) )
ELSE
IF nKey == K_ESC
IF ::lDirty .AND. Set( _SET_SCOREBOARD )
cBackScr := SaveScreen( ::nTop, ::nRight - 18, ::nTop, ::nRight )
nRow := Row()
nCol := Col()
hb_dispOutAt( ::nTop, ::nRight - 18, "Abort Edit? (Y/N)" )
SetPos( ::nTop, ::nRight - 1 )
nYesNoKey := Inkey( 0 )
RestScreen( ::nTop, ::nRight - 18, ::nTop, ::nRight, cBackScr )
SetPos( nRow, nCol )
IF Upper( Chr( nYesNoKey ) ) == "Y"
::lSaved := .F.
::lExitEdit := .T.
ENDIF
ELSE
::lExitEdit := .T.
ENDIF
ENDIF
ENDIF
RETURN Self
METHOD IdleHook() CLASS HBMemoEditor
IF ISCHARACTER( ::xUserFunction )
::xDo( ME_IDLE )
ENDIF
RETURN Self
METHOD HandleUserKey( nKey, nUserKey ) CLASS HBMemoEditor
// HBEditor does not handle these keys and would call ::KeyboardHook() causing infinite loop
LOCAL aUnHandledKeys := { K_CTRL_J, K_CTRL_K, K_CTRL_L, K_CTRL_N, K_CTRL_O,;
K_CTRL_P, K_CTRL_Q, K_CTRL_T, K_CTRL_U, K_F1 }
DO CASE
// I won't reach this point during ME_INIT since ME_DEFAULT ends initialization phase of MemoEdit()
CASE nUserKey == ME_DEFAULT
// HBEditor is not able to handle keys with a value higher than 256, but I have to tell him
// that user wants to save text
IF ( nKey <= 256 .OR. nKey == K_ALT_W ) .AND. AScan( aUnHandledKeys, nKey ) == 0
::super:Edit( nKey )
ENDIF
// TOFIX: Not clipper compatible, see teditor.prg
CASE ( nUserKey >= 1 .AND. nUserKey <= 31 ) .OR. nUserKey == K_ALT_W
IF AScan( aUnHandledKeys, nUserKey ) == 0
::super:Edit( nUserKey )
ENDIF
CASE nUserKey == ME_DATA
IF nKey <= 256 .AND. AScan( aUnHandledKeys, nKey ) == 0
::super:Edit( nKey )
ENDIF
CASE nUserKey == ME_TOGGLEWRAP
::lWordWrap := !::lWordWrap
CASE nUserKey == ME_TOGGLESCROLL
// TODO: HBEditor does not support vertical scrolling of text inside window without moving cursor position
CASE nUserKey == ME_WORDRIGHT
::MoveCursor( K_CTRL_RIGHT )
CASE nUserKey == ME_BOTTOMRIGHT
::MoveCursor( K_CTRL_END )
#ifdef HB_COMPAT_XPP
CASE nUserKey == ME_PASTE
// TODO
#endif
OTHERWISE
// Do nothing
ENDCASE
RETURN Self
METHOD xDo( nStatus ) CLASS HBMemoEditor
LOCAL nOldRow := ::Row()
LOCAL nOldCol := ::Col()
LOCAL nOldCur := SetCursor()
LOCAL xResult := Do( ::xUserFunction, nStatus, ::nRow, ::nCol - 1 )
IF ! ISNUMBER( xResult )
xResult := ME_DEFAULT
ENDIF
::SetPos( nOldRow, nOldCol )
SetCursor( nOldCur )
RETURN xResult
METHOD MoveCursor( nKey ) CLASS HBMemoEditor
IF nKey == K_CTRL_END // same value as CTRL-W
::lSaved := .T.
::lExitEdit := .T.
ELSE
RETURN ::Super:MoveCursor( nKey )
ENDIF
RETURN .f.
/*----------------------------------------------------------------------------------------*/
FUNCTION MemoEdit( cString,;
nTop,;
nLeft,;
nBottom,;
nRight,;
lEditMode,;
xUserFunction,;
nLineLength,;
nTabSize,;
nTextBuffRow,;
nTextBuffColumn,;
nWindowRow,;
nWindowColumn )
LOCAL oEd
LOCAL nOldCursor
DEFAULT nTop TO 0
DEFAULT nLeft TO 0
DEFAULT nBottom TO MaxRow()
DEFAULT nRight TO MaxCol()
DEFAULT lEditMode TO .T.
DEFAULT nLineLength TO nRight - nLeft
DEFAULT nTabSize TO 4
DEFAULT nTextBuffRow TO 1
DEFAULT nTextBuffColumn TO 0
DEFAULT nWindowRow TO 0
DEFAULT nWindowColumn TO nTextBuffColumn
DEFAULT cString TO ""
// Original MemoEdit() converts Tabs into spaces;
oEd := HBMemoEditor():New( StrTran( cString, Chr( K_TAB ), Space( 1 ) ), nTop, nLeft, nBottom, nRight, lEditMode, nLineLength, nTabSize, nTextBuffRow, nTextBuffColumn, nWindowRow, nWindowColumn )
oEd:MemoInit( xUserFunction )
oEd:display()
IF ! ISLOGICAL( xUserFunction ) .OR. xUserFunction == .T.
nOldCursor := SetCursor( iif( Set( _SET_INSERT ), SC_INSERT, SC_NORMAL ) )
oEd:Edit()
IF oEd:Changed()
cString := oEd:GetText()
// dbu tests for LastKey() == K_CTRL_END, so I try to make it happy
HB_SetLastKey( K_CTRL_END )
ENDIF
SetCursor( nOldCursor )
ENDIF
RETURN cString