]>
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
);
169 void cbBarHintsPlugin::ExcludeHints( wxRect
& rect
, cbBarInfo
& info
)
171 int boxHeight
= BTN_BOX_HEIGHT
;
173 // collapse and close box are not placed on fixed bars
175 if ( info
.IsFixed() || ( !mCloseBoxOn
&& !mCollapseBoxOn
) )
179 int height
= wxMax( mGrooveCount
*(GROOVE_WIDTH
+ GROOVE_TO_GROOVE_GAP
)
180 - GROOVE_TO_GROOVE_GAP
,
184 if ( mpPane
->IsHorizontal() )
186 rect
.x
+= ( mHintGap
*2 + height
);
187 rect
.width
-= (height
+ 2*mHintGap
);
189 rect
.x
-= info
.mDimInfo
.mHorizGap
+ 2;
190 rect
.width
+= info
.mDimInfo
.mHorizGap
+ 2;
194 rect
.y
+= (mHintGap
*2 + height
);
195 rect
.height
-= (height
+ 2*mHintGap
);
197 rect
.y
-= info
.mDimInfo
.mVertGap
+ 2;
198 rect
.height
+= info
.mDimInfo
.mVertGap
+ 2;
202 void cbBarHintsPlugin::DoDrawHint( wxDC
& dc
, wxRect
& rect
,
203 int pos
, int boxOfs
, int grooveOfs
,
208 if ( mpPane
->IsHorizontal() )
212 mBoxes
[CLOSE_BOX_IDX
]->Draw( dc
);
214 if ( mCollapseBoxOn
)
216 mBoxes
[COLLAPSE_BOX_IDX
]->Draw( dc
);
222 mBoxes
[CLOSE_BOX_IDX
]->Draw( dc
);
224 if ( mCollapseBoxOn
)
226 mBoxes
[COLLAPSE_BOX_IDX
]->Draw( dc
);
230 if ( mpPane
->IsHorizontal() )
232 DrawGrooves( dc
, wxPoint( rect
.x
+ mHintGap
+ grooveOfs
, pos
),
233 rect
.height
- (pos
- rect
.y
) - mHintGap
);
235 DrawGrooves( dc
, wxPoint( rect
.x
+ mHintGap
, rect
.y
+ mHintGap
+ grooveOfs
),
236 (pos
- rect
.x
) - mHintGap
);
239 void cbBarHintsPlugin::GetHintsLayout( wxRect
& rect
, cbBarInfo
& info
,
240 int& boxOfs
, int& grooveOfs
, int& pos
)
242 int boxHeight
= BTN_BOX_HEIGHT
;
243 // int boxWidth = BTN_BOX_WIDTH + BOX_TO_GROOVE_GAP + BTN_BOX_WIDTH;
245 // collapse and close box are not placed on fixed bars
247 if ( info
.IsFixed() || ( !mCloseBoxOn
&& !mCollapseBoxOn
) )
254 if ( !mCloseBoxOn || !mCollapseBoxOn )
256 boxWidth = BTN_BOX_WIDTH;
258 int grooveHeight
= mGrooveCount
*(GROOVE_WIDTH
+ GROOVE_TO_GROOVE_GAP
)
259 - GROOVE_TO_GROOVE_GAP
;
261 int height
= wxMax( grooveHeight
, boxHeight
);
263 // center boxs and groves with respect to each other
265 boxOfs
= ( height
- boxHeight
) / 2;
266 grooveOfs
= ( height
- grooveHeight
) / 2;
268 pos
= ( mpPane
->IsHorizontal() ) ? rect
.y
+ mHintGap
269 : rect
.x
+ rect
.width
- mHintGap
;
271 // setup positions for boxes
273 if ( !info
.IsFixed() )
275 // what direction "collapse-triangle" should look at?
277 bool& isAtLeft
= ((cbCollapseBox
*)(mBoxes
[COLLAPSE_BOX_IDX
]))->mIsAtLeft
;
279 isAtLeft
= info
.mBounds
.x
<= mpPane
->mPaneWidth
- ( info
.mBounds
.x
+ info
.mBounds
.width
);
281 if ( info
.IsExpanded() )
285 cbBarInfo
* pCur
= info
.mpPrev
;
289 if ( !pCur
->IsFixed() )
291 isAtLeft
= TRUE
; break;
298 // collapse/expand works only when more not-fixed bars are present in the same row
300 mBoxes
[COLLAPSE_BOX_IDX
]->Enable( info
.mpRow
->mNotFixedBarsCnt
> 1 );
303 for ( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
305 mBoxes
[i
]->mpPane
= mpPane
;
308 if ( mpPane
->IsHorizontal() )
312 mBoxes
[CLOSE_BOX_IDX
]->mPos
= wxPoint( rect
.x
+ mHintGap
+ boxOfs
, pos
);
314 pos
+= BTN_BOX_HEIGHT
;
317 if ( mCollapseBoxOn
)
319 if ( mCloseBoxOn
) pos
+= BOX_T_BOX_GAP
;
321 mBoxes
[COLLAPSE_BOX_IDX
]->mPos
= wxPoint( rect
.x
+ mHintGap
+ boxOfs
, pos
);
323 pos
+= BTN_BOX_HEIGHT
;
325 pos
+= BOX_TO_GROOVE_GAP
;
332 pos
-= BTN_BOX_WIDTH
;
334 mBoxes
[CLOSE_BOX_IDX
]->mPos
= wxPoint( pos
, rect
.y
+ mHintGap
+ boxOfs
);
337 if ( mCollapseBoxOn
)
339 if ( mCloseBoxOn
) pos
-= BOX_T_BOX_GAP
;
341 pos
-= BTN_BOX_WIDTH
;
343 mBoxes
[COLLAPSE_BOX_IDX
]->mPos
= wxPoint( pos
, rect
.y
+ mHintGap
+ boxOfs
);
345 pos
-= BOX_TO_GROOVE_GAP
;
351 static inline bool is_in_box( const wxPoint
& rectPos
, const wxPoint
& mousePos
)
353 return ( mousePos
.x
>= rectPos
.x
&&
354 mousePos
.y
>= rectPos
.y
&&
355 mousePos
.x
< rectPos
.x
+ BTN_BOX_WIDTH
&&
356 mousePos
.y
< rectPos
.y
+ BTN_BOX_HEIGHT
);
359 int cbBarHintsPlugin::HitTestHints( cbBarInfo
& info
, const wxPoint
& pos
)
361 wxPoint inPane
= pos
;
362 mpPane
->PaneToFrame( &inPane
.x
, &inPane
.y
);
364 wxRect
& rect
= info
.mBoundsInParent
;
366 if ( info
.IsFixed() ) return FALSE
;
368 int boxOfs
, grooveOfs
, coord
;
370 GetHintsLayout( rect
, info
, boxOfs
, grooveOfs
, coord
);
372 if ( mpPane
->IsHorizontal() )
376 if ( is_in_box( wxPoint( rect
.x
+ mHintGap
+ boxOfs
, coord
), inPane
) )
378 return CLOSE_BOX_HITTED
;
380 coord
+= BTN_BOX_HEIGHT
;
383 if ( mCollapseBoxOn
)
385 if ( mCloseBoxOn
) coord
+= BOX_T_BOX_GAP
;
387 if ( is_in_box( wxPoint( rect
.x
+ mHintGap
+ boxOfs
, coord
), inPane
) )
389 return COLLAPSE_BOX_HITTED
;
391 coord
+= BTN_BOX_HEIGHT
;
398 coord
-= BTN_BOX_WIDTH
;
400 if ( is_in_box( wxPoint( coord
, rect
.y
+ mHintGap
+ boxOfs
), inPane
) )
402 return CLOSE_BOX_HITTED
;
405 if ( mCollapseBoxOn
)
407 if ( mCloseBoxOn
) coord
-= BOX_T_BOX_GAP
;
408 coord
-= BTN_BOX_WIDTH
;
410 if ( is_in_box( wxPoint( coord
, rect
.y
+ mHintGap
+ boxOfs
), inPane
) )
412 return COLLAPSE_BOX_HITTED
;
419 // handlers for plugin-events
421 void cbBarHintsPlugin::OnSizeBarWindow( cbSizeBarWndEvent
& event
)
423 wxRect
& rect
= event
.mBoundsInParent
;
424 mpPane
= event
.mpPane
;
426 ExcludeHints( rect
, *event
.mpBar
);
428 event
.Skip(); // pass event to the next plugin in the chain
431 void cbBarHintsPlugin::OnDrawBarDecorations( cbDrawBarDecorEvent
& event
)
433 wxRect
& rect
= event
.mBoundsInParent
;
434 mpPane
= event
.mpPane
;
436 int boxOfs
, grooveOfs
, pos
;
438 GetHintsLayout( rect
, *event
.mpBar
, boxOfs
, grooveOfs
, pos
);
440 DoDrawHint( *event
.mpDc
, rect
, pos
, boxOfs
, grooveOfs
, event
.mpBar
->IsFixed() );
442 // let other plugins add on their decorations
447 void cbBarHintsPlugin::OnLeftDown( cbLeftDownEvent
& event
)
449 mpPane
= event
.mpPane
;
450 wxPoint inFrame
= event
.mPos
;
452 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
454 wxBarIterator
iter( mpPane
->GetRowList() );
458 while ( iter
.Next() )
460 cbBarInfo
& bar
= iter
.BarInfo();
462 int boxOfs
, grooveOfs
, pos
;
464 GetHintsLayout( bar
.mBoundsInParent
, bar
, boxOfs
, grooveOfs
, pos
);
466 if ( !bar
.IsFixed() )
469 for ( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
471 mBoxes
[i
]->OnLeftDown( inFrame
);
473 if ( mBoxes
[i
]->mPressed
)
478 return; // event handled
487 void cbBarHintsPlugin::OnLeftUp( cbLeftUpEvent
& event
)
491 wxPoint inFrame
= event
.mPos
;
492 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
494 int boxOfs
, grooveOfs
, pos
;
496 GetHintsLayout( mpClickedBar
->mBoundsInParent
, *mpClickedBar
, boxOfs
, grooveOfs
, pos
);
498 int result
= HitTestHints( *mpClickedBar
, event
.mPos
);
501 for ( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
503 mBoxes
[i
]->OnLeftUp( inFrame
);
505 if ( mBoxes
[i
]->WasClicked() )
509 mpLayout
->SetBarState( mpClickedBar
, wxCBAR_HIDDEN
, TRUE
);
513 if ( mpClickedBar
->IsExpanded() )
514 mpPane
->ContractBar( mpClickedBar
);
516 mpPane
->ExpandBar( mpClickedBar
);
528 void cbBarHintsPlugin::OnMotion( cbMotionEvent
& event
)
532 wxPoint inFrame
= event
.mPos
;
533 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
535 mpPane
= event
.mpPane
;
538 for ( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
540 mBoxes
[i
]->OnMotion( inFrame
);
547 void cbBarHintsPlugin::OnInitPlugin()
549 cbPluginBase::OnInitPlugin();
551 cbDockPane
** panes
= mpLayout
->GetPanesArray();
554 for ( i
= 0; i
!= MAX_PANES
; ++i
)
556 if ( panes
[i
]->MatchesMask( mPaneMask
) )
558 panes
[i
]->mProps
.mMinCBarDim
.x
= 25;
559 panes
[i
]->mProps
.mMinCBarDim
.y
= 16;