1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "cbcustom.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
30 // helper class to receive menu customization event
32 class cbContextMenuHandler
: public wxEvtHandler
35 cbSimpleCustomizationPlugin
* mpBackRef
;
38 void OnMenuCommand( wxCommandEvent
& evt
);
40 void OnCommandEvents( wxCommandEvent
& evt
);
42 DECLARE_EVENT_TABLE();
45 // FIXME:: is this "safe" ?
47 #define CB_CUSTOMIZE_MENU_FIRST_ITEM_ID 17500
49 /***** Implementation for helper class cbContextMenuHandler *****/
51 BEGIN_EVENT_TABLE( cbContextMenuHandler
, wxEvtHandler
)
53 // FIXME:: what is the right range for these ids ? so that they
54 // would not collide with user commands?
56 EVT_COMMAND_RANGE( CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
,
57 CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
+ 300,
58 wxEVT_COMMAND_MENU_SELECTED
,
59 cbContextMenuHandler::OnCommandEvents
)
63 void cbContextMenuHandler::OnCommandEvents( wxCommandEvent
& evt
)
65 //wxMessageBox("Wowwwww, Yeah!");
67 mpBackRef
->OnMenuItemSelected( evt
);
70 /***** Implementation for class cbSimpleCustomizationPlugin *****/
72 IMPLEMENT_DYNAMIC_CLASS( cbSimpleCustomizationPlugin
, cbPluginBase
)
74 BEGIN_EVENT_TABLE( cbSimpleCustomizationPlugin
, cbPluginBase
)
76 EVT_PL_CUSTOMIZE_BAR ( cbSimpleCustomizationPlugin::OnCustomizeBar
)
77 EVT_PL_CUSTOMIZE_LAYOUT( cbSimpleCustomizationPlugin::OnCustomizeLayout
)
81 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin(void)
84 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin( wxFrameLayout
* pPanel
, int paneMask
)
86 : cbPluginBase( pPanel
, paneMask
)
89 void cbSimpleCustomizationPlugin::OnCustomizeBar( cbCustomizeBarEvent
& event
)
91 // ingnore bar customization, treat it
92 // as layout-customization...ugly, eh?
94 cbCustomizeLayoutEvent
clEvt( event
.mClickPos
);
96 OnCustomizeLayout( clEvt
);
99 void cbSimpleCustomizationPlugin::OnCustomizeLayout( cbCustomizeLayoutEvent
& event
)
101 wxString helpStr1
= "Select this item to show the corresponding control bar";
102 wxString helpStr2
= "Select this itme to hide the corresponding control bar";
104 int id
= CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
;
106 wxMenu
* pMenu
= new wxMenu();
108 BarArrayT
& bars
= mpLayout
->GetBars();
110 for( size_t i
= 0; i
!= bars
.GetCount(); ++i
)
112 cbBarInfo
& bar
= *bars
[i
];
114 bool isHidden
= ( bar
.mState
== wxCBAR_HIDDEN
);
116 wxString
* pHelpStr
= ( isHidden
) ? &helpStr1
: &helpStr2
;
118 pMenu
->Append( id
, bar
.mName
, *pHelpStr
, TRUE
);
120 pMenu
->Check( id
, (isHidden
== FALSE
) );
125 pMenu
->AppendSeparator();
126 pMenu
->Append( id
, "Customize...", "Show layout customization dialog", FALSE
);
127 mCustMenuItemId
= id
;
129 cbContextMenuHandler
* pHandler
= new cbContextMenuHandler();
130 pHandler
->mpBackRef
= this;
132 wxWindow
* pFrm
= &mpLayout
->GetParentFrame();
134 // FOR NOW FOR NOW:: to work-around wxFrame's (MSW) nasty event-handling bugs!!!
136 wxWindow
* pTmpWnd
= new wxWindow( pFrm
, -1, event
.mClickPos
, wxSize(0,0) );
138 pMenu
->SetEventHandler( pHandler
);
140 pTmpWnd
->PopupMenu( pMenu
, 0,0 );
147 // event is "eaten" by this plugin
150 void cbSimpleCustomizationPlugin::OnMenuItemSelected( wxCommandEvent
& event
)
152 if ( event
.m_commandInt
== mCustMenuItemId
)
154 wxMessageBox("Customization dialog box is not supproted by this plugin yet");
160 cbBarInfo
* pBar
= mpLayout
->GetBars()[ event
.m_commandInt
-
161 CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
164 wxASSERT( pBar
); // DBG::
166 // "inverse" bar-visibility of the selected bar
170 if ( pBar
->mState
== wxCBAR_HIDDEN
)
172 if ( pBar
->mAlignment
== -1 )
174 pBar
->mAlignment
= 0; // just remove "-1" marking
175 newState
= wxCBAR_FLOATING
;
178 if ( pBar
->mAlignment
== wxTOP
||
179 pBar
->mAlignment
== wxBOTTOM
)
181 newState
= wxCBAR_DOCKED_HORIZONTALLY
;
183 newState
= wxCBAR_DOCKED_VERTICALLY
;
187 newState
= wxCBAR_HIDDEN
;
189 if ( pBar
->mState
== wxCBAR_FLOATING
)
191 pBar
->mAlignment
= -1;
194 mpLayout
->SetBarState( pBar
, newState
, TRUE
);
196 if ( newState
== wxCBAR_FLOATING
)
198 mpLayout
->RepositionFloatedBar( pBar
);
201 // menu-item-selected event is "eaten"