You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
3.8KB

  1. /* PawfalInput Fltk Dialog
  2. * Copyleft (C) 2001 Dan Bethell <dan@pawfal.org>
  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "PawfalInput.h"
  19. #include <string.h>
  20. bool Pawfal_Input(const char *a, const char *b, char *out)
  21. {
  22. PawfalInput pi(300, 100,a,b);
  23. if (pi.go())
  24. {
  25. strcpy(out,pi.getText());
  26. return true;
  27. }
  28. return true;
  29. }
  30. PawfalInput::PawfalInput(int x, int y, int w, int h, const char *label, const char *dflt):
  31. Fl_Window(x,y,w, h),
  32. lbl(new Fl_Box(50, ((h-30)/2)-20, w-60,20, label)),
  33. input(new Fl_Input(50,((h-30)/2)+0,w-60,20)),
  34. ok(new Fl_Button(w-100, h-25, 30, 20, "ok")),
  35. cancel(new Fl_Button(w-60, h-25, 50, 20, "cancel")),
  36. keyhit(false)
  37. {
  38. lbl->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
  39. lbl->labelfont(FL_SCREEN_BOLD);
  40. lbl->labelsize(12);
  41. ok->labelfont(FL_SCREEN_BOLD);
  42. ok->labelsize(12);
  43. cancel->labelfont(FL_SCREEN_BOLD);
  44. cancel->labelsize(12);
  45. input->value(dflt);
  46. input->textfont(FL_SCREEN_BOLD);
  47. input->textsize(12);
  48. logo = new Fl_Pixmap(tv_xpm);
  49. end();
  50. set_modal();
  51. //clear_border();
  52. }
  53. PawfalInput::PawfalInput(int w, int h, const char *label, const char *dflt):
  54. Fl_Window(w, h, "Enter text"),
  55. lbl(new Fl_Box(50, ((h-30)/2)-20, w-60,20, label)),
  56. input(new Fl_Input(50,((h-30)/2)+0,w-60,20)),
  57. ok(new Fl_Button(w-100, h-25, 30, 20, "ok")),
  58. cancel(new Fl_Button(w-60, h-25, 50, 20, "cancel")),
  59. keyhit(false)
  60. {
  61. lbl->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
  62. lbl->labelfont(FL_SCREEN_BOLD);
  63. lbl->labelsize(12);
  64. ok->labelfont(FL_SCREEN_BOLD);
  65. ok->labelsize(12);
  66. cancel->labelfont(FL_SCREEN_BOLD);
  67. cancel->labelsize(12);
  68. input->value(dflt);
  69. input->textfont(FL_SCREEN_BOLD);
  70. input->textsize(12);
  71. logo = new Fl_Pixmap(tv_xpm);
  72. end();
  73. set_modal();
  74. //clear_border();
  75. }
  76. PawfalInput::~PawfalInput()
  77. {
  78. delete logo;
  79. }
  80. int PawfalInput::handle(int e)
  81. {
  82. int result = Fl_Window::handle(e);
  83. if (e==FL_KEYBOARD)
  84. {
  85. if (Fl::event_key()==FL_Escape||Fl::event_key()==FL_Enter)
  86. keyhit=true;
  87. }
  88. return result;
  89. }
  90. void PawfalInput::draw()
  91. {
  92. Fl_Window::draw();
  93. logo->draw(10, 10);
  94. }
  95. void PawfalInput::ok_cb(Fl_Button *b, void *d)
  96. {
  97. assert(b!=NULL);
  98. PawfalInput *ptr = (PawfalInput *)d;
  99. assert(ptr!=NULL);
  100. }
  101. void PawfalInput::cancel_cb(Fl_Button *b, void *d)
  102. {
  103. assert(b!=NULL);
  104. PawfalInput *ptr = (PawfalInput *)d;
  105. assert(ptr!=NULL);
  106. }
  107. bool PawfalInput::go()
  108. {
  109. bool result = false;
  110. show();
  111. for (;;)
  112. {
  113. Fl_Widget *o = Fl::readqueue();
  114. if (!o&&!keyhit) Fl::wait();
  115. else if (keyhit)
  116. {
  117. int key = Fl::event_key();
  118. if (key==FL_Escape)
  119. {
  120. result = false;
  121. break;
  122. }
  123. if (key==FL_Enter)
  124. {
  125. result=true;
  126. break;
  127. }
  128. }
  129. else if (o == ok) {result = true; break;}
  130. else if (o == cancel) {result = false; break;}
  131. }
  132. hide();
  133. return result;
  134. }