1
// Gmsh - Copyright (C) 1997-2009 C. Geuzaine, J.-F. Remacle
3
// See the LICENSE.txt file for license information. Please report all
4
// bugs and problems to <gmsh@geuz.org>.
8
#include <FL/Fl_Return_Button.H>
11
#include "messageWindow.h"
12
#include "paletteWindow.h"
13
#include "fileDialogs.h"
14
#include "GmshMessage.h"
20
void message_cb(Fl_Widget *w, void *data)
22
GUI::instance()->messages->show();
25
static void message_auto_scroll_cb(Fl_Widget *w, void *data)
27
CTX.msg_auto_scroll = GUI::instance()->messages->butt->value();
30
static void message_copy_cb(Fl_Widget *w, void *data)
33
for(int i = 1; i <= GUI::instance()->messages->browser->size(); i++) {
34
if(GUI::instance()->messages->browser->selected(i)) {
35
const char *c = GUI::instance()->messages->browser->text(i);
37
buff += std::string(&c[5]);
39
buff += std::string(c);
44
Fl::copy(buff.c_str(), buff.size(), 0);
45
Fl::copy(buff.c_str(), buff.size(), 1);
48
static void message_clear_cb(Fl_Widget *w, void *data)
50
GUI::instance()->messages->browser->clear();
53
static void message_save_cb(Fl_Widget *w, void *data)
56
if(file_chooser(0, 1, "Save", "*")) {
57
std::string name = file_chooser_get_name(1);
58
if(CTX.confirm_overwrite) {
60
if(!fl_choice("File '%s' already exists.\n\nDo you want to replace it?",
61
"Cancel", "Replace", NULL, name.c_str()))
64
GUI::instance()->messages->save(name.c_str());
68
messageWindow::messageWindow(int deltaFontSize)
70
FL_NORMAL_SIZE -= deltaFontSize;
72
int width = CTX.msg_size[0];
73
int height = CTX.msg_size[1];
75
win = new paletteWindow
76
(width, height, CTX.non_modal_windows ? true : false, "Message Console");
77
win->box(GMSH_WINDOW_BOX);
79
browser = new Fl_Browser(0, 0, width, height - 2 * WB - BH);
80
browser->box(FL_FLAT_BOX);
81
browser->textfont(FL_COURIER);
82
browser->textsize(FL_NORMAL_SIZE - 1);
83
browser->type(FL_MULTI_BROWSER);
84
browser->callback(message_copy_cb);
87
butt = new Fl_Check_Button
88
(width - 3 * BB - 3 * WB, height - BH - WB, BB, BH, "Auto scroll");
89
butt->type(FL_TOGGLE_BUTTON);
90
butt->callback(message_auto_scroll_cb);
93
Fl_Return_Button *o = new Fl_Return_Button
94
(width - 2 * BB - 2 * WB, height - BH - WB, BB, BH, "Clear");
95
o->callback(message_clear_cb);
98
Fl_Button *o = new Fl_Button
99
(width - BB - WB, height - BH - WB, BB, BH, "Save");
100
o->callback(message_save_cb);
103
win->resizable(new Fl_Box(1, 1, 4, 4));
104
win->size_range(WB + 100 + 2 * BB + 3 * WB, 100);
106
win->position(CTX.msg_position[0], CTX.msg_position[1]);
109
FL_NORMAL_SIZE += deltaFontSize;
112
void messageWindow::add(const char *msg)
114
browser->add(msg, 0);
115
if(CTX.msg_auto_scroll)
116
browser->bottomline(browser->size());
119
void messageWindow::save(const char *filename)
121
FILE *fp = fopen(filename, "w");
124
Msg::Error("Unable to open file '%s'", filename);
128
Msg::StatusBar(2, true, "Writing '%s'", filename);
129
for(int i = 1; i <= browser->size(); i++) {
130
const char *c = browser->text(i);
132
fprintf(fp, "%s\n", &c[5]);
134
fprintf(fp, "%s\n", c);
136
Msg::StatusBar(2, true, "Wrote '%s'", filename);
140
void messageWindow::show(bool redrawOnly)
142
if(win->shown() && redrawOnly)