]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/fl/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 "barhintspl.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
28 #include "wx/fl/barhintspl.h"
32 #define GROOVE_WIDTH 3 // left shade + middle line + right shade
33 #define GROOVE_TO_GROOVE_GAP 1
34 #define BOX_T_BOX_GAP 2
35 #define BOX_TO_GROOVE_GAP 3
37 #define BOXES_IN_HINT 2
38 #define CLOSE_BOX_IDX 0
39 #define COLLAPSE_BOX_IDX 1
43 #define CLOSE_BOX_HITTED 1
44 #define COLLAPSE_BOX_HITTED 2
46 /***** Implementation fro class cbBarHintsPlugin *****/
48 IMPLEMENT_DYNAMIC_CLASS( cbBarHintsPlugin
, cbPluginBase
)
50 BEGIN_EVENT_TABLE( cbBarHintsPlugin
, cbPluginBase
)
52 EVT_PL_SIZE_BAR_WND ( cbBarHintsPlugin::OnSizeBarWindow
)
53 EVT_PL_DRAW_BAR_DECOR( cbBarHintsPlugin::OnDrawBarDecorations
)
55 EVT_PL_LEFT_DOWN( cbBarHintsPlugin::OnLeftDown
)
56 EVT_PL_LEFT_UP ( cbBarHintsPlugin::OnLeftUp
)
57 EVT_PL_MOTION ( cbBarHintsPlugin::OnMotion
)
61 cbBarHintsPlugin::cbBarHintsPlugin(void)
64 mBtnPressed ( FALSE
),
66 mCollapseBoxOn( TRUE
),
71 mBoxes
[CLOSE_BOX_IDX
] = NULL
;
72 mBoxes
[COLLAPSE_BOX_IDX
] = NULL
;
75 cbBarHintsPlugin::cbBarHintsPlugin( wxFrameLayout
* pLayout
, int paneMask
)
77 : cbPluginBase( pLayout
, paneMask
),
79 mBtnPressed ( FALSE
),
81 mCollapseBoxOn( TRUE
),
86 mBoxes
[CLOSE_BOX_IDX
] = NULL
;
87 mBoxes
[COLLAPSE_BOX_IDX
] = NULL
;
91 cbBarHintsPlugin::~cbBarHintsPlugin()
93 if (mBoxes
[CLOSE_BOX_IDX
])
94 delete mBoxes
[CLOSE_BOX_IDX
];
96 if (mBoxes
[COLLAPSE_BOX_IDX
])
97 delete mBoxes
[COLLAPSE_BOX_IDX
];
98 } // cbBarHintsPlugin destructor
101 void cbBarHintsPlugin::SetGrooveCount( int nGrooves
)
103 mGrooveCount
= nGrooves
;
106 void cbBarHintsPlugin::CreateBoxes()
108 cbCloseBox
* box1
= new cbCloseBox();
109 cbCollapseBox
* box2
= new cbCollapseBox();
111 mBoxes
[CLOSE_BOX_IDX
] = box1
;
112 mBoxes
[COLLAPSE_BOX_IDX
] = box2
;
115 for( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
117 mBoxes
[i
]->mpLayout
= mpLayout
;
118 mBoxes
[i
]->mpPlugin
= this;
119 mBoxes
[i
]->mpWnd
= NULL
;
124 void cbBarHintsPlugin::Draw3DBox( wxDC
& dc
, const wxPoint
& pos
, bool pressed
)
128 void cbBarHintsPlugin::DrawCloseBox( wxDC
& dc
, const wxPoint
& pos
, bool pressed
)
132 void cbBarHintsPlugin::DrawCollapseBox( wxDC
& dc
, const wxPoint
& pos
,
133 bool atLeft
, bool disabled
, bool pressed
)
137 void cbBarHintsPlugin::DrawGrooves( wxDC
& dc
, const wxPoint
& pos
, int length
)
142 for( i
= 0; i
!= mGrooveCount
; ++i
, ofs
+= ( GROOVE_WIDTH
+ GROOVE_TO_GROOVE_GAP
) )
144 if ( mpPane
->IsHorizontal() )
146 dc
.SetPen( mpLayout
->mLightPen
);
147 dc
.DrawLine( pos
.x
+ ofs
, pos
.y
, pos
.x
+ ofs
, pos
.y
+ length
- 1 );
148 dc
.DrawPoint( pos
.x
+ ofs
+ 1, pos
.y
);
150 dc
.SetPen( mpLayout
->mDarkPen
);
151 dc
.DrawLine( pos
.x
+ ofs
+ 2, pos
.y
, pos
.x
+ ofs
+ 2, pos
.y
+ length
);
152 dc
.DrawPoint( pos
.x
+ ofs
+ 1, pos
.y
+ length
- 1 );
153 dc
.DrawPoint( pos
.x
+ ofs
, pos
.y
+ length
- 1 );
157 dc
.SetPen( mpLayout
->mLightPen
);
158 dc
.DrawLine( pos
.x
, pos
.y
+ ofs
, pos
.x
+ length
- 1, pos
.y
+ ofs
);
159 dc
.DrawPoint( pos
.x
, pos
.y
+ ofs
+ 1 );
161 dc
.SetPen( mpLayout
->mDarkPen
);
162 dc
.DrawLine( pos
.x
, pos
.y
+ ofs
+ 2, pos
.x
+ length
, pos
.y
+ ofs
+ 2 );
163 dc
.DrawPoint( pos
.x
+ length
- 1, pos
.y
+ ofs
+ 1 );
164 dc
.DrawPoint( pos
.x
+ length
- 1, pos
.y
+ ofs
);
168 void cbBarHintsPlugin::ExcludeHints( wxRect
& rect
, cbBarInfo
& info
)
170 int boxHeight
= BTN_BOX_HEIGHT
;
172 // collapse and close box are not placed on fixed bars
174 if ( info
.IsFixed() || ( !mCloseBoxOn
&& !mCollapseBoxOn
) )
178 int height
= wxMax( mGrooveCount
*(GROOVE_WIDTH
+ GROOVE_TO_GROOVE_GAP
)
179 - GROOVE_TO_GROOVE_GAP
,
183 if ( mpPane
->IsHorizontal() )
185 rect
.x
+= ( mHintGap
*2 + height
);
186 rect
.width
-= (height
+ 2*mHintGap
);
188 rect
.x
-= info
.mDimInfo
.mHorizGap
+ 2;
189 rect
.width
+= info
.mDimInfo
.mHorizGap
+ 2;
193 rect
.y
+= (mHintGap
*2 + height
);
194 rect
.height
-= (height
+ 2*mHintGap
);
196 rect
.y
-= info
.mDimInfo
.mVertGap
+ 2;
197 rect
.height
+= info
.mDimInfo
.mVertGap
+ 2;
201 void cbBarHintsPlugin::DoDrawHint( wxDC
& dc
, wxRect
& rect
,
202 int pos
, int boxOfs
, int grooveOfs
,
207 if ( mpPane
->IsHorizontal() )
211 mBoxes
[CLOSE_BOX_IDX
]->Draw( dc
);
213 if ( mCollapseBoxOn
)
215 mBoxes
[COLLAPSE_BOX_IDX
]->Draw( dc
);
221 mBoxes
[CLOSE_BOX_IDX
]->Draw( dc
);
223 if ( mCollapseBoxOn
)
225 mBoxes
[COLLAPSE_BOX_IDX
]->Draw( dc
);
229 if ( mpPane
->IsHorizontal() )
231 DrawGrooves( dc
, wxPoint( rect
.x
+ mHintGap
+ grooveOfs
, pos
),
232 rect
.height
- (pos
- rect
.y
) - mHintGap
);
234 DrawGrooves( dc
, wxPoint( rect
.x
+ mHintGap
, rect
.y
+ mHintGap
+ grooveOfs
),
235 (pos
- rect
.x
) - mHintGap
);
238 void cbBarHintsPlugin::GetHintsLayout( wxRect
& rect
, cbBarInfo
& info
,
239 int& boxOfs
, int& grooveOfs
, int& pos
)
241 int boxHeight
= BTN_BOX_HEIGHT
;
242 int boxWidth
= BTN_BOX_WIDTH
+ BOX_TO_GROOVE_GAP
+ BTN_BOX_WIDTH
;
244 // collapse and close box are not placed on fixed bars
246 if ( info
.IsFixed() || ( !mCloseBoxOn
&& !mCollapseBoxOn
) )
252 if ( !mCloseBoxOn
|| !mCollapseBoxOn
)
254 boxWidth
= BTN_BOX_WIDTH
;
256 int grooveHeight
= mGrooveCount
*(GROOVE_WIDTH
+ GROOVE_TO_GROOVE_GAP
)
257 - GROOVE_TO_GROOVE_GAP
;
259 int height
= wxMax( grooveHeight
, boxHeight
);
261 // center boxs and groves with respect to each other
263 boxOfs
= ( height
- boxHeight
) / 2;
264 grooveOfs
= ( height
- grooveHeight
) / 2;
266 pos
= ( mpPane
->IsHorizontal() ) ? rect
.y
+ mHintGap
267 : rect
.x
+ rect
.width
- mHintGap
;
269 // setup positions for boxes
271 if ( !info
.IsFixed() )
273 // what direction "collapse-triangle" should look at?
275 bool& isAtLeft
= ((cbCollapseBox
*)(mBoxes
[COLLAPSE_BOX_IDX
]))->mIsAtLeft
;
277 isAtLeft
= info
.mBounds
.x
<= mpPane
->mPaneWidth
- ( info
.mBounds
.x
+ info
.mBounds
.width
);
279 if ( info
.IsExpanded() )
283 cbBarInfo
* pCur
= info
.mpPrev
;
287 if ( !pCur
->IsFixed() )
289 isAtLeft
= TRUE
; break;
296 // collapse/expand works only when more not-fixed bars are present in the same row
298 mBoxes
[COLLAPSE_BOX_IDX
]->Enable( info
.mpRow
->mNotFixedBarsCnt
> 1 );
301 for( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
303 mBoxes
[i
]->mpPane
= mpPane
;
306 if ( mpPane
->IsHorizontal() )
310 mBoxes
[CLOSE_BOX_IDX
]->mPos
= wxPoint( rect
.x
+ mHintGap
+ boxOfs
, pos
);
312 pos
+= BTN_BOX_HEIGHT
;
315 if ( mCollapseBoxOn
)
317 if ( mCloseBoxOn
) pos
+= BOX_T_BOX_GAP
;
319 mBoxes
[COLLAPSE_BOX_IDX
]->mPos
= wxPoint( rect
.x
+ mHintGap
+ boxOfs
, pos
);
321 pos
+= BTN_BOX_HEIGHT
;
323 pos
+= BOX_TO_GROOVE_GAP
;
330 pos
-= BTN_BOX_WIDTH
;
332 mBoxes
[CLOSE_BOX_IDX
]->mPos
= wxPoint( pos
, rect
.y
+ mHintGap
+ boxOfs
);
335 if ( mCollapseBoxOn
)
337 if ( mCloseBoxOn
) pos
-= BOX_T_BOX_GAP
;
339 pos
-= BTN_BOX_WIDTH
;
341 mBoxes
[COLLAPSE_BOX_IDX
]->mPos
= wxPoint( pos
, rect
.y
+ mHintGap
+ boxOfs
);
343 pos
-= BOX_TO_GROOVE_GAP
;
349 static inline bool is_in_box( const wxPoint
& rectPos
, const wxPoint
& mousePos
)
351 return ( mousePos
.x
>= rectPos
.x
&&
352 mousePos
.y
>= rectPos
.y
&&
353 mousePos
.x
< rectPos
.x
+ BTN_BOX_WIDTH
&&
354 mousePos
.y
< rectPos
.y
+ BTN_BOX_HEIGHT
);
357 int cbBarHintsPlugin::HitTestHints( cbBarInfo
& info
, const wxPoint
& pos
)
359 wxPoint inPane
= pos
;
360 mpPane
->PaneToFrame( &inPane
.x
, &inPane
.y
);
362 wxRect
& rect
= info
.mBoundsInParent
;
364 if ( info
.IsFixed() ) return FALSE
;
366 int boxOfs
, grooveOfs
, coord
;
368 GetHintsLayout( rect
, info
, boxOfs
, grooveOfs
, coord
);
370 if ( mpPane
->IsHorizontal() )
374 if ( is_in_box( wxPoint( rect
.x
+ mHintGap
+ boxOfs
, coord
), inPane
) )
376 return CLOSE_BOX_HITTED
;
378 coord
+= BTN_BOX_HEIGHT
;
381 if ( mCollapseBoxOn
)
383 if ( mCloseBoxOn
) coord
+= BOX_T_BOX_GAP
;
385 if ( is_in_box( wxPoint( rect
.x
+ mHintGap
+ boxOfs
, coord
), inPane
) )
387 return COLLAPSE_BOX_HITTED
;
389 coord
+= BTN_BOX_HEIGHT
;
396 coord
-= BTN_BOX_WIDTH
;
398 if ( is_in_box( wxPoint( coord
, rect
.y
+ mHintGap
+ boxOfs
), inPane
) )
400 return CLOSE_BOX_HITTED
;
403 if ( mCollapseBoxOn
)
405 if ( mCloseBoxOn
) coord
-= BOX_T_BOX_GAP
;
406 coord
-= BTN_BOX_WIDTH
;
408 if ( is_in_box( wxPoint( coord
, rect
.y
+ mHintGap
+ boxOfs
), inPane
) )
410 return COLLAPSE_BOX_HITTED
;
417 // handlers for plugin-events
419 void cbBarHintsPlugin::OnSizeBarWindow( cbSizeBarWndEvent
& event
)
421 wxRect
& rect
= event
.mBoundsInParent
;
422 mpPane
= event
.mpPane
;
424 ExcludeHints( rect
, *event
.mpBar
);
426 event
.Skip(); // pass event to the next plugin in the chain
429 void cbBarHintsPlugin::OnDrawBarDecorations( cbDrawBarDecorEvent
& event
)
431 wxRect
& rect
= event
.mBoundsInParent
;
432 mpPane
= event
.mpPane
;
434 int boxOfs
, grooveOfs
, pos
;
436 GetHintsLayout( rect
, *event
.mpBar
, boxOfs
, grooveOfs
, pos
);
438 DoDrawHint( *event
.mpDc
, rect
, pos
, boxOfs
, grooveOfs
, event
.mpBar
->IsFixed() );
440 // let other plugins add on their decorations
445 void cbBarHintsPlugin::OnLeftDown( cbLeftDownEvent
& event
)
447 mpPane
= event
.mpPane
;
449 wxPoint inFrame
= event
.mPos
;
450 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
452 wxBarIterator
iter( mpPane
->GetRowList() );
456 while ( iter
.Next() )
458 cbBarInfo
& bar
= iter
.BarInfo();
460 int boxOfs
, grooveOfs
, pos
;
462 GetHintsLayout( bar
.mBoundsInParent
, bar
, boxOfs
, grooveOfs
, pos
);
464 if ( !bar
.IsFixed() )
467 for( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
469 mBoxes
[i
]->OnLeftDown( inFrame
);
471 if ( mBoxes
[i
]->mPressed
)
476 return; // event handled
485 void cbBarHintsPlugin::OnLeftUp( cbLeftUpEvent
& event
)
489 wxPoint inFrame
= event
.mPos
;
490 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
492 int boxOfs
, grooveOfs
, pos
;
494 GetHintsLayout( mpClickedBar
->mBoundsInParent
, *mpClickedBar
, boxOfs
, grooveOfs
, pos
);
496 int result
= HitTestHints( *mpClickedBar
, event
.mPos
);
499 for( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
501 mBoxes
[i
]->OnLeftUp( inFrame
);
503 if ( mBoxes
[i
]->WasClicked() )
507 mpLayout
->SetBarState( mpClickedBar
, wxCBAR_HIDDEN
, TRUE
);
510 if ( mpClickedBar
->IsExpanded() )
512 mpPane
->ContractBar( mpClickedBar
);
514 mpPane
->ExpandBar( mpClickedBar
);
526 void cbBarHintsPlugin::OnMotion( cbMotionEvent
& event
)
530 wxPoint inFrame
= event
.mPos
;
531 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
533 mpPane
= event
.mpPane
;
536 for( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
538 mBoxes
[i
]->OnMotion( inFrame
);
544 void cbBarHintsPlugin::OnInitPlugin()
546 cbPluginBase::OnInitPlugin();
548 cbDockPane
** panes
= mpLayout
->GetPanesArray();
551 for( i
= 0; i
!= MAX_PANES
; ++i
)
553 if ( panes
[i
]->MatchesMask( mPaneMask
) )
555 panes
[i
]->mProps
.mMinCBarDim
.x
= 25;
556 panes
[i
]->mProps
.mMinCBarDim
.y
= 16;