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