ROOT logo
// @(#)root/gui:$Id: TGMdiMenu.cxx 23115 2008-04-10 13:35:37Z rdm $
// Author: Bertrand Bellenot   20/08/2004

/*************************************************************************
 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

/**************************************************************************

    This file is part of TGMdi an extension to the xclass toolkit.
    Copyright (C) 1998-2002 by Harald Radke, Hector Peraza.

    This application is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This application is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

**************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGMdiMenu.                                                           //
//                                                                      //
// This file contains the TGMdiMenuBar class.                           //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TGMdi.h"
#include "TGMdiMenu.h"
#include "TList.h"
#include "Riostream.h"


ClassImp(TGMdiMenuBar)

//______________________________________________________________________________
TGMdiMenuBar::TGMdiMenuBar(const TGWindow *p, int w, int h) :
   TGCompositeFrame(p, w, h, kHorizontalFrame)
{
   // TGMdiMenuBar constructor.

   fLHint = new TGLayoutHints(kLHintsNormal);
   fLeftHint = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 1, 1, 1, 1);
   fBarHint = new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 1, 1, 1, 1);
   fRightHint = new TGLayoutHints(kLHintsRight | kLHintsCenterY, 1, 2, 1, 1);

   fLeft = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);
   fBar = new TGMenuBar(this, 1, 20, kHorizontalFrame);
   fRight = new TGCompositeFrame(this, 10, 10, kHorizontalFrame);

   AddFrame(fLeft,  fLeftHint);
   AddFrame(fBar,   fBarHint);
   AddFrame(fRight, fRightHint);
}

//______________________________________________________________________________
TGMdiMenuBar::~TGMdiMenuBar()
{
   // TGMdiMenuBar destructor.

   if (!MustCleanup()) {
      delete fLHint;
      delete fLeftHint;
      delete fRightHint;
      delete fBarHint;
   }
}

//______________________________________________________________________________
void TGMdiMenuBar::AddPopup(TGHotString *s, TGPopupMenu *menu, TGLayoutHints *l)
{
   // Add popup menu to the MDI menu bar with layout hints l.

   fBar->AddPopup(s, menu, l);
   // Layout();
}

//______________________________________________________________________________
void TGMdiMenuBar::AddFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
{
   // This is called from TGMdiMainFrame on Maximize().

   // Hide all frames first
   TGFrameElement *el;
   TIter nextl(fLeft->GetList());
   while ((el = (TGFrameElement *) nextl())) {
      fLeft->HideFrame(el->fFrame);
   }
   TIter nextr(fRight->GetList());
   while ((el = (TGFrameElement *) nextr())) {
      fRight->HideFrame(el->fFrame);
   }
   // Then add specified frames
   icon->ReparentWindow(fLeft);
   buttons->ReparentWindow(fRight);
   fLeft->AddFrame(icon, fLHint);
   fRight->AddFrame(buttons, fLHint);
}

//______________________________________________________________________________
void TGMdiMenuBar::RemoveFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
{
   // This is called from TGMdiMainFrame on Restore()

   // Remove specified frames
   fLeft->RemoveFrame(icon);
   fRight->RemoveFrame(buttons);
   // Then show (restore) last frames
   TGFrameElement *el;
   el = (TGFrameElement *)fLeft->GetList()->Last();
   if (el)
      fLeft->ShowFrame(el->fFrame);
   el = (TGFrameElement *)fRight->GetList()->Last();
   if (el)
      fRight->ShowFrame(el->fFrame);
}

//______________________________________________________________________________
void TGMdiMenuBar::ShowFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
{
   // This is called from TGMdiMainFrame on Maximize().

   // Hide all frames first
   TGFrameElement *el;
   TIter nextl(fLeft->GetList());
   while ((el = (TGFrameElement *) nextl())) {
      fLeft->HideFrame(el->fFrame);
   }
   TIter nextr(fRight->GetList());
   while ((el = (TGFrameElement *) nextr())) {
      fRight->HideFrame(el->fFrame);
   }
   // Then show specified frames
   fLeft->ShowFrame(icon);
   fRight->ShowFrame(buttons);
}

//______________________________________________________________________________
void TGMdiMenuBar::HideFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons)
{
   // Used to hide specific frames from menu bar

   // Hide specified frames
   fLeft->HideFrame(icon);
   fRight->HideFrame(buttons);
   
   // Then show (restore) last frames
   TGFrameElement *el;
   el = (TGFrameElement *)fLeft->GetList()->Last();
   if (el)
      fLeft->ShowFrame(el->fFrame);
   el = (TGFrameElement *)fRight->GetList()->Last();
   if (el)
      fRight->ShowFrame(el->fFrame);
}

//______________________________________________________________________________
void TGMdiMenuBar::SavePrimitive(ostream &out, Option_t *option /*= ""*/)
{
   // Save a MDI menu as a C++ statement(s) on output stream out

   out << endl;
   out << "   // MDI menu bar" << endl;

   out << "   TGMdiMenuBar *";
   out << GetName() << " = new TGMdiMenuBar(" << fParent->GetName()
       << "," << GetWidth() << "," << GetHeight() << ");" << endl;

   if (!fList) return;

   out << "   TGMenuBar *" << fBar->GetName() << " = " << GetName()
       << "->GetMenuBar();" << endl;

   TGFrameElement *el;
   TIter next(fBar->GetList());

   while ((el = (TGFrameElement *)next())) {
      el->fFrame->SavePrimitive(out, option);
      el->fLayout->SavePrimitive(out, option);
      out << ");" << endl;
   }
}
 TGMdiMenu.cxx:1
 TGMdiMenu.cxx:2
 TGMdiMenu.cxx:3
 TGMdiMenu.cxx:4
 TGMdiMenu.cxx:5
 TGMdiMenu.cxx:6
 TGMdiMenu.cxx:7
 TGMdiMenu.cxx:8
 TGMdiMenu.cxx:9
 TGMdiMenu.cxx:10
 TGMdiMenu.cxx:11
 TGMdiMenu.cxx:12
 TGMdiMenu.cxx:13
 TGMdiMenu.cxx:14
 TGMdiMenu.cxx:15
 TGMdiMenu.cxx:16
 TGMdiMenu.cxx:17
 TGMdiMenu.cxx:18
 TGMdiMenu.cxx:19
 TGMdiMenu.cxx:20
 TGMdiMenu.cxx:21
 TGMdiMenu.cxx:22
 TGMdiMenu.cxx:23
 TGMdiMenu.cxx:24
 TGMdiMenu.cxx:25
 TGMdiMenu.cxx:26
 TGMdiMenu.cxx:27
 TGMdiMenu.cxx:28
 TGMdiMenu.cxx:29
 TGMdiMenu.cxx:30
 TGMdiMenu.cxx:31
 TGMdiMenu.cxx:32
 TGMdiMenu.cxx:33
 TGMdiMenu.cxx:34
 TGMdiMenu.cxx:35
 TGMdiMenu.cxx:36
 TGMdiMenu.cxx:37
 TGMdiMenu.cxx:38
 TGMdiMenu.cxx:39
 TGMdiMenu.cxx:40
 TGMdiMenu.cxx:41
 TGMdiMenu.cxx:42
 TGMdiMenu.cxx:43
 TGMdiMenu.cxx:44
 TGMdiMenu.cxx:45
 TGMdiMenu.cxx:46
 TGMdiMenu.cxx:47
 TGMdiMenu.cxx:48
 TGMdiMenu.cxx:49
 TGMdiMenu.cxx:50
 TGMdiMenu.cxx:51
 TGMdiMenu.cxx:52
 TGMdiMenu.cxx:53
 TGMdiMenu.cxx:54
 TGMdiMenu.cxx:55
 TGMdiMenu.cxx:56
 TGMdiMenu.cxx:57
 TGMdiMenu.cxx:58
 TGMdiMenu.cxx:59
 TGMdiMenu.cxx:60
 TGMdiMenu.cxx:61
 TGMdiMenu.cxx:62
 TGMdiMenu.cxx:63
 TGMdiMenu.cxx:64
 TGMdiMenu.cxx:65
 TGMdiMenu.cxx:66
 TGMdiMenu.cxx:67
 TGMdiMenu.cxx:68
 TGMdiMenu.cxx:69
 TGMdiMenu.cxx:70
 TGMdiMenu.cxx:71
 TGMdiMenu.cxx:72
 TGMdiMenu.cxx:73
 TGMdiMenu.cxx:74
 TGMdiMenu.cxx:75
 TGMdiMenu.cxx:76
 TGMdiMenu.cxx:77
 TGMdiMenu.cxx:78
 TGMdiMenu.cxx:79
 TGMdiMenu.cxx:80
 TGMdiMenu.cxx:81
 TGMdiMenu.cxx:82
 TGMdiMenu.cxx:83
 TGMdiMenu.cxx:84
 TGMdiMenu.cxx:85
 TGMdiMenu.cxx:86
 TGMdiMenu.cxx:87
 TGMdiMenu.cxx:88
 TGMdiMenu.cxx:89
 TGMdiMenu.cxx:90
 TGMdiMenu.cxx:91
 TGMdiMenu.cxx:92
 TGMdiMenu.cxx:93
 TGMdiMenu.cxx:94
 TGMdiMenu.cxx:95
 TGMdiMenu.cxx:96
 TGMdiMenu.cxx:97
 TGMdiMenu.cxx:98
 TGMdiMenu.cxx:99
 TGMdiMenu.cxx:100
 TGMdiMenu.cxx:101
 TGMdiMenu.cxx:102
 TGMdiMenu.cxx:103
 TGMdiMenu.cxx:104
 TGMdiMenu.cxx:105
 TGMdiMenu.cxx:106
 TGMdiMenu.cxx:107
 TGMdiMenu.cxx:108
 TGMdiMenu.cxx:109
 TGMdiMenu.cxx:110
 TGMdiMenu.cxx:111
 TGMdiMenu.cxx:112
 TGMdiMenu.cxx:113
 TGMdiMenu.cxx:114
 TGMdiMenu.cxx:115
 TGMdiMenu.cxx:116
 TGMdiMenu.cxx:117
 TGMdiMenu.cxx:118
 TGMdiMenu.cxx:119
 TGMdiMenu.cxx:120
 TGMdiMenu.cxx:121
 TGMdiMenu.cxx:122
 TGMdiMenu.cxx:123
 TGMdiMenu.cxx:124
 TGMdiMenu.cxx:125
 TGMdiMenu.cxx:126
 TGMdiMenu.cxx:127
 TGMdiMenu.cxx:128
 TGMdiMenu.cxx:129
 TGMdiMenu.cxx:130
 TGMdiMenu.cxx:131
 TGMdiMenu.cxx:132
 TGMdiMenu.cxx:133
 TGMdiMenu.cxx:134
 TGMdiMenu.cxx:135
 TGMdiMenu.cxx:136
 TGMdiMenu.cxx:137
 TGMdiMenu.cxx:138
 TGMdiMenu.cxx:139
 TGMdiMenu.cxx:140
 TGMdiMenu.cxx:141
 TGMdiMenu.cxx:142
 TGMdiMenu.cxx:143
 TGMdiMenu.cxx:144
 TGMdiMenu.cxx:145
 TGMdiMenu.cxx:146
 TGMdiMenu.cxx:147
 TGMdiMenu.cxx:148
 TGMdiMenu.cxx:149
 TGMdiMenu.cxx:150
 TGMdiMenu.cxx:151
 TGMdiMenu.cxx:152
 TGMdiMenu.cxx:153
 TGMdiMenu.cxx:154
 TGMdiMenu.cxx:155
 TGMdiMenu.cxx:156
 TGMdiMenu.cxx:157
 TGMdiMenu.cxx:158
 TGMdiMenu.cxx:159
 TGMdiMenu.cxx:160
 TGMdiMenu.cxx:161
 TGMdiMenu.cxx:162
 TGMdiMenu.cxx:163
 TGMdiMenu.cxx:164
 TGMdiMenu.cxx:165
 TGMdiMenu.cxx:166
 TGMdiMenu.cxx:167
 TGMdiMenu.cxx:168
 TGMdiMenu.cxx:169
 TGMdiMenu.cxx:170
 TGMdiMenu.cxx:171
 TGMdiMenu.cxx:172
 TGMdiMenu.cxx:173
 TGMdiMenu.cxx:174
 TGMdiMenu.cxx:175
 TGMdiMenu.cxx:176
 TGMdiMenu.cxx:177
 TGMdiMenu.cxx:178
 TGMdiMenu.cxx:179
 TGMdiMenu.cxx:180
 TGMdiMenu.cxx:181
 TGMdiMenu.cxx:182
 TGMdiMenu.cxx:183
 TGMdiMenu.cxx:184
 TGMdiMenu.cxx:185
 TGMdiMenu.cxx:186
 TGMdiMenu.cxx:187
 TGMdiMenu.cxx:188
 TGMdiMenu.cxx:189
 TGMdiMenu.cxx:190
 TGMdiMenu.cxx:191
 TGMdiMenu.cxx:192
 TGMdiMenu.cxx:193
 TGMdiMenu.cxx:194
 TGMdiMenu.cxx:195