📄 fieldviewc.c
字号:
/* * $Id: FieldViewC.C,v 1.9 2001/03/07 10:39:18 evgeny Exp $ * * Copyright (c) 1992 HAL Computer Systems International, Ltd. * * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. * 1315 Dell Avenue * Campbell, CA 95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * http://www.gnu.org/copyleft/gpl.html * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include <config.h>#include "HalAppC.h"#include "FieldViewC.h"#include "VItemC.h"#include "VBoxC.h"#include "rsrc.h"#include "WArgList.h"#include "WXmString.h"#include <Xm/Label.h>#include <X11/keysym.h>#include <X11/IntrinsicP.h>#include <X11/CoreP.h>#include <values.h>/*----------------------------------------------------------------------- * Method to check data pointer */inline BooleanFieldViewC::DataValid(const ItemDataC *data){ return (data && (data->view == this));}/*----------------------------------------------------------------------- * Constructor for FieldViewC */FieldViewC::FieldViewC(VBoxC *vb) : ViewC(vb){ WArgList args; titleWin = (Window)NULL; titleGC = NULL; titlePickGC = NULL; resizeCursor = (Cursor)NULL; maxTitleHt = 0; maxPmWd = 0; focusHere = False; hlItem = NULL; flashItem = NULL; flashTimer = (XtIntervalId)NULL; dropItem = NULL; dragIcon = NULL; scrollTimer = (XtIntervalId)NULL; pressItem = NULL; clickCount = 1; lastClickTime = 0; needPlaces = True; needSetVisItemCount = False; prevCompareFunction = NULL; columnList.AllowDuplicates(TRUE); columnDisplayOrder.AllowDuplicates(TRUE); columnDisplayOrder.SetSorted(FALSE); columnSortOrder.AllowDuplicates(FALSE); columnSortOrder.SetSorted(FALSE);//// Create a title area in the main view box// Dimension st, bw, mw; XtVaGetValues(vb->ViewFrame(), XmNshadowThickness, &st, XmNborderWidth, &bw, XmNmarginWidth, &mw, NULL); Position off = st + bw + mw; args.Reset(); args.TopAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM, off); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_NONE); args.MarginWidth(0); args.MarginHeight(0); titleDA = XmCreateDrawingArea(vb->ViewForm(), "titleDA", ARGS); args.Reset(); args.MappedWhenManaged(False); args.RecomputeSize(False); titleSizeLabel = XmCreateLabel(titleDA, "titleSizeLabel", ARGS); XtManageChild(titleSizeLabel); XtAddCallback(titleDA, XmNexposeCallback, (XtCallbackProc)TitleExpose, (XtPointer)this); XtAddCallback(titleDA, XmNinputCallback, (XtCallbackProc)TitleInput, (XtPointer)this);//// Get resources// Widget da = viewBox->ViewDA(); char *cl = "FieldViewC"; regFgColor = get_color(cl, da, "foreground", XtDefaultForeground); regBgColor = get_color(cl, da, "background", XtDefaultBackground); hlColor = get_color(cl, da, "highlightColor", regFgColor); invFgColor = get_color(cl, da, "selectedForeground", regBgColor); invBgColor = get_color(cl, da, "selectedBackground", regFgColor); titleFgColor = get_color(cl, da, "titleForeground", regFgColor); titleBgColor = get_color(cl, da, "titleBackground", regBgColor); dropColor = get_color(cl, da, "validDropColor", hlColor); hlThick = get_int(cl, da, XmNhighlightThickness); sepThick = get_int(cl, da, "separatorThickness", 1); ySpacing = get_int(cl, da, "vertSpacing"); itemMarginWd = get_int(cl, da, "itemMarginWidth"); itemMarginHt = get_int(cl, da, "itemMarginHeight"); visItemCount = get_int(cl, da, "visibleItemCount", 0); autoScrollInterval = get_int(cl, da, "autoScrollInterval", 100); pickSortThreshold = get_int(cl, da, "pickSortThreshold", 7); showPixmaps = get_boolean(cl, da, "showPixmaps", True); dragTitlesEnabled = get_boolean(cl, da, "dragTitlesEnabled", True); pickSortColumnEnabled = get_boolean(cl, da, "pickSortColumnEnabled", False);#if 0 pickSortColumnEnabled = get_boolean(cl, da, "pickSortColumnEnabled", viewBox->compFunc == NULL);#endif if ( visItemCount > 0 ) needSetVisItemCount = True;//// Load the XmFontList// fontList = viewBox->FontList();//// Load Font// font = viewBox->Font();//// Get keyboard focus policy// Widget shell = XtParent(viewBox->ViewDA()); while ( !XtIsShell(shell) ) shell = XtParent(shell); unsigned char focusPolicy; XtVaGetValues(shell, XmNkeyboardFocusPolicy, &focusPolicy, NULL); if ( focusPolicy == XmEXPLICIT ) {//// Add event handler for keyboard focus change// XtAddEventHandler(viewBox->ViewDA(), FocusChangeMask, False, (XtEventHandler)HandleFocusChange, (XtPointer)this); } else { // XmPOINTER XtAddEventHandler(viewBox->ViewDA(), EnterWindowMask|LeaveWindowMask, False, (XtEventHandler)HandleFocusChange, (XtPointer)this); XtAddEventHandler(viewBox->ViewDA(), PointerMotionMask|PointerMotionHintMask, False, (XtEventHandler)HandlePointerMotion, (XtPointer)this); } if ( XtIsManaged(viewBox->ViewDA()) && needSetVisItemCount ) { SetVisibleItemCount(visItemCount); }} // End Constructor/*----------------------------------------------------------------------- * Destructor for FieldViewC */FieldViewC::~FieldViewC(){//// Delete data// unsigned count = dataDict.size(); int i; for (i=0; i<count; i++) { delete dataDict[i]->val; delete dataDict[i]; }//// Free pixmaps// count = pixmapFileDict.size(); for (i=0; i<count; i++) { PixmapC *pm = pixmapFileDict[i]->val; delete pm; } count = pixmapDataDict.size(); for (i=0; i<count; i++) { PixmapC *pm = pixmapDataDict[i]->val; delete pm; } count = columnList.size(); for (i=0; i<count; i++) { delete columnList[i]; }//// Free graphics structures// if ( halApp->xRunning ) { if ( titleGC ) XtReleaseGC(titleDA, titleGC); if ( titlePickGC ) XtReleaseGC(viewBox->ViewDA(), titlePickGC); if ( resizeCursor ) XFreeCursor(halApp->display, resizeCursor); }} // End Destructor/*----------------------------------------------------------------------- * Display this view */voidFieldViewC::Show(){ shown = True;//// Display the title area// if ( !titleWin && XtIsRealized(titleDA) ) InitializeTitle(); XtManageChild(titleDA);//// Attach the scrolled window to the title area// WArgList args; args.TopAttachment(XmATTACH_WIDGET, titleDA); XtSetValues(viewBox->ScrollForm(), ARGS);//// Loop through items and add any that are needed// VItemListC& items = viewBox->Items(); unsigned count = items.size(); for (int i=0; i<count; i++) { VItemC *item = items[i];//// Look up the view data in the data dictionary// ItemDataC *data = dataDict.definitionOf(item); if ( data ) { item->SetViewData(data); //..data->GetFieldSizes(font); } else { _AddItem(*item); } } // End for each item in view needPlaces = True;//// Set the GC values// XtGCMask valMask = GCClipMask | GCFillStyle | GCFunction | GCGraphicsExposures | GCLineStyle | GCLineWidth | GCPlaneMask | GCForeground; XGCValues vals; vals.clip_mask = None; vals.fill_style = FillSolid; vals.function = GXcopy; vals.graphics_exposures = TRUE; vals.line_style = LineSolid; vals.line_width = 0; vals.plane_mask = AllPlanes; vals.foreground = regFgColor; if ( viewBox->GoodFont() ) { valMask |= GCFont; vals.font = font->fid; } XChangeGC(halApp->display, viewBox->ViewGC(), valMask, &vals); _EnablePickSortColumn(pickSortColumnEnabled); Redraw();} // End Show/*----------------------------------------------------------------------- * Remove this view */voidFieldViewC::Hide(){//// Attach the scrolled window to the form// WArgList args; args.TopAttachment(XmATTACH_FORM); XtSetValues(viewBox->ScrollForm(), ARGS);//// Hide the title areas// XtUnmanageChild(titleDA);//// Clear view data// VItemListC& items = viewBox->Items(); unsigned count = items.size(); for (int i=0; i<count; i++) { //cout <<"Clearing data for item " <<hex <<(int)items[i] <<dec NL; items[i]->SetViewData(NULL); } _EnablePickSortColumn(False); shown = False;} // End Hide/*----------------------------------------------------------------------- * Calculate all sizes */voidFieldViewC::PlaceItems(){ fontList = viewBox->FontList(); font = viewBox->Font();//// Initialize columns with title sizes. Also get title height.// maxTitleHt = 0; unsigned ccount = columnList.size(); int i; for (i=0; i<ccount; i++) { int id = *columnDisplayOrder[i]; ColumnC *column = columnList[id]; if ( !column->visible ) continue; FieldC& title = column->title; if ( title.height == 0 ) GetTitleSize(title); column->curWd = title.width; if ( title.height > maxTitleHt ) maxTitleHt = title.height; } // End for each column//// Loop through items// daHt = 0; daWd = 0; maxPmWd = 0; int extra = (hlThick + itemMarginHt) * 2 + ySpacing; VItemListC& visItems = viewBox->VisItems(); unsigned icount = visItems.size(); for (i=0; i<icount; i++) { VItemC *item = visItems[i]; ItemDataC *data = (ItemDataC *)item->ViewData(); if ( !DataValid(data) ) continue;//// Get the item size// if ( data->itemHt == 0 ) GetFieldSizes(data);//// Update the pixmap size width// if ( showPixmaps && data->pixmap && data->pixmap->wd > maxPmWd ) maxPmWd = data->pixmap->wd;//// Update the column widths// for (int j=0; j<ccount; j++) { int pos = *columnDisplayOrder[j]; ColumnC *column = columnList[pos]; if ( !column->visible || pos < 0 || pos >= data->fieldList.size() ) continue; FieldC *field = data->fieldList[pos]; if ( field->width > column->curWd ) column->curWd = field->width; } // End for each column//// Update the drawing area height// daHt += data->itemHt + extra; } // End for each view item daHt -= ySpacing;//// Get the overall area width// extra = (itemMarginWd*2) + sepThick; daWd = (itemMarginWd + hlThick) * 2; daWd += maxPmWd; for (i=0; i<ccount; i++) { int id = *columnDisplayOrder[i]; ColumnC *column = columnList[id]; if ( !column->visible ) continue; daWd += column->Width() + extra; }//// Loop through the items and set their bounds// extra = (hlThick + itemMarginHt) * 2; int x = 0; int y = 0; for (i=0; i<icount; i++) { VItemC *item = visItems[i]; ItemDataC *data = (ItemDataC *)item->ViewData(); if ( !DataValid(data) ) continue; int ht = data->itemHt + extra; data->bounds.Set(x, y, daWd, ht); y += ht + ySpacing; } // End for each visible item needPlaces = False;} // End PlaceItems/*----------------------------------------------------------------------- * Return size */voidFieldViewC::GetSize(int *wd, int *ht){ *wd = daWd; *ht = daHt;}/*----------------------------------------------------------------------- * Public method to add a new item to this view box */voidFieldViewC::AddItem(VItemC& item){ if ( !viewBox->Realized() ) return;//// Add the item// _AddItem(item);//// Redraw if necessary// viewBox->Changed(True);} // End AddItem/*----------------------------------------------------------------------- * Add new items to this view */voidFieldViewC::AddItems(const VItemListC& list){ if ( !viewBox->Realized() ) return;//// Add items// unsigned count = list.size(); for (int i=0; i<count; i++) _AddItem(*list[i]); viewBox->Changed(True);} // End AddItems/*----------------------------------------------------------------------- * Private method to add a new item to this view box
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -