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