PageRenderTime 424ms CodeModel.GetById 201ms app.highlight 7ms RepoModel.GetById 214ms app.codeStats 0ms

/apps/common/ftk_app.h

http://ftk.googlecode.com/
C++ Header | 117 lines | 60 code | 27 blank | 30 comment | 22 complexity | 65d277bbc33f0e04c9db23ad7929d01a MD5 | raw file
  1/*
  2 * File: ftk_app.h    
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   application interface
  5 *
  6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
  7 *
  8 * Licensed under the Academic Free License version 2.1
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 23 */
 24
 25/*
 26 * History:
 27 * ================================================================
 28 * 2010-08-15 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31
 32#ifndef FTK_APP_H
 33#define FTK_APP_H
 34
 35#include "ftk.h"
 36
 37FTK_BEGIN_DECLS
 38
 39struct _FtkApp;
 40typedef struct _FtkApp FtkApp;
 41
 42typedef FtkBitmap*  (*FtkAppGetIcon)(FtkApp* thiz);
 43typedef const char* (*FtkAppGetName)(FtkApp* thiz);
 44typedef Ret  (*FtkAppRun)(FtkApp* thiz, int argc, char* argv[]);
 45typedef void (*FtkAppDestroy)(FtkApp* thiz);
 46typedef FtkApp* (*FtkLoadApp)(void);
 47
 48struct _FtkApp
 49{
 50	FtkAppGetIcon get_icon;
 51	FtkAppGetName get_name;
 52	FtkAppRun     run;
 53	FtkAppDestroy destroy;
 54
 55	char priv[ZERO_LEN_ARRAY];
 56};
 57
 58static inline FtkBitmap* ftk_app_get_icon(FtkApp* thiz)
 59{
 60	return_val_if_fail(thiz != NULL && thiz->get_icon != NULL, NULL);
 61
 62	return thiz->get_icon(thiz);
 63}
 64
 65static inline const char* ftk_app_get_name(FtkApp* thiz)
 66{
 67	return_val_if_fail(thiz != NULL && thiz->get_name != NULL, NULL);
 68
 69	return thiz->get_name(thiz);
 70}
 71
 72static inline Ret ftk_app_run(FtkApp* thiz, int argc, char* argv[])
 73{
 74	return_val_if_fail(thiz != NULL && thiz->run != NULL, RET_FAIL);
 75
 76	return thiz->run(thiz, argc, argv);
 77}
 78
 79static inline void ftk_app_destroy(FtkApp* thiz)
 80{
 81	if(thiz != NULL && thiz->destroy != NULL)
 82	{
 83//		thiz->destroy(thiz);
 84	}
 85
 86	return;
 87}
 88
 89#include "ftk_config.h"
 90#include "ftk_globals.h"
 91
 92static FtkBitmap* ftk_app_load_bitmap(FtkApp* thiz, const char* app_name, const char* icon_name)
 93{
 94	FtkBitmap* icon = NULL;
 95	char file_name[FTK_MAX_PATH + 1] = {0};
 96	return_val_if_fail(thiz != NULL && app_name != NULL && icon_name != NULL, NULL);
 97
 98	ftk_snprintf(file_name, FTK_MAX_PATH, "%s/%s/icons/%s"FTK_STOCK_IMG_SUFFIX, 
 99		FTK_ROOT_DIR, app_name, icon_name);
100	icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), file_name);
101
102	if(icon != NULL) return icon;
103
104	ftk_snprintf(file_name, FTK_MAX_PATH, "./icons/%s"FTK_STOCK_IMG_SUFFIX, icon_name);
105	icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), file_name);
106
107	if(icon != NULL) return icon;
108
109	icon = ftk_theme_load_image(ftk_default_theme(), "flag-32"FTK_STOCK_IMG_SUFFIX);
110
111	return icon;
112}
113
114FTK_END_DECLS
115
116#endif/*FTK_APP_H*/
117