]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/mainapp.C
Mathed fix from Dekel, GNOME patch from Marko, language-code from Garst
[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   accel_ = NULL;
51
52   // initial (dummy) menu
53   vector<Gnome::UI::Info> menus, fm;
54   fm.push_back(Gnome::MenuItems::Open());
55   menus.push_back(Gnome::Menus::File(fm));
56
57   Gnome::UI::Array menu = menus;
58   gnome_app_create_menus(this->gtkobj(),
59                          menu.gtkobj());
60
61   menusize_ = menu.size();
62
63   // packing widgets
64
65   // temporary main widget
66   Gtk::HBox * h = manage( new Gtk::HBox() );
67   Gnome::Pixmap * p;
68   p = Gtk::wrap( GNOME_PIXMAP( gnome_stock_pixmap_widget(NULL, GNOME_STOCK_PIXMAP_ABOUT) ) );
69
70   h->children().push_back( Gtk::Box_Helpers::Element( *p ) );
71   h->children().push_back( *(manage(new Gtk::Label("Waiting for LyXView port"))) );
72
73   view_ = h;
74   // temporary main widget: done
75
76   // packing main widget and separator
77   Gtk::Separator * sep = manage( new Gtk::HSeparator() );
78
79   box_.children().push_back( Gtk::Box_Helpers::Element(*view_) );
80   box_.children().push_back( Gtk::Box_Helpers::Element(*sep, false) );
81   
82   box_.show_all();
83   
84   set_contents(box_);
85
86   key_press_event.connect(slot(this, &GLyxAppWin::key_pressed));
87 }
88
89
90 void GLyxAppWin::set_menu(Gnome::UI::Array &menu)
91 {
92   // clean up and install new menus
93   gnome_app_remove_menus(this->gtkobj(),"/",menusize_);
94   gnome_app_insert_menus(this->gtkobj(), "", menu.gtkobj());
95   gnome_app_install_menu_hints(this->gtkobj(), menu.gtkobj());
96   menusize_ = menu.size();
97 }
98
99 void GLyxAppWin::update_menu(string path, int noelms, Gnome::UI::Array &menu)
100 {
101   // remove "noelms" items and install new items from "menu"
102   gnome_app_remove_menus(this->gtkobj(),path.c_str(),noelms);
103   gnome_app_insert_menus(this->gtkobj(),path.c_str(),menu.gtkobj());
104   gnome_app_install_menu_hints(this->gtkobj(),menu.gtkobj());
105 }
106   
107 // clean up first, then add new action widget and finally, disable main view
108 void GLyxAppWin::add_action(Gtk::Container &action, string title, bool expand, Gtk::AccelGroup * acgr)
109 {
110   remove_action();
111
112   Gtk::Frame * frame = manage( new Gtk::Frame(title) );
113   frame->set_border_width(2);
114   action.set_border_width(2);
115   frame->add(action);
116   
117   box_.children().push_back( Gtk::Box_Helpers::Element( *frame, expand ) );
118   box_.show_all();
119
120   accel_ = acgr;
121   if (accel_ != NULL) add_accel_group(*accel_);
122   
123   view_->set_sensitive(false);
124   action_mode = true;
125 }
126
127 void GLyxAppWin::remove_action()
128 {
129   if (accel_ != NULL)
130     {
131       remove_accel_group(*accel_);
132       accel_ = NULL;
133     }
134   
135   while ( box_.children().size() > 2 )
136     {
137       box_.children().pop_back();
138     }
139
140   view_->set_sensitive(true);  
141   action_mode = false;
142 }
143
144 gint GLyxAppWin::key_pressed(GdkEventKey * e)
145 {
146   if (action_mode &&
147       e->keyval == GDK_Escape)
148     {
149       remove_action();
150       return TRUE;
151     }
152   return FALSE;
153 }
154