all repos — openbox @ cee0482c78b4c0a0c69724f16ef7eef5919278c1

openbox fork - make it a bit more like ryudo

otk/messagedialog.hh (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifndef __messagedialog_hh
#define __messagedialog_hh

#include "widget.hh"
#include "ustring.hh"

#include <vector>

namespace otk {

class Button;
class Label;

class DialogButton {
  ustring _label;
  bool _default;
public:
  DialogButton(char *label) : _label(label), _default(false)
    {}
  DialogButton(char *label, bool def) : _label(label), _default(def)
    {}
  inline const ustring& label() const { return _label; }
  inline const bool& isDefault() const { return _default; }
};

class MessageDialog : public Widget {
public:
  MessageDialog(int screen, EventDispatcher *ed, ustring title,
		ustring caption);
  MessageDialog(EventDispatcher *ed, ustring title, ustring caption);
  MessageDialog(Widget *parent, ustring title, ustring caption);
  virtual ~MessageDialog();

  virtual void addButton(const DialogButton &b) { _buttons.push_back(b); }

  virtual const DialogButton& run();

  virtual void show();
  virtual void hide();
  virtual void focus();

  virtual const DialogButton& result() const { return *_result; }
  virtual void setResult(const DialogButton &result) { _result = &result; }
  
  virtual void keyPressHandler(const XKeyEvent &e);
  virtual void clientMessageHandler(const XClientMessageEvent &e);

private:
  static DialogButton _default_result;

  void init(const ustring &title, const ustring &caption);

  std::vector<DialogButton> _buttons;
  std::vector<Button *> _button_widgets;
  Label *_label;
  Widget *_button_holder;
  KeyCode _return;
  KeyCode _escape;
  const DialogButton *_result;
};

}

#endif // __messagedialog_hh