home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / Private.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.0 KB  |  192 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*-----------------------------------------*/
  19. /*                                                                        */
  20. /* Name:        <Xfe/Private.c>                                            */
  21. /* Description:    Xfe widgets private utilities.                            */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29.  
  30. #include <Xfe/XfeP.h>
  31.  
  32. #define MESSAGE1 "%s needs to have the same depth as the widget."
  33. #define MESSAGE2 "Cannot obtain geometry info for %s."
  34.  
  35. /*----------------------------------------------------------------------*/
  36. /*                                                                        */
  37. /* Callbacks                                                            */
  38. /*                                                                        */
  39. /*----------------------------------------------------------------------*/
  40. /* extern */ void
  41. _XfeInvokeCallbacks(Widget            w,
  42.                     XtCallbackList    list,
  43.                     int                reason,
  44.                     XEvent *        event,
  45.                     Boolean            flush_display)
  46. {
  47.     /* Make sure widget is alive and callback list is not NULL */
  48.     if (_XfeIsAlive(w) && list)
  49.     {
  50.         XmAnyCallbackStruct cbs;
  51.         
  52.         cbs.event     = event;
  53.         cbs.reason    = reason;
  54.  
  55.         /* Flush the display before invoking callback if needed */
  56.         if (flush_display)
  57.         {
  58.             XFlush(XtDisplay(w));
  59.         }
  60.  
  61.         /* Invoke the Callback List */
  62.         XtCallCallbackList(w,list,&cbs);
  63.     }
  64. }
  65. /*----------------------------------------------------------------------*/
  66.  
  67. /*----------------------------------------------------------------------*/
  68. /*                                                                        */
  69. /* Warnings                                                                */
  70. /*                                                                        */
  71. /*----------------------------------------------------------------------*/
  72. /* extern */ void
  73. _XfeSimpleWarning(Widget w,String warning)
  74. {
  75.     static char buf[2048];
  76.  
  77.     sprintf(buf,
  78.             "\n\t%s: %s\n\t%s: %s\n\t%s\n",
  79.             "Name",XtName(w),
  80.             "Class",w->core.widget_class->core_class.class_name,
  81.             warning);
  82.  
  83.     XtAppWarning(XtWidgetToApplicationContext(w),buf);
  84. }
  85. /*----------------------------------------------------------------------*/
  86. /* extern */ void
  87. _XfeExtraWarning(Widget        w,
  88.                  String        warning,
  89.                  String        filename,
  90.                  Cardinal    lineno)
  91. {
  92.     static char buf[2048];
  93.     static char line_buf[32];
  94.     static char window_buf[32];
  95.  
  96.     if (lineno)
  97.     {
  98.         sprintf(line_buf,"%d",lineno);
  99.     }
  100.     else
  101.     {
  102.         sprintf(line_buf,"%s","unknown");
  103.     }
  104.  
  105.     if (XtIsRealized(w))
  106.     {
  107.         Widget windowed = XfeWindowedWidget(w);
  108.  
  109.         if (_XfeWindow(windowed) && (_XfeWindow(windowed) != None))
  110.         {
  111.             if (w == windowed)
  112.             {
  113.                 sprintf(window_buf,"0x%x",(int) _XfeWindow(windowed));
  114.             }
  115.             else
  116.             {
  117.                 sprintf(window_buf,"0x%x (parent's)",(int) _XfeWindow(windowed));
  118.             }
  119.         }
  120.         else
  121.         {
  122.             sprintf(window_buf,"%s","invalid");
  123.         }
  124.  
  125.         
  126.     }
  127.     else
  128.     {
  129.         sprintf(window_buf,"%s","unrealized");
  130.     }
  131.  
  132.     sprintf(buf,
  133.             "\n  %-14s %s\n  %-14s %s\n  %-14s %s\n  %-14s %s\n  %-14s %s\n  %s",
  134.             "Filename:",        filename ? filename : "unknown",
  135.             "Line Number:",        line_buf,
  136.             "Widget Name:",        XtName(w),
  137.             "Widget Class:",    w->core.widget_class->core_class.class_name,
  138.             "Widget Window:",    window_buf,
  139.             warning);
  140.  
  141.     XtAppWarning(XtWidgetToApplicationContext(w),buf);
  142. }
  143. /*----------------------------------------------------------------------*/
  144. /* extern */ void
  145. _XfeArgumentWarning(Widget        w,
  146.                     String        format,
  147.                     XtPointer    argument,
  148.                     String        filename,
  149.                     Cardinal    lineno)
  150. {
  151.     static char buf[2048];
  152.  
  153.     sprintf(buf,format,argument);
  154.  
  155.     _XfeExtraWarning(w,buf,filename,lineno);
  156. }
  157. /*----------------------------------------------------------------------*/
  158.  
  159. /*----------------------------------------------------------------------*/
  160. /*                                                                        */
  161. /* Actions                                                                */
  162. /*                                                                        */
  163. /*----------------------------------------------------------------------*/
  164. /* extern */ XtActionProc
  165. _XfeGetActionProc(WidgetClass wc,String name)
  166. {
  167.     XtActionProc    proc = NULL;
  168.     XtActionsRec *    action_list = NULL;
  169.     Cardinal        num_actions;
  170.     Cardinal        i;
  171.  
  172.     assert( wc != NULL );
  173.  
  174.     XtGetActionList(wc,&action_list,&num_actions);
  175.  
  176.     if (action_list && num_actions)
  177.     {
  178.         for(i = 0; i < num_actions; i++)
  179.         {
  180.             if (strcmp(action_list[i].string,name) == 0)
  181.             {
  182.                 proc = action_list[i].proc;
  183.             }
  184.         }
  185.  
  186.         XtFree((char *) action_list);
  187.     }
  188.  
  189.     return proc;
  190. }
  191. /*----------------------------------------------------------------------*/
  192.