home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1999 March / VPR9903A.BIN / APUPDATE / VC / Tx300d / TX300D.LZH / OUTLINE.C < prev    next >
C/C++ Source or Header  |  1997-06-12  |  65KB  |  2,612 lines

  1. // WZ EDITOR 標準機能 アウトライン
  2. // Copyright 1996 TY
  3. // Thanks y.mikomeさん for title.c
  4. // Shift+Returnで見出しレベルの開閉、
  5. // Shift+Escで本文との行き来ができます。
  6.  
  7. //2.94 970121 高速オープン対応
  8. //2.99D 970331 TXCMDBASE対応
  9.  
  10. //{###編集}
  11.  
  12. #include <windows.h>
  13. #include "dialog.h"
  14.  
  15. #ifdef __FLAT__
  16. #pragma multidef+
  17. extern "comctl32.dll" {
  18.     #include "c:\msvc40\include\commctrl.h"
  19. }
  20. #pragma multidef-
  21. #endif
  22.  
  23. #export
  24. #define IDD_TITLELIST    19990
  25. #define IDD_TITLEVIEW    19991
  26. #define CON_SELCHANGED    (WM_TXUSER + 1)
  27. #endexport
  28.  
  29. #define IDD_TITLE            1000
  30. #define IDD_LEFT            1003
  31. #define IDD_RIGHT            1004
  32. #define IDD_UP                1005
  33. #define IDD_DOWN            1006
  34. #define IDD_CUT                1007
  35. #define IDD_COPY            1008
  36. #define IDD_COPYLIST        1009
  37. #define IDD_FLUSHLIST        1010
  38. #define IDD_CONFIG            1011
  39. #define IDD_CLOSE            1012
  40. #define IDD_PASTE            1013
  41. #define IDD_EDITLABEL        1014
  42. #define IDD_LABELADD        1015
  43. #define IDD_LABELCHILD        1016
  44. #define IDD_LABELINSERT        1017
  45. #define IDD_LABELNAME        1018
  46. #define IDD_SEARCH            1019
  47. #define IDD_SEARCHNEXT        1020
  48. #define IDD_LEFTWITHSUB        1021    //2.99C 970323 new
  49. #define IDD_RIGHTWITHSUB    1022    //2.99C 970323 new
  50.  
  51. #export
  52. typedef struct {
  53.     BOOL fUndisp;            // 表示しない/する
  54.     int nest;                // ネスト(0:なし)
  55.     NPARA npara;            // 行番号
  56.     mchar szstr[CCHWORD];    // 見出し文字列
  57. } HEADLINE;
  58. #endexport
  59.  
  60. static void txhSetLast(TX* text,HEADLINE* hl)
  61. {
  62.     memset(hl,0,sizeof(HEADLINE));
  63.     {
  64.         NPARA npara = text->npara;
  65.         txSetUndisp(text);
  66.         txJumpFileEnd(text);
  67.         hl->npara = text->npara;
  68.         txJumpPara(text,npara);
  69.         txSetDisp(text);
  70.     }
  71. }
  72.  
  73. #define txhAdd(text,hl)            txRecordAdd(text->txOutline,hl)
  74. #define txhDel(text,ihl)        txRecordDelete(text->txOutline,ihl,1)
  75. #define txhWrite(text,ihl,hl)    txRecordWrite(text->txOutline,ihl,hl)
  76. #define txhInsert(text,ihi,hl)    {txRecordInsert(text->txOutline,ihi,1);txRecordWrite(text->txOutline,ihi,hl);}
  77. #define txhGetCount(text)        txRecordGetCount(text->txOutline)
  78.  
  79. static BOOL txhRead(TX* text,TXRECORD ihl,HEADLINE* hl)
  80. {
  81.     TXRECORD n = txRecordGetCount(text->txOutline);
  82.     if (ihl < n) {
  83.         return txRecordRead(text->txOutline,ihl,hl);
  84.     }
  85.     // EOF
  86.     txhSetLast(text,hl);
  87.     return TRUE;
  88. }
  89.  
  90. static void txhInit(TX* text)
  91. {
  92.     if (text->txOutline == NULL) {
  93.         text->txOutline = malloc(sizeof(TX));
  94.         txInitText(text->txOutline);
  95.         txOpenTextBinary(text->txOutline,NULL,sizeof(HEADLINE),0);
  96.         if (text->fFrame) text->fReport++;
  97.     }
  98. }
  99.  
  100. static void txhTerm(TX* text)
  101. {
  102.     if (text->txOutline) {
  103.         txClose(text->txOutline);
  104.         free(text->txOutline);
  105.         text->txOutline = NULL;
  106.         if (text->fFrame) text->fReport--;
  107.     }
  108. }
  109.  
  110. static void txhReset(TX* text)
  111. {
  112.     txhTerm(text);
  113.     txhInit(text);
  114. }
  115.  
  116. static int _nestDispMax = 6;
  117.  
  118. #define WINDOW_V    0    // 縦割り
  119. #define WINDOW_H    1    // 横割り
  120. #define WINDOW_HV    2    // 浮動
  121. permanent int p_modeWindow = WINDOW_V;    //2.99D 970330 旧modeWindow
  122. permanent BOOL fSmallFont = FALSE;
  123. permanent int lcxTitleListV = 30;
  124. permanent int lcyTitleListH = 10;
  125. permanent int lcxTitleList = 60;
  126. permanent int lcyTitleList = 10;
  127. permanent BOOL fExtendTextWindow = TRUE;
  128. static BOOL _fFlushWindow;
  129. static BOOL _fModeress = TRUE;
  130.  
  131. static TXRECORD txrecordFromNpara(TX* text,NPARA npara)
  132. {
  133.     TXRECORD n = txRecordGetCount(text->txOutline);
  134.     TXRECORD i;
  135.     for (i = 0;i < n;i++) {
  136.         HEADLINE hl;
  137.         txRecordRead(text->txOutline,i,&hl);
  138.         if (npara == hl.npara) return i;
  139.         if (npara < hl.npara) return i - 1;
  140.     }
  141.     if (n == 0) return TXRECORD_ERROR;
  142.     return n - 1;
  143. }
  144.  
  145. static int ilistFromTxrecord(TX* text,TXRECORD irecord)
  146. {
  147.     if (irecord == TXRECORD_ERROR) return LB_ERR;
  148.     TXRECORD i;
  149.     int j = -1;
  150.     
  151.     for (i = 0;i <= irecord;i++) {
  152.         HEADLINE hl;
  153.         txRecordRead(text->txOutline,i,&hl);
  154.         if (!hl.fUndisp && hl.nest < _nestDispMax + 2) {
  155.             j++;
  156.         }
  157.     }
  158.     return j;
  159. }
  160.  
  161. static TXRECORD ilistToTxrecord(TX* text,int ilist)
  162. {
  163.     TXRECORD i;
  164.     int j = -1;
  165.     
  166.     for (i = 0;j < ilist;i++) {
  167.         HEADLINE hl;
  168.         txRecordRead(text->txOutline,i,&hl);
  169.         if (!hl.fUndisp && hl.nest < _nestDispMax + 2) {
  170.             j++;
  171.         }
  172.     }
  173.     return i - 1;
  174. }
  175.  
  176. static TXHIGH BOOL JumpPara(TX* text,NPARA npara)
  177. {
  178.     txJumpFileTop(text);
  179.     while(1) {
  180.         if (text->npara == npara) return TRUE;
  181.         if (!txNextPara(text)) break;
  182.     }
  183.     return FALSE;
  184. }
  185.  
  186. static void tlFromHl(CHOOSEOUTLINE* context)
  187. {
  188.     TX* text = context->text;
  189.     if (context->fUndisp) return;
  190.     HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
  191.     TXRECORD n = txRecordGetCount(text->txOutline);
  192.     TXRECORD i;
  193.     if (context->textTree) {//2.90 
  194.         TX* text = context->textTree;
  195.         int nest0 = 0;
  196.         txDeleteText(text);
  197.         for (i = 0;i < n;i++) {
  198.             HEADLINE hl;
  199.             txhRead(context->text,i,&hl);
  200. #if 0
  201.             //
  202.             if (hl.nest >= nest0 + 2) {
  203.                 int n = hl.nest - nest0 - 1;
  204.                 int nest = nest0+1;
  205.                 while(n--) {
  206.                     txInsertChar(text,nest + '0');
  207.                     txInsert(text,"(見出しなし)");
  208.                     txInsertChar(text,0);
  209.                     txInsertChar(text,'1');    // fNotExistTitle
  210.                     txInsertReturn(text);
  211.                     nest++;
  212.                 }
  213.             }
  214. #endif
  215.             //
  216.             txInsertChar(text,hl.nest + '0');
  217.             txInsert(text,hl.szstr);
  218.             txInsertChar(text,0);
  219.             txInsertChar(text,'0');    // fNotExistTitle
  220.             txInsertReturn(text);
  221.             //
  222.             nest0 = hl.nest;
  223.         }
  224.         dialogWriteItem(dialogFromHwnd(context->hwnd),IDD_TITLELIST);
  225.     } else {
  226.         SendMessage(hctrl,LB_RESETCONTENT,0,0);
  227.         for (i = 0;i < n;i++) {
  228.             HEADLINE hl;
  229.             txhRead(text,i,&hl);
  230.             if (!hl.fUndisp && hl.nest < _nestDispMax + 2) {
  231.                 mchar buff[CCHLINE];
  232.                 int l;
  233.                 if (context->modeWindow == WINDOW_V) {
  234.                     l = (hl.nest - 1) * 1;
  235.                 } else {
  236.                     l = (hl.nest - 1) * 4;
  237.                 }
  238.                 memset(buff,' ',l);
  239.                 if (!context->fNoTitleHead) {
  240.                     HEADLINE hl1;
  241.                     txhRead(text,i+1,&hl1);
  242.                     strcpy(buff + l,"・");l += 2;
  243.                     if (hl1.fUndisp) {
  244.                         buff[l++] = '+';
  245.                     }
  246.                 }
  247.                 strcpymax(buff + l,hl.szstr,CCHLINE - l);
  248.                 SendMessage(hctrl,LB_ADDSTRING,0,(LPARAM)buff);
  249.             }
  250.         }
  251.     }
  252. }
  253.  
  254. static TXRECORD tlGetNow(CHOOSEOUTLINE* context)
  255. {
  256.     HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
  257.     if (context->textTree) {//2.90 
  258.         #ifdef __FLAT__
  259.         TV_ITEM tvi;
  260.         structClear(tvi);
  261.         if (context->fDragging) {
  262.             tvi.hItem = context->hDragItem;
  263.         } else {
  264.             tvi.hItem = TreeView_GetSelection(hctrl);
  265.         }
  266.         TreeView_GetItem(hctrl,&tvi);
  267.         if (tvi.lParam > 0) {
  268.             return tvi.lParam - 1;
  269.         }
  270.         #endif
  271.     } else {
  272.         int i = SendMessage(hctrl,LB_GETCURSEL,0,0);
  273.         if (i != LB_ERR) {
  274.         #if 1
  275.             return ilistToTxrecord(context->text,i);
  276.         #else
  277.             return i;
  278.         #endif
  279.         }
  280.     }
  281.     return TXRECORD_ERROR;
  282. }
  283.  
  284. #ifdef __FLAT__
  285. static TXRECORD tvhGetParam(HWND hctrl,HTREEITEM h)
  286. {
  287.     if (h) {
  288.         TV_ITEM tvi;
  289.         structClear(tvi);
  290.         tvi.hItem = h;
  291.         TreeView_GetItem(hctrl,&tvi);
  292.         if ((long)tvi.lParam < 0) {
  293.             return -tvi.lParam - 1;
  294.         } else {
  295.             return tvi.lParam - 1;
  296.         }
  297.     }
  298.     return TXRECORD_ERROR;
  299. }
  300.  
  301. static int treeviewGetNest(HWND hctrl,HTREEITEM h)
  302. {
  303.     int nest = 0;
  304.     while(1) {
  305.         h = TreeView_GetParent(hctrl,h);
  306.         if (!h) break;
  307.         nest++;
  308.     }
  309.     return nest;
  310. }
  311.  
  312. static TXRECORD tlGetNowEx(CHOOSEOUTLINE* context)
  313. {
  314.     TXRECORD i = tlGetNow(context);
  315.     if (i != TXRECORD_ERROR) return i;
  316.     HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
  317.     if (context->textTree) {
  318.         return tvhGetParam(hctrl,TreeView_GetSelection(hctrl));
  319.     }
  320.     return TXRECORD_ERROR;
  321. }
  322. #endif
  323.  
  324. static void FlushLeftRight(CHOOSEOUTLINE* context);
  325.  
  326. static void tlSetNow(CHOOSEOUTLINE* context,TXRECORD i)
  327. {
  328.     TX* text = context->text;
  329.     HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
  330.     if (context->textTree) {//2.90 
  331. #ifdef __FLAT__
  332.         if (context->fUndisp) return;
  333.         int lParam = i + 1;
  334.         // まず、カレントが一致するか調べる
  335.         HTREEITEM h;
  336.         TV_ITEM tvi;
  337.         structClear(tvi);
  338.         tvi.hItem = h = TreeView_GetSelection(hctrl);
  339.         TreeView_GetItem(hctrl,&tvi);
  340.         if (tvi.lParam != lParam) {
  341.             h = treeviewSearchParam(hctrl,lParam);
  342.         }
  343.         if (h) {
  344.             TreeView_SelectItem(hctrl,h);
  345.         }
  346. #endif
  347.     } else {
  348.         SendMessage(hctrl,LB_SETCURSEL,ilistFromTxrecord(text,i),0);
  349.     }
  350.     FlushLeftRight(context);//1.99A 
  351. }
  352.  
  353. static BOOL tlIsEditable(CHOOSEOUTLINE* context)
  354. {
  355. //2.99D 970331 アウトラインの情報が古いとアウトラインのツリーで入れ替えなどをおこなうと
  356. // 思わぬ編集結果を招く危険があるので、チェックするようにした
  357.     if (!context->fOutlineStd) return TRUE;//3.00B1 970612 慣用句の挿入で、編集してOKすると「アウトラインを再作成してから実行してください」と表示された
  358.     if (context->nEdit == context->text->nEdit) return TRUE;
  359.     information("アウトラインを再作成してから実行してください");
  360.     return FALSE;
  361. }
  362.  
  363. static void tlSetEditable(CHOOSEOUTLINE* context)
  364. {
  365. //2.99D 970331
  366.     context->nEdit = context->text->nEdit;
  367. }
  368.  
  369. static int tlMakePrim(CHOOSEOUTLINE* context)
  370. {
  371.     TX* text = context->text;
  372.     int ret = 0;
  373.     txhReset(text);
  374.     txSetUndispEx(text);
  375.     txJumpFileTop(text);
  376.     txSetHigh(text);
  377.     {
  378.         txstr szline;
  379.         PARAATR paraatr;
  380.         while(1) {
  381.             INT lch;
  382.             int lchTop = txParaatrRead(text,¶atr,&lch);
  383.             if (paraatr.modeTitle) {
  384.                 txGetPara(text,szline);
  385.                 mchar* psz = &szline[lchTop];
  386.                 HEADLINE hl;
  387.                 memset(&hl,0,sizeof(HEADLINE));
  388.                 hl.npara = text->npara;
  389.                 hl.nest = paraatr.modeTitle;
  390.                 if (lch == -1) {
  391.                     strcpymax(hl.szstr,psz,CCHWORD);
  392.                 } else {
  393.                     strcpylenmax(hl.szstr,psz,lch,CCHWORD);
  394.                 }
  395.                 txhAdd(text,&hl);
  396.             }
  397.             if (!txNextPara(text)) break;
  398.         }
  399.     }
  400.     txJumpFileTop(text);
  401.     txResetHigh(text);
  402.     txSetDispEx(text);
  403.     context->nEdit = text->nEdit;//2.99D 970331 
  404.     return ret;
  405. }
  406.  
  407. static int tlMake(CHOOSEOUTLINE* context)
  408. {
  409.     TX* text = context->text;
  410.     int ret = tlMakePrim(context);
  411.     if (!context->fUndisp) {
  412.         tlFromHl(context);
  413.         tlSetNow(context,txrecordFromNpara(text,text->npara));
  414.     }
  415.     return ret;
  416. }
  417.  
  418. static mchar* GetTitleString(TX* text,int modeTitle)
  419. {
  420.     if (1 <= modeTitle) {
  421.         if (modeTitle <= SZTITLE_N) {
  422.             return text->tsztitle[modeTitle - 1];
  423.         }
  424.         if (modeTitle <= HEAD_N) {
  425.             return text->tszformat[modeTitle - SZTITLE_N - 1 + SZFORMAT_TITLE4];
  426.         }
  427.     }
  428.     return NULL;
  429. }
  430.  
  431. static void myEnableWindow(HWND hwnd,BOOL f)
  432. {
  433.     if (hwnd) EnableWindow(hwnd,f);
  434. }
  435.  
  436. static void FlushLeftRight(CHOOSEOUTLINE* context)
  437. {
  438.     TX* text = context->text;
  439.     TXRECORD i = tlGetNow(context);
  440.     if (i != TXRECORD_ERROR) {
  441.         HEADLINE hl;
  442.         txhRead(text,i,&hl);
  443.         //
  444.         mchar* sztitle = GetTitleString(text,hl.nest);
  445.         BOOL fEnable = !(sztitle && sztitle[0] == '^');    // 正規表現でなければ...
  446.         myEnableWindow(GetDlgItem(context->hwnd,IDD_LEFT),fEnable);
  447.         myEnableWindow(GetDlgItem(context->hwnd,IDD_RIGHT),fEnable);
  448.     }
  449. }
  450.  
  451. static BOOL tlJump(CHOOSEOUTLINE* context)
  452. {
  453.     TX* text = context->text;
  454.     TXRECORD i = tlGetNow(context);
  455.     if (i != TXRECORD_ERROR) {
  456.         HEADLINE hl;
  457.         txhRead(text,i,&hl);
  458. #if 1//1.99A 使いやすく
  459.         text->fUndisp++;//2.95 970129 txSetUndisp(text);から変更。マウスがチラチラする
  460.         if (text->hwndtext2) {
  461.             //2.95 970129 新多重化対応 SetFocusしてあげないと、txJumpParaによる位置変更が効かない
  462.             HWND hwnd = SetFocus(text->hwndtext);
  463.             txJumpPara(text,hl.npara);
  464.             txSetLy(text,1);
  465.             SetFocus(hwnd);
  466.         } else {
  467.             txJumpPara(text,hl.npara);
  468.             txSetLy(text,1);
  469.         }
  470.         txSetDisp(text);
  471. #else
  472.         txJumpPara(text,hl.npara);
  473. #endif
  474.         FlushLeftRight(context);//1.99A 
  475.         return TRUE;
  476.     }
  477.     return FALSE;
  478. }
  479.  
  480. static TXRECORD txhGetPrev(tx* text,TXRECORD ihl,HEADLINE* hl,HEADLINE* _hl0)
  481. {
  482.     int nest = hl->nest;
  483.     while(ihl > 0) {
  484.         HEADLINE hl0;
  485.         ihl--;
  486.         txhRead(text,ihl,&hl0);
  487.         if (hl0.nest <= nest) {
  488.             *_hl0 = hl0;
  489.             return ihl;
  490.         }
  491.     }
  492.     return TXRECORD_ERROR;
  493. }
  494.  
  495. static TXRECORD txhGetNext(TX* text,TXRECORD ihl,HEADLINE* hl,HEADLINE* _hl1)
  496. {
  497.     TXRECORD n = txRecordGetCount(text->txOutline);
  498.     int nest = hl->nest;
  499.     while(ihl + 1 < n) {
  500.         HEADLINE hl1;
  501.         ihl++;
  502.         txhRead(text,ihl,&hl1);
  503.         if (hl1.nest <= nest) {
  504.             *_hl1 = hl1;
  505.             return ihl;
  506.         }
  507.     }
  508.     txhSetLast(text,_hl1);
  509.     return n;
  510. }
  511.  
  512. static void hlExchange(TX* text,TXRECORD i0,TXRECORD i,TXRECORD i1,HEADLINE* hl0,HEADLINE* hl,HEADLINE* hl1)
  513. {
  514.     NPARA nparaD = hl->npara - hl0->npara;
  515.     TXRECORD j = i0;
  516.     TXRECORD ii;
  517.     for (ii = i;ii < i1;ii++,j++) {
  518.         HEADLINE hl;
  519.         txhRead(text,ii,&hl);
  520.         txhDel(text,ii);
  521.         txRecordInsert(text->txOutline,j,1);
  522.         hl.npara -= nparaD;
  523.         txhWrite(text,j,&hl);
  524.     }
  525.     {
  526.         NPARA nparaD = hl1->npara - hl->npara;
  527.         for (ii = i0 + (i1 - i);ii < i1;ii++) {
  528.             HEADLINE hl;
  529.             txhRead(text,ii,&hl);
  530.             hl.npara += nparaD;
  531.             txhWrite(text,ii,&hl);
  532.         }
  533.     }
  534. }
  535.  
  536. static BOOL tlUp(CHOOSEOUTLINE* context)
  537. {
  538.     if (!tlIsEditable(context)) return FALSE;//2.99D 970331 
  539.     TX* text = context->text;
  540.     TXRECORD i = tlGetNow(context);
  541.     if (i != TXRECORD_ERROR && i > 0) {
  542.         TXRECORD i0 = i;
  543.         txSetUndisp(text);
  544.         do {
  545.             HEADLINE hl;
  546.             HEADLINE hl0;
  547.             HEADLINE hl1;
  548.             TXRECORD i1;
  549.             //
  550.             txhRead(text,i,&hl);
  551.             i0 = txhGetPrev(text,i,&hl,&hl0);
  552.             if (i0 == TXRECORD_ERROR) {
  553.                 i0 = i;
  554.                 break;
  555.             }
  556.             i1 = txhGetNext(text,i,&hl,&hl1);
  557.             //
  558.             txJumpPara(text,hl.npara);
  559.             txSelectEx(text,CLIP_PARA);
  560.             txJumpPara(text,hl1.npara);
  561.             txSelectTsPushDelete(text);
  562.             //
  563.             txJumpPara(text,hl0.npara);
  564.             txTsPop(text);
  565.             //
  566.             hlExchange(text,i0,i,i1,&hl0,&hl,&hl1);
  567.             //
  568.             tlFromHl(context);
  569.         } while(0);
  570.         txSetDisp(text);
  571.         tlSetNow(context,i0);
  572.         tlSetEditable(context);//2.99D 970331 
  573.         return TRUE;
  574.     }
  575.     return FALSE;
  576. }
  577.  
  578. static BOOL tlDown(CHOOSEOUTLINE* context)
  579. {
  580.     if (!tlIsEditable(context)) return FALSE;//2.99D 970331 
  581.     TX* text = context->text;
  582.     TXRECORD i = tlGetNow(context);
  583.     TXRECORD n = txRecordGetCount(text->txOutline);
  584.     if (i != TXRECORD_ERROR && i + 1 < n) {
  585.         TXRECORD i1 = i;
  586.         txSetUndisp(text);
  587.         {
  588.             HEADLINE hl;
  589.             HEADLINE hl1;
  590.             HEADLINE hl2;
  591.             TXRECORD i2;
  592.             //
  593.             txhRead(text,i,&hl);
  594.             i1 = txhGetNext(text,i,&hl,&hl1);
  595.             i2 = txhGetNext(text,i1,&hl,&hl2);
  596.             //
  597.             txJumpPara(text,hl.npara);
  598.             txSelectEx(text,CLIP_PARA);
  599.             txJumpPara(text,hl1.npara);
  600.             txSelectTsPushDelete(text);
  601.             //
  602.             NPARA nparaDst = hl2.npara - (hl1.npara - hl.npara);
  603.             txJumpPara(text,nparaDst);
  604.             txTsPop(text);
  605.             //
  606.             hlExchange(text,i,i1,i2,&hl,&hl1,&hl2);
  607.             //
  608.             tlFromHl(context);
  609.             i1 = i + i2 - i1;
  610.         }
  611.         txSetDisp(text);
  612.         tlSetNow(context,i1);
  613.         tlSetEditable(context);//2.99D 970331 
  614.         return TRUE;
  615.     }
  616.     return FALSE;
  617. }
  618.  
  619. static BOOL tlCut(CHOOSEOUTLINE* context,BOOL fCut)
  620. {
  621. // fCut=0: Copy
  622. // fCut=1: CopyDelete
  623. // fCut=2: Delete
  624. // fCut=3: Copy
  625. // else    hctrl
  626.     if (!tlIsEditable(context)) return FALSE;//2.99D 970331 
  627.     TX* text = context->text;
  628.     TXRECORD i = tlGetNow(context);
  629.     if (i != TXRECORD_ERROR) {
  630.         txSetUndisp(text);
  631.         {
  632.             HEADLINE hl;
  633.             txhRead(text,i,&hl);
  634.             HEADLINE hl1;
  635.             int i1 = txhGetNext(text,i,&hl,&hl1);
  636.             //
  637.             txJumpPara(text,hl.npara);
  638.             if (fCut >= 4) {
  639.                 HWND hctrl = (HWND)fCut;
  640.                 SendMessage(hctrl,LB_RESETCONTENT,0,0);
  641.                 NPARA npara;
  642.                 txstr szstr;
  643.                 txstr szstr2;
  644. //information("%d %d",hl.npara, hl1.npara);
  645.                 for (npara = hl.npara;npara < hl1.npara;npara++) {
  646.                     txGetPara(text,szstr);
  647.                     reReplace(szstr2,CCHWORD,szstr,\"\t",\" ",SEARCH_ALL);
  648.                     SendMessage(hctrl,LB_ADDSTRING,0,(LPARAM)(mchar*)szstr2);
  649.                     txNextPara(text);
  650.                 }
  651.             } else {
  652.                 txSelectEx(text,CLIP_PARA);
  653.                 txJumpPara(text,hl1.npara);
  654.                 if (fCut == 3) {//2.92 
  655.                     txSelectCopyQuit(text);
  656.                     txJumpPara(text,hl.npara);
  657.                     if (hl.npara + 1 == hl1.npara) {
  658.                         // 本文が空の場合は、見出しを本文としてCopy
  659.                         TX _text;
  660.                         TX* text = &_text;
  661.                         txInit(text,NULL);
  662.                         txPaste(text);
  663.                         txInsert(text,hl.szstr);
  664.                         txInsertReturn(text);
  665.                         txJumpFileTop(text);
  666.                         txSelectEx(text,CLIP_PARA);
  667.                         txJumpFileEnd(text);
  668.                         txSelectCopyQuit(text);
  669.                         txClose(text);
  670.                     }
  671.                 } else if (fCut) {
  672.                     if (fCut == 2) {
  673.                         txSelectDelete(text);
  674.                     } else {
  675.                         txSelectCopyDelete(text);
  676.                     }
  677.                     //
  678.                     {
  679.                         NPARA nparaD = hl1.npara - hl.npara;
  680.                         txRecordDelete(text->txOutline,i,i1 - i);
  681.                         //
  682.                         TXRECORD n = txRecordGetCount(text->txOutline);
  683.                         int ii;
  684.                         for (ii = i;ii < n;ii++) {
  685.                             txhRead(text,ii,&hl);
  686.                             hl.npara -= nparaD;
  687.                             txhWrite(text,ii,&hl);
  688.                         }
  689.                     }
  690.                 } else {
  691.                     txSelectCopyQuit(text);
  692.                     txJumpPara(text,hl.npara);
  693.                 }
  694.             }
  695.         }
  696.         txSetDisp(text);
  697.         if (fCut == 1) {
  698.             // カット時のみ実行
  699.             // 置換リストなどでちらついた
  700.             tlFromHl(context);
  701.             tlSetNow(context,txrecordFromNpara(text,text->npara));
  702.         }
  703.         tlSetEditable(context);//2.99D 970331 
  704.         return TRUE;
  705.     }
  706.     return FALSE;
  707. }
  708.  
  709. static BOOL tlPaste(CHOOSEOUTLINE* context)
  710. {
  711.     if (!tlIsEditable(context)) return FALSE;//2.99D 970331 
  712.     TX* text = context->text;
  713.     TXRECORD i = tlGetNow(context);
  714.     if (i != TXRECORD_ERROR) {
  715.         txSetUndisp(text);
  716.         {
  717.             HEADLINE hl;
  718.             txhRead(text,i,&hl);
  719.             txJumpPara(text,hl.npara);
  720.             txPaste(text);
  721.             txJumpPara(text,hl.npara);
  722.         }
  723.         txSetDisp(text);
  724.         tlSetEditable(context);//2.99D 970331 
  725.         return TRUE;
  726.     }
  727.     return FALSE;
  728. }
  729.  
  730. static BOOL tlMove(TX* text,TXRECORD ii,BOOL fLeft,BOOL fExec)
  731. {
  732. //2.99C 970323 new
  733.     HEADLINE hl;
  734.     BOOL f = FALSE;
  735.     txhRead(text,ii,&hl);
  736.     txJumpPara(text,hl.npara);
  737.     //
  738.     PARAATR paraatr;
  739.     txParaatrRead(text,¶atr,NULL);
  740.     if (fLeft) {
  741.         if (paraatr.modeTitle >= 2) {
  742.             f = TRUE;
  743.             paraatr.modeTitle = paraatr.modeTitle - 1;
  744.             hl.nest--;
  745.         }
  746.     } else {
  747.         if (paraatr.modeTitle < 6) {
  748.             f = TRUE;
  749.             paraatr.modeTitle = paraatr.modeTitle + 1;
  750.             hl.nest++;
  751.         }
  752.     }
  753.     if (f && fExec) {
  754.         txParaatrWrite(text,¶atr);
  755.         txhWrite(text,ii,&hl);
  756.     }
  757.     return f;
  758. }
  759.  
  760. static BOOL _tlLeft(CHOOSEOUTLINE* context,BOOL fLeft,BOOL fMoveSub)
  761. {
  762. //2.99C 970323 fMoveSub:子も移動
  763.     if (!tlIsEditable(context)) return FALSE;//2.99D 970331 
  764.     TX* text = context->text;
  765.     TXRECORD i = tlGetNow(context);
  766.     if (i != TXRECORD_ERROR) {
  767.         BOOL fEdit = FALSE;
  768.         HEADLINE hl;
  769.         txhRead(text,i,&hl);
  770.         //
  771.         HEADLINE hl1;
  772.         TXRECORD i1;
  773.         i1 = txhGetNext(text,i,&hl,&hl1);
  774.         //
  775.         txSetUndisp(text);
  776. #if 1//2.99C 970323 
  777.         BOOL fOK = TRUE;
  778.         if (fMoveSub) {
  779.             // 最初に実行できるかどうかチェックする
  780.             for (TXRECORD ii = i;ii < i1;ii++) {
  781.                 if (!tlMove(text,ii,fLeft,FALSE)) {
  782.                     fOK = FALSE;
  783.                     break;
  784.                 }
  785.             }
  786.         } else {
  787.             i1 = i + 1;
  788.             if (!tlMove(text,i,fLeft,FALSE)) fOK = FALSE;
  789.         }
  790.         if (fOK) {
  791.             fEdit = TRUE;
  792.             for (TXRECORD ii = i;ii < i1;ii++) {
  793.                 tlMove(text,ii,fLeft,TRUE);
  794.             }
  795.         } else {
  796.             information("これ以上見出しレベルを動かせません");
  797.         }
  798. #else
  799.         TXRECORD ii = i;
  800. //        for (ii = i;ii < i1;ii++) {// 複数項目まとめるのはあまりうまくいかない
  801.             BOOL f = FALSE;
  802.             txhRead(text,ii,&hl);
  803.             txJumpPara(text,hl.npara);
  804.             //
  805.             PARAATR paraatr;
  806.             txParaatrRead(text,¶atr,NULL);
  807.             if (fLeft) {
  808.                 if (paraatr.modeTitle >= 2) {
  809.                     f = TRUE;
  810.                     paraatr.modeTitle = paraatr.modeTitle - 1;
  811.                     hl.nest--;
  812.                 }
  813.             } else {
  814.                 if (paraatr.modeTitle < 6) {
  815.                     f = TRUE;
  816.                     paraatr.modeTitle = paraatr.modeTitle + 1;
  817.                     hl.nest++;
  818.                 }
  819.             }
  820.             if (f) {
  821.                 fEdit = TRUE;
  822.                 txParaatrWrite(text,¶atr);
  823.                 txhWrite(text,ii,&hl);
  824.             }
  825. //        }
  826. #endif
  827.         txSetDisp(text);
  828.         if (fEdit) {
  829.             tlFromHl(context);
  830.             tlSetNow(context,i);
  831.         }
  832.         tlSetEditable(context);//2.99D 970331 
  833.         return TRUE;
  834.     }
  835.     return FALSE;
  836. }
  837.  
  838. static BOOL tlLeft(CHOOSEOUTLINE* context)
  839. {
  840.     return _tlLeft(context,TRUE,FALSE);
  841. }
  842.  
  843. static BOOL tlRight(CHOOSEOUTLINE* context)
  844. {
  845.     return _tlLeft(context,FALSE,FALSE);
  846. }
  847.  
  848. static BOOL tlLeftWithSub(CHOOSEOUTLINE* context)
  849. {
  850. //2.99C 970323 new
  851.     return _tlLeft(context,TRUE,TRUE);
  852. }
  853.  
  854. static BOOL tlRightWithSub(CHOOSEOUTLINE* context)
  855. {
  856. //2.99C 970323 new
  857.     return _tlLeft(context,FALSE,TRUE);
  858. }
  859.  
  860. permanent int x,y;//ウィンドウ位置を覚える
  861. permanent BOOL fWindowPos;
  862. static BOOL _fNoTxReport;
  863.  
  864. static void close(TX* text,HWND hwnd,BOOL fClose)
  865. {
  866.     text->fOutline = FALSE;//1.99C 
  867.     if (text->outlineContext->modeWindow != WINDOW_HV) {
  868.         _fFlushWindow = TRUE;
  869.         PostMessage(text->hwndbase,WM_TXFLUSHWINDOWSIZE,0,0);
  870.         SetFocus(text->hwndtext);
  871.     }
  872.     if (fClose) {
  873.         SendMessage(hwnd,WM_CLOSE,0,0);
  874.     } else {
  875.         PostMessage(hwnd,WM_CLOSE,0,0);
  876.     }
  877. }
  878.  
  879. static void tlFlushListview(CHOOSEOUTLINE* context)
  880. {
  881.     tlCut(context,(BOOL)GetDlgItem(context->hwnd,IDD_TITLEVIEW));
  882.     SendMessage(context->hwnd,CON_SELCHANGED,0,0);
  883. }
  884.  
  885. static void tlOpenClose(CHOOSEOUTLINE* context)
  886. {
  887.     TX* text = context->text;
  888.     HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
  889.     int itop = SendMessage(hctrl,LB_GETTOPINDEX,0,0);
  890.     int isel = SendMessage(hctrl,LB_GETCURSEL,0,0);
  891.     TXRECORD i = tlGetNow(context);
  892.     if (i != TXRECORD_ERROR) {
  893.         int i0 = i;
  894.         HEADLINE hl0;
  895.         txhRead(text,i,&hl0);
  896.         //
  897.         HEADLINE hl;
  898.         txhRead(text,i+1,&hl);
  899.         BOOL fUndisp = !hl.fUndisp;
  900.         //
  901.         TXRECORD n = txRecordGetCount(text->txOutline);
  902.         for (i++;i < n;i++) {
  903.             HEADLINE hl;
  904.             txhRead(text,i,&hl);
  905.             if (hl.nest <= hl0.nest) break;
  906.             hl.fUndisp = fUndisp;
  907.             txhWrite(text,i,&hl);
  908.         }
  909.         //
  910.         tlFromHl(context);
  911.         // これでも駄目みたい
  912.         SendMessage(hctrl,LB_SETTOPINDEX,itop,0);
  913.         SendMessage(hctrl,LB_SETCURSEL,isel,0);
  914. ///        tlSetNow(text,context,i0);
  915.     }
  916. }
  917.  
  918. static BOOL ExtendWindow(TX* text,HWND hwnd,RECT* rClose)
  919. {
  920.     text->cxOutline = 0;//2.00E5
  921.     if (text->outlineContext->modeWindow == WINDOW_V && fExtendTextWindow) {
  922.         RECT r;
  923.         GetWindowRect(text->hwndbase,&r);
  924.         RECT r2;
  925.         if (rClose) {
  926.             r2.right = -rClose->right;
  927.         } else {
  928.             GetClientRect(hwnd,&r2);
  929.             text->cxOutline = r2.right;//2.00E5 
  930.         }
  931.         int cx = r.right - r.left + r2.right;
  932.         int cy = r.bottom - r.top;
  933.         MoveWindow(text->hwndbase,r.left,r.top,cx,cy,TRUE);
  934.         return TRUE;
  935.     } else {
  936.         if (rClose) {
  937.             //2.00B "縦割り時に変化しない"をオフにするとアウトラインウィンドウを閉じても画面表示に反映されなかった
  938.             SendMessage(text->hwndbase,WM_TXFLUSHWINDOWSIZE,0,0);
  939.         }
  940.         return FALSE;
  941.     }
  942. }
  943.  
  944. static void _outlineClose(TX* text,BOOL fClosed)
  945. {
  946. //2.99D 970330 new
  947.     if (text->hwndOutline) {
  948.         HWND hwnd = text->hwndOutline;
  949.         if (!text->fDestorying && text->fOpen/*2.99D*/) {
  950.             SetFocus(text->hwndtext);//2.00B 
  951.         }
  952.         RECT r2;
  953.         GetClientRect(hwnd,&r2);
  954.         if (fClosed) {
  955.             dialogUnlink(hwnd);
  956.         } else {
  957.             // DestroyWindowはdialogFreeがしてくれる。
  958.             dialogFree(hwnd);// これしないとそのうち開かなくなっちゃう
  959.         }
  960.         text->hwndOutline = NULL;
  961. #if 1//2.99D 970330 
  962.         text->fOutline = FALSE;
  963. #else
  964.         if (!text->fDestorying) {
  965.             //2.94 970121 破棄中は、fOutlineを変更しない。forプロファイルセーブ
  966.             text->fOutline = FALSE;//1.99C 
  967.         }
  968. #endif
  969. #if 0    //2.99D 970330 位置移動
  970.         {
  971.             CHOOSEOUTLINE* oc = text->outlineContext;
  972.             if (oc) {
  973.                 if (oc->textTree) {//2.90 
  974.                     txClose(oc->textTree);
  975.                     oc->textTree = NULL;
  976.                 }
  977.                 free(oc);
  978.                 text->outlineContext = NULL;
  979.             }
  980.         }
  981. #endif
  982.         //
  983.         if (text->fDestorying && text->fOpen/*2.99D*/) {
  984.             //2.99D 970330 for DEBUGWIN err
  985.         } else {
  986.             ExtendWindow(text,hwnd,&r2);
  987.         }
  988.         //2.99D 970330 last
  989.         {
  990.             CHOOSEOUTLINE* oc = text->outlineContext;
  991.             if (oc) {
  992.                 if (oc->textTree) {//2.90 
  993.                     txClose(oc->textTree);
  994.                     oc->textTree = NULL;
  995.                 }
  996.                 free(oc);
  997.                 text->outlineContext = NULL;
  998.             }
  999.         }
  1000.     }
  1001. }
  1002.  
  1003. static void outlineClosed(TX* text)
  1004. {
  1005. //2.99D 970330 new for DEBUGWIN err
  1006.     _outlineClose(text,TRUE);
  1007. }
  1008.  
  1009. static void outlineClose(TX* text)
  1010. {
  1011. #if 1//2.99D 970330 
  1012.     _outlineClose(text,FALSE);
  1013. #else
  1014.     if (text->hwndOutline) {
  1015.         HWND hwnd = text->hwndOutline;
  1016.         if (!text->fDestorying) {
  1017.             SetFocus(text->hwndtext);//2.00B 
  1018.         }
  1019.         RECT r2;
  1020.         GetClientRect(hwnd,&r2);
  1021.         //
  1022.         DestroyWindow(hwnd);
  1023.         dialogFree(hwnd);//1.95 これしないとそのうち開かなくなっちゃう
  1024.         text->hwndOutline = NULL;
  1025.         if (!text->fDestorying) {
  1026.             //2.94 970121 破棄中は、fOutlineを変更しない。forプロファイルセーブ
  1027.             text->fOutline = FALSE;//1.99C 
  1028.         }
  1029.         //
  1030.         {
  1031.             CHOOSEOUTLINE* oc = text->outlineContext;
  1032.             if (oc) {
  1033.                 if (oc->textTree) {//2.90 
  1034.                     txClose(oc->textTree);
  1035.                     oc->textTree = NULL;
  1036.                 }
  1037.                 free(oc);
  1038.                 text->outlineContext = NULL;
  1039.             }
  1040.         }
  1041.         //
  1042.         ExtendWindow(text,hwnd,&r2);
  1043.     }
  1044. #endif
  1045. }
  1046.  
  1047. #ifdef __FLAT__
  1048. static void BeginDrag(CHOOSEOUTLINE* context,NM_TREEVIEW* tvn)
  1049. {
  1050.     HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
  1051.     HIMAGELIST hDragImage = TreeView_CreateDragImage(hctrl,tvn->itemNew.hItem);
  1052.     RECT rcItem;
  1053.     TreeView_GetItemRect(hctrl,tvn->itemNew.hItem,&rcItem,TRUE);
  1054.     ImageList_BeginDrag(hDragImage,0,tvn->ptDrag.x,tvn->ptDrag.y);
  1055.     ShowCursor(FALSE);
  1056.     SetCapture(context->hwnd);
  1057.     context->fDragging = TRUE;
  1058.     context->hDragItem = tvn->itemNew.hItem;
  1059. }
  1060.  
  1061. static void DragQuit(CHOOSEOUTLINE* context)
  1062. {
  1063.     HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
  1064.     context->fDragging = FALSE;
  1065.     TreeView_SelectDropTarget(hctrl,NULL);
  1066.     ReleaseCapture();
  1067.     ShowCursor(TRUE);
  1068.     ImageList_EndDrag();
  1069. }
  1070.  
  1071. // tree構造が大幅に変わることがあるので、TreeViewはその都度作り直す
  1072. // ドラッグされたアイテムのみをTreeView内で動かしてもだめ
  1073. static void DropItem(CHOOSEOUTLINE* context)
  1074. {
  1075.     HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
  1076.     HTREEITEM hTarget = TreeView_GetDropHilight(hctrl);
  1077. //    HTREEITEM hTargetNext = TreeView_GetNextSibling(hctrl,hTarget);
  1078.     NPARA npara;
  1079.     //
  1080.     txSetUndisp(context->text);//2.99C 970325 
  1081.     context->fUndisp++;
  1082.     {
  1083.         tlCut(context,TRUE);
  1084.         context->fDragging = FALSE;
  1085.         //
  1086.         TreeView_SelectItem(hctrl,hTarget);
  1087.         TreeView_SelectDropTarget(hctrl,NULL);
  1088.         //
  1089.         ReleaseCapture();
  1090.         ShowCursor(TRUE);
  1091.         ImageList_EndDrag();
  1092.         //
  1093.         tlJump(context);
  1094.         tlPaste(context);
  1095.         //
  1096.         npara = text->npara;
  1097.         tlMake(context);
  1098.     }
  1099.     context->fUndisp--;
  1100.     //
  1101.     tlFromHl(context);
  1102.     tlSetNow(context,txrecordFromNpara(context->text,npara));
  1103.     txSetDisp(context->text);//2.99C 970325 
  1104. }
  1105.  
  1106. #endif
  1107.  
  1108. BOOL tlSetActive(TX* text)
  1109. {
  1110.     if (text->hwndOutline) {
  1111.         SetActiveWindow(text->hwndOutline);
  1112.         SetFocus(text->hwndOutline);
  1113.         if (text->outlineContext) {
  1114.             CHOOSEOUTLINE* oc = text->outlineContext;
  1115.             tlSetNow(oc,txrecordFromNpara(oc->text,oc->text->npara));
  1116.             return TRUE;
  1117.         }
  1118.     }
  1119.     return FALSE;
  1120. }
  1121.  
  1122. #ifdef __FLAT__
  1123. FARPROC _wndprocPrev;
  1124. FARPROC _wndproc;
  1125. LRESULT TXCALLBACK wndprocEdit(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  1126. {
  1127.     if (message == WM_GETDLGCODE) {
  1128.         return DLGC_WANTALLKEYS;
  1129.     }
  1130.     return CallWindowProc(_wndprocPrev,hwnd,message,wParam,lParam);
  1131. }
  1132.  
  1133. static void labelSet(CHOOSEOUTLINE* context,mchar* szText)
  1134. {
  1135.     TXRECORD i = tlGetNow(context);
  1136.     if (i != TXRECORD_ERROR) {
  1137.         TX* text = context->text;
  1138.         HEADLINE hl;
  1139.         txhRead(text,i,&hl);
  1140.         txJumpNpara(text,hl.npara);
  1141.         {
  1142.             PARAATR paraatr;
  1143.             INT lch;
  1144.             int lchTop = txParaatrRead(text,¶atr,&lch);
  1145.             txstr szline;
  1146.             txGetPara(text,szline);
  1147.             mchar* psz = &szline[lchTop];
  1148.             if (lch == -1) {
  1149.                 lch = strlen(psz);
  1150.             }
  1151.             txRightBytes(text,lchTop);
  1152.             txDeleteBytes(text,lch);
  1153.         }
  1154.         txInsert(text,szText);
  1155.         strcpymax(hl.szstr,szText,CCHWORD);
  1156.         txhWrite(text,i,&hl);
  1157.     }
  1158. }
  1159.  
  1160. static mchar* txGetTitle(TX* text,int ititle)
  1161. {
  1162.     if (ititle) {
  1163.         ititle--;
  1164.         if (ititle < 3) return text->tsztitle[ititle];
  1165.         if (ititle < 6) return text->tszformat[ititle - 3 + SZFORMAT_TITLE4];
  1166.     }
  1167.     return "";
  1168. }
  1169.  
  1170. #define LI_CHILD    0
  1171. #define LI_NULL        1
  1172. #define LI_ADD        2
  1173. #define LI_INSERT    3
  1174. static BOOL labelInsert(CHOOSEOUTLINE* context,int mode)
  1175. {
  1176.     TX* text = context->text;
  1177.     if (!context->textTree) return FALSE;
  1178.     HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
  1179.     BOOL fChild = (mode == LI_CHILD);
  1180.     TXRECORD i = tlGetNow(context);
  1181.     BOOL fNew = FALSE;
  1182.     int nest = 0;
  1183.     if (mode == LI_NULL) {
  1184.         if (i == TXRECORD_ERROR) {
  1185.             i = tlGetNowEx(context);
  1186.             if (i != TXRECORD_ERROR) {
  1187.                 HTREEITEM h = TreeView_GetSelection(hctrl);
  1188.                 nest = treeviewGetNest(hctrl,h) + 1;
  1189.             }
  1190.         } else {
  1191.             return FALSE;
  1192.         }
  1193.     } else if (mode == LI_ADD || mode == LI_INSERT) {
  1194.         if (i == TXRECORD_ERROR) {
  1195.             i = tlGetNowEx(context);
  1196.             if (mode == LI_INSERT && i != TXRECORD_ERROR) {
  1197.                 // "(名前なし)"で挿入の場合
  1198.                 HTREEITEM h = TreeView_GetSelection(hctrl);
  1199.                 nest = treeviewGetNest(hctrl,h) + 1;
  1200.             }
  1201.         }
  1202.         if (i != TXRECORD_ERROR) {
  1203.             if (mode == LI_ADD) {
  1204.                 HTREEITEM h = TreeView_GetSelection(hctrl);
  1205.                 nest = treeviewGetNest(hctrl,h) + 1;
  1206.                 HTREEITEM h1 = TreeView_GetNextSibling(hctrl,h);
  1207.                 if (h1) {
  1208.                     i = tvhGetParam(hctrl,h1);
  1209.                 } else {
  1210.                     HTREEITEM h1 = TreeView_GetParent(hctrl,h);
  1211.                     if (h1 && (h1 = TreeView_GetNextSibling(hctrl,h1))) {
  1212.                         i = tvhGetParam(hctrl,h1);
  1213.                     } else {
  1214.                         i = txhGetCount(text);
  1215.                         fNew = TRUE;
  1216.                     }
  1217.                 }
  1218.             }
  1219. //information("%d",i);
  1220.         }
  1221.     }
  1222.     if (i == TXRECORD_ERROR) {
  1223.         // 空の場合
  1224.         i = txhGetCount(text);
  1225.         fNew = TRUE;
  1226.         fChild = FALSE;
  1227.         nest = 1;
  1228.     }
  1229.     HEADLINE hl;
  1230.     if (fNew) {
  1231.         structClear(hl);
  1232.         txJumpFileEnd(text);
  1233.     } else {
  1234.         txhRead(text,i,&hl);
  1235.         txJumpPara(text,hl.npara);
  1236.     }
  1237.     {
  1238.         PARAATR paraatr;
  1239.         txParaatrRead(text,¶atr,NULL);
  1240.         if (nest) paraatr.modeTitle = nest;
  1241.         paraatr.modeTitle = paraatr.modeTitle + fChild;
  1242. //information(txGetTitle(text,paraatr.modeTitle));
  1243.         BOOL fC = !stricmp(txGetTitle(text,paraatr.modeTitle),"^C関数定義");
  1244.         mchar* sztitle;
  1245.         NPARA nparaIncrease = 1;
  1246.         //
  1247.         if (fChild) {
  1248.             txJumpParaEnd(text);
  1249.             txInsertReturn(text);
  1250.         } else {
  1251.             txJumpParaTop(text);
  1252.             txInsertReturn(text);
  1253.             txPrevPara(text);
  1254.         }
  1255.         if (fC) {
  1256.             sztitle = "NewFunction";
  1257.             txSetUndisp(text);
  1258.             txInsertLine(text,"void %s(void)",sztitle);
  1259.             txInsertLine(text,"{");
  1260.             txInsertLine(text,"\treturn;");
  1261.             txInsertLine(text,"}");
  1262.             txInsertReturn(text);
  1263.             txPrevPara(text);
  1264.             txPrevPara(text);
  1265.             txPrevPara(text);
  1266.             txPrevPara(text);
  1267.             txPrevPara(text);
  1268.             txSetDisp(text);
  1269.             nparaIncrease += 5;
  1270.         } else {
  1271.             if (mode == LI_NULL) {
  1272.                 sztitle = "見出し";
  1273.             } else {
  1274.                 sztitle = "新規見出し";
  1275.             }
  1276.             txInsert(text,sztitle);
  1277.             txParaatrWrite(text,¶atr);
  1278.         }
  1279.         //
  1280.         hl.npara = text->npara;
  1281.         hl.nest = paraatr.modeTitle;
  1282.         strcpymax(hl.szstr,sztitle,CCHWORD);
  1283.         txhInsert(text,i+fChild,&hl);
  1284.         {
  1285.             TXRECORD now = i + fChild + 1;
  1286.             TXRECORD n = txhGetCount(text);
  1287.             for (;now < n;now++) {
  1288.                 txhRead(text,now,&hl);
  1289.                 hl.npara += nparaIncrease;
  1290.                 txhWrite(text,now,&hl);
  1291.             }
  1292.         }
  1293.         //
  1294.         tlFromHl(context);
  1295.         tlSetNow(context,i+fChild);
  1296.         //
  1297.         HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
  1298.         HTREEITEM h = TreeView_GetSelection(hctrl);
  1299.         TreeView_EditLabel(hctrl,h);
  1300.     }
  1301.     return TRUE;
  1302. }
  1303. static BOOL labelSearch(CHOOSEOUTLINE* context,BOOL fNext)
  1304. {
  1305.     TX* text = context->text;
  1306.     static mchar _szSearch[CCHWORD];
  1307.     static TXRECORD _txrecordSearch;
  1308.     if (!fNext) {
  1309.         HDIALOG hd = dialog("見出しの検索");
  1310.         dialogSetParent(hd,context->hwnd);
  1311.         dialogStrC(hd,NULL,_szSearch,0,cchof(_szSearch),30);
  1312.         if (!dialogOpen(hd)) {
  1313.             tlSetActive(text);
  1314.             return FALSE;
  1315.         }
  1316.         tlSetActive(text);
  1317.         _txrecordSearch = 0;
  1318.     }
  1319.     BOOL ret = FALSE;
  1320.     TXRECORD n = txhGetCount(text);
  1321.     TXRECORD i;
  1322.     for (i = _txrecordSearch;i < n;i++) {
  1323.         HEADLINE hl;
  1324.         txhRead(text,i,&hl);
  1325.         if (stristr(hl.szstr,_szSearch)) {
  1326.             _txrecordSearch = i + 1;
  1327.             tlSetNow(context,i);
  1328.             ret = TRUE;
  1329.             break;
  1330.         }
  1331.     }
  1332.     if (!ret) statprintf("見出しが見つかりません");
  1333.     return ret;
  1334. }
  1335. #endif
  1336.  
  1337. static BOOL tlContents(CHOOSEOUTLINE* context)
  1338. {
  1339.     HWND hctrl = GetDlgItem(context->hwnd,IDD_TITLELIST);
  1340.     BOOL fTree = (context->textTree != NULL);
  1341.     int n;
  1342.     if (context->textTree) {
  1343.         n = txhGetCount(context->text);
  1344.     } else {
  1345.         n = SendMessage(hctrl,LB_GETCOUNT,0,0);
  1346.     }
  1347.     if (n > 0) {
  1348.         tx body;
  1349.         tx* text = &body;
  1350.         txInitText(text);
  1351.         txOpenText(text);
  1352.         int i;
  1353.         txSetUndisp(context->text);
  1354.         for (i = 0;i < n;i++) {
  1355.             if (fTree) {
  1356.                 HEADLINE hl;
  1357.                 txhRead(context->text,i,&hl);
  1358.                 {
  1359.                     int n = hl.nest - 1;
  1360.                     while(n--) txInsert(text,"  ");
  1361.                 }
  1362.                 txInsert(text,hl.szstr);
  1363.             } else {
  1364.                 mchar buff[CCHLINE];
  1365.                 SendMessage(hctrl,LB_GETTEXT,i,(LPARAM)buff);
  1366.                 txInsert(text,buff);
  1367.             }
  1368.             if (context->text->editmode == 2) {
  1369.                 TXRECORD irecord = ilistToTxrecord(context->text,i);
  1370.                 HEADLINE hl;
  1371.                 txhRead(text,irecord,&hl);
  1372.                 txJumpPara(context->text,hl.npara);
  1373.                 txInsertf(text,".....%d",context->text->npage);
  1374.             }
  1375.             txInsertReturn(text);
  1376.         }
  1377.         txSetDisp(context->text);
  1378.         txSelectAll(text);
  1379.         txSelectCopy(text);
  1380.         txClose(text);
  1381.         return TRUE;
  1382.     }
  1383.     return FALSE;
  1384. }
  1385.  
  1386. TX* TXAPI outlineGetTx(HWND hwnd)
  1387. {
  1388.     CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
  1389.     return context->text;
  1390. }
  1391.  
  1392. TXRECORD TXAPI outlineGetCursel(HWND hwnd)
  1393. {
  1394.     CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
  1395.     return tlGetNow(context);
  1396. }
  1397.  
  1398. void TXAPI outlineSetCursel(HWND hwnd,TXRECORD i)
  1399. {
  1400. #if 1//3.00B1 970612 WZ16の慣用句の挿入で編集すると、プレビュー内容が正しくなかった
  1401.     CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
  1402.     if (context->textTree) {
  1403.         tlSetNow(context,i);
  1404.     } else {
  1405.         tlSetNow(context,i);
  1406.         tlFlushListview(context);
  1407.     }
  1408. #else
  1409.     CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
  1410.     tlSetNow(context,i);
  1411. #endif
  1412. }
  1413.  
  1414. BOOL TXAPI outlineGetCurheadline(HWND hwnd,HEADLINE* hl)
  1415. {
  1416.     CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
  1417.     TX* text = context->text;
  1418.     TXRECORD i = tlGetNow(context);
  1419.     structClear(*hl);
  1420.     if (i != TXRECORD_ERROR) {
  1421.         txhRead(text,i,hl);
  1422.         return TRUE;
  1423.     } else {
  1424.         return FALSE;
  1425.     }
  1426. }
  1427.  
  1428. BOOL TXAPI outlineGetHeadline(HWND hwnd,HEADLINE* hl,TXRECORD i)
  1429. {
  1430. // iが無効ならFALSEを返す
  1431.     CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
  1432.     TX* text = context->text;
  1433.     structClear(*hl);
  1434.     if (i < txhGetCount(text)) {
  1435.         txhRead(text,i,hl);
  1436.         return TRUE;
  1437.     } else {
  1438.         return FALSE;
  1439.     }
  1440. }
  1441.  
  1442. BOOL TXAPI outlineFlush(HWND hwnd)
  1443. {
  1444.     CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
  1445.     tlMake(context);
  1446.     if (!context->fOutlineStd) tlFlushListview(context);
  1447.     return TRUE;
  1448. }
  1449.  
  1450. BOOL TXAPI outlineCopy(HWND hwnd)
  1451. {
  1452.     CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
  1453.     tlCut(context,FALSE);
  1454.     return TRUE;
  1455. }
  1456.  
  1457. BOOL TXAPI outlineCut(HWND hwnd)
  1458. {
  1459.     CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
  1460.     tlCut(context,TRUE);
  1461.     return TRUE;
  1462. }
  1463.  
  1464. BOOL TXAPI outlineClear(HWND hwnd)
  1465. {
  1466.     CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(dialogFromHwnd(hwnd));
  1467.     tlCut(context,2);
  1468.     return TRUE;
  1469. }
  1470.  
  1471. static BOOL handleKey(HWND hwnd,WPARAM wParam)
  1472. {
  1473.     int idd = 0;
  1474.     if (
  1475.         (GetKeyState(VK_CONTROL) < 0) &&
  1476.         !(GetKeyState(VK_SHIFT) < 0) &&
  1477.         !(GetKeyState(VK_MENU) < 0)
  1478.     ) {
  1479.         // Ctrl+xxx
  1480.         switch(wParam) {
  1481.             case VK_UP: idd = IDD_UP;break;
  1482.             case VK_DOWN:idd = IDD_DOWN;break;
  1483.             case VK_LEFT:idd = IDD_LEFTWITHSUB;break;
  1484.             case VK_RIGHT:idd = IDD_RIGHTWITHSUB;break;
  1485.             case 'A':idd = IDD_LABELADD;break;
  1486.             case 'C':idd = IDD_COPY;break;
  1487.             case 'F':idd = IDD_SEARCH;break;
  1488.             case 'N':idd = IDD_LABELINSERT;break;
  1489.             case 'B':idd = IDD_LABELCHILD;break;
  1490.             case 'V':idd = IDD_PASTE;break;
  1491.             case 'X':idd = IDD_CUT;break;
  1492.         }
  1493.     }
  1494.     if (
  1495.         !(GetKeyState(VK_CONTROL) < 0) &&
  1496.         (GetKeyState(VK_SHIFT) < 0) &&
  1497.         !(GetKeyState(VK_MENU) < 0)
  1498.     ) {
  1499.         // Shift+xxx
  1500.         switch(wParam) {
  1501.             case VK_LEFT:idd = IDD_LEFT;break;
  1502.             case VK_RIGHT:idd = IDD_RIGHT;break;
  1503.         }
  1504.     }
  1505.     if (
  1506.         !(GetKeyState(VK_CONTROL) < 0) &&
  1507.         !(GetKeyState(VK_SHIFT) < 0) &&
  1508.         !(GetKeyState(VK_MENU) < 0)
  1509.     ) {
  1510.         // No shift
  1511.         switch(wParam) {
  1512.             case VK_F2:idd = IDD_EDITLABEL;break;
  1513.             case VK_F3:idd = IDD_SEARCHNEXT;break;
  1514.             case VK_F5:idd = IDD_FLUSHLIST;break;
  1515.         }
  1516.     }
  1517.     if (idd) {
  1518.         PostMessage(hwnd,WM_COMMAND,idd,0);
  1519.         return TRUE;
  1520.     }
  1521.     return FALSE;
  1522. }
  1523.  
  1524. BOOL dlgprocTitlelist(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  1525. {
  1526.     BOOL ret = FALSE;//途中returnで返ってはいけない
  1527.     _fNoTxReport = TRUE;
  1528.     HDIALOG hd = dialogFromHwnd(hwnd);
  1529.     CHOOSEOUTLINE* context = (LPVOID)dialogGetCustdata(hd);
  1530.     TX* text = context->text;
  1531.     if (context->hook.address) {
  1532.         DWORD ret;
  1533.         macroCallAddress(&context->hook,&ret,4,(DWORD)hwnd,(DWORD)message,(DWORD)wParam,(DWORD)lParam);
  1534.         if (ret) return ret;
  1535.     }
  1536. #ifdef __FLAT__
  1537.     if (context->fLabelEditing) {
  1538.         if (message != WM_NOTIFY) return FALSE;
  1539.     }
  1540. #endif
  1541.     switch(message) {
  1542.         case WM_INITDIALOG: {
  1543.             if (context->fOutlineStd) text->fLastFocusOutline = TRUE;//2.95 970129 
  1544.             context->hwnd = hwnd;
  1545. //            context->fIniting = TRUE;
  1546.             if (context->textTree) {
  1547. //                context->fUndisp++;
  1548.                 tlMake(context);
  1549. //                context->fUndisp--;
  1550.             } else {
  1551.                 tlMake(context);
  1552. //2.92             SendDlgItemMessage(hwnd,IDD_TITLELIST,LB_SETCURSEL,context->iselFirst,0);
  1553.             }
  1554. #if 1//2.92 
  1555.             PostMessage(hwnd,WM_TXUSER,0,0);
  1556. #endif
  1557.             if (context->fOutlineStd) {
  1558.                 if (context->modeWindow == WINDOW_HV) {
  1559.                     if (fWindowPos) {
  1560.                         SetWindowPos(hwnd,NULL,x,y,0,0,SWP_NOSIZE);
  1561.                     }
  1562.                 } else {
  1563.                     SetWindowPos(hwnd,NULL,-30000,-30000,0,0,SWP_NOSIZE);// ちらつき抑止
  1564.                     ExtendWindow(text,hwnd,NULL);
  1565.                     PostMessage(text->hwndbase,WM_TXFLUSHWINDOWSIZE,0,0);
  1566.                 }
  1567.                 {
  1568.                     HWND hctrl = GetDlgItem(hwnd,IDD_TITLE);
  1569.                     if (hctrl) {
  1570.                         static mchar* tsz[] = {
  1571.                             "見出し1まで",
  1572.                             "見出し2まで",
  1573.                             "見出し3まで",
  1574.                             "見出し4まで",
  1575.                             "見出し5まで",
  1576.                             "見出し6まで",
  1577.                             "全ての見出し",
  1578.                             NULL,
  1579.                         };
  1580.                         int i;
  1581.                         for (i = 0;tsz[i];i++) {
  1582.                             SendMessage(hctrl,CB_ADDSTRING,0,(LPARAM)tsz[i]);
  1583.                         }
  1584.                         SendMessage(hctrl,CB_SETCURSEL,_nestDispMax,0);
  1585.                         // set Z order bottom.
  1586.                         SetWindowPos(hctrl,HWND_BOTTOM,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
  1587.                     }
  1588.                 }
  1589.                 tlSetNow(context,txrecordFromNpara(text,text->npara));
  1590.             } else {
  1591.                 tlFlushListview(context);
  1592.             }
  1593. //            context->fIniting = FALSE;
  1594.             if (context->textTree) {
  1595.                 if (context->fOutlineStd) {
  1596.                     // fOutlineStd時のみ。他の時は他のアイテム初期化があるので、しない
  1597.                     return INITDIALOG_SKIP_TRUE;
  1598.                 }
  1599.             }
  1600.             break;
  1601.         }
  1602. #ifdef __FLAT__//2.90 
  1603.         case WM_CONTEXTMENU: {
  1604.             if (!context->fOutlineStd) {
  1605.                 break;
  1606.             }
  1607.             if (wParam == GetDlgItem(hwnd,IDD_TITLELIST)) {
  1608.                 HMENU hmenu = menuNew();
  1609.                 //
  1610.                 menuStr(hmenu,"↑(&U)\tCtrl+Up",IDD_UP);
  1611.                 menuStr(hmenu,"↓(&D)\tCtrl+Down",IDD_DOWN);
  1612. #if 1//2.99C 970323 子見出し毎にランクを上げ下げするコマンドを追加
  1613.                 menuStr(hmenu,"子見出ごと←(&L)\tCtrl+Left",IDD_LEFTWITHSUB);
  1614.                 menuStr(hmenu,"子見出ごと→(&R)\tCtrl+Right",IDD_RIGHTWITHSUB);
  1615.                 menuStr(hmenu,"子見出は移動しない←(&1)\tShift+Left",IDD_LEFT);
  1616.                 menuStr(hmenu,"子見出は移動しない→(&2)\tShift+Right",IDD_RIGHT);
  1617. #else
  1618.                 menuStr(hmenu,"←(&L)",IDD_LEFT);
  1619.                 menuStr(hmenu,"→(&R)",IDD_RIGHT);
  1620. #endif
  1621.                 menuSepa(hmenu);
  1622.             #if 1//2.99A 970321 アウトラインのコンテキストメニューのメニューコマンドの名称一部変更
  1623.                 menuStr(hmenu,"見出しの追加(&W)\tCtrl+A",IDD_LABELADD);
  1624.                 menuStr(hmenu,"子見出しの追加(&N)\tCtrl+B",IDD_LABELCHILD);
  1625.                 menuStr(hmenu,"見出しの挿入(&I)\tCtrl+I",IDD_LABELINSERT);
  1626.                 menuStr(hmenu,"名前の変更(&M)\tF2",IDD_EDITLABEL);
  1627.             #else
  1628.                 menuStr(hmenu,"新規作成(&W)",IDD_LABELADD);
  1629.                 menuStr(hmenu,"子見出しの新規作成(&N)",IDD_LABELCHILD);
  1630.                 menuStr(hmenu,"新規挿入(&I)",IDD_LABELINSERT);
  1631.                 menuStr(hmenu,"名前の変更(&M)",IDD_EDITLABEL);
  1632.             #endif
  1633.                 menuSepa(hmenu);
  1634.                 menuStr(hmenu,"切り抜き(&T)\tCtrl+X",IDD_CUT);
  1635.                 menuStr(hmenu,"コピー(&C)\tCtrl+C",IDD_COPY);
  1636.                 menuStr(hmenu,"貼り付け(&P)\tCtrl+V",IDD_PASTE);
  1637.                 menuStr(hmenu,"目次を作成してコピー(&E)",IDD_COPYLIST);
  1638.                 menuSepa(hmenu);
  1639.                 menuStr(hmenu,"検索(&F)...\tCtrl+F",IDD_SEARCH);
  1640.                 menuStr(hmenu,"次検索(&S)\tF3",IDD_SEARCHNEXT);
  1641.                 menuSepa(hmenu);
  1642.                 menuStr(hmenu,"設定(&O)...",IDD_CONFIG);
  1643.                 menuStr(hmenu,"再作成(&H)\tF5",IDD_FLUSHLIST);
  1644.                 menuSepa(hmenu);
  1645.                 menuStr(hmenu,"閉じる(&X)\tCtrl+F4",IDD_CLOSE);
  1646.                 //
  1647.                 POINT point;
  1648. //                GetCursorPos(&point);
  1649. //                TrackPopupMenu(hmenu,TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN,point.x,point.y,0,hwnd,NULL);
  1650.                 point.x = LOWORD(lParam);
  1651.                 point.y = HIWORD(lParam);
  1652.                 if (point.x == 65535) {// by keyboard
  1653.                     HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
  1654.                     HTREEITEM h = TreeView_GetSelection(hctrl);
  1655.                     if (h) {
  1656.                         RECT rcItem;
  1657.                         TreeView_GetItemRect(hctrl,h,&rcItem,TRUE);
  1658.                         point.x = rcItem.right;
  1659.                         point.y = rcItem.bottom;
  1660.                         ClientToScreen(hctrl,&point);
  1661.                     }
  1662.                 }
  1663.                 TrackPopupMenu(hmenu,TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_LEFTALIGN,point.x,point.y,0,hwnd,NULL);
  1664.                 menuDelete(hmenu);
  1665.                 return TRUE;
  1666.             }
  1667.             break;
  1668.         }
  1669.         case WM_NOTIFY: {
  1670.             TV_DISPINFO* nm = (LPVOID)lParam;
  1671.             if (nm->hdr.idFrom == IDD_TITLELIST) {
  1672.                 switch(nm->hdr.code) {
  1673.                     case TVN_SELCHANGED: {
  1674.                         if (!context->fUndisp) {
  1675.                             tlJump(context);
  1676.                             if (!context->fOutlineStd) tlFlushListview(context);//2.92 
  1677.                         }
  1678.                         break;
  1679.                     }
  1680.                     case TVN_BEGINDRAG: {
  1681.                         NM_TREEVIEW* tvn = (LPVOID)lParam;
  1682.                         BeginDrag(context,tvn);
  1683.                         break;
  1684.                     }
  1685.                     case TVN_BEGINLABELEDIT: {
  1686.                         HWND hctrl = nm->hdr.hwndFrom;
  1687.                         TV_DISPINFO* tvis = (LPVOID)lParam;
  1688.                         TV_ITEM* tvi = &tvis->item;
  1689.                         //
  1690.                         tvi->mask = TVIF_TEXT|TVIF_PARAM;
  1691.                         static mchar buff[CCHWORD];
  1692.                         tvi->pszText = buff;
  1693.                         tvi->cchTextMax = CCHWORD;
  1694.                         TreeView_GetItem(hctrl,tvi);
  1695.                         tvi->mask = TVIF_TEXT;
  1696.                         TreeView_SetItem(hctrl,tvi);
  1697.                         // dialog.tll内のダイアログプロシジャーを無効にしないと、ハングする
  1698.                         context->fLabelEditing = TRUE;
  1699.                         dialogSetHookState(hd,HOOKSTATE_HOOKALL);
  1700.                         //
  1701.                         HWND hctrl = TreeView_GetEditControl(nm->hdr.hwndFrom);
  1702.                         _wndproc = macroMakeWndProc("wndprocEdit");
  1703.                         _wndprocPrev = GetWindowLong(hctrl,GWL_WNDPROC);
  1704.                         SetWindowLong(hctrl,GWL_WNDPROC,(LONG)_wndproc);
  1705.                         //
  1706.                         if ((long)tvi->lParam < 0) {
  1707. #if 1
  1708.                             context->fLabelName = TRUE;
  1709.                             PostMessage(nm->hdr.hwndFrom,TVM_ENDEDITLABELNOW,TRUE,0);
  1710. #else
  1711.                             // 編集不可
  1712.                             information("編集できません");
  1713.                             PostMessage(nm->hdr.hwndFrom,TVM_ENDEDITLABELNOW,TRUE,0);
  1714. #endif
  1715.                         }
  1716.                         return 0;
  1717.                     }
  1718.                     case TVN_ENDLABELEDIT: {
  1719.                         HWND hctrl = nm->hdr.hwndFrom;
  1720.                         TV_DISPINFO* tvis = (LPVOID)lParam;
  1721.                         TV_ITEM* tvi = &tvis->item;
  1722.                         BOOL fEdit = FALSE;
  1723.                         if (tvi->pszText) {
  1724.                             tvi->mask = TVIF_TEXT;
  1725.                             TreeView_SetItem(hctrl,tvi);
  1726.                             fEdit = TRUE;
  1727.                         }
  1728.                         //
  1729.                         context->fLabelEditing = FALSE;
  1730.                         dialogSetHookState(hd,HOOKSTATE_HOOKONCE);
  1731.                         //
  1732.                         HWND hctrl = TreeView_GetEditControl(nm->hdr.hwndFrom);
  1733.                         SetWindowLong(hctrl,GWL_WNDPROC,(DWORD)_wndprocPrev);
  1734.                         macroFreeWndProc(_wndproc);
  1735.                         //
  1736.                         if (fEdit) {
  1737.                             labelSet(context,tvi->pszText);
  1738.                         }
  1739.                         if (context->fLabelName) {
  1740.                             context->fLabelName = FALSE;
  1741.                             PostMessage(hwnd,WM_COMMAND,IDD_LABELNAME,0);
  1742.                         }
  1743.                         return 0;
  1744.                     }
  1745. #if 0    // 乗っ取れない
  1746.                     case TVN_KEYDOWN: {
  1747.                         TV_KEYDOWN* tvk = (LPVOID)lParam;
  1748.                         if (handleKey(hwnd,tvk->wVKey)) {
  1749.                             return TRUE;
  1750.                         }
  1751.                         break;
  1752.                     }
  1753. #endif
  1754. #if 0    // ESCはダイアログだから来ない
  1755.                     case TVN_KEYDOWN: {
  1756.                         TV_KEYDOWN* tvk = (LPVOID)lParam;
  1757.                         if (tvk->wVKey == VK_ESCAPE && context->fDragging) {
  1758.                             DragQuit(context);
  1759.                             return TRUE;
  1760.                         }
  1761.                         break;
  1762.                     }
  1763. #endif
  1764.                 }
  1765.             }
  1766.             break;
  1767.         }
  1768.         case WM_MOUSEMOVE: {
  1769.             if (context->fDragging) {
  1770.                 HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
  1771.                 POINT point;
  1772.                 point.x = LOWORD(lParam);
  1773.                 point.y = HIWORD(lParam);
  1774.                 ImageList_DragMove(point.x,point.y);
  1775.                 UINT flags = TVHT_ONITEM;
  1776.                 TV_HITTESTINFO tvht;
  1777.                 tvht.pt = point;
  1778.                 tvht.flags = TVHT_ONITEM;
  1779.                 TreeView_HitTest(hctrl,&tvht);
  1780.                 if (tvht.hItem) {
  1781.                     TreeView_SelectDropTarget(hctrl,tvht.hItem);
  1782.                 }
  1783.             }
  1784.             break;
  1785.         }
  1786.         case WM_LBUTTONUP: {
  1787.             if (context->fDragging) {
  1788.                 DropItem(context);
  1789.             }
  1790.             break;
  1791.         }
  1792. #endif
  1793.         case WM_COMMAND: {
  1794.             int id = WM_COMMAND_GetId(wParam);
  1795.             int notify = WM_COMMAND_GetNotify(wParam,lParam);
  1796.             
  1797.             if (!context->fOutlineStd) {
  1798.                 if (id == IDOK) {
  1799.                     tlCut(context,3);//2.92 FALSE->3
  1800.                 } else if (id == IDD_TITLELIST && notify == CBN_SELCHANGE) {
  1801.                     if (!context->textTree) tlFlushListview(context);
  1802.                 }
  1803.                 break;
  1804.             }
  1805.             if (id == IDOK || id == IDCANCEL) {
  1806.                 if (context->modeWindow == WINDOW_HV) {
  1807.                     // 位置を覚える
  1808.                     fWindowPos = TRUE;
  1809.                     WINDOWPLACEMENT wplace;
  1810.                     wplace.length = sizeof(WINDOWPLACEMENT);
  1811.                     GetWindowPlacement(hwnd,(LPWINDOWPLACEMENT)&wplace);
  1812.                     x = wplace.rcNormalPosition.left;
  1813.                     y = wplace.rcNormalPosition.top;
  1814.                 }
  1815.             }
  1816.             
  1817.             switch(id) {
  1818.                 case IDD_TITLE: {
  1819.                     if (notify == CBN_SELCHANGE) {
  1820.                         _nestDispMax = SendDlgItemMessage(hwnd,id,CB_GETCURSEL,0,0);
  1821.                         tlFromHl(context);
  1822.                         tlSetNow(context,txrecordFromNpara(text,text->npara));
  1823.                     }
  1824.                     break;
  1825.                 }
  1826.                 case IDD_TITLELIST: {
  1827.                     if (!context->textTree) {
  1828.                         if (notify == CBN_SELCHANGE) {
  1829.                             tlJump(context);
  1830.                         } else if (notify == LBN_DBLCLK) {
  1831.                             tlOpenClose(context);
  1832.                         }
  1833.                     }
  1834.                     break;
  1835.                 }
  1836.                 case IDOK: {
  1837.                     if (GetKeyState(VK_SHIFT) < 0) {
  1838.                         //1.94 Shift+Return/OKで、開閉
  1839.                         tlOpenClose(context);
  1840.                         return TRUE;
  1841.                     }
  1842.                     tlJump(context);
  1843.                     SetFocus(text->hwndtext);
  1844.                     break;
  1845.                 }
  1846.                 case IDD_UP: {
  1847.                     tlUp(context);
  1848.                     break;
  1849.                 }
  1850.                 case IDD_DOWN: {
  1851.                     tlDown(context);
  1852.                     break;
  1853.                 }
  1854.                 case IDD_LEFT: {
  1855.                     tlLeft(context);
  1856.                     break;
  1857.                 }
  1858.                 case IDD_RIGHT: {
  1859.                     tlRight(context);
  1860.                     break;
  1861.                 }
  1862.                 case IDD_LEFTWITHSUB: {//2.99C 970323 new
  1863.                     tlLeftWithSub(context);
  1864.                     break;
  1865.                 }
  1866.                 case IDD_RIGHTWITHSUB: {//2.99C 970323 new
  1867.                     tlRightWithSub(context);
  1868.                     break;
  1869.                 }
  1870.                 case IDD_CUT: {
  1871.                     tlCut(context,TRUE);
  1872.                     break;
  1873.                 }
  1874.                 case IDD_COPY: {
  1875.                     tlCut(context,FALSE);
  1876.                     break;
  1877.                 }
  1878.                 case IDD_PASTE: {
  1879.                     tlPaste(context);
  1880.                     tlMake(context);
  1881.                     break;
  1882.                 }
  1883.                 case IDD_COPYLIST: {
  1884.                     tlContents(context);
  1885.                     break;
  1886.                 }
  1887.                 case IDD_FLUSHLIST: {
  1888.                     tlMake(context);
  1889.                     break;
  1890.                 }
  1891.                 case IDD_CONFIG: {
  1892.                     HDIALOG hd = dialog("アウトラインの設定");
  1893.                     dialogSetContexthelp(hd,TRUE);
  1894.                     dialogSetGroupRight(hd,DTCX * 50);
  1895.                     
  1896.                     int modeWindow1 = p_modeWindow;
  1897.                     
  1898.                     dialogGroup(hd,"ウィンドウの位置");
  1899.                         dialogControlHelp(hd,-298);
  1900.                         dialogRadioID(hd,&modeWindow1,"縦割り(&V)","横割り(&H)","浮動(&W)");
  1901.                     dialogGroupEnd(hd);
  1902.                     
  1903.                     dialogGroup(hd,"見出しリストの大きさ");
  1904.                         dialogControlHelp(hd,246);
  1905.                         dialogControlGuide(hd,"文字",8);
  1906.                         dialogInt(hd,"縦割り時の幅(&X):",&lcxTitleListV,20,4);
  1907.                         dialogControlHelp(hd,247);
  1908.                         dialogControlGuide(hd,"文字",8);
  1909.                         dialogInt(hd,"横割り時の高さ(&Y):",&lcyTitleListH,20,4);
  1910.                         dialogControlHelp(hd,248);
  1911.                         dialogControlGuide(hd,"文字",8);
  1912.                         dialogIntXY(hd,"浮動時の幅と高さ(&Z):",&lcxTitleList,&lcyTitleList,20,4);
  1913.                     dialogGroupEnd(hd);
  1914.                     
  1915.                     dialogGroup(hd,"本文ウィンドウのサイズ");
  1916.                         dialogControlHelp(hd,249);
  1917.                         dialogCheck(hd,"縦割り時に変化しない(&S)",&fExtendTextWindow);
  1918.                     dialogGroupEnd(hd);
  1919.                     
  1920.                     if (!_fwin40) {
  1921.                         dialogGroup(hd,"フォント");
  1922.                         dialogControlHelp(hd,250);
  1923.                             dialogCheck(hd,"小さいフォントで表示(&S)",&fSmallFont);
  1924.                         dialogGroupEnd(hd);
  1925.                     }
  1926.                     if (dialogOpen(hd)) {
  1927.                         close(text,hwnd,TRUE);
  1928.                         PostMessage(text->hwndbase,WM_COMMAND,IDM_WZCMDTOP + wzcmdRegister("\m.uiTitleList"),0);
  1929.                         p_modeWindow = modeWindow1;
  1930.                     }
  1931.                     break;
  1932.                 }
  1933. #ifdef __FLAT__
  1934.                 case IDD_EDITLABEL: {
  1935.                     HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
  1936.                     HTREEITEM h = TreeView_GetSelection(hctrl);
  1937.                     TreeView_EditLabel(hctrl,h);
  1938.                     break;
  1939.                 }
  1940.                 case IDD_LABELCHILD: {
  1941.                     labelInsert(context,LI_CHILD);
  1942.                     break;
  1943.                 }
  1944.                 case IDD_LABELADD: {
  1945.                     labelInsert(context,LI_ADD);
  1946.                     break;
  1947.                 }
  1948.                 case IDD_LABELINSERT: {
  1949.                     labelInsert(context,LI_INSERT);
  1950.                     break;
  1951.                 }
  1952.                 case IDD_LABELNAME: {
  1953.                     labelInsert(context,LI_NULL);
  1954.                     break;
  1955.                 }
  1956.                 case IDD_SEARCH: {
  1957.                     labelSearch(context,FALSE);
  1958.                     break;
  1959.                 }
  1960.                 case IDD_SEARCHNEXT: {
  1961.                     labelSearch(context,TRUE);
  1962.                     break;
  1963.                 }
  1964. #endif
  1965.             }
  1966.             if (_fModeress) {
  1967.                 if (id == IDCANCEL) {
  1968.                     if (context->modeWindow == WINDOW_HV) {
  1969.                         close(text,hwnd,FALSE);
  1970.                     } else {
  1971.                         if (context->fDragging) {
  1972. #ifdef __FLAT__
  1973.                             DragQuit(context);
  1974.                             return TRUE;
  1975. #endif
  1976.                         } else {
  1977.                             SetFocus(text->hwndtext);
  1978.                         }
  1979.                     }
  1980.                 } else if (id == IDD_CLOSE) {
  1981.                     close(text,hwnd,FALSE);
  1982.                 }
  1983.                 ret = TRUE;
  1984.             }
  1985.             break;
  1986.         }
  1987.         case WM_CLOSE: {
  1988.             if (!context->fOutlineStd) break;
  1989.             if (_fModeress) {
  1990.                 // ダイアログプロシジャーはWM_CLOSEを処理しない
  1991.                 outlineClose(text);
  1992.                 ret = TRUE;//2.99D 970330 for DEBUGWIN err
  1993.             }
  1994.             break;
  1995.         }
  1996.         case WM_TXUSER: {//2.92 
  1997.             if (context->iselFirst) {
  1998.                 tlSetNow(context,context->iselFirst);
  1999.                 #ifndef __FLAT__
  2000.                 //2.97A 970228 WZ16で内容表示が初期化されなかった
  2001.                 tlFlushListview(context);
  2002.                 #endif
  2003.             }
  2004.             break;
  2005.         }
  2006.         case WM_KEYDOWN: {
  2007.             break;
  2008.         }
  2009.         case WM_SETFOCUS: {//2.95 970129 
  2010.             if (context->fOutlineStd) text->fLastFocusOutline = TRUE;
  2011.             break;
  2012.         }
  2013.         case WM_ACTIVATE: {//2.99C 970323 浮動アウトライン表示中にテキストでダイアログを開いて閉じるとフォーカスがアウトラインに移ってしまっていた
  2014.             if (text->fOutlineHV) {
  2015.                 BOOL fActive = LOWORD(wParam);
  2016.                 if (fActive != WA_INACTIVE) {
  2017.                     #ifdef __FLAT__
  2018.                     HWND hwnd0 = lParam;
  2019.                     #else
  2020.                     HWND hwnd0 = LOWORD(lParam);
  2021.                     #endif
  2022.                     if (hwnd0 != text->hwndbase) {
  2023.                         PostMessage(hwnd,WM_TXUSER+2,0,0);
  2024.                     }
  2025.                 }
  2026.             }
  2027.             break;
  2028.         }
  2029.         case WM_TXUSER+2: {//2.99C 970323 WM_TXUSER+1は使用中
  2030.             SetFocus(text->hwndtext);
  2031.             break;
  2032.         }
  2033.         case WM_TXKEYDOWN: {//2.99C 970324 outlineキーボードインターフェースサポート
  2034.             TXKEYDOWNARG* arg = (LPVOID)lParam;
  2035.             if (handleKey(hwnd,wParam)) {
  2036.                 arg->fHook = TRUE;
  2037.             }
  2038.             break;
  2039.         }
  2040. #if 0
  2041.         case WM_CTLCOLORDLG:{
  2042.             return (int)GetStockObject(WHITE_BRUSH);
  2043.         }
  2044. #endif
  2045.     }
  2046.     _fNoTxReport = FALSE;
  2047.     return ret;
  2048. }
  2049.  
  2050. #define MODE_WZOUTLINE    0x8000
  2051.  
  2052. //2.92 
  2053. static void contextFreeText(CHOOSEOUTLINE* context)
  2054. {
  2055.     if (context->textTree) {//2.90 
  2056.         txClose(context->textTree);
  2057.         free(context->textTree);
  2058.         context->textTree = NULL;
  2059.     }
  2060. }
  2061.  
  2062. BOOL TXAPI dialogSelectTitle(HDIALOG hd,CHOOSEOUTLINE* context)
  2063. {
  2064.     if (context->szhook) {
  2065.         macroGetFuncAddress(context->szhook,&context->hook);
  2066.     }
  2067.     dialogSetCustdata(hd,(DWORD)context);
  2068.     //
  2069.     if (_fwin40) {//2.90 
  2070.         TX* text = malloc(sizeof(TX));
  2071.         if (text) {
  2072.             context->textTree = text;
  2073.             txInitText(text);
  2074.             txOpenText(text);
  2075.             dialogSetControlData(hd,IDD_TITLELIST,text);
  2076.         }
  2077.     }
  2078.     //
  2079.     dialogSetHookEx(hd,"\m.dlgprocTitlelist");
  2080.     //
  2081.     if (context->fOutlineStd) {
  2082.         if (_fModeress) {
  2083.             context->text->hwndOutline = dialogCreate(hd);
  2084.         } else {
  2085.             dialogOpen(hd);
  2086.             contextFreeText(context);
  2087.         }
  2088.     } else {
  2089.         context->modeWindow = WINDOW_V;//2.99D 970330 
  2090.         int ret = dialogOpen(hd);
  2091.         contextFreeText(context);
  2092.         return ret;
  2093.     }
  2094. }
  2095.  
  2096. static BOOL _dialogSmallButtonCmd(HDIALOG hd,mchar* szCaption,int id,int cx,int dcs)
  2097. {
  2098.     int ret;
  2099.     DTRECT r;
  2100.     dialogGetPos(hd,&r);
  2101.     r.cx = cx * DTCX;
  2102.     r.cy = DTCYBUTTON;
  2103.     ret = _dialogAddItem(hd,dcs,szCaption,id,&r,WS_GROUP);
  2104.     r.y += r.cy + DTCY / 4;
  2105.     dialogSetPos(hd,&r);
  2106.     return ret;
  2107. }
  2108.  
  2109. static BOOL dialogSmallButtonCmd(HDIALOG hd,mchar* szCaption,int id,int cx)
  2110. {
  2111.     return _dialogSmallButtonCmd(hd,szCaption,id,cx,DCS_PUSHBUTTON);
  2112. }
  2113.  
  2114. static BOOL dialogSmallButtonCmdDefault(HDIALOG hd,mchar* szCaption,int id,int cx)
  2115. {
  2116.     return _dialogSmallButtonCmd(hd,szCaption,id,cx,DCS_DEFPUSHBUTTON);
  2117. }
  2118.  
  2119. BOOL TXAPI dialogAddTitle(HDIALOG hd,DTRECT* r)
  2120. {
  2121. //2.92 
  2122.     if (_fwin40) {//2.90 
  2123.         #ifdef __FLAT__
  2124.         dialogControlID(hd,IDD_TITLELIST);
  2125.         dialogControlStyle(hd,WS_TABSTOP|WS_VSCROLL|WS_BORDER|WS_CHILD|WS_VISIBLE|TVS_HASBUTTONS|TVS_LINESATROOT|TVS_HASLINES|TVS_SHOWSELALWAYS|TVS_EDITLABELS);
  2126.         dialogTree(hd,NULL,NULL,r->cx / DTCX,r->cy / DTCY);
  2127.         dialogControlStyle(hd,0);
  2128.         #endif
  2129.     } else {
  2130.         __dialogAddItem(hd,"LISTBOX",NULL,IDD_TITLELIST,r,LBS_NOTIFY|WS_BORDER|WS_VSCROLL|WS_HSCROLL|WS_CHILD|WS_VISIBLE|WS_TABSTOP);
  2131.     }
  2132.     return TRUE;
  2133. }
  2134.  
  2135. BOOL uiTitleList(TX* text)
  2136. {
  2137.     BOOL fHV = (p_modeWindow == WINDOW_HV);    // 浮動?
  2138.     if (text->hwndOutline) {
  2139.         tlSetActive(text);
  2140.         return FALSE;
  2141.     }
  2142.     //
  2143.     if (!text->outlineContext) {
  2144.         text->outlineContext = malloc(sizeof(CHOOSEOUTLINE));
  2145.         if (!text->outlineContext) return FALSE;
  2146.     }
  2147.     CHOOSEOUTLINE* context = text->outlineContext;
  2148.     memset(context,0,sizeof(CHOOSEOUTLINE));
  2149.     context->text = text;
  2150.     context->fOutlineStd = TRUE;
  2151.     context->modeWindow = p_modeWindow;//2.99D 970330 
  2152.     text->fOutline = TRUE;
  2153.     text->fOutlineHV = fHV;//2.99A 970321 浮動型アウトラインで本文に戻れなかった
  2154.     //
  2155.     HDIALOG hd = _dialog("アウトライン",EXDS_POSDEFAULT|(fSmallFont?EXDS_BIGFORCE:0),NULL);
  2156.     dialogSetParent(hd,text->hwndbase);//2.90 
  2157.     //
  2158.     DTRECT r;
  2159.     if (!_fwin40) {
  2160.         dialogGetPos(hd,&r);
  2161.         r.y -= DTCY / 3;
  2162.         r.cx = DTCX * 20;
  2163.         r.cy = DTCY * 7;
  2164.         __dialogAddItem(hd,"COMBOBOX",NULL,IDD_TITLE,&r,CBS_AUTOHSCROLL|CBS_DROPDOWNLIST|WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|WS_GROUP);
  2165.         dialogLF(hd);
  2166.     }
  2167.     //
  2168.     dialogGetPos(hd,&r);
  2169.     {
  2170.         RECT rs;
  2171.         GetClientRect(text->hwndbase,&rs);
  2172.         DWORD dwBaseUnits = dialogGetBaseUnits(hd);
  2173.         int cxd = LOWORD(dwBaseUnits);
  2174.         int cyd = HIWORD(dwBaseUnits);
  2175.         
  2176.         if (fHV) {
  2177.             r.cx = DTCX * lcxTitleList;
  2178.             r.cy = DTCY * lcyTitleList;
  2179.         } else if (context->modeWindow == WINDOW_V) {
  2180.             r.cx = DTCX * lcxTitleListV;
  2181.             r.cy = (rs.bottom * 8) / cyd - DTCY * 17;
  2182.         } else {
  2183.             r.cx = (rs.right * 4) / cxd - DTCX * 28;
  2184.             r.cy = DTCY * lcyTitleListH;
  2185.         }
  2186.     }
  2187.     dialogAddTitle(hd,&r);
  2188.     dialogSetPos(hd,&r);
  2189.     dialogSetFocus(hd,IDD_TITLELIST);
  2190.     //
  2191.     if (context->modeWindow == WINDOW_V) {
  2192.         dialogLF(hd);
  2193.     } else {
  2194.         dialogLFV(hd);
  2195.     }
  2196.     //
  2197.     dialogSetPosLF(hd);
  2198.     //
  2199.     int cx;
  2200.     if (fHV) {
  2201.         if (_fwin40) {
  2202.             //2.99A 970321 Win95/NTでは浮動アウトラインでボタンつけない
  2203.             dialogSetNoButton(hd);
  2204.         } else {
  2205.             cx = 6;
  2206.             dialogControlID(hd,IDD_UP);
  2207.             dialogButtonCmd(hd,"↑(&U)",NULL,cx);
  2208.             dialogControlID(hd,IDD_DOWN);
  2209.             dialogButtonCmd(hd,"↓(&D)",NULL,cx);
  2210.             dialogLFV(hd);
  2211.             dialogControlID(hd,IDD_LEFT);
  2212.             dialogButtonCmd(hd,"←(&L)",NULL,cx);
  2213.             dialogControlID(hd,IDD_RIGHT);
  2214.             dialogButtonCmd(hd,"→(&R)",NULL,cx);
  2215.             
  2216.             dialogLF(hd);
  2217.             cx = 13;
  2218.             dialogSpaceV(hd);
  2219.             dialogControlID(hd,IDD_CUT);
  2220.             dialogButtonCmd(hd,"切り抜き(&T)",NULL,cx);
  2221.             dialogControlID(hd,IDD_COPY);
  2222.             dialogButtonCmd(hd,"コピー(&C)",NULL,cx);
  2223.             dialogControlID(hd,IDD_PASTE);
  2224.             dialogButtonCmd(hd,"貼り付け(&P)",NULL,cx);
  2225.             
  2226.             dialogLFV(hd);
  2227.             
  2228.             dialogOK(hd,cx);
  2229.             dialogControlID(hd,IDCANCEL);
  2230.             dialogButtonCmd(hd,"閉じる(&X)",NULL,cx);
  2231.             dialogControlID(hd,IDD_CONFIG);
  2232.             dialogButtonCmd(hd,"設定(&O)...",NULL,cx);
  2233.             
  2234.             dialogLF(hd);
  2235.             r.y += r.cy + DTCYINT;
  2236.             dialogSetPos(hd,&r);
  2237.             dialogSetH(hd);
  2238.             dialogControlID(hd,IDD_COPYLIST);
  2239.             if (_fwin40) {
  2240.                 dialogButtonCmd(hd,"目次を作成してコピー(&I)",NULL,cx * 2);
  2241.             } else {
  2242.                 dialogButtonCmd(hd,"一覧をコピー(&I)",NULL,cx);
  2243.             }
  2244.             //
  2245.             dialogControlID(hd,IDD_FLUSHLIST);
  2246.             dialogButtonCmd(hd,"再作成(&H)",NULL,cx);
  2247.         }
  2248.     } else {
  2249.         if (!_fwin40) {
  2250.             BOOL fVwide = (context->modeWindow == WINDOW_V && lcxTitleListV >= 30);
  2251.             cx = 4;
  2252.             dialogSmallButtonCmd(hd,"↑",IDD_UP,cx);
  2253.             dialogSmallButtonCmd(hd,"↓",IDD_DOWN,cx);
  2254.             if (fVwide) dialogLFV(hd);
  2255.             dialogSmallButtonCmd(hd,"←",IDD_LEFT,cx);
  2256.             dialogSmallButtonCmd(hd,"→",IDD_RIGHT,cx);
  2257.             
  2258.             if (context->modeWindow == WINDOW_V) {
  2259.                 dialogLFV(hd);
  2260.             } else {
  2261.                 dialogSmallButtonCmdDefault(hd,"OK",IDOK,cx);
  2262.                 dialogLFV(hd);
  2263.             }
  2264.             
  2265.             if (fVwide) {
  2266.                 cx = 6;
  2267.             } else {
  2268.                 cx = 8;
  2269.             }
  2270.             dialogSmallButtonCmd(hd,"切抜&T",IDD_CUT,cx);
  2271.             dialogSmallButtonCmd(hd,"貼付&P",IDD_PASTE,cx);
  2272.             if (fVwide) dialogLFV(hd);
  2273.             cx = 8;
  2274.             dialogSmallButtonCmd(hd,"設定&O",IDD_CONFIG,cx);
  2275.             dialogSmallButtonCmd(hd,"再作成&H",IDD_FLUSHLIST,cx);
  2276.             
  2277.             if (context->modeWindow == WINDOW_V) {
  2278.                 dialogLFV(hd);
  2279.                 cx = 4;
  2280.                 dialogSmallButtonCmdDefault(hd,"OK",IDOK,cx);
  2281.             }
  2282.             dialogSmallButtonCmd(hd,"&X",IDD_CLOSE,cx);
  2283.         }
  2284.         DWORD style = dialogGetStyle(hd);
  2285.         dialogSetStyle(hd,WS_VISIBLE|WS_CHILD|(style & DS_SETFONT));
  2286.         dialogSetNoButton(hd);
  2287.     }
  2288.     return dialogSelectTitle(hd,context);
  2289. }
  2290.  
  2291. static void olJustDlg(TX* text,int cx,int cy)
  2292. {
  2293.     HWND hwnd = text->hwndOutline;
  2294.     CHOOSEOUTLINE* context = text->outlineContext;    //2.94 970121 
  2295.     DWORD dw = GetDialogBaseUnits();
  2296.     int dtcx = LOWORD(dw);
  2297.     int dtcy = HIWORD(dw);
  2298.     int dx = 0;
  2299.     int dy = 0;
  2300.     int yTop;
  2301.     int yEnd;
  2302.     POINT p;
  2303.     if (context->modeWindow == WINDOW_V) {
  2304.         RECT rTitle;
  2305.         HWND hctrl = GetDlgItem(hwnd,IDD_TITLE);
  2306.         if (hctrl) {
  2307.             GetWindowRect(hctrl,&rTitle);
  2308.             ScreenToClientRect(hwnd,&rTitle);
  2309.             yTop = rTitle.bottom + dtcy / 2;
  2310.             //
  2311.             RECT rOK;
  2312.             HWND hctrl = GetDlgItem(hwnd,IDOK);
  2313.             GetWindowRect(hctrl,&rOK);
  2314.             ScreenToClientRect(hwnd,&rOK);
  2315.             yEnd = rOK.top;
  2316.             //
  2317.             RECT rRight;
  2318.             HWND hctrl = GetDlgItem(hwnd,IDD_RIGHT);
  2319.             GetWindowRect(hctrl,&rRight);
  2320.             ScreenToClientRect(hwnd,&rRight);
  2321.             yEnd = cy - (rRight.bottom - rOK.top + dtcy);
  2322.             // move TITLELIST
  2323.             RECT rList;
  2324.             HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
  2325.             GetWindowRect(hctrl,&rList);
  2326.             ScreenToClientRect(hwnd,&rList);
  2327.             MoveWindow(hctrl,rList.left,yTop,rList.right - rList.left,yEnd - yTop,TRUE);
  2328.             // move buttons
  2329.             yTop = yEnd + dtcy / 2;
  2330.             dy = yTop - rOK.top;
  2331.         } else {
  2332.             // move TITLELIST
  2333.             RECT rList;
  2334.             HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
  2335.             GetWindowRect(hctrl,&rList);
  2336.             ScreenToClientRect(hwnd,&rList);
  2337.             int dx = dtcx / 4;
  2338.             MoveWindow(hctrl,dx,0,cx-dx,cy,TRUE);
  2339.         }
  2340.         //
  2341.     } else if (context->modeWindow == WINDOW_H) {
  2342.         RECT rTitle;
  2343.         HWND hctrl = GetDlgItem(hwnd,IDD_TITLE);
  2344.         if (hctrl) {
  2345.             GetWindowRect(hctrl,&rTitle);
  2346.             ScreenToClientRect(hwnd,&rTitle);
  2347.             yTop = rTitle.bottom + dtcy;
  2348.             //
  2349.             RECT rOK;
  2350.             HWND hctrl = GetDlgItem(hwnd,IDD_CONFIG);
  2351.             GetWindowRect(hctrl,&rOK);
  2352.             ScreenToClientRect(hwnd,&rOK);
  2353.             //
  2354.             RECT rUp;
  2355.             HWND hctrl = GetDlgItem(hwnd,IDD_UP);
  2356.             GetWindowRect(hctrl,&rUp);
  2357.             ScreenToClientRect(hwnd,&rUp);
  2358.             int xEnd = cx - (dtcx + rOK.right - rUp.left + dtcx);
  2359.             // move TITLELIST
  2360.             RECT rList;
  2361.             HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
  2362.             GetWindowRect(hctrl,&rList);
  2363.             ScreenToClientRect(hwnd,&rList);
  2364.             MoveWindow(hctrl,rList.left,rList.top,xEnd - rList.left,rList.bottom - rList.top,TRUE);
  2365.             // move buttons
  2366.             dx = xEnd - rUp.left + dtcx;
  2367.         } else {
  2368.             // move TITLELIST
  2369.             RECT rList;
  2370.             HWND hctrl = GetDlgItem(hwnd,IDD_TITLELIST);
  2371.             GetWindowRect(hctrl,&rList);
  2372.             ScreenToClientRect(hwnd,&rList);
  2373.             int dy = dtcy / 8;
  2374.             MoveWindow(hctrl,0,dy,cx,cy-dy,TRUE);
  2375.         }
  2376.     }
  2377.     // move buttons
  2378.     if (dx || dy) {
  2379.         static int tid[] = {
  2380.             IDD_UP,IDD_DOWN,IDD_LEFT,IDD_RIGHT,
  2381.             IDOK,IDD_CLOSE,IDD_CUT,IDD_COPY,IDD_PASTE,
  2382.             IDD_CONFIG,IDD_FLUSHLIST,
  2383.             0,
  2384.         };
  2385.         int i;
  2386.         for (i = 0;tid[i];i++) {
  2387.             HWND hctrl = GetDlgItem(hwnd,tid[i]);
  2388.             if (hctrl) {
  2389.                 RECT r;
  2390.                 GetWindowRect(hctrl,&r);
  2391.                 ScreenToClientRect(hwnd,&r);
  2392.                 MoveWindow(hctrl,r.left + dx,r.top + dy,r.right - r.left,r.bottom - r.top,FALSE);
  2393.             }
  2394.         }
  2395.     }
  2396. }
  2397.  
  2398. //##hook
  2399.  
  2400. HOOKRESULT __wndprocbase(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  2401. {
  2402.     TX* text = textTarget;//2.94 970121 
  2403.     switch(message) {
  2404.         case WM_TXWINDOWSIZE: {
  2405.             if (_fFlushWindow) {
  2406.                 _fFlushWindow = FALSE;
  2407.                 RECT r = *(RECT*)lParam;
  2408.                 MoveWindow(text->hwndtext,r.left,r.top,r.right-r.left,r.bottom-r.top,TRUE);
  2409.             } else if (text->hwndOutline) {
  2410.                 CHOOSEOUTLINE* context = text->outlineContext;
  2411.                 if (context->modeWindow != WINDOW_HV) {
  2412.                     RECT rs;
  2413.                     GetClientRect(text->hwndOutline,&rs);
  2414.                     //
  2415.                     RECT* rp = (RECT*)lParam;
  2416.                     RECT r = *rp;
  2417.                     RECT r2 = r;
  2418.                     if (context->modeWindow == WINDOW_H) {
  2419.                         r.bottom -= rs.bottom;
  2420.                         r2.top = r.bottom;
  2421.                     } else {
  2422.                         r.right -= rs.right;
  2423.                         r2.left = r.right;
  2424.                     }
  2425. #if 1//2.95 970129 分割対応
  2426.                     rp->right = r.right;
  2427.                     rp->bottom = r.bottom;
  2428.                     //
  2429.                     int cx = r2.right-r2.left;
  2430.                     int cy = r2.bottom-r2.top;
  2431.                     olJustDlg(text,cx,cy);
  2432.                     MoveWindow(text->hwndOutline,r2.left,r2.top,cx,cy,TRUE);
  2433.                     return HOOK_CONTINUE;
  2434. #else
  2435.                     MoveWindow(text->hwndtext,r.left,r.top,r.right-r.left,r.bottom-r.top,TRUE);
  2436.                     //
  2437.                     int cx = r2.right-r2.left;
  2438.                     int cy = r2.bottom-r2.top;
  2439.                     olJustDlg(text,cx,cy);
  2440.                     MoveWindow(text->hwndOutline,r2.left,r2.top,cx,cy,TRUE);
  2441.                     return HOOK_CAPTURE;
  2442. #endif
  2443.                 }
  2444.             }
  2445.             break;
  2446.         }
  2447. #if 0//2.99D 970330 for DEBUGWIN
  2448.         case WM_DESTROY: {
  2449.             // __deleteでこれを実行すると、dialog.tllが既にunloadされてる事がある
  2450.               outlineClosed(text);//2.99D 970330 旧outlineClose
  2451.             break;
  2452.         }
  2453. #endif
  2454. #if 0//2.00E5 アウトラインが付いたり付かなかったり、ウィンドウのサイズが変わったりした
  2455.     #if 1//1.99A 
  2456.         case WM_TXCLOSE: {
  2457.             outlineClose(text);
  2458.             break;
  2459.         }
  2460.     #else
  2461.         case WM_TXQUERYCLOSE: {
  2462.             outlineClose(text);
  2463.             break;
  2464.         }
  2465.     #endif
  2466. #endif
  2467.     }
  2468.     return HOOK_CONTINUE;
  2469. }
  2470.  
  2471. //2.00B 
  2472. static BOOL _fAck = FALSE;
  2473. static void txreportHandle(HWND hwnd,TXREPORT* r,BOOL fDeleted)
  2474. {
  2475.     TX* text = r->text;
  2476.     if (
  2477.         text->fFrame &&
  2478.         !text->fNoOutlineFlush//2.00E4 
  2479.     ) {
  2480.         BOOL f = FALSE;
  2481.         TXRECORD n = txRecordGetCount(text->txOutline);
  2482.         TXRECORD i;
  2483.         for (i = 0;i < n;i++) {
  2484.             HEADLINE hl;
  2485.             txhRead(text,i,&hl);
  2486.             if (fDeleted) {
  2487.                 if (hl.npara >= r->npara) {
  2488.                     if (hl.npara < r->npara + r->nparaCount) {
  2489.                         f = TRUE;
  2490.                         break;
  2491.                     }
  2492.                     hl.npara -= r->nparaCount;
  2493.                     txhWrite(text,i,&hl);
  2494.                 }
  2495.             } else {
  2496.                 if (hl.npara >= r->npara) {
  2497.                     hl.npara += r->nparaCount;
  2498.                     txhWrite(text,i,&hl);
  2499.                 }
  2500.             }
  2501.         }
  2502.         if (f && !_fAck) {
  2503.             // これをしないと
  2504.             // 次のイベントループまでに沢山WM_TXREPORTが来たとき困る
  2505.             _fAck = TRUE;
  2506.             PostMessage(hwnd,WM_TXREPORTACK,0,0);
  2507.         }
  2508.     }
  2509. }
  2510.  
  2511. HOOKRESULT __wndproctext(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  2512. {
  2513.     TX* text = textTarget;//2.94 970121 
  2514.     switch(message) {
  2515.         case WM_RBUTTONDOWN:
  2516.         case WM_LBUTTONDOWN: {
  2517.             SetFocus(hwnd);
  2518.             break;
  2519.         }
  2520.         case WM_KEYDOWN: {
  2521.             if (text->hwndOutline) {
  2522.                 if (wParam == VK_ESCAPE && GetKeyState(VK_SHIFT) < 0) {
  2523.                     // SHIFT+ESC
  2524.                     tlSetActive(text);
  2525.                     return TRUE;
  2526.                 }
  2527.             }
  2528.             break;
  2529.         }
  2530.         case WM_TXREPORT: {//2.00B 
  2531.             if (_fNoTxReport || !text->hwndOutline) break;
  2532.             TXREPORT* r = (LPVOID)lParam;
  2533.             switch(wParam) {
  2534.                 case TXREPORT_TEXTBUFF_INSERT: {
  2535.                     txreportHandle(hwnd,r,FALSE);
  2536.                     break;
  2537.                 }
  2538.                 case TXREPORT_TEXTBUFF_DELETE: {
  2539.                     txreportHandle(hwnd,r,TRUE);
  2540.                     break;
  2541.                 }
  2542.             }
  2543.             break;
  2544.         }
  2545.         case WM_TXREPORTACK: {
  2546.             _fAck = FALSE;
  2547.             //2.90 いきなりtlMakeのように時間がかかる処理を始めるのは不自然。
  2548.             // フラッシュはユーザの明示的な指示でがあったときだけ行なう。
  2549.             break;
  2550.         }
  2551.     }
  2552.     return FALSE;
  2553. }
  2554.  
  2555. __new
  2556. {
  2557.     macroHookWndBase();
  2558.     macroHookWndText();
  2559. }
  2560.  
  2561. __delete
  2562. {
  2563. }
  2564.  
  2565. main
  2566. {
  2567.     uiTitleList(text);
  2568. }
  2569.  
  2570. //2.90 ファイル-再読み込みで、アウトラインもフラッシュするようにした
  2571. flush
  2572. {
  2573.     if (text->hwndOutline) {
  2574.         tlMake(text->outlineContext);
  2575.     } else {
  2576.         uiTitleList(text);
  2577.     }
  2578. }
  2579.  
  2580. //2.00E2 outline.swをShift+Escにキー割り当てした
  2581. BOOL TXCMDBASE sw(TX* text)
  2582. {
  2583. // アウトラインウィンドウを出します。
  2584. // アウトラインウィンドウが出ているときは消します。
  2585.     //{#MS} +{Esc}
  2586.     //{#VZ} +{Esc}
  2587.     //{#MI} +{Esc}
  2588.     TX* text = txGetFrame(textf);
  2589.     if (text->fOutline) {
  2590.         outlineClose(text);
  2591.     } else {
  2592.         uiTitleList(text);
  2593.     }
  2594.     return TRUE;
  2595. }
  2596.  
  2597. void op(TX* text,int op)
  2598. {
  2599. //2.99D 970330 for WZ.EXE
  2600.     switch(op) {
  2601.         case OUTLINEOP_OPEN: {
  2602.             uiTitleList(text);
  2603.             break;
  2604.         }
  2605.         case OUTLINEOP_CLOSE: {
  2606.             outlineClose(text);
  2607.             break;
  2608.         }
  2609.     }
  2610. }
  2611.  
  2612.