]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/fl/barhintspl.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Implementation for cbBarHintsPlugin
4 // Author: Aleksandras Gluchovas
6 // Created: 30/11/98 (my 22th birthday :-)
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
24 #include "wx/fl/barhintspl.h"
28 #define GROOVE_WIDTH 3 // left shade + middle line + right shade
29 #define GROOVE_TO_GROOVE_GAP 1
30 #define BOX_T_BOX_GAP 2
31 #define BOX_TO_GROOVE_GAP 3
33 #define BOXES_IN_HINT 2
34 #define CLOSE_BOX_IDX 0
35 #define COLLAPSE_BOX_IDX 1
39 #define CLOSE_BOX_HITTED 1
40 #define COLLAPSE_BOX_HITTED 2
42 /***** Implementation fro class cbBarHintsPlugin *****/
44 IMPLEMENT_DYNAMIC_CLASS( cbBarHintsPlugin
, cbPluginBase
)
46 BEGIN_EVENT_TABLE( cbBarHintsPlugin
, cbPluginBase
)
48 EVT_PL_SIZE_BAR_WND ( cbBarHintsPlugin::OnSizeBarWindow
)
49 EVT_PL_DRAW_BAR_DECOR( cbBarHintsPlugin::OnDrawBarDecorations
)
51 EVT_PL_LEFT_DOWN( cbBarHintsPlugin::OnLeftDown
)
52 EVT_PL_LEFT_UP ( cbBarHintsPlugin::OnLeftUp
)
53 EVT_PL_MOTION ( cbBarHintsPlugin::OnMotion
)
57 cbBarHintsPlugin::cbBarHintsPlugin(void)
60 mBtnPressed ( false ),
62 mCollapseBoxOn( true ),
67 mBoxes
[CLOSE_BOX_IDX
] = NULL
;
68 mBoxes
[COLLAPSE_BOX_IDX
] = NULL
;
71 cbBarHintsPlugin::cbBarHintsPlugin( wxFrameLayout
* pLayout
, int paneMask
)
73 : cbPluginBase( pLayout
, paneMask
),
75 mBtnPressed ( false ),
77 mCollapseBoxOn( true ),
82 mBoxes
[CLOSE_BOX_IDX
] = NULL
;
83 mBoxes
[COLLAPSE_BOX_IDX
] = NULL
;
87 cbBarHintsPlugin::~cbBarHintsPlugin()
89 if (mBoxes
[CLOSE_BOX_IDX
])
90 delete mBoxes
[CLOSE_BOX_IDX
];
92 if (mBoxes
[COLLAPSE_BOX_IDX
])
93 delete mBoxes
[COLLAPSE_BOX_IDX
];
94 } // cbBarHintsPlugin destructor
97 void cbBarHintsPlugin::SetGrooveCount( int nGrooves
)
99 mGrooveCount
= nGrooves
;
102 void cbBarHintsPlugin::CreateBoxes()
104 cbCloseBox
* box1
= new cbCloseBox();
105 cbCollapseBox
* box2
= new cbCollapseBox();
107 mBoxes
[CLOSE_BOX_IDX
] = box1
;
108 mBoxes
[COLLAPSE_BOX_IDX
] = box2
;
111 for ( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
113 mBoxes
[i
]->mpLayout
= mpLayout
;
114 mBoxes
[i
]->mpPlugin
= this;
115 mBoxes
[i
]->mpWnd
= NULL
;
120 void cbBarHintsPlugin::Draw3DBox( wxDC
& WXUNUSED(dc
), const wxPoint
& WXUNUSED(pos
), bool WXUNUSED(pressed
) )
124 void cbBarHintsPlugin::DrawCloseBox( wxDC
& WXUNUSED(dc
), const wxPoint
& WXUNUSED(pos
), bool WXUNUSED(pressed
) )
128 void cbBarHintsPlugin::DrawCollapseBox( wxDC
& WXUNUSED(dc
), const wxPoint
& WXUNUSED(pos
),
129 bool WXUNUSED(atLeft
), bool WXUNUSED(disabled
), bool WXUNUSED(pressed
) )
133 void cbBarHintsPlugin::DrawGrooves( wxDC
& dc
, const wxPoint
& pos
, int length
)
138 for ( i
= 0; i
!= mGrooveCount
; ++i
, ofs
+= ( GROOVE_WIDTH
+ GROOVE_TO_GROOVE_GAP
) )
140 if ( mpPane
->IsHorizontal() )
142 dc
.SetPen( mpLayout
->mLightPen
);
143 dc
.DrawLine( pos
.x
+ ofs
, pos
.y
, pos
.x
+ ofs
, pos
.y
+ length
- 1 );
144 dc
.DrawPoint( pos
.x
+ ofs
+ 1, pos
.y
);
146 dc
.SetPen( mpLayout
->mDarkPen
);
147 dc
.DrawLine( pos
.x
+ ofs
+ 2, pos
.y
, pos
.x
+ ofs
+ 2, pos
.y
+ length
);
148 dc
.DrawPoint( pos
.x
+ ofs
+ 1, pos
.y
+ length
- 1 );
149 dc
.DrawPoint( pos
.x
+ ofs
, pos
.y
+ length
- 1 );
153 dc
.SetPen( mpLayout
->mLightPen
);
154 dc
.DrawLine( pos
.x
, pos
.y
+ ofs
, pos
.x
+ length
- 1, pos
.y
+ ofs
);
155 dc
.DrawPoint( pos
.x
, pos
.y
+ ofs
+ 1 );
157 dc
.SetPen( mpLayout
->mDarkPen
);
158 dc
.DrawLine( pos
.x
, pos
.y
+ ofs
+ 2, pos
.x
+ length
, pos
.y
+ ofs
+ 2 );
159 dc
.DrawPoint( pos
.x
+ length
- 1, pos
.y
+ ofs
+ 1 );
160 dc
.DrawPoint( pos
.x
+ length
- 1, pos
.y
+ ofs
);
165 void cbBarHintsPlugin::ExcludeHints( wxRect
& rect
, cbBarInfo
& info
)
167 int boxHeight
= BTN_BOX_HEIGHT
;
169 // collapse and close box are not placed on fixed bars
171 if ( info
.IsFixed() || ( !mCloseBoxOn
&& !mCollapseBoxOn
) )
175 int height
= wxMax( mGrooveCount
*(GROOVE_WIDTH
+ GROOVE_TO_GROOVE_GAP
)
176 - GROOVE_TO_GROOVE_GAP
,
180 if ( mpPane
->IsHorizontal() )
182 rect
.x
+= ( mHintGap
*2 + height
);
183 rect
.width
-= (height
+ 2*mHintGap
);
185 rect
.x
-= info
.mDimInfo
.mHorizGap
+ 2;
186 rect
.width
+= info
.mDimInfo
.mHorizGap
+ 2;
190 rect
.y
+= (mHintGap
*2 + height
);
191 rect
.height
-= (height
+ 2*mHintGap
);
193 rect
.y
-= info
.mDimInfo
.mVertGap
+ 2;
194 rect
.height
+= info
.mDimInfo
.mVertGap
+ 2;
198 void cbBarHintsPlugin::DoDrawHint( wxDC
& dc
, wxRect
& rect
,
199 int pos
, int WXUNUSED(boxOfs
), int grooveOfs
,
204 if ( mpPane
->IsHorizontal() )
208 mBoxes
[CLOSE_BOX_IDX
]->Draw( dc
);
210 if ( mCollapseBoxOn
)
212 mBoxes
[COLLAPSE_BOX_IDX
]->Draw( dc
);
218 mBoxes
[CLOSE_BOX_IDX
]->Draw( dc
);
220 if ( mCollapseBoxOn
)
222 mBoxes
[COLLAPSE_BOX_IDX
]->Draw( dc
);
226 if ( mpPane
->IsHorizontal() )
228 DrawGrooves( dc
, wxPoint( rect
.x
+ mHintGap
+ grooveOfs
, pos
),
229 rect
.height
- (pos
- rect
.y
) - mHintGap
);
231 DrawGrooves( dc
, wxPoint( rect
.x
+ mHintGap
, rect
.y
+ mHintGap
+ grooveOfs
),
232 (pos
- rect
.x
) - mHintGap
);
235 void cbBarHintsPlugin::GetHintsLayout( wxRect
& rect
, cbBarInfo
& info
,
236 int& boxOfs
, int& grooveOfs
, int& pos
)
238 int boxHeight
= BTN_BOX_HEIGHT
;
239 // int boxWidth = BTN_BOX_WIDTH + BOX_TO_GROOVE_GAP + BTN_BOX_WIDTH;
241 // collapse and close box are not placed on fixed bars
243 if ( info
.IsFixed() || ( !mCloseBoxOn
&& !mCollapseBoxOn
) )
250 if ( !mCloseBoxOn || !mCollapseBoxOn )
252 boxWidth = BTN_BOX_WIDTH;
254 int grooveHeight
= mGrooveCount
*(GROOVE_WIDTH
+ GROOVE_TO_GROOVE_GAP
)
255 - GROOVE_TO_GROOVE_GAP
;
257 int height
= wxMax( grooveHeight
, boxHeight
);
259 // center boxs and groves with respect to each other
261 boxOfs
= ( height
- boxHeight
) / 2;
262 grooveOfs
= ( height
- grooveHeight
) / 2;
264 pos
= ( mpPane
->IsHorizontal() ) ? rect
.y
+ mHintGap
265 : rect
.x
+ rect
.width
- mHintGap
;
267 // setup positions for boxes
269 if ( !info
.IsFixed() )
271 // what direction "collapse-triangle" should look at?
273 bool& isAtLeft
= ((cbCollapseBox
*)(mBoxes
[COLLAPSE_BOX_IDX
]))->mIsAtLeft
;
275 isAtLeft
= info
.mBounds
.x
<= mpPane
->mPaneWidth
- ( info
.mBounds
.x
+ info
.mBounds
.width
);
277 if ( info
.IsExpanded() )
281 cbBarInfo
* pCur
= info
.mpPrev
;
285 if ( !pCur
->IsFixed() )
287 isAtLeft
= true; break;
294 // collapse/expand works only when more not-fixed bars are present in the same row
296 mBoxes
[COLLAPSE_BOX_IDX
]->Enable( info
.mpRow
->mNotFixedBarsCnt
> 1 );
299 for ( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
301 mBoxes
[i
]->mpPane
= mpPane
;
304 if ( mpPane
->IsHorizontal() )
308 mBoxes
[CLOSE_BOX_IDX
]->mPos
= wxPoint( rect
.x
+ mHintGap
+ boxOfs
, pos
);
310 pos
+= BTN_BOX_HEIGHT
;
313 if ( mCollapseBoxOn
)
315 if ( mCloseBoxOn
) pos
+= BOX_T_BOX_GAP
;
317 mBoxes
[COLLAPSE_BOX_IDX
]->mPos
= wxPoint( rect
.x
+ mHintGap
+ boxOfs
, pos
);
319 pos
+= BTN_BOX_HEIGHT
;
321 pos
+= BOX_TO_GROOVE_GAP
;
328 pos
-= BTN_BOX_WIDTH
;
330 mBoxes
[CLOSE_BOX_IDX
]->mPos
= wxPoint( pos
, rect
.y
+ mHintGap
+ boxOfs
);
333 if ( mCollapseBoxOn
)
335 if ( mCloseBoxOn
) pos
-= BOX_T_BOX_GAP
;
337 pos
-= BTN_BOX_WIDTH
;
339 mBoxes
[COLLAPSE_BOX_IDX
]->mPos
= wxPoint( pos
, rect
.y
+ mHintGap
+ boxOfs
);
341 pos
-= BOX_TO_GROOVE_GAP
;
347 static inline bool is_in_box( const wxPoint
& rectPos
, const wxPoint
& mousePos
)
349 return ( mousePos
.x
>= rectPos
.x
&&
350 mousePos
.y
>= rectPos
.y
&&
351 mousePos
.x
< rectPos
.x
+ BTN_BOX_WIDTH
&&
352 mousePos
.y
< rectPos
.y
+ BTN_BOX_HEIGHT
);
355 int cbBarHintsPlugin::HitTestHints( cbBarInfo
& info
, const wxPoint
& pos
)
357 wxPoint inPane
= pos
;
358 mpPane
->PaneToFrame( &inPane
.x
, &inPane
.y
);
360 wxRect
& rect
= info
.mBoundsInParent
;
362 if ( info
.IsFixed() ) return false;
364 int boxOfs
, grooveOfs
, coord
;
366 GetHintsLayout( rect
, info
, boxOfs
, grooveOfs
, coord
);
368 if ( mpPane
->IsHorizontal() )
372 if ( is_in_box( wxPoint( rect
.x
+ mHintGap
+ boxOfs
, coord
), inPane
) )
374 return CLOSE_BOX_HITTED
;
376 coord
+= BTN_BOX_HEIGHT
;
379 if ( mCollapseBoxOn
)
381 if ( mCloseBoxOn
) coord
+= BOX_T_BOX_GAP
;
383 if ( is_in_box( wxPoint( rect
.x
+ mHintGap
+ boxOfs
, coord
), inPane
) )
385 return COLLAPSE_BOX_HITTED
;
387 coord
+= BTN_BOX_HEIGHT
;
394 coord
-= BTN_BOX_WIDTH
;
396 if ( is_in_box( wxPoint( coord
, rect
.y
+ mHintGap
+ boxOfs
), inPane
) )
398 return CLOSE_BOX_HITTED
;
401 if ( mCollapseBoxOn
)
403 if ( mCloseBoxOn
) coord
-= BOX_T_BOX_GAP
;
404 coord
-= BTN_BOX_WIDTH
;
406 if ( is_in_box( wxPoint( coord
, rect
.y
+ mHintGap
+ boxOfs
), inPane
) )
408 return COLLAPSE_BOX_HITTED
;
415 // handlers for plugin-events
417 void cbBarHintsPlugin::OnSizeBarWindow( cbSizeBarWndEvent
& event
)
419 wxRect
& rect
= event
.mBoundsInParent
;
420 mpPane
= event
.mpPane
;
422 ExcludeHints( rect
, *event
.mpBar
);
424 event
.Skip(); // pass event to the next plugin in the chain
427 void cbBarHintsPlugin::OnDrawBarDecorations( cbDrawBarDecorEvent
& event
)
429 wxRect
& rect
= event
.mBoundsInParent
;
430 mpPane
= event
.mpPane
;
432 int boxOfs
, grooveOfs
, pos
;
434 GetHintsLayout( rect
, *event
.mpBar
, boxOfs
, grooveOfs
, pos
);
436 DoDrawHint( *event
.mpDc
, rect
, pos
, boxOfs
, grooveOfs
, event
.mpBar
->IsFixed() );
438 // let other plugins add on their decorations
443 void cbBarHintsPlugin::OnLeftDown( cbLeftDownEvent
& event
)
445 mpPane
= event
.mpPane
;
446 wxPoint inFrame
= event
.mPos
;
448 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
450 wxBarIterator
iter( mpPane
->GetRowList() );
454 while ( iter
.Next() )
456 cbBarInfo
& bar
= iter
.BarInfo();
458 int boxOfs
, grooveOfs
, pos
;
460 GetHintsLayout( bar
.mBoundsInParent
, bar
, boxOfs
, grooveOfs
, pos
);
462 if ( !bar
.IsFixed() )
465 for ( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
467 mBoxes
[i
]->mPressed
= false;
468 mBoxes
[i
]->mWasClicked
= false;
470 for ( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
472 mBoxes
[i
]->OnLeftDown( inFrame
);
474 if ( mBoxes
[i
]->mPressed
)
479 return; // event handled
488 void cbBarHintsPlugin::OnLeftUp( cbLeftUpEvent
& event
)
492 wxPoint inFrame
= event
.mPos
;
493 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
495 int boxOfs
, grooveOfs
, pos
;
497 GetHintsLayout( mpClickedBar
->mBoundsInParent
, *mpClickedBar
, boxOfs
, grooveOfs
, pos
);
499 HitTestHints( *mpClickedBar
, event
.mPos
);
502 for ( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
504 mBoxes
[i
]->OnLeftUp( inFrame
);
506 if ( mBoxes
[i
]->WasClicked() )
510 mpLayout
->SetBarState( mpClickedBar
, wxCBAR_HIDDEN
, true );
511 // Notify bar child window of close event:
512 if(mpClickedBar
->mpBarWnd
!=NULL
)
513 mpClickedBar
->mpBarWnd
->Close();
517 if ( mpClickedBar
->IsExpanded() )
518 mpPane
->ContractBar( mpClickedBar
);
520 mpPane
->ExpandBar( mpClickedBar
);
532 void cbBarHintsPlugin::OnMotion( cbMotionEvent
& event
)
536 wxPoint inFrame
= event
.mPos
;
537 mpPane
->PaneToFrame( &inFrame
.x
, &inFrame
.y
);
539 mpPane
= event
.mpPane
;
542 for ( i
= 0; i
!= BOXES_IN_HINT
; ++i
)
544 mBoxes
[i
]->OnMotion( inFrame
);
551 void cbBarHintsPlugin::OnInitPlugin()
553 cbPluginBase::OnInitPlugin();
555 cbDockPane
** panes
= mpLayout
->GetPanesArray();
558 for ( i
= 0; i
!= MAX_PANES
; ++i
)
560 if ( panes
[i
]->MatchesMask( mPaneMask
) )
562 panes
[i
]->mProps
.mMinCBarDim
.x
= 25;
563 panes
[i
]->mProps
.mMinCBarDim
.y
= 16;