forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FrameListMenu.cpp
268 lines (218 loc) · 7.04 KB
/
FrameListMenu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
//////////////////////////////////////////////////////////////////////////
// //
// Name: FrameListMenu.cpp //
// //
// Description: A menu class for listing all the xfe windows. //
// This class can be used with both XmCascadeButton and //
// XfeCascade widgets. //
// //
// Author: Ramiro Estrugo <[email protected]> //
// //
//////////////////////////////////////////////////////////////////////////
#include "FrameListMenu.h"
#include "MozillaApp.h"
#include "felocale.h"
#include "intl_csi.h"
#include <Xm/PushBG.h>
#include <Xm/ToggleBG.h>
#include <Xfe/Xfe.h>
#define MAX_ITEM_WIDTH 40
//////////////////////////////////////////////////////////////////////////
XFE_FrameListMenu::XFE_FrameListMenu(Widget w, XFE_Frame * frame)
{
m_cascade = w;
m_parentFrame = frame;
XP_ASSERT( m_parentFrame != NULL );
XtAddCallback(m_cascade,
XmNdestroyCallback,
&XFE_FrameListMenu::destroy_cb,
(XtPointer) this);
XtAddCallback(m_cascade,
XmNcascadingCallback,
&XFE_FrameListMenu::cascading_cb,
(XtPointer) this);
XtVaGetValues(m_cascade,XmNsubMenuId,&m_submenu,NULL);
XtVaGetValues(m_submenu,XmNnumChildren,&m_firstslot,NULL);
XP_ASSERT(m_submenu);
}
//////////////////////////////////////////////////////////////////////////
XFE_FrameListMenu::~XFE_FrameListMenu()
{
}
//////////////////////////////////////////////////////////////////////////
void
XFE_FrameListMenu::generate(Widget cascade, XtPointer, XFE_Frame *frame)
{
XFE_FrameListMenu *obj;
obj = new XFE_FrameListMenu(cascade, frame);
}
//////////////////////////////////////////////////////////////////////////
void
XFE_FrameListMenu::cascading()
{
XP_List * frame_list = getShownFrames();
XFE_Frame * frame;
int i;
int frame_count = XP_ListCount(frame_list);
Cardinal num_children;
WidgetList children;
int total_slots_needed;
int slots_to_add;
int count;
XfeChildrenGet(m_submenu,&children,&num_children);
XP_ASSERT( num_children > 1 );
// Total number of slots needed
total_slots_needed = m_firstslot + 1 + frame_count;
// Number of slots to add
slots_to_add = total_slots_needed - num_children;
// Add more slots if needed
if (slots_to_add > 0)
{
for (i = 0; i < slots_to_add; i++)
{
Widget item = XtVaCreateWidget(xfeCmdFrameListRaiseItem,
//xmToggleButtonGadgetClass,
xmPushButtonGadgetClass,
m_submenu,
NULL);
XtAddCallback(item,
XmNactivateCallback,
//XmNvalueChangedCallback,
&XFE_FrameListMenu::item_activate_cb,
(XtPointer) this);
}
// Update num_slots, since we added stuff
XfeChildrenGet(m_submenu,&children,&num_children);
}
count = 1;
// Configure the items
for (i = (int) m_firstslot + 1; i < (int) num_children; i++)
{
// Get the next frame
frame = (XFE_Frame*) XP_ListNextObject(frame_list);
// If the frame is valid, add its title to the slot buttons
if (frame)
{
MWContext * context = m_parentFrame->getContext();
INTL_CharSetInfo c = LO_GetDocumentCharacterSetInfo(context);
XmFontList font_list;
char name[1024];
XP_SPRINTF(name,"%d. %s",count++,frame->getTitle());
INTL_MidTruncateString(INTL_GetCSIWinCSID(c),
name,
name,
MAX_ITEM_WIDTH);
XmString label = fe_ConvertToXmString((unsigned char *) name,
INTL_GetCSIWinCSID(c),
NULL,
XmFONT_IS_FONT,
&font_list);
if (label)
{
XtVaSetValues(children[i],XmNlabelString,label,NULL);
XmStringFree(label);
}
XtManageChild(children[i]);
}
// If the frame is not valid, the unmanage the slot button
else
{
XtUnmanageChild(children[i]);
}
}
// Update the display so that the gadget buttons get drawn
XmUpdateDisplay(m_submenu);
if (frame_list)
{
XP_ListDestroy(frame_list);
}
}
//////////////////////////////////////////////////////////////////////////
void
XFE_FrameListMenu::item_activate(Widget item)
{
XP_ASSERT( XfeIsAlive(m_submenu) );
int i = XfeChildGetIndex(item) - m_firstslot;
XP_ASSERT( i > 0 );
if (i <= 0)
{
return;
}
XP_List * frame_list = getShownFrames();
XFE_Frame * frame = (XFE_Frame *) XP_ListGetObjectNum(frame_list,i);
XP_ASSERT( frame != NULL );
if (frame)
{
frame->show();
}
XmUpdateDisplay(frame->getBaseWidget());
if (frame_list)
{
XP_ListDestroy(frame_list);
}
}
//////////////////////////////////////////////////////////////////////////
void
XFE_FrameListMenu::destroy_cb(Widget, XtPointer clientData, XtPointer)
{
XFE_FrameListMenu *obj = (XFE_FrameListMenu*)clientData;
delete obj;
}
//////////////////////////////////////////////////////////////////////////
void
XFE_FrameListMenu::cascading_cb(Widget, XtPointer clientData, XtPointer)
{
XFE_FrameListMenu *obj = (XFE_FrameListMenu*)clientData;
obj->cascading();
}
//////////////////////////////////////////////////////////////////////////
void
XFE_FrameListMenu::item_activate_cb(Widget item, XtPointer clientData, XtPointer)
{
XFE_FrameListMenu *obj = (XFE_FrameListMenu*)clientData;
obj->item_activate(item);
}
//////////////////////////////////////////////////////////////////////////
XP_List *
XFE_FrameListMenu::getShownFrames()
{
XP_List * frame_list = XFE_MozillaApp::theApp()->getAllFrameList();
Cardinal frame_count = XP_ListCount(frame_list);
XP_List * shown_frame_list = NULL;
Cardinal i;
// Find the shown frames and add them to a list
for (i = 0; i < frame_count; i++)
{
// Get the next frame
XFE_Frame * frame = (XFE_Frame*) XP_ListNextObject(frame_list);
// Add it to list if valid and shown
if (frame && XfeIsAlive(frame->getBaseWidget()) && frame->isShown())
{
// Create a new list as soon as we find the first shown item
if (!shown_frame_list)
{
shown_frame_list = XP_ListNew();
}
XP_ListAddObject(shown_frame_list,frame);
}
}
return shown_frame_list;
}
//////////////////////////////////////////////////////////////////////////