1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: cbSimpleCustomizationPlugin class declaration
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "cbcustom.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/fl/cbcustom.h"
29 // helper class to receive menu customization event
31 class cbContextMenuHandler
: public wxEvtHandler
34 cbSimpleCustomizationPlugin
* mpBackRef
;
37 void OnMenuCommand( wxCommandEvent
& evt
);
39 void OnCommandEvents( wxCommandEvent
& evt
);
44 // FIXME:: is this "safe" ?
46 #define CB_CUSTOMIZE_MENU_FIRST_ITEM_ID 17500
48 /***** Implementation for helper class cbContextMenuHandler *****/
50 BEGIN_EVENT_TABLE( cbContextMenuHandler
, wxEvtHandler
)
52 // FIXME:: what is the right range for these ids ? so that they
53 // would not collide with user commands?
55 EVT_COMMAND_RANGE( CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
,
56 CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
+ 300,
57 wxEVT_COMMAND_MENU_SELECTED
,
58 cbContextMenuHandler::OnCommandEvents
)
62 void cbContextMenuHandler::OnCommandEvents( wxCommandEvent
& evt
)
64 //wxMessageBox("Wowwwww, Yeah!");
66 mpBackRef
->OnMenuItemSelected( evt
);
69 /***** Implementation for class cbSimpleCustomizationPlugin *****/
71 IMPLEMENT_DYNAMIC_CLASS( cbSimpleCustomizationPlugin
, cbPluginBase
)
73 BEGIN_EVENT_TABLE( cbSimpleCustomizationPlugin
, cbPluginBase
)
75 EVT_PL_CUSTOMIZE_BAR ( cbSimpleCustomizationPlugin::OnCustomizeBar
)
76 EVT_PL_CUSTOMIZE_LAYOUT( cbSimpleCustomizationPlugin::OnCustomizeLayout
)
80 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin(void)
83 cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin( wxFrameLayout
* pPanel
, int paneMask
)
85 : cbPluginBase( pPanel
, paneMask
)
88 void cbSimpleCustomizationPlugin::OnCustomizeBar( cbCustomizeBarEvent
& event
)
90 // ingnore bar customization, treat it
91 // as layout-customization...ugly, eh?
93 cbCustomizeLayoutEvent
clEvt( event
.mClickPos
);
95 OnCustomizeLayout( clEvt
);
98 void cbSimpleCustomizationPlugin::OnCustomizeLayout( cbCustomizeLayoutEvent
& event
)
100 wxString helpStr1
= wxT("Select this item to show the corresponding control bar");
101 wxString helpStr2
= wxT("Select this itme to hide the corresponding control bar");
103 int id
= CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
;
105 wxMenu
* pMenu
= new wxMenu();
107 BarArrayT
& bars
= mpLayout
->GetBars();
109 for( size_t i
= 0; i
!= bars
.GetCount(); ++i
)
111 cbBarInfo
& bar
= *bars
[i
];
113 bool isHidden
= ( bar
.mState
== wxCBAR_HIDDEN
);
115 wxString
* pHelpStr
= ( isHidden
) ? &helpStr1
: &helpStr2
;
117 pMenu
->Append( id
, bar
.mName
, *pHelpStr
, TRUE
);
119 pMenu
->Check( id
, (isHidden
== FALSE
) );
124 // Customization dialog not implemented, so don't show the menu item
126 pMenu
->AppendSeparator();
127 pMenu
->Append( id
, "Customize...", "Show layout customization dialog", FALSE
);
129 mCustMenuItemId
= id
;
131 cbContextMenuHandler
* pHandler
= new cbContextMenuHandler();
132 pHandler
->mpBackRef
= this;
134 wxWindow
* pFrm
= &mpLayout
->GetParentFrame();
136 // FOR NOW FOR NOW:: to work-around wxFrame's (MSW) nasty event-handling bugs!!!
138 wxWindow
* pTmpWnd
= new wxWindow( pFrm
, -1, event
.mClickPos
, wxSize(0,0) );
140 pMenu
->SetEventHandler( pHandler
);
142 pTmpWnd
->PopupMenu( pMenu
, 0,0 );
149 // event is "eaten" by this plugin
152 void cbSimpleCustomizationPlugin::OnMenuItemSelected( wxCommandEvent
& event
)
154 if ( event
.GetId() == mCustMenuItemId
)
156 wxMessageBox(wxT("Customization dialog box is not supported by this plugin yet"));
162 cbBarInfo
* pBar
= mpLayout
->GetBars()[ event
.GetId() -
163 CB_CUSTOMIZE_MENU_FIRST_ITEM_ID
166 wxASSERT( pBar
); // DBG::
168 // "inverse" bar-visibility of the selected bar
172 if ( pBar
->mState
== wxCBAR_HIDDEN
)
174 if ( pBar
->mAlignment
== -1 )
176 pBar
->mAlignment
= 0; // just remove "-1" marking
177 newState
= wxCBAR_FLOATING
;
180 if ( pBar
->mAlignment
== FL_ALIGN_TOP
||
181 pBar
->mAlignment
== FL_ALIGN_BOTTOM
)
183 newState
= wxCBAR_DOCKED_HORIZONTALLY
;
185 newState
= wxCBAR_DOCKED_VERTICALLY
;
189 newState
= wxCBAR_HIDDEN
;
191 if ( pBar
->mState
== wxCBAR_FLOATING
)
193 pBar
->mAlignment
= -1;
196 mpLayout
->SetBarState( pBar
, newState
, TRUE
);
198 if ( newState
== wxCBAR_FLOATING
)
200 mpLayout
->RepositionFloatedBar( pBar
);
203 // menu-item-selected event is "eaten"