home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / ListPrint.sit / ListPrint / WindowSet.c < prev    next >
Text File  |  1995-02-10  |  13KB  |  515 lines

  1. //******************************************************************************
  2. //*                                            *
  3. //*    Macintosh プログラム作成の勉強                    *
  4. //*    This Program is lesson for Macintohs.                    *
  5. //*                                            *
  6. //*    1994/ 4/26 By SAGAWA KAZUYOSHI                        *
  7. //*    1994/ 9/20 By SAGAWA KAZUYOSHI                        *
  8. //*                                            *
  9. //******************************************************************************
  10. #include    "Constants.h"
  11. #include    "ListPrint.h"
  12.  
  13.  
  14. //**************************************************************************
  15. //*
  16. //*    本モジュールの中だけで使用されている関数プロトタイプ宣言
  17. //*
  18. //**************************************************************************
  19.  
  20.  
  21.  
  22. //#########################################################################
  23. //#
  24. //#    FUC    イベント実行の関数群
  25. //#
  26. //#    IN    無し
  27. //#    OT    無し
  28. //#    EX    無し
  29. //#
  30. //##########################################################################
  31.  
  32. /**************************************************************************
  33.  *
  34.  *    FUC    ウィンドウ破棄
  35.  *
  36.  *    IN    ウィンドウポインター 
  37.  *    OT    無し
  38.  *    EX    無し
  39.  *
  40.  *************************************************************************/
  41. void    TrashWindow(WindowPtr TargetWindow)
  42. {
  43.     DisposeWindow(TargetWindow);
  44. }
  45.  
  46. //extern    TBHandle TextInputDialog();
  47.  
  48. /**************************************************************************
  49.  *
  50.  *    FUC    アクションイベント
  51.  *
  52.  *    IN    無し
  53.  *    OT    無し
  54.  *    EX    無し
  55.  *
  56.  *************************************************************************/
  57. void    DoAction(void)
  58. {
  59. //    SysBeep(0);
  60. }
  61.  
  62. /**************************************************************************
  63.  *
  64.  *    FUC    タブ値入力
  65.  *
  66.  *    IN    入力文字
  67.  *    OT    無し
  68.  *    EX    TEHtab tabsItemNow 
  69.  *
  70.  *************************************************************************/
  71. void    DoTab(char theChar)
  72. {
  73.     CharsHandle    hText;
  74.     short        len, maxLen;
  75.     Point        LocalMouse;
  76.     char        *p;
  77.     static short    pw[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};/* 10のべき乗TBL */
  78.  
  79.     if ( theChar == 0x08 || theChar == 0x1c || theChar == 0x1d ||
  80.         (theChar >= '0' && theChar <= '9') )    /* delet ← → */
  81.     {
  82.         TEKey(theChar, TEHtab);
  83.         hText = TEGetText(TEHtab);
  84.  
  85.         tabsItemNow = 0;
  86.         p = (char *)*hText + (*TEHtab)->teLength-1;
  87.         for (len = maxLen = (**TEHtab).teLength-1; len >= 0; len--) {
  88.             if (maxLen > 3) break;            /* Guard */
  89.             tabsItemNow += (int)( *p & 0x0f ) * pw[maxLen-len];
  90.             p--;
  91.         }
  92.         if (tabsItemNow > 32) {
  93.             tabsItemNow = 32;                /* Guard */
  94.             TESetText("32", 2, TEHtab);
  95.             TEUpdate(&viewRect, TEHtab);
  96.         }
  97.     }
  98.     else {
  99.         SysBeep(0);
  100.     }
  101. }
  102.  
  103. /**************************************************************************
  104.  *
  105.  *    FUC    スクロールリスト
  106.  *
  107.  *    IN    入力文字
  108.  *    OT    無し
  109.  *    EX    listData.hList 
  110.  *
  111.  *************************************************************************/
  112. void    DoScrollList(char theChar)
  113. {
  114.     EventRecord    event;            /* Dummy Event */
  115.     CharsHandle    hText;
  116.     short        len;
  117.     Rect        box;
  118.     Point        LocalMouse;
  119.  
  120.     if ( theChar == 0x1e ) {                    /* ↑ */
  121.         LocalMouse.h = (*listData.hList)->rView.right + 10;
  122.         LocalMouse.v = (*listData.hList)->rView.top   + 10;
  123.         event.what      = mouseDown;
  124. //        event.where.h   = inContent;
  125.         event.modifiers = 0;
  126.         
  127.         LClick(LocalMouse, event.modifiers, listData.hList);
  128.     }
  129.     else if ( theChar == 0x1f ) {                /* ↓ */
  130.         LocalMouse.h = (*listData.hList)->rView.right  + 10;
  131.         LocalMouse.v = (*listData.hList)->rView.bottom - 10;
  132.         event.what      = mouseDown;
  133. //        event.where     = inContent;
  134.         event.modifiers = 0;
  135.         
  136.         LClick(LocalMouse, event.modifiers, listData.hList);
  137.     }
  138.  
  139.  
  140. //        //@@@@@ScrollListをカーソルキーで動かしたい@@@@@
  141. //    if (    ((*listData.hList)->lastClick.v >= 0) && 
  142. //        ((*listData.hList)->lastClick.v <= listData.CellNum) ) 
  143. //    {
  144. //        LocalMouse.h = (*listData.hList)->rView.left;
  145. //        LocalMouse.v = (*listData.hList)->rView.top;
  146.  
  147. //        len = (*listData.hList)->lastClick.v * 32;
  148. //        LocalMouse.v += len;
  149. //        LClick(LocalMouse, event.modifiers, listData.hList);
  150. //        (*listData.hList)->lastClick.v++;
  151. //    }
  152.  
  153. //    theCell = LLastClick(lP->hList);
  154. //    if ( (theCell.v >= 0) && (theCell.v <= lP->CellNum) ) {
  155. //        LDelRow(1, theCell.v, lP->hList);
  156. //        if (lP->CellNum >= 0) lP->CellNum--;
  157.  
  158. //        (*lP->hList)->lastClick.v = -1;
  159. //        (*lP->hList)->lastClick.h = -1;
  160. //    }
  161.  
  162. //        LAutoScroll(listData.hList);
  163. //        LocalMouse.h = event.where.h, LocalMouse.v = event.where.v;
  164. //        GlobalToLocal(&LocalMouse);
  165. //        box = (*listData.hList)->rView, box.right += scrollBarWidth;
  166. //        if ( PtInRect(LocalMouse, &(*listData.hList)->rView) ) {
  167. //            LClick(LocalMouse, event.modifiers, listData.hList);
  168. //            DoButtonHilite();
  169. //        }
  170. }
  171.  
  172. /**************************************************************************
  173.  *
  174.  *    FUC    コンテント
  175.  *
  176.  *    IN    ウィンドウポインター 
  177.  *    OT    無し
  178.  *    EX    無し
  179.  *
  180.  *************************************************************************/
  181. void    DoContent(WindowPtr TargetWindow)
  182. {
  183.     int        i;
  184.     int        cntlCode;
  185.     ControlHandle    theControl;
  186.     Point        LocalMouse;
  187.     Rect        box;
  188.     
  189.     if(TargetWindow != FrontWindow())    SelectWindow(TargetWindow);
  190.     else {
  191.         LocalMouse.h = event.where.h;
  192.         LocalMouse.v = event.where.v;
  193.         GlobalToLocal(&LocalMouse);
  194.  
  195.         if ( (cntlCode = FindControl(LocalMouse, TargetWindow, &theControl)) ) {
  196.             switch (cntlCode) {
  197.                 case 1:        /* PopUpMenu */
  198.                     DoContentPopUpMenu(theControl);
  199.                     break;
  200.                 case inCheckBox:
  201.                     DoContentCheckBox(theControl);
  202.                     break;
  203.                 case inButton:
  204.                     DoContentButton(theControl);
  205.                     break;
  206.                 default:
  207.                     box = (*listData.hList)->rView;
  208.                     box.right += scrollBarWidth;
  209.                     if ( PtInRect(LocalMouse, &box) ) {
  210.                         i = LClick(LocalMouse, event.modifiers, listData.hList);
  211.                         DoButtonHilite();
  212.                     }
  213.                     break;
  214.             }
  215.         }
  216.         else {
  217.             box = (*listData.hList)->rView;
  218.             box.right += scrollBarWidth;
  219.             if ( PtInRect(LocalMouse, &box) ) {
  220.                 i = LClick(LocalMouse, event.modifiers, listData.hList);
  221.                 DoButtonHilite();
  222.             }
  223.  
  224.             TEDeactivate(TEHtab);
  225.             if ( PtInRect(LocalMouse, &(*TEHtab)->viewRect) ) {
  226.                 TEActivate(TEHtab);
  227.                 TEClick(LocalMouse, event.modifiers, TEHtab);
  228.             }
  229.  
  230.             DoContentColorIconButton();
  231.         }
  232.     }
  233. }
  234.  
  235. /**************************************************************************
  236.  *
  237.  *    FUC    ポップアップメニュー
  238.  *
  239.  *    IN    コントロールハンドル
  240.  *    OT    無し
  241.  *    EX    無し
  242.  *
  243.  *************************************************************************/
  244. void    DoContentPopUpMenu(ControlHandle theControl)
  245. {
  246.     int        on;
  247.     Point        mouseLoc, Global;
  248.     long        ItemID = false;
  249.  
  250.     GetMouse(&mouseLoc);
  251.     on = PtInRect(mouseLoc, &(**hControl[fontCntlNumber]).contrlRect);
  252.     if ( on ) {
  253.         Global.v = (**hControl[fontCntlNumber]).contrlRect.top;
  254.         Global.h = (**hControl[fontCntlNumber]).contrlRect.left;
  255.         LocalToGlobal(&Global);
  256.  
  257.         ItemID = PopUpMenuSelect(GetMHandle(fontMenuID), Global.v, Global.h, fontItemNow);
  258.     }
  259.     else {
  260.         on = PtInRect(mouseLoc, &(**hControl[sizeCntlNumber]).contrlRect);
  261.         if ( on ) {
  262.             Global.v = (**hControl[sizeCntlNumber]).contrlRect.top;
  263.             Global.h = (**hControl[sizeCntlNumber]).contrlRect.left;
  264.             LocalToGlobal(&Global);
  265.  
  266.             ItemID = PopUpMenuSelect(GetMHandle(sizeMenuID),
  267.                                     Global.v, Global.h, sizeItemNow);
  268.         }
  269.     }
  270.  
  271.     if (ItemID) {
  272.         DoMenu(ItemID);
  273.  
  274.         SetCtlValue(theControl, ItemID);            // PopUpMenu 表示変更
  275.     }
  276. }
  277.  
  278. /**************************************************************************
  279.  *
  280.  *    FUC    チェックボックス
  281.  *
  282.  *    IN    コントロールハンドル
  283.  *    OT    無し
  284.  *    EX    無し
  285.  *
  286.  *************************************************************************/
  287. void    DoContentCheckBox(ControlHandle theControl)
  288. {
  289.     int    value, on, refCon;
  290.     Point    mouseLoc;
  291.  
  292.     TrackControl(theControl, event.where, (void*)-1);    /* inButtonが返る */
  293.  
  294.     GetMouse(&mouseLoc);
  295.     on = PtInRect(mouseLoc, &(**theControl).contrlRect);
  296.     if ( on ) {
  297.         value = GetCtlValue(theControl);
  298.  
  299.         refCon = GetCRefCon(theControl);        /* コントロールID値を入れておく*/
  300.         if (refCon == lineNumCntlID) {
  301.             value ^= 1;
  302.             SetCtlValue(theControl, value);    /* Max=1 Min=0 */
  303.         }
  304.         else if ( !value ) {
  305.             if (refCon == lineSpaceNormalCntlID) {        /* 普通 */
  306.                 SetCtlValue(hControl[lineSpaceNarrowCntlNumber], 0);    /* OFF  */
  307.                 SetCtlValue(theControl, 1);                    /* ON   */
  308.             }
  309.             else if (refCon == lineSpaceNarrowCntlID) {        /* 狭く */
  310.                 SetCtlValue(hControl[lineSpaceNormalCntlNumber], 0);
  311.                 SetCtlValue(theControl, 1);
  312.             }
  313.         }
  314.     }
  315. }
  316.  
  317. /**************************************************************************
  318.  *
  319.  *    FUC    ボタン
  320.  *
  321.  *    IN    コントロールハンドル
  322.  *    OT    無し
  323.  *    EX    無し
  324.  *
  325.  *************************************************************************/
  326. void    DoContentButton(ControlHandle theControl)
  327. {
  328.     int    Value, on;
  329.     Point    mouseLoc;
  330.  
  331.     TrackControl(theControl, event.where, (void*)-1);    /* inButtonが返る */
  332.  
  333.     GetMouse(&mouseLoc);
  334.     on = PtInRect(mouseLoc, &(**theControl).contrlRect);
  335.     if ( on ) {
  336.         Value = GetCtlValue(theControl);
  337.         if (Value == removeCntlID) {
  338.             if ( ScrollListDelCell(&listData) )
  339.                 SelectFileDelete(listData.DelCell.v, &listData);
  340.             DoButtonHilite();
  341.         }
  342.         else if (Value == printCntlID) {
  343.             DoPrintCommand();
  344.         }
  345.     }
  346. }
  347.  
  348. /**************************************************************************
  349.  *
  350.  *    FUC    カラーアイコンボタン
  351.  *
  352.  *    IN    コントロールハンドル
  353.  *    OT    無し
  354.  *    EX    hColorIcon[]
  355.  *
  356.  *        1995/02/09 新規作成
  357.  *
  358.  *************************************************************************/
  359. void    DoContentColorIconButton(void)
  360. {
  361.     int        i, on, mouseOn, iconNum;
  362.     Point        mouseLoc;
  363.     EventRecord    event;            /* Self Loop Event */
  364.     Boolean        isEvent;
  365.  
  366.     iconNum = 0;
  367.     GetMouse(&mouseLoc);
  368.     on = PtInRect(mouseLoc, &cIconData[iconNum].rect);
  369.     if ( !on ) {
  370.         on = PtInRect(mouseLoc, &cIconData[++iconNum].rect);
  371.     }
  372.  
  373.     if ( on ) {
  374.         mouseOn = false;
  375.         while ( true ) {
  376.             isEvent = WaitNextEvent(everyEvent, &event, 2, 0);
  377.             SystemTask();            /* DAに一定時間を配分する        */
  378.  
  379.             if (event.what == mouseUp) {
  380.                 break;            /* 終了                    */
  381.             }
  382.  
  383.             GetMouse(&mouseLoc);
  384.             on = PtInRect(mouseLoc, &cIconData[iconNum].rect);
  385.             if ( on ) {
  386.                 if ( !mouseOn ) {
  387.                     PlotCIcon(&cIconData[iconNum].rect,
  388.                                     cIconData[iconNum].ciHandle[1]);
  389.                     mouseOn = true;
  390.                 }
  391.             }
  392.             else {
  393.                 if ( mouseOn ) {
  394.                     PlotCIcon(&cIconData[iconNum].rect,
  395.                                     cIconData[iconNum].ciHandle[0]);
  396.                     mouseOn = false;
  397.                 }
  398.             }
  399.         };
  400.         PlotCIcon(&cIconData[iconNum].rect, cIconData[iconNum].ciHandle[0]);
  401.     }
  402. }
  403.  
  404.  
  405. //TrackControl()は、コントロール以外の場合にはダメのようだ
  406. //    TrackControl((ControlHandle)hColorIcon[0], event.where, (void*)ColorIconButton);
  407. //    TrackControl((ControlHandle)hColorIcon[0], event.where, (void*)-1);    バクダン
  408. //    TrackControl((ControlHandle)hColorIcon[0],        終了は出来る
  409. //    TrackControl(hControl[removeCntlID],        落ちる
  410. //    TrackControl((ControlHandle)0,            落ちる
  411.  
  412. /**************************************************************************
  413.  *
  414.  *    FUC    ドラッグ
  415.  *
  416.  *    IN    ウィンドウポインター 
  417.  *    OT    無し
  418.  *    EX    無し
  419.  *
  420.  *************************************************************************/
  421. void    DoDrag(WindowPtr TargetWindow)
  422. {
  423.     Rect    DragArea;
  424.  
  425.     if(TargetWindow != FrontWindow())
  426.         SelectWindow(TargetWindow);
  427.     else {
  428.         DragArea = screenBits.bounds;
  429.         InsetRect(&DragArea,4,4);
  430.         DragWindow(TargetWindow, event.where, &DragArea);
  431.     }
  432. }
  433.  
  434. /**************************************************************************
  435.  *
  436.  *    FUC    グロウ
  437.  *
  438.  *    IN    ウィンドウポインター 
  439.  *    OT    無し
  440.  *    EX    無し
  441.  *
  442.  *************************************************************************/
  443. void    DoGrow(WindowPtr TargetWindow)
  444. {
  445.     long    Growth;
  446.     Rect    GrowArea;
  447.  
  448.     if(TargetWindow != FrontWindow())
  449.         SelectWindow(TargetWindow);
  450.     else {
  451.         GrowArea = screenBits.bounds;
  452.         GrowArea.left += 40; GrowArea.top += 40;
  453.         Growth = GrowWindow(TargetWindow, event.where, &GrowArea);
  454.         if(Growth != 0) {
  455.             EraseRect    (&TargetWindow->portRect);
  456.             SizeWindow    (TargetWindow, LoWord(Growth), HiWord(Growth), true);
  457. //            DrawGrowIcon    (TargetWindow);    /* サイズボックス・スクロールバー枠描画 */
  458.             InvalRect    (&TargetWindow->portRect);    /* UpDate領域に追加        */
  459.             ValidGrowArea    (&TargetWindow->portRect);    /* UpDate領域から削除        */
  460. //            DrawControls    (TargetWindow);    /* コントロールを全て描く        */
  461.         }
  462.     }
  463. }
  464.  
  465. /**************************************************************************
  466.  *
  467.  *    FUC    
  468.  *
  469.  *    IN    ウィンドウポインター 
  470.  *    OT    無し
  471.  *    EX    無し
  472.  *
  473.  *************************************************************************/
  474. void    DoGoAway(WindowPtr TargetWindow, Point Click)
  475. {
  476.     if(TargetWindow != FrontWindow())
  477.         SelectWindow(TargetWindow);
  478.     else if(TrackGoAway(TargetWindow, Click)) ;
  479. ////        DoCloseCommand();
  480. }
  481.  
  482. /**************************************************************************
  483.  *
  484.  *    FUC    ズーム
  485.  *
  486.  *    IN    ウィンドウポインター 
  487.  *    OT    無し
  488.  *    EX    無し
  489.  *
  490.  *************************************************************************/
  491. void    DoZoom(WindowPtr TargetWindow, Point Click, int Part)
  492. {
  493.     if(TargetWindow != FrontWindow())
  494.         SelectWindow(TargetWindow);
  495.     else if(TrackBox(TargetWindow, Click, Part))
  496.         ZoomWindow(TargetWindow, Part, false);
  497. }
  498.  
  499. /**************************************************************************
  500.  *
  501.  *    FUC    
  502.  *
  503.  *    IN    箱形
  504.  *    OT    無し
  505.  *    EX    無し
  506.  *
  507.  *************************************************************************/
  508. void    ValidGrowArea(Rect * pRect)
  509. {
  510.     Rect vRect;
  511.     SetRect(&vRect, pRect->right-scrollBarWidth, pRect->top, pRect->right, pRect->bottom);
  512.     ValidRect(&vRect);
  513.     SetRect(&vRect, pRect->left, pRect->bottom-scrollBarWidth, pRect->right, pRect->bottom);
  514.     ValidRect(&vRect);
  515. }