]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/fl/cbcustom.cpp
Warning fixes, source cleaning.
[wxWidgets.git] / contrib / src / fl / cbcustom.cpp
CommitLineData
8e08b761 1/////////////////////////////////////////////////////////////////////////////
4cbc57f0
JS
2// Name: cbcustom.cpp
3// Purpose: cbSimpleCustomizationPlugin class declaration
8e08b761
JS
4// Author: Aleksandras Gluchovas
5// Modified by:
6// Created: 06/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Aleksandras Gluchovas
c82c42d4 9// Licence: wxWindows licence
8e08b761
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13 #pragma implementation "cbcustom.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/wx.h"
25#endif
26
27#include "wx/fl/cbcustom.h"
28
29// helper class to receive menu customization event
30
31class cbContextMenuHandler : public wxEvtHandler
32{
33public:
c82c42d4 34 cbSimpleCustomizationPlugin* mpBackRef;
8e08b761
JS
35
36public:
c82c42d4 37 void OnMenuCommand( wxCommandEvent& evt );
8e08b761 38
c82c42d4 39 void OnCommandEvents( wxCommandEvent& evt );
8e08b761 40
c82c42d4 41 DECLARE_EVENT_TABLE()
8e08b761
JS
42};
43
44// FIXME:: is this "safe" ?
45
46#define CB_CUSTOMIZE_MENU_FIRST_ITEM_ID 17500
47
48/***** Implementation for helper class cbContextMenuHandler *****/
49
50BEGIN_EVENT_TABLE( cbContextMenuHandler, wxEvtHandler )
51
c82c42d4
WS
52 // FIXME:: what is the right range for these ids ? so that they
53 // would not collide with user commands?
8e08b761 54
c82c42d4
WS
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 )
8e08b761
JS
59
60END_EVENT_TABLE()
61
62void cbContextMenuHandler::OnCommandEvents( wxCommandEvent& evt )
63{
c82c42d4 64 //wxMessageBox("Wowwwww, Yeah!");
8e08b761 65
c82c42d4 66 mpBackRef->OnMenuItemSelected( evt );
8e08b761
JS
67}
68
69/***** Implementation for class cbSimpleCustomizationPlugin *****/
70
71IMPLEMENT_DYNAMIC_CLASS( cbSimpleCustomizationPlugin, cbPluginBase )
72
73BEGIN_EVENT_TABLE( cbSimpleCustomizationPlugin, cbPluginBase )
74
c82c42d4
WS
75 EVT_PL_CUSTOMIZE_BAR ( cbSimpleCustomizationPlugin::OnCustomizeBar )
76 EVT_PL_CUSTOMIZE_LAYOUT( cbSimpleCustomizationPlugin::OnCustomizeLayout )
8e08b761
JS
77
78END_EVENT_TABLE()
79
80cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin(void)
81{}
82
83cbSimpleCustomizationPlugin::cbSimpleCustomizationPlugin( wxFrameLayout* pPanel, int paneMask )
84
c82c42d4 85 : cbPluginBase( pPanel, paneMask )
8e08b761
JS
86{}
87
88void cbSimpleCustomizationPlugin::OnCustomizeBar( cbCustomizeBarEvent& event )
89{
c82c42d4
WS
90 // ingnore bar customization, treat it
91 // as layout-customization...ugly, eh?
8e08b761 92
c82c42d4 93 cbCustomizeLayoutEvent clEvt( event.mClickPos );
8e08b761 94
c82c42d4 95 OnCustomizeLayout( clEvt );
8e08b761
JS
96}
97
98void cbSimpleCustomizationPlugin::OnCustomizeLayout( cbCustomizeLayoutEvent& event )
99{
c82c42d4
WS
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");
8e08b761 102
c82c42d4 103 int id = CB_CUSTOMIZE_MENU_FIRST_ITEM_ID;
8e08b761 104
c82c42d4 105 wxMenu* pMenu = new wxMenu();
8e08b761 106
c82c42d4 107 BarArrayT& bars = mpLayout->GetBars();
8e08b761 108
c82c42d4
WS
109 for( size_t i = 0; i != bars.GetCount(); ++i )
110 {
111 cbBarInfo& bar = *bars[i];
8e08b761 112
c82c42d4 113 bool isHidden = ( bar.mState == wxCBAR_HIDDEN );
8e08b761 114
c82c42d4 115 wxString* pHelpStr = ( isHidden ) ? &helpStr1 : &helpStr2;
8e08b761 116
c82c42d4 117 pMenu->Append( id, bar.mName, *pHelpStr, true );
8e08b761 118
c82c42d4
WS
119 pMenu->Check( id, (isHidden == false) );
120
121 ++id;
122 }
8e08b761 123
b669b781
JS
124 // Customization dialog not implemented, so don't show the menu item
125#if 0
c82c42d4
WS
126 pMenu->AppendSeparator();
127 pMenu->Append( id, "Customize...", "Show layout customization dialog", false );
b669b781 128#endif
c82c42d4 129 mCustMenuItemId = id;
8e08b761 130
c82c42d4
WS
131 cbContextMenuHandler* pHandler = new cbContextMenuHandler();
132 pHandler->mpBackRef = this;
8e08b761 133
c82c42d4 134 wxWindow* pFrm = &mpLayout->GetParentFrame();
8e08b761 135
c82c42d4 136 // FOR NOW FOR NOW:: to work-around wxFrame's (MSW) nasty event-handling bugs!!!
8e08b761 137
c82c42d4 138 wxWindow* pTmpWnd = new wxWindow( pFrm, wxID_ANY, event.mClickPos, wxSize(0,0) );
8e08b761 139
c82c42d4 140 pMenu->SetEventHandler( pHandler );
8e08b761 141
c82c42d4 142 pTmpWnd->PopupMenu( pMenu, 0,0 );
8e08b761 143
c82c42d4 144 pTmpWnd->Destroy();
8e08b761 145
c82c42d4
WS
146 delete pMenu;
147 delete pHandler;
8e08b761 148
c82c42d4 149 // event is "eaten" by this plugin
8e08b761
JS
150}
151
152void cbSimpleCustomizationPlugin::OnMenuItemSelected( wxCommandEvent& event )
153{
c82c42d4
WS
154 if ( event.GetId() == mCustMenuItemId )
155 {
156 wxMessageBox(wxT("Customization dialog box is not supported by this plugin yet"));
8e08b761 157
c82c42d4
WS
158 return;
159 }
160 else
161 {
162 cbBarInfo* pBar = mpLayout->GetBars()[ event.GetId() - CB_CUSTOMIZE_MENU_FIRST_ITEM_ID ];
8e08b761 163
c82c42d4 164 wxASSERT( pBar ); // DBG::
8e08b761 165
c82c42d4 166 // "inverse" bar-visibility of the selected bar
8e08b761 167
c82c42d4 168 int newState;
8e08b761 169
c82c42d4
WS
170 if ( pBar->mState == wxCBAR_HIDDEN )
171 {
172 if ( pBar->mAlignment == -1 )
173 {
174 pBar->mAlignment = 0; // just remove "-1" marking
175 newState = wxCBAR_FLOATING;
176 }
177 else
178 if ( pBar->mAlignment == FL_ALIGN_TOP ||
179 pBar->mAlignment == FL_ALIGN_BOTTOM )
8e08b761 180
c82c42d4
WS
181 newState = wxCBAR_DOCKED_HORIZONTALLY;
182 else
183 newState = wxCBAR_DOCKED_VERTICALLY;
184 }
185 else
186 {
187 newState = wxCBAR_HIDDEN;
8e08b761 188
c82c42d4 189 if ( pBar->mState == wxCBAR_FLOATING )
8e08b761 190
c82c42d4
WS
191 pBar->mAlignment = -1;
192 }
8e08b761 193
c82c42d4 194 mpLayout->SetBarState( pBar, newState, true );
8e08b761 195
c82c42d4
WS
196 if ( newState == wxCBAR_FLOATING )
197 mpLayout->RepositionFloatedBar( pBar );
198 }
8e08b761 199
c82c42d4 200 // menu-item-selected event is "eaten"
8e08b761
JS
201}
202