⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 backlite.cxx

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/*                                                                        * 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 <stdio.h>#include <stdarg.h>#include <stdlib.h>#include <unistd.h>// Local header files#include <FL/Enumerations.H>#include "nxbl.h"#include <nxbutton.h>#include <wm/scrtoplib.h>#include <pixlib/pixlib.h>#include <sysconf_plugin.h>static char *def_bat_warn = "Warning: Using backlight with battery\n"    "will reduce battery life.", *tmout_lbls[2][11] = {    {"10 Seconds",     "30 Seconds",     "1 Minute",     "2 Minutes",     "3 Minutes",     "4 Minutes",     "5 Minutes",     NULL},    {"1 Minute",     "2 Minutes",     "3 Minutes",     "4 Minutes",     "5 Minutes",     "6 Minutes",     "7 Minutes",     "8 Minutes",     "9 Minutes",     "10 Minutes",     NULL}}, *mode_lbls[] ={"Battery", "External"};signed short tmout_vals[2][11] = {    {10, 30, 60, 120, 180, 240, 300, -1},    {60, 120, 180, 240, 300, 360, 420,     480, 540, 600, -1}};/*******************************************************************************\****	Function:	~NxBacklite()**	Desc:		Class NxBacklite destructor, responsible for free()ing dynamic**				memory**	Accepts:	N/A**	Returns:	N/A**\*******************************************************************************/NxBacklite::~NxBacklite(){    // Reset the backlite to the last stored value for the current mode....    if (pix_pwr_onBattery())	_blMode = blBATTERY;    else	_blMode = blACPOWER;    GetAppPrefs();    SetValues();    SetBl();    delete _mbmode;    delete _mbtimeunit[0];    delete _mbtimeunit[1];    delete _pwrdn_ck;    delete _wake_ck;    delete _brightness;    delete _bat_warning;    delete _mainw;}/*******************************************************************************\****	Function:	NxBacklite()**	Desc:		Class NxBacklite constructor, handles parsing of commandline**				arguments**	Accepts:	int argc = Number of arguments on instantiation**				char **argv = Argument vector**				char *appname = Applications par name**	Returns:	N/A**\*******************************************************************************/NxBacklite::NxBacklite(int X, int Y, int W, int H, char *appname){    _mainw = 0;    // Get the current power mode....    if (pix_pwr_onBattery())	_blMode = blBATTERY;    else	_blMode = blACPOWER;    memset(&_bl_settings, 0, sizeof(_bl_settings));    _winX = X;    _winY = Y;    // Get the Application preferences from PAR    GetAppPrefs();    // Build the window and widgets    MakeWindow(X, Y, W, H);    // Set the initial values....    SetValues();    SetBl();}voidNxBacklite::GetAppPrefs(void){    char *pardb;		// name of the default database    db_handle *hdb;		// Database handle    int idx;			// Index value    // Setup the database    if ((pardb = db_getDefaultDB()) == NULL) {	return;    }				// end of if    if ((hdb = db_openDB(pardb, PAR_DB_MODE_RDONLY)) == NULL) {	return;    }				// end of if    // Get the stored values for the ac power    idx = (int) blACPOWER;    if (par_getGlobalPref(hdb, "backlight", "ac_timeout", PAR_INT,			  &_bl_settings[idx].tmout_val, sizeof(int)) == -1)	printf("No ac_timeout value!");    if (par_getGlobalPref(hdb, "backlight", "ac_wakeup", PAR_BOOL,			  &_bl_settings[idx].wake_up, sizeof(bool)) == -1)	printf("No ac_wakeup value!");    if (par_getGlobalPref(hdb, "backlight", "ac_level", PAR_INT,			  &_bl_settings[idx].brite_val, sizeof(int)) == -1)	printf("No ac_level value!");    // Get the stored values for the batter power    idx = (int) blBATTERY;    if (par_getGlobalPref(hdb, "backlight", "bat_timeout", PAR_INT,			  &_bl_settings[idx].tmout_val, sizeof(int)) == -1)	printf("No bat_timeout value!");    if (par_getGlobalPref(hdb, "backlight", "bat_wakeup", PAR_BOOL,			  &_bl_settings[idx].wake_up, sizeof(bool)) == -1)	printf("No bat_wakeup value!");    if (par_getGlobalPref(hdb, "backlight", "bat_level", PAR_INT,			  &_bl_settings[idx].brite_val, sizeof(int)) == -1)	printf("No bat_level value!");    // Close the database and return    db_closeDB(hdb);    return;}				// end of NxBacklite::GetAppPrefs(void)voidNxBacklite::ShowWindow(void){    _mainw->show();}voidNxBacklite::HideWindow(void){    _mainw->hide();}/*******************************************************************************\****	Function:	void MakeWindow()**	Desc:		Creates the main fltk window and adds the appropriate widgets to**				it**	Accepts:	Nothing (void)**	Returns:	Nothing (void)**\*******************************************************************************/voidNxBacklite::MakeWindow(int X, int Y, int W, int H){    int curx,			// Current x coordinate      cury,			// Current y coordinate      mar = 4;			// Left margin    NxApp *instance = sysconf_get_instance();    if (_mainw)	return;    _mainw = new Fl_Group(X, Y, W, H);    _mainw->color(instance->getGlobalColor(APP_BG));    // Set the widgets    cury = Y + BUTTON_Y - _winY;    curx = X + BUTTON_X;    {	// Add the bottom "OK" button	NxButton *o;		// Ok button	o = new NxButton(curx, cury, BUTTON_WIDTH, BUTTON_HEIGHT, "Save");	o->when(FL_WHEN_RELEASE);	o->callback(save_exit_cb, (void *) this);	curx += 63;    }				// end of OK button    {	// Add the bottom "Cancel" Button	NxButton *o = new NxButton(curx, cury, BUTTON_WIDTH,				   BUTTON_HEIGHT, "Reset");	o->when(FL_WHEN_RELEASE);	o->callback(save_exit_cb, (void *) this);    }				// end of Cancel button    cury = Y + 2 * mar;    curx = X + mar;    {	// Add the Label for the mode selection	NxOutput *o = new NxOutput(curx, cury, (_mainw->w() - curx) - MB_W,				   BUTTON_HEIGHT);	o->selection_color(o->color());	o->align(FL_ALIGN_LEFT);	o->value("Power mode: ");	curx = _mainw->w() - (curx + MB_W);    }				// end of ML text widget    {	NxMenuButton *o = _mbmode = new NxMenuButton(curx, cury, MB_W, MB_H);	instance->def_font(o);	for (int i = 0; i < ((int) blACPOWER + 1); i++)	    o->add(mode_lbls[i]);	o->box(FL_BORDER_BOX);	o->when(FL_WHEN_CHANGED);	o->callback(mode_sel_cb, (void *) this);	o->label("Unknown");	cury += (int) (BUTTON_HEIGHT * 2);	curx = X + mar;	DPRINTF("Menubutton: x=%d y=%d w=%d h=%d.\n", o->x(), o->y(), o->w(),		o->h());    }				// end of Mode menu button    {	// Add the Multiline warning...	NxMlOutput *o = _bat_warning = new NxMlOutput(curx, cury,						      _mainw->w() - curx,						      (2 * BUTTON_HEIGHT));	o->color(_mainw->color());	o->selection_color(o->color());	o->value(def_bat_warn);	instance->def_font(o);	cury += o->h() + BUTTON_HEIGHT;	o->hide();    }				// end of battery warning widget    {	NxCheckButton *o = new NxCheckButton(curx, cury);	instance->def_font(o);	o->when(FL_WHEN_CHANGED);	o->callback(pwrdn_ck_cb, (void *) this);	o->box(FL_FLAT_BOX);	o->label("Turn off backlight if\nidle for: ");	_pwrdn_ck = o;	curx = _mainw->w() - ((2 * mar) + MB_W);    }				// end of Power down check button    {	NxMenuButton *o = new NxMenuButton(curx, cury, MB_W + mar, MB_H);	instance->def_font(o);	for (int i = 0; tmout_lbls[(int) blACPOWER][i]; i++)	    o->add(tmout_lbls[(int) blACPOWER][i]);	o->box(FL_BORDER_BOX);	o->when(FL_WHEN_CHANGED);	o->callback(tm_sel_cb, (void *) this);	o->label("Unset");	_mbtimeunit[(int) blACPOWER] = o;	o->hide();    }				// end of ACPower timevals menu button    {	NxMenuButton *o = new NxMenuButton(curx, cury, MB_W + mar, MB_H);	instance->def_font(o);	for (int i = 0; tmout_lbls[(int) blBATTERY][i]; i++)	    o->add(tmout_lbls[(int) blBATTERY][i]);	o->box(FL_BORDER_BOX);	o->when(FL_WHEN_CHANGED);	o->callback(tm_sel_cb);	o->label("Unset");	_mbtimeunit[(int) blBATTERY] = o;	curx = X + mar;	cury += (3 * BUTTON_HEIGHT);    }				// end of BATTERY timevals menu button    {	NxCheckButton *o = new NxCheckButton(curx, cury);	instance->def_font(o);	o->box(FL_FLAT_BOX);	o->label	    ("Turn on backlight when a button is\npressed or the screen is tapped");	o->when(FL_WHEN_CHANGED);	o->callback(wake_toggle_cb, (void *) this);	_wake_ck = o;	curx = X + mar;	cury = cury + o->h() + (2 * BUTTON_HEIGHT);    }				// end of wake check_box widget    {	NxValueSlider *o =	    new NxValueSlider(curx, cury, _mainw->w() - (5 * curx),			      BUTTON_HEIGHT);	instance->def_font(o);	o->box(FL_BORDER_BOX);	o->maximum(100.0);	o->minimum(0.0);	o->type(FL_HORIZONTAL);	o->step(1.0);	o->align(FL_ALIGN_TOP | FL_ALIGN_LEFT);	o->label("Brightness Level:");	o->when(FL_WHEN_CHANGED);	o->callback(brite_sel_cb, (void *) this);	_brightness = o;    }				// end of slider    _mainw->end();    _mainw->hide();    return;}				// end of NxBacklite::MakeWindow(void)/*******************************************************************************\****	Function:	void SetAppPrefs()**	Desc:		Stores any changed values into the PAR database**	Accepts:	Nothing (void)**	Returns:	Nothing (void)**	\*******************************************************************************/voidNxBacklite::SetAppPrefs(void){    char *pardb;		// Database name    int idx;			// Quick index variable    db_handle *hdb;		// Database handle    if ((pardb = db_getDefaultDB()) == NULL) {	printf("Unable to get the current database\n");	return;    }				// end of if    if ((hdb = db_openDB(pardb, PAR_DB_MODE_RW)) == NULL) {	printf("Unable to open the database %s\n", pardb);	return;    }				// end of if

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -