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