home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MODEL / DLOGWIN.CPP < prev    next >
C/C++ Source or Header  |  1996-04-15  |  16KB  |  660 lines

  1. //
  2. //        ダイアログ処理関数
  3. //
  4. //        1996.1.16        M.Takatsu
  5. //
  6. #include <owl\owlpch.h>
  7. #pragma hdrstop
  8. #include <owl\button.h>
  9. #include <owl\edit.h>
  10. #include <owl\slider.h>
  11. #include <owl\static.h>
  12. #include <owl\checkbox.h>
  13. #include <owl\radiobut.h>
  14. #include <owl\groupbox.h>
  15. #include <owl\opensave.h>
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <assert.h>
  21.  
  22. #include "model.rh"
  23.  
  24.  
  25. #include "message.h"
  26. extern "C" {
  27. #include "ml.h"
  28. #include "dlog.h"
  29. #include "model.h"
  30. }
  31.  
  32. #define OFFSET    1000
  33.  
  34. #define    DLOG_STEP    (FontV+2)
  35. //#define    DLOG_OFFSET    (FontV+DLOG_STEP)
  36. #define DLOG_OFFSET FontV
  37. #define    MAX_FIELD    30
  38. #define MAX_SELECT    10
  39. #define DLOG_ID_SLIDER    (DIALOG_FRAME+1)
  40. #define DLOG_ID_BUTTON    (DLOG_ID_SLIDER+32)
  41. #define DLOG_ID_END     (DLOG_ID_BUTTON+32)
  42. #define BORDER 4
  43. #define    RIGHTBORDER    (FontH*3)
  44. #define MAXSTRING    512
  45. #define MAXBUTTONTEXT 16
  46. #define SLIDERSTEP 10
  47. #define SLIDEROFFSET 30
  48.  
  49. typedef    struct    {
  50.     int        type ;
  51.     TEdit   *control;
  52.     int        max ;
  53.     char    str[MAXSTRING] ;
  54.     char    wild[MAXSTRING] ;
  55. }
  56.     cStringData ;
  57.  
  58. typedef    struct    {
  59.     int        type ;
  60.     TCheckBox    *control;
  61.     int        stat ;
  62. }
  63.     cToggleData ;
  64.  
  65. typedef    struct    {
  66.     int        type ;
  67.     TRadioButton    *control[MAX_SELECT];
  68.     int        sels;
  69.     int        stat;
  70. }
  71.     cSelectData ;
  72.  
  73. typedef    struct    {
  74.     int        type ;
  75.     TSlider    *control;
  76.     TStatic    *text;
  77.     int        size;
  78.     int        step;
  79.     int        count ;
  80.     int        ident ;
  81. }
  82.     cSliderData ;
  83.  
  84. typedef    union    {
  85.     int            type ;
  86.     cStringData    str ;
  87.     cToggleData    toggle ;
  88.     cSelectData    select ;
  89.     cSliderData    slider ;
  90. }
  91.     cDlogData ;
  92.  
  93. class TDlog : public TDialog {
  94. public:
  95.     TDlog (TWindow* parent);
  96.     virtual ~TDlog ();
  97.     virtual void SetupWindow ();
  98.  
  99. protected:
  100.     void CmEnd();
  101.     void CmOK ();
  102.     void CmCancel ();
  103.     void CmDlogButton0();
  104.     void CmDlogButton1();
  105.     void CmDlogButton2();
  106.     void CmDlogButton3();
  107.     void CmDlogButton4();
  108.     void CmDlogButton5();
  109.     void CmDlogButton6();
  110.     void CmDlogButton7();
  111.     void EvSlider(UINT code);
  112.     void CmButton(int pos);
  113. #define E(n) void CmButton##n () {CmButton(n);}
  114.     E(0)  E(1)  E(2)  E(3)  E(4)  E(5)  E(6)  E(7)
  115.     E(8)  E(9)  E(10) E(11) E(12) E(13) E(14) E(15)
  116.     E(16) E(17) E(18) E(19) E(20) E(21) E(22) E(23)
  117.     E(24) E(25) E(26) E(27) E(28) E(29) E(30) E(31)
  118. #undef E
  119.  
  120.     DECLARE_RESPONSE_TABLE(TDlog);
  121. };
  122.  
  123. #define EV_CHILD_NOTIFY_ALL_CODES_2(id,func) \
  124.         EV_CHILD_NOTIFY_ALL_CODES((id)+0,func),\
  125.         EV_CHILD_NOTIFY_ALL_CODES((id)+1,func)
  126. #define EV_CHILD_NOTIFY_ALL_CODES_4(id,func) \
  127.         EV_CHILD_NOTIFY_ALL_CODES_2((id)+0,func),\
  128.         EV_CHILD_NOTIFY_ALL_CODES_2((id)+2,func)
  129. #define EV_CHILD_NOTIFY_ALL_CODES_8(id,func) \
  130.         EV_CHILD_NOTIFY_ALL_CODES_4((id)+0,func),\
  131.         EV_CHILD_NOTIFY_ALL_CODES_4((id)+4,func)
  132. #define EV_CHILD_NOTIFY_ALL_CODES_16(id,func) \
  133.         EV_CHILD_NOTIFY_ALL_CODES_8((id)+0,func),\
  134.         EV_CHILD_NOTIFY_ALL_CODES_8((id)+8,func)
  135. #define EV_CHILD_NOTIFY_ALL_CODES_32(id,func) \
  136.         EV_CHILD_NOTIFY_ALL_CODES_16((id)+0,func),\
  137.         EV_CHILD_NOTIFY_ALL_CODES_16((id)+16,func)
  138.  
  139. #define EV_BN_CLICKED_AND_CODE(id,func) EV_CHILD_NOTIFY_AND_CODE(id,BN_CLICKED,func)
  140.  
  141. #define EV_BN_CLICKED_AND_CODE_4(id, func) \
  142.         EV_BN_CLICKED_AND_CODE((id)+0, func),\
  143.         EV_BN_CLICKED_AND_CODE((id)+1, func),\
  144.         EV_BN_CLICKED_AND_CODE((id)+2, func),\
  145.         EV_BN_CLICKED_AND_CODE((id)+3, func)
  146. #define EV_BN_CLICKED_AND_CODE_16(id, func) \
  147.         EV_BN_CLICKED_AND_CODE_4((id)+ 0, func),\
  148.         EV_BN_CLICKED_AND_CODE_4((id)+ 4, func),\
  149.         EV_BN_CLICKED_AND_CODE_4((id)+ 8, func),\
  150.         EV_BN_CLICKED_AND_CODE_4((id)+12, func)
  151. #define EV_BN_CLICKED_AND_CODE_32(id,func) \
  152.         EV_BN_CLICKED_AND_CODE_16((id)+ 0, func),\
  153.         EV_BN_CLICKED_AND_CODE_16((id)+16, func)
  154.  
  155.  
  156. DEFINE_RESPONSE_TABLE1(TDlog, TDialog)
  157.     EV_CHILD_NOTIFY_ALL_CODES_32(DLOG_ID_SLIDER, EvSlider),
  158. #define E(n) EV_BN_CLICKED(DLOG_ID_BUTTON+n, CmButton##n),
  159.     E(0)  E(1)  E(2)  E(3)  E(4)  E(5)  E(6)  E(7)
  160.     E(8)  E(9)  E(10) E(11) E(12) E(13) E(14) E(15)
  161.     E(16) E(17) E(18) E(19) E(20) E(21) E(22) E(23)
  162.     E(24) E(25) E(26) E(27) E(28) E(29) E(30) E(31)
  163. #undef E
  164.  
  165.     EV_BN_CLICKED(IDOK, CmOK),
  166.     EV_BN_CLICKED(DLOG_ID_END+0, CmDlogButton0),
  167.     EV_BN_CLICKED(DLOG_ID_END+1, CmDlogButton1),
  168.     EV_BN_CLICKED(DLOG_ID_END+2, CmDlogButton2),
  169.     EV_BN_CLICKED(DLOG_ID_END+3, CmDlogButton3),
  170.     EV_BN_CLICKED(DLOG_ID_END+4, CmDlogButton4),
  171.     EV_BN_CLICKED(DLOG_ID_END+5, CmDlogButton5),
  172.     EV_BN_CLICKED(DLOG_ID_END+6, CmDlogButton6),
  173.     EV_BN_CLICKED(DLOG_ID_END+7, CmDlogButton7),
  174. END_RESPONSE_TABLE;
  175.  
  176. extern int    QuitFlag;
  177. extern    int        FontH, FontV ;
  178.  
  179. static    TDlog *DlogWindow = NULL;
  180. static    cDlogData    Dlog[MAX_FIELD];
  181. static    int        maxwidth;
  182. static    int        dx, dy, dw, dh;
  183.  
  184. #if 0
  185. static    int        buttontype;
  186. TButton *b_ok, *b_cancel;
  187. #endif
  188. TButton    *dlogbutton[DLOG_MAX_BUTTON];
  189. int    dlogbuttonwidth[DLOG_MAX_BUTTON];
  190. char    buttontext[DLOG_MAX_BUTTON][MAXBUTTONTEXT];
  191.  
  192. static    void    SliderDisplay( cSliderData* );
  193. static    int        SliderConv( cSliderData* );
  194.  
  195. extern    TWindow *GetModelWindow(void);
  196. extern    TApplication    *Application ;
  197.  
  198.  
  199. TDlog::TDlog (TWindow* parent) :
  200.     TDialog(parent, DIALOG_FRAME, NULL)
  201. {
  202.     for (int i = 0; i < DLOG_MAX_BUTTON; ++i) {
  203.         dlogbutton[i] = NULL;
  204.     }
  205. }
  206.  
  207. void TDlog::SetupWindow ()
  208. {
  209.     TDialog::SetupWindow();
  210.  
  211.     // INSERT>> 追加のコードはここに
  212.     int ox = GetSystemMetrics(SM_CXBORDER)*2;
  213.     int oy = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYBORDER);
  214.  
  215.     if (dw < maxwidth) {
  216.         dw = maxwidth;
  217.     }
  218.  
  219.     MoveWindow(dx-(dw/2), dy-(dh/2), dw+ox, dh+oy);
  220.  
  221.     int bx, by;
  222.  
  223.     bx = dw - FontH * 3;
  224.     by = dh - (FontV+BORDER*5);
  225.     for (int i = 0; i < DLOG_MAX_BUTTON; ++i) {
  226.         if (dlogbutton[i] != NULL) {
  227.             bx -= FontH * (dlogbuttonwidth[i]+ 2);
  228.             dlogbutton[i]->MoveWindow(bx, by, FontH * (dlogbuttonwidth[i]+2), FontV+BORDER*2);
  229.             bx -= FontH * 2;
  230.         }
  231.     }
  232.  
  233.     for (i = 0; i < MAX_FIELD; ++i) {
  234.         cToggleData *td;
  235.         cSelectData *sd;
  236.         cSliderData *hd;
  237.         switch (Dlog[i].type) {
  238.         case DLOG_STRING:
  239.             break;
  240.         case DLOG_TOGGLE:
  241.             td = &(Dlog[i].toggle);
  242.             if (td->stat) {
  243.                 td->control->Check();
  244.             }
  245.             break;
  246.         case DLOG_SELECT:
  247.             sd = &(Dlog[i].select);
  248.             sd->control[sd->stat]->Check();
  249.             break;
  250.         case DLOG_SLIDER:
  251.             hd = &(Dlog[i].slider);
  252.             hd->control->SetPosition((hd->count+1) * SLIDERSTEP);
  253.             hd->control->PageMagnitude = SLIDERSTEP;
  254.             hd->control->LineMagnitude = SLIDERSTEP;
  255.             hd->control->DeltaPos(SLIDERSTEP);
  256.             hd->control->SetRange(SLIDERSTEP, SLIDERSTEP * hd->step);
  257.             hd->control->SetRuler(SLIDERSTEP, TRUE);
  258.             hd->control->SetPosition(0);
  259.             hd->control->SetPosition((hd->count+1) * SLIDERSTEP);
  260.  
  261.             SliderDisplay(hd);
  262.             break;
  263.         }
  264.     }
  265. }
  266.  
  267. TDlog::~TDlog()
  268. {
  269. }
  270.  
  271. void TDlog::EvSlider(UINT /*code*/)
  272. {
  273.     int i;
  274.     for (i = 0; i < MAX_FIELD; ++i) {
  275.         cSliderData *sd = &(Dlog[i].slider);
  276.         if (Dlog[i].type == DLOG_SLIDER
  277.          && sd->count != (sd->control->GetPosition()/SLIDERSTEP)-1) {
  278.             sd->count = (sd->control->GetPosition()/SLIDERSTEP)-1;
  279.             if (sd->count < 0) {
  280.                 sd->count = 0;
  281.             } else if (sd->count >= sd->step) {
  282.                 sd->count = sd->step-1;
  283.             }
  284.             SliderDisplay(sd);
  285.         }
  286.     }
  287. }
  288.  
  289. void TDlog::CmEnd()
  290. {
  291.     int i, j;
  292.     for (i = 0; i < MAX_FIELD; ++i) {
  293.         cStringData *str;
  294.         cToggleData *tgl;
  295.         cSelectData *sel;
  296.         switch (Dlog[i].type) {
  297.         case DLOG_STRING:
  298.             str = &(Dlog[i].str);
  299.             str->control->GetText(str->str, MAXSTRING);
  300.             break;
  301.         case DLOG_TOGGLE:
  302.             tgl = &(Dlog[i].toggle);
  303.             tgl->stat = (tgl->control->GetCheck() == BF_CHECKED);
  304.             break;
  305.         case DLOG_SELECT:
  306.             sel = &(Dlog[i].select);
  307.             for (j = 0; j < sel->sels; ++j) {
  308.                 if (sel->control[j]->GetCheck() == BF_CHECKED) {
  309.                     sel->stat = j;
  310.                     break;
  311.                 }
  312.             }
  313.             break;
  314.         case DLOG_SLIDER:
  315.             break;
  316.         }
  317.     }
  318. }
  319.  
  320. void TDlog::CmOK()          {CmEnd();CloseWindow(OFFSET + 0x0d);}
  321. void TDlog::CmCancel()      {CmEnd();CloseWindow(OFFSET + 0);}
  322. void TDlog::CmDlogButton0() {CmEnd();CloseWindow(OFFSET + 0);}
  323. void TDlog::CmDlogButton1() {CmEnd();CloseWindow(OFFSET + 1);}
  324. void TDlog::CmDlogButton2() {CmEnd();CloseWindow(OFFSET + 2);}
  325. void TDlog::CmDlogButton3() {CmEnd();CloseWindow(OFFSET + 3);}
  326. void TDlog::CmDlogButton4() {CmEnd();CloseWindow(OFFSET + 4);}
  327. void TDlog::CmDlogButton5() {CmEnd();CloseWindow(OFFSET + 5);}
  328. void TDlog::CmDlogButton6() {CmEnd();CloseWindow(OFFSET + 6);}
  329. void TDlog::CmDlogButton7() {CmEnd();CloseWindow(OFFSET + 7);}
  330.  
  331. void TDlog::CmButton(int pos)
  332. {
  333.     cStringData    *sd ;
  334.  
  335.     if (0 <= pos && pos < MAX_FIELD && Dlog[pos].type == DLOG_STRING) {
  336.         sd = &Dlog[pos].str ;
  337.  
  338.         TOpenSaveDialog::TData FileData(OFN_HIDEREADONLY,
  339.                             sd->wild + 4, 0, NULL, sd->wild);
  340.         if (TFileOpenDialog(this, FileData).Execute() == IDOK) {
  341.             sd->control->SetText(FileData.FileName);
  342.         }
  343.     }
  344. }
  345.  
  346. void    DlogOpen(char *title, int fields, char *button[] )
  347. {
  348.     TWindow *parent;
  349.     int        i ;
  350.  
  351.     dw = FontH * 20;
  352. //    dh = DLOG_STEP * fields + FontV * 5;
  353.     dh = DLOG_STEP * fields + FontV * 4;
  354.  
  355.     maxwidth = FontH * 20;
  356.  
  357.     dx = GetSystemMetrics(SM_CXSCREEN)/2;
  358.     dy = GetSystemMetrics(SM_CYSCREEN)/2;
  359.  
  360.     if (DlogWindow == NULL) {
  361.         delete DlogWindow;
  362.     }
  363.     parent = GetModelWindow();
  364.     DlogWindow = new TDlog(parent);
  365.  
  366. //    new TStatic(DlogWindow, 0, title, FontH*2, BORDER, FontH*60, FontV, strlen(title));
  367.     DlogWindow->SetCaption(title);
  368.  
  369.     for (i = 0; button[i] != NULL; i++) {
  370.         strcpy(buttontext[i], button[i]);
  371.     }
  372.     for (; i < DLOG_MAX_BUTTON; i++) {
  373.         buttontext[i][0] = '\0';
  374.     }
  375.  
  376. #if 0
  377.     int bx, by;
  378.  
  379.     bx = dw- FontH * 5;
  380.     by = dh - (FontV+BORDER*5);
  381.  
  382.     new TButton(DlogWindow, IDOK,     "決定", -100, -100, 0, 0);
  383.     new TButton(DlogWindow, IDCANCEL, "中止", -100, -100, 0, 0);
  384.     for (i = 0; button[i] != NULL; i++) {
  385.         int len;
  386.         len = dlogbuttonwidth[i] = strlen(button[i]);
  387.         dlogbutton[i] = new TButton(DlogWindow, DLOG_ID_END+ i, button[i], bx - FontH * (len+2), by, FontH * (len+2), FontV + BORDER*2);
  388.         bx -= FontH * (len + 4);
  389.     }
  390. #endif
  391.  
  392.     for( i = 0 ; i < MAX_FIELD ; i++ ) {
  393.         Dlog[i].type = 0 ;
  394.     }
  395. }
  396.  
  397. /*    メッセージの表示    */
  398. int        DlogMessage(int field, char *msg )
  399. {
  400.     int x = FontH * 2;
  401.     int y = DLOG_OFFSET + field * DLOG_STEP;
  402.     int len = strlen(msg);
  403.     new TStatic(DlogWindow, 0, msg, x, y,
  404.                 FontH * len, FontV, len);
  405.     if (maxwidth < x + FontH * len + RIGHTBORDER) {
  406.         maxwidth = x + FontH * len + RIGHTBORDER;
  407.     }
  408.     return FontH * (4 + len);
  409. }
  410.  
  411. /*    文字列入力フィールド表示    */
  412. void    DlogString( int field, char *msg, char *str, int max, char *wild )
  413. {
  414.     cStringData    *sd ;
  415.  
  416.     Dlog[field].type = DLOG_STRING ;
  417.     sd = &Dlog[field].str ;
  418.     sd->max = max ;
  419.     strcpy( sd->str, str );
  420.     int x = DlogMessage(field, msg);
  421.     int y = DLOG_OFFSET + field * DLOG_STEP;
  422.     sd->control = new TEdit(DlogWindow, 0, sd->str,
  423.                             x, y-BORDER, max*FontH, FontV+BORDER*2, MAXSTRING);
  424.     x += max * FontH ;
  425.  
  426.     if (wild != NULL && wild[0]) {
  427.         strcpy(sd->wild, wild);
  428.         sd->wild[3] = '\0';
  429.         new TButton(DlogWindow, DLOG_ID_BUTTON + field, "参照",
  430.                     x + FontH, y-BORDER, 6 * FontH, FontV + BORDER*2);
  431. //printf("field = %d, Create ID=%08x\n", field, DLOG_ID_BUTTON+ field);
  432.         x += FontH + 6 * FontH;
  433.     }
  434.  
  435.     if (maxwidth < x + RIGHTBORDER) {
  436.         maxwidth = x + RIGHTBORDER;
  437.     }
  438. }
  439.  
  440. /*    トグルスイッチ表示    */
  441. void    DlogToggle( int field, char *msg, char *str, int sw )
  442. {
  443.     cToggleData    *td ;
  444.  
  445.     Dlog[field].type = DLOG_TOGGLE ;
  446.     td = &Dlog[field].toggle ;
  447.     int x = DlogMessage(field, msg);
  448.     int y = DLOG_OFFSET + field * DLOG_STEP;
  449.     int len = strlen(str);
  450.     td->control = new TCheckBox(DlogWindow, DLOG_ID_BUTTON + field,
  451.                             str,
  452.                             x, y-BORDER, (len+4)*FontH, FontV+BORDER*2);
  453.     td->stat = sw ;
  454.     if (maxwidth < x + (len+4) * FontH + RIGHTBORDER) {
  455.         maxwidth = x + (len+4) * FontH + RIGHTBORDER;
  456.     }
  457. }
  458.  
  459. /*    選択スイッチ表示    */
  460. void    DlogSelect( int field, char *msg, char **item, int stat )
  461. {
  462.     int        i, len, n, max ;
  463.     cSelectData    *sd ;
  464.  
  465.     max = 0 ;
  466.     for( n = 0 ; item[n] != NULL ; n++ )
  467.     {
  468.         len = strlen( item[n] ) ;
  469.         if ( max < len )
  470.             max = len ;
  471.     }
  472.  
  473.     Dlog[field].type = DLOG_SELECT ;
  474.     sd = &Dlog[field].select ;
  475.     int x = DlogMessage(field, msg);
  476.     int y = DLOG_OFFSET + field * DLOG_STEP;
  477.     TGroupBox *tbox = new TGroupBox(DlogWindow, 0, "", x, y-BORDER*3,
  478.                             ((max+5) * n +1) * FontH, FontV+BORDER*4);
  479.     sd->sels = n ;
  480.     if (stat < 0 || stat >= n) {
  481.         stat = 0;
  482.     }
  483.     sd->stat = stat ;
  484.     x += FontH;
  485.     for (i = 0; i < n; ++i) {
  486.         sd->control[i]  = new TRadioButton(DlogWindow, 0, item[i],
  487.                                 x, y, FontH * (max+4), FontV, tbox);
  488.         x += FontH * (max+5);
  489.     }
  490.     if (maxwidth < x + ((max+5)*n+1) * FontH + RIGHTBORDER) {
  491.         maxwidth = x + RIGHTBORDER;
  492.     }
  493.  
  494. }
  495.  
  496. /*    スライドスイッチ表示    */
  497. void    DlogSlider( int field, char *msg, int size, int step, int start, int ident )
  498. {
  499.     cSliderData    *sd ;
  500.  
  501.     Dlog[field].type = DLOG_SLIDER ;
  502.     sd = &Dlog[field].slider ;
  503.     int x = DlogMessage(field, msg);
  504.     int y = DLOG_OFFSET + field * DLOG_STEP;
  505.  
  506.     sd->control = new THSlider(DlogWindow, DLOG_ID_SLIDER + field,
  507.                         x, y-BORDER, size, FontV+BORDER*2);
  508.     sd->text = new TStatic(DlogWindow, 0, "hoge", x + size + 2 * FontH, y,
  509.                             FontH * 6, FontV, 6);
  510.     sd->size = size ;
  511.     sd->step = step;
  512.     sd->count = start ;
  513.     sd->ident = ident ;
  514.     if (maxwidth < x + size + 8 * FontH + RIGHTBORDER) {
  515.         maxwidth = x + size + 8 * FontH + RIGHTBORDER;
  516.     }
  517.  
  518. }
  519.  
  520. static    int        SliderConv( cSliderData *sd )
  521. {
  522.     int            slider ;
  523.     DataStruct    *mark ;
  524.  
  525.     if ( sd->ident >= 0 )
  526.     {
  527.         mark = StackTop();
  528.         StackPushInt( sd->count );
  529.  
  530.         CallFunction( sd->ident, 1, mark+1 );
  531.         slider = mark[1].id.i ;
  532.         StackRelease( mark );
  533.     }
  534.     else
  535.     {
  536.         slider = sd->count ;
  537.     }
  538.     return slider ;
  539. }
  540.  
  541. static    void    SliderDisplay( cSliderData    *sd )
  542. {
  543.     char    str[10] ;
  544.  
  545.     sprintf( str, "%6d", SliderConv( sd ) );
  546.     sd->text->SetText(str);
  547. }
  548.  
  549. /*    入力待ち    */
  550. int        DlogWait()
  551. {
  552. //    new TButton(DlogWindow, IDOK,     "決定", -100, -100, 0, 0);
  553. //    new TButton(DlogWindow, IDCANCEL, "中止", -100, -100, 0, 0);
  554.     int w;
  555.     w = 0;
  556.     for (int i = 0; i < DLOG_MAX_BUTTON; i++) {
  557.         if (buttontext[i][0] != '\0') {
  558.             int len;
  559.             len = dlogbuttonwidth[i] = strlen(buttontext[i]);
  560.             dlogbutton[i] = new TButton(DlogWindow, DLOG_ID_END+i, buttontext[i], 0,0,0,0);
  561.             w += (len+2) * FontH;
  562.         }
  563.     }
  564.     if (maxwidth < w) maxwidth = w;
  565.  
  566.     int ret;
  567.     ret = DlogWindow->Execute();
  568.     delete DlogWindow;
  569.     DlogWindow = NULL;
  570.     Application->PumpWaitingMessages();
  571.  
  572.     if (ret >= OFFSET) {
  573.         ret -= OFFSET;
  574.     } else if (ret == IDCANCEL) {
  575.         ret = 0;
  576.     } else if (ret == IDOK) {
  577.         ret = 1;
  578.     }
  579.     return ret;
  580. }
  581.  
  582. /*    答を得る    */
  583. int        DlogAnswer( int n, char *str, int *ip )
  584. {
  585.     switch( Dlog[n].type )
  586.     {
  587.         case DLOG_STRING:
  588.             strcpy( str, Dlog[n].str.str );
  589.             return DLOG_STRING ;
  590.         case DLOG_TOGGLE:
  591.             *ip = Dlog[n].toggle.stat ;
  592.             return DLOG_TOGGLE ;
  593.         case DLOG_SELECT:
  594.             *ip = Dlog[n].select.stat ;
  595.             return DLOG_SELECT ;
  596.         case DLOG_SLIDER:
  597.             *ip = Dlog[n].slider.count ;
  598.             return DLOG_SLIDER ;
  599.         default:
  600.             return 0 ;
  601.     }
  602. }
  603.  
  604.  
  605. /*
  606.  *    ファイル名入力
  607.  */
  608. int    DlogFileOpen(char *str, int n, char *title, char *def, char *defext, char *selext)
  609. {
  610. //printf("title=%s\ndefault=%s\ndefext=%s\nselext=%s\n",
  611. //    title, def, defext, selext);
  612.  
  613. #if 0
  614.     TOpenSaveDialog::TData FileData(OFN_HIDEREADONLY,
  615.                         selext, 0, def, defext);
  616.     if (TFileOpenDialog(GetModelWindow(), FileData,0,title).Execute() == IDOK) {
  617.         strncpy(str, FileData.FileName, n-1);
  618.         str[n-1] = '\0';
  619.         return TRUE;
  620.     }
  621. #else
  622.     if (def && *def) {
  623.         char *name, *p, initialdir[F_NAME_LEN];
  624.         strcpy(initialdir, def);
  625.         if ((p = strrchr(initialdir, '\\')) == NULL) {
  626.             p = initialdir;
  627.         }
  628.         if ((name = strrchr(p, '/')) == NULL) {
  629.             name = p;
  630.         }
  631.         if (*name == '/' || *name == '\\') {
  632.             *name = '\0';
  633.             name++;
  634.             p = initialdir;
  635.         } else {
  636.             p = NULL;
  637.         }
  638.  
  639.         TOpenSaveDialog::TData FileData(OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
  640.                             selext, 0, p, defext);
  641.         strcpy(FileData.FileName, name);
  642.         if (TFileSaveDialog(GetModelWindow(), FileData,0,title).Execute() == IDOK) {
  643.             strncpy(str, FileData.FileName, n-1);
  644.             str[n-1] = '\0';
  645.             return TRUE;
  646.         }
  647.     } else {
  648.         TOpenSaveDialog::TData FileData(OFN_HIDEREADONLY,
  649.                             selext, 0, "", defext);
  650.         if (TFileOpenDialog(GetModelWindow(), FileData,0,title).Execute() == IDOK) {
  651.             strncpy(str, FileData.FileName, n-1);
  652.             str[n-1] = '\0';
  653.             return TRUE;
  654.         }
  655.     }
  656. #endif
  657.     return FALSE;
  658. }
  659.  
  660.