ButtonInterface.C 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: ButtonInterface.C /main/4 1996/04/05 16:48:43 mgreess $ */
  24. /*
  25. *+SNOTICE
  26. *
  27. * RESTRICTED CONFIDENTIAL INFORMATION:
  28. *
  29. * The information in this document is subject to special
  30. * restrictions in a confidential disclosure agreement bertween
  31. * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
  32. * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
  33. * Sun's specific written approval. This documment and all copies
  34. * and derivative works thereof must be returned or destroyed at
  35. * Sun's request.
  36. *
  37. * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
  38. *
  39. *+ENOTICE
  40. */
  41. ///////////////////////////////////////////////////////////////////////////////
  42. //////////////////////////////////////////////////////////////////////////////
  43. // This example code is from the book:
  44. //
  45. // Object-Oriented Programming with C++ and OSF/Motif
  46. // by
  47. // Douglas Young
  48. // Prentice Hall, 1992
  49. // ISBN 0-13-630252-1
  50. //
  51. // Copyright 1991 by Prentice Hall
  52. // All Rights Reserved
  53. //
  54. // Permission to use, copy, modify, and distribute this software for
  55. // any purpose except publication and without fee is hereby granted, provided
  56. // that the above copyright notice appear in all copies of the software.
  57. ///////////////////////////////////////////////////////////////////////////////
  58. //////////////////////////////////////////////////////////////////////////////
  59. //////////////////////////////////////////////////////////////
  60. // ButtonInterface.C: A push button interface to a Cmd object
  61. ///////////////////////////////////////////////////////////////
  62. #include <stdlib.h>
  63. #include <ctype.h>
  64. #include "ButtonInterface.h"
  65. #include <Xm/PushB.h>
  66. #include "Help.hh"
  67. #include "Cmd.h"
  68. ButtonInterface::ButtonInterface ( Widget parent,
  69. Cmd *cmd ) : CmdInterface ( cmd )
  70. {
  71. // We need to generate a button name that doesn't have illegal characters.
  72. //
  73. char w_name[200];
  74. mapName(_name, w_name);
  75. XmString label = XmStringCreateLocalized(_cmd->getLabel());
  76. _w = XtVaCreateWidget (w_name,
  77. xmPushButtonWidgetClass,
  78. parent,
  79. XmNlabelString, label, NULL);
  80. XmStringFree(label);
  81. printHelpId("_w", _w);
  82. // XtAddCallback(_w, XmNhelpCallback, HelpCB, helpId);
  83. // free(helpId);
  84. installDestroyHandler();
  85. // The _active member is set when each instance is registered
  86. // with an associated Cmd object. Now that a widget exists,
  87. // set the widget's sensitivity according to its active state.
  88. if ( _active )
  89. activate();
  90. else
  91. deactivate();
  92. #ifdef GNU_CC // No idea what the right ifdef is for automatically recognizing g++
  93. // G++ reportedly doesn't like the form expected by cfront. I'm
  94. // told this will work, but I haven't tested it myself.
  95. XtAddCallback ( _w,
  96. XmNactivateCallback,
  97. executeCmdCallback,
  98. (XtPointer) this );
  99. #else
  100. XtAddCallback ( _w,
  101. XmNactivateCallback,
  102. &CmdInterface::executeCmdCallback,
  103. (XtPointer) this );
  104. #endif
  105. }
  106. #ifndef CAN_INLINE_VIRTUALS
  107. ButtonInterface::~ButtonInterface(void)
  108. {
  109. }
  110. #endif /* ! CAN_INLINE_VIRTUALS */
  111. void
  112. ButtonInterface::mapName(const char * input, char * output)
  113. {
  114. strcpy(output, input);
  115. for (char * cur = output; *cur; cur++) {
  116. if (isspace(*cur) || *cur == ',') {
  117. *cur = '_';
  118. continue;
  119. }
  120. if (*cur == '.' || *cur == ':') {
  121. *cur = 0;
  122. break;
  123. }
  124. }
  125. }