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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
|
/***********************************************************************/
/* Open Visualization Data Explorer */
/* (C) Copyright IBM Corp. 1989,1999 */
/* ALL RIGHTS RESERVED */
/* This code licensed under the */
/* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */
/***********************************************************************/
#include <dxconfig.h>
#include "PageTab.h"
#include "PageGroupManager.h"
#include "Application.h"
#include "PageSelector.h"
#include "EditorWindow.h"
//
// In order to use EditorWorkSpace::DXDropSite methods
//
#include "EditorWorkSpace.h"
String PageTab::DefaultResources[] = {
".recomputeSize: False",
".topOffset: 0",
".leftOffset: 0",
".bottomOffset: 0",
NUL(char*)
};
// gethostname is needed by decodeDropType which is part of drag-n-drop
#if defined(NEEDS_GETHOSTNAME_DECL)
extern "C" int gethostname(char *address, int address_len);
#endif
Pixmap PageTab::AnimationPixmap = NUL(Pixmap);
Pixmap PageTab::AnimationMaskPixmap = NUL(Pixmap);
boolean PageTab::ClassInitialized = FALSE;
Dictionary* PageTab::DropTypeDictionary = new Dictionary;
Dictionary* PageTab::DragTypeDictionary = new Dictionary;
Widget PageTab::DragIcon = NUL(Widget);
#include "pagedrag.bm"
#include "pagedragmask.bm"
#include "animation.bm"
#include "anim_mask.bm"
#define DXPAGETRASH "DXPAGETRASH"
#define DXPAGENAME "DXPAGENAME"
#define DXMODULES "DXMODULES"
PageTab::PageTab(PageSelector* sel, WorkSpace* ws, const char* group) :
NotebookTab(group)
{
this->workSpace = ws;
this->selector = sel;
this->set = FALSE;
this->group_rec = NUL(PageGroupRecord*);
this->position = 0;
this->has_desired_position = FALSE;
this->color_timer = 0;
this->group_name = DuplicateString(group);
}
int PageTab::getDesiredPosition()
{
ASSERT(this->hasDesiredPosition());
return this->desired_position;
}
void PageTab::activate()
{
this->NotebookTab::activate();
this->selector->togglePage(this);
}
void PageTab::createButton (Widget p, PageGroupRecord* prec)
{
this->has_desired_position = TRUE;
this->desired_position = prec->order_in_list;
this->createButton(p);
this->setGroup(prec);
}
void PageTab::createButton (Widget p)
{
this->NotebookTab::createButton(p);
if (!PageTab::ClassInitialized) {
this->setDefaultResources (theApplication->getRootWidget(),
PageTab::DefaultResources);
this->DXDropSite::addSupportedType (PageTab::PageName, DXPAGENAME, TRUE);
this->DXDropSite::addSupportedType (PageTab::Modules, DXMODULES, TRUE);
this->DragSource::addSupportedType (PageTab::PageName, DXPAGENAME, TRUE);
PageTab::DragIcon = this->createDragIcon(pagedrag_width, pagedrag_height,
(char *)pagedrag_bits, (char *)pagedragmask_bits);
PageTab::AnimationPixmap = XCreateBitmapFromData(XtDisplay(p),
XtWindow(p), (char *)animation_bits, animation_width, animation_height);
PageTab::AnimationMaskPixmap = XCreateBitmapFromData(XtDisplay(p),
XtWindow(p), (char *)anim_mask_bits, anim_mask_width, anim_mask_height);
PageTab::ClassInitialized = TRUE;
}
Widget w = this->getRootWidget();
this->setDragWidget(w);
this->setDragIcon(PageTab::DragIcon);
this->setIntraShellBehavior(TRUE);
}
PageTab::~PageTab()
{
if (this->group_name) delete this->group_name;
if (this->color_timer) XtRemoveTimeOut(this->color_timer);
}
void PageTab::setState(boolean value)
{
this->NotebookTab::setState(value);
if (this->group_rec) this->group_rec->showing = value;
}
void PageTab::setGroup(PageGroupRecord* rec)
{
if (this->group_name) delete this->group_name;
this->group_rec = rec;
const char* rec_name = rec->getName();
this->group_name = DuplicateString(rec_name);
this->setLabel(this->group_name);
this->setPosition (this->position);
}
void PageTab::setPosition (int order, boolean designated_by_user)
{
this->position = order;
if (designated_by_user) this->has_desired_position = FALSE;
if (this->group_rec) this->group_rec->order_in_list = order;
}
int PageTab::getPosition ()
{
if (this->group_rec)
this->position = this->group_rec->order_in_list;
return this->position;
}
//
// It might be nice to set a timer to set the color because we're really going
// to just walk thru the net turning things on, then off, then moving to the
// next node. If you're turning lots of nodes in 1 page on/off, then we would
// save some time by not changing the color of the page's tab.
//
void PageTab::setColor (Pixel fg)
{
if (this->color_timer)
XtRemoveTimeOut(this->color_timer);
XtAppContext apcxt = theApplication->getApplicationContext();
this->pending_fg = fg;
this->color_timer =
XtAppAddTimeOut (apcxt, 100, (XtTimerCallbackProc)
PageTab_ColorTimerTO, (XtPointer)this);
}
//
// Does the saved info for this group say the page should be visible?
// This is used to put up the same page which was showing when the net
// was saved.
//
boolean PageTab::getDesiredShowing()
{
return (this->group_rec?this->group_rec->showing:FALSE);
}
extern "C"
void PageTab_ColorTimerTO (XtPointer clientData, XtIntervalId* )
{
PageTab* pt = (PageTab*)clientData;
ASSERT(pt);
XtVaSetValues (pt->getRootWidget(), XmNforeground, pt->pending_fg, NULL);
pt->setDirty(TRUE,TRUE);
pt->color_timer = 0;
}
// Called to consumate a dnd operation
boolean PageTab::decodeDropType
(int tag, char *type, XtPointer value, unsigned long len, int, int)
{
boolean retVal;
int x,y;
int width,height;
EditorWorkSpace* ews = (EditorWorkSpace*)this->getWorkSpace();
switch (tag) {
case PageTab::Modules:
//
// Put the new nodes below whatever net we already have.
//
ews->getMaxWidthHeight (&width, &height);
if ((height > width) && (width < 400)) {
y = 0;
x = width + 10;
} else {
x = 0;
y = height + 10;
}
retVal = this->transfer(type, value, len, x,y);
break;
case PageTab::PageName:
//
// A page name is held in *value. Notify the PageSelector to move
// the corresponding tab right after me.
//
retVal = this->selector->changeOrdering (this, (char*)value);
break;
default:
retVal = FALSE;
break;
}
return retVal;
}
boolean PageTab::decodeDragType (int tag,
char *a, XtPointer *value, unsigned long *length, long operation)
{
boolean retVal;
if (this->isIntraShell() == FALSE)
return FALSE;
const char* gname = this->getGroupName();
char* cp = DuplicateString(gname);
switch(tag) {
#if 0
case PageTab::PageTrash:
gname = this->getGroupName();
if (!gname)
retVal = FALSE;
else if (EqualString(gname, "Untitled"))
retVal = FALSE;
else {
*value = (XtPointer)cp;
*length = strlen(cp);
retVal = TRUE;
}
break;
#endif
case PageTab::PageName:
//
// get some space and put a string there. The string says the name
// of the button which is being moved. The drop site will move me.
//
*value = (XtPointer)cp;
*length = strlen(cp);
retVal = TRUE;
break;
default:
retVal = FALSE;
break;
}
return retVal;
}
#if 0
void PageTab::dropFinish(long operation, int tag, unsigned char status)
{
if (tag == PageTab::PageTrash) {
const char* gname = this->getGroupName();
if (gname)
this->selector->requestPageDeletion (gname);
}
}
#endif
void PageTab::manage()
{
if (this->isManaged()) return ;
this->setDropWidget(this->getRootWidget(), XmDROP_SITE_SIMPLE,
PageTab::AnimationPixmap, PageTab::AnimationMaskPixmap);
this->UIComponent::manage();
}
void PageTab::unmanage()
{
this->UIComponent::unmanage();
XmDropSiteUnregister (this->getRootWidget());
}
//
// A drop has deposited a network for placement in the workspace corresponding
// to this tab. We already set x,y to lead us to empty space in the page.
// In order to get the drop to hit our page, we must remove its page group info
// and replace it with our own.
//
boolean PageTab::mergeNetElements (Network* tmpnet, List* tmppanels, int x, int y)
{
EditorWorkSpace* ews = (EditorWorkSpace*)this->getWorkSpace();
EditorWindow* ew = this->selector->getEditor();
ASSERT(ew);
if (!ew->pagifyNetNodes (tmpnet, ews)) return FALSE;
boolean retVal = ews->mergeNetElements (tmpnet, tmppanels, x, y);
if (retVal) ews->setMembersInitialized(FALSE);
return retVal;
}
void PageTab::multiClick()
{
this->selector->postPageNamePrompt(this);
}
|