From d062eda8e56ab5ce283b540e6b41ad1e1d4e939b Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 11 Jan 2002 16:05:08 +0000 Subject: [PATCH] first steps of gnome frontend rebirth git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3337 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gnome/GUIRunTime.C | 4 - src/frontends/gnome/Makefile.am | 11 +- src/frontends/gnome/Menubar_pimpl.C | 413 ---------------------------- src/frontends/gnome/Menubar_pimpl.h | 110 -------- src/frontends/gnome/mainapp.C | 153 ----------- src/frontends/gnome/mainapp.h | 67 ----- 6 files changed, 7 insertions(+), 751 deletions(-) delete mode 100644 src/frontends/gnome/Menubar_pimpl.C delete mode 100644 src/frontends/gnome/Menubar_pimpl.h delete mode 100644 src/frontends/gnome/mainapp.C delete mode 100644 src/frontends/gnome/mainapp.h diff --git a/src/frontends/gnome/GUIRunTime.C b/src/frontends/gnome/GUIRunTime.C index 0ec386c177..74738fb247 100644 --- a/src/frontends/gnome/GUIRunTime.C +++ b/src/frontends/gnome/GUIRunTime.C @@ -19,7 +19,6 @@ #include "debug.h" #include -#include "mainapp.h" #include using std::endl; @@ -40,7 +39,6 @@ int const xforms_include_version = FL_INCLUDE_VERSION; } // namespace anon -GLyxAppWin * mainAppWin; int GUIRunTime::initApplication(int &, char * argv[]) { @@ -75,8 +73,6 @@ int GUIRunTime::initApplication(int &, char * argv[]) string app_version(VERSION); static Gnome::Main a(app_id, app_version, 1, argv); glade_gnome_init(); // Initialize the glade library. - static GLyxAppWin appWin; - mainAppWin = &appWin; return 0; } diff --git a/src/frontends/gnome/Makefile.am b/src/frontends/gnome/Makefile.am index fedecc5d71..44ba737352 100644 --- a/src/frontends/gnome/Makefile.am +++ b/src/frontends/gnome/Makefile.am @@ -24,6 +24,7 @@ libgnome_la_LIBADD = \ ../xforms/FormMathsSpace.lo \ ../xforms/DropDown.lo \ ../xforms/Alert_pimpl.lo \ + ../xforms/Menubar_pimpl.lo \ @LYX_LIBS@ @FRONTEND_LDFLAGS@ @FRONTEND_LIBS@ # ../xforms/FileDialog.lo \ @@ -85,15 +86,17 @@ libgnome_la_SOURCES = \ gnomeBC.h \ GUIRunTime.C \ pixbutton.h \ - mainapp.C \ - mainapp.h \ - Menubar_pimpl.C \ - Menubar_pimpl.h \ support.c \ support.h \ Timeout_pimpl.C \ Timeout_pimpl.h +# Trying to make things a litte more tidy. -- Koz-2002-01-11 +# mainapp.C \ +# mainapp.h \ +# Menubar_pimpl.C \ +# Menubar_pimpl.h \ +# # FormCopyright.C \ # FormCopyright.h \ # FormCredits.C \ diff --git a/src/frontends/gnome/Menubar_pimpl.C b/src/frontends/gnome/Menubar_pimpl.C deleted file mode 100644 index f3630ac3e2..0000000000 --- a/src/frontends/gnome/Menubar_pimpl.C +++ /dev/null @@ -1,413 +0,0 @@ -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 2000 The LyX Team. - * - * ====================================================== */ - -#ifdef __GNUG__ -#pragma implementation -#endif - -#include - -#include -#include -#include "support/lstrings.h" -#include "support/filetools.h" -#include "support/StrPool.h" -#include "support/LAssert.h" -#include "debug.h" -#include "LyXAction.h" -#include "lyxfunc.h" -#include "FuncStatus.h" -#include "kbmap.h" -#include "bufferlist.h" -#include "lastfiles.h" -#include "LyXView.h" -#include "MenuBackend.h" -#include "Menubar_pimpl.h" -#include "lyxtext.h" -#include "exporter.h" - -#include "mainapp.h" - -#include - -using std::endl; - -// temporary solution for LyXView -extern GLyxAppWin * mainAppWin; - -// Some constants -extern boost::scoped_ptr toplevel_keymap; -extern LyXAction lyxaction; -extern BufferList bufferlist; -extern LastFiles * lastfiles; - - - -Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mb) - : owner_(view), menubackend_(&mb), ignore_action_(false) -{ - -} - -Menubar::Pimpl::~Pimpl() -{ - if (utoc_.connected()) utoc_.disconnect(); -} - -void Menubar::Pimpl::set(string const & menu_name) -{ - // if (current_menu_name_ != menu_name) // disabled until Lastfiles and Documents are added dynamically to menu - //{ - current_menu_name_ = menu_name; - - // clean up the lists - toc_.clear(); - if (utoc_.connected()) utoc_.disconnect(); - - // compose new menu - vector menus; - composeUIInfo(current_menu_name_, menus, ""); - - // set menu - Menu_ = menus; - mainAppWin->set_menu(Menu_); - - // connect all menu items to correspoding action - wid_act_.clear(); - ignore_action_ = true; - connectWidgetToAction(Menu_.gtkobj()); - ignore_action_ = false; - - // update state of the items - update(); - updateAllLists(); - //} -} - -void Menubar::Pimpl::updateAllLists() -{ -#ifdef WITH_WARNINGS -#warning Implement me! (be 20010324) -#endif -#if 0 - // update lists - if (toc_.size() > 0) - { - vector toclist = (owner_->view()->buffer()->getTocList())[Buffer::TOC_TOC]; - updateList(&toclist, &toc_); - } -#endif -} - -int const max_number_of_items = 25; - -void Menubar::Pimpl::updateList(vector * toclist, vector * pgui) -{ - vector & gui = *pgui; - int szGui = gui.size(); - int i; - for (i=0; i < szGui; ++i) - { - int oldsz = gui[i].lst.size(); - vector menu; - string label; - - menu.push_back(Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_MENU_REFRESH), - _("Refresh"), SigC::slot(this, &Menubar::Pimpl::updateAllLists))); - - if (toclist->size() > max_number_of_items) - composeTocUIInfo(menu, *toclist, toclist->begin(), 0); - else - { - vector::const_iterator end = toclist->end(); - for (vector::const_iterator it = toclist->begin(); - it != end; ++it) - - { - label = string(4*(*it).depth,' ')+(*it).str; - - menu.push_back(Gnome::UI::Item(label, - SigC::bind(SigC::slot(this, &Menubar::Pimpl::callbackToc), (*it)), - label)); - } - } - - gui[i].lst = menu; - mainAppWin->update_menu(gui[i].path, oldsz, gui[i].lst); - } -} - -vector::const_iterator -Menubar::Pimpl::composeTocUIInfo(vector & menu, - vector const & toclist, - vector::const_iterator begin, - int mylevel) -{ - string label = _(""); - - vector::const_iterator end = toclist.end(); - vector::const_iterator it; - for (it = begin; it != end && (*it).depth >= mylevel; ++it) - { - if ( (*it).depth == mylevel && - (it+1 == end || (*(it+1)).depth <= mylevel) ) - { - label = (*it).str; - menu.push_back(Gnome::UI::Item(label, - SigC::bind(SigC::slot(this, &Menubar::Pimpl::callbackToc), (*it)), - label)); - } - else - { - vector submenu; - if ( (*it).depth == mylevel ) - { - label = (*it).str; - submenu.push_back(Gnome::UI::Item(label, - SigC::bind(SigC::slot(this, &Menubar::Pimpl::callbackToc), (*it)), - label)); - ++it; - } - it = composeTocUIInfo(submenu, toclist, it, mylevel+1); - menu.push_back(Gnome::UI::Menu(label,submenu,label)); - } - } - --it; - return it; -} - -void Menubar::Pimpl::callback(int action) -{ - // Dispatch action OR record action to local variable (see connectWidgetToAction) - if (!ignore_action_) { - Pimpl::update(); - owner_->getLyXFunc()->dispatch(action); - } else - action_ = action; -} - -void Menubar::Pimpl::callbackToc(Buffer::TocItem tg) -{ -#if 0 - if (!owner_->view()->available()) return; - - owner_->view()->beforeChange(); - owner_->view()->text->SetCursor( owner_->view(), tg.par, 0 ); - owner_->view()->text->sel_cursor = owner_->view()->text->cursor; - owner_->view()->update(BufferView::SELECT|BufferView::FITCUR); -#endif - - owner_->getLyXFunc()->dispatch(LFUN_GOTO_PARAGRAPH, tg.str); -} - -void Menubar::Pimpl::composeUIInfo(string const & menu_name, vector & Menus, string rootpath) -{ - string path = rootpath; - - if (!menubackend_->hasMenu(menu_name)) - { - cout << "ERROR:composeUIInfo: Unknown menu `" << menu_name - << "'" << endl; - return; - } - - Menu menu = Menu(); - menubackend_->getMenu(menu_name).expand(menu, owner_->buffer()); - - for (Menu::const_iterator i = menu.begin(); i != menu.end(); ++i) - { - MenuItem item = (*i); - switch(item.kind()) { - - case MenuItem::Command: { - string label = item.label(); - - path = rootpath + label; - - if (label.find(item.shortcut()) != string::npos) - label.insert(label.find(item.shortcut()), "_"); - - FuncStatus flag = owner_->getLyXFunc()->getStatus(item.action()); - - Gnome::UI::Info gitem; - SigC::Slot0 cback = SigC::bind(SigC::slot(this, &Menubar::Pimpl::callback),item.action()); - - { - using namespace Gnome::MenuItems; - int ac = item.action(); - kb_action action; - string argument; - if (lyxaction.isPseudoAction(ac)) - action = lyxaction.retrieveActionArg(ac, argument); - else - action = static_cast(ac); - - switch(action) { - case LFUN_FILE_OPEN: - gitem = Open(cback); - break; - case LFUN_QUIT: - gitem = Exit(cback); - break; - case LFUN_CLOSEBUFFER: - gitem = Close(cback); - break; - case LFUN_MENUWRITE: - gitem = Save(cback); - break; - case LFUN_WRITEAS: - gitem = SaveAs(cback); - break; - case LFUN_BUFFER_PRINT: - gitem = Print(cback); - break; - case LFUN_CUT: - gitem = Cut(cback); - break; - case LFUN_COPY: - gitem = Copy(cback); - break; - case LFUN_PASTE: - gitem = Paste(cback); - break; - case LFUN_UNDO: - gitem = Gnome::MenuItems::Undo(cback); // confused with class Undo - break; - case LFUN_REDO: - gitem = Redo(cback); - break; - case LFUN_DIALOG_PREFERENCES: - gitem = Preferences(cback); - break; - case LFUN_MENUNEW: - gitem = Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_MENU_NEW), - label, cback, lyxaction.helpText(item.action())); - break; - case LFUN_MENUNEWTMPLT: - gitem = Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_MENU_NEW), - label, cback, lyxaction.helpText(item.action())); - break; - case LFUN_MENUSEARCH: - gitem = Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_MENU_SRCHRPL), - label, cback, lyxaction.helpText(item.action())); - break; - case LFUN_SPELLCHECK: - gitem = Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_MENU_SPELLCHECK), - label, cback, lyxaction.helpText(item.action())); - break; - default: - gitem = Gnome::UI::Item(label, cback, lyxaction.helpText(item.action())); - break; - } - } - - // first handle optional entries. - if (item.optional() && (flag.disabled())) { - lyxerr[Debug::GUI] - << "Skipping optional item " << item.label() << endl; - break; - } - if ((flag.onoff(true)) || - (flag.onoff(false))) - gitem = Gnome::UI::ToggleItem(label, cback, lyxaction.helpText(item.action())); - - Menus.push_back(gitem); - break; - } - - case MenuItem::Submenu: { - vector submenu; - string label = item.label(); - - path = rootpath + label; - - if (label.find(item.shortcut()) != string::npos) - label.insert(label.find(item.shortcut()), "_"); - composeUIInfo(item.submenu(), submenu, path + "/"); - Menus.push_back(Gnome::UI::Menu(label,submenu,label)); - break; - } - - case MenuItem::Separator: { - - path = rootpath + ""; - - Menus.push_back(Gnome::UI::Separator()); - break; - } - - case MenuItem::Toc: { - ListsHolder t; - t.path = path; - toc_.push_back(t); - break; - } - - case MenuItem::Documents: - case MenuItem::Lastfiles: - case MenuItem::ViewFormats: - case MenuItem::UpdateFormats: - case MenuItem::ExportFormats: - lyxerr << "Menubar::Pimpl::create_submenu: " - "this should not happen" << endl; - break; - } - } -} - -void Menubar::Pimpl::connectWidgetToAction(GnomeUIInfo * guinfo) -{ - for (; guinfo->type != GnomeUIInfoType(GNOME_APP_UI_ENDOFINFO); ++guinfo) - { - if ( ( guinfo->type == GnomeUIInfoType(GNOME_APP_UI_ITEM) || - guinfo->type == GnomeUIInfoType(GNOME_APP_UI_TOGGLEITEM) ) && - guinfo->moreinfo != 0 ) - { - (*((void(*)(void *, void *))(guinfo->moreinfo)))(0, guinfo->user_data); - wid_act_.push_back( GtkWidgetToAction( guinfo->widget, action_ ) ); - } - else if ( guinfo->type == GnomeUIInfoType(GNOME_APP_UI_SUBTREE) || - guinfo->type == GnomeUIInfoType(GNOME_APP_UI_RADIOITEMS) ) - { - connectWidgetToAction( (GnomeUIInfo *)(guinfo->moreinfo) ); - } - } -} - -void Menubar::Pimpl::update() -{ - vector::const_iterator end=wid_act_.end(); - for (vector::const_iterator i = wid_act_.begin(); i != end; ++i) - { - GtkWidgetToAction wa = (*i); - FuncStatus flag = owner_->getLyXFunc()->getStatus(wa.action_); - - if ( flag.disabled() || flag.unknown()) gtk_widget_set_sensitive(wa.widget_, false); - else gtk_widget_set_sensitive(wa.widget_, true); - - if ( flag.onoff(true)) - { - ignore_action_=true; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(wa.widget_), true); - ignore_action_=false; - } - - if ( flag.onoff(false)) - { - ignore_action_=true; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(wa.widget_), false); - ignore_action_=false; - } - } -} - -void Menubar::Pimpl::openByName(string const &) -{ -// Pimpl::update(); -} diff --git a/src/frontends/gnome/Menubar_pimpl.h b/src/frontends/gnome/Menubar_pimpl.h deleted file mode 100644 index 215aa4b7ed..0000000000 --- a/src/frontends/gnome/Menubar_pimpl.h +++ /dev/null @@ -1,110 +0,0 @@ -// -*- C++ -*- -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 2000 The LyX Team. - * - * ====================================================== */ - -#ifndef MENUBAR_PIMPL_H -#define MENUBAR_PIMPL_H - -#ifdef __GNUG__ -#pragma interface -#endif - -#include -#include "gettext.h" -#include "LString.h" -#include -#include -#include "frontends/Menubar.h" -#include "commandtags.h" -#include "buffer.h" - -class LyXView; -class MenuBackend; -class MenuItem; -class StrPool; - -#include "debug.h" - -/* - Structure containing Gtk widget and corresponding LyX action -*/ -struct GtkWidgetToAction -{ -public: - GtkWidgetToAction(GtkWidget * w, int a) { widget_=w; action_=a; } - -public: - GtkWidget * widget_; - int action_; -}; - -/** The LyX GUI independent menubar class - The GUI interface is implemented in the corresponding Menubar_pimpl class. - */ -class Menubar::Pimpl: public SigC::Object { -public: - /// - Pimpl(LyXView *, MenuBackend const &); - /// - ~Pimpl(); - /// - void set(string const &); - /// Opens a top-level submenu given its name - void openByName(string const &); - /// update the state of menuitems - void update(); - /// update TOC, LOF, ... on user' request - void updateAllLists(); - -protected: - /// callback function - void callback(int action); - /// callback function used by lists - void callbackToc(Buffer::TocItem tg); - /// compose Gnome::UI::Array object describing the menu - void composeUIInfo(string const & menu_name, vector & Menus, string path); - /// compose Gnome::UI::Array object describing the TOClist - vector::const_iterator - composeTocUIInfo(vector & menu, - vector const & toclist, - vector::const_iterator begin, - int mylevel); - /// populate wid_act_ vector with all widgets and corresponding actions - void connectWidgetToAction(GnomeUIInfo * guinfo); - - /// lists (toc, lof, lot, loa) - struct ListsHolder { - string path; - Gnome::UI::Array lst; - - ListsHolder () { } - ListsHolder (const ListsHolder & a) { path = a.path; lst = a.lst; } - }; - /// populate lists - void updateList(vector *, vector *); - -private: - /// - LyXView * owner_; - /// - MenuBackend const * menubackend_; - /// - string current_menu_name_; - Gnome::UI::Array Menu_; - - /// - bool ignore_action_; - int action_; - vector wid_act_; - - /// toc - SigC::Connection utoc_; - vector toc_; -}; -#endif diff --git a/src/frontends/gnome/mainapp.C b/src/frontends/gnome/mainapp.C deleted file mode 100644 index a0d7887638..0000000000 --- a/src/frontends/gnome/mainapp.C +++ /dev/null @@ -1,153 +0,0 @@ -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 2000 The LyX Team. - * - * ====================================================== */ - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "mainapp.h" - -using SigC::bind; -using SigC::slot; - -GLyxAppWin::GLyxAppWin() : - Gnome::App(PACKAGE,"LyX Gnomified"), - status_(false, true, GNOME_PREFERENCES_NEVER), - action_mode(false) -{ - init(); - show_all(); -} - -GLyxAppWin::~GLyxAppWin() -{ -} - -void GLyxAppWin::init() -{ - // set defaults - set_policy(false, true, false); - set_default_size(250, 350); - set_wmclass(PACKAGE, "GnomeLyX"); - - set_statusbar(status_); - - accel_ = 0; - - // initial (dummy) menu - vector menus, fm; - fm.push_back(Gnome::MenuItems::Open()); - menus.push_back(Gnome::Menus::File(fm)); - - GLyxAppWin::Array menu = menus; - gnome_app_create_menus(this->gtkobj(), - menu.gtkobj()); - - menusize_ = menu.size(); - - // packing widgets - - // temporary main widget - Gtk::HBox * h = manage( new Gtk::HBox() ); - Gnome::Pixmap * p; - p = Gtk::wrap( GNOME_PIXMAP( gnome_stock_pixmap_widget(0, GNOME_STOCK_PIXMAP_ABOUT) ) ); - - h->children().push_back( Gtk::Box_Helpers::Element( *p ) ); - h->children().push_back( *(manage(new Gtk::Label("Waiting for LyXView port"))) ); - - view_ = h; - // temporary main widget: done - - // packing main widget and separator - Gtk::Separator * sep = manage( new Gtk::HSeparator() ); - - box_.children().push_back( Gtk::Box_Helpers::Element(*view_) ); - box_.children().push_back( Gtk::Box_Helpers::Element(*sep, false) ); - - box_.show_all(); - - set_contents(box_); - - key_press_event.connect(slot(this, &GLyxAppWin::key_pressed)); -} - - -void GLyxAppWin::set_menu(Array &menu) -{ - // clean up and install new menus - gnome_app_remove_menus(this->gtkobj(),"/",menusize_); - gnome_app_insert_menus(this->gtkobj(), "", menu.gtkobj()); - gnome_app_install_menu_hints(this->gtkobj(), menu.gtkobj()); - menusize_ = menu.size(); -} - -void GLyxAppWin::update_menu(string path, int noelms, Array &menu) -{ - // remove "noelms" items and install new items from "menu" - gnome_app_remove_menus(this->gtkobj(),path.c_str(),noelms); - gnome_app_insert_menus(this->gtkobj(),path.c_str(),menu.gtkobj()); - gnome_app_install_menu_hints(this->gtkobj(),menu.gtkobj()); -} - -// clean up first, then add new action widget and finally, disable main view -void GLyxAppWin::add_action(Gtk::Container &action, string title, bool expand, Gtk::AccelGroup * acgr) -{ - remove_action(); - - Gtk::Frame * frame = manage( new Gtk::Frame(title) ); - frame->set_border_width(2); - action.set_border_width(2); - frame->add(action); - - box_.children().push_back( Gtk::Box_Helpers::Element( *frame, expand ) ); - box_.show_all(); - - accel_ = acgr; - if (accel_ != 0) add_accel_group(*accel_); - - view_->set_sensitive(false); - action_mode = true; -} - -void GLyxAppWin::remove_action() -{ - if (accel_ != 0) - { - remove_accel_group(*accel_); - accel_ = 0; - } - - while ( box_.children().size() > 2 ) - { - box_.children().pop_back(); - } - - view_->set_sensitive(true); - action_mode = false; -} - -gint GLyxAppWin::key_pressed(GdkEventKey * e) -{ - if (action_mode && - e->keyval == GDK_Escape) - { - remove_action(); - return TRUE; - } - return FALSE; -} - diff --git a/src/frontends/gnome/mainapp.h b/src/frontends/gnome/mainapp.h deleted file mode 100644 index a283394881..0000000000 --- a/src/frontends/gnome/mainapp.h +++ /dev/null @@ -1,67 +0,0 @@ -// -*- C++ -*- -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 2000 The LyX Team. - * - * ====================================================== */ - -#ifndef GNOMELYX_MAINWIN -#define GNOMELYX_MAINWIN - -#include -#include -#include -#include -#include - -#include "MenuBackend.h" - -/* - This is (most probably) temporary class and it will be either merged with - LyXView or replaced by new implementation of GUI-dependend MainWindow class -*/ - -class GLyxAppWin: public Gnome::App -{ - public: - /// - typedef Gnome::UI::Array Array; - - GLyxAppWin(); - ~GLyxAppWin(); - - /// set menu of the window - void set_menu(Array &); - /// update menu - void update_menu(string path, - int noelms, - Array &); - /// add action area - void add_action(Gtk::Container &, string title, bool expand=false, Gtk::AccelGroup * acgr=0); - /// remove action area - void remove_action(); - /// clears action area if Escape is pressed - gint key_pressed(GdkEventKey * e); - - protected: - /// init window widgets - void init(); - - protected: - // widgets - Gnome::AppBar status_; - Gtk::VBox box_; - Gtk::Widget *view_; - - Gtk::AccelGroup * accel_; - - bool action_mode; - - // menu size - int menusize_; -}; - -#endif