NumericFilter.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is Vision.
  13. *
  14. * The Initial Developer of the Original Code is The Vision Team.
  15. * Portions created by The Vision Team are
  16. * Copyright (C) 1999, 2000, 2001 The Vision Team. All Rights
  17. * Reserved.
  18. *
  19. * Contributor(s): Rene Gollent
  20. * Wade Majors
  21. * Todd Lair
  22. */
  23. #include <InterfaceDefs.h>
  24. #include <Message.h>
  25. #include <ctype.h>
  26. #include "NumericFilter.h"
  27. #include <TextView.h>
  28. #include <Invoker.h>
  29. #include <stdio.h>
  30. NumericFilter::NumericFilter (void)
  31. : BMessageFilter (B_ANY_DELIVERY, B_ANY_SOURCE)
  32. {
  33. }
  34. NumericFilter::~NumericFilter (void)
  35. {
  36. }
  37. filter_result
  38. NumericFilter::Filter (BMessage *msg, BHandler **handler)
  39. {
  40. filter_result result = B_DISPATCH_MESSAGE;
  41. switch (msg->what)
  42. {
  43. case B_KEY_DOWN:
  44. {
  45. uint32 modifier (msg->FindInt32 ("modifiers"));
  46. const char *bytes (msg->FindString ("bytes"));
  47. if ((modifier & B_SHIFT_KEY) == 0
  48. && (modifier & B_CONTROL_KEY) == 0
  49. && (modifier & B_OPTION_KEY) == 0
  50. && (modifier & B_COMMAND_KEY) == 0)
  51. {
  52. switch (bytes[0])
  53. {
  54. case B_BACKSPACE:
  55. case B_LEFT_ARROW:
  56. case B_RIGHT_ARROW:
  57. case B_HOME:
  58. case B_END:
  59. case B_TAB:
  60. break;
  61. case B_ENTER:
  62. // for some stupid reason BTextControl on R5 does not always Invoke() when
  63. // you hit enter, so forcing the issue here.
  64. if (dynamic_cast<BTextView *>(*handler))
  65. {
  66. dynamic_cast<BInvoker *>(((BView *)*handler)->Parent())->Invoke();
  67. }
  68. break;
  69. default:
  70. if (!isdigit(bytes[0]))
  71. result = B_SKIP_MESSAGE;
  72. break;
  73. }
  74. }
  75. else if ((modifier & B_SHIFT_KEY) != 0)
  76. {
  77. if (bytes[0] == B_LEFT_ARROW
  78. || bytes[0] == B_RIGHT_ARROW
  79. || bytes[0] == B_HOME
  80. || bytes[0] == B_END
  81. || bytes[0] == B_TAB)
  82. break;
  83. else
  84. result = B_SKIP_MESSAGE;
  85. }
  86. }
  87. break;
  88. }
  89. return result;
  90. }