Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGMdiDecorFrame.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Bertrand Bellenot 20/08/2004
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGMdiDecorFrame
13 #define ROOT_TGMdiDecorFrame
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TGMdiDecorFrame, TGMdiTitleBar, TGMdiButtons, TGMdiTitleIcon, //
18 // TGMdiWinResizer, TGMdiVerticalWinResizer, TGMdiHorizontalWinResizer, //
19 // and TGMdiCornerWinResizer. //
20 // //
21 // This header contains all different MDI frame decoration classes. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #include "TGFrame.h"
26 #include "TGMenu.h"
27 #include "TGButton.h"
28 #include "TGIcon.h"
29 #include "TGLabel.h"
30 #include "TGFont.h"
31 #include "TGMdiMainFrame.h"
32 #include "TGMdiFrame.h"
33 
34 
35 // placement of window resizers
36 enum EMdiResizerPlacement {
37  kMdiResizerTop = 1,
38  kMdiResizerBottom = 2,
39  kMdiResizerLeft = 4,
40  kMdiResizerRight = 8
41 };
42 
43 
44 class TGMdiMainFrame;
45 class TGMdiDecorFrame;
46 class TGMdiFrame;
47 class TGMdiTitleBar;
48 class TGMdiTitleIcon;
49 class TGMdiButtons;
50 
51 
52 //----------------------------------------------------------------------
53 
54 class TGMdiWinResizer : public TGFrame, public TGWidget {
55 
56 friend class TGMdiMainFrame;
57 
58 protected:
59  const TGWindow *fMdiWin; // owner MDI Window
60  Int_t fWinX, fWinY, fWinW, fWinH; // MDI win position and dimension
61  Int_t fOldX, fOldY, fOldW, fOldH; // old MDI win position and dimension
62  Int_t fNewX, fNewY, fNewW, fNewH; // new MDI win position and dimension
63  Int_t fMinW, fMinH; // Min width and height of the MDI Win
64  Int_t fMdiOptions; // MDI options
65  Int_t fPos; // position of the resizer
66  Int_t fX0, fY0; // initial position of the mouse click
67  Bool_t fLeftButPressed, fRightButPressed, fMidButPressed; // mouse buttons flags
68 
69  const TGGC *fBoxGC; // GC used for resizing rectangle
70  Int_t fLineW; // line width of resizing rectangle
71 
72  void MoveResizeIt();
73  void DrawBox(Int_t x, Int_t y, UInt_t width, UInt_t height);
74 
75 public:
76  TGMdiWinResizer(const TGWindow *p, const TGWindow *mdiwin, Int_t pos,
77  const TGGC *boxGC, Int_t linew,
78  Int_t mdioptions = kMdiDefaultResizeMode,
79  Int_t w = 1, Int_t h = 1, UInt_t options = kOwnBackground);
80 
81  virtual Bool_t HandleButton(Event_t *event);
82  virtual void DrawBorder() {};
83 
84  void SetResizeMode(Int_t mode) { fMdiOptions = mode; }
85  void SetMinSize(Int_t w = 50, Int_t h = 20) { fMinW = w; fMinH = h; }
86 
87  ClassDef(TGMdiWinResizer, 0) // Window Resizer
88 };
89 
90 
91 class TGMdiVerticalWinResizer : public TGMdiWinResizer {
92 
93 public:
94  TGMdiVerticalWinResizer(const TGWindow *p, const TGWindow *mdiwin,
95  Int_t pos, const TGGC *boxGC, Int_t linew,
96  Int_t mdioptions = kMdiDefaultResizeMode,
97  Int_t w = 4, Int_t h = 5);
98 
99  virtual Bool_t HandleMotion(Event_t *event);
100  virtual void DrawBorder();
101 
102  ClassDef(TGMdiVerticalWinResizer, 0) // Vertical Window Resizer
103 };
104 
105 
106 class TGMdiHorizontalWinResizer : public TGMdiWinResizer {
107 
108 public:
109  TGMdiHorizontalWinResizer(const TGWindow *p, const TGWindow *mdiwin,
110  Int_t pos, const TGGC *boxGC, Int_t linew,
111  Int_t mdioptions = kMdiDefaultResizeMode,
112  Int_t w = 5, Int_t h = 4);
113 
114  virtual Bool_t HandleMotion(Event_t *event);
115  virtual void DrawBorder();
116 
117  ClassDef(TGMdiHorizontalWinResizer, 0) // Horizontal Window Resizer
118 };
119 
120 
121 class TGMdiCornerWinResizer : public TGMdiWinResizer {
122 
123 public:
124  TGMdiCornerWinResizer(const TGWindow *p, const TGWindow *mdiwin,
125  Int_t pos, const TGGC *boxGC, Int_t linew,
126  Int_t mdioptions = kMdiDefaultResizeMode,
127  Int_t w = 20, Int_t h = 20);
128 
129  virtual Bool_t HandleMotion(Event_t *event);
130  virtual void DrawBorder();
131 
132  ClassDef(TGMdiCornerWinResizer, 0) // Corner Window Resizer
133 };
134 
135 
136 //----------------------------------------------------------------------
137 
138 class TGMdiButtons : public TGCompositeFrame {
139 
140 friend class TGMdiTitleBar;
141 
142 protected:
143  TGPictureButton *fButton[5]; // MDI picture buttons
144  TGLayoutHints *fDefaultHint, *fCloseHint; // Layout hints
145  const TGWindow *fMsgWindow; // window handling container messages
146 
147 public:
148  TGMdiButtons(const TGWindow *p, const TGWindow *titlebar);
149  virtual ~TGMdiButtons();
150 
151  TGPictureButton *GetButton(Int_t no) const { return fButton[no]; }
152 
153  ClassDef(TGMdiButtons, 0) // MDI Buttons Frame
154 };
155 
156 
157 //----------------------------------------------------------------------
158 
159 class TGMdiTitleIcon : public TGIcon {
160 
161 friend class TGMdiFrame;
162 friend class TGMdiTitleBar;
163 
164 protected:
165  const TGWindow *fMsgWindow; // window handling container messages
166  TGPopupMenu *fPopup; // Popup menu associated to the title icon
167 
168  virtual void DoRedraw();
169 
170 public:
171  TGMdiTitleIcon(const TGWindow *p, const TGWindow *titlebar,
172  const TGPicture *pic, Int_t w, Int_t h);
173  virtual ~TGMdiTitleIcon();
174 
175  virtual Bool_t HandleDoubleClick(Event_t *event);
176  virtual Bool_t HandleButton(Event_t *event);
177  TGPopupMenu *GetPopup() const { return fPopup; }
178 
179  ClassDef(TGMdiTitleIcon, 0) // MDI Title Icon
180 };
181 
182 
183 //----------------------------------------------------------------------
184 
185 class TGMdiTitleBar : public TGCompositeFrame {
186 
187 friend class TGMdiDecorFrame;
188 friend class TGMdiMainFrame;
189 
190 protected:
191  const TGWindow *fMdiWin; // owner MDI window
192  TGMdiButtons *fButtons; // MDI buttons
193  TGMdiTitleIcon *fWinIcon; // title icon
194  TGLabel *fWinName; // window name label
195  TGCompositeFrame *fLFrame, *fMFrame,*fRFrame; // the three parts of the title bar
196  TGLayoutHints *fLHint, *fLeftHint, *fMiddleHint, *fRightHint; // layout hints
197  Int_t fX0, fY0; // initial position of the mouse click
198  Bool_t fLeftButPressed, fRightButPressed, fMidButPressed; // mouse button pressed
199 
200  TGMdiTitleBar(const TGWindow *p, const TGWindow *mdiwin,
201  const char *name = "Untitled");
202  void LayoutButtons(UInt_t buttonmask, Bool_t isMinimized,
203  Bool_t isMaximized);
204 
205  void AddFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons);
206  void RemoveFrames(TGMdiTitleIcon *icon, TGMdiButtons *buttons);
207 
208 public:
209  virtual ~TGMdiTitleBar();
210 
211  virtual Bool_t HandleButton(Event_t *event);
212  virtual Bool_t HandleDoubleClick(Event_t *event);
213  virtual Bool_t HandleMotion(Event_t *event);
214  virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
215 
216  void SetTitleBarColors(UInt_t fore, UInt_t back, TGFont *f);
217  TGMdiButtons *GetButtons() const { return fButtons; }
218  TGMdiTitleIcon *GetWinIcon() const { return fWinIcon; }
219  TGLabel *GetWinName() const { return fWinName; }
220  Int_t GetX0() { return fX0; }
221  Int_t GetY0() { return fY0; }
222  Bool_t IsLeftButPressed() { return fLeftButPressed; }
223  Bool_t IsRightButPressed() { return fRightButPressed; }
224  Bool_t IsMidButPressed() { return fMidButPressed; }
225 
226  void SetX0(Int_t x0) { fX0 = x0; }
227  void SetY0(Int_t y0) { fY0 = y0; }
228  void SetLeftButPressed(Bool_t press = kTRUE) { fLeftButPressed = press; }
229  void SetRightButPressed(Bool_t press = kTRUE) { fRightButPressed= press; }
230  void SetMidButPressed(Bool_t press = kTRUE) { fMidButPressed = press; }
231 
232  ClassDef(TGMdiTitleBar, 0) // MDI Title Bar
233 };
234 
235 
236 //----------------------------------------------------------------------
237 
238 class TGMdiDecorFrame : public TGCompositeFrame {
239 
240 friend class TGMdiMainFrame;
241 
242 protected:
243  Int_t fPreResizeX, fPreResizeY; // position before resizing
244  Int_t fPreResizeWidth, fPreResizeHeight; // dimension before resizing
245  Int_t fMinimizedX, fMinimizedY; // minimized position
246  Bool_t fIsMinimized, fIsMaximized; // minimized and maximized flags
247  Bool_t fMinimizedUserPlacement; // user placement flag
248  Bool_t fIsCurrent; // current mdi window flag
249 
250  TGMdiFrame *fFrame; // parent (owner) MDI frame
251  TGMdiMainFrame *fMdiMainFrame; // MDI main frame
252 
253  TGMdiVerticalWinResizer *fUpperHR, *fLowerHR; // upper and lower vertical resizers
254  TGMdiCornerWinResizer *fUpperLeftCR, *fLowerLeftCR; // upper left and lower left resizers
255  TGMdiCornerWinResizer *fUpperRightCR, *fLowerRightCR; // upper right and lower right resizers
256  TGMdiHorizontalWinResizer *fLeftVR, *fRightVR; // left and right horizontal resizers
257  TGLayoutHints *fLHint, *fExpandHint; // layout hints
258 
259  ULong_t fButtonMask; // mask used to display/hide buttons
260  TGMdiTitleBar *fTitlebar; // MDI window title bar
261 
262 public:
263  enum {
264  // border width of decorated windows
265  kMdiBorderWidth = 5
266  };
267 
268  TGMdiDecorFrame(TGMdiMainFrame *main, TGMdiFrame *frame, Int_t w, Int_t h,
269  const TGGC *boxGC, UInt_t options = 0,
270  Pixel_t back = GetDefaultFrameBackground());
271  virtual ~TGMdiDecorFrame();
272 
273  virtual Bool_t HandleButton(Event_t *event);
274  virtual Bool_t HandleConfigureNotify(Event_t *event);
275 
276  virtual Int_t CloseWindow() { return fFrame->CloseWindow(); }
277  virtual void Layout();
278 
279  virtual void Move(Int_t x, Int_t y);
280  virtual void MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h);
281 
282  void SetMdiButtons(ULong_t buttons);
283  ULong_t GetMdiButtons() const { return fButtonMask; }
284 
285  void SetResizeMode(Int_t mode = kMdiDefaultResizeMode);
286 
287  void SetWindowName(const char *name);
288  void SetWindowIcon(const TGPicture *pic);
289  const char *GetWindowName() {
290  return (const char *)fTitlebar->GetWinName()->GetText()->GetString();
291  }
292  const TGPicture *GetWindowIcon() { return fTitlebar->GetWinIcon()->GetPicture(); }
293  Bool_t IsCurrent() const { return fIsCurrent; }
294  Bool_t IsMinimized() const { return fIsMinimized; }
295  Bool_t IsMaximized() const { return fIsMaximized; }
296  Int_t GetPreResizeX() const { return fPreResizeX; }
297  Int_t GetPreResizeY() const { return fPreResizeY; }
298  Int_t GetPreResizeWidth() const { return fPreResizeWidth; }
299  Int_t GetPreResizeHeight() const { return fPreResizeHeight; }
300  Int_t GetMinimizedX() const { return fMinimizedX; }
301  Int_t GetMinimizedY() const { return fMinimizedY; }
302  Bool_t GetMinUserPlacement() const { return fMinimizedUserPlacement; }
303 
304  void SetCurrent(Bool_t cur = kTRUE) {fIsCurrent = cur; }
305  void SetDecorBorderWidth(Int_t bw);
306  void SetPreResizeX(Int_t x) { fPreResizeX = x; }
307  void SetPreResizeY(Int_t y) { fPreResizeY = y; }
308  void SetPreResizeWidth(Int_t w) { fPreResizeWidth = w; }
309  void SetPreResizeHeight(Int_t h) { fPreResizeHeight = h; }
310  void SetMinimizedX(Int_t x) { fMinimizedX = x; }
311  void SetMinimizedY(Int_t y) { fMinimizedY = y; }
312  void Minimize(Bool_t min = kTRUE) { fIsMinimized = min; }
313  void Maximize(Bool_t max = kTRUE) { fIsMaximized = max; }
314  void SetMinUserPlacement(Bool_t place = kTRUE) { fMinimizedUserPlacement = place; }
315 
316  TGMdiFrame *GetMdiFrame() const { return fFrame; }
317  TGMdiTitleBar *GetTitleBar() const { return fTitlebar; }
318 
319  TGMdiVerticalWinResizer *GetUpperHR() const { return fUpperHR; }
320  TGMdiVerticalWinResizer *GetLowerHR() const { return fLowerHR; }
321  TGMdiCornerWinResizer *GetUpperLeftCR() const { return fUpperLeftCR; }
322  TGMdiCornerWinResizer *GetLowerLeftCR() const { return fLowerLeftCR; }
323  TGMdiCornerWinResizer *GetUpperRightCR() const { return fUpperRightCR; }
324  TGMdiCornerWinResizer *GetLowerRightCR() const { return fLowerRightCR; }
325  TGMdiHorizontalWinResizer *GetLeftVR() const { return fLeftVR; }
326  TGMdiHorizontalWinResizer *GetRightVR() const { return fRightVR; }
327 
328  ClassDef(TGMdiDecorFrame, 0) // MDI Decor Frame
329 };
330 
331 #endif