home *** CD-ROM | disk | FTP | other *** search
/ Phoenix Heaven Sunny 2 / APPARE2.BIN / oh_towns / art2 / src.lzh / DESKTOP.C < prev    next >
C/C++ Source or Header  |  1995-06-19  |  9KB  |  362 lines

  1. #define MODULE_DESKTOPS
  2. #if 0
  3.  
  4. int    toolboxToolFunc(int kobj, int messId)
  5. int    desktop_about(int kobj)
  6. int    desktop_quit(int kobj)
  7. int    desktop_create(int kobj)
  8. int    desktopMITEMfile_loadimgFunc(kobj, messId, argc, pev, trigger)
  9. int    desktopMITEMfile_saveimgFunc(int kobj)
  10. int    desktop_setImageZoom(int kobj)
  11.  
  12. #endif
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <winb.h>
  18. #include <te.h>
  19. #include <fntb.h>
  20. #include <gui.h>
  21. #include <file_dlg.h>
  22. #include "art.h"
  23. #include "guisub.h"
  24. #include "alert.h"
  25.  
  26. #include "about.h"
  27. #include "imagewin.h"
  28. #include "colsel.h"
  29. #include "pic.h"
  30. #include "setup.h"
  31. #include "desktop.h"
  32.  
  33. int    idDesktopSelectiveHyper = -1 ;
  34. int    idBackDialog = -1 ;
  35. int    idDesktopWinAttachHyper = -1 ;
  36. int    idDesktopToolAttachHyper = -1 ;
  37. int    idToolBoxDlg = -1 ;
  38. int    idToolBoxToolTIcon[12] = -1 ;
  39. int    idToolBoxMsg = -1 ;
  40. int    idToolBoxUndoDBtn = -1 ;
  41. int    idDesktopDialog = -1 ;
  42. int    idDesktopMenu = -1 ;
  43. int    idDesktopMItem_System = -1 ;
  44. int    idDesktopSystemMenu = -1 ;
  45. int    idDesktopSystemMItem[3] = -1 ;
  46. int    idDesktopMItem_File = -1 ;
  47. int    idDesktopFileMenu = -1 ;
  48. int    idDesktopFileMItem[4] = -1 ;
  49. int    idDesktopMItem_Image = -1 ;
  50. int    idDesktopImageMenu = -1 ;
  51. int    idDesktopImageMItem[4] = -1 ;
  52. int    idDesktopZoomMenu = -1 ;
  53. int    idDesktopZoomMItem[8] = -1 ;
  54. int    idDesktopMItem_Setup = -1 ;
  55. int    idDesktopExitIcon = -1 ;
  56. int    idDesktopAlertHyper = -1 ;
  57. int    idDesktopHelpIcon = -1 ;
  58. int    idDesktopSkbIcon = -1 ;
  59. int    idDesktopFileDlgHyper = -1 ;
  60. int    idImageClearDlg = -1 ;
  61. int    idImageClearTitleMsg = -1 ;
  62. int    idImageClearMsg[4] = -1 ;
  63. int    idImageClearDBtn[2] = -1 ;
  64. int    idDesktopMItem_Edit = -1 ;
  65. int    idDesktopMItem_Layer = -1 ;
  66. int    idDesktopLayerMenu = -1 ;
  67. int    idDesktopLayerMItem[8] = -1 ;
  68.  
  69. static int tool_x = 0;
  70.  
  71. /*--------------------------------------------------------*/
  72. /*                   モジュールの初期化                   */
  73. /*--------------------------------------------------------*/
  74.  
  75. int        desktop_init(void)
  76. {
  77.     RM_initRadioButton(idToolBoxToolTIcon,INTNUM(idToolBoxToolTIcon),&tool_x);
  78.     return 0;
  79. }
  80.  
  81. /*--------------------------------------------------------*/
  82. /*                   部品の呼び出し関数                   */
  83. /*--------------------------------------------------------*/
  84.  
  85. int    toolboxToolFunc(int kobj, int messId)
  86. // idToolBoxToolTIcon[i]:MJ_TICONL40の呼び出し関数
  87. {
  88.     RM_pushRadioButton(kobj,idToolBoxDlg,idToolBoxToolTIcon,
  89.                        INTNUM(idToolBoxToolTIcon),&tool_x);
  90.     return NOERR ;
  91. }
  92.  
  93. int    ToolBoxUndoDBtnFunc(int kobj)
  94. /*    initDataZDESKTOP:idToolBoxUndoDBtn:MJ_DBUTTONL40の呼び出し関数    */
  95. {
  96.     imagewin_recoverUndo();
  97.     return NOERR ;
  98. }
  99.  
  100. int    desktop_about(int kobj)
  101. // desktopMITEMsystem_about:MJ_MITEML40の呼び出し関数
  102. {
  103.     WINCTRL* ctrl;
  104.     MMI_GetControl(&ctrl);
  105.     static char msgbuf[40];
  106.     sprintf(msgbuf, "Free Memory %dK", TL_checkMemory(0)*4);
  107.     MMI_SendMessage(aboutMSG[6], MM_SETMSG, 1, msgbuf);
  108.     static char msgbuf2[40];
  109.     sprintf(msgbuf2,"現在の画面: %d×%d×%s colors",
  110.             ctrl->bound.rdwx+1, ctrl->bound.rdwy+1, 
  111.             (scrPixelSize == 16 ? "32K" : "16M"));
  112.     MMI_SendMessage(aboutMSG[7], MM_SETMSG, 1, msgbuf2);
  113.     RM_moveCenter(aboutALT);
  114.     MMI_SendMessage(aboutALT, MM_ATTACH, 1, idDesktopAlertHyper);
  115.     MMI_SendMessage(aboutALT, MM_SHOW, 0);
  116.     return NOERR ;
  117. }
  118.  
  119. int    desktop_quit(int kobj)
  120. // desktopMITEMsystem_quit:MJ_MITEML40の呼び出し関数
  121. // desktopICONexit:MJ_ICONL40の呼び出し関数
  122. {
  123.     if (dispCheckMessage("ARTemisの終了",
  124.             "ARTemis を終了します。よろしいですか?", "終了") == 0)
  125.         MMI_SetHaltFlag(TRUE);
  126.     return NOERR ;
  127. }
  128.  
  129. int    desktop_create(int kobj)
  130. // desktopMITEMfile_create:MJ_MITEML40の呼び出し関数
  131. {
  132.     desktop_createNewPicture();
  133.     return NOERR ;
  134. }
  135.  
  136. int    desktopMITEMfile_loadimgFunc(int kobj)
  137. // desktopMITEMfile_loadimg:MJ_MITEML40の呼び出し関数
  138. {
  139.     char pathbuf[_MAX_PATH];
  140.     int ret;
  141.     ret = RM_callSimpleFDG(
  142.             idDesktopFileDlgHyper, idDesktopSelectiveHyper,
  143.             "画像の読込", "読込","取消",
  144.             "*.TIF",FDG_NONE,NULL,pathbuf);
  145.     if (ret != 0)
  146.         return NOERR;
  147.     TIFFINFO info;
  148.     if ((ret = RM_getTIFFinfo(pathbuf, &info)) != NOERR)
  149.     {
  150.         dispAlertMessage("画像の読み込み",
  151.             (ret == TIFFERR_NOMEMORY ? 
  152.                 "TIFF読み込み処理に必要なメモリが不足しているので、"
  153.                 "読み込むことができません" :
  154.              ret == TIFFERR_INVALIDFORMAT ?
  155.                 "このファイルはTIFFファイルではないので、"
  156.                 "ARTemisで読み込むことはできません" :
  157.  
  158.                 "ファイルをオープンできません")
  159.         );
  160.         return NOERR;
  161.     }
  162.     if (info.pixelsize != 16 && info.pixelsize != 24)
  163.     {
  164.         dispAlertMessage("画像の読み込み",
  165.                          "このファイルはフルカラーTIFFファイルでも"
  166.                          "32768色TIFFでもないので、ARTemisで読み込"
  167.                          "むことはできません");
  168.         return NOERR;
  169.     }
  170.     IMWIN* win = imagewin_new(info.pixelsize, info.wid, info.ht);
  171.     if (win == NULL)
  172.     {
  173.         dispAlertMessage("画像の読み込み",
  174.             "新しい画像ウィンドウ生成に必要なメモリが不足しています。"
  175.             "不要な画像ウィンドウをクローズしてみてください");
  176.         return NOERR;
  177.     }
  178.     imagewin_link(win);
  179.     imagewin_setFileName(win, pathbuf, FALSE);
  180.     imagewin_show(win);
  181.     int csr;
  182.     MG_PushPtr(MOSICON_WAIT, &csr);
  183.     pic_loadTIFF_(win->pic, pathbuf);
  184.     imagewin_updateBuf(win);
  185.     imagewin_updateScr(win);
  186.     MG_PopPtr(csr);
  187.     return NOERR;
  188. }
  189.  
  190. int    desktopMITEMfile_saveimgFunc(int kobj)
  191. // desktopMITEMfile_saveimg:MJ_MITEML40の呼び出し関数
  192. {
  193.     IMWIN* win = imagewin_getCurrentWin();
  194.     if (win == NULL)
  195.         return NOERR;
  196.     char pathbuf[_MAX_PATH];
  197.     int ret;
  198.     ret = RM_callSimpleFDG(
  199.             idDesktopFileDlgHyper, idDesktopSelectiveHyper,
  200.             "画像の保存", "保存","取消",
  201.             "*.TIF",FDG_TEXT,(win->fname[0]==0 ? NULL : win->fname),pathbuf);
  202.     if (ret != 0)
  203.         return NOERR;
  204.     char drive[_MAX_DRIVE],dir[_MAX_DIR],basename[_MAX_FNAME],ext[_MAX_EXT];
  205.     _splitpath(pathbuf, drive,dir,basename,ext);
  206.     if (basename[0] == 0)
  207.     {
  208.         dispAlertMessage("画像の保存",
  209.             "保存するファイル名が指定されませんでした");
  210.         goto END;
  211.     }
  212.     _makepath(pathbuf, drive,dir,basename,".TIF");
  213.     FILE *fp = fopen(pathbuf, "rb");
  214.     if (fp != NULL)
  215.     {
  216.         fclose(fp);
  217.         if (dispCheckMessage("画像の保存",
  218.                 "同じ名前のファイルがディスクに存在しています。"
  219.                 "上書きしますか?", "上書き") != 0)
  220.             goto END;
  221.     }
  222.     int csr;
  223.     MG_PushPtr(MOSICON_WAIT, &csr);
  224.     ret = pic_saveTIFF_(win->pic, pathbuf);
  225.     MG_PopPtr(csr);
  226.     if (ret == NOERR)
  227.         imagewin_setFileName(win, pathbuf, TRUE);
  228.     else if (ret == TIFFERR_NOMEMORY)
  229.     {
  230.         dispAlertMessage("画像の保存",
  231.                 "画像の保存処理に必要なメモリが不足しているので、"
  232.                 "保存することができません");
  233.     }
  234.     else if (ret == TIFFERR_NODISKSPACE)
  235.     {
  236.         dispAlertMessage("画像の保存",
  237.                 "ディスクの空き容量が不足しています");
  238.     }
  239.     else if (ret == TIFFERR_CANNOTOPEN)
  240.     {
  241.         dispAlertMessage("画像の保存",
  242.                 "ファイルがオープンできません。"
  243.                 "ファイル名に不適切な文字が含まれているのだと思います");
  244.     }
  245. END:
  246.     return NOERR ;
  247. }
  248.  
  249. int    Desktop_FileCloseProc(int kobj)
  250. // idDesktopFileMItem[3]:MJ_MITEML40の呼び出し関数
  251. {
  252.     IMWIN* win = imagewin_getCurrentWin();
  253.     if (win == NULL)
  254.         return NOERR;
  255.     char buf[250];
  256.     sprintf(buf, "画像 %s のウィンドウをクローズします。"
  257.             "画像データは破棄されますが、よろしいですか?",
  258.             (win->fname[0]==0 ? "<名称未定>" : win->fname));
  259.     if (dispCheckMessage("画像ウィンドウを閉じる", buf, "続行") == 0)
  260.     {
  261.         imagewin_unlink(win);
  262.         imagewin_destroy(win);
  263.         if (imagewin_getCurrentWin() == win)
  264.             imagewin_setCurrentWin(NULL);
  265.     }
  266.     return NOERR ;
  267. }
  268.  
  269. int    Desktop_UndoProc(int kobj)
  270. // idDesktopImageMItem[3]:MJ_MITEML40の呼び出し関数
  271. {
  272.     imagewin_recoverUndo();
  273.     return NOERR ;
  274. }
  275.  
  276.  
  277. static int flag_imgclear;
  278.  
  279.   /* ■画像のクリア■ */
  280.  
  281.         /*initDataDESKTOP:desktopMITEMfile_clear:MJ_MITEML40の呼び出し関数    */
  282.     int    desktopMITEMfile_clearFunc(kobj, messId, argc, pev, trigger)
  283.     int        kobj ;
  284.     int        messId ;
  285.     int        argc ;
  286.     EVENT    *pev ;
  287.     int        trigger ;
  288.     {
  289.         EXECDIALOG(idImageClearDlg);
  290.         if (flag_imgclear)
  291.         {
  292.             IMWIN *win;
  293.             if ((win = imagewin_getCurrentWin()) != NULL)
  294.             {
  295.                 WINCLIP *clip;
  296.                 PIXEL pixel;
  297.                 colsel_getPixel(&pixel);
  298.                 pic_clear(win->pic, &pixel);
  299.                 imagewin_updateBuf(win);
  300.                 imagewin_updateScr(win);
  301.             }
  302.         }
  303.         return NOERR ;
  304.     }
  305.  
  306.   /* ■「画像のクリア」ダイアログメニューのボタン■ */
  307.  
  308.         /*    initDataDESKTOP:imgclearDBTN[0]:MJ_DBUTTONL40の呼び出し関数    */
  309.         /*    initDataDESKTOP:imgclearDBTN[1]:MJ_DBUTTONL40の呼び出し関数    */
  310.     int    imgclearDBTNFunc(kobj, messId, argc, pev, trigger)
  311.     int        kobj ;
  312.     int        messId ;
  313.     int        argc ;
  314.     EVENT    *pev ;
  315.     int        trigger ;
  316.     {
  317.         if (kobj == idImageClearDBtn[0])
  318.             flag_imgclear = 1;
  319.         else
  320.             flag_imgclear = 0;
  321.         MMI_SetHaltFlag(TRUE);
  322.         return NOERR ;
  323.     }
  324.  
  325. int    desktop_setImageZoom(int kobj)
  326. // idDesktopZoomMItem[i]:MJ_MITEML40の呼び出し関数
  327. {
  328.     int i;
  329.     for (i=0; i<INTNUM(idDesktopZoomMItem); i++)
  330.         if (idDesktopZoomMItem[i] == kobj)
  331.             goto FOUND;
  332.     return NOERR;
  333.   FOUND:
  334.     IMWIN* win = imagewin_getCurrentWin();
  335.     if (win != NULL)
  336.     {
  337.         imagewin_setZoom(win, i+1);
  338.         imagewin_updateTitle(win, TRUE);
  339.     }
  340.     return NOERR ;
  341. }
  342.  
  343. /*    initDataZDESKTOP:idDesktopMItem_Setup:MJ_MITEML40の呼び出し関数    */
  344. int    desktop_setup(kobj, messId, argc, pev, trigger)
  345. int        kobj ;
  346. int        messId ;
  347. int        argc ;
  348. EVENT    *pev ;
  349. int        trigger ;
  350. {
  351.     cmd_setup();
  352.     return NOERR ;
  353. }
  354.  
  355.  
  356.  
  357. int        toolbox_getCurrentTool(void)
  358. {
  359.     return tool_x;
  360. }
  361.  
  362.