📄 buttprefwinc.c
字号:
/* * $Id: ButtPrefWinC.C,v 1.2 2000/05/07 12:26:11 fnevgeny Exp $ * * Copyright (c) 1994 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 "ButtPrefWinC.h"#include "ButtonMgrC.h"#include "ButtonEditWinC.h"#include <hgl/WArgList.h>#include <hgl/WXmString.h>#include <hgl/rsrc.h>#include <hgl/HalAppC.h>#include <hgl/RegexC.h>#include <hgl/TextMisc.h>#include <hgl/RowColC.h>#include <hgl/ButtonBox.h>#include <hgl/StringListC.h>#include <Xm/Form.h>#include <Xm/Label.h>#include <Xm/CascadeB.h>#include <Xm/PushB.h>#include <Xm/Frame.h>#include <Xm/ToggleB.h>#include <Xm/TextF.h>#include <Xm/PanedW.h>#include <Xm/ArrowB.h>#include <Xm/List.h>#include <Xm/AtomMgr.h>#include <X11/Xmu/Xct.h>extern int debuglev;/*------------------------------------------------------------------------ * Function used to sort the entries by name. */static intSortByLabel(const void *a, const void *b){ ButtonEntryC *ba = *(ButtonEntryC **)a; ButtonEntryC *bb = *(ButtonEntryC **)b; return ba->label.compare(bb->label);}/*------------------------------------------------------------------------ * Function used to sort the entries by position index. */static intSortByIndex(const void *a, const void *b){ ButtonEntryC *ba = *(ButtonEntryC **)a; ButtonEntryC *bb = *(ButtonEntryC **)b; if ( ba->posIndex > bb->posIndex ) return 1; if ( ba->posIndex < bb->posIndex ) return -1; return 0;}/*--------------------------------------------------------------- * Main window constructor */ButtPrefWinC::ButtPrefWinC(Widget par, ButtonMgrC *mgr) : OptWinC(par, "buttonWin"){ WArgList args; Widget wlist[10]; buttMgr = NULL; editWin = NULL; buttMgrList.AllowDuplicates(False); availList.AllowDuplicates(FALSE); availList.SetSorted(FALSE); AddManager(mgr);//// Create appForm hierarchy//// appForm// PanedWindow panedWin// args.Reset(); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.TopAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); Widget panedWin = XmCreatePanedWindow(appForm, "panedWin", ARGS);//// Create panedWin hierarchy//// panedWin// Form availForm// Form arrowForm// Form usedForm// Form placeForm// Widget availForm = XmCreateForm(panedWin, "availForm", 0,0); arrowForm = XmCreateForm(panedWin, "arrowForm", 0,0); Widget usedForm = XmCreateForm(panedWin, "userForm", 0,0); args.Reset(); args.AllowResize(True); placeForm = XmCreateForm(panedWin, "placeForm", ARGS);//// Create availForm hierarchy//// availForm// Label availTitle// List availListW// args.Reset(); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.TopAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_NONE); args.Alignment(XmALIGNMENT_BEGINNING); Widget availTitle = XmCreateLabel(availForm, "availTitle", ARGS); XtManageChild(availTitle); args.Reset(); args.TopAttachment(XmATTACH_WIDGET, availTitle); args.BottomAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.SelectionPolicy(XmEXTENDED_SELECT); args.ListSizePolicy(XmCONSTANT); args.UserData(this); availListW = XmCreateScrolledList(availForm, "availList", ARGS); XtManageChild(availListW); XtAddCallback(availListW, XmNextendedSelectionCallback, (XtCallbackProc)SelectAvail, (XtPointer)this);//// Create arrowForm hierarchy//// arrowForm// ArrowButton addAB// ArrowButton remAB// args.Reset(); args.ArrowDirection(XmARROW_DOWN); args.TopAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_NONE); args.RightAttachment(XmATTACH_POSITION, 50); addAB = XmCreateArrowButton(arrowForm, "addAB", ARGS); args.ArrowDirection(XmARROW_UP); args.LeftAttachment(XmATTACH_POSITION, 50); args.RightAttachment(XmATTACH_NONE); remAB = XmCreateArrowButton(arrowForm, "remAB", ARGS); XtSetSensitive(addAB, False); XtSetSensitive(remAB, False); XtAddCallback(addAB, XmNactivateCallback, (XtCallbackProc)HandleAdd, (XtPointer)this); XtAddCallback(remAB, XmNactivateCallback, (XtCallbackProc)HandleRem, (XtPointer)this); wlist[0] = addAB; wlist[1] = remAB; XtManageChildren(wlist, 2);//// Create usedForm hierarchy//// usedForm// Label usedTitle// List usedListW// args.Reset(); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.TopAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_NONE); args.Alignment(XmALIGNMENT_BEGINNING); Widget usedTitle = XmCreateLabel(usedForm, "userTitle", ARGS); XtManageChild(usedTitle); args.Reset(); args.TopAttachment(XmATTACH_WIDGET, usedTitle); args.BottomAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.SelectionPolicy(XmEXTENDED_SELECT); args.ListSizePolicy(XmCONSTANT); args.UserData(this); usedListW = XmCreateScrolledList(usedForm, "userList", ARGS); XtManageChild(usedListW); XtAddCallback(usedListW, XmNextendedSelectionCallback, (XtCallbackProc)SelectUsed, (XtPointer)this); XtAddCallback(usedListW, XmNdefaultActionCallback, (XtCallbackProc)HandleEdit, (XtPointer)this);//// Create placeForm hierarchy//// placeForm// Label placeTitle// Frame gravFrame// ToggleButton sameSizeTB// args.Reset(); args.TopAttachment(XmATTACH_NONE); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_FORM); Widget gravFrame = XmCreateFrame(placeForm, "gravFrame", ARGS); args.Reset(); args.TopAttachment(XmATTACH_NONE); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_OPPOSITE_WIDGET, gravFrame); args.BottomAttachment(XmATTACH_WIDGET, gravFrame); Widget placeTitle = XmCreateLabel(placeForm, "placeTitle", ARGS); args.Reset(); args.TopAttachment(XmATTACH_OPPOSITE_WIDGET, gravFrame); args.LeftAttachment(XmATTACH_WIDGET, gravFrame); args.RightAttachment(XmATTACH_NONE); args.BottomAttachment(XmATTACH_NONE); sameSizeTB = XmCreateToggleButton(placeForm, "sameSizeTB", ARGS);//// Create gravFrame hierarchy//// gravFrame// RowColC gravRC// gravRC = new RowColC(gravFrame, "gravRC", 0,0);//// Set up 3 Columns// gravRC->Defer(True); gravRC->SetOrientation(RcROW_MAJOR); gravRC->SetColCount(3); gravRC->SetColAlignment(XmALIGNMENT_CENTER); gravRC->SetColWidthAdjust(RcADJUST_EQUAL); gravRC->SetColResize(False);//// Create gravRC hierarchy//// gravRC// ToggleButton northTB// ToggleButton westTB// ToggleButton eastTB// ToggleButton southTB// args.Reset(); args.IndicatorType(XmONE_OF_MANY); northTB = XmCreateToggleButton(*gravRC, "northTB", ARGS); westTB = XmCreateToggleButton(*gravRC, "westTB", ARGS); eastTB = XmCreateToggleButton(*gravRC, "eastTB", ARGS); southTB = XmCreateToggleButton(*gravRC, "southTB", ARGS); XtAddCallback(northTB, XmNvalueChangedCallback, (XtCallbackProc)DoNorth, (XtPointer)this); XtAddCallback(westTB, XmNvalueChangedCallback, (XtCallbackProc)DoWest, (XtPointer)this); XtAddCallback(eastTB, XmNvalueChangedCallback, (XtCallbackProc)DoEast, (XtPointer)this); XtAddCallback(southTB, XmNvalueChangedCallback, (XtCallbackProc)DoSouth, (XtPointer)this); wlist[0] = northTB; wlist[1] = westTB; wlist[2] = eastTB; wlist[3] = southTB; XtManageChildren(wlist, 4); // gravRC children XtManageChild(*gravRC); wlist[0] = NULL; wlist[1] = northTB; wlist[2] = NULL; wlist[3] = westTB; wlist[4] = NULL; wlist[5] = eastTB; wlist[6] = NULL; wlist[7] = southTB; wlist[8] = NULL; gravRC->SetChildren(wlist, 9); gravRC->Defer(False); wlist[0] = gravFrame; wlist[1] = placeTitle; wlist[2] = sameSizeTB; XtManageChildren(wlist, 3); // placeForm children wlist[0] = availForm; wlist[1] = arrowForm; wlist[2] = usedForm; wlist[3] = placeForm; XtManageChildren(wlist, 4); // panedWin children XtManageChild(panedWin); // appForm children//// Build list of buttons// Widget helpCB; WidgetList cbList; Cardinal cbCount; XtVaGetValues(mgr->MenuBar(), XmNmenuHelpWidget, &helpCB, XmNnumChildren, &cbCount, XmNchildren, &cbList, NULL); if ( debuglev > 1 ) cout <<"Found " <<cbCount <<" children in menu bar" NL;//// Look for cascade buttons// StringC labStr; for (int i=0; i<cbCount; i++) { Widget cb = cbList[i]; if ( debuglev > 1 ) cout <<"Checking menu bar widget " <<XtName(cb) NL;//// Ignore non-cascade buttons and the help button// if ( cb != helpCB && XmIsCascadeButton(cb) ) { labStr = get_string(cb, XmNlabelString); ProcessCascade(cb, labStr); } } // End for each menuBar child HandleHelp();//// Sort the available button list alphabetically// availList.sort(SortByLabel);//// Set up drag-and-drop// XmDropSiteUnregister(availListW); XmDropSiteUnregister(usedListW); Atom impAtoms[1]; impAtoms[0] = XmInternAtom(halApp->display, "COMPOUND_TEXT", False); args.Reset(); args.ImportTargets(impAtoms); args.NumImportTargets(1); args.DropProc((XtCallbackProc)HandleDrop); XmDropSiteRegister(availListW, ARGS); XmDropSiteRegister(usedListW, ARGS);//// Prepare for final initialization// XtAddCallback(shell, XmNpopupCallback, (XtCallbackProc)DoPopup, (XtPointer)this);} // End constructor/*--------------------------------------------------------------- * Main window destructor */ButtPrefWinC::~ButtPrefWinC(){ unsigned count = availList.size(); int i; for (i=0; i<count; i++) delete availList[i]; count = usedList.size(); for (i=0; i<count; i++) delete usedList[i]; delete gravRC; delete editWin;}/*--------------------------------------------------------------- * Method to look at widgets in cascade button hierarchy */voidButtPrefWinC::ProcessCascade(Widget cb, StringC label){//// Get the button name and the pulldown menu widget// Widget pd; XtVaGetValues(cb, XmNsubMenuId, &pd, NULL); if ( debuglev > 1 ) cout <<"Found pulldown: " <<XtName(pd) <<" for cascade: " <<label NL; if ( !pd ) return;//// Get the children of the pulldown menu// WidgetList pdList; Cardinal pdCount; XtVaGetValues(pd, XmNnumChildren, &pdCount, XmNchildren, &pdList, NULL); if ( debuglev > 1 ) cout <<"Found " <<pdCount <<" children in pulldown" NL;//// Look for push buttons and cascade buttons// StringC title; for (int i=0; i<pdCount; i++) { Widget w = pdList[i]; if ( debuglev > 1 ) cout <<"Checking pulldown widget " <<XtName(w) NL; if ( !XmIsLabel(w) ) continue; title = label; title += "/"; title += get_string(w, XmNlabelString); if ( XmIsCascadeButton(w) ) {//// Skip special cases of quick and recent folder menus. These contents of// these menus are continually changing and there would be no point in// offering custom buttons for them.// StringC name = XtName(w); if ( !name.EndsWith("RecentCB") && !name.EndsWith("QuickCB") ) ProcessCascade(w, title); } else if ( XmIsPushButton(w) ) { StringC abbrev = get_string(w, "abbrev", title); ButtonEntryC *be = new ButtonEntryC(XtName(w), title, abbrev);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -