SimpleGUI
messagebox.h
1 #ifndef MESSAGE_H
2 #define MESSAGE_H
3 
4 #include "simplegui.h"
5 #include <cstdio>
6 
7 enum MessageBoxType {
8  MSG_OK,MSG_OKCANCEL,MSG_YESNO
9 };
10 
11 //===================================================================================
12 
13 class MessageBox* messageBox = NULL;
14 
21 class MessageBox :public Frame {
22 private:
23  Label* info;
24  Button* buttons[2];
25  MessageBoxType type;
26  int returnValue;
27  //-------------------------------------------------------------------------------
28  static void triggerOk() {
29  messageBox->returnValue = 0;
30  messageBox->dispose();
31  }
32  //-------------------------------------------------------------------------------
33  static void triggerCancel() {
34  messageBox->returnValue = 1;
35  messageBox->dispose();
36  }
37  //-------------------------------------------------------------------------------
38  static void triggerYes() {
39  messageBox->returnValue = 0;
40  messageBox->dispose();
41  }
42  //-------------------------------------------------------------------------------
43  static void triggerNo() {
44  messageBox->returnValue = 1;
45  messageBox->dispose();
46  }
47  //-------------------------------------------------------------------------------
48  static void triggerButton(MessageBoxType type) {
49  if (type == MSG_OK) {
50  }
51  }
52 
53 public:
54  MessageBox(const char title[], const char text[], MessageBoxType type)
55  : Frame(100,100,strlen(text)*6+20,70,title) {
56  messageBox = this;
57  int msgWidth = strlen(text)*6;
58  this->type = type;
59  add( info = new Label(10,10,msgWidth,20,text) );
60  switch (type) {
61  case MSG_OK:
62  add( buttons[0] = new Button(10,40,msgWidth,20,"Ok") );
63  buttons[0]->action = &triggerOk;
64  break;
65  case MSG_OKCANCEL:
66  add( buttons[0] = new Button(10,40,msgWidth/2-5,20,"Ok") );
67  add( buttons[1] = new Button(20+msgWidth/2-5,40,msgWidth/2-5,20,"Cancel") );
68  buttons[0]->action = &triggerOk;
69  buttons[1]->action = &triggerCancel;
70  break;
71  case MSG_YESNO:
72  add( buttons[0] = new Button(10,40,msgWidth/2-5,20,"Yes") );
73  add( buttons[1] = new Button(20+msgWidth/2-5,40,msgWidth/2-5,20,"No") );
74  buttons[0]->action = &triggerYes;
75  buttons[1]->action = &triggerNo;
76  break;
77  }
78  }
79  //-------------------------------------------------------------------------------
80  static int show(const char title[], const char text[], MessageBoxType type=MSG_OK) {
81  MessageBox msg(title,text,type);
82  msg.run();
83  return messageBox->returnValue;
84  }
85 
86 };
87 
88 #endif // MESSAGE_H
The Button class is the prefered object usted to execute actions in common applications. This object is actionated by means of a click with the mouse device. This class can program the two actions inherited of Widget class.
Definition: simplegui.h:228
The Label class is the most simple visual class, useful show information to an application final user...
Definition: simplegui.h:106
The MessageBox class is a frame useful to show rapid information, this frame can be customized to ret...
Definition: messagebox.h:21
The Frame class manage all visual objects: Labels, InputText, Buttons, Lists, so on. One frame works like a window, and send all actions to each object after use them.
Definition: simplegui.h:454