From 2fe7465d032b5e57c81cb4ef2ef5705d5264d2d5 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 20 Jul 2000 11:39:14 +0000 Subject: [PATCH] More cleanups of the toolbar. The buttons are now toggled/disabled when needed git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@905 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 21 ++++ {images => lib/images}/unknown.xpm | 0 src/BufferView_pimpl.C | 2 +- src/LyXView.C | 11 ++ src/LyXView.h | 4 + src/lyxfunc.C | 111 +++++++++--------- src/toolbar.C | 176 ++++++++++++++--------------- src/toolbar.h | 29 +++-- 8 files changed, 193 insertions(+), 161 deletions(-) rename {images => lib/images}/unknown.xpm (100%) diff --git a/ChangeLog b/ChangeLog index 5cbbc34823..a379b83890 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2000-07-20 Jean-Marc Lasgouttes + + * src/lyxfunc.C (Dispatch): use LyXView::ShowState instead of + setting explicitely the minibuffer. + * src/BufferView_pimpl.C (workAreaButtonRelease): ditto. + + * src/LyXView.C (showState): new function. Shows font information + in minibuffer and update toolbar state. + (LyXView): call Toolbar::update after creating the + view. + + * src/toolbar.C: change toollist to be a vector instead of a + linked list. + (BubbleTimerCB): get help string directly from the callback + argument of the corresponding icon (which is the action) + (set): remove unnecessary ugliness. + (update): new function. update the icons (depressed, disabled) + depending of the status of the corresponding action. + + * src/toolbar.h: remove help in toolbarItem + 2000-07-19 Dekel Tsur * src/Painter.C (text): Added code for using symbol glyphs from diff --git a/images/unknown.xpm b/lib/images/unknown.xpm similarity index 100% rename from images/unknown.xpm rename to lib/images/unknown.xpm diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 18efb50d74..de3c38e4f9 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -754,7 +754,7 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y, if (button >= 2) return; bv_->setState(); - owner_->getMiniBuffer()->Set(CurrentState(bv_)); + owner_->showState(); // Did we hit an editable inset? if (inset_hit != 0) { diff --git a/src/LyXView.C b/src/LyXView.C index 4a1c93f551..d9cdc70bbf 100644 --- a/src/LyXView.C +++ b/src/LyXView.C @@ -36,6 +36,7 @@ #include "menus.h" #include "frontends/Dialogs.h" #include "lyx_gui_misc.h" // [update,Close]AllBufferRelatedDialogs +#include "bufferview_funcs.h" // CurrentState() using std::endl; @@ -63,6 +64,9 @@ LyXView::LyXView(int width, int height) lyxfunc = new LyXFunc(this); intl = new Intl; + // Make sure the buttons are disabled if needed. + toolbar->update(); + dialogs_ = new Dialogs(this); // temporary until all dialogs moved into Dialogs. dialogs_->updateBufferDependent @@ -440,3 +444,10 @@ void LyXView::updateWindowTitle() last_title = title; } } + + +void LyXView::showState() +{ + getMiniBuffer()->Set(CurrentState(view())); + getToolbar()->update(); +} diff --git a/src/LyXView.h b/src/LyXView.h index 23e2a30e66..eb7a5c5a9b 100644 --- a/src/LyXView.h +++ b/src/LyXView.h @@ -92,6 +92,10 @@ public: /// Updates the title of the window void updateWindowTitle(); + + /// Show state (toolbar and font in minibuffer) + void showState(); + /// Reset autosave timer void resetAutosaveTimer(); private: diff --git a/src/lyxfunc.C b/src/lyxfunc.C index ed4429f003..4d15da22df 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -179,7 +179,7 @@ void LyXFunc::moveCursorUpdate(bool selecting) /* ---> Everytime the cursor is moved, show the current font state. */ // should this too me moved out of this func? - //owner->getMiniBuffer()->Set(CurrentState()); + //owner->showState(); owner->view()->setState(); } @@ -220,7 +220,7 @@ int LyXFunc::processKeyEvent(XEvent * ev) owner->view()->unlockInset(tli); owner->view()->text->CursorRight(owner->view()); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); } else { tli->UnlockInsetInInset(owner->view(), tli->GetLockingInset(),true); @@ -593,29 +593,26 @@ string LyXFunc::Dispatch(int ac, case LFUN_BREAKLINE: owner->view()->text->CursorRight(owner->view()); owner->view()->setState(); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_RIGHT: if (!owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params)) { owner->view()->text->CursorRight(owner->view()); moveCursorUpdate(false); - owner->getMiniBuffer()-> - Set(CurrentState(owner->view())); + owner->showState(); } return string(); case LFUN_LEFT: if (owner->view()->text->cursor.par()->isRightToLeftPar(owner->buffer()->params)) { owner->view()->text->CursorRight(owner->view()); moveCursorUpdate(false); - owner->getMiniBuffer()-> - Set(CurrentState(owner->view())); + owner->showState(); } return string(); case LFUN_DOWN: owner->view()->text->CursorDown(owner->view()); moveCursorUpdate(false); - owner->getMiniBuffer()-> - Set(CurrentState(owner->view())); + owner->showState(); return string(); default: break; @@ -999,13 +996,13 @@ string LyXFunc::Dispatch(int ac, case LFUN_FREE: Free(owner->view()); owner->view()->setState(); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_TEX: Tex(owner->view()); owner->view()->setState(); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; #ifndef NEW_INSETS case LFUN_MELT: @@ -1228,52 +1225,52 @@ string LyXFunc::Dispatch(int ac, case LFUN_LANGUAGE: Lang(owner->view(), argument); owner->view()->setState(); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_EMPH: Emph(owner->view()); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_BOLD: Bold(owner->view()); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_NOUN: Noun(owner->view()); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_CODE: Code(owner->view()); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_SANS: Sans(owner->view()); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_ROMAN: Roman(owner->view()); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_DEFAULT: StyleReset(owner->view()); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_UNDERLINE: Underline(owner->view()); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_FONT_SIZE: FontSize(owner->view(), argument); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_FONT_STATE: @@ -1381,7 +1378,7 @@ string LyXFunc::Dispatch(int ac, tmptext->CursorRight(owner->view(), false); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); } break; @@ -1417,7 +1414,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); } break; @@ -1427,7 +1424,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorUp(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_DOWN: @@ -1437,7 +1434,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorDown(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_UP_PARAGRAPH: @@ -1447,7 +1444,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorUpParagraph(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_DOWN_PARAGRAPH: @@ -1457,7 +1454,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorDownParagraph(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_PRIOR: @@ -1467,7 +1464,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->cursorPrevious(); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_NEXT: @@ -1477,7 +1474,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->cursorNext(); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_HOME: @@ -1487,7 +1484,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorHome(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_END: @@ -1497,7 +1494,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorEnd(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_SHIFT_TAB: @@ -1508,7 +1505,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorTab(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_WORDRIGHT: @@ -1521,7 +1518,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorRightOneWord(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_WORDLEFT: @@ -1534,7 +1531,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorLeftOneWord(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_BEGINNINGBUF: @@ -1544,7 +1541,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorTop(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_ENDBUF: @@ -1554,7 +1551,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorBottom(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; @@ -1567,7 +1564,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorRight(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_LEFTSEL: @@ -1578,7 +1575,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorLeft(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_UPSEL: @@ -1586,7 +1583,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorUp(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_DOWNSEL: @@ -1594,7 +1591,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorDown(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_UP_PARAGRAPHSEL: @@ -1602,7 +1599,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorUpParagraph(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_DOWN_PARAGRAPHSEL: @@ -1610,7 +1607,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorDownParagraph(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_PRIORSEL: @@ -1618,7 +1615,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->cursorPrevious(); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_NEXTSEL: @@ -1626,7 +1623,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->cursorNext(); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_HOMESEL: @@ -1634,7 +1631,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorHome(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_ENDSEL: @@ -1642,7 +1639,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorEnd(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_WORDRIGHTSEL: @@ -1653,7 +1650,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorRightOneWord(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_WORDLEFTSEL: @@ -1664,7 +1661,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorLeftOneWord(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_BEGINNINGBUFSEL: @@ -1672,7 +1669,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorTop(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; case LFUN_ENDBUFSEL: @@ -1680,7 +1677,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->CursorBottom(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(true); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; // --- text changing commands ------------------------ @@ -1735,7 +1732,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->cut(); } moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); owner->view()->setState(); break; @@ -1789,7 +1786,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->DeleteWordForward(owner->view()); owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; /* -------> Delete word backward. */ @@ -1798,7 +1795,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->DeleteWordBackward(owner->view()); owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); moveCursorUpdate(false); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; /* -------> Kill to end of line. */ @@ -1843,7 +1840,7 @@ string LyXFunc::Dispatch(int ac, } else { owner->view()->cut(); } - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); owner->view()->setState(); } break; @@ -1887,7 +1884,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->sel_cursor = owner->view()->text->cursor; owner->view()->setState(); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; } @@ -1899,7 +1896,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->text->sel_cursor = owner->view()->text->cursor; owner->view()->setState(); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); break; } @@ -1934,7 +1931,7 @@ string LyXFunc::Dispatch(int ac, owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); owner->view()->text->sel_cursor = cursor; owner->view()->setState(); - owner->getMiniBuffer()->Set(CurrentState(owner->view())); + owner->showState(); } break; diff --git a/src/toolbar.C b/src/toolbar.C index ab7c9efdfc..fa756910d9 100644 --- a/src/toolbar.C +++ b/src/toolbar.C @@ -66,8 +66,11 @@ Toolbar::Toolbar(LyXView * o, int x, int y) void Toolbar::BubbleTimerCB(FL_OBJECT *, long data) { FL_OBJECT * ob = reinterpret_cast(data); - char * help = static_cast(ob->u_vdata); - fl_show_oneliner(help, ob->form->x + ob->x, + // The trick we use to get the help text is to read the + // argument of the callback that has been registered for + // ToolBarCB. (JMarc) + string help = lyxaction.helpText(ob->argument); + fl_show_oneliner(help.c_str(), ob->form->x + ob->x, ob->form->y + ob->y + ob->h); } @@ -83,10 +86,10 @@ int Toolbar::BubblePost(FL_OBJECT *ob, int event, FL_Coord /*mx*/, FL_Coord /*my*/, int /*key*/, void */*xev*/) { - string help = static_cast(ob->u_vdata); - Toolbar * t = reinterpret_cast(ob->u_ldata); + Toolbar * t = reinterpret_cast(ob->u_vdata); - if(event == FL_ENTER && !help.empty()){ + // We do not test for empty help here, since this can never happen + if(event == FL_ENTER){ fl_set_object_callback(t->bubble_timer, C_Toolbar_BubbleTimerCB, reinterpret_cast(ob)); @@ -111,39 +114,58 @@ extern "C" int C_Toolbar_BubblePost(FL_OBJECT * ob, int event, void Toolbar::activate() { - toolbarItem * tmp= 0; - toolbarItem * item = toollist; - while(item){ - tmp = item->next; - if (item->icon) { - fl_activate_object(item->icon); + ToolbarList::const_iterator p = toollist.begin(); + for (; p != toollist.end(); ++p) { + if (p->icon) { + fl_activate_object(p->icon); } - item = tmp; } } void Toolbar::deactivate() { - toolbarItem * tmp= 0; - toolbarItem * item = toollist; - while(item){ - tmp = item->next; - if (item->icon) { - fl_deactivate_object(item->icon); + ToolbarList::const_iterator p = toollist.begin(); + for (; p != toollist.end(); ++p) { + if (p->icon) { + fl_deactivate_object(p->icon); + } + } +} + +void Toolbar::update() +{ + ToolbarList::const_iterator p = toollist.begin(); + for (; p != toollist.end(); ++p) { + if (p->icon) { + int status = owner->getLyXFunc()->getStatus(p->action); + if (status & LyXFunc::ToggleOn) { + // I'd like to use a different color + // here, but then the problem is to + // know how to use transparency with + // Xpm library. It seems pretty + // complicated to me (JMarc) + fl_set_object_boxtype(p->icon, FL_DOWN_BOX); + } else { + fl_set_object_boxtype(p->icon, FL_UP_BOX); + } + + if (status & LyXFunc::Disabled) { + // Is there a way here to specify a + // mask in order to show that the + // button is disabled? (JMarc) + fl_deactivate_object(p->icon); + } + else + fl_activate_object(p->icon); } - item = tmp; } } void Toolbar::ToolbarCB(FL_OBJECT * ob, long ac) { -#if FL_REVISION >= 89 Toolbar * t = static_cast(ob->u_vdata); -#else - Toolbar * t = reinterpret_cast(ob->u_ldata); -#endif string res = t->owner->getLyXFunc()->Dispatch(int(ac)); if(!res.empty()) @@ -223,7 +245,6 @@ void Toolbar::set(bool doingmain) if (!cleaned) return; FL_OBJECT * obj; - toolbarItem * item = toollist; if (!doingmain) { fl_freeze_form(owner->getForm()); @@ -237,11 +258,11 @@ void Toolbar::set(bool doingmain) xpos, ypos, 0, 0, "Timer"); #endif - while(item != 0) { + ToolbarList::iterator item = toollist.begin(); + for (; item != toollist.end(); ++item) { switch(item->action){ case TOOL_SEPARATOR: xpos += sepspace; - item = item->next; break; case TOOL_LAYOUTS: xpos += standardspacing; @@ -251,7 +272,6 @@ void Toolbar::set(bool doingmain) combox->setcallback(LayoutsCB); combox->resize(FL_RESIZE_ALL); combox->gravity(NorthWestGravity, NorthWestGravity); - item = item->next; xpos += 135; break; default: @@ -261,39 +281,28 @@ void Toolbar::set(bool doingmain) xpos, ypos, buttonwidth, height, ""); - fl_set_object_boxtype(obj, FL_UP_BOX); - fl_set_object_color(obj, FL_MCOL, FL_BLUE); fl_set_object_resize(obj, FL_RESIZE_ALL); fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity); fl_set_object_callback(obj, C_Toolbar_ToolbarCB, static_cast(item->action)); + fl_set_object_color(obj, FL_MCOL, FL_BLUE); // Remove the blue feedback rectangle fl_set_pixmapbutton_focus_outline(obj, 0); - // set the bubble-help (Matthias) -#if FL_REVISION >= 89 // Set the tooltip - fl_set_object_helper(obj, item->help.c_str()); - // The toolbar that this object belongs too. - obj->u_vdata = this; - - +#if FL_REVISION >= 89 + string help = lyxaction.helpText(action); + fl_set_object_helper(obj, help.c_str()); #else -#ifdef WITH_WARNINGS -#warning This is dangerous! -#endif - obj->u_vdata = const_cast(item->help.c_str()); - // we need to know what toolbar this item - // belongs too. (Lgb) - obj->u_ldata = reinterpret_cast(this); - fl_set_object_posthandler(obj, C_Toolbar_BubblePost); #endif + // The toolbar that this object belongs too. + obj->u_vdata = this; + setPixmap(obj, item->action, buttonwidth, height); - item = item->next; // we must remember to update the positions xpos += buttonwidth; // ypos is constant @@ -311,7 +320,10 @@ void Toolbar::set(bool doingmain) // Should be safe to do this here. owner->updateLayoutChoice(); } - + + // set the state of the icons + //update(); + cleaned = false; } @@ -325,21 +337,18 @@ void Toolbar::add(int action, bool doclean) if (!doclean && owner) { // first "hide" the toolbar buttons. This is not a real hide // actually it deletes and frees the button altogether. - lyxerr << "Toolbar::add: \"hide\" the toolbar buttons." << endl; - toolbarItem * tmp= 0; - toolbarItem * item = toollist; + lyxerr << "Toolbar::add: \"hide\" the toolbar buttons." + << endl; lightReset(); fl_freeze_form(owner->getForm()); - while(item){ - tmp = item->next; - if (item->icon) { - fl_delete_object(item->icon); - fl_free_object(item->icon); - } - item = tmp; + + ToolbarList::iterator p = toollist.begin(); + for (; p != toollist.end(); ++p) { + p->clean(); } + if (combox) { delete combox; combox = 0; @@ -351,44 +360,30 @@ void Toolbar::add(int action, bool doclean) // there exist some special actions not part of // kb_action: SEPARATOR, LAYOUTS - toolbarItem * newItem, * tmp; - - // adds an item to the list - newItem = new toolbarItem; - newItem->action = action; - newItem->help = lyxaction.helpText(action); - // the new item is placed at the end of the list - tmp = toollist; - if (tmp != 0){ - while(tmp->next != 0) - tmp = tmp->next; - // here is tmp->next == 0 - tmp->next = newItem; - } else - toollist = newItem; + toolbarItem newItem; + newItem.action = action; + toollist.push_back(newItem); } void Toolbar::clean() { - toolbarItem * tmp = 0; - toolbarItem * item = toollist; - - reset(); + //reset(); // I do not understand what this reset() is, anyway //now delete all the objects.. if (owner) fl_freeze_form(owner->getForm()); - while (item) { - tmp = item->next; - delete item; - item = tmp; - } + + // G++ vector does not have clear defined + //toollist.clear(); + toollist.erase(toollist.begin(), toollist.end()); + lyxerr[Debug::TOOLBAR] << "Combox: " << combox << endl; if (combox) { delete combox; combox = 0; } + if (owner) fl_unfreeze_form(owner->getForm()); lyxerr[Debug::TOOLBAR] << "toolbar cleaned" << endl; @@ -401,20 +396,13 @@ void Toolbar::push(int nth) lyxerr[Debug::TOOLBAR] << "Toolbar::push: trying to trigger no `" << nth << '\'' << endl; - if (nth == 0) return; - - int count = 0; - toolbarItem * tmp = toollist; - while (tmp) { - ++count; - if (count == nth) { - fl_trigger_object(tmp->icon); - return; - } - tmp = tmp->next; + if (nth <= 0 || nth >= int(toollist.size())) { + // item nth not found... + LyXBell(); + return; } - // item nth not found... - LyXBell(); + + fl_trigger_object(toollist[nth - 1].icon); } @@ -433,7 +421,7 @@ void Toolbar::add(string const & func, bool doclean) void Toolbar::reset() { - toollist = 0; + //toollist = 0; // what is this supposed to do? cleaned = false; lightReset(); } diff --git a/src/toolbar.h b/src/toolbar.h index 71c957a925..1fd54d2772 100644 --- a/src/toolbar.h +++ b/src/toolbar.h @@ -18,6 +18,7 @@ #pragma interface #endif +#include #include FORMS_H_LOCATION #include "lyxfunc.h" #include "combox.h" @@ -69,7 +70,8 @@ public: void activate(); /// deactivates the toolbar void deactivate(); - + /// update the state of the icons + void update(); /// static void ToolbarCB(FL_OBJECT *, long); @@ -85,32 +87,41 @@ private: /// struct toolbarItem { - /// - toolbarItem * next; /// int action; /// - string help; - /// FL_OBJECT * icon; /// toolbarItem() { - next = 0; action = LFUN_NOACTION; icon = 0; } /// - ~toolbarItem() { + void clean() { if (icon) { fl_delete_object(icon); fl_free_object(icon); + icon = 0; } } + /// + ~toolbarItem() { + clean(); + } + toolbarItem & operator=(const toolbarItem & ti) { + // do we have to check icon and IsBitmap too? + action = ti.action; + icon = 0; // locally we need to get the icon anew + + return *this; + } }; - /// a list containing all the buttons - toolbarItem * toollist; + /// typedef to simplify things + typedef std::vector ToolbarList; + /// The list containing all the buttons + ToolbarList toollist; /// LyXView * owner; #if FL_REVISION < 89 -- 2.39.2