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

📄 nxweek.cxx

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CXX
📖 第 1 页 / 共 3 页
字号:
/*                                                                        * 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.                                                 */#include <FL/fl_draw.H>#include <FL/Fl.H>#include "nxweek.h"#include <stdio.h>#include <stdlib.h>#include "nxschedule.h"#include <nxapp.h>#ifdef DEBUG#define DPRINT(str, args...) printf("DEBUG: " str, ## args)#else#define DPRINT(args...)#endifWeekGrid::WeekGrid(int X, int Y, int W, int H, const char *L):Fl_Widget(X, Y, W, H, L){    info_draw = 0;    b_height = H / 24;    Fl_Widget::h((int) (6.5 * b_height));    save_h = Fl_Widget::h();    b_width = w() / 7;    scroll_count = 1;    color_ = FL_WHITE;    line_color_ = txt_color_ = FL_BLACK;    font_ = FL_HELVETICA;    f_size_ = FL_NORMAL_SIZE;    date_sunday = 0;    date_mark = 0;    memset(db_name, 0, sizeof(db_name));    db = NULL;    first_appt = NULL;    pix_ratio = (double) b_height / 7200;	//pix per second    day_pix = 86400 * pix_ratio;    num_recs = 0;    memset(appt_array, 0, sizeof(appt_array));    output_box = NULL;}WeekGrid::~WeekGrid(){    if (first_appt)	free_appts(first_appt);}voidWeekGrid::resize(int X, int Y, int W, int H){}voidWeekGrid::draw(){    int X;    int Y;    char buf[10];    if (info_draw) {	ShowInfo(Fl::event_x(), Fl::event_y());	return;    }    fl_color(color_);    fl_rectf(x(), y(), w(), (int) (6.5 * b_height));    fl_color(line_color_);    fl_rect(x(), y(), w(), (int) (6.5 * b_height));    for (X = 1; X < 7; X++)	fl_line(x() + (X * b_width), y(), x() + (X * b_width),		(int) (6.5 * b_height) + y() - 1);    for (Y = 1; Y < 7; Y++)	fl_line(x(), y() + (Y * b_height), x() + w() - 1,		y() + (Y * b_height));    int idx = 0;    switch (scroll_count) {    case 0:	idx = 0;	break;    case 1:	idx = 8;	break;    case 2:	idx = 12;	break;    default:	idx = 0;	break;    }    int count = 0;    for (; idx <= 24 && count < 7; idx++) {	int val = idx % 12;	if (0 != idx % 2)	    continue;	if (0 == val)	    val = 12;	if (idx < 12 || idx == 24)	    sprintf(buf, "%d:00 am", val);	else	    sprintf(buf, "%d:00 pm", val);	//fl_font(font_, f_size_);	fl_color(NxApp::Instance()->getGlobalColor(APP_FG));	fl_draw(buf, 25, y() + ((count * b_height) - ((int) fl_height()) - 2),		2 * BUTTON_W, 2 * BUTTON_W, FL_ALIGN_RIGHT);	count++;    }    // need to get the appointmets and put them on the grid    DrawAppointments();}intWeekGrid::UpCount(){    if (MAX_COUNT == scroll_count)	return 0;    scroll_count++;    return 1;}intWeekGrid::DownCount(){    if (0 == scroll_count)	return 0;    scroll_count--;    return 1;}intWeekGrid::Overlap(appt * p_Appt){    time_t new_time = 0;    tm *tt;    int max_val = 0;    int low_val = 0;    int hi_val = 0;    int t_hour = 0;    int t_min = 0;    int col = 0;    int row = 0;    int h1 = 0;    int idx = 0;    if (NULL == p_Appt)	return 0;    new_time = p_Appt->start_time;    tt = localtime(&new_time);    t_hour = tt->tm_hour;    t_min = tt->tm_min;    col = tt->tm_wday;    row = (t_min / MIN_INC) + (t_hour * HOUR_INC);    new_time = p_Appt->end_time;    tt = localtime(&new_time);    t_hour = tt->tm_hour;    t_min = tt->tm_min;    h1 = (t_min / MIN_INC) + (t_hour * HOUR_INC);    h1 = h1 - row;    for (idx = 0; idx < h1; idx++) {	if (LEFT & p_Appt->overlay) {	// go hi	    hi_val = appt_array[col][row + idx] >> 4;	    if (hi_val > max_val)		max_val = hi_val;	} else {		// go low	    low_val = appt_array[col][row + idx] & APPT_MASK;	    if (low_val > max_val)		max_val = low_val;	}    }    return max_val;}voidWeekGrid::GetOverlapDim(appt * p_Appt, appt * p_Prev){    time_t new_time = 0;    tm *tt;    int t_hour = 0;    int t_min = 0;    int h1 = 0;    int h2 = 0;    int col = 0;    int row1 = 0;    int row2 = 0;    int idx = 0;    uchar hi_val = 0;    uchar low_val = 0;    uchar val = 0;    if (NULL == p_Appt && NULL == p_Prev)	return;    if (NULL == p_Appt)		// single appt only	new_time = p_Prev->start_time;    else	new_time = p_Appt->start_time;    tt = localtime(&new_time);    t_hour = tt->tm_hour;    t_min = tt->tm_min;    col = tt->tm_wday;    row1 = (t_min / MIN_INC) + (t_hour * HOUR_INC);    if (NULL == p_Appt) {	// single only	new_time = p_Prev->end_time;	tt = localtime(&new_time);	t_hour = tt->tm_hour;	t_min = tt->tm_min;	h1 = (t_min / MIN_INC) + (t_hour * HOUR_INC);	h1 = h1 - row1;	for (idx = 0; idx < h1; idx++) {	    val = appt_array[col][row1 + idx];	    val &= APPT_MASK;	    if (val < MAX_VAL) {		appt_array[col][row1 + idx]++;	    }	    low_val = appt_array[col][row1 + idx] & APPT_MASK;	    val = appt_array[col][row1 + idx] >> 4;	    if (val < MAX_VAL)		val++;	    val = val << 4;	    appt_array[col][row1 + idx] = val | low_val;	}    } else if (NULL == p_Prev) {	// double on top of double	new_time = p_Appt->end_time;	tt = localtime(&new_time);	t_hour = tt->tm_hour;	t_min = tt->tm_min;	h1 = (t_min / MIN_INC) + (t_hour * HOUR_INC);	h1 = h1 - row1;	for (idx = 0; idx < h1; idx++) {	    if (RIGHT & p_Appt->overlay) {		hi_val = appt_array[col][row1 + idx] >> 4;		val = appt_array[col][row1 + idx] & APPT_MASK;		if (MAX_VAL > val) {		    val++;		}		hi_val = hi_val << 4;		appt_array[col][row1 + idx] = hi_val | val;	    } else {		low_val = appt_array[col][row1 + idx] & APPT_MASK;		val = appt_array[col][row1 + idx] >> 4;		if (val < MAX_VAL)		    val++;		val = val << 4;		appt_array[col][row1 + idx] = val | low_val;	    }	}    } else {			// single on top of single	if (p_Appt->y >= p_Prev->y) {	    p_Appt->overlay = RIGHT;	    p_Prev->overlay = LEFT;	} else {	    p_Appt->overlay = LEFT;	    p_Prev->overlay = RIGHT;	}	// zero out a side and add other appt	if (p_Appt->overlay & RIGHT) {	    new_time = p_Prev->start_time;	    tt = localtime(&new_time);	    t_hour = tt->tm_hour;	    t_min = tt->tm_min;	    row1 = (t_min / MIN_INC) + (t_hour * HOUR_INC);	    new_time = p_Prev->end_time;	    tt = localtime(&new_time);	    t_hour = tt->tm_hour;	    t_min = tt->tm_min;	    h1 = (t_min / MIN_INC) + (t_hour * HOUR_INC);	    h1 = h1 - row1;	    for (idx = 0; idx < h1; idx++) {	// clear out bits		val = appt_array[col][row1 + idx] & APPT_MASK;		if (val > 0)		    appt_array[col][row1 + idx]--;	    }	    new_time = p_Appt->start_time;	    tt = localtime(&new_time);	    t_hour = tt->tm_hour;	    t_min = tt->tm_min;	    row2 = (t_min / MIN_INC) + (t_hour * HOUR_INC);	    new_time = p_Appt->end_time;	    tt = localtime(&new_time);	    t_hour = tt->tm_hour;	    t_min = tt->tm_min;	    h2 = (t_min / MIN_INC) + (t_hour * HOUR_INC);	    h2 = h2 - row2;	    for (idx = 0; idx < h2; idx++) {	// add bits		val = appt_array[col][row2 + idx] & APPT_MASK;		if (val < MAX_VAL) {		    appt_array[col][row2 + idx]++;		}	    }	} else {	    new_time = p_Prev->start_time;	    tt = localtime(&new_time);	    t_hour = tt->tm_hour;	    t_min = tt->tm_min;	    row1 = (t_min / MIN_INC) + (t_hour * HOUR_INC);	    new_time = p_Prev->end_time;	    tt = localtime(&new_time);	    t_hour = tt->tm_hour;	    t_min = tt->tm_min;	    h1 = (t_min / MIN_INC) + (t_hour * HOUR_INC);	    h1 = h1 - row1;	    for (idx = 0; idx < h1; idx++) {	// clear out bits		low_val = appt_array[col][row1 + idx] & APPT_MASK;		val = appt_array[col][row1 + idx] >> 4;		if (val > 0)		    val--;		val = val << 4;		appt_array[col][row1 + idx] = val | low_val;	    }	    new_time = p_Appt->start_time;	    tt = localtime(&new_time);	    t_hour = tt->tm_hour;	    t_min = tt->tm_min;	    row2 = (t_min / MIN_INC) + (t_hour * HOUR_INC);	    new_time = p_Appt->end_time;	    tt = localtime(&new_time);	    t_hour = tt->tm_hour;	    t_min = tt->tm_min;	    h2 = (t_min / MIN_INC) + (t_hour * HOUR_INC);	    h2 = h2 - row2;	    for (idx = 0; idx < h2; idx++) {	// add bits		low_val = appt_array[col][row2 + idx] & APPT_MASK;		val = appt_array[col][row2 + idx] >> 4;		if (val < MAX_VAL)		    val++;		val = val << 4;		appt_array[col][row2 + idx] = val | low_val;	    }	}    }}voidWeekGrid::GetOverlap(){    appt *p_PrevAppt = NULL;    appt *p_CurAppt = NULL;    appt *temp_appt = NULL;    appt *mark_appt = NULL;    appt *r_mark_appt = NULL;    appt *l_mark_appt = NULL;    tm *t1;    int yday = 0;    int yday2 = 0;    time_t new_time = 0;    int overlay = 0;    int left = 0;    int temp_left;    int single = 1;    p_CurAppt = first_appt;    while (p_CurAppt) {	single = 1;	new_time = p_CurAppt->start_time;	t1 = localtime(&new_time);	yday = t1->tm_yday;	left = !left;	if (yday != yday2) {	// first for day	    left = 0;	    yday2 = yday;	    GetOverlapDim(NULL, p_CurAppt);	    p_CurAppt = p_CurAppt->next_appt;	    continue;	}	p_PrevAppt = p_CurAppt->prev_appt;	while (p_PrevAppt) {	    if ((p_CurAppt->y >= p_PrevAppt->y)		&& (p_CurAppt->y < (p_PrevAppt->y + p_PrevAppt->h))) {		single = 0;		r_mark_appt = NULL;		l_mark_appt = NULL;		overlay = p_PrevAppt->overlay;		temp_appt = p_CurAppt->prev_appt;		temp_left = left;		temp_appt = p_CurAppt->prev_appt;		mark_appt = NULL;		if ((overlay & LEFT) || (overlay & RIGHT)) {	// go on top of shorter overlay		    if (left) {	// can it go left alone check			while (temp_appt) {			    if ((LEFT & temp_appt->overlay)				&& (p_CurAppt->y >= temp_appt->y)				&& (p_CurAppt->y <				    (temp_appt->y + temp_appt->h))) {				l_mark_appt = temp_appt;				break;			    }			    temp_appt = temp_appt->prev_appt;			}			// else check to see if it can go right			if (l_mark_appt) {			    left = 0;			    temp_appt = p_CurAppt->prev_appt;			    while (temp_appt) {				if ((RIGHT & temp_appt->overlay)				    && (p_CurAppt->y >= temp_appt->y)				    && (p_CurAppt->y <					(temp_appt->y + temp_appt->h))) {				    r_mark_appt = temp_appt;				    break;				}				temp_appt = temp_appt->prev_appt;			    }			    if (r_mark_appt) {	// can't go right either which one ends first prev or mark?				if ((l_mark_appt->y + l_mark_appt->h) >				    (r_mark_appt->y + r_mark_appt->h)) {				    mark_appt = r_mark_appt;				    left = 0;				} else {				    mark_appt = l_mark_appt;				    left = 1;				}			    }			}		    } else {	// check to see if it can go right alone 			DPRINT("going right\n");			temp_appt = p_CurAppt->prev_appt;			while (temp_appt) {			    if ((RIGHT & temp_appt->overlay)				&& (p_CurAppt->y >= temp_appt->y)				&& (p_CurAppt->y <				    (temp_appt->y + temp_appt->h))) {				r_mark_appt = temp_appt;				break;			    }			    temp_appt = temp_appt->prev_appt;			}			// else check to see if can go left alone       			if (r_mark_appt) {			    left = 1;			    temp_appt = p_CurAppt->prev_appt;			    while (temp_appt) {				if ((LEFT & temp_appt->overlay)				    && (p_CurAppt->y >= temp_appt->y)				    && (p_CurAppt->y <

⌨️ 快捷键说明

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