home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gkdemo.zip / GKFILES.SET / DEMOCTRL.C < prev    next >
C/C++ Source or Header  |  1994-12-09  |  7KB  |  249 lines

  1. /* Demo of some of the controls    */
  2. #define GKInclAll
  3. #include "gk.h"
  4.  
  5. static void MenuOpenNotify(GKObject menu);
  6. static void MenuCloseNotify(GKObject menu);
  7. static void MenuNotify(GKObject menu, GKObject mitem, int cmd);
  8. static void PopUpMenuAccel(GKObject obj, GKEvent *eventp, GKVal proc_data);
  9. static void PushMeNotify(GKObject obj);
  10. static void EditNotify(GKObject obj);
  11. static void CBNotify(GKObject obj, int cmd);
  12. static void SliderNotify(GKObject obj, long position, int cmd);
  13. static void ButtonNotify(GKObject obj);
  14. static void RemoveObj(GKObject obj, GKEvent *eventp, GKVal proc_data);
  15.  
  16. static int menu_notify_flag=GKTRUE;
  17.  
  18. main(argc,argv)
  19. int        argc;
  20. char    **argv;
  21. {
  22.     gkRegisterNamedProcedure("MenuOpenNotify", (GKNamedProcedure)MenuOpenNotify);
  23.     gkRegisterNamedProcedure("MenuCloseNotify", (GKNamedProcedure)MenuCloseNotify);
  24.     gkRegisterNamedProcedure("MenuNotify", (GKNamedProcedure)MenuNotify);
  25.     gkRegisterNamedProcedure("PopUpMenuAccel", (GKNamedProcedure)PopUpMenuAccel);
  26.     gkRegisterNamedProcedure("PushMeNotify", (GKNamedProcedure)PushMeNotify);
  27.     gkRegisterNamedProcedure("EditNotify", (GKNamedProcedure)EditNotify);
  28.     gkRegisterNamedProcedure("CBNotify", (GKNamedProcedure)CBNotify);
  29.     gkRegisterNamedProcedure("SliderNotify", (GKNamedProcedure)SliderNotify);
  30.     gkRegisterNamedProcedure("ButtonNotify", (GKNamedProcedure)ButtonNotify);
  31.     gkRegisterNamedProcedure("RemoveObj", (GKNamedProcedure)RemoveObj);
  32.  
  33.     gkInit(GKInit_Args, &argc, argv,
  34.            GKInit_StripArgs,
  35.            NULL);
  36.  
  37.     if (gkCreateObjectGroup("Democtrl-Fonts") == -1) {
  38.         gkError("Couldn't create democtrl object group");
  39.         exit(1);
  40.     }
  41.  
  42.     if (gkCreateObjectGroup("Democtrl") == -1) {
  43.         gkError("Couldn't create democtrl object group");
  44.         exit(1);
  45.     }
  46.  
  47.     gkSet(gkFindInstance("MainFrame"),
  48.           GKWindow_Show, GKTRUE,
  49.           GKWindow_TopLevelAccelerator,    "Btn3Down",    PopUpMenuAccel,
  50.                       gkFindInstance("Options-SubMenu"),
  51.           NULL);
  52.  
  53.     gkDispatch();
  54. }
  55.  
  56. /*----------------------------------------------------------------------*/
  57. /* Menu Item notification
  58.  */
  59. static void    MenuOpenNotify(GKObject menu)
  60. {
  61.     GKObject    edit;
  62.  
  63.     edit=gkFindInstance("MyEdit");
  64.     if (edit != NULL)
  65.         gkSet(edit,
  66.               GKEdit_Text, "Menu Opened",
  67.               NULL);
  68. }
  69.  
  70. /*----------------------------------------------------------------------*/
  71. static void    MenuCloseNotify(GKObject menu)
  72. {
  73.     GKObject    edit;
  74.  
  75.     edit=gkFindInstance("MyEdit");
  76.     if (edit != NULL)
  77.         gkSet(edit,
  78.               GKEdit_Text, "Menu Closed",
  79.               NULL);
  80. }
  81.  
  82. /*----------------------------------------------------------------------*/
  83. static void    MenuNotify(GKObject menu, GKObject mitem, int cmd)
  84. {
  85.     GKObject    edit, obj;
  86.     char        b[100], *label;
  87.  
  88.     if (!menu_notify_flag)
  89.         return;
  90.  
  91.     label=(char *)gkGet((GKObject)gkGet(mitem, GKMenuItem_LabelGfxObj, NULL),
  92.                         GKGfxText_String, NULL);
  93.  
  94.     switch (cmd) {
  95.     case GKMenuItemCmd_Highlighted:
  96.         ut_snprintf(b,sizeof(b),"Highlighted %s", label);
  97.         break;
  98.  
  99.     case GKMenuItemCmd_Selected:
  100.         ut_snprintf(b,sizeof(b),"Selected %s", label);
  101.         if ((menu == gkFindInstance("File-SubMenu")) &&
  102.             (gkGet(menu, GKMenu_ItemIdx, mitem) == 0)) {
  103.             if (gkCreateObjectGroup("OpenDialogGroup") == 0) {
  104.                 if ((int)gkGet(gkFindInstance("OpenDialog"), GKFileDialog_Canceled, NULL))
  105.                     strcpy(b,"File Open Canceled");
  106.                 else
  107.                     ut_snprintf(b,sizeof(b),"Open file '%s'", 
  108.                         (char *)gkGet(gkFindInstance("OpenDialog"), GKFileDialog_FileName, NULL));
  109.  
  110.                 gkDestroy(gkFindInstance("OpenDialog"));
  111.             }
  112.         }
  113.  
  114.         break;
  115.     }
  116.  
  117.     edit=gkFindInstance("MyEdit");
  118.     if (edit != NULL)
  119.         gkSet(edit,
  120.               GKEdit_Text, b,
  121.               NULL);
  122. }
  123.  
  124. /*----------------------------------------------------------------------*/
  125. static void PopUpMenuAccel(obj,eventp,proc_data)
  126. GKObject    obj;
  127. GKEvent        *eventp;
  128. GKVal        proc_data;
  129. {
  130.     GKPoint    pt;
  131.  
  132.     pt.x=eventp->u.button.x;
  133.     pt.y=eventp->u.button.y;
  134.     gkWindowCoorToDisplayCoor(eventp->window, &pt);
  135.     gkInvokePopUpMenu((GKObject)proc_data, pt.x, pt.y, eventp->u.button.button);
  136. }
  137.  
  138. /*----------------------------------------------------------------------*/
  139. /* Button notification 
  140.  */
  141. static void    PushMeNotify(obj)
  142. GKObject    obj;
  143. {
  144.     if (gkCreateObjectGroup("MyDialogGroup") == -1) {
  145.         gkError("Couldn't create dialog");
  146.         return;
  147.     }
  148.  
  149.     gkModalDialog(gkFindInstance("MyDialog"), GKFALSE);
  150. }
  151.  
  152. /*----------------------------------------------------------------------*/
  153. /* Display message about modified text in edit object 
  154.  */
  155. static void    EditNotify(obj)
  156. GKObject    obj;
  157. {
  158.     gkInfo("Modified Text: \"%s\"", (char *)gkGet(obj, GKEdit_Text, NULL));
  159. }
  160.  
  161. /*----------------------------------------------------------------------*/
  162. /* Display info about ComboBox actions. 
  163.  */
  164. static void    CBNotify(obj, cmd)
  165. GKObject    obj;
  166. int            cmd;
  167. {
  168.     char        b[100], *str="???";
  169.     GKObject    edit;
  170.  
  171.     switch (cmd) {
  172.     case GKComboBoxCmd_TextChanged:    str="TextChanged"; break;
  173.     case GKComboBoxCmd_ListOpened:    str="ListOpened"; break;
  174.     case GKComboBoxCmd_ListClosed:    str="ListClosed"; break;
  175.     case GKComboBoxCmd_Executed:    str="Executed";
  176.         gkSet(obj,
  177.               GKComboBox_FontObj, gkFindInstance("Times-Roman-20.0"),
  178.               NULL);
  179.         break;
  180.     }
  181.  
  182.     ut_snprintf(b,sizeof(b),"Combo: cmd=%s Value=\"%s\"",str,
  183.                 (char *)gkGet(obj, GKComboBox_EditText, NULL));
  184.  
  185.     edit=gkFindInstance("MyEdit");
  186.  
  187.     if (edit != NULL) {
  188.         gkSet(edit,
  189.               GKEdit_Text, b,
  190.               NULL);
  191.     }
  192. }
  193.  
  194. /*----------------------------------------------------------------------*/
  195. /* Display info when slider is dragged or released.
  196.  */
  197. static void    SliderNotify(obj, position, cmd)
  198. GKObject    obj;
  199. long        position;
  200. int            cmd;
  201. {
  202.     char        b[80], *str="???";
  203.     GKObject    edit;
  204.  
  205.     edit=gkFindInstance("MyEdit");
  206.     if (edit != NULL) {
  207.         if (cmd == GKSliderCmd_Drag)
  208.             str="Drag";
  209.         else if (cmd == GKSliderCmd_Set)
  210.             str="Set";
  211.  
  212.         ut_snprintf(b,sizeof(b),"Slider %s pos=%ld",str,position);
  213.         gkSet(edit,
  214.               GKEdit_Text, b,
  215.               NULL);
  216.     }
  217. }
  218.  
  219. /*----------------------------------------------------------------------*/
  220. /* Change the label on the button when pressed
  221.  */
  222. static void    ButtonNotify(obj)
  223. GKObject    obj;
  224. {
  225.     GKGfxObj    label;
  226.     char        str[40];
  227.     int            cnt;
  228.  
  229.     label=(GKGfxObj)gkGet(obj, GKButton_LabelGfxObj, NULL);
  230.     cnt=(int)gkGet(obj, GKIR_KeyData, (GKVal)ButtonNotify);
  231.     if (cnt == 10)
  232.         menu_notify_flag=GKFALSE;
  233.  
  234.     gkSet(obj, GKIR_KeyData, (GKVal)ButtonNotify, (GKVal)(cnt+1),
  235.           NULL);
  236.     ut_snprintf(str, sizeof(str), "{UL}B{ul}utton-%d",cnt);
  237.     gkSet(label, GKGfxText_String, str,
  238.           NULL);
  239. }
  240.  
  241. /*----------------------------------------------------------------------*/
  242. static void RemoveObj(obj,eventp,proc_data)
  243. GKObject    obj;
  244. GKEvent        *eventp;
  245. GKVal        proc_data;
  246. {
  247.     gkDestroy(obj);
  248. }
  249.