/** * @brief Saves Etk's config to disk * @return Returns ETK_TRUE on a successful save, ETK_FALSE otherwise. */ Etk_Bool etk_config_save(void) { Eet_File *ef; char buf[PATH_MAX]; char *home; Etk_Bool ret; home = getenv("HOME"); if (!home) return 0; snprintf(buf, sizeof(buf), "%s/.e/etk/config.eet", home); ef = eet_open(buf, EET_FILE_MODE_WRITE); if (!ef) return 0; ret = eet_data_write(ef, _etk_config_ver_edd, "config/version", _etk_config->version, 1); if (!ret) ETK_WARNING("Problem saving config!"); ret = eet_data_write(ef, _etk_config_gen_edd, "config/general", _etk_config->general, 1); if (!ret) ETK_WARNING("Problem saving config/stickies!"); eet_close(ef); return ret; }
/** * @brief Initializes the config system * @return Returns true if initialization was successful, false otherwise */ Etk_Bool etk_config_init(void) { char *home; char buf[PATH_MAX]; home = getenv("HOME"); if (!home) { ETK_WARNING("Cant find home directory!"); return ETK_FALSE; } /* make sure ~/.e exists and is a dir */ snprintf(buf, sizeof(buf), "%s/.e", home); if (!ecore_file_is_dir(buf)) { if (ecore_file_exists(buf)) { ETK_WARNING("Cant create config path!"); return ETK_FALSE; } if (!ecore_file_mkdir(buf)) { ETK_WARNING("Cant create config path!"); return ETK_FALSE; } } /* make sure ~/.e/etk exists and is a dir */ snprintf(buf, sizeof(buf), "%s/.e/etk", home); if (!ecore_file_is_dir(buf)) { if (ecore_file_exists(buf)) { ETK_WARNING("Cant create config path!"); return ETK_FALSE; } if (!ecore_file_mkdir(buf)) { ETK_WARNING("Cant create config path!"); return ETK_FALSE; } } _etk_config_gen_edd = NEWD("Etk_Config_General", Etk_Config_General); CFG_GEN_NEWI("wmt", wm_theme, EET_T_STRING); CFG_GEN_NEWI("wt", widget_theme, EET_T_STRING); CFG_GEN_NEWI("fn", font, EET_T_STRING); CFG_GEN_NEWI("en", engine, EET_T_STRING); _etk_config_ver_edd = NEWD("Etk_Config_Version", Etk_Config_Version); CFG_VER_NEWI("mj", major, EET_T_INT); CFG_VER_NEWI("mn", minor, EET_T_INT); CFG_VER_NEWI("pa", patch, EET_T_INT); CFG_VER_NEWI("sp", subpatch, EET_T_INT); return ETK_TRUE; }
EMessenger::EMessenger(eint64 targetTeam, euint64 targetToken, e_bigtime_t timestamp, e_status_t *perr) : fHandlerToken(E_MAXUINT64), fLooperToken(E_MAXUINT64), fPort(NULL), fSem(NULL), fTargetTeam(E_INT64_CONSTANT(0)) { if(targetTeam != etk_get_current_team_id()) { ETK_WARNING("[APP]: %s --- Remote target unsupported yet.", __PRETTY_FUNCTION__); if(perr) *perr = E_ERROR; return; } if(etk_ref_handler(targetToken) == false) { if(perr) *perr = E_ERROR; return; } euint64 looperToken = E_MAXUINT64; if(etk_get_handler_create_time_stamp(targetToken) != timestamp || (looperToken = etk_get_ref_looper_token(targetToken)) == E_MAXUINT64) { etk_unref_handler(targetToken); if(perr) *perr = E_ERROR; return; } fTargetTeam = targetTeam; fHandlerToken = targetToken; fLooperToken = looperToken; if(perr) *perr = E_OK; }
e_font_detach_callback* EFontFT2::Attach(void (*callback)(void*), void *data) { EAutolock <ELocker> autolock(&etk_ft2_font_locker); e_font_detach_callback *eCallback = EFontEngine::Attach(callback, data); if(eCallback && !fFace) { if(FT_New_Face(_etk_ft2_library_, fFilename, fFaceIndex, &fFace) || !fFace) { ETK_DEBUG("[FONT]: %s --- CAN NOT load face[%s:%d].", __PRETTY_FUNCTION__, fFilename, fFaceIndex); EFontEngine::Detach(eCallback); return NULL; } if(FT_Select_Charmap(fFace, FT_ENCODING_UNICODE)) { if(FT_Select_Charmap(fFace, FT_ENCODING_NONE)) { ETK_WARNING("[FONT]: %s --- font[%s] don't support unicode at all.", __PRETTY_FUNCTION__, fFilename); FT_Done_Face(fFace); fFace = NULL; EFontEngine::Detach(eCallback); return NULL; } } } return eCallback; }
status_t BScrollBar::SetTarget(BView *target) { if (target == this) return B_ERROR; if (target == fTarget) return B_OK; if (target != NULL) { if (!(target->Ancestor() == Ancestor() || (target->Window() == Window() && Window() != NULL))) { ETK_WARNING("[INTERFACE]: %s --- target hasn't same ancestor as this.", __PRETTY_FUNCTION__); return B_BAD_VALUE; } if (target->fScrollBar.AddItem(this) == false) return B_ERROR; } if (fTarget != NULL) fTarget->fScrollBar.RemoveItem(this); fTarget = target; if (fTarget != NULL) { if (fOrientation == B_HORIZONTAL) fTarget->ScrollTo(fValue, fTarget->LeftTop().y); else fTarget->ScrollTo(fTarget->LeftTop().x, fValue); } return B_OK; }
static void server() { ENetEndpoint endpoint(SOCK_STREAM); if(endpoint.InitCheck() != E_OK) ETK_ERROR("Failed to create endpoint: %s.", endpoint.ErrorStr()); if(endpoint.Bind(DEFAULT_PORT) != E_OK) ETK_ERROR("Bind(%d) failed: %s.", DEFAULT_PORT, endpoint.ErrorStr()); if(endpoint.Listen() != E_OK) ETK_ERROR("Listen() failed: %s.", endpoint.ErrorStr()); while(true) { ETK_OUTPUT("Waiting for client ...\n"); ENetEndpoint *connection = endpoint.Accept(500); if(connection == NULL) { ETK_WARNING("Accept() == NULL: %s.", endpoint.ErrorStr()); continue; } struct in_addr addr; euint16 port; connection->RemoteAddr().GetAddr(addr, &port); euint32 ip = E_BENDIAN_TO_HOST_INT32(addr.s_addr); ETK_OUTPUT("connection from %d.%d.%d.%d, port: %d\n", ip >> 24, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff, port); EString buf; time_t curTime = time(NULL); buf << ctime(&curTime) << "\r\n"; connection->Send(buf.String(), buf.Length()); delete connection; } }
EMessenger::EMessenger(const char *signature, eint64 team, e_status_t *perr) : fHandlerToken(E_MAXUINT64), fLooperToken(E_MAXUINT64), fPort(NULL), fSem(NULL), fTargetTeam(E_INT64_CONSTANT(0)) { // TODO ETK_WARNING("[APP]: %s --- Remote target unsupported yet.", __PRETTY_FUNCTION__); if(perr) *perr = E_ERROR; }
EWin32GraphicsWindow::EWin32GraphicsWindow(EWin32GraphicsEngine *win32Engine, eint32 x, eint32 y, euint32 w, euint32 h) : EGraphicsWindow(), win32Window(NULL), fLook((e_window_look)0), fFeel((e_window_feel)0), fActivateWhenShown(false), hbrBackground(NULL), fEngine(NULL), fRequestWin(NULL), fRequestAsyncWin(NULL), WM_ETK_MESSAGE(0) { if(w == E_MAXUINT32 || h == E_MAXUINT32) { ETK_DEBUG("[GRAPHICS]: %s --- Either width or height is so large.", __PRETTY_FUNCTION__); return; } if(win32Engine == NULL) return; do { EAutolock <EWin32GraphicsEngine> autolock(win32Engine); if(autolock.IsLocked() == false || win32Engine->InitCheck() != E_OK || win32Engine->WM_ETK_MESSAGE == 0 || win32Engine->win32RequestWin == NULL || win32Engine->win32RequestAsyncWin == NULL) { if(fRequestWin != NULL) CloseHandle(fRequestWin); if(fRequestAsyncWin != NULL) CloseHandle(fRequestAsyncWin); ETK_WARNING("[GRAPHICS]: %s --- Invalid engine or unable to duplicate handle.", __PRETTY_FUNCTION__); return; } WM_ETK_MESSAGE = win32Engine->WM_ETK_MESSAGE; fRequestWin = win32Engine->win32RequestWin; fRequestAsyncWin = win32Engine->win32RequestAsyncWin; } while(false); e_rgb_color whiteColor = {255, 255, 255, 255}; EGraphicsDrawable::SetBackgroundColor(whiteColor); etk_win32_gdi_callback_t callback; callback.command = WM_ETK_MESSAGE_CREATE_WINDOW; callback.win = this; callback.x = x; callback.y = y; callback.w = w; callback.h = h; callback.bkColor = whiteColor; bool successed = (SendMessageA(fRequestWin, WM_ETK_MESSAGE, WM_ETK_MESSAGE_WINDOW, (LPARAM)&callback) == (LRESULT)TRUE); if(successed == false || win32Window == NULL) { ETK_DEBUG("[GRAPHICS]: %s --- Unable to create window: \"%s\".", __PRETTY_FUNCTION__, successed ? "win32Window = NULL" : "SendMessageA failed"); } else { fEngine = win32Engine; } }
void EMessageQueue::Unlock() { if(etk_count_locker_locks(fLocker) <= 0) { ETK_WARNING("[APP]: %s -- MessageQueue wasn't locked by current thread.", __PRETTY_FUNCTION__); return; } etk_unlock_locker(fLocker); }
e_status_t EMessenger::_SendMessageToPort(void *port, const EMessage *msg, euint32 flags, e_bigtime_t timeout) { if(!port || !msg) return E_ERROR; size_t flattenedSize = msg->FlattenedSize(); if(flattenedSize <= 0) { ETK_WARNING("[APP]: Faltten size little than 1. (%s:%d)", __FILE__, __LINE__); return E_ERROR; } char *buffer = (char*)malloc(flattenedSize); if(!buffer) { ETK_WARNING("[APP]: Buffer malloc failed. (%s:%d)", __FILE__, __LINE__); return E_NO_MEMORY; } if(msg->Flatten(buffer, flattenedSize) == false) { free(buffer); ETK_WARNING("[APP]: Flatten message failed. (%s:%d)", __FILE__, __LINE__); return E_ERROR; } e_status_t status; if((status = etk_write_port_etc(port, _EVENTS_PENDING_, buffer, flattenedSize, flags, timeout)) != E_OK) { free(buffer); ETK_WARNING("[APP]: write port %s. (%s:%d)", status == E_TIMEOUT ? "time out" : "failed", __FILE__, __LINE__); return status; } free(buffer); return E_OK; }
_IMPEXP_ETK bool etk_font_freetype2_init(void) { EAutolock <ELocker> autolock(&etk_ft2_font_locker); if(!_etk_ft2_initialized_) { FT_Error error = FT_Init_FreeType(&_etk_ft2_library_); if(error) { ETK_WARNING("[FONT]: %s --- CAN NOT initialize freetype engine %d\n", __PRETTY_FUNCTION__, error); return false; } _etk_ft2_initialized_ = true; } return true; }
e_status_t EMessenger::SendMessage(const EMessage *a_message, EMessage *reply_message, e_bigtime_t sendTimeout, e_bigtime_t replyTimeout) const { if(a_message == NULL || reply_message == NULL) { ETK_WARNING("[APP]: %s --- Can't post empty message or \"reply_message\" assigned to be \"NULL\".", __PRETTY_FUNCTION__); return E_BAD_VALUE; } void *port = etk_create_port(1, NULL, ETK_AREA_ACCESS_OWNER); if(port == NULL) return E_NO_MORE_PORTS; EMessage *aMsg = new EMessage(*a_message); if(aMsg->fSource != NULL) etk_delete_port(aMsg->fSource); aMsg->fTeam = etk_get_current_team_id(); aMsg->fIsReply = false; aMsg->fReplyToken = E_MAXUINT64; aMsg->fReplyTokenTimestamp = E_MAXINT64; aMsg->fNoticeSource = true; // auto close the port when deleted aMsg->fSource = port; // auto delete the port when deleted e_status_t status = _SendMessage(aMsg, E_MAXUINT64, sendTimeout); if(status == E_OK) { EMessage *reply = _GetMessageFromPort(port, E_TIMEOUT, replyTimeout, &status); if(reply != NULL) { *reply_message = *reply; delete reply; } else { reply_message->what = E_NO_REPLY; } } delete aMsg; return status; }
_IMPEXP_ETK e_status_t etk_unlock_locker(void *data) { etk_posix_locker_t *locker = (etk_posix_locker_t*)data; if(!locker) return E_BAD_VALUE; etk_lock_locker_inter(locker); if(locker->HolderThreadIsCurrent() == false) { etk_unlock_locker_inter(locker); ETK_WARNING("[KERNEL]: %s -- Can't unlock when didn't hold it in current thread!", __PRETTY_FUNCTION__); return E_ERROR; } else { if(locker->lockCount <= E_INT64_CONSTANT(1)) { if(pthread_mutex_unlock(&(locker->Locker)) != 0) { etk_unlock_locker_inter(locker); return E_ERROR; } } locker->lockCount--; if(locker->lockCount <= E_INT64_CONSTANT(0)) { locker->SetHolderThreadId(E_INT64_CONSTANT(0)); locker->lockCount = E_INT64_CONSTANT(0); pthread_cond_broadcast(&(locker->Cond)); } etk_unlock_locker_inter(locker); } return E_OK; }
e_status_t EMessenger::SendMessage(const EMessage *a_message, EHandler *reply_to, e_bigtime_t timeout) const { if(a_message == NULL) { ETK_WARNING("[APP]: %s --- Can't post empty message.", __PRETTY_FUNCTION__); return E_BAD_VALUE; } euint64 replyToken = etk_get_handler_token(reply_to); EMessage aMsg(*a_message); aMsg.fIsReply = false; if(aMsg.fSource != NULL) { etk_delete_port(aMsg.fSource); aMsg.fSource = NULL; } return _SendMessage(&aMsg, replyToken, timeout); }
e_status_t EDFBGraphicsEngine::UpdateFonts(bool check_only) { EString fonts_dirs; const char *dirs = getenv("DIRECTFB_FONTS_DIR"); if(dirs) fonts_dirs += dirs; if(fonts_dirs.Length() <= 0) ETK_WARNING("[FONT]: you can set the environment \"DIRECTFB_FONTS_DIR\" to match the correct dirs."); EAutolock <EDFBGraphicsEngine> autolock(this); if(autolock.IsLocked() == false || InitCheck() != E_OK) return E_ERROR; if(check_only) { ETK_WARNING("[GRAPHICS]: %s --- check_only not implement yet.", __PRETTY_FUNCTION__); return E_ERROR; } ETK_DEBUG("[GRAPHICS]: Updating DirectFB fonts ..."); EStringArray *fonts_dirs_array = fonts_dirs.Split(":"); ETK_DEBUG("[FONT]: Fonts directory number: %d", (fonts_dirs_array ? fonts_dirs_array->CountItems() : 0)); eint32 count = 0; const EString *_fonts_dir; for(eint32 m = 0; (_fonts_dir = (fonts_dirs_array ? fonts_dirs_array->ItemAt(m) : NULL)) != NULL; m++) { EDirectory directory(_fonts_dir->String()); if(directory.InitCheck() != E_OK) { ETK_WARNING("[FONT]: CAN NOT open fonts directory - \"%s\"!", _fonts_dir->String()); continue; } ETK_DEBUG("[FONT]: Opening font directory \"%s\"...", _fonts_dir->String()); EEntry aEntry; while(directory.GetNextEntry(&aEntry, true) == E_OK) { EPath aPath; if(aEntry.GetPath(&aPath) != E_OK) continue; EString filename = aPath.Leaf(); if(filename.Length() <= 0 || filename == "." || filename == "..") continue; ETK_DEBUG("[FONT]: Reading font file \"%s\" ...", aPath.Path()); EDFBFont *engine = new EDFBFont(this, aPath.Path()); if(engine == NULL || engine->IsValid() == false || etk_font_add(engine->Family(), engine->Style(), engine) == false) { if(engine) delete engine; continue; } count++; } } if(fonts_dirs_array) delete fonts_dirs_array; if(count == 0) { EDFBFont *engine = new EDFBFont(this, NULL); if(engine == NULL || engine->IsValid() == false || etk_font_add(engine->Family(), engine->Style(), engine) == false) { if(engine) delete engine; } } ETK_DEBUG("[GRAPHICS]: DirectFB fonts updated."); return E_OK; }
_IMPEXP_ETK bool etk_update_freetype2_font_families(bool check_only) { EString fonts_dirs; #ifdef _WIN32 const char dir_env_sep = ';'; #else const char dir_env_sep = ':'; #endif const char *dirs = getenv("FREETYPE_FONTS_DIR"); if(dirs) fonts_dirs += dirs; if(fonts_dirs.Length() <= 0) { #ifdef _WIN32 fonts_dirs = "C:\\Progra~1\\freetype"; #elif defined(ETK_OS_BEOS) fonts_dirs = "/boot/beos/etc/fonts/ttfonts"; ETK_WARNING("[FONT]: you can set the environment \"FREETYPE_FONTS_DIR\" to match the correct dirs."); #else fonts_dirs = "/usr/share/fonts/freetype"; #endif } EAutolock <ELocker> autolock(&etk_ft2_font_locker); if(check_only) { ETK_WARNING("[FONT]: %s --- check_only not implement yet.", __PRETTY_FUNCTION__); return false; } if(!_etk_ft2_initialized_) { ETK_WARNING("[FONT]: Freetype engine not initialize! REFUSE TO LOAD FONTS!!!"); return false; } EStringArray *fonts_dirs_array = fonts_dirs.Split(dir_env_sep); if(!fonts_dirs_array) { ETK_WARNING("[FONT]: %s --- Couldn't find any font directory.", __PRETTY_FUNCTION__); return false; } ETK_DEBUG("[FONT]: Updating FreeType2 fonts ..."); // ETK_DEBUG("[FONT]: Fonts directory number: %d", fonts_dirs_array->CountItems()); const EString *_fonts_dir; for(eint32 m = 0; (_fonts_dir = fonts_dirs_array->ItemAt(m)) != NULL; m++) { EDirectory directory(_fonts_dir->String()); if(directory.InitCheck() != E_OK) { ETK_WARNING("[FONT]: CAN NOT open fonts directory - \"%s\"!", _fonts_dir->String()); continue; } // ETK_DEBUG("[FONT]: Opening font directory \"%s\"...", _fonts_dir->String()); EEntry aEntry; while(directory.GetNextEntry(&aEntry, true) == E_OK) { EPath aPath; if(aEntry.GetPath(&aPath) != E_OK) continue; EString filename = aPath.Leaf(); // Ignore not "*.ttf" etc... if(filename.Length() < 5) continue; const char *fontPattern[] = {".ttf", ".ttc", ".pcf", ".fon", ".pfa", ".pfb"}; bool isPatternMatched = false; for(euint8 i = 0; i < 6; i++) { if(filename.IFindLast(fontPattern[i]) == filename.Length() - (eint32)strlen(fontPattern[i])) { isPatternMatched = true; break; } } if(!isPatternMatched) continue; // ETK_DEBUG("[FONT]: Reading font file \"%s\" ...", aPath.Path()); eint32 faceIndex = 0, nFaces = 0; do{ EFontFT2 *engine = new EFontFT2(&aEntry, faceIndex); if(!engine || !engine->IsValid()) { if(engine) delete engine; if(faceIndex == 0) break; else { faceIndex++; continue; } } if(faceIndex == 0) { nFaces = engine->CountFaces(); // ETK_DEBUG("\tFaces Number: %d", nFaces); } // ETK_DEBUG("\tFamily[%d]: %s", faceIndex, engine->Family()); // ETK_DEBUG("\t\tStyle: %s", engine->Style()); if(!etk_font_add(engine->Family(), engine->Style(), engine)) delete engine; faceIndex++; }while(faceIndex < nFaces); } } if(fonts_dirs_array) delete fonts_dirs_array; ETK_DEBUG("[FONT]: FreeType2 fonts updated."); return true; }
/** * @brief Loads Etk's config from disk * @return Returns ETK_TRUE on a successful load, ETK_FALSE otherwise. */ Etk_Bool etk_config_load(void) { Eet_File *ef; char buf[PATH_MAX]; char *home; home = getenv("HOME"); if (!home) { _etk_config_defaults_apply(); return ETK_FALSE; } snprintf(buf, sizeof(buf), "%s/.e/etk/config.eet", home); if (!ecore_file_exists(buf) || ecore_file_size(buf) == 0) { /* no saved config */ _etk_config_defaults_apply(); return ETK_FALSE; } ef = eet_open(buf, EET_FILE_MODE_READ); if (!ef) { ETK_WARNING("Cant open configuration file! Using program defaults."); return ETK_FALSE; } if (!_etk_config) _etk_config = malloc(sizeof(Etk_Config)); else { free(_etk_config->version); if (_etk_config->general) { free(_etk_config->general->wm_theme); free(_etk_config->general->widget_theme); free(_etk_config->general->font); free(_etk_config->general->engine); free(_etk_config->general); } } _etk_config->version = NULL; _etk_config->version = eet_data_read(ef, _etk_config_ver_edd, "config/version"); if(!_etk_config->version) { ETK_WARNING("Incompatible configuration file! Creating new one."); eet_close(ef); _etk_config_defaults_apply(); return ETK_FALSE; } else { Etk_Config_Version *v; v = _etk_config_version_parse(VERSION); if(_etk_config_version_compare(v, _etk_config->version) != 0) { ETK_WARNING("Your version / configuration of Etk is not valid!"); eet_close(ef); free(v); _etk_config_defaults_apply(); return ETK_FALSE; } free(v); } _etk_config->general = eet_data_read(ef, _etk_config_gen_edd, "config/general"); if (!_etk_config->general) _etk_config_defaults_apply(); eet_close(ef); return ETK_TRUE; }
_IMPEXP_ETK void* etk_clone_area(const char *name, void **dest_addr, euint32 protection, const char *domain) { char *ipc_name = etk_area_ipc_name(name, domain); if(!ipc_name) return NULL; etk_win32_area_t *area = new etk_win32_area_t(); if(!area) { free(ipc_name); return NULL; } area->prot = protection; DWORD prot = (protection & E_WRITE_AREA ? FILE_MAP_ALL_ACCESS : FILE_MAP_READ); HANDLE handler; _ETK_LOCK_AREA_(); if((handler = OpenFileMapping(prot, FALSE, ipc_name)) == NULL) { // ETK_DEBUG("[KERNEL]: %s --- Can't clone area : open file mapping failed."", __PRETTY_FUNCTION__); _ETK_UNLOCK_AREA_(); free(ipc_name); delete area; return NULL; } if((area->addr = MapViewOfFile(handler, prot, 0, 0, 0)) == NULL) { ETK_DEBUG("[KERNEL]: %s --- Can't clone area : MapViewOfFile failed.", __PRETTY_FUNCTION__); CloseHandle(handler); _ETK_UNLOCK_AREA_(); free(ipc_name); delete area; return NULL; } etk_win32_area_info_t area_info; bzero(&area_info, sizeof(etk_win32_area_info_t)); memcpy(&area_info, area->addr, sizeof(etk_win32_area_info_t)); if(area_info.magic != WIN32_AREA_INFO_MAGIC || area_info.closed) { ETK_WARNING("[KERNEL]: %s --- FileMapping(%s) seem not created by ETK", __PRETTY_FUNCTION__, ipc_name); UnmapViewOfFile(area->addr); CloseHandle(handler); _ETK_UNLOCK_AREA_(); free(ipc_name); delete area; return NULL; } area->length = area_info.length; area->mapping = handler; area->name = e_strdup(name); area->domain = e_strdup(domain); area->ipc_name = ipc_name; area->openedIPC = true; area->created = true; _ETK_UNLOCK_AREA_(); if(dest_addr) *dest_addr = (void*)((char*)area->addr + sizeof(etk_win32_area_info_t)); return area; }
euint8* EFontFT2::RenderString(const char *string, eint32 *width, eint32 *height, bool *is_mono, float size, float spacing, float shear, bool bold, eint32 length) { if(string == NULL || *string == 0 || length == 0 || width == NULL || height == NULL || is_mono == NULL) return NULL; EAutolock <ELocker> autolock(&etk_ft2_font_locker); if(!IsAttached()) return NULL; bool isfixed = IsFixedSize(size); if(!fScalable && !isfixed) return NULL; float stringWidth; e_font_height fontHeight; if((stringWidth = StringWidth(string, size, spacing, shear, bold, length)) <= 0) return NULL; GetHeight(&fontHeight, size, shear, bold); eint32 w, h; w = (eint32)ceil(stringWidth) + 1; h = (eint32)ceil(fontHeight.ascent + fontHeight.descent) + 1; euint8 *bitmap = new euint8[w * h]; if(!bitmap) { ETK_WARNING("[FONT]: %s --- Unable to alloc memory for bitmap data.", __PRETTY_FUNCTION__); return NULL; } bzero(bitmap, sizeof(euint8) * (size_t)(w * h)); eunichar *unicode = e_utf8_convert_to_unicode(string, length); if(!unicode) { delete[] bitmap; return NULL; } const eunichar *ch; euint32 x = 0; euint32 y = (euint32)ceil(fontHeight.ascent); bool do_mono = fForceFontAliasing; for(ch = unicode; !(ch == NULL || *ch == 0); ch = e_unicode_next(ch, NULL)) { if(FT_Load_Char(fFace, *ch, (do_mono ? (FT_LOAD_RENDER | FT_LOAD_MONOCHROME) : FT_LOAD_RENDER))) { ETK_DEBUG("[FONT]: %s --- FT_Load_Char failed.", __PRETTY_FUNCTION__); continue; } FT_Bitmap *ftbitmap = &(fFace->glyph->bitmap); eint32 xx = x + (eint32)(fFace->glyph->bitmap_left); eint32 yy = y - (eint32)(fFace->glyph->bitmap_top); eint32 bitmapWidth = (eint32)(ftbitmap->width); eint32 bitmapHeight = (eint32)(ftbitmap->rows); eint32 lineBytes = (eint32)(ftbitmap->pitch > 0 ? ftbitmap->pitch : -(ftbitmap->pitch)); eint32 maxxx = min_c(w, xx + bitmapWidth); eint32 maxyy = min_c(h, yy + bitmapHeight); for(eint32 i = yy, p = 0; i < maxyy; i++, p++) { euint8* dest = bitmap; dest += i * w + xx; unsigned char* src = ftbitmap->buffer; src += p * lineBytes; switch(ftbitmap->pixel_mode) { case FT_PIXEL_MODE_GRAY: for(eint32 j = xx; j < maxxx; j++) *dest++ = (euint8)(*src++); break; case FT_PIXEL_MODE_MONO: for(eint32 j = xx; j < maxxx; ) { euint8 val = (euint8)(*src++); eint32 left = maxxx - j >= 8 ? 8 : maxxx - j; euint8 left_offset = 7; for(eint32 k = 0; k < left; k++, left_offset--, j++) *dest++ = (val & (1 << left_offset)) ? 255 : 0; } break; default: ETK_DEBUG("[FONT]: %s --- The mode of freetype bitmap not supported.", __PRETTY_FUNCTION__); } } x += (euint32)((float)(fFace->glyph->metrics.horiAdvance) / 64.f) + (euint32)ceil((double)(spacing * size)); // next x } free(unicode); *width = w; *height = h; *is_mono = do_mono; return bitmap; }
_IMPEXP_ETK e_status_t etk_resize_area(void *data, void **start_addr, size_t new_size) { ETK_WARNING("%s: Not supported.", __PRETTY_FUNCTION__); return E_ERROR; }
_IMPEXP_ETK e_status_t etk_set_area_protection(void *data, euint32 new_protection) { ETK_WARNING("%s: Not supported.", __PRETTY_FUNCTION__); return E_ERROR; }
EMessage* EMessenger::_GetMessageFromPort(void *port, euint32 flags, e_bigtime_t timeout, e_status_t *err) { e_status_t retErr = E_OK; EMessage* retMsg = NULL; do{ ssize_t bufferSize = etk_port_buffer_size_etc(port, flags, timeout); if(bufferSize == 0) { eint32 code; retErr = etk_read_port_etc(port, &code, NULL, 0, E_TIMEOUT, E_INT64_CONSTANT(0)); // if(retErr != E_OK) ETK_DEBUG("[APP]: Port read failed(0x%x). (%s:%d)", retErr, __FILE__, __LINE__); break; } else if(bufferSize < 0) { retErr = bufferSize; // if(!(retErr == E_WOULD_BLOCK || retErr == E_TIMED_OUT)) // ETK_DEBUG("[APP]: Port read failed(0x%x). (%s:%d)", retErr, __FILE__, __LINE__); break; } char *buffer = (char*)malloc((size_t)bufferSize); if(!buffer) { retErr = E_NO_MEMORY; ETK_WARNING("[APP]: Memory alloc failed. (%s:%d)", __FILE__, __LINE__); break; } bzero(buffer, (size_t)bufferSize); eint32 code; if((retErr = etk_read_port_etc(port, &code, buffer, bufferSize, E_TIMEOUT, E_INT64_CONSTANT(0))) != E_OK) { // ETK_DEBUG("[APP]: Port read failed(0x%x). (%s:%d)", retErr, __FILE__, __LINE__); free(buffer); break; } if(code != _EVENTS_PENDING_ || (size_t)bufferSize < sizeof(size_t)) { ETK_WARNING("[APP]: Message is invalid. (%s:%d)", __FILE__, __LINE__); free(buffer); retErr = E_ERROR; break; } size_t msgBufferSize = 0; memcpy(&msgBufferSize, buffer, sizeof(size_t)); if(bufferSize != (ssize_t)msgBufferSize) /* the first "size_t" == FlattenedSize() */ { ETK_WARNING("[APP]: Message length is invalid. (%s:%d)", __FILE__, __LINE__); free(buffer); retErr = E_ERROR; break; } if((retMsg = new EMessage()) == NULL) { ETK_WARNING("[APP]: Memory alloc failed. (%s:%d)", __FILE__, __LINE__); free(buffer); retErr = E_NO_MEMORY; break; } if(retMsg->Unflatten(buffer, msgBufferSize) == false) { ETK_WARNING("[APP]: Message unflatten failed. (%s:%d)", __FILE__, __LINE__); delete retMsg; retMsg = NULL; retErr = E_ERROR; } free(buffer); }while(false); if(err) *err = retErr; return retMsg; }
/** * @brief Does the same thing as etk_init() except you can specify custom arguments that could be then retrieved with * etk_argument_* functions. For example, etk_init_full(argc, argv, "--option1 value --toggle1") * @param argc the location of the "argc" parameter passed to main(). It is used to parse the arguments specific to Etk. * It can be set to NULL. * @param argv the location of the "argv" parameter passed to main(). It is used to parse the arguments specific to Etk. * It can be set to NULL. * @param custom_opts a string corresponding to the custom arguments to add to argv. It can be set to NULL * @return Returns the number of times Etk has been initialized, or 0 on failure * @note It initializes Evas, Ecore and Edje so you don't need to initialize them after an etk_init() * @see etk_init() * @see etk_shutdown() */ int etk_init_full(int argc, char **argv, const char *custom_opts) { char *engine_name = NULL; if (_etk_main_init_count > 0) { _etk_main_init_count++; return _etk_main_init_count; } else { /* Parse the arguments */ etk_argument_init(argc, argv, custom_opts); etk_argument_value_get("etk-engine", 0, ETK_TRUE, &engine_name); /* Initialize the EFL */ if (!evas_init()) { ETK_WARNING("Evas initialization failed!"); return 0; } if (!ecore_init()) { ETK_WARNING("Ecore initialization failed!"); return 0; } if (!ecore_imf_init()) { ETK_WARNING("Ecore_IMF initialization failed!"); } if (!edje_init()) { ETK_WARNING("Edje initialization failed!"); return 0; } /* TODO: maybe we should do this in etk_main(). * Problem: if we do this, a program that uses directly ecore_main_loop_begin() and not etk_main() won't work */ _etk_main_idle_enterer = ecore_idle_enterer_add(_etk_main_idle_enterer_cb, NULL); /* Initialize the subsystems of Etk */ if (!etk_config_init()) { ETK_WARNING("Etk_Config initialization failed!"); return 0; } etk_config_load(); etk_theme_init(); if (!etk_engine_init()) { ETK_WARNING("Etk_Engine initialization failed!"); return 0; } if (!etk_engine_load(engine_name ? engine_name : "ecore_evas_software_x11")) { ETK_WARNING("Etk can not load the requested engine!"); return 0; } etk_event_init(); etk_tooltips_init(); /* Initialize Gettext */ setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); free(engine_name); _etk_main_init_count++; return _etk_main_init_count; } }
/* Adds a new widget to the box, after the cell "after" */ static void _etk_box_insert_after_cell(Etk_Box *box, Etk_Widget *child, Etk_Box_Group group, Etk_Box_Cell *after, Etk_Box_Fill_Policy fill_policy, int padding) { Etk_Box_Cell *cell; Etk_Widget *box_widget; if (!(box_widget = ETK_WIDGET(box)) || !child) return; if (after && after->group != group) { ETK_WARNING("The child to pack and the widget after which the child should be packed " "do not belong to the same child-group"); return; } cell = malloc(sizeof(Etk_Box_Cell)); cell->prev = NULL; cell->next = NULL; cell->child = child; cell->focus_node = NULL; cell->group = group; cell->fill_policy = fill_policy; cell->padding = padding; if (after) { cell->prev = after; cell->next = after->next; if (after->next) after->next->prev = cell; else box->last_cell[group] = cell; after->next = cell; box_widget->focus_order = eina_list_append_relative_list(box_widget->focus_order, child, after->focus_node); cell->focus_node = eina_list_next(after->focus_node); } else { cell->next = box->first_cell[group]; if (box->first_cell[group]) box->first_cell[group]->prev = cell; else box->last_cell[group] = cell; box->first_cell[group] = cell; if (group == ETK_BOX_START || !box->last_cell[ETK_BOX_START]) { box_widget->focus_order = eina_list_prepend(box_widget->focus_order, child); cell->focus_node = box_widget->focus_order; } else { box_widget->focus_order = eina_list_append_relative_list(box_widget->focus_order, child, box->last_cell[ETK_BOX_START]->focus_node); cell->focus_node = eina_list_next(box->last_cell[ETK_BOX_START]->focus_node); } } box->cells_count[group]++; etk_widget_parent_set(child, ETK_WIDGET(box)); etk_object_data_set(ETK_OBJECT(child), "_Etk_Box::Cell", cell); etk_signal_emit(ETK_CONTAINER_CHILD_ADDED_SIGNAL, ETK_OBJECT(box), child); }