TGMdiMenu.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGMdiMenu.cxx 35582 2010-09-22 13:38:27Z bellenot $
00002 // Author: Bertrand Bellenot   20/08/2004
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 /**************************************************************************
00013 
00014     This file is part of TGMdi an extension to the xclass toolkit.
00015     Copyright (C) 1998-2002 by Harald Radke, Hector Peraza.
00016 
00017     This application is free software; you can redistribute it and/or
00018     modify it under the terms of the GNU Library General Public
00019     License as published by the Free Software Foundation; either
00020     version 2 of the License, or (at your option) any later version.
00021 
00022     This application is distributed in the hope that it will be useful,
00023     but WITHOUT ANY WARRANTY; without even the implied warranty of
00024     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025     Library General Public License for more details.
00026 
00027     You should have received a copy of the GNU Library General Public
00028     License along with this library; if not, write to the Free
00029     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00030 
00031 **************************************************************************/
00032 
00033 //////////////////////////////////////////////////////////////////////////
00034 //                                                                      //
00035 // TGMdiMenu.                                                           //
00036 //                                                                      //
00037 // This file contains the TGMdiMenuBar class.                           //
00038 //                                                                      //
00039 //////////////////////////////////////////////////////////////////////////
00040 
00041 #include "TGMdi.h"
00042 #include "TGMdiMenu.h"
00043 #include "TList.h"
00044 #include "Riostream.h"
00045 
00046 
00047 ClassImp(TGMdiMenuBar)
00048 
00049 //______________________________________________________________________________
00050 TGMdiMenuBar::TGMdiMenuBar(const TGWindow *p, int w, int h) :
00051    TGCompositeFrame(p, w, h, kHorizontalFrame)
00052 {
00053    // TGMdiMenuBar constructor.
00054 
00055    fLHint = new TGLayoutHints(kLHintsNormal);
00056    fLeftHint = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 1, 1, 1, 1);
00057    fBarHint = new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 1, 1, 1, 1);
00058    fRightHint = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 1, 2, 1, 1);
00059 
00060    fLeft = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);
00061    fBar = new TGMenuBar(this, 1, 20, kHorizontalFrame);
00062    fRight = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);
00063 
00064    AddFrame(fLeft,  fLeftHint);
00065    AddFrame(fBar,   fBarHint);
00066    AddFrame(fRight, fRightHint);
00067 }
00068 
00069 //______________________________________________________________________________
00070 TGMdiMenuBar::~TGMdiMenuBar()
00071 {
00072    // TGMdiMenuBar destructor.
00073 
00074    if (!MustCleanup()) {
00075       delete fLHint;
00076       delete fLeftHint;
00077       delete fRightHint;
00078       delete fBarHint;
00079    }
00080 }
00081 
00082 //______________________________________________________________________________
00083 void TGMdiMenuBar::AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l)
00084 {
00085    // Add popup menu to the MDI menu bar with layout hints l.
00086 
00087    fBar->AddPopup(s, menu, l);
00088    // Layout();
00089 }
00090 
00091 //______________________________________________________________________________
00092 void TGMdiMenuBar::AddFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
00093 {
00094    // This is called from TGMdiMainFrame on Maximize().
00095 
00096    // Hide all frames first
00097    TGFrameElement *el;
00098    TIter nextl(fLeft->GetList());
00099    while ((el = (TGFrameElement *) nextl())) {
00100       fLeft->HideFrame(el->fFrame);
00101    }
00102    TIter nextr(fRight->GetList());
00103    while ((el = (TGFrameElement *) nextr())) {
00104       fRight->HideFrame(el->fFrame);
00105    }
00106    // Then add specified frames
00107    icon->ReparentWindow(fLeft);
00108    buttons->ReparentWindow(fRight);
00109    fLeft->AddFrame(icon, fLHint);
00110    fRight->AddFrame(buttons, fLHint);
00111 }
00112 
00113 //______________________________________________________________________________
00114 void TGMdiMenuBar::RemoveFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
00115 {
00116    // This is called from TGMdiMainFrame on Restore()
00117 
00118    // Remove specified frames
00119    fLeft->RemoveFrame(icon);
00120    fRight->RemoveFrame(buttons);
00121    // Then show (restore) last frames
00122    TGFrameElement *el;
00123    el = (TGFrameElement *)fLeft->GetList()->Last();
00124    if (el)
00125       fLeft->ShowFrame(el->fFrame);
00126    el = (TGFrameElement *)fRight->GetList()->Last();
00127    if (el)
00128       fRight->ShowFrame(el->fFrame);
00129 }
00130 
00131 //______________________________________________________________________________
00132 void TGMdiMenuBar::ShowFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
00133 {
00134    // This is called from TGMdiMainFrame on Maximize().
00135 
00136    // Hide all frames first
00137    TGFrameElement *el;
00138    TIter nextl(fLeft->GetList());
00139    while ((el = (TGFrameElement *) nextl())) {
00140       fLeft->HideFrame(el->fFrame);
00141    }
00142    TIter nextr(fRight->GetList());
00143    while ((el = (TGFrameElement *) nextr())) {
00144       fRight->HideFrame(el->fFrame);
00145    }
00146    // Then show specified frames
00147    fLeft->ShowFrame(icon);
00148    fRight->ShowFrame(buttons);
00149 }
00150 
00151 //______________________________________________________________________________
00152 void TGMdiMenuBar::HideFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
00153 {
00154    // Used to hide specific frames from menu bar
00155 
00156    // Hide specified frames
00157    fLeft->HideFrame(icon);
00158    fRight->HideFrame(buttons);
00159    
00160    // Then show (restore) last frames
00161    TGFrameElement *el;
00162    el = (TGFrameElement *)fLeft->GetList()->Last();
00163    if (el)
00164       fLeft->ShowFrame(el->fFrame);
00165    el = (TGFrameElement *)fRight->GetList()->Last();
00166    if (el)
00167       fRight->ShowFrame(el->fFrame);
00168 }
00169 
00170 //______________________________________________________________________________
00171 void TGMdiMenuBar::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
00172 {
00173    // Save a MDI menu as a C++ statement(s) on output stream out
00174 
00175    out << endl;
00176    out << "   // MDI menu bar" << endl;
00177 
00178    out << "   TGMdiMenuBar *";
00179    out << GetName() << " = new TGMdiMenuBar(" << fParent->GetName()
00180        << "," << GetWidth() << "," << GetHeight() << ");" << endl;
00181    if (option && strstr(option, "keep_names"))
00182       out << "   " << GetName() << "->SetName(\"" << GetName() << "\");" << endl;
00183 
00184    if (!fList) return;
00185 
00186    out << "   TGMenuBar *" << fBar->GetName() << " = " << GetName()
00187        << "->GetMenuBar();" << endl;
00188 
00189    TGFrameElement *el;
00190    TIter next(fBar->GetList());
00191 
00192    while ((el = (TGFrameElement *)next())) {
00193       el->fFrame->SavePrimitive(out, option);
00194       el->fLayout->SavePrimitive(out, option);
00195       out << ");" << endl;
00196    }
00197 }

Generated on Tue Jul 5 14:22:02 2011 for ROOT_528-00b_version by  doxygen 1.5.1