home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1999 March
/
VPR9903A.BIN
/
APUPDATE
/
VC
/
Tx300d
/
TX300D.LZH
/
OUTLINE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-12
|
65KB
|
2,612 lines
// WZ EDITOR 標準機能 アウトライン
// Copyright 1996 TY
// Thanks y.mikomeさん for title.c
// Shift+Returnで見出しレベルの開閉、
// Shift+Escで本文との行き来ができます。
//2.94 970121 高速オープン対応
//2.99D 970331 TXCMDBASE対応
//{###編集}
#include <windows.h>
#include "dialog.h"
#ifdef __FLAT__
#pragma multidef+
extern "comctl32.dll" {
#include "c:\msvc40\include\commctrl.h"
}
#pragma multidef-
#endif
#export
#define IDD_TITLELIST 19990
#define IDD_TITLEVIEW 19991
#define CON_SELCHANGED (WM_TXUSER + 1)
#endexport
#define IDD_TITLE 1000
#define IDD_LEFT 1003
#define IDD_RIGHT 1004
#define IDD_UP 1005
#define IDD_DOWN 1006
#define IDD_CUT 1007
#define IDD_COPY 1008
#define IDD_COPYLIST 1009
#define IDD_FLUSHLIST 1010
#define IDD_CONFIG 1011
#define IDD_CLOSE 1012
#define IDD_PASTE 1013
#define IDD_EDITLABEL 1014
#define IDD_LABELADD 1015
#define IDD_LABELCHILD 1016
#define IDD_LABELINSERT 1017
#define IDD_LABELNAME 1018
#define IDD_SEARCH 1019
#define IDD_SEARCHNEXT 1020
#define IDD_LEFTWITHSUB 1021 //2.99C 970323 new
#define IDD_RIGHTWITHSUB 1022 //2.99C 970323 new
#export
typedef struct {
BOOL fUndisp; // 表示しない/する
int nest; // ネスト(0:なし)
NPARA npara; // 行番号
mchar szstr[CCHWORD]; // 見出し文字列
} HEADLINE;
#endexport
static void txhSetLast(TX* text,HEADLINE* hl)
{
memset(hl,0,sizeof(HEADLINE));
{
NPARA npara = text->npara;
txSetUndisp(text);
txJumpFileEnd(text);
hl->npara = text->npara;
txJumpPara(text,npara);
txSetDisp(text);
}
}
#define txhAdd(text,hl) txRecordAdd(text->txOutline,hl)
#define txhDel(text,ihl) txRecordDelete(text->txOutline,ihl,1)
#define txhWrite(text,ihl,hl) txRecordWrite(text->txOutline,ihl,hl)
#define txhInsert(text,ihi,hl) {txRecordInsert(text->txOutline,ihi,1);txRecordWrite(text->txOutline,ihi,hl);}
#define txhGetCount(text) txRecordGetCount(text->txOutline)
static BOOL txhRead(TX* text,TXRECORD ihl,HEADLINE* hl)
{
TXRECORD n = txRecordGetCount(text->txOutline);
if (ihl < n) {
return txRecordRead(text->txOutline,ihl,hl);
}
// EOF
txhSetLast(text,hl);
return TRUE;
}
static void txhInit(TX* text)
{
if (text->txOutline == NULL) {
text->txOutline = malloc(sizeof(TX));
txInitText(text->txOutline);
txOpenTextBinary(text->txOutline,NULL,sizeof(HEADLINE),0);
if (text->fFrame) text->fReport++;
}
}
static void txhTerm(TX* text)
{
if (text->txOutline) {
txClose(text->txOutline);
free(text->txOutline);
text->txOutline = NULL;
if (text->fFrame) text->fReport--;
}
}
static void txhReset(TX* text)
{
txhTerm(text);
txhInit(text);
}
static int _nestDispMax = 6;
#define WINDOW_V 0 // 縦割り
#define WINDOW_H 1 // 横割り
#define WINDOW_HV 2 // 浮動
permanent int p_modeWindow = WINDOW_V; //2.99D 970330 旧modeWindow
permanent BOOL fSmallFont = FALSE;
permanent int lcxTitleListV = 30;
permanent int lcyTitleListH = 10;
permanent int lcxTitleList = 60;
permanent int lcyTitleList = 10;
permanent BOOL fExtendTextWindow = TRUE;
static BOOL _fFlushWindow;
static BOOL _fModeress = TRUE;
static TXRECORD txrecordFromNpara(TX* text,NPARA npara)
{
TXRECORD n = txRecordGetCount(text->txOutline);
TXRECORD i;
for (i = 0;i < n;i++) {
HEADLINE hl;
txRecordRead(text->txOutline,i,&hl);
if (npara == hl.npara) return i;
if (npara < hl.npara) return i - 1;
}
if (n == 0) return TXRECORD_ERROR;
return n - 1;
}
static int ilistFromTxrecord(TX* text,TXRECORD irecord)
{
if (irecord == TXRECORD_ERROR) return LB_ERR;
TXRECORD i;
int j = -1;
for (i = 0;i <= irecord;i++) {
HEADLINE hl;
txRecordRead(text->txOutline,i,&hl);
if (!hl.fUndisp && hl.nest < _nestDispMax + 2) {
j++;
}
}
return j;
}
static TXRECORD ilistToTxrecord(TX* text,int ilist)
{
TXRECORD i;
int j = -1;
for (i = 0;j < ilist;i++) {
HEADLINE hl;
txRecordRead(text->txOutline,i,&hl);
if (!hl.fUndisp && hl.nest < _nestDispMax + 2) {
j++;
}
}
return i - 1;
}
static TXHIGH BOOL JumpPara(TX* text,NPARA npara)
{
txJumpFileTop(text);
while(1) {
if (text->npara == npara) return TRUE;
if (!txNextPara(text)) break;
}
return FALSE;
}
static void tlFromHl(CHOOSEOUTLINE* context)
{
TX* text = context->text;
if (context->fUndisp) return;
HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
TXRECORD n = txRecordGetCount(text->txOutline);
TXRECORD i;
if (context->textTree) {//2.90
TX* text = context->textTree;
int nest0 = 0;
txDeleteText(text);
for (i = 0;i < n;i++) {
HEADLINE hl;
txhRead(context->text,i,&hl);
#if 0
//
if (hl.nest >= nest0 + 2) {
int n = hl.nest - nest0 - 1;
int nest = nest0+1;
while(n--) {
txInsertChar(text,nest + '0');
txInsert(text,"(見出しなし)");
txInsertChar(text,0);
txInsertChar(text,'1'); // fNotExistTitle
txInsertReturn(text);
nest++;
}
}
#endif
//
txInsertChar(text,hl.nest + '0');
txInsert(text,hl.szstr);
txInsertChar(text,0);
txInsertChar(text,'0'); // fNotExistTitle
txInsertReturn(text);
//
nest0 = hl.nest;
}
dialogWriteItem(dialogFromHwnd(context->hwnd),IDD_TITLELIST);
} else {
SendMessage(hctrl,LB_RESETCONTENT,0,0);
for (i = 0;i < n;i++) {
HEADLINE hl;
txhRead(text,i,&hl);
if (!hl.fUndisp && hl.nest < _nestDispMax + 2) {
mchar buff[CCHLINE];
int l;
if (context->modeWindow == WINDOW_V) {
l = (hl.nest - 1) * 1;
} else {
l = (hl.nest - 1) * 4;
}
memset(buff,' ',l);
if (!context->fNoTitleHead) {
HEADLINE hl1;
txhRead(text,i+1,&hl1);
strcpy(buff + l,"・");l += 2;
if (hl1.fUndisp) {
buff[l++] = '+';
}
}
strcpymax(buff + l,hl.szstr,CCHLINE - l);
SendMessage(hctrl,LB_ADDSTRING,0,(LPARAM)buff);
}
}
}
}
static TXRECORD tlGetNow(CHOOSEOUTLINE* context)
{
HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
if (context->textTree) {//2.90
#ifdef __FLAT__
TV_ITEM tvi;
structClear(tvi);
if (context->fDragging) {
tvi.hItem = context->hDragItem;
} else {
tvi.hItem = TreeView_GetSelection(hctrl);
}
TreeView_GetItem(hctrl,&tvi);
if (tvi.lParam > 0) {
return tvi.lParam - 1;
}
#endif
} else {
int i = SendMessage(hctrl,LB_GETCURSEL,0,0);
if (i != LB_ERR) {
#if 1
return ilistToTxrecord(context->text,i);
#else
return i;
#endif
}
}
return TXRECORD_ERROR;
}
#ifdef __FLAT__
static TXRECORD tvhGetParam(HWND hctrl,HTREEITEM h)
{
if (h) {
TV_ITEM tvi;
structClear(tvi);
tvi.hItem = h;
TreeView_GetItem(hctrl,&tvi);
if ((long)tvi.lParam < 0) {
return -tvi.lParam - 1;
} else {
return tvi.lParam - 1;
}
}
return TXRECORD_ERROR;
}
static int treeviewGetNest(HWND hctrl,HTREEITEM h)
{
int nest = 0;
while(1) {
h = TreeView_GetParent(hctrl,h);
if (!h) break;
nest++;
}
return nest;
}
static TXRECORD tlGetNowEx(CHOOSEOUTLINE* context)
{
TXRECORD i = tlGetNow(context);
if (i != TXRECORD_ERROR) return i;
HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
if (context->textTree) {
return tvhGetParam(hctrl,TreeView_GetSelection(hctrl));
}
return TXRECORD_ERROR;
}
#endif
static void FlushLeftRight(CHOOSEOUTLINE* context);
static void tlSetNow(CHOOSEOUTLINE* context,TXRECORD i)
{
TX* text = context->text;
HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
if (context->textTree) {//2.90
#ifdef __FLAT__
if (context->fUndisp) return;
int lParam = i + 1;
// まず、カレントが一致するか調べる
HTREEITEM h;
TV_ITEM tvi;
structClear(tvi);
tvi.hItem = h = TreeView_GetSelection(hctrl);
TreeView_GetItem(hctrl,&tvi);
if (tvi.lParam != lParam) {
h = treeviewSearchParam(hctrl,lParam);
}
if (h) {
TreeView_SelectItem(hctrl,h);
}
#endif
} else {
SendMessage(hctrl,LB_SETCURSEL,ilistFromTxrecord(text,i),0);
}
FlushLeftRight(context);//1.99A
}
static BOOL tlIsEditable(CHOOSEOUTLINE* context)
{
//2.99D 970331 アウトラインの情報が古いとアウトラインのツリーで入れ替えなどをおこなうと
// 思わぬ編集結果を招く危険があるので、チェックするようにした
if (!context->fOutlineStd) return TRUE;//3.00B1 970612 慣用句の挿入で、編集してOKすると「アウトラインを再作成してから実行してください」と表示された
if (context->nEdit == context->text->nEdit) return TRUE;
information("アウトラインを再作成してから実行してください");
return FALSE;
}
static void tlSetEditable(CHOOSEOUTLINE* context)
{
//2.99D 970331
context->nEdit = context->text->nEdit;
}
static int tlMakePrim(CHOOSEOUTLINE* context)
{
TX* text = context->text;
int ret = 0;
txhReset(text);
txSetUndispEx(text);
txJumpFileTop(text);
txSetHigh(text);
{
txstr szline;
PARAATR paraatr;
while(1) {
INT lch;
int lchTop = txParaatrRead(text,¶atr,&lch);
if (paraatr.modeTitle) {
txGetPara(text,szline);
mchar* psz = &szline[lchTop];
HEADLINE hl;
memset(&hl,0,sizeof(HEADLINE));
hl.npara = text->npara;
hl.nest = paraatr.modeTitle;
if (lch == -1) {
strcpymax(hl.szstr,psz,CCHWORD);
} else {
strcpylenmax(hl.szstr,psz,lch,CCHWORD);
}
txhAdd(text,&hl);
}
if (!txNextPara(text)) break;
}
}
txJumpFileTop(text);
txResetHigh(text);
txSetDispEx(text);
context->nEdit = text->nEdit;//2.99D 970331
return ret;
}
static int tlMake(CHOOSEOUTLINE* context)
{
TX* text = context->text;
int ret = tlMakePrim(context);
if (!context->fUndisp) {
tlFromHl(context);
tlSetNow(context,txrecordFromNpara(text,text->npara));
}
return ret;
}
static mchar* GetTitleString(TX* text,int modeTitle)
{
if (1 <= modeTitle) {
if (modeTitle <= SZTITLE_N) {
return text->tsztitle[modeTitle - 1];
}
if (modeTitle <= HEAD_N) {
return text->tszformat[modeTitle - SZTITLE_N - 1 + SZFORMAT_TITLE4];
}
}
return NULL;
}
static void myEnableWindow(HWND hwnd,BOOL f)
{
if (hwnd) EnableWindow(hwnd,f);
}
static void FlushLeftRight(CHOOSEOUTLINE* context)
{
TX* text = context->text;
TXRECORD i = tlGetNow(context);
if (i != TXRECORD_ERROR) {
HEADLINE hl;
txhRead(text,i,&hl);
//
mchar* sztitle = GetTitleString(text,hl.nest);
BOOL fEnable = !(sztitle && sztitle[0] == '^'); // 正規表現でなければ...
myEnableWindow(GetDlgItem(context->hwnd,IDD_LEFT),fEnable);
myEnableWindow(GetDlgItem(context->hwnd,IDD_RIGHT),fEnable);
}
}
static BOOL tlJump(CHOOSEOUTLINE* context)
{
TX* text = context->text;
TXRECORD i = tlGetNow(context);
if (i != TXRECORD_ERROR) {
HEADLINE hl;
txhRead(text,i,&hl);
#if 1//1.99A 使いやすく
text->fUndisp++;//2.95 970129 txSetUndisp(text);から変更。マウスがチラチラする
if (text->hwndtext2) {
//2.95 970129 新多重化対応 SetFocusしてあげないと、txJumpParaによる位置変更が効かない
HWND hwnd = SetFocus(text->hwndtext);
txJumpPara(text,hl.npara);
txSetLy(text,1);
SetFocus(hwnd);
} else {
txJumpPara(text,hl.npara);
txSetLy(text,1);
}
txSetDisp(text);
#else
txJumpPara(text,hl.npara);
#endif
FlushLeftRight(context);//1.99A
return TRUE;
}
return FALSE;
}
static TXRECORD txhGetPrev(tx* text,TXRECORD ihl,HEADLINE* hl,HEADLINE* _hl0)
{
int nest = hl->nest;
while(ihl > 0) {
HEADLINE hl0;
ihl--;
txhRead(text,ihl,&hl0);
if (hl0.nest <= nest) {
*_hl0 = hl0;
return ihl;
}
}
return TXRECORD_ERROR;
}
static TXRECORD txhGetNext(TX* text,TXRECORD ihl,HEADLINE* hl,HEADLINE* _hl1)
{
TXRECORD n = txRecordGetCount(text->txOutline);
int nest = hl->nest;
while(ihl + 1 < n) {
HEADLINE hl1;
ihl++;
txhRead(text,ihl,&hl1);
if (hl1.nest <= nest) {
*_hl1 = hl1;
return ihl;
}
}
txhSetLast(text,_hl1);
return n;
}
static void hlExchange(TX* text,TXRECORD i0,TXRECORD i,TXRECORD i1,HEADLINE* hl0,HEADLINE* hl,HEADLINE* hl1)
{
NPARA nparaD = hl->npara - hl0->npara;
TXRECORD j = i0;
TXRECORD ii;
for (ii = i;ii < i1;ii++,j++) {
HEADLINE hl;
txhRead(text,ii,&hl);
txhDel(text,ii);
txRecordInsert(text->txOutline,j,1);
hl.npara -= nparaD;
txhWrite(text,j,&hl);
}
{
NPARA nparaD = hl1->npara - hl->npara;
for (ii = i0 + (i1 - i);ii < i1;ii++) {
HEADLINE hl;
txhRead(text,ii,&hl);
hl.npara += nparaD;
txhWrite(text,ii,&hl);
}
}
}
static BOOL tlUp(CHOOSEOUTLINE* context)
{
if (!tlIsEditable(context)) return FALSE;//2.99D 970331
TX* text = context->text;
TXRECORD i = tlGetNow(context);
if (i != TXRECORD_ERROR && i > 0) {
TXRECORD i0 = i;
txSetUndisp(text);
do {
HEADLINE hl;
HEADLINE hl0;
HEADLINE hl1;
TXRECORD i1;
//
txhRead(text,i,&hl);
i0 = txhGetPrev(text,i,&hl,&hl0);
if (i0 == TXRECORD_ERROR) {
i0 = i;
break;
}
i1 = txhGetNext(text,i,&hl,&hl1);
//
txJumpPara(text,hl.npara);
txSelectEx(text,CLIP_PARA);
txJumpPara(text,hl1.npara);
txSelectTsPushDelete(text);
//
txJumpPara(text,hl0.npara);
txTsPop(text);
//
hlExchange(text,i0,i,i1,&hl0,&hl,&hl1);
//
tlFromHl(context);
} while(0);
txSetDisp(text);
tlSetNow(context,i0);
tlSetEditable(context);//2.99D 970331
return TRUE;
}
return FALSE;
}
static BOOL tlDown(CHOOSEOUTLINE* context)
{
if (!tlIsEditable(context)) return FALSE;//2.99D 970331
TX* text = context->text;
TXRECORD i = tlGetNow(context);
TXRECORD n = txRecordGetCount(text->txOutline);
if (i != TXRECORD_ERROR && i + 1 < n) {
TXRECORD i1 = i;
txSetUndisp(text);
{
HEADLINE hl;
HEADLINE hl1;
HEADLINE hl2;
TXRECORD i2;
//
txhRead(text,i,&hl);
i1 = txhGetNext(text,i,&hl,&hl1);
i2 = txhGetNext(text,i1,&hl,&hl2);
//
txJumpPara(text,hl.npara);
txSelectEx(text,CLIP_PARA);
txJumpPara(text,hl1.npara);
txSelectTsPushDelete(text);
//
NPARA nparaDst = hl2.npara - (hl1.npara - hl.npara);
txJumpPara(text,nparaDst);
txTsPop(text);
//
hlExchange(text,i,i1,i2,&hl,&hl1,&hl2);
//
tlFromHl(context);
i1 = i + i2 - i1;
}
txSetDisp(text);
tlSetNow(context,i1);
tlSetEditable(context);//2.99D 970331
return TRUE;
}
return FALSE;
}
static BOOL tlCut(CHOOSEOUTLINE* context,BOOL fCut)
{
// fCut=0: Copy
// fCut=1: CopyDelete
// fCut=2: Delete
// fCut=3: Copy
// else hctrl
if (!tlIsEditable(context)) return FALSE;//2.99D 970331
TX* text = context->text;
TXRECORD i = tlGetNow(context);
if (i != TXRECORD_ERROR) {
txSetUndisp(text);
{
HEADLINE hl;
txhRead(text,i,&hl);
HEADLINE hl1;
int i1 = txhGetNext(text,i,&hl,&hl1);
//
txJumpPara(text,hl.npara);
if (fCut >= 4) {
HWND hctrl = (HWND)fCut;
SendMessage(hctrl,LB_RESETCONTENT,0,0);
NPARA npara;
txstr szstr;
txstr szstr2;
//information("%d %d",hl.npara, hl1.npara);
for (npara = hl.npara;npara < hl1.npara;npara++) {
txGetPara(text,szstr);
reReplace(szstr2,CCHWORD,szstr,\"\t",\" ",SEARCH_ALL);
SendMessage(hctrl,LB_ADDSTRING,0,(LPARAM)(mchar*)szstr2);
txNextPara(text);
}
} else {
txSelectEx(text,CLIP_PARA);
txJumpPara(text,hl1.npara);
if (fCut == 3) {//2.92
txSelectCopyQuit(text);
txJumpPara(text,hl.npara);
if (hl.npara + 1 == hl1.npara) {
// 本文が空の場合は、見出しを本文としてCopy
TX _text;
TX* text = &_text;
txInit(text,NULL);
txPaste(text);
txInsert(text,hl.szstr);
txInsertReturn(text);
txJumpFileTop(text);
txSelectEx(text,CLIP_PARA);
txJumpFileEnd(text);
txSelectCopyQuit(text);
txClose(text);
}
} else if (fCut) {
if (fCut == 2) {
txSelectDelete(text);
} else {
txSelectCopyDelete(text);
}
//
{
NPARA nparaD = hl1.npara - hl.npara;
txRecordDelete(text->txOutline,i,i1 - i);
//
TXRECORD n = txRecordGetCount(text->txOutline);
int ii;
for (ii = i;ii < n;ii++) {
txhRead(text,ii,&hl);
hl.npara -= nparaD;
txhWrite(text,ii,&hl);
}
}
} else {
txSelectCopyQuit(text);
txJumpPara(text,hl.npara);
}
}
}
txSetDisp(text);
if (fCut == 1) {
// カット時のみ実行
// 置換リストなどでちらついた
tlFromHl(context);
tlSetNow(context,txrecordFromNpara(text,text->npara));
}
tlSetEditable(context);//2.99D 970331
return TRUE;
}
return FALSE;
}
static BOOL tlPaste(CHOOSEOUTLINE* context)
{
if (!tlIsEditable(context)) return FALSE;//2.99D 970331
TX* text = context->text;
TXRECORD i = tlGetNow(context);
if (i != TXRECORD_ERROR) {
txSetUndisp(text);
{
HEADLINE hl;
txhRead(text,i,&hl);
txJumpPara(text,hl.npara);
txPaste(text);
txJumpPara(text,hl.npara);
}
txSetDisp(text);
tlSetEditable(context);//2.99D 970331
return TRUE;
}
return FALSE;
}
static BOOL tlMove(TX* text,TXRECORD ii,BOOL fLeft,BOOL fExec)
{
//2.99C 970323 new
HEADLINE hl;
BOOL f = FALSE;
txhRead(text,ii,&hl);
txJumpPara(text,hl.npara);
//
PARAATR paraatr;
txParaatrRead(text,¶atr,NULL);
if (fLeft) {
if (paraatr.modeTitle >= 2) {
f = TRUE;
paraatr.modeTitle = paraatr.modeTitle - 1;
hl.nest--;
}
} else {
if (paraatr.modeTitle < 6) {
f = TRUE;
paraatr.modeTitle = paraatr.modeTitle + 1;
hl.nest++;
}
}
if (f && fExec) {
txParaatrWrite(text,¶atr);
txhWrite(text,ii,&hl);
}
return f;
}
static BOOL _tlLeft(CHOOSEOUTLINE* context,BOOL fLeft,BOOL fMoveSub)
{
//2.99C 970323 fMoveSub:子も移動
if (!tlIsEditable(context)) return FALSE;//2.99D 970331
TX* text = context->text;
TXRECORD i = tlGetNow(context);
if (i != TXRECORD_ERROR) {
BOOL fEdit = FALSE;
HEADLINE hl;
txhRead(text,i,&hl);
//
HEADLINE hl1;
TXRECORD i1;
i1 = txhGetNext(text,i,&hl,&hl1);
//
txSetUndisp(text);
#if 1//2.99C 970323
BOOL fOK = TRUE;
if (fMoveSub) {
// 最初に実行できるかどうかチェックする
for (TXRECORD ii = i;ii < i1;ii++) {
if (!tlMove(text,ii,fLeft,FALSE)) {
fOK = FALSE;
break;
}
}
} else {
i1 = i + 1;
if (!tlMove(text,i,fLeft,FALSE)) fOK = FALSE;
}
if (fOK) {
fEdit = TRUE;
for (TXRECORD ii = i;ii < i1;ii++) {
tlMove(text,ii,fLeft,TRUE);
}
} else {
information("これ以上見出しレベルを動かせません");
}
#else
TXRECORD ii = i;
// for (ii = i;ii < i1;ii++) {// 複数項目まとめるのはあまりうまくいかない
BOOL f = FALSE;
txhRead(text,ii,&hl);
txJumpPara(text,hl.npara);
//
PARAATR paraatr;
txParaatrRead(text,¶atr,NULL);
if (fLeft) {
if (paraatr.modeTitle >= 2) {
f = TRUE;
paraatr.modeTitle = paraatr.modeTitle - 1;
hl.nest--;
}
} else {
if (paraatr.modeTitle < 6) {
f = TRUE;
paraatr.modeTitle = paraatr.modeTitle + 1;
hl.nest++;
}
}
if (f) {
fEdit = TRUE;
txParaatrWrite(text,¶atr);
txhWrite(text,ii,&hl);
}
// }
#endif
txSetDisp(text);
if (fEdit) {
tlFromHl(context);
tlSetNow(context,i);
}
tlSetEditable(context);//2.99D 970331
return TRUE;
}
return FALSE;
}
static BOOL tlLeft(CHOOSEOUTLINE* context)
{
return _tlLeft(context,TRUE,FALSE);
}
static BOOL tlRight(CHOOSEOUTLINE* context)
{
return _tlLeft(context,FALSE,FALSE);
}
static BOOL tlLeftWithSub(CHOOSEOUTLINE* context)
{
//2.99C 970323 new
return _tlLeft(context,TRUE,TRUE);
}
static BOOL tlRightWithSub(CHOOSEOUTLINE* context)
{
//2.99C 970323 new
return _tlLeft(context,FALSE,TRUE);
}
permanent int x,y;//ウィンドウ位置を覚える
permanent BOOL fWindowPos;
static BOOL _fNoTxReport;
static void close(TX* text,HWND hwnd,BOOL fClose)
{
text->fOutline = FALSE;//1.99C
if (text->outlineContext->modeWindow != WINDOW_HV) {
_fFlushWindow = TRUE;
PostMessage(text->hwndbase,WM_TXFLUSHWINDOWSIZE,0,0);
SetFocus(text->hwndtext);
}
if (fClose) {
SendMessage(hwnd,WM_CLOSE,0,0);
} else {
PostMessage(hwnd,WM_CLOSE,0,0);
}
}
static void tlFlushListview(CHOOSEOUTLINE* context)
{
tlCut(context,(BOOL)GetDlgItem(context->hwnd,IDD_TITLEVIEW));
SendMessage(context->hwnd,CON_SELCHANGED,0,0);
}
static void tlOpenClose(CHOOSEOUTLINE* context)
{
TX* text = context->text;
HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
int itop = SendMessage(hctrl,LB_GETTOPINDEX,0,0);
int isel = SendMessage(hctrl,LB_GETCURSEL,0,0);
TXRECORD i = tlGetNow(context);
if (i != TXRECORD_ERROR) {
int i0 = i;
HEADLINE hl0;
txhRead(text,i,&hl0);
//
HEADLINE hl;
txhRead(text,i+1,&hl);
BOOL fUndisp = !hl.fUndisp;
//
TXRECORD n = txRecordGetCount(text->txOutline);
for (i++;i < n;i++) {
HEADLINE hl;
txhRead(text,i,&hl);
if (hl.nest <= hl0.nest) break;
hl.fUndisp = fUndisp;
txhWrite(text,i,&hl);
}
//
tlFromHl(context);
// これでも駄目みたい
SendMessage(hctrl,LB_SETTOPINDEX,itop,0);
SendMessage(hctrl,LB_SETCURSEL,isel,0);
/// tlSetNow(text,context,i0);
}
}
static BOOL ExtendWindow(TX* text,HWND hwnd,RECT* rClose)
{
text->cxOutline = 0;//2.00E5
if (text->outlineContext->modeWindow == WINDOW_V && fExtendTextWindow) {
RECT r;
GetWindowRect(text->hwndbase,&r);
RECT r2;
if (rClose) {
r2.right = -rClose->right;
} else {
GetClientRect(hwnd,&r2);
text->cxOutline = r2.right;//2.00E5
}
int cx = r.right - r.left + r2.right;
int cy = r.bottom - r.top;
MoveWindow(text->hwndbase,r.left,r.top,cx,cy,TRUE);
return TRUE;
} else {
if (rClose) {
//2.00B "縦割り時に変化しない"をオフにするとアウトラインウィンドウを閉じても画面表示に反映されなかった
SendMessage(text->hwndbase,WM_TXFLUSHWINDOWSIZE,0,0);
}
return FALSE;
}
}
static void _outlineClose(TX* text,BOOL fClosed)
{
//2.99D 970330 new
if (text->hwndOutline) {
HWND hwnd = text->hwndOutline;
if (!text->fDestorying && text->fOpen/*2.99D*/) {
SetFocus(text->hwndtext);//2.00B
}
RECT r2;
GetClientRect(hwnd,&r2);
if (fClosed) {
dialogUnlink(hwnd);
} else {
// DestroyWindowはdialogFreeがしてくれる。
dialogFree(hwnd);// これしないとそのうち開かなくなっちゃう
}
text->hwndOutline = NULL;
#if 1//2.99D 970330
text->fOutline = FALSE;
#else
if (!text->fDestorying) {
//2.94 970121 破棄中は、fOutlineを変更しない。forプロファイルセーブ
text->fOutline = FALSE;//1.99C
}
#endif
#if 0 //2.99D 970330 位置移動
{
CHOOSEOUTLINE* oc = text->outlineContext;
if (oc) {
if (oc->textTree) {//2.90
txClose(oc->textTree);
oc->textTree = NULL;
}
free(oc);
text->outlineContext = NULL;
}
}
#endif
//
if (text->fDestorying && text->fOpen/*2.99D*/) {
//2.99D 970330 for DEBUGWIN err
} else {
ExtendWindow(text,hwnd,&r2);
}
//2.99D 970330 last
{
CHOOSEOUTLINE* oc = text->outlineContext;
if (oc) {
if (oc->textTree) {//2.90
txClose(oc->textTree);
oc->textTree = NULL;
}
free(oc);
text->outlineContext = NULL;
}
}
}
}
static void outlineClosed(TX* text)
{
//2.99D 970330 new for DEBUGWIN err
_outlineClose(text,TRUE);
}
static void outlineClose(TX* text)
{
#if 1//2.99D 970330
_outlineClose(text,FALSE);
#else
if (text->hwndOutline) {
HWND hwnd = text->hwndOutline;
if (!text->fDestorying) {
SetFocus(text->hwndtext);//2.00B
}
RECT r2;
GetClientRect(hwnd,&r2);
//
DestroyWindow(hwnd);
dialogFree(hwnd);//1.95 これしないとそのうち開かなくなっちゃう
text->hwndOutline = NULL;
if (!text->fDestorying) {
//2.94 970121 破棄中は、fOutlineを変更しない。forプロファイルセーブ
text->fOutline = FALSE;//1.99C
}
//
{
CHOOSEOUTLINE* oc = text->outlineContext;
if (oc) {
if (oc->textTree) {//2.90
txClose(oc->textTree);
oc->textTree = NULL;
}
free(oc);
text->outlineContext = NULL;
}
}
//
ExtendWindow(text,hwnd,&r2);
}
#endif
}
#ifdef __FLAT__
static void BeginDrag(CHOOSEOUTLINE* context,NM_TREEVIEW* tvn)
{
HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
HIMAGELIST hDragImage = TreeView_CreateDragImage(hctrl,tvn->itemNew.hItem);
RECT rcItem;
TreeView_GetItemRect(hctrl,tvn->itemNew.hItem,&rcItem,TRUE);
ImageList_BeginDrag(hDragImage,0,tvn->ptDrag.x,tvn->ptDrag.y);
ShowCursor(FALSE);
SetCapture(context->hwnd);
context->fDragging = TRUE;
context->hDragItem = tvn->itemNew.hItem;
}
static void DragQuit(CHOOSEOUTLINE* context)
{
HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
context->fDragging = FALSE;
TreeView_SelectDropTarget(hctrl,NULL);
ReleaseCapture();
ShowCursor(TRUE);
ImageList_EndDrag();
}
// tree構造が大幅に変わることがあるので、TreeViewはその都度作り直す
// ドラッグされたアイテムのみをTreeView内で動かしてもだめ
static void DropItem(CHOOSEOUTLINE* context)
{
HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
HTREEITEM hTarget = TreeView_GetDropHilight(hctrl);
// HTREEITEM hTargetNext = TreeView_GetNextSibling(hctrl,hTarget);
NPARA npara;
//
txSetUndisp(context->text);//2.99C 970325
context->fUndisp++;
{
tlCut(context,TRUE);
context->fDragging = FALSE;
//
TreeView_SelectItem(hctrl,hTarget);
TreeView_SelectDropTarget(hctrl,NULL);
//
ReleaseCapture();
ShowCursor(TRUE);
ImageList_EndDrag();
//
tlJump(context);
tlPaste(context);
//
npara = text->npara;
tlMake(context);
}
context->fUndisp--;
//
tlFromHl(context);
tlSetNow(context,txrecordFromNpara(context->text,npara));
txSetDisp(context->text);//2.99C 970325
}
#endif
BOOL tlSetActive(TX* text)
{
if (text->hwndOutline) {
SetActiveWindow(text->hwndOutline);
SetFocus(text->hwndOutline);
if (text->outlineContext) {
CHOOSEOUTLINE* oc = text->outlineContext;
tlSetNow(oc,txrecordFromNpara(oc->text,oc->text->npara));
return TRUE;
}
}
return FALSE;
}
#ifdef __FLAT__
FARPROC _wndprocPrev;
FARPROC _wndproc;
LRESULT TXCALLBACK wndprocEdit(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
if (message == WM_GETDLGCODE) {
return DLGC_WANTALLKEYS;
}
return CallWindowProc(_wndprocPrev,hwnd,message,wParam,lParam);
}
static void labelSet(CHOOSEOUTLINE* context,mchar* szText)
{
TXRECORD i = tlGetNow(context);
if (i != TXRECORD_ERROR) {
TX* text = context->text;
HEADLINE hl;
txhRead(text,i,&hl);
txJumpNpara(text,hl.npara);
{
PARAATR paraatr;
INT lch;
int lchTop = txParaatrRead(text,¶atr,&lch);
txstr szline;
txGetPara(text,szline);
mchar* psz = &szline[lchTop];
if (lch == -1) {
lch = strlen(psz);
}
txRightBytes(text,lchTop);
txDeleteBytes(text,lch);
}
txInsert(text,szText);
strcpymax(hl.szstr,szText,CCHWORD);
txhWrite(text,i,&hl);
}
}
static mchar* txGetTitle(TX* text,int ititle)
{
if (ititle) {
ititle--;
if (ititle < 3) return text->tsztitle[ititle];
if (ititle < 6) return text->tszformat[ititle - 3 + SZFORMAT_TITLE4];
}
return "";
}
#define LI_CHILD 0
#define LI_NULL 1
#define LI_ADD 2
#define LI_INSERT 3
static BOOL labelInsert(CHOOSEOUTLINE* context,int mode)
{
TX* text = context->text;
if (!context->textTree) return FALSE;
HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
BOOL fChild = (mode == LI_CHILD);
TXRECORD i = tlGetNow(context);
BOOL fNew = FALSE;
int nest = 0;
if (mode == LI_NULL) {
if (i == TXRECORD_ERROR) {
i = tlGetNowEx(context);
if (i != TXRECORD_ERROR) {
HTREEITEM h = TreeView_GetSelection(hctrl);
nest = treeviewGetNest(hctrl,h) + 1;
}
} else {
return FALSE;
}
} else if (mode == LI_ADD || mode == LI_INSERT) {
if (i == TXRECORD_ERROR) {
i = tlGetNowEx(context);
if (mode == LI_INSERT && i != TXRECORD_ERROR) {
// "(名前なし)"で挿入の場合
HTREEITEM h = TreeView_GetSelection(hctrl);
nest = treeviewGetNest(hctrl,h) + 1;
}
}
if (i != TXRECORD_ERROR) {
if (mode == LI_ADD) {
HTREEITEM h = TreeView_GetSelection(hctrl);
nest = treeviewGetNest(hctrl,h) + 1;
HTREEITEM h1 = TreeView_GetNextSibling(hctrl,h);
if (h1) {
i = tvhGetParam(hctrl,h1);
} else {
HTREEITEM h1 = TreeView_GetParent(hctrl,h);
if (h1 && (h1 = TreeView_GetNextSibling(hctrl,h1))) {
i = tvhGetParam(hctrl,h1);
} else {
i = txhGetCount(text);
fNew = TRUE;
}
}
}
//information("%d",i);
}
}
if (i == TXRECORD_ERROR) {
// 空の場合
i = txhGetCount(text);
fNew = TRUE;
fChild = FALSE;
nest = 1;
}
HEADLINE hl;
if (fNew) {
structClear(hl);
txJumpFileEnd(text);
} else {
txhRead(text,i,&hl);
txJumpPara(text,hl.npara);
}
{
PARAATR paraatr;
txParaatrRead(text,¶atr,NULL);
if (nest) paraatr.modeTitle = nest;
paraatr.modeTitle = paraatr.modeTitle + fChild;
//information(txGetTitle(text,paraatr.modeTitle));
BOOL fC = !stricmp(txGetTitle(text,paraatr.modeTitle),"^C関数定義");
mchar* sztitle;
NPARA nparaIncrease = 1;
//
if (fChild) {
txJumpParaEnd(text);
txInsertReturn(text);
} else {
txJumpParaTop(text);
txInsertReturn(text);
txPrevPara(text);
}
if (fC) {
sztitle = "NewFunction";
txSetUndisp(text);
txInsertLine(text,"void %s(void)",sztitle);
txInsertLine(text,"{");
txInsertLine(text,"\treturn;");
txInsertLine(text,"}");
txInsertReturn(text);
txPrevPara(text);
txPrevPara(text);
txPrevPara(text);
txPrevPara(text);
txPrevPara(text);
txSetDisp(text);
nparaIncrease += 5;
} else {
if (mode == LI_NULL) {
sztitle = "見出し";
} else {
sztitle = "新規見出し";
}
txInsert(text,sztitle);
txParaatrWrite(text,¶atr);
}
//
hl.npara = text->npara;
hl.nest = paraatr.modeTitle;
strcpymax(hl.szstr,sztitle,CCHWORD);
txhInsert(text,i+fChild,&hl);
{
TXRECORD now = i + fChild + 1;
TXRECORD n = txhGetCount(text);
for (;now < n;now++) {
txhRead(text,now,&hl);
hl.npara += nparaIncrease;
txhWrite(text,now,&hl);
}
}
//
tlFromHl(context);
tlSetNow(context,i+fChild);
//
HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
HTREEITEM h = TreeView_GetSelection(hctrl);
TreeView_EditLabel(hctrl,h);
}
return TRUE;
}
static BOOL labelSearch(CHOOSEOUTLINE* context,BOOL fNext)
{
TX* text = context->text;
static mchar _szSearch[CCHWORD];
static TXRECORD _txrecordSearch;
if (!fNext) {
HDIALOG hd = dialog("見出しの検索");
dialogSetParent(hd,context->hwnd);
dialogStrC(hd,NULL,_szSearch,0,cchof(_szSearch),30);
if (!dialogOpen(hd)) {
tlSetActive(text);
return FALSE;
}
tlSetActive(text);
_txrecordSearch = 0;
}
BOOL ret = FALSE;
TXRECORD n = txhGetCount(text);
TXRECORD i;
for (i = _txrecordSearch;i < n;i++) {
HEADLINE hl;
txhRead(text,i,&hl);
if (stristr(hl.szstr,_szSearch)) {
_txrecordSearch = i + 1;
tlSetNow(context,i);
ret = TRUE;
break;
}
}
if (!ret) statprintf("見出しが見つかりません");
return ret;
}
#endif
static BOOL tlContents(CHOOSEOUTLINE* context)
{
HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
BOOL fTree = (context->textTree != NULL);
int n;
if (context->textTree) {
n = txhGetCount(context->text);
} else {
n = SendMessage(hctrl,LB_GETCOUNT,0,0);
}
if (n > 0) {
tx body;
tx* text = &body;
txInitText(text);
txOpenText(text);
int i;
txSetUndisp(context->text);
for (i = 0;i < n;i++) {
if (fTree) {
HEADLINE hl;
txhRead(context->text,i,&hl);
{
int n = hl.nest - 1;
while(n--) txInsert(text," ");
}
txInsert(text,hl.szstr);
} else {
mchar buff[CCHLINE];
SendMessage(hctrl,LB_GETTEXT,i,(LPARAM)buff);
txInsert(text,buff);
}
if (context->text->editmode == 2) {
TXRECORD irecord = ilistToTxrecord(context->text,i);
HEADLINE hl;
txhRead(text,irecord,&hl);
txJumpPara(context->text,hl.npara);
txInsertf(text,".....%d",context->text->npage);
}
txInsertReturn(text);
}
txSetDisp(context->text);
txSelectAll(text);
txSelectCopy(text);
txClose(text);
return TRUE;
}
return FALSE;
}
TX* TXAPI outlineGetTx(HWND hwnd)
{
CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
return context->text;
}
TXRECORD TXAPI outlineGetCursel(HWND hwnd)
{
CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
return tlGetNow(context);
}
void TXAPI outlineSetCursel(HWND hwnd,TXRECORD i)
{
#if 1//3.00B1 970612 WZ16の慣用句の挿入で編集すると、プレビュー内容が正しくなかった
CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
if (context->textTree) {
tlSetNow(context,i);
} else {
tlSetNow(context,i);
tlFlushListview(context);
}
#else
CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
tlSetNow(context,i);
#endif
}
BOOL TXAPI outlineGetCurheadline(HWND hwnd,HEADLINE* hl)
{
CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
TX* text = context->text;
TXRECORD i = tlGetNow(context);
structClear(*hl);
if (i != TXRECORD_ERROR) {
txhRead(text,i,hl);
return TRUE;
} else {
return FALSE;
}
}
BOOL TXAPI outlineGetHeadline(HWND hwnd,HEADLINE* hl,TXRECORD i)
{
// iが無効ならFALSEを返す
CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
TX* text = context->text;
structClear(*hl);
if (i < txhGetCount(text)) {
txhRead(text,i,hl);
return TRUE;
} else {
return FALSE;
}
}
BOOL TXAPI outlineFlush(HWND hwnd)
{
CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
tlMake(context);
if (!context->fOutlineStd) tlFlushListview(context);
return TRUE;
}
BOOL TXAPI outlineCopy(HWND hwnd)
{
CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
tlCut(context,FALSE);
return TRUE;
}
BOOL TXAPI outlineCut(HWND hwnd)
{
CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
tlCut(context,TRUE);
return TRUE;
}
BOOL TXAPI outlineClear(HWND hwnd)
{
CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
tlCut(context,2);
return TRUE;
}
static BOOL handleKey(HWND hwnd,WPARAM wParam)
{
int idd = 0;
if (
(GetKeyState(VK_CONTROL) < 0) &&
!(GetKeyState(VK_SHIFT) < 0) &&
!(GetKeyState(VK_MENU) < 0)
) {
// Ctrl+xxx
switch(wParam) {
case VK_UP: idd = IDD_UP;break;
case VK_DOWN:idd = IDD_DOWN;break;
case VK_LEFT:idd = IDD_LEFTWITHSUB;break;
case VK_RIGHT:idd = IDD_RIGHTWITHSUB;break;
case 'A':idd = IDD_LABELADD;break;
case 'C':idd = IDD_COPY;break;
case 'F':idd = IDD_SEARCH;break;
case 'N':idd = IDD_LABELINSERT;break;
case 'B':idd = IDD_LABELCHILD;break;
case 'V':idd = IDD_PASTE;break;
case 'X':idd = IDD_CUT;break;
}
}
if (
!(GetKeyState(VK_CONTROL) < 0) &&
(GetKeyState(VK_SHIFT) < 0) &&
!(GetKeyState(VK_MENU) < 0)
) {
// Shift+xxx
switch(wParam) {
case VK_LEFT:idd = IDD_LEFT;break;
case VK_RIGHT:idd = IDD_RIGHT;break;
}
}
if (
!(GetKeyState(VK_CONTROL) < 0) &&
!(GetKeyState(VK_SHIFT) < 0) &&
!(GetKeyState(VK_MENU) < 0)
) {
// No shift
switch(wParam) {
case VK_F2:idd = IDD_EDITLABEL;break;
case VK_F3:idd = IDD_SEARCHNEXT;break;
case VK_F5:idd = IDD_FLUSHLIST;break;
}
}
if (idd) {
PostMessage(hwnd,WM_COMMAND,idd,0);
return TRUE;
}
return FALSE;
}
BOOL dlgprocTitlelist(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
BOOL ret = FALSE;//途中returnで返ってはいけない
_fNoTxReport = TRUE;
HDIALOG hd = dialogFromHwnd(hwnd);
CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(hd);
TX* text = context->text;
if (context->hook.address) {
DWORD ret;
macroCallAddress(&context->hook,&ret,4,(DWORD)hwnd,(DWORD)message,(DWORD)wParam,(DWORD)lParam);
if (ret) return ret;
}
#ifdef __FLAT__
if (context->fLabelEditing) {
if (message != WM_NOTIFY) return FALSE;
}
#endif
switch(message) {
case WM_INITDIALOG: {
if (context->fOutlineStd) text->fLastFocusOutline = TRUE;//2.95 970129
context->hwnd = hwnd;
// context->fIniting = TRUE;
if (context->textTree) {
// context->fUndisp++;
tlMake(context);
// context->fUndisp--;
} else {
tlMake(context);
//2.92 SendDlgItemMessage(hwnd,IDD_TITLELIST,LB_SETCURSEL,context->iselFirst,0);
}
#if 1//2.92
PostMessage(hwnd,WM_TXUSER,0,0);
#endif
if (context->fOutlineStd) {
if (context->modeWindow == WINDOW_HV) {
if (fWindowPos) {
SetWindowPos(hwnd,NULL,x,y,0,0,SWP_NOSIZE);
}
} else {
SetWindowPos(hwnd,NULL,-30000,-30000,0,0,SWP_NOSIZE);// ちらつき抑止
ExtendWindow(text,hwnd,NULL);
PostMessage(text->hwndbase,WM_TXFLUSHWINDOWSIZE,0,0);
}
{
HWND hctrl = GetDlgItem(hwnd,IDD_TITLE);
if (hctrl) {
static mchar* tsz[] = {
"見出し1まで",
"見出し2まで",
"見出し3まで",
"見出し4まで",
"見出し5まで",
"見出し6まで",
"全ての見出し",
NULL,
};
int i;
for (i = 0;tsz[i];i++) {
SendMessage(hctrl,CB_ADDSTRING,0,(LPARAM)tsz[i]);
}
SendMessage(hctrl,CB_SETCURSEL,_nestDispMax,0);
// set Z order bottom.
SetWindowPos(hctrl,HWND_BOTTOM,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
}
}
tlSetNow(context,txrecordFromNpara(text,text->npara));
} else {
tlFlushListview(context);
}
// context->fIniting = FALSE;
if (context->textTree) {
if (context->fOutlineStd) {
// fOutlineStd時のみ。他の時は他のアイテム初期化があるので、しない
return INITDIALOG_SKIP_TRUE;
}
}
break;
}
#ifdef __FLAT__//2.90
case WM_CONTEXTMENU: {
if (!context->fOutlineStd) {
break;
}
if (wParam == GetDlgItem(hwnd,IDD_TITLELIST)) {
HMENU hmenu = menuNew();
//
menuStr(hmenu,"↑(&U)\tCtrl+Up",IDD_UP);
menuStr(hmenu,"↓(&D)\tCtrl+Down",IDD_DOWN);
#if 1//2.99C 970323 子見出し毎にランクを上げ下げするコマンドを追加
menuStr(hmenu,"子見出ごと←(&L)\tCtrl+Left",IDD_LEFTWITHSUB);
menuStr(hmenu,"子見出ごと→(&R)\tCtrl+Right",IDD_RIGHTWITHSUB);
menuStr(hmenu,"子見出は移動しない←(&1)\tShift+Left",IDD_LEFT);
menuStr(hmenu,"子見出は移動しない→(&2)\tShift+Right",IDD_RIGHT);
#else
menuStr(hmenu,"←(&L)",IDD_LEFT);
menuStr(hmenu,"→(&R)",IDD_RIGHT);
#endif
menuSepa(hmenu);
#if 1//2.99A 970321 アウトラインのコンテキストメニューのメニューコマンドの名称一部変更
menuStr(hmenu,"見出しの追加(&W)\tCtrl+A",IDD_LABELADD);
menuStr(hmenu,"子見出しの追加(&N)\tCtrl+B",IDD_LABELCHILD);
menuStr(hmenu,"見出しの挿入(&I)\tCtrl+I",IDD_LABELINSERT);
menuStr(hmenu,"名前の変更(&M)\tF2",IDD_EDITLABEL);
#else
menuStr(hmenu,"新規作成(&W)",IDD_LABELADD);
menuStr(hmenu,"子見出しの新規作成(&N)",IDD_LABELCHILD);
menuStr(hmenu,"新規挿入(&I)",IDD_LABELINSERT);
menuStr(hmenu,"名前の変更(&M)",IDD_EDITLABEL);
#endif
menuSepa(hmenu);
menuStr(hmenu,"切り抜き(&T)\tCtrl+X",IDD_CUT);
menuStr(hmenu,"コピー(&C)\tCtrl+C",IDD_COPY);
menuStr(hmenu,"貼り付け(&P)\tCtrl+V",IDD_PASTE);
menuStr(hmenu,"目次を作成してコピー(&E)",IDD_COPYLIST);
menuSepa(hmenu);
menuStr(hmenu,"検索(&F)...\tCtrl+F",IDD_SEARCH);
menuStr(hmenu,"次検索(&S)\tF3",IDD_SEARCHNEXT);
menuSepa(hmenu);
menuStr(hmenu,"設定(&O)...",IDD_CONFIG);
menuStr(hmenu,"再作成(&H)\tF5",IDD_FLUSHLIST);
menuSepa(hmenu);
menuStr(hmenu,"閉じる(&X)\tCtrl+F4",IDD_CLOSE);
//
POINT point;
// GetCursorPos(&point);
// TrackPopupMenu(hmenu,TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN,point.x,point.y,0,hwnd,NULL);
point.x = LOWORD(lParam);
point.y = HIWORD(lParam);
if (point.x == 65535) {// by keyboard
HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
HTREEITEM h = TreeView_GetSelection(hctrl);
if (h) {
RECT rcItem;
TreeView_GetItemRect(hctrl,h,&rcItem,TRUE);
point.x = rcItem.right;
point.y = rcItem.bottom;
ClientToScreen(hctrl,&point);
}
}
TrackPopupMenu(hmenu,TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN,point.x,point.y,0,hwnd,NULL);
menuDelete(hmenu);
return TRUE;
}
break;
}
case WM_NOTIFY: {
TV_DISPINFO* nm = (LPVOID)lParam;
if (nm->hdr.idFrom == IDD_TITLELIST) {
switch(nm->hdr.code) {
case TVN_SELCHANGED: {
if (!context->fUndisp) {
tlJump(context);
if (!context->fOutlineStd) tlFlushListview(context);//2.92
}
break;
}
case TVN_BEGINDRAG: {
NM_TREEVIEW* tvn = (LPVOID)lParam;
BeginDrag(context,tvn);
break;
}
case TVN_BEGINLABELEDIT: {
HWND hctrl = nm->hdr.hwndFrom;
TV_DISPINFO* tvis = (LPVOID)lParam;
TV_ITEM* tvi = &tvis->item;
//
tvi->mask = TVIF_TEXT|TVIF_PARAM;
static mchar buff[CCHWORD];
tvi->pszText = buff;
tvi->cchTextMax = CCHWORD;
TreeView_GetItem(hctrl,tvi);
tvi->mask = TVIF_TEXT;
TreeView_SetItem(hctrl,tvi);
// dialog.tll内のダイアログプロシジャーを無効にしないと、ハングする
context->fLabelEditing = TRUE;
dialogSetHookState(hd,HOOKSTATE_HOOKALL);
//
HWND hctrl = TreeView_GetEditControl(nm->hdr.hwndFrom);
_wndproc = macroMakeWndProc("wndprocEdit");
_wndprocPrev = GetWindowLong(hctrl,GWL_WNDPROC);
SetWindowLong(hctrl,GWL_WNDPROC,(LONG)_wndproc);
//
if ((long)tvi->lParam < 0) {
#if 1
context->fLabelName = TRUE;
PostMessage(nm->hdr.hwndFrom,TVM_ENDEDITLABELNOW,TRUE,0);
#else
// 編集不可
information("編集できません");
PostMessage(nm->hdr.hwndFrom,TVM_ENDEDITLABELNOW,TRUE,0);
#endif
}
return 0;
}
case TVN_ENDLABELEDIT: {
HWND hctrl = nm->hdr.hwndFrom;
TV_DISPINFO* tvis = (LPVOID)lParam;
TV_ITEM* tvi = &tvis->item;
BOOL fEdit = FALSE;
if (tvi->pszText) {
tvi->mask = TVIF_TEXT;
TreeView_SetItem(hctrl,tvi);
fEdit = TRUE;
}
//
context->fLabelEditing = FALSE;
dialogSetHookState(hd,HOOKSTATE_HOOKONCE);
//
HWND hctrl = TreeView_GetEditControl(nm->hdr.hwndFrom);
SetWindowLong(hctrl,GWL_WNDPROC,(DWORD)_wndprocPrev);
macroFreeWndProc(_wndproc);
//
if (fEdit) {
labelSet(context,tvi->pszText);
}
if (context->fLabelName) {
context->fLabelName = FALSE;
PostMessage(hwnd,WM_COMMAND,IDD_LABELNAME,0);
}
return 0;
}
#if 0 // 乗っ取れない
case TVN_KEYDOWN: {
TV_KEYDOWN* tvk = (LPVOID)lParam;
if (handleKey(hwnd,tvk->wVKey)) {
return TRUE;
}
break;
}
#endif
#if 0 // ESCはダイアログだから来ない
case TVN_KEYDOWN: {
TV_KEYDOWN* tvk = (LPVOID)lParam;
if (tvk->wVKey == VK_ESCAPE && context->fDragging) {
DragQuit(context);
return TRUE;
}
break;
}
#endif
}
}
break;
}
case WM_MOUSEMOVE: {
if (context->fDragging) {
HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
POINT point;
point.x = LOWORD(lParam);
point.y = HIWORD(lParam);
ImageList_DragMove(point.x,point.y);
UINT flags = TVHT_ONITEM;
TV_HITTESTINFO tvht;
tvht.pt = point;
tvht.flags = TVHT_ONITEM;
TreeView_HitTest(hctrl,&tvht);
if (tvht.hItem) {
TreeView_SelectDropTarget(hctrl,tvht.hItem);
}
}
break;
}
case WM_LBUTTONUP: {
if (context->fDragging) {
DropItem(context);
}
break;
}
#endif
case WM_COMMAND: {
int id = WM_COMMAND_GetId(wParam);
int notify = WM_COMMAND_GetNotify(wParam,lParam);
if (!context->fOutlineStd) {
if (id == IDOK) {
tlCut(context,3);//2.92 FALSE->3
} else if (id == IDD_TITLELIST && notify == CBN_SELCHANGE) {
if (!context->textTree) tlFlushListview(context);
}
break;
}
if (id == IDOK || id == IDCANCEL) {
if (context->modeWindow == WINDOW_HV) {
// 位置を覚える
fWindowPos = TRUE;
WINDOWPLACEMENT wplace;
wplace.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hwnd,(LPWINDOWPLACEMENT)&wplace);
x = wplace.rcNormalPosition.left;
y = wplace.rcNormalPosition.top;
}
}
switch(id) {
case IDD_TITLE: {
if (notify == CBN_SELCHANGE) {
_nestDispMax = SendDlgItemMessage(hwnd,id,CB_GETCURSEL,0,0);
tlFromHl(context);
tlSetNow(context,txrecordFromNpara(text,text->npara));
}
break;
}
case IDD_TITLELIST: {
if (!context->textTree) {
if (notify == CBN_SELCHANGE) {
tlJump(context);
} else if (notify == LBN_DBLCLK) {
tlOpenClose(context);
}
}
break;
}
case IDOK: {
if (GetKeyState(VK_SHIFT) < 0) {
//1.94 Shift+Return/OKで、開閉
tlOpenClose(context);
return TRUE;
}
tlJump(context);
SetFocus(text->hwndtext);
break;
}
case IDD_UP: {
tlUp(context);
break;
}
case IDD_DOWN: {
tlDown(context);
break;
}
case IDD_LEFT: {
tlLeft(context);
break;
}
case IDD_RIGHT: {
tlRight(context);
break;
}
case IDD_LEFTWITHSUB: {//2.99C 970323 new
tlLeftWithSub(context);
break;
}
case IDD_RIGHTWITHSUB: {//2.99C 970323 new
tlRightWithSub(context);
break;
}
case IDD_CUT: {
tlCut(context,TRUE);
break;
}
case IDD_COPY: {
tlCut(context,FALSE);
break;
}
case IDD_PASTE: {
tlPaste(context);
tlMake(context);
break;
}
case IDD_COPYLIST: {
tlContents(context);
break;
}
case IDD_FLUSHLIST: {
tlMake(context);
break;
}
case IDD_CONFIG: {
HDIALOG hd = dialog("アウトラインの設定");
dialogSetContexthelp(hd,TRUE);
dialogSetGroupRight(hd,DTCX * 50);
int modeWindow1 = p_modeWindow;
dialogGroup(hd,"ウィンドウの位置");
dialogControlHelp(hd,-298);
dialogRadioID(hd,&modeWindow1,"縦割り(&V)","横割り(&H)","浮動(&W)");
dialogGroupEnd(hd);
dialogGroup(hd,"見出しリストの大きさ");
dialogControlHelp(hd,246);
dialogControlGuide(hd,"文字",8);
dialogInt(hd,"縦割り時の幅(&X):",&lcxTitleListV,20,4);
dialogControlHelp(hd,247);
dialogControlGuide(hd,"文字",8);
dialogInt(hd,"横割り時の高さ(&Y):",&lcyTitleListH,20,4);
dialogControlHelp(hd,248);
dialogControlGuide(hd,"文字",8);
dialogIntXY(hd,"浮動時の幅と高さ(&Z):",&lcxTitleList,&lcyTitleList,20,4);
dialogGroupEnd(hd);
dialogGroup(hd,"本文ウィンドウのサイズ");
dialogControlHelp(hd,249);
dialogCheck(hd,"縦割り時に変化しない(&S)",&fExtendTextWindow);
dialogGroupEnd(hd);
if (!_fwin40) {
dialogGroup(hd,"フォント");
dialogControlHelp(hd,250);
dialogCheck(hd,"小さいフォントで表示(&S)",&fSmallFont);
dialogGroupEnd(hd);
}
if (dialogOpen(hd)) {
close(text,hwnd,TRUE);
PostMessage(text->hwndbase,WM_COMMAND,IDM_WZCMDTOP + wzcmdRegister("\m.uiTitleList"),0);
p_modeWindow = modeWindow1;
}
break;
}
#ifdef __FLAT__
case IDD_EDITLABEL: {
HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
HTREEITEM h = TreeView_GetSelection(hctrl);
TreeView_EditLabel(hctrl,h);
break;
}
case IDD_LABELCHILD: {
labelInsert(context,LI_CHILD);
break;
}
case IDD_LABELADD: {
labelInsert(context,LI_ADD);
break;
}
case IDD_LABELINSERT: {
labelInsert(context,LI_INSERT);
break;
}
case IDD_LABELNAME: {
labelInsert(context,LI_NULL);
break;
}
case IDD_SEARCH: {
labelSearch(context,FALSE);
break;
}
case IDD_SEARCHNEXT: {
labelSearch(context,TRUE);
break;
}
#endif
}
if (_fModeress) {
if (id == IDCANCEL) {
if (context->modeWindow == WINDOW_HV) {
close(text,hwnd,FALSE);
} else {
if (context->fDragging) {
#ifdef __FLAT__
DragQuit(context);
return TRUE;
#endif
} else {
SetFocus(text->hwndtext);
}
}
} else if (id == IDD_CLOSE) {
close(text,hwnd,FALSE);
}
ret = TRUE;
}
break;
}
case WM_CLOSE: {
if (!context->fOutlineStd) break;
if (_fModeress) {
// ダイアログプロシジャーはWM_CLOSEを処理しない
outlineClose(text);
ret = TRUE;//2.99D 970330 for DEBUGWIN err
}
break;
}
case WM_TXUSER: {//2.92
if (context->iselFirst) {
tlSetNow(context,context->iselFirst);
#ifndef __FLAT__
//2.97A 970228 WZ16で内容表示が初期化されなかった
tlFlushListview(context);
#endif
}
break;
}
case WM_KEYDOWN: {
break;
}
case WM_SETFOCUS: {//2.95 970129
if (context->fOutlineStd) text->fLastFocusOutline = TRUE;
break;
}
case WM_ACTIVATE: {//2.99C 970323 浮動アウトライン表示中にテキストでダイアログを開いて閉じるとフォーカスがアウトラインに移ってしまっていた
if (text->fOutlineHV) {
BOOL fActive = LOWORD(wParam);
if (fActive != WA_INACTIVE) {
#ifdef __FLAT__
HWND hwnd0 = lParam;
#else
HWND hwnd0 = LOWORD(lParam);
#endif
if (hwnd0 != text->hwndbase) {
PostMessage(hwnd,WM_TXUSER+2,0,0);
}
}
}
break;
}
case WM_TXUSER+2: {//2.99C 970323 WM_TXUSER+1は使用中
SetFocus(text->hwndtext);
break;
}
case WM_TXKEYDOWN: {//2.99C 970324 outlineキーボードインターフェースサポート
TXKEYDOWNARG* arg = (LPVOID)lParam;
if (handleKey(hwnd,wParam)) {
arg->fHook = TRUE;
}
break;
}
#if 0
case WM_CTLCOLORDLG:{
return (int)GetStockObject(WHITE_BRUSH);
}
#endif
}
_fNoTxReport = FALSE;
return ret;
}
#define MODE_WZOUTLINE 0x8000
//2.92
static void contextFreeText(CHOOSEOUTLINE* context)
{
if (context->textTree) {//2.90
txClose(context->textTree);
free(context->textTree);
context->textTree = NULL;
}
}
BOOL TXAPI dialogSelectTitle(HDIALOG hd,CHOOSEOUTLINE* context)
{
if (context->szhook) {
macroGetFuncAddress(context->szhook,&context->hook);
}
dialogSetCustdata(hd,(DWORD)context);
//
if (_fwin40) {//2.90
TX* text = malloc(sizeof(TX));
if (text) {
context->textTree = text;
txInitText(text);
txOpenText(text);
dialogSetControlData(hd,IDD_TITLELIST,text);
}
}
//
dialogSetHookEx(hd,"\m.dlgprocTitlelist");
//
if (context->fOutlineStd) {
if (_fModeress) {
context->text->hwndOutline = dialogCreate(hd);
} else {
dialogOpen(hd);
contextFreeText(context);
}
} else {
context->modeWindow = WINDOW_V;//2.99D 970330
int ret = dialogOpen(hd);
contextFreeText(context);
return ret;
}
}
static BOOL _dialogSmallButtonCmd(HDIALOG hd,mchar* szCaption,int id,int cx,int dcs)
{
int ret;
DTRECT r;
dialogGetPos(hd,&r);
r.cx = cx * DTCX;
r.cy = DTCYBUTTON;
ret = _dialogAddItem(hd,dcs,szCaption,id,&r,WS_GROUP);
r.y += r.cy + DTCY / 4;
dialogSetPos(hd,&r);
return ret;
}
static BOOL dialogSmallButtonCmd(HDIALOG hd,mchar* szCaption,int id,int cx)
{
return _dialogSmallButtonCmd(hd,szCaption,id,cx,DCS_PUSHBUTTON);
}
static BOOL dialogSmallButtonCmdDefault(HDIALOG hd,mchar* szCaption,int id,int cx)
{
return _dialogSmallButtonCmd(hd,szCaption,id,cx,DCS_DEFPUSHBUTTON);
}
BOOL TXAPI dialogAddTitle(HDIALOG hd,DTRECT* r)
{
//2.92
if (_fwin40) {//2.90
#ifdef __FLAT__
dialogControlID(hd,IDD_TITLELIST);
dialogControlStyle(hd,WS_TABSTOP|WS_VSCROLL|WS_BORDER|WS_CHILD|WS_VISIBLE|TVS_HASBUTTONS|TVS_LINESATROOT|TVS_HASLINES|TVS_SHOWSELALWAYS|TVS_EDITLABELS);
dialogTree(hd,NULL,NULL,r->cx / DTCX,r->cy / DTCY);
dialogControlStyle(hd,0);
#endif
} else {
__dialogAddItem(hd,"LISTBOX",NULL,IDD_TITLELIST,r,LBS_NOTIFY|WS_BORDER|WS_VSCROLL|WS_HSCROLL|WS_CHILD|WS_VISIBLE|WS_TABSTOP);
}
return TRUE;
}
BOOL uiTitleList(TX* text)
{
BOOL fHV = (p_modeWindow == WINDOW_HV); // 浮動?
if (text->hwndOutline) {
tlSetActive(text);
return FALSE;
}
//
if (!text->outlineContext) {
text->outlineContext = malloc(sizeof(CHOOSEOUTLINE));
if (!text->outlineContext) return FALSE;
}
CHOOSEOUTLINE* context = text->outlineContext;
memset(context,0,sizeof(CHOOSEOUTLINE));
context->text = text;
context->fOutlineStd = TRUE;
context->modeWindow = p_modeWindow;//2.99D 970330
text->fOutline = TRUE;
text->fOutlineHV = fHV;//2.99A 970321 浮動型アウトラインで本文に戻れなかった
//
HDIALOG hd = _dialog("アウトライン",EXDS_POSDEFAULT|(fSmallFont?EXDS_BIGFORCE:0),NULL);
dialogSetParent(hd,text->hwndbase);//2.90
//
DTRECT r;
if (!_fwin40) {
dialogGetPos(hd,&r);
r.y -= DTCY / 3;
r.cx = DTCX * 20;
r.cy = DTCY * 7;
__dialogAddItem(hd,"COMBOBOX",NULL,IDD_TITLE,&r,CBS_AUTOHSCROLL|CBS_DROPDOWNLIST|WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|WS_GROUP);
dialogLF(hd);
}
//
dialogGetPos(hd,&r);
{
RECT rs;
GetClientRect(text->hwndbase,&rs);
DWORD dwBaseUnits = dialogGetBaseUnits(hd);
int cxd = LOWORD(dwBaseUnits);
int cyd = HIWORD(dwBaseUnits);
if (fHV) {
r.cx = DTCX * lcxTitleList;
r.cy = DTCY * lcyTitleList;
} else if (context->modeWindow == WINDOW_V) {
r.cx = DTCX * lcxTitleListV;
r.cy = (rs.bottom * 8) / cyd - DTCY * 17;
} else {
r.cx = (rs.right * 4) / cxd - DTCX * 28;
r.cy = DTCY * lcyTitleListH;
}
}
dialogAddTitle(hd,&r);
dialogSetPos(hd,&r);
dialogSetFocus(hd,IDD_TITLELIST);
//
if (context->modeWindow == WINDOW_V) {
dialogLF(hd);
} else {
dialogLFV(hd);
}
//
dialogSetPosLF(hd);
//
int cx;
if (fHV) {
if (_fwin40) {
//2.99A 970321 Win95/NTでは浮動アウトラインでボタンつけない
dialogSetNoButton(hd);
} else {
cx = 6;
dialogControlID(hd,IDD_UP);
dialogButtonCmd(hd,"↑(&U)",NULL,cx);
dialogControlID(hd,IDD_DOWN);
dialogButtonCmd(hd,"↓(&D)",NULL,cx);
dialogLFV(hd);
dialogControlID(hd,IDD_LEFT);
dialogButtonCmd(hd,"←(&L)",NULL,cx);
dialogControlID(hd,IDD_RIGHT);
dialogButtonCmd(hd,"→(&R)",NULL,cx);
dialogLF(hd);
cx = 13;
dialogSpaceV(hd);
dialogControlID(hd,IDD_CUT);
dialogButtonCmd(hd,"切り抜き(&T)",NULL,cx);
dialogControlID(hd,IDD_COPY);
dialogButtonCmd(hd,"コピー(&C)",NULL,cx);
dialogControlID(hd,IDD_PASTE);
dialogButtonCmd(hd,"貼り付け(&P)",NULL,cx);
dialogLFV(hd);
dialogOK(hd,cx);
dialogControlID(hd,IDCANCEL);
dialogButtonCmd(hd,"閉じる(&X)",NULL,cx);
dialogControlID(hd,IDD_CONFIG);
dialogButtonCmd(hd,"設定(&O)...",NULL,cx);
dialogLF(hd);
r.y += r.cy + DTCYINT;
dialogSetPos(hd,&r);
dialogSetH(hd);
dialogControlID(hd,IDD_COPYLIST);
if (_fwin40) {
dialogButtonCmd(hd,"目次を作成してコピー(&I)",NULL,cx * 2);
} else {
dialogButtonCmd(hd,"一覧をコピー(&I)",NULL,cx);
}
//
dialogControlID(hd,IDD_FLUSHLIST);
dialogButtonCmd(hd,"再作成(&H)",NULL,cx);
}
} else {
if (!_fwin40) {
BOOL fVwide = (context->modeWindow == WINDOW_V && lcxTitleListV >= 30);
cx = 4;
dialogSmallButtonCmd(hd,"↑",IDD_UP,cx);
dialogSmallButtonCmd(hd,"↓",IDD_DOWN,cx);
if (fVwide) dialogLFV(hd);
dialogSmallButtonCmd(hd,"←",IDD_LEFT,cx);
dialogSmallButtonCmd(hd,"→",IDD_RIGHT,cx);
if (context->modeWindow == WINDOW_V) {
dialogLFV(hd);
} else {
dialogSmallButtonCmdDefault(hd,"OK",IDOK,cx);
dialogLFV(hd);
}
if (fVwide) {
cx = 6;
} else {
cx = 8;
}
dialogSmallButtonCmd(hd,"切抜&T",IDD_CUT,cx);
dialogSmallButtonCmd(hd,"貼付&P",IDD_PASTE,cx);
if (fVwide) dialogLFV(hd);
cx = 8;
dialogSmallButtonCmd(hd,"設定&O",IDD_CONFIG,cx);
dialogSmallButtonCmd(hd,"再作成&H",IDD_FLUSHLIST,cx);
if (context->modeWindow == WINDOW_V) {
dialogLFV(hd);
cx = 4;
dialogSmallButtonCmdDefault(hd,"OK",IDOK,cx);
}
dialogSmallButtonCmd(hd,"&X",IDD_CLOSE,cx);
}
DWORD style = dialogGetStyle(hd);
dialogSetStyle(hd,WS_VISIBLE|WS_CHILD|(style & DS_SETFONT));
dialogSetNoButton(hd);
}
return dialogSelectTitle(hd,context);
}
static void olJustDlg(TX* text,int cx,int cy)
{
HWND hwnd = text->hwndOutline;
CHOOSEOUTLINE* context = text->outlineContext; //2.94 970121
DWORD dw = GetDialogBaseUnits();
int dtcx = LOWORD(dw);
int dtcy = HIWORD(dw);
int dx = 0;
int dy = 0;
int yTop;
int yEnd;
POINT p;
if (context->modeWindow == WINDOW_V) {
RECT rTitle;
HWND hctrl = GetDlgItem(hwnd,IDD_TITLE);
if (hctrl) {
GetWindowRect(hctrl,&rTitle);
ScreenToClientRect(hwnd,&rTitle);
yTop = rTitle.bottom + dtcy / 2;
//
RECT rOK;
HWND hctrl = GetDlgItem(hwnd,IDOK);
GetWindowRect(hctrl,&rOK);
ScreenToClientRect(hwnd,&rOK);
yEnd = rOK.top;
//
RECT rRight;
HWND hctrl = GetDlgItem(hwnd,IDD_RIGHT);
GetWindowRect(hctrl,&rRight);
ScreenToClientRect(hwnd,&rRight);
yEnd = cy - (rRight.bottom - rOK.top + dtcy);
// move TITLELIST
RECT rList;
HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
GetWindowRect(hctrl,&rList);
ScreenToClientRect(hwnd,&rList);
MoveWindow(hctrl,rList.left,yTop,rList.right - rList.left,yEnd - yTop,TRUE);
// move buttons
yTop = yEnd + dtcy / 2;
dy = yTop - rOK.top;
} else {
// move TITLELIST
RECT rList;
HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
GetWindowRect(hctrl,&rList);
ScreenToClientRect(hwnd,&rList);
int dx = dtcx / 4;
MoveWindow(hctrl,dx,0,cx-dx,cy,TRUE);
}
//
} else if (context->modeWindow == WINDOW_H) {
RECT rTitle;
HWND hctrl = GetDlgItem(hwnd,IDD_TITLE);
if (hctrl) {
GetWindowRect(hctrl,&rTitle);
ScreenToClientRect(hwnd,&rTitle);
yTop = rTitle.bottom + dtcy;
//
RECT rOK;
HWND hctrl = GetDlgItem(hwnd,IDD_CONFIG);
GetWindowRect(hctrl,&rOK);
ScreenToClientRect(hwnd,&rOK);
//
RECT rUp;
HWND hctrl = GetDlgItem(hwnd,IDD_UP);
GetWindowRect(hctrl,&rUp);
ScreenToClientRect(hwnd,&rUp);
int xEnd = cx - (dtcx + rOK.right - rUp.left + dtcx);
// move TITLELIST
RECT rList;
HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
GetWindowRect(hctrl,&rList);
ScreenToClientRect(hwnd,&rList);
MoveWindow(hctrl,rList.left,rList.top,xEnd - rList.left,rList.bottom - rList.top,TRUE);
// move buttons
dx = xEnd - rUp.left + dtcx;
} else {
// move TITLELIST
RECT rList;
HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
GetWindowRect(hctrl,&rList);
ScreenToClientRect(hwnd,&rList);
int dy = dtcy / 8;
MoveWindow(hctrl,0,dy,cx,cy-dy,TRUE);
}
}
// move buttons
if (dx || dy) {
static int tid[] = {
IDD_UP,IDD_DOWN,IDD_LEFT,IDD_RIGHT,
IDOK,IDD_CLOSE,IDD_CUT,IDD_COPY,IDD_PASTE,
IDD_CONFIG,IDD_FLUSHLIST,
0,
};
int i;
for (i = 0;tid[i];i++) {
HWND hctrl = GetDlgItem(hwnd,tid[i]);
if (hctrl) {
RECT r;
GetWindowRect(hctrl,&r);
ScreenToClientRect(hwnd,&r);
MoveWindow(hctrl,r.left + dx,r.top + dy,r.right - r.left,r.bottom - r.top,FALSE);
}
}
}
}
//##hook
HOOKRESULT __wndprocbase(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
TX* text = textTarget;//2.94 970121
switch(message) {
case WM_TXWINDOWSIZE: {
if (_fFlushWindow) {
_fFlushWindow = FALSE;
RECT r = *(RECT*)lParam;
MoveWindow(text->hwndtext,r.left,r.top,r.right-r.left,r.bottom-r.top,TRUE);
} else if (text->hwndOutline) {
CHOOSEOUTLINE* context = text->outlineContext;
if (context->modeWindow != WINDOW_HV) {
RECT rs;
GetClientRect(text->hwndOutline,&rs);
//
RECT* rp = (RECT*)lParam;
RECT r = *rp;
RECT r2 = r;
if (context->modeWindow == WINDOW_H) {
r.bottom -= rs.bottom;
r2.top = r.bottom;
} else {
r.right -= rs.right;
r2.left = r.right;
}
#if 1//2.95 970129 分割対応
rp->right = r.right;
rp->bottom = r.bottom;
//
int cx = r2.right-r2.left;
int cy = r2.bottom-r2.top;
olJustDlg(text,cx,cy);
MoveWindow(text->hwndOutline,r2.left,r2.top,cx,cy,TRUE);
return HOOK_CONTINUE;
#else
MoveWindow(text->hwndtext,r.left,r.top,r.right-r.left,r.bottom-r.top,TRUE);
//
int cx = r2.right-r2.left;
int cy = r2.bottom-r2.top;
olJustDlg(text,cx,cy);
MoveWindow(text->hwndOutline,r2.left,r2.top,cx,cy,TRUE);
return HOOK_CAPTURE;
#endif
}
}
break;
}
#if 0//2.99D 970330 for DEBUGWIN
case WM_DESTROY: {
// __deleteでこれを実行すると、dialog.tllが既にunloadされてる事がある
outlineClosed(text);//2.99D 970330 旧outlineClose
break;
}
#endif
#if 0//2.00E5 アウトラインが付いたり付かなかったり、ウィンドウのサイズが変わったりした
#if 1//1.99A
case WM_TXCLOSE: {
outlineClose(text);
break;
}
#else
case WM_TXQUERYCLOSE: {
outlineClose(text);
break;
}
#endif
#endif
}
return HOOK_CONTINUE;
}
//2.00B
static BOOL _fAck = FALSE;
static void txreportHandle(HWND hwnd,TXREPORT* r,BOOL fDeleted)
{
TX* text = r->text;
if (
text->fFrame &&
!text->fNoOutlineFlush//2.00E4
) {
BOOL f = FALSE;
TXRECORD n = txRecordGetCount(text->txOutline);
TXRECORD i;
for (i = 0;i < n;i++) {
HEADLINE hl;
txhRead(text,i,&hl);
if (fDeleted) {
if (hl.npara >= r->npara) {
if (hl.npara < r->npara + r->nparaCount) {
f = TRUE;
break;
}
hl.npara -= r->nparaCount;
txhWrite(text,i,&hl);
}
} else {
if (hl.npara >= r->npara) {
hl.npara += r->nparaCount;
txhWrite(text,i,&hl);
}
}
}
if (f && !_fAck) {
// これをしないと
// 次のイベントループまでに沢山WM_TXREPORTが来たとき困る
_fAck = TRUE;
PostMessage(hwnd,WM_TXREPORTACK,0,0);
}
}
}
HOOKRESULT __wndproctext(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
TX* text = textTarget;//2.94 970121
switch(message) {
case WM_RBUTTONDOWN:
case WM_LBUTTONDOWN: {
SetFocus(hwnd);
break;
}
case WM_KEYDOWN: {
if (text->hwndOutline) {
if (wParam == VK_ESCAPE && GetKeyState(VK_SHIFT) < 0) {
// SHIFT+ESC
tlSetActive(text);
return TRUE;
}
}
break;
}
case WM_TXREPORT: {//2.00B
if (_fNoTxReport || !text->hwndOutline) break;
TXREPORT* r = (LPVOID)lParam;
switch(wParam) {
case TXREPORT_TEXTBUFF_INSERT: {
txreportHandle(hwnd,r,FALSE);
break;
}
case TXREPORT_TEXTBUFF_DELETE: {
txreportHandle(hwnd,r,TRUE);
break;
}
}
break;
}
case WM_TXREPORTACK: {
_fAck = FALSE;
//2.90 いきなりtlMakeのように時間がかかる処理を始めるのは不自然。
// フラッシュはユーザの明示的な指示でがあったときだけ行なう。
break;
}
}
return FALSE;
}
__new
{
macroHookWndBase();
macroHookWndText();
}
__delete
{
}
main
{
uiTitleList(text);
}
//2.90 ファイル-再読み込みで、アウトラインもフラッシュするようにした
flush
{
if (text->hwndOutline) {
tlMake(text->outlineContext);
} else {
uiTitleList(text);
}
}
//2.00E2 outline.swをShift+Escにキー割り当てした
BOOL TXCMDBASE sw(TX* text)
{
// アウトラインウィンドウを出します。
// アウトラインウィンドウが出ているときは消します。
//{#MS} +{Esc}
//{#VZ} +{Esc}
//{#MI} +{Esc}
TX* text = txGetFrame(textf);
if (text->fOutline) {
outlineClose(text);
} else {
uiTitleList(text);
}
return TRUE;
}
void op(TX* text,int op)
{
//2.99D 970330 for WZ.EXE
switch(op) {
case OUTLINEOP_OPEN: {
uiTitleList(text);
break;
}
case OUTLINEOP_CLOSE: {
outlineClose(text);
break;
}
}
}