/* * wSelect.c * * Handling a selection in a template window * * © 1994-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Glass. * * Glass 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, or (at your option) * any later version. * * Glass 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. * * You should have received a copy of the GNU General Public License * along with Glass. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*----- Header files ------------------------------------------------------*/ /* * ANSI standard headers */ #include #include #include /* * Steel headers */ #define _STDAPP #define _LOWLVL #include "steel/Steel.h" /* * Glass headers */ #include "gStruct.h" #include "gMenus.h" #include "gIcons.h" #include "glass.h" #include "gPrefs.h" #include "window.h" #include "_window.h" #include "intMsgs.h" #include "toolbox.h" #include "editIcon.h" #include "editWin.h" #include "indir.h" #include "align.h" #include "iconData.h" #include "tearEdit.h" /*----- Private variables -------------------------------------------------*/ static glass_windPointer *window__selOwner; /* The window that owns the */ /* current selection. */ static int window__selIcon=-1; /* The main currently selected icon */ /*----- Main code ---------------------------------------------------------*/ /* * void window__updateSelectBox(glass_windPointer *w,int icon,BOOL makesi) * * Use * Updates the select box around the specified icon. * * Parameters * glass_windPointer *w == the window containing the icon * int icon == the icon number whose selection border we change * BOOL makesi == whether to change the border from main sel to normal sel */ static void window__updateSelectBox(glass_windPointer *w, int icon, BOOL makesi) { wimp_redrawstr r; BOOL more; r.w=w->h; window_boundingBox(w,icon,&r.box); r.box.x0-=window__HANDLEWIDTH+16; r.box.x1+=window__HANDLEWIDTH+16; r.box.y0-=window__HANDLEWIDTH+16; r.box.y1+=window__HANDLEWIDTH+16; wimpt_noerr(wimp_update_wind(&r,&more)); while (more) { window__drawSelectBox(w,icon,makesi,&r); wimpt_noerr(wimp_get_rectangle(&r,&more)); } } /* * void window__select(glass_windPointer *w,int icon,BOOL sel) * * Use * Selects or deselects the given icon. * * Parameters * glass_windPointer *w == the window we're talking about * int icon == the icon to select (or not) * BOOL sel == TRUE to select, FALSE to deslect */ void window__select(glass_windPointer *w,int icon,BOOL sel) { /* --- Make sure there's something sensible to do --- */ if (icon==-1) return; if (w->def->i[icon].selected==sel) return; if (w->def->i[icon].i.flags & wimp_IDELETED) return; /* --- Update the selection counter --- */ if (sel) w->selno++; else w->selno--; w->def->i[icon].selected=sel; /* --- In test mode you can't see the selection rectangles --- */ #ifndef glass_DEMO if (w->testMode) { if (icon==window__selIcon && w==window__selOwner && !sel) window__selIcon=-1; return; } #endif /* --- Draw the selection boxes around the icons --- * * * It doesn't matter whether we're drawing or undrawing -- seeing as we're * using XOR plotting for the rectangles, and we know that the seleciton * state has changed, we just draw the selection boxes straight over the * top. */ window__updateSelectBox(w,icon,FALSE); if (icon==window__selIcon && w==window__selOwner && !sel) { window__selIcon=-1; tearEdit_update(w,-1); } } /* * void window__setSelectedIcon(int i) * * Use * Makes the specified icon in the current selection owner highlighted. * * Parameters * int i == the icon number to highlight */ void window__setSelectedIcon(int i) { int o=window__selIcon; if (i==o) return; if (o!=-1) window__updateSelectBox(window__selOwner,o,TRUE); window__selIcon=i; if (i!=-1) { if (window__selOwner->def->i[i].selected) window__updateSelectBox(window__selOwner,i,TRUE); else window__select(window__selOwner,i,TRUE); } tearEdit_update(window__selOwner,i); } /* * void window__setSelectedIconDeselecting(int i) * * Use * Sets up the currently selected icon, deselecting the old one. * * Parameters * int i == the new icon to select */ void window__setSelectedIconDeselecting(int i) { int o=window__selIcon; if (o==i) return; else if (o==-1 || i==-1) window__setSelectedIcon(i); else { /* --- To prevent flickering, we must do all the work here --- */ window__updateSelectBox(window__selOwner,o,FALSE); window__selOwner->def->i[o].selected=FALSE; window__selIcon=i; if (window__selOwner->def->i[i].selected) window__updateSelectBox(window__selOwner,i,TRUE); else window__updateSelectBox(window__selOwner,i,FALSE); window__selOwner->def->i[i].selected=TRUE; tearEdit_update(window__selOwner,i); } } /* * int window__lowestSelected(glass_windPointer *w) * * Use * Returns the selected icon with the lowest number in the specified window. */ int window__lowestSelected(glass_windPointer *w) { int i; for (i=0;idef->desc.w.nicons;i++) { if (w->def->i[i].selected) return (i); } return (-1); } /* * void window__gainSelection(glass_windPointer *w) * * Use * Gives the specified window the input focus, tool and info bars, and the * selection. If 0 is specified, then the tool bars are taken down, and no * selection is set. * * Parameters * glass_windPointer *w == the new selection owner */ void window__gainSelection(glass_windPointer *w) { int i; wimp_caretstr c; if (w) { c.w=w->h; c.i=-1; c.x=w->def->desc.w.ex.x0-50; c.y=0; c.height=0x02000000; c.index=-1; wimpt_noerr(wimp_set_caret_pos(&c)); } if (window__selOwner==w) return; if (w) window__renumber(w,FALSE); if (window__selOwner!=0) { for (i=0;idef->desc.w.nicons;i++) window__select(window__selOwner,i,FALSE); for (i=0;iguide[i].selected) { window__selOwner->guide[i].selected=FALSE; window__redrawGuide(window__selOwner,i); } } } window__selOwner=w; window__moveToolbars(w); } /* * glass_windPointer *window_selectionOwner(void) * * Use * Returns the window currently owning the selection. */ glass_windPointer *window_selectionOwner(void) { return (window__selOwner); } /* * int window__selectedIcon(void) * * Use * Returns the currently selected icon */ int window__selectedIcon(void) { return (window__selIcon); } /* * void window__renumberSelectedIcon(int nsel) * * Use * To be called when the selected icon is renumbered. */ void window__renumberSelectedIcon(int nsel) { window__selIcon=nsel; tearEdit_update(window__selOwner,window__selIcon); }