]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FormError.C
Remove unneeded files, we have switched to use the libglade and there is no
[lyx.git] / src / frontends / gnome / FormError.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "gettext.h"
19 #include "Dialogs.h"
20 #include "FormError.h"
21 #include "LyXView.h"
22 #include "buffer.h"
23 #include "lyxfunc.h"
24
25 #include <gtk--/label.h>
26 #include <gtk--/box.h>
27 #include <gtk--/button.h>
28 #include <gtk--/buttonbox.h>
29 #include <gnome--/stock.h>
30 #include <gtk--/separator.h>
31 #include <gtk--/alignment.h>
32
33 // temporary solution for LyXView
34 #include "mainapp.h"
35 extern GLyxAppWin * mainAppWin;
36
37
38 FormError::FormError(LyXView * lv, Dialogs * d)
39         : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0), dialog_(0)
40 {
41   // let the dialog be shown
42   // These are permanent connections so we won't bother
43   // storing a copy because we won't be disconnecting.
44   d->showError.connect(slot(this, &FormError::showInset));
45 }
46
47
48 FormError::~FormError()
49 {
50   hide();
51 }
52
53 void FormError::showInset( InsetError * const inset )
54 {
55   if( dialog_!=0 || inset == 0 ) return;
56   
57   inset_ = inset;
58   ih_ = inset_->hideDialog.connect(slot(this, &FormError::hide));
59
60   show();
61 }
62
63 void FormError::show()
64 {
65   if (!dialog_)
66     {
67       using namespace Gtk::Box_Helpers;
68       
69       Gtk::Label * label = manage( new Gtk::Label(inset_->getContents()) );
70       Gtk::Box * hbox = manage( new Gtk::HBox() );
71       Gtk::Button * b_close = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CLOSE) ) );
72       Gtk::Alignment * alg1 = manage( new Gtk::Alignment(0.5, 0.5, 0, 0) );
73       Gtk::Alignment * mbox = manage( new Gtk::Alignment(0.5, 0.5, 0, 0) );
74       
75       // set up spacing
76       hbox->set_spacing(4);
77
78       // packing
79       alg1->add(*b_close);
80       
81       hbox->children().push_back(Element(*label, false, false));
82       hbox->children().push_back(Element(*manage(new Gtk::VSeparator()), false, false));
83       hbox->children().push_back(Element(*alg1, false, false));
84
85       mbox->add(*hbox);
86       
87       // packing dialog to main window
88       dialog_ = mbox;
89       mainAppWin->add_action(*dialog_, _(" Error "));
90
91       // setting focus
92       GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_close->gtkobj()), GTK_CAN_DEFAULT);
93       gtk_widget_grab_focus (GTK_WIDGET(b_close->gtkobj()));
94       gtk_widget_grab_default (GTK_WIDGET(b_close->gtkobj()));
95
96       // connecting signals
97       b_close->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
98       dialog_->destroy.connect(slot(this, &FormError::free));
99
100       u_ = d_->updateBufferDependent.connect(slot(this, &FormError::updateSlot));
101       h_ = d_->hideBufferDependent.connect(slot(this, &FormError::hide));
102     }
103 }
104
105 void FormError::updateSlot(bool buffchanged)
106 {
107   if (buffchanged) hide();
108 }
109
110 void FormError::hide()
111 {
112   if (dialog_!=0) mainAppWin->remove_action();
113 }
114
115 void FormError::free()
116 {
117   if (dialog_!=0)
118     {
119       dialog_ = 0;
120       u_.disconnect();
121       h_.disconnect();
122       inset_ = 0;
123       ih_.disconnect();
124     }
125 }
126
127 void FormError::apply()
128 {
129 }
130