home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 110 / EnigmaAmiga110CD.iso / indispensabili / utility / apdf / xpdf-0.80 / ltk / ltkbuttondialog.cc < prev    next >
C/C++ Source or Header  |  1998-11-27  |  4KB  |  123 lines

  1. //========================================================================
  2. //
  3. // LTKButtonDialog.cc
  4. //
  5. // Copyright 1997 Derek B. Noonburg
  6. //
  7. //========================================================================
  8.  
  9. #ifdef __GNUC__
  10. #pragma implementation
  11. #endif
  12.  
  13. #include <stdlib.h>
  14. #include <stddef.h>
  15. #include "LTKApp.h"
  16. #include "LTKLabel.h"
  17. #include "LTKButton.h"
  18. #include "LTKEmpty.h"
  19. #include "LTKBox.h"
  20. #include "LTKWindow.h"
  21. #include "LTKBorder.h"
  22. #include "LTKButtonDialog.h"
  23.  
  24. //------------------------------------------------------------------------
  25. // LTKButtonDialog
  26. //------------------------------------------------------------------------
  27.  
  28. LTKButtonDialog::LTKButtonDialog(LTKWindow *overWin1, char *title,
  29.                  char *line1, char *line2, char *line3,
  30.                  char *trueBtnLabel, char *falseBtnLabel) {
  31.   LTKBox *box;
  32.  
  33.   overWin = overWin1;
  34.   widget = new LTKButtonDialogWidget(NULL, 0, line1, line2, line3,
  35.                      trueBtnLabel, falseBtnLabel);
  36.   box = new LTKBox(NULL, 1, 1, 0, 0, 0, 0, ltkBorderNone, 0, 0, widget);
  37.   win = new LTKWindow(overWin->getApp(), gTrue, title, NULL, NULL, box);
  38. }
  39.  
  40. LTKButtonDialog::~LTKButtonDialog() {
  41.   delete win;
  42. }
  43.  
  44. GBool LTKButtonDialog::go() {
  45.   win->layoutDialog(overWin, -1, -1);
  46.   win->map();
  47.   do {
  48.     overWin->getApp()->doEvent(gTrue);
  49.   } while (!widget->isDone());
  50.   return widget->whichBtn();
  51. }
  52.  
  53. //------------------------------------------------------------------------
  54. // LTKButtonDialogWidget
  55. //------------------------------------------------------------------------
  56.  
  57. LTKButtonDialogWidget::LTKButtonDialogWidget(char *name1, int widgetNum1,
  58.                          char *line1, char *line2,
  59.                          char *line3,
  60.                          char *trueBtnLabel,
  61.                          char *falseBtnLabel):
  62.     LTKCompoundWidget(name1, widgetNum1) {
  63.   LTKLabel *label1, *label2, *label3;
  64.   LTKBox *labelBox1, *labelBox2, *labelBox3, *labelBox;
  65.   LTKButton *trueBtn, *falseBtn;
  66.   LTKEmpty *empty;
  67.   LTKBox *trueBtnBox, *falseBtnBox, *emptyBox, *btnBox;
  68.  
  69.   labelBox1 = labelBox2 = labelBox3 = NULL;
  70.   if (line1) {
  71.     label1 = new LTKLabel(NULL, 0, ltkLabelStatic, -1, NULL, line1);
  72.     labelBox1 = new LTKBox(NULL, 1, 1, 0, 0, 0, 0, ltkBorderNone, 0, 0,
  73.                label1);
  74.     if (line2) {
  75.       label2 = new LTKLabel(NULL, 0, ltkLabelStatic, -1, NULL, line2);
  76.       labelBox2 = new LTKBox(NULL, 1, 1, 0, 0, 0, 0, ltkBorderNone, 0, 0,
  77.                  label2);
  78.       if (line3) {
  79.     label3 = new LTKLabel(NULL, 0, ltkLabelStatic, -1, NULL, line3);
  80.     labelBox3 = new LTKBox(NULL, 1, 1, 0, 0, 0, 0, ltkBorderNone, 0, 0,
  81.                    label3);
  82.     labelBox = new LTKBox(NULL, 1, 3, 2, 2, 2, 2, ltkBorderNone, 0, 0,
  83.                   labelBox1, labelBox2, labelBox3);
  84.       } else {
  85.     labelBox = new LTKBox(NULL, 1, 2, 2, 2, 2, 2, ltkBorderNone, 0, 0,
  86.                   labelBox1, labelBox2);
  87.       }
  88.     } else {
  89.       labelBox = new LTKBox(NULL, 1, 1, 2, 2, 2, 2, ltkBorderNone, 0, 0,
  90.                 labelBox1);
  91.     }
  92.   } else {
  93.     labelBox = new LTKBox(NULL, 1, 1, 2, 2, 2, 2, ltkBorderNone, 0, 0,
  94.               new LTKEmpty());
  95.   }
  96.   trueBtn = new LTKButton(NULL, 1, trueBtnLabel ? trueBtnLabel : "Ok",
  97.               ltkButtonClick, &buttonCbk);
  98.   trueBtnBox = new LTKBox(NULL, 1, 1, 0, 0, 0, 0, ltkBorderNone, 0, 0,
  99.               trueBtn);
  100.   falseBtn = new LTKButton(NULL, 0, falseBtnLabel ? falseBtnLabel : "Cancel",
  101.                ltkButtonClick, &buttonCbk);
  102.   falseBtnBox = new LTKBox(NULL, 1, 1, 0, 0, 0, 0, ltkBorderNone, 0, 0,
  103.                falseBtn);
  104.   empty = new LTKEmpty();
  105.   emptyBox = new LTKBox(NULL, 1, 1, 0, 0, 0, 0, ltkBorderNone, 1, 0,
  106.             empty);
  107.   btnBox = new LTKBox(NULL, 3, 1, 6, 6, 8, 6, ltkBorderNone, 1, 0,
  108.               trueBtnBox, emptyBox, falseBtnBox);
  109.   box = new LTKBox(NULL, 1, 2, 0, 0, 0, 0, ltkBorderNone, 0, 0,
  110.            labelBox, btnBox);
  111.   box->setCompoundParent(this);
  112.   done = gFalse;
  113.   btn = gFalse;
  114. }
  115.  
  116. void LTKButtonDialogWidget::buttonCbk(LTKWidget *widget, int n, GBool on) {
  117.   LTKButtonDialogWidget *w;
  118.  
  119.   w = (LTKButtonDialogWidget *)widget->getCompoundParent();
  120.   w->done = gTrue;
  121.   w->btn = n != 0;
  122. }
  123.