home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / xv / paneltext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  3.7 KB  |  142 lines

  1. /* Paneltext XView package.
  2.    Copyright (C) 1995 Jakub Jelinek.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #ifdef HAVE_CONFIG_H
  19. #include <config.h>
  20. #endif
  21. #include <xview/xview.h>
  22. #include <xview/panel.h>
  23. #include <xview_private/draw_impl.h>
  24. #include <xview_private/panel_impl.h>
  25. #include "paneltext.h"
  26. #include "paneltext_impl.h"
  27.  
  28. Pkg_private int paneltext_init();
  29. Pkg_private Xv_opaque paneltext_set_avlist();
  30. Pkg_private Xv_opaque paneltext_get_attr();
  31. Pkg_private int paneltext_destroy();
  32. static void paneltext_accept_key(Paneltext paneltext, Event * event);
  33.  
  34. Xv_pkg paneltext_pkg =
  35. {
  36.     "Paneltext",
  37.     ATTR_PANELTEXT,
  38.     sizeof(Paneltext_struct),
  39.     &xv_panel_text_pkg,
  40.     paneltext_init,
  41.     paneltext_set_avlist,
  42.     paneltext_get_attr,
  43.     paneltext_destroy,
  44.     NULL
  45. };
  46.  
  47. Pkg_private int paneltext_init(Xv_opaque parent, Paneltext paneltext, 
  48.     Attr_avlist avlist)
  49. {
  50.     Paneltext_info *tinfo;
  51.     Paneltext_struct *paneltext_object;
  52.     Text_info *dp = TEXT_PRIVATE(paneltext);
  53.     Item_info *ip = ITEM_PRIVATE(paneltext);
  54.  
  55.     tinfo = xv_alloc(Paneltext_info);
  56.  
  57.     tinfo->notify = (void (*)()) NULL;
  58.  
  59.     paneltext_object = (Paneltext_struct *) paneltext;
  60.     paneltext_object->private_data = (Xv_opaque) tinfo;
  61.  
  62.     tinfo->accept_key = ip->ops.panel_op_accept_key;
  63.     ip->ops.panel_op_accept_key = (void (*)()) paneltext_accept_key;
  64.  
  65.     return XV_OK;
  66. }
  67.  
  68. Pkg_private Xv_opaque paneltext_set_avlist(Paneltext paneltext, 
  69.     Attr_avlist avlist)
  70. {
  71.     register Paneltext_attr attr;
  72.     register Paneltext_info *tinfo = PANELTEXT_PRIVATE(paneltext);
  73.  
  74.     if (*avlist != XV_END_CREATE) {
  75.     Xv_opaque set_result;
  76.     set_result =
  77.         xv_super_set_avlist(paneltext, &paneltext_pkg, avlist);
  78.     if (set_result != XV_OK) {
  79.         return set_result;
  80.     }
  81.     }
  82.     while ((attr = (Paneltext_attr) * avlist++))
  83.     switch (attr) {
  84.  
  85.     case PANELTEXT_NOTIFY:
  86.         ATTR_CONSUME(*(avlist - 1));
  87.         tinfo->notify = (void (*)()) *avlist++;
  88.         break;
  89.  
  90.     case XV_END_CREATE:
  91.         break;
  92.  
  93.     default:
  94.         avlist = attr_skip(attr, avlist);
  95.  
  96.     }
  97.  
  98.     return XV_SET_DONE;
  99. }
  100.  
  101. Pkg_private Xv_opaque paneltext_get_attr(Paneltext paneltext, int *status, 
  102.     Attr_attribute which_attr, Attr_avlist avlist)
  103. {
  104.     Paneltext_info *tinfo = PANELTEXT_PRIVATE(paneltext);
  105.     Text_info *dp = TEXT_PRIVATE(paneltext);
  106.  
  107.     switch (which_attr) {
  108.  
  109.     case PANELTEXT_NOTIFY:
  110.     return (Xv_opaque) tinfo->notify;
  111.  
  112.     case PANELTEXT_CARETPOS:
  113.     return (Xv_opaque) dp->caret_position;
  114.  
  115.     default:
  116.     *status = XV_ERROR;
  117.     return (Xv_opaque) 0;
  118.     }
  119. }
  120.  
  121. Pkg_private int paneltext_destroy(Paneltext paneltext, Destroy_status status)
  122. {
  123.     Paneltext_info *tinfo = PANELTEXT_PRIVATE(paneltext);
  124.  
  125.     if ((status == DESTROY_CHECKING) || (status == DESTROY_SAVE_YOURSELF))
  126.     return XV_OK;
  127.  
  128.     free(tinfo);
  129.     return XV_OK;
  130. }
  131.  
  132. static void paneltext_accept_key(Paneltext paneltext, Event * event)
  133. {
  134.     Paneltext_info *tinfo = PANELTEXT_PRIVATE(paneltext);
  135.     Text_info *dp = TEXT_PRIVATE(paneltext);
  136.  
  137.     if (tinfo->accept_key != NULL)
  138.     (*tinfo->accept_key) (paneltext, event);
  139.     if (tinfo->notify != NULL)
  140.     (*tinfo->notify) (paneltext, event, dp->value, dp->caret_position);
  141. }
  142.