diff options
Diffstat (limited to 'app/bin/dlayer.c')
-rw-r--r-- | app/bin/dlayer.c | 658 |
1 files changed, 562 insertions, 96 deletions
diff --git a/app/bin/dlayer.c b/app/bin/dlayer.c index 352dbe1..e5fed61 100644 --- a/app/bin/dlayer.c +++ b/app/bin/dlayer.c @@ -20,19 +20,17 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <assert.h> -#include <stdbool.h> -#include <stdint.h> -#include <string.h> - +#include "cselect.h" #include "custom.h" +#include "paths.h" #include "dynstring.h" #include "fileio.h" -#include "i18n.h" #include "layout.h" -#include "messages.h" #include "param.h" #include "track.h" +#include "include/partcatalog.h" +#include "include/stringxtc.h" +#include "common-ui.h" /***************************************************************************** * @@ -45,10 +43,13 @@ #define LAYERPREF_ONMAP (2) #define LAYERPREF_VISIBLE (4) #define LAYERPREF_MODULE (8) +#define LAYERPREF_NOBUTTON (16) #define LAYERPREF_SECTION ("Layers") #define LAYERPREF_NAME "name" #define LAYERPREF_COLOR "color" #define LAYERPREF_FLAGS "flags" +#define LAYERPREF_LIST "list" +#define LAYERPREF_SETTINGS "settings" unsigned int curLayer; long layerCount = 10; @@ -73,12 +74,17 @@ typedef struct { BOOL_T visible; /**< visible flag */ BOOL_T onMap; /**< is layer shown map */ BOOL_T module; /**< is layer a module (all or nothing) */ + BOOL_T button_off; /**< hide button */ long objCount; /**< number of objects on layer */ + dynArr_t layerLinkList; /**< other layers that show/hide with this one */ + char settingsName[STR_SHORT_SIZE]; /**< name of settings file to load when this is current */ } layer_t; static layer_t layers[NUM_LAYERS]; static layer_t *layers_save = NULL; +static Catalog * settingsCatalog; + static int oldColorMap[][3] = { { 255, 255, 255 }, /* White */ @@ -140,7 +146,7 @@ static int oldColorMap[][3] = { }; static void DoLayerOp(void * data); -static void UpdateLayerDlg(void); +void UpdateLayerDlg(unsigned int); static void InitializeLayers(void LayerInitFunc(void), int newCurrLayer); static void LayerPrefSave(void); @@ -148,7 +154,7 @@ static void LayerPrefLoad(void); int IsLayerValid(unsigned int layer) { - return (layer <= NUM_LAYERS); + return (layer <= NUM_LAYERS && layer != -1); } BOOL_T GetLayerVisible(unsigned int layer) @@ -160,6 +166,15 @@ BOOL_T GetLayerVisible(unsigned int layer) } } +BOOL_T GetLayerHidden(unsigned int layer) +{ + if (!IsLayerValid(layer)) { + return TRUE; + } else { + return layers[layer].button_off; + } +} + BOOL_T GetLayerFrozen(unsigned int layer) { @@ -227,8 +242,9 @@ static void RedrawLayer( unsigned int l, BOOL_T draw ) } -static void FlipLayer(unsigned int layer) +EXPORT void FlipLayer( void * layerVP ) { + unsigned int layer = (unsigned int)VP2L(layerVP); wBool_t visible; if (!IsLayerValid(layer)) { @@ -236,7 +252,8 @@ static void FlipLayer(unsigned int layer) } if (layer == curLayer && layers[layer].visible) { - wButtonSetBusy(layer_btns[layer], layers[layer].visible); + if (!layers[layer].button_off) + wButtonSetBusy(layer_btns[layer], layers[layer].visible); NoticeMessage(MSG_LAYER_HIDE, _("Ok"), NULL); return; } @@ -246,13 +263,26 @@ static void FlipLayer(unsigned int layer) layers[layer].visible = visible; if (layer<NUM_BUTTONS) { - wButtonSetBusy(layer_btns[layer], visible != 0); - wButtonSetLabel(layer_btns[layer], (char *)show_layer_bmps[layer]); + if (!layers[layer].button_off) { + wButtonSetBusy(layer_btns[layer], visible != 0); + wButtonSetLabel(layer_btns[layer], (char *)show_layer_bmps[layer]); + } } + /* Set visible on related layers other than current */ + for (int i=0;i<layers[layer].layerLinkList.cnt;i++) { + int l = DYNARR_N(int,layers[layer].layerLinkList,i)-1; + if ((l != curLayer) && (l >=0) && (l < NUM_LAYERS)) { + layers[l].visible = layers[layer].visible; + if (!layers[l].button_off) + wButtonSetBusy(layer_btns[l], layers[l].visible); + } + } + RedrawLayer(layer, TRUE); } +static char lastSettings[STR_SHORT_SIZE]; void SetCurrLayer(wIndex_t inx, const char * name, wIndex_t op, void * listContext, void * arg) { @@ -264,16 +294,44 @@ void SetCurrLayer(wIndex_t inx, const char * name, wIndex_t op, return; } + char *array[1]; + if (!layers[inx].settingsName[0] || strcmp(layers[inx].settingsName," ")==0) { + if (lastSettings[0]) { + DoSettingsRead(1,NULL, NULL); + } + lastSettings[0] = '\0'; + } else { + if (strcmp(layers[inx].settingsName,lastSettings)!=0) { + if (!lastSettings[0]) wPrefFlush(""); // Save Last Settings for no settings file + array[0] = layers[inx].settingsName; + DoSettingsRead(1,array, NULL); + } + strcpy(lastSettings,layers[inx].settingsName); + } + + curLayer = newLayer; if (!IsLayerValid(curLayer)) { - curLayer = 0; + curLayer = 0; //Too big or -1 + layers[curLayer].frozen = FALSE; //Make sure the layer is not frozen } + if (!layers[curLayer].visible) { - FlipLayer(inx); + FlipLayer(I2VP(inx)); } + /* Set visible on related layers other than current */ + for (int i=0;i<layers[curLayer].layerLinkList.cnt;i++) { + int l = DYNARR_N(int,layers[curLayer].layerLinkList,i)-1; + if (l != curLayer && l >=0 && l < NUM_LAYERS) { + layers[l].visible = layers[curLayer].visible; + if (!layers[l].button_off) + wButtonSetBusy(layer_btns[l], layers[l].visible); + } + } + if (recordF) { fprintf(recordF, "SETCURRLAYER %d\n", inx); } @@ -307,6 +365,17 @@ static void SetLayerColor(unsigned int inx, wDrawColor color) } } +static void SetLayerHideButton(unsigned int inx, wBool_t hide) { + if (hide != layers[inx].button_off) { + if (inx < NUM_BUTTONS) { + wControlShow((wControl_p)layer_btns[inx],!hide); + if (!hide) wButtonSetBusy(layer_btns[inx], layers[inx].visible); + } + layers[inx].button_off = hide; + layoutLayerChanged = TRUE; + } +} + char * FormatLayerName(unsigned int layerNumber) { @@ -316,13 +385,15 @@ FormatLayerName(unsigned int layerNumber) DynStringPrintf(&string, "%2d %c %s", layerNumber + 1, - (layers[layerNumber].objCount > 0 ? '+' : '-'), + (layers[layerNumber].frozen ? '*': layers[layerNumber].module ? 'm': layers[layerNumber].objCount > 0 ? '+' : '-'), layers[layerNumber].name); result = strdup(DynStringToCStr(&string)); DynStringFree(&string); return result; } +static int lbits_width[3] = {14,20,26}; +static int lbits_height[3] = {16,24,32}; #include "bitmaps/l1.xbm" #include "bitmaps/l2.xbm" @@ -425,17 +496,37 @@ FormatLayerName(unsigned int layerNumber) #include "bitmaps/l99.xbm" -static char * show_layer_bits[NUM_BUTTONS] = { - l1_bits, l2_bits, l3_bits, l4_bits, l5_bits, l6_bits, l7_bits, l8_bits, l9_bits, l10_bits, - l11_bits, l12_bits, l13_bits, l14_bits, l15_bits, l16_bits, l17_bits, l18_bits, l19_bits, l20_bits, - l21_bits, l22_bits, l23_bits, l24_bits, l25_bits, l26_bits, l27_bits, l28_bits, l29_bits, l30_bits, - l31_bits, l32_bits, l33_bits, l34_bits, l35_bits, l36_bits, l37_bits, l38_bits, l39_bits, l40_bits, - l41_bits, l42_bits, l43_bits, l44_bits, l45_bits, l46_bits, l47_bits, l48_bits, l49_bits, l50_bits, - l51_bits, l52_bits, l53_bits, l54_bits, l55_bits, l56_bits, l57_bits, l58_bits, l59_bits, l60_bits, - l61_bits, l62_bits, l63_bits, l64_bits, l65_bits, l66_bits, l67_bits, l68_bits, l69_bits, l70_bits, - l71_bits, l72_bits, l73_bits, l74_bits, l75_bits, l76_bits, l77_bits, l78_bits, l79_bits, l80_bits, - l81_bits, l82_bits, l83_bits, l84_bits, l85_bits, l86_bits, l87_bits, l88_bits, l89_bits, l90_bits, - l91_bits, l92_bits, l93_bits, l94_bits, l95_bits, l96_bits, l97_bits, l98_bits, l99_bits, +static char * show_layer_bits[3][NUM_BUTTONS] = { + { l1_x16, l2_x16, l3_x16, l4_x16, l5_x16, l6_x16, l7_x16, l8_x16, l9_x16, l10_x16, + l11_x16, l12_x16, l13_x16, l14_x16, l15_x16, l16_x16, l17_x16, l18_x16, l19_x16, l20_x16, + l21_x16, l22_x16, l23_x16, l24_x16, l25_x16, l26_x16, l27_x16, l28_x16, l29_x16, l30_x16, + l31_x16, l32_x16, l33_x16, l34_x16, l35_x16, l36_x16, l37_x16, l38_x16, l39_x16, l40_x16, + l41_x16, l42_x16, l43_x16, l44_x16, l45_x16, l46_x16, l47_x16, l48_x16, l49_x16, l50_x16, + l51_x16, l52_x16, l53_x16, l54_x16, l55_x16, l56_x16, l57_x16, l58_x16, l59_x16, l60_x16, + l61_x16, l62_x16, l63_x16, l64_x16, l65_x16, l66_x16, l67_x16, l68_x16, l69_x16, l70_x16, + l71_x16, l72_x16, l73_x16, l74_x16, l75_x16, l76_x16, l77_x16, l78_x16, l79_x16, l80_x16, + l81_x16, l82_x16, l83_x16, l84_x16, l85_x16, l86_x16, l87_x16, l88_x16, l89_x16, l90_x16, + l91_x16, l92_x16, l93_x16, l94_x16, l95_x16, l96_x16, l97_x16, l98_x16, l99_x16, }, + { l1_x24, l2_x24, l3_x24, l4_x24, l5_x24, l6_x24, l7_x24, l8_x24, l9_x24, l10_x24, + l11_x24, l12_x24, l13_x24, l14_x24, l15_x24, l16_x24, l17_x24, l18_x24, l19_x24, l20_x24, + l21_x24, l22_x24, l23_x24, l24_x24, l25_x24, l26_x24, l27_x24, l28_x24, l29_x24, l30_x24, + l31_x24, l32_x24, l33_x24, l34_x24, l35_x24, l36_x24, l37_x24, l38_x24, l39_x24, l40_x24, + l41_x24, l42_x24, l43_x24, l44_x24, l45_x24, l46_x24, l47_x24, l48_x24, l49_x24, l50_x24, + l51_x24, l52_x24, l53_x24, l54_x24, l55_x24, l56_x24, l57_x24, l58_x24, l59_x24, l60_x24, + l61_x24, l62_x24, l63_x24, l64_x24, l65_x24, l66_x24, l67_x24, l68_x24, l69_x24, l70_x24, + l71_x24, l72_x24, l73_x24, l74_x24, l75_x24, l76_x24, l77_x24, l78_x24, l79_x24, l80_x24, + l81_x24, l82_x24, l83_x24, l84_x24, l85_x24, l86_x24, l87_x24, l88_x24, l89_x24, l90_x24, + l91_x24, l92_x24, l93_x24, l94_x24, l95_x24, l96_x24, l97_x24, l98_x24, l99_x24, }, + { l1_x32, l2_x32, l3_x32, l4_x32, l5_x32, l6_x32, l7_x32, l8_x32, l9_x32, l10_x32, + l11_x32, l12_x32, l13_x32, l14_x32, l15_x32, l16_x32, l17_x32, l18_x32, l19_x32, l20_x32, + l21_x32, l22_x32, l23_x32, l24_x32, l25_x32, l26_x32, l27_x32, l28_x32, l29_x32, l30_x32, + l31_x32, l32_x32, l33_x32, l34_x32, l35_x32, l36_x32, l37_x32, l38_x32, l39_x32, l40_x32, + l41_x32, l42_x32, l43_x32, l44_x32, l45_x32, l46_x32, l47_x32, l48_x32, l49_x32, l50_x32, + l51_x32, l52_x32, l53_x32, l54_x32, l55_x32, l56_x32, l57_x32, l58_x32, l59_x32, l60_x32, + l61_x32, l62_x32, l63_x32, l64_x32, l65_x32, l66_x32, l67_x32, l68_x32, l69_x32, l70_x32, + l71_x32, l72_x32, l73_x32, l74_x32, l75_x32, l76_x32, l77_x32, l78_x32, l79_x32, l80_x32, + l81_x32, l82_x32, l83_x32, l84_x32, l85_x32, l86_x32, l87_x32, l88_x32, l89_x32, l90_x32, + l91_x32, l92_x32, l93_x32, l94_x32, l95_x32, l96_x32, l97_x32, l98_x32, l99_x32, } }; @@ -456,13 +547,16 @@ static wDrawColor layerColorTab[COUNT(layerRawColorTab)]; static wWin_p layerW; static char layerName[STR_SHORT_SIZE]; +static char layerLinkList[STR_LONG_SIZE]; +static char settingsName[STR_SHORT_SIZE]; static wDrawColor layerColor; static long layerUseColor = TRUE; static long layerVisible = TRUE; static long layerFrozen = FALSE; static long layerOnMap = TRUE; static long layerModule = FALSE; -static void LayerOk(void *); +static long layerNoButton = FALSE; +static void LayerOk(void * unused); static BOOL_T layerRedrawMap = FALSE; #define ENUMLAYER_RELOAD (1) @@ -475,12 +569,13 @@ static char *onMapLabels[] = { "", NULL }; static char *moduleLabels[] = { "", NULL }; static char *layerColorLabels[] = { "", NULL }; static paramIntegerRange_t i0_20 = { 0, NUM_BUTTONS }; +static paramListData_t layerUiListData = { 10, 370, 0 }; static paramData_t layerPLs[] = { #define I_LIST (0) - { PD_DROPLIST, NULL, "layer", PDO_LISTINDEX|PDO_DLGNOLABELALIGN, (void*)250 }, + { PD_DROPLIST, NULL, "layer", PDO_LISTINDEX, I2VP(250), N_("Select Layer:") }, #define I_NAME (1) - { PD_STRING, layerName, "name", PDO_NOPREF|PDO_STRINGLIMITLENGTH, (void*)(250-54), N_("Name"), 0, 0, sizeof(layerName) }, + { PD_STRING, layerName, "name", PDO_NOPREF|PDO_STRINGLIMITLENGTH, I2VP(250-54), N_("Name"), 0, 0, sizeof(layerName) }, #define I_COLOR (2) { PD_COLORLIST, &layerColor, "color", PDO_NOPREF, NULL, N_("Color") }, #define I_USE_COLOR (3) @@ -493,19 +588,116 @@ static paramData_t layerPLs[] = { { PD_TOGGLE, &layerOnMap, "onmap", PDO_NOPREF|PDO_DLGHORZ, onMapLabels, N_("On Map"), BC_HORZ|BC_NOBORDER }, #define I_MOD (7) { PD_TOGGLE, &layerModule, "module", PDO_NOPREF|PDO_DLGHORZ, moduleLabels, N_("Module"), BC_HORZ|BC_NOBORDER }, -#define I_COUNT (8) - { PD_STRING, NULL, "object-count", PDO_NOPREF|PDO_DLGBOXEND, (void*)(80), N_("Count"), BO_READONLY }, - { PD_MESSAGE, N_("Personal Preferences"), NULL, PDO_DLGRESETMARGIN, (void *)180 }, - { PD_BUTTON, (void*)DoLayerOp, "reset", PDO_DLGRESETMARGIN, 0, N_("Load"), 0, (void *)ENUMLAYER_RELOAD }, - { PD_BUTTON, (void*)DoLayerOp, "save", PDO_DLGHORZ, 0, N_("Save"), 0, (void *)ENUMLAYER_SAVE }, - { PD_BUTTON, (void*)DoLayerOp, "clear", PDO_DLGHORZ | PDO_DLGBOXEND, 0, N_("Defaults"), 0, (void *)ENUMLAYER_CLEAR }, +#define I_BUT (8) + { PD_TOGGLE, &layerNoButton, "button", PDO_NOPREF|PDO_DLGHORZ, moduleLabels, N_("No Button"), BC_HORZ|BC_NOBORDER }, +#define I_LINKLIST (9) + { PD_STRING, layerLinkList, "layerlist", PDO_NOPREF|PDO_STRINGLIMITLENGTH, I2VP(250-54), N_("Linked Layers"), 0, 0, sizeof(layerLinkList) }, +#define I_SETTINGS (10) + { PD_DROPLIST, NULL, "settings", PDO_LISTINDEX, I2VP( 250), N_("Settings when Current") }, +#define I_COUNT (11) + { PD_MESSAGE, N_("Object Count:"), NULL, PDO_DLGBOXEND|PDO_DLGNOLABELALIGN, I2VP(370) }, + { PD_MESSAGE, N_("All Layer Preferences"), NULL, PDO_DLGRESETMARGIN, I2VP(180) }, + { PD_BUTTON, DoLayerOp, "load", PDO_DLGRESETMARGIN, 0, N_("Load"), 0, I2VP(ENUMLAYER_RELOAD) }, + { PD_BUTTON, DoLayerOp, "save", PDO_DLGHORZ, 0, N_("Save"), 0, I2VP(ENUMLAYER_SAVE) }, + { PD_BUTTON, DoLayerOp, "clear", PDO_DLGHORZ | PDO_DLGBOXEND, 0, N_("Defaults"), 0, I2VP(ENUMLAYER_CLEAR) }, { PD_LONG, &newLayerCount, "button-count", PDO_DLGBOXEND|PDO_DLGRESETMARGIN, &i0_20, N_("Number of Layer Buttons") }, }; -static paramGroup_t layerPG = { "layer", 0, layerPLs, sizeof layerPLs/sizeof layerPLs[0] }; +#define settingsListL ((wList_p)layerPLs[I_SETTINGS].control) +#define MESSAGETEXT ((wMessage_p)layerPLs[I_COUNT].control) + +static paramGroup_t layerPG = { "layer", 0, layerPLs, COUNT( layerPLs ) }; + +/** + * Reload the listbox showing the current catalog + */ + +static +int LoadFileListLoad(Catalog *catalog, char * name) +{ + CatalogEntry *currentEntry = catalog->head; + DynString description; + DynStringMalloc(&description, STR_SHORT_SIZE); + + wControlShow((wControl_p)settingsListL, FALSE); + wListClear(settingsListL); + + int currset = 0; + + int i = 0; + + wListAddValue(settingsListL," ",NULL," "); + + while (currentEntry) { + i++; + DynStringClear(&description); + DynStringCatCStr(&description, + currentEntry->contents) ; + wListAddValue(settingsListL, + DynStringToCStr(&description), + NULL, + currentEntry->fullFileName[0]); + if (strcmp(currentEntry->fullFileName[0],name)==0) currset = i; + currentEntry = currentEntry->next; + } + + + wListSetIndex(settingsListL,currset); + + wControlShow((wControl_p)settingsListL, TRUE); + + DynStringFree(&description); + + if (currset == 0 && strcmp(" ",name)!=0) return FALSE; + return TRUE; + +} #define layerL ((wList_p)layerPLs[I_LIST].control) +#define layerS ((wList_p)layerPLs[I_SETTINGS].control) + +void GetLayerLinkString(int inx,char * list) { + + char * cp = &list[0]; + cp[0] = '\0'; + int len = 0; + for (int i = 0; i<layers[inx].layerLinkList.cnt && len<STR_LONG_SIZE-5; i++) { + int l = DYNARR_N(int,layers[inx].layerLinkList,i); + if (i==0) + cp += sprintf(cp,"%d",l); + else + cp += sprintf(cp,";%d",l); + cp[0] = '\0'; + } +} + +void PutLayerListArray(int inx, char * list) { + char * cp = &list[0]; + DYNARR_RESET(int, layers[inx].layerLinkList); + while (cp) { + cp = strpbrk(list,",; "); + if (cp) { + cp[0] ='\0'; + int i = abs((int)strtol(list,&list,0)); + if (i>0 && i !=inx-1 && i<NUM_LAYERS) { + DYNARR_APPEND(int,layers[inx].layerLinkList,1); + DYNARR_LAST(int, layers[inx].layerLinkList) = i; + } + cp[0] = ';'; + list = cp+1; + } else { + int i = abs((int)strtol(list,&list,0)); + if (i>0 && i !=inx-1 && i<NUM_LAYERS) { + DYNARR_APPEND(int,layers[inx].layerLinkList,1); + DYNARR_LAST(int,layers[inx].layerLinkList) = i; + } + cp = 0; + } + } +} + + /** * Load the layer settings to hard coded system defaults */ @@ -521,7 +713,9 @@ LayerSystemDefaults(void) layers[inx].frozen = FALSE; layers[inx].onMap = TRUE; layers[inx].module = FALSE; + layers[inx].button_off = FALSE; layers[inx].objCount = 0; + DYNARR_RESET(int,layers[inx].layerLinkList); SetLayerColor(inx, layerColorTab[inx%COUNT(layerColorTab)]); } } @@ -540,6 +734,11 @@ void LoadLayerLists(void) wListClear(layerL); } + if (layerS) { + wListClear(layerS); + } + + /* add all layers to both lists */ for (inx=0; inx<NUM_LAYERS; inx++) { char *layerLabel; @@ -556,9 +755,8 @@ void LoadLayerLists(void) /* set current layer to selected */ wListSetIndex(setLayerL, curLayer); - if (layerL) { - wListSetIndex(layerL, curLayer); - } + if (layerL) wListSetIndex(layerL,curLayer); + } /** @@ -572,7 +770,7 @@ void LoadLayerLists(void) static void DoLayerOp(void * data) { - switch ((long)data) { + switch (VP2L(data)) { case ENUMLAYER_CLEAR: InitializeLayers(LayerSystemDefaults, -1); break; @@ -586,13 +784,12 @@ static void DoLayerOp(void * data) break; } - UpdateLayerDlg(); + UpdateLayerDlg(curLayer); //Reset to current Layer if (layoutLayerChanged) { MainProc(mainW, wResize_e, NULL, NULL); layoutLayerChanged = FALSE; - changed++; - SetWindowTitle(); + SetFileChanged(); } } @@ -602,35 +799,50 @@ static void DoLayerOp(void * data) * elements to the new settings. */ -static void -UpdateLayerDlg() +EXPORT void UpdateLayerDlg(unsigned int layer) { - int inx; + int inx; /* update the globals for the layer dialog */ - layerVisible = layers[curLayer].visible; - layerFrozen = layers[curLayer].frozen; - layerOnMap = layers[curLayer].onMap; - layerModule = layers[curLayer].module; - layerColor = layers[curLayer].color; - layerUseColor = layers[curLayer].useColor; - strcpy(layerName, layers[curLayer].name); - layerCurrent = curLayer; + layerVisible = layers[layer].visible; + layerFrozen = layers[layer].frozen; + layerOnMap = layers[layer].onMap; + layerModule = layers[layer].module; + layerColor = layers[layer].color; + layerUseColor = layers[layer].useColor; + layerNoButton = layers[layer].button_off; + strcpy(layerName, layers[layer].name); + strcpy(settingsName, layers[layer].settingsName); + GetLayerLinkString(layer,layerLinkList); + + layerCurrent = layer; /* now re-load the layer list boxes */ LoadLayerLists(); - sprintf(message, "%ld", layers[curLayer].objCount); - ParamLoadMessage(&layerPG, I_COUNT, message); + + /* force update of the 'manage layers' dialogbox */ if (layerL) { + wListSetIndex(layerL,layer); ParamLoadControls(&layerPG); } - /* finally show the layer buttons with ballon text */ + if (layerS) { + if (!LoadFileListLoad(settingsCatalog,settingsName)) + layers[layer].settingsName[0] = '\0'; + } + + sprintf(message, "Object Count: %ld", layers[layer].objCount); + if (MESSAGETEXT) wMessageSetValue(MESSAGETEXT, message); + + /* finally show the layer buttons with balloon text */ for (inx = 0; inx < NUM_BUTTONS; inx++) { - wButtonSetBusy(layer_btns[inx], layers[inx].visible != 0); - wControlSetBalloonText((wControl_p)layer_btns[inx], + if (!layers[inx].button_off) { + wButtonSetBusy(layer_btns[inx], layers[inx].visible != 0); + wControlSetBalloonText((wControl_p)layer_btns[inx], (layers[inx].name[0] != '\0' ? layers[inx].name :_("Show/Hide Layer"))); + } } + } /** @@ -648,7 +860,7 @@ FillLayerList( wList_p listLayers) for (int inx = 0; inx < NUM_LAYERS; inx++) { char *layerFormattedName; layerFormattedName = FormatLayerName(inx); - wListAddValue((wList_p)listLayers, layerFormattedName, NULL, (void*)(long)inx); + wListAddValue((wList_p)listLayers, layerFormattedName, NULL, I2VP(inx)); free(layerFormattedName); } @@ -670,9 +882,20 @@ InitializeLayers(void LayerInitFunc(void), int newCurrLayer) /* count the objects on each layer */ LayerSetCounts(); - /* Switch the current layer when requested */ + /* Switch the current layer when requested or the first above not frozen*/ if (newCurrLayer != -1) { - curLayer = newCurrLayer; + curLayer = -1; + for (int i = newCurrLayer; i< NUM_LAYERS; i++) { + if (!layers[i].frozen) { + curLayer = i; + break; + } + } + if (curLayer == -1) { + ErrorMessage( MSG_NO_EMPTY_LAYER ); + layers[0].frozen = FALSE; + curLayer = 0; + } } } @@ -686,6 +909,7 @@ LayerPrefSave(void) unsigned int inx; int flags; char buffer[ 80 ]; + char links[STR_LONG_SIZE]; char layersSaved[ 3 * NUM_LAYERS + 1 ]; /* 0..99 plus separator */ /* FIXME: values for layers that are configured to default now should be overwritten in the settings */ layersSaved[ 0 ] = '\0'; @@ -693,8 +917,10 @@ LayerPrefSave(void) for (inx = 0; inx < NUM_LAYERS; inx++) { /* if a name is set that is not the default value or a color different from the default has been set, information about the layer needs to be saved */ - if ((layers[inx].name[0] && inx != 0) || + if ((layers[inx].name[0]) || layers[inx].frozen || (!layers[inx].onMap) || (!layers[inx].visible) || + layers[inx].button_off || (layers[inx].layerLinkList.cnt>0) || + layers[inx].module || layers[inx].color != layerColorTab[inx%COUNT(layerColorTab)]) { sprintf(buffer, LAYERPREF_NAME ".%0u", inx); wPrefSetString(LAYERPREF_SECTION, buffer, layers[inx].name); @@ -718,9 +944,24 @@ LayerPrefSave(void) flags |= LAYERPREF_MODULE; } + if (layers[inx].button_off) { + flags |= LAYERPREF_NOBUTTON; + } + sprintf(buffer, LAYERPREF_FLAGS ".%0u", inx); wPrefSetInteger(LAYERPREF_SECTION, buffer, flags); + if (layers[inx].layerLinkList.cnt>0) { + sprintf(buffer, LAYERPREF_LIST ".%0u", inx); + GetLayerLinkString(inx,links); + wPrefSetString(LAYERPREF_SECTION, buffer, links); + + if (settingsName[0] && strcmp(settingsName," ")!=0) { + sprintf(buffer, LAYERPREF_SETTINGS ".%0u", inx); + wPrefSetString(LAYERPREF_SECTION, buffer, layers[inx].settingsName); + } + } + /* extend the list of layers that are set up via the preferences */ if (layersSaved[ 0 ]) { strcat(layersSaved, ","); @@ -758,6 +999,7 @@ LayerPrefLoad(void) int inx; char layerOption[20]; const char *layerValue; + char listValue[STR_LONG_SIZE]; int color; inx = atoi(prefString); sprintf(layerOption, LAYERPREF_NAME ".%d", inx); @@ -783,9 +1025,40 @@ LayerPrefLoad(void) layers[inx].onMap = ((flags & LAYERPREF_ONMAP) != 0); layers[inx].visible = ((flags & LAYERPREF_VISIBLE) != 0); layers[inx].module = ((flags & LAYERPREF_MODULE) !=0); + layers[inx].button_off = ((flags & LAYERPREF_NOBUTTON) !=0); + + sprintf(layerOption, LAYERPREF_LIST ".%d", inx); + layerValue = wPrefGetString(LAYERPREF_SECTION,layerOption); + if (layerValue) { + strcpy(listValue,layerValue); + PutLayerListArray(inx,listValue); + } else { + listValue[0] = '\0'; + PutLayerListArray(inx,listValue); + } + sprintf(layerOption, LAYERPREF_SETTINGS ".%d", inx); + layerValue = wPrefGetString(LAYERPREF_SECTION,layerOption); + if (layerValue) { + strcpy(layers[inx].settingsName,layerValue); + } else { + layers[inx].settingsName[0] = '\0'; + } + prefString = strtok(NULL, ","); } } + //Make sure curLayer not frozen + for (int i=curLayer; i<NUM_LAYERS; i++) { + if (!layers[i].frozen) { + curLayer = i; + break; + } + } + if (layers[curLayer].frozen) { + ErrorMessage( MSG_NO_EMPTY_LAYER ); + layers[0].frozen = FALSE; + curLayer = 0; + } } /** @@ -852,7 +1125,7 @@ void DefaultLayerProperties(void) { InitializeLayers(LayerPrefLoad, 0); - UpdateLayerDlg(); + UpdateLayerDlg(curLayer); //Use Current Layer if (layoutLayerChanged) { MainProc(mainW, wResize_e, NULL, NULL); @@ -892,6 +1165,8 @@ static void LayerUpdate(void) layerModule = FALSE; ParamLoadControl(&layerPG, I_MOD); } + char oldLinkList[STR_LONG_SIZE]; + GetLayerLinkString((int)layerCurrent,oldLinkList); if (strcmp(layers[(int)layerCurrent].name, layerName) || layerColor != layers[(int)layerCurrent].color || @@ -899,9 +1174,11 @@ static void LayerUpdate(void) layers[(int)layerCurrent].visible != (BOOL_T)layerVisible || layers[(int)layerCurrent].frozen != (BOOL_T)layerFrozen || layers[(int)layerCurrent].onMap != (BOOL_T)layerOnMap || - layers[(int)layerCurrent].module != (BOOL_T)layerModule) { - changed++; - SetWindowTitle(); + layers[(int)layerCurrent].module != (BOOL_T)layerModule || + layers[(int)layerCurrent].button_off != (BOOL_T)layerNoButton || + strcmp(layers[(int)layerCurrent].settingsName,settingsName) || + strcmp(oldLinkList,layerLinkList)) { + SetFileChanged(); } if (layerL) { @@ -912,11 +1189,12 @@ static void LayerUpdate(void) free(layerFormattedName); } + layerFormattedName = FormatLayerName(layerCurrent); wListSetValues(setLayerL, layerCurrent, layerFormattedName, NULL, NULL); free(layerFormattedName); - if (layerCurrent < NUM_BUTTONS) { + if (layerCurrent < NUM_BUTTONS && !layers[(int)layerCurrent].button_off) { if (strlen(layers[(int)layerCurrent].name)>0) { wControlSetBalloonText((wControl_p)layer_btns[(int)layerCurrent], layers[(int)layerCurrent].name); @@ -937,15 +1215,25 @@ static void LayerUpdate(void) SetLayerColor(layerCurrent, layerColor); if (layerCurrent<NUM_BUTTONS && - layers[(int)layerCurrent].visible!=(BOOL_T)layerVisible) { + layers[(int)layerCurrent].visible!=(BOOL_T)layerVisible && !layers[(int)layerCurrent].button_off) { wButtonSetBusy(layer_btns[(int)layerCurrent], layerVisible); } layers[(int)layerCurrent].useColor = (BOOL_T)layerUseColor; + if (layers[(int)layerCurrent].visible != (BOOL_T)layerVisible) + FlipLayer(I2VP(layerCurrent)); layers[(int)layerCurrent].visible = (BOOL_T)layerVisible; layers[(int)layerCurrent].frozen = (BOOL_T)layerFrozen; + if (layers[(int)layerCurrent].frozen) DeselectLayer(layerCurrent); layers[(int)layerCurrent].onMap = (BOOL_T)layerOnMap; layers[(int)layerCurrent].module = (BOOL_T)layerModule; + strcpy(layers[(int)layerCurrent].settingsName,settingsName); + + PutLayerListArray((int)layerCurrent,layerLinkList); + + SetLayerHideButton(layerCurrent,layerNoButton); + + MainProc( mainW, wResize_e, NULL, NULL ); if (layerRedrawMap) { DoRedraw(); @@ -968,15 +1256,26 @@ static void LayerSelect( layerCurrent = (unsigned int)inx; strcpy(layerName, layers[inx].name); + strcpy(settingsName, layers[inx].settingsName); layerVisible = layers[inx].visible; layerFrozen = layers[inx].frozen; layerOnMap = layers[inx].onMap; layerModule = layers[inx].module; layerColor = layers[inx].color; layerUseColor = layers[inx].useColor; + layerNoButton = layers[inx].button_off; sprintf(message, "%ld", layers[inx].objCount); + GetLayerLinkString(inx,layerLinkList); ParamLoadMessage(&layerPG, I_COUNT, message); ParamLoadControls(&layerPG); + + if (layerS) { + if (!LoadFileListLoad(settingsCatalog,settingsName)) { + settingsName[0] = '\0'; + layers[inx].settingsName[0] = '\0'; + } + + } } void ResetLayers(void) @@ -989,9 +1288,13 @@ void ResetLayers(void) layers[inx].frozen = FALSE; layers[inx].onMap = TRUE; layers[inx].module = FALSE; + layers[inx].button_off = FALSE; layers[inx].objCount = 0; + strcpy(layers[inx].settingsName,""); + DYNARR_RESET(int,layers[inx].layerLinkList); SetLayerColor(inx, layerColorTab[inx%COUNT(layerColorTab)]); + if (inx<NUM_BUTTONS) { wButtonSetLabel(layer_btns[inx], (char*)show_layer_bmps[inx]); } @@ -1003,7 +1306,21 @@ void ResetLayers(void) wControlSetBalloonText((wControl_p)layer_btns[inx], _("Show/Hide Layer")); } - curLayer = 0; + curLayer = -1; + + for (int i=0;i<NUM_LAYERS;i++) { + if (!layers[i].frozen) { + curLayer = i; + break; + } + } + + if (curLayer == -1) { + ErrorMessage( MSG_NO_EMPTY_LAYER ); + layers[0].frozen = FALSE; + curLayer = 0; + } + layerVisible = TRUE; layerFrozen = FALSE; layerOnMap = TRUE; @@ -1011,6 +1328,8 @@ void ResetLayers(void) layerColor = layers[0].color; layerUseColor = TRUE; strcpy(layerName, layers[0].name); + strcpy(settingsName, layers[0].settingsName); + LoadLayerLists(); if (layerL) { @@ -1028,6 +1347,10 @@ void SaveLayers(void) abort(); } + for (int i=0;i<NUM_LAYERS;i++) { + layers[i].settingsName[0] = '\0'; + } + memcpy(layers_save, layers, NUM_LAYERS * sizeof layers[0]); ResetLayers(); } @@ -1075,7 +1398,7 @@ void RestoreLayers(void) * */ -static void LayerOk(void * junk) +static void LayerOk(void * unused) { LayerSelect(layerCurrent); @@ -1113,30 +1436,135 @@ static void LayerDlgUpdate( case I_MAP: layerRedrawMap = TRUE; - break; + /* No Break */ + case I_VIS: + case I_FRZ: + case I_MOD: + case I_BUT: + LayerUpdate(); + UpdateLayerDlg(layerCurrent); + break; + + case I_SETTINGS: + if (strcmp((char*)wListGetItemContext(settingsListL,(wIndex_t)*(long*)valueP)," ")==0) + settingsName[0] = '\0'; + else + strcpy(settingsName,(char*)wListGetItemContext(settingsListL,(wIndex_t)*(long*)valueP)); + break; } + + + } +/** + * Scan opened directory for the next settings file + * + * \param dir IN opened directory handle + * \param dirName IN name of directory + * \param fileName OUT fully qualified filename + * + * \return TRUE if file found, FALSE if not + */ -static void DoLayer(void * junk) +static bool +GetNextSettingsFile(DIR *dir, const char *dirName, char **fileName) +{ + bool done = false; + bool res = false; + + /* + * get all files from the directory + */ + while (!done) { + struct stat fileState; + struct dirent *ent; + + ent = readdir(dir); + + if (ent) { + if (!XtcStricmp(FindFileExtension(ent->d_name), "xset")) { + /* create full file name and get the state for that file */ + MakeFullpath(fileName, dirName, ent->d_name, NULL); + + if (stat(*fileName, &fileState) == -1) { + fprintf(stderr, "Error getting file state for %s\n", *fileName); + continue; + } + + /* ignore any directories */ + if (!(fileState.st_mode & S_IFDIR)) { + done = true; + res = true; + } + } + } else { + done = true; + res = false; + } + } + return (res); +} + + +/* + * Get all the settings files in the working directory + */ + +static CatalogEntry * +ScanSettingsDirectory(Catalog *catalog, const char *dirName) +{ + DIR *d; + CatalogEntry *newEntry = catalog->head; + char contents[STR_SHORT_SIZE]; + + d = opendir(dirName); + if (d) { + char *fileName = NULL; + + while (GetNextSettingsFile(d, dirName, &fileName)) { + char *contents_start = strrchr(fileName,PATH_SEPARATOR[0]); + if (contents_start[0] == '/') contents_start++; + char *contents_end = strchr(contents_start,'.'); + if (contents_end[0] == '.') contents_end[0] = '\0'; + strcpy(contents,contents_start); + contents_end[0] = '.'; + newEntry = InsertInOrder(catalog,contents, NULL); + UpdateCatalogEntry(newEntry, fileName, contents, NULL); + free(fileName); + fileName = NULL; + } + closedir(d); + } + + return (newEntry); +} + +static void DoLayer(void * unused) { if (layerW == NULL) { layerW = ParamCreateDialog(&layerPG, MakeWindowTitle(_("Layers")), _("Done"), LayerOk, wHide, TRUE, NULL, 0, LayerDlgUpdate); } + if (settingsCatalog) CatalogDiscard(settingsCatalog); + else settingsCatalog = InitCatalog(); + ScanSettingsDirectory(settingsCatalog, wGetAppWorkDir()); + + /* set the globals to the values for the current layer */ - UpdateLayerDlg(); + UpdateLayerDlg(curLayer); layerRedrawMap = FALSE; wShow(layerW); layoutLayerChanged = FALSE; } + BOOL_T ReadLayers(char * line) { - char * name; - int inx, visible, frozen, color, onMap, module, dontUseColor, ColorFlags; + char * name, *layerLinkList, *layerSettingsName; + int inx, visible, frozen, color, onMap, module, dontUseColor, ColorFlags, button_off; unsigned long rgb; /* older files didn't support layers */ @@ -1151,9 +1579,15 @@ BOOL_T ReadLayers(char * line) curLayer = atoi(line+7); if (!IsLayerValid(curLayer)) { + curLayer = 0; } + if (layers[curLayer].frozen) { + ErrorMessage( MSG_NOT_UNFROZEN_LAYER ); + layers[curLayer].frozen = FALSE; + } + if (layerL) { wListSetIndex(layerL, curLayer); } @@ -1165,15 +1599,33 @@ BOOL_T ReadLayers(char * line) return TRUE; } - /* get the properties for a layer from the file and update the layer accordingly */ + if (strncmp(line, "LINK", 4) == 0) { + if (!GetArgs(line+4, "dq" , &inx, &layerLinkList)) { + return FALSE; + } + PutLayerListArray(inx,layerLinkList); + return TRUE; + } - if (!GetArgs(line, "dddduddd0q", &inx, &visible, &frozen, &onMap, &rgb, &module, &dontUseColor, &ColorFlags, - &name)) { - return FALSE; + if (strncmp(line, "SET", 3) == 0) { + if (!GetArgs(line+3, "dq", &inx, &layerSettingsName)) { + return FALSE; + } + strcpy(layers[inx].settingsName,layerSettingsName); + return TRUE; } + /* get the properties for a layer from the file and update the layer accordingly */ + + if (!GetArgs(line, "dddduddddq", &inx, &visible, &frozen, &onMap, &rgb, &module, &dontUseColor, &ColorFlags, &button_off, + &name)) { + + return FALSE; + } + + if (paramVersion < 9) { - if ((int)rgb < sizeof oldColorMap/sizeof oldColorMap[0]) { + if ((int)rgb < COUNT( oldColorMap ) ) { rgb = wRGB(oldColorMap[(int)rgb][0], oldColorMap[(int)rgb][1], oldColorMap[(int)rgb][2]); } else { @@ -1194,15 +1646,15 @@ BOOL_T ReadLayers(char * line) layers[inx].module = module; layers[inx].color = color; layers[inx].useColor = !dontUseColor; + layers[inx].button_off = button_off; colorTrack = ColorFlags&1; //Make sure globals are set colorDraw = ColorFlags&2; - if (inx<NUM_BUTTONS) { + if (inx<NUM_BUTTONS && !layers[inx].button_off) { if (strlen(name) > 0) { wControlSetBalloonText((wControl_p)layer_btns[(int)inx], layers[inx].name); } - wButtonSetBusy(layer_btns[(int)inx], visible); } MyFree(name); @@ -1227,12 +1679,15 @@ IsLayerConfigured(unsigned int layerNumber) layers[layerNumber].frozen || !layers[layerNumber].onMap || layers[layerNumber].module || + layers[layerNumber].button_off || layers[layerNumber].color != layerColorTab[layerNumber % (COUNT(layerColorTab))] || layers[layerNumber].name[0] || + layers[layerNumber].layerLinkList.cnt > 0 || layers[layerNumber].objCount); } + /** * Save the layer information to the file. * @@ -1259,12 +1714,20 @@ BOOL_T WriteLayers(FILE * f) wDrawGetRGB(layers[inx].color), layers[inx].module, layers[inx].useColor?0:1, - ColorFlags, 0, + ColorFlags, layers[inx].button_off, PutTitle(layers[inx].name)); } } fprintf(f, "LAYERS CURRENT %u\n", curLayer); + + for (inx = 0; inx < NUM_LAYERS; inx++) { + GetLayerLinkString(inx,layerLinkList); + if (IsLayerConfigured(inx) && strlen(layerLinkList)>0) + fprintf(f, "LAYERS LINK %u \"%s\"\n",inx,layerLinkList); + if (IsLayerConfigured(inx) && layers[inx].settingsName[0]) + fprintf(f, "LAYERS SET %u \"%s\"\n",inx, layers[inx].settingsName); + } return TRUE; } @@ -1281,8 +1744,10 @@ void InitLayers(void) /* create the bitmaps for the layer buttons */ /* all bitmaps have to have the same dimensions */ - for (i = 0; i<NUM_BUTTONS; i++) { - show_layer_bmps[i] = wIconCreateBitMap(l1_width, l1_height, show_layer_bits[i], + for (int i = 0;i<NUM_LAYERS; i++) { + // char *bits = (show_layer_bits[i] + iconSize * sizeof(char*))); + show_layer_bmps[i] = wIconCreateBitMap(lbits_width[iconSize], lbits_height[iconSize], + show_layer_bits[iconSize][i], layerColorTab[i%(COUNT(layerColorTab))]); layers[i].color = layerColorTab[i%(COUNT(layerColorTab))]; layers[i].useColor = TRUE; @@ -1294,11 +1759,13 @@ void InitLayers(void) wControlSetBalloonText((wControl_p)setLayerL, GetBalloonHelpStr("cmdLayerSet")); AddToolbarControl((wControl_p)setLayerL, IC_MODETRAIN_TOO); - backgroundB = AddToolbarButton("cmdBackgroundShow", wIconCreatePixMap(background), 0, - (addButtonCallBack_t)BackgroundToggleShow, NULL); + backgroundB = AddToolbarButton("cmdBackgroundShow", wIconCreatePixMap(background_xpm[iconSize]), 0, + BackgroundToggleShow, NULL); + /* add the help text */ + wControlSetBalloonText((wControl_p)backgroundB, _("Show/Hide Background")); wControlActive((wControl_p)backgroundB, FALSE); - for (i = 0; i<NUM_LAYERS; i++) { + for (int i = 0; i<NUM_LAYERS; i++) { char *layerName; if (i<NUM_BUTTONS) { @@ -1306,17 +1773,17 @@ void InitLayers(void) sprintf(message, "cmdLayerShow%u", i); layer_btns[i] = wButtonCreate(mainW, 0, 0, message, (char*)(show_layer_bmps[i]), - BO_ICON, 0, (wButtonCallBack_p)FlipLayer, (void*)(intptr_t)i); + BO_ICON, 0, FlipLayer, I2VP(i) ); /* add the help text */ wControlSetBalloonText((wControl_p)layer_btns[i], _("Show/Hide Layer")); /* put on toolbar */ - AddToolbarControl((wControl_p)layer_btns[i], IC_MODETRAIN_TOO); - /* set state of button */ - wButtonSetBusy(layer_btns[i], 1); + AddToolbarControl((wControl_p)layer_btns[i], IC_MODETRAIN_TOO); + /* set state of button */ + wButtonSetBusy(layer_btns[i], 1); } layerName = FormatLayerName(i); - wListAddValue(setLayerL, layerName, NULL, (void*)(long)i); + wListAddValue(setLayerL, layerName, NULL, I2VP(i)); free(layerName); } @@ -1324,7 +1791,6 @@ void InitLayers(void) AddPlaybackProc("LAYERS", (playbackProc_p)ReadLayers, NULL); } - addButtonCallBack_t InitLayersDialog(void) { ParamRegister(&layerPG); |