📄 regional.cxx
字号:
/* * Copyright (c) 2003 Century Software, Inc. All Rights Reserved. * * This file is part of the PIXIL Operating Environment * * The use, copying and distribution of this file is governed by one * of two licenses, the PIXIL Commercial License, or the GNU General * Public License, version 2. * * Licensees holding a valid PIXIL Commercial License may use this file * in accordance with the PIXIL Commercial License Agreement provided * with the Software. Others are governed under the terms of the GNU * General Public License version 2. * * This file may be distributed and/or modified under the terms of the * GNU General Public License version 2 as published by the Free * Software Foundation and appearing in the file LICENSE.GPL included * in the packaging of this file. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. * * RESTRICTED RIGHTS LEGEND * * Use, duplication, or disclosure by the government is subject to * restriction as set forth in paragraph (b)(3)(b) of the Rights in * Technical Data and Computer Software clause in DAR 7-104.9(a). * * See http://www.pixil.org/gpl/ for GPL licensing * information. * * See http://www.pixil.org/license.html or * email cetsales@centurysoftware.com for information about the PIXIL * Commercial License Agreement, or if any conditions of this licensing * are not clear to you. */// System header files#include <dirent.h>#include <stdarg.h>#include <langinfo.h>#include <locale.h>#ifndef __UCLIBC__#include <monetary.h>#endif#include <stdio.h>#include <stdlib.h>#include <sys/stat.h>#include <sys/wait.h>#include <unistd.h>// Local header files#include <FL/Enumerations.H>#include "nxreg.h"#include <pixlib/pixlib.h>#include <sysconf_plugin.h>// Typedef, macro, enum/struct/union definitionstypedef struct{ char *locale_nm, *locale_cd;}LocalInfo_t;static char *tmdt_lbls[REG_NUM_TMDT] = { "Time: ", "Short Date: ", "Long Date: "}, *nmbrs_lbls[REG_NUM_NMBRS] ={"Positive num: ", "Negative num: ", "Positive cur: ", "Negative cur: "};// This should be done dynamically, somehow, once the regional packaging gets done....static const LocalInfo_t locale_info[] = { {"Danish", "da_DK"}, {"Dutch", "nl_NL"}, {"English (GB)", "en_GB"}, {"English (US)", "en_US"}, {"Finnish", "fi_FI"}, {"French", "fr_FR"}, {"German", "de_DE"}, {"Italian", "it_IT"}, {"Norwegian", "no_NO"}, {"Portuguese", "pt_PT"}, {"Spanish", "es_ES"}, {"Swedish", "sv_SE"}, {0, 0}}; // List of all supported localesNxRegional::~NxRegional(){ GetAppPrefs(); delete _mbreg; for (int i = 0; i < REG_NUM_TMDT; i++) { delete _regtmdt[i].nb; delete[]_regtmdt[i].label; } for (int i = 0; i < REG_NUM_NMBRS; i++) { delete _regnmbrs[i].nb; delete[]_regnmbrs[i].label; } delete _mainw;}NxRegional::NxRegional(int X, int Y, int W, int H, char *appname){ _winX = X; _winY = Y; _nregidx = _oregidx = -1; memset(_regtmdt, 0, sizeof(_regtmdt)); memset(_regnmbrs, 0, sizeof(_regnmbrs)); // Get the Application preferences from PAR GetAppPrefs(); // Build the window and widgets MakeWindow(X, Y, W, H); // Set the initial values.... SetValues();}voidNxRegional::ShowWindow(void){ _mainw->show();}voidNxRegional::HideWindow(void){ _mainw->hide();}#ifdef NOTUSEDvoidNxRegional::clean_locale_dir(void){ char sysbuf[1024]; DIR *pdir; struct dirent *dentry; struct stat statbuf; if ((pdir = opendir(locale_dir)) != NULL) { while ((dentry = readdir(pdir)) != NULL) { // Skip over the root and parent directories if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, "..")) continue; // Stat the file sprintf(sysbuf, "%s/%s", locale_dir, dentry->d_name); if (!stat(sysbuf, &statbuf) && S_ISDIR(statbuf.st_mode)) { // See if the tar file exists to rebuild strcat(sysbuf, ".tar.gz"); if (stat(sysbuf, &statbuf)) continue; sprintf(sysbuf, "rm -rf %s/%s", locale_dir, dentry->d_name); system(sysbuf); } // end of if } // end of while closedir(pdir); } // end of if return;} // end of NxRegional::clean_locale_dir(void)#endifintNxRegional::FindLocale(char *key){ int i, key_len, found = -1; // Note: Since the list is alphabetical by long name, rather than locale // value, and the list is relative short (< 13), a linear search // is being done. When this increases a more efficient search // algorithm will need to be used for (i = 0; locale_info[i].locale_nm != NULL; i++) { key_len = strlen(key); if (!memcmp(key, locale_info[i].locale_cd, key_len)) { found = i; break; } // end of if } // end of for return (found);} // end of NxRegional::FindLocale(char *)voidNxRegional::GetAppPrefs(void){ char *pardb, // name of the default database par_data[512]; // Data retrieved from PAR db_handle *hdb; // Database handle int rc; // Index value // Setup the database if ((pardb = db_getDefaultDB()) == NULL) { printf("No default database present!"); return; } // end of if if ((hdb = db_openDB(pardb, PAR_DB_MODE_RDONLY)) == NULL) { printf("Error opening %s, error=%d", pardb, pardb_errno); return; } // end of if // Get the stored Locale value if ((rc = par_getGlobalPref(hdb, "language", "default", PAR_TEXT, par_data, sizeof(par_data))) > 0) { // Null terminate the string par_data[rc] = '\0'; if ((_oregidx = FindLocale(par_data)) > 0) DPRINTF("Current selected region=%s (%s)\n", locale_info[_oregidx].locale_nm, locale_info[_oregidx].locale_cd); _nregidx = _oregidx; } // end of if // Force a default (good 'ol U.S. style engrish) if (_oregidx == -1) { sprintf(par_data, "en_US"); _oregidx = FindLocale(par_data); } // end of if // Set _oregidx and _nregidx initially to be the same _nregidx = _oregidx; // Close the database and return db_closeDB(hdb); return;} // end of NxRegional::GetAppPrefs(void)#ifdef NOTUSEDintNxRegional::is_locale_dir(char *lcd){ char fqpn[1024]; // Fully qualified path name int rc = 0; // Result code struct stat statbuf; // Stat buffer if (lcd == NULL || *lcd == '\0') return (rc); // See if the directory exists sprintf(fqpn, "%s/%s", locale_dir, lcd); if (stat(fqpn, &statbuf)) { // see if the tar file exists strcat(fqpn, ".tar.gz"); if (stat(fqpn, &statbuf)) return (rc); } rc = 1; return (rc);} // end of NxRegional::is_locale_dir(char *)#endifvoidNxRegional::MakeWindow(int X, int Y, int W, int H){ int curx, // Current x coordinate cury, // Current y coordinate mar = 4; // Left margin Fl_Color def_bg, // Default background color def_fg; // Default forground color NxApp *instance = sysconf_get_instance(); _mainw = new Fl_Group(X, Y, W, H); def_bg = instance->getGlobalColor(APP_BG); def_fg = instance->getGlobalColor(APP_FG); _mainw->color(def_bg); cury = Y + BUTTON_Y - _winY; curx = X + BUTTON_X; { NxButton *o; o = new NxButton(curx, cury, BUTTON_WIDTH, BUTTON_HEIGHT, "Save"); o->when(FL_WHEN_RELEASE); o->callback(save_reset_cb, (void *) this); _save = o; curx += 63; } // end of "Save" button { NxButton *o; o = new NxButton(curx, cury, BUTTON_WIDTH, BUTTON_HEIGHT, "Reset"); o->when(FL_WHEN_RELEASE); o->callback(save_reset_cb, (void *) this); _reset = o; } // end of "Reset button { double width; NxBox *o; NxMenuButton *p; curx = X + mar; cury = Y + mar; fl_font(DEFAULT_TEXT_FONT, DEFAULT_TEXT_SIZE); width = fl_width("Region: "); width += 6; o = new NxBox(curx, cury, (int) width, BUTTON_HEIGHT, "Region: "); o->labelfont(FL_BOLD); o->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); curx += mar + o->w(); p = new NxMenuButton(curx, cury, (_mainw->w() / 3) * 2, BUTTON_HEIGHT); p->label("Select Region"); for (int i = 0; locale_info[i].locale_nm != NULL; i++) { p->add(locale_info[i].locale_nm); } // end of for p->when(FL_WHEN_RELEASE); p->callback(mb_cb, (void *) this); _mbreg = p; cury += BUTTON_HEIGHT + mar; curx = mar; } // end of menu button { NxBox *o = new NxBox(curx, cury + 5, _mainw->w() - (2 * mar), BUTTON_HEIGHT); o->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT); o->label("Appearance Samples"); cury += BUTTON_HEIGHT; } // end of bogus text { NxBox *o = new NxBox(curx, cury, _mainw->w() - (2 * mar), BUTTON_HEIGHT); o->labeltype(FL_SYMBOL_LABEL); o->label("@line"); o->labelcolor(instance->getGlobalColor(BUTTON_FACE)); o->align(FL_ALIGN_TOP | FL_ALIGN_INSIDE); cury += (int) (1.5 * BUTTON_HEIGHT);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -