Marko's GNOME patch + enhancements/fixes for insettabular/text.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@962 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2000-08-09 13:51:59 +00:00
parent 67191fe11f
commit 25b8f50efb
15 changed files with 558 additions and 22 deletions

View File

@ -1,3 +1,32 @@
2000-08-09 Juergen Vigna <jug@sad.it>
* src/insets/insettext.C (draw): small fix for clearing rectangle.
* src/insets/insettabular.C: make drawing of single cell smarter.
2000-08-09 Marko Vendelin <markov@ioc.ee>
* src/frontends/gnome/Menubar_pimpl.C
* src/frontends/gnome/Menubar_pimpl.h: Gnome frontend Menubar
implementation: new files
* src/frontends/gnome/mainapp.C
* src/frontends/gnome/mainapp.h: Gnome main window (temporary
implementation)
* src/main.C: create Gnome main window
* src/frontends/xforms/Menubar_pimpl.h
* src/frontends/Menubar.C
* src/frontends/Menubar.h: added method Menubar::update that calls
Menubar_pimpl::update and xforms/Menubar_pimpl::update (empty one)
* src/LyXView.C: calls Menubar::update to update the state
of menu items
* src/frontends/gnome/Makefile.am: added new files
* src/frontends/Makefile.am: added frontend compiler options
2000-08-08 Juergen Vigna <jug@sad.it>
* src/lyx_cb.C (AutoSave): autosave for unnamed files enabled!

View File

@ -38,6 +38,15 @@ src/frontends/xforms/FormPreferences.C
src/frontends/xforms/form_preferences.C
src/frontends/xforms/FormPrint.C
src/frontends/xforms/form_print.C
src/frontends/xforms/FormRef.C
src/frontends/xforms/form_ref.C
src/frontends/xforms/forms/form_citation.C
src/frontends/xforms/forms/form_copyright.C
src/frontends/xforms/forms/form_graphics.C
src/frontends/xforms/forms/form_preferences.C
src/frontends/xforms/forms/form_print.C
src/frontends/xforms/forms/form_tabular.C
src/frontends/xforms/forms/form_url.C
src/frontends/xforms/FormTabular.C
src/frontends/xforms/form_tabular.C
src/frontends/xforms/FormToc.C
@ -64,7 +73,6 @@ src/insets/insetlist.C
src/insets/insetmarginal.C
src/insets/insetminipage.C
src/insets/insetparent.C
src/insets/insetref.C
src/insets/insettabular.C
src/insets/insettext.C
src/insets/insettheorem.C

View File

@ -70,6 +70,7 @@ LyXView::LyXView(int width, int height)
// Make sure the buttons are disabled if needed.
toolbar->update();
menubar->update();
dialogs_ = new Dialogs(this);
// temporary until all dialogs moved into Dialogs.
@ -138,6 +139,7 @@ void LyXView::setLayout(int layout)
void LyXView::updateToolbar()
{
toolbar->update();
menubar->update();
}
@ -484,4 +486,5 @@ void LyXView::showState()
{
getMiniBuffer()->Set(CurrentState(view()));
getToolbar()->update();
menubar->update();
}

View File

@ -3,7 +3,7 @@ DISTCLEANFILES= *.orig *.rej *~ *.bak core
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
SUBDIRS = @FRONTEND@
ETAGS_ARGS = --lang=c++
INCLUDES = -I${srcdir}/.. -I${srcdir}/@FRONTEND@
INCLUDES = ${FRONTEND_INCLUDES} -I${srcdir}/.. -I${srcdir}/@FRONTEND@ ${SIGC_CFLAGS}
LIBS =
noinst_LTLIBRARIES = libfrontends.la
libfrontends_la_SOURCES=\

View File

@ -44,3 +44,8 @@ void Menubar::openByName(string const & name)
{
pimpl_->openByName(name);
}
void Menubar::update()
{
pimpl_->update();
}

View File

@ -36,16 +36,16 @@ public:
void set(string const &);
/// Opens a top-level submenu given its name
void openByName(string const &);
/// update the state of the menuitems
void update();
//I disable this temporarily until I find a nice way to make it work
//with compaq cxx. (Jean-Marc)
// Is this a new comment? (Lgb)
struct Pimpl;
///
friend struct Pimpl;
private:
///
Pimpl * pimpl_;
};
#endif

View File

@ -16,7 +16,9 @@ libgnome_la_SOURCES = \
Menubar_pimpl.C \
Menubar_pimpl.h \
Toolbar_pimpl.C \
Toolbar_pimpl.h
Toolbar_pimpl.h \
mainapp.C \
mainapp.h
# These still have to be added. Sooner or later. ARRae-20000411
# GUI_defaults.C \

View File

@ -0,0 +1,253 @@
// -*- C++ -*-
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 2000 The LyX Team.
*
* ====================================================== */
#ifdef __GNUG__
#pragma implementation
#endif
#include <config.h>
#include <algorithm>
#include <cctype>
#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 "kbmap.h"
#include "bufferlist.h"
#include "lastfiles.h"
#include "LyXView.h"
#include "MenuBackend.h"
#include "Menubar_pimpl.h"
#include "mainapp.h"
using SigC::slot;
using SigC::bind;
using std::endl;
// temporary solution for LyXView
extern GLyxAppWin * mainAppWin;
// Some constants
extern LyXAction lyxaction;
extern BufferList bufferlist;
extern LastFiles * lastfiles;
Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mb)
: owner_(view), menubackend_(&mb), ignore_action_(false)
{
// Should we do something here?
}
Menubar::Pimpl::~Pimpl()
{
// Should we do something here?
}
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;
// compose new menu
vector<Gnome::UI::Info> 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();
}
}
void Menubar::Pimpl::callback(int action)
{
// Dispatch action OR record action to local variable (see connectWidgetToAction)
if (!ignore_action_) owner_->getLyXFunc()->Dispatch(action);
else action_ = action;
}
void Menubar::Pimpl::composeUIInfo(string const & menu_name, vector<Gnome::UI::Info> & Menus)
{
if (!menubackend_->hasMenu(menu_name))
{
cout << "ERROR:composeUIInfo: Unknown menu `" << menu_name
<< "'" << endl;
return;
}
Menu menu = menubackend_->getMenu(menu_name);
for (Menu::const_iterator i = menu.begin(); i != menu.end(); ++i)
{
MenuItem item = (*i);
switch(item.kind()) {
case MenuItem::Command: {
string label = item.label();
if (label.find(item.shortcut()) != string::npos)
label.insert(label.find(item.shortcut()), "_");
LyXFunc::func_status flag = owner_->getLyXFunc()->getStatus(item.action());
Gnome::UI::Info gitem;
SigC::Slot0<void> cback = bind<int>(slot(this, &Menubar::Pimpl::callback),item.action());
{
using namespace Gnome::MenuItems;
string actionname = lyxaction.getActionName(item.action());
if ( actionname == "buffer-open") gitem = Open(cback);
else if ( actionname == "lyx-quit") gitem = Exit(cback);
else if ( actionname == "buffer-close") gitem = Close(cback);
else if ( actionname == "buffer-write") gitem = Save(cback);
else if ( actionname == "buffer-write-as") gitem = SaveAs(cback);
else if ( actionname == "buffer-print") gitem = Print(cback);
else if ( actionname == "cut") gitem = Cut(cback);
else if ( actionname == "copy") gitem = Copy(cback);
else if ( actionname == "paste") gitem = Paste(cback);
else if ( actionname == "undo") gitem = Gnome::MenuItems::Undo(cback); // confused with class Undo
else if ( actionname == "redo") gitem = Redo(cback);
else if ( actionname == "dialog-preferences") gitem = Preferences(cback);
else if ( actionname == "buffer-new")
gitem = Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_MENU_NEW),
label, cback, lyxaction.helpText(item.action()));
else if ( actionname == "buffer-new-template")
gitem = Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_MENU_NEW),
label, cback, lyxaction.helpText(item.action()));
else if ( actionname == "find-replace" )
gitem = Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_MENU_SRCHRPL),
label, cback, lyxaction.helpText(item.action()));
else if ( actionname == "spellchecker" )
gitem = Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_MENU_SPELLCHECK),
label, cback, lyxaction.helpText(item.action()));
// else if ( actionname == "" )
// gitem = Gnome::UI::Item(Gnome::UI::Icon(),
// label, cback, lyxaction.helpText(item.action()));
else gitem = Gnome::UI::Item(label, cback, lyxaction.helpText(item.action()));
}
// DON'T KNOW HOW TO TOGGLE/UNTOGGLE IT (Marko)
if ((flag & LyXFunc::ToggleOn) || (flag & LyXFunc::ToggleOff))
gitem = Gnome::UI::ToggleItem(label, cback, lyxaction.helpText(item.action()));
Menus.push_back(gitem);
break;
}
case MenuItem::Submenu: {
vector<Gnome::UI::Info> submenu;
string label = item.label();
if (label.find(item.shortcut()) != string::npos)
label.insert(label.find(item.shortcut()), "_");
composeUIInfo(item.submenu(), submenu);
Menus.push_back(Gnome::UI::Menu(label,submenu,label));
break;
}
case MenuItem::Separator: {
Menus.push_back(Gnome::UI::Separator());
break;
}
case MenuItem::Lastfiles: {
int ii = 1;
for (LastFiles::const_iterator cit = lastfiles->begin();
cit != lastfiles->end() && ii < 10; ++cit, ++ii)
{
int action = lyxaction.getPseudoAction(LFUN_FILE_OPEN, (*cit));
string label = "_" + tostr(ii) + ". " + MakeDisplayPath((*cit),30);
Menus.push_back(Gnome::UI::Item(label,
bind<int>(slot(this, &Menubar::Pimpl::callback), action),
label));
}
break;
}
case MenuItem::Documents: {
std::vector<string> names = bufferlist.getFileNames();
for (std::vector<string>::const_iterator cit = names.begin();
cit != names.end() ; ++cit)
{
int action = lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *cit);
string label = MakeDisplayPath(*cit, 30);
Menus.push_back(Gnome::UI::Item(label,
bind<int>(slot(this, &Menubar::Pimpl::callback), action),
label));
}
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) )
{
(*((void(*)(void *, void *))(guinfo->moreinfo)))(NULL, 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<GtkWidgetToAction>::const_iterator end=wid_act_.end();
for (vector<GtkWidgetToAction>::const_iterator i = wid_act_.begin(); i != end; ++i)
{
GtkWidgetToAction wa = (*i);
LyXFunc::func_status flag = owner_->getLyXFunc()->getStatus(wa.action_);
if ( flag & (LyXFunc::Disabled | LyXFunc::Unknown) ) gtk_widget_set_sensitive(wa.widget_, false);
else gtk_widget_set_sensitive(wa.widget_, true);
//don't know how to toggle/untoggle GtkCheckMenuItem
if ( flag & LyXFunc::ToggleOn )
{
ignore_action_=true;
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(wa.widget_), true);
ignore_action_=false;
}
if ( flag & LyXFunc::ToggleOff )
{
ignore_action_=true;
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(wa.widget_), false);
ignore_action_=false;
}
}
}

View File

@ -0,0 +1,81 @@
// -*- 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 <vector>
#include "LString.h"
#include <gnome--/app.h>
#include "frontends/Menubar.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();
protected:
/// callback function
void callback(int action);
/// compose Gnome::UI::Array object describing the menu
void composeUIInfo(string const & menu_name, vector<Gnome::UI::Info> & Menus);
/// populate wid_act_ vector with all widgets and corresponding actions
void connectWidgetToAction(GnomeUIInfo * guinfo);
private:
///
LyXView * owner_;
///
MenuBackend const * menubackend_;
///
string current_menu_name_;
Gnome::UI::Array Menu_;
///
bool ignore_action_;
int action_;
vector<GtkWidgetToAction> wid_act_;
};
#endif

View File

@ -0,0 +1,69 @@
// -*- C++ -*-
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 2000 The LyX Team.
*
* ====================================================== */
#include <config.h>
#include <gnome--/main.h>
#include <gtk--/accelgroup.h>
#include <vector>
#include <algorithm>
#include "mainapp.h"
using SigC::bind;
using SigC::slot;
GLyxAppWin::GLyxAppWin() :
Gnome::App("GnomeLyX","LyX Gnomified"),
status_(false, true, GNOME_PREFERENCES_NEVER)
{
init();
show_all();
}
GLyxAppWin::~GLyxAppWin()
{
}
void GLyxAppWin::init()
{
// set defaults
set_policy(false, true, false);
set_default_size(250, 350);
set_wmclass("lyx", "GnomeLyX");
frame_.set_shadow_type(GTK_SHADOW_IN);
set_contents(frame_);
set_statusbar(status_);
// initial (dummy) menu
vector<Gnome::UI::Info> menus, fm;
fm.push_back(Gnome::MenuItems::Open());
menus.push_back(Gnome::Menus::File(fm));
Gnome::UI::Array menu = menus;
gnome_app_create_menus(this->gtkobj(),
menu.gtkobj());
menusize_ = menu.size();
}
void GLyxAppWin::set_menu(Gnome::UI::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();
}

View File

@ -0,0 +1,47 @@
// -*- C++ -*-
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 2000 The LyX Team.
*
* ====================================================== */
#ifndef GNOMELYX_MAINWIN
#define GNOMELYX_MAINWIN
#include <gnome--/app.h>
#include <gnome--/appbar.h>
#include <gtk--/frame.h>
#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:
GLyxAppWin();
~GLyxAppWin();
/// set menu of the window
void set_menu(Gnome::UI::Array &);
protected:
/// init window widgets
void init();
protected:
// widgets
Gnome::AppBar status_;
Gtk::Frame frame_;
// menu size
int menusize_;
};
#endif

View File

@ -59,6 +59,9 @@ public:
string const & menuname,
std::vector<int> & smn, StrPool & strpool);
/// update the state of the menuitems
void update() { }
private:
///
FL_OBJECT * frame_;

View File

@ -244,6 +244,8 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
}
top_x = int(x);
top_baseline = baseline;
if (bv->text->status == LyXText::CHANGED_IN_DRAW)
return;
bool dodraw;
x += ADD_TO_TABULAR_WIDTH;
if (cleared || (need_update == FULL) || (need_update == CELL)) {
@ -258,20 +260,34 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
if (hasSelection())
DrawCellSelection(pain, nx, baseline, i, j, cell);
if (dodraw && !cleared && locked && the_locking_inset) {
if (the_locking_inset == tabular->GetCellInset(cell))
#warning Reminder make this better! (Jug)
if (need_update == CELL) // clear this cell
pain.fillRectangle(cx,
baseline -
tabular->GetAscentOfRow(i),
tabular->GetWidthOfColumn(cell),
tabular->GetAscentOfRow(i) +
tabular->GetDescentOfRow(i));
tabular->GetCellInset(cell)->draw(bv, font,
baseline, cx,
need_update==CELL);
if (need_update == CELL)
DrawCellLines(pain, nx, baseline, i, cell);
if (the_locking_inset == tabular->GetCellInset(cell)) {
LyXText::text_status st = bv->text->status;
do {
bv->text->status = st;
if (need_update == CELL) {
// clear before the inset
pain.fillRectangle(
nx+1,
baseline - tabular->GetAscentOfRow(i)+1,
cx - nx - 1,
tabular->GetAscentOfRow(i) +
tabular->GetDescentOfRow(i) - 1);
// clear behind the inset
pain.fillRectangle(
cx + the_locking_inset->width(bv,font) + 1,
baseline - tabular->GetAscentOfRow(i)+1,
tabular->GetWidthOfColumn(cell) -
tabular->GetBeginningOfTextInCell(cell) -
the_locking_inset->width(bv,font) - 1,
tabular->GetAscentOfRow(i) +
tabular->GetDescentOfRow(i) - 1);
}
tabular->GetCellInset(cell)->draw(
bv, font, baseline, cx, false);
// if (need_update == CELL)
// DrawCellLines(pain, nx, baseline, i, cell);
} while(bv->text->status == LyXText::CHANGED_IN_DRAW);
}
} else if (dodraw) {
tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
cleared);

View File

@ -242,6 +242,20 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
{
Painter & pain = bv->painter();
// no draw is necessary !!!
if ((drawFrame == LOCKED) && !locked && !par->size()) {
if (!cleared && (need_update == CLEAR_FRAME)) {
pain.rectangle(top_x, baseline - insetAscent, insetWidth,
insetAscent + insetDescent,
LColor::background);
}
top_x = int(x);
top_baseline = baseline;
x += width(bv, f);
need_update = NONE;
return;
}
xpos = x;
UpdatableInset::draw(bv, f, baseline, x, cleared);
@ -251,8 +265,10 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
int h = insetAscent + insetDescent;
int ty = baseline - insetAscent;
if (ty < 0)
if (ty < 0) {
h += ty;
ty = 0;
}
if ((ty + h) > pain.paperHeight())
h = pain.paperHeight();
if ((top_x + drawTextXOffset + w) > pain.paperWidth())
@ -318,7 +334,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
insetAscent + insetDescent,
LColor::background);
}
x += insetWidth - TEXT_TO_INSET_OFFSET;
x += width(bv, f) - 1;
if (bv->text->status==LyXText::CHANGED_IN_DRAW)
need_update = INIT;
else if (need_update != INIT)

View File

@ -16,6 +16,8 @@
#endif
#ifdef GTKGUI
# include <gnome--/main.h>
# include "frontends/gnome/mainapp.h"
GLyxAppWin * mainAppWin;
#endif
#include FORMS_H_LOCATION
@ -70,7 +72,9 @@ int main(int argc, char * argv[])
KApplication a( argc, argv );
#endif
#ifdef GTKGUI
Gnome::Main a(PACKAGE,VERSION,argc, argv );
Gnome::Main a(PACKAGE,VERSION,1,argv); //argc, argv );
GLyxAppWin appWin;
mainAppWin = &appWin;
#endif
// lyx_localedir is used by gettext_init() is we have