Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 15.37 KB | None | 0 0
  1. #include "common.h"
  2. #include "logo.h"
  3. #include "event.h"
  4. #include "file.h"
  5. #include "menu.h"
  6. #include "mouse.h"
  7. #include "ui.h"
  8. #include "han.h"
  9. #include "pinyin.h"
  10. #include "edit.h"
  11. #include "music.h"
  12. #include "keyboard.h"
  13. #include "dialog.h"
  14. #include "select.h"
  15. #include "search.h"
  16. #include "cursor.h"
  17.  
  18. void MainLoop(void);
  19.  
  20. int main(void)
  21. {
  22.     MainLoop();
  23.     return 0;
  24. }
  25.  
  26. void InitAllKeyBinding(void *n)
  27. /* Initialize Keybindings */
  28. {
  29.     Event *func;
  30.    
  31.     func = ALLOC(sizeof(Event));
  32.     InitEvent(func);
  33.     RegEvent(func, &Exit);
  34.     AddKeyBinding(n, KBState(ESC, NOMOD), func);
  35.    
  36.     func = ALLOC(sizeof(Event));
  37.     InitEvent(func);
  38.     RegEvent(func, &ClearGraph);
  39.     RegEvent(func, &DrawLogo);
  40.     RegEvent(func, &Exit);
  41.     AddKeyBinding(n, KBState(F7, NOMOD), func);
  42.    
  43.     func = ALLOC(sizeof(Event));
  44.     InitEvent(func);
  45.     RegEvent(func, &OpenMenu0);
  46.     AddKeyBinding(n, KBState(F1, NOMOD), func);
  47.    
  48.     func = ALLOC(sizeof(Event));
  49.     InitEvent(func);
  50.     RegEvent(func, &OpenMenu1);
  51.     AddKeyBinding(n, KBState(F2, NOMOD), func);
  52.    
  53.     func = ALLOC(sizeof(Event));
  54.     InitEvent(func);
  55.     RegEvent(func, &OpenMenu2);
  56.     AddKeyBinding(n, KBState(F3, NOMOD), func);
  57.    
  58.     func = ALLOC(sizeof(Event));
  59.     InitEvent(func);
  60.     RegEvent(func, &OpenMenu3);
  61.     AddKeyBinding(n, KBState(F4, NOMOD), func);
  62.    
  63.     func = ALLOC(sizeof(Event));
  64.     InitEvent(func);
  65.     RegEvent(func, &OpenMenu4);
  66.     AddKeyBinding(n, KBState(F5, NOMOD), func);
  67.    
  68.     func = ALLOC(sizeof(Event));
  69.     InitEvent(func);
  70.     RegEvent(func, &MenuUp);
  71.     RegEvent(func, &CursorUp);
  72.     AddKeyBinding(n, KBState(UP, NOMOD), func);
  73.    
  74.     func = ALLOC(sizeof(Event));
  75.     InitEvent(func);
  76.     RegEvent(func, &MenuDown);
  77.     RegEvent(func, &CursorDown);
  78.     AddKeyBinding(n, KBState(DOWN, NOMOD), func);
  79.    
  80.     func = ALLOC(sizeof(Event));
  81.     InitEvent(func);
  82.     RegEvent(func, &FormMenuLeft);
  83.     RegEvent(func, &CursorLeft);
  84.     AddKeyBinding(n, KBState(LEFT, NOMOD), func);
  85.    
  86.     func = ALLOC(sizeof(Event));
  87.     InitEvent(func);
  88.     RegEvent(func, &FormMenuRight);
  89.     RegEvent(func, &CursorRight);
  90.     AddKeyBinding(n, KBState(RIGHT, NOMOD), func);
  91.    
  92.     func = ALLOC(sizeof(Event));
  93.     InitEvent(func);
  94.     RegEvent(func, &IMSwitch);
  95.     AddKeyBinding(n, KBState(SPACE, CTRL), func);
  96.    
  97.     func = ALLOC(sizeof(Event));
  98.     InitEvent(func);
  99.     RegEvent(func, &WidthSwitch);
  100.     AddKeyBinding(n, KBState(SPACE, LEFTSHIFT), func);
  101.    
  102.     func = ALLOC(sizeof(Event));
  103.     InitEvent(func);
  104.     RegEvent(func, &PuncSwitch);
  105.     AddKeyBinding(n, KBState('P', CTRL), func);
  106.    
  107.     func = ALLOC(sizeof(Event));
  108.     InitEvent(func);
  109.     RegEvent(func, &DrawOpenWindow);
  110.     AddKeyBinding(n, KBState('O', CTRL), func);
  111.    
  112.     func = ALLOC(sizeof(Event));
  113.     InitEvent(func);
  114.     RegEvent(func, &NewFile);
  115.     AddKeyBinding(n, KBState('N', CTRL), func);
  116.    
  117.     func = ALLOC(sizeof(Event));
  118.     InitEvent(func);
  119.     RegEvent(func, &DrawSaveWindow);
  120.     AddKeyBinding(n, KBState('S', CTRL), func);
  121.    
  122.     func = ALLOC(sizeof(Event));
  123.     InitEvent(func);
  124.     RegEvent(func, &DrawFindWindow);
  125.     AddKeyBinding(n, KBState('F', CTRL), func);
  126.    
  127.     func = ALLOC(sizeof(Event));
  128.     InitEvent(func);
  129.     RegEvent(func, &DrawReplaceWindow);
  130.     AddKeyBinding(n, KBState('H', CTRL), func);
  131.    
  132.     func = ALLOC(sizeof(Event));
  133.     InitEvent(func);
  134.     RegEvent(func, &BackSpace);
  135.     AddKeyBinding(n, KBState(BACKSPACE, NOMOD), func);
  136.    
  137.     func = ALLOC(sizeof(Event));
  138.     InitEvent(func);
  139.     RegEvent(func, &Delete);
  140.     AddKeyBinding(n, KBState(DELETE, NOMOD), func);
  141.    
  142.     func = ALLOC(sizeof(Event));
  143.     InitEvent(func);
  144.     RegEvent(func, &EnterKey);
  145.     AddKeyBinding(n, KBState(ENTER, NOMOD), func);
  146.    
  147.     func = ALLOC(sizeof(Event));
  148.     InitEvent(func);
  149.     RegEvent(func, &Home);
  150.     AddKeyBinding(n, KBState(HOME, NOMOD), func);
  151.    
  152.     func = ALLOC(sizeof(Event));
  153.     InitEvent(func);
  154.     RegEvent(func, &CtrlHome);
  155.     AddKeyBinding(n, KBState(CTRLHOME, CTRL), func);
  156.    
  157.     func = ALLOC(sizeof(Event));
  158.     InitEvent(func);
  159.     RegEvent(func, &End);
  160.     AddKeyBinding(n, KBState(END, NOMOD), func);
  161.    
  162.     func = ALLOC(sizeof(Event));
  163.     InitEvent(func);
  164.     RegEvent(func, &CtrlEnd);
  165.     AddKeyBinding(n, KBState(CTRLEND, CTRL), func);
  166.    
  167.     func = ALLOC(sizeof(Event));
  168.     InitEvent(func);
  169.     RegEvent(func, &CtrlA);
  170.     AddKeyBinding(n, KBState('A', CTRL), func);
  171.    
  172.     func = ALLOC(sizeof(Event));
  173.     InitEvent(func);
  174.     RegEvent(func, &CheckEnterSubmit);
  175.     AddKeyBinding(n, KBState(ENTER, NOMOD), func);
  176.    
  177.     func = ALLOC(sizeof(Event));
  178.     InitEvent(func);
  179.     RegEvent(func, &SwitchTextBox);
  180.     AddKeyBinding(n, KBState(TAB, NOMOD), func);
  181.    
  182.     func = ALLOC(sizeof(Event));
  183.     InitEvent(func);
  184.     RegEvent(func, &CancelButton);
  185.     AddKeyBinding(n, KBState('C', ALT), func);
  186.    
  187.     func = ALLOC(sizeof(Event));
  188.     InitEvent(func);
  189.     RegEvent(func, &OpenButton);
  190.     AddKeyBinding(n, KBState('O', ALT), func);
  191.    
  192.     func = ALLOC(sizeof(Event));
  193.     InitEvent(func);
  194.     RegEvent(func, &CmdSearch);
  195.     AddKeyBinding(n, KBState('F', ALT), func);
  196.    
  197.     func = ALLOC(sizeof(Event));
  198.     InitEvent(func);
  199.     RegEvent(func, &DoSearch);
  200.     AddKeyBinding(n, KBState(F6, NOMOD), func);
  201.    
  202.     func = ALLOC(sizeof(Event));
  203.     InitEvent(func);
  204.     RegEvent(func, &CmdReplace);
  205.     AddKeyBinding(n, KBState('R', ALT), func);
  206. }
  207.  
  208. void InitFormMenu(void *n)
  209. /* Initialize form menus */
  210. {
  211.     FormMenu *formmenu;
  212.     Menu *menu, *contextmenu;
  213.     State *s;
  214.     Event *func;
  215.     s = (State *)n;
  216.     formmenu = ALLOC(sizeof(FormMenu));
  217.     InitFormMenuItem(formmenu);
  218.    
  219.     AddFormMenu(formmenu, "文件(F1)");
  220.         menu = ALLOC(sizeof(Menu));
  221.         InitMenuItem(menu);
  222.         AddMenuToFormMenu(menu, formmenu);
  223.        
  224.         func = ALLOC(sizeof(Event));
  225.         InitEvent(func);
  226.         RegEvent(func, &NewFile);
  227.         AddMenu(menu, 1, "新建(N)      Ctrl+N", func);
  228.            
  229.         func = ALLOC(sizeof(Event));
  230.         InitEvent(func);
  231.         RegEvent(func, &DrawOpenWindow);
  232.         AddMenu(menu, 1, "打开(O)...   Ctrl+O", func);
  233.        
  234.         func = ALLOC(sizeof(Event));
  235.         InitEvent(func);
  236.         RegEvent(func, &DrawSaveWindow);
  237.         AddMenu(menu, 1, "保存(S)      Ctrl+S", func);
  238.        
  239.         func = ALLOC(sizeof(Event));
  240.         InitEvent(func);
  241.         RegEvent(func, &DrawSaveAsWindow);
  242.         AddMenu(menu, 1, "另存为...", func);
  243.        
  244.         func = ALLOC(sizeof(Event));
  245.         InitEvent(func);
  246.         RegEvent(func, &DoNothing);
  247.         AddMenu(menu, 0, "-", func);
  248.        
  249.         func = ALLOC(sizeof(Event));
  250.         InitEvent(func);
  251.         RegEvent(func, &Exit);
  252.         AddMenu(menu, 1, "退出(Q)      Esc", func);
  253.        
  254.     AddFormMenu(formmenu, "编辑(F2)");
  255.         menu = ALLOC(sizeof(Menu));
  256.         InitMenuItem(menu);
  257.         AddMenuToFormMenu(menu, formmenu);
  258.        
  259.         func = ALLOC(sizeof(Event));
  260.         InitEvent(func);
  261.         RegEvent(func, &DoNothing);
  262.         AddMenu(menu, 0, "撤销(U)      Ctrl+Z", func);
  263.        
  264.         func = ALLOC(sizeof(Event));
  265.         InitEvent(func);
  266.         RegEvent(func, &DoNothing);
  267.         AddMenu(menu, 0, "-", func);
  268.        
  269.         func = ALLOC(sizeof(Event));
  270.         InitEvent(func);
  271.         RegEvent(func, &DoNothing);
  272.         AddMenu(menu, 0, "剪切(T)      Ctrl+X", func);
  273.        
  274.         func = ALLOC(sizeof(Event));
  275.         InitEvent(func);
  276.         RegEvent(func, &DoNothing);
  277.         AddMenu(menu, 0, "复制(C)      Ctrl+C", func);
  278.        
  279.         func = ALLOC(sizeof(Event));
  280.         InitEvent(func);
  281.         RegEvent(func, &DoNothing);
  282.         AddMenu(menu, 0, "粘贴(P)      Ctrl+V", func);
  283.        
  284.         func = ALLOC(sizeof(Event));
  285.         InitEvent(func);
  286.         RegEvent(func, &Delete);
  287.         AddMenu(menu, 0, "删除(L)      Del", func);
  288.        
  289.         func = ALLOC(sizeof(Event));
  290.         InitEvent(func);
  291.         RegEvent(func, &DoNothing);
  292.         AddMenu(menu, 0, "-", func);
  293.        
  294.         func = ALLOC(sizeof(Event));
  295.         InitEvent(func);
  296.         RegEvent(func, &DrawFindWindow);
  297.         AddMenu(menu, 1, "查找(F)...   Ctrl+F", func);
  298.        
  299.         func = ALLOC(sizeof(Event));
  300.         InitEvent(func);
  301.         RegEvent(func, &DoSearch);
  302.         AddMenu(menu, 0, "查找下一个   F6", func);
  303.        
  304.         func = ALLOC(sizeof(Event));
  305.         InitEvent(func);
  306.         RegEvent(func, &DrawReplaceWindow);
  307.         AddMenu(menu, 1, "替换(R)...   Ctrl+H", func);
  308.        
  309.         func = ALLOC(sizeof(Event));
  310.         InitEvent(func);
  311.         RegEvent(func, &DoNothing);
  312.         AddMenu(menu, 0, "-", func);
  313.        
  314.         func = ALLOC(sizeof(Event));
  315.         InitEvent(func);
  316.         RegEvent(func, &DoNothing);
  317.         AddMenu(menu, 1, "全选(A)      Ctrl+A", func);
  318.        
  319.     AddFormMenu(formmenu, "选项(F3)");
  320.         menu = ALLOC(sizeof(Menu));
  321.         InitMenuItem(menu);
  322.         AddMenuToFormMenu(menu, formmenu);
  323.        
  324.         func = ALLOC(sizeof(Event));
  325.         InitEvent(func);
  326.         RegEvent(func, &ChangeDotted);
  327.         AddMenu(menu, 3 - s -> dotted, "平滑拖动", func);
  328.        
  329.         func = ALLOC(sizeof(Event));
  330.         InitEvent(func);
  331.         RegEvent(func, &ChangeHighlight);
  332.         AddMenu(menu, 2 + s -> highlight, "代码高亮", func);
  333.        
  334.         func = ALLOC(sizeof(Event));
  335.         InitEvent(func);
  336.         RegEvent(func, &DoNothing);
  337.         AddMenu(menu, 5, "自动换行", func);
  338.        
  339.     /*AddFormMenu(formmenu, "格式(F3)");
  340.         menu = ALLOC(sizeof(Menu));
  341.         InitMenuItem(menu);
  342.         AddMenuToFormMenu(menu, formmenu);
  343.        
  344.         func = ALLOC(sizeof(Event));
  345.         InitEvent(func);
  346.         RegEvent(func, &DoNothing);
  347.         AddMenu(menu, 1, "字体(F)...", func);*/
  348.    
  349.     AddFormMenu(formmenu, "工具(F4)");
  350.         menu = ALLOC(sizeof(Menu));
  351.         InitMenuItem(menu);
  352.         AddMenuToFormMenu(menu, formmenu);
  353.        
  354.         func = ALLOC(sizeof(Event));
  355.         InitEvent(func);
  356.         RegEvent(func, &Compile);
  357.         AddMenu(menu, 1, "编译(C)...   F9", func);
  358.        
  359.         func = ALLOC(sizeof(Event));
  360.         InitEvent(func);
  361.         RegEvent(func, &RandomMusic);
  362.         AddMenu(menu, 1, "音乐(M)...", func);
  363.        
  364.     AddFormMenu(formmenu, "帮助(F5)");
  365.         menu = ALLOC(sizeof(Menu));
  366.         InitMenuItem(menu);
  367.         AddMenuToFormMenu(menu, formmenu);
  368.        
  369.         func = ALLOC(sizeof(Event));
  370.         InitEvent(func);
  371.         RegEvent(func, &ShowHelp);
  372.         AddMenu(menu, 1, "帮助(H)...", func);
  373.        
  374.         func = ALLOC(sizeof(Event));
  375.         InitEvent(func);
  376.         RegEvent(func, &DoNothing);
  377.         AddMenu(menu, 0, "-", func);
  378.        
  379.         func = ALLOC(sizeof(Event));
  380.         InitEvent(func);
  381.         RegEvent(func, &ClearGraph);
  382.         RegEvent(func, &DrawLogo);
  383.         RegEvent(func, &DrawMainWindow);
  384.         RegEvent(func, &DrawFormMenu);
  385.         RegEvent(func, &DrawMainTextBox);
  386.         RegEvent(func, &DrawStatusBox);
  387.         AddMenu(menu, 1, "关于(A)...", func);
  388.    
  389.     contextmenu = ALLOC(sizeof(Menu));
  390.     InitMenuItem(contextmenu);
  391.    
  392.     func = ALLOC(sizeof(Event));
  393.     InitEvent(func);
  394.     RegEvent(func, &Exit);
  395.     AddMenu(contextmenu, 1, "关闭(C)", func);
  396.    
  397.     s -> menu = formmenu;
  398.     s -> contextmenu = contextmenu;
  399. }
  400.  
  401. void InitStatus(void *n)
  402. /* Initialize the main state */
  403. {
  404.     State *s;
  405.     s = (State *)n;
  406.    
  407.     s -> isexit = 0;
  408.     s -> isclearmenu = 0;
  409.     s -> isdrag = 0;
  410.     s -> ischosen = 0;
  411.     s -> startchar = 0;
  412.     s -> startrow = 0;
  413.     s -> endrow = 0;
  414.     s -> endchar = 0;
  415.     s -> ischildwindow = 0;
  416.     s -> dotted = 1;
  417.     s -> highlight = 0;
  418.     s -> isedit = 1;
  419.     s -> iscontextmenu = 0;
  420.     s -> page = 0;
  421.     s -> chinese = 0;
  422.     s -> chipunc = 0;
  423.     s -> fullwidth = 0;
  424.     s -> filehead = NULL;
  425.     s -> childhead = NULL;
  426.     s -> iscursor = 0;
  427.     s -> cursortime = -1;
  428.     s -> currentcolumn = 1;
  429.     s -> currentrow = 1;
  430.     s -> pagemovecount = 0;
  431.     s -> mousetype = 1;
  432.     s -> isput = 0;
  433.     s -> ispinyin = 0;
  434.     s -> pinyinpage = 0;
  435.     s -> sheng = 0;
  436.     s -> yun = 0;
  437.     s -> searchstring = NULL;
  438.     s -> isreplace = 0;
  439.     s -> filename = (char *)ALLOC(20 * sizeof(char));
  440.    
  441.     srand(time(0));
  442. }
  443.    
  444. void MainLoop(void)
  445. /* The main loop, everything is here! */
  446. {
  447.     Event *OnLoad, *OnUnload, *OnMainLoop, *Redraw;
  448.     /* The main loop events */
  449.    
  450.     State *s;
  451.    
  452.     s = (State *)ALLOC(sizeof(State));
  453.     OnLoad = ALLOC(sizeof(Event));
  454.     OnMainLoop = ALLOC(sizeof(Event));
  455.     OnUnload = ALLOC(sizeof(Event));
  456.     Redraw = ALLOC(sizeof(Event));
  457.  
  458.     InitEvent(OnLoad);
  459.     InitEvent(OnMainLoop);
  460.     InitEvent(OnUnload);
  461.     InitEvent(Redraw);
  462.  
  463.     /* Add customed functions here to register events
  464.      * Example:
  465.      *     RegEvent(&OnLoad, &custom_function);        */
  466.    
  467.     RegEvent(OnLoad, &InitStatus);
  468.     RegEvent(OnLoad, &InitGraph);
  469.     RegEvent(OnLoad, &StartupMusic);
  470.     RegEvent(OnLoad, &CalcDelay);
  471.     RegEvent(OnLoad, &InitColor);
  472.     RegEvent(OnLoad, &OpenHZK);
  473.     RegEvent(OnLoad, &NewFile);
  474.     RegEvent(OnLoad, &LoadKeyMap);
  475.     RegEvent(OnLoad, &LoadKeyBinding);
  476.     RegEvent(OnLoad, &InitAllKeyBinding);
  477.     RegEvent(OnLoad, &DrawMainWindow);
  478.     RegEvent(OnLoad, &DrawMainTextBox);
  479.     RegEvent(OnLoad, &InitFormMenu);
  480.     RegEvent(OnLoad, &DrawFormMenu);
  481.     RegEvent(OnLoad, &DrawStatusBox);
  482.     RegEvent(OnLoad, &LoadMouse);
  483.     RegEvent(OnLoad, &FadingColor);
  484.    
  485.     RegEvent(OnMainLoop, &PlayMusic);
  486.     RegEvent(OnMainLoop, &CheckKeyboard);
  487.     RegEvent(OnMainLoop, &CheckKeyBinding);
  488.     RegEvent(OnMainLoop, &CharInput);
  489.     RegEvent(OnMainLoop, &PinyinInput);
  490.     RegEvent(OnMainLoop, &PinyinShow);
  491.     RegEvent(OnMainLoop, &RedrawMouse);
  492.     RegEvent(OnMainLoop, &IsMoveOverMenu);
  493.     RegEvent(OnMainLoop, &DrawMoveOverMenu);
  494.     RegEvent(OnMainLoop, &ChildTitleContextMenu);
  495.     RegEvent(OnMainLoop, &IsClickFormMenu);
  496.     RegEvent(OnMainLoop, &IsMoveOverFormMenu);
  497.     RegEvent(OnMainLoop, &DrawMoveOverFormMenu);
  498.     RegEvent(OnMainLoop, &DrawClickFormMenu);
  499.     RegEvent(OnMainLoop, &MoveChildWindow);
  500.     RegEvent(OnMainLoop, &CheckChildButton);
  501.     RegEvent(OnMainLoop, &CheckIMSwitch);
  502.     RegEvent(OnMainLoop, &CheckStatus);
  503.     //RegEvent(OnMainLoop, &GetCurPos);
  504.     RegEvent(OnMainLoop, &FlashCur);
  505.     //RegEvent(OnMainLoop, &MousetoCursor);
  506.     RegEvent(OnMainLoop, &ChosenArea);
  507.     RegEvent(OnMainLoop, &IsExit);
  508.    
  509.     RegEvent(OnUnload, &LogoutMusic);
  510.     RegEvent(OnUnload, &CloseHZK);
  511.     RegEvent(OnUnload, &FadingColor);
  512.  
  513.     //RegEvent(Redraw, &DrawMainWindow);
  514.     RegEvent(Redraw, &DrawFormMenu);
  515.     RegEvent(Redraw, &DrawMainTextBox);
  516.     RegEvent(Redraw, &ClearMenuMoveOver);
  517.    
  518.     s -> redraw = Redraw;
  519.    
  520.     DoEvent(OnLoad, (void *)s);
  521.  
  522.     while(!s -> isexit)
  523.         DoEvent(OnMainLoop, (void *)s);
  524.    
  525.     DoEvent(OnUnload, (void *)s);
  526.    
  527.     FreeEvent(OnLoad);
  528.     FreeEvent(OnUnload);
  529.     FreeEvent(OnMainLoop);
  530.     FreeEvent(Redraw);
  531.     FREEMEMRow(s -> filehead);
  532.     FREEMEMChar(s -> searchstring);
  533.        
  534.     closegraph();
  535.    
  536.     while(1)
  537.         PlayMusic((void *)s);
  538. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement