]>
git.saurik.com Git - wxWidgets.git/blob - utils/framelayout/src/barhintspl.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
6 // Created: 30/11/98 (my 22th birthday :-)
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "rowlayoutpl.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
29 #include "barhintspl.h"
33 #define GROOVE_WIDTH 3 // left shade + middle line + right shade
34 #define GROOVE_TO_GROOVE_GAP 1
35 #define BOX_T_BOX_GAP 2
36 #define BOX_TO_GROOVE_GAP 3
38 #define BOXES_IN_HINT 2
39 #define CLOSE_BOX_IDX 0
40 #define COLLAPSE_BOX_IDX 1
44 #define CLOSE_BOX_HITTED 1
45 #define COLLAPSE_BOX_HITTED 2
47 /***** Implementation fro class cbBarHintsPlugin *****/
49 IMPLEMENT_DYNAMIC_CLASS( cbBarHintsPlugin
, cbPluginBase
)
51 BEGIN_EVENT_TABLE( cbBarHintsPlugin
, cbPluginBase
)
53 EVT_PL_SIZE_BAR_WND ( cbBarHintsPlugin::OnSizeBarWindow
)
54 EVT_PL_DRAW_BAR_DECOR( cbBarHintsPlugin::OnDrawBarDecorations
)
56 EVT_PL_LEFT_DOWN( cbBarHintsPlugin::OnLeftDown
)
57 EVT_PL_LEFT_UP ( cbBarHintsPlugin::OnLeftUp
)
58 EVT_PL_MOTION ( cbBarHintsPlugin::OnMotion
)
62 cbBarHintsPlugin::cbBarHintsPlugin(void)
65 mCollapseBoxOn( TRUE
),
67 mBtnPressed ( FALSE
),
73 cbBarHintsPlugin::cbBarHintsPlugin( wxFrameLayout
* pLayout
, int paneMask
)
75 : cbPluginBase( pLayout
, paneMask
),
77 mCollapseBoxOn( TRUE
),
79 mBtnPressed ( FALSE
),
85 void cbBarHintsPlugin::SetGrooveCount( int nGrooves
)
87 mGrooveCount
= nGrooves
;
90 void cbBarHintsPlugin::CreateBoxes()
92 cbCloseBox
* box1
= new cbCloseBox();
93 cbCollapseBox
* box2
= new cbCollapseBox();
95 mBoxes
[CLOSE_BOX_IDX
] = box1
;
96 mBoxes
[COLLAPSE_BOX_IDX
] = box2
;
98 for( int i
= 0; i
!= BOXES_IN_HINT
; ++i
)
100 mBoxes
[i
]->mpLayout
= mpLayout
;
101 mBoxes
[i
]->mpPlugin
= this;
102 mBoxes
[i
]->mpWnd
= NULL
;
106 void cbBarHintsPlugin::Draw3DBox( wxDC
& dc
, const wxPoint
& pos
, bool pressed
)
110 void cbBarHintsPlugin::DrawCloseBox( wxDC
& dc
, const wxPoint
& pos
, bool pressed
)
114 void cbBarHintsPlugin::DrawCollapseBox( wxDC
& dc
, const wxPoint
& pos
,
115 bool atLeft
, bool disabled
, bool pressed
)
119 void cbBarHintsPlugin::DrawGrooves( wxDC
& dc
, const wxPoint
& pos
, int length
)
123 for( int i
= 0; i
!= mGrooveCount
; ++i
, ofs
+= ( GROOVE_WIDTH
+ GROOVE_TO_GROOVE_GAP
) )
125 if ( mpPane
->IsHorizontal() )
127 dc
.SetPen( mpLayout
->mLightPen
);
128 dc
.DrawLine( pos
.x
+ ofs
, pos
.y
, pos
.x
+ ofs
, pos
.y
+ length
- 1 );
129 dc
.DrawPoint( pos
.x
+ ofs
+ 1, pos
.y
);
131 dc
.SetPen( mpLayout
->mDarkPen
);
132 dc
.DrawLine( pos
.x
+ ofs
+ 2, pos
.y
, pos
.x
+ ofs
+ 2, pos
.y
+ length
);
133 dc
.DrawPoint( pos
.x
+ ofs
+ 1, pos
.y
+ length
- 1 );
134 dc
.DrawPoint( pos
.x
+ ofs
, pos
.y
+ length
- 1 );
138 dc
.SetPen( mpLayout
->mLightPen
);
139 dc
.DrawLine( pos
.x
, pos
.y
+ ofs
, pos
.x
+ length
- 1, pos
.y
+ ofs
);
140 dc
.DrawPoint( pos
.x
, pos
.y
+ ofs
+ 1 );
142 dc
.SetPen( mpLayout
->mDarkPen
);
143 dc
.DrawLine( pos
.x
, pos
.y
+ ofs
+ 2, pos
.x
+ length
, pos
.y
+ ofs
+ 2 );
144 dc
.DrawPoint( pos
.x
+ length
- 1, pos
.y
+ ofs
+ 1 );
145 dc
.DrawPoint( pos
.x
+ length
- 1, pos
.y
+ ofs
);
149 void cbBarHintsPlugin::ExcludeHints( wxRect
& rect
, cbBarInfo
& info
)
151 int boxHeight
= BTN_BOX_HEIGHT
;
153 // collapse and close box are not placed on fixed bars
155 if ( info
.IsFixed() || ( !mCloseBoxOn
&& !mCollapseBoxOn
) )
159 int height
= wxMax( mGrooveCount
*(GROOVE_WIDTH
+ GROOVE_TO_GROOVE_GAP
)
160 - GROOVE_TO_GROOVE_GAP
,
164 if ( mpPane
->IsHorizontal() )
166 rect
.x
+= ( mHintGap
*2 + height
);
167 rect
.width
-= (height
+ 2*mHintGap
);
169 rect
.x
-= info
.mDimInfo
.mHorizGap
+ 2;
170 rect
.width
+= info
.mDimInfo
.mHorizGap
+ 2;
174 rect
.y
+= (mHintGap
*2 + height
);
175 rect
.height
-= (height
+ 2*mHintGap
);
177 rect
.y
-= info
.mDimInfo
.mVertGap
+ 2;
178 rect
.height
+= info
.mDimInfo
.mVertGap
+ 2;
182 void cbBarHintsPlugin::DoDrawHint( wxDC
& dc
, wxRect
& rect
,
183 int pos
, int boxOfs
, int grooveOfs
,
188 if ( mpPane
->IsHorizontal() )
192 mBoxes
[CLOSE_BOX_IDX
]->Draw( dc
);
194 if ( mCollapseBoxOn
)
196 mBoxes
[COLLAPSE_BOX_IDX
]->Draw( dc
);
202 mBoxes
[CLOSE_BOX_IDX
]->Draw( dc
);
204 if ( mCollapseBoxOn
)
206 mBoxes
[COLLAPSE_BOX_IDX
]->Draw( dc
);
210 if ( mpPane
->IsHorizontal() )
212 DrawGrooves( dc
, wxPoint( rect
.x
+ mHintGap
+ grooveOfs
, pos
),
213 rect
.height
- (pos
- rect
.y
) - mHintGap
);
215 DrawGrooves( dc
, wxPoint( rect
.x
+ mHintGap
, rect
.y
+ mHintGap
+ grooveOfs
),
216 (pos
- rect
.x
) - mHintGap
);
219 void cbBarHintsPlugin::GetHintsLayout( wxRect
& rect
, cbBarInfo
& info
,
220 int& boxOfs
, int& grooveOfs
, int& pos
)
222 int boxHeight
= BTN_BOX_HEIGHT
;
223 int boxWidth
= BTN_BOX_WIDTH
+ BOX_TO_GROOVE_GAP
+ BTN_BOX_WIDTH
;
225 // collapse and close box are not placed on fixed bars
227 if ( info
.IsFixed() || ( !mCloseBoxOn
&& !mCollapseBoxOn
) )
233 if ( !mCloseBoxOn
|| !mCollapseBoxOn
)
235 boxWidth
= BTN_BOX_WIDTH
;
237 int grooveHeight
= mGrooveCount
*(GROOVE_WIDTH
+ GROOVE_TO_GROOVE_GAP
)
238 - GROOVE_TO_GROOVE_GAP
;
240 int height
= wxMax( grooveHeight
, boxHeight
);
242 // center boxs and groves with respect to each other
244 boxOfs
= ( height
- boxHeight
) / 2;
245 grooveOfs
= ( height
- grooveHeight
) / 2;
247 pos
= ( mpPane
->IsHorizontal() ) ? rect
.y
+ mHintGap
248 : rect
.x
+ rect
.width
- mHintGap
;
250 // setup positions for boxes
252 if ( !info
.IsFixed() )
254 // what direction "collapse-triangle" should look at?
256 bool& isAtLeft
= ((cbCollapseBox
*)(mBoxes
[COLLAPSE_BOX_IDX
]))->mIsAtLeft
;
258 isAtLeft
= info
.mBounds
.x
<= mpPane
->mPaneWidth
- ( info
.mBounds
.x
+ info
.mBounds
.width
);
260 if ( info
.IsExpanded() )
264 cbBarInfo
* pCur
= info
.mpPrev
;
268 if ( !pCur
->IsFixed() )
270 isAtLeft
= TRUE
; break;
277 // collapse/expand works only when more not-fixed bars are present in the same row
279 mBoxes
[COLLAPSE_BOX_IDX
]->Enable( info
.mpRow
->mNotFixedBarsCnt
> 1 );
281 for( int i
= 0; i
!= BOXES_IN_HINT
; ++i
)
283 mBoxes
[i
]->mpPane
= mpPane
;
286 if ( mpPane
->IsHorizontal() )
290 mBoxes
[CLOSE_BOX_IDX
]->mPos
= wxPoint( rect
.x
+ mHintGap
+ boxOfs
, pos
);
292 pos
+= BTN_BOX_HEIGHT
;
295 if ( mCollapseBoxOn
)
297 if ( mCloseBoxOn
) pos
+= BOX_T_BOX_GAP
;
299 mBoxes
[COLLAPSE_BOX_IDX
]->mPos
= wxPoint( rect
.x
+ mHintGap
+ boxOfs
, pos
);
301 pos
+= BTN_BOX_HEIGHT
;
303 pos
+= BOX_TO_GROOVE_GAP
;
310 pos
-= BTN_BOX_WIDTH
;
312 mBoxes
[CLOSE_BOX_IDX
]->mPos
= wxPoint( pos
, rect
.y
+ mHintGap
+ boxOfs
);
315 if ( mCollapseBoxOn
)
317 if ( mCloseBoxOn
) pos
-= BOX_T_BOX_GAP
;
319 pos
-= BTN_BOX_WIDTH
;
321 mBoxes
[COLLAPSE_BOX_IDX
]->mPos
= wxPoint( pos
, rect
.y
+ mHintGap
+ boxOfs
);
323 pos
-= BOX_TO_GROOVE_GAP
;
329 static inline bool is_in_box( const wxPoint
& rectPos
, const wxPoint
& mousePos
)
331 return ( mousePos
.x
>= rectPos
.x
&&
332 mousePos
.y
>= rectPos
.y
&&
333 mousePos
.x
< rectPos
.x
+ BTN_BOX_WIDTH
&&
334 mousePos
.y
< rectPos
.y
+ BTN_BOX_HEIGHT
);
337 int cbBarHintsPlugin::HitTestHints( cbBarInfo
& info
, const wxPoint
& pos
)
339 wxPoint inPane
= pos
;
340 mpPane
->PaneToFrame( &inPane
.x
, &inPane
.y
);
342 wxRect
& rect
= info
.mBoundsInParent
;
344 if ( info
.IsFixed() ) return FALSE
;
346 int boxOfs
, grooveOfs
, coord
;
348 GetHintsLayout( rect
, info
, boxOfs
, grooveOfs
, coord
);
350 if ( mpPane
->IsHorizontal() )
354 if ( is_in_box( wxPoint( rect
.x
+ mHintGap
+ boxOfs
, coord
), inPane
) )
356 return CLOSE_BOX_HITTED
;
358 coord
+= BTN_BOX_HEIGHT
;
361 if ( mCollapseBoxOn
)
363 if ( mCloseBoxOn
) coord
+= BOX_T_BOX_GAP
;
365 if ( is_in_box( wxPoint( rect
.x
+ mHintGap
+ boxOfs
, coord
), inPane
) )
367 return COLLAPSE_BOX_HITTED
;
369 coord
+= BTN_BOX_HEIGHT
;
376 coord
-= BTN_BOX_WIDTH
;
378 if ( is_in_box( wxPoint( coord
, rect
.y
+ mHintGap
+ boxOfs
), inPane
) )
380 return CLOSE_BOX_HITTED
;
383 if ( mCollapseBoxOn
)
385 if ( mCloseBoxOn
) coord
-= BOX_T_BOX_GAP
;
386 coord
-= BTN_BOX_WIDTH
;
388 if ( is_in_box( wxPoint( coord
, rect
.y
+ mHintGap
+ boxOfs
), inPane
) )
390 return COLLAPSE_BOX_HITTED
;
397 // handlers for plugin-events
399 void cbBarHintsPlugin::OnSizeBarWindow( cbSizeBarWndEvent
& event
)
401 wxRect
& rect
= event
.mBoundsInParent
;
402 mpPane
= event
.mpPane
;
404 ExcludeHints( rect
, *event
.mpBar
);
406 event
.Skip(); // pass event to the next plugin in the chain
409 void cbBarHintsPlugin::OnDrawBarDecorations( cbDrawBarDecorEvent
& event
)
411 wxRect
& rect
= event
.mBoundsInParent
;
412 mpPane
= event
.mpPane
;
414 int boxOfs
, grooveOfs
, pos
;
416 GetHintsLayout( rect
, *event
.mpBar
, boxOfs
, grooveOfs
, pos
);
418 DoDrawHint( *event
.mpDc
, rect
, pos
, boxOfs
, grooveOfs
, event
.mpBar
->IsFixed() );
420 // let other plugins add on their decorations
425 void cbBarHintsPlugin::OnLeftDown( cbLeftDownEvent
& event
)
427 mpPane
= event
.mpPane
;
429 wxPoint inFrame
= event
.mPos
;
430 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
432 wxBarIterator
iter( mpPane
->GetRowList() );
436 while ( iter
.Next() )
438 cbBarInfo
& bar
= iter
.BarInfo();
440 int boxOfs
, grooveOfs
, pos
;
442 GetHintsLayout( bar
.mBoundsInParent
, bar
, boxOfs
, grooveOfs
, pos
);
444 if ( !bar
.IsFixed() )
446 for( int i
= 0; i
!= BOXES_IN_HINT
; ++i
)
448 mBoxes
[i
]->OnLeftDown( inFrame
);
450 if ( mBoxes
[i
]->mPressed
)
455 return; // event handled
463 void cbBarHintsPlugin::OnLeftUp( cbLeftUpEvent
& event
)
467 wxPoint inFrame
= event
.mPos
;
468 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
470 int boxOfs
, grooveOfs
, pos
;
472 GetHintsLayout( mpClickedBar
->mBoundsInParent
, *mpClickedBar
, boxOfs
, grooveOfs
, pos
);
474 int result
= HitTestHints( *mpClickedBar
, event
.mPos
);
476 for( int i
= 0; i
!= BOXES_IN_HINT
; ++i
)
478 mBoxes
[i
]->OnLeftUp( inFrame
);
480 if ( mBoxes
[i
]->WasClicked() )
484 mpLayout
->SetBarState( mpClickedBar
, wxCBAR_HIDDEN
, TRUE
);
487 if ( mpClickedBar
->IsExpanded() )
489 mpPane
->ContractBar( mpClickedBar
);
491 mpPane
->ExpandBar( mpClickedBar
);
503 void cbBarHintsPlugin::OnMotion( cbMotionEvent
& event
)
507 wxPoint inFrame
= event
.mPos
;
508 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
510 mpPane
= event
.mpPane
;
512 for( int i
= 0; i
!= BOXES_IN_HINT
; ++i
)
514 mBoxes
[i
]->OnMotion( inFrame
);
520 void cbBarHintsPlugin::OnInitPlugin()
522 cbPluginBase::OnInitPlugin();
524 cbDockPane
** panes
= mpLayout
->GetPanesArray();
526 for( int i
= 0; i
!= MAX_PANES
; ++i
)
528 if ( panes
[i
]->MatchesMask( mPaneMask
) )
530 panes
[i
]->mProps
.mMinCBarDim
.x
= 25;
531 panes
[i
]->mProps
.mMinCBarDim
.y
= 16;