home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1996 November
/
VPR9611A.ISO
/
ols
/
win31
/
hmize120
/
hmize120.lzh
/
SOURCE.LZH
/
EDITEDIT.CPP
next >
Wrap
C/C++ Source or Header
|
1994-01-16
|
10KB
|
414 lines
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include "global.h"
#include "editedit.h"
static HANDLE hmemClipboard;
static LPSTR pbText;
static WORD cbText;
static HANDLE hmemWrite;
static LPSTR pbWrite;
static BOOL GetText( BOOL fSelectOne = FALSE ) {
DWORD dw = SendMessage( hwndTarget, EM_GETSEL, 0, 0L );
if( HIWORD(dw) == LOWORD(dw) ) {
if( fSelectOne ) {
SendShiftVKey( VK_RIGHT );
dw = SendMessage( hwndTarget, EM_GETSEL, 0, 0L );
if( HIWORD(dw) == LOWORD(dw) ) return FALSE;
} else {
return FALSE;
}
}
SendMessage( hwndTarget, WM_CUT, 0, 0L );
if( !OpenClipboard( NULL ) ) {
return FALSE;
}
hmemClipboard = GetClipboardData( CF_TEXT );
if( hmemClipboard == NULL ) return FALSE;
cbText = (WORD)GlobalSize( hmemClipboard );
pbText = (LPSTR)GlobalLock( hmemClipboard );
return TRUE;
}
static void EndTextAccess( void ) {
GlobalUnlock( hmemClipboard );
CloseClipboard();
}
static BOOL AllocWrite( WORD cb ) {
hmemWrite = GlobalAlloc( GMEM_MOVEABLE, cb );
if( hmemWrite == NULL ) return FALSE;
pbWrite = GlobalLock( hmemWrite );
if( pbWrite == NULL ) return FALSE;
return TRUE;
}
static BOOL Paste( BOOL fWithSelect = TRUE ) {
if( !OpenClipboard( NULL ) ) return FALSE;
EmptyClipboard();
*pbWrite = '\0';
WORD cb = FP_OFF(pbWrite);
GlobalUnlock( hmemWrite );
SetClipboardData( CF_TEXT, hmemWrite );
CloseClipboard();
SendMessage( hwndTarget, WM_PASTE, 0, 0L );
if( fWithSelect ) {
DWORD dw = SendMessage( hwndTarget, EM_GETSEL, 0, 0L );
SendMessage( hwndTarget, EM_SETSEL, TRUE, MAKELONG( LOWORD(dw) - cb, LOWORD(dw) ) );
}
return TRUE;
}
BOOL ToUpper( void ) {
if( !GetText() ) return FALSE;
if( !AllocWrite( cbText ) ) {
EndTextAccess();
return FALSE;
}
while( *pbText != '\0' ) {
if( (*pbText >= 0x81 && *pbText <= 0x9F)
|| *pbText >= 0xE0 ) {
WORD w = ((WORD)(*pbText) << 8) + pbText[1];
if( w >= 0x8281 && w <= 0x829A ) {
w += 0x8260 - 0x8281;
*pbWrite = HIBYTE(w);
pbWrite[1] = LOBYTE(w);
} else {
*(WORD FAR*)pbWrite = *(WORD FAR*)pbText;
}
pbText += 2;
pbWrite += 2;
} else {
if( *pbText >= 'a' && *pbText <= 'z' ) {
*pbWrite = *pbText - 'a' + 'A';
} else {
*pbWrite = *pbText;
}
pbText ++;
pbWrite ++;
}
}
EndTextAccess();
return Paste();
}
BOOL ToLower( void ) {
if( !GetText() ) return FALSE;
if( !AllocWrite( cbText ) ) {
EndTextAccess();
return FALSE;
}
while( *pbText != '\0' ) {
if( (*pbText >= 0x81 && *pbText <= 0x9F)
|| *pbText >= 0xE0 ) {
WORD w = ((WORD)(*pbText) << 8) + pbText[1];
if( w >= 0x8260 && w <= 0x8279 ) {
w += 0x8281 - 0x8260;
*pbWrite = HIBYTE(w);
pbWrite[1] = LOBYTE(w);
} else {
*(WORD FAR*)pbWrite = *(WORD FAR*)pbText;
}
pbText += 2;
pbWrite += 2;
} else {
if( *pbText >= 'A' && *pbText <= 'Z' ) {
*pbWrite = *pbText - 'A' + 'a';
} else {
*pbWrite = *pbText;
}
pbText ++;
pbWrite ++;
}
}
EndTextAccess();
return Paste();
}
static char szZenkakuEisuu[] =
" !”#$%&’()*+,-./0123456789:;<=>?@"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ[¥]^_`"
"abcdefghijklmnopqrstuvwxyz"
"{|} ̄";
static char szZenkakuKata[] =
"。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソ\タチツテト"
"ナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゛゜";
static char szZenkakuHira[] =
"。「」、・をぁぃぅぇぉゃゅょっーあいうえおかきくけこさしすせそたちつてと"
"なにぬねのはひふへほまみむめもやゆよらりるれろわん゛゜";
static char szKataDakuon[] =
"カガキギクグケゲコゴサザシジスズセゼソゾタダチヂツヅテデトドハバヒビフブヘベホボウヴ";
static char szKataHandaku[] = "ハパヒピフプヘペホポ";
static char szHiraDakuon[] =
"カがキぎクぐケげコごサざシじスずセぜソぞタだチぢツづテでトどハばヒびフぶヘべホぼ";
static char szHiraHandaku[] = "ハぱヒぴフぷヘぺホぽ";
static WORD near ToHankakuLocal( WORD w ) {
char* pch = szZenkakuEisuu;
BYTE b = ' ';
while( *pch != '\0' ) {
if( *pch == HIBYTE(w) && pch[1] == LOBYTE(w) ) {
return b;
}
pch += 2;
b ++;
}
b = 0xA1;
pch = szZenkakuKata;
while( *pch != '\0' ) {
if( *pch == HIBYTE(w) && pch[1] == LOBYTE(w) ) {
return b;
}
pch += 2;
b ++;
}
pch = szKataDakuon;
while( *pch != '\0' ) {
if( pch[1] == HIBYTE(w) && pch[2] == LOBYTE(w) ) {
return (((WORD)pch[0] << 8) + (WORD)0xDE);
}
pch += 3;
}
pch = szKataHandaku;
while( *pch != '\0' ) {
if( pch[1] == HIBYTE(w) && pch[2] == LOBYTE(w) ) {
return (((WORD)pch[0] << 8) + (WORD)0xDF);
}
pch += 3;
}
b = 0xA1;
pch = szZenkakuHira;
while( *pch != '\0' ) {
if( *pch == HIBYTE(w) && pch[1] == LOBYTE(w) ) {
return b;
}
pch += 2;
b ++;
}
pch = szHiraDakuon;
while( *pch != '\0' ) {
if( pch[1] == HIBYTE(w) && pch[2] == LOBYTE(w) ) {
return (((WORD)pch[0] << 8) + (WORD)0xDE);
}
pch += 3;
}
pch = szHiraHandaku;
while( *pch != '\0' ) {
if( pch[1] == HIBYTE(w) && pch[2] == LOBYTE(w) ) {
return (((WORD)pch[0] << 8) + (WORD)0xDF);
}
pch += 3;
}
return w;
}
BOOL ToHankaku( void ) {
if( !GetText() ) return FALSE;
if( !AllocWrite( cbText ) ) {
EndTextAccess();
return FALSE;
}
while( *pbText != '\0' ) {
if( (*pbText >= 0x81 && *pbText <= 0x9F) || *pbText >= 0xE0 ) {
WORD w = ((WORD)*pbText << 8) + (WORD)pbText[1];
w = ToHankakuLocal( w );
if( w <= 0xFF ) {
*pbWrite = (char)w;
pbWrite ++;
} else {
*pbWrite = HIBYTE(w);
pbWrite[1] = LOBYTE(w);
pbWrite += 2;
}
pbText += 2;
} else {
*pbWrite = *pbText;
pbWrite ++;
pbText ++;
}
}
EndTextAccess();
return Paste();
}
static WORD near ToDakuon( BYTE b, char* pch ) {
while( *pch != '\0' ) {
if( pch[0] == b ) {
return ((WORD)pch[1] << 8) + (WORD)pch[2];
}
pch += 3;
}
return 0;
}
static WORD near ToZenkakuHiraLocal( BYTE b ) {
char* pch = NULL;
if( b >= ' ' && b <= '~' ) {
pch = szZenkakuEisuu + (b - ' ') * 2;
} else if( b >= 0xA1 && b <= 0xDF ) {
pch = szZenkakuHira + (b - 0xA1) * 2;
}
if( pch != NULL ) {
return ((WORD)*pch << 8) + pch[1];
}
return b;
}
static WORD near ToZenkakuKataLocal( BYTE b ) {
char* pch = NULL;
if( b >= ' ' && b <= '~' ) {
pch = szZenkakuEisuu + (b - ' ') * 2;
} else if( b >= 0xA1 && b <= 0xDF ) {
pch = szZenkakuKata + (b - 0xA1) * 2;
}
if( pch != NULL ) {
return ((WORD)*pch << 8) + pch[1];
}
return b;
}
BOOL ToZenkakuHira( void ) {
if( !GetText() ) return FALSE;
if( !AllocWrite( cbText * 2 ) ) {
EndTextAccess();
return FALSE;
}
while( *pbText != '\0' ) {
WORD w;
if( (*pbText >= 0x81 && *pbText <= 0x9F) || *pbText >= 0xE0 ) {
w = ((WORD)*pbText << 8) + (WORD)pbText[1];
if( w >= 0x8340 && w <= 0x837E ) {
w = w - 0x8340 + 0x829F;
} else if( w >= 0x8380 && w <= 0x8393 ) {
w = w - 0x8380 + 0x82DE;
}
*pbWrite = HIBYTE(w);
pbWrite[1] = LOBYTE(w);
pbWrite += 2;
pbText += 2;
} else {
w = *pbText;
pbText ++;
if( *pbText == 0xDE ) {
pbText ++;
w = ToDakuon( (char)w, szHiraDakuon );
} else if( *pbText == 0xDF ) {
pbText ++;
w = ToDakuon( (char)w, szHiraHandaku );
}
if( w <= 0xFF ) w = ToZenkakuHiraLocal( (BYTE)w );
if( w > 0xFF ) {
*pbWrite = HIBYTE(w);
pbWrite[1] = LOBYTE(w);
pbWrite += 2;
} else {
*pbWrite = (BYTE)w;
pbWrite ++;
}
}
}
EndTextAccess();
return Paste();
}
BOOL ToZenkakuKata( void ) {
if( !GetText() ) return FALSE;
if( !AllocWrite( cbText * 2 ) ) {
EndTextAccess();
return FALSE;
}
while( *pbText != '\0' ) {
WORD w;
if( (*pbText >= 0x81 && *pbText <= 0x9F) || *pbText >= 0xE0 ) {
w = ((WORD)*pbText << 8) + (WORD)pbText[1];
if( w >= 0x829F && w <= 0x82DD ) {
w = w - 0x829F + 0x8340;
} else if( w >= 0x82DE && w <= 0x82F1 ) {
w = w - 0x82DE + 0x8380;
}
*pbWrite = HIBYTE(w);
pbWrite[1] = LOBYTE(w);
pbWrite += 2;
pbText += 2;
} else {
w = *pbText;
pbText ++;
if( *pbText == 0xDE ) {
pbText ++;
w = ToDakuon( (char)w, szKataDakuon );
} else if( *pbText == 0xDF ) {
pbText ++;
w = ToDakuon( (char)w, szKataHandaku );
}
if( w <= 0xFF ) w = ToZenkakuKataLocal( (BYTE)w );
if( w > 0xFF ) {
*pbWrite = HIBYTE(w);
pbWrite[1] = LOBYTE(w);
pbWrite += 2;
} else {
*pbWrite = (BYTE)w;
pbWrite ++;
}
}
}
EndTextAccess();
return Paste();
}
BOOL CaseChange( void ) {
if( !GetText( TRUE ) ) return FALSE;
if( !AllocWrite( cbText * 2 ) ) {
EndTextAccess();
return FALSE;
}
while( *pbText != '\0' ) {
if( (*pbText >= 0x81 && *pbText <= 0x9F)
|| *pbText >= 0xE0 ) {
WORD w = ((WORD)(*pbText) << 8) + pbText[1];
if( w >= 0x8281 && w <= 0x829A ) {
w += 0x8260 - 0x8281;
*pbWrite = HIBYTE(w);
pbWrite[1] = LOBYTE(w);
} else if( w >= 0x8260 && w <= 0x8279 ) {
w += 0x8281 - 0x8260;
*pbWrite = HIBYTE(w);
pbWrite[1] = LOBYTE(w);
} else {
*(WORD FAR*)pbWrite = *(WORD FAR*)pbText;
}
pbText += 2;
pbWrite += 2;
} else {
if( *pbText >= 'a' && *pbText <= 'z' ) {
*pbWrite = *pbText - 'a' + 'A';
} else if( *pbText >= 'A' && *pbText <= 'Z' ) {
*pbWrite = *pbText - 'A' + 'a';
} else {
*pbWrite = *pbText;
}
pbText ++;
pbWrite ++;
}
}
EndTextAccess();
return Paste( FALSE );
}
BOOL CapsLockForget( int xInput ) {
DWORD dw = SendMessage( hwndTarget, EM_GETSEL, 0, 0L );
if( LOWORD(dw) != HIWORD(dw) ) return FALSE;
if( xInput >= LOWORD(dw) ) return FALSE;
DebugOut( "CapsLockForget processing\x0d\x0a" );
SendMessage( hwndTarget, EM_SETSEL, TRUE, MAKELONG( xInput, LOWORD(dw) ) );
return CaseChange();
}