📄 rowcolc.c
字号:
} if ( newHt > 0 ) { prefHt = newHt; newHt = 0; if ( debug2 ) cout <<" but the programmed height is: " <<prefHt <<endl; }//// Ask for the new size// Dimension realWd, realHt; XtGeometryResult answer = XtMakeResizeRequest(rcw, prefWd, prefHt, &realWd, &realHt);//// Accept compromises// if ( answer == XtGeometryAlmost ) { prefWd = realWd; prefHt = realHt; XtMakeResizeRequest(rcw, prefWd, prefHt, NULL, NULL); if ( debug2 ) cout <<" but parent says almost, be: " <<prefWd <<" by " <<prefHt <<endl; }//// Stick with what we got.// else if ( answer == XtGeometryNo ) { prefWd = rcw->core.width; prefHt = rcw->core.height; if ( debug2 ) cout <<" but parent says no, be: " <<prefWd <<" by " <<prefHt <<endl; }//// Some parents will say yes, but not change the size// else if ( rcw->core.width != prefWd || rcw->core.height != prefHt ) { prefWd = rcw->core.width; prefHt = rcw->core.height; if ( debug2 ) cout <<" but parent lied: " <<prefWd <<" by " <<prefHt <<endl; } } // End if not called from HandleResize//// Update size and positions// if ( titleRow ) titleRow->SetSize(titleRow->prefSize); if ( titleCol ) titleCol->SetSize(titleCol->prefSize); FitToWidth(prefWd); FitToHeight(prefHt); if ( changed ) {//// Refresh all rows and columns// if ( titleRow ) titleRow->Refresh(); if ( titleCol ) titleCol->Refresh(); //cout <<"Refreshing rows" <<endl; unsigned count = rowList.size(); int i; for (i=0; i<count; i++) rowList[i]->Refresh(); //cout <<"Refreshing columns" <<endl; count = colList.size(); for (i=0; i<count; i++) colList[i]->Refresh();//// Update the child geometries and visibilities// RefreshChildren(childList); if ( titleRow ) RefreshChildren(titleRow->childList); if ( titleCol ) RefreshChildren(titleCol->childList); } // End if anything changed selfResize = False;//// Remove any resize events from the queue. We don't need them.// XSync(halApp->display, FALSE); XEvent event; while ( XCheckTypedWindowEvent(halApp->display, XtWindow(rcw), ConfigureNotify, &event) ) ; deferred = saveDeferred; changed = False; if ( debug2 ) cout <<"RowColC(" <<rcw->core.name <<")::Refresh exited" <<endl;} // End RowColC Refresh/*----------------------------------------------------------------------- * Method to loop through child list, updating geometries and visibilities */voidRowColC::RefreshChildren(RowColChildListC& list){ if ( debug2 ) cout <<"RowColC(" <<rcw->core.name <<")::RefreshChildren entered" <<endl;//// Unmanage the widgets that will be off and the ones that will be changing.// WidgetListC unmanageList; WidgetListC manageList; RowColChildListC changeList;#if 0 Widget traverseWidget = NULL;#endif unsigned count = list.size(); int i; for (i=0; i<count; i++) { RowColChildC *child = list[i]; if ( !child->w ) continue;//// Process child if it is visible// if ( child->row->visible && child->col->visible ) {//// See if the geometry has changed.// Boolean posChange = (child->curX != child->w->core.x || child->curY != child->w->core.y); Boolean sizeChange = (child->curWd != child->w->core.width || child->curHt != child->w->core.height); if ( posChange || sizeChange ) changeList.add(child);//// Manage the child again /*after changes are made or*/ if it is off.// if ( /*sizeChange ||*/ !XtIsManaged(child->w) ) { if ( debug2 ) cout <<" will manage " <<child->w->core.name <<endl; manageList.add(child->w); } } // End if child is visible//// Unmanage the child if it will no longer be visible.// else if ( XtIsManaged(child->w) ) { if ( debug2 ) cout <<" will unmanage " <<child->w->core.name <<endl; if ( XmIsPrimitive(child->w) && Prim_HaveTraversal(child->w) ) { if ( debug2 ) cout <<" " <<child->w->core.name <<" has the traversal" <<endl;#if 0 traverseWidget = child->w;#endif } unmanageList.add(child->w); } // End if child is not visible } // End for each child//// Turn off widgets// if ( unmanageList.size() > 0 ) { if ( debug2 ) cout <<"Unmanaging " <<unmanageList.size() <<" children" <<endl; XtUnmanageChildren(unmanageList.start(), unmanageList.size()); }//// Update geometries// count = changeList.size(); for (i=0; i<count; i++) { RowColChildC *child = changeList[i]; if ( child->curWd > 0 && child->curHt > 0 ) { if ( debug2 ) cout <<" setting geometry for " <<child->w->core.name <<"\tto " <<dec(child->curWd,4) <<" by " <<dec(child->curHt,4) <<" at " <<dec(child->curX,4) <<", " <<dec(child->curY,4) <<endl; XtConfigureWidget(child->w, child->curX, child->curY, child->curWd, child->curHt, child->w->core.border_width);#if 0//// Remove any resize events from the queue. We don't need them.// XSync(halApp->display, FALSE); XEvent event; while ( XCheckTypedWindowEvent(halApp->display, XtWindow(child->w), ConfigureNotify, &event) ) ;#endif } }//// Turn on the visible widgets again// if ( manageList.size() > 0 ) { if ( debug2 ) cout <<"Managing " <<manageList.size() <<" children" <<endl; XtManageChildren(manageList.start(), manageList.size()); }#if 0//// Reset the traversal// if ( traverseWidget ) XmProcessTraversal(traverseWidget, XmTRAVERSE_CURRENT);#endif} // End RowColC RefreshChildren/*----------------------------------------------------------------------- * Method to lay out the columns, using the given width */voidRowColC::FitToWidth(Dimension daWd){ if ( debug2 ) cout <<"RowColC(" <<rcw->core.name <<")::FitToWidth" <<endl; Dimension availWd; RowColPart *rc = GetRowColPart(rcw);//// Loop through the columns. Subtract the width of any that can be resized.// unsigned count = colList.size(); unsigned visCount = 0; int i; for (i=0; i<count; i++) { ColC *col = (ColC*)colList[i]; if ( col->visible ) visCount++; } availWd = daWd - rc->marginWd*2 - rc->colSpacing*(visCount-1); unsigned resizeCount = 0; for (i=0; i<count; i++) { ColC *col = (ColC*)colList[i]; if ( col->visible ) { if ( col->resizeOk ) resizeCount++; else { col->SetSize(col->prefSize); availWd -= col->prefSize; } } }//// If there are any that can be resized and there is any available width,// divide it up.// if ( availWd > 0 && resizeCount > 0 ) {//// If the columns are to be the same size, divide the space evenly.// if ( rc->uniformCols ) { int colWd = (int)availWd / (int)resizeCount; for (i=0; i<count; i++) { ColC *col = (ColC*)colList[i]; if ( col->visible && col->resizeOk ) col->SetSize(colWd); } }//// If the columns don't have to be the same size, divide the space// proportionally.// else {//// See how much space they would like to occupy// Dimension prefTotal = 0; for (i=0; i<count; i++) { ColC *col = (ColC*)colList[i]; if ( col->visible && col->resizeOk ) prefTotal += col->prefSize; }//// Set the new size in proportion to the old size// if ( prefTotal > 0 ) { for (i=0; i<count; i++) { ColC *col = (ColC*)colList[i]; if ( col->visible && col->resizeOk ) { float scale = (float)col->prefSize / (float)prefTotal; int newWd = (int)(scale * (float)availWd); col->SetSize(newWd); } } } } // End if space divided up proportionally } // End if there are columns to be resized//// Now set the column positions// int x = rc->marginWd; for (i=0; i<count; i++) { ColC *col = (ColC*)colList[i]; if ( col->visible ) { col->SetPosition(x); x += col->realSize + rc->colSpacing; } }} // End RowColC FitToWidth/*----------------------------------------------------------------------- * Method to lay out the rows, using the given height */voidRowColC::FitToHeight(Dimension daHt){ if ( debug2 ) cout <<"RowColC(" <<rcw->core.name <<")::FitToHeight" <<endl; Dimension availHt; RowColPart *rc = GetRowColPart(rcw);//// Loop through the rows. Subtract the height of any that can be resized.// unsigned count = rowList.size(); unsigned visCount = 0; int i; for (i=0; i<count; i++) { RowC *row = (RowC*)rowList[i]; if ( row->visible ) visCount++; } availHt = daHt - rc->marginHt*2 - rc->rowSpacing*(visCount-1); unsigned resizeCount = 0; for (i=0; i<count; i++) { RowC *row = (RowC*)rowList[i]; if ( row->visible ) { if ( row->resizeOk ) resizeCount++; else { row->SetSize(row->prefSize); availHt -= row->prefSize; } } }//// If there are any that can be resized and there is any available height,// divide it up.// if ( availHt > 0 && resizeCount > 0 ) {//// If the rows are to be the same size, divide the space evenly.// if ( rc->uniformRows ) { int rowHt = (int)availHt / (int)resizeCount; for (i=0; i<count; i++) { RowC *row = (RowC*)rowList[i]; if ( row->visible && row->resizeOk ) row->SetSize(rowHt); } }//// If the rows don't have to be the same size, divide the space// proportionally.// else {//// See how much space they would like to occupy// Dimension prefTotal = 0; for (i=0; i<count; i++) { RowC *row = (RowC*)rowList[i]; if ( row->visible && row->resizeOk ) prefTotal += row->prefSize; }//// Set the new size in proportion to the old size// if ( prefTotal > 0 ) { for (i=0; i<count; i++) { RowC *row = (RowC*)rowList[i]; if ( row->visible && row->resizeOk ) { float scale = (float)row->prefSize / (float)prefTotal; int newHt = (int)(scale * (float)availHt); row->SetSize(newHt); } } } } // End if space divided up proportionally } // End if there are rows to be resized//// Now set the row positions// int y = rc->marginHt; for (i=0; i<count; i++) { RowC *row = (RowC*)rowList[i]; if ( row->visible ) { row->SetPosition(y); y += row->realSize + rc->rowSpacing; } }} // End RowColC FitToHeight/*----------------------------------------------------------------------- * Callback for expose */voidRowColC::HandleExpose(Widget w, RowColC *This, XtPointer){ if ( debug2 ) cout <<"RowColC(" <<This->rcw->core.name <<")::HandleExpose" <<endl; XtRemoveCallback(w, XmNexposeCallback, (XtCallbackProc)HandleExpose, (XtPointer)This); This->ExposeIt();}voidRowColC::HandleMapChange(Widget, RowColC *This, XEvent *ev, Boolean*){ if ( ev->type != MapNotify ) return; if ( debug2 ) cout <<"RowColC(" <<This->rcw->core.name <<")::HandleMapChange" <<endl; XtRemoveEventHandler(This->rcw, StructureNotifyMask, False, (XtEventHandler)HandleMapChange, (XtPointer)This); This->ExposeIt();}voidRowColC::ExposeIt(){ if ( exposed ) return;//// Reset preferred sizes// unsigned count = childList.size(); int i; for (i=0; i<count; i++) { RowColChildC *child = childList[i]; child->prefWd = 0; child->prefHt = 0; } if ( titleRow ) { count = titleRow->childList.size(); for (i=0; i<count; i++) { RowColChildC *child = titleRow->childList[i]; child->prefWd = 0; child->prefHt = 0; } } if ( titleCol ) { count = titleCol->childList.size(); for (i=0; i<count; i++) { RowColChildC *child = titleCol->childList[i]; child->prefWd = 0; child->prefHt = 0; } } exposed = True;//// Always redraw after the first expose event// if ( !deferred ) Refresh(); else changed = True;} // End ExposeIt/*----------------------------------------------------------------------- * Callback for resize */voidRowColC::HandleResize(Widget w, RowColC *This, XtPointer){ if ( This->inResize || This->selfResize ) return; if ( debug2 ) cout <<"Resize for " <<XtName(w) <<" is " <<w->core.width SP w->core.height <<endl; This->inResize = True; This->Refresh(); This->inResize = False;}/*----------------------------------------------------------------------- * Callbacks for child resize */voidRowColC::HandleChildResize(Widget, RowColC *This, XtPointer data){ RowColGeometryCallbackStruct *geo = (RowColGeometryCallbackStruct *)data; This->ChildResize(geo->widget, geo->desiredWd, geo->desiredHt);}voidRowColC::HandleTitleResize(Widget w, RowColC *This, XEvent *ev, Boolean*){ if ( ev->type != ConfigureNotify && ev->type != MapNotify ) return;//// Let's find out what size the child really wants to be// XtWidgetGeometry geo; XtQueryGeometry(w, NULL, &geo); This->ChildResize(w, geo.width, geo.height);}voidRowColC::ChildResize(Widget w, Dimension newWd, Dimension newHt){ if ( selfResize ) return;//// Look up this widget in the child list// RowColChildC *child = NULL; int index = childList.indexOf(w); if ( index != childList.NULL_INDEX ) child = childList[index];//// If it wasn't found, try the title row// if ( !child && titleRow ) { index = titleRow->childList.indexOf(w); if ( index != titleRow->childList.NULL_INDEX ) child = titleRow->childList[index]; }//// If it still wasn't found, try the title column// if ( !child && titleCol ) { index = titleCol->childList.indexOf(w); if ( index != titleCol->childList.NULL_INDEX ) child = titleCol->childList[index]; }//// If it still wasn't found, punt// if ( !child ) return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -