]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/mainapp.C
Clean-up of the button controller.
[lyx.git] / src / frontends / gnome / mainapp.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 2000 The LyX Team.
7  *
8  * ====================================================== */
9
10 #include <config.h>
11
12 #include <gnome--/main.h>
13 #include <gtk--/accelgroup.h>
14 #include <gnome--/pixmap.h>
15 #include <gtk--/separator.h>
16 #include <gtk--/frame.h>
17 #include <gtk--/label.h>
18
19 #include <vector>
20 #include <algorithm>
21
22 #include "mainapp.h"
23
24 using SigC::bind;
25 using SigC::slot;
26
27 GLyxAppWin::GLyxAppWin() :
28   Gnome::App(PACKAGE,"LyX Gnomified"),
29          status_(false, true, GNOME_PREFERENCES_NEVER),
30          action_mode(false)
31 {
32   init();
33   show_all();
34 }
35
36 GLyxAppWin::~GLyxAppWin()
37 {
38 }
39
40 void GLyxAppWin::init()
41 {
42   // set defaults
43   set_policy(false, true, false);
44   set_default_size(250, 350);
45   set_wmclass(PACKAGE, "GnomeLyX");
46
47   set_statusbar(status_);
48
49   accel_ = 0;
50
51   // initial (dummy) menu
52   vector<Gnome::UI::Info> menus, fm;
53   fm.push_back(Gnome::MenuItems::Open());
54   menus.push_back(Gnome::Menus::File(fm));
55
56   Gnome::UI::Array menu = menus;
57   gnome_app_create_menus(this->gtkobj(),
58                          menu.gtkobj());
59
60   menusize_ = menu.size();
61
62   // packing widgets
63
64   // temporary main widget
65   Gtk::HBox * h = manage( new Gtk::HBox() );
66   Gnome::Pixmap * p;
67   p = Gtk::wrap( GNOME_PIXMAP( gnome_stock_pixmap_widget(0, GNOME_STOCK_PIXMAP_ABOUT) ) );
68
69   h->children().push_back( Gtk::Box_Helpers::Element( *p ) );
70   h->children().push_back( *(manage(new Gtk::Label("Waiting for LyXView port"))) );
71
72   view_ = h;
73   // temporary main widget: done
74
75   // packing main widget and separator
76   Gtk::Separator * sep = manage( new Gtk::HSeparator() );
77
78   box_.children().push_back( Gtk::Box_Helpers::Element(*view_) );
79   box_.children().push_back( Gtk::Box_Helpers::Element(*sep, false) );
80   
81   box_.show_all();
82   
83   set_contents(box_);
84
85   key_press_event.connect(slot(this, &GLyxAppWin::key_pressed));
86 }
87
88
89 void GLyxAppWin::set_menu(Gnome::UI::Array &menu)
90 {
91   // clean up and install new menus
92   gnome_app_remove_menus(this->gtkobj(),"/",menusize_);
93   gnome_app_insert_menus(this->gtkobj(), "", menu.gtkobj());
94   gnome_app_install_menu_hints(this->gtkobj(), menu.gtkobj());
95   menusize_ = menu.size();
96 }
97
98 void GLyxAppWin::update_menu(string path, int noelms, Gnome::UI::Array &menu)
99 {
100   // remove "noelms" items and install new items from "menu"
101   gnome_app_remove_menus(this->gtkobj(),path.c_str(),noelms);
102   gnome_app_insert_menus(this->gtkobj(),path.c_str(),menu.gtkobj());
103   gnome_app_install_menu_hints(this->gtkobj(),menu.gtkobj());
104 }
105   
106 // clean up first, then add new action widget and finally, disable main view
107 void GLyxAppWin::add_action(Gtk::Container &action, string title, bool expand, Gtk::AccelGroup * acgr)
108 {
109   remove_action();
110
111   Gtk::Frame * frame = manage( new Gtk::Frame(title) );
112   frame->set_border_width(2);
113   action.set_border_width(2);
114   frame->add(action);
115   
116   box_.children().push_back( Gtk::Box_Helpers::Element( *frame, expand ) );
117   box_.show_all();
118
119   accel_ = acgr;
120   if (accel_ != 0) add_accel_group(*accel_);
121   
122   view_->set_sensitive(false);
123   action_mode = true;
124 }
125
126 void GLyxAppWin::remove_action()
127 {
128   if (accel_ != 0)
129     {
130       remove_accel_group(*accel_);
131       accel_ = 0;
132     }
133   
134   while ( box_.children().size() > 2 )
135     {
136       box_.children().pop_back();
137     }
138
139   view_->set_sensitive(true);  
140   action_mode = false;
141 }
142
143 gint GLyxAppWin::key_pressed(GdkEventKey * e)
144 {
145   if (action_mode &&
146       e->keyval == GDK_Escape)
147     {
148       remove_action();
149       return TRUE;
150     }
151   return FALSE;
152 }
153